I am trying to draw MP backgrounds around Python codes ; I want to automatically call some macros before/after the \startpython/\stoppython
pair, so I define another environment to setup/clean. I already used that successfully with my other setups (not with vimtyping environments, but with Lists or TikZ...), but here I get this error :
"tex error > tex error on line 1 in file /opt/context/tex/texmf-context/tex/context/base/mkiv/cont-yes.mkiv: ! TeX capacity exceeded, sorry [input stack size=10000]"
I reproduced this behavior in the MWE below ; is there something I didn't see in the manuals ?
\usemodule[vim]
\definevimtyping[python][
syntax=python
]
%% these are temps, the aim is to add MP background around
\def\startPythonCode{
\startpython
}
\def\stopPythonCode{
\stoppython
}
\starttext
\startpython %% This works, no pb
print("Hello World")
\stoppython
\startPythonCode
print("Hello World") %% pb here : TeX capacity exceeded
\stopPythonCode
\stoptext
Thank you in advance,
======= EDIT ======
As it was asked in the coments, I add the MP background I intend to use :
\startuseMPgraphic{mp:codeFrame}
numeric u,o ; u := 1EmWidth ; o := BodyFontSize;
for i=1 upto nofmultipars :
pair bl, br, ul, ur;
bl := llcorner multipars[i]; br := lrcorner multipars[i];
ul := ulcorner multipars[i]; ur := urcorner multipars[i];
path p;
p := ( bl -- br -- ur -- ul -- cycle ) enlarged (0,0.5u) shifted (0,0);
draw p withpen pencircle scaled 1bp withcolor 0.5 white;
endfor;
\stopuseMPgraphic
\definetextbackground[codeFrameBackground][
mp=mp:codeFrame,
location=always,
leftoffset=1em,rightoffset=1em,
topoffset=0ex,bottomoffset=0ex,
before={},
after={},
level=-2,
]
Thank you in advance,
====== EDIT 2 =======
The before/after
pair, as suggested in DG's answer, does not seem to work with my real environment. Here is a new MWE, closer to my real environment, and which reproduces a "Missing } inserted" error.
In the /home/adrien/Enseignement-physique/tex/context/ConTeXt_adrienLicari_code.tex file :
\usemodule[vim]
%% Backgrounds
\startuseMPgraphic{mp:codeFrame}
numeric u,o ; u := 1EmWidth ; o := BodyFontSize;
for i=1 upto nofmultipars :
pair bl, br, ul, ur;
bl := llcorner multipars[i]; br := lrcorner multipars[i];
ul := ulcorner multipars[i]; ur := urcorner multipars[i];
path p;
p := ( bl -- br -- ur -- ul -- cycle ) enlarged (0,0.5u) shifted (0,0);
draw p withpen pencircle scaled 1bp withcolor 0.5 white;
endfor;
\stopuseMPgraphic
\definetextbackground[codeFrameBackground][
mp=mp:codeFrame,
location=always,
leftoffset=1em,rightoffset=1em,
topoffset=0ex,bottomoffset=0ex,
before={},
after={},
level=-2
]
%% Python
\definevimtyping[python][
syntax=python,
strip=yes,
tab=4,
margin=1em,
left={}, right={},
numbering=yes,
directory=../tmp-vimout/,
before={\startcodeFrameBackground},
after={\stopcodeFrameBackground}
]
In the mwe.tex file :
%% Environnement personnalisé
\usepath[{/home/adrien/Enseignement-physique/tex/context}]
\environment ConTeXt_adrienLicari_code
\starttext
\startpython
print('Hello, world!') # Fonction d'affichage
\stoppython
\stoptext
Thank you in advance,
before=
andafter=
for that? github.com/adityam/filter/blob/master/…