答案1
这非常简单xparse
:我们将列表“拆分为零”。
\documentclass{article}
\usepackage{yhmath}
\usepackage{xparse}
\NewDocumentCommand{\myarc}{>{\SplitList{}}m}{%
\ProcessList{#1}{\wideparen}%
}
\begin{document}
$13\myarc{682}75$
\end{document}
过程很简单:将每个数字输入到\wideparen
,这样就\myarc{123}
变成了\wideparen{1}\wideparen{2}\wideparen{3}
。
如果要避免重叠,请添加一个小空格:
\documentclass{article}
\usepackage{yhmath}
\usepackage{xparse}
\NewDocumentCommand{\myarc}{>{\SplitList{}}m}{%
\ProcessList{#1}{\widerparen}%
}
\NewDocumentCommand{\widerparen}{m}{\mskip.3mu\wideparen{#1}\mskip.3mu}
\begin{document}
$13\myarc{682}75$
\end{document}
这与之前相同,但是使用\widerparen
,在数字的左边和右边添加一些空间。
如果您只想将弧线放在参数中的第一个和最后一个数字上,则代码会更复杂一些。我留下来\myarc*
打印每个数字上的弧线。
\documentclass{article}
\usepackage{yhmath}
\usepackage{xparse}
\NewDocumentCommand{\widerparen}{m}{\mskip.3mu\wideparen{#1}\mskip.3mu}
\ExplSyntaxOn
\NewDocumentCommand{\myarc}{sm}
{
\IfBooleanTF{#1}
{ \enas_arc_all:n { #2 } } % the call is \myarc*{123}
{ \enas_arc_fl:n { #2 } } % the call is \myarc{123}
}
\seq_new:N \l_enas_arc_input_seq
\cs_new_protected:Nn \enas_arc_all:n
{% this is essentially the same as the easy version
% split the input one digit at a time
\seq_set_split:Nnn \l_enas_arc_input_seq { } { #1 }
% apply \widerparen to each digit
\seq_map_inline:Nn \l_enas_arc_input_seq
{
\widerparen{##1}
}
}
\cs_new_protected:Nn \enas_arc_fl:n
{% we only want the arc on the first and last digit
% split the input one digit at a time
\seq_set_split:Nnn \l_enas_arc_input_seq { } { #1 }
% get the first item and store it
\seq_pop_left:NN \l_enas_arc_input_seq \l_enas_arc_digit_tl
% apply \wideparen to it
\wideparen { \l_enas_arc_digit_tl }
\seq_if_empty:NF \l_enas_arc_input_seq
{% there are other digits, get the last one
\seq_pop_right:NN \l_enas_arc_input_seq \l_enas_arc_digit_tl
\seq_if_empty:NTF \l_enas_arc_input_seq
{% they were only two, add some space
\mskip .6mu
}
{% there are digits in between, print them
\seq_use:Nn \l_enas_arc_input_seq {}
}
% print the last digit
\wideparen { \l_enas_arc_digit_tl }
}
}
\ExplSyntaxOff
\begin{document}
$13\myarc{6}8275$
$13\myarc{68}275$
$13\myarc{682}75$
$13\myarc*{682}75$
\end{document}
答案2
在这里,我设置了一个迭代,从参数中一次取出一个标记并将其应用于\wideparen
它。
\documentclass{article}
\usepackage{yhmath}
%underline
\newcommand{\myarc}[1]{\myarchelp#1\relax}
\def\myarchelp#1#2\relax{\wideparen{#1}\ifx\relax#2\relax\else\myarchelp#2\relax\fi}
\begin{document}
$13\myarc{682}75$
\end{document}
楼主在评论中问是否可以将操作限制在参数的第一个和最后一个字符。类似这样的方法似乎可行
\documentclass{article}
\usepackage{yhmath}
\newcommand{\myarc}[1]{\myarcaux#1\relax}
\def\myarcaux#1#2\relax{\wideparen{#1}\ifx\relax#2\relax\else%
\myarchelp#2\relax\relax\fi}
\def\myarchelp#1#2#3\relax{\ifx\relax#2\wideparen{#1}\else#1\fi\ifx\relax#2\relax\else%
\myarchelp#2#3\relax\fi}
\begin{document}
$13\myarc{682}75$
$13\myarc{645682}75$
$13\myarc{62}75$
$13\myarc{6}75$
\end{document}