[comp.text] TeX macro for Nuclear Physics symbols

rbr4@uhura.cc.rochester.edu (Roland Roberts) (01/20/89)

I'm trying to write a macro that will output nuclear physics symbols
as shown in the summary line, namely a superscript mass number
followed by the letter abbreviation.  What I use now is 

\def\Ni#1 {\ifmmode {}^{#1}\rm{Ni} \else ${}^{#1}\rm{Ni}$ \fi}

which is fine when typing a symbol in the middle of text, e.g.

"... one of the interesting properties of \Ni64 lies in ..."

but is a nuissance when writing a reaction in the standard form

"... We have examined the reaction \Ni64(\O16,\O18)\Ni62 at ..."

Note that TeX chokes on the above line (the \O macro is defined the
same way as the \Ni).  Admittedly, the extra spaces that have to be
added to the above line for it to work are only a nuissance, but I'm
wondering if there is a way to avoid needing them.  

I'm thinking of playing around with changing the catcode for the
digits to be able to distinguish them from the `(' and `)', but am not
sure if it will get me anywhere.  Any help is appreciated!
 -- 
Roland Roberts                      BITNET: roberts@uornsrl
  Nuclear Structure Research Lab  INTERNET: rbr4@uhura.cc.rochester.edu
  271 East River Road                 UUCP: rochester!ur-cc!rbr4
  Rochester, NY  14267                AT&T: (716) 275-8962

rjchen@phoenix.Princeton.EDU (Raymond Juimong Chen) (01/20/89)

% Gosh, this was a fun challenge!  Here's my shot.

\catcode`@=11 % make macros that should remain inaccessible inaccessible.

\newtoks\@lement % remember the element.
\def\Ni{\@lement={Ni}\g@tisotope}
\def\O{\@lement={O}\g@tisotope}
% You get the idea.

% We now pull a really dirty trick.
% Since it is hard to grab a number from the input stream, we ask
% \TeX\ to do it for us...  The trick is to store the number into
% a scratch \count register, then wake up.  We do this via an
% \afterassignment.

% the unpleasant side-effect is that one space token is eaten up
% after the number.  This can be gotten-around by collecting the
% digits explicitly (as a previous attempt at this did), but
% it's just so much less elegant.  (You have to write a macro
% which recognizes digits, and then play games with \futurelet
% the way the \prim@s macros do in plain.tex.  It's ugly.)
% So instead, if you want a space,
% you'll have to put it in yourself.  (A previous attempt put the
% space in explicitly, but that was just too yucky, since very
% often, a symbol will appear at the end of a clause.)  This shouldn't
% be too much of a hassle, since you're already used to putting
% explicit spaces after control sequences, right?

% the token \b@ck will tell us how to get back to whatever
% we were doing before it all started.  That is, it will be \relax
% if we were already in math mode, otherwise it will be $.

% Okay, dive in!
% We put the isotope number into \count0, then ask \g@tis@tope to
% finish up.

\def\g@tisotope{\let\b@ck\relax\ifmmode\else$\let\b@ck$\fi
\afterassignment\g@tis@tope\count0=}

% ah, so now we can do what needs to be done.  It's all easy sailing
% from here.

\def\g@tis@tope{{}^{\number\count0}{\rm\the\@lement}\b@ck}

\catcode`@=12 % yay.

% Now, let's test it.
% Note:  I'm a mathematician, not a nuclear physicist.  This will be nonsense,
% but it illustrates the macros.

% note the explicit space here -----vv
It is important to notice that \Ni19\ reacts violently when
exposed to \O23, a very rare isotope.
The compound~\Ni19\O23, a very important \Ni19-derived compound,
is relatively inert.  Moreover, the complex
$\Ni19(\O23_3\O16_2)_3$ is kind of yuccky-tasting.

\end

Courtesy of your local TeXacker (who finished his last final exam 
a few hours ago, yay!)...
--
Raymond Chen	UUCP: ...allegra!princeton!{phoenix|pucc}!rjchen
		BITNET: rjchen@phoenix.UUCP, rjchen@pucc
		ARPA: rjchen@phoenix.PRINCETON.EDU, rjchen@pucc.PRINCETON.EDU
-- 
Raymond Chen	UUCP: ...allegra!princeton!{phoenix|pucc}!rjchen
		BITNET: rjchen@phoenix.UUCP, rjchen@pucc
		ARPA: rjchen@phoenix.PRINCETON.EDU, rjchen@pucc.PRINCETON.EDU
"Say something, please!  ('Yes' would be best.)" - The Doctor

rjchen@phoenix.Princeton.EDU (Raymond Juimong Chen) (01/21/89)

Aigh!  Bug patch.  I shouldn't have used \count0 outside of grouping,
since it messes up the page number.  (Thud thud.  Sound of head banging
against desk.)  It's safe to use it, though, since the output routine
will not get activated while \count0 contains a funny value.

@x
\def\g@tisotope{\let\b@ck\relax\ifmmode\else$\let\b@ck$\fi
\afterassignment\g@tis@tope\count0=}
@y
\def\g@tisotope{\let\b@ck\relax\ifmmode\else$\let\b@ck$\fi
\bgroup\afterassignment\g@tis@tope\count0=}
@z

@x
\def\g@tis@tope{{}^{\number\count0}{\rm\the\@lement}\b@ck}
@y
\def\g@tis@tope{{}^{\number\count0}\egroup{\rm\the\@lement}\b@ck}
@z

% Is anybody out there?
-- 
Raymond Chen	UUCP: ...allegra!princeton!{phoenix|pucc}!rjchen
		BITNET: rjchen@phoenix.UUCP, rjchen@pucc
		ARPA: rjchen@phoenix.PRINCETON.EDU, rjchen@pucc.PRINCETON.EDU
"Say something, please!  ('Yes' would be best.)" - The Doctor

tbrakitz@phoenix.Princeton.EDU (Triantaphyllos Byron Rakitzis) (01/22/89)

In article <5652@phoenix.Princeton.EDU> rjchen@phoenix.Princeton.EDU (Raymond Juimong Chen) writes:
>Aigh!  Bug patch.  I shouldn't have used \count0 outside of grouping,
>since it messes up the page number.  (Thud thud.  Sound of head banging
>against desk.)  It's safe to use it, though, since the output routine
>will not get activated while \count0 contains a funny value.
>

Hey, Ray, why didn't you use \newcount, or whatever the sequence is
which assigns you a new register. You didn't have to use count0, you
know. There are only 255 more count registers at your disposal.

Cheers.

-- 
"I've found it much easier on my ulcer to stop trying to clean out the Augean
stables of the net." 
				Chuq Von Rospach
Byron Rakitzis. (tbrakitz@phoenix.princeton.edu ---- tbrakitz@pucc.bitnet)