灵感来自David Carlisle 对我之前问题的回答和评论,我想看看我是否可以尝试重新定义数学模式重音宏(\bar
、、等)来专门为和输入调整字距\hat
,因为我想分别使用 AMS 黑板粗体和 Computer Modern calligraphic 而不是 中的 Latin Modern 。\dot
\mathbb
\mathcal
LuaTeX
unicode-math
这是我的 MWE:
% !TEX program = lualatex
% DOCUMENT CLASS
\documentclass[11pt,preview,varwidth,%
border={3pt 5pt 3pt 5pt}% left bottom right top
]{standalone}
% PACKAGES
\usepackage{amsmath}
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}
\let\lmmathbb\mathbb % Latin Modern blackboard bold
\let\lmmathcal\mathcal % Latin Modern calligraphic
\DeclareMathAlphabet{\amsmathbb}{U}{msb}{m}{n} % AMS blackboard bold
\DeclareMathAlphabet{\cmmathcal}{OMS}{cmsy}{m}{n} % Computer Modern calligraphic
% START OF DOCUMENT
\begin{document}
\begin{tabular}{lcr}
Latin Modern's \verb|\mathbb| & : & \(\bar{\lmmathbb{A}} \hat{\lmmathbb{A}} \vec{\lmmathbb{A}} \dot{\lmmathbb{A}} \ddot{\lmmathbb{A}}\) \\
\(\cmmathcal{AMS}\)'s \verb|\mathbb| (with \textit{unkerned} accents) & : & \(\bar{\amsmathbb{A}} \hat{\amsmathbb{A}} \vec{\amsmathbb{A}} \dot{\amsmathbb{A}} \ddot{\amsmathbb{A}}\) \\
Latin Modern's \verb|\mathcal| & : & \(\bar{\lmmathcal{A}} \hat{\lmmathcal{A}} \vec{\lmmathcal{A}} \dot{\lmmathcal{A}} \ddot{\lmmathcal{A}}\) \\
Computer Modern's \verb|\mathcal| (with \textit{unkerned} accents) & : & \(\bar{\cmmathcal{A}} \hat{\cmmathcal{A}} \vec{\cmmathcal{A}} \dot{\cmmathcal{A}} \ddot{\cmmathcal{A}}\)
\end{tabular}
\end{document}
% END OF DOCUMENT
我想要实现以下目标:
.
.
.
\begin{tabular}{lcr}
Latin Modern's \verb|\mathbb| & : & \(\bar{\lmmathbb{A}} \hat{\lmmathbb{A}} \vec{\lmmathbb{A}} \dot{\lmmathbb{A}} \ddot{\lmmathbb{A}}\) \\
\(\cmmathcal{AMS}\)'s \verb|\mathbb| (with \textit{kerned} accents) & : & \(\bar{\amsmathbb{A}} \hat{\amsmathbb{A}} \vec{\amsmathbb{A}} \dot{\amsmathbb{A}} \ddot{\amsmathbb{A}}\) \\
Latin Modern's \verb|\mathcal| & : & \(\bar{\lmmathcal{A}} \hat{\lmmathcal{A}} \vec{\lmmathcal{A}} \dot{\lmmathcal{A}} \ddot{\lmmathcal{A}}\) \\
Computer Modern's \verb|\mathcal| (with \textit{kerned} accents) & : & \(\bar{\cmmathcal{A}} \hat{\cmmathcal{A}} \vec{\cmmathcal{A}} \dot{\cmmathcal{A}} \ddot{\cmmathcal{A}}\)
\end{tabular}
.
.
.
我如何才能有效地重新定义\bar
、\hat
、\vec
、\dot
和以达到上述和输入\ddot
的预期结果?(要求它们在其他方面表现正常)\amsmathbb
\cmmathcal
答案1
这是我的方法,但我不知道它是否“有效”,如有任何反馈我将非常感谢。
% !TEX program = lualatex
% DOCUMENT CLASS
\documentclass[11pt,preview,varwidth,%
border={3pt 5pt 3pt 5pt}% left bottom right top
]{standalone}
% PACKAGES
\usepackage{amsmath}
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}
\let\lmmathbb\mathbb % Latin Modern blackboard bold
\let\lmmathcal\mathcal % Latin Modern calligraphic
\DeclareMathAlphabet{\amsmathbb}{U}{msb}{m}{n} % AMS blackboard bold
\DeclareMathAlphabet{\cmmathcal}{OMS}{cmsy}{m}{n} % Computer Modern calligraphic
\usepackage{xstring} % For \string and \IfSubStr
% \shiftmath (https://tex.stackexchange.com/a/666905/)
\newcommand{\shiftmath}[3]{#1{{\mkern-#2mu}#3{\mkern#2mu}}}
% \amsmathbbkerning and \cmmathcalkerning
\newcommand{\amsmathbbkerning}{-2}
\newcommand{\cmmathcalkerning}{1.5}
% \ArgZapSpaces (https://tex.stackexchange.com/a/652826/)
\ExplSyntaxOn
\cs_new_protected:Npn \__user_arg_zap_spaces:n #1
{
\tl_set:Nn \ProcessedArgument {#1}
\tl_remove_all:Nn \ProcessedArgument { ~ }
}
\cs_set_eq:NN \ArgZapSpaces \__user_arg_zap_spaces:n
\ExplSyntaxOff
% \bar redefinition
\let\oldbar\bar
\NewDocumentCommand{\newbar}{>{\ArgZapSpaces}m}{%
\IfSubStr{\string#1}{\string\amsmathbb}{%
\shiftmath{\oldbar}{\amsmathbbkerning}{#1} % if \amsmathbb
}{%
\IfSubStr{\string#1}{\string\cmmathcal}{%
\shiftmath{\oldbar}{\cmmathcalkerning}{#1} % if \cmmathcal
}{%
\oldbar{#1} % if neither \amsmathbb nor \cmmathcal
}
}
}
\AtBeginDocument{\def\bar{\newbar}}
% \hat redefinition
\let\oldhat\hat
\NewDocumentCommand{\newhat}{>{\ArgZapSpaces}m}{%
\IfSubStr{\string#1}{\string\amsmathbb}{%
\shiftmath{\oldhat}{\amsmathbbkerning}{#1} % if \amsmathbb
}{%
\IfSubStr{\string#1}{\string\cmmathcal}{%
\shiftmath{\oldhat}{\cmmathcalkerning}{#1} % if \cmmathcal
}{%
\oldhat{#1} % if neither \amsmathbb nor \cmmathcal
}
}
}
\AtBeginDocument{\def\hat{\newhat}}
% \vec redefinition
\let\oldvec\vec
\NewDocumentCommand{\newvec}{>{\ArgZapSpaces}m}{%
\IfSubStr{\string#1}{\string\amsmathbb}{%
\shiftmath{\oldvec}{\amsmathbbkerning}{#1} % if \amsmathbb
}{%
\IfSubStr{\string#1}{\string\cmmathcal}{%
\shiftmath{\oldvec}{\cmmathcalkerning}{#1} % if \cmmathcal
}{%
\oldvec{#1} % if neither \amsmathbb nor \cmmathcal
}
}
}
\AtBeginDocument{\def\vec{\newvec}}
% \dot redefinition
\let\olddot\dot
\NewDocumentCommand{\newdot}{>{\ArgZapSpaces}m}{%
\IfSubStr{\string#1}{\string\amsmathbb}{%
\shiftmath{\olddot}{\amsmathbbkerning}{#1} % if \amsmathbb
}{%
\IfSubStr{\string#1}{\string\cmmathcal}{%
\shiftmath{\olddot}{\cmmathcalkerning}{#1} % if \cmmathcal
}{%
\olddot{#1} % if neither \amsmathbb nor \cmmathcal
}
}
}
\AtBeginDocument{\def\dot{\newdot}}
% \ddot redefinition
\let\oldddot\ddot
\NewDocumentCommand{\newddot}{>{\ArgZapSpaces}m}{%
\IfSubStr{\string#1}{\string\amsmathbb}{%
\shiftmath{\oldddot}{\amsmathbbkerning}{#1} % if \amsmathbb
}{%
\IfSubStr{\string#1}{\string\cmmathcal}{%
\shiftmath{\oldddot}{\cmmathcalkerning}{#1} % if \cmmathcal
}{%
\oldddot{#1} % if neither \amsmathbb nor \cmmathcal
}
}
}
\AtBeginDocument{\def\ddot{\newddot}}
% START OF DOCUMENT
\begin{document}
\begin{tabular}{lcr}
Latin Modern's \verb|\mathbb| & : & \(\bar{\lmmathbb{A}} \hat{\lmmathbb{A}} \vec{\lmmathbb{A}} \dot{\lmmathbb{A}} \ddot{\lmmathbb{A}}\) \\
\(\cmmathcal{AMS}\)'s \verb|\mathbb| (with \textit{unkerned} accents) & : & \(\oldbar{\amsmathbb{A}} \oldhat{\amsmathbb{A}} \oldvec{\amsmathbb{A}} \olddot{\amsmathbb{A}} \oldddot{\amsmathbb{A}}\) \\
\(\cmmathcal{AMS}\)'s \verb|\mathbb| (with \textit{kerned} accents) & : & \(\bar{\amsmathbb{A}} \hat{\amsmathbb{A}} \vec{\amsmathbb{A}} \dot{\amsmathbb{A}} \ddot{\amsmathbb{A}}\) \\
Latin Modern's \verb|\mathcal| & : & \(\bar{\lmmathcal{A}} \hat{\lmmathcal{A}} \vec{\lmmathcal{A}} \dot{\lmmathcal{A}} \ddot{\lmmathcal{A}}\) \\
Computer Modern's \verb|\mathcal| (with \textit{unkerned} accents) & : & \(\oldbar{\cmmathcal{A}} \oldhat{\cmmathcal{A}} \oldvec{\cmmathcal{A}} \olddot{\cmmathcal{A}} \oldddot{\cmmathcal{A}}\) \\
Computer Modern's \verb|\mathcal| (with \textit{kerned} accents) & : & \(\bar{\cmmathcal{A}} \hat{\cmmathcal{A}} \vec{\cmmathcal{A}} \dot{\cmmathcal{A}} \ddot{\cmmathcal{A}}\)
\end{tabular}
\end{document}
% END OF DOCUMENT