8

Why does the \pm sign is ower compared to the number next to it? Is it normal behaviour? How can I raise it so to be at the same level as the number?

My distribution is Vanilla TeX and it is installed less than a week ago so it is updated.

enter image description here

\documentclass{article}

\usepackage[top=0.7in, bottom=1.2in, left=0.8in, right=0.8in]{geometry}

\usepackage{parskip}

\setlength{\parindent}{0cm}

\usepackage{amsmath}

\usepackage{unicode-math}

\usepackage{fontspec}

\usepackage[greek,english]{babel}

\setmainfont
[
    Ligatures=TeX,
    Extension=.otf,
    UprightFont=*,
    BoldFont=*Bold,
    ItalicFont=*It,
    BoldItalicFont=*BoldIt,
    Mapping=tex-text
]{GFSArtemisia}

\setsansfont[Mapping=tex-text]{GFSArtemisia.otf}

\setmathfont{latinmodern-math.otf}

\setmathfont[range=\varnothing]{Asana-Math.otf}

\setmathfont[range=\int]{latinmodern-math.otf}

\begin{document}

$$x= \pm 1$$

\end{document}
  • 1
    Please read Why is \[\] preferable to $$?... – Werner May 9 '15 at 0:13
  • 1
    Note that unicode-math already loads fontspec, so no need to load both – darthbith May 9 '15 at 1:07
  • @darthbith I know it, someone has mention it previously. I do it just in case. Thank you though. – Adam May 9 '15 at 1:24
5

The following, stripped-down version of your example reproduces the positioning problem you've encountered:

\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}
\begin{document}
$x= \pm 1$
\end{document}

The culprit appears to be the instruction \usepackage{unicode-math}, which loads the Latin Modern Math fonts. If the package isn't loaded, the positioning problem with the \pm symbol goes away, because fonts from the amsfonts collection are loaded instead. In a deeper sense, the culprit should be called the Latin Modern Math font. (See also @egreg's answer for a way to fix the bug introduced in a recent version of the Latin Modern Math fonts.)

Judging from your example code, the reason for loading the unicode-math package is so that you can run the instruction \setmathfont[range=\varnothing]{Asana-Math.otf}. If you can make do without this alternate form of the \varnothing symbol, I suggest you simply not load the unicode-math package and drop the \setmathfont instructions.

enter image description here

\documentclass{article}
\usepackage{fontspec}
\begin{document}
$x= \pm 1$
\end{document}
  • Thank you for your answer! It is not minimal as I usually don't know which package depends on what output exactly, so I remove the ones I am absolutely sure that are not needed and leave the rest. Furthermore that way I have learned so many things about dependencies. – Adam May 9 '15 at 3:18
  • I get nothing with “LM Math”; check whether you have a very old version of Latin Modern Math (that used to be called like that). – egreg May 9 '15 at 9:18
  • @egreg: from the log file: Package: unicode-math 2014/06/30 v0.7f Unicode maths in XeLaTeX and LuaLaTeX, lualatex-math 2014/08/18 v1.4, and luaotfload | load : Lookup/name: "LM Math" -> "LMMATH-v0903.otf". Is that a really old version of the otf file? – Mico May 9 '15 at 9:40
  • otfinfo -v latinmodern-math.otf gives me Version 1.959 – egreg May 9 '15 at 9:42
  • @egreg - Indeed, a by now four-year-old version of LM-MATH was still hanging around. I've deleted it, and now the second "solution" no longer works on my system either (MacTeX2015 pre-release). Will edit my answer to delete the second solution. Thanks for alerting me to this issue. – Mico May 9 '15 at 9:57
7

It seems to be a “design decision” (read “bug”) by the developers of Latin Modern Math.

Here is the evidence; I typeset the character in text mode, so it can't be influenced by possible effects of automatic math spacing or vertical shifting.

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

\setmathfont{latinmodern-math.otf}

\newfontface{\test}{latinmodern-math.otf}


\begin{document}

{\test\char"B1 +} $x= \pm 1$

\end{document}

enter image description here

Fixed version:

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

\AtBeginDocument{%
  \let\ORIpm\pm
  \let\pm\shifteduppm
}

\makeatletter
\newcommand{\shifteduppm}{%
  \mathbin{\mathpalette\shifted@up@pm\relax}%
}
\newcommand{\shifted@up@pm}{%
  \raisebox{\depth}{$\m@th#1\ORIpm$}%
}
\makeatother

\setmathfont{latinmodern-math.otf}

\newfontface{\test}{latinmodern-math.otf}

\begin{document}

{\test\char"B1 +} $x= \pm 1$

\end{document}

enter image description here

As you see, the usage in math is as expected.

Alternative solution: use the \pm symbol from good old Computer Modern:

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

\DeclareSymbolFont{oldsymbols}{OMS}{cmsy}{m}{n}
\SetSymbolFont{oldsymbols}{bold}{OMS}{cmsy}{b}{n}
\DeclareMathSymbol{\CMpm}{\mathbin}{oldsymbols}{"06}
\AtBeginDocument{\let\pm\CMpm}

\setmathfont{latinmodern-math.otf}

\newfontface{\test}{latinmodern-math.otf}

\begin{document}

{\test\char"B1 +} $x= \pm 1$

\end{document}
  • In the fixed version you use \mathpalette but then you don't use the first argument. – Manuel May 9 '15 at 11:44
  • Excellent. Thank you very much for your answer! – Adam May 9 '15 at 19:33
  • I see the same "design decision" in STIX TWO MATH under Lualatex, and this code repairs it there as well. – John Sep 3 '18 at 19:31
1

It's due to the font you choose. You should use an other font if you dislike this sign. So with this font it's normal. Do you need the line :

\setmathfont{latinmodern-math.otf}

maybe you can reassign the base font only for the \pm sign, like you did for \int for example

p.s. : I didn't know Vanilla TeX. My answer is correct for XeLaTeX, but I think it should also work for Vanilla.

  • The OP is already using the instruction \setmathfont{latinmodern-math.otf}. – Mico May 9 '15 at 2:28

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.