diff options
Diffstat (limited to 'macros/latex/contrib/randexam/randexam.tex')
-rw-r--r-- | macros/latex/contrib/randexam/randexam.tex | 541 |
1 files changed, 541 insertions, 0 deletions
diff --git a/macros/latex/contrib/randexam/randexam.tex b/macros/latex/contrib/randexam/randexam.tex new file mode 100644 index 0000000000..9e38395b94 --- /dev/null +++ b/macros/latex/contrib/randexam/randexam.tex @@ -0,0 +1,541 @@ +% -*- coding: utf-8 -*- + +\documentclass[12pt,plain,most]{randexam} +\geometry{b5paper,margin=2cm} + +\newcommand*{\myversion}{2024B} +\newcommand*{\mydate}{\the\year-\mylpad\month-\mylpad\day} +\newcommand*{\mylpad}[1]{\ifnum#1<10 0\the#1\else\the#1\fi} + +\cfoot{\small\thepage} + +\setlength{\parindent}{0pt} +\setlength{\parskip}{7pt plus 1pt minus 1pt} + +\usepackage{arevtext} +\usepackage{iftex} +\usepackage{ninecolors} +\usepackage{hyperref} +\hypersetup{ + colorlinks=true, + urlcolor=blue3, + linkcolor=blue3, +} + +\renewcommand\familydefault{\sfdefault} + +\renewcommand{\baselinestretch}{1} +\renewcommand{\arraystretch}{1.3} + +\usepackage{tabularx} + +\newcommand{\fillbox}[1]{\ulinefill{#1}\underline{#1}\ulinefill{#1}} + +\usepackage{fancyvrb} + +\DefineVerbatimEnvironment{code}{Verbatim}{% + formatcom=\color{blue!50!red}% +} + +\usepackage{codehigh} + +\NewDocumentCommand\mypkg{m}{\textcolor{blue3}{\mbox{#1}}} +\NewDocumentCommand\myopt{m}{\textcolor{yellow3}{\mbox{#1}}} +\NewDocumentCommand\mycmd{m}{\textcolor{green3}{\ttfamily\fakeverb{#1}}} +\NewDocumentCommand\myenv{m}{\textcolor{green3}{\ttfamily#1}} +\NewDocumentCommand\myfile{m}{\textcolor{purple3}{\mbox{#1}}} +\NewDocumentCommand\mykey{m}{\textcolor{brown3}{\mbox{\fakeverb{#1}}}} +\NewDocumentCommand\myval{m}{\textcolor{azure3}{\mbox{\fakeverb{#1}}}} + +\begin{document} + +{% + \renewcommand{\arraystretch}{2}% + \noindent\Large + \begin{tabularx}{\linewidth}{|X|} + \hline + Title: \fillbox{\color{blue3}The randexam class for LaTeX}\\ + Author: \fillbox{Jianrui Lyu (tolvjr@163.com)}\\ + Version: \fillbox{\myversion{} (\mydate)}\\ + \hline + \end{tabularx}% +} + +\tableofcontents + +\section{Introduction} + +Document class \mypkg{randexam} is an exam class for LaTeX. +With this class you could easily make an exam paper and its randomized variants. + +The class mainly focuses on making math exam papers, but you could use it to make other exam papers. + +The latest release of this package can be downloaded from here: \newline +\textcolor{blue}{\href{https://ctan.org/pkg/randexam}{\ttfamily https://ctan.org/pkg/randexam}}. + +\section{Basic Structure} + +\subsection{A randexam document} + +The following is the basic structure of a \mypkg{randexam} document: +\begin{code} +\documentclass{randexam} +% document preamble +\begin{document} +% document body +\end{document} +\end{code} +In document preamble you could set some options for the exam. +In document body you write the contents of the exam. + +\subsection{Document preamble} + +In document preamble you normally set some class options with \mycmd{\SetExamOption} command. +For example, you could change the random seed with \myopt{seed} key. The seed is used only when +you add class option \myopt{random} (see Subsection \ref{opt:random}): +\begin{code} +\SetExamOption{ + seed = 19061116, % random seed +} +\end{code} + +\subsection{Document body} + +In document body you normally write an \mycmd{\examtitle}, +multiple \mycmd{\examgroup}, and an optional \mycmd{\examdata} commands: + +\begin{code} +\examtitle{name=Math Final Exam,date=2018-06-28,version=A} +...... +\examgroup{Fill in the blanks.}{3 points for each.} +...... +\examgroup{Select one answer.}{3 points for each.} +...... +\examgroup{Work out math calculations.}{8 points for each.} +...... +\examdata{Some data may be used in the exam} +...... +\end{code} + +\subsection{Exam title} + +In calling \mycmd{\examtitle} command, +you need to provide some basic informations of the exam: + +\begin{code} +\examtitle{name=Math Final Exam,date=2018-06-28,version=A} +\end{code} + +If the \mykey{date} key is missing, it has the default value \myval{\today}. +When class option \myopt{random} is passed, the value of \mykey{version} key +will be modified from \myval{A} to \myval{B}. + +\subsection{Exam groups} + +The questions in an exam could be separated into several groups: + +\begin{code} +\examgroup{Fill in the blanks.}{3 points for each.} +...... +\examgroup{Select one answer.}{3 points for each.} +...... +\examgroup{Work out math calculations.}{8 points for each.} +...... +\end{code} + +\subsection{Exam data} + +At the end of the exam, you could add some appendix data with \mycmd{\examdata} command: + +\begin{code} +\examdata{Some data may be used in the exam} +...... +\end{code} + +You must put appendix data after \mycmd{\examdata} command, +or the exam variants will be incorrect. + +\section{Types of questions} + +\subsection{True-or-false questions} + +\begin{code} +\examgroup{True-or-false questions}{3 points for each.} + +\begin{question} +The first true-or-false question. \tickout{T} +\end{question} + +\begin{question} +The second true-or-false question. \tickout{F} +\end{question} +\end{code} + +\begin{question} +The first true-or-false question. \tickout{T} +\end{question} + +\begin{question} +The second true-or-false question. \tickout{F} +\end{question} + +With \mycmd{\tickout{T}} and \mycmd{\tickout{F}}, you get \textcolor{blue}{\textsf{T}} +and \textcolor{blue}{\textsf{F}}; with \mycmd{\tickout{t}} and \mycmd{\tickout{f}}, +you get \textcolor{blue}{$\checkmark$} and \textcolor{blue}{\large$\times$}. + +You must put answers inside \mycmd{\tickout} command, +so as to make \mypkg{randexam} hide them in generating blank exam papers. + +\subsection{Fill-in-the-blank questions} + +\begin{code} +\examgroup{Fill in the blanks.}{3 points for each.} + +\begin{question} +The first fill-in-the-blank question \fillout{answer}. +\end{question} + +\begin{question} +The second fill-in-the-blank question \fillout{answer}. +\end{question} +\end{code} + +\begin{question} +The first fill-in-the-blank question \fillout{answer}. +\end{question} + +\begin{question} +The second fill-in-the-blank question \fillout{answer}. +\end{question} + +With \mycmd{\fillout} command, the underline will fill the whole line; +with \mycmd{\fillin} command, the underline will be minimal. + +You must put answers inside \mycmd{\fillout} or \mycmd{\fillin} command, +so as to make \mypkg{randexam} hide them in generating blank exam papers. + +\subsection{Multiple-choice questions} + +\begin{code} +\examgroup{Select one answer.}{3 points for each.} + +\begin{question} +The first multiple-choice questions \pickout{A}. +\begin{abcd} + \item First + \item Second + \item Third + \item Fourth +\end{abcd} +\end{question} + +\begin{question} +The second multiple-choice questions \pickout{C}. +\begin{abcd} + \item First choice + \item Second choice + \item Third choice + \item Fourth choice +\end{abcd} +\end{question} +\end{code} + +\begin{question} +The first multiple-choice questions \pickout{A}. +\begin{abcd} + \item First + \item Second + \item Third + \item Fourth +\end{abcd} +\end{question} + +\begin{question} +The second multiple-choice questions \pickout{C}. +\begin{abcd} + \item First choice + \item Second choice + \item Third choice + \item Fourth choice +\end{abcd} +\end{question} + +With \mycmd{\pickout} command, the answer will be printed on the right edge of the line; +with \mycmd{\pickin} command, the answer will be printed on current position. + +You must put answers inside \mycmd{\pickout} or \mycmd{\pickin} command, +so as to make \mypkg{randexam} hide them in generating blank exam papers. + +The four choices of multiple-choice questions could be typeset with \myenv{abcd} environment. +And \myenv{abcd} environment will put them in one, two, or four rows +according to the lengths of the choices. + +\subsection{Subjective questions} + +For subjective questions, you could put answers inside \myenv{solution} environment. + +\begin{code} +\examgroup{Work out math calculations.}{8 points for each.} + +\begin{question} +The first math calculation question. +\end{question} + +\begin{solution} +Answer to the first question. +\end{solution} + +\begin{question} +The second math calculation question. +\end{question} + +\begin{solution} +Answer to the second question. +\end{solution} +\end{code} + +\begin{question} +The first math calculation question. +\end{question} + +\begin{solution} +Answer to the first question. +\end{solution} + +\begin{question} +The second math calculation question. +\end{question} + +\begin{solution} +Answer to the second question. +\end{solution} + +\subsection{Other questions} + +You can write other types of questions. For example: + +\begin{code} +\examgroup{Some question type}{4 points for each.} + +\begin{question} +First question text. \answer{Answer text.} +\end{question} + +\begin{question} +Second question text. \answer{Answer text.} +\end{question} +\end{code} + +\begin{question} +First question text. \answer{Answer text.} +\end{question} + +\begin{question} +Second question text. \answer{Answer text.} +\end{question} + +You must put answer text inside \mycmd{\answer} command, +so as to make \mypkg{randexam} hide them in generating blank exam papers. + +\section{Other components} + +\subsection{Grade tables} + +Normally you need a grade table after exam title. +You can get it by using \mycmd{\gradetable} command. + +\begin{code} +\gradetable +\end{code} + +\gradetable + +\subsection{Answer tables} + +Before true-or-false, fill-in-the-blank, or multiple-choice questions, +you may use \mycmd{\answertable} to generate an blank answer table: + +\begin{code} +\answertable[3em]{6}{3} +\end{code} + +\answertable[3em]{6}{3} + +The meanings of the three arguments of \verb!\answertable! commands are as follows: +\begin{itemize} + \item The first one means the strut height of the answer rows; its default value is \verb!1em!. + \item The second one means the total number of questions in this exam group. + \item The third one means the number of questions in each row. +\end{itemize} + +\subsection{Vertical space} + +You could leave some vertical space after a \myenv{question} or \myenv{solution} environment. +At this time \mypkg{randexam} class supports the following commands for adding vertical space:\par + +\renewcommand{\arraystretch}{1.3}% +\begin{tabularx}{\linewidth}{l<{\qquad}X} + \hline + \texttt{\string\smallskip} & Add small vertical space\\ + \hline + \texttt{\string\medskip} & Add medium vertical space\\ + \hline + \texttt{\string\bigskip} & Add big vertical space\\ + \hline + \texttt{\string\vfill} & Fill vertical space available\\ + \hline +\end{tabularx}\par + +Of course, you could use multiple commands in the above tables. + +In the exam body, you could use \mycmd{\newpage} to make a page break, +but you should \underline{NOT} use other page breaking commands, such as \mycmd{\clearpage}, +or the exam variants may be wrong. + +\section{Writing questions} + +\subsection{points key} + +The \myenv{question} environment accepts a \mykey{points} key: + +\begin{code} +\begin{question}[points=4] +This is a question. +\end{question} +\end{code} + +\begin{question}[points=4] +This is a question. +\end{question} + +\section{Writing solutions} + +\subsection{Solution name} + +If you want to change the name of \myenv{solution} environment, +you could redefine \mycmd{\solutionname} command. +The following example changes it from "Solution" to "Proof": + +\begin{code} +\renewcommand{\solutionname}{Proof} +\end{code} + +\subsection{Points command} + +Inside \myenv{solution} environment, you could use \mycmd{\points} to give points for each step. +For example: + +\begin{code} +\begin{solution} +$1+1=2$ \points{4} +$2+2=4$ \points{8} +\end{solution} +\end{code} + +\begin{solution} +$1+1=2$ \points{4} +$2+2=4$ \points{8} +\end{solution} + +You can also use \mycmd{\points} command inside displayed formulas or \myenv{align*} environment. +And the point text will be printed at the right edge of the line. + +\subsection{Alignment commands} + +With class option \myopt{many}, \mypkg{randexam} will load \mypkg{freealign} package. +and \mypkg{freealign} package provides several commands for aligning math formulas in different lines. + +Here is the first example: + +\begin{code} +We have $(a+b)^2 \? = (a+b)(a+b)$ \\ + \+$= a^2+2ab+b^2$ \points{2} +\end{code} + +\hrule +We have $(a+b)^2 \? = (a+b)(a+b)$ \\ + \+$= a^2+2ab+b^2$ \points{2} +\hrule\vskip0.5em + +The \mycmd{\?} command \underline{inside} the first formula saves current horizontal position, +and the \mycmd{\+} command \underline{before} the second formula jumps to previously saved position. + +Here is another example: + +\begin{code} +We have \? $(a+b)^2 = (a+b)(a+b)$ \\ + \< $= a^2+2ab+b^2$ \points{2} +\end{code} + +\hrule +We have \? $(a+b)^2 = (a+b)(a+b)$ \\ + \< $= a^2+2ab+b^2$ \points{2} +\hrule\vskip0.5em + +The \mycmd{\?} command \underline{before} the first formula saves current horizontal position, +and the \mycmd{\<} command \underline{before} the second formula jumps to the left +of previously saved position by the width of $=$. + +Because \mypkg{freealign} package uses \mypkg{zref} package to save positions, +you need two compilations to get correct results. + +\section{Class options} + +\subsection{Blank exam papers} + +Assume \myfile{exam-a-answer.tex} is an exam paper with answers. +You can easily get an blank exam paper with answers removed, +by creating an \myfile{exam-a-blank.tex} file with the following lines: + +\begin{code} +\PassOptionsToClass{noanswer}{randexam} +\input{exam-a-answer} +\end{code} + +That is to say, when adding \myopt{noanswer} option to \mypkg{randexam} class, +The answers will be hidden in the compiled exam paper. + +\subsection{Randomized variants}\label{opt:random} + +Assume \myfile{exam-a-answer.tex} is an exam paper. +You can get an randomized variant with all questions in the same group shuffled, +by creating an \myfile{exam-b-answer.tex} file with the following lines: + +\begin{code} +\PassOptionsToClass{random}{randexam} +\input{exam-a-answer} +\end{code} + +That is to say, when adding \myopt{random} option to \mypkg{randexam} class, +The questions in the same group will be shuffled in the compiled exam paper. +Furthermore, four choices in an \myenv{abcd} environment will be shuffled too. + +\subsection{Two column exam papers} + +Assume \myfile{exam-a-blank.tex} is the TeX file of an exam paper of A4 size. +You could get an exam paper of A3 size, +by creating a new TeX file with the following lines: + +\begin{code} +\PassOptionsToClass{a3paper}{randexam} +\input{exam-a-blank} +\end{code} + +That is to say, when adding \myopt{a3paper} option to \mypkg{randexam} class, +The result paper will be a two column document in A3 size. + +Assume \myfile{exam-a-blank.pdf} is the PDF file of an exam paper of A4 size. +You could get an exam paper of A3 size, +by creating a new TeX file with the following lines: +\begin{code} + +\documentclass[a3input]{randexam} +\begin{document} +\includepdf[pages=-,nup=2x1]{exam-a-blank} +\end{document} +\end{code} + +That is to say, you can make an exam of A3 size from an exam of A4 size, +even if you have only the PDF file. + +\end{document} |