Using metapost figures in context
Hi, Does there exist a startstop command (say startMPfigure) for managing figures drawn using MP such that 1. I can use \startMPfigure{label} ...... \stopMPfigure and then use \useexternalMPfigure{label} to include the figure. 2. The figures are converted into pdf once. If the code inside \startstop MPfigures changes, the pdf for each figure is recreated. Basically, I want MPfigures to be converted into pdf for faster inclusion in the main document, the figure should be recompiled if necessary and I should be able to include the figure using a label (so that I can separate the figures from the main document). uniqueMPgraphic provides the first functionality, but the figure is converted into pdf on runtime (thereby increasing the processing time of the document). I can use a separate document with each figure inside a \startMPpage ... \stopMPpage, but (i) I need to remember figure numbers manually, (ii) after making change in one figure, the whole file needs to be recompiled. Another possibility is to use one tex file for each figure, compile them separately and then then use figure library to get a "label" for each figure. But this becomes difficult to manage, as soon as I get large number of files. Is their something basic that I am missing here? How do others manage mpfigures? To Hans: is it possible to have a \startMPfigure command such that 1. \startMPfigure[label] figure code \stopMPfigure creates a \jobname-figure-\nofMPfigurefile file with current MP environment current MP inclusion figure code (from inside \startstop MPfigure) Convert this into \jobname-figure-\nofMPfigurefile.pdf only if something changes (similar to what is done in m-r module). 2. The resultant pdf can be included using \useMPfigure{label}. Would such a feature make sense? Aditya
Aditya Mahajan wrote:
Hi,
Does there exist a startstop command (say startMPfigure) for managing figures drawn using MP such that
1. I can use \startMPfigure{label} ...... \stopMPfigure and then use \useexternalMPfigure{label} to include the figure.
grep for \startMPrun .. \stopMPrun
2. The figures are converted into pdf once. If the code inside \startstop MPfigures changes, the pdf for each figure is recreated.
Basically, I want MPfigures to be converted into pdf for faster inclusion in the main document, the figure should be recompiled if necessary and I should be able to include the figure using a label (so that I can separate the figures from the main document).
you can use the figure database mechanism (davids arnold does that) or make individual files, say 'thatfile.tex' \starttext \startMPpage fill fullcircle scaled 10cm; \stopMPpage \stoptext and then in test.tex say: \def\MyMpgraphic[#1]% {\executesystemcommand{texmfstart --ifchanged=#1.tex texexec #1.tex} \externalfigure[#1.pdf]} \starttext \MyMpgraphic[thatfile] \MyMpgraphic[thatfile][width=3cm] \stoptext (you need a version of texmfstart that provided the -ifchanged)
uniqueMPgraphic provides the first functionality, but the figure is converted into pdf on runtime (thereby increasing the processing time of the document).
expect this to be sped up later this year (neglectable)
I can use a separate document with each figure inside a \startMPpage ... \stopMPpage, but (i) I need to remember figure numbers manually, (ii) after making change in one figure, the whole file needs to be recompiled.
so who not filenames like whateverprefix-somelabel
Another possibility is to use one tex file for each figure, compile them separately and then then use figure library to get a "label" for each figure. But this becomes difficult to manage, as soon as I get large number of files.
Is their something basic that I am missing here? How do others manage mpfigures?
To Hans: is it possible to have a \startMPfigure command such that
1. \startMPfigure[label] figure code \stopMPfigure
creates a \jobname-figure-\nofMPfigurefile file with
current MP environment current MP inclusion figure code (from inside \startstop MPfigure)
Convert this into \jobname-figure-\nofMPfigurefile.pdf only if something changes (similar to what is done in m-r module).
see prev example for a starter
2. The resultant pdf can be included using \useMPfigure{label}.
Would such a feature make sense?
would be a different command remind me later this week Hans -- ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Mon, 12 Jun 2006, Hans Hagen wrote:
Aditya Mahajan wrote:
Hi,
Does there exist a startstop command (say startMPfigure) for managing figures drawn using MP such that
1. I can use \startMPfigure{label} ...... \stopMPfigure and then use \useexternalMPfigure{label} to include the figure.
grep for \startMPrun .. \stopMPrun
Thanks! This was almost what I needed.
2. The figures are converted into pdf once. If the code inside \startstop MPfigures changes, the pdf for each figure is recreated.
Basically, I want MPfigures to be converted into pdf for faster inclusion in the main document, the figure should be recompiled if necessary and I should be able to include the figure using a label (so that I can separate the figures from the main document).
you can use the figure database mechanism (davids arnold does that)
or make individual files, say 'thatfile.tex'
\starttext \startMPpage fill fullcircle scaled 10cm; \stopMPpage \stoptext
and then in test.tex say:
\def\MyMpgraphic[#1]% {\executesystemcommand{texmfstart --ifchanged=#1.tex texexec #1.tex} \externalfigure[#1.pdf]}
\starttext
\MyMpgraphic[thatfile]
\MyMpgraphic[thatfile][width=3cm]
\stoptext
(you need a version of texmfstart that provided the -ifchanged)
I have a simple version using this idea that is working. See at the end.
uniqueMPgraphic provides the first functionality, but the figure is converted into pdf on runtime (thereby increasing the processing time of the document).
expect this to be sped up later this year (neglectable)
I can use a separate document with each figure inside a \startMPpage ... \stopMPpage, but (i) I need to remember figure numbers manually, (ii) after making change in one figure, the whole file needs to be recompiled.
so who not filenames like whateverprefix-somelabel
Did not think of that. Was too busy trying to figure out how to do number to label mapping :)
Another possibility is to use one tex file for each figure, compile them separately and then then use figure library to get a "label" for each figure. But this becomes difficult to manage, as soon as I get large number of files.
Is their something basic that I am missing here? How do others manage mpfigures?
To Hans: is it possible to have a \startMPfigure command such that
1. \startMPfigure[label] figure code \stopMPfigure
creates a \jobname-figure-\nofMPfigurefile file with
current MP environment current MP inclusion figure code (from inside \startstop MPfigure)
Convert this into \jobname-figure-\nofMPfigurefile.pdf only if something changes (similar to what is done in m-r module).
see prev example for a starter
2. The resultant pdf can be included using \useMPfigure{label}.
Would such a feature make sense?
would be a different command
I have right now kept the command as MPfigure. The following works, but I can not figure out 1. How to force texexec to give pdf output from an mp file. Do I need to start another mptopdf process? 2. How to get textext to work? 3. I needed to set randomseed to false. Does this have any drawbacks? supp-mps.tex says that this feature is optional. Does metapost have a good random seed initializer now? \def\startMPfigure#1#2\stopMPfigure {\bgroup \setMPrandomseedfalse %Otherwise randomseed := number line always differ % \forceMPTEXgraphictrue %Does not work \def\executeMPOST##1% {texmfstart --verbose --ifchanged=##1.mp bin:mpost \ifcase\interactionmode\MPOSTbatchswitch\or\MPOSTnonstopswitch\fi \space\ifuseMETAFUNformat \MPOSTformatswitch metafun \fi ##1} \def\executeMPTEX##1% slower, due to nested texexec call {texmfstart --verbose --ifchanged=##1.mp texexec --batch \ifcase\interactionmode --logfile='mptex.log' \fi --output=\MPOSTdriver\space \ifuseMETAFUNformat --mpformat=metafun \fi --mptex --nomp --once ##1} \startMPrun{\jobname-#1} beginfig(1) #2 endfig; \stopMPrun\egroup} \def\useMPfigure{\dosingleempty\douseMPfigure} \def\douseMPfigure[#1]% {\externalfigure[\jobname-#1.1]} \starttext \startMPfigure{circle} fill fullcircle scaled 10cm; \stopMPfigure \startMPfigure{axis} drawarrow (0,0)--(1cm,0) ; drawarrow (0,0)--(0,1cm) ; label.llft(btex (0,0) etex,origin) ; \stopMPfigure \hbox to \hsize \bgroup \hss \useMPfigure[circle][width=1cm] \hss \useMPfigure[axis] \hss \egroup \stoptext Aditya
On Mon, 12 Jun 2006, Aditya Mahajan wrote:
2. How to get textext to work?
startMPrun not check for textext. Consider % \forceMPTEXgraphictrue % Does not make a difference! \starttext \startMPrun{testmp} beginfig(1) drawarrow (0,0)--(1cm,0) ; drawarrow (0,0)--(0,1cm) ; label.llft(textext("(0,0)"),origin) ; endfig; \stopMPrun \externalfigure[testmp.1] \stoptext which gives the dreaded "unknown" string, while \starttext \startMPgraphic beginfig(1) drawarrow (0,0)--(1cm,0) ; drawarrow (0,0)--(0,1cm) ; label.llft(textext("(0,0)"),origin) ; endfig; \stopMPgraphic \externalfigure[\jobname-mpgraph.1] \stoptext works. I can get my previous macro to work for textext using startMPgraphic. \def\startMPfigure#1#2\stopMPfigure {\bgroup \setMPrandomseedfalse %Otherwise randomseed := number line always differ \def\executeMPOST##1% {texmfstart --verbose --ifchanged=##1.mp bin:mpost \ifcase\interactionmode\MPOSTbatchswitch\or\MPOSTnonstopswitch\fi \space\ifuseMETAFUNformat \MPOSTformatswitch metafun \fi ##1} \def\executeMPTEX##1% slower, due to nested texexec call {texmfstart --verbose --ifchanged=##1.mp texexec --batch \ifcase\interactionmode --logfile='mptex.log' \fi --output=\MPOSTdriver\space \ifuseMETAFUNformat --mpformat=metafun \fi --mptex --nomp --once ##1} \def\MPgraphicfile{\jobname-#1} \newcount\currentMPgraphic \startMPgraphic #2 \stopMPgraphic\egroup\deallocateMPslot\currentMPgraphic} \def\useMPfigure{\dosingleempty\douseMPfigure} \def\douseMPfigure[#1]% {\externalfigure[\jobname-#1.1]} \starttext \startMPfigure{circle} fill fullcircle scaled 10cm; \stopMPfigure \startMPfigure{axis} drawarrow (0,0)--(1cm,0) ; drawarrow (0,0)--(0,1cm) ; label.llft(textext("(0,0)") ,origin) ; \stopMPfigure \hbox to \hsize \bgroup \hss \useMPfigure[circle][width=1cm] \hss \useMPfigure[axis] \hss \egroup \stoptext Right now I have a big speed improvement as metapost is not executed each time. I only need to convert the mps files to pdf to save a bit on pdf conversion. Aditya
Aditya Mahajan wrote:
I have right now kept the command as MPfigure.
grep MPfigure in meta-fig -) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Tue, 13 Jun 2006, Hans Hagen wrote:
Aditya Mahajan wrote:
I have right now kept the command as MPfigure.
grep MPfigure in meta-fig -)
Now I am using staticMPfigure. This is the final version \def\startstaticMPfigure#1#2\stopstaticMPfigure {\bgroup \setMPrandomseedfalse %Otherwise randomseed := number line always differ \doifmodeelse{*pdf} {\def\executeMPTEX##1% {texmfstart --verbose --ifchanged=##1.mp texexec --mpgraphic ##1.mp} \let\executeMPOST=\executeMPTEX} {\def\executeMPOST##1% {texmfstart --verbose --ifchanged=##1.mp bin:mpost \ifcase\interactionmode\MPOSTbatchswitch\or\MPOSTnonstopswitch\fi \space\ifuseMETAFUNformat \MPOSTformatswitch metafun \fi ##1} \def\executeMPTEX##1% slower, due to nested texexec call {texmfstart --verbose --ifchanged=##1.mp texexec --batch \ifcase\interactionmode --logfile='mptex.log' \fi --output=\MPOSTdriver\space \ifuseMETAFUNformat --mpformat=metafun \fi --mptex --nomp --once ##1}} \def\MPgraphicfile{\jobname-#1} \newcount\currentMPgraphic \startMPgraphic #2 \stopMPgraphic\egroup\deallocateMPslot\currentMPgraphic} \def\usestaticMPfigure{\dosingleempty\dousestaticMPfigure} \def\dousestaticMPfigure[#1]% {\doifmodeelse{*pdf} {\externalfigure[\jobname-#1.pdf]} {\externalfigure[\jobname-#1.1]}} \starttext \startstaticMPfigure{circle} fill fullcircle scaled 10cm; \stopstaticMPfigure \startstaticMPfigure{axis} drawarrow (0,0)--(1cm,0) ; drawarrow (0,0)--(0,1cm) ; label.llft(textext("(0,0)") ,origin) ; \stopstaticMPfigure \hbox to \hsize \bgroup \hss \usestaticMPfigure[circle][width=1cm] \hss \usestaticMPfigure[axis] \hss \egroup \stoptext Thanks, Aditya
Aditya Mahajan wrote:
n lines deleted
I added to texexec: texexec --mpgraphic somefile.mp which will run mp and make a pdf file. when more graphics are in the file, names become somefile-1.pdf etc one can always say: \useexternalfigure[whatever][somefile-123.pdf] to have more symbolic names Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (2)
-
Aditya Mahajan
-
Hans Hagen