From f7d86b5eb60376920570e7e83b2de729b2565a02 Mon Sep 17 00:00:00 2001 From: Interitio Date: Fri, 29 Aug 2025 23:28:51 +1000 Subject: [PATCH] Add sty files locally. --- fancycom.sty | 306 +++++++++++++++++++++++++++++++++++++++++ fancymath.sty | 371 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 677 insertions(+) create mode 100644 fancycom.sty create mode 100644 fancymath.sty diff --git a/fancycom.sty b/fancycom.sty new file mode 100644 index 0000000..cc6c92c --- /dev/null +++ b/fancycom.sty @@ -0,0 +1,306 @@ +%LaTeX package providing some shorthands and quick commands, tailored to certain unspecified fields of maths. +%Not checked for conflicts with other packages. +%Mostly for personal use. +%Will not always be backwards compatible, although every effort will be made so that this is so. +%Written by Adam Walsh +%Version 1.0 (will not upgrade version numbers for minor command editions) + +\ProvidesPackage{fancycom}[2018/02/03 v1.0 Fancy maths common commands package] + +\RequirePackage{amsfonts} +\RequirePackage{amsthm} +\RequirePackage{amsmath} +\RequirePackage{amssymb} + +\RequirePackage{mathtools} + +\RequirePackage{calc} +\RequirePackage{textcomp} +\RequirePackage[nointegrals]{wasysym} +\RequirePackage{xparse} + +%\RequirePackage{mathrsfs} +\RequirePackage[mathscr]{euscript} + +\RequirePackage{tikz-cd} + +%Textual shortcuts/aids + \newcommand{\mbb}[1]{\mathbb{#1}} %Emblacken your symbols! + \newcommand{\mbf}[1]{\mathbf{#1}} %Embolden your symbols! + \newcommand{\mfk}[1]{\mathfrak{#1}} %Enfraken your symbols! + \newcommand{\bsl}{\backslash} %Backslash + \newcommand{\cndall}{\,\,\,\forall} %forall given as condition + \newcommand{\st}{\,\mid\,} %Such that symbol. : is also used. + \newcommand{\what}[1]{& \qquad &\begin{sloppy}\textit{\small\mbox{#1}\small}\end{sloppy}} %Little comment for an align block. Memento of 2007. + +%Basic symbol extensions + \def\bA{\mathbb{A}} + \def\bF{\mathbb{F}} + \def\bN{\mathbb{N}} + \def\bR{\mathbb{R}} + \def\bZ{\mathbb{Z}} + \def\bQ{\mathbb{Q}} + \def\bC{\mathbb{C}} + \def\bO{\mathbb{O}} + \def\bP{\mathbb{P}} + \def\bS{\mathbb{S}} + \def\fR{\mathfrak{R}} + \def\fZ{\mathfrak{Z}} + \def\fQ{\mathfrak{Q}} + \def\fC{\mathfrak{C}} + \def\fO{\mathfrak{O}} + \def\sC{\mathscr{C}} + \def\sD{\mathscr{D}} + \def\sP{\mathscr{P}} + \def\sF{\mathscr{F}} + \def\sH{\mathscr{H}} + \def\sM{\mathscr{M}} + \def\sT{\mathscr{T}} + \def\cA{\mathcal{A}} + \def\cB{\mathcal{B}} + \def\cO{\mathcal{O}} + \def\cF{\mathcal{F}} + \def\cG{\mathcal{G}} + \def\cC{\mathcal{C}} + \def\cD{\mathcal{D}} + \def\cT{\mathcal{T}} + \def\cP{\mathcal{P}} + \def\cS{\mathcal{S}} + + \def\bfz{\mathbf{0}} + + \def\fkp{\mathfrak{p}} + \def\fkq{\mathfrak{q}} + \def\fkm{\mathfrak{m}} + + +%Symbol abbreviations + \def\lm{\lambda} + \def\eps{\epsilon} + \def\veps{\varepsilon} + \def\vphi{\varphi} + + \def\ot{\otimes} + \def\ptl{\partial} + \def\bdry{\partial} + + \def\nin{\not\in} + + \newcommand{\isom}{\cong} %Isomorphism + \newcommand{\ceq}{\coloneqq} %Defined to be equal to + \newcommand{\eqc}{\eqqcolon} %Equal to be defined to + \newcommand{\ra}{\rangle} %Right angle bracket + \newcommand{\la}{\langle} %Left angle bracket + \newcommand{\wto}{\rightharpoonup} %Weak convergence, or just an arrow with the bottom half missing + \renewcommand{\to}{\longrightarrow} %A long right arrow, for functions and such + \newcommand{\lmto}{\longmapsto} %A right arrow with a vertical tail, for mapping definitions + \newcommand{\llim}{\lim\limits} %limit set up so that it always writes the limits underneath + +%Function constructors + \newcommand{\func}[3]{#1\colon#2\to #3} %Generic function definition without mapping + \newcommand{\mfunc}[3]{#1\colon#2\mapsto #3} %Generic function definition with only mapping + \newcommand{\afunc}[3]{#1\colon#2&\to #3} %Generic function with alignment on arrow + \newcommand{\vfunc}[5]{\func{#1}{#2}{#3},\quad#4\longmapsto #5} %Generic function definition with mapping + \newcommand{\vafunc}[5]{\afunc{#1}{#2}{#3}\\#4&\longmapsto #5} %Generic function over two lines aligned on arrow + + +%More complex operator constructors + \DeclareDocumentCommand\amod{ m g g } + {% + \IfNoValueTF{#2} + {% + \pmod{#1} + }{% + \IfNoValueTF{#3} + {% + {#1}\pmod{#2} + }{% + {#1} \,\equiv\, #2\pmod{#3} + } + } + } + + \DeclareDocumentCommand\ppp{ m g } + {% + \IfNoValueTF{#2} + {% + \frac{\partial}{\partial #1} + }{% + \frac{\partial #1}{\partial #2} + } + } + + \newcommand{\pp}[1]{\frac{\partial}{\partial #1}} + + +%For theorems and proofs + + \newtheorem{Theorem}{Theorem} + \newtheorem{Proposition}{Proposition} + \newtheorem{Conjecture}[Theorem]{Conjecture} + \newtheorem{Lemma}[Theorem]{Lemma} + \newtheorem{Corollary}[Theorem]{Corollary} + +\theoremstyle{remark} + \newtheorem{Example}{Example} + \newtheorem{Note}{Note} + \newtheorem{Question}{Question} + \newtheorem{Remark}{Remark} + +\theoremstyle{definition} + \newtheorem{Result}[Theorem]{Result} + \newtheorem{Definition}[Theorem]{Definition} + %Shorthands + \DeclareDocumentCommand\sdef{m}{\begin{Definition}#1\end{Definition}} + \DeclareDocumentCommand\sex{m}{\begin{Example}#1\end{Example}} + \DeclareDocumentCommand\snote{m}{\begin{Note}#1\end{Note}} + \DeclareDocumentCommand\slem{m}{\begin{Lemma}#1\end{Lemma}} + \DeclareDocumentCommand\sresult{m}{\begin{Result}#1\end{Result}} + \DeclareDocumentCommand\sres{m}{\begin{Result}#1\end{Result}} + \DeclareDocumentCommand\sques{m}{\begin{Question}#1\end{Question}} + \DeclareDocumentCommand\srem{m}{\begin{Remark}#1\end{Remark}} + + + +%Mathematical Operators + \DeclareMathOperator{\Ell}{Ell} %Elliptic genera + \DeclareMathOperator{\id}{id} + \DeclareMathOperator{\Id}{id} + \DeclareMathOperator{\Set}{\mathscr{S}et} + \DeclareMathOperator{\Hom}{\mathscr{H}om} + \DeclareMathOperator{\Top}{\mathscr{T}op} + \DeclareMathOperator{\Mod}{\mathbf{Mod}} + \DeclareMathOperator{\Comm}{\mathbf{Comm}} + \DeclareMathOperator{\Grp}{\mathbf{Grp}} + \DeclareMathOperator{\GL}{GL} + \DeclareMathOperator{\Obj}{Obj} + \DeclareMathOperator{\Spec}{Spec} + \DeclareMathOperator{\Specm}{Specm} + \DeclareMathOperator{\Min}{min} + \DeclareMathOperator{\Ker}{Ker} + \DeclareMathOperator{\im}{Im} + \DeclareMathOperator{\CoIm}{CoIm} + \DeclareMathOperator{\CoKer}{CoKer} + \DeclareMathOperator{\Der}{Der} + \DeclareMathOperator{\End}{End} + + +% Brackets and braces + \DeclareDocumentCommand\braces{}{{\ifnum\z@=`}\fi\@braces} + \DeclareDocumentCommand\@braces{ s t\big t\Big t\bigg t\Bigg m m m } + { % General braces with automatic and manual sizing + \IfBooleanTF{#1} + {\left#6\smash{#8}\right#7\vphantom{#8}} + { + \IfBooleanTF{#2}{\bigl#6{#8}\bigr#7}{ + \IfBooleanTF{#3}{\Bigl#6{#8}\Bigr#7}{ + \IfBooleanTF{#4}{\biggl#6{#8}\biggr#7}{ + \IfBooleanTF{#5}{\Biggl#6{#8}\Biggr#7}{\left#6{#8}\right#7} + } + } + } + } + \ifnum\z@=`{\fi} + } + + + \DeclareDocumentCommand\quantity{}{{\ifnum\z@=`}\fi\@quantity} + \DeclareDocumentCommand\@quantity{ t\big t\Big t\bigg t\Bigg g o d() d|| } + { % Flexible automatic bracketing of an expression in () or [] or {} or || + % Handles manual override of sizing + \IfBooleanTF{#1}{\let\ltag\bigl \let\rtag\bigr}{ + \IfBooleanTF{#2}{\let\ltag\Bigl \let\rtag\Bigr}{ + \IfBooleanTF{#3}{\let\ltag\biggl \let\rtag\biggr}{ + \IfBooleanTF{#4} + {\let\ltag\Biggl \let\rtag\Biggr} + {\let\ltag\left \let\rtag\right} + } + } + } + % Handles actual bracketing + \IfNoValueTF{#5}{ + \IfNoValueTF{#6}{ + \IfNoValueTF{#7}{ + \IfNoValueTF{#8} + {()} + {\ltag\lvert{#8}\rtag\rvert} + } + {\ltag(#7\rtag) \IfNoValueTF{#8}{}{|#8|}} + } + {\ltag[#6\rtag] \IfNoValueTF{#7}{}{(#7)} \IfNoValueTF{#8}{}{|#8|}} + } + {\ltag\lbrace#5\rtag\rbrace \IfNoValueTF{#6}{}{[#6]} \IfNoValueTF{#7}{}{(#7)} \IfNoValueTF{#8}{}{|#8|}} + \ifnum\z@=`{\fi} + } + \DeclareDocumentCommand\qty{}{\quantity} % Shorthand for \quantity + \DeclareDocumentCommand\pqty{ l m }{\braces#1{\lparen}{\rparen}{#2}} + \DeclareDocumentCommand\bqty{ l m }{\braces#1{\lbrack}{\rbrack}{#2}} + \DeclareDocumentCommand\Bqty{ l m }{\braces#1{\lbrace}{\rbrace}{#2}} + \DeclareDocumentCommand\vqty{ l m }{\braces#1{\lvert}{\rvert}{#2}} + +%Matrix constructors +\DeclareDocumentCommand\pmqty{m}{\begin{pmatrix}#1\end{pmatrix}} +\DeclareDocumentCommand\Pmqty{m}{\left\lgroup\begin{matrix}#1\end{matrix}\right\rgroup} +\DeclareDocumentCommand\bmqty{m}{\begin{bmatrix}#1\end{bmatrix}} +\DeclareDocumentCommand\Bmqty{m}{\begin{Bmatrix}#1\end{Bmatrix}} +\DeclareDocumentCommand\sbmqty{m}{\left[\begin{smallmatrix}#1\end{smallmatrix}\right]} +\DeclareDocumentCommand\vmqty{m}{\begin{vmatrix}#1\end{vmatrix}} +\DeclareDocumentCommand\matrixquantity{}{{\ifnum\z@=`}\fi\@matrixquantity} +\DeclareDocumentCommand\@matrixquantity{ s g o d() d|| } +{ + \mathord{ + \IfNoValueTF{#2} + { + \IfNoValueTF{#3} + { + \IfNoValueTF{#4} + { + \IfNoValueTF{#5} + {()} + {\vmqty{#5}} + } + { + \IfBooleanTF{#1} + {\Pmqty{#4}} + {\pmqty{#4}} + \IfNoValueTF{#5}{}{|#5|} + } + } + {\bmqty{#3} \IfNoValueTF{#4}{}{(#4)} \IfNoValueTF{#5}{}{|#5|}} + } + {\begin{matrix}#2\end{matrix} \IfNoValueTF{#3}{}{[#3]} \IfNoValueTF{#4}{}{(#4)} \IfNoValueTF{#5}{}{|#5|}} + } + \ifnum\z@=`{\fi} +} +\DeclareDocumentCommand\mqty{}{\matrixquantity} % Shorthand for \matrixquantity +\DeclareDocumentCommand\matrixdeterminant{m}{\vmqty{#1}} % Matrix determinant +\DeclareDocumentCommand\mdet{}{\matrixdeterminant} % Shorthand for matrix determinant + + +% Quick quad text (math-mode text with \quad spacing) + \DeclareDocumentCommand\qqtext{ s m }{\IfBooleanTF{#1}{}{\quad}\text{#2}\quad} + \DeclareDocumentCommand\qq{}{\qqtext} + + \DeclareDocumentCommand\qcomma{}{,\quad} + \DeclareDocumentCommand\qc{}{\qcomma} + + \DeclareDocumentCommand\qif{s}{\IfBooleanTF{#1}{}{\quad}\text{if}\quad} + \DeclareDocumentCommand\qthen{s}{\IfBooleanTF{#1}{}{\quad}\text{then}\quad} + \DeclareDocumentCommand\qelse{s}{\IfBooleanTF{#1}{}{\quad}\text{else}\quad} + \DeclareDocumentCommand\qotherwise{s}{\IfBooleanTF{#1}{}{\quad}\text{otherwise}\quad} + \DeclareDocumentCommand\qunless{s}{\IfBooleanTF{#1}{}{\quad}\text{unless}\quad} + \DeclareDocumentCommand\qgiven{s}{\IfBooleanTF{#1}{}{\quad}\text{given}\quad} + \DeclareDocumentCommand\qusing{s}{\IfBooleanTF{#1}{}{\quad}\text{using}\quad} + \DeclareDocumentCommand\qassume{s}{\IfBooleanTF{#1}{}{\quad}\text{assume}\quad} + \DeclareDocumentCommand\qsince{s}{\IfBooleanTF{#1}{}{\quad}\text{since}\quad} + \DeclareDocumentCommand\qlet{s}{\IfBooleanTF{#1}{}{\quad}\text{let}\quad} + \DeclareDocumentCommand\qfor{s}{\IfBooleanTF{#1}{}{\quad}\text{for}\quad} + \DeclareDocumentCommand\qall{s}{\IfBooleanTF{#1}{}{\quad}\text{all}\quad} + \DeclareDocumentCommand\qeven{s}{\IfBooleanTF{#1}{}{\quad}\text{even}\quad} + \DeclareDocumentCommand\qodd{s}{\IfBooleanTF{#1}{}{\quad}\text{odd}\quad} + \DeclareDocumentCommand\qinteger{s}{\IfBooleanTF{#1}{}{\quad}\text{integer}\quad} + \DeclareDocumentCommand\qand{s}{\IfBooleanTF{#1}{}{\quad}\text{and}\quad} + \DeclareDocumentCommand\qor{s}{\IfBooleanTF{#1}{}{\quad}\text{or}\quad} + \DeclareDocumentCommand\qas{s}{\IfBooleanTF{#1}{}{\quad}\text{as}\quad} + \DeclareDocumentCommand\qin{s}{\IfBooleanTF{#1}{}{\quad}\text{in}\quad} + \DeclareDocumentCommand\qcc{s}{\IfBooleanTF{#1}{}{\quad}\text{c.c.}\quad} diff --git a/fancymath.sty b/fancymath.sty new file mode 100644 index 0000000..4892d1e --- /dev/null +++ b/fancymath.sty @@ -0,0 +1,371 @@ +%LaTeX package for writing fancy mathematics fast, specifically tailored to writing assignments and course notes. +%Requires and integrates with the fancycom package, which defines many mathematical command shortcuts. +%Not carefully checked for integration with other packages. +%Written by Adam Walsh +%Version 1.0 + +%----------Identification------------ +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{fancymath}[2016/06/17 v1.0 Fancy Maths Package] + +%----------Initial code-------------- + +\RequirePackage{ifthen} + +%Layout colour +%% 0=Full (default) +%% 1=Black (no colour) +%% 2=Grey (Greyscale colours) +\newcounter{colour} +\newboolean{fullcolour} +\setboolean{fullcolour}{true} +\newcommand{\colour}{} + +%Default Layouts +%% 0=plain (default) +%% 1=Assignment +%% 2=General Submission +%% 3=Course Notes +%% 4= +\newcounter{layout} + + +%Separate questions on different pages (for question and answer environment) +%%0= multiple questions per page (default) +%%1= One question and answer per page +\newboolean{sepquest} + +\newboolean{qthm} + +%----------Option Declaration------------ + +%Colour selection +\DeclareOption{grey}{% + \setcounter{colour}{2}% + \setboolean{fullcolour}{false}% + \renewcommand{\colour}{\color{Gray}}} + +\DeclareOption{black}{% + \setcounter{colour}{1}% + \setboolean{fullcolour}{false}% + \renewcommand{\colour}{\color{Black}}} + +%Default Layout selection +\DeclareOption{ass}{\setcounter{layout}{1}} +\DeclareOption{general}{\setcounter{layout}{2}} +\DeclareOption{notes}{\setcounter{layout}{3}} + +%Seperate questions option +\DeclareOption{qsep}{\setboolean{sepquest}{true}} + +\DeclareOption{qthm}{\setboolean{qthm}{true}} + +%---------Process Options---------------- +\ProcessOptions + +%------------Package Loading--------------- + +\RequirePackage[table,dvipsnames]{xcolor} %To use coloured layout +\RequirePackage{fancyhdr} %To make the headers and footers fancy +\RequirePackage{geometry} %To manipulate the geometry of the pages + +\RequirePackage{calc} %For manipulating values + + +%------------Main Code--------------- + + +%Some formatting lengths not usually useful in mathematical submissions. +\setlength{\parindent}{0mm} +\setlength{\parskip}{0mm} + + + +%General values used in titles and styling +\newcommand{\authorname}{} +\newcommand{\authornumber}{} +\newcommand{\coursename}{} +\newcommand{\coursenumber}{} +\newcommand{\submissiontitle}{} +\newcommand{\assignmentnumber}{} +\newcommand{\thetitle}{\submissiontitle} +\newcommand{\theauthor}{\authorname} +\newcommand{\therightfoot}{} +\newcommand{\theleftfoot}{} +\newcommand{\thelefthead}{} +\newcommand{\therighthead}{} + + + +%Control sequences for basic style values +\newcommand{\aname}[1]{% + \renewcommand{\authorname}{#1}} +\newcommand{\anum}[1]{% + \renewcommand{\authornumber}{#1}} +\newcommand{\cname}[1]{% + \renewcommand{\coursename}{#1}} +\newcommand{\cnum}[1]{% + \renewcommand{\coursenumber}{#1}} +\newcommand{\stitle}[1]{% + \renewcommand{\submissiontitle}{#1}} +\newcommand{\assnum}[1]{% + \renewcommand{\assignmentnumber}{#1}} + +%Advanced control sequences for controlling styling +\newcommand{\rawtitle}[1]{% + \renewcommand{\thetitle}{#1}} +\newcommand{\rawauthor}[1]{% + \renewcommand{\theauthor}{#1}} +\newcommand{\rawrfoot}[1]{% + \renewcommand{\therightfoot}{#1}} +\newcommand{\rawlfoot}[1]{% + \renewcommand{\theleftfoot}{#1}} +\newcommand{\rawlhead}[1]{% + \renewcommand{\thelefthead}{#1}} +\newcommand{\rawrhead}[1]{% + \renewcommand{\therighthead}{#1}} + + +%Styling common to all layouts, including plain + +%The page geometry +\geometry{% + a4paper,% + left=20mm,% + right=20mm,% + top=20mm,% + bottom=20mm,% + heightrounded} + + + +%Styling common to general non-plain layouts +\ifthenelse{\not \value{layout}=0}{% + %Base colours, determined from colour option + \newcommand{\titlecolour}{% + \ifthenelse{\boolean{fullcolour}}{\color{Brown}}{\colour}} + \newcommand{\headcolour}{% + \ifthenelse{\boolean{fullcolour}}{\color{Blue}}{\colour}} + \newcommand{\headrulecolour}{% + \ifthenelse{\boolean{fullcolour}}{\color{Brown}}{\colour}} + \newcommand{\enumcolour}{% + \ifthenelse{\boolean{fullcolour}}{\color{Brown}}{\colour}} + + %Some default values for the footers + \rawlfoot{\authorname} + \rawrfoot{\today} + \rawlhead{\submissiontitle} + \rawrhead{\thepage} + + %Page style + \pagestyle{fancy} + + %Set the headers and footers + \fancyhead{} + \fancyfoot{} + \fancyfoot[L]{\headcolour\theleftfoot} + \fancyfoot[C]{\headcolour\thepage} + \fancyfoot[R]{\headcolour{}\therightfoot} + \fancyhead[L]{\headcolour\thelefthead} + \fancyhead[R]{\headcolour\therighthead} + + %Make the headrule + \renewcommand{\headrule}{\headrulecolour\vbox to 0pt{\hbox to\headwidth{\hrulefill}\vss}} + \headheight=21pt + + %Slightly modify line spacing + \renewcommand{\baselinestretch}{1.1} + + %Set the style and colour of the enumerate labels + \renewcommand{\theenumi}{\alph{enumi}} + \renewcommand{\theenumii}{\roman{enumii}} + \renewcommand{\theenumiii}{\alph{enumiii}} + \renewcommand{\labelenumi}{\enumcolour(\theenumi)} + \renewcommand{\labelenumii}{\enumcolour(\theenumii)} + \renewcommand{\labelenumiii}{\enumcolour(\theenumiii)} + + %Make title info for maketitle + \author{\titlecolour\theauthor} + \title{\titlecolour\thetitle} + \date{\titlecolour\today} + +}{} + +%---Notes specific layout and styling--- +\ifthenelse{\value{layout}=3}{% + %Set the Notes specific headers and footers + \rawlfoot{\authorname, \today} + \rawrfoot{Notes} + \rawlhead{\coursenumber -- \coursename} + + %Assignment specific title and Author + \rawauthor{\authorname} + \rawtitle{\coursename -- Notes} +}{} + +%---Assignment specific layout and styling--- +\ifthenelse{\value{layout}=1}{% + %Set the Assignment specific headers and footers + \rawlfoot{\authorname} + \rawrfoot{\today} + \rawrhead{Assignment \assignmentnumber} + \rawlhead{\coursenumber -- \coursename} + + %Assignment specific title and Author + \rawauthor{\authorname, Student \authornumber} + \rawtitle{\coursenumber -- Assignment \assignmentnumber} +}{} + + +%Defining the Question-and-Answer environment for use in assignments. +%%Formats Questions and Answers with incrementing counters +%Base lengths +%%Amount questions and answers are indented +\newlength{\qmargin} +\setlength{\qmargin}{5mm} + +%%Amount of vertical space between question/answer title and question/answer. +\newlength{\qgap} +\setlength{\qgap}{5mm} + +%%Amount of vertical space between end of question and answer. +\newlength{\qagap} +\setlength{\qagap}{0.5em} + + +%Base colours, determined from colour option +%%Default colour is gray anyway +\newcommand{\qcolour}{% + \ifthenelse{\boolean{fullcolour}}{\color{Gray}}{\colour}} + + +\ifthenelse{\boolean{qthm}}{ + %Values + \newcounter{question} + \newcounter{nextanswer} + + \newboolean{firstquest} + \newboolean{questopen} + \newboolean{answeropen} + + \RequirePackage{amsthm} + \theoremstyle{plain} + \newtheorem{Question}[question]{Question} + + + \makeatletter + + \newcommand{\theanswer}{Answer \arabic{nextanswer}} + + \newcommand{\qnum}[1]{% + \setcounter{question}{#1}% + \addtocounter{question}{-1}% + \setcounter{nextanswer}{#1}% + } + + \newcommand{\startqanda}{% + \setcounter{question}{0}% + \setcounter{nextanswer}{0}% + \setboolean{firstquest}{true}% + \setboolean{questopen}{false}% + \setboolean{answeropen}{false}% + } + + \newcommand{\closeqanda}{% + \ifthenelse{\boolean{questopen}}{\closequestion}{}% + \ifthenelse{\boolean{answeropen}}{\closeanswer}{}% + } + + \newcommand{\question}[1][0]{% + \closeqanda% + \ifthenelse{\boolean{sepquest} \and \not \boolean{firstquest} }{\newpage}{}% + \setboolean{firstquest}{false}% + \ifthenelse{#1=0}{}{\qnum{#1}}% + \begin{Question} + \@minipagetrue% + \setboolean{questopen}{true}% + \setcounter{nextanswer}{\value{question}}% + } + \newcommand{\closequestion}{% + \end{Question}% + \setboolean{questopen}{false}% + } + + \newcommand{\answer}[1][0]{% + \closeqanda% + \ifthenelse{#1=0}{}{\qnum{#1}\stepcounter{question}\stepcounter{question}}% + \begin{proof}[\theanswer] + \@minipagetrue% + \setboolean{answeropen}{true}% + \setcounter{question}{\value{nextanswer}}% + \stepcounter{nextanswer}% + \phantom{}% + } + \newcommand{\closeanswer}{% + \ifvmode\vspace*{-\baselineskip}\fi% + %\unskip% + \end{proof}% + \setboolean{answeropen}{false}% + } + + \newenvironment{qanda}{% + \startqanda% + }{% + \closeqanda% + } + \makeatother +}{ + + %Values + \newcounter{question} + \newcounter{lastquestion} + \newboolean{firstquest} + + + %Control Sequences + \newcommand{\qnum}[1]{% + \setcounter{question}{#1}% + \addtocounter{question}{-1}% + \setcounter{lastquestion}{\value{question}}} + + %The environment + \newenvironment{qanda}{% + \setcounter{question}{0}% + \setcounter{lastquestion}{0}% + \setboolean{firstquest}{true}% + \begin{list}{}{% + \renewcommand{\makelabel}[1]{\qcolour\textbf{##1}\\}% + \setlength{\leftmargin}{\qmargin}% + }% + }{% + \end{list}% + } + + %The question and answer commands + \makeatletter + \newcommand{\question}[1][0]{% + \ifthenelse{\boolean{sepquest} \and \not \boolean{firstquest} }{\newpage}{}% + \setboolean{firstquest}{false}% + \ifthenelse{#1=0}{% + \stepcounter{question}% + \setcounter{lastquestion}{\value{question}}% + \item[Question \arabic{question}]% + }{% + \setcounter{lastquestion}{#1}% + \item[Question #1]% + }% + \hfill\break\@minipagetrue% + } + + \newcommand{\answer}[1][0]{% + \vspace{\the\qagap}% + \ifthenelse{#1=0}{% + \item[Answer \arabic{lastquestion}]% + }{% + \item[Answer #1]% + }% + \hfill\break% + \@minipagetrue% + } + \makeatother +}