summaryrefslogtreecommitdiff
path: root/tex/context/base/supp-mps.tex
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2002-12-20 00:00:00 +0100
committerHans Hagen <pragma@wxs.nl>2002-12-20 00:00:00 +0100
commitd66c6c7f5bf3b189c2b194ba167fb39f548742e5 (patch)
tree23d545dc0956f461418b7e738a018fe046077c32 /tex/context/base/supp-mps.tex
parentd4d7f62e436c20b5ea3ee7f8c9fc3bbacd5dda43 (diff)
downloadcontext-d66c6c7f5bf3b189c2b194ba167fb39f548742e5.tar.gz
stable 2002.12.20
Diffstat (limited to 'tex/context/base/supp-mps.tex')
-rw-r--r--tex/context/base/supp-mps.tex261
1 files changed, 152 insertions, 109 deletions
diff --git a/tex/context/base/supp-mps.tex b/tex/context/base/supp-mps.tex
index 7ba4c2223..c8559f1fd 100644
--- a/tex/context/base/supp-mps.tex
+++ b/tex/context/base/supp-mps.tex
@@ -60,7 +60,7 @@
%D This is implemented as:
\long\def\startMPgraphic#1\stopMPgraphic
- {\checkMPTEXgraphic{#1}%
+ {\checkMPTEXgraphic{#1}% % potential speedup: pass #1 as macro
\startwritingMPgraphic
\writeMPgraphic{#1}%
\stopwritingMPgraphic}
@@ -276,7 +276,7 @@
\newif\ifMPTEXgraphic
-\def\dowriteMPgraphicline%
+\def\dowriteMPgraphicline
{\futurelet\next\dodowriteMPgraphicline}
%D A first version:
@@ -305,44 +305,79 @@
\newif\ifforceMPTEXgraphic
-\convertargument etex\to\MPasciiB
-\convertargument textext\to\MPasciiC % geen "text"
-\convertargument graphictext\to\MPasciiD % geen "text"
+%D Before we supported the graph module, we had:
+%D
+%D \starttypen
+%D \convertargument etex\to\MPasciiB
+%D \convertargument textext\to\MPasciiC % geen "text"
+%D \convertargument graphictext\to\MPasciiD % geen "text"
+%D
+%D \long\def\checkMPTEXgraphic#1%
+%D {\ifforceMPTEXgraphic
+%D \global\MPTEXgraphictrue
+%D \else
+%D \expandafter\convertargument#1\to\MPasciiA
+%D \doifstringinstringelse\MPasciiB\MPasciiA{\global\MPTEXgraphictrue}
+%D {\doifstringinstringelse\MPasciiC\MPasciiA{\global\MPTEXgraphictrue}
+%D {\doifstringinstringelse\MPasciiD\MPasciiA{\global\MPTEXgraphictrue}
+%D {\global\MPTEXgraphicfalse}}}%
+%D \fi}
+%D \stoptypen
+%D
+%D The next alternative permits extensions in other modules
+%D without the need to know the details of testing.
+
+\newtoks\MPTEXgrapicchecks
\long\def\checkMPTEXgraphic#1%
{\ifforceMPTEXgraphic
\global\MPTEXgraphictrue
\else
- \expandafter\convertargument#1\to\MPasciiA
- \doifstringinstringelse\MPasciiB\MPasciiA
- {\global\MPTEXgraphictrue}
- {\doifstringinstringelse\MPasciiC\MPasciiA
- {\global\MPTEXgraphictrue}
- {\doifstringinstringelse\MPasciiD\MPasciiA
- {\global\MPTEXgraphictrue}
- {\global\MPTEXgraphicfalse}}}%
+ \global\MPTEXgraphicfalse
+ \expandafter\convertargument#1\to\MPascii
+ \the\MPTEXgrapicchecks\relax
\fi}
+%D We could have used a kind of array approach using a
+%D counter appended to \type {MPascii}, but this is an
+%D as efficient alternative. (The uglyness comes from
+%D expanding after the string \type {#1}).
+
+\def\forceMPTEXcheck#1%
+ {\expanded{\convertargument#1\noexpand\to
+ \@EA\noexpand\csname MPascii#1\endcsname}%
+ \@EA\appendtoks
+ \@EA\doifincsnameelse\csname MPascii#1\endcsname\MPascii
+ {\global\MPTEXgraphictrue\gobbleuntil\relax}\donothing
+ \to \MPTEXgrapicchecks}
+
+\forceMPTEXcheck{etex}
+\forceMPTEXcheck{textext}
+\forceMPTEXcheck{graphictext}
+
\def\flushMPTEXgraphic
{\ifMPTEXgraphic \ifx\everyMPTEXgraphic\emptytoks \else
\immediate\write\MPwrite{verbatimtex \the\everyMPTEXgraphic\space etex;}%
\fi \fi}
-% \long\def\dodowriteMPgraphicline#1tex #2#3etex#4\MPend%
+\long\def\flushMPgraphicline#1#2;%
+ {\ifx#1\relax \else
+ \immediate\write\MPwrite{#1#2;}%
+ \expandafter\flushMPgraphicline
+ \fi}
+
+% the next one fails on btex \vbox {\hbox .. leading to \vbox \hbox
+%
+% \long\def\dodowriteMPgraphicline#1tex #2#3etex#4\MPend
% {\ifx\next\empty\else\ifx\next\relax\else
% \bgroup
-% \let\par=\space
+% \let\par\space
% \ifx#2\relax
% \iflongMPlines
% \immediate\write\MPwrite{#1;}%
% \else
% \edef\ascii{#1}%
-% \long\def\flush##1##2;%
-% {\ifx##1\relax \else
-% \immediate\write\MPwrite{##1##2;}%
-% \expandafter\flush
-% \fi}%
-% \expandafter\flush\ascii\empty;\relax;%
+% \expandafter\flushMPgraphicline\ascii\empty;\relax;%
% \fi
% \egroup
% \else
@@ -352,31 +387,35 @@
% \dowriteMPgraphicline#4tex \relax etex\MPend
% \fi
% \fi\fi}
+%
+% so we need a two step approach
-\long\def\flushMPgraphicline#1#2;%
- {\ifx#1\relax \else
- \immediate\write\MPwrite{#1#2;}%
- \expandafter\flushMPgraphicline
- \fi}
+\long\def\dodowriteMPgraphicline#1tex %
+ {\doifnextcharelse\relax
+ {\nododowriteMPgraphicline{#1}}
+ {\redodowriteMPgraphicline{#1}}}
-\long\def\dodowriteMPgraphicline#1tex #2#3etex#4\MPend
+\long\def\redodowriteMPgraphicline#1#2etex#3\MPend
{\ifx\next\empty\else\ifx\next\relax\else
\bgroup
\let\par\space
- \ifx#2\relax
- \iflongMPlines
- \immediate\write\MPwrite{#1;}%
- \else
- \edef\ascii{#1}%
- \expandafter\flushMPgraphicline\ascii\empty;\relax;%
- \fi
- \egroup
+ \convertargument#2\to\ascii
+ \immediate\write\MPwrite{#1tex \ascii etex}%
+ \egroup
+ \dowriteMPgraphicline#3tex \relax etex\MPend
+ \fi\fi}
+
+\long\def\nododowriteMPgraphicline#1#2\MPend
+ {\ifx\next\empty\else\ifx\next\relax\else
+ \bgroup
+ \let\par\space
+ \iflongMPlines
+ \immediate\write\MPwrite{#1;}%
\else
- \convertargument#2#3\to\ascii
- \immediate\write\MPwrite{#1tex \ascii etex}%
- \egroup
- \dowriteMPgraphicline#4tex \relax etex\MPend
+ \edef\ascii{#1}%
+ \expandafter\flushMPgraphicline\ascii\empty;\relax;%
\fi
+ \egroup
\fi\fi}
%D This stripper is suboptimal in the sense that more
@@ -431,21 +470,26 @@
\the\everyMPgraphic
\ifrunMPgraphics
\openMPgraphicfile{1}{runtime}%
- \theMPinclusions % no reset here !
+ % no reset here !
+ \theMPinclusions
\else
- \openMPgraphicfile{0}{collected}%
- \theMPinclusions \let\theMPinclusions\relax % reset here !
+ \openMPgraphicfile{0}{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
- \global\let\flushMPgraphics\closeMPgraphicfiles % \dodostopwritingMPgraphic
- \global\let\stopwritingMPgraphic=\dostopwritingMPgraphic}
+ \globallet\flushMPgraphics\closeMPgraphicfiles % \dodostopwritingMPgraphic
+ \globallet\stopwritingMPgraphic=\dostopwritingMPgraphic}
\let\MPgraphicfiles\empty
+\let\MPinputtranslation\empty
+
\def\openMPgraphicfile#1#2% #1=alwaysopen #2=message
{%\doifundefinedelse{\@@MPG\@@MPG\MPgraphicfile}
% {\donetrue
@@ -460,12 +504,16 @@
\@EA\let\@EA\MPwrite\csname\@@MPG\@@MPG\MPgraphicfile\endcsname
\ifdone
\immediate\openout\MPwrite=\MPgraphicfile.mp
+ \ifx\MPinputtranslation\empty\else
+ \immediate\write\MPwrite{\MPinputtranslation}%
+ \immediate\write\MPwrite{verbatimtex \MPinputtranslation etex ;}
+ \fi
\immediate\write\MPwrite{\letterpercent\space #2 graphics of job "\jobname"}%
\writeMPgraph
\setMPrandomseed
\fi}
-\def\dostopwritingMPgraphic%
+\def\dostopwritingMPgraphic
{\ifMPrun \else
\immediate\write\MPwrite{endfig;}%
\immediate\write\MPwrite{let end = mprunend ;}%
@@ -475,7 +523,7 @@
\fi
\elabelgroup}
-\def\dodostopwritingMPgraphic%
+\def\dodostopwritingMPgraphic
{\ifnum\currentMPgraphic>0
\donetrue
\else\ifMPrun
@@ -487,7 +535,7 @@
\finishwritingMPgraphics
\runMPgraphic\MPgraphicfile
\fi
- \global\let\flushMPgraphics\relax}
+ \globallet\flushMPgraphics\relax}
\def\finishwritingMPgraphics
{\immediate\write\MPwrite{end.}%
@@ -511,6 +559,30 @@
\def \allocateMPslot#1{\global\advance#1 1 }
\def\deallocateMPslot#1{}
+%D \macros
+%D {translateMPinput}
+%D
+%D For my polish friends:
+%D
+%D \starttypen
+%D % translate=il2-pl
+%D
+%D \translateMPinput{il2-pl}
+%D
+%D \startMPenvironment[global]
+%D \setupbodyfont[plr]
+%D \stopMPenvironment
+%D
+%D \TeX: ± ¶
+%D
+%D \startMPcode
+%D draw btex MetaPost: ± ¶ etex scaled 5 ;
+%D \stopMPcode
+%D \stoptypen
+
+\def\translateMPinput#1%
+ {\xdef\MPinputtranslation{\letterpercent -translate-file=#1\space}}
+
%D \macros
%D {setMPrandomseed}
%D
@@ -794,11 +866,6 @@
\ifx\undefined\interactionmode \chardef\interactionmode=255 \fi
-% \def\executeMPOST#1%
-% {mpost
-% \ifcase\interactionmode -int=batchmode \fi
-% \ifuseMETAFUNformat -progname=mpost -mem=metafun \fi #1}
-
\def\MPOSTbatchswitch {-int=batchmode}
\def\MPOSTformatswitch{-progname=mpost -mem=}
\def\MPOSTdriver {dvips}
@@ -814,17 +881,6 @@
--output=\MPOSTdriver\space
\ifuseMETAFUNformat --mpformat=metafun \fi --mptex --nomp --once #1}
-% \def\executeMetaPost#1% @EA's
-% {\ifrunMPTEXgraphics
-% \ifMPTEXgraphic
-% \executeMPTEX{#1}%
-% \else
-% \executeMPOST{#1}%
-% \fi
-% \else
-% \executeMPOST{#1}%
-% \fi}
-
\def\executeMetaPost
{\ifrunMPTEXgraphics
\ifMPTEXgraphic
@@ -1092,11 +1148,11 @@
\def\includeMPcharacters(#1) #2 #3 #4#5#6#7#8#9\relax
{\edef\temp{#4#5#6#7#8}%
\ifx\temp\PSnfont % round font size (to pt)
- \scratchdimen=#3pt
+ \scratchdimen#3pt
\ifdim\scratchdimen<1pt
\def\size{1pt}%
\else
- \advance\scratchdimen by .5pt
+ \advance\scratchdimen .5pt
\def\size##1.##2\relax{\def\size{##1pt}}%
\expandafter\size\the\scratchdimen\relax
\fi
@@ -1181,7 +1237,7 @@
\fi\fi
\ifdone
\message{[MP color conversion #1}%
- \endlinechar=-1
+ \endlinechar\minusone
\uncatcodespecials
\donefalse
\immediate\openout\scratchwrite=\convertMPcolorpath\convertMPcolorfile
@@ -1207,6 +1263,9 @@
%D copied back. We don't have to reduce to gray scales;
%D \METAPOST\ already takes care of that.
+%D BTW, this code is quite old, and not as complete as the
+%D \PDF\ converter, which also handles spot colors and so.
+
\def\handleMPcolor
{\expandafter\dohandleMPcolor\fileline setrgbcolor*\\}
@@ -1228,18 +1287,18 @@
\immediate\write\scratchwrite
{\@@cl@@s \space setgray #4}%
\else
- \dimen0=1pt \advance\dimen0 -#1pt
- \dimen2=1pt \advance\dimen2 -#2pt
- \dimen4=1pt \advance\dimen4 -#3pt
+ \dimen0=1\s!pt \advance\dimen0 -#1\s!pt
+ \dimen2=1\s!pt \advance\dimen2 -#2\s!pt
+ \dimen4=1\s!pt \advance\dimen4 -#3\s!pt
\ifreduceMPcolors
- \dimen6=\dimen0
- \ifdim\dimen2<\dimen6 \dimen6=\dimen2 \fi
- \ifdim\dimen4<\dimen6 \dimen6=\dimen4 \fi
+ \dimen6\dimen0
+ \ifdim\dimen2<\dimen6 \dimen6\dimen2 \fi
+ \ifdim\dimen4<\dimen6 \dimen6\dimen4 \fi
\advance\dimen0 -\dimen6
\advance\dimen2 -\dimen6
\advance\dimen4 -\dimen6
\else
- \dimen6=\zeropoint
+ \dimen6\zeropoint
\fi
\immediate\write\scratchwrite
{\withoutpt{\the\dimen0} \space
@@ -1251,7 +1310,7 @@
\egroup
\donetrue} % needed for message
-\def\handleMPcopy%
+\def\handleMPcopy
{\immediate\write\scratchwrite{\fileline}}
%D The next macro is needed for forced conversion. This macro
@@ -1261,17 +1320,17 @@
\ifx\convertRGBtoGRAY\undefined
\def\convertRGBtoGRAY#1#2#3%
- {\scratchdimen=#1\s!pt
- \scratchdimen=300\scratchdimen
- \scratchcounter=\scratchdimen
- \scratchdimen=#2\s!pt
- \scratchdimen=590\scratchdimen
- \advance\scratchcounter by \scratchdimen
- \scratchdimen=#3\s!pt
- \scratchdimen=110\scratchdimen
- \advance\scratchcounter by \scratchdimen
- \advance\scratchcounter by \!!medcard
- \divide\scratchcounter by \!!maxcard
+ {\scratchdimen#1\s!pt
+ \scratchdimen300\scratchdimen
+ \scratchcounter\scratchdimen
+ \scratchdimen#2\s!pt
+ \scratchdimen590\scratchdimen
+ \advance\scratchcounter \scratchdimen
+ \scratchdimen#3\s!pt
+ \scratchdimen110\scratchdimen
+ \advance\scratchcounter \scratchdimen
+ \advance\scratchcounter \!!medcard
+ \divide\scratchcounter \!!maxcard
\edef\@@cl@@s{\realcolorvalue\scratchcounter}}
\fi
@@ -1400,12 +1459,12 @@
\newif\ifMPshiftdrawing \MPshiftdrawingfalse
\def\resetMPdrawing
- {\global\let\MPdrawingdata\empty
+ {\globallet\MPdrawingdata\empty
\global\MPdrawingdonefalse}
\def\pushMPdrawing
{\pushmacro\MPdrawingdata
- \global\let\MPdrawingdata\empty}
+ \globallet\MPdrawingdata\empty}
\def\popMPdrawing
{\popmacro\MPdrawingdata}
@@ -1532,22 +1591,6 @@
\newif\ifrecycleMPslots \recycleMPslotstrue
-% \def\allocateMPslot#1%
-% {\ifrunMPgraphics
-% \ifcase\pdfoutput \recycleMPslotsfalse \fi
-% \else
-% \recycleMPslotsfalse
-% \fi
-% \ifrecycleMPslots
-% \doloop % slow but used seldom
-% {\doifundefined{\recurselevel MP}
-% {\global\letvalue{\recurselevel MP}=\empty
-% \global#1=\recurselevel\exitloop}}%
-% %\message{[MP slot + \number#1]%
-% \else
-% \global\advance#1 1
-% \fi}
-
%D When a graphic takes space in the text flow, we can run
%D into deadlock typesetting. In the first pass, the graphic
%D is not available, but in the second pass it is. The
@@ -1580,16 +1623,16 @@
\ifrecycleMPslots
\doloop % slow but used seldom
{\doifundefined{\recurselevel MP}
- {\global\letvalue{\recurselevel MP}\empty
+ {\letgvalueempty{\recurselevel MP}%
\global#1=\recurselevel
\exitloop}}%
% \message{[MP slot + \number#1]%
\else\ifMPstaticgraphic
\global#1\maxnofMPgraphics
- \global\advance\maxnofMPgraphics -1
+ \global\advance\maxnofMPgraphics \minusone
\else
\global#1\minnofMPgraphics
- \global\advance\minnofMPgraphics 1
+ \global\advance\minnofMPgraphics \plusone
\fi\fi
\ifnum\minnofMPgraphics<\maxnofMPgraphics \else
\writestatus{\m!systems}{increase \string\maxnofMPgraphics}%
@@ -1609,10 +1652,10 @@
%D Experimental and overloaded later, since we need to be
%D more clever due to \METAPOST's limit of 4~open files.
-\def\MPdatafile%
+\def\MPdatafile
{mp-\the\currentMPgraphic.mpd}
-\def\getMPdata%
+\def\getMPdata
{\input \MPdatafile\relax}
%D \macros
@@ -1634,7 +1677,7 @@
%D
%D this automatically places the graphic
-\long\def\startMPcode#1\stopMPcode%
+\long\def\startMPcode#1\stopMPcode
{\startuseMPgraphic{@@}#1\stopuseMPgraphic\useMPgraphic{@@}}
\protect \endinput