\stackMath 有什么作用?

\stackMath 有什么作用?

我想在同一个文件中使用宽帽子和宽波浪线,因此我使用以下代码

\documentclass{article}
\usepackage{wasysym}
\usepackage{scalerel,stackengine}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%(1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\reallywidetilde[1]{\ThisStyle{%
     \setbox0=\hbox{$\SavedStyle#1$}%
     \stackengine{-.1\LMpt}{$\SavedStyle#1$}{%
         \stretchto{\scaleto{\SavedStyle\mkern.2mu\AC}{.5150\wd0}}{.6\ht0}%
     }{O}{c}{F}{T}{S}%
}}

\def\test#1{$%
    \reallywidetilde{#1}\,
    %   \scriptstyle\reallywidetilde{#1}\,
    %   \scriptscriptstyle\reallywidetilde{#1}
    $\par}

\parskip 1ex


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%(2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\stackMath
\newcommand{\reallywidehat}[1]{%
    \savestack{\tmpbox}{\stretchto{%
            \scaleto{%
                \scalerel*[\widthof{\ensuremath{#1}}]                         {\kern-.6pt\bigwedge\kern-.6pt}%
                    {\rule[-\textheight/2]{1ex}{\textheight}}%WIDTH-LIMITED     BIG WEDGE
            }{\textheight}% 
        }{0.5ex}}%
    \stackon[1pt]{#1}{\tmpbox}%
}
\parskip 1ex

\begin{document}
\reallywidetilde{A}
\test{abcdefghijklm}
\test{abcdefghijk}
\end{document}

我从以前的帖子中使用了代码 非常宽的帽子符号

数学模式中的大波浪符号

部分 (1) 和 (2) 都运行良好,但放在一起时,它们会发生冲突,并且 \reallywidetilde 不再起作用。有没有办法让它们兼容?

答案1

默认情况下,该stackengine包可以在数学模式或文本模式下处理其堆叠参数。如果您只在给定文档中将其功能用于单个函数,\stackMath或者\stackText(这是全局设置!)就足以为整个文档设置适当的模式。

如果您可能以两种方式使用它,那么您可以将包保留为文本模式,并将数学模式使用包装在 \ensurestackMath{}宏中。在下面的 MWE 中,我在 内部使用了该过程\reallywidehat

\documentclass{article}
\usepackage{wasysym}
\usepackage{scalerel,stackengine}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%(1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\reallywidetilde[1]{\ThisStyle{%
     \setbox0=\hbox{$\SavedStyle#1$}%
     \stackengine{-.1\LMpt}{$\SavedStyle#1$}{%
         \stretchto{\scaleto{\SavedStyle\mkern.2mu\AC}{.5150\wd0}}{.6\ht0}%
     }{O}{c}{F}{T}{S}%
}}

\def\test#1{$%
    \reallywidetilde{#1}\,
    %   \scriptstyle\reallywidetilde{#1}\,
    %   \scriptscriptstyle\reallywidetilde{#1}
    $\par}

\parskip 1ex


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%(2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\stackMath
\newcommand{\reallywidehat}[1]{%
    \savestack{\tmpbox}{\stretchto{%
            \scaleto{%
                \scalerel*[\widthof{\ensuremath{#1}}]                         {\kern-.6pt\bigwedge\kern-.6pt}%
                    {\rule[-\textheight/2]{1ex}{\textheight}}%WIDTH-LIMITED     BIG WEDGE
            }{\textheight}% 
        }{0.5ex}}%
    \ensurestackMath{\stackon[1pt]{#1}{\tmpbox}}%
}
\parskip 1ex

\begin{document}
\reallywidetilde{A}
\test{abcdefghijklm}
\test{abcdefghijk}
\reallywidehat{abcde}
\end{document}

在此处输入图片描述

或者,您可以stackengine通过 离开全局数学模式\stackMath,并重新定义\reallywidetile宏以默认在数学模式下运行,如下所示

\newcommand\reallywidetilde[1]{\ThisStyle{%
     \setbox0=\hbox{$\SavedStyle#1$}%
     \stackengine{-.1\LMpt}{\SavedStyle#1}{%
         \stretchto{\scaleto{\SavedStyle\mkern.2mu\AC}{.5150\wd0}}{.6\ht0}%
     }{O}{c}{F}{T}{S}%
}}

#2请注意,的参数\stackengine不再设置在$符号之间。同样,#3已经将其参数转换为数学模式,因此不需要进行任何更改。

相关内容