I have looked into a few threads about passing arguments to \input command but haven't found much. Any help with my current predicament (or feedback of an alternative approach) would be appreciated! My current setup (working, but not ideal) is:
Relevant part from main.tex
\begin{tikzpicture}[scale=.3]
\input{grid}
%some other shapes
\end{tikzpicture}
grid.tex
\draw[black!20!white] (0,0) grid (20, 20);
\fill (0,0) circle (2pt) node[below left] {(0,200)};
\fill (20,0) circle (2pt) node[below right] {(200,200)};
\fill (0,20) circle (2pt) node[above left] {(0,0)};
\fill (20,20) circle (2pt) node[above right] {(200,0)};
\fill (20,20) circle (2pt) node[above right] {(200,0)};
\tiny
\foreach \x in {20, 40, ..., 180} {
\fill (\x/10,20) circle (2pt) node[above] {\x};
}
\foreach \y in {20, 40, ..., 180} {
\fill (0,20-\y/10) circle (2pt) node[left] {\y};
}
Although I'd like to customize the grid. Something like -
\pgfmathsetmacro{\inc}{#1/10}
\draw[black!20!white] (0,0) grid (\inc,\inc);
\fill (0,0) circle (2pt) node[below left] {(0,#1)};
\fill (\inc,0) circle (2pt) node[below right] {(#1,#1)};
\fill (0,\inc) circle (2pt) node[above left] {(0,0)};
\fill (\inc,\inc) circle (2pt) node[above right] {(#1,0)};
\fill (\inc,\inc) circle (2pt) node[above right] {(#1,0)};
\tiny
\foreach \x in {#2, #2*2, ..., #1 - #2} {
\fill (\x/10,\inc) circle (2pt) node[above] {\x};
}
\foreach \y in {#3, #3*2, ..., #1 - #3} {
\fill (0,\inc-\y/10) circle (2pt) node[left] {\y};
}
And input it in main.tex as:
\begin{tikzpicture}[scale=.3]
\input{grid}[160][10][25]
%some other shapes
\end{tikzpicture}
or
\begin{tikzpicture}[scale=.3]
\input{grid}[300][15][15]
%some other shapes
\end{tikzpicture}
EDIT:
MWE as requested by @Andrew (working, but not ideal) -
main.tex:
\documentclass{exam}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=.3]
\input{grid}
\end{tikzpicture}
\end{center}
\end{document}
grid.tex:
\draw[black!20!white] (0,0) grid (20, 20);
\fill (0,0) circle (2pt) node[below left] {(0,200)};
\fill (20,0) circle (2pt) node[below right] {(200,200)};
\fill (0,20) circle (2pt) node[above left] {(0,0)};
\fill (20,20) circle (2pt) node[above right] {(200,0)};
\fill (20,20) circle (2pt) node[above right] {(200,0)};
\tiny
\foreach \x in {20, 40, ..., 180} {
\fill (\x/10,20) circle (2pt) node[above] {\x};
}
\foreach \y in {20, 40, ..., 180} {
\fill (0,20-\y/10) circle (2pt) node[left] {\y};
}
EDIT 2:
Taking suggestion given by @Andrew, I have managed to define variables in the main file and use the same in grid.tex
main.tex:
\documentclass{exam}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=.3]
\def\gridsize{300}
\def\xMarker{45}
\def\yMarker{50}
\input{grid}
\end{tikzpicture}
\end{center}
\end{document}
grid.tex:
\pgfmathsetmacro\size{\gridsize/10}
\draw[black!20!white] (0,0) grid (\size,\size);
\fill (0,0) circle (2pt) node[below left] {(0,\gridsize)};
\fill (\size,0) circle (2pt) node[below right] {(\gridsize,\gridsize)};
\fill (0,\size) circle (2pt) node[above left] {(0,0)};
\fill (\size,\size) circle (2pt) node[above right] {(\gridsize,0)};
\fill (\size,\size) circle (2pt) node[above right] {(\gridsize,0)};
\tiny
\foreach \x in {0,\xMarker, ..., \gridsize} {
\fill (\x/10,\size) circle (2pt) node[above] {\x};
}
\foreach \y in {0,\yMarker, ..., \gridsize} {
\fill (0,\size-\y/10) circle (2pt) node[left] {\y};
}
Still hoping I can just pass the values to the file somehow :)
I don't think I can create a command since I can't put it inside tikz.
\documentclass
command, include any necessary packages and be as small as possible to demonstrate your problem. Ideally it should compile unless, of course, that is what you are asking about.\input
in this way because\input
is not really a macro and, instead, it simply includes the specified file. What you could do is define macros, say\A, \B, ...
, inmain.tex
and then use these macros as "parameters" in the included file.\input
i.e. define a new macro. But\input
simply takes one argument. That is, it isn't that you haven't figured out how to use it with more parameters. There are no more parameters. And this is certainly not a macro you want to mess around redefining.tikzpicture
? It seems an odd thing to have your heart set on. Why not: define a macro to produce the grid? (Define it in another file if you like. Or not.) Or, better, perhaps, use apic
? (Define it in another file if you like. A TiKZ library or not. Or not. As you wish.)\NewDocumentCommand
. I'd go for apic
, but a macro is certainly an option.