diff --git a/ouexam.dtx b/ouexam.dtx index 986c255..15ff872 100644 --- a/ouexam.dtx +++ b/ouexam.dtx @@ -36,7 +36,7 @@ % % \fi % -%% \CheckSum{889} +%% \CheckSum{912} %% %% \CharacterTable %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z @@ -111,7 +111,7 @@ % Version 2.0 of \textsf{ouexam} introduced several major changes from earlier % versions. Consequently, documents created using an earlier version of % \textsf{ouexam} are \emph{incompatible} with version 2.0 or later. Versions 2.0 -% and greater of \textsf{ouexam} will detect attempts to process version 1.x +% and greater of \textsf{ouexam} will detect attempts to process a version 1.x % document and display an error message. % % The older version (1.2) is still available and can be downloaded from the same @@ -428,6 +428,9 @@ % depending on how full the last line of the question is. % \end{itemize} % +% \changes{2.3.1}{2013/05/31}{NJS Enforced proper question environment nesting.} +% The various \textsf{question} environments must be correctly nested in order for the features described above to work correctly, i.e., \textsf{question} at the top level, followed by \textsf{subquestion} and \textsf{subsubquestion}. Any variation to this nesting order will cause an error. +% % % \changes{2.2}{2010/04/26}{NJS Added time allocation macros.} % \subsection{Time allocations} @@ -1350,6 +1353,16 @@ % \end{macro} % \end{macro} % +% \begin{macro}{qdepth} +% \changes{2.3.1}{2013/05/31}{NJS New \texttt{qdepth} counter.} +% This counter is incremented every time a \textsf{question}, \textsf{subquestion} or \textsf{subsubquestion} environment is opened, and decremented every time these environments close. It measures the nesting depth of questions, and is used to check that we don't have things like a \texttt{subquestion} that isn't enclosed by a \texttt{question}, or a \texttt{question} nested inside another \texttt{question}. Note that this counter does \emph{not} reset inside any other environment. +% +% \begin{macrocode} +\newcounter{qdepth} +\setcounter{qdepth}{0} +% \end{macrocode} +% \end{macro} +% % At the end of the document, check that the running total of marks for the % examination matches what we were expecting: % @@ -1387,6 +1400,8 @@ % \changes{2.0}{2001/05/15}{NJS Total marks for a question are now printed only % if the question has no sub-questions.} % \begin{environment}{question} +% \changes{2.3.1}{2013/05/31}{NJS Check question depth when opening the +% environment.} % The \textsf{question} environment specifies a top-level question, and produces % questions numbered in the form ``1.'', ``2.'', etc. It has one mandatory % argument, the number of marks allocated to the question, which is used to @@ -1402,6 +1417,15 @@ \else\setcounter{qexpected}{#1}\fi% % \end{macrocode} % +% Check that the environment is being opened at the correct depth. The \textsf{question} environment should normally only be opened at depth 0: +% \begin{macrocode} + \ifnum\theqdepth=0% + \else\ClassError{ouexam}{question environment nested inside another % + question, subquestion or subsubquestion environment}% + \fi% + \addtocounter{qdepth}{1}% +% \end{macrocode} +% % For each top-level question, we increment the |question| counter, which also % resets the |hassubs| and |qrunning| counters to zero: % \begin{macrocode} @@ -1463,6 +1487,12 @@ % \begin{macrocode} \setcounter{lastexpected}{\value{qexpected}}% \end{list}% +% \end{macrocode} +% +% \item |qdepth| is decremented. +% +% \begin{macrocode} + \addtocounter{qdepth}{-1}% } % \end{macrocode} % @@ -1474,6 +1504,8 @@ % redefinition of \textsf{enumerate}.} % \changes{2.0}{2001/05/13}{NJS Added penalty handling to ensure correct placement % of marks in output.} +% \changes{2.3.1}{2013/05/31}{NJS Check question depth when opening the +% environment.} % The \textsf{subquestion} environment is the analogue of \textsf{question} for % sub-questions. On initialisation, it sets |subqexpected| to the value of the % mandatory argument (defaulting to zero if the argument is empty), increments @@ -1490,6 +1522,15 @@ \setcounter{subqexpected}{#1}% \addtocounter{hassubs}{1}% \refstepcounter{subquestion}% +% \end{macrocode} +% The \textsf{subquestion} environment should normally only be opened at depth 1: +% \begin{macrocode} + \ifnum\theqdepth=1% + \else\ClassError{ouexam}{subquestion environment either outside a % + question environment, or nested inside another subquestion or % + subsubquestion environment}% + \fi% + \addtocounter{qdepth}{1}% \begin{list}{\labelsubquestion}{\settowidth{\labelwidth}{(m)}}% \item \ignorespaces% }{% @@ -1530,6 +1571,7 @@ % \begin{macrocode} \setcounter{lastexpected}{\value{subqexpected}}% \end{list}% + \addtocounter{qdepth}{-1}% } % \end{macrocode} % \end{environment} @@ -1539,6 +1581,8 @@ % redefinition of \textsf{enumerate}.} % \changes{2.0}{2001/05/13}{NJS Added penalty handling to ensure correct placement % of marks in output.} +% \changes{2.3.1}{2013/05/31}{NJS Check question depth when opening the +% environment.} % This is similar to both \textsf{question} and \textsf{subquestion}, and % generates an appropriately numbered sub-sub-question (``(i)'', ``(ii)'', etc.). % \begin{macrocode} @@ -1552,6 +1596,15 @@ % \begin{macrocode} \addtocounter{hassubsubs}{1}% \refstepcounter{subsubquestion}% +% \end{macrocode} +% The \textsf{subsubquestion} environment should normally only be opened at depth 2: +% \begin{macrocode} + \ifnum\theqdepth=2% + \else\ClassError{ouexam}{subsubquestion environment either outside a % + subquestion environment, or nested inside another subsubquestion % + environment}% + \fi% + \addtocounter{qdepth}{1}% \begin{list}{\labelsubsubquestion}{\settowidth{\labelwidth}{(viii)}}% \item \ignorespaces% }{% @@ -1573,14 +1626,11 @@ \else marks\fi)% \parfillskip=0pt \finalhyphendemerits=0 \par% \end{list}% + \addtocounter{qdepth}{-1}% } % \end{macrocode} % \end{environment} % -% Note that none of these three environments check whether they are correctly -% nested (i.e., \textsf{subsubquestion} within \textsf{subquestion} within -% \textsf{question}). -% % % \subsection{Draft examination printing} %