# Can I use curly braces inside of a \def?

I'm using tikz to compete in a codegolf question here. To get around having to write \typein a whole bunch of times I have \def~{\typein[}. Since nearly every \typein is prepended by ]{} so I would like to define ]{}\typein[ instead. However \def doesn't like curly braces for obvious reasons.

Is there some way I could add curly braces to my definition?

Here is my code if that helps at all:

\documentclass[tikz]{standalone}\begin{document}\tikz\def~{\typein[}~\a]{}~\s]{}~\d]{}~\r]{}\def\u{)--(\a+\d}\draw(0,0)--(\a,127\u,\s\u+64,\s\u+\r+64,0);\end{document}


There is no problem at all in using matching pairs of {..} which appears to be what you want. If I understand correctly your problem was hiding the ] which needs to close the optional argument.
\documentclass[tikz]{standalone}\begin{document}\tikz\def~#1{\typein[#1]{}}~\a~\s~\d~\r\def\u{)--(\a+\d}\draw(0,0)--(\a,127\u,\s\u+64,\s\u+\r+64,0);\end{document}

• @EpsilonNeighborhoodWatch not what you were trying to do but you asked about {} in a def which are no problem at all as shown here, and just vaguely hinted that you had tried to have the braces [ and ] for the optional \typein argument be in different macros, but that can not work. – David Carlisle May 31 '17 at 18:15