Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

\aftergroup executes the next token after the end of the current group. Is there a variant, \Vaftergroup{\some\tokens\a\b} that would put \some\tokens\a\b after the current group ends? Of course, one can do \aftergroup\some\aftergroup\tokens\aftergroup\a\aftergroup\b, but when the list is longer, it becomes messy.

This is motivated by an answer that works but is ugly.

share|improve this question
mark wooding's doafter package was designed after he had asked this question some time in the 80s. it's conceivable he did it without benefit of etex (which would have been very new at the time, if it existed at all) – wasteofspace May 14 at 9:21

3 Answers

up vote 10 down vote accepted

In much the same vein as Herbert's answer, a 'pre-built' version of the same idea is provided by the etextools package: see \AfterGroup. I guess that \aftergroup is used rarely enough that this has not been a big demand :-)

share|improve this answer
studying this package will teach me much about the fine points of expansion, I believe :). Thanks for the info! – Bruno Le Floch Jan 2 '11 at 23:24
2  
@Bruno ...or else drive you mad :) – Will Robertson Jan 3 '11 at 2:04
1  
The \AfterGroup macro solves the problem in the way outlined by Herbert, but defining a new global temporary macro each time (via a counter) which is then undefined at use time. – egreg May 14 at 9:21

don't know if this might help.

\documentclass{article}

\def\ta{Hello}
\def\tb{ World. }
\def\tc{How are you?}
%\def\Tokens{\ta\tb\tc}

\begin{document}

\begingroup
\gdef\Tokens{\ta\tb\tc}% or like above with def
\aftergroup\Tokens
\let\ua=\tc
\let\ub=\tb
\let\uc=\ta
\ua\ub\uc---\par
\endgroup

\end{document}
share|improve this answer
2  
Thanks. This is what I ended up doing, but I didn't like the idea of a global temporary variable: bad things can happen before the group is finished. – Bruno Le Floch Jan 2 '11 at 22:55

Below there is an alternative. \Tokens remains local.

\documentclass{article}

\def\ta{Hello}
\def\tb{ World. }
\def\tc{How are you?}
%\def\Tokens{\ta\tb\tc}

\begin{document}

\begingroup
\def\Tokens{\ta\tb\tc}% or like above with def
\let\ua=\tc
\let\ub=\tb
\let\uc=\ta
\ua\ub\uc---\par
\expandafter\endgroup\Tokens

\show\Tokens
\end{document}
share|improve this answer
This requires that you 'know' where the end-of-group is (and is going to be tricky to pull off in box/\halign contexts). Herbert's answer is 'general' in the sense you don't need to know where or how the group is going to end. – Joseph Wright May 14 at 9:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.