Pgfmath code conflict

I am using the following code, and it works except for the custom macro \QuadraticEquations.

However, it works in a stand alone file. Am I missing something obvious?

\documentclass{article}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{tikz}

\newcommand*{\Difficulty}{10}%

\newcommand{\FracQuestion}[1]{%
\foreach \i in {1,...,#1}{%
\pgfmathtruncatemacro{\DenomDifficulty}{2*\Difficulty}%
\pgfmathtruncatemacro{\Neum}{random(\Difficulty)}
\pgfmathtruncatemacro{\Denom}{random(\DenomDifficulty)}
\item $\dfrac{\Neum}{\Denom}$%
}%
}%

\newcommand{\LinearSystem}[1]{%
\foreach \i in {1,...,#1}{%
\pgfmathtruncatemacro{\Xa}{random(\Difficulty)}%
\pgfmathtruncatemacro{\Ya}{random(\Difficulty)}%
\pgfmathtruncatemacro{\Za}{random(\Difficulty)}%
\pgfmathtruncatemacro{\Xb}{random(\Difficulty)}%
\pgfmathtruncatemacro{\Yb}{random(\Difficulty)}%
\pgfmathtruncatemacro{\Zb}{random(\Difficulty)}%
\item \begin{cases}\begin{aligned}% \Xa x + \Ya y &= \Za \\% \Xb x + \Yb y &= \Zb \\% \end{aligned}\end{cases}%
}%
}%

\foreach \i in {1,...,#1}{%
\pgfmathtruncatemacro{\rootI}{random(-\Difficulty,\Difficulty)}%
\pgfmathtruncatemacro{\rootII}{random(-\Difficulty,\Difficulty)}%
\pgfmathtruncatemacro{\A}{1)}%
\pgfmathtruncatemacro{\B}{-\A*(\rootI+\rootII)}%
\pgfmathtruncatemacro{\C}{\A*\rootI*\rootII}%
\item $\A x^2 \pgfmathprintnumber[showpos]{\B} x \pgfmathprintnumber[showpos]{\C} = 0$%
}%
}%

\foreach \i in {1,...,#1}{%
\pgfmathtruncatemacro{\A}{random(\Difficulty)}%
\pgfmathtruncatemacro{\B}{random(\Difficulty)}%
\pgfmathsetmacro{\C}{(\B*\B)/(4*\A)}%
\item $\A x^2 + \B x + \C = 0$%
}%
}%

\begin{document}
\section{Random Fractions:}
\begin{enumerate}
\FracQuestion{3}
\end{enumerate}

\section{Random 2x2 Linear Equations:}
\begin{enumerate}
\LinearSystem{3}
\end{enumerate}

\begin{enumerate}
\end{enumerate}

\section{Random Quadratic Equations (Equal Roots):}
\begin{enumerate}
\end{enumerate}
\end{document}

• Weclome to TeX.SE! Please spend a couple minutes on reading guide tour and check out the tutorials on how to format your post: link, link. As you can see, your question got downvoted because of such a poor formatting. May 15 at 13:07

Just read the error that the compiler yields. You get

\begin{enumerate} on input line 66 ended by \end{document}. \end{document}


It means that for some reason, enumerate environment hasn't been closed. When you look at \QuadraticEquations's definition you can see that

\newcommand{\QuadraticEquations}[3]{%
\foreach \i in {1,...,#1}{%
\pgfmathtruncatemacro{\rootI}{random(-\Difficulty,\Difficulty)}%
\pgfmathtruncatemacro{\rootII}{random(-\Difficulty,\Difficulty)}%
\pgfmathtruncatemacro{\A}{1)}%
\pgfmathtruncatemacro{\B}{-\A*(\rootI+\rootII)}%
\pgfmathtruncatemacro{\C}{\A*\rootI*\rootII}%
\item $\A x^2 \pgfmathprintnumber[showpos]{\B} x \pgfmathprintnumber[showpos]{\C} = 0$%
}%
}%


defined the way that it requires from you 3 arguments whereas your macro needs only one, that's why \end{enumerate} is being swallowed and error occurs.

TL;DR

Replace

\newcommand{\QuadraticEquations}[3]


with

\newcommand{\QuadraticEquations}[1]

• Thanks for your help but I don't know what is going on as know I am getting~ .0.0.0.0 1x2 − 1x − 72 = 0.0.0.0.0 1x2 − 1x − 56 = 0.0.0.0.0 1x2 −3x−70=0 ~ as the result May 15 at 17:47
• @PaulA I don't have such an issue when I compile the code. You can ask a new question and attack some screenshots of your output, but please, don't forget to read the tour guide and these two articles: link, link May 15 at 18:46
• Thanks and I think I have learnt how to format my queries from now on. May 16 at 10:39