6.8.3 TeX and LaTeX Language Modes

The d T (calc-tex-language) command selects the conventions of “math mode” in Donald Knuth’s TeX typesetting language, and the d L (calc-latex-language) command selects the conventions of “math mode” in LaTeX, a typesetting language that uses TeX as its formatting engine. Calc’s LaTeX language mode can read any formula that the TeX language mode can, although LaTeX mode may display it differently.

Formulas are entered and displayed in the appropriate notation; ‘sin(a/b)’ will appear as ‘\sin\left( {a \over b} \right)’ in TeX mode and ‘\sin\left(\frac{a}{b}\right)’ in LaTeX mode. Math formulas are often enclosed by ‘$ $’ signs in TeX and LaTeX; these should be omitted when interfacing with Calc. To Calc, the ‘$’ sign has the same meaning it always does in algebraic formulas (a reference to an existing entry on the stack).

Complex numbers are displayed as in ‘3 + 4i’. Fractions and quotients are written using \over in TeX mode (as in {a \over b}) and \frac in LaTeX mode (as in \frac{a}{b}); binomial coefficients are written with \choose in TeX mode (as in {a \choose b}) and \binom in LaTeX mode (as in \binom{a}{b}). Interval forms are written with \ldots, and error forms are written with \pm. Absolute values are written as in ‘|x + 1|’, and the floor and ceiling functions are written with \lfloor, \rfloor, etc. The words \left and \right are ignored when reading formulas in TeX and LaTeX modes. Both inf and uinf are written as \infty; when read, \infty always translates to inf.

Function calls are written the usual way, with the function name followed by the arguments in parentheses. However, functions for which TeX and LaTeX have special names (like \sin) will use curly braces instead of parentheses for very simple arguments. During input, curly braces and parentheses work equally well for grouping, but when the document is formatted the curly braces will be invisible. Thus the printed result is ‘sin 2x’ but ‘sin(2 + x)’.

The TeX specific unit names (see Predefined Units) will not use the ‘tex’ prefix; the unit name for a TeX point will be ‘pt’ instead of ‘texpt’, for example.

Function and variable names not treated specially by TeX and LaTeX are simply written out as-is, which will cause them to come out in italic letters in the printed document. If you invoke d T or d L with a positive numeric prefix argument, names of more than one character will instead be enclosed in a protective commands that will prevent them from being typeset in the math italics; they will be written ‘\hbox{name}’ in TeX mode and ‘\text{name}’ in LaTeX mode. The ‘\hbox{ }’ and ‘\text{ }’ notations are ignored during reading. If you use a negative prefix argument, such function names are written ‘\name’, and function names that begin with \ during reading have the \ removed. (Note that in this mode, long variable names are still written with \hbox or \text. However, you can always make an actual variable name like \bar in any TeX mode.)

During reading, text of the form ‘\matrix{ ... }’ is replaced by ‘[ ... ]’. The same also applies to \pmatrix and \bmatrix. In LaTeX mode this also applies to ‘\begin{matrix} ... \end{matrix}’, ‘\begin{bmatrix} ... \end{bmatrix}’, ‘\begin{pmatrix} ... \end{pmatrix}’, as well as ‘\begin{smallmatrix} ... \end{smallmatrix}’. The symbol ‘&’ is interpreted as a comma, and the symbols ‘\cr’ and ‘\\’ are interpreted as semicolons. During output, matrices are displayed in ‘\matrix{ a & b \\ c & d}’ format in TeX mode and in ‘\begin{pmatrix} a & b \\ c & d \end{pmatrix}’ format in LaTeX mode; you may need to edit this afterwards to change to your preferred matrix form. If you invoke d T or d L with an argument of 2 or −2, then matrices will be displayed in two-dimensional form, such as

a & b \\
c & d

This may be convenient for isolated matrices, but could lead to expressions being displayed like

\begin{pmatrix} \times x
a & b \\
c & d

While this wouldn’t bother Calc, it is incorrect LaTeX. (Similarly for TeX.)

Accents like \tilde and \bar translate into function calls internally (‘tilde(x)’, ‘bar(x)’). The \underline sequence is treated as an accent. The \vec accent corresponds to the function name Vec, because vec is the name of a built-in Calc function. The following table shows the accents in Calc, TeX, LaTeX and eqn (described in the next section):

Calc      TeX           LaTeX         eqn
----      ---           -----         ---
acute     \acute        \acute
Acute                   \Acute
bar       \bar          \bar          bar
Bar                     \Bar
breve     \breve        \breve
Breve                   \Breve
check     \check        \check
Check                   \Check
dddot                   \dddot
ddddot                  \ddddot
dot       \dot          \dot          dot
Dot                     \Dot
dotdot    \ddot         \ddot         dotdot
DotDot                  \Ddot
dyad                                  dyad
grave     \grave        \grave
Grave                   \Grave
hat       \hat          \hat          hat
Hat                     \Hat
Prime                                 prime
tilde     \tilde        \tilde        tilde
Tilde                   \Tilde
under     \underline    \underline    under
Vec       \vec          \vec          vec
VEC                     \Vec

The ‘=>’ (evaluates-to) operator appears as a \to symbol: ‘{a \to b}’. TeX defines \to as an alias for \rightarrow. However, if the ‘=>’ is the top-level expression being formatted, a slightly different notation is used: ‘\evalto a \to b’. The \evalto word is ignored by Calc’s input routines, and is undefined in TeX. You will typically want to include one of the following definitions at the top of a TeX file that uses \evalto:


The first definition formats evaluates-to operators in the usual way. The second causes only the b part to appear in the printed document; the a part and the arrow are hidden. Another definition you may wish to use is ‘\let\to=\Rightarrow’ which causes \to to appear more like Calc’s ‘=>’ symbol. See The Evaluates-To Operator, for a discussion of evalto.

The complete set of TeX control sequences that are ignored during reading is:

\hbox  \mbox  \text  \left  \right
\,  \>  \:  \;  \!  \quad  \qquad  \hfil  \hfill
\displaystyle  \textstyle  \dsize  \tsize
\scriptstyle  \scriptscriptstyle  \ssize  \ssize
\rm  \bf  \it  \sl  \roman  \bold  \italic  \slanted
\cal  \mit  \Cal  \Bbb  \frak  \goth

Note that, because these symbols are ignored, reading a TeX or LaTeX formula into Calc and writing it back out may lose spacing and font information.

Also, the “discretionary multiplication sign” ‘\*’ is read the same as ‘*’.

The TeX version of this manual includes some printed examples at the end of this section.