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