# Define certain letter in math-mode to be always non-italic - using unicode-math in lualatex

I once had this question a while ago, asking about how to set the letter j always to be non-italic j in math mode without using \mathrm.

The provided solution was:

\DeclareMathSymbol{j}{\mathalpha}{operators}{j}


However, since I changed to lualatex and unicode-math the above line has either

## no effect:

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

\DeclareMathSymbol{j}{\mathalpha}{operators}{j}

\begin{document}

$$j ~~\text{is not}~~ \mathrm{j}$$

\end{document}


or in case I define e.g. MinionPro and MnSymbol as my math fonts, the j

## disappears completely:

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

\setmainfont{Minion Pro}
\setmathfont{MnSymbol}
\setmathfont[range=\mathup/{num,latin,Latin,greek,Greek}]{Minion Pro}
\setmathfont[range=\mathbfup/{num,latin,Latin,greek,Greek}]{MinionPro-Bold}
\setmathfont[range=\mathit/{num,latin,Latin,greek,Greek}]{MinionPro-It}
\setmathfont[range=\mathbfit/{num,latin,Latin,greek,Greek}]{MinionPro-BoldIt}
\setmathfont[range=\mathscr,StylisticSet={1}]{XITS Math}
\setmathrm{Minion Pro}

\DeclareMathSymbol{j}{\mathalpha}{operators}{j}

\begin{document}

$$j ~~\text{is not}~~ \mathrm{j}$$
But actually $j$ is not there at all.

\end{document}


I tried to declare the unicode character j separately, which didn't worked out.

\setmathfont[range={"006A} ]{Minion Pro}


It made appear the j again, but it was still italic.

Any new solutions for the old problem in case unicode-math is used?

I hope it was the appropriate action to ask a new question. I didn't wanted to alter the old question as it would have made the answer invalid.

## Edit:

Not knowing that it would be important, I also need to include the amssymb package, which together with egreg's solution gives the following result:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{fontspec}
\usepackage{unicode-math}
\usepackage{etoolbox}

\setmainfont{Minion Pro}
\setmathfont{MnSymbol}
\setmathfont[range=\mathup/{num,latin,Latin,greek,Greek}]{Minion Pro}
\setmathfont[range=\mathbfup/{num,latin,Latin,greek,Greek}]{MinionPro-Bold}
\setmathfont[range=\mathit/{num,latin,Latin,greek,Greek}]{MinionPro-It}
\setmathfont[range=\mathbfit/{num,latin,Latin,greek,Greek}]{MinionPro-BoldIt}
\setmathfont[range=\mathscr,StylisticSet={1}]{XITS Math}
\setmathrm{Minion Pro}

\AfterEndPreamble{ %
\Umathcodej="0"4"6A
}

\begin{document}

$$j ~~\text{is not}~~ \mathrm{j}$$
But actually $j$ is not there at all.

\end{document}


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

\AtBeginDocument{\Umathcodej="0"0"6A }

\begin{document}

$$j ~~\text{is}~~ \mathrm{j}$$

\end{document}


I don't have MinionPro. but here is your extended version using Arial (you want 6)

\documentclass{article}

\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{fontspec}
\usepackage{unicode-math}
\usepackage{etoolbox}

\setmainfont{Arial}
\setmathfont{MnSymbol}
\setmathfont[range=\mathup/{num,latin,Latin,greek,Greek}]{Arial}
\setmathfont[range=\mathbfup/{num,latin,Latin,greek,Greek}]{Arial}
\setmathfont[range=\mathit/{num,latin,Latin,greek,Greek}]{Arial}
\setmathfont[range=\mathbfit/{num,latin,Latin,greek,Greek}]{Arial}
\setmathfont[range=\mathscr,StylisticSet={1}]{XITS Math}
\setmathrm{Arial}

\AfterEndPreamble{ %
\Umathcodej="0"6"6A
}

\begin{document}
\showoutput
$$j ~~\text{is}~~ \mathrm{j}$$
But actually $j$ is not there at all.

\end{document}


• It does solve the problem for the standard font in the first MWE, it does not work for the second MWE. – thewaywewalk Apr 21 '15 at 10:20
• @thewaywewalk I didn't do that one as I don't have the font but I just fixed your extended example using a substituted font, see updated answer – David Carlisle Apr 21 '15 at 11:44
• it finally was \Umathcodej="0"10"6A - and I'd say the most robust way is to put these command directly after the \setmathrm command. Thanks! – thewaywewalk Apr 21 '15 at 12:19

Use the proper family number for j:

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

\setmainfont{Minion Pro}
\setmathfont{MnSymbol}
\setmathfont[range=\mathup/{num,latin,Latin,greek,Greek}]{Minion Pro} % this is number 4
\setmathfont[range=\mathbfup/{num,latin,Latin,greek,Greek}]{MinionPro-Bold}
\setmathfont[range=\mathit/{num,latin,Latin,greek,Greek}]{MinionPro-It}
\setmathfont[range=\mathbfit/{num,latin,Latin,greek,Greek}]{MinionPro-BoldIt}
\setmathfont[range=\mathscr,StylisticSet={1}]{XITS Math}

\AtBeginDocument{\Umathcodej="0"4"6A }

\begin{document}

$$j \text{ is } \mathrm{j}\ne\mathbf{j}\ne\mathit{j}$$

\end{document}


• The use of the amssymb package seems to invalidate your soluton (see my edit) - can you tell why and how to fix that? And where did you got the "0"4"6A from. I always find 006A for j. I'm sorry that I haven't included this information in the first place, it didn't seemed relevant. – thewaywewalk Apr 21 '15 at 11:33
• @thewaywewalk he got it from my answer of course:-) – David Carlisle Apr 21 '15 at 11:36
• @DavidCarlisle I found 006A in the unicode table and suggested it in my question. You gave me the right code to make it work for the default font, but then egreg suggested to use 046A instead, which worked also for this case. But now with amssymb loaded it seems to change again. I'm very confused where all the character mappings come from. – thewaywewalk Apr 21 '15 at 11:41
• @thewaywewalk ignore the banter between egreg and me:-) LaTeX dynamically allocates math fonts and hides the font allocation numbers behind symbolic names such as letters but unicode-math isn't quite expecting you to do this so you need to see what number has been allocated to the mathrm font and use the same number in the primitive \Umathcode so it could be 0 or 4 or 6 or any other number between 0 and 255 (or 15) depending on the order in which you declare fonts in the preamble. – David Carlisle Apr 21 '15 at 11:50
• @thewaywewalk I added \showoutput $$j ~~\text{is}~~ \mathrm{j}\showlists$$ and the log showed .\fam6 j so I needed 6 which is "6 in hex. – David Carlisle Apr 21 '15 at 12:12