# Italic math within \mathrm

How can I escape to "normal math" from within \mathrm?

In my package mhchem, I used \text{\ensuremath{2n-1}} which did a perfect job. However, unicode-math came along, broke established behavior and I now need to find another way ([1], [2]).

\mathnormal was suggested, but that renders digits differently.

So, what is an alternative for this code that works in a generic setup?  \mathrm{...\text{\ensuremath{2n-1}}...} 

• your question is phrased as a general question but really you are asking about a unicode-math specific context and the answer is to use a unicode-math specific command to undo its changes, as discussed in github. – David Carlisle Apr 28 '18 at 9:09
• @DavidCarlisle No, I don't want a unicode-math-specific solution. I want a generic one and avoid any "Is unicode-math active?" code in my package. – mhchem Apr 28 '18 at 9:10
• then sorry you are doomed. The question has no general answer for any possible definition of \mathrm – David Carlisle Apr 28 '18 at 9:11
• unicode tex engines like xetex and luatex have two essentially separate math layout engines. One for classic tex tfm fonts and one for opentype fonts with a MATH table. unicode-math package tries as far as possible to make the surface syntax for the user the same, but internally everything is different and if you are using "hidden" math contexts then it is not likely that you can avoid having conditional code for the two contexts – David Carlisle Apr 28 '18 at 9:15
• Can you please show an example for the changed digits? – Ulrike Fischer Apr 28 '18 at 12:28

I'm not entirely sure what you mean by "escaping to normal math from within \mathrm, but I think (hope?) that \mathrm{\symit{2n-1}} does what you need.

Here's a table to show the output of the 4 available \sym<xx> directives. After that, a contrast between \mathrm{\text{\ensuremath{2n-1}}} and \mathrm{\symit{2n-1}}.

\documentclass{article}
\usepackage{array}
\usepackage{amsmath} % for \text and \ensuremath macros
\usepackage{unicode-math}
\begin{document}
$\begin{array}{@{} >{$}l<{$} >{$\ttfamily}l<{$} l} default & & 2n-1 \\ upright & \string\symup & \symup{2n-1} \\ bold & \string\symbf & \symbf{2n-1} \\ italic & \string\symit & \symit{2n-1} \\ sans-serif & \string\symsf & \symsf{2n-1} \end{array}$

\medskip
$\mathrm{2n-1}$ \& $\symup{2n-1}$

$\mathrm{\text{\ensuremath{2n-1}}}$ \&
$\mathrm{\symit{2n-1}}$
\end{document}

• Yes, \mathrm{\symit{2n-1}} does what I need. Initially, I was looking for code that worked everywhere, but, according to David, that is not possible. So, I guess my package will need a "if unicode-math" condition. – mhchem Apr 28 '18 at 20:14
• @mhchem - You may want to load the ifluatex and ifxetex packages, and use them to set up high-level macros whose definitions will differ depending on whether LuaLaTeX, XeLaTeX, or pdfLaTeX is in use. – Mico Apr 28 '18 at 20:18
• I don't understand. I could compile a document with LuaLaTeX or XeLaTeX and the command \symit would still be undefined (when the package unicode-math was not loaded). – mhchem Apr 28 '18 at 20:23
• @mhchem - Sorry I wasn't clear enough. I was assuming that if LuaLaTeX or XeLaTeX are used to compile the document, the unicode-math package would be loaded. – Mico Apr 28 '18 at 20:34
• Obervation: while $2n-1$ and $\symit{2n-1}$ liik identical, $\Delta$ will differ from $\symit{\Delta}$ – mhchem Jun 21 '18 at 7:51