5

I want to specify the font (in the example below: Times New Roman) for all minus signs, regardless of whether they were created with the Unicode character "2212 or with a hyphen in math mode.

If I add "2212 to the range option of \setmathfont, it works when I write my text using the proper unicode character "minus sign". See the first two 6 in my example.

But when I write $-6$ (here - is an ordinary hyphen), the output is a correct minus sign, but not in Times New Roman. See the last 6 in my example.

\documentclass{article}
\RequirePackage[silent]{fontspec}
\setmainfont{Times New Roman}
\RequirePackage{unicode-math}
\setmathfont{STIXTwoMath}[]
\setmathfont{Times New Roman}[ range = { up/{num,latin,Latin}, "2212 } ]

\begin{document}

%% Minus ("2212) in source code:
−6 and $−6$

%% Hyphen ("002D) in source code:
-6 and $-6$ 

\end{document}

Output:

enter image description here

Does anyone know how I can get "access" to the hyphen in $ environments?

2
  • You want the input to be a hyphen, but the output to be the minus sign of Times New Roman? Commented Dec 15, 2023 at 16:48
  • Yes, exactly. But only in math mode: $-6$ should become a proper "minus 6", but the minus sign in Times New Roman and not from STIX.
    – Simon
    Commented Dec 15, 2023 at 17:04

2 Answers 2

4

I am unsure why that is, but if you say range = { "2212, \minus }, it works, but you really need to state both "2212 and \minus:

\documentclass{article}
\RequirePackage[silent]{fontspec}
\setmainfont{Times New Roman}
\RequirePackage{unicode-math}
\setmathfont{STIX Two Math}
\setmathfont{Times New Roman}[ 
    range = { "2212, \minus } 
]

\begin{document}

%% Minus ("2212) in source code:
−6 and $−6$

%% Hyphen ("002D) in source code:
-6 and $-6$ 

\end{document}

enter image description here

So, you might want to do something like this to select the same font for plus and minus sign:

\documentclass{article}
\RequirePackage[silent]{fontspec}
\setmainfont{Times New Roman}
\RequirePackage{unicode-math}
\setmathfont{STIX Two Math}
\setmathfont{Times New Roman}[ 
    range = { "2212, \minus, "002B } 
]

\begin{document}

-6 and $-6$ 

+6 and $+6$ 

\end{document}

enter image description here

2
  • thank you so much! The \minus solves the problem indeed.
    – Simon
    Commented Dec 16, 2023 at 12:06
  • 1
    @Simon It does, but it feels like a bug as you need to select both \minus and "2212. Commented Dec 16, 2023 at 12:14
0

I suggest you write \textnormal{-}.

enter image description here

\documentclass{article}
\RequirePackage{unicode-math}
\setmainfont{Times New Roman}
\setmathfont{STIXTwoMath}[]
\setmathfont{Times New Roman}[ range = { up/{num,latin,Latin}, "2212 } ]

\begin{document}

%% Minus ("2212) in source code:
−6 and $−6$

%% Hyphen ("002D) in source code:
-6 and $\textnormal{-}6$ 

\end{document}
1
  • Thanks, Mico. But I don't want to change the input `$-6$'. I'm looking for a global solution. (My example was a minimal working example taken from a much bigger project.)
    – Simon
    Commented Dec 15, 2023 at 17:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .