Use \def
\def
is an incredibly powerful tool when it comes to golfing. \def
allows you to assign something to a variable.
This can be used simply with the to save a number you may use a bunch of times for instance
\def\x{1456}
Will define 1456
as \x
for future use much like saving a variable might in a programming language.
However \def
is much more powerful than that, because \def
doesn't define a variable it defines a snippet of code to be substituted into the program whenever it is called.
For example say you want to draw some rectangles using \draw
you might write the following code:
\draw(0,0)rectangle(3,4)rectangle(8,0);\draw(2,2)rectangle(3,3);
Using \def
this could be written as:
\def\x{)rectangle(}\draw(0,0\x3,4\x8,0);\draw(2,2\x3,3);
Does anyone golf in Tikz? – Pavel – 2017-02-07T20:43:51.790
@Pavel I do.
– Post Rock Garf Hunter – 2017-02-07T20:44:33.267Shouldn't this be a question for meta ? – Sergiy Kolodyazhnyy – 2017-02-07T22:21:12.867
@WheatWizard It seems like a question about "how to approach answering a question" , rather than a programming puzzle itself. I see there's a tips tag, so I assume it's on-topic on the main site. Still learning the ropes on this site, so questions about how to approach answering/reducing answers seems more suitable for meta site rather than main one. – Sergiy Kolodyazhnyy – 2017-02-07T22:28:32.753
4@Serg There are a good deal of [tag:tips] questions of similar content on the main site. These are generally considered to be on-topic. – Post Rock Garf Hunter – 2017-02-07T22:49:48.167
2
For those interested, there is a tikz/pgf manual (its where I found the information for my answers).
Version 3.0.1a, Version 2.10
Do you think this question is worth generalizing/editing to "Tips for golfing in TeX/LaTeX", or should I create a new question? Things like
\def
are not specific to TikZ, and I have some more answers I'd like to add (but none are TikZ-related). – ShreevatsaR – 2017-05-31T17:49:42.0571@ShreevatsaR I think perhaps a new question should be made for TeX/LaTeX, all of the tips here are currently specific to Tikz, and I can see some benefit in keeping them separate. – Post Rock Garf Hunter – 2017-05-31T17:51:34.697
@WheatWizard Ok makes sense; I've created a new question here.
– ShreevatsaR – 2017-06-01T05:46:06.033