在 METAPOST 中使用 btex 和 etex 的乳膠標籤問題

在 METAPOST 中使用 btex 和 etex 的乳膠標籤問題

以下簡單的 METAPOST 程式碼編譯時不會出錯:

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;

日誌檔指出:

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

mpxerr 文件指出:

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

我很困惑。我檢查並重新檢查了程式碼,它似乎是正確的。編譯時調用正確的可執行檔(即 mpost.exe、latex.exe) 發生了什麼事?

我已閱讀此論壇中的相關問題並嘗試實施建議的解決方案。什麼都不起作用。

答案1

既然已經是 2022 年了,確實沒有必要%&latex再使用 Metapost 的古董通話了。舊的文檔和樣本確實都需要更新。

您在這裡有兩個選擇:

首先,如果您只是想簡單地嘗試一下mpost,並且並不真正關心與任何複雜的 LaTeX 格式的集成,那麼請替換您的序言,以便您的 MP 文件如下所示:

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;

如果您使用它進行編譯,mpost現在將在具有副檔名的檔案中建立封裝 PostScript 格式的輸出,您可以使用任何 PostScript 檢視器來檢視該輸出,或使用類似工具.eps將其製作為 PDF 。epstopdf

另一方面,如果您想以更現代的風格使用 MP,並在需要時使用所有有用的 LaTeX 格式,那麼請切換到 usinglualatexluamplib套件。像這樣:

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

編譯此文件lualatex可直接產生 PDF 檔案。

實際上,標籤有一個智慧選項,可以讓您完全擺脫繁瑣的btex ... etex機制。檢查 mplib textext 選項...

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

編譯它以lualatex獲得如下所示的 PDF:

在此輸入影像描述

您可以閱讀有關的(稀疏)文檔luamplib 這裡

相關內容