我正在尝试编写一个循环,它将生成一组可在 probsoln 包中使用的随机变量。
我想做一个循环来生成 A、B、C 等。这次考试会有很多问题,我更愿意不单独定义每个问题。然后我想将这些数字传递给选定的问题。我尝试过使用该lcg
包,但我认为该包可能存在一些兼容性问题probsoln
。
这是工作代码(不含循环):
\documentclass[12pt,a4paper,twocolumn]{article}
\usepackage[pdftex]{graphicx}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{amsfonts} %This contains extra fonts needed for math
\usepackage{amscd} %This allows you to draw commutative diagrams.
\usepackage{probsoln}
\usepackage{multicol}
\usepackage{enumerate}
\usepackage[T1]{fontenc}
\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes,shapes.multipart}
\usetikzlibrary{arrows,backgrounds,snakes}
\usepackage{fancyhdr}
\usepackage[
top = 1.50cm,
bottom = 1.50cm,
left = 1.50cm,
right = 1.50cm]{geometry}
\newcommand{\bigbrk}{\vspace*{2in}}
\newcommand{\bigbigbrk}{\vspace*{11in}}
\newcommand{\smallbrk}{\vspace*{.3in}}
\setcounter{section}{0}
\newcommand*\mycirc[1]{%
\begin{tikzpicture}
\node[draw,circle,inner sep=1pt] {#1};
\end{tikzpicture}}
\loadrandomproblems[ac-ma]{1}{ac-ma}
\input{ac-ma}
\newcounter{A}
\newcounter{B}
\newcounter{C}
\random{A}{1}{9}
\random{B}{1}{9}
\random{C}{1}{9}
\begin{document}
\begin{enumerate}
\item \useproblem{AC.MA:DIST}{\arabic{A}}{\arabic{B}}
\end{enumerate}
\end{document}
\endinput
该.tex
文件是从问题数据库中提取的,代码如下:
ac-ma.tex
\def\add#1#2{
\newcount\tmp
\newcount\tmptwo
\tmp=#1
\tmptwo=1
\advance\tmp by #2
\advance\tmp by \tmptwo
\number\tmp
}
\begin{defproblem}[2]{AC.MA:DIST}
If $(#1.95+#2.05)x=x$, then what is the value of $x$?
\begin{multicols}{4}
\begin{enumerate}
\correctitem $\displaystyle{\frac{1}{\add{#1}{#2}}}$
\incorrectitem $\add{#1}{#2}$
\incorrectitem $\add{-#1}{#2}$
\incorrectitem $\add{#1}{-#2}$
\end{enumerate}
\end{multicols}
\end{defproblem}
\begin{defproblem}[1]{GE.LA:E2}
$\angle A$ is a supplement of $\angle B$. If the measure of $\angle A$ is $#1^\circ$, what is the measure of $\angle B$?
\begin{multicols}{4}
\begin{enumerate}
\incorrectitem \add{#1}{90}
\incorrectitem \add{#1}{180}
\incorrectitem \add{-#1}{90}
\correctitem \add{-#1}{180}
\end{enumerate}
\end{multicols}
\end{defproblem}
\begin{defproblem}[1]{GE.LA:E3}
$\angle P$ is a supplement of $\angle Q$. If the measure of $\angle P$ is $(#1x)^\circ$, what is the measure of $\angle Q$?
\begin{multicols}{4}
\begin{enumerate}
\incorrectitem $90-#1x$
\incorrectitem $90+#1x$
\incorrectitem $180-#1x$
\incorrectitem $180+#1x$
\end{enumerate}
\end{multicols}
\end{defproblem}
\endinput
%%
%% End of file `ac-ma.tex'.
任何意见或建议都将不胜感激!我很抱歉在序言中提到了所有这些包,但我以后的问题需要它们。
谢谢您的帮助,但是现在我试图通过在 enumerate 下添加一行将数字传递到随机选择函数中:
\item \selectrandomly{ac-ma}{1}{\myrandomC}
不幸的是,它不愿意接受我的论点,并且我不断收到此错误:
Problem `AC.MA:SYS' (in data base `ac-ma') requires 1 argument(s).
Please specify (e.g. {12}):
我需要将输入包装到某些东西中吗?我尝试使用 \thisproblem 和 \foreachproblem,但总是出现相同的错误。
@grames,我现在正在使用 \esami 包,并尝试从 test1 文件中提取一组随机问题。查看文档,似乎适当的命令是 \estraies[3]{test1}{beta}。然后我会将问题:beta1、beta2 等传递到 \esercizi{beta1,beta2,beta3} 命令行。不幸的是,我似乎做错了什么,因为我一直收到以下错误:
! LaTeX Error: Lonely \item--perhaps a missing list environment.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.40 }
?
以下是代码:
test1.tex
\newproblem{prob1
\FPsetpar{a}{0}{10}
\FPsetpar{b}{0}{10}
\item If $(\a.95+\b.05)x=x$, then what is the value of $x$?
\vspace{10 mm}
\begin{answers}{2}\bChoices[random]
\Ans1 $0$ \eAns
\Ans0 \FPsv{a+b+1}\eAns
\Ans0 \FPsv{a+b}\eAns
\Ans0 $\displaystyle{\frac{1}{\FPsv{a+b}}}$ \eAns
\eChoices\end{answers}}
\newproblem{prob2
\FPsetpar{a}{2}{5}
\item For what value of $x$ is the equation \begin{equation*} \frac{x-\a}{\a+x}=0 \end{equation*} true?
\vspace{10 mm}
\begin{answers}{2}\bChoices
\Ans0 -\a \eAns
\Ans1 \a \eAns \eFreeze
\Ans0 all real numbers \eAns \eFreeze
\Ans0 There are no values for $x$ that would make the equation true. \eAns
\eChoices\end{answers}}
\newproblem{prob3
\FPsetpar{a}{2}{5}
\item If $\a x-\a=xy-y$ and $x\neq1$, what is the value of $y$?
\vspace{10 mm}
\begin{answers}{2}\bChoices[random]
\Ans1 \a \eAns
\Ans0 -\a \eAns
\Ans0 0 \eAns \eFreeze
\Ans0 There are no values for $x$ that would make the equation true. \eAns
\eChoices\end{answers}}
\newproblem{prob4
\FPsetpar{a}{2}{5}
\item If $\a x-\a=xy-y$ and $x\neq1$, what is the value of $y$?
\vspace{10 mm}
\begin{answers}{2}\bChoices[random]
\Ans1 \a \eAns
\Ans0 -\a \eAns
\Ans0 0 \eAns \eFreeze
\Ans0 There are no values for $x$ that would make the equation true. \eAns
\eChoices\end{answers}}
master_new.tex
\documentclass[a4paper,UKenglish]{article}
\usepackage[shufflerandom,xyz,twocolumns, autopstoff,nosolutions]{esami}
\usepackage{lmodern,textcomp}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
% +=============================+
% | DEFINITIONS |
% +=============================+
\def\examname{The name of the exam}
\def\numcompiti{1}%%% The number of the versions
\date{2013/3/22}%%% THE DATE IN THE FORMAT YYYY/MM/DD
\def\Data{\longdate}%%% or \shortdate: the date in the heading
\begin{document}
\testversioni
\pagestyle{esame}
\whiledo{\thevers<\numcompiti}{\stepvers
% +=============================+
% | THE SEED |
% +=============================+
\FPeval\seme{round((\thenomefile+(3*\thevers)):0)}
\randomi=\seme
\permuta
\estraies[0]{test1}{beta}
\section*{Mathematics Achievement}
\begin{test}
\begin{questions}
\esercizi{betai,betaii}
\end{questions}
\end{test}
%\closevers
}
\end{document}
任何帮助都将不胜感激。谢谢 MeTutel
@grames 好的,很高兴知道。我还没能让它工作,但我会继续尝试。我还有一个问题。您的包使用 PSTricks 包来处理图形,根据文档,它应该在工作区空间中。我已将选项更改为 autostopon,但我尝试生成的图形仍然不起作用。我希望所有问题都不会造成麻烦,但我正在尝试在提交问题之前通读文档和示例并尝试代码。这是我正在使用的代码,首先是问题文件。eachtest.tex
\newproblem{
\item Determine the are of the figure below.
\begin{workarea}[10mm]{10mm}
\begin{pspicture}(4,5)
\psframe(0.7,2)(3.3,3)
\rput(2,2.5){First Example}
\end{pspicture}
\end{workarea}
\vspace{10 mm}
\begin{answers}{2}\bChoices[random]
\Ans0 Wrong \eAns
\Ans1 Right \eAns
\Ans0 Wrong \eAns
\Ans0 Wrong \eAns
\eChoices\end{answers}
}'
\documentclass[a4paper,UKenglish]{article}
\usepackage[shufflerandom,autopston,xyz,twocolumns,solutions]{esami}
\usepackage{lmodern,textcomp}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
% +=============================+
% | DEFINITIONS |
% +=============================+
\def\examname{The name of the exam}
\def\numcompiti{1}%%% The number of the versions
\date{2013/3/22}%%% THE DATE IN THE FORMAT YYYY/MM/DD
\def\Data{\longdate}%%% or \shortdate: the date in the heading
\begin{document}
\testversioni
\pagestyle{esame}
\whiledo{\thevers<\numcompiti}{\stepvers
% +=============================+
% | THE SEED |
% +=============================+
\FPeval\seme{round((\thenomefile+(3*\thevers)):0)}
\randomi=\seme
\permuta
\section*{Mathematics Achievement}
\begin{test}
\begin{questions}
\esercizi{eachtest}
%\esercizi{probs-ac-ma,probs-ge-ma,probs-ge-qr}
\end{questions}
\end{test}
\closevers
}
\end{document}
答案1
由于您已经在使用 TikZ,因此可以使用模块random()
的功能;在 中给出一个随机实数,在 中给出一个整数,在 中给出一个整数。然后将得到的随机整数(用伪随机替换所有随机词)保存到宏中...pgfmath
random()
[0,1]
random(x)
[1,x]
random(x,y)
[x,y]
\myrandomA,\myrandomB
我还删除/修改了一些包声明,因为有些包声明会加载其他包声明等,并使用 filecontents 包进行ac-ma.tex
动态创建。
\PassOptionsToPackage{usenames,dvipsnames,svgnames,table}{xcolor}
\documentclass[12pt,a4paper,twocolumn]{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{amsfonts} %This contains extra fonts needed for math
\usepackage{amscd} %This allows you to draw commutative diagrams.
\usepackage{probsoln}
\usepackage{multicol}
\usepackage{enumerate}
\usepackage{filecontents}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{shapes,shapes.multipart}
\usetikzlibrary{arrows,backgrounds,snakes}
\usepackage{fancyhdr}
\usepackage[
top = 1.50cm,
bottom = 1.50cm,
left = 1.50cm,
right = 1.50cm]{geometry}
\begin{filecontents}{ac-ma.tex}
\def\add#1#2{
\newcount\tmp
\newcount\tmptwo
\tmp=#1
\tmptwo=1
\advance\tmp by #2
\advance\tmp by \tmptwo
\number\tmp
}
\begin{defproblem}[2]{AC.MA:DIST}
If $(#1.95+#2.05)x=x$, then what is the value of $x$?
\begin{multicols}{4}
\begin{enumerate}
\correctitem $\displaystyle{\frac{1}{\add{#1}{#2}}}$
\incorrectitem $\add{#1}{#2}$
\incorrectitem $\add{-#1}{#2}$
\incorrectitem $\add{#1}{-#2}$
\end{enumerate}
\end{multicols}
\end{defproblem}
\begin{defproblem}[1]{GE.LA:E2}
$\angle A$ is a supplement of $\angle B$. If the measure of $\angle A$ is $#1^\circ$, what is the measure of $\angle B$?
\begin{multicols}{4}
\begin{enumerate}
\incorrectitem \add{#1}{90}
\incorrectitem \add{#1}{180}
\incorrectitem \add{-#1}{90}
\correctitem \add{-#1}{180}
\end{enumerate}
\end{multicols}
\end{defproblem}
\begin{defproblem}[1]{GE.LA:E3}
$\angle P$ is a supplement of $\angle Q$. If the measure of $\angle P$ is $(#1x)^\circ$, what is the measure of $\angle Q$?
\begin{multicols}{4}
\begin{enumerate}
\incorrectitem $90-#1x$
\incorrectitem $90+#1x$
\incorrectitem $180-#1x$
\incorrectitem $180+#1x$
\end{enumerate}
\end{multicols}
\end{defproblem}
\endinput
%%
%% End of file `ac-ma.tex'.
\end{filecontents}
\newcommand{\bigbrk}{\vspace*{2in}}
\newcommand{\bigbigbrk}{\vspace*{11in}}
\newcommand{\smallbrk}{\vspace*{.3in}}
\setcounter{section}{0}
\newcommand*\mycirc[1]{%
\begin{tikzpicture}
\node[draw,circle,inner sep=1pt] {#1};
\end{tikzpicture}}
\loadrandomproblems[ac-ma]{1}{ac-ma}
\input{ac-ma}
%================================ MODIFIED
%================================
\foreach \x in {A,...,C}{
\pgfmathparse{random(9)}
\expandafter\xdef\csname myrandom\x\endcsname{\pgfmathresult}
}
\begin{document}
\begin{enumerate}
\item \useproblem{AC.MA:DIST}{\myrandomA}{\myrandomB}
\end{enumerate}
%================================
%================================
\end{document}
然而,这个问题似乎是错误的,因为无论如何答案似乎都是零。
答案2
我们在 esami 包中使用 fp 和 random 解决了类似的问题。您可以在以下链接中查看 esami.sty 文件中的宏https://www.dropbox.com/sh/0t92kehukgafni5/0Mi0qsYLlR