summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/supp-mps.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/supp-mps.tex')
-rw-r--r--Master/texmf-dist/tex/context/base/supp-mps.tex342
1 files changed, 249 insertions, 93 deletions
diff --git a/Master/texmf-dist/tex/context/base/supp-mps.tex b/Master/texmf-dist/tex/context/base/supp-mps.tex
index 23e6ccc89d9..17d26d631ca 100644
--- a/Master/texmf-dist/tex/context/base/supp-mps.tex
+++ b/Master/texmf-dist/tex/context/base/supp-mps.tex
@@ -50,6 +50,8 @@
\bgroup \catcode`\%=\@@other \xdef\letterpercent{\string%} \egroup
+% todo : sort out ^^M, \par and ; mess
+
%D \macros
%D {startMPgraphic}
%D
@@ -196,24 +198,111 @@
%D passing them to \type{\MPinclusions}:
%D
%D \starttyping
+%D \startMPinclusions
+%D input mp-mine ;
+%D \stopMPinclusions
+%D \stoptyping
+%D
+%D \starttyping
%D \MPinclusions{input mp-mine}
%D \stoptyping
%D
+%D These commands reset their content each time. You can append
+%D code as follows:
+%D
+%D \starttyping
+%D \startMPinclusions[+]
+%D input mp-mine ;
+%D \stopMPinclusions
+%D \stoptyping
+%D
%D The token register \type {\MPinitializations} is expanded
%D before all other inclusions, the extensions are expanded
%D only once per run.
-\newtoks \MPinitializations % each graphic
+%D The next hack prevents too long lines:
+
+\long\def\runtimeobeyMPlines
+ {\ifx\rawcharacter\undefined
+ \let\obeyedline\space
+ \else
+ \obeylines
+ \ifx\systemendofline\undefined
+ \def\obeyedline{\rawcharacter{10}}%
+ \else
+ \let\obeyedline\systemendofline
+ \fi
+ \fi}
+
+\long\def\obeyMPlines % anyhow, we end up with ^^M's in the input
+ {\obeylines
+ \let\obeyedline\relax} % delay expansion
+
+\ifx\everydump\undefined
+ % maybe we're not using context
+\else
+ \appendtoks
+ \let\obeyMPlines\runtimeobeyMPlines
+ \to \everydump
+\fi
+
+%D We use two distinguished token registers:
+
\newtoks \MPextensions % once per run (can be multiple graphics)
+\newtoks \MPinitializations % each graphic
+
+\let\stopMPextensions \relax % so that we can use it in \expanded
+\let\stopMPinitializations\relax % so that we can use it in \expanded
+\let\stopMPinclusions \relax % so that we can use it in \expanded
+
+\def\startMPextensions % no text checking done here !
+ {\begingroup
+ \obeyMPlines
+ \dostartMPextensions}
+
+\def\dostartMPextensions#1\stopMPextensions
+ {\endgroup
+ \MPextensions\expandafter{\the\MPextensions#1}}
-\long\def\startMPinclusions#1\stopMPinclusions % document wide
- {\long\def\theMPinclusions
- {% \expanded !
- \@EA\expanded\@EA{\@EA\writeMPgraphic\@EA{\the\MPextensions;}}% new
- \writeMPgraphic{#1}}}
+\def\startMPinitializations % no text checking done here !
+ {\begingroup
+ \obeyMPlines
+ \dostartMPinitializations}
-\long\def\MPinclusions#1%
- {\startMPinclusions#1\stopMPinclusions}
+\def\dostartMPinitializations#1\stopMPinitializations
+ {\endgroup
+ \MPinitializations\expandafter{\the\MPinitializations#1}}
+
+\def\startMPinclusions
+ {\begingroup
+ \dosingleempty\dostartMPinclusions}
+
+\long\def\dostartMPinclusions
+ {\obeyMPlines
+ \dodostartMPinclusions}
+
+\long\def\dodostartMPinclusions[#1]#2\stopMPinclusions % document wide
+ {\endgroup
+ \doifelse{#1}{+}
+ {\@EA\long\@EA\def\@EA\theMPinclusions\@EA
+ {\theMPinclusions
+ \writeMPgraphic{#2}}}
+ {\long\def\theMPinclusions
+ {% \expanded !
+% \@EA\expanded\@EA{\@EA\writeMPgraphic\@EA{\the\MPextensions;}}% new
+ \writeMPgraphic{#2}}}}
+
+\def\MPinclusions
+ {\dosingleempty\doMPinclusions}
+
+\long\def\doMPinclusions[#1]#2%
+ {\startMPinclusions[#1]#2\stopMPinclusions}
+
+\def\theMPextensions
+ {\@EA\expanded\@EA{\@EA\writeMPgraphic\@EA{\the\MPextensions;}}}
+
+\def\theMPinitializations
+ {\@EA\expanded\@EA{\@EA\writeMPgraphic\@EA{\the\MPinitializations;}}}
\startMPinclusions \stopMPinclusions
@@ -227,7 +316,7 @@
\newwrite\MPwrite
-\newif\iflongMPlines
+\newif\iflongMPlines \longMPlinestrue % we now have \obeyMPlines
\ifx \overlaywidth \undefined \def \overlaywidth {4cm} \fi
\ifx \overlayheight \undefined \def \overlayheight {3cm} \fi
@@ -327,7 +416,8 @@
\bgroup
\let\par\space
\iflongMPlines
- \immediate\write\MPwrite{#1;}%
+ %\immediate\write\MPwrite{#1;}% oeps, ; invalid
+ \immediate\write\MPwrite{#1}%
\else
\long\edef\ascii{#1}%
\expandafter\flushMPgraphicline\ascii\empty;\relax;%
@@ -394,16 +484,27 @@
% \the\MPTEXgraphicchecks\relax % \relax is end condition!
% \fi}
+% \long\def\writecheckedMPgraphic#1%
+% {\ifforceMPTEXgraphic
+% \global\MPTEXgraphictrue
+% \else
+% \global\MPTEXgraphicfalse
+% \expandafter\convertargument#1\to\MPascii
+% \the\MPTEXgraphicchecks\relax % \relax is end condition!
+% \fi
+% \flushMPTEXgraphic % verbatimtex etc
+% \writeMPgraphic{#1}}
+
\long\def\writecheckedMPgraphic#1%
{\ifforceMPTEXgraphic
\global\MPTEXgraphictrue
\else
\global\MPTEXgraphicfalse
- \expandafter\convertargument#1\to\MPascii
+ \edef\ascii{#1}\convertcommand\ascii\to\MPascii
\the\MPTEXgraphicchecks\relax % \relax is end condition!
\fi
\flushMPTEXgraphic % verbatimtex etc
- \writeMPgraphic{#1}}
+ \writeMPgraphic{#1}} % potential optimization: pass \ascii
%D We could have used a kind of array approach using a
%D counter appended to \type {MPascii}, but this is an
@@ -434,6 +535,18 @@
%D \stopMPcode
%D \stoptyping
+%D A goodie for Mojca (the gnuplot wizzard):
+%D
+%D \starttyping
+%D \startMPcode
+%D draw fullcircle scaled 4cm ;
+%D draw \textext{$\sqrt{\frac{3}{2}^3}$} ;
+%D \stopMPcode
+%D \stoptyping
+
+\long\def\textext#1{\normalunexpanded{textext("#1")}} % or \detokenize
+
+
\def\flushMPTEXgraphic
{\ifMPTEXgraphic
\immediate\write\MPwrite{verbatimtex \the\everyMPTEXgraphic\space etex;}%
@@ -536,6 +649,17 @@
\let \} \letterclosebrace
\to \everyMPgraphic
+%D Not the best place but we need to make sure that no funny
+%D active characters creep in. Some day we will move this code.
+
+\ifx\disablediscretionaries\undefined
+ \let\disablediscretionaries\relax
+\fi
+
+\appendtoks
+ \disablediscretionaries
+\to \everyMPgraphic
+
\def\writeMPgraph
{\immediate\write\MPwrite{mpgraph:=\the\currentMPgraphic;}}
@@ -546,64 +670,6 @@
\fi
\endTEX
-% buggy (at least in collected graphics, lazy expansion)
-%
-% \def\startwritingMPgraphic
-% {\blabelgroup
-% \global\advance\nofMPgraphics 1
-% \ifMPrun \else
-% \allocateMPslot\currentMPgraphic
-% \fi
-% \enableincludeMPgraphics
-% \xdef\MPgraphic{\the\currentMPgraphic}%
-% \the\everyMPgraphic
-% \ifrunMPgraphics
-% \openMPgraphicfile1{runtime}%
-% % no reset here !
-% \theMPinclusions
-% \else
-% \openMPgraphicfile0{collected}%
-% % reset here ! global added (due to adding \blabelgroup)
-% \theMPinclusions
-% \global\let\theMPinclusions\relax
-% \fi
-% \flushMPTEXgraphic
-% \ifMPrun \else
-% \immediate\write\MPwrite{let mprunend = end ;}%
-% \immediate\write\MPwrite{beginfig(\the\currentMPgraphic);}%
-% \fi
-% \globallet\flushMPgraphics\closeMPgraphicfiles % \dodostopwritingMPgraphic
-% \globallet\stopwritingMPgraphic=\dostopwritingMPgraphic}
-
-% \def\startwritingMPgraphic
-% {\blabelgroup
-% \global\advance\nofMPgraphics 1
-% \ifMPrun \else
-% \allocateMPslot\currentMPgraphic
-% \fi
-% \enableincludeMPgraphics
-% \xdef\MPgraphic{\the\currentMPgraphic}%
-% \the\everyMPgraphic
-% \ifrunMPgraphics
-% \openMPgraphicfile1{runtime}%
-% % no reset here !
-% \theMPinclusions
-% \@EA\expanded\@EA{\@EA\writeMPgraphic\@EA{\the\MPinitializations;}}%
-% \else
-% \openMPgraphicfile0{collected}%
-% % reset here ! global added (due to adding \blabelgroup)
-% \theMPinclusions
-% \global\let\theMPinclusions\relax
-% \fi
-% \flushMPTEXgraphic
-% \ifMPrun \else
-% \immediate\write\MPwrite{let mprunend = end ;}%
-% \immediate\write\MPwrite{beginfig(\the\currentMPgraphic);}%
-% \@EA\expanded\@EA{\@EA\writeMPgraphic\@EA{\the\MPinitializations;}}%
-% \fi
-% \globallet\flushMPgraphics\closeMPgraphicfiles % \dodostopwritingMPgraphic
-% \globallet\stopwritingMPgraphic=\dostopwritingMPgraphic}
-
\def\startwritingMPgraphic
{\blabelgroup
@@ -618,21 +684,26 @@
\ifrunMPgraphics
\openMPgraphicfile1{runtime}%
% no reset here !
+ \theMPextensions
\theMPinclusions
- \@EA\expanded\@EA{\@EA\writeMPgraphic\@EA{\the\MPinitializations;}}%
+% \theMPinitializations
\else
\openMPgraphicfile0{collected}%
% reset here ! global added (due to adding \blabelgroup)
+ \theMPextensions
\theMPinclusions
+ \global\let\theMPextensions\relax
\global\let\theMPinclusions\relax
\fi
- %\flushMPTEXgraphic
- \ifMPrun \else
+ \theMPinitializations % always
+ \ifMPrun
+% \theMPinitializations
+ \else
\immediate\write\MPwrite{let mprunend = end ;}%
\immediate\write\MPwrite{beginfig(\the\currentMPgraphic);}%
- \ifrunMPgraphics \else
- \@EA\expanded\@EA{\@EA\writeMPgraphic\@EA{\the\MPinitializations;}}%
- \fi
+% \ifrunMPgraphics \else
+% \theMPinitializations
+% \fi
\fi
\globallet\flushMPgraphics\closeMPgraphicfiles % \dodostopwritingMPgraphic
\globallet\stopwritingMPgraphic\dostopwritingMPgraphic}
@@ -656,7 +727,7 @@
\fi
\@EA\let\@EA\MPwrite\csname\@@MPG\@@MPG\MPgraphicfile\endcsname
\ifdone
- \immediate\openout\MPwrite=\MPgraphicfile.mp
+ \immediate\openout\MPwrite\MPgraphicfile.mp\relax
\ifx\MPinputtranslation\empty\else
\immediate\write\MPwrite{\MPinputtranslation}%
\immediate\write\MPwrite{verbatimtex \MPinputtranslation etex ;}%
@@ -852,6 +923,18 @@
\newcount\MPobjectcounter
+% \def\douseMPbox#1%
+% {\global\advance\MPobjectcounter\plusone
+% \setobject{MP}{\number\MPobjectcounter}\vbox
+% {\forgetall
+% \loadMPgraphic{\MPgraphicfile.\the\currentMPgraphic}{}%
+% \deallocateMPslot\currentMPgraphic
+% \placeMPgraphic}%
+% \setxvalue{#1}{\noexpand\getobject{MP}{\number\MPobjectcounter}}}
+%
+% The next one saves the boundingbox. This helps positioning reused
+% graphics in layers.
+
\def\douseMPbox#1%
{\global\advance\MPobjectcounter\plusone
\setobject{MP}{\number\MPobjectcounter}\vbox
@@ -859,7 +942,15 @@
\loadMPgraphic{\MPgraphicfile.\the\currentMPgraphic}{}%
\deallocateMPslot\currentMPgraphic
\placeMPgraphic}%
- \setxvalue{#1}{\noexpand\getobject{MP}{\number\MPobjectcounter}}}
+ \setxvalue{#1}%
+ {\noexpand\dodouseMPbox{\number\MPobjectcounter}{\MPllx}{\MPlly}{\MPurx}{\MPury}}}
+
+\def\dodouseMPbox#1#2#3#4#5% space delimiting would save some tokens
+ {\xdef\MPllx{#2}% but it's not worth the effort and looks
+ \xdef\MPlly{#3}% ugly as well
+ \xdef\MPurx{#4}%
+ \xdef\MPury{#5}%
+ \getobject{MP}{#1}}
\def\nouseMPbox#1%
{\setxvalue{#1}%
@@ -899,6 +990,8 @@
\getvalue{\@@MPG#1}%
\elabelgroup}
+\let\stopreusableMPgraphic \relax % so that we can use it in \expanded
+
%D \macros
%D {startuseMPgraphic,useMPgraphic}
%D
@@ -922,18 +1015,29 @@
\deallocateMPslot\currentMPgraphic
\egroup}
-\long\def\startuseMPgraphic#1#2\stopuseMPgraphic
+\long\def\startuseMPgraphic
{\blabelgroup
- \long\setgvalue{\@@MPG#1}{\handleuseMPgraphic{#1}{#2}}%
+ \obeyMPlines
+ \dostartuseMPgraphic}
+
+\long\def\dostartuseMPgraphic#1#2\stopuseMPgraphic
+ {\long\setgvalue{\@@MPG#1}{\handleuseMPgraphic{#1}{#2}}%
\elabelgroup}
-\long\def\startusableMPgraphic#1#2\stopusableMPgraphic % dummy
+\long\def\startusableMPgraphic
{\blabelgroup
- \long\setgvalue{\@@MPG#1}{\handleuseMPgraphic{#1}{#2}}%
+ \obeyMPlines
+ \dostartusableMPgraphic}
+
+\long\def\dostartusableMPgraphic#1#2\stopusableMPgraphic
+ {\long\setgvalue{\@@MPG#1}{\handleuseMPgraphic{#1}{#2}}%
\elabelgroup}
\let\useMPgraphic=\reuseMPgraphic
+\let\stopuseMPgraphic \relax % so that we can use it in \expanded
+\let\stopusableMPgraphic \relax % so that we can use it in \expanded
+
%D \macros
%D {doifMPgraphicelse}
%D
@@ -1014,22 +1118,24 @@
\def\executesystemcommand#1{\immediate\write18{#1}}
\fi
+\ifx\TEXEXECcommand \undefined \def\TEXEXECcommand{texmfstart texexec} \fi
+
\ifx\undefined\executeMetaPost
\ifx\undefined\interactionmode \chardef\interactionmode=255 \fi
\def\MPOSTbatchswitch {-int=batchmode}
\def\MPOSTnonstopswitch {-int=nonstopmode}
- \def\MPOSTformatswitch {-progname=mpost -mem=}
+ \def\MPOSTformatswitch {-progname=metafun -mem=}
\def\MPOSTdriver {dvips}
- \def\executeMPOST#1%
+ \def\executeMPOST#1% direct call
{mpost
\ifcase\interactionmode\MPOSTbatchswitch\or\MPOSTnonstopswitch\fi
\space\ifuseMETAFUNformat \MPOSTformatswitch metafun \fi #1}
- \def\executeMPTEX#1%
- {texexec
+ \def\executeMPTEX#1% slower, due to nested texexec call
+ {\TEXEXECcommand\space
--batch \ifcase\interactionmode --logfile='mptex.log' \fi
--output=\MPOSTdriver\space
\ifuseMETAFUNformat --mpformat=metafun \fi --mptex --nomp --once #1}
@@ -1156,7 +1262,7 @@
\bgroup
\message{[MP fonts #1]}%
%\uncatcodespecials
- \endlinechar=-1
+ \endlinechar\minusone
\setMPspecials
\obeyMPspecials
\setbox\scratchbox\hbox
@@ -1406,18 +1512,18 @@
\endlinechar\minusone
\uncatcodespecials
\donefalse
- \immediate\openout\scratchwrite=\convertMPcolorpath\convertMPcolorfile
+ \immediate\openout\scratchwrite\convertMPcolorpath\convertMPcolorfile\relax
\doprocessfile\scratchread{#1}\handleMPcolor
\immediate\closeout\scratchwrite
\ifdone
- \immediate\openout\scratchwrite=\convertMPcolorpath#1\relax
+ \immediate\openout\scratchwrite\convertMPcolorpath#1\relax
\doprocessfile\scratchread{\convertMPcolorpath \convertMPcolorfile}\handleMPcopy
\immediate\closeout\scratchwrite
\message{done]}%
\else
\message{not needed]}%
\fi
- \immediate\openout\scratchwrite=\convertMPcolorpath\convertMPcolorfile
+ \immediate\openout\scratchwrite\convertMPcolorpath\convertMPcolorfile
\immediate\closeout\scratchwrite
\fi
\egroup}
@@ -1640,7 +1746,7 @@
\def\getMPdrawing
{\ifMPdrawingdone
\expandafter\startMPgraphic\MPdrawingdata\stopMPgraphic
- \loadcurrentMPgraphic\empty
+ \loadcurrentMPgraphic{}%
\deallocateMPslot\currentMPgraphic
\placeMPgraphic
\fi}
@@ -1858,7 +1964,57 @@
%D
%D this automatically places the graphic
-\long\def\startMPcode#1\stopMPcode
- {\startuseMPgraphic{@@}#1\stopuseMPgraphic\useMPgraphic{@@}}
+\long\def\startMPcode
+ {\begingroup
+ \obeyMPlines
+ \dostartMPcode}
+
+\long\def\dostartMPcode#1\stopMPcode
+ {\startuseMPgraphic{@@}#1\stopuseMPgraphic
+ \useMPgraphic{@@}%
+ \endgroup}
+
+\let\stopMPcode \relax % so that we can use it in \expanded
+
+%D \macros
+%D {startstaticMPgraphic}
+%D
+%D Dedicated to Aditya Mahajan. See meta-ini for usage.
+
+\long\def\startstaticMPgraphic#1#2\stopstaticMPgraphic
+ {\bgroup
+ \setMPrandomseedfalse
+ \def\MPgraphicfile{#1}% no \jobname here
+ \let\allocateMPslot \gobbleoneargument
+ \let\deallocateMPslot\gobbleoneargument
+ \let\runMPgraphic \gobbleoneargument
+ \runMPgraphicstrue
+ \enableincludeMPgraphics
+ \currentMPgraphic\plusone % hack, else no close
+ \startMPgraphic#2\stopMPgraphic
+ \executeMPgraphicfile
+ \egroup}
+
+
+\ifx\doifmode\undefined
+ \def\executeMPgraphicfile
+ {\executesystemcommand
+ {texmfstart --ifchanged=\MPgraphicfile.mp
+ texexec --mpgraphic \MPgraphicfile.mp}}
+\else
+ \def\executeMPgraphicfile
+ {\doifmode{*\v!first}{\executesystemcommand
+ {texmfstart --ifchanged=\MPgraphicfile.mp
+ texexec --mpgraphic \MPgraphicfile.mp}}}
+\fi
+
+%D Special for \XETEX\ (problem with newlines). This will go
+%D away once the version supporting \type {--8bit} is
+%D widespread.
+
+\beginXETEX
+ \let\obeyMPlines\relax
+ \longMPlinesfalse % alas
+\endXETEX
\protect \endinput