8

Consider the following example:

\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}

Is it possible to change \def to \newcommand* and keep the syntax

\door(a,b){c}

instead of

\door{0}{0}{1}

?

1 Answers1

8

\def allows for specifying the parameter text that is to be expected, while \newcommand does not. xparse brings this back, but not with the simplicity that accompanies \def:

enter image description here

\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}{,} splits r() - a required argument that is delimited by (...) - into two parts that should be separated by , in the following way: (a,b) > {a}{b}. As such, \@firstoftwo#1 results in a, and \@secondoftwo#1 results in b. Of course, you could define commands for these rather than \@first-/\@secondoftwo.

Werner
  • 603,163