[comp.text.tex] Help on LaTeX hacking.

ne201ph@prism.gatech.EDU (Halvorson,Peter J) (01/26/91)

I hope someone can help me with this problem.

I'm writing a technical paper and make frequent reference to leidenfrost
temperature.  I have abbreviated this with:

\newcommand{\tleid}{$ T_{Leid}$}

Now I can just put \tleid in normal text.  The first problem is that this 
will ignore a normal space after \tleid.  If I put a hard space in the 
definition, it wouldn't work if followed by a punctuation mark.  The second
problem is that I would like to be able to use the same command if I'm
already in the math mode ( although I could live with \tleidm or something
similar).

Is the answer obvious to anyone?

Thanks

ne201ph@prism.gatech.EDU (Halvorson,Peter J) (01/27/91)

In article <20376@hydra.gatech.EDU> I write:
>I hope someone can help me with this problem.
>
>I'm writing a technical paper and make frequent reference to leidenfrost
>temperature.  I have abbreviated this with:
>
>\newcommand{\tleid}{$ T_{Leid}$}
>
>Now I can just put \tleid in normal text.  The first problem is that this 
>will ignore a normal space after \tleid.  If I put a hard space in the 
>definition, it wouldn't work if followed by a punctuation mark.  The second
>problem is that I would like to be able to use the same command if I'm
>already in the math mode ( although I could live with \tleidm or something
>similar).
>
>Is the answer obvious to anyone?
>
>Thanks
>

The answer was obvious to at least 5 people so far,

raymond@math.berkeley.edu (Raymond Chen),
guy@phy.duke.edu (Guy Metcalfe),
Kresten Krab Thorup <krab@iesd.auc.dk>,
Laszlo C. Balint <lba@kolvi.hut.fi>,
and allbery@NCoast.ORG (Brandon S. Allbery KB8JRR).

TeX will not treat a command as an ordinary word, I can stick {} after each
use, or a \ if I really want a space after.  I can write it to detect math
mode like this:

\newcommand{\tleid}{\ifmmode T_{Leid}\else$ T_{Leid}$\fi}

Thanks.


-- 
              Peter Halvorson   --    Nuclear Engineering Program
          Georgia Institute of Technology, Atlanta Georgia, 30332
    uucp:    ...!{allegra,amd,hplabs,ut-ngp}!gatech!prism!ne201ph
Internet: ne201ph@prism.gatech.edu  --   peter@fission.gatech.edu

rig@eng.umd.edu (Ronald Greenberg) (01/30/91)

In article <1991Jan29.112220.9742@news.arc.nasa.gov> ogawa@orion.arc.nasa.gov (Arthur Ogawa) writes:
>>> Now I can just put \tleid in normal text.  The first problem is that this
>>> will ignore a normal space after \tleid.  If I put a hard space in the
>>> definition, it wouldn't work if followed by a punctuation mark.  
>
>Invoke the macro with, eg,
>
>put \tleid{} in normal text.
>
>An alternative is 
>
>put \tleid\ in normal text.

Sure, I have several macros that I use this way.  But it is always
annoying that I sometimes forget to put in the extra \ in the all
places where I need a space.  Has somebody got a macro that will put
in a space unless the next character is a punctuation mark?
--

Ron Greenberg		rig@umiacs.umd.edu

grodan@cyklop.nada.kth.se (Mats G L|fdahl) (01/30/91)

In article <1991Jan29.181407.20206@eng.umd.edu> rig@eng.umd.edu (Ronald Greenberg) writes:

   [deleted stuff]
   Sure, I have several macros that I use this way.  But it is always
   annoying that I sometimes forget to put in the extra \ in the all
   places where I need a space.  Has somebody got a macro that will put
   in a space unless the next character is a punctuation mark?
   --

   Ron Greenberg		rig@umiacs.umd.edu

I wrote a macro \AfterMacro, a couple of years ago, that I sometimes
use this in macro packages intended for people with NO TeX 
experience at all. Myself, I think it's better to use the \Tleid\
notation. You can use \AfterMacro in macro definitions, that expands to
abbreviations or names or formulas.



-------------cut-------------------

\def\AfterMacro#1{\if#1,,\else	% Feel free to add more punctuation
                  \if#1..\else  % marks, as you need them.
                  \if#1!!\else
                  \if#1??\else
                  \if#1::\else
                  \if#1;;\else
                  \if#1''\else
                  \if#1))\else
                  \if#1-\-\else % NOTE: '-' epands to '\-'
                  \ #1\fi\fi\fi\fi\fi\fi\fi\fi\fi}

\def\tEx{\TeX\expandafter\AfterMacro}
\def\jon{Jonathan\expandafter\AfterMacro}
\def\Tleid{\ifmmode T_{\rm Leid}\else$T_{\rm Leid}$\expandafter\AfterMacro\fi}


This is how to use \tEx in a sentence, which could also end with \tEx.
This is how to use \jon in a sentence, which could also end with \jon.
\jon's car (owned by \jon) is green. You can use \Tleid (Yes,
\Tleid!!) in the text or in a formula $\Tleid < 2\Tleid$.

\bye


-------------cut-------------------

--
 -----------------------------------------------------------------------------
 Mats Lofdahl, Stockholm Observatory, S-133 36 Saltsjobaden | +46 - 8 16 44 75 
 -----------------------------------------------------------------------------
 Internet: lofdahl@astro.su.se | Bitnet: grodan@sekth | Sunet: royacs::lofdahl
 -----------------------------------------------------------------------------