1

I'm working on a document that uses mfpicand would like to compile without having to do mpost every time.

I tried to use the code given in this post, but have been unsuccessful.

MWE:

\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}
  • You need two runs of LaTeX with the -shell-escape option active. – egreg Feb 16 at 0:43
  • @egreg I’m using LaTeXmk. Shouldn’t that already be taken care of – Michael Link Feb 16 at 0:43
  • No idea, sorry. For a short period, mpost had been in the “safe list” for being run even without shell-escape active. It seems that a “restricted version” of mpost will be available with TL 2019. Anyway, look for shell-escape in the documentation of latexmk. It should also be possible to make it run metapost by itself. – egreg Feb 16 at 0:52
0

For what it's worth, to get the triple compilation (latex+mpost+latex) in one stroke, I use the following shell script on my Mac OS X system, through the command line as well as through the TeXShop graphic interface (via the Engines feature, for those who use TeXShop). This kind of script should work on any Unix system. It certainly needs to be adapted on others.

#!/bin/tcsh

set filename = "$1"
set mpname = "${filename:r}.mp"

pdflatex --shell-escape -synctex=1 "$filename"
mpost "$mpname"
pdflatex --shell-escape -synctex=1 "$filename"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.