I'm developing worksheets for students to practice determining equations of lines.
Everything is working except for the last command \ManySolutions. In fact, the code compiles without it.
Does anyone know what's wrong? Is there some incompatibility with $$ vs \(\) or is \foreach incompatible with some other command I put in there?
\documentclass{article}
\usepackage{ifthen}
\usepackage{pgf}
\pgfmathsetseed{\number\pdfrandomseed}
\usepackage{pgffor}
\usepackage{tikz}
\newcommand{\MyScale}{0.4}
\newcommand{\VertLine}
{%
%
\pgfmathrandominteger{\xvar}{-9}{9}
%
State the slope, $y_{int}$, and equation in slope-intercept form.
\newcommand{\Exercise}
{%
\begin{tikzpicture}[scale=\MyScale]
\draw[help lines, gray, thin] (-10,-10) grid (10,10);
\draw[very thick,<->] (-10.3,0)--(10.3,0);
\draw[very thick,<->] (0,-10.3)--(0,10.3);
\draw[thick, blue] (\xvar,-10)--(\xvar,10);
\end{tikzpicture}%
}
%
\newcommand{\Solution}
{%
Slope is undefined.
\ifnum\xvar=0
{$y_{int}$ is all real numbers.}
\else
{There is no $y_{int}$.}
\fi
Equation: $x=\xvar$%
\vspace{1cm}
}
}
\newcommand{\ManySolutions}{}
\newcommand{\ManyExercises}[1]
{%
\foreach \x in {1,...,#1}
{%
\VertLine \Exercise \par \vspace{0.5cm}
\xdef\ManySolutions{\ManySolutions \Solution \par}
}
}
\begin{document}
\ManyExercises{15}
\ManySolutions
%It does compile if I replace the two lines above with:
% \VertLine
% \Exercise
% \Solution
% So I know the graph and solutions can be generated.
\end{document}
\newcommandwithin a\foreach, at the second step of loop it gives you an error because the command already exists. – CarLaTeX Aug 29 '17 at 03:35