14

How can I get the kerning and ligatures of text mode in an upright math font with the unicode-math package loaded?

1. Without unicode-math

Code:

\documentclass{article}

\begin{document}
  affinity\par
  $\mathrm{affinity}$\par
\end{document}

Output:

Kerning and ligatures of text mode.

2. With unicode-math

Code:

\documentclass{article}
\usepackage{unicode-math}

\begin{document}
  affinity\par
  $\mathrm{affinity}$\par
\end{document}

Output:

Kerning and ligatures of math mode. I would like those of text mode here.

8

The use of math alphabet commands in unicode-math is somewhat broken there are open issues at github which mentions \mathit but \mathrm is the same.

You can redefine \mathrm to use the Roman text font as follows:

enter image description here

\documentclass{article}
\usepackage{unicode-math}

\setmathfont{Latin Modern Math}
\setmathfont[range=\mathup]{Latin Modern Roman}
\begin{document}
  affinity\par
  $\mathrm{affinity}$\par
\end{document}

not working version including mathit

\documentclass{article}
\usepackage{unicode-math}

\setmathfont{Latin Modern Math}
\setmathfont[range=\mathup]{Latin Modern Roman}
%\setmathfont[range=\mathit]{lmroman12-italic}% affects normal math as well.
\DeclareMathAlphabet\xxmathit{EU2}{lmr}{m}{it}% EU1 for xetex EU2 for luatex
\def\xmathit#1{\xxmathit{\mathup{#1}}}% right font but ff ligature broken
\begin{document}
\showoutput
  1 affinity\par
  2 \textit{affinity}\par
  3 $affinity$\par
  4 $\mathrm{affinity}$\par
  5 $\xmathit{affinity}$\par
\end{document}
  • Thank you! Now if I want to do the same thing but with \mathit, what is the name of the Latin Modern italic text font? (Latin Modern Roman Italic or Latin Modern Roman-Italic don't work.) – Maggyero May 22 '15 at 18:00
  • @Maggyero I'm not sure, I added an example to the question with two possible ways one commented out, the other selects the right font but ligatures not working. As I say I opened a github issue last year on mathit not working with unicode-math, you could ping will there..... – David Carlisle May 22 '15 at 19:20
  • Is there a way to contact him directly on Stackexchange? – Maggyero May 22 '15 at 21:57
  • no, see meta.tex.stackexchange.com/questions/6164/…, although he regularly passes by tex.stackexchange.com/users/179/will-robertson (I could mail him:-) – David Carlisle May 22 '15 at 22:05
  • Alright, yes could you email him? By the way, I read the Github issue you opened but at the end of the thread Will says: "(Discussion continued on LaTeX-L.)" without any url, what it this LaTeX-L? – Maggyero May 23 '15 at 7:50
1

To follow-up the discussion in the comments of David Carlisle's answer about the unicode-math package:

In LaTeX, there are two fonts in math mode:

  • one for letters (variables), usually called math font (better called math letter font);
  • one for words, usually called math text font (better called math word font),

and one text font in text mode, usually called text font.

The text font and the math text font may be different:

\documentclass{article}
\renewcommand{\familydefault}{ppl} % sets Palatino as text font
\begin{document}
    $\mathnormal{affinity}$\par    % math letter font
    $\mathit{affinity}$\par        % math word font
    $\textit{affinity}$\par        % text font
\end{document}

Here \mathnormal, \mathit and \textit result in three different fonts being used: Latin Modern Math, Latin Modern and Palatino respectively.

With the unicode-math package loaded, the output becomes different:

\documentclass{article}
\usepackage{unicode-math}
\setmainfont{Palatino}             % sets Palatino as text font
\setmathfont{Latin Modern Math}    % sets Latin Modern Math as math letter font
\begin{document}
    $\mathnormal{affinity}$\par    % math letter font
    $\mathit{affinity}$\par        % math word font
    $\textit{affinity}$\par        % text font
\end{document}

Here the package redefines \mathnormal as nothing and \mathit as math letter font (instead of math word font in classic LaTeX). So by default the unicode-math package breaks the standard behaviour of LaTeX. That is why David Carlisle opened an issue at Github as said in his answer (there is another interesting Github issue about the same problem here).

As suggested by David Carlisle in the Github issue, I first thought about introducing new math font commands \mathwxx for math word font in the unicode-math package, to keep backward compatibility:

But finally I am wondering if those new math font commands \mathwxx are needed, and even if they make sense: indeed, when do we need to use an upright math letter font after all? Math letter fonts are only for variables, therefore they should always be in italic, never upright. We only need an upright math font for non variables, that is for math word fonts, so we should better replace the math letter font of the Unicode ranges \mathup and \mathbf by a math word font:

\documentclass{article}
\usepackage{unicode-math}
\setmainfont{Palatino}
\setmathfont{Latin Modern Math}
\setmathfont[range=\mathup]{Latin Modern Roman} % sets a math word font instead of the default math letter font
\setmathfont[range=\mathbfup]{lmroman12-bold}   % sets a math word font instead of the default math letter font
\let\mathnormal\mathit                          % redefines \mathnormal as before the unicode-math package
\begin{document}
    \noindent
    \texttt{\backslash mathup}: $\mathup{affinity}$\\
    \texttt{\backslash mathbf}: $\mathbf{affinity}$\\
    \texttt{\backslash mathit} or \texttt{\backslash mathnormal}: $\mathit{affinity}$ (default)\\
    \texttt{\backslash mathbfit}: $\mathbfit{affinity}$\\
\end{document}

Thus with that setup we get the standard LaTeX behaviour.

  • I'm not sure the above is really an answer, more an extended comment. But some comments. It is best not to use minimal class for font examples as there are many artefacts due to the fact that it doesn't set up fonts. "two fonts in math mode" isn't right in classic tex (where there are usually four, and up to 16) or unicode-math (where there is usually just one). – David Carlisle May 26 '15 at 8:44
  • 1
    Your initial example is using computer modern not latin modern for math, the missing mathnormal commands are not because \mathnormal is defined to do nothing but as warned in the log Missing character: There is no 𝑎 (U+1D44E) in font cmmi10! the final example says that with that suggested setup you get "the default latex behaviour" but it shows exactly the problem that is raised in github that \mathit is giving the math italic font as accessed by \mathnormal (or no font command at all) instead of a text italic font. – David Carlisle May 26 '15 at 8:47
  • @DavidCarlisle: Yes, this was to continue our discussion with some visual examples. 1. 'It is best not to use minimal', alright, I'll edit the answer. 2. 'There are usually four, and up to sixteen', you're right, actually I meant two fonts in the generic sense: the math font used for variables (math letter italic) and the math font used for constants, operators and subscript specifiers (math word upright). 3. 'Your initial example is using computer modern, not latin modern for math', that's just what I wanted to ask you: how to use Latin modern math without the unicode-math package? – Maggyero May 26 '15 at 10:46
  • 2
    Yes of course people use \mathit to make multi-letter words, what other use would it have? See for example this answer of egreg's giving \mathit as the solution to make a variable called AB as opposed to the product of two variables A and B tex.stackexchange.com/questions/16433/… but search the internet for \mathit you will find it is almost always used with more than one letter in its argument. – David Carlisle May 26 '15 at 11:12
  • 1
    I agree with the comments, it's just a matter of resources (i.e., time). I'd hoped to address this many months ago by now… apologies for the inconvenience. – Will Robertson May 28 '15 at 0:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.