TeX - LaTeX Asked by Isabella B on April 11, 2021
Pretty much what the title says, and that is bugging me a lot. I’m using the unicode-math
package because I enjoy the upright bold greek letters it provides, as I use them for vector notation, but I noticed this weird problem. PS: I’m using XeLaTeX.
MWE:
documentclass{article}
usepackage{unicode-math}
begin{document}
[ sin^{2}x+cos^{2}x=1 ]
end{document}
PS 2: This is a Windows ruler I got from the fullscreen snip tool.
Subscripts seem to be much less affected.
Edit: As Ulrike Fischer pointed out, I had to fix the other trig macros as well, so I copy-pasted his code for other operators (all based on the spacing of the cos
macro).
I’ll leave the code just below, so that anyone with the same problems doesn’t have to bother.
makeatletter
defsin{qopnamerelax o{vphantom{operator@font cos}smash{operator@font sin}}}
defsinh{qopnamerelax o{vphantom{operator@font cos}smash{operator@font sinh}}}
defcosh{qopnamerelax o{vphantom{operator@font cos}smash{operator@font cosh}}}
deftan{qopnamerelax o{vphantom{operator@font cos}smash{operator@font tan}}}
deftanh{qopnamerelax o{vphantom{operator@font cos}smash{operator@font tanh}}}
defcot{qopnamerelax o{vphantom{operator@font cos}smash{operator@font cot}}}
defcoth{qopnamerelax o{vphantom{operator@font cos}smash{operator@font coth}}}
defsec{qopnamerelax o{vphantom{operator@font cos}smash{operator@font sec}}}
defcsc{qopnamerelax o{vphantom{operator@font cos}smash{operator@font csc}}}
makeatother
Edit 2: I’ve recently run into some problems using Ulrike Fischer’s solution, namely when using hyperref
‘s texofpdfstring
command with the altered macros. A viable solution I found is to redefine the macros above with
letcmdrelaxDeclareMathOperator{cmd}{definition}
instead of just using defcmd
.
As before, I’ll provide the code for the other macros:
makeatletter
letsinrelaxDeclareMathOperator{sin}{qopnamerelax o{vphantom{operator@font cos}smash{operator@font sin}}}
letsinhrelaxDeclareMathOperator{sinh}{qopnamerelax o{vphantom{operator@font cos}smash{operator@font sinh}}}
letcoshrelaxDeclareMathOperator{cosh}{qopnamerelax o{vphantom{operator@font cos}smash{operator@font cosh}}}
lettanrelaxDeclareMathOperator{tan}{qopnamerelax o{vphantom{operator@font cos}smash{operator@font tan}}}
lettanhrelaxDeclareMathOperator{tanh}{qopnamerelax o{vphantom{operator@font cos}smash{operator@font tanh}}}
letcotrelaxDeclareMathOperator{cot}{qopnamerelax o{vphantom{operator@font cos}smash{operator@font cot}}}
letcothrelaxDeclareMathOperator{coth}{qopnamerelax o{vphantom{operator@font cos}smash{operator@font coth}}}
letsecrelaxDeclareMathOperator{sec}{qopnamerelax o{vphantom{operator@font cos}smash{operator@font sec}}}
letcscrelaxDeclareMathOperator{csc}{qopnamerelax o{vphantom{operator@font cos}smash{operator@font csc}}}
makeatother
As wipet pointed out the placement depends on the height of the operator. You can see a similar effect (but much less pronounced) also with classical tex if you use large enough letters:
documentclass{article}
usepackage{amsmath}
usepackage{tikz}
defsin{qopnamerelax o{SIN}}
begin{document}
[tikz[overlay]draw[red](0,4.4pt)--++(5,0); sin^{2}x+cos^{2}x=1 ]
end{document}
This basically means that the amsopn definitions of these operators assume that the height differences don't matter -- an assumption which is no longer true in the context of unicode-math.
You can correct the height for example like this. As can be seen such corrections would be needed for other operators too:
documentclass{article}
usepackage{unicode-math}
usepackage{amsmath}
usepackage{tikz}
makeatletter
defsin{qopnamerelax o{vphantom{operator@font cos}smash{operator@font sin}}}
begin{document}
[tikz[overlay]draw[red](0,4.4pt)--++(5,0); cot^2 tanh^2 sin^{2}x+cos^{2}x=1 ]
end{document}
Correct answer by Ulrike Fischer on April 11, 2021
I experimented with LuaTeX, no XeTeX, but the problems are similar.
There are many position parameters read from Unicode math font. They are listed at pages 104--108 of LuaTeX manual. Main rules of vertical position of the exponent are controlled by two parameters:
Umathsupshiftup
minimal shifting up. (10pt typesetting, Latin Modern math, displaystyle, value: 3.63pt)
Umathsupshiftdrop
bottom of the exponent is shifted up to the height of the nucleus minus this value (10pt typesetting, Latin Modern math, displaystyle, value: 2.5pt)
Suppose, that we have "cos" in the nucleus and "2" in the exponent. First, the "2" is shifted up to the height of "cos" and then shifted down by Umathsupshiftdrop
. If the distance from baseline to bottom of such "2" is less than Umathsupshiftup
then forget previous calculation and shift up the "2" from baseline to Umathsupshiftup
. This second case is true when "cos" in in nucleus. But if "sin" is in the nucleus, then first case is true because "i" is higher than "cos". We can set
Umathsupshiftdropdisplaystyle=3pt
then the second case will be true for both: "sin" and "cos" and the exponent will be in the same height.
The parameters mentioned here are read from Unicode math font table (MathConstants), so the different positions of the exponent in "sin" and "cos" can be considered as bug (or feature?) of Latin Modern fonts.
I don't know, why XeTeX gives much more difference in this positioning than LuaTeX. The Umathsupshiftdrop
is represented as fontdimen24
in XeTeX. You can do experiments with this.
Answered by wipet on April 11, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP