这是这问题。问题是,如果tikz-cd
使用命令\tikzcdset{arrow style=math font}
来使箭头适合数学字体,箭头的茎部将不再很好地呈现。必须在所用的数学字体中找出箭头茎部的线宽和 x 高度,并像这样调整箭头:
\documentclass{standalone}
\usepackage{unicode-math}
\usepackage{tikz-cd}
\setmathfont{Libertinus Math}
%%%% Adjustment for tikz-cd arrows under Libertinus Math
\tikzcdset{arrow style=math font}
\tikzcdset{every arrow/.append style={line width=0.052em}}%
\pgfmathdeclarefunction*{axis_height}{0}{%
\begingroup%
\pgfmathreturn0.265em%
\endgroup}%
%%%%
\begin{document}
\begin{tikzcd}
a\arrow[r]&b
\end{tikzcd}
\end{document}
现在我想写一个小包,其中包含我经常使用的我最喜欢的数学字体的线宽和轴高值。如果使用这些数学字体之一,该包应该会自动检测并进行适当的调整。
但是,我不知道如何找到使用的数学字体。由于我主要使用,因此对和字体unicode-math
有效的解决方案就让我很满意。但如果还可以添加对字体包(如、等)的支持,那就太好了。unicode-math
otf.
eulervm
newtxmath
答案1
此解决方案unicode-math
仅支持。注释指示必须添加其他行的位置以支持更多字体。
\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{unicode-math}
\usepackage{tikz-cd}
\setmathfont{Libertinus Math}
% Adjustment for tikz-cd arrows under Libertinus Math
\tikzcdset{
match-arrows/.is choice,
% copy and adjust the next three lines for each font required other than Latin Modern Math
match-arrows/libertinus/.style={
match-arrows aux={0.052em}{0.265em}
},
% next part is standard
match-arrows aux/.code n args=2{%
\tikzcdset{%
arrow style=math font,
every arrow/.append style={line width=#1},
}%
\pgfmathdeclarefunction*{axis_height}{0}{%
\begingroup
\pgfmathreturn#2%
\endgroup
}%
},
}
\ExplSyntaxOn
% create a new variable for each maths font you want to support
\tl_new:N \l_john_dorian_libertinus_tl
\tl_new:N \l_john_dorisan_lmm_tl
% set the variable to the name of the approproate font, substituting tildes for any spaces
\tl_set:Nn \l_john_dorisan_lmm_tl { Latin ~ Modern ~ Math }
\tl_set:Nn \l_john_dorian_libertinus_tl { Libertinus ~ Math}
\AtBeginDocument{
\tl_if_exist:NT \l__um_fontname_tl
{
\tl_case:Nn \l__um_fontname_tl
{% add a line here with the variable on the left and the code which should be executed on the right in curly brackets
\l_john_dorisan_lmm_tl { }
\l_john_dorian_libertinus_tl { \tikzcdset{ match - arrows = libertinus, } }
}
}
}
\ExplSyntaxOff
\begin{document}
\begin{tikzcd}
a\arrow[r]&b
\end{tikzcd}
\end{document}
如图所示,代码产生以下箭头:
如果我们注释掉 Libertinus Math 的开关,代码将生成以下箭头: