Closed mdeff closed 2 years ago
Note that many OpenType math fonts have this issue.
For example, compare the Latin Modern OpenType (\setmathfont{latinmodern-math.otf}
)
with the Latin Modern from TeX (i.e., without \usepackage{unicode-math}
):
Are you using LuaTeX? This is a known LuaTeX issue as it ignores italic correction by default. If you search tex.stackexchange.com/ you might find a way to activate the italic correction. XeTeX should not have this problem.
Thanks for the hint! I'm using LuaTex.
There's indeed an answer on the TeX Stack Exchange where you suggest the following:
\everymath{\luatexcatcodetable\CatcodeTableLaTeX}
\everydisplay{\luatexcatcodetable\CatcodeTableLaTeX}
But \luatexcatcodetable
and \CatcodeTableLaTeX
are giving me an "undefined control sequence" error. Would you know of any other way?
XeTeX (i.e., compiling with latexmk -pdfxe
) indeed does not have this problem.
STIX Two and Cambria don't have this problem, neither with LuaTeX nor XeTeX.
The pics produced by the lua-visual-debug
package indicate, that italic correction does indeed not work for "STIX Two" either. Here is what it looks like without unicode-math
:
Note the yellow box to the right of the second f, which indicates kerning. Now with \usepackage{unicode-math}
, it looks like this:
Using \setmathfont{STIX Two Math}
produces
which still has no kerning. However, the box of the f seems to be bigger, preventing a real issue. But if you compare the STIX Two Math font to Libertinus Math in fontforge you will see that both have an "italic correction" indicator, which is not respected.
I also opened a new question on tex.SE, where someone noted that it works, if one does not use \left
and \right
:
There seems to be a solution by adding \mathitalicsmode=1
in the preamble. However, for some reason I don't understand yet, you have to remove the surrounding brackets {
and }
from the commands. So
\mathitalicsmode=1
\newcommand*{\norm}[1]{{\ensuremath{\left\|#1\right\|}}}
\newcommand*{\inner}[1]{{\ensuremath{\left\langle#1\right\rangle}}}
seems to work.
That works! Thanks for investigating and sharing your findings.
Though italic correction is not ideal for every font. For example, with STIX Two, italic correction introduces too much space. (Although that's a slight problem compared to the overlap with Libertinus.)
It's too bad that different fonts encode this information differently. 😕
\setmathfont{STIX Two Math}
without \mathitalicsmode=1
:
\setmathfont{STIX Two Math}
with \mathitalicsmode=1
:
STIX fonts are under active development, please report issues you have https://github.com/stipub/stixfonts/issues (they might be working around the broken LuaTeX default by increasing the right sidebearing and forgot to remove the italic correction).
need package physics
\ket{f} |f\rangle \expval{f,f} \langle f,f \rangle
\mathitalicsmode=1
\usepackage{unicode-math}
\unimathsetup{mathrm=sym,mathbf=sym,mathsf=sym,bold-style=ISO}
\usepackage[math=+ss08]{libertinus-otf}
\mathitalicsmode=1
\mathitalicsmode=1
\usepackage{unicode-math}
\unimathsetup{mathrm=sym,mathbf=sym,mathsf=sym,bold-style=ISO}
\usepackage[math=+ss08]{libertinus-otf}
\mathitalicsmode=1
has limited effect, for example: $ \left\langle f,f\right\rangle $
has correct spacing, but $ \left\langle {f,f}\right\rangle $
still outputs wrong spacing .
The definition of \expval
in physics looks like this:
\DeclareDocumentCommand\expectationvalue{ s s m g }
{ % Expectation value
\IfNoValueTF{#4}
{
\IfBooleanTF{#1}
{\vphantom{#3}\left\langle\smash{#3}\right\rangle} % Starred implicit form: no resizing
{\left\langle{#3}\right\rangle} % Normal implicit form: auto sizing
}
{
\IfBooleanTF{#1}
{
\IfBooleanTF{#2}
{\left\langle{#4}\middle\vert{#3}\middle\vert{#4}\right\rangle} % Double starred explicit form: total auto sizing
{\vphantom{#3#4}\left\langle\smash{#4}\middle\vert\smash{#3}\middle\vert\smash{#4}\right\rangle} % Starred explicit form: no resizing
}
{\vphantom{#3}\left\langle{#4}\middle\vert\smash{#3}\middle\vert{#4}\right\rangle} % Normal explicit form: only resize based on bra/ket arguments
}
}
You can see it added { }
or \smash
. Both currently invalidate the automatically added italic correction. It should be because, with { }
or \smash
, their contents will form a new ord atom, and no italic correction is applied to the end of this ord atom.
Italic correction can only be added manually: \expval{f,f\/}
.
\mathitalicsmode=1
has limited effect
so maybe increase width of letter f
is the ultimate solution?
\documentclass{article}
\usepackage{unicode-math}
\mathitalicsmode=1
\setmathfont{LibertinusMath-Regular.otf}
\newcommand*{\norm}[1]{{\ensuremath{\|{#1}\|}}}
\newcommand*{\inner}[1]{{\ensuremath{\langle{#1}\rangle}}}
\begin{document}
\[
\inner{f, f} \hspace{2em}
\norm{f}_2^2 \hspace{2em}
\inner{g, g} \hspace{2em}
\norm{g}_2^2 \hspace{2em}
\]
\end{document}
\documentclass{article}
\usepackage{unicode-math}
\mathitalicsmode=2
\setmathfont{LibertinusMath-Regular.otf}
\newcommand*{\norm}[1]{{\ensuremath{\|{#1}\|}}}
\newcommand*{\inner}[1]{{\ensuremath{\langle{#1}\rangle}}}
\begin{document}
\[
\inner{f, f} \hspace{2em}
\norm{f}_2^2 \hspace{2em}
\inner{g, g} \hspace{2em}
\norm{g}_2^2 \hspace{2em}
\]
\end{document}
Describe the bug When typesetting ⟨f,f⟩ and ‖f‖, the spacing between the letter f and the angles and bars is uneven.
Steps to reproduce Compile the following document with
latexmk -pdflua
.Expected vs. actual behavior The spacing should be similar on the left and right, as it is when typesetting ⟨g,g⟩ and ‖g‖.
Screenshots![20211227_191848](https://user-images.githubusercontent.com/6806065/147497860-823b0168-9138-443e-90b5-266168b062e8.png)