5

I understand that TeX macro arguments can be parsed using proper delimiters. And as the classic example goes in The TeXbook,

enter image description here

Along the same line, I tried to define a macro (for some special purpose, the following is actually a much simpler scenario of my situation),

\documentclass{article}

\def\mycommand\cone\bgroup#1\egroup\ctwo #2.#3\end{#1:#2:#3}

\begin{document}

\mycommand\cone{One}\ctwo Two.Three\end

\end{document}

Where, \cone and \ctwo are used/system defined macros, and I am not interested in these definitions, rather I would like to ignore them. My points of interest are the three arguments.

Now, when I try compile the above file, I get the error message,

! Use of \mycommand doesn't match its definition.
l.10 \mycommand\cone{
                     One}\ctwo Two.Three

This is where I get stuck.

Please note that the "\cone{One}\ctwo Two.Three" part is rather unalterable. So, any suggested change will have to be in the definition of \mycommand.

I know that as has been pointed out also in The TeXbook, the parameter list can not contain any braces. To circumvent this, I tried using \bgroup and \egroup.

1 Answer 1

7
\def\mycommand\cone\bgroup#1\egroup\ctwo #2.#3\end{#1:#2:#3}

would require explict \bgroup. It seems like you want

\def\mycommand\cone#1\ctwo #2.#3\end{#1:#2:#3}

Then

\mycommand\cone{One}\ctwo Two.Three\end

or

 \mycommand\cone One\ctwo Two.Three\end

would have #1 = One

1
  • 3
    Indeed TeX strips off a pair of braces around a delimited argument if this doesn't lead to unbalanced braces (double dangerous bend at the end of page 203 that ends on the following page of the TeXbook).
    – egreg
    Nov 4, 2013 at 17:02

You must log in to answer this question.

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