1

Using \NewDocumentCommand, it's possible to specify a delimited argument (e.g. r() for a required argument in parentheses). Is it possible to use other arguments in the same command as those delimiters? For example, is it possible to do something like this, or are there any workarounds?

\documentclass{article}

\NewDocumentCommand\getbetween { m m r#1#2 } { #3 }

\begin{document}

\getbetween() (abc)

\end{document}

(The code above produces the errors that there is an "Illegal parameter number in definition of \__tl_map_1:w." and that there is an "Invalid argument type '##' in command '\getbetween'.")

4
  • 2
    This might be an x-y-problem. What do you want to achieve in the "big picture"? Note that I'd like to discourage you from implementing such behaviour, this doesn't seem like a well-defined interface.
    – Skillmon
    Commented Jan 3 at 20:33
  • I'd like to automatically size delimiters, e.g.\NewDocumentCommand{\autosize}{ r() }{ \left(#1\right) }. Ideally I'd like to have some way to support different types of delimiters without having to exhaustively define r(), r[], r\{\}, etc. versions for every delimiter pair to support.
    – Gravitron
    Commented Jan 3 at 20:40
  • 3
    @Gravitron in that case you should use the declarations provided by mathtools Commented Jan 3 at 21:48
  • Ah, that looks useful. Thanks!
    – Gravitron
    Commented Jan 4 at 1:00

1 Answer 1

1

If you want this, you can do it in two steps:

\documentclass{article}

\NewDocumentCommand\getbetweenx{}{}

\NewDocumentCommand\getbetween { m m}{%
 \RenewDocumentCommand\getbetweenx{r#1#2 } {arg was: ``##1''}%
 \getbetweenx}

\begin{document}

\getbetween() (abc)

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .