3

When there are words consisting of several letters in an equation, I have to add \mathit to brace each word up or the inter-letter space will vary. See the difference between the two instances of "CDF" and "erf" in below MWS? But such a practice is really tedious and adds difficulty to fast reading an equation. Is there a package that automatically uniformizes the inter-letter space for words in an equation so I don't have to add hundreds \mathit in one paper?

\documentclass[journal]{IEEEtran}

\usepackage{amsmath}
\begin{document}
     \begin{align}      
     \label{cdf}
         CDF &= \frac{1}{2}(1 + erf(\frac{x-\mu}{\sigma\sqrt{2}}))
     \end{align}    

     \begin{align}      
     \label{cdf}
         \mathit{CDF} &= \frac{1}{2}(1 + \mathit{erf}(\frac{x-\mu}{\sigma\sqrt{2}}))
     \end{align}    
  
\end{document}

enter image description here

3
  • Welcome to TeX.SE.
    – Mico
    Commented Aug 19, 2023 at 7:43
  • 2
    Off-topic: It's poor typographic practice to use an align environment for single-line equations. I suggest you use equation environments for numbered single-line equations.
    – Mico
    Commented Aug 19, 2023 at 7:46
  • 2
    A thought that's prompted by your expressed desire to avoid having "to add hundreds \mathit in one paper". One of the many deep beauties of TeX is that it's a macro programming language. Thus, rather than write \mathit{erf} hundreds of times, you could (a) replace all instances of erf with \erf and (b) define once -- presumably in the preamble -- what \erf is supposed to do. You could set \newcommand\erf{\mathit{erf}}, or you could pursue the approach I suggest in my answer, viz., run \DeclareMathOperator{\erf}{erf}, giving \erf the same status as \det, \sin, \log, etc.
    – Mico
    Commented Aug 19, 2023 at 15:09

1 Answer 1

14

In fine math typesetting, it's very common to use an upright font shape for operators such as "log", "sin", "det", "abs", and so on. "erf" is no different in this regard. Since you already make use of the amsmath package, you can use its \DeclareMathOperator macro to declare a new operator called, say, \erf, as follows:

\DeclareMathOperator{\erf}{erf}

Then, perform a global, one-time-only search and replace from erf to \erf in the body of the TeX document.

The case for giving special typographic treatment to "CDF" is actually different to the one for "erf". Here, "CDF" is not an operator but an acronym. Since "CDF" definitely doesn't denote the product of variables named "C", "D", and "F", it's customary to use either \mathit or (I believe, more commonly) mathrm to affect the way the acronym is typeset. Better still, define a macro called, say, \vn (short for "variable name") as follows:

\newcommand\vn[1]{\mathrm{#1}}

and then write \vn{CDF} instead of just CDF. Using \vn is not only shorter than \mathrm, but also affords far greater typesetting flexibility. Suppose one journal requires math-roman notation for variable names, whereas an other journal requires math-italic notation. All you'll have to do in your paper is to change the argument of \vn.

Building on these thoughts, I'd rewrite your test document as follows:

enter image description here

\documentclass[journal]{IEEEtran}
\usepackage{amsmath} % for '\DeclareMathOperator' macro
\DeclareMathOperator{\erf}{erf} % "error function" operator
\newcommand\vn[1]{\mathrm{#1}}  % for typesetting variable names

% Optional -- load a Times Roman math font package
\usepackage[lite]{mtpro2} % cf. https://pctex.com/mtpro2.html

\begin{document}

\begin{equation} \label{cdf}
\vn{CDF} = \frac{1}{2}\biggl(
  1+\erf\biggl( \frac{x-\mu}{\sqrt{2\sigma^2}} \biggr)
  \biggr)
\end{equation}     

\end{document}
9
  • Thanks. So as of now there is no such a feature available in Latex as I requested - we have to put "\mathit" or "\mathrm" to modify every word in the mathematic environment (Using a defined var '\vn' might make things a bit better but doesn't really fix the issue). Personally I think this is a very desirable feature and wonder if the Latex community shall consider adding it. To recap what I'm asking for: Commented Aug 20, 2023 at 9:37
  • 1. Create a package that automatically identifies the space before/after a word in the math environment. 2. The package will treat the identified word as a single variable (rather than each letter as a variable) by default. Commented Aug 20, 2023 at 9:41
  • BTW, CDF stands for Cumulative Distribution Function therefore is preferred to be treated as a var😊 Commented Aug 20, 2023 at 9:45
  • 1
    @ShermanChen - Is something stopping you from (a) doing a global search and replace of erf for \erf and (b) providing a suitable definition of \erf in the preamble? Incidentally, as an econometrician, I'm quite familiar with the acronym "CDF", and I'm also quite familiar with the notion that "erf" is not a variable name but an operator name. BTW, is it challening or burdensome to have to write \sin, \tan and \log instead of sin, tan, and log?
    – Mico
    Commented Aug 20, 2023 at 9:58
  • 3
    @ShermanChen I think Mico is recommending that in future you use exactly the same approach for "erf" as you currently do for "log" (having defined an appropriate macro). In my experience this is an extremely widely used and convenient approach. Yes, there is a little work involved if you want to convert previously existing documents. For that, if you want to avoid interactive search-and-replace, there are also editors that enable replacement only within mathmode; see for example tex.stackexchange.com/questions/65295/… . Commented Aug 20, 2023 at 13:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .