summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/meta-ini.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/meta-ini.mkiv')
-rw-r--r--Master/texmf-dist/tex/context/base/meta-ini.mkiv1010
1 files changed, 506 insertions, 504 deletions
diff --git a/Master/texmf-dist/tex/context/base/meta-ini.mkiv b/Master/texmf-dist/tex/context/base/meta-ini.mkiv
index e95eb178604..d2f5cd6cb4c 100644
--- a/Master/texmf-dist/tex/context/base/meta-ini.mkiv
+++ b/Master/texmf-dist/tex/context/base/meta-ini.mkiv
@@ -5,7 +5,7 @@
%D subtitle=Initialization,
%D author=Hans Hagen,
%D date=\currentdate,
-%D copyright=PRAGMA]
+%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
@@ -17,111 +17,126 @@
\unprotect
-%D Instead of sharing code with \MKII, I decided to copy
-%D the code. Otherwise maintainance becomes a pain and after all,
-%D the \MKII\ code will not change.
+\newtoks \t_meta_extensions % mp, once
+\newtoks \t_meta_initializations % tex, each
+\newtoks \t_meta_userinclusions % mp, user
-\let \useMETAFUNformattrue\relax \let \useMETAFUNformatfalse\relax
-\let \longMPlinestrue\relax \let \longMPlinesfalse\relax
-\let \runMPgraphicstrue\relax \let \runMPgraphicsfalse\relax
-\let \runMPTEXgraphicstrue\relax \let \runMPTEXgraphicsfalse\relax
-\let \MPstaticgraphictrue\relax \let \MPstaticgraphicfalse\relax
-\let\forceMPTEXgraphictrue\relax \let\forceMPTEXgraphicfalse\relax
+\newtoks \everyMPgraphic % mp % public or not ?
-\let \obeyMPlines\relax
-\let \forceMPTEXcheck\gobbleoneargument
-\let\maxnofMPgraphics\scratchcounter
+\appendtoks
+ \restoreendofline % see interferences-001.tex
+\to \everyMPgraphic
-\newtoks \MPextensions % mp, once
-\newtoks \MPinitializations % tex, each
-\newtoks \MPuserinclusions % mp, user
-\newtoks \MPfinalizations % mp, user
-\newtoks \everyMPgraphic % mp
-\newtoks \everyMPTEXgraphic % tex
+\def\MPruntimefile {mprun}
+\def\currentMPformat {metafun}
+\def\defaultMPinstance{metafun}
-\newif\ifMPrun
-\def\MPruntimefile{mprun}
+%installcorenamespace{graphicvariable} % todo
+\installcorenamespace{mpinstance}
+\installcorenamespace{mpinstancetokens}
+\installcorenamespace{mpgraphic}
+\installcorenamespace{mpstaticgraphic}
+\installcorenamespace{mpclip}
% The next command is, of course, dedicated to Mojca, who
% needs it for gnuplot. Anyway, the whole multiple engine
% mechanism is to keep her gnuplot from interfering.
-\def\startMPdefinitions
- {\dosinglegroupempty\dostartMPdefinitions}
+\unexpanded\def\startMPdefinitions
+ {\dosinglegroupempty\meta_start_definitions}
-\long\def\dostartMPdefinitions#1#2\stopMPdefinitions
- {\edef\currentMPgraphicinstance{#1}%
- \ifx\currentMPgraphicinstance\empty
- \let\currentMPgraphicinstance\defaultMPgraphicinstance
+\def\meta_start_definitions#1#2\stopMPdefinitions
+ {\edef\currentMPinstance{#1}%
+ \ifx\currentMPinstance\empty
+ \let\currentMPinstance\defaultMPinstance
\fi
- \global\MPinstancetoks\expandafter{\the\MPinstancetoks#2}}
+ \global\t_meta_instance\expandafter{\the\t_meta_instance#2}}
+
+\let\stopMPdefinitions\relax
-\long\def\startMPextensions#1\stopMPextensions
- {\global\MPextensions\expandafter{\the\MPextensions#1}}
+\unexpanded\def\startMPextensions#1\stopMPextensions
+ {\global\t_meta_extensions\expandafter{\the\t_meta_extensions#1}}
-\long\def\startMPinitializations#1\stopMPinitializations
- {\global\MPinitializations\expandafter{\the\MPinitializations#1}}
+\let\stopMPextensions\relax
-\long\def\startMPinclusions
- {\dosingleempty\dostartMPinclusions}
+\unexpanded\def\startMPinitializations#1\stopMPinitializations
+ {\global\t_meta_initializations\expandafter{\the\t_meta_initializations#1}}
-\long\def\dostartMPinclusions[#1]#2\stopMPinclusions
- {\doifnot{#1}{+}{\global\MPuserinclusions\emptytoks}%
- \global\MPuserinclusions\expandafter{\the\MPuserinclusions#2}}
+\let\stopMPinitializations\relax
-\def\MPinclusions
- {\dosingleempty\doMPinclusions}
+\unexpanded\def\startMPinclusions
+ {\dosingleempty\meta_start_inclusions}
+
+\def\meta_start_inclusions[#1]#2\stopMPinclusions
+ {\edef\m_meta_option{#1}%
+ \ifx\m_meta_option\!!plustoken \else
+ \global\t_meta_userinclusions\emptytoks
+ \fi
+ \global\t_meta_userinclusions\expandafter{\the\t_meta_userinclusions#2}}
-\long\def\doMPinclusions[#1]#2%
- {\doifnot{#1}{+}{\global\MPuserinclusions\emptytoks}%
- \global\MPuserinclusions\expandafter{\the\MPuserinclusions#2}}
+\let\stopMPinclusions\relax
-\def\presetMPdefinitions
+\unexpanded\def\MPinclusions
+ {\dosingleempty\meta_inclusions}
+
+\def\meta_inclusions[#1]#2%
+ {\edef\m_meta_option{#1}%
+ \ifx\m_meta_option\!!plustoken \else
+ \global\t_meta_userinclusions\emptytoks
+ \fi
+ \global\t_meta_userinclusions\expandafter{\the\t_meta_userinclusions#2}}
+
+\def\meta_preset_definitions
{\edef\overlaywidth {\overlaywidth \space}%
\edef\overlayheight {\overlayheight \space}%
\edef\overlaylinewidth{\overlaylinewidth\space}%
\edef\currentwidth {\the\hsize \space}%
\edef\currentheight {\the\vsize \space}}
-\def\currentMPformat{metafun}
+\def\t_meta_instance{\csname\??mpinstancetokens\currentMPinstance\endcsname} % token register
-\def\@@MPF{@MPF@}
+\installcommandhandler \??mpinstance {MPinstance} \??mpinstance
-\def\MPinstancetoks{\csname\@@MPF::\currentMPgraphicinstance\endcsname}
+\setupMPinstance
+ [\s!format=metafun,
+ \s!extensions=\v!no,
+ \s!initializations=\v!no,
+ \c!textstyle=,
+ \c!textcolor=]
-\unexpanded\def\defineMPinstance
- {\dodoubleargument\dodefineMPinstance}
+% \unexpanded\def\defineMPinstance
+% {\dodoubleargument\meta_define_instance}
-\def\dodefineMPinstance[#1][#2]%
- {\ifcsname\@@MPF::#1\endcsname\else\expandafter\newtoks\csname\@@MPF::#1\endcsname\fi
- \MPinstancetoks\emptytoks % in case we redefine
- \getparameters[\@@MPF#1][\s!format=mpost,\s!extensions=\v!no,\s!initializations=\v!no,#2]}
+% \def\meta_define_instance[#1][#2]%
+% {\ifcsname\??mpinstancetokens#1\endcsname\else\expandafter\newtoks\csname\??mpinstancetokens#1\endcsname\fi
+% \t_meta_instance\emptytoks % in case we redefine
+% \getparameters[\??mpinstance#1][\s!format=mpost,\s!extensions=\v!no,\s!initializations=\v!no,#2]}
-\def\resetMPinstance[#1]%
- {\writestatus\m!metapost{reset will be implemented when needed}}
+\appendtoks
+ \ifcsname\??mpinstancetokens\currentMPinstance\endcsname \else
+ \expandafter\newtoks\csname\??mpinstancetokens\currentMPinstance\endcsname
+ \fi
+ \t_meta_instance\emptytoks % in case we redefine
+\to \everydefineMPinstance
-\def\defaultMPgraphicinstance{metafun}
+\unexpanded\def\resetMPinstance[#1]%
+ {\writestatus\m!metapost{reset will be implemented when needed}}
-\def\splitMPgraphicname[#1]%
- {\dosplitMPgraphicname[#1::::]}
+\def\meta_analyze_graphicname[#1]%
+ {\meta_analyze_graphicname_indeed[#1::::]}
-\def\dosplitMPgraphicname[#1::#2::#3]% instance ::
+\def\meta_analyze_graphicname_indeed[#1::#2::#3]% instance ::
{\edef\currentMPgraphicname{#2}%
\ifx\currentMPgraphicname\empty
\edef\currentMPgraphicname{#1}%
- \let\currentMPgraphicinstance\defaultMPgraphicinstance
+ \let\currentMPinstance\defaultMPinstance
\else
- \edef\currentMPgraphicinstance{#1}%
+ \edef\currentMPinstance{#1}%
\fi
- \edef\currentMPgraphicformat
- {\ifcsname\@@MPF\currentMPgraphicinstance\s!format\endcsname
- \csname\@@MPF\currentMPgraphicinstance\s!format\endcsname
- \else
- \defaultMPgraphicinstance
- \fi}}
+ \edef\currentMPformat{\MPinstanceparameter\s!format}}
-\def\currentMPgraphicinstance{\defaultMPgraphicinstance}
-\def\currentMPgraphicformat {\currentMPgraphicinstance}
+\def\currentMPinstance{\defaultMPinstance}
+\def\currentMPformat {\currentMPinstance}
\defineMPinstance[metafun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes]
\defineMPinstance[extrafun][\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes]
@@ -129,54 +144,69 @@
\defineMPinstance[metapost][\s!format=mpost]
\defineMPinstance[nofun] [\s!format=mpost]
-\def\beginMPgraphicgroup#1%
+\newconditional\c_meta_include_extensions
+\newconditional\c_meta_include_initializations
+
+\def\meta_begin_graphic_group#1%
{\begingroup
- \splitMPgraphicname[#1]}
+ \meta_analyze_graphicname[#1]}
-\def\endMPgraphicgroup
+\def\meta_end_graphic_group
{\endgroup}
\def\MPaskedfigure{false}
-\def\currentMPinitializations
- {\ifconditional\includeMPinitializations\the\MPinitializations;\fi\theMPrandomseed;}
+\def\meta_flush_current_initializations
+ {\ifconditional\c_meta_include_initializations\the\t_meta_initializations;\fi\theMPrandomseed;}
-\def\currentMPpreamble
- {\ifconditional\includeMPextensions\the\MPextensions;\the\MPuserinclusions;\fi\the\MPinstancetoks;}
+\def\meta_flush_current_preamble
+ {\ifconditional\c_meta_include_extensions\the\t_meta_extensions;\the\t_meta_userinclusions;\fi\the\t_meta_instance;}
-\def\dostartcurrentMPgraphic
+\def\meta_start_current_graphic
{\begingroup
- \enableincludeMPgraphics
+ \meta_enable_include
\the\everyMPgraphic
- \presetMPdefinitions
+ \meta_preset_definitions
\setMPrandomseed % this has to change
% we need to preexpand the token lists
- \doifelsevalue{\@@MPF\currentMPgraphicinstance\s!extensions}\v!yes
- {\settrue \includeMPextensions\letgvalue{\@@MPF\currentMPgraphicinstance\s!extensions}\v!no}
- {\setfalse\includeMPextensions}%
- \doifelsevalue{\@@MPF\currentMPgraphicinstance\s!initializations}\v!yes
- {\settrue \includeMPinitializations}%
- {\setfalse\includeMPinitializations}}
-
-\def\dostopcurrentMPgraphic
- {\global\MPinstancetoks\emptytoks
+ \edef\p_extensions{\MPinstanceparameter\s!extensions}%
+ \ifx\p_extensions\v!yes
+ \settrue \c_meta_include_extensions
+ \global\letMPinstanceparameter\s!extensions\v!no % needs checking
+ \else
+ \setfalse\c_meta_include_extensions
+ \fi
+ \edef\p_initializations{\MPinstanceparameter\s!initializations}%
+ \ifx\p_initializations\v!yes
+ \settrue \c_meta_include_initializations
+ \else
+ \setfalse\c_meta_include_initializations
+ \fi
+ \edef\p_setups{\MPinstanceparameter\c!setups}%
+ \ifx\p_setups\empty \else
+ \setups[\p_setups]%
+ \fi
+ \useMPinstancestyleandcolor\c!textstyle\c!textcolor}
+
+\def\meta_stop_current_graphic
+ {\global\t_meta_instance\emptytoks
\endgroup}
-\unexpanded\long\def\processMPgraphic#1% todo: extensions and inclusions outside beginfig
- {\dostartcurrentMPgraphic
+\unexpanded\def\meta_process_graphic#1% todo: extensions and inclusions outside beginfig
+ {\meta_start_current_graphic
\forgetall
- \setbox\MPgraphicbox\hbox\bgroup % ; added 20100901 (as in mkii)
+ \setbox\b_meta_graphic\hbox\bgroup % ; added 20100901 (as in mkii)
\normalexpanded{\noexpand\ctxlua{metapost.graphic(
- "\currentMPgraphicinstance",
- "\currentMPgraphicformat",
+ "\currentMPinstance",
+ "\currentMPformat",
\!!bs#1;\!!es,
- \!!bs\currentMPinitializations;\!!es,
- \!!bs\currentMPpreamble;\!!es,
+ \!!bs\meta_flush_current_initializations;\!!es,
+ \!!bs\meta_flush_current_preamble;\!!es,
\MPaskedfigure
)}}%
\egroup
\placeMPgraphic
- \dostopcurrentMPgraphic}
+ \meta_stop_current_graphic}
\newif\ifsetMPrandomseed \setMPrandomseedtrue % false by default
@@ -187,105 +217,101 @@
\def\theMPrandomseed{randomseed:=\localMPseed}%
\fi\fi}
-%D To be integrated
-
-\def\@@MPG{@MPG@}
+%D Calling up previously defined graphics.
-\def\doifMPgraphicelse#1%
- {\ifcsname\@@MPG#1\endcsname\expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi}
+\def\includeMPgraphic#1% gets expanded !
+ {\ifcsname\??mpgraphic#1\endcsname
+ \csname\??mpgraphic#1\endcsname ; % ; is safeguard
+ \fi}
-\def\includeMPgraphic#1%
- {\executeifdefined{\@@MPG#1};} % ; if not found
+\unexpanded\def\meta_enable_include % public
+ {\let\meta_handle_use_graphic \thirdofthreearguments
+ \let\meta_handle_reusable_graphic\thirdofthreearguments}
-\def\enableincludeMPgraphics
- {\let\handleuseMPgraphic \thirdofthreearguments
- \let\handlereusableMPgraphic\thirdofthreearguments}
+%D Drawings (stepwise built):
-\newif\ifMPdrawingdone \MPdrawingdonefalse
+\newif\ifMPdrawingdone \MPdrawingdonefalse
-\def\finalizeMPdrawing
+\unexpanded\def\finalizeMPdrawing
{\MPdrawingdonetrue}
\let\MPdrawingdata\empty
-\newif\ifMPshiftdrawing \MPshiftdrawingfalse
-
-\def\resetMPdrawing
- {\globallet\MPdrawingdata\empty
+\unexpanded\def\resetMPdrawing
+ {\global\let\MPdrawingdata\empty
\global\MPdrawingdonefalse}
-\def\pushMPdrawing
+\unexpanded\def\pushMPdrawing
{\globalpushmacro\MPdrawingdata
- \globallet\MPdrawingdata\empty}
+ \global\let\MPdrawingdata\empty}
-\def\popMPdrawing
+\unexpanded\def\popMPdrawing
{\globalpopmacro\MPdrawingdata}
-\def\getMPdrawing
+\unexpanded\def\getMPdrawing
{\ifMPdrawingdone
- \expandafter\processMPgraphic\expandafter{\MPdrawingdata}% is this expansion still needed?
+ \expandafter\meta_process_graphic\expandafter{\MPdrawingdata}% is this expansion still needed?
\fi}
\def\startMPdrawing
- {\dosingleempty\dostartMPdrawing}
+ {\dosingleempty\meta_start_drawing}
-\long\def\dostartMPdrawing[#1]#2\stopMPdrawing
+\def\meta_start_drawing[#1]#2\stopMPdrawing
{\relax
\bgroup
- \enableincludeMPgraphics
- \presetMPdefinitions % in case #2 has measures
- \doifelse{#1}{-}{\convertargument#2\to\asciia}{\long\def\asciia{#2}}%
- \long\xdef\MPdrawingdata{\MPdrawingdata\asciia}%
+ \meta_enable_include
+ \meta_preset_definitions % in case #2 has measures
+ \doifelse{#1}{-}{\convertargument#2\to\asciia}{\def\asciia{#2}}%
+ \xdef\MPdrawingdata{\MPdrawingdata\asciia}%
\egroup}
\let\stopMPdrawing\relax
-\long\def\MPdrawing#1%
+\def\MPdrawing#1%
{\relax
\bgroup
- \enableincludeMPgraphics
- \presetMPdefinitions
- \long\xdef\MPdrawingdata{\MPdrawingdata#1}%
+ \meta_enable_include
+ \meta_preset_definitions
+ \xdef\MPdrawingdata{\MPdrawingdata#1}%
\egroup}
-\let\stopMPclip\relax
+\unexpanded\def\startMPclip#1#2\stopMPclip % todo: store at the lua end or just store less
+ {\setgvalue{\??mpclip#1}{#2}}
-\long\def\startMPclip#1#2\stopMPclip % todo: store at the lua end or just store less
- {\long\setgvalue{MPC:#1}{#2}}
+\let\stopMPclip\relax
-\def\grabMPclippath#1#2#3#4#5% #5 is alternative
+\unexpanded\def\meta_grab_clip_path#1#2#3#4% #4 is alternative (called in backend code)
{\begingroup
- \edef\width {#3\space}\let\overlaywidth \width
- \edef\height{#4\space}\let\overlayheight\height
- \ifcsname MPC:#1\endcsname
- \dostartcurrentMPgraphic
+ \edef\width {#2\space}\let\overlaywidth \width
+ \edef\height{#3\space}\let\overlayheight\height
+ \ifcsname\??mpclip#1\endcsname
+ \meta_start_current_graphic
\xdef\MPclippath{\normalexpanded{\noexpand\ctxlua{metapost.theclippath(
- "\currentMPgraphicinstance",
- "\currentMPgraphicformat",
- \!!bs\getvalue{MPC:#1}\!!es,
- \!!bs\currentMPinitializations\!!es,
- \!!bs\currentMPpreamble\!!es
+ "\currentMPinstance",
+ "\currentMPformat",
+ \!!bs\getvalue{\??mpclip#1}\!!es,
+ \!!bs\meta_flush_current_initializations\!!es,
+ \!!bs\meta_flush_current_preamble\!!es
)}}}%
- \dostopcurrentMPgraphic
- \ifx\MPclippath\empty\xdef\MPclippath{#5}\fi
+ \meta_stop_current_graphic
+ \ifx\MPclippath\empty
+ \xdef\MPclippath{#4}%
+ \fi
\else
- \xdef\MPclippath{#5}%
+ \xdef\MPclippath{#4}%
\fi
- % #2 : method is obsolete, only pdf now, we can always
- % gsub the result to ps
\endgroup}
-%D Next we will use these support macros.
-
-\startMPextensions
- if unknown context_tool: input mp-tool; fi;
- if unknown context_spec: input mp-spec; fi;
- if unknown context_grph: input mp-grph; fi;
-\stopMPextensions
-
%D Since we want lables to follow the document settings, we
%D also set the font related variables.
+\unexpanded\def\MPfontsizehskip#1%
+ {\dontleavehmode
+ \begingroup
+ \definedfont[#1]%
+ \hskip\cldcontext{fonts.hashes.parameters[font.current()].designsize}sp\relax
+ \endgroup}
+
\startMPinitializations % scale is not yet ok
defaultfont:="\truefontname{Regular}";
defaultscale:=\the\bodyfontsize/10pt;
@@ -297,26 +323,13 @@
defaultfont:="rm-lmtt10";
\stopMPinitializations
-%D A signal that we're in combines \CONTEXT||\METAFUN mode:
+%D A signal that we're in combined \CONTEXT||\METAFUN mode:
\startMPextensions
string contextversion;
contextversion:="\contextversion";
\stopMPextensions
-%D Some safeguards:
-%D
-%D \starttyping
-%D \appendtoks \cleanupfeatures \to \everyMPgraphic
-%D \stoptyping
-%D
-%D No, we don't want that (else we loose UTF etc).
-
-%D Another one:
-
-\prependtoks \MPstaticgraphictrue \to \everyoverlay
-\prependtoks \MPstaticgraphictrue \to \everypagebody
-
%D \macros
%D {setupMPvariables}
%D
@@ -331,43 +344,102 @@
%D \setupMPvariables[meta:button][size=20pt]
%D \stoptyping
-\def\@@meta{meta:}
+% \startlines
+% \def\xxx{\lineheight} \doprepareMPvariable{xxx} \xxx
+% \def\xxx{2pt} \doprepareMPvariable{xxx} \xxx
+% \def\xxx{2} \doprepareMPvariable{xxx} \xxx
+% \def\xxx{\scratchcounter} \doprepareMPvariable{xxx} \xxx
+% \def\xxx{red} \doprepareMPvariable{xxx} \xxx
+% \def\xxx{0.4} \doprepareMPvariable{xxx} \xxx
+% \stoplines
+
+% currently the inheritance of backgrounds does not work and
+% we might drop it anyway (too messy)
+
+\newbox\b_meta_variable_box
+
+\let \currentmpvariableclass \empty
+\let \m_meta_current_variable \empty
+\let \m_meta_current_variable_template\empty
+
+\def \meta_prepare_variable_default {\MPcolor{black}} % just to be sure we use a color but ...
+\edef\meta_unknown_variable_template {\??gv:\s!unknown}
+
+\letvalue{\??gv:\s!unknown}\empty
\unexpanded\def\setupMPvariables
- {\dodoubleempty\dosetupMPvariables}
+ {\dodoubleempty\meta_setup_variables}
-\def\dosetupMPvariables[#1][#2]%
+\def\meta_setup_variables[#1][#2]%
{\ifsecondargument
- \getrawparameters[#1:][#2]% brr, todo: [\@@meta#1:]
+ \getrawparameters[\??gv#1:][#2]%
\else
- \getrawparameters[\@@meta][#1]%
+ \getrawparameters[\??gv:][#1]%
+ \fi}
+
+\unexpanded\def\presetMPvariable
+ {\dodoubleargument\meta_preset_variable}
+
+\def\meta_preset_variable[#1][#2=#3]%
+ {\ifcsname\??gv#1:#2\endcsname \else
+ \setvalue{\??gv#1:#2}{#3}%
\fi}
-\let\@@framed\s!unknown
+\def\MPrawvar#1#2% no checking
+ {\csname\??gv#1:#2\endcsname}
-\def\MPvariable#1%
- {\csname
- \ifcsname\@@framed\@@meta#1\endcsname\@@framed\fi\@@meta#1%
- \endcsname}
+\def\MPvariable#1% todo: could be a framed chain
+ {\csname\??gv\currentmpvariableclass:#1\endcsname}
-\let\MPvar\MPvariable
+\unexpanded\def\useMPvariables
+ {\dodoubleargument\meta_use_variables}
-\let\setMPvariables\setupMPvariables
+\def\meta_use_variables[#1][#2]%
+ {\edef\currentmpvariableclass{#1}%
+ \meta_prepare_variables{#2}}
-\def\MPrawvar#1#2{\csname#1:#2\endcsname}
+\unexpanded\def\meta_prepare_variables#1%
+ {\processcommalist[#1]\meta_prepare_variable}
-\def\presetMPvariable
- {\dodoubleargument\dopresetMPvariable}
+\unexpanded\def\meta_prepare_variable#1%
+ {\edef\m_meta_current_variable_template
+ {\??gv\currentmpvariableclass:#1}%
+ \edef\m_meta_current_variable
+ {\csname\ifcsname\m_meta_current_variable_template\endcsname
+ \m_meta_current_variable_template\else\meta_unknown_variable_template
+ \fi\endcsname}%
+ \ifx\m_meta_current_variable\empty
+ \expandafter\meta_prepare_variable_nop
+ \else
+ \expandafter\meta_prepare_variable_yes
+ \fi}
-\def\dopresetMPvariable[#1][#2=#3]%
- {\ifcsname#1:#2\endcsname\else\setvalue{#1:#2}{#3}\fi}
+\def\meta_prepare_variable_nop
+ {\expandafter \let\csname\m_meta_current_variable_template\endcsname\meta_prepare_variable_default}
-\def\useMPvariables
- {\dodoubleargument\douseMPvariables}
+\def\meta_prepare_variable_color
+ {\expandafter\edef\csname\m_meta_current_variable_template\endcsname{\MPcolor\m_meta_current_variable}}
-\def\douseMPvariables[#1][#2]%
- {\def\@@meta{#1:}%
- \prepareMPvariables{#2}}
+\def\meta_prepare_variable_number
+ {\expandafter\edef\csname\m_meta_current_variable_template\endcsname{\number\m_meta_current_variable}}% also accepts 0.number
+
+\def\meta_prepare_variable_dimension
+ {\expandafter\edef\csname\m_meta_current_variable_template\endcsname{\the\dimexpr\m_meta_current_variable}}
+
+\def\meta_prepare_variable_yes
+ {\defconvertedcommand\ascii\m_meta_current_variable % otherwise problems
+ \doifcolorelse \ascii % with 2\bodyfontsize
+ {\meta_prepare_variable_color}
+ {\begingroup
+ \setbox\b_meta_variable_box\hbox{\scratchdimen\m_meta_current_variable sp}%
+ \ifzeropt\wd\b_meta_variable_box
+ \endgroup\meta_prepare_variable_number
+ \else
+ \endgroup\meta_prepare_variable_dimension
+ \fi}}
+
+\let\MPvar \MPvariable
+\let\setMPvariables\setupMPvariables
%D \macros
%D {startuniqueMPgraphic, uniqueMPgraphic}
@@ -405,165 +477,161 @@
%D \uniqueMPgraphic{meta:hash}{gap=10pt,angle=30}
%D \stoptyping
-\newcount \MPobjectcounter
-\newbox \MPgraphicbox
-\newconstant\MPboxmode
+\newcount\c_meta_object_counter
+\newbox \b_meta_graphic
-\def\doobeyMPboxdepth % mode = 1
- {\setbox\MPgraphicbox\hbox{\hskip\MPllx\onebasepoint\raise\MPlly\onebasepoint\box\MPgraphicbox}}
+% hm, isn't this already done elsewhere?
+
+\unexpanded\def\meta_obey_box_depth
+ {\setbox\b_meta_graphic\hbox\bgroup
+ \raise\MPlly\box\b_meta_graphic
+ \egroup}
-\def\doignoreMPboxdepth % mode = 2
+\unexpanded\def\meta_ignore_box_depth
{\normalexpanded
- {\noexpand\doobeyMPboxdepth
- \wd\MPgraphicbox\the\wd\MPgraphicbox
- \ht\MPgraphicbox\the\ht\MPgraphicbox
- \dp\MPgraphicbox\the\dp\MPgraphicbox}}
-
-\def\obeyMPboxdepth {\MPboxmode\plusone}
-\def\ignoreMPboxdepth{\MPboxmode\plustwo}
-\def\normalMPboxdepth{\MPboxmode\zerocount}
-
-% compatibility hack:
-
-\let\MPshiftdrawingtrue \ignoreMPboxdepth
-\let\MPshiftdrawingfalse\normalMPboxdepth
-
-\unexpanded\def\placeMPgraphic
- {\ifcase\MPboxmode
- \or % 1
- \doobeyMPboxdepth
- \or % 2
- \doignoreMPboxdepth
- \fi
- \box\MPgraphicbox}
+ {\meta_obey_box_depth % hence the \unexpanded
+ \wd\b_meta_graphic\the\wd\b_meta_graphic
+ \ht\b_meta_graphic\the\ht\b_meta_graphic
+ \dp\b_meta_graphic\the\dp\b_meta_graphic}}
+
+\unexpanded\def\meta_obey_box_origin
+ {\setbox\b_meta_graphic\hbox\bgroup
+ \hskip\MPllx\raise\MPlly\box\b_meta_graphic
+ \egroup}
+
+\unexpanded\def\obeyMPboxdepth {\let\meta_relocate_box\meta_obey_box_depth }
+\unexpanded\def\ignoreMPboxdepth{\let\meta_relocate_box\meta_ignore_box_depth}
+\unexpanded\def\obeyMPboxorigin {\let\meta_relocate_box\meta_obey_box_origin }
+\unexpanded\def\normalMPboxdepth{\let\meta_relocate_box\relax }
+
+\let\meta_relocate_box\relax
-\def\reuseMPbox#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}%
+\unexpanded\def\placeMPgraphic % the converter also displaces so in fact we revert
+ {\meta_relocate_box
+ \box\b_meta_graphic}
+
+\unexpanded\def\meta_reuse_box#1#2#3#4#5% space delimiting would save some tokens
+ {\MPllx#2\MPlly#3\MPurx#4\MPury#5%
\hbox{\forcecolorhack\getobject{MP}{#1}}} % else no proper color intent
-\long\def\handleuniqueMPgraphic#1#2#3%
- {\begingroup
- \def\@@meta{#1:}%
+\def\meta_handle_unique_graphic#1#2#3% when there are too many, we can store data at the lua end, although,
+ {\begingroup % when there are that many they're probably not that unique anyway
+ \edef\currentmpvariableclass{#1}%
\extendMPoverlaystamp{#2}% incl prepare
- \ifcsname\@@MPG\overlaystamp:#1\endcsname\else
- \enableincludeMPgraphics % redundant
- \global\advance\MPobjectcounter\plusone
- \setobject{MP}{\number\MPobjectcounter}\hbox{\processMPgraphic{#3}}% was vbox, graphic must end up as hbox
- \setxvalue{\@@MPG\overlaystamp:#1}{\noexpand\reuseMPbox{\number\MPobjectcounter}{\MPllx}{\MPlly}{\MPurx}{\MPury}}%
+ \ifcsname\??mpgraphic\overlaystamp:#1\endcsname\else
+ \meta_enable_include % redundant
+ \global\advance\c_meta_object_counter\plusone
+ \setobject{MP}{\number\c_meta_object_counter}\hbox{\meta_process_graphic{#3}}% was vbox, graphic must end up as hbox
+ \setxvalue{\??mpgraphic\overlaystamp:#1}{\meta_reuse_box{\number\c_meta_object_counter}{\the\MPllx}{\the\MPlly}{\the\MPurx}{\the\MPury}}%
\fi
- \getvalue{\@@MPG\overlaystamp:#1}%
+ \getvalue{\??mpgraphic\overlaystamp:#1}%
\endgroup}
-\long\unexpanded\def\startuniqueMPgraphic
- {\dodoublegroupempty\dostartuniqueMPgraphic}
+\unexpanded\def\startuniqueMPgraphic
+ {\dodoublegroupempty\meta_start_unique_graphic}
+
+\def\meta_start_unique_graphic#1#2#3\stopuniqueMPgraphic
+ {\setgvalue{\??mpgraphic#1}{\meta_handle_unique_graphic{#1}{#2}{#3}}}
-\long\def\dostartuniqueMPgraphic#1#2#3\stopuniqueMPgraphic%
- {\long\setgvalue{\@@MPG#1}{\handleuniqueMPgraphic{#1}{#2}{#3}}}
+\let\stopuniqueMPgraphic\relax
\unexpanded\def\uniqueMPgraphic
- {\dodoublegroupempty\douniqueMPgraphic}
+ {\dodoublegroupempty\meta_unique_graphic}
-\def\douniqueMPgraphic#1#2%
- {\beginMPgraphicgroup{#1}%
+\def\meta_unique_graphic#1#2%
+ {\meta_begin_graphic_group{#1}%
\setupMPvariables[\currentMPgraphicname][#2]%
- \getvalue{\@@MPG\currentMPgraphicname}\empty
- \endMPgraphicgroup}
+ \getvalue{\??mpgraphic\currentMPgraphicname}\empty
+ \meta_end_graphic_group}
-\let\stopuniqueMPcode \relax % so that we can use it in \expanded
-
-\long\def\handleuseMPgraphic#1#2#3%
+\def\meta_handle_use_graphic#1#2#3%
{\begingroup
- \def\@@meta{#1:}%
- \prepareMPvariables{#2}%
- \enableincludeMPgraphics % redundant
- \processMPgraphic{#3}%
+ \edef\currentmpvariableclass{#1}%
+ \meta_prepare_variables{#2}%
+ \meta_enable_include % redundant
+ \meta_process_graphic{#3}%
\endgroup}
-\long\unexpanded\def\startuseMPgraphic
- {\dodoublegroupempty\dostartuseMPgraphic}
+\unexpanded\def\startuseMPgraphic
+ {\dodoublegroupempty\meta_start_use_graphic}
+
+\def\meta_start_use_graphic#1#2#3\stopuseMPgraphic
+ {\setgvalue{\??mpgraphic#1}{\meta_handle_use_graphic{#1}{#2}{#3}}}
-\long\def\dostartuseMPgraphic#1#2#3\stopuseMPgraphic
- {\long\setgvalue{\@@MPG#1}{\handleuseMPgraphic{#1}{#2}{#3}}}
+\let\stopuseMPgraphic\relax
-\long\unexpanded\def\startusableMPgraphic % redundant but handy
- {\dodoublegroupempty\dostartusableMPgraphic}
+\unexpanded\def\startusableMPgraphic % redundant but handy
+ {\dodoublegroupempty\meta_start_usable_graphic}
-\long\def\dostartusableMPgraphic#1#2#3\stopusableMPgraphic
- {\long\setgvalue{\@@MPG#1}{\handleuseMPgraphic{#1}{#2}{#3}}}
+\def\meta_start_usable_graphic#1#2#3\stopusableMPgraphic
+ {\setgvalue{\??mpgraphic#1}{\meta_handle_use_graphic{#1}{#2}{#3}}}
-\let\stopuseMPgraphic \relax % so that we can use it in \expanded
-\let\stopusableMPgraphic \relax % so that we can use it in \expanded
+\let\stopusableMPgraphic\relax
-\long\def\handlereusableMPgraphic#1#2#3%
+\def\meta_handle_reusable_graphic#1#2#3%
{\begingroup
- \def\@@meta{#1:}%
- \prepareMPvariables{#2}%
- \enableincludeMPgraphics % redundant
- \global\advance\MPobjectcounter\plusone
- \setobject{MP}{\number\MPobjectcounter}\hbox{\processMPgraphic{#3}}% was vbox, graphic must end up as hbox
- \setxvalue{\@@MPG#1}{\noexpand\reuseMPbox{\number\MPobjectcounter}{\MPllx}{\MPlly}{\MPurx}{\MPury}}%
- \getvalue{\@@MPG#1}%
+ \edef\currentmpvariableclass{#1}%
+ \meta_prepare_variables{#2}%
+ \meta_enable_include % redundant
+ \global\advance\c_meta_object_counter\plusone
+ \setobject{MP}{\number\c_meta_object_counter}\hbox{\meta_process_graphic{#3}}% was vbox, graphic must end up as hbox
+ \setxvalue{\??mpgraphic#1}{\meta_reuse_box{\number\c_meta_object_counter}{\the\MPllx}{\the\MPlly}{\the\MPurx}{\the\MPury}}%
+ \getvalue{\??mpgraphic#1}%
\endgroup}
-\long\unexpanded\def\startreusableMPgraphic
- {\dodoublegroupempty\dostartreusableMPgraphic}
+\unexpanded\def\startreusableMPgraphic
+ {\dodoublegroupempty\meta_start_reusable_graphic}
-\long\def\dostartreusableMPgraphic#1#2#3\stopreusableMPgraphic
- {\long\setgvalue{\@@MPG#1}{\handlereusableMPgraphic{#1}{#2}{#3}}}
+\def\meta_start_reusable_graphic#1#2#3\stopreusableMPgraphic
+ {\setgvalue{\??mpgraphic#1}{\meta_handle_reusable_graphic{#1}{#2}{#3}}}
-\let\stopreusableMPgraphic \relax % so that we can use it in \expanded
+\let\stopreusableMPgraphic\relax
\unexpanded\def\useMPgraphic
- {\dodoublegroupempty\douseMPgraphic}
+ {\dodoublegroupempty\meta_use_graphic}
-\def\douseMPgraphic#1#2%
- {\beginMPgraphicgroup{#1}%
+\def\meta_use_graphic#1#2%
+ {\meta_begin_graphic_group{#1}%
\doifsomething{#2}{\setupMPvariables[\currentMPgraphicname][#2]}%
- \getvalue{\@@MPG\currentMPgraphicname}\empty
- \endMPgraphicgroup}
+ \getvalue{\??mpgraphic\currentMPgraphicname}\empty
+ \meta_end_graphic_group}
\let\reuseMPgraphic \useMPgraphic % we can save a setup here if needed
\let\reusableMPgraphic\reuseMPgraphic % we can save a setup here if needed
-\let\stopuseMPcode \relax % so that we can use it in \expanded
-\let\stopusableMPcode \relax % so that we can use it in \expanded
-\let\stopreusableMPcode \relax % so that we can use it in \expanded
-\let\stopuniqueMPcode \relax % so that we can use it in \expanded
-
-\def\enableincludeMPgraphics
- {\let\handleuseMPgraphic \thirdofthreearguments
- \let\handlereusableMPgraphic\thirdofthreearguments}
+\unexpanded\def\meta_enable_include
+ {\let\meta_handle_use_graphic \thirdofthreearguments
+ \let\meta_handle_reusable_graphic\thirdofthreearguments}
%D \macros
%D {startuniqueMPpagegraphic,uniqueMPpagegraphic}
%D
%D Experimental.
-\def\MPpageprefix{\doifoddpageelse oe:}
+\def\m_meta_page_prefix{\doifoddpageelse oe}
\def\overlaypagestamp
- {\MPpageprefix\overlaywidth:\overlayheight:\overlaydepth:\MPcolor\overlaycolor:\MPcolor\overlaylinecolor}
+ {\m_meta_page_prefix:\overlaywidth:\overlayheight:\overlaydepth:\MPcolor\overlaycolor:\MPcolor\overlaylinecolor}
+
+\unexpanded\def\startuniqueMPpagegraphic
+ {\dodoublegroupempty\meta_start_unique_page_graphic}
-\long\unexpanded\def\startuniqueMPpagegraphic
- {\dodoublegroupempty\dostartuniqueMPpagegraphic}
+\def\meta_start_unique_page_graphic#1#2#3\stopuniqueMPpagegraphic % inefficient, double storage
+ {\setgvalue{\??mpgraphic o:#1}{\meta_handle_unique_graphic{o:#1}{#2}{#3}}% % but these also keep the state
+ \setgvalue{\??mpgraphic e:#1}{\meta_handle_unique_graphic{e:#1}{#2}{#3}}} % and meaning will be redefined
-\long\def\dostartuniqueMPpagegraphic#1#2#3\stopuniqueMPpagegraphic
- {\long\setgvalue{\@@MPG o:#1}{\handleuniqueMPgraphic{o:#1}{#2}{#3}}%
- \long\setgvalue{\@@MPG e:#1}{\handleuniqueMPgraphic{e:#1}{#2}{#3}}}
+\let\stopuniqueMPpagegraphic\relax
\unexpanded\def\uniqueMPpagegraphic
- {\dodoublegroupempty\douniqueMPpagegraphic}
+ {\dodoublegroupempty\meta_unique_page_graphic}
-\def\douniqueMPpagegraphic#1#2%
- {\beginMPgraphicgroup{#1}%
+\def\meta_unique_page_graphic#1#2%
+ {\meta_begin_graphic_group{#1}%
\let\overlaystamp\overlaypagestamp
- \setupMPvariables[\MPpageprefix\currentMPgraphicname][#2]% prefix is new here
- \getvalue{\@@MPG\MPpageprefix\currentMPgraphicname}{}%
- \endMPgraphicgroup}
-
+ \setupMPvariables[\m_meta_page_prefix:\currentMPgraphicname][#2]% prefix is new here
+ \getvalue{\??mpgraphic\m_meta_page_prefix:\currentMPgraphicname}{}%
+ \meta_end_graphic_group}
+
%D One way of defining a stamp is:
%D
%D \starttyping
@@ -576,59 +644,23 @@
%D Since we need to feed \METAPOST\ with expanded dimensions,
%D we introduce a dedicated expansion engine.
-\def\prepareMPvariable#1%
- {\ifcsname\@@framed\@@meta#1\endcsname
- \doprepareMPvariable{\@@framed\@@meta#1}%
- \else
- \doprepareMPvariable{\@@meta#1}%
- \fi}
-
-% \startlines
-% \def\xxx{\lineheight} \doprepareMPvariable{xxx} \xxx
-% \def\xxx{2pt} \doprepareMPvariable{xxx} \xxx
-% \def\xxx{2} \doprepareMPvariable{xxx} \xxx
-% \def\xxx{\scratchcounter} \doprepareMPvariable{xxx} \xxx
-% \def\xxx{red} \doprepareMPvariable{xxx} \xxx
-% \def\xxx{0.4} \doprepareMPvariable{xxx} \xxx
-% \stoplines
-
-\def\doprepareMPvariable#1%
- {\edef\theMPvariable{\getvalue{#1}}%
- \doifelsenothing\theMPvariable
- {\setevalue{#1}{\MPcolor{black}}}
- {\defconvertedcommand\ascii\theMPvariable % otherwise problems
- \doifcolorelse \ascii % with 2\bodyfontsize
- {\setevalue{#1}{\MPcolor\theMPvariable}}
- {% can be aux macro
- \setbox\scratchbox\hbox{\scratchdimen\theMPvariable sp}%
- \ifdim\wd\scratchbox=\zeropoint
- % \scratchcounter\theMPvariable
- % \setevalue{#1}{\the\scratchcounter}%
- % also accepts 0.number :
- \setevalue{#1}{\number\theMPvariable}%
- \else
- \scratchdimen\theMPvariable
- \setevalue{#1}{\the\scratchdimen}%
- \fi}}}
-
%D We redefine \type {\extendMPoverlaystamp} to preprocess
-%D variables using \type {\prepareMPvariable}.
-
-\def\doextendMPoverlaystamp#1%
- {\prepareMPvariable{#1}%
- \edef\overlaystamp{\overlaystamp:\MPvariable{#1}}}
+%D variables using \type {\meta_prepare_variable}.
-\def\extendMPoverlaystamp#1%
- {\processcommalist[#1]\doextendMPoverlaystamp}
+\unexpanded\def\extendMPoverlaystamp#1%
+ {\processcommalist[#1]\meta_extend_overlay_stamp}
-\def\prepareMPvariables#1%
- {\processcommalist[#1]\prepareMPvariable}
+\def\meta_extend_overlay_stamp#1%
+ {\meta_prepare_variable{#1}%
+ \edef\overlaystamp{\overlaystamp:\MPvariable{#1}}}
%D \macros
%D {MPdatafile}
%D
%D We redefine a macro from \type {supp-mps.tex}:
+% This will change ...
+
\def\MPdataMPDfile{\jobname-mpgraph.mpd}
\def\MPdataMPOfile{\jobname-mpgraph.mpo}
\def\MPdataMPYfile{\jobname-mpgraph.mpy}
@@ -640,7 +672,7 @@
def data_mpy_file = "\MPdataMPYfile" enddef ;
\stopMPextensions
-\def\getMPdata
+\unexpanded\def\getMPdata
{\let\MPdata\secondoftwoarguments
\startreadingfile
% \startnointerference % no, else we need to do all data global
@@ -648,37 +680,24 @@
% \stopnointerference
\stopreadingfile}
-%D For the moment, the next one is a private macro:
-
-\def\processMPbuffer
- {\dosingleempty\doprocessMPbuffer}
-
-\def\doprocessMPbuffer[#1]%
- {\doifelsenothing{#1}
- {\dodoprocessMPbuffer{\jobname}}
- {\dodoprocessMPbuffer{#1}}}
+% We need this trick because we need to make sure that the tex scanner
+% sees newlines and does not quit. Also, we do need to flush the buffer
+% under a normal catcode regime in order to expand embedded tex macros.
+% As usual with buffers, \type {#1} can be a list.
-% we need to go via a toks because we have no multiline print in
-% luatex (i.e. tex.sprint does not interpret lines) and therefore
-% omits all after a comment token
+\unexpanded\def\processMPbuffer
+ {\dosingleempty\meta_process_buffer}
-\newtoks\mpbuffertoks
+\def\meta_process_buffer[#1]%
+ {\meta_begin_graphic_group{#1}%
+ \meta_process_graphic{\ctxcommand{feedback("\currentMPgraphicname")}}%
+ \meta_end_graphic_group}
-\def\doprocessMPbuffer[#1]%
- {\doifelsenothing{#1}
- {\doprocessMPbuffer[\jobname]}
- {\beginMPgraphicgroup{#1}%
- % we need this trick because tex.sprint does not interprets newlines and the scanner
- % stops at a newline; also, we do need to flush the buffer under a normal catcode
- % regime in order to expand embedded tex macros; #1 can be a list
- \processMPgraphic{\ctxcommand{feedback("\currentMPgraphicname")}}%
- \endMPgraphicgroup}}
+\unexpanded\def\runMPbuffer
+ {\dosingleempty\meta_run_buffer}
-\def\runMPbuffer
- {\dosingleempty\dorunMPbuffer}
-
-\def\dorunMPbuffer[#1]% processing only
- {\startnointerference\doprocessMPbuffer[#1]\stopnointerference}
+\def\meta_run_buffer[#1]% processing only
+ {\startnointerference\meta_process_buffer[#1]\stopnointerference}
%D \macros
%D {startMPenvironment, resetMPenvironment}
@@ -686,25 +705,43 @@
%D In order to synchronize the main \TEX\ run and the runs
%D local to \METAPOST, environments can be passed.
-\ifx\everyMPTEXgraphic\undefined
- \newtoks\everyMPTEXgraphic
-\fi
-
-%D A more general way of passing environments is:
-
-\def\startMPenvironment % second arg gobbles spaces, so that reset gives \emptytoks
- {\dodoubleempty\dostartMPenvironment}
-
-\long\def\dostartMPenvironment[#1][#2]#3\stopMPenvironment
- {\doif{#1}\s!reset\resetMPenvironment % reset mp toks
- \doif{#1}\v!global{#3}% % use in main doc too
- \doif{#1}+{#3}% % use in main doc too
- \ctxlua{metapost.tex.set(\!!bs\detokenize{#3}\!!es)}}
-
-\def\resetMPenvironment
+% \unexpanded\def\startMPenvironment % second arg gobbles spaces, so that reset gives \emptytoks
+% {\dodoubleempty\dostartMPenvironment}
+
+% \def\dostartMPenvironment[#1][#2]#3\stopMPenvironment
+% {\edef\m_meta_option{#1}
+% \ifx\m_meta_option\s!reset
+% \resetMPenvironment % reset mp toks
+% \else\ifx\m_meta_option\v!global
+% #3% % use in main doc too
+% \else\ifx\m_meta_option\!!plustoken
+% #3% % use in main doc too
+% \fi\fi\fi
+% \ctxlua{metapost.tex.set(\!!bs\detokenize{#3}\!!es)}}
+
+\unexpanded\def\startMPenvironment
+ {\begingroup
+ \catcode\endoflineasciicode \ignorecatcode
+ \dosingleempty\dostartMPenvironment}
+
+\def\dostartMPenvironment[#1]#2\stopMPenvironment
+ {\endgroup
+ \edef\m_meta_option{#1}
+ \ifx\m_meta_option\s!reset
+ \resetMPenvironment % reset mp toks
+ \else\ifx\m_meta_option\v!global
+ #2% % use in main doc too
+ \else\ifx\m_meta_option\!!plustoken
+ #2% % use in main doc too
+ \fi\fi\fi
+ \ctxlua{metapost.tex.set(\!!bs\detokenize{#2}\!!es)}}
+
+\let\stopMPenvironment\relax
+
+\unexpanded\def\resetMPenvironment
{\ctxlua{metapost.tex.reset()}}
-\def\useMPenvironmentbuffer[#1]%
+\unexpanded\def\useMPenvironmentbuffer[#1]%
{\ctxlua{metapost.tex.set(buffers.content("#1"))}}
%D This command takes \type {[reset]} as optional
@@ -722,41 +759,45 @@
%D
%D The most simple case:
-\def\startMPcode{\dosinglegroupempty\dostartMPcode}
+\unexpanded\def\startMPcode
+ {\dosinglegroupempty\meta_start_code}
-\def\dostartMPcode
+\def\meta_start_code
{\iffirstargument
- \expandafter\dodostartMPcode
+ \expandafter\meta_start_code_instance
\else
- \expandafter\nodostartMPcode
+ \expandafter\meta_start_code_standard
\fi}
-\def\dodostartMPcode#1#2\stopMPcode
- {\beginMPgraphicgroup{#1::\s!dummy}% name does not matter
- \processMPgraphic{#2}%
- \endMPgraphicgroup}
+\def\meta_start_code_instance#1#2\stopMPcode
+ {\meta_begin_graphic_group{#1::\s!dummy}% name does not matter
+ \meta_enable_include
+ \meta_process_graphic{#2}%
+ \meta_end_graphic_group}
-\def\nodostartMPcode#1#2\stopMPcode
- {\processMPgraphic{#2}}
+\def\meta_start_code_standard#1#2\stopMPcode
+ {\let\currentMPinstance\defaultMPinstance
+ \meta_process_graphic{#2}}
\let\stopMPcode\relax
-\def\MPcode{\dosinglegroupempty\doMPcode}
+\unexpanded\def\MPcode
+ {\dosinglegroupempty\meta_code}
-\def\doMPcode
+\def\meta_code
{\iffirstargument
- \expandafter\dodoMPcode
+ \expandafter\meta_code_instance
\else
- \expandafter\nodoMPcode
+ \expandafter\meta_code_standard
\fi}
-\def\dodoMPcode#1#2%
- {\beginMPgraphicgroup{#1::\s!dummy}% name does not matter
- \processMPgraphic{#2}%
- \endMPgraphicgroup}
+\def\meta_code_instance#1#2%
+ {\meta_begin_graphic_group{#1::\s!dummy}% name does not matter
+ \meta_process_graphic{#2}%
+ \meta_end_graphic_group}
-\def\nodoMPcode#1#2%
- {\processMPgraphic{#2}}
+\def\meta_code_standard#1% #2
+ {\meta_process_graphic}
% a bit nasty (also needed for compatibility:
@@ -766,9 +807,9 @@
% \startMPrun{mprun} input mp-www.mp ; \stopMPrun % instance
% \externalfigure[mprun.4][width=10cm,height=8cm]
-\let\MPruninstance\defaultMPgraphicinstance
+\let\MPruninstance\defaultMPinstance
-\def\useMPrun#1#2% name n
+\unexpanded\def\useMPrun#1#2% name n
{\begingroup
\def\MPaskedfigure{#2}%
\doifelsenothing{#1}
@@ -776,34 +817,17 @@
{\useMPgraphic{#1}}%
\endgroup}
-\def\startMPrun
- {\dosinglegroupempty\dostartMPrun}
+\unexpanded\def\startMPrun
+ {\dosinglegroupempty\meta_start_run}
-\long\def\dostartMPrun#1#2\stopMPrun
+\def\meta_start_run#1#2\stopMPrun
{\iffirstargument
\startuseMPgraphic{#1}#2\stopuseMPgraphic
\else
\startuseMPgraphic{mprun}#2\stopuseMPgraphic
\fi}
-% for old time sake
-
-\def\dostartMPgraphic
- {\iffirstargument
- \expandafter\dodostartMPgraphic
- \else
- \expandafter\nodostartMPgraphic
- \fi}
-
-\def\dodostartMPgraphic#1#2\stopMPgraphic
- {\beginMPgraphicgroup{#1::\s!dummy}% name does not matter
- \processMPgraphic{#2}%
- \endMPgraphicgroup}
-
-\def\nodostartMPgraphic#1#2\stopMPcode
- {\processMPgraphic{#2}}
-
-\let\stopMPcode\relax
+\let\stopMPrun\relax
%D The \type {\resetMPenvironment} is a quick way to erase
%D the token list.
@@ -830,7 +854,7 @@
%D Loading specific \METAPOST\ related definitions is
%D accomplished by:
-\unexpanded\def\useMPlibrary[#1]{\ctxlua{metapost.uselibrary(\!!bs#1\!!es)}}
+\unexpanded\def\useMPlibrary[#1]{\ctxcommand{useMPlibrary(\!!bs#1\!!es)}}
%D \macros
%D {setMPtext, MPtext, MPstring, MPbetex}
@@ -845,34 +869,32 @@
%D \MPbetex {identifier}
%D \stoptyping
-\def\@@MPT{@MPT@}
+\installcorenamespace{mptext}
-\def\forceMPTEXgraphic
- {\long\def\checkMPTEXgraphic##1{\global\MPTEXgraphictrue}}
+\unexpanded\def\setMPtext#1#2% todo : #1 must be made : safe
+ {\defconvertedargument\ascii{#2}%
+ \dodoglobal\letvalue{\??mptext#1}\ascii}
-\def\setMPtext#1#2% todo : #1 must be made : safe
- {%\forceMPTEXgraphic
- \defconvertedargument\ascii{#2}%
- \dodoglobal\letvalue{\@@MPT#1}\ascii}
+\def\MPtext #1{\executeifdefined{\??mptext#1}\empty}
+\def\MPstring#1{"\executeifdefined{\??mptext#1}\empty"}
+\def\MPbetex #1{btex \executeifdefined{\??mptext#1}\empty\space etex}
-\def\MPtext #1{\executeifdefined{\@@MPT#1}\empty}
-\def\MPstring #1{"\executeifdefined{\@@MPT#1}\empty"}
-\def\MPbetex #1{btex \executeifdefined{\@@MPT#1}\empty\space etex}
+%D In order to communicate conveniently with the \TEX\
+%D engine, we introduce some typesetting variables.
-%D Unfortunately \METAPOST\ does not have \CMYK\ support
-%D built in, but by means of specials we can supply the
-%D information needed to handle them naturaly.
+% \setupcolors[state=stop,conversion=never] % quite tricky ... type mismatch
-% \newif\ifMPcmykcolors \MPcmykcolorstrue
-% \newif\ifMPspotcolors \MPspotcolorstrue
+% A dirty trick, ** in colo-ini.lua (mpcolor).
-\startMPinitializations
- cmykcolors:=\ifMPcmykcolors true\else false\fi;
- spotcolors:=\ifMPspotcolors true\else false\fi;
-\stopMPinitializations
+% \def\m_meta_colo_initializations{%
+% OverlayLineColor:=\MPcolor{\overlaylinecolor};
+% OverlayColor:=\MPcolor{\overlaycolor};
+% }
-%D In order to communicate conveniently with the \TEX\
-%D engine, we introduce some typesetting variables.
+\def\m_meta_colo_initializations{%
+ vardef OverlayLineColor=\MPcolor{\overlaylinecolor} enddef;
+ vardef OverlayColor=\MPcolor{\overlaycolor} enddef;
+}
\startMPextensions
color OverlayColor,OverlayLineColor;
@@ -883,9 +905,13 @@
OverlayWidth:=\overlaywidth;
OverlayHeight:=\overlayheight;
OverlayDepth:=\overlayheight;
- OverlayColor:=\MPcolor{\overlaycolor};
OverlayLineWidth:=\overlaylinewidth;
- OverlayLineColor:=\MPcolor{\overlaylinecolor};
+ %
+ \m_meta_colo_initializations
+% OverlayLineColor:=\MPcolor{\overlaylinecolor};
+% OverlayColor:=\MPcolor{\overlaycolor};
+% vardef OverlayLineColor=\MPcolor{\overlaylinecolor} enddef;
+% vardef OverlayColor=\MPcolor{\overlaycolor} enddef;
%
BaseLineSkip:=\the\baselineskip;
LineHeight:=\the\baselineskip;
@@ -911,10 +937,9 @@
\disablecompoundcharacters
\to \everyMPgraphic
-\appendtoks % before color
- %\normalexpanded{\noexpand\definecolor[currentcolor][\currentcolorname]}%
- \doregistercolor{currentcolor}\currentcolorname
-\to \everyMPgraphic
+% \appendtoks % before color, inefficient, replace by low level copy
+% \doregistercolor{currentcolor}\currentcolorname
+% \to \everyMPgraphic
% \color[green]{abc \startMPcode
% fill fullcircle scaled 3cm withoutcolor;
@@ -922,10 +947,6 @@
% fill fullcircle scaled 1cm withcolor \MPcolor{red} ;
% \stopMPcode def}
-% \appendtoks
-% \doactivatecolor\s!black\forcecolorhack % we can also move this to the backend
-% \to \everyMPgraphic
-
\appendtoks
\baselineskip1\baselineskip
\lineheight 1\lineheight
@@ -999,26 +1020,20 @@
%D can occur. One took me over a day to uncover when
%D processing the screen version of the \METAFUN\ manual.
-%D For my eyes only:
+\def\doifelseMPgraphic#1%
+ {\ifcsname\??mpgraphic #1\endcsname \expandafter \firstoftwoarguments \else
+ \ifcsname\??mpgraphic o:#1\endcsname \doubleexpandafter\firstoftwoarguments \else
+ \ifcsname\??mpgraphic e:#1\endcsname \tripleexpandafter\firstoftwoarguments \else
+ \tripleexpandafter\secondoftwoarguments \fi\fi\fi}
-\def\doifelseMPgraphic#1{\doifdefinedelse{\@@MPG#1}}
-
-%D \macros
-%D {startMPcolor}
-
-\long\unexpanded\def\startMPcolor#1\stopMPcolor
- {\writestatus \m!metapost % eventually this placeholder will go away
- {\string\startMPcolor...\stopMPcolor\space is obsolete,\space
- use \string\defineintermediatecolor\space instead}}
-
-\let\stopMPcolor\relax
+\let\doifMPgraphicelse\doifelseMPgraphic
%D New:
\definelayerpreset % no dx,dy - else nasty non-mp placement
[mp]
- [\c!y=-\MPury bp,
- \c!x=\MPllx bp,
+ [\c!y=-\MPury,
+ \c!x=\MPllx,
\c!method=\v!fit]
\definelayer
@@ -1085,38 +1100,27 @@
%D
%D \typebuffer \getbuffer
-\def\usestaticMPfigure
- {\dodoubleempty\dousestaticMPfigure}
-
-\def\dousestaticMPfigure[#1][#2]%
- {\ifsecondargument
- \scale[#2]{\reuseMPgraphic{\@@MPG#1@S@}}%
- \else
- \reuseMPgraphic{\@@MPG#1@S@}%
- \fi}
-
\unexpanded\def\startstaticMPfigure#1#2\stopstaticMPfigure
- {\startreusableMPgraphic{\@@MPG#1@S@}#2\stopreusableMPgraphic}
+ {\startreusableMPgraphic{\??mpstaticgraphic#1}#2\stopreusableMPgraphic}
-\long\unexpanded\def\startstaticMPgraphic
- {\dodoublegroupempty\dostartstaticMPgraphic}
+\unexpanded\def\startstaticMPgraphic
+ {\dodoublegroupempty\meta_start_static_graphic}
-\long\def\dostartstaticMPgraphic#1#2#3\stopstaticMPgraphic
- {\long\setgvalue{\@@MPG#1@S@}{\handlereusableMPgraphic{#1}{#2}{#3}}}
+\def\meta_start_static_graphic#1#2#3\stopstaticMPgraphic
+ {\startreusableMPgraphic{\??mpstaticgraphic#1}{#2}#3\stopreusableMPgraphic}
-%D New:
-
-\newconditional\manyMPspecials % when set to true, > 1000 specials can be used
-
-\settrue \manyMPspecials % per 1/4/2006
-
-\prependtoks
- _special_div_ := 1000\ifconditional\manyMPspecials0\fi ;
-\to \MPextensions
+\let\stopstaticMPfigure \relax
+\let\stopstaticMPgraphic\relax
-%D Needed too.
+\unexpanded\def\usestaticMPfigure
+ {\dodoubleempty\meta_use_static_figure}
-\let\initializeMPgraphics\relax
+\def\meta_use_static_figure[#1][#2]%
+ {\ifsecondargument
+ \scale[#2]{\reuseMPgraphic{\??mpstaticgraphic#1}}%
+ \else
+ \reuseMPgraphic{\??mpstaticgraphic#1}%
+ \fi}
%D Goody for preventing overflows:
@@ -1160,10 +1164,8 @@
\newconstant\MPcolormethod
-% can be faster, just
-
\appendtoks
- \ctxlua{metapost.setoutercolor(\number\MPcolormethod,\number\currentcolormodel,\number\dogetattribute{color},\number\dogetattribute{transparency})}%
+ \ctxlua{metapost.setoutercolor(\number\MPcolormethod,\number\attribute\colormodelattribute,\number\attribute\colorattribute,\number\dogetattribute{transparency})}%
\to \everyMPgraphic
\startMPinitializations
@@ -1175,7 +1177,7 @@
%D
%D Here is a generic setup command:
-\newtoks \everysetupMPgraphics
+\newtoks\everysetupMPgraphics
\unexpanded\def\setupMPgraphics[#1]%
{\getparameters[\??mp][#1]%