TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


the call

\start coucou\fin{3}4

will display


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:


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"


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

share|improve this question
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
up vote 5 down vote accepted

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).


\start cocou\fin{3}

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


enter image description here

share|improve this answer
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:

\ifnum3=#2 +++#1+++\fi}
share|improve this answer

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.

\start fish\fin{3}4
share|improve this answer
yes, it gives the output I mentioned... but does not solve the problem of my EDIT1. – nicolas roy Jun 28 '12 at 21:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.