Debian Codegraph @

texmf-dist/source/latex/ou-tma/ou-tma.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2025 by G. I. Riley <[email protected]>
4 % ---------------------------------------------------------------------------
5 % This work may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either version 1.3
7 % of this license or (at your option) any later version.
8 % The latest version of this license is in
9 % http://www.latex-project.org/lppl.txt
10 % and version 1.3 or later is part of all distributions of LaTeX
11 % version 2005/12/01 or later.
12 %
13 % This work has the LPPL maintenance status `maintained.'
14 %
15 % The Current Maintainer of this work is Geoff Riley.
16 %
17 % This work consists of the files ou-tma.dtx and ou-tma.ins
18 % and the derived filebase ou-tma.sty.
19 %
20 % \fi
21 %
22 % \iffalse
23 %<*driver>
24 \ProvidesFile{ou-tma.dtx}
25 %</driver>
26 %<package>\NeedsTeXFormat{LaTeX2e}[2023-11-01]
27 %<package>\ProvidesPackage{ou-tma}
28 %<package> [2025-09-30 v1.21 OU-TMA package]
29 %<*driver>
30 \documentclass[a4paper,11pt]{ltxdoc}
31 \usepackage[T1]{fontenc}
32 \usepackage{dtxdescribe}
33 % \OnlyDescription
34 \listfiles
35 \EnableCrossrefs
36 % \DisableCrossrefs
37 \CodelineIndex
38 % \SetupDoc{reportchangedates}
39 \setlength\hfuzz{15pt} % don't show so many
40 \hbadness=7000 % over- and underfull box warnings
41 \usepackage{ou-tma}
42 \geometry{left=1mm,marginparwidth=40mm,marginparsep=1mm}
43 \fancyhf{} % Clear all headers and footers
44 \fancyhead[L]{\textsf{ou-tma}}
45 \fancyhead[R]{\textrm{\thepage}}
46 \RenewDocumentCommand{\headrulewidth}{}{1pt} % Remove header rule
47 \begin{document}
48 \DocInput{ou-tma.dtx}
49 \end{document}
50 %</driver>
51 % \fi
52 % \makeatletter
53 % \GetFileInfo{ou-tma.sty}
54 % \IfPackageLoadedTF{doc}{ ^^A doc
55 % \NewDocElement[
56 % macrolike=false,
57 % toplevel=true,
58 % idxtype=variable,
59 % idxgroup=Variable,
60 % printtype=\textit{Var}
61 % ]{Variable}{variable}
62 % }{^^A not doc
63 % \newcommand*{\DescribeVariable}[2][]{%
64 % \DTXD@filemaXD@filemarginparindex{#1}{#2}{Var}{variable}{usage}%
65 % }
66 % }^^A not doc
67 % \newcommand{\ItemDescribeVariable}[2][]{%
68 % \item[\texttt{#2}:]%
69 % \setlength{\parskip}{1.5ex}%
70 % \DescribeVariable[#1]{#2}%
71 % }
72 %
73 % \makeatother
74 %
75 % \newcommand{\stma}{\textsf{ou-tma}}
76 % \newcommand{\TMA}{\acro{TMA}}
77 % \newcommand{\OU}{\acro{OU}}
78 % \DoNotIndex{\!,\@ifpackageloaded,\ ,\AtBeginDocument,\author,\crefname,\else}
79 % \DoNotIndex{\endinput,\ensuremath,\ExplSyntaxOff,\ExplSyntaxOn,\fancyhead}
80 % \DoNotIndex{\fancyhf,\fi,\frac,\g,\geometry,\headrulewidth,\hspace,\ifthenelse}
81 % \DoNotIndex{\large,\makebox,\mathbb,\mathcal,\mathop,\mathrm,\newcommand}
82 % \DoNotIndex{\newcounter,\NewDocumentCommand,\NewDocumentEnvironment,\newif}
83 % \DoNotIndex{\newtheorem,\numberwithin,\overrightarrow,\PackageWarning}
84 % \DoNotIndex{\par,\parindent,\parskip,\ProcessOptions,\ProvideDocumentCommand}
85 % \DoNotIndex{\refstepcounter,\relax,\renewcommand,\RenewDocumentCommand}
86 % \DoNotIndex{\RequirePackage,\setcounter,\setlength,\space,\sqsubset,\sqsupset}
87 % \DoNotIndex{\setcounter,\textbf,\textrm,\textsuperscript,\tl,\typeout}
88 % \DoNotIndex{\unicode,\vspace,\DeclareMathOperator,\DeclareOption}
89 % \title{The \stma\ Package\thanks{This document
90 % corresponds to \stma\ \fileversion, dated~\filedate.}}
91 % \author{Geoff Riley \\ \href{mailto:[email protected]}{[email protected]}}
92 % \date{\filedate\ (\fileversion)}
93 % \RecordChanges
94 % \renewcommand\code[1]{\mbox{$\ell$-#1}}
95 % \renewcommand\main[1]{\underline{\mbox{$\ell$-#1}}}
96 % \setcounter{IndexColumns}{2}
97 % \setcounter{GlossaryColumns}{2}
98 % \maketitle
99 %
100 % \begin{abstract}
101 % The \stma\ package provides macros and environments to assist in writing Tutor
102 % Marked Assessments (\TMA s) for Open University courses.
103 % \end{abstract}
104 %
105 % \tableofcontents
106 %
107 % \section{Introduction}
108 %
109 % The \stma\ package simplifies the creation of \TMA s by providing an environment
110 % to encompass answers to questions commands to enumerate parts and subparts of those
111 % questions, and a set of macros facilitating mathematical entry based on the styles
112 % used by the Open University (\OU).
113 %
114 % \section{Compiling and installing \stma}
115 %
116 % To compile the \stma\ package:
117 %
118 % \userentry{pdflatex tma.ins}
119 %
120 % To compile the \stma\ documentation:
121 %
122 % \userentry{pdflatex ou-tma.dtx}
123 % \fqquad(several times)
124 % \userentry{makeindex -s gglo.ist -o ou-tma.gls ou-tma.glo}
125 % \userentry{makeindex -s gind.ist ou-tma}
126 % \userentry{pdflatex ou-tma.dtx}
127 % \fqquad(several times)
128 %
129 % The file \filenm{ou-tma.sty} should be placed in an appropriate location within the \TeX\
130 % directory structure. For example in a directory such as \filenm{tex/latex/tma}.
131 %
132 % \section{Usage}
133 %
134 % To use the \stma\ package, in its most basic form, it should be included in the preamble
135 % of your \LaTeX\ document:
136 % \begin{quote}
137 % \cs{documentclass}|[a4paper,11pt]{article}|\\
138 % \cs{usepackage}|{ou-tma}|\\
139 % \vdots\\
140 % \cs{begin}|{document}|\\
141 % \vdots\\
142 % \cs{end}|{document}|
143 % \end{quote}
144 %
145 % \subsection{Options}
146 %
147 % A number of options are available to modify the results of using the \stma\ package. These should be included within the \cs{usepackage} declaration:
148 % \begin{quote}
149 % |\usepackage|\oarg{option,\dots}|{ou-tma}|
150 % \end{quote}
151 % The following options are available:
152 % \begin{description}
153 % \ItemDescribeOption{alph} (default) question numbering as 1(b)(iii);
154 % \ItemDescribeOption{roman} varies question numbering to sequence used by M381 i.e. 1(ii)(c);
155 % \ItemDescribeOption{cleveref} question numbering creates automatic referencing for use with cleveref package;
156 % \ItemDescribeOption{pdfbookmark} add PDF bookmarks for each question using hyperref package; and
157 % \ItemDescribeOption{legacy} enables old definitions of |\vec| and |\C| for backward compatibility.
158 % \end{description}
159 %
160 % \subsection{Macros and environments}
161 %
162 % The \stma\ package provides several valuable macros and environments, most are documented here.
163 %
164 % \subsubsection{Document level commands}
165 %
166 % The document-level commands are intended for use within the document's preamble. They generally affect what appears on the title page and the headers/footers.
167 %
168 % The most essential part of an assignment is to identify who it has been written by and what it has been written for. To this end, the \DescribeMacro{\myname}\cs{myname} macro is used to specify your name: this should be your name as recorded with the University. As names are not unique, the \OU\ allocates a Personal Identification Number (or PIN) as a unique identifier for each student; this should be declared with the \DescribeMacro{\mypin}\cs{mypin} macro. It is formed by a letter, followed by seven digits---or six digits and a letter \texttt{X}. This is distinct from the \acro{OUCU}, or \OU\ Computer User identifier that is used to log in to the \OU\ website.
169 % Once the personal identification has been done, the module being worked needs to be declared, the course code of your module should be given with the \DescribeMacro{\mycourse}\cs{mycourse} macro and the number of the assignment using the \DescribeMacro{\mytma}\cs{mytma} macro. Note that this is just the assignment number; there is no need to include the characters |TMA|.
170 % The final document level command is used if you wish to set a specific date that will be displayed on the compiled document title page; you may use \DescribeMacro{\setdate}\cs{setdate}. This will override the default of using the compile date.
171 %
172 % Example:
173 % \begin{verbatim}
174 % \myname{Anthony Neil Other}
175 % \mypin{A1234567}
176 % \mycourse{M101} % The original Maths introduction module
177 % \mytma{02} % TMA02
178 % \setdate{March 2025}
179 % \end{verbatim}
180 %
181 % \subsubsection{Question environment commands}
182 %
183 % These commands are the ones that, though few, comprise the bulk of the body of the \TMA\ answer content of a paper.
184 %
185 % Within a \TMA, each answer should be placeed in a \DescribeEnv{question}\env{question} environment. The question number is printed across the margin, preceded by the question string which defaults to `Q' but may be redefined by use of the command \DescribeMacro{\setquestionstring}\cs{setquestionstrimg}\marg{required question number introduction}. The question number itself is automatically incremented unless one is specified in the optional parameter. Since the question is presented as an environment, it may be convenient to place each question in a separate file to be included in the main paper.
186 %
187 % Often questions are comprised of multiple parts, therefore, \DescribeMacro{\qpart}\cs{qpart} indicates the start of a question part. It will set the part identifier within the left-hand margin space. Normally, the parts are lettered as |a|, |b|, |c|\dots unless the option \optn{roman} has been given to the \stma\ package when the parts are numbered as |i|, |ii|, |iii|\dots
188 % As with the actual questions, this is an auto-incrementing value unless an optional value is given.
189 % Note that the value should be numerical even if the parts are lettered or in Roman numerals. Each new question restarts the numbering at $1$, which will be rendered as |a| or |i| as dictated by the options in effect.
190 %
191 % There are occasions that the parts of questions may be further divided into sub-parts; these may be declared using the \DescribeMacro{\qsubpart}\cs{qsubpart} macro. As with \cs{qpart}, this is set in the left margin and automatically incremented: an option to choose the sub-part number is also available. If a \cs{qsubpart} immediately follows a \cs{qpart}, both marginal markers will be set on the same line.
192 %
193 % Note that \env{question} is an environment to be used with the \cs{begin}\thinbrspace\dots\cs{end} structure, \cs{qpart} and \cs{qsubpart} are both macros that lay down titles in the margin and are designed to be used on a line on their own.
194 %
195 % Example:
196 % \begin{quote}
197 % |\begin{question}|\oarg{question number}\\
198 % \vdots\\
199 % |\qpart|\oarg{part number}\\
200 % \vdots\\
201 % |\qsubpart|\oarg{sub-part number}\\
202 % \vdots\\
203 % |\end{question}|
204 % \end{quote}
205 %
206 % \subsubsection{Mathematical symbology}
207 %
208 % Various mathematical symbols and elements are defined for convenience, working from the normal suggested formats used within Open University courses. These are mostly as proscribed by the various standards bodies too, for reference see ``Quantities and units - Part 2: Mathematics'' ISO 80000‑2:2019\footnote{Available from British Standards Online as BS EN ISO-2:2019 (ISBN 978 0 539 23108 3), The European Standards Agency and The International Standard Organisetion. All are purchasable publications.}
209 %
210 % These commands are created in such a manner that they will work correctly in both text and maths modes.
211 %
212 % \begin{description}
213 % \item[Differential operators] \DescribeMacro{\dd}\DescribeMacro{\e}\DescribeMacro{\ii}The general advise for most \OU\ modules is to use an upright letter `d' when specifying differential variables, thus \cs{dd} is provided to allow simple accomodation of this. Similarly, Euler's number and the imaginary unit representation of $\sqrt{-1}$ are both usually given upright letters of `e', (\cs{e}), and `i', (\cs{ii}), respectively.
214 %
215 %\emph{Remember that it is always the exception that proves the rule: follow the the module guidebook for the course being completed.}
216 % \begin{dtxexample}*{Differential}
217 % In display mode, compare \dd\ with $d$:
218 % \[
219 % \frac{\dd^2 y}{\dd x^2} + x\frac{\dd y}{\dd x} + y = 2\sin(x)\\
220 % \]
221 % and in line mode $\e^{\ii x} = \cos(x) + \ii\sin(x)$
222 % \end{dtxexample}
223 %
224 % \item[Number sets] Standard `black-board' fonts are used to indicate a number of frequently designated groups of numbers.
225 %
226 % \begin{description}
227 % \ItemDescribeMacro{\N} \N\ represents all natural numbers;
228 % \ItemDescribeMacro{\Z} \Z\ represents all integers;
229 % \ItemDescribeMacro{\Q} \Q\ represents all rational numbers;
230 % \ItemDescribeMacro{\R} \R\ represents all real numbers; and
231 % \ItemDescribeMacro{\Complex} \Complex\ represents all complex numbers.
232 % \end{description}
233 %
234 % \begin{dtxexample}*{Number sets}
235 % The relationship between number sets:
236 % \begin{itemize}
237 % \item \N\ (Natural numbers) $\subseteq \Z$ (Integers);
238 % every natural number is also an integer.
239 % \item \Z\ (Integers) $\subseteq \Q$ (Rational numbers);
240 % every integer is also a rational number.
241 % \item \Q\ (Rational numbers) $\subseteq \R$ (Real
242 % numbers); every rational number is also a real
243 % number.
244 % \item \Complex\ (Complex numbers) $\supseteq \R$ (Real
245 % number); complex numbers include real numbers as
246 % a subset, since they can be represented by
247 % $a+\ii b$ where $a$ and $b$ are real numbers.
248 % \end{itemize}
249 % \end{dtxexample}
250 %
251 % \item[Vector notation] \DescribeMacro{\vect}\DescribeMacro{\ve}Two different vector representations are typically used on \OU\ modules, there is the two, or more, letter with an over arrow version given with \cs{vect}; and the emboldened upright letter version \cs{ve}---the latter is commonly handwritten as an underlined letter.
252 %
253 % \begin{dtxexample}*{Vectors}
254 % Given a point $A$ at the co-ordinate $(6, 3)$ and a
255 % point $B$ at the co-ordinate $(-4, 8)$, the vector
256 % $\vect{AB}$ has a gradient of $\frac{8-3}{-4-6} =
257 % \frac{5}{-10} = -\frac{1}{2}$
258 % The standard unit vectors are \ve{i} and \ve{j}.
259 % They are usually at right angles to each other.
260 %\end{dtxexample}
261 %
262 % \item[Ordinal indicators] \DescribeMacro{\st}\DescribeMacro{\nd}\DescribeMacro{\rd}\DescribeMacro{\nth}The use of ordinal indicators is not specific to \OU\ modules, but frequently is a useful element that is just inconvenient to produce.
263 %
264 % So the standard four English ordinals are provided \cs{st}, \cs{nd}, \cs{rd}, and \cs{nth}, e.g. 1\st, 2\nd, 3\rd, and 4\nth.
265 %
266 % Note that the last ordinal is \cs{nth} not \cs{th}, the latter produces a thorn character, \th, and that only works if you have other than the default 7-bit font encoding (\acro{OT1}).
267 %
268 % \item[Combinatoral notations] There are two combinatoral forms that are commonly used in \OU\ modules, the combination selecting $r$ out of a total of $n$ items where order does not matter, and the permutations of $r$ out of $n$ items were order matters.
269 % \begin{description}
270 % \ItemDescribeMacro{\comb}\marg{n}\marg{r}. This is equivelent to \[
271 % \comb{n}{r} = \frac{n!}{r!(n-r)!}
272 % \]
273 % \ItemDescribeMacro{\perm}\marg{n}\marg{r}. This is equivalent to \[
274 % \perm{n}{r} = \frac{n!}{(n-r)!}
275 % \]
276 % \end{description}
277 %
278 % \item[Mathematical operators] Additional mathematical operators are defined, again for convenience of entry.
279 % \begin{description}
280 % \ItemDescribeMacro{\re} $\mapsto \re$
281 % \ItemDescribeMacro{\im} $\mapsto \im$
282 % \ItemDescribeMacro{\Log} $\mapsto \Log$
283 % \ItemDescribeMacro{\Arg} $\mapsto \Arg$
284 % \ItemDescribeMacro{\Wnd} $\mapsto \Wnd$
285 % \ItemDescribeMacro{\Res} $\mapsto \Res$
286 % \ItemDescribeMacro{\Ker} $\mapsto \Ker$
287 % \ItemDescribeMacro{\Orb} $\mapsto \Orb$
288 % \ItemDescribeMacro{\Stab} $\mapsto \Stab$
289 % \ItemDescribeMacro{\Fix} $\mapsto \Fix$
290 % \end{description}
291 %
292 % \item[Derivatives] There are three derivative forms defined specifically for speeding calculas entry and accuracy. One used the $\dd x$ form and two use the partial, $\partial x$, form.
293 %
294 % \begin{description}
295 % \ItemDescribeMacro{\deriv}\marg{y}\marg{x} $\mapsto \deriv{y}{x}$
296 % \ItemDescribeMacro{\pderiv}\marg{y}\marg{x} $\mapsto \pderiv{y}{x}$
297 % \ItemDescribeMacro{\psderiv}\marg{y}\marg{x}\marg{z} $\mapsto \psderiv{y}{x}{z}$
298 % \end{description}
299 %
300 % \item[Additional symbols] \DescribeMacro{\rect}\cs{rect}, \rect, is defined particularly for the use of \acro{M208} people although others may find it useful.
301 %
302 % \item[Legacy elements] There are a couple of macros which become enabled when using the \optn{legacy} option. These are now deprecated and may be removed from a future version. There are name clashes with standard \LaTeX\ commands, so please be aware of this if used.
303 % \begin{description}
304 % \ItemDescribeMacro{\C} is the original version of \cs{Complex}
305 % \ItemDescribeMacro{\vec} is the original version of \cs{vect}
306 % \end{description}
307 %
308 % \end{description}
309 %
310 % \MaybeStop{}
311 %
312 % \section{Implementation}
313 %
314 % \begin{macrocode}
315 %% ou-tma.sty
316 %% Copyright 2025 G. I. Riley <[email protected]>
317 %
318 % This work may be distributed and/or modified under the
319 % conditions of the LaTeX Project Public License, either version 1.3
320 % of this license or (at your option) any later version.
321 % The latest version of this license is in
322 % http://www.latex-project.org/lppl.txt
323 % and version 1.3 or later is part of all distributions of LaTeX
324 % version 2005-12-01 or later.
325 %
326 % This work has the LPPL maintenance status `maintained.'
327 %
328 % The Current Maintainer of this work is Geoff Riley.
329 %
330 %% This package may be freely used, especially by, but not limited to,
331 %% students, lecturers and staff of the Open University. It was created
332 %% by the efforts of many who are now or have been connected with the
333 %% Open University Students Association. No acknowledgement is
334 %% _required_ for using this package within the production of a _Tutor
335 %% Marked Assessment._
336 % \end{macrocode}
337 %
338 % Adapted by Peter McFarlane from various sources.
339 % All errors of style or content are mine or subsequent contributors.
340 % Acknowledgements to Bob Margolis and Rob Lynas (from whom some macros
341 % are plagiarised).
342 % Further contributions from Steve Mayer and Tim Dale.
343 % Annotations, in part, and further modification by Geoff Riley.
344 %
345 %
346 % Package Options
347 % \begin{itemize}
348 % \item[\cs{[alph]}] (default) question numbering as 1(b)(iii)
349 % \item[\cs{[roman]}] varies question numbering to sequence used by M381
350 % i.e. 1(ii)(c)
351 % \item[\cs{[cleveref]}] question numbering creates automatic referencing for
352 % use with cleveref package
353 % \item[\cs{[pdfbookmark]}] add PDF bookmarks for each question using hyperref package
354 % \item[\cs{[legacy]}] enables old definitions of |\vec| and |\C| for backward
355 % compatibility
356 % \end{itemize}
357 %
358 % To use a package option, place the option(s) before the package name:\\\nopagebreak
359 % \fqquad\cs{usepackage}|[roman,cleveref]{ou-tma}|
360 %
361 % \changes{v1.21}{2025-09-30}{
362 % Documentation error spotted and corrected in very first example. A couple of
363 % other occurances also corrected in less conspicuous places.}
364 % \changes{v1.20}{2025-04-07}{
365 % Package name changed from `tma' to `ou-tma' to become a
366 % little more descriptive and to abide by the minimum package
367 % name length suggested by CTAN.}
368 % \changes{v1.19}{2025-02-18}{
369 % PDF metadata (apparently) was solved with help from Steve Mayers; all down
370 % to the use of commands as string containers. New (\LaTeX3) commands
371 % are robust and fail to expand within the context of the metadata and
372 % bookmarks; old (\LaTeX2e) commands are fragile and correctly expanded. I
373 % have a mix of old commands and new variables now.}
374 % \changes{v1.18}{2025-02-16}{
375 % PDF metadata doesn't set correctly so I have removed it: the cause is an
376 % incompatibility between \LaTeX\ unicode and the PDF restricted character
377 % allowance.}
378 % \changes{v1.17}{2025-02-13}{
379 % Rewritten with \LaTeX3\ syntax from the `xparse' package to make commands
380 % less fragile.
381 % Finally, I got the alignment of part and subpart numbering to line up correctly.}
382 % \changes{v1.16}{2024-11-22}{
383 % Added File Properties to pdf files using the hyperref setup system when
384 % in pdfbookmark mode.}
385 % \changes{v1.15}{2024-11-21}{
386 % Define \cs{setdate} and \cs{thedate} to allow the header date to be used within
387 % the document, eg header and footer.}
388 % \changes{v1.14}{2024-11-17}{
389 % Allow replacement of Question marker tag using \cs{setquestionstring}.
390 % References with cleveref not working.
391 % Replaced my attempts at keeping \cs{qpart} and \cs{qsubpart} on the same line with
392 % Steve Mayers contribution.}
393 % \changes{v1.13}{2024-11-16}{
394 % Arranged for \cs{qsubpart} to go on the same line as the \cs{qpart} when
395 % there is no intervening text
396 % \cs{qsubpart} indents further than \cs{qpart}.}
397 % \changes{v1.12}{2024-11-08}{
398 % Standardized package name to 'tma' to make it compatible with CTAN.
399 % Avoided redefining standard \LaTeX\ commands.
400 % Consolidated geometry settings.
401 % Adjusted loading order of packages.
402 % Improved code readability and comments.
403 % Added 'legacy' option to allow old definitions of \cs{vec} and \cs{C}.}
404 %
405 % Before getting into the main package, it is necessary to ensure that the \LaTeX3\ extensions are loaded. Most modern versions of the \LaTeX\ core have this rolled in as standard, but as a belt and braces approach, inclusion here does no harm.
406 % \begin{macrocode}
407 \RequirePackage{expl3} % LaTeX3 "experimental"
408 % \end{macrocode}
409 %
410 % \subsection{Package Initialisation}
411 %
412 % We are starting off using the \cs{ExplSyntaxOn} command to enable the \LaTeX3\ extensions before declaring a set of `constants' that will be used by our package. Working with the established conventions the constants are declared as variables are named to reflect their ownership and function. These are all declared as `token lists' so that they may, effectively, hold string elements.
413 % \begingroup
414 % \catcode`_=11 % Make the underscore character a letter!
415 % \begin{description}
416 % \ItemDescribeVariable{g_tma_constant_name} holds the students personal name
417 % \ItemDescribeVariable{g_tma_constant_tma} holds the number of the \TMA\ being answered
418 % \ItemDescribeVariable{g_tma_constant_course} holds the \OU\ course code for the module being studied
419 % \ItemDescribeVariable{g_tma_constant_pin} holds the students personal identification number
420 % \ItemDescribeVariable{g_tma_constant_thedate} holds the date to be printed on the front page of the \TMA
421 % \end{description}
422 % \endgroup
423 % \begin{macrocode}
424 % %%%%%%%%%%%%%%%%%%%%%%%%%
425 %% Package Initialization
426 % %%%%%%%%%%%%%%%%%%%%%%%%%
427 \ExplSyntaxOn
428 \tl_new:N \g_tma_constant_name
429 \tl_new:N \g_tma_constant_tma
430 \tl_new:N \g_tma_constant_course
431 \tl_new:N \g_tma_constant_pin
432 \tl_new:N \g_tma_constant_thedate
433 % \end{macrocode}
434 % These `constants' are given initial generic values.
435 % \begin{macrocode}
436 \tl_gset:Nn \g_tma_constant_name {name}
437 \tl_gset:Nn \g_tma_constant_tma {tma}
438 \tl_gset:Nn \g_tma_constant_course {course}
439 \tl_gset:Nn \g_tma_constant_pin {pin}
440 \tl_gset:Nn \g_tma_constant_thedate {the~date}
441 % \end{macrocode}
442 % Then commands are provided to retrieve the values when required.
443 % \begin{description}
444 % \ItemDescribeMacro{\name} returns the students name
445 % \ItemDescribeMacro{\tma} returns the working \TMA\ number
446 % \ItemDescribeMacro{\course} returns the \OU\ course reference
447 % \ItemDescribeMacro{\pin} returns the students personal identification number
448 % \ItemDescribeMacro{\thedate} returns the date to be printed on the title page of the \TMA
449 % \end{description}
450 % \begin{macrocode}
451 \newcommand{\name}{\g_tma_constant_name}
452 \newcommand{\tma}{\g_tma_constant_tma}
453 \newcommand{\course}{\g_tma_constant_course}
454 \newcommand{\pin}{\g_tma_constant_pin}
455 \newcommand{\thedate}{\g_tma_constant_thedate}
456 % \end{macrocode}
457 % Finally, macros are provided to set the values of the `constants': these should only be used within the preamble. Use within the body of the text is unpredicable.
458 % \begin{description}
459 % \ItemDescribeMacro{\myname}\marg{name} Set the students name
460 % \ItemDescribeMacro{\mytma}\marg{\TMA\ number} Set the \TMA\ number
461 % \ItemDescribeMacro{\mycourse}\marg{course code} Set the \OU\ course code for the module
462 % \ItemDescribeMacro{\mypin}\marg{pin} Set the students personal identification number
463 % \ItemDescribeMacro{\setdate}\marg{the date} Set the required date to display on the title page, default is the date of report generation
464 % \end{description}
465 % \begin{macrocode}
466 \NewDocumentCommand{\myname}{m}{%
467 \tl_gset:Nn \g_tma_constant_name{#1}}
468 \NewDocumentCommand{\mytma}{m}{%
469 \tl_gset:Nn \g_tma_constant_tma{#1}}
470 \NewDocumentCommand{\mycourse}{m}{%
471 \tl_gset:Nn \g_tma_constant_course{#1}}
472 \NewDocumentCommand{\mypin}{m}{%
473 \tl_gset:Nn \g_tma_constant_pin{#1}}
474 \NewDocumentCommand{\setdate}{m}{%
475 \date{#1}\tl_gset:Nn \g_tma_constant_thedate{#1}}
476 % \end{macrocode}
477 % That's the end of the \LaTeX3\ extensions requiring the extension switch, so it can be turned off.
478 % \begin{macrocode}
479 \ExplSyntaxOff
480 % \end{macrocode}
481 % Set the \cs{title} and \cs{author} ready for use by the \cs{maketitle} macro at the start of the main document. They use the constants defined above so that changes are automatically reflected. They may be redefined by the user if required.
482 % \begin{macrocode}
483 \title{\textbf{TMA: \course-\tma}}
484 \author{\textbf{\name\space\pin}}
485 % \end{macrocode}
486 % In order to allow the question introduction string to be modified, a general \LaTeX\ string is created along with a macro to set it.
487 % \begin{description}
488 % \ItemDescribeMacro{\tma@questionstring} Hold the string to be printed before the question number, the default is `Q'.
489 % \ItemDescribeMacro{\setquestionstring}\marg{string} Set the string to precede the question number
490 % \end{description}
491 % \begin{macrocode}
492 \NewDocumentCommand{\tma@questionstring}{}{\relax}
493 \NewDocumentCommand{\setquestionstring}{m}{%
494 \RenewDocumentCommand{\tma@questionstring}{}{#1}}
495 % \end{macrocode}
496 % Set the default date to `today'.
497 % \begin{macrocode}
498 \setdate{\today}
499 % \end{macrocode}
500 %
501 % \subsection{Package Loading}
502 %
503 % Here we load the useful packages that have proven their worth for \OU\ students over the years. Many have properties that are utilised by the rest of the \stma\ package.
504 % \begin{macrocode}
505 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
506 %% Package Loading
507 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
508
509 \RequirePackage{amsmath}
510 \RequirePackage{amssymb}
511 \RequirePackage{amsthm}
512 \RequirePackage{wasysym}
513 \RequirePackage{bm}
514 \RequirePackage{upgreek}
515 \RequirePackage{graphicx}
516 \RequirePackage{lastpage}
517 \RequirePackage{xifthen}
518 \RequirePackage{verbatim}
519 \RequirePackage{fancyhdr}
520 \RequirePackage{geometry}
521 \RequirePackage{calc}
522 \RequirePackage[UKenglish]{isodate} % use UK format for date
523 \cleanlookdateon % remove th,st, rd from date
524
525 % \end{macrocode}
526 %
527 % \subsection{Geometry Settings}
528 %
529 % An important part of \TMA\ answering is providing a consistent output, to this end the following page geometry has been brought together as a compromise suitable for most modules.
530 % \begin{macrocode}
531 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
532 %% Geometry Settings
533 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
534
535 \geometry{
536 headheight=10mm,
537 headsep=5mm,
538 bottom=25mm,
539 footskip=15mm,
540 left=30mm,
541 right=30mm,
542 marginparwidth=0mm,
543 marginparsep=0mm,
544 includemp
545 }
546 % \end{macrocode}
547 %
548 % \subsection{Margin Notes}
549 %
550 % By default, no margin notes are assumed to be required, however, if one is wanted, the \DescribeMacro{\marginnotes}\cs{marginnotes} command will set up the side margin ready to accept notes using the \DescribeMacro{\marginnote}\cs{marginnote}\marg{note} command.
551 %
552 % \begin{macrocode}
553 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
554 %% Margin Notes
555 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
556
557 \NewDocumentCommand{\marginnote}{m}{\marginpar{#1}}
558 \NewDocumentCommand{\marginnotes}{}{
559 \geometry{
560 marginparwidth=40mm,
561 marginparsep=5mm,
562 left=20mm,
563 right=15mm
564 }
565 }
566 % \end{macrocode}
567 %
568 % \subsection{Question Numbering}
569 %
570 % We set up three counters to keep track of the question number along with associated parts and subparts.
571 % \begin{description}
572 % \ItemDescribeCounter{question} Holds the current question number, when a new question is started this value is used unless one is provided, in either case the used value is incremented as saved back here. When used, the \cs{qpart} is automatically reset so that the first part will be part 1.
573 % \ItemDescribeCounter{qpart} Holds the current part number as a numeric value, as with the question number this may be overridden and is incremented after being used. When used, the \cs{qsubpart} is automatically reset so that the first subpart will be sub-part 1.
574 % \ItemDescribeCounter{qsubpart} Holds the current sub-part number as a numeric value, again, the value may be overridden and is incremented after being used.
575 % \end{description}
576 % \begin{macrocode}
577 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
578 %% Question Numbering
579 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
580
581 \newcounter{question}
582 \newcounter{qpart}[question]
583 \newcounter{qsubpart}[qpart]
584 % \end{macrocode}
585 % The question number is set to print as arabic digits,
586 % \begin{macrocode}
587 \renewcommand{\thequestion}{\arabic{question}}
588 % \end{macrocode}
589 %
590 % \subsection{Option Handling}
591 %
592 % In order to handle the incoming options for the \stma\ package, we create a set of four new boolean tokens.
593 % \begin{description}
594 % \ItemDescribeBoolean{tma@roman} False indicates `alph' numbering, true indicates `roman' numbering of parts and subpart.
595 % \ItemDescribeBoolean{tma@usecleveref} True indicates that the \pkg{cleveref} package is requested.
596 % \ItemDescribeBoolean{tma@usepdfbookmark} True indicated that the \pkg{pdfbookmark} package is requested.
597 % \ItemDescribeBoolean{tma@legacy} True indicted that the commands \cs{Complex} and \cs{vect} will be redefined to the legacy commands \cs{C} and \cs{vec}.
598 % \end{description}
599 %
600 % \begin{macrocode}
601 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
602 %% Option Handling
603 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
604 % Define boolean flags
605 \newif\iftma@roman
606 \newif\iftma@usecleveref
607 \newif\iftma@usepdfbookmark
608 \newif\iftma@legacy
609
610 % Set default options
611 \tma@romanfalse % Default numbering is `alph'
612 \tma@useclevereffalse % Default is not to use cleveref
613 \tma@usepdfbookmarkfalse % Default is not to use pdfbookmark
614 \tma@legacyfalse % Default is not to use legacy definitions
615 % \end{macrocode}
616 %
617 % We now set up the default states and commands for the \stma\ package operation.
618 % \begin{description}
619 % \ItemDescribeMacro{\theqpart} returns the current question part number as either an alpha or roman index.
620 % \ItemDescribeMacro{\theqsubpart} returns the current question subpart number as either a roman or an alpha index.
621 % \ItemDescribeMacro{\tma@crefname}\marg{label type}\marg{singular name}\marg{plural name} Declares a label with singular and plural spellings for the \pkg{cleveref} package.
622 % \ItemDescribeMacro{\tma@stepcounter}\marg{counter name} Increments the named counter by one.
623 % \ItemDescribeMacro{\tma@bookmark}\oarg{level}\marg{text}\marg{name} The level is optional, numerical, the default is zero, the top level. The text is what will appear in the bookmark panel, and the name is what may be used as a reference to the location from other parts of the document.
624 % \ItemDescribeMacro{\tma@pageref}\marg{name} returns the page number, if known, that contains the bookmark with the label name.
625 % \end{description}
626 %
627 % \begin{macrocode}
628 % Define commands with default values
629 \renewcommand{\theqpart}{\alph{qpart}}
630 \renewcommand{\theqsubpart}{\roman{qsubpart}}
631 \NewDocumentCommand{\tma@crefname}{mmm}{\relax}
632 \NewDocumentCommand{\tma@stepcounter}{m}{\stepcounter{#1}}
633 \NewDocumentCommand{\tma@bookmark}{O{0}mm}{\relax}
634 \NewDocumentCommand{\tma@pageref}{m}{\pageref{#1}}
635 % \end{macrocode}
636 %
637 % Declare each of the valid options for the option processing system. In each case, the action is to set the appropriate boolean to true or false.
638 %
639 % \begin{macrocode}
640 % Declare options
641 \DeclareOption{roman}{%
642 \tma@romantrue%
643 }
644 \DeclareOption{alph}{%
645 \tma@romanfalse%
646 }
647 \DeclareOption{cleveref}{%
648 \tma@useclevereftrue%
649 }
650 \DeclareOption{pdfbookmark}{%
651 \tma@usepdfbookmarktrue%
652 }
653 \DeclareOption{legacy}{%
654 \tma@legacytrue%
655 }
656 \DeclareOption*{%
657 \PackageWarning{ou-tma}{Unknown option `\CurrentOption'}%
658 }
659 % \end{macrocode}
660 % Go ahead, process those options!
661 % \begin{macrocode}
662 % Process options
663 \ProcessOptions\relax
664 % \end{macrocode}
665 %
666 % \subsection{Debugging Options}
667 %
668 % A short section of code outputting to the log the state of the four main options that may be passed to the \stma\ package.
669 %
670 % \begin{macrocode}
671 \typeout{**************** OPTION RESULTS **********}
672 \iftma@usepdfbookmark
673 \typeout{pdfbookmark is TRUE}
674 \else
675 \typeout{pdfbookmark is FALSE}
676 \fi
677 \iftma@roman
678 \typeout{roman is TRUE}
679 \else
680 \typeout{roman is FALSE}
681 \fi
682 \iftma@usecleveref
683 \typeout{cleveref is TRUE}
684 \else
685 \typeout{cleveref is FALSE}
686 \fi
687 \iftma@legacy
688 \typeout{legacy is TRUE}
689 \else
690 \typeout{legacy is FALSE}
691 \fi
692 \typeout{************* END OPTION RESULTS **********}
693 % \end{macrocode}
694 %
695 % \subsection{Package adjustments based on Options}
696 % \begin{macrocode}
697 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
698 %% Set Up Package Based on Options
699 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
700
701 % Set question numbering
702 \iftma@roman
703 \renewcommand{\theqpart}{\roman{qpart}}
704 \renewcommand{\theqsubpart}{\alph{qsubpart}}
705 \else
706 \renewcommand{\theqpart}{\alph{qpart}}
707 \renewcommand{\theqsubpart}{\roman{qsubpart}}
708 \fi
709 % Load hyperref if necessary
710 \iftma@usepdfbookmark
711 \AtBeginDocument{%
712 \hypersetup{%
713 colorlinks=true,%
714 linkcolor=blue,%
715 urlcolor=blue,%
716 pdfstartview=FitH,%
717 pdftitle={TMA~\tma}, %
718 pdfauthor={\name~—~\pin}, %
719 pdfkeywords={OUCU:~\pin, TMA~\tma}, %
720 pdfsubject=\course%
721 }%
722 }
723 \RequirePackage[pdfencoding=unicode,psdextra]{hyperref}
724 \fi
725
726 % Load cleveref if necessary
727 \iftma@usecleveref
728 % Ensure hyperref is loaded before cleveref
729 \@ifpackageloaded{hyperref}%
730 {}%
731 {\RequirePackage[pdfencoding=unicode,psdextra]{hyperref}}
732 \RequirePackage{cleveref}
733 % Redefine commands for cleveref
734 \RenewDocumentCommand{\tma@crefname}{mmm}{\crefname{#1}{#2}{#3}}
735 \RenewDocumentCommand{\tma@stepcounter}{m}{\refstepcounter{#1}}
736 \fi
737
738 % Redefine commands for pdfbookmark
739 \iftma@usepdfbookmark
740 \RenewDocumentCommand{\tma@pageref}{m}{\pageref*{#1}}
741 \RenewDocumentCommand{\tma@bookmark}{O{0} +m +m}{%
742 \pdfbookmark[#1]{#2}{#3}%
743 }
744 \fi
745
746 \setquestionstring{Q}
747
748 % \end{macrocode}
749 %
750 % \subsection{Question Environment}
751 % \begin{macrocode}
752 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
753 %% Question Environment
754 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
755
756 % Set up cref names if cleveref is used
757 \iftma@usecleveref
758 \tma@crefname{question}{question}{questions}
759 \tma@crefname{qpart}{part}{parts}
760 \tma@crefname{qsubpart}{section}{sections}
761 \fi
762
763 \NewDocumentEnvironment{question}{O{0}}{%
764 \ifthenelse{#1>0}{\setcounter{question}{#1-1}}{\relax}%
765 \tma@stepcounter{question}%
766 \tma@bookmark{Question \thequestion}%
767 {question\thequestion}%
768 \makebox[0em][r]{\large{\tma@questionstring~\thequestion%
769 \hspace{0.3em}}}\par%
770 }{%
771 \par \vspace{3em}%
772 }
773
774 \NewDocumentCommand{\qpart}{O{0}}{%
775 \ifthenelse{#1>0}{\setcounter{qpart}{#1-1}}{\relax}%
776 \tma@stepcounter{qpart}%
777 \tma@bookmark[1]{\thequestion.\theqpart}%
778 {qpart.\thequestion.\theqpart}%
779 \par%
780 \makebox[0pt][r]{\large{(\theqpart)\hspace{1.5em} }}%
781 }
782
783 \NewDocumentCommand{\qsubpart}{O{0}}{%
784 \ifthenelse{#1>0}{\setcounter{qsubpart}{#1-1}}{\relax}%
785 \tma@stepcounter{qsubpart}%
786 \tma@bookmark[2]{\thequestion.\theqpart.\theqsubpart}%
787 {qsubpart.\thequestion.\theqpart.\theqsubpart}%
788 \ifthenelse{\value{qsubpart}>1}%
789 {\par}{}%
790 \hspace{-2em}\makebox[2em][l]{\large{(\theqsubpart)}}%
791 }
792
793 % \end{macrocode}
794 %
795 % \subsection{Mathematical commands}
796 % \begin{macrocode}
797 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
798 %% Mathematical Commands
799 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
800
801 %% Differential Operators
802 \NewDocumentCommand{\dd}{}{\ensuremath{\mathop{}\!\mathrm{d}}}
803 \NewDocumentCommand{\e}{}{\ensuremath{\mathrm{e}}}
804 \NewDocumentCommand{\ii}{}{\ensuremath{\mathrm{i}}}
805
806 %% Number Sets
807 \NewDocumentCommand{\N}{}{\ensuremath{\mathbb{N}}}
808 \NewDocumentCommand{\Z}{}{\ensuremath{\mathbb{Z}}}
809 \NewDocumentCommand{\Q}{}{\ensuremath{\mathbb{Q}}}
810 \NewDocumentCommand{\R}{}{\ensuremath{\mathbb{R}}}
811 \NewDocumentCommand{\Complex}{}{%
812 \ensuremath{\mathbb{C}}} % Changed from \C to \Complex
813 \NewDocumentCommand{\Rr}{}{\ensuremath{\mathcal{R}}}
814
815 %% Vector Notation
816 \NewDocumentCommand{\vect}{m}{%
817 \ensuremath{\overrightarrow{#1}}} % Changed from \vec to \vect
818 \NewDocumentCommand{\ve}{m}{\ensuremath{\textbf{#1}}}
819
820 %% Ordinal Indicators
821 \NewDocumentCommand{\st}{}{\textsuperscript{st}}
822 \NewDocumentCommand{\nd}{}{\textsuperscript{nd}}
823 \NewDocumentCommand{\rd}{}{\textsuperscript{rd}}
824 \NewDocumentCommand{\nth}{}{\textsuperscript{th}}
825
826 %% Additional Symbols
827 \NewDocumentCommand{\rect}{}{\ensuremath{\sqsubset\!\!\sqsupset}}
828
829 %% Combinatorial Notations
830 \NewDocumentCommand{\comb}{mm}{\ensuremath{{}^{#1}C_{#2}}}
831 \NewDocumentCommand{\perm}{mm}{\ensuremath{{}^{#1}P_{#2}}}
832
833 %% Mathematical Operators
834 \DeclareMathOperator{\re}{Re}
835 \DeclareMathOperator{\im}{Im}
836 \DeclareMathOperator{\Log}{Log}
837 \DeclareMathOperator{\Arg}{Arg}
838 \DeclareMathOperator{\Wnd}{Wnd}
839 \DeclareMathOperator{\Res}{Res}
840 \DeclareMathOperator{\Ker}{Ker}
841 \DeclareMathOperator{\Orb}{Orb}
842 \DeclareMathOperator{\Stab}{Stab}
843 \DeclareMathOperator{\Fix}{Fix}
844
845 %% Derivatives
846 \NewDocumentCommand{\deriv}{mm}{%
847 \frac{\dd{}#1}{\dd{}#2}}
848 \NewDocumentCommand{\pderiv}{mm}{%
849 \frac{\partial #1}{\partial #2}}
850 \NewDocumentCommand{\psderiv}{mmm}{%
851 \frac{\partial^2 #1}{\partial #2 \partial #3}}
852
853 % Legacy Definitions
854 \iftma@legacy
855 % Redefine \vec to old definition
856 \RenewDocumentCommand{\vec}{m}{\ensuremath{\overrightarrow{#1}}}
857 % Redefine \C to old definition
858 \ProvideDocumentCommand{\C}{}{\ensuremath{\mathbb{C}}}
859 \RenewDocumentCommand{\C}{}{\ensuremath{\mathbb{C}}}
860 \fi
861
862 % \end{macrocode}
863 %
864 % \subsection{Theorem Environment}
865 % \begin{macrocode}
866 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
867 %% Theorem Environment
868 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
869
870 \newtheorem{lemma}{Lemma}
871 \newtheorem{theorem}{Theorem}
872 % Define \blacksmiley without loading wasysym
873 \ProvideDocumentCommand{\blacksmiley}{}{%
874 \ensuremath{\unicode{263B}}} % Unicode for blacksmiley emoji
875 \RenewDocumentCommand{\qedsymbol}{}{\blacksmiley}
876
877 % \end{macrocode}
878 %
879 % \subsection{Miscellaneous Settings}
880 % \begin{macrocode}
881 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
882 %% Miscellaneous Settings
883 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
884
885 \RenewDocumentCommand{\thefootnote}{}{\fnsymbol{footnote}}
886 \numberwithin{equation}{question}
887 \setlength{\parindent}{0pt}
888 \setlength{\parskip}{2ex plus 0.3ex minus 0.2ex}
889
890 % \end{macrocode}
891 %
892 % \subsection{Header and Footer Settings}
893 % \begin{macrocode}
894 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
895 %% Header and Footer Settings
896 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
897
898 \pagestyle{fancy}
899 \fancyhf{} % Clear all headers and footers
900 \fancyhead[L]{\textrm{\name\ \pin}}
901 \fancyhead[C]{\textrm{\course\ TMA-\tma}}
902 \fancyhead[R]{\textrm{Page \thepage\ of \tma@pageref{LastPage}}}
903 \RenewDocumentCommand{\headrulewidth}{}{0pt} % Remove header rule
904
905 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
906 %% End of Package
907 % %%%%%%%%%%%%%%%%%%%%%%%%%%%
908
909 \endinput
910 % \end{macrocode}
911 % \Finale
912 % \PrintChanges
913 % \PrintIndex