'Dimension too large' error when setmathfont has the option Scale=MatchLowercaseSuperscript placement using...

I encountered my boss during an on-site interview at another company. Should I bring it up when seeing him next time?

Rationale to prefer local variables over instance variables?

How to mitigate "bandwagon attacking" from players?

When do _WA_Sys_ statistics Get Updated?

Can a space-faring robot still function over a billion years?

Giving a talk in my old university, how prominently should I tell students my salary?

What is the meaning of "notice to quit at once" and "Lotty points”

Practical reasons to have both a large police force and bounty hunting network?

The need of reserving one's ability in job interviews

I can't die. Who am I?

Lock enemy's y-axis when using Vector3.MoveTowards to follow the player

Should I use HTTPS on a domain that will only be used for redirection?

Why is it "take a leak?"

PTIJ: What’s wrong with eating meat and couscous?

In which way proportional valves are controlled solely by current?

Is every open circuit a capacitor?

Caulking a corner instead of taping with joint compound?

Would the melodic leap of the opening phrase of Mozart's K545 be considered dissonant?

How to kill a localhost:8080

Is there a full canon version of Tyrion's jackass/honeycomb joke?

Understanding the template

When to use mean vs median

How can I be pwned if I'm not registered on the compromised site?

What could be a means to defeat a childrens’ nightmare?



'Dimension too large' error when setmathfont has the option Scale=MatchLowercase


Superscript placement using unicode-math with scalingCambria Math becomes plain CambriaUpright greeks in Asana-math?unicode-math and tex4ht with utf-8 inputxelatex problem: Missing chars in TeXLive 2013 / textfont XXX is undefined errors in miktexPrevent XeTeX infinite loopGraph theory notationHow do I get the XITS font to work with unicode-math and hepnames in lualatexAboriginal fonts cause wrong page size warningsPackage xcolor Error: “Undefined colors when master (classicthesis 3.1) has PDF included” even though the PDF has been deleted from the documentXeLaTex includegraphics Dimension too large













4















documentclass{article}
usepackage{unicode-math}
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase]{Cambria Math}
begin{document}
n $n sqrt[n]{n}$
end{document}


The above code when typeset with XeTeX produces an error saying 'Dimension too large'. Removing [Scale=MatchLowercase] resolves it but I need the option for the combination of other text and math fonts I'm using.



This issue seems recent. The last time I typeset a XeTeX document that uses unicode-math and contains sqrt[n]{n} was about a year ago and the issue wasn't present at the time. Is there something wrong with one of the latest versions of unicode-math, namely 0.8m or 0.8n?



Nevertheless, the output PDF file is fine. I'm not sure if I should be worried, but having to keep dismissing the error is inconvenient. As a workaround I'll use the notation ^{1/n} for now.










share|improve this question




















  • 4





    Looks like a bug. Add an issue at github.com/wspr/unicode-math/issues (with lualatex it works, the problem is xetex specific).

    – Ulrike Fischer
    Feb 20 at 9:52
















4















documentclass{article}
usepackage{unicode-math}
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase]{Cambria Math}
begin{document}
n $n sqrt[n]{n}$
end{document}


The above code when typeset with XeTeX produces an error saying 'Dimension too large'. Removing [Scale=MatchLowercase] resolves it but I need the option for the combination of other text and math fonts I'm using.



This issue seems recent. The last time I typeset a XeTeX document that uses unicode-math and contains sqrt[n]{n} was about a year ago and the issue wasn't present at the time. Is there something wrong with one of the latest versions of unicode-math, namely 0.8m or 0.8n?



Nevertheless, the output PDF file is fine. I'm not sure if I should be worried, but having to keep dismissing the error is inconvenient. As a workaround I'll use the notation ^{1/n} for now.










share|improve this question




















  • 4





    Looks like a bug. Add an issue at github.com/wspr/unicode-math/issues (with lualatex it works, the problem is xetex specific).

    – Ulrike Fischer
    Feb 20 at 9:52














4












4








4








documentclass{article}
usepackage{unicode-math}
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase]{Cambria Math}
begin{document}
n $n sqrt[n]{n}$
end{document}


The above code when typeset with XeTeX produces an error saying 'Dimension too large'. Removing [Scale=MatchLowercase] resolves it but I need the option for the combination of other text and math fonts I'm using.



This issue seems recent. The last time I typeset a XeTeX document that uses unicode-math and contains sqrt[n]{n} was about a year ago and the issue wasn't present at the time. Is there something wrong with one of the latest versions of unicode-math, namely 0.8m or 0.8n?



Nevertheless, the output PDF file is fine. I'm not sure if I should be worried, but having to keep dismissing the error is inconvenient. As a workaround I'll use the notation ^{1/n} for now.










share|improve this question
















documentclass{article}
usepackage{unicode-math}
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase]{Cambria Math}
begin{document}
n $n sqrt[n]{n}$
end{document}


The above code when typeset with XeTeX produces an error saying 'Dimension too large'. Removing [Scale=MatchLowercase] resolves it but I need the option for the combination of other text and math fonts I'm using.



This issue seems recent. The last time I typeset a XeTeX document that uses unicode-math and contains sqrt[n]{n} was about a year ago and the issue wasn't present at the time. Is there something wrong with one of the latest versions of unicode-math, namely 0.8m or 0.8n?



Nevertheless, the output PDF file is fine. I'm not sure if I should be worried, but having to keep dismissing the error is inconvenient. As a workaround I'll use the notation ^{1/n} for now.







xetex unicode-math bugs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 20 at 10:45







Taiki

















asked Feb 20 at 9:11









TaikiTaiki

30919




30919








  • 4





    Looks like a bug. Add an issue at github.com/wspr/unicode-math/issues (with lualatex it works, the problem is xetex specific).

    – Ulrike Fischer
    Feb 20 at 9:52














  • 4





    Looks like a bug. Add an issue at github.com/wspr/unicode-math/issues (with lualatex it works, the problem is xetex specific).

    – Ulrike Fischer
    Feb 20 at 9:52








4




4





Looks like a bug. Add an issue at github.com/wspr/unicode-math/issues (with lualatex it works, the problem is xetex specific).

– Ulrike Fischer
Feb 20 at 9:52





Looks like a bug. Add an issue at github.com/wspr/unicode-math/issues (with lualatex it works, the problem is xetex specific).

– Ulrike Fischer
Feb 20 at 9:52










2 Answers
2






active

oldest

votes


















7














Imho the definition of __um_fontdimen_to_percent:nN is faulty, it should use dim_to_decimal_in_sp instead of dim_to_decimal:n



documentclass{article}
usepackage{unicode-math}
ExplSyntaxOn
cs_set:Nn __um_fontdimen_to_percent:nN
{
fp_eval:n { dim_to_decimal_in_sp:n { fontdimen #1 #2 } / 100 }
}
ExplSyntaxOff
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase]{Cambria Math}

begin{document}
n $n sqrt[n]{n}$
end{document}





share|improve this answer


























  • Thank you. I think I'll leave it to you to add an issue to github.com/wspr/unicode-math/issues along with the suggested fix.

    – Taiki
    Feb 20 at 10:26








  • 2





    No, you found the bug so you should add the issue. I already spent enough time in finding the relevant code piece.

    – Ulrike Fischer
    Feb 20 at 10:28











  • OK. Done: github.com/wspr/unicode-math/issues/515

    – Taiki
    Feb 20 at 10:43






  • 1





    For information : this is not XeTeX-specific ; also arise with LuaLaTeX (only with beamer, in my setup) and the above does fix it.

    – ysalmon
    Feb 20 at 14:33






  • 1





    Oh dear! This posted solution is not bullet-proof: It still breaks down if I use setmathfont[Scale=1.031380753]{latinmodern-math.otf}. See the continued discussions on GitHub.

    – Ruixi Zhang
    Feb 20 at 23:19





















2














Update



As of unicode-math v0.8o (2019/03/04), this bug is fixed for normal Scale usage. The update includes a variant of Ulrike Fischer’s answer, and more crucially, a sloppier setup for font dimensions in fam 2 and 3.



The change from ScaleAgain = 1.00001 and ScaleAgain = 0.99999 to ScaleAgain = 1.0001 and ScaleAgain = 0.9999 effectively lowered the upper bound of the set B in Theorem 1 below. The set B now terminates at around k=10000, which is around Scale=0.153. This means, as long as the user requested Scale is above 0.153, then unicode-math would setup font dimensions correctly.



If the requested Scale is below 0.153, then the font dimension problem persists. But it was deemed that normal usage would never produce Scale=0.153 or lower, so we are safe for the most parts. See more detailed analysis here and here.





Old answers



Although I agree with Ulrike Fischer that this is a unicode-math bug, I’m afraid that I have to disagree with the claim that “__um_fontdimen_to_percent:nN is broken”. Indeed, using dim_to_decimal_in_sp:n is a great improvement, but it is not where the actual problem lies. I shall first present my solution and then try to discuss the root cause.



Note that the following solution is meant to be temporary until unicode-math fixes this in the next release.





Solution



For a relatively simple solution, you can use the new feature ScaleAgain to slightly distort the font size (it won’t be visible to the human eyes):



documentclass{article}
usepackage{unicode-math}% v0.8n, 2019/02/15
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase,ScaleAgain=0.99999]{Cambria Math}
begin{document}
n $n sqrt[n]{n}$
end{document}


ScaleAgain



In practice, you’ll have to try a range of ScaleAgain near 1 to be able to compile. Again, this shall be fixed in the next release of unicode-math.





A Theorem on the overflow behavior of unicode-math v0.8n



For those who are interested in the bizarre overflow behavior, here is a theorem, based on the two fixed ScaleAgain factors in unicode-math v0.8n.



First comes the visualizations on which Scale’s are safe and which may cause problem:




Near Scale=1:
scale1

Near Scale=1.2:
scale1.2

Near Scale=1.5:
scale1.5



All green line segments represent the safe Scale factors, while red line segments represent the problematic ones.



Here is the rigorous mathematical description:
Theorem



In particular, Scale=1.031369386, Scale=1.031374755, Scale=1.031384644 and Scale=1.031390014 all lead to ! Dimension too large. Near Scale=1.03138:
scale1.03138






Discussions



The x-heights of Georgia and Cambria Math are, respectively, 986/2048 and 956/2048. And Scale=MatchLowercase is correctly converted into Scale=1.03138 by fontspec. Now, if we were to apply the suggested re-definition of __um_fontdimen_to_percent:nN when using Latin Modern Math, we would be surprise to find out that:



documentclass{article}
usepackage{unicode-math}% v0.8n, 2019/02/15
% https://tex.stackexchange.com/a/475802, by Ulrike Fischer:
ExplSyntaxOn
cs_set:Nn __um_fontdimen_to_percent:nN
{
fp_eval:n { dim_to_decimal_in_sp:n { fontdimen #1 #2 } / 100 }
}
ExplSyntaxOff

newcommand*tempscale{1.03138}% Also fails at 1.02, 1.05, 1.07
setmathfont[Scale=tempscale]{latinmodern-math.otf}

begin{document}
n $n sqrt[n]{n}$
end{document}


still produces the ! Dimension too large. error.



Even more strangely, if we instead use a scale factor of either 1.03137 or 1.03139, then your Georgia + Cambria Math example compiles successfully, and so does my Latin Modern Math example (with or without the re-definition of __um_fontdimen_to_percent:nN).



The root cause of the problem is the new feature ScaleAgain from fontspec, which is meant to solve a long standing problem (see Superscript placement using unicode-math with scaling and Scale option doesn't fully work with LuaLaTeX). Oh, and also the fact that TeX is “not good at math”.



To setup the math-related legacy font dimensions correctly, unicode-math must load the same math font three times. But TeX wouldn’t allow the same font to be loaded twice at the same size, so unicode-math has to load the font at slightly different sizes for the 2nd and the 3rd times. These slightly different sizes are obtained by compounding the previous scale factor. This was the main reason that ScaleAgain was introduced in fontspec, so unicode-math can do ScaleAgain=1.00001 for the 2nd time and ScaleAgain=0.99999 for the 3rd time. As my comment pointed out, sometimes unicode-math will fail to distinguish the three sizes due to TeX’s binary arithmetic.



Your example was “unlucky” enough to have Scale=1.03138, which translates to Round( 1.03138 * 2^16 ) = 67593. After ScaleAgain=1.00001, TeX sees 1.03139, which translates to Round( 1.03139 * 2^16 ) = 67593. So TeX thinks that the second family and the first family are the same font, and proceeds to overwrite fontdimen’s under the instruction of unicode-math. This causes the overflow, because the new fontdimen’s are no longer percentages which are less than one, but are now physical lengths which can get quite large.



With setmathfont[Scale=MatchLowercase,ScaleAgain=0.99999]{Cambria Math}, we are basically trying to prevent TeX from loading the math font at the same size accidentally.






share|improve this answer


























  • __um_fontdimen_to_percent:nN is broken. Multiplying a dimension by 65536 is simply a very bad idea - it will overflow even if the dimension is only 1pt large. Imho your ScaleAgain workaround is only hiding the problem - something in the math is wrong when unicode-math is trying to insert a kern.

    – Ulrike Fischer
    Feb 21 at 11:53











  • @UlrikeFischer I fully agree with your improvement for __um_fontdimen_to_percent:nN. But, on the contrary, your dim_to_decimal_in_sp:n actually hides the bug even more IMHO. See, setmathfont[Scale=0.7]{latinmodern-math.otf} is not supposed to work, either, but your improvement let it through. I continued my discussion here.

    – Ruixi Zhang
    Feb 21 at 16:58











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f475792%2fdimension-too-large-error-when-setmathfont-has-the-option-scale-matchlowercas%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









7














Imho the definition of __um_fontdimen_to_percent:nN is faulty, it should use dim_to_decimal_in_sp instead of dim_to_decimal:n



documentclass{article}
usepackage{unicode-math}
ExplSyntaxOn
cs_set:Nn __um_fontdimen_to_percent:nN
{
fp_eval:n { dim_to_decimal_in_sp:n { fontdimen #1 #2 } / 100 }
}
ExplSyntaxOff
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase]{Cambria Math}

begin{document}
n $n sqrt[n]{n}$
end{document}





share|improve this answer


























  • Thank you. I think I'll leave it to you to add an issue to github.com/wspr/unicode-math/issues along with the suggested fix.

    – Taiki
    Feb 20 at 10:26








  • 2





    No, you found the bug so you should add the issue. I already spent enough time in finding the relevant code piece.

    – Ulrike Fischer
    Feb 20 at 10:28











  • OK. Done: github.com/wspr/unicode-math/issues/515

    – Taiki
    Feb 20 at 10:43






  • 1





    For information : this is not XeTeX-specific ; also arise with LuaLaTeX (only with beamer, in my setup) and the above does fix it.

    – ysalmon
    Feb 20 at 14:33






  • 1





    Oh dear! This posted solution is not bullet-proof: It still breaks down if I use setmathfont[Scale=1.031380753]{latinmodern-math.otf}. See the continued discussions on GitHub.

    – Ruixi Zhang
    Feb 20 at 23:19


















7














Imho the definition of __um_fontdimen_to_percent:nN is faulty, it should use dim_to_decimal_in_sp instead of dim_to_decimal:n



documentclass{article}
usepackage{unicode-math}
ExplSyntaxOn
cs_set:Nn __um_fontdimen_to_percent:nN
{
fp_eval:n { dim_to_decimal_in_sp:n { fontdimen #1 #2 } / 100 }
}
ExplSyntaxOff
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase]{Cambria Math}

begin{document}
n $n sqrt[n]{n}$
end{document}





share|improve this answer


























  • Thank you. I think I'll leave it to you to add an issue to github.com/wspr/unicode-math/issues along with the suggested fix.

    – Taiki
    Feb 20 at 10:26








  • 2





    No, you found the bug so you should add the issue. I already spent enough time in finding the relevant code piece.

    – Ulrike Fischer
    Feb 20 at 10:28











  • OK. Done: github.com/wspr/unicode-math/issues/515

    – Taiki
    Feb 20 at 10:43






  • 1





    For information : this is not XeTeX-specific ; also arise with LuaLaTeX (only with beamer, in my setup) and the above does fix it.

    – ysalmon
    Feb 20 at 14:33






  • 1





    Oh dear! This posted solution is not bullet-proof: It still breaks down if I use setmathfont[Scale=1.031380753]{latinmodern-math.otf}. See the continued discussions on GitHub.

    – Ruixi Zhang
    Feb 20 at 23:19
















7












7








7







Imho the definition of __um_fontdimen_to_percent:nN is faulty, it should use dim_to_decimal_in_sp instead of dim_to_decimal:n



documentclass{article}
usepackage{unicode-math}
ExplSyntaxOn
cs_set:Nn __um_fontdimen_to_percent:nN
{
fp_eval:n { dim_to_decimal_in_sp:n { fontdimen #1 #2 } / 100 }
}
ExplSyntaxOff
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase]{Cambria Math}

begin{document}
n $n sqrt[n]{n}$
end{document}





share|improve this answer















Imho the definition of __um_fontdimen_to_percent:nN is faulty, it should use dim_to_decimal_in_sp instead of dim_to_decimal:n



documentclass{article}
usepackage{unicode-math}
ExplSyntaxOn
cs_set:Nn __um_fontdimen_to_percent:nN
{
fp_eval:n { dim_to_decimal_in_sp:n { fontdimen #1 #2 } / 100 }
}
ExplSyntaxOff
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase]{Cambria Math}

begin{document}
n $n sqrt[n]{n}$
end{document}






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 20 at 10:31

























answered Feb 20 at 10:21









Ulrike FischerUlrike Fischer

194k8302688




194k8302688













  • Thank you. I think I'll leave it to you to add an issue to github.com/wspr/unicode-math/issues along with the suggested fix.

    – Taiki
    Feb 20 at 10:26








  • 2





    No, you found the bug so you should add the issue. I already spent enough time in finding the relevant code piece.

    – Ulrike Fischer
    Feb 20 at 10:28











  • OK. Done: github.com/wspr/unicode-math/issues/515

    – Taiki
    Feb 20 at 10:43






  • 1





    For information : this is not XeTeX-specific ; also arise with LuaLaTeX (only with beamer, in my setup) and the above does fix it.

    – ysalmon
    Feb 20 at 14:33






  • 1





    Oh dear! This posted solution is not bullet-proof: It still breaks down if I use setmathfont[Scale=1.031380753]{latinmodern-math.otf}. See the continued discussions on GitHub.

    – Ruixi Zhang
    Feb 20 at 23:19





















  • Thank you. I think I'll leave it to you to add an issue to github.com/wspr/unicode-math/issues along with the suggested fix.

    – Taiki
    Feb 20 at 10:26








  • 2





    No, you found the bug so you should add the issue. I already spent enough time in finding the relevant code piece.

    – Ulrike Fischer
    Feb 20 at 10:28











  • OK. Done: github.com/wspr/unicode-math/issues/515

    – Taiki
    Feb 20 at 10:43






  • 1





    For information : this is not XeTeX-specific ; also arise with LuaLaTeX (only with beamer, in my setup) and the above does fix it.

    – ysalmon
    Feb 20 at 14:33






  • 1





    Oh dear! This posted solution is not bullet-proof: It still breaks down if I use setmathfont[Scale=1.031380753]{latinmodern-math.otf}. See the continued discussions on GitHub.

    – Ruixi Zhang
    Feb 20 at 23:19



















Thank you. I think I'll leave it to you to add an issue to github.com/wspr/unicode-math/issues along with the suggested fix.

– Taiki
Feb 20 at 10:26







Thank you. I think I'll leave it to you to add an issue to github.com/wspr/unicode-math/issues along with the suggested fix.

– Taiki
Feb 20 at 10:26






2




2





No, you found the bug so you should add the issue. I already spent enough time in finding the relevant code piece.

– Ulrike Fischer
Feb 20 at 10:28





No, you found the bug so you should add the issue. I already spent enough time in finding the relevant code piece.

– Ulrike Fischer
Feb 20 at 10:28













OK. Done: github.com/wspr/unicode-math/issues/515

– Taiki
Feb 20 at 10:43





OK. Done: github.com/wspr/unicode-math/issues/515

– Taiki
Feb 20 at 10:43




1




1





For information : this is not XeTeX-specific ; also arise with LuaLaTeX (only with beamer, in my setup) and the above does fix it.

– ysalmon
Feb 20 at 14:33





For information : this is not XeTeX-specific ; also arise with LuaLaTeX (only with beamer, in my setup) and the above does fix it.

– ysalmon
Feb 20 at 14:33




1




1





Oh dear! This posted solution is not bullet-proof: It still breaks down if I use setmathfont[Scale=1.031380753]{latinmodern-math.otf}. See the continued discussions on GitHub.

– Ruixi Zhang
Feb 20 at 23:19







Oh dear! This posted solution is not bullet-proof: It still breaks down if I use setmathfont[Scale=1.031380753]{latinmodern-math.otf}. See the continued discussions on GitHub.

– Ruixi Zhang
Feb 20 at 23:19













2














Update



As of unicode-math v0.8o (2019/03/04), this bug is fixed for normal Scale usage. The update includes a variant of Ulrike Fischer’s answer, and more crucially, a sloppier setup for font dimensions in fam 2 and 3.



The change from ScaleAgain = 1.00001 and ScaleAgain = 0.99999 to ScaleAgain = 1.0001 and ScaleAgain = 0.9999 effectively lowered the upper bound of the set B in Theorem 1 below. The set B now terminates at around k=10000, which is around Scale=0.153. This means, as long as the user requested Scale is above 0.153, then unicode-math would setup font dimensions correctly.



If the requested Scale is below 0.153, then the font dimension problem persists. But it was deemed that normal usage would never produce Scale=0.153 or lower, so we are safe for the most parts. See more detailed analysis here and here.





Old answers



Although I agree with Ulrike Fischer that this is a unicode-math bug, I’m afraid that I have to disagree with the claim that “__um_fontdimen_to_percent:nN is broken”. Indeed, using dim_to_decimal_in_sp:n is a great improvement, but it is not where the actual problem lies. I shall first present my solution and then try to discuss the root cause.



Note that the following solution is meant to be temporary until unicode-math fixes this in the next release.





Solution



For a relatively simple solution, you can use the new feature ScaleAgain to slightly distort the font size (it won’t be visible to the human eyes):



documentclass{article}
usepackage{unicode-math}% v0.8n, 2019/02/15
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase,ScaleAgain=0.99999]{Cambria Math}
begin{document}
n $n sqrt[n]{n}$
end{document}


ScaleAgain



In practice, you’ll have to try a range of ScaleAgain near 1 to be able to compile. Again, this shall be fixed in the next release of unicode-math.





A Theorem on the overflow behavior of unicode-math v0.8n



For those who are interested in the bizarre overflow behavior, here is a theorem, based on the two fixed ScaleAgain factors in unicode-math v0.8n.



First comes the visualizations on which Scale’s are safe and which may cause problem:




Near Scale=1:
scale1

Near Scale=1.2:
scale1.2

Near Scale=1.5:
scale1.5



All green line segments represent the safe Scale factors, while red line segments represent the problematic ones.



Here is the rigorous mathematical description:
Theorem



In particular, Scale=1.031369386, Scale=1.031374755, Scale=1.031384644 and Scale=1.031390014 all lead to ! Dimension too large. Near Scale=1.03138:
scale1.03138






Discussions



The x-heights of Georgia and Cambria Math are, respectively, 986/2048 and 956/2048. And Scale=MatchLowercase is correctly converted into Scale=1.03138 by fontspec. Now, if we were to apply the suggested re-definition of __um_fontdimen_to_percent:nN when using Latin Modern Math, we would be surprise to find out that:



documentclass{article}
usepackage{unicode-math}% v0.8n, 2019/02/15
% https://tex.stackexchange.com/a/475802, by Ulrike Fischer:
ExplSyntaxOn
cs_set:Nn __um_fontdimen_to_percent:nN
{
fp_eval:n { dim_to_decimal_in_sp:n { fontdimen #1 #2 } / 100 }
}
ExplSyntaxOff

newcommand*tempscale{1.03138}% Also fails at 1.02, 1.05, 1.07
setmathfont[Scale=tempscale]{latinmodern-math.otf}

begin{document}
n $n sqrt[n]{n}$
end{document}


still produces the ! Dimension too large. error.



Even more strangely, if we instead use a scale factor of either 1.03137 or 1.03139, then your Georgia + Cambria Math example compiles successfully, and so does my Latin Modern Math example (with or without the re-definition of __um_fontdimen_to_percent:nN).



The root cause of the problem is the new feature ScaleAgain from fontspec, which is meant to solve a long standing problem (see Superscript placement using unicode-math with scaling and Scale option doesn't fully work with LuaLaTeX). Oh, and also the fact that TeX is “not good at math”.



To setup the math-related legacy font dimensions correctly, unicode-math must load the same math font three times. But TeX wouldn’t allow the same font to be loaded twice at the same size, so unicode-math has to load the font at slightly different sizes for the 2nd and the 3rd times. These slightly different sizes are obtained by compounding the previous scale factor. This was the main reason that ScaleAgain was introduced in fontspec, so unicode-math can do ScaleAgain=1.00001 for the 2nd time and ScaleAgain=0.99999 for the 3rd time. As my comment pointed out, sometimes unicode-math will fail to distinguish the three sizes due to TeX’s binary arithmetic.



Your example was “unlucky” enough to have Scale=1.03138, which translates to Round( 1.03138 * 2^16 ) = 67593. After ScaleAgain=1.00001, TeX sees 1.03139, which translates to Round( 1.03139 * 2^16 ) = 67593. So TeX thinks that the second family and the first family are the same font, and proceeds to overwrite fontdimen’s under the instruction of unicode-math. This causes the overflow, because the new fontdimen’s are no longer percentages which are less than one, but are now physical lengths which can get quite large.



With setmathfont[Scale=MatchLowercase,ScaleAgain=0.99999]{Cambria Math}, we are basically trying to prevent TeX from loading the math font at the same size accidentally.






share|improve this answer


























  • __um_fontdimen_to_percent:nN is broken. Multiplying a dimension by 65536 is simply a very bad idea - it will overflow even if the dimension is only 1pt large. Imho your ScaleAgain workaround is only hiding the problem - something in the math is wrong when unicode-math is trying to insert a kern.

    – Ulrike Fischer
    Feb 21 at 11:53











  • @UlrikeFischer I fully agree with your improvement for __um_fontdimen_to_percent:nN. But, on the contrary, your dim_to_decimal_in_sp:n actually hides the bug even more IMHO. See, setmathfont[Scale=0.7]{latinmodern-math.otf} is not supposed to work, either, but your improvement let it through. I continued my discussion here.

    – Ruixi Zhang
    Feb 21 at 16:58
















2














Update



As of unicode-math v0.8o (2019/03/04), this bug is fixed for normal Scale usage. The update includes a variant of Ulrike Fischer’s answer, and more crucially, a sloppier setup for font dimensions in fam 2 and 3.



The change from ScaleAgain = 1.00001 and ScaleAgain = 0.99999 to ScaleAgain = 1.0001 and ScaleAgain = 0.9999 effectively lowered the upper bound of the set B in Theorem 1 below. The set B now terminates at around k=10000, which is around Scale=0.153. This means, as long as the user requested Scale is above 0.153, then unicode-math would setup font dimensions correctly.



If the requested Scale is below 0.153, then the font dimension problem persists. But it was deemed that normal usage would never produce Scale=0.153 or lower, so we are safe for the most parts. See more detailed analysis here and here.





Old answers



Although I agree with Ulrike Fischer that this is a unicode-math bug, I’m afraid that I have to disagree with the claim that “__um_fontdimen_to_percent:nN is broken”. Indeed, using dim_to_decimal_in_sp:n is a great improvement, but it is not where the actual problem lies. I shall first present my solution and then try to discuss the root cause.



Note that the following solution is meant to be temporary until unicode-math fixes this in the next release.





Solution



For a relatively simple solution, you can use the new feature ScaleAgain to slightly distort the font size (it won’t be visible to the human eyes):



documentclass{article}
usepackage{unicode-math}% v0.8n, 2019/02/15
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase,ScaleAgain=0.99999]{Cambria Math}
begin{document}
n $n sqrt[n]{n}$
end{document}


ScaleAgain



In practice, you’ll have to try a range of ScaleAgain near 1 to be able to compile. Again, this shall be fixed in the next release of unicode-math.





A Theorem on the overflow behavior of unicode-math v0.8n



For those who are interested in the bizarre overflow behavior, here is a theorem, based on the two fixed ScaleAgain factors in unicode-math v0.8n.



First comes the visualizations on which Scale’s are safe and which may cause problem:




Near Scale=1:
scale1

Near Scale=1.2:
scale1.2

Near Scale=1.5:
scale1.5



All green line segments represent the safe Scale factors, while red line segments represent the problematic ones.



Here is the rigorous mathematical description:
Theorem



In particular, Scale=1.031369386, Scale=1.031374755, Scale=1.031384644 and Scale=1.031390014 all lead to ! Dimension too large. Near Scale=1.03138:
scale1.03138






Discussions



The x-heights of Georgia and Cambria Math are, respectively, 986/2048 and 956/2048. And Scale=MatchLowercase is correctly converted into Scale=1.03138 by fontspec. Now, if we were to apply the suggested re-definition of __um_fontdimen_to_percent:nN when using Latin Modern Math, we would be surprise to find out that:



documentclass{article}
usepackage{unicode-math}% v0.8n, 2019/02/15
% https://tex.stackexchange.com/a/475802, by Ulrike Fischer:
ExplSyntaxOn
cs_set:Nn __um_fontdimen_to_percent:nN
{
fp_eval:n { dim_to_decimal_in_sp:n { fontdimen #1 #2 } / 100 }
}
ExplSyntaxOff

newcommand*tempscale{1.03138}% Also fails at 1.02, 1.05, 1.07
setmathfont[Scale=tempscale]{latinmodern-math.otf}

begin{document}
n $n sqrt[n]{n}$
end{document}


still produces the ! Dimension too large. error.



Even more strangely, if we instead use a scale factor of either 1.03137 or 1.03139, then your Georgia + Cambria Math example compiles successfully, and so does my Latin Modern Math example (with or without the re-definition of __um_fontdimen_to_percent:nN).



The root cause of the problem is the new feature ScaleAgain from fontspec, which is meant to solve a long standing problem (see Superscript placement using unicode-math with scaling and Scale option doesn't fully work with LuaLaTeX). Oh, and also the fact that TeX is “not good at math”.



To setup the math-related legacy font dimensions correctly, unicode-math must load the same math font three times. But TeX wouldn’t allow the same font to be loaded twice at the same size, so unicode-math has to load the font at slightly different sizes for the 2nd and the 3rd times. These slightly different sizes are obtained by compounding the previous scale factor. This was the main reason that ScaleAgain was introduced in fontspec, so unicode-math can do ScaleAgain=1.00001 for the 2nd time and ScaleAgain=0.99999 for the 3rd time. As my comment pointed out, sometimes unicode-math will fail to distinguish the three sizes due to TeX’s binary arithmetic.



Your example was “unlucky” enough to have Scale=1.03138, which translates to Round( 1.03138 * 2^16 ) = 67593. After ScaleAgain=1.00001, TeX sees 1.03139, which translates to Round( 1.03139 * 2^16 ) = 67593. So TeX thinks that the second family and the first family are the same font, and proceeds to overwrite fontdimen’s under the instruction of unicode-math. This causes the overflow, because the new fontdimen’s are no longer percentages which are less than one, but are now physical lengths which can get quite large.



With setmathfont[Scale=MatchLowercase,ScaleAgain=0.99999]{Cambria Math}, we are basically trying to prevent TeX from loading the math font at the same size accidentally.






share|improve this answer


























  • __um_fontdimen_to_percent:nN is broken. Multiplying a dimension by 65536 is simply a very bad idea - it will overflow even if the dimension is only 1pt large. Imho your ScaleAgain workaround is only hiding the problem - something in the math is wrong when unicode-math is trying to insert a kern.

    – Ulrike Fischer
    Feb 21 at 11:53











  • @UlrikeFischer I fully agree with your improvement for __um_fontdimen_to_percent:nN. But, on the contrary, your dim_to_decimal_in_sp:n actually hides the bug even more IMHO. See, setmathfont[Scale=0.7]{latinmodern-math.otf} is not supposed to work, either, but your improvement let it through. I continued my discussion here.

    – Ruixi Zhang
    Feb 21 at 16:58














2












2








2







Update



As of unicode-math v0.8o (2019/03/04), this bug is fixed for normal Scale usage. The update includes a variant of Ulrike Fischer’s answer, and more crucially, a sloppier setup for font dimensions in fam 2 and 3.



The change from ScaleAgain = 1.00001 and ScaleAgain = 0.99999 to ScaleAgain = 1.0001 and ScaleAgain = 0.9999 effectively lowered the upper bound of the set B in Theorem 1 below. The set B now terminates at around k=10000, which is around Scale=0.153. This means, as long as the user requested Scale is above 0.153, then unicode-math would setup font dimensions correctly.



If the requested Scale is below 0.153, then the font dimension problem persists. But it was deemed that normal usage would never produce Scale=0.153 or lower, so we are safe for the most parts. See more detailed analysis here and here.





Old answers



Although I agree with Ulrike Fischer that this is a unicode-math bug, I’m afraid that I have to disagree with the claim that “__um_fontdimen_to_percent:nN is broken”. Indeed, using dim_to_decimal_in_sp:n is a great improvement, but it is not where the actual problem lies. I shall first present my solution and then try to discuss the root cause.



Note that the following solution is meant to be temporary until unicode-math fixes this in the next release.





Solution



For a relatively simple solution, you can use the new feature ScaleAgain to slightly distort the font size (it won’t be visible to the human eyes):



documentclass{article}
usepackage{unicode-math}% v0.8n, 2019/02/15
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase,ScaleAgain=0.99999]{Cambria Math}
begin{document}
n $n sqrt[n]{n}$
end{document}


ScaleAgain



In practice, you’ll have to try a range of ScaleAgain near 1 to be able to compile. Again, this shall be fixed in the next release of unicode-math.





A Theorem on the overflow behavior of unicode-math v0.8n



For those who are interested in the bizarre overflow behavior, here is a theorem, based on the two fixed ScaleAgain factors in unicode-math v0.8n.



First comes the visualizations on which Scale’s are safe and which may cause problem:




Near Scale=1:
scale1

Near Scale=1.2:
scale1.2

Near Scale=1.5:
scale1.5



All green line segments represent the safe Scale factors, while red line segments represent the problematic ones.



Here is the rigorous mathematical description:
Theorem



In particular, Scale=1.031369386, Scale=1.031374755, Scale=1.031384644 and Scale=1.031390014 all lead to ! Dimension too large. Near Scale=1.03138:
scale1.03138






Discussions



The x-heights of Georgia and Cambria Math are, respectively, 986/2048 and 956/2048. And Scale=MatchLowercase is correctly converted into Scale=1.03138 by fontspec. Now, if we were to apply the suggested re-definition of __um_fontdimen_to_percent:nN when using Latin Modern Math, we would be surprise to find out that:



documentclass{article}
usepackage{unicode-math}% v0.8n, 2019/02/15
% https://tex.stackexchange.com/a/475802, by Ulrike Fischer:
ExplSyntaxOn
cs_set:Nn __um_fontdimen_to_percent:nN
{
fp_eval:n { dim_to_decimal_in_sp:n { fontdimen #1 #2 } / 100 }
}
ExplSyntaxOff

newcommand*tempscale{1.03138}% Also fails at 1.02, 1.05, 1.07
setmathfont[Scale=tempscale]{latinmodern-math.otf}

begin{document}
n $n sqrt[n]{n}$
end{document}


still produces the ! Dimension too large. error.



Even more strangely, if we instead use a scale factor of either 1.03137 or 1.03139, then your Georgia + Cambria Math example compiles successfully, and so does my Latin Modern Math example (with or without the re-definition of __um_fontdimen_to_percent:nN).



The root cause of the problem is the new feature ScaleAgain from fontspec, which is meant to solve a long standing problem (see Superscript placement using unicode-math with scaling and Scale option doesn't fully work with LuaLaTeX). Oh, and also the fact that TeX is “not good at math”.



To setup the math-related legacy font dimensions correctly, unicode-math must load the same math font three times. But TeX wouldn’t allow the same font to be loaded twice at the same size, so unicode-math has to load the font at slightly different sizes for the 2nd and the 3rd times. These slightly different sizes are obtained by compounding the previous scale factor. This was the main reason that ScaleAgain was introduced in fontspec, so unicode-math can do ScaleAgain=1.00001 for the 2nd time and ScaleAgain=0.99999 for the 3rd time. As my comment pointed out, sometimes unicode-math will fail to distinguish the three sizes due to TeX’s binary arithmetic.



Your example was “unlucky” enough to have Scale=1.03138, which translates to Round( 1.03138 * 2^16 ) = 67593. After ScaleAgain=1.00001, TeX sees 1.03139, which translates to Round( 1.03139 * 2^16 ) = 67593. So TeX thinks that the second family and the first family are the same font, and proceeds to overwrite fontdimen’s under the instruction of unicode-math. This causes the overflow, because the new fontdimen’s are no longer percentages which are less than one, but are now physical lengths which can get quite large.



With setmathfont[Scale=MatchLowercase,ScaleAgain=0.99999]{Cambria Math}, we are basically trying to prevent TeX from loading the math font at the same size accidentally.






share|improve this answer















Update



As of unicode-math v0.8o (2019/03/04), this bug is fixed for normal Scale usage. The update includes a variant of Ulrike Fischer’s answer, and more crucially, a sloppier setup for font dimensions in fam 2 and 3.



The change from ScaleAgain = 1.00001 and ScaleAgain = 0.99999 to ScaleAgain = 1.0001 and ScaleAgain = 0.9999 effectively lowered the upper bound of the set B in Theorem 1 below. The set B now terminates at around k=10000, which is around Scale=0.153. This means, as long as the user requested Scale is above 0.153, then unicode-math would setup font dimensions correctly.



If the requested Scale is below 0.153, then the font dimension problem persists. But it was deemed that normal usage would never produce Scale=0.153 or lower, so we are safe for the most parts. See more detailed analysis here and here.





Old answers



Although I agree with Ulrike Fischer that this is a unicode-math bug, I’m afraid that I have to disagree with the claim that “__um_fontdimen_to_percent:nN is broken”. Indeed, using dim_to_decimal_in_sp:n is a great improvement, but it is not where the actual problem lies. I shall first present my solution and then try to discuss the root cause.



Note that the following solution is meant to be temporary until unicode-math fixes this in the next release.





Solution



For a relatively simple solution, you can use the new feature ScaleAgain to slightly distort the font size (it won’t be visible to the human eyes):



documentclass{article}
usepackage{unicode-math}% v0.8n, 2019/02/15
setmainfont{Georgia}
setmathfont[Scale=MatchLowercase,ScaleAgain=0.99999]{Cambria Math}
begin{document}
n $n sqrt[n]{n}$
end{document}


ScaleAgain



In practice, you’ll have to try a range of ScaleAgain near 1 to be able to compile. Again, this shall be fixed in the next release of unicode-math.





A Theorem on the overflow behavior of unicode-math v0.8n



For those who are interested in the bizarre overflow behavior, here is a theorem, based on the two fixed ScaleAgain factors in unicode-math v0.8n.



First comes the visualizations on which Scale’s are safe and which may cause problem:




Near Scale=1:
scale1

Near Scale=1.2:
scale1.2

Near Scale=1.5:
scale1.5



All green line segments represent the safe Scale factors, while red line segments represent the problematic ones.



Here is the rigorous mathematical description:
Theorem



In particular, Scale=1.031369386, Scale=1.031374755, Scale=1.031384644 and Scale=1.031390014 all lead to ! Dimension too large. Near Scale=1.03138:
scale1.03138






Discussions



The x-heights of Georgia and Cambria Math are, respectively, 986/2048 and 956/2048. And Scale=MatchLowercase is correctly converted into Scale=1.03138 by fontspec. Now, if we were to apply the suggested re-definition of __um_fontdimen_to_percent:nN when using Latin Modern Math, we would be surprise to find out that:



documentclass{article}
usepackage{unicode-math}% v0.8n, 2019/02/15
% https://tex.stackexchange.com/a/475802, by Ulrike Fischer:
ExplSyntaxOn
cs_set:Nn __um_fontdimen_to_percent:nN
{
fp_eval:n { dim_to_decimal_in_sp:n { fontdimen #1 #2 } / 100 }
}
ExplSyntaxOff

newcommand*tempscale{1.03138}% Also fails at 1.02, 1.05, 1.07
setmathfont[Scale=tempscale]{latinmodern-math.otf}

begin{document}
n $n sqrt[n]{n}$
end{document}


still produces the ! Dimension too large. error.



Even more strangely, if we instead use a scale factor of either 1.03137 or 1.03139, then your Georgia + Cambria Math example compiles successfully, and so does my Latin Modern Math example (with or without the re-definition of __um_fontdimen_to_percent:nN).



The root cause of the problem is the new feature ScaleAgain from fontspec, which is meant to solve a long standing problem (see Superscript placement using unicode-math with scaling and Scale option doesn't fully work with LuaLaTeX). Oh, and also the fact that TeX is “not good at math”.



To setup the math-related legacy font dimensions correctly, unicode-math must load the same math font three times. But TeX wouldn’t allow the same font to be loaded twice at the same size, so unicode-math has to load the font at slightly different sizes for the 2nd and the 3rd times. These slightly different sizes are obtained by compounding the previous scale factor. This was the main reason that ScaleAgain was introduced in fontspec, so unicode-math can do ScaleAgain=1.00001 for the 2nd time and ScaleAgain=0.99999 for the 3rd time. As my comment pointed out, sometimes unicode-math will fail to distinguish the three sizes due to TeX’s binary arithmetic.



Your example was “unlucky” enough to have Scale=1.03138, which translates to Round( 1.03138 * 2^16 ) = 67593. After ScaleAgain=1.00001, TeX sees 1.03139, which translates to Round( 1.03139 * 2^16 ) = 67593. So TeX thinks that the second family and the first family are the same font, and proceeds to overwrite fontdimen’s under the instruction of unicode-math. This causes the overflow, because the new fontdimen’s are no longer percentages which are less than one, but are now physical lengths which can get quite large.



With setmathfont[Scale=MatchLowercase,ScaleAgain=0.99999]{Cambria Math}, we are basically trying to prevent TeX from loading the math font at the same size accidentally.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered Feb 21 at 5:37









Ruixi ZhangRuixi Zhang

5,538322




5,538322













  • __um_fontdimen_to_percent:nN is broken. Multiplying a dimension by 65536 is simply a very bad idea - it will overflow even if the dimension is only 1pt large. Imho your ScaleAgain workaround is only hiding the problem - something in the math is wrong when unicode-math is trying to insert a kern.

    – Ulrike Fischer
    Feb 21 at 11:53











  • @UlrikeFischer I fully agree with your improvement for __um_fontdimen_to_percent:nN. But, on the contrary, your dim_to_decimal_in_sp:n actually hides the bug even more IMHO. See, setmathfont[Scale=0.7]{latinmodern-math.otf} is not supposed to work, either, but your improvement let it through. I continued my discussion here.

    – Ruixi Zhang
    Feb 21 at 16:58



















  • __um_fontdimen_to_percent:nN is broken. Multiplying a dimension by 65536 is simply a very bad idea - it will overflow even if the dimension is only 1pt large. Imho your ScaleAgain workaround is only hiding the problem - something in the math is wrong when unicode-math is trying to insert a kern.

    – Ulrike Fischer
    Feb 21 at 11:53











  • @UlrikeFischer I fully agree with your improvement for __um_fontdimen_to_percent:nN. But, on the contrary, your dim_to_decimal_in_sp:n actually hides the bug even more IMHO. See, setmathfont[Scale=0.7]{latinmodern-math.otf} is not supposed to work, either, but your improvement let it through. I continued my discussion here.

    – Ruixi Zhang
    Feb 21 at 16:58

















__um_fontdimen_to_percent:nN is broken. Multiplying a dimension by 65536 is simply a very bad idea - it will overflow even if the dimension is only 1pt large. Imho your ScaleAgain workaround is only hiding the problem - something in the math is wrong when unicode-math is trying to insert a kern.

– Ulrike Fischer
Feb 21 at 11:53





__um_fontdimen_to_percent:nN is broken. Multiplying a dimension by 65536 is simply a very bad idea - it will overflow even if the dimension is only 1pt large. Imho your ScaleAgain workaround is only hiding the problem - something in the math is wrong when unicode-math is trying to insert a kern.

– Ulrike Fischer
Feb 21 at 11:53













@UlrikeFischer I fully agree with your improvement for __um_fontdimen_to_percent:nN. But, on the contrary, your dim_to_decimal_in_sp:n actually hides the bug even more IMHO. See, setmathfont[Scale=0.7]{latinmodern-math.otf} is not supposed to work, either, but your improvement let it through. I continued my discussion here.

– Ruixi Zhang
Feb 21 at 16:58





@UlrikeFischer I fully agree with your improvement for __um_fontdimen_to_percent:nN. But, on the contrary, your dim_to_decimal_in_sp:n actually hides the bug even more IMHO. See, setmathfont[Scale=0.7]{latinmodern-math.otf} is not supposed to work, either, but your improvement let it through. I continued my discussion here.

– Ruixi Zhang
Feb 21 at 16:58


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f475792%2fdimension-too-large-error-when-setmathfont-has-the-option-scale-matchlowercas%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

El tren de la libertad Índice Antecedentes "Porque yo decido" Desarrollo de la...

Puerta de Hutt Referencias Enlaces externos Menú de navegación15°58′00″S 5°42′00″O /...

Castillo d'Acher Características Menú de navegación