我遇到了一个严重的问题,使用widebar
由 Hendrik Vogt 定义的数学命令来回答问题 16337。在我使用它的参数之前,它工作得很好 \(wide)hat
。这是一个 M(non)WE:
\documentclass[12pt, a4paper]{article}
\usepackage{amsmath}%
\makeatletter
\newcommand*\if@single[3]{%
\setbox0\hbox{${\mathaccent"0362{#1}}^H$}%
\setbox2\hbox{${\mathaccent"0362{\kern0pt#1}}^H$}%
\ifdim\ht0=\ht2 #3\else #2\fi
}
%The bar will be moved to the right by a half of \macc@kerna, which is computed by amsmath:
\newcommand*\rel@kern[1]{\kern#1\dimexpr\macc@kerna}
%If there's a superscript following the bar, then no negative kern may follow the bar;
%an additional {} makes sure that the superscript is high enough in this case:
\newcommand*\widebar[1]{\@ifnextchar^{{\wide@bar{#1}{0}}}{\wide@bar{#1}{1}}}
%Use a separate algorithm for single symbols:
\newcommand*\wide@bar[2]{\if@single{#1}{\wide@bar@{#1}{#2}{1}}{\wide@bar@{#1}{#2}{2}}}
\newcommand*\wide@bar@[3]{%
\begingroup
\def\mathaccent##1##2{%
%If there's more than a single symbol, use the first character instead (see below):
\if#32 \let\macc@nucleus\first@char \fi
%Determine the italic correction:
\setbox\z@\hbox{$\macc@style{\macc@nucleus}_{}$}%
\setbox\tw@\hbox{$\macc@style{\macc@nucleus}{}_{}$}%
\dimen@\wd\tw@
\advance\dimen@-\wd\z@
%Now \dimen@ is the italic correction of the symbol.
\divide\dimen@ 3
\@tempdima\wd\tw@
\advance\@tempdima-\scriptspace
%Now \@tempdima is the width of the symbol.
\divide\@tempdima 10
\advance\dimen@-\@tempdima
%Now \dimen@ = (italic correction / 3) - (Breite / 10)
\ifdim\dimen@>\z@ \dimen@0pt\fi
%The bar will be shortened in the case \dimen@<0 !
\rel@kern{0.6}\kern-\dimen@
\if#31
\overline{\rel@kern{-0.6}\kern\dimen@\macc@nucleus\rel@kern{0.4}\kern\dimen@}%
\advance\[email protected]\dimexpr\macc@kerna
%Place the combined final kern (-\dimen@) if it is >0 or if a superscript follows:
\let\final@kern#2%
\ifdim\dimen@<\z@ \let\final@kern1\fi
\if\final@kern1 \kern-\dimen@\fi
\else
\overline{\rel@kern{-0.6}\kern\dimen@#1}%
\fi
}%
\macc@depth\@ne
\let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
\mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
\macc@set@skewchar\relax
\let\mathaccentV\macc@nested@a
%The following initialises \macc@kerna and calls \mathaccent:
\if#31
\macc@nested@a\relax111{#1}%
\else
%If the argument consists of more than one symbol, and if the first token is
%a letter, use that letter for the computations:
\def\gobble@till@marker##1\endmarker{}%
\futurelet\first@char\gobble@till@marker#1\endmarker
\ifcat\noexpand\first@char A\else
\def\first@char{}%
\fi
\macc@nested@a\relax111{\first@char}%
\fi
\endgroup
}
\makeatother
\begin{document}
$ \widebar{f \circ \widehat{x}} $
\end{document}
.log 文件提供以下内容:
! TeX capacity exceeded, sorry [grouping levels=255].
<to be read again>
\macc@style
l.195 ...i(f)^*} = \widebar{f \circ \widehat{x}} =
\widebar f \circ \widehat...
If you really absolutely need more capacity, …
如果没有\widehat
命令的话就完美了:
有人可以帮忙吗?
答案1
已修改,在末尾添加重要说明:
根据我的回答数学模式中的大波浪符号,我采用了类似的方法来处理宽帽和条形。在以各种数学样式展示它们之后,我展示了它们的复合函数,包括您感兴趣的函数。
\documentclass{article}
\usepackage{scalerel}[2014/03/10]
\usepackage{stackengine}
\newcommand\reallywidetilde[1]{\ThisStyle{%
\setbox0=\hbox{$\SavedStyle#1$}%
\stackengine{1pt-\LMpt}{$\SavedStyle#1$}{%
\stretchto{\scaleto{\SavedStyle\mkern.2mu\sim}{.5467\wd0}}{.5\ht0}%
% .2mu is the kern imbalance when clipping white space
% .5467++++ is \ht/[kerned \wd] aspect ratio for \sim glyph
}{O}{c}{F}{T}{S}%
}}
\newcommand\reallywidehat[1]{\ThisStyle{%
\setbox0=\hbox{$\SavedStyle#1$}%
\stackengine{-1.0\ht0+.5pt}{$\SavedStyle#1$}{%
\stretchto{\scaleto{\SavedStyle\mkern.15mu\char'136}{2.6\wd0}}{1.4\ht0}%
}{O}{c}{F}{T}{S}%
}}
\newcommand\reallywidebar[1]{\ThisStyle{%
\setbox0=\hbox{$\SavedStyle#1$}%
\stackengine{.5pt+\LMpt}{$\SavedStyle#1$}{%
\rule{\wd0}{\dimexpr.3\LMpt+.3pt}%
}{O}{c}{F}{T}{S}%
}}
\def\test#1{$%
\reallywidetilde{#1}\,
\scriptstyle\reallywidetilde{#1}\,
\scriptscriptstyle\reallywidetilde{#1}$~$
\reallywidehat{#1}\,
\scriptstyle\reallywidehat{#1}\,
\scriptscriptstyle\reallywidehat{#1}$~$
\reallywidebar{#1}\,
\scriptstyle\reallywidebar{#1}\,
\scriptscriptstyle\reallywidebar{#1}
$\par}
\parskip 1ex
\begin{document}
Normal math (different styles):
\test{abcde}
\test{abc}
\test{a}
Composites:
$\reallywidebar{D + \reallywidehat{C +\reallywidetilde{ag}}}$
$\reallywidebar{f \circ \reallywidehat{x}}$
\end{document}
重要提示:(基于更好的理解进一步修改)
我想提出一个有趣的观察。TeX 自动处理不同数学样式的方式是使用\mathchoice
,其中构建了四个框,并且只使用其中一个,具体取决于本地数学样式。此 MWE 中使用的包\ThisStyle{...\SavedStyle...}
的构造scalerel
是 的美化版本,\mathchoice
有助于节省输入。
但无论使用\mathchoice
或\ThisStyle
来实现结果,的嵌套\mathchoices
都会变得计算效率很低。
对于这种情况,覆盖\mathchoice
并告诉它使用哪个框可能是有意义的。可以通过定义以下宏来实现:
\def\fixDS#1{{\renewcommand\mathchoice[4]{##1}#1}}% FORCE \displaystyle
\def\fixTS#1{{\renewcommand\mathchoice[4]{##2}#1}}% FORCE \textstyle
\def\fixSS#1{{\renewcommand\mathchoice[4]{##3}#1}}% FORCE \scriptstyle
\def\fixsS#1{{\renewcommand\mathchoice[4]{##4}#1}}% FORCE \scriptscriptstyle
在我的倒数第二个例子中,由于所有\mathchoice
符号都出现在中\displaystyle
,因此可以通过调用以下命令节省大量编译时间:
$\fixDS{\reallywidebar{D + \reallywidehat{C +\reallywidetilde{ag}}}}$
如果 s 出现在不同的数学样式中,也可以使用类似的方法\mathchoice
。例如,以下第一个形式在选择一个框之前构造了许多框,而第二个形式则绕过了分支\mathchoice
。
$\reallywidebar{A_{\reallywidebar{A_{\reallywidebar{A}}}}}$
$\fixDS{\reallywidebar{A_{\fixSS{\reallywidebar{A_\fixsS{\reallywidebar{A}}}}}}}$
仅当嵌套的计算成本\mathchoice
导致编译速度明显减慢时,才需要考虑这种硬连线方法。
补充
在得知上述方法对 来说\reallywidehat
看起来不太美观后newtxmath
,我重新设计了一个适合该字体的版本。还进行了调整\reallywidetilde
以匹配字体特征:
\documentclass{article}
\usepackage{scalerel}[2014/03/10]
\usepackage{stackengine}
\usepackage{newtxtext,newtxmath}
\newcommand\reallywidetilde[1]{\ThisStyle{%
\setbox0=\hbox{$\SavedStyle#1$}%
\stackengine{1pt-\LMpt}{$\SavedStyle#1$}{%
\stretchto{\scaleto{\SavedStyle\mkern.2mu\sim}{.65\wd0}}{.5\ht0}%
% .2mu is the kern imbalance when clipping white space
% .5467++++ is \ht/[kerned \wd] aspect ratio for \sim glyph
}{O}{c}{F}{T}{S}%
}}
\newcommand\reallywidehat[1]{\ThisStyle{%
\setbox0=\hbox{$\SavedStyle#1$}%
\stackengine{-1.0\ht0+1.8pt}{$\SavedStyle#1$}{%
\stretchto{\scaleto{\SavedStyle\mkern.15mu\mathchar"0362}{1.3\wd0}}{1.15\ht0}%
}{O}{c}{F}{T}{S}%
}}
\newcommand\reallywidebar[1]{\ThisStyle{%
\setbox0=\hbox{$\SavedStyle#1$}%
\stackengine{.5pt+\LMpt}{$\SavedStyle#1$}{%
\rule{\wd0}{\dimexpr.3\LMpt+.3pt}%
}{O}{c}{F}{T}{S}%
}}
\def\test#1{$%
\reallywidetilde{#1}\,
\scriptstyle\reallywidetilde{#1}\,
\scriptscriptstyle\reallywidetilde{#1}$~$
\reallywidehat{#1}\,
\scriptstyle\reallywidehat{#1}\,
\scriptscriptstyle\reallywidehat{#1}$~$
\reallywidebar{#1}\,
\scriptstyle\reallywidebar{#1}\,
\scriptscriptstyle\reallywidebar{#1}
$\par}
\parskip 1ex
\begin{document}
Normal math (different styles):
\test{abcde}
\test{abc}
\test{a}
Composites:
$\reallywidebar{D + \reallywidehat{C +\reallywidetilde{ag}}}$
$\reallywidebar{f \circ \reallywidehat{x}}$
\end{document}
答案2
我解决了代码这样\widebar
就可以嵌套重音符号了。我没有进行任何实际测试,但它在您的示例中运行良好:
$\widebar{f \circ \widehat{x}}$