![考试类中带有 mfpic 的空白框](https://linux22.com/image/390656/%E8%80%83%E8%AF%95%E7%B1%BB%E4%B8%AD%E5%B8%A6%E6%9C%89%20mfpic%20%E7%9A%84%E7%A9%BA%E7%99%BD%E6%A1%86.png)
我正在编写一个要使用的文档mfpic
,并且希望无需mpost
每次都进行编译。
我尝试使用给出的代码这个帖子,但均未成功。
梅威瑟:
\documentclass{exam}
\usepackage{etoolbox}
\usepackage[metapost]{mfpic}
\title{College Algebra \\ Relations Worksheet}
\date{Feb 17, 2019}
\opengraphsfile{RelationsQuiz}
\makeatletter
\patchcmd{\mfp@closegraphsfile}
{\global}
{\immediate\write18{mpost \mfp@filename}\global}
{}{}
\makeatother
\begin{document}
\begin{questions}
\question Text here
\begin{mfpic}[15]{-5}{5}{-2}{5}
\point[4pt]{(-4, 3), (-3, 2), (-3, 4), (0, -1), (2, 3), (4, 0)}
\axes
\tlabel[cc](5,-0.5){$x$}
\tlabel[cc](0.5,5){$y$}
\xmarks{-4,-3,-2,-1,1,2,3,4}
\ymarks{-1,1,2,3,4}
\tlpointsep{5pt}
\scriptsize
\axislabels {x}{{$-4 \hspace{7pt}$} -4, {$-3 \hspace{7pt}$} -3, {$-2 \hspace{7pt}$} -2, {$-1 \hspace{7pt}$} -1, {$1$} 1, {$2$} 2, {$3$} 3, {$4$} 4}
\axislabels {y}{{$-1$} -1, {$1$} 1, {$2$} 2, {$3$} 3, {$4$} 4}
\end{mfpic}
\question \begin{mfpic}[15]{-4}{4}{-4}{4}
\hatchcolor[gray]{.7}
\lhatch \rect{(2,-4), (-3.75,1)}
\axes
\arrow \dashed \polyline{(2,1), (2,-4)}
\arrow \polyline{(2,1), (-4,1)}
\gclear \circle{(2,1),0.1}
\circle{(2,1),0.1}
\tlabel[cc](4,-0.5){$x$}
\tlabel[cc](0.5,4){$y$}
\xmarks{-3,-2,-1,1,2,3}
\ymarks{-3,-2,-1,1,2,3}
\tlpointsep{5pt}
\scriptsize
\axislabels {x}{{$-3 \hspace{7pt}$} -3,{$-2 \hspace{7pt}$} -2,{$-1 \hspace{7pt}$} -1,{$1$} 1,{$2$} 2,{$3$} 3}
\axislabels {y}{ {$-3$} -3,{$-2$} -2, {$-1$} -1, {$1$} 1, {$2$} 2, {$3$} 3}
\normalsize
\end{mfpic}
\end{questions}
\closegraphsfile
\end{document}
答案1
您可以将对 的调用更改mpost
为对 的调用r-mpost
,这是 的受限版本,mpost
允许使用受限 shell-escape 运行,并且对于 而言已经足够mfpic
。
如今,我希望不用 就能做到这一点\patchcmd
,但不幸的是,mfpic
它没有为此提供合理的解决方案。shellesc
建议使用 而不是\immediate\write18
。
\documentclass{exam}
\usepackage[metapost]{mfpic}
\usepackage{shellesc}
\usepackage{etoolbox}
\title{College Algebra \\ Relations Worksheet}
\date{Feb 17, 2019}
\opengraphsfile{\jobname-mfpic}% just not to clobber my files
\makeatletter
\patchcmd{\mfp@closegraphsfile}
{\immediate\closeout\mfp@out}
{\immediate\closeout\mfp@out\ShellEscape{r-mpost \mfp@filename}}
{}{}
\makeatother
\begin{document}
\begin{questions}
\question Text here
\begin{mfpic}[15]{-5}{5}{-2}{5}
\point[4pt]{(-4, 3), (-3, 2), (-3, 4), (0, -1), (2, 3), (4, 0)}
\axes
\tlabel[cc](5,-0.5){$x$}
\tlabel[cc](0.5,5){$y$}
\xmarks{-4,-3,-2,-1,1,2,3,4}
\ymarks{-1,1,2,3,4}
\tlpointsep{5pt}
\scriptsize
\axislabels {x}{{$-4 \hspace{7pt}$} -4, {$-3 \hspace{7pt}$} -3, {$-2 \hspace{7pt}$} -2,
{$-1 \hspace{7pt}$} -1, {$1$} 1, {$2$} 2, {$3$} 3, {$4$} 4}
\axislabels {y}{{$-1$} -1, {$1$} 1, {$2$} 2, {$3$} 3, {$4$} 4}
\end{mfpic}
\question \begin{mfpic}[15]{-4}{4}{-4}{4}
\hatchcolor[gray]{.7}
\lhatch \rect{(2,-4), (-3.75,1)}
\axes
\arrow \dashed \polyline{(2,1), (2,-4)}
\arrow \polyline{(2,1), (-4,1)}
\gclear \circle{(2,1),0.1}
\circle{(2,1),0.1}
\tlabel[cc](4,-0.5){$x$}
\tlabel[cc](0.5,4){$y$}
\xmarks{-3,-2,-1,1,2,3}
\ymarks{-3,-2,-1,1,2,3}
\tlpointsep{5pt}
\scriptsize
\axislabels {x}{{$-3 \hspace{7pt}$} -3,{$-2 \hspace{7pt}$} -2,
{$-1 \hspace{7pt}$} -1,{$1$} 1,{$2$} 2,{$3$} 3}
\axislabels {y}{ {$-3$} -3,{$-2$} -2, {$-1$} -1, {$1$} 1, {$2$} 2, {$3$} 3}
\normalsize
\end{mfpic}
\end{questions}
\closegraphsfile
\end{document}
答案2
值得一提的是,为了一次性完成三重编译(latex+mpost+latex),我在 Mac OS X 系统上使用以下 shell 脚本,通过命令行以及 TeXShop 图形界面(Engines
对于使用 TeXShop 的用户,通过该功能)。这种脚本应该适用于任何 Unix 系统。当然,它需要在其他系统上进行调整。
#!/bin/tcsh
set filename = "$1"
set mpname = "${filename:r}.mp"
pdflatex --shell-escape -synctex=1 "$filename"
mpost "$mpname"
pdflatex --shell-escape -synctex=1 "$filename"