# Can I have a curly brace as macro argument delimiter?

Is there any trick that allows to have a { in argument delimiters of a macro ? for example, with this definition :

\def\start#1\fin{+++#1+++}


the call

\start coucou\fin{3}4


will display

+++coucou+++34

because \fin is the right delimiter of the argument of the macro \start. Now, i would like the whole \fin{3} to be the delimiter. So that the same call as above would now output:

+++coucou+++4

The problem is how to include the curly brace in the delimiters.

Edit1 In particular, I would like the following call

\start coucou\fin{2}blabla\fin{3}


to "output"

coucou\fin{2}blabla

but, regarding to David's comments, it seems to be impossible.

-
It's impossible to have what you ask in the title, however it is of course possible to define a command that works as in your edit. Just define it as in my or egreg's version but of the argument after \fin _isn't 3 then just recurse and collect up to the next \fin and check again. This is how environments like tabularx or ams alignments that collect environments work, they scan up to \end check if it is the correct environment and if not collect up to the next \end. Oh I just realised \fin is probably \end if you're not english:-) –  David Carlisle Jun 28 '12 at 23:36
can you make this in an expandable way ? I would appreciate a few lines of code. –  nicolas roy Jun 29 '12 at 18:52
ok, i guess i could try to learn it in tabularx... –  nicolas roy Jun 29 '12 at 19:05
well, it seems to me, that the idea you wrote in your comment above is precisely egreg's solution. Is it something more ? –  nicolas roy Jun 29 '12 at 19:12
Sorry about that, I hadn't looked in detail at egreg's. I could delete my comment if you think it confusing or leave it, as it's true:-) –  David Carlisle Jun 29 '12 at 20:06

If the arguments to \fin are simple numbers, you can check whether the argument is 3; here's a Plain TeX version (put the standard things to make it into LaTeX).

\def\start{+++\startaux}
\def\startaux#1\fin#2{%
#1%
\ifnum#2=3
+++%
\else
\fin{#2}%
\expandafter\startaux
\fi
}
\def\fin#1{-#1-}

\start cocou\fin{3}

\start cocou\fin{2}blabla\fin{3}

\bye


-
yes, I think this is the answer I need :) By the way, what is \bye supposed to do ? for my TeX, it is just an undefined control sequence... –  nicolas roy Jun 29 '12 at 20:38
@nicolasroy \bye is the Plain TeX way to end a job. –  egreg Jun 29 '12 at 20:41

No you can have \lbrace a command token that acts like { in some contexts and you can have a character token { of a different catcode such as 12 (other) but a token list (however constructed) can not have mis matched token of catcode 1 or 2.

So best you can do is something like:

\def\start#1\fin#2{%
\ifnum3=#2 +++#1+++\fi}

-

This gives the output that you want. I'm not sure that it will resolve whatever issue it is that led you to ask the question though.

\documentclass{article}
\def\start#1\fin{+++#1+++\fin}
\def\fin#1{}
\begin{document}
\start fish\fin{3}4
\end{document}

-
yes, it gives the output I mentioned... but does not solve the problem of my EDIT1. –  nicolas roy Jun 28 '12 at 21:47