7

I've been experimenting with METAPOST and in particular with luamplib. I found that I couldn't have tex typeset labels with the btex/etex construct as apparently is possible with straight up METAPOST. After a little googling, I found that btex/etex can be made to work by using the files luatexkomplib.tex and the corresponding luatexkomplib.lua found here. My usage is as follows:

\documentclass{article}

\usepackage{pdftexcmds}

\makeatletter
\let\pdfescapename=\pdf@escapename
\let\pdfstrcmp=\pdf@strcmp
\input{luatexkomplib}
\makeatother

\begin{document}

\begin{mplibcode}

beginfig(1)
u=50;
draw fullcircle scaled u;
pickup pencircle scaled 2;
draw (u/2,0); draw(0,u/2); draw(-u/2,0); draw(0,-u/2);
label.rt(btex $\theta = 0$ etex scaled .5, (u/2,0));
label.top(btex $\theta = \displaystyle{\frac{\pi}{2}}$ etex scaled .5, (0,u/2));
label.lft(btex $\theta = \pi$ etex scaled .5, (-u/2,0));
label.bot(btex $\theta =\displaystyle{\frac{3\pi}{2}}$ etex scaled .5, (0,-u/2));
endfig;
end;

\end{mplibcode}
\end{document}

Which produces the expected circle with tex labelled points. My question is: do I break anything by using these two files rather than using the luamplib package? If not, then have I missed an updated luamplib package somewhere?

2 Answers 2

5

Had I looked a little harder on Google, I would have found the following "TODO" page on the luamplib GitHub:

  • use infwarerr and ltxcmds for Plain/LaTeX compat
  • use own verbatim env for LaTeX (à la luacode) yep, will be much better than working arround fancyvrb
  • make variants of mplibcode with \ { } still special?
    • actually, also make commands not changing the catcode as requested by Arno T.
  • expand doc?
  • synchronize with Context?
  • add a figure with mpfun in the test files

The following implement btex-etex commands: http://cvs.ktug.or.kr/viewcvs/ko.TeX/luatexko/luatexkomplib.tex http://cvs.ktug.or.kr/viewcvs/ko.TeX/luatexko/luatexkomplib.lua

Since these two files are mentioned as having implemented the btex/etex tags, I'll just assume that there is no problem with using them (and wonder why the package hasn't been updated to include them).

3

Two years and a half later, and since Dohyun Kim (author of the luatexkomplib files) maintains luamplib himself, the situation has much evolved in this domain. In particular, since version 2.0 (2013/05) it supports the btex…etex flags directly. So the following code is sufficient to produce the required figure, in the document's current fonts.

\documentclass{article}

\usepackage{luamplib}

\begin{document}

\begin{mplibcode}

beginfig(1)
u=50;
draw fullcircle scaled u;
pickup pencircle scaled 2;
draw (u/2,0); draw(0,u/2); draw(-u/2,0); draw(0,-u/2);
label.rt(btex $\theta = 0$ etex scaled .5, (u/2,0));
label.top(btex $\theta = \displaystyle{\frac{\pi}{2}}$ etex scaled .5, (0,u/2));
label.lft(btex $\theta = \pi$ etex scaled .5, (-u/2,0));
label.bot(btex $\theta =\displaystyle{\frac{3\pi}{2}}$ etex scaled .5, (0,-u/2));
endfig;
end;

\end{mplibcode}
\end{document}

enter image description here

Since version 2.03 (2013/12) luamplib even supports a textext macro similar to its ConTeXt's namesake. So the following code produces exactly the same output:

\documentclass{article}

\usepackage{luamplib}

\begin{document}

\begin{mplibcode}

beginfig(1)
u=50;
draw fullcircle scaled u;
pickup pencircle scaled 2;
draw (u/2,0); draw(0,u/2); draw(-u/2,0); draw(0,-u/2);
label.rt(textext("$\theta = 0$") scaled .5, (u/2,0));
label.top(textext("$\theta = \displaystyle{\frac{\pi}{2}}$") scaled .5, (0,u/2));
label.lft(textext("$\theta = \pi$") scaled .5, (-u/2,0));
label.bot(textext("$\theta =\displaystyle{\frac{3\pi}{2}}$") scaled .5, (0,-u/2));
endfig;

\end{mplibcode}
\end{document}

The main advantage of textext (or its synonym TEX) is that it allows to handle variable in labels much more easily. For example, the following code

\documentclass{article}
\usepackage{luamplib}
\begin{document}
  \begin{mplibcode}
    beginfig(1);
      for i = 1 upto 5:
        label(textext("$n_" & decimal i & "$"), (i*cm, 0));
      endfor
    endfig;
  \end{mplibcode}
\end{document}

produces this:

enter image description here

Even handier, since version 2.6.0 (2014/03) if you insert \mplibtextextlabel{enable} in preamble, each text of your labels (simply given as strings) will be typeset via textext automatically, and still in the document's current fonts. So the following code produces the same output as the one before.

\documentclass{article}
\usepackage{luamplib}
  \mplibtextextlabel{enable}
\begin{document}
  \begin{mplibcode}
    beginfig(1);
      for i = 1 upto 5:
        label("$n_" & decimal i & "$", (i*cm, 0));
      endfor
    endfig;
  \end{mplibcode}
\end{document}

See luamplib's documentation for (much) more informations.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .