MPenvironment \def gives "Parameters must be numbered consecutively"
This test file (beta 2006.09.28): ============ 1.tex ============================ \starttext \startMPenvironment \def\2#1#2{\vbox{\halign{\hfil##\hfil\cr #1\cr #2\cr}}} \stopMPenvironment \startreusableMPgraphic{fig} label(btex sun etex, origin); \stopreusableMPgraphic \reuseMPgraphic{fig} \stoptext ======================================== fails with the error: ! Parameters must be numbered consecutively. <to be read again> ## l.44 \global \loadfontfileoncetrue \def \2## 1##2{\vbox {\halign {\hfil ####\... 1-mpgraph.mp gets this figure definition: beginfig(1); verbatimtex \global \loadfontfileoncetrue \def \2##1##2{\vbox {\halign {\hfil ####\hfil \cr ##1\cr ##2\cr }}} etex; label(btex sun etex , origin); ; endfig; So the parameters in the definition are being doubled up by one of the transformations that inserts the verbatimtex..etex block. By the way, should the verbatimtex..etex block go outside the beginfig..endfig, as it would in a standalone MP file? If only for efficiency rather than MP reparsing it with each beginfig. -Sanjoy `A society of sheep must in time beget a government of wolves.' -- Bertrand de Jouvenal
Sanjoy Mahajan wrote:
This test file (beta 2006.09.28):
============ 1.tex ============================ \starttext \startMPenvironment \def\2#1#2{\vbox{\halign{\hfil##\hfil\cr #1\cr #2\cr}}} \stopMPenvironment
\startreusableMPgraphic{fig} label(btex sun etex, origin); \stopreusableMPgraphic
\reuseMPgraphic{fig}
\stoptext ========================================
fails with the error:
! Parameters must be numbered consecutively. <to be read again> ## l.44 \global \loadfontfileoncetrue \def \2## 1##2{\vbox {\halign {\hfil ####\...
1-mpgraph.mp gets this figure definition:
beginfig(1); verbatimtex \global \loadfontfileoncetrue \def \2##1##2{\vbox {\halign {\hfil ####\hfil \cr ##1\cr ##2\cr }}} etex; label(btex sun etex , origin); ; endfig;
environments are saved in macros, therefore you end up in an argument mess \starttext \startbuffer[mp] \def\2#1#2{\vbox{\halign{\hfil##\hfil\cr #1\cr #2\cr}}} \stopbuffer \def\useMPenvironmentbuffer[#1]% {\expanded{\startMPenvironment\noexpand\readfile{\TEXbufferfile{\jobname}}{}{}}\stopMPenvironment} \useMPenvironmentbuffer[mp] \startreusableMPgraphic{fig} label(btex sun etex, origin); \stopreusableMPgraphic \reuseMPgraphic{fig} \stoptext works ok ; maybe i should add that command to the core but anyhow you can wikify it
So the parameters in the definition are being doubled up by one of the transformations that inserts the verbatimtex..etex block. By the way, should the verbatimtex..etex block go outside the beginfig..endfig, as it would in a standalone MP file? If only for efficiency rather than MP reparsing it with each beginfig.
depends, if you process them runtime, it does not matter, if you process graphics between runs, they may be some cary over effects, although the btex/etex snippets are grouped Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
works ok ; maybe i should add that command to the core but anyhow you can wikify it
Using btex..etex is becoming complex with all the interactions, so instead I wikified an example of converting from btex..etex to \sometxt -- preaching what I am trying to practice. Instead I'll use the MPenvironment just for font and size switching (e.g. to use a different size for figures than for main text).
(i didn't expect users to cook up all kind of commands in environments; when i have to do that, I normally put them in an environment and load that in the mp graphic (since one loads tex files there)
I hadn't thought of that. Do you mean something like (which I couldn't get to compile): \starttext \startreusableMPgraphic{fig} \def\hello{hhh} % perhaps in an environment file label(\sometxt{\hello}, origin); \stopreusableMPgraphic \reuseMPgraphic{fig} \stoptext -Sanjoy `Never underestimate the evil of which men of power are capable.' --Bertrand Russell, _War Crimes in Vietnam_, chapter 1.
On Fri, 29 Sep 2006, Hans Hagen wrote:
environments are saved in macros, therefore you end up in an argument mess
\starttext
\startbuffer[mp] \def\2#1#2{\vbox{\halign{\hfil##\hfil\cr #1\cr #2\cr}}} \stopbuffer
\def\useMPenvironmentbuffer[#1]%
{\expanded{\startMPenvironment\noexpand\readfile{\TEXbufferfile{\jobname}}{}{}}\stopMPenvironment}
Shouldn't that be \readfile{\TEXbufferfile{#1}?
\useMPenvironmentbuffer[mp]
\startreusableMPgraphic{fig} label(btex sun etex, origin);
If you try label(btex \2{one}{two} etex, origin) ; it does not work.
\stopreusableMPgraphic
\reuseMPgraphic{fig}
\stoptext
works ok ; maybe i should add that command to the core but anyhow you can wikify it
How about defining something like \startMPTEX .... \stopMPTEX which writes everything to a file jobname-mp, so that the user does not need to be aware that he/she has to create a buffer with the name mp. However, using \startbuffer[mp] is fragile as the user can also define a buffer with the name mp. How about a different/ less common word, say verbtaimtex? Aditya
On 9/29/06, Sanjoy Mahajan wrote:
This test file (beta 2006.09.28):
============ 1.tex ============================ \starttext \startMPenvironment \def\2#1#2{\vbox{\halign{\hfil##\hfil\cr #1\cr #2\cr}}} \stopMPenvironment
A lesson that I learned while trying to implement a few functions for gnuplot: never try to do tricky stuff like definitions inside MPenvironement, because it is parsed and changed slightly. I would also prefer if definitions and other commands inside MPenvironement would work as they were supposed to, but exactly this was one reason more why I like \sometxt so much now. You can create a definition anywhere in your TeX document and then use it inside \sometxt: \def\a{abc} \starttext \startMPcode label(\sometxt{\a},origin); \stopMPcode \stoptext Would that kind of approach satisfy your needs? (that being just another point of view from what Hans pointed out; Hans's approach might also be useful; although I admit that I will soon start mixing up all the different MP commands: MPinclusions, MPextensions, preambles, environment ... ) Mojca PS: that should go into another thread and is not that urgent since I found an ugly workaround, but anyway: is there a chance to access dimensions such as PageWidth, OverlayWidth ... and others inside MPextensions/inclusions? OverlayWidth is defined just behind the extensions/inclusions, which basically means that I can use it inside a graphic, but not inside macros defined in MPextensions. Any remedy for that?
never try to do tricky stuff like definitions inside MPenvironement, because it is parsed and changed slightly.
I'm learning that lesson too. Another one: "don't use btex..etex instead use \sometxt". So I now try to use the MPenvironment only for font and size switching (e.g. if I want the figures to be in a smaller font). I wikified a small example of converting to \sometxt: http://wiki.contextgarden.net/Mpgraphic#startMPenvironment. It's probably not in the right place on the wiki though.
\def\a{abc}
\starttext \startMPcode label(\sometxt{\a},origin); \stopMPcode \stoptext
Would that kind of approach satisfy your needs?
It would. I've used this sed script to help me convert my standalone metapost files: sed 's/btex (.*) etex/\\sometxt{\1}/' < standalone.mp But for the next chapter's figures, I'll write a python script that will do the other transformations: e.g. turn each beginfig into \startstaticMPfigure -- or is it \startstaticMPgraphic? I always have to check, hence I'll put it in a script and have *it* remember. I know that metafun was made for integrating backgrounds and the like, not for standalone figures, so it may seem strange to convert all of one's standalone figures into metafun figures and place them in the .tex source file. But I like having the source for the standalone figures in the same file near their use: it's figure--text integration (one theme of Tufte's books), done in the source file. -Sanjoy `Never underestimate the evil of which men of power are capable.' --Bertrand Russell, _War Crimes in Vietnam_, chapter 1.
participants (4)
-
Aditya Mahajan
-
Hans Hagen
-
Mojca Miklavec
-
Sanjoy Mahajan