请考虑以下示例:
\documentclass{article}
\usepackage{pstricks-add}
\def\door(#1,#2)#3{
\psline[
linecap = 0,
linewidth = 1.5\pslinewidth,
linecolor = white
](#1,#2)(!#1 #2 #3 add)
\psline[
linecap = 2
](#1,#2)(!#1 #3 add #2)
\psarc[
linestyle = dotted
](#1,#2){#3}{0}{90}
}
\begin{document}
\begin{pspicture}(1,1)
\door(0,0){1}
\end{pspicture}
\end{document}
是否可以更改\def
为\newcommand*
并保留语法
\door(a,b){c}
代替
\door{0}{0}{1}
?
答案1
\def
允许指定预期的参数文本,但\newcommand
不允许。xparse
带回了这一点,但没有伴随而来的简单性\def
:
\documentclass{article}
\usepackage{pstricks-add,xparse}
\def\door(#1,#2)#3{
\psline[
linecap = 0,
linewidth = 1.5\pslinewidth,
linecolor = white
](#1,#2)(!#1 #2 #3 add)
\psline[
linecap = 2
](#1,#2)(!#1 #3 add #2)
\psarc[
linestyle = dotted
](#1,#2){#3}{0}{90}
}
\makeatletter
\NewDocumentCommand{\Xdoor}{ > { \SplitArgument {1} {,} } r() m}{%
\psline[
linecap = 0,
linewidth = 1.5\pslinewidth,
linecolor = white
](\@firstoftwo#1,\@secondoftwo#1)(!\@firstoftwo#1 \@secondoftwo#1 #2 add)
\psline[
linecap = 2
](\@firstoftwo#1,\@secondoftwo#1)(!\@firstoftwo#1 #2 add \@secondoftwo#1)
\psarc[
linestyle = dotted
](\@firstoftwo#1,\@secondoftwo#1){#2}{0}{90}
}
\makeatother
\begin{document}
\begin{pspicture}(3,1)
\door(0,0){1}
\Xdoor(2,0){1}
\end{pspicture}
\end{document}
\SplitArgument{1}{,}
将- 一个由...分隔的必需参数r()
-拆分为两个部分,这两个部分应按以下方式分隔: > 。因此,结果为,并结果为。当然,您可以为这些而不是-/定义命令。r
(
)
,
(a,b)
{a}{b}
\@firstoftwo#1
a
\@secondoftwo#1
b
\@first
\@secondoftwo