0

The following simple METAPOST code does not compile without error:

verbatimtex
%&latex
\documentclass{article}
\begin{document}
etex
beginfig(1);
z0 = (0,0); z1 = (sqrt(3)*cm,0);
z2 = (sqrt(3)*cm,1cm);
draw z0--z1--z2--cycle;
label.bot(btex $w$ etex, 1/2[z0,z1]);
endfig;
end;

The log file states:

This is MetaPost, version 2.01 (MiKTeX 22.3)  14 APR 2022 17:40
Sample.mp Preloading the plain mem file, version 1.005) (./Sample.mp
>> Sample.mp
>> Sample.mpx
! ! Unable to read mpx file.
l.10 label.bot(btex
                $w$ etex, 1/2[z0,z1]);
The two files given above are one of your source files
and an auxiliary file I need to read to find out what your
btex..etex blocks mean. If you don't know why I had trouble,
try running it manually through MPtoTeX, TeX, and DVItoMP

The mpxerr file states:

This is mikTeX, Version 3.141592653 (MiKTeX 22.3) (preloaded format=tex 2022.4.14)  14 APR 
2022 
17:38
restricted \write18 enabled.
%&-line parsing enabled.
**./mp8HtMK1.tex
(mp8HtMK1.tex
! Undefined control sequence.
l.2 \documentclass
              {article}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
l.3 \begin
      {document}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

[1] [1] )
Output written on mp8HtMK1.dvi (2 pages, 340 bytes).

I am baffled. I have checked and re-checked the code and it seems to be correct. When compiling it is calling the correct executables (i.e. mpost.exe, latex.exe) What is happening?

I have read related questions in this forum and tried to implement the suggested solutions. Nothing works.

4
  • 3
    Not that it helps you, but your code works here (TeXLive 2022, linux). (Both running mpost and mptodpf work.)
    – mickep
    Commented Apr 14, 2022 at 22:17
  • 1
    The error says that MikTeX is using preloaded format=tex -- plain TeX instead of LaTex, which is why you are getting Undefined control sequence from the \begin{document}
    – Thruston
    Commented Apr 14, 2022 at 22:38
  • @Thruston Yes, indeed. That is what is most puzzling. I checked and it clearly should be using latex.exe. It is told to load latex by the editor. I also checked the paths within MikTeX and they all call the correct executable files. I have absolutely no idea why it is using tex.
    – John
    Commented Apr 14, 2022 at 23:26
  • @mickep In TeXLive it works like a charm. I assume then the problem is internal of the executable files within MikTeX? Thanks for your tip.
    – John
    Commented Apr 15, 2022 at 3:16

1 Answer 1

2

Since this is 2022, there is really no need to use the antique %&latex call with Metapost any more. The old documents and samples really all need to be updated.

You have two options here:

First, if you just want to try out plain mpost and you don't really care about integration with any complex LaTeX format, then replace your preamble so that your MP file looks like this:

prologues := 3;
outputtemplate := "%j%c.%{outputformat}";
beginfig(1);
z0 = (0,0); z1 = (sqrt(3)*cm,0);
z2 = (sqrt(3)*cm,1cm);
draw z0--z1--z2--cycle;
label.bot(btex $w$ etex, 1/2[z0,z1]);
endfig;
end;

if you compile this with mpost it will now create output in Encapsulated PostScript format in a file with an .eps extension, which you can view with any PostScript viewer or make into a PDF with epstopdf or similar tools.

On the other hand, if you would like to use MP in a more modern style, with all the useful LaTeX formatting if you need it, then switch to using lualatex and the luamplib package. Like this:

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\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 $w$ etex, 1/2[z0,z1]);
endfig;
\end{mplibcode}
\end{document}

Compile this with lualatex to produce a PDF file directly.

And actually there is a smart option for labels that lets you get rid of the cumbersome btex ... etex mechanism completely. Checkout the mplib textext option...

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable} % <---- extra option
\begin{mplibcode}
beginfig(1);
z0 = (0,0); z1 = (sqrt(3)*cm,0);
z2 = (sqrt(3)*cm,1cm);
draw z0--z1--z2--cycle;
label.bot("$w$", 1/2[z0,z1]);
endfig;
\end{mplibcode}
\end{document}

Compile this with lualatex to get a PDF that looks like this:

enter image description here

You can read the (sparse) documentation on luamplib here.

1
  • Thank you, Thurston. I appreciate the answer. I am aware that is 2022, and yet I have an important reason (important to me anyway) why I must find a way to properly compile files with such old code. The example is in itself irrelevant. I will try TeXLive, as -mickep pointed in the comment above.
    – John
    Commented Apr 14, 2022 at 23:18

You must log in to answer this question.

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