
次の単純な 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 年になったので、Metapost でアンティーク%&latex
コールを使用する必要はもうありません。古いドキュメントとサンプルはすべて更新する必要があります。
ここでは 2 つのオプションがあります。
まず、単にプレーンを試してみたいだけで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
を持つファイルに Encapsulated PostScript 形式の出力が作成され、任意の PostScript ビューアで表示したり、または同様のツールを.eps
使用して PDF に変換したりできます。epstopdf
一方、必要に応じて便利な LaTeX フォーマットをすべて使用して、より現代的なスタイルで MP を使用したい場合は、パッケージの使用に切り替えますlualatex
。luamplib
次のようになります。
\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
ここ。