lundi 1 décembre 2014

Delimiting-a-macro-with-itself-chain


Reading this question and the answer of @Werner made me think about if it is possible to have chains of self-delimiting macros like \XX abc \XX def \XX xyz or lets say



\begin{someenv}
\XX abc
\XX def
\XX xyz
\end{someenv}


The original definition will obviously fail here - insufficent number fo \XXs. So, a first step towards an easy redefinition of \XX could be to say



\def\XX#1\XX{do sth with #1\\ \XX}


The problem now is to terminate this chain in an elegant way. A rather rude and not desiderable way is shown in the MWE below.



\documentclass{article}

\def\XX#1\XX{do sth with #1\\ \XX}

\newenvironment{someenv}{\center}{\endcenter}

\def\abc{def}

\begin{document}
\begin{someenv}
\XX xyz
\XX abc
\XX \abc
\let\XX\empty %this is the bad guy that needs to be busted
\end{someenv}
\end{document}




Aucun commentaire:

Enregistrer un commentaire