# Shortcut to writing out long, common, expressions?

I'm writing an astronomy paper and have some symbols and variables which are common throughout. It's becoming cumbersome to write them out each time. Is there a way to create a shortcut of sorts for these? Note, most are in math-mode.

For example:
log(Hi)

$\log(\textrm{H}\textsc{i})$


log(SFR/M*)

$\log(\textrm{SFR} / \textrm{M}_{\odot})$

-


As you've already noted in a comment, a complication arises if these macros can also be used in bold surroundings such as sectioning headers. Specifically, given the above definition of \loghi, LaTeX will try to typeset the letter i in bold-smallcaps. As you've discovered, if the font family you're using does not feature a bold-smallcaps font, the letter will be set in "ordinary" bold, i.e., as i. Not the desired effect, right?!

What to do? I think you have (at least) two options. The first is to use a font family that does feature a bold-smallcap font. Two such families arenewt xtext/newtxmath and newpxtext/newpxmath . The former provides a "Times Roman" look, the latter a "Palatino" look. This may (or may not...) be acceptable to you.

Second, you could set up the macro that defines \loghi in such a way that it won't even try to use a (possibly nonexistent) bold smallcaps glyph. For instance,

\newcommand\loghi{\log(\mathrm{H}\textsc{\mdseries i})}


(note the addition of \mdseries to the argument of \textsc) instructs LaTeX to apply \textsc to a "medium weight" (rather than a "bold weight") version of i. As long as the medium-weight font features smallcaps glyphs, you'll be guaranteed success.

-
Fantastic answer and details. I really appreciate the advice on this one. Thank you. –  Carl May 10 at 6:22
@Carl - Thanks for the compliment! Incidentally, if the symbols "H" and "i" belong together in some way, it may be better -- from a syntactic point of view -- to set up the shortcut macro as \newcommand\loghi{\log(\textsc{\mdseries Hi})}. An uppercase letter is rendered "as is" when subjected to \textsc, so the look of "H" using either definition will be the same. Nevertheless, even though the appearance will be the same, it's still useful to tailor the shortcut definition to obey all syntactic aspects of the expression at hand. –  Mico May 10 at 7:14
If you want to use the macro in header and use the hyperref package, you should also wrap it in a \texorpdfstring –  Cephalopod May 10 at 12:01
@Arian - I'm not sure how your comment relates the posting's topic, which is how to go about creating shortcuts for recurring expressions. Do verify for yourself that the issue with hyperref (specifically, the possible need for a \texorpdfstring directive) arises equally if the expression is generated via a shortcut macro or if it is written out fully from the start, i.e., without a shortcut macro. –  Mico May 10 at 15:57

I would split the problem into two parts. First you define the elementary symbols, then expressions in terms of them:

\documentclass{article}
\usepackage{amsmath}

%% first the symbols
\newcommand{\Hi}{\textnormal{H\kern-.1em\textsc{i}}}
\newcommand{\SFR}{\mathrm{SFR}}
\newcommand{\Mo}{\mathrm{M}_{\odot}}
%% then common expressions
\newcommand{\lHi}{\log\Hi}
\newcommand{\lsfrmo}{\log(\SFR/\Mo)}

\begin{document}
\begin{gather*}
\log\Hi + \log(\SFR/\Mo)\\
\lHi+\lsfrmo
\end{gather*}
\end{document}


I've added some bit to the definition of \Hi just to show how you can redefine the elementary symbol without any need to modify also the definition of the expression defined in terms of it.

With \textnormal{...} we ensure the font will be the “initial” one, independently of the context. This is needed for \Hi, but not for \SFR; since \mathrm is more efficient than \textnormal, it's preferable when it's possible to use it.

-