我正在使用以下代码,除了自定义宏之外它都可以工作\QuadraticEquations
。
但是,它在独立文件中有效。我是否忽略了某些显而易见的东西?
\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}$%
}%
}%
\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$%
}%
}%
\newcommand{\QuadraticEquationsEqualRoots}[1]{%
\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}
\section{Random Quadratic Equations:}
\begin{enumerate}
\QuadraticEquations{3}
\end{enumerate}
\section{Random Quadratic Equations (Equal Roots):}
\begin{enumerate}
\QuadraticEquationsEqualRoots{3}
\end{enumerate}
\end{document}
答案1
只需阅读编译器给出的错误即可。你得到
\begin{enumerate} on input line 66 ended by \end{document}. \end{document}
这意味着由于某种原因,enumerate
环境尚未关闭。当你查看\QuadraticEquations
的定义时,你会看到
\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$%
}%
}%
定义的方式需要您提供 3 个参数,而您的宏只需要一个,这就是为什么\end{enumerate}
它会被吞噬并发生错误。
总结
代替
\newcommand{\QuadraticEquations}[3]
和
\newcommand{\QuadraticEquations}[1]