15

Disclaimer: I am not sure if I am "allowed" to ask such a question, but I was also not sure if it belongs to Meta instead.

  • Often when somebody asks a tikz-focussed question, some users consistently offer Metapost alternatives just for comparison -- which is excellent -- see here for example.
  • Q: In terms of future-proof-ness, is it still beneficial for a beginner to spend time learning Metapost?
  • A possible answer could be that it is not beneficial because the LaTeX core team does not consider Metapost in their future development (I am just making this example answer up!).
  • 1
    For luatex with metapost there is already a post. https://tex.stackexchange.com/questions/515491/how-to-properly-use-metapost-in-plain-luatex/515736?r=SearchResults&s=1%7C28.3317#515736 – user206750 Feb 06 '23 at 00:51
  • 2
    Guilty as charged, your honour. Without getting too philosophical, I think learning is generally beneficial. And specifically, I note that the language is being actively developed by the luamplib team who have made careful well thought-out improvements to the integration with LaTeX and the support of large valued arithmetic without spoiling the beauty of the core language. – Thruston Feb 06 '23 at 09:08
  • 1
    The question definitely does not belong on Meta, because there only questions about the (use of the) site itself are on-topic, not meta-questions about LaTeX and related technologies. About the question itself: do you have a reason to believe that Metapost will not be developed further? If yes, what is this reason? If no, why did you ask the question? Also, why would Lua (the programming language) or LuaLaTeX (the engine) be relevant here? – Marijn Feb 06 '23 at 14:30
  • @Marijn Thanks for your interest. My question is based on a gutt-feeling. I rarely see Metapost questions but often Metapost answers. Also, I do not remember ever reading about Metapost in LaTeX books (I read a few but I could be wrong). I am not very familiar with the correct terminology, sorry if "Lua" is not used correctly. – Dr. Manuel Kuehner Feb 06 '23 at 15:22
  • 2
    @Marijn fair enough. LuaLaTeX is relevant because of the luamplib project which integrates Metapost into LuaLaTeX, as @mickep notes in his first bullet point below. – Thruston Feb 07 '23 at 09:03
  • @Thruston Will you also provide an answer? :) You also seem to be very knowledgeable. – Dr. Manuel Kuehner Feb 07 '23 at 16:38

2 Answers2

20

I was one of the persons answering in the linked question with a metapost/metafun example to the tikz question, and now I see that another metapost answer was in fact selected. I do not see why metapost should not be relevant (I truly hope that tikz, metapost, asymptote and pstricks all will survive and have a good future.) A beginner can choose any of these and get started pretty quickly.

Let me give a few reasons in favor of metapost (a bit subjective, of course):

  • It is, "in the age of lua", already integrated with lua: there is luamplib that makes it easy to use metapost directly with lualatex.
  • It is relatively simple compared to for example tikz.
  • It is quick, at least that is my experience (as mainly a ConTeXt user). I remember trying tikz in a big latex project, and I remember it as slowing down compilation a lot. That was a while ago, and I know one can externalize and so on, so...
  • It is actively developed.
  • The result is very pleasing (one can ask why in your linked question it is the metapost answer that is selected...).
  • It is very fun to use. Maybe because of its design with the linear equation solver and simple programming like loops and so on.
  • (Only for fun) I have heard rumors saying that cool people like DEK do use metapost for their drawings.

It could be fun to hear what plans the LaTeX core team has, but they usually strive for backwards compatibility, so I cannot see that they would drop metapost for any reason, just as they hopefully do not drop tikz, pstricks or asymptote. (Why (and how) would they?)

I use ConTeXt, and there I would say that metapost, or its extension metafun, is the very natural choice, since it is very integrated. One example of a simple integrated usage can be seen here in a recent question.

mickep
  • 8,685
6

The question is asked in two ways: "In terms of future-proof-ness, is it still beneficial for a beginner to learn Metapost?", and "Is Metapost still relevant in the age of lua?".

tl;dr -- Yes, which ever way you ask the question.

Let's first consider the state of the Metapost project. Metapost was first released in 1995 after a surprisingly long six-year gestation period. John Hobby had worked on TeX and Metafont with Knuth, and built the elegant cubic spline curve system for Metafont; it occurred to him in 1989 that the system could be adapted to produce PostScript output, so that he could produce better figures for his research papers. Hobby passed the project on to others after some years, and in 2007 it was separated into a front-end and back-end library by Taco Hoekwater, and support for extended floating point arithmetic was added. The project is still actively maintained by a small team who are very responsive to questions on the mailing list. You can find more details on the project home page at Tug.

The split into separate libraries was an important step, because it has allowed the system to be linked into lualatex. This greatly simplifies the work flow. If I want to produce a stand-alone MP graphic today, I use this template file:

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);

endfig; \end{mplibcode} \end{document}

and compile it with lualatex to produce a self-contained PDF file. My work flow looks a bit like this:

enter image description here

With the \mplibtextextlabel option enabled, you get a complete integration with regular LaTeX typesetting. You can include whatever LaTeX packages you want in the template, and use all the modern fonts supported by fontspec. You can even include an image file in a TeX label and draw on top of it (something that was very hard in regular old-fashioned Metapost). If you want to find out more about the work flow and integration with TeX, you might like to read Chapter 12 of my Drawing with Metapost project.

But you are not limited to producing single-picture PDFs. Provided you are happy to switch to the modern font world of fontspec, you will find that lualatex is very capable of producing large documents with all your Metapost illustrations included in a single source file. I have some examples of what you can do in one of my other pet projects, here. The details of how to integrate your graphics into your TeX source are set out in the (admittedly sparse) documentation for the luamplib package on CTAN.

All of this is to say that (in my opinion) MP is alive and well in 2023, and you can invest time and effort into learning it with confidence that the system will be around for as long as TeX is.

However, none of this touches on why you might like to learn it. So here are just two possible reason that echo the list of points in @mickep's answer.

  • It's a very well-designed language. I have nothing but admiration for the tikz-pgf team, but I have never really got to enjoy using TikZ, with its seemingly endless array of special-purpose notations and layers. Plain Metapost is a pretty small language and is well-adapted for semi-numerical drawings.

  • It's simple, but it is also subtle and interesting. I realise that this might sound odd to some people, but you might actually get a therapeutic joy from working out your own way to solve a geometrical puzzle in MP. It is a pleasure to use, like a well-designed hand tool.

Finally here's an example of the sort of drawing it's good at.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\usepackage{unicode-math}
\setmathfont{TeX Gyre Termes Math}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
beginfig(1);
    path C, vv, aa, oo;
    C = fullcircle scaled 4cm;
    linejoin := 0;
    linecap := 0;
    for t=0 upto 2:
      p := 8/3t+2;
      drawarrow subpath (p-4/3,p+4/3) of C withcolor Blues 8 7;
      vv := (origin -- unitvector(direction p of C) scaled 2cm)            shifted point p of C;
      aa := (origin -- unitvector(direction p of C) scaled 1cm rotated 90) shifted point p of C;
      drawarrow vv withpen pencircle scaled 2 withcolor Greens 8 6;
      drawarrow aa withpen pencircle scaled 2 withcolor Oranges 8 6;
      label("$\vec{v}$", unitvector(direction 3/4 of vv) rotated -90 scaled 7 shifted point 3/4 of vv); 
      label("$\vec{a}$", unitvector(direction 2/3 of aa) rotated +90 scaled 7 shifted point 2/3 of aa); 
      fill fullcircle scaled 5 shifted point p of C;
    endfor
    oo = subpath(3.4,4.2) of C scaled 1.12;
    drawarrow oo withpen pencircle scaled 4 withcolor Blues 8 3;
    label.lft("$\omega$", point 2/3 of oo);
endfig;
\end{mplibcode}
\end{document}
Thruston
  • 42,268