考试类中带有 mfpic 的空白框

考试类中带有 mfpic 的空白框

我正在编写一个要使用的文档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"

相关内容