Problema con etiquetas de látex usando btex y etex en METAPOST

Problema con etiquetas de látex usando btex y etex en METAPOST

El siguiente código METAPOST simple no se compila sin errores:

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;

El archivo de registro dice:

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

El archivo mpxerr dice:

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).

Estoy desconcertado. Revisé y volví a verificar el código y parece ser correcto. Al compilar, llama a los ejecutables correctos (es decir, mpost.exe, latex.exe). ¿Qué está pasando?

Leí preguntas relacionadas en este foro y traté de implementar las soluciones sugeridas. Nada funciona.

Respuesta1

Dado que estamos en 2022, ya no es necesario utilizar la %&latexllamada antigua con Metapost. Realmente es necesario actualizar todos los documentos y muestras antiguos.

Tienes dos opciones aquí:

Primero, si solo desea probar mposty realmente no le importa la integración con ningún formato LaTeX complejo, reemplace su preámbulo para que su archivo MP se vea así:

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;

si compila esto con mpostél, ahora creará una salida en formato PostScript encapsulado en un archivo con una .epsextensión, que puede ver con cualquier visor PostScript o convertirlo en un PDF con epstopdfherramientas similares.

Por otro lado, si desea utilizar MP en un estilo más moderno, con todo el formato LaTeX útil si lo necesita, cambie a usar lualatexy el luamplibpaquete. Como esto:

\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}

Compílelo con lualatexpara producir un archivo PDF directamente.

Y, de hecho, existe una opción inteligente para las etiquetas que le permite deshacerse btex ... etexpor completo del engorroso mecanismo. Consulte la opción de texto de texto mplib...

\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 esto con lualatexpara obtener un PDF similar a este:

ingrese la descripción de la imagen aquí

Puede leer la (escasa) documentación enluamplib aquí.

información relacionada