metapost作图宏包mpgraphics的自动重命名
我们希望mpgraphics可以自动重命名,并将图的标题改为该重命名。可以这样实现:
\makeatletter
\NewDocumentEnvironment{mpfig}{m}{%
\stepcounter{mpgfig}%
\xdef\MPGCutFile{\mpgfigname.mp}
\MPGverbatimwrite{\MPGCutFile}
}{
\endMPGverbatimwrite%
\MPGgraphicsinclude%
\IfFileExists{\mpgfigname.\[email protected]}{%
\immediate\write18{cp "\mpgfigname.\[email protected]" "img/#1.\[email protected]"}%
{\begin{center} \thempgfig:#1 \end{center}}%
}{
\csname @[email protected]@\[email protected] true\endcsname
}
\global\@[email protected]\noindent%
}
\makeatother
添加上述代码到preamble区域。然后可以这样使用
\begin{mpfig}{a-circle}
draw fullcircle scaled 100pt;
\end{mpfig}
则可以重命名生成的文件到`img/`目录下(需要自己创建), 请用pdflatex编译。