答案页面不工作

答案页面不工作

我正在开发工作表,让学生练习确定直线方程。

除最后一条命令外,所有命令均正常运行\ManySolutions。事实上,即使没有这条命令,代码也可以编译。

有人知道哪里出了问题吗?是否与$$vs不兼容\(\),或者\foreach与我在其中输入的其他命令不兼容?

\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}

答案1

这是我目前的工作成果:

\documentclass{article}

\usepackage{amssymb}
\usepackage{pgf}
 \pgfmathsetseed{\number\pdfrandomseed}
\usepackage{pgffor}
\usepackage{tikz}



\newcommand{\MyScale}{0.4}

\newcommand{\Exercise}{}
\newcommand{\Solution}{}
\newcommand{\VertLine}
{%
%
 \pgfmathrandominteger{\xvar}{-9}{9}
%
 State the slope, $y_{int}$, and equation in slope-intercept form.

 \renewcommand{\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}%
  }
%
 \renewcommand{\Solution}
  {%
   Slope is undefined.
   \ifnum\xvar=0 $y_{int}$ is all real numbers \else There is no $y_{int}$.\fi

   Equation: $x=\xvar$
   \vskip 1cm

 }
}


\newcommand{\ManySolutions}{}



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

%\renewcommand{\ManyExercises}[1]
%{%
%  \newcount\X
%  \X=1
%  \loop
%  \advance \X by 1
%   \VertLine \Exercise \par \vspace{5cm}
%   \edef\oldManySolutions{\ManySolutions}
%   \xdef\ManySolutions{\oldManySolutions \Solution\par }
%  \ifnum\X<#1
%  \relax
%  \repeat
%}





\begin{document}

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


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

\end{document}

注释掉的方式\ManyExercises和上面的结果是一样的,这样我发现问题出在注释掉的 \vspace{1cm} 上,结果当然是没有空格的。

编辑\vspace{1cm}用 \vskip 替换给出了想要的结果

相关内容