[XeTeX] Need some input about \newcommand to create alias
Maxim Cournoyer
maxim.cournoyer at gmail.com
Sat Nov 28 06:28:43 CET 2009
Ok, as a small recapitulation :
1) Using \codeux\, as proposed by Joe Pleso, does work.
2) Adding a pair of { } such as in \newcommand\{codeux}{CO$_2${ } does
work. Do not forget the space between the accolades. :)
3) For chemistry specific stuff, Wilfred's recommendation of chchem
package seems like a much more elegant solution!
Thank you all for these great suggestions!
See you around,
Maxim
Le vendredi 27 novembre 2009 à 20:58 -0800, Wilfred van Rooijen a
écrit :
> 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 <amunn at msu.edu> wrote:
>
> > From: Alan Munn <amunn at msu.edu>
> > Subject: Re: [XeTeX] Need some input about \newcommand to create alias
> > To: "Unicode-based TeX for Mac OS X and other platforms" <xetex at tug.org>
> > 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.
> >
> > http://www.tex.ac.uk/cgi-bin/texfaq2html?introduction=yes
> >
> >
> > -- Alan Munn
> >
> > amunn at msu.edu
> > 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.
> http://mail.promotions.yahoo.com/newdomains/aa/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/xetex/attachments/20091128/d902f244/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: face-smile.png
Type: image/png
Size: 873 bytes
Desc: not available
URL: <http://tug.org/pipermail/xetex/attachments/20091128/d902f244/attachment-0001.png>
More information about the XeTeX
mailing list