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})$
Best Answer
Creating macros that provide shortcuts for frequently used strings is a very good idea. For an entry-level introduction to the uses of the LaTeX
\newcommand
directive see, e.g., Chapter 6, "Customizing LaTeX", of the guide The Not So Short Introduction to LATEX2e.For instance, you could issue the instructions
in the preamble and, later on in the body of the text, write something like
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 letteri
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 are
newt xtext
/newtxmath
andnewpxtext
/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,(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 ofi
. As long as the medium-weight font features smallcaps glyphs, you'll be guaranteed success.