[Tex/LaTex] Typesetting mathematical constants

amsmathbest practicesmath-mode

Is there any command for typesetting constants in mathematical formulas?
I would imagine something similar to \operatorname or \DeclareMathOperator, but for constants.

I want the constant to be typeset in roman font as in the text mode (with proper spacing and ligatures – this concerns constants denoted by a couple of letters).

Best Answer

(updated to incorporate the comments by @egreg, barbara beaton, and @DCh)

I assume your document uses a roman (serif) font rather than a sans-serif font for mathematics. To ensure that constants are typeset consistently using upright Roman letters, it's handy to create a dedicated macro named, say, \ct that uses the following macros in a nested fashion: \text (from the amsmath package), \rmfamily(just in case the surrounding material is non-roman), and \upshape.

\newcommand\ct[1]{\text{\rmfamily\upshape #1}}

Then, use this macro to typeset an equation such as

$\ct{e}^{\ct{i}\pi}-1=0$

Suppose, furthermore, that your documents contains two frequently-occurring constants named ab-cd and fi-fi. (You did say that the names of the constants might contain ligatures...) To help speed up typing, you could define two macros \abcd and \fifi as follows:

\newcommand*{\abcd}{\ct{ab-cd}}
\newcommand*{\fifi}{\ct{fi-fi}}

The result of a full MWE:

enter image description here

\DeclareSymbolFont{AMSb}{U}{msb}{m}{n}
\documentclass[noamsfonts]{amsart}  \usepackage[bitstream-charter]{mathdesign}

%% use the \ct macro to define math constants
\newcommand\ct[1]{\text{\rmfamily\upshape #1}}

%% define two math constants with rather contrived names...
\newcommand{\abcd}{\ct{ab-cd}}
\newcommand{\fifi}{\ct{fi-fi}}

\begin{document} 
\sffamily  % switch to sans-serif for main text font

$\ct{e}^{\ct{i}\piup}-1=0$,
$(\abcd)^2-\ct{e}^{(\fifi^3)}=0$

not in math mode: ab-cd, fi-fi
\end{document}