2

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}
4

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.

perhaps

\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}
| improve this answer | |
  • @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
  • Sorry my last comment was a bit confusing. This does answer the question. I was just commenting about how the provided code was helpful not the post as a whole. – Sriotchilism O'Zaic May 31 '17 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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