我正在创建带有解决方案的练习工作表,以便学生练习从线性图确定方程。
但是我的解决方案页面没有再次编译。[上一篇文章。
我用 替换了所有\(
,\)
并$
仔细检查了代码……所以我想我不会再犯同样的错误。
有人知道发生了什么问题吗?
\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
接受后编辑 不使用 Reals 符号且不会产生任何错误的新代码:
\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}
这是一个不使用\ifthenelse
but 的解决方案\ifnum
。
通过调试我发现这个命令导致了问题,并将其替换为\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}