<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.28.1">
</HEAD>
<BODY>
Ok, as a small recapitulation :<BR>
<BR>
1) Using \codeux\, as proposed by Joe Pleso, does work.<BR>
<BR>
2) Adding a pair of { } such as in \newcommand\{codeux}{CO$_2${ } does work. Do not forget the space between the accolades. <IMG SRC="cid:1259385598.7908.17.camel@maxim-desktop" ALIGN="middle" ALT=":)" BORDER="0"><BR>
<BR>
3) For chemistry specific stuff, <TT><FONT COLOR="#1a1a1a">Wilfred</FONT></TT>'s recommendation of chchem package seems like a much more elegant solution!<BR>
<BR>
Thank you all for these great suggestions!<BR>
<BR>
See you around,<BR>
<BR>
Maxim<BR>
<BR>
<BR>
Le vendredi 27 novembre 2009 à 20:58 -0800, Wilfred van Rooijen a écrit :
<BLOCKQUOTE TYPE=CITE>
<PRE>
An even better solution:
\usepackage[version=3]{mhchem}
Then simply type \ce{CO2} :-))
The package mhchem is one of the most helpful packages for chemistry-related typesetting. If you do a lot of scientific typesetting, also see the SIunits package - it is fantastic!
Wilfred
PS your solution of \codeux or similar is deficient in the sense that it uses a math environment to set the '2', which may cause strange spacing (characters are not spaced in the usual way in a math environment. To see what I mean, type eff and $eff$ and observe the ugly result). Also the math environment may use a different font from the normal text, so that the '2' would look different from for instance the page number. It depends on taste whether you want that or not. A better option would be to use CO$_\text{2}$, or maybe CO$_\mathrm{2}$. The mhchem package does something similar, but also has an automatic detection, so that you can type \ce{C2H5OH} and get what you want.
--- On Sat, 28/11/09, Alan Munn <<A HREF="mailto:amunn@msu.edu">amunn@msu.edu</A>> wrote:
> From: Alan Munn <<A HREF="mailto:amunn@msu.edu">amunn@msu.edu</A>>
> Subject: Re: [XeTeX] Need some input about \newcommand to create alias
> To: "Unicode-based TeX for Mac OS X and other platforms" <<A HREF="mailto:xetex@tug.org">xetex@tug.org</A>>
> Date: Saturday, 28 November, 2009, 1:38 PM
> At 11:23 PM -0500 11/27/09, Maxim
> Cournoyer wrote:
> > Dear XeTeX fidels,
> >
> > In my first document written with XeTeX, I wanted to
> do an alias for the abbreviation CO_2 (carbon dioxyde), but
> had two difficulties.
> >
> > My first one was to try to use something like this :
> %\newcommand{\co2}{CO$_2$}
> > The problem was that it seems we cannot use "numbers"
> in the command name, such as the '2' in \co2. Is there a way
> to circumvent this?
>
> Not really. Numbers aren't allowed in macro names.
>
> >
> > Another weird issue I ran into was, after
> changing \co2 to something more wordy as \codeux, my
> actual replacement would delete all trailing space. Let me
> explain by an example :
> > ex : The traffic in developed nations is the
> cause to an average of 26% of t
sults : The traffic in developed nations is
> the cause to an average of 26% of the CO_2emissions.
> >
> > Note the lack of a space character between the _2
> subscript and emissions. Using CO$_2$ straight in my text
> solved the problem, surprisingly. Is there an explanation
> for this?
>
> Yes, commands gobble the spaces after them.
>
> > What should I do to prevent this from
> happening?
>
> Two solutions:
>
> \newcommand{codeux}{CO$_2${}}
>
> or
>
> \usepackage{xspace}
> \newcommand{codeux}{CO$_2$\xspace}
>
>
> Alan
>
> P.S. Neither of these questions is actually related to
> xetex. You might want to check the TeX FAQ, and get a
> good introduction to LaTeX. Or post your questions to
> the comp.text.tex newsgroup.
>
> <A HREF="http://www.tex.ac.uk/cgi-bin/texfaq2html?introduction=yes">http://www.tex.ac.uk/cgi-bin/texfaq2html?introduction=yes</A>
>
>
> -- Alan Munn
>
> <A HREF="mailto:amunn@msu.edu">amunn@msu.edu</A>
> Department of Linguistics
> and Germanic, Slavic, Asian and African
> Languages Tel.
> 517-355-7491
> Michigan State University, East Lansing MI 48824
> USA Fax 517-432-2736
>
Get your preferred Email name!
Now you can @ymail.com and @rocketmail.com.
<A HREF="http://mail.promotions.yahoo.com/newdomains/aa/">http://mail.promotions.yahoo.com/newdomains/aa/</A>
</PRE>
</BLOCKQUOTE>
<BR>
</BODY>
</HTML>