# A macro based on the syntax

I want to define a macro that depends on his syntax, for example

\def\macro(#1){code here}
\def\macro[#1){different code here}
...
\def\macro(#1]{different code here}


I saw many way to do this. Someones are very general and provide a way to define any kind of macro with a list of delimeters. Someones require the xparse package.

Is there any native way to define this if the list of possible delimiter is given?

• What's the problem with your approach? Could you please show some example of your use-case? – TeXnician Apr 5 '18 at 9:08
• \def\macro{\futurelet\nexttoken\processmacro} \def\processmacro{\ifx\nexttoken[<do this>\else\ifx\nexttoken(<do that>\fi\fi} roughly. But there's no way to differentiate between the first and third one. If you used syntax ]#1] for your third one then it's possible. – Manuel Apr 5 '18 at 9:14
• Are you perhaps trying to implement a syntax for intervals on the real line? – egreg Apr 5 '18 at 9:47
• Yes, it could be an example! – Luca Benatti Apr 5 '18 at 10:04
• @Manuel Yes there is: grab token-by-token and branch when you find the first end token. Not saying I'd want to do it, but it is doable! – Joseph Wright Apr 5 '18 at 10:12