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.

Most technical writers will immediately see how I'd like to use this. I'm writing a paper about something I'll call That Which Will Be Abbreviated (TWWBA). I'd like to have a macro, \TWWBA{}, that will produce That Which Will Be Abbreviated (TWWBA) the first time it is called, and TWWBA on all following invocations.

Is there a way to do this?

share|improve this question
    
I'd actually like to see a general solution to the problem. Presumably it would be a macro that would be defined to redefine itself on its first usage? –  Seamus Nov 16 '11 at 16:25
    
@Seamus: Either that or a macro that changes a flag on first use that tells it to use the other text on the following uses. I slightly changed the title of this question to make it acronym-specific, hoping that users who don't know glossaries or acronym would get help here. I'd recommend looking for a general solution in another question? Just to keep the purposes separate -- acronyms vs. general usage. –  doncherry Nov 16 '11 at 16:34
    
Wow, thanks for the great response and the edits. I'm all set in terms of the article I'm writing, but another answer that explained how this could be done with conditionals would be great, if only for completeness. –  Colin K Nov 16 '11 at 18:15
add comment

3 Answers

up vote 21 down vote accepted

I recommend using glossaries or acronym (with a preference for the former). For limited use one can also define them directly:

\newcommand{\newacronym}[3]{\newcommand#1{#3 (#2)\gdef#1{#2}}}

Thus

\newacronym{\TWWBA}{TWWBA}{That Which Will Be Abbreviated}

will allow to write \TWBBA and get

That Which Will Be Abbreviated (TWWBA)

the first time and

TWWBA

thereafter. This is roughly what the two packages do (but they do better): the first execution of the command redefines itself. It's necessary to use low level commands, because the higher level LaTeX commands are unable to make global definitions of commands.

share|improve this answer
    
I'm marking this as the answer because it answers the question exactly as I asked it as well as pointing me to acronym and glossary, which are both excellent. –  Colin K Nov 16 '11 at 18:12
    
@ColinK You shouldn't. –  egreg Nov 16 '11 at 18:27
    
Why not? It includes the basics of the other answers, and tells me what I wanted to know about writing macros. –  Colin K Nov 16 '11 at 20:37
    
This is the most comprehensive answer, so it gets my vote! –  qubyte Nov 16 '11 at 23:59
add comment
\documentclass{article}
\usepackage{glossaries}
\newacronym{twwba}{TWWBA}{That Which Will Be Abbreviated}
\begin{document}
text \gls{twwba}


more text \gls{twwba} 
\end{document}
share|improve this answer
add comment

This is handled nicely by the acronym package. I recommend it.

EDIT

As mentioned by egreg in the comment below, the glossaries package is particularly useful for this too.

share|improve this answer
    
Also the glossaries package has this feature and is more customizable. –  egreg Nov 16 '11 at 16:03
    
Indeed it does. I used that one for my thesis and was very pleased with the result. –  qubyte Nov 16 '11 at 16:04
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.