1

I want to use verbatimtex in metapost and compile it in lualatex. Followed is a small code. But it failed. I have googled and added verbatimtex block here and there but no lucky. Please help. Thank you.

\RequirePackage{luatex85}
verbatimtex
%&latex
\documentclass{article}
\usepackage{luamplib}
\mplibtextextlabel{enable}
\begin{document}
etex

\begin{mplibcode}

beginfig(1);
z0 = (0,0); z1 = (sqrt(3)*cm,0);
z2 = (sqrt(3)*cm,1cm);
draw z0--z1--z2--cycle;
label.bot(btex $\sqrt{3}$ etex, 1/2[z0,z1]);
label.rt(btex $\frac{1}{2}$ etex, 1/2[z1,z2]);
label.top(btex 1 etex, 1/2[z0,z2]);
endfig;
\end{mplibcode}

verbatimtex
\end{document}
etex
end;
2

MetaPost is already integrated in Lua(La)TeX, so in most cases, verbatimtex… etex is useless. You might want to use it though if you want your pictures centered, flushed left or right and so on, to insert before each picture the \leavevmode command necessary to do that.

See below, and the luamplib documentation for more details, especially page 2.

%\RequirePackage{luatex85} % Needed mostly for the standalone class
\documentclass{article}
\usepackage{luamplib}
    %\mplibtextextlabel{enable} % Not needed here since you use btex… etex
    \everymplib{verbatimtex \leavevmode etex; beginfig(1);}
    \everyendmplib{endfig;}
\begin{document}
Here is a picture:
\begin{center}
  \begin{mplibcode}
    z0 = (0,0); z1 = (sqrt(3)*cm,0);
    z2 = (sqrt(3)*cm,1cm);
    draw z0--z1--z2--cycle;
    label.bot(btex $\sqrt{3}$ etex, 1/2[z0,z1]);
    label.rt(btex $\frac{1}{2}$ etex, 1/2[z1,z2]);
    label.top(btex 1 etex, 1/2[z0,z2]);
  \end{mplibcode}
\end{center}
\end{document}

enter image description here

  • Thank you Franck. To be honest, I have read the luamplib documentation before I asked this question. But due to my English ability and not familiar to lualatex, I was lost. Thanks again. – warem Oct 26 '17 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.