I am trying to create a simple (hopefully) macro for myself that will make drawing number lines with TikZ more efficient. I can make such lines manually, but since I will need so many similar pictures, a macro would be super useful.
One other note, though: I actually don't want the closing brace for \tikz{}
in the macro because I would like to be able to add other paths inside the macro when I actually use it in the body.
Is any of this possible?
In my MWE, I manually make a number line from 0 to 3 with tick marks at every quarter. That worked. The macro meant to create exactly the same thing did not work. What am I missing here?
Thanks!
\documentclass{article}
\usepackage{tikz}
% THE MACRO THAT DIDN'T WORK
\newcommand{\NL}[4]
{\tikz[xscale=[#1],yscale=[#2]]
{
\draw(0,0)--([#3],0);
\foreach \x in {0,...,[#3]}
\node[below] at (\x,-0.2) {\x};
\foreach \x in {0,...,[#3]*[#4]}
\draw (\x,-0.2)--(\x,0.2);
}
}
\begin{document}
Number line from 0 to 3 with tick marks at every quarter.
MANUAL WAY
\tikz[xscale=4,yscale=1.2]
{\draw (0,0)--(3,0);
\foreach \x in {0,...,3}
\node[below] at (\x,-0.3) {\x};
\foreach \x in {0,...,12}
\draw (\x/4,-0.2)--(\x/4,0.2);
}
ATTEMPT TO MAKE EXACTLY THE SAME NUMBER LINE WITH THE MACRO
\NL{4}{1.2}{3}{4}
% xscale of 4, yscale of 1.2, x-axis from 0 to 3, denominator of quarters
\end{document}