\documentclass{report}
\RequirePackage{xspace}
\newenvironment{ENV}{}{\xspace}
\newcommand{\CMD}{\begin{ENV}hello\end{ENV}}
\begin{document}
1 \CMD 2 \CMD! 3
\end{document}
I expected it to print:
1 hello 2 hello! 3
but instead, there is a space before the '!':
1 hello 2 hello ! 3
Can someone explain this to me?
\xspace works by looking ahead to the next token that would be
processed. If it appears in the `ending' argument to an environment
definition, when it gets executed it will see some part of the
environment wrap-up code, decide it's not a punctuation character, and
insert the space.
The document says that \xspace is for use in the argument of a
command, *not* in the arguments of an environment: what you need is
\newcommand{\CMD}{hello\xspace}
--
Robin (Campaign for Real Radio 3) Fairbairns r...@cl.cam.ac.uk
U of Cambridge Computer Lab, Pembroke St, Cambridge CB2 3QG, UK
Home page: http://www.cl.cam.ac.uk/users/rf/robin.html
Thanks for the explanation. I see how using
'\newcommand{\CMD}{hello\xspace}' would work, but I am really trying to
design an _environment_ that would append a space at the end, the way
\xspace would. I am an experienced programmer, but relatively new to TeX
and LaTex. Can you give me a few pointers on how to go about designing
such an environment?
There is no reason to. \xspace might be needed because spaces after
commands are ignored, but spaces after } are preserved just fine.
In fact, \end contains a system of *deleting* following spaces.
>I am an experienced programmer, but relatively new to TeX
>and LaTex. Can you give me a few pointers on how to go about designing
>such an environment?
Look at the definition of \end in LaTeX; it is in ltmiscen.dtx.
Donald Arseneau as...@triumf.ca
Maybe I'm going about this wrong. Let me explain exactly what I'm trying
to accomplish. I have to typeset a document that will contain a number
of abbreviations, in the form of commands. For instance, suppose the
abbreviations \a and \b should respectively expand to 'A' and 'B'. The
expansion of 'The \a and the \b, etc.' will not, as you know, have a
space after the \a unless we use \a\. If at all possible, I would rather
not have to impose that extra backslash to the author of the document.
'\newcommand{\a}{A\xspace}' would be fine if there was not also the
requirement that the expansion may need to be, for example, in a font
different from the surrounding text. I would like to be able to
experiment different fonts for _all_ these abbreviations at once. So I
thought I might get away with something like
\newcommand{\a}{\begin{TrySomeFont}A\end{TrySomeFont}}
\newcommand{\b}{\begin{TrySomeFont}B\end{TrySomeFont}}
...
\newenvironment{TrySomeFont}{...set the font here...}{...\xspace}
But, alas, that doesn't work.
I will take a look at ltmiscen.dtx (I have to download it first), but if
you have any ideas on how I can solve my problem, short of cutting and
pasting any font changes into each abbreviation definition :-(, I would
appreciate them.
Thanks - Luc
Maybe I'm misunderstanding your question, but why not do this:
\newcommand{\trymyfonts}[1]{{\bfseries#1}}
\newcommand{\myabbrev}[1]{\trymyfonts{#1}\xspace}
\newcommand{\a}{\myabbrev{A}}
\newcommand{\b}{\myabbrev{B}}
Where you can change \bfseries to any sequence of font-selection
commands that you want. For example, for italics-sans-serif, you could
use "\sffamily\itshape". And you can define any new abbreviations you
want with the \myabbrev command.
Then, when you want to change the font of your abbreviations, you just
change the definition of \trymyfonts, and voila.
Cheers,
--Diego
\,|,/
~(o o)~
/===================oOO--(_)--OOo===========================================\
Greg Salomons | Email: smo...@eeyore.phy.queensu.ca
Dept. of Physics | Phone: (613) 545-6000 ext. 7375
Queen's University | Fax: (613) 545-6463
Kingston, Ont. Canada, | Disclaimer: I accept no responsibility for the
K7L-3N6 | fact that my employer may not share my opinions.
\===========================================================================/
|/ \|
(_) (_)