0

I am creating exercise worksheets with solutions for students to practice determining equations from linear graphs.

But my solutions page is not compiling... again. [Previous post.]

I replaced all the \( and \) with $ and have double checked the code... so I think I'm not making the same mistake again.

Does anybody know what's going wrong?

\documentclass{article}

\usepackage{amssymb}
 \newcommand{\reals}{\mathbb{R}}
\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.

   \ifthenelse{\equal{\xvar}{0}}{$y_{int} \in \reals $}{There is no $y_{int}$.}

   Equation: $x=\xvar$%
   \vspace{1cm}
 }
}


\newcommand{\ManySolutions}{}

\newcommand{\ManyExercises}[1]
{%
  \foreach \x in {1,...,#1}
  {%
   \VertLine \Exercise \par \vspace{5cm}
   \xdef\ManySolutions{\ManySolutions \Solution \par} 
  }
}



\begin{document}

%This does not compile...
\ManyExercises{10}

%It does compile if I replace the line above with:
%% \VertLine
%% \Exercise
%% \Solution

\end{document}

1 Answers1

1

Edit After accepted New code that doesn't use Reals symbol and doesn't produce any error:

\documentclass{article}

\usepackage{amssymb}
\let\origmathbb\mathbb
\usepackage{ifthen}
\usepackage{pgf}
 \pgfmathsetseed{\number\pdfrandomseed}
\usepackage{pgffor}
\usepackage{tikz}


\xdef\Reals{\noexpand\origmathbb{R}}

\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} \in Reals $}\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{5cm}
   \edef\oldManySolutions{\ManySolutions}
   \xdef\ManySolutions{\oldManySolutions \Solution  \par} 
  }
}





\begin{document}

%This does not compile...%%%Compiles now
\ManyExercises{10}

%It does compile if I replace the line above with:
%% \VertLine
%% \Exercise
%% \Solution

\end{document}

Here is a solution which doesn't use \ifthenelse but \ifnum instead.

I found by debuging that this command was causing the problem and replaced it with \ifnum

\documentclass{article}

\usepackage{amssymb}
 \newcommand{\reals}{\mathbb{R}}
\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} \in \reals $}
   \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{5cm}
   \xdef\ManySolutions{\ManySolutions \Solution \par} 
  }
}



\begin{document}

%This does not compile...%%%Compiles now
\ManyExercises{10}

%It does compile if I replace the line above with:
%% \VertLine
%% \Exercise
%% \Solution

\end{document}
koleygr
  • 20,105
  • I fount also this: https://tex.stackexchange.com/questions/294686/ifthenelse-inside-tikz-not-working that explains the problem and how to use \iftenelse inside tikz... I don't know if it can be called a duplicate... Different question but the answer is based on that. – koleygr Aug 29 '17 at 00:40
  • Wow. How did you debug this? – WeCanLearnAnything Aug 29 '17 at 01:07
  • @WeCanLearnAnything I removed for start the content of \foreach command and it wsa working... So the problem was clearly in there... uncommented first line (in foreach)... works again... Then removed one by one the arguments in \ManySolutions and found out that \Solution caused the problem... Commented content... etc... – koleygr Aug 29 '17 at 01:18
  • I am not able to compile the code that you gave. http://imgur.com/a/jiWXe – WeCanLearnAnything Aug 29 '17 at 02:17
  • @WeCanLearnAnything I changed \reals to mathcal{R} and works. Thanks for noticing. – koleygr Aug 29 '17 at 02:23
  • Strange... When I compile the code as it is... 4 of 5 times compiles ok. But the one gives \GenericError. May be a bug or something – koleygr Aug 29 '17 at 02:32
  • I think it has to do with the case when \xvar=0 and the real numbers symbol is needed. Then it does not compile. I think that symbol is maybe incompatible with \foreach. – WeCanLearnAnything Aug 29 '17 at 02:32
  • Also... I can't get the \ManySolutions to compile either. – WeCanLearnAnything Aug 29 '17 at 02:42
  • I'm going to mark this as solved since we fixed the if stuff and I can replace \reals with all real numbers. But now I can't get \ManySolutions to compile, so I'm going to start a new thread. Thanks! – WeCanLearnAnything Aug 29 '17 at 03:04
  • Every time I compile it I only get graphs of vertical lines. – Cragfelt Aug 29 '17 at 03:05
  • Ok... I am just trying to find out why it doesn't compile with \mathbb{R} there... I think we have to find out – koleygr Aug 29 '17 at 03:05
  • @Cragfelt if you see the tikzpicture it has the same x value =\xvar for both points of the line. So I suppose it is what you have to expect – koleygr Aug 29 '17 at 03:12
  • @koleygr You are right. I've changed one of them and got oblique straight lines. – Cragfelt Aug 29 '17 at 03:15
  • @WeCanLearnAnything It would be nice if in the solutions part, you incorporate the equation of the line, generated from the code. – Cragfelt Aug 29 '17 at 03:19
  • @Cragfelt he is just creating the code to use it later... I suppose if he find the latex coding he needs he will use it as he wish. – koleygr Aug 29 '17 at 03:24
  • For some reason I forgot to put in the \ManySolutions line in the code originally. Other problems got solved: replacing \ifthenelse with \ifnum and \reals with all real numbers makes the code - exercises only - compile. I started a new thread with the solutions/answer page issue here. https://tex.stackexchange.com/questions/388733/answer-page-not-working – WeCanLearnAnything Aug 29 '17 at 03:30
  • @koleygr that sounds good. I am very interested in this kind of works...

    @WeCanLearnAnything I was searching about the usage of those conditionals and found that you can put this other code\ifthenelse{\value{\xvar}=0}{"condition 1"}{"condition 2"}. Could work.

    – Cragfelt Aug 29 '17 at 04:25