<p></p><p></p><p> - 写了一个宏 `\xhat`,用着试试。</p><p> - 宏定义中,需要解释的部分可能非常多,确有兴趣的,评论提出吧。</p><p><br/></p><p><img src="/data/ueditor/php/upload/image/20190830/1567130181449957.png" title="1567130181449957.png" alt="image.png"/></p><p>第二个可选参数的作用不明显,再说吧。</p><p><br/></p><p><img src="/data/ueditor/php/upload/image/20190830/1567130325130240.png" title="1567130325130240.png" alt="image.png"/></p><p>对用户 <a href="https://wenda.latexstudio.net/u-10015.html" title="registor" target="_blank" style="box-sizing: content-box; background: 0px 0px rgb(255, 255, 255); text-decoration-line: none; transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1) 0s; cursor: pointer; margin: 0px 5px 0px 0px; padding: 0px; outline: 0px; font-size: 15px; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; white-space: normal;">registor</a>私信「线条较宽时,线的交接处不好看」的回应:增加 tikz 选项 `line cap=round`。</p><p><br/></p><pre class="brush:plain;toolbar:false">% question from https://wenda.latexstudio.net/q-1115.html
\documentclass{article}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{xparse}
\makeatletter
\newsavebox\xhat@box
\newsavebox\xhat@box@pre
\newsavebox\xhat@box@suf
\newsavebox\xhat@box@voffset
\tikzset{
xhat line/.style={
line cap=round
},
xhat arrow/.style={
arrows={-Latex[length=3pt]}
}
}
\ExplSyntaxOn
\NewDocumentCommand \xhat { >{\SplitArgument{1}{,}} O{,} O{} m }{
\xhat@getxoffset#1
\savebox\xhat@box@voffset{\ensuremath{#2}}
\savebox\xhat@box{\ensuremath{#3}}
\mathnormal{
\mathop{
\mathstrut
\xhat@voffset{\xhat@box@voffset}\xhat@voffset{\xhat@box}
\smash[t]{\usebox\xhat@box}
}
\limits^{
\begin{tikzpicture}[baseline={(beg)}]
\path
(.5\wd\xhat@box@pre, 0) coordinate (beg)
(\wd\xhat@box - .5\wd\xhat@box@suf, 0) coordinate (end);
\draw[white] (0, 0) -- +(\wd\xhat@box, 0);
\draw[xhat~ line]
(beg) -- node[midway, fill=black, draw=white, circle, line~ width=1pt, inner~ sep=1pt] {} (end);
\path[xhat~ line, xhat~ arrow]
(beg) edge +(0, -5pt)
(end) edge +(0, -5pt);
\end{tikzpicture}
}
}
}
\def\xhat@getxoffset#1#2{
\savebox\xhat@box@pre{\ensuremath{#1}}
\savebox\xhat@box@suf{\ensuremath{#2}}
}
\def\xhat@voffset#1{
\rule{0pt}{\dimexpr\ht#1 - 2pt\relax}
}
\ExplSyntaxOff
\makeatother
\input code-with-output
% code-with-output is downloadable from
% https://github.com/muzimuzhi/latex-examples/blob/master/utilities/code-with-output.tex
\begin{document}
\begin{example*}{Usages of \texttt{\textbackslash xhat}}
% \xhat
% [<left offset text>, <right offset text>]
% [<phantom height text>]
% (<extra tikz options>)
% {<whole text>}
\parindent=0pt\Large
Function of \verb|<left/right offset text>|:
\begin{align*}
abc \xhat {abc} ffffd \xhat {ST} \\
abc \xhat[a,b]{abc} ffffd \xhat[S,T]{ST}
\end{align*}
Function of \verb|<phantom height text>|:
\begin{align*}
abc \xhat[\bm{S},\bm{T}] {\bm{TS}} &=
\xhat[\bm{g},\bm{g}_s]{\bm{g}^k\bm{g}^l\bm{g}_r\bm{g}_s} \\
abc \xhat[\bm{S},\bm{T}][g^l]{\bm{TS}} &=
\xhat[\bm{g},\bm{g}_s]{\bm{g}^k\bm{g}^l\bm{g}_r\bm{g}_s}
\end{align*}
\end{example*}
\begin{example*}{Usage of \texttt{\textbackslash xhat}, 2}
\parindent=0pt\Large
Line cap is always round.
\Huge
\[
\xhat[\bm{S},\bm{T}]{\bm{TS}} \qquad
\tikzset{xhat line/.append style={line width=3pt}}
\xhat[\bm{S},\bm{T}]{\bm{TS}}
\]
\end{example*}
\end{document}</pre><p><br/></p><p></p><p></p>