Take the 2-minute tour ×
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.

1 Answer 1

up vote 14 down vote accepted

An easy way is to just nullify the macro within the body so that the next time it does not have an effect if it is called again via either

\global\let\FirstTime\relax%

or

\global\def\FirstTime{}%

enter image description here

As per David Carlisle's comment, we need to add a \global to ensure that the macro is nullified for subsequent use in the case the first use was within a group (as per updated test case below)

References:

Code:

\documentclass{article}

\newcommand*{\FirstTime}{%
    \gdef\FirstTime{}%
    \textbf{FirstTime: }%
}%


\begin{document}
\begingroup
    abcd \FirstTime defg \FirstTime xys
\endgroup

    abcd \FirstTime defg \FirstTime xys

    abcd \FirstTime defg \FirstTime xys
\end{document}
share|improve this answer
    
Credit also goes to user "Stephen" who posted a similar answer to an earlier question of mine. –  Lover of Structure Feb 23 '13 at 21:41
add comment

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.