[Tex/LaTex] Difference between \mathit and math-style = TeX

fontsmath-modeunicode-math

I would like to know what the difference is between \mathit and setting [math-style = TeX] regarding italics in math mode.

This code will explain it better

\documentclass{article}

\usepackage[math-style = TeX]{unicode-math}

\begin{document}

    \[ \mathit{\rho} \rho \]

\end{document}

Only the latter showing up with an "italic" style (TeX math-style).

If an unicode math font such as STIX Two Math is loaded, the same will happen, but this time a cross inside a rectangular box will show up as \mathit{\rho}

Here's the code for said scenario

\documentclass{article}

\usepackage[math-style = TeX]{unicode-math}

\setmathfont{STIX Two Math}

\begin{document}

    \[ \mathit{\rho} \rho \]

\end{document}

Best Answer

I would like to know what the difference is between \mathit and setting [math-style = TeX] regarding italics in math mode.

There's a huge difference between (a) loading the unicode-math package and selecting a math-style (e.g., "TeX" or "ISO") that employs italics for lowercase Latin and Greek letters and (b) using \mathit. (Aside: For more information on the math styles provided by the unicode-math package, see section 5.1 of the package's user guide.)

Using \mathit operates quite independently of the chosen math style. Using \mathit can generate outcomes which may be unexpected -- at least at first. This is because the \mathit directive accesses its letters from the text font, not from the math font. This is by design. According to David Carlisle's comment (see below), \mathit should be used for multi-letter identifiers, such as the names of variables. For variable names, it's better to use italics from the text font, rather than "true" math-mode italics.

Consider the table below, which shows the four available math styles (ISO, TeX, french, and upright), with lowercase and uppercase Latin and Greek letters. The math font is set to Stix Two Text, while the text font is set to Calibri. I chose a sans-serif text font to make the difference between text and math fonts glaringly obvious.

Confirming what I asserted above, observe that the \mathit output, shown in the final column, does not employ letters from the math font family. Instead, it quite evidently employs letters from the text font family.

enter image description here

\documentclass{article}
\usepackage{array}
\newcommand\myarray[1]{\par\noindent% 
% Structure of table:
  %col. 1: math style
  %col. 2: math mode, lowercase Latin letters
  %col. 3: math mode, uppercase Latin letters
  %col. 4: math mode, lowercase Greek letters
  %col. 5: math mode, uppercase Greek letters
  %=col. 6: output of \mathit
    $\begin{array}{@{}p{1.2cm} >{$}p{1cm}<{$} *{3}{>{$}p{0.6cm}<{$}} l }
    #1 & abcffi & XYZ & \alpha\beta\gamma & \Phi\Psi\Omega
    & \mathit{abcffi} \\ % <-- final column uses "\mathit{...}"
    \end{array}$}

\usepackage{unicode-math}
\setmainfont{Calibri}[ItalicFont="Calibri Italic"] % sans-serif text font
%% or: \setmainfont{Stix Two Text} 

\begin{document}
\setmathfont{Stix Two Math}[math-style = ISO]
\myarray{ISO}

\setmathfont{Stix Two Math}[math-style = TeX]
\myarray{TeX}

\setmathfont{Stix Two Math}[math-style = french]
\myarray{french}

\setmathfont{Stix Two Math}[math-style = upright]
\myarray{upright}
\end{document}