我想写一份试卷的tex文件,比如
(Derivative function)
1. $3x-1$
2. $2x+1$
3. $4x^2+2x+3$
4. $7x^3-3x-6$
5. $\sin6x-7$
6. $\cos5x+2$
然后,我可以设置一个逻辑变量\examtype
,比如=0,typeset
Exam paper (A)
(Derivative function)
2. $2x+1$
4. $7x^3-3x-6$
6. $\cos5x+2$
否则,设置\examtype
=1,排版
Exam paper (B)
(Derivative function)
1. $3x-1$
3. $4x^2+2x+3$
5. $\sin6x-7$
。
答案1
以下是提供一些选项的版本。它定义了一个MyExam
接受两个参数的环境:第一个是标题,第二个用于选择要打印的项目。
1.odd
或even
:
您可以选择打印odd
或even
提问:
2. 问题清单:
您可以将特定问题打印为明确指定的1,5,6
问题列表或一系列问题1,...,5
:
或者列表和范围的组合1,...,4,6
:
笔记:
- 我已经使用
newtoggle
过包裹etoolbox
因为我更喜欢那个语法而不是\newif
语法。但如果你不想包含额外的包,那么调整它以使用\newif
或其他一些条件方法 - 包裹
xstring
用于字符串比较 - 该
pgf
库因其数学功能和\foreach
循环而被使用。
代码:
\documentclass{article}
\usepackage{enumitem}
\usepackage{xstring}
\usepackage{etoolbox}
\usepackage{pgffor}
\usepackage{pgfmath}
\newlist{MyEnumerate}{enumerate}{1}
\setlist[MyEnumerate]{label={\arabic*.}}
\newcommand{\QuestionSelector}{}%
\newcounter{MyExamCounter}
\newtoggle{DisplayThisItem}%
\newcommand{\MyItem}[1]{%
\stepcounter{MyExamCounter}%
\global\togglefalse{DisplayThisItem}%
\pgfmathsetmacro{\Remainder}{mod(\arabic{MyExamCounter},2)}%
\IfStrEqCase{\QuestionSelector}{
{odd}{\IfEq{\Remainder}{1}{\global\toggletrue{DisplayThisItem}}{}}%
{even}{\IfEq{\Remainder}{0}{\global\toggletrue{DisplayThisItem}}{}}%
}[%
\edef\ListOfItems{\QuestionSelector}%
\foreach \x in \ListOfItems {%
\IfEq{\x}{\arabic{MyExamCounter}}{%
\global\toggletrue{DisplayThisItem}%
\breakforeach%
}{}%
}%
]%
\iftoggle{DisplayThisItem}{%
\begin{MyEnumerate}[series=MyExamList]%
\item[\arabic{MyExamCounter}.] #1%
\end{MyEnumerate}%
}{}%
}%
\newenvironment{MyExam}[2]{%
\setcounter{MyExamCounter}{0}%
\renewcommand*{\QuestionSelector}{#2}%
\par\noindent\textbf{#1}%
}{%
}
\newcommand*{\MyListOfQuestions}{%
\MyItem{$3x-1$}
\MyItem{$2x+1$}
\MyItem{$4x^2+2x+3$}
\MyItem{$7x^3-3x-6$}
\MyItem{$\sin6x-7$}
\MyItem{$\cos5x+2$}
}%
\begin{document}
\begin{minipage}[t]{0.45\linewidth}
\begin{MyExam}{Derivative function: Odd}{odd}
\MyListOfQuestions
\end{MyExam}
\end{minipage}%
\begin{minipage}[t]{0.45\linewidth}
\begin{MyExam}{Derivative function: Even}{even}
\MyListOfQuestions
\end{MyExam}
\end{minipage}%
\bigskip
\begin{minipage}[t]{0.45\linewidth}
\begin{MyExam}{Derivative function: 1,5,6}{1,5,6}
\MyListOfQuestions
\end{MyExam}
\end{minipage}%
\begin{minipage}[t]{0.45\linewidth}
\begin{MyExam}{Derivative function: 1,...,5}{1,...,5}
\MyListOfQuestions
\end{MyExam}
\end{minipage}
\bigskip
\begin{MyExam}{Derivative function: 1,...,4,6}{1,...,4,6}
\MyListOfQuestions
\end{MyExam}
\end{document}