# La composition soignée des formules mathématiques

It is widely spoken that the Equation Editor of Word (OneNote / Office) is inferior and harder to use than LaTeX. While this is true for a hardcore user, a lot of people spreading the word aren’t really understanding the thing and are just parroting others. I suspect that for a lot of them, the ability to efficiently typeset beautiful mathematical formulae is limited by knowledge and carefulness. People don’t seem to care enough to learn and correctly employ the tools at hand.

The title is in French, which roughly means ‘fine typesetting of mathmatical formulae’. I put the tag ‘Programming’ because I believe typesetting a document is one kind of programming.

## Do you typeset finely?

The following LaTeX document contains 6 typographical errors, try to spot them:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

By Newton-Leibniz formula, we have

\begin{align*}
\int_0^1{x^2dx}
=&\frac{x^3}{3}|_0^1\\
=&\frac13
\end{align*}

\end{document}


Answer By the order of appearance:

1. The dash between Newton and Leibniz is too short. Use -- to produce an en-dash.
2. There is an extra blank line between the text and the equation, pushing the equation to a new paragraph. Remove the extra blank line.
3. The ‘d’ in the integrand should not be italicised. See here on how to fix this.
4. The spacing around ‘=’ is incorrect. See here on how to fix this.
5. The vertical bar is not properly sized. See here on how to fix this.
6. There should be a full stop. Add a full stop at the end of the equation.

A corrected version is the following:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

By Newton--Leibniz formula, we have
\begin{align*}
\int_0^1{x^2\operatorname{d}\!x}
&{}={\left.\frac{x^3}{3}\right|}_0^1\\
&{}=\frac13.
\end{align*}

\end{document}


## Quick comparison

Word LaTeX
Basic maths OK OK
Keyboard input Yes Yes
WYSIWYG Optional No
Learning curve Shallow Steep
Parentheses sizing Automatic Manual
Display vs inline Automatic Adjustable
N-ary operations Limited Customisable
\limits and \nolimits Adjustable Adjustable
Fonts Limited Customisable
Alignment Limited Customisable
Programmability No Yes
Manual layout No Yes

While the above chart shows Word has fewer functionalities and less customisability, the reality is Word is sufficient for most homework assignment typesetting tasks for computer science students. Of course, it is the common and recommended practice to use LaTeX, but that’s no reason to demolish Office Equation Editor, and certainly no reason to say ‘LaTeX is easier’ just because you didn’t learn or know how to use Equation Editor.

Surprisingly, the format Office uses is open (see Unicode Technical Note #28). In addition, you can send e-mails with equations with Outlook (rendered as images if the recipient does not use Outlook).

## Tips on keyboarding input to Word

The list is by no means a comprehensive guide.

N.B. The tips assume Unicode mode and Word for Windows (Desktop). Word now has LaTeX mode, which tries to mimic some LaTeX syntax. You can go to File | Options | Proofing | AutoCorrect Options… | Math AutoCorrect to see a comprehensive list of out-of-box commands.

The first rule of thumb is to remember that in Word, Space can be used to convert certain character sequence you just entered into a Unicode character that controls the typesetting process in Word. It’s much like the escaping character \ in LaTeX, and it’s optional. Even if you don’t press Space, the conversion happens automatically at certain semantic boundaries, e.g., when typing a closing parenthesis, a conversion of the suffix of your input is performed.

Word doesn’t assign semantics to italicisation and you might need to reformat italicisation in certain circumstances.

### Fractions

Type x^2/y^3 Space to get \frac{x^2}{y^3}, x\sdiv((x+y)^2) Space to get \sfrac{x}{{\left({x+y}\right)}^2}, and G\ldiv N Space to get G/N.

### Fonts

\frakturX, \scriptX and \doubleX correspond to \mathfrak{X}, \mathcal{X} and \mathbb{X}. Not every letter (case sensitive) is available every font. Some commands like \ii and \ell are also available.

### Matrix

You can create a matrix with \matrix. For example, type (\matrix Space (a_11&a_12&a_13@a_21&a_22&a_23)) Space to get the LaTeX equivalent of

\left(\begin{matrix}
a_{11}&a_{12}&a_{13}\\
a_{21}&a_{22}&a_{23}
\end{matrix}\right)
% or
\begin{pmatrix}
a_{11}&a_{12}&a_{13}\\
a_{21}&a_{22}&a_{23}
\end{pmatrix}


You can adjust the alignment of columns of matrices by opening the context menu and choosing the desired alignment.

### Functions and limits

Type sin Space to get the effect of \sin{}. Note that functions in Word consist of two placeholders, one for the function name and the other for the arguments. Place the content correctly to ensure correct semantics and automatic parentheses sizing.

Type lim Space to get the effect of \lim{}. Type lim_(n\to\infty) Space 1/n Space Right =0 to get \lim_{n\to\infty}\frac1n=0.

You might have noticed that sine and limit are different. The \limits is automatic for max, min, lim, Pr and any n-ary operation in Word. And \nolimits is the default for most other functions. Once a function or limit is created, you can edit the function name. Alternatively, you can type argmin\below(x\in Space X) \funcapply Space f(x) Space, then move the cursor and de-italicise argmin to get \operatorname*{argmin}_{x\in X}{f\left(x\right)}.

### Parentheses

Type \left Space to insert a blank left parenthesis (equivalent to LaTeX \left.) and \right Space to insert a blank right parenthesis (equivalent to LaTeX \right.). For example, typing {\right Space Space gets you the equivalent of \left\{{}\right.. The first Space converts \right to the Unicode character that represents a blank right parenthesis in Word, and the second Space pairs up the left brace and the right blank parenthesis.

Type \norm Space \nabla Space f(x)\norm Space Space to get \left\|\nabla f\left(x\right)\right\|.

Note that parentheses are also used for grouping when typing, so f^(n) Space doesn’t give you f^{\left(n\right)}. Type f^((n)) Space to get it.

Type 0.\overbrace(9\cdots Space ) Space ^n=1-10^(-n) Space to get 0.\overbrace{9\cdots9}^n=1-{10}^{-n}.

### Box and accents

Type \rect(a^2+b^2=c^2) Space to get \boxed{a^2+b^2=c^2}.

Type x\bar Space Space to get \overline{x}.

### Equation array and phantom alignment

Type \eqarray(x+2y&=1@2x+y&=2) Space to get \begin{align*}x+2y&{}=1\2x+y&{}=2\end{align*}.

Use \phantom and \vphantom to create space from phantom text.

## Common mistakes when typesetting in LaTeX

This section lists some common mistakes people make when typesetting mathematical formulae in LaTeX, which results in either incorrect semantics or poorly typeset documents. Often, such mistakes result a document ‘even inferior than one typeset by Word’ (in LaTeX 极端拥趸’s tongue, 极端拥趸 means radical enthusiast). The list is by no means a comprehensive checklist for mistakes.

### Not defining commands

This is the #1 mistake. If something appears repeatedly, define a command. It is good for semantics. Just as we advocate semantic Web, a LaTeX document is better understood and better concentrated on the content (one of the selling points as seen by many) when you define semantical commands instead of using the semanticless style commands.

\newcommand{\PR}[2]{\Pr_{#1}\left[{#2}\right]}

% possible styles, choose one
\newcommand{\transpose}[1]{{#1}^\top}
\newcommand{\transpose}[1]{{#1}^\textrm{T}}

\newcommand{\adabsurdum}{$\rightarrow\!\parallel$ }

\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator*{\argmax}{argmax}
\DeclareMathOperator*{\argmin}{argmin}


### \mathrm vs \textrm

Use \textrm for annotational text in maths environments. Use \mathrm for multi-letter variable names and other non-italicised maths texts. Not only do they carry different semantics, under certain circumstances, their fonts are also different (both are Computer Modern by default so usually the same appearance)!

### \operatorname vs \mathrm

Use \operatorname for function names and \mathrm for variable names. \operatorname carries semantics and comes with \mathrm formatting and handles space according to the usual rules for operators.

% good, better is to define a command
The rank of matrix $M$ is denoted $r\left(M\right)$ or $\operatorname{rank}M$.

% bad, incorrect spacing
The rank of matrix $M$ is denoted $\mathrm{rank}M$.


### Parentheses sizing

Use \left and \right to pair parentheses whenever possible, even when it does not change the size of parentheses. One benefit is that you never have to change it if you later decided to put a more complicated formula inside. The other is encoding the grouping information, which contributes to semantics.

When the content inside this pair of parenthesis is spread across multiple lines (e.g., inside align environment), using \left and \right is impossible, and manual adjustment is required.

Parentheses sizing is automatic and mandatory in Word.

### Placeholder operands in align

If the equations are aligned at a binary operator, insert a placeholder operand to obtain correct spacing. Careful readers might have notice that there.

% good (1)
\begin{align*}
x+2y={}&1\\
2x+y={}&1\\&{}+1
\end{align*}

% good
% but explicit {} is recommended
% and you should really use (1)
% to naturally align = and +
\begin{align*}
x+2y&=1\\
\end{align*}

% bad, incorrect spacing around "="
\begin{align*}
x+2y=&1\\
2x+y=&2\\&+1
\end{align*}


Word doesn’t suffer from this problem and the spacing is correct.

### ‘dx’ in the integrand

The $\operatorname{d}\!x$ in the integrand should not be typeset as $dx$. However, just using \operatorname{d} isn’t enough, as there is usually no space between ‘d’ and ‘x’. I use a custom command for typesetting.

% good
\newcommand{\dx}[1]{\operatorname{d}\!{#1}}
\begin{align*}
\int_0^1{f\left(x\right)\dx{x}}
\end{align*}

% bad, incorrect spacing
\begin{align*}
\int_0^1{f\left(x\right)\operatorname{d}x}
\end{align*}

% bad, incorrect semantics
\begin{align*}
\int_0^1{f\left(x\right)\mathrm{d}x}
\end{align*}

% bad, incorrect styling
\begin{align*}
\int_0^1{f\left(x\right)dx}
\end{align*}


## Conclusion

I once typeset my maths for computer science homework with Word instead of LaTeX (which was mandatory), but was never discovered. Of course I had to use Computer Modern, but I kept the document semantically organised. Just like everyone does in LaTeX, the formats are controlled using Styles instead of ad-hoc formatting. For privacy and academic reasons, I cannot make this file public, but you can see the hero image for an excerpt.

Office Equation Editor implements and renders a large range of equations than one might have expected, and it is not fair to claim it is ‘harder to use than LaTeX’ just because one didn’t learn it. Under day-to-day circumstances, Office Equation Editor works really well and the effort you need for it is less than that you need for LaTeX.

Fine typesetting requires both software and effort. The final result depends on both the typesetting software and the attitude of the author toward typesetting.

There is much more for fine typesetting. John Steinberger, in his mathematics for computer science course, set a standard for typesetting homework assignments (some advices are useful for people who aren’t native users of the Latin script and the English language) and it was then I started to typeset documents seriously. My methodology to fine typesetting involves several layers of consideration. Semanticising reduces formatting each individual character to formatting each semantical element, care should be taken for controlling the styles, and writing of the content is also crucial.