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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to define acronyms via the \def command. I know that the acronym package exists, but that's too much typing (\ac{myacronym} vs. \myacronym).

The problem that I have is that for \def\myacronym{acronym expanded}, it won't have an empty space after it, so I can only use it in front of punctuation. For \def\myacronym{acronym expanded }, I cannot use it before punctuation because it always causes an empty space.

My question is: How can I detect whether punctuation comes after the acronym, so I can dynamically generate a space only if needed. Also, it would be nice to be able to detect whether there is the string ". " before my acronym, so I could make the acronym uppercase dynamically.

I guess this is kind of hard to do since those parameters are not passed to the function, but maybe somebody has an idea.

share|improve this question
Not answering your question, but I tend to use some \myacronym\ text to produce the space when I need to. – Juan A. Navarro Aug 18 '10 at 12:36

If I understand it correctly, the \xspace macro from the xspace package does this.



similar for plain.tex.

share|improve this answer
xspace is the way to go for this, but I've found that it ends up being more confusing than helpful. Once you use it, \myacronym no longer behaves like other control words. For example, \newcommand*\foo{fat orange object\xspace} What if I want to talk about five \foo s? Without the \xspace, that would produce the desired plural. Since it's there, you'll get "...object s". \foo{}s works, but it seems best to not use \xspace for consistency. – TH. Aug 18 '10 at 14:29
@TH: but doesn't \foo s look odd in and of itself? Why not define \foos at the same time as \foo. What if \foo had a funny plural, say "category", then \foos will expand correctly to "categories" whilst \foo s will expand incorrectly to "categorys". Then it does make sense to use \xspace at the end of macros. – Loop Space Aug 24 '10 at 17:06

Use the xspace package, and put \xspace at the end of your definitions.

share|improve this answer

You have gotten the answer to the \def question.

This is just a note.

I used to format acronyms as I go and find that very distracting with long documents. So now while drafting I input acronyms as is (all caps) and at final stage use the text editor to change all of them into the markup I need. It takes about 0.3 second for each chapter and save me from all those extra typings.

BTW, in general I'd recommend the package glossaries for typesetting acronyms.

share|improve this answer

I don't know of any way to look behind to tell whether or not the acronym should be capitalised, but you could fake it. If you define \Myacronym to be the correctly capitalised version then you can use \myacronym or \Myacronym accordingly. Although this isn't quite what you want, it will actually look better when scanning the source text: compare

And so to bed. \Myacronym got up early in the morning.


And so to bed. \myacronym got up early in the morning.

On a quick scan, the eye doesn't recognise the \ and disregards it as noise; thus the small 'm' looks a bit odd on the second one.

share|improve this answer
This is how I do it. – Lev Bishop Aug 18 '10 at 13:13
When is an acronym not capitalized? Are you talking about abbreviations? – Geoff Aug 24 '10 at 16:40
@Geoff: fair point, I always forget which is which. In my defence, the questioner asked about capitalisation and about acronyms so it looks like we're both confused on this issue and so my answer is still relevant to the intended question. – Loop Space Aug 24 '10 at 17:04
Thanks, I was confused! – Geoff Aug 24 '10 at 17:06

Your Answer


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