![使用 Asana Math 时括号大小不一致](https://linux22.com/image/425551/%E4%BD%BF%E7%94%A8%20Asana%20Math%20%E6%97%B6%E6%8B%AC%E5%8F%B7%E5%A4%A7%E5%B0%8F%E4%B8%8D%E4%B8%80%E8%87%B4.png)
我使用\setmathfont{Asana Math}[Scale=MatchLowercase]
并使用 lualatex。
我注意到当我这样做时,我会得到不同大小的 (),具体取决于它周围是否存在额外的术语。
这是 MWE。这是使用最新更新的 TL 2020(10 月 1 日之后)
\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{mleftright}
\mleftright
\usepackage[mathit=sym,bold-style=ISO]{unicode-math}
\setmathfont{Asana Math}[Scale=MatchLowercase]
\begin{document}
\[
-\cos \left(x \right) {\mathrm e}^{x}+\cos \left(y \right)
\]
\end{document}
已编译
lualatex foo5.tex
This is LuaHBTeX, Version 1.12.0 (TeX Live 2020)
restricted system commands enabled.
(./foo5.tex
LaTeX2e <2020-10-01> patch level 2
L3 programming layer <2020-10-27> xparse <2020-03-03> (/usr/local/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/size11.clo)) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/local/texlive/2020/texmf-dist/tex/generic/mleftright/mleftright.sty (/usr/local/texlive/2020/texmf-dist/tex/generic/infwarerr/infwarerr.sty) (/usr/local/texlive/2020/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/unicode-math/unicode-math.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/l3kernel/expl3.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-luatex.def)) (/usr/local/texlive/2020/texmf-dist/tex/latex/unicode-math/unicode-math-luatex.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/l3packages/xparse/xparse.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/l3packages/xparse/xparse-generic.tex))
(/usr/local/texlive/2020/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/fontspec/fontspec.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/fontspec/fontspec-luatex.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/base/fontenc.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/fontspec/fontspec.cfg))) (/usr/local/texlive/2020/texmf-dist/tex/latex/base/fix-cm.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/base/ts1enc.def)) (/usr/local/texlive/2020/texmf-dist/tex/lualatex/lualatex-math/lualatex-math.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/etoolbox/etoolbox.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/unicode-math/unicode-math-table.tex))) (./foo5.aux) [1{/usr/local/texlive/2020/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./foo5.aux))
488 words of node memory still in use:
6 hlist, 2 vlist, 2 rule, 2 glue, 4 kern, 1 glyph, 7 attribute, 52 glue_spec, 7 attribute_list, 1 write nodes
avail lists: 2:39,3:21,4:4,5:23,6:2,7:72,8:23,9:42
</usr/local/texlive/2020/texmf-dist/fonts/opentype/public/Asana-Math/Asana-Math.otf></usr/local/texlive/2020/texmf-dist/fonts/opentype/public/lm/lmroman10-regular.otf></usr/local/texlive/2020/texmf-dist/fonts/opentype/public/Asana-Math/Asana-Math.otf>
Output written on foo5.pdf (1 page, 6484 bytes).
Transcript written on foo5.log.
给予
第二个括号cos
比第一个大得多,看起来不太好看。删除以下行
\usepackage[mathit=sym,bold-style=ISO]{unicode-math}
\setmathfont{Asana Math}[Scale=MatchLowercase]
再次编译得到
现在括号的大小与预期相同。请不要抱怨我为什么使用\left
和\right
,这是 CAS 自动生成的 Latex,上面是一些生成的 Latex 的小例子。我无法控制这一点。
在我的实际代码中,我也使用了Baskervaldx
with,Asana Math
但通过测试,我发现仅使用Asana Math
本身会显示此问题。所以我尝试使顶部 MWE 更简单以显示问题。但如果您想查看我使用的完整字体,这里再次是 MWE。给出的输出与上面第一个相同
\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{mleftright}
\mleftright
\usepackage[mathit=sym,bold-style=ISO]{unicode-math}
\setmathfont{Asana Math}[Scale=MatchLowercase]
\setmainfont{Baskervaldx}[
UprightFont=*-Reg,
ItalicFont=*-Ita,
BoldFont=*-Bol,
BoldItalicFont=*-BolIta,
]
\begin{document}
\[
-\cos \left(x \right) {\mathrm e}^{x}+\cos \left(y \right)
\]
\end{document}
有没有办法使用Asana Math
和使括号大小相同。同样,我无法从代码中删除\left
和\right
。我做错了什么吗?
欢迎任何建议。
编辑 2021 年 1 月 13 日
这是一个使用已接受答案中的 lua 代码产生错误的示例。我现在不知道为什么会这样。这是自动生成的 latex
\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{mleftright}
\mleftright
\usepackage[mathit=sym,bold-style=ISO]{unicode-math}
\setmathfont{Asana Math}[Scale=MatchLowercase]
{\catcode`\%=12
\directlua{
function spuriousleftright(s)
return string.gsub(s,'\string\\left(..[ ]*)\string\\right(.)','%1%2')
end
luatexbase.add_to_callback('process_input_buffer',spuriousleftright,'zzz')
}
}
\begin{document}
\[
y = \left\{\begin{array}{cc}\left[\right] & c_{2}+\frac{\ln \left(\frac{3 v \left(y \right)}{y}\right)}{2}<0 \\\left[0\right] & c_{2}+\frac{\ln \left(\frac{3 v \left(y \right)}{y}\right)}{2}=0 \\\left[c_{2}+\frac{\ln \left(\frac{3 v \left(y \right)}{y}\right)}{2}, -c_{2}-\frac{\ln \left(\frac{3 v \left(y \right)}{y}\right)}{2}\right] & 0<c_{2}+\frac{\ln \left(\frac{3 v \left(y \right)}{y}\right)}{2} \end{array}\right.
\]
\end{document}
现在使用 lualatex 编译时会出现! Illegal unit of measure (pt inserted).
错误。
lualatex foo5.tex
This is LuaHBTeX, Version 1.12.0 (TeX Live 2020)
restricted system commands enabled.
(./foo5.tex
LaTeX2e <2020-10-01> patch level 2
L3 programming layer <2020-12-07> xparse <2020-03-03> (/usr/local/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/size11.clo)) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/local/texlive/2020/texmf-dist/tex/generic/mleftright/mleftright.sty (/usr/local/texlive/2020/texmf-dist/tex/generic/infwarerr/infwarerr.sty) (/usr/local/texlive/2020/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/unicode-math/unicode-math.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/l3kernel/expl3.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-luatex.def)) (/usr/local/texlive/2020/texmf-dist/tex/latex/unicode-math/unicode-math-luatex.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/l3packages/xparse/xparse.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/l3packages/xparse/xparse-generic.tex))
(/usr/local/texlive/2020/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/fontspec/fontspec.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/fontspec/fontspec-luatex.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/base/fontenc.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/fontspec/fontspec.cfg))) (/usr/local/texlive/2020/texmf-dist/tex/latex/base/fix-cm.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/base/ts1enc.def)) (/usr/local/texlive/2020/texmf-dist/tex/lualatex/lualatex-math/lualatex-math.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/etoolbox/etoolbox.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/unicode-math/unicode-math-table.tex))) (./foo5.aux)
! Illegal unit of measure (pt inserted).
<to be read again>
>
l.21 y = \left\{\begin{array}{cc}\left[\right] & c_{2}+\frac{\ln \left(\frac{3 v (y )}{y}\right)}{2}<0 \\[0]
& c_{2}+\frac{\ln \left(\frac{3 v (y )}{y}\right)}{2}=0 \\\left[c_{2}+\frac{\ln \left(\frac{3 v (y )}{y}\right)}{2}, -c_{2}-\frac{\ln \left(\fra...
?
编辑 3/31/2021
我发现了一个情况,其中 () 保持很大,并且不会像其他数学函数那样减小。这是一个 MWE。当使用\psi
\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{mleftright}
\mleftright
\usepackage[mathit=sym,bold-style=ISO]{unicode-math}
\setmathfont{Asana Math}[Scale=MatchLowercase]
{\catcode`\%=12
\directlua{
function spuriousleftright(s)
return string.gsub(s,'\string\\left(..[ ]*)\string\\right(.)','\string\\relax %1%2')
end
luatexbase.add_to_callback('process_input_buffer',spuriousleftright,'zzz')
}
}
\begin{document}
\[
-\cos \left(x \right) +\cos \left(y \right)
\]
\[
-\cos \left(x \right) +\psi\left( y\right)
\]
\end{document}
与不再次使用此字体时相比:
\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{mleftright}
\mleftright
\begin{document}
\[
-\cos \left(x \right) +\cos \left(y \right)
\]
\[
-\cos \left(x \right) +\psi\left( y\right)
\]
\end{document}
答案1
我会在 CAS 中修复 tex 生成问题,或者在将生成的 tex 传递给 latex 之前对其进行处理。由于您使用的是 luatex,因此您可以动态地进行处理,但如果您在外部进行处理,则可以查看转换后的结果,这样调试起来会更容易,但是这会通过回调动态修改输入缓冲区
\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{mleftright}
\mleftright
\usepackage[mathit=sym,bold-style=ISO]{unicode-math}
\setmathfont{Asana Math}[Scale=MatchLowercase]
{\catcode`\%=12
\directlua{
function spuriousleftright(s)
return string.gsub(s,'\string\\left(..[ ]*)\string\\right(.)','\string\\relax %1%2')
end
luatexbase.add_to_callback('process_input_buffer',spuriousleftright,'zzz')
}
}
\begin{document}
\[
-\cos \left(x \right) {\mathrm e}^{x}+\cos \left(y \right)
\]
\end{document}
答案2
一个简单的例子:
\documentclass{article}
\usepackage{unicode-math}
\setmathfont{Asana Math}
\begin{document}
$\left(x\right)\left(y\right)$
\end{document}
的字形具有很深的下降部,并且 TeX 遵循和 的y
规则。\left
\right
您可以通过粉碎下降器来避免该问题(这不是最好的解决方案,但无论如何您的排版不是最高质量的)。
\documentclass{article}
\usepackage{amsmath}
\usepackage{unicode-math}
\setmathfont{Asana Math}
\Umathcharnumdef\standardy=\Umathcodenum`y
\begingroup\lccode`~=`y \lowercase{\endgroup
\AtBeginDocument{\def~{{\smash[b]{\standardy}}}\mathcode`y="8000 }
}
\begin{document}
$\left(x\right)\left(y\right)\left(p\right)\left(b\right)$
\textit{xypb}
\end{document}
但如您所见,其他字母也需要同样的处理。我在 Baskervaldx 中添加了斜体字母,以表明我的意思“不是最高品质”。