Typesetting HEP particle names in LaTeX

For anyone who's ever tried to write a large particle physics document (say, to take a flippant example, a PhD thesis) and who's unfeasibly picky about both the niceties of typesetting and the "right way" to construct macro languages, the difficulty of typesetting particle names has probably been a constant niggle. Okay, so I'm probably just describing myself here but in the interests of self-importance I'll continue anyway!

So, I hear you ask, what's up with the particle names thing? Well, here's a few factoids about particle name typesetting as it should be done:

Yes, I expect I am one of the very few people who cares about these conventions! Anyway, a while ago Michel Goosens and Eric van Herwijnen at CERN defined a "Particle Entity Notation" code for specifying particles and supplied a LaTeX style file called pennames.sty to define the most common ones. However, this suffers from both the boldness and italic problems: the supplied macros are always upright and of normal weight (as opposed to bold).

The boldness problem resides in the fact that the best command for boldening in LaTeX (\bm from the bm.sty package) is not automatically called when a math environment is entered while in bold context. This leads to problems in e.g. LaTeX section and chapter titles where, unless a second boldened title is specified, the particle name will be in a lighter weight than the surrounding text. An ever more insidious problem is that if you use a math symbol in a first-level header in e.g. "book" class, it will appear with different weighting in the Table of Contents, in the text and in the page header! You can't deal with this explicitly because you can only specify one alternative (short/long) form of the title! Aaargh.

A solution

Well, this bothered me for a while, not least because having to supply a bold and a non-bold version of my section and chapter titles is really manky from a programmer's point of view! So I've written a couple of macros which conditionally handle boldnes, italic-ness and then combine the two into a single particle name macro which also handles the sub- and super-scripting properly. So, without further ado, here's the command for conditionally typesetting maths in bold (thanks to Viet-Trung Luu on comp.text.tex for supplying me with this and hence inspiring the rest of the solution):

%% Use the bold symbol if reqd for math fonts \DeclareRobustCommand{\maybebm}[1]{% \def\boldname{b}% \def\boldexname{bx}% \ifx\f@series\boldname% \boldsymbol{#1}% \else\ifx\f@series\boldexname% \boldsymbol{#1}% \else% #1% \fi\fi% }

and the conditional italic macro (well, actually conditional uprightness if you examine the logic, but that's for a reason):

%% Use \mathrm if not in italic context %% (`backward logic'' for a reason) \def\italname{it}% \DeclareRobustCommand{\maybeit}[1]{% \ifx\f@shape\italname% #1% \else% \mathrm{#1}% \fi% } .

For extreme pickiness, here's a little macro to move subscripts a little to the left in italic contexts:

%% Maybe-italic subscript shifting \DeclareRobustCommand{\maybeitsubscript}[1]{% \ifx\f@shape\italname% {\!\!#1}% \else% {#1}% \fi% } .

Finally, here's a few definitions of particle name macros based on these:

%% The main command for declaring HEP particle names \providecommand{\HepParticle}[3]{% \ensuremath{\maybebm{{\maybeit{% {#1}_{\maybeitsubscript{#2}}^{#3}}% }}}% } %% And a shortcut for generic antiparticles \providecommand{\HepAntiParticle}[3]{\ensuremath{\overline{\HepParticle{#1}{#2}{#3}}}} %% And a shortcut for SUSY antiparticles \providecommand{\HepSusyParticle}[3]{\ensuremath{\tilde{\HepParticle{#1}{#2}{#3}}}} %% A few examples of this in use (note these aren't PEN-compliant codes... for now!): %% B mesons \providecommand{\pB}{\HepParticle{B}{}{}\xspace} \providecommand{\pBbar}{\HepAntiParticle{B}{}{}\xspace} \providecommand{\pBd}{\HepParticle{\pB}{d}{0}\xspace} \providecommand{\pBdbar}{\HepAntiParticle{\pB}{d}{0}\xspace} \providecommand{\pBu}{\HepParticle{\pB}{u}{+}\xspace} \providecommand{\pBs}{\HepParticle{\pB}{s}{0}\xspace} \providecommand{\pBsbar}{\HepAntiParticle{\pB}{s}{0}\xspace} \providecommand{\pBc}{\HepParticle{\pB}{c}{+}\xspace} \providecommand{\pBzero}{\HepParticle{\pB}{}{0}\xspace} \providecommand{\pBplus}{\HepParticle{\pB}{}{+}\xspace} \providecommand{\pBminus}{\HepParticle{\pB}{}{-}\xspace} %% Hyperons \providecommand{\pLambda}{\HepParticle{\Lambda}{}{}\xspace} \providecommand{\pLambdaB}{\HepParticle{\pLambda}{b}{}\xspace}

Well, I'm glad that's out of the way! Hope it's useful to someone else, too: I just keep compiling bits of my thesis and gazing at the new magically-adapting particle names with a mixture of awe and smugness! You might be interested to know that I've now re-implemented the PEN pennames.sty package as heppennames.sty. This is available, along with a new "hepnicenames.sty" package from the CTAN system at e.g. http://www.ctan.org/tex-archive/macros/latex/contrib/hepnames/. Have fun, and please let me know if you;re using this!