# How do I get the XITS font to work with unicode-math and hepnames in lualatex

I have been trying to get the XITS font, hepnames and unicode-math to behave correctly together for quite some time now, but I have been unable to find a solution to my problem.

Perhaps, I have been searching wrong... the closest I could find to my problem was this question, so I would appreciate any help with my issue, even if it is just pointing me to a link with relevant information.

The problem itself is quite easy to describe, the hepnames package provides a series of macros to typeset particle symbols, from what I have been able to gather it uses mathmode for this, which requires me to use unicode-math to change the font. After setting this up, it seems that some of the macros work and others do not, and when the macros do not work, there is no output (for that macro) in the generated pdf file. I tried running the same file with XeLaTeX, just to confirm it was not a LuaLaTeX bug or something, and the output was nearly identical, with the only difference that XeLaTeX would output empty boxes where the failing macros are. Also, moving the order of the commands in the preamble changes the macros that do and do not work.

Here is a MWE:

\RequirePackage[l2tabu, orthodox]{nag}
\documentclass[12pt,a4paper,twoside]{report}

\usepackage{hepnames}

\usepackage{fontspec}
% With setmainfont here, the \Pgm and \Pgt macros work
\setmainfont
[    Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic,
]{xits}

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

% With setmainfont here, the \Pl macro works
\setmathfont
[    Extension = .otf,
BoldFont = *bold,
Ligatures=TeX,
]{xits-math}

\begin{document}

Macros being tested:
\begin{itemize}
\item $\Pgm$ should print $\mu$-like
\item $\Pgt$ should print $\tau$-like
\item $\Pgn$ should print $\nu$-like % I was unable to get this macro, \Pgn, to work under any circumstance
\item $\Pl$ should print an ell
\end{itemize}

\end{document}


I tried looking into the log files. When the setmainfont command is in the second position in the MWE (the one where only the comment is), the log has the following 3 lines inside:

Missing character: There is no 𝜇 (U+1D707) in font "[xits-regular.otf]:mode=base;script=latn;language=DFLT;"!
Missing character: There is no 𝜏 (U+1D70F) in font "[xits-regular.otf]:mode=base;script=latn;language=DFLT;"!
Missing character: There is no 𝜈 (U+1D708) in font "[xits-italic.otf]:mode=base;script=latn;language=DFLT;"!


And when the setmainfont command is in the position exactly like the MWE, I get similar messages but, the weird part here, for a font that is not XITS (cmti10 is the computer modern font, right?):

Missing character: There is no 𝜈 (U+1D708) in font cmti10!
Missing character: There is no ℓ (U+2113) in font cmti10!


And this final part of the logs just confuses me. Why does it not use the xits font? Why does it not use the xits-math font when it does use the xits font? Why can it not find the characters for mu, tau, nu? As shown in the MWE, it does find those characters when I use $\mu \tau \nu$

As a final note, I am working on a mac and according to the TeX Live Utility, everything on my system is up to date (TeX Live 2015).

This is my first post on a stackexchange website, even though I have been a long time lurker, so please forgive me if I am doing something wrong. Also, despite me knowing quite a bit of LaTeX, I am not an expert user but I will be happy to try any suggestions.

The package is not adapted to unicode-math. It uses e.g. \mathit where with unicode-math you should use \symit. In your example you can solve the problem with this patch, but there more places which need to be corrected. You should contact the author.

\documentclass[12pt,a4paper,twoside]{report}

\usepackage{hepnames}

\usepackage{fontspec}
% With setmainfont here, the \Pgm and \Pgt macros work
\setmainfont
[    Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic,
]{xits}

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

% With setmainfont here, the \Pl macro works
\setmathfont
[    Extension = .otf,
BoldFont = *bold,
Ligatures=TeX,
]{xits-math}
\usepackage{xpatch}
\makeatletter
\xpatchcmd\@HepGenStyle{\mathit}{\symit}{}{\show\fail}
\makeatother
\begin{document}

Macros being tested:
\begin{itemize}
\item $\Pgm$ should print $\mu$-like
\item $\Pgt$ should print $\tau$-like
\item $\Pgn$ should print $\nu$-like % I was unable to get this macro, \Pgn, to work under any circumstance
\item $\Pl$ should print an ell
\end{itemize}

\end{document}


# Edit

The correct place for the \setmainfont is behind unicode-math, as this will set \mathit to the italic version of xits and not to computer modern.

In this case one then has to patch another command and replace \mathup. The symbols are upright now. If this is not wanted, use \usepackage[italic]{hepnames}.

\documentclass[12pt,a4paper,twoside]{report}

\usepackage{hepnames}

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

\setmainfont
[    Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic,
]{xits}

% With setmainfont here, the \Pl macro works
\setmathfont
[    Extension = .otf,
BoldFont = *bold,
Ligatures=TeX,
]{xits-math}

\usepackage{xpatch}
\makeatletter
\xpatchcmd\@HepGenStyle{\mathit}{\symit}{}{\show\fail}
\xpatchcmd\@HepConStyle{\mathup}{\symup}{}{\show\fail}
\makeatother
\begin{document}

Macros being tested:
\begin{itemize}
\item $\Pgm$ should print $\mu$-like
\item $\Pgt$ should print $\tau$-like
\item $\Pgn$ should print $\nu$-like % I was unable to get this macro, \Pgn, to work under any circumstance
\item $\Pl$ should print an ell
\end{itemize}

\end{document}


• Works just like advertised, but I'd like some more information. While David's answer gives some more information on the internal details, I'd like to understand a bit better on how the two solutions compare. From what I understand, both solutions tackle the problem in the same way, but your solution seems a bit more refined, by modifying only a specific macro. The disadvantage of your solution, is as you said, that there are other places where it needs to be modified whereas David's solution should work in those cases as well. Is my reasoning correct? – Cristovao Mar 1 '16 at 0:44
• Unicode-math has two "italic"-commands for a reason. Compare $\mathit{fitali} \neq \symit{fitali}$. \symit is for single symbols and maps to the mathematical unicode plane. \mathit maps to a text font. With Davids solution you are loosing \mathit. This may not matter in your document but it is imho not a general solution. (Like mine, there are certainly other places in the hebnames package which should be adapted to unicode-math to avoid wrong symbols and fonts but this would take some time.) – Ulrike Fischer Mar 1 '16 at 8:47
• I edited the question with a patch for the other (correct) placement of \setmainfont. – Ulrike Fischer Mar 1 '16 at 9:23

unicode-math (mostly) assumes that all symbols will be in a single large math font and that (in particular) italic will be obtained by shifting up to the plain 1 area math alphabets at Unicode U+1Dxxx.

The hep* packages in places assume a more classic TeX font layout with \mathit selecting a separate italic font.

the simplest change without requiring deeper changes to either package is just alias \mathit to \symit which selects characters within the same font by shifting the character number.

The first two rows work already with the current unicode-math package, however the second two require \mathit to be aliased to \symit (or if a global redefinition is not suitable a local definition or a package change could be used)

\documentclass[12pt,a4paper,twoside]{report}

\usepackage{hepnames}

\usepackage{fontspec}
% With setmainfont here, the \Pgm and \Pgt macros work
\setmainfont
[    Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic,
]{xits}

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

% With setmainfont here, the \Pl macro works
\setmathfont
[    Extension = .otf,
BoldFont = *bold,
Ligatures=TeX,
]{xits-math}

\begin{document}

\let\mathit\symit %<< only change

Macros being tested:
\begin{itemize}
\item $\Pgm$ should print $\mu$-like
\item $\Pgt$ should print $\tau$-like
\item $\tracingall\Pgn$ should print $\nu$-like % I was unable to get this macro, \Pgn, to work under any circumstance
\item $\Pl$ should print an ell
\end{itemize}

\end{document}