diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/meta-ini.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/meta-ini.mkiv | 429 |
1 files changed, 303 insertions, 126 deletions
diff --git a/Master/texmf-dist/tex/context/base/meta-ini.mkiv b/Master/texmf-dist/tex/context/base/meta-ini.mkiv index a62b81ccf3c..00b1da032ab 100644 --- a/Master/texmf-dist/tex/context/base/meta-ini.mkiv +++ b/Master/texmf-dist/tex/context/base/meta-ini.mkiv @@ -4,23 +4,64 @@ %D title=\METAPOST\ Graphics, %D subtitle=Initialization, %D author=Hans Hagen, -%D date=\currentdate, +%D date=\ currentdate, %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 %C details. +% initializations: +% +% - pass settings from tex to mp (delayed expansion) +% - used by context core (and modules) +% - cummulative definitions +% - flushed each graphic +% - can be disabled per instance +% - managed at the tex end +% +% extensions: +% +% - add mp functionality (immediate expansion) +% - cummulative +% - all instances or subset of instances +% - can be disabled per instance +% - managed at the lua/mp end +% - could be managed at the tex end but no real reason and also messy +% +% definitions: +% +% - add mp functionality (delayed expansion) +% - cummulative +% - per instance +% - managed at the tex end +% +% inclusions: +% +% - add mp functionality (delayed expansion) +% - cummulative only when [+] +% - per instance +% - managed at the tex end +% +% order of execution: +% +% definitions +% extensions +% inclusions +% beginfig +% initializations +% graphic +% endfig + +% The instance will be implemented stepwise ... I should redo some code in order to +% make the macros look better than they do now. + \writestatus{loading}{MetaPost Graphics / Initializations} \registerctxluafile{meta-ini}{1.001} \unprotect -\newtoks \t_meta_extensions % mp, once -\newtoks \t_meta_initializations % tex, each -\newtoks \t_meta_userinclusions % mp, user - \newtoks \everyMPgraphic % mp % public or not ? \appendtoks @@ -33,11 +74,16 @@ %installcorenamespace{graphicvariable} % todo \installcorenamespace{mpinstance} -\installcorenamespace{mpinstancetokens} +\installcorenamespace{mpinclusions} +\installcorenamespace{mpdefinitions} \installcorenamespace{mpgraphic} \installcorenamespace{mpstaticgraphic} \installcorenamespace{mpclip} +\newtoks \t_meta_initializations % tex, each +\def \t_meta_inclusions {\csname\??mpinclusions \currentMPinstance\endcsname} % token register +\def \t_meta_definitions {\csname\??mpdefinitions\currentMPinstance\endcsname} % token register + % 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. @@ -46,20 +92,25 @@ {\dosinglegroupempty\meta_start_definitions} \def\meta_start_definitions#1#2\stopMPdefinitions - {\edef\currentMPinstance{#1}% + {\let\m_meta_saved_instance\currentMPinstance + \edef\currentMPinstance{#1}% \ifx\currentMPinstance\empty \let\currentMPinstance\defaultMPinstance \fi - \global\t_meta_instance\expandafter{\the\t_meta_instance#2}} + \global\t_meta_definitions\expandafter{\the\t_meta_definitions#2}% + \let\currentMPinstance\m_meta_saved_instance} \let\stopMPdefinitions\relax -\unexpanded\def\startMPextensions#1\stopMPextensions - {\global\t_meta_extensions\expandafter{\the\t_meta_extensions#1}} +\unexpanded\def\startMPextensions + {\dosinglegroupempty\meta_start_extensions} + +\def\meta_start_extensions#1#2\stopMPextensions % we could use buffers instead + {\ctxlua{metapost.setextensions("#1",\!!bs#2\!!es)}} \let\stopMPextensions\relax -\unexpanded\def\startMPinitializations#1\stopMPinitializations +\unexpanded\def\startMPinitializations#1\stopMPinitializations % for all instances, when enables {\global\t_meta_initializations\expandafter{\the\t_meta_initializations#1}} \let\stopMPinitializations\relax @@ -67,24 +118,42 @@ \unexpanded\def\startMPinclusions {\dosingleempty\meta_start_inclusions} -\def\meta_start_inclusions[#1]#2\stopMPinclusions +\unexpanded\def\meta_start_inclusions[#1]% {\edef\m_meta_option{#1}% + \dosinglegroupempty\meta_start_inclusions_indeed} + +\def\meta_start_inclusions_indeed#1#2\stopMPinclusions + {\let\m_meta_saved_instance\currentMPinstance + \edef\currentMPinstance{#1}% + \ifx\currentMPinstance\empty + \let\currentMPinstance\defaultMPinstance + \fi \ifx\m_meta_option\!!plustoken \else - \global\t_meta_userinclusions\emptytoks + \global\t_meta_inclusions\emptytoks \fi - \global\t_meta_userinclusions\expandafter{\the\t_meta_userinclusions#2}} + \global\t_meta_inclusions\expandafter{\the\t_meta_inclusions#2}% + \let\currentMPinstance\m_meta_saved_instance} \let\stopMPinclusions\relax \unexpanded\def\MPinclusions {\dosingleempty\meta_inclusions} -\def\meta_inclusions[#1]#2% +\def\meta_inclusions[#1]% {\edef\m_meta_option{#1}% + \dosinglegroupempty\meta_inclusions_indeed} + +\def\meta_inclusions_indeed#1#2% + {\let\m_meta_saved_instance\currentMPinstance + \edef\currentMPinstance{#1}% + \ifx\currentMPinstance\empty + \let\currentMPinstance\defaultMPinstance + \fi \ifx\m_meta_option\!!plustoken \else - \global\t_meta_userinclusions\emptytoks + \global\t_meta_inclusions\emptytoks \fi - \global\t_meta_userinclusions\expandafter{\the\t_meta_userinclusions#2}} + \global\t_meta_inclusions\expandafter{\the\t_meta_inclusions#2}% + \let\currentMPinstance\m_meta_saved_instance} \def\meta_preset_definitions {\edef\overlaywidth {\overlaywidth \space}% @@ -93,58 +162,57 @@ \edef\currentwidth {\the\hsize \space}% \edef\currentheight {\the\vsize \space}} -\def\t_meta_instance{\csname\??mpinstancetokens\currentMPinstance\endcsname} % token register - \installcommandhandler \??mpinstance {MPinstance} \??mpinstance \setupMPinstance [\s!format=metafun, \s!extensions=\v!no, \s!initializations=\v!no, + \c!method=\s!default, \c!textstyle=, \c!textcolor=] -% \unexpanded\def\defineMPinstance -% {\dodoubleargument\meta_define_instance} - -% \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]} - \appendtoks - \ifcsname\??mpinstancetokens\currentMPinstance\endcsname \else - \expandafter\newtoks\csname\??mpinstancetokens\currentMPinstance\endcsname + \ifcsname\??mpdefinitions\currentMPinstance\endcsname \else + \expandafter\newtoks\csname\??mpdefinitions\currentMPinstance\endcsname + \fi + \ifcsname\??mpinclusions\currentMPinstance\endcsname \else + \expandafter\newtoks\csname\??mpinclusions\currentMPinstance\endcsname \fi - \t_meta_instance\emptytoks % in case we redefine + \t_meta_definitions\emptytoks % in case we redefine + \t_meta_inclusions \emptytoks % in case we redefine \to \everydefineMPinstance \unexpanded\def\resetMPinstance[#1]% {\writestatus\m!metapost{reset will be implemented when needed}} \def\meta_analyze_graphicname[#1]% - {\meta_analyze_graphicname_indeed[#1::::]} + %{\normalexpanded{\meta_analyze_graphicname_indeed[#1::::]}} + {\normalexpanded{\meta_analyze_graphicname_indeed[#1}::::]} -\def\meta_analyze_graphicname_indeed[#1::#2::#3]% instance :: +\unexpanded\def\meta_analyze_graphicname_indeed[#1::#2::#3]% instance :: {\edef\currentMPgraphicname{#2}% \ifx\currentMPgraphicname\empty \edef\currentMPgraphicname{#1}% \let\currentMPinstance\defaultMPinstance - \else + \else\ifcsname\??mpdefinitions#1\endcsname \edef\currentMPinstance{#1}% - \fi + \else + \let\currentMPinstance\defaultMPinstance + \fi\fi \edef\currentMPformat{\MPinstanceparameter\s!format}} \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] -\defineMPinstance[mprun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes] -\defineMPinstance[metapost][\s!format=mpost] -\defineMPinstance[nofun] [\s!format=mpost] +\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] +\defineMPinstance[doublefun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!double] +\defineMPinstance[decimalfun][\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes,\c!method=\s!decimal] +\defineMPinstance[mprun] [\s!format=metafun,\s!extensions=\v!yes,\s!initializations=\v!yes] +\defineMPinstance[metapost] [\s!format=mpost] +\defineMPinstance[nofun] [\s!format=mpost] -\newconditional\c_meta_include_extensions \newconditional\c_meta_include_initializations \def\meta_begin_graphic_group#1% @@ -157,10 +225,16 @@ \def\MPaskedfigure{false} \def\meta_flush_current_initializations - {\ifconditional\c_meta_include_initializations\the\t_meta_initializations;\fi\theMPrandomseed;} + {\ifconditional\c_meta_include_initializations + \the\t_meta_initializations + \fi + \theMPrandomseed;} -\def\meta_flush_current_preamble - {\ifconditional\c_meta_include_extensions\the\t_meta_extensions;\the\t_meta_userinclusions;\fi\the\t_meta_instance;} +\def\meta_flush_current_inclusions + {\the\t_meta_inclusions} + +\def\meta_flush_current_definitions + {\the\t_meta_definitions} \def\meta_start_current_graphic {\begingroup @@ -168,14 +242,6 @@ \the\everyMPgraphic \meta_preset_definitions \setMPrandomseed % this has to change - % we need to preexpand the token lists - \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 @@ -189,25 +255,62 @@ \useMPinstancestyleandcolor\c!textstyle\c!textcolor} \def\meta_stop_current_graphic - {\global\t_meta_instance\emptytoks + {\global\t_meta_definitions\emptytoks + \global\t_meta_inclusions\emptytoks \endgroup} +\def\meta_process_graphic_start + {\setbox\b_meta_graphic\hbox\bgroup} + +\def\meta_process_graphic_stop + {\egroup + \meta_place_graphic} + +\unexpanded\def\meta_process_graphic_instance#1% + {\edef\currentMPinstance{#1}% + \ifx\currentMPinstance\empty + \let\currentMPinstance\defaultMPinstance + \fi + \edef\currentMPformat{\MPinstanceparameter\s!format}% + \meta_process_graphic} + \unexpanded\def\meta_process_graphic#1% todo: extensions and inclusions outside beginfig {\meta_start_current_graphic \forgetall - \setbox\b_meta_graphic\hbox\bgroup % ; added 20100901 (as in mkii) - \normalexpanded{\noexpand\ctxlua{metapost.graphic( - "\currentMPinstance", - "\currentMPformat", - \!!bs#1;\!!es, - \!!bs\meta_flush_current_initializations;\!!es, - \!!bs\meta_flush_current_preamble;\!!es, - \MPaskedfigure - )}}% - \egroup - \placeMPgraphic + \edef\p_extensions{\MPinstanceparameter\s!extensions}% + \meta_process_graphic_start + \normalexpanded{\noexpand\ctxlua{metapost.graphic { + instance = "\currentMPinstance", + format = "\currentMPformat", + data = \!!bs#1;\!!es, + initializations = \!!bs\meta_flush_current_initializations\!!es, +% useextensions = "\MPinstanceparameter\s!extensions", +\ifx\p_extensions\v!yes + extensions = \!!bs\ctxcommand{getmpextensions("\currentMPinstance")}\!!es, +\fi + inclusions = \!!bs\meta_flush_current_inclusions\!!es, + definitions = \!!bs\meta_flush_current_definitions\!!es, + figure = "\MPaskedfigure", + method = "\MPinstanceparameter\c!method", + }}}% + \meta_process_graphic_stop \meta_stop_current_graphic} +\let\meta_process_graphic_figure_start\relax +\let\meta_process_graphic_figure_stop \relax + +\unexpanded\def\processMPfigurefile#1% special case: obeys beginfig .. endfig and makes pages + {\begingroup + \let\normal_meta_process_graphic_start\meta_process_graphic_start + \let\normal_meta_process_graphic_stop \meta_process_graphic_stop + \let\meta_process_graphic_start\relax + \let\meta_process_graphic_stop \relax + \def\meta_process_graphic_figure_start{\startTEXpage\normal_meta_process_graphic_start}% + \def\meta_process_graphic_figure_stop {\normal_meta_process_graphic_stop\stopTEXpage} + \def\MPaskedfigure{all}% + \meta_process_graphic{input "#1" ;}% + \endgroup} + \newif\ifsetMPrandomseed \setMPrandomseedtrue % false by default \def\setMPrandomseed @@ -286,13 +389,15 @@ \edef\height{#3\space}\let\overlayheight\height \ifcsname\??mpclip#1\endcsname \meta_start_current_graphic - \xdef\MPclippath{\normalexpanded{\noexpand\ctxlua{metapost.theclippath( - "\currentMPinstance", - "\currentMPformat", - \!!bs\getvalue{\??mpclip#1}\!!es, - \!!bs\meta_flush_current_initializations\!!es, - \!!bs\meta_flush_current_preamble\!!es - )}}}% + \xdef\MPclippath{\normalexpanded{\noexpand\ctxlua{metapost.theclippath { + instance = "\currentMPinstance", + format = "\currentMPformat", + data = \!!bs\getvalue{\??mpclip#1}\!!es, + initializations = \!!bs\meta_flush_current_initializations\!!es, + useextensions = "\MPinstanceparameter\s!extensions", + inclusions = \!!bs\meta_flush_current_inclusions\!!es, + method = "\MPinstanceparameter\c!method", + }}}}% \meta_stop_current_graphic \ifx\MPclippath\empty \xdef\MPclippath{#4}% @@ -344,15 +449,10 @@ %D \setupMPvariables[meta:button][size=20pt] %D \stoptyping -% \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 - +% \lineheight 2pt 2 \scratchcounter red 0.4 .5\bodyfontsize +% +% see cont-loc for test code +% % currently the inheritance of backgrounds does not work and % we might drop it anyway (too messy) @@ -362,34 +462,36 @@ \let \m_meta_current_variable \empty \let \m_meta_current_variable_template\empty +\installcorenamespace{graphicvariable} + \def \meta_prepare_variable_default {\MPcolor{black}} % just to be sure we use a color but ... -\edef\meta_unknown_variable_template {\??gv:\s!unknown} +\edef\meta_unknown_variable_template {\??graphicvariable:\s!unknown} -\letvalue{\??gv:\s!unknown}\empty +\letvalue{\??graphicvariable:\s!unknown}\empty \unexpanded\def\setupMPvariables {\dodoubleempty\meta_setup_variables} \def\meta_setup_variables[#1][#2]% {\ifsecondargument - \getrawparameters[\??gv#1:][#2]% + \getrawparameters[\??graphicvariable#1:][#2]% \else - \getrawparameters[\??gv:][#1]% + \getrawparameters[\??graphicvariable:][#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}% + {\ifcsname\??graphicvariable#1:#2\endcsname \else + \setvalue{\??graphicvariable#1:#2}{#3}% \fi} \def\MPrawvar#1#2% no checking - {\csname\??gv#1:#2\endcsname} + {\csname\??graphicvariable#1:#2\endcsname} \def\MPvariable#1% todo: could be a framed chain - {\csname\??gv\currentmpvariableclass:#1\endcsname} + {\csname\??graphicvariable\currentmpvariableclass:#1\endcsname} \unexpanded\def\useMPvariables {\dodoubleargument\meta_use_variables} @@ -403,7 +505,7 @@ \unexpanded\def\meta_prepare_variable#1% {\edef\m_meta_current_variable_template - {\??gv\currentmpvariableclass:#1}% + {\??graphicvariable\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 @@ -414,6 +516,28 @@ \expandafter\meta_prepare_variable_yes \fi} +\unexpanded\def\meta_prepare_instance_variables + {\expandafter\processcommalist\expandafter[\m_meta_instance_variables]\meta_prepare_instance_variable} + +\unexpanded\def\meta_prepare_instance_variable#1% + {\edef\m_meta_current_variable_template + {\??graphicvariable\currentmpvariableclass:#1}% + \edef\m_meta_current_variable + {\csname + \ifcsname\m_meta_current_variable_template\endcsname + \m_meta_current_variable_template + \else\ifcsname\??graphicvariable\currentMPgraphicname:#1\endcsname + \??graphicvariable\currentMPgraphicname:#1% + \else + \meta_unknown_variable_template + \fi\fi + \endcsname}% + \ifx\m_meta_current_variable\empty + \expandafter\meta_prepare_variable_nop + \else + \expandafter\meta_prepare_variable_yes + \fi} + \def\meta_prepare_variable_nop {\expandafter \let\csname\m_meta_current_variable_template\endcsname\meta_prepare_variable_default} @@ -496,7 +620,7 @@ \unexpanded\def\meta_obey_box_origin {\setbox\b_meta_graphic\hbox\bgroup - \hskip\MPllx\raise\MPlly\box\b_meta_graphic + \kern\MPllx\raise\MPlly\box\b_meta_graphic \egroup} \unexpanded\def\obeyMPboxdepth {\let\meta_relocate_box\meta_obey_box_depth } @@ -506,7 +630,7 @@ \let\meta_relocate_box\relax -\unexpanded\def\placeMPgraphic % the converter also displaces so in fact we revert +\unexpanded\def\meta_place_graphic % the converter also displaces so in fact we revert {\meta_relocate_box \box\b_meta_graphic} @@ -530,7 +654,13 @@ \unexpanded\def\startuniqueMPgraphic {\dodoublegroupempty\meta_start_unique_graphic} -\def\meta_start_unique_graphic#1#2#3\stopuniqueMPgraphic +% \def\meta_start_unique_graphic#1#2#3\stopuniqueMPgraphic +% {\setgvalue{\??mpgraphic#1}{\meta_handle_unique_graphic{#1}{#2}{#3}}} + +\def\meta_start_unique_graphic#1% + {\normalexpanded{\meta_start_unique_graphic_indeed{#1}}} + +\unexpanded\def\meta_start_unique_graphic_indeed#1#2#3\stopuniqueMPgraphic {\setgvalue{\??mpgraphic#1}{\meta_handle_unique_graphic{#1}{#2}{#3}}} \let\stopuniqueMPgraphic\relax @@ -540,14 +670,18 @@ \def\meta_unique_graphic#1#2% {\meta_begin_graphic_group{#1}% - \setupMPvariables[\currentMPgraphicname][#2]% - \getvalue{\??mpgraphic\currentMPgraphicname}\empty +% \setupMPvariables[\currentMPgraphicname][#2]% + \setupMPvariables[#1][#2]% + \getvalue{\??mpgraphic#1}\empty \meta_end_graphic_group} \def\meta_handle_use_graphic#1#2#3% {\begingroup \edef\currentmpvariableclass{#1}% - \meta_prepare_variables{#2}% + \edef\m_meta_instance_variables{#2}% + \ifx\m_meta_instance_variables\empty \else + \meta_prepare_instance_variables + \fi \meta_enable_include % redundant \meta_process_graphic{#3}% \endgroup} @@ -555,7 +689,22 @@ \unexpanded\def\startuseMPgraphic {\dodoublegroupempty\meta_start_use_graphic} -\def\meta_start_use_graphic#1#2#3\stopuseMPgraphic +% \def\meta_start_use_graphic#1#2#3\stopuseMPgraphic +% {\setgvalue{\??mpgraphic#1}{\meta_handle_use_graphic{#1}{#2}{#3}}} +% +% better, expansion of #1: +% +% \def\meta_start_use_graphic#1#2#3\stopuseMPgraphic +% %{\setgvalue{\??mpgraphic#1}{\meta_handle_use_graphic{#1}{#2}{#3}}} +% %{\setxvalue{\??mpgraphic#1}{\noexpand\meta_handle_use_graphic{#1}{\normalunexpanded{#2}}{\normalunexpanded{#3}}}} +% {\global\expandafter\gdef\csname\??mpgraphic#1\expandafter\endcsname\expandafter{\expandafter\meta_handle_use_graphic\expandafter{\normalexpanded{#1}}{#2}{#3}}} +% +% cleaner: + +\def\meta_start_use_graphic#1% + {\normalexpanded{\meta_start_use_graphic_indeed{#1}}} + +\unexpanded\def\meta_start_use_graphic_indeed#1#2#3\stopuseMPgraphic {\setgvalue{\??mpgraphic#1}{\meta_handle_use_graphic{#1}{#2}{#3}}} \let\stopuseMPgraphic\relax @@ -563,7 +712,13 @@ \unexpanded\def\startusableMPgraphic % redundant but handy {\dodoublegroupempty\meta_start_usable_graphic} -\def\meta_start_usable_graphic#1#2#3\stopusableMPgraphic +% \def\meta_start_usable_graphic#1#2#3\stopusableMPgraphic +% {\setgvalue{\??mpgraphic#1}{\meta_handle_use_graphic{#1}{#2}{#3}}} + +\def\meta_start_usable_graphic#1% + {\normalexpanded{\meta_start_usable_graphic_indeed{#1}}} + +\unexpanded\def\meta_start_usable_graphic_indeed#1#2#3\stopusableMPgraphic {\setgvalue{\??mpgraphic#1}{\meta_handle_use_graphic{#1}{#2}{#3}}} \let\stopusableMPgraphic\relax @@ -571,7 +726,10 @@ \def\meta_handle_reusable_graphic#1#2#3% {\begingroup \edef\currentmpvariableclass{#1}% - \meta_prepare_variables{#2}% + \edef\m_meta_instance_variables{#2}% + \ifx\m_meta_instance_variables\empty \else + \meta_prepare_instance_variables + \fi \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 @@ -582,7 +740,13 @@ \unexpanded\def\startreusableMPgraphic {\dodoublegroupempty\meta_start_reusable_graphic} -\def\meta_start_reusable_graphic#1#2#3\stopreusableMPgraphic +% \def\meta_start_reusable_graphic#1#2#3\stopreusableMPgraphic +% {\setgvalue{\??mpgraphic#1}{\meta_handle_reusable_graphic{#1}{#2}{#3}}} + +\def\meta_start_reusable_graphic#1% + {\normalexpanded{\meta_start_reusable_graphic_indeed{#1}}} + +\unexpanded\def\meta_start_reusable_graphic_indeed#1#2#3\stopreusableMPgraphic {\setgvalue{\??mpgraphic#1}{\meta_handle_reusable_graphic{#1}{#2}{#3}}} \let\stopreusableMPgraphic\relax @@ -592,8 +756,9 @@ \def\meta_use_graphic#1#2% {\meta_begin_graphic_group{#1}% - \doifsomething{#2}{\setupMPvariables[\currentMPgraphicname][#2]}% - \getvalue{\??mpgraphic\currentMPgraphicname}\empty +% \doifsomething{#2}{\setupMPvariables[\currentMPgraphicname][#2]}% + \doifsomething{#2}{\setupMPvariables[#1][#2]}% + \getvalue{\??mpgraphic#1}\empty \meta_end_graphic_group} \let\reuseMPgraphic \useMPgraphic % we can save a setup here if needed @@ -616,9 +781,16 @@ \unexpanded\def\startuniqueMPpagegraphic {\dodoublegroupempty\meta_start_unique_page_graphic} -\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 +% \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 + +\def\meta_start_unique_page_graphic#1% + {\normalexpanded{\meta_start_unique_page_graphic_indeed{#1}}} + +\unexpanded\def\meta_start_unique_page_graphic_indeed#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 \let\stopuniqueMPpagegraphic\relax @@ -628,8 +800,9 @@ \def\meta_unique_page_graphic#1#2% {\meta_begin_graphic_group{#1}% \let\overlaystamp\overlaypagestamp - \setupMPvariables[\m_meta_page_prefix:\currentMPgraphicname][#2]% prefix is new here - \getvalue{\??mpgraphic\m_meta_page_prefix:\currentMPgraphicname}{}% +% \setupMPvariables[\m_meta_page_prefix:\currentMPgraphicname][#2]% prefix is new here + \setupMPvariables[\m_meta_page_prefix:#1][#2]% prefix is new here + \getvalue{\??mpgraphic\m_meta_page_prefix:#1}{}% \meta_end_graphic_group} %D One way of defining a stamp is: @@ -651,7 +824,7 @@ {\processcommalist[#1]\meta_extend_overlay_stamp} \def\meta_extend_overlay_stamp#1% - {\meta_prepare_variable{#1}% + {\meta_prepare_instance_variable{#1}% \edef\overlaystamp{\overlaystamp:\MPvariable{#1}}} %D \macros @@ -722,9 +895,9 @@ \unexpanded\def\startMPenvironment {\begingroup \catcode\endoflineasciicode \ignorecatcode - \dosingleempty\dostartMPenvironment} + \dosingleempty\meta_start_environment} -\def\dostartMPenvironment[#1]#2\stopMPenvironment +\def\meta_start_environment[#1]#2\stopMPenvironment {\endgroup \edef\m_meta_option{#1} \ifx\m_meta_option\s!reset @@ -770,34 +943,44 @@ \fi} \def\meta_start_code_instance#1#2\stopMPcode - {\meta_begin_graphic_group{#1::\s!dummy}% name does not matter + {\begingroup + \edef\currentMPinstance{#1}% + \let\currentMPgraphicname\empty + \edef\currentMPformat{\MPinstanceparameter\s!format}% \meta_enable_include \meta_process_graphic{#2}% - \meta_end_graphic_group} + \endgroup} \def\meta_start_code_standard#1#2\stopMPcode - {\let\currentMPinstance\defaultMPinstance - \meta_process_graphic{#2}} + {\begingroup + \let\currentMPinstance\defaultMPinstance + \let\currentMPgraphicname\empty + \edef\currentMPformat{\MPinstanceparameter\s!format}% + \meta_process_graphic{#2}% + \endgroup} \let\stopMPcode\relax \unexpanded\def\MPcode - {\dosinglegroupempty\meta_code} + {\dodoublegroupempty\meta_code} \def\meta_code - {\iffirstargument + {\ifsecondargument \expandafter\meta_code_instance \else \expandafter\meta_code_standard \fi} \def\meta_code_instance#1#2% - {\meta_begin_graphic_group{#1::\s!dummy}% name does not matter + {\meta_begin_graphic_group{#1}% + \meta_enable_include \meta_process_graphic{#2}% \meta_end_graphic_group} -\def\meta_code_standard#1% #2 - {\meta_process_graphic} +\def\meta_code_standard#1#2% + {\let\currentMPinstance\defaultMPinstance + \meta_enable_include + \meta_process_graphic{#1}} % a bit nasty (also needed for compatibility: @@ -903,10 +1086,6 @@ OverlayLineWidth:=\overlaylinewidth; % \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; @@ -1172,11 +1351,9 @@ %D %D Here is a generic setup command: -\newtoks\everysetupMPgraphics +\installcorenamespace{MPgraphics} -\unexpanded\def\setupMPgraphics[#1]% - {\getparameters[\??mp][#1]% - \the\everysetupMPgraphics} +\installsetuponlycommandhandler \??MPgraphics {MPgraphics} %D Here we hook in the outer color. When \type {color} is set to \type %D {global} we get the outer color automatically. If you change this @@ -1184,7 +1361,7 @@ %D behave in unexpected ways. \appendtoks - \doifelse\@@mpcolor\v!global{\MPcolormethod\plusone}{\MPcolormethod\zerocount}% + \doifelse{\directMPgraphicsparameter\c!color}\v!global{\MPcolormethod\plusone}{\MPcolormethod\zerocount}% \to \everysetupMPgraphics \setupMPgraphics |