![如何重新定义数学模式重音宏(\bar、\hat 等)以仅针对 \mathbb 和 \mathcal 输入进行字距调整,但其他方面则表现正常](https://linux22.com/image/458026/%E5%A6%82%E4%BD%95%E9%87%8D%E6%96%B0%E5%AE%9A%E4%B9%89%E6%95%B0%E5%AD%A6%E6%A8%A1%E5%BC%8F%E9%87%8D%E9%9F%B3%E5%AE%8F%EF%BC%88%5Cbar%E3%80%81%5Chat%20%E7%AD%89%EF%BC%89%E4%BB%A5%E4%BB%85%E9%92%88%E5%AF%B9%20%5Cmathbb%20%E5%92%8C%20%5Cmathcal%20%E8%BE%93%E5%85%A5%E8%BF%9B%E8%A1%8C%E5%AD%97%E8%B7%9D%E8%B0%83%E6%95%B4%EF%BC%8C%E4%BD%86%E5%85%B6%E4%BB%96%E6%96%B9%E9%9D%A2%E5%88%99%E8%A1%A8%E7%8E%B0%E6%AD%A3%E5%B8%B8.png)
灵感来自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