diff options
author | Norbert Preining <norbert@preining.info> | 2021-01-05 03:01:29 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2021-01-05 03:01:29 +0000 |
commit | 3e4b487ff7bce6f8b3965a0fb2a8f73923ed7e63 (patch) | |
tree | c12b747e0d08405362064b931be5099bd84b3a5a /macros | |
parent | b49dd7c340dbe68a28c8a976cd6a1429ca8aafff (diff) |
CTAN sync 202101050301
Diffstat (limited to 'macros')
19 files changed, 5349 insertions, 1308 deletions
diff --git a/macros/latex/contrib/bookcover/bookcover-example1.pdf b/macros/latex/contrib/bookcover/bookcover-example1.pdf Binary files differindex a3016225cc..eff10290d9 100644 --- a/macros/latex/contrib/bookcover/bookcover-example1.pdf +++ b/macros/latex/contrib/bookcover/bookcover-example1.pdf diff --git a/macros/latex/contrib/bookcover/bookcover-example2.pdf b/macros/latex/contrib/bookcover/bookcover-example2.pdf Binary files differindex 86cbd0a572..3dc0f4642e 100644 --- a/macros/latex/contrib/bookcover/bookcover-example2.pdf +++ b/macros/latex/contrib/bookcover/bookcover-example2.pdf diff --git a/macros/latex/contrib/bookcover/bookcover.dtx b/macros/latex/contrib/bookcover/bookcover.dtx index 55f03e82ac..47ddeb2314 100644 --- a/macros/latex/contrib/bookcover/bookcover.dtx +++ b/macros/latex/contrib/bookcover/bookcover.dtx @@ -17,12 +17,12 @@ % \iffalse %<*driver> \ProvidesFile{bookcover.dtx} -\newcommand{\eifiledate}{2020/12/26} -\newcommand{\eifilever}{v3.2} +\newcommand{\eifiledate}{2021/01/04} +\newcommand{\eifilever}{v3.3} %</driver> %<class> -%<class>\NeedsTeXFormat{LaTeX2e}[2020/10/01] -%<class>\ProvidesClass{bookcover}[2020/12/26 v3.2 class for book covers and dust jackets] +%<class>\NeedsTeXFormat{LaTeX2e}[1999/12/01] +%<class>\ProvidesClass{bookcover}[2021/01/04 v3.3 class for book covers and dust jackets] % %<*driver> \documentclass{ltxdoc} @@ -616,10 +616,7 @@ % % \begin{examplelst} % \documentclass[spinewidth=15mm]{bookcover} -% % The pdflatex or lualatex should be called with the -shell-escape option. -% % The next line is only required for pdflatex and lualatex. -% \usepackage{pst-barcode} -% \usepackage[pdfcrop={-hires}]{auto-pst-pdf} +% \usepackage{GS1,qrcode} % % \begin{document} % @@ -630,14 +627,10 @@ % \bookcovercomponent{normal}{back}[,1cm,,]{ % \vfill % \centering -% \setlength{\fboxsep}{2mm} +% \savebox0{\EANBarcode[module_height=25mm]{ISBN 978-615-5297-19-9}} % \colorbox{white}{% -% \begin{pspicture}(1.5in,1in) -% \psbarcode{1787-6117}{includetext width=1.5 height=1}{issn} -% \end{pspicture}\qquad -% \begin{pspicture}(1.2in,1.2in) -% \psbarcode{https://www.ctan.org/pkg/bookcover}{includetext width=1.2 height=1.2}{qrcode} -% \end{pspicture}}} +% \usebox0 +% \raisebox{\depth}{\qrcode[height=\ht0]{https://www.ctan.org/pkg/bookcover}}}} % % \end{bookcover} % @@ -924,6 +917,7 @@ %% CLASS AND PACKAGES \LoadClass{article} +\@ifundefined{AddToHook}{\RequirePackage{lthooks,picture}}{}% for LaTeX format older than 2020/10/01 \RequirePackage{geometry,graphicx,calc,tikz,xparse,etoolbox} \RequirePackage[nonefgrulers]{fgruler} diff --git a/macros/latex/contrib/bookcover/bookcover.pdf b/macros/latex/contrib/bookcover/bookcover.pdf Binary files differindex 9c9f2efa3c..29aac35547 100644 --- a/macros/latex/contrib/bookcover/bookcover.pdf +++ b/macros/latex/contrib/bookcover/bookcover.pdf diff --git a/macros/latex/contrib/bookcover/figures/bookcover-barcode.pdf b/macros/latex/contrib/bookcover/figures/bookcover-barcode.pdf Binary files differindex fbd7fc3208..f648d9295c 100644 --- a/macros/latex/contrib/bookcover/figures/bookcover-barcode.pdf +++ b/macros/latex/contrib/bookcover/figures/bookcover-barcode.pdf diff --git a/macros/latex/contrib/csquotes/README.md b/macros/latex/contrib/csquotes/README.md index 60a0689276..5534ce2eb1 100644 --- a/macros/latex/contrib/csquotes/README.md +++ b/macros/latex/contrib/csquotes/README.md @@ -16,7 +16,7 @@ quotes are freely configurable. ## License -Copyright (c) 2003-2011 Philipp Lehman, 2015-2019 Joseph Wright. +Copyright (c) 2003-2011 Philipp Lehman, 2015-2019,2021 Joseph Wright. Permission is granted to copy, distribute and/or modify this software under the terms of the LaTeX Project Public License (LPPL), version 1.3c or any later version. diff --git a/macros/latex/contrib/csquotes/csq-compat.def b/macros/latex/contrib/csquotes/csq-compat.def index d4c9485a30..b8ad344c1d 100644 --- a/macros/latex/contrib/csquotes/csq-compat.def +++ b/macros/latex/contrib/csquotes/csq-compat.def @@ -1,5 +1,5 @@ \ProvidesFile{csq-compat.def} - [2019-12-06 v5.2j csquotes backwards compatibility (JAW)] + [2021-01-04 v5.2k csquotes backwards compatibility (JAW)] \def\csq@getversion#1{% \expandafter\csq@getversion@i diff --git a/macros/latex/contrib/csquotes/csquotes.def b/macros/latex/contrib/csquotes/csquotes.def index beab625e06..12197c3ee8 100644 --- a/macros/latex/contrib/csquotes/csquotes.def +++ b/macros/latex/contrib/csquotes/csquotes.def @@ -1,5 +1,5 @@ \ProvidesFile{csquotes.def} - [2019-12-06 v5.2j csquotes generic definitions (JAW)] + [2021-01-04 v5.2k csquotes generic definitions (JAW)] % Set defaults @@ -21,23 +21,17 @@ [0.025em] {\guilsinglright} {\guilsinglleft} -\DeclareQuoteStyle[quotes]{croatian}% verified +\DeclareQuoteStyle[quotes]{croatian}% based on Croatian Orthography by IHJJ (The Institute of Croatian Language and Linguistics) {\quotedblbase} {\textquotedblright} - [0.05em]% unsure - {\quotesinglbase} + [0.05em] + {\textquoteleft} {\textquoteright} -\DeclareQuoteStyle[guillemets]{croatian}% verified +\DeclareQuoteStyle[guillemets]{croatian}% based on Croatian Orthography by IHJJ (The Institute of Croatian Language and Linguistics) {\guillemotright} {\guillemotleft} [0.025em] - {\quotesinglbase} - {\textquoteright} -\DeclareQuoteStyle[guillemets*]{croatian}% verified - {\guillemotleft} - {\guillemotright} - [0.025em] - {\quotesinglbase} + {\textquoteleft} {\textquoteright} \DeclareQuoteStyle[quotes]{czech} {\quotedblbase} @@ -227,6 +221,11 @@ [0.05em] {\textquotedblleft} {\textquotedblright} +\DeclareQuoteStyle{romanian} + {\quotedblbase} + {\textquotedblright} + {\guillemotleft} + {\guillemotright} \DeclareQuoteStyle{russian}% verified {\guillemotleft} {\guillemotright} diff --git a/macros/latex/contrib/csquotes/csquotes.pdf b/macros/latex/contrib/csquotes/csquotes.pdf Binary files differindex de42c872e3..4f48bfb8a9 100644 --- a/macros/latex/contrib/csquotes/csquotes.pdf +++ b/macros/latex/contrib/csquotes/csquotes.pdf diff --git a/macros/latex/contrib/csquotes/csquotes.sty b/macros/latex/contrib/csquotes/csquotes.sty index 9f1db3d123..72bc9ba031 100644 --- a/macros/latex/contrib/csquotes/csquotes.sty +++ b/macros/latex/contrib/csquotes/csquotes.sty @@ -1,5 +1,5 @@ % Copyright (c) 2003-2011 Philipp Lehman. -% (c) 2015-2019 Joseph Wright. +% (c) 2015-2019,2021 Joseph Wright. % % Permission is granted to copy, distribute and/or modify this % software under the terms of the LaTeX Project Public License @@ -12,7 +12,7 @@ \NeedsTeXFormat{LaTeX2e}[2005/12/01] \ProvidesPackage{csquotes} - [2019-12-06 v5.2j context-sensitive quotations (JAW)] + [2021-01-04 v5.2k context-sensitive quotations (JAW)] %% Compatibility and requirements diff --git a/macros/latex/contrib/csquotes/csquotes.tex b/macros/latex/contrib/csquotes/csquotes.tex index db52185989..b37a5737b9 100644 --- a/macros/latex/contrib/csquotes/csquotes.tex +++ b/macros/latex/contrib/csquotes/csquotes.tex @@ -18,8 +18,8 @@ url={http://www.ctan.org/pkg/csquotes/}, author={Philipp Lehman, Joseph Wright}, email={joseph.wright@morningstar2.co.uk}, - revision={v5.2j}, - date={2019-12-06}} + revision={v5.2k}, + date={2021-01-04}} \hypersetup{% pdftitle={The csquotes Package}, @@ -110,7 +110,7 @@ This package provides advanced facilities for inline and display quotations. It \subsection{License} -Copyright © 2003--2011 Philipp Lehman, 2015--2019 Joseph Wright. Permission is granted to copy, distribute and\slash or modify this software under the terms of the \lppl, version 1.3c or any later version.\fnurl{http://www.latex-project.org/lppl/} +Copyright © 2003--2011 Philipp Lehman, 2015--2019,2021 Joseph Wright. Permission is granted to copy, distribute and\slash or modify this software under the terms of the \lppl, version 1.3c or any later version.\fnurl{http://www.latex-project.org/lppl/} \subsection{Contributions} @@ -145,7 +145,7 @@ This option controls multilingual support. It requires either the \sty{babel} pa \multicolumn{1}{@{}H}{Option key} & \multicolumn{1}{@{}H}{Possible values} \\ \cmidrule(r){1-1}\cmidrule{2-2} austrian & quotes, guillemets \\ - croatian & quotes, guillemets, guillemets\* \\ + croatian & quotes, guillemets \\ czech & quotes, guillemets \\ danish & quotes, guillemets, topquotes \\ english & american, british \\ @@ -155,10 +155,13 @@ This option controls multilingual support. It requires either the \sty{babel} pa german & quotes, guillemets, swiss \\ hungarian & \\ italian & guillemets, quotes \\ + latin & \raggedright italianguillemets, germanquotes, germanguillemets, + britishquotes, americanquotes \tabularnewline latvian & \\ norwegian & guillemets, quotes \\ polish & guillemets, guillemets\* \\ portuguese & portuguese, brazilian \\ + romanian & \\ serbian & quotes, guillemets, german \\ spanish & spanish, mexican \\ swedish & quotes, guillemets, guillemets\* \\ @@ -639,7 +642,7 @@ If available, this package will load the configuration file \path{csquotes.cfg}. \multicolumn{1}{@{}H}{Quote style} & \multicolumn{1}{@{}H}{Style variants} \\ \cmidrule(r){1-1}\cmidrule{2-2} austrian & quotes, guillemets \\ - croatian & quotes, guillemets, guillemets\* \\ + croatian & quotes, guillemets \\ czech & quotes, guillemets \\ danish & quotes, guillemets \\ dutch & -- \\ @@ -649,6 +652,8 @@ If available, this package will load the configuration file \path{csquotes.cfg}. german & quotes, guillemets, swiss \\ greek & -- \\ italian & guillemets, quotes \\ + latin & \raggedright italianguillemets, germanquotes, germanguillemets, + britishquotes, americanquotes \tabularnewline norwegian & guillemets, quotes \\ portuguese & portuguese, brazilian \\ russian & -- \\ @@ -710,8 +715,9 @@ This command may be used in the configuration file or in the document preamble. french & french/quotes & swedish & swedish/quotes \\ german & german/quotes & swiss & german/swiss \\ italian & italian/guillemets & swissgerman & german/swiss \\ - mexican & spanish/mexican & UKenglish & british \\ - naustrian & austrian & USenglish & american \\ + latin & latin/italianguillemets & UKenglish & british \\ + mexican & spanish/mexican & USenglish & american \\ + naustrian & austrian \\ \bottomrule \end{tabularx} \caption[Language Aliases]{Language Aliases Defined by Default} diff --git a/macros/latex/contrib/fancyhdr/README b/macros/latex/contrib/fancyhdr/README index 4e6dd1b805..77a6cea64e 100644 --- a/macros/latex/contrib/fancyhdr/README +++ b/macros/latex/contrib/fancyhdr/README @@ -22,19 +22,26 @@ just loads fancyhdr with a warning message. The documentation (fancyhdr.dtx/fancyhdr.pdf) describes both fancyhdr.sty and extramarks.sty. In order to latex the documentation you need to have a copy of -boxedminipage.sty (CTAN:/macros/latex/contrib/boxedminipage) installed. +boxedminipage.sty (CTAN:/macros/latex/contrib/boxedminipage) and +refcount.sty (CTAN:/macros/latex/contrib/oberdiek/) installed. -fancyhdr.sty version 3 and extramarks.sty version 2 are the packages as -described in the second edition of The LaTeX Companion. But that -documentation should also suffice for the newer versions. +This is version 4.0 of fancyhdr.sty and extramarks.sty. They are +described in the forthcoming third edition of The LaTeX Companion. +Extramarks.sty has not been changed, except for the version and +copyright information. + +The older versions fancyhdr.sty version 3 and extramarks.sty version 2 +are the packages as described in the second edition of The LaTeX +Companion. That documentation can still be used for the newer +versions, but some of the newer features will be missing. LICENCE: All files in this package may be distributed under the terms of the LaTeX Project Public License, as described in lppl.txt in the base -LaTeX distribution. Either version 1 or, at your option, any later +LaTeX distribution. Either version 1.3 or, at your option, any later version. -- -Piet van Oostrum. -<piet@vanoostrum.org> -http://www.piet.vanoostrum.org/ +Pieter van Oostrum. +<pieter@vanoostrum.org> +http://pieter.vanoostrum.org/ diff --git a/macros/latex/contrib/fancyhdr/fancyhdr.dtx b/macros/latex/contrib/fancyhdr/fancyhdr.dtx index 7c4da85a05..3315b199ea 100644 --- a/macros/latex/contrib/fancyhdr/fancyhdr.dtx +++ b/macros/latex/contrib/fancyhdr/fancyhdr.dtx @@ -1,8 +1,8 @@ % \iffalse meta-comment % -% Copyright (C) 2016 by Piet van Oostrum <piet@vanoostrum.org> +% Copyright (C) 1994-2021 by Pieter van Oostrum <pieter@vanoostrum.org> % ------------------------------------------------------- -% +% % This file may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either version 1.3 % of this license or (at your option) any later version. @@ -10,7 +10,7 @@ % % http://www.latex-project.org/lppl.txt % -% and version 1.3 or later is part of all distributions of LaTeX +% and version 1.3 or later is part of all distributions of LaTeX % version 2005/12/01 or later. % % \fi @@ -26,11 +26,11 @@ %<fancyhdr>\ProvidesPackage{fancyhdr}% %<fancyheadings>\ProvidesPackage{fancyheadings} %<extramarks>\ProvidesPackage{extramarks} -%<fancyhdr|fancyheadings|extramarks> [2019/01/31 v3.10 +%<fancyhdr|fancyheadings|extramarks> [2021/01/04 v4.0 %<fancyhdr> Extensive control of page headers and footers]% %<fancyheadings> Legacy package to call fancyhdr] %<extramarks> Extra marks for LaTeX] -%<fancyhdr|extramarks>% Copyright (C) 1994-2019 by Piet van Oostrum <piet@vanoostrum.org> +%<fancyhdr|extramarks>% Copyright (C) 1994-2021 by Pieter van Oostrum <pieter@vanoostrum.org> %<fancyheadings>% Public domain %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % \end{macrocode} @@ -48,6 +48,7 @@ \usepackage[T1]{fontenc} \usepackage{url} \usepackage[fit]{truncate} +\usepackage{ifthen} \usepackage{fancyhdr} \GetFileInfo{fancyhdr.sty} \def\latex/{\protect\LaTeX{}} @@ -70,6 +71,7 @@ \newcommand{\CmdIndex}[1]{\index{#1=\string\texttt{\bs#1}}} \newcommand{\TTindex}[1]{\index{#1=\string\texttt{#1}}} \newcommand{\PSindex}[1]{\index{page style>#1=\string\texttt{#1}}} +\newcommand{\OPTindex}[1]{\index{option>#1=\string\texttt{#1}}} \renewcommand{\topfraction}{0.9} \renewcommand{\bottomfraction}{0.9} \renewcommand{\textfraction}{0.05} @@ -84,6 +86,89 @@ \newenvironment{xvspace}{\vspace{1ex}}{{\vspace{1ex}}} \setcounter{tocdepth}{1} +% Compare section numbers in references +\usepackage{refcount} +\newcounter{secnum} +% #1=current section label #2=ref section label +\newcommand{\smartref}[2]{% + \setcounterref{secnum}{#1}% + \addtocounter{secnum}{-1}% + \ifnum\value{secnum}=\getrefnumber{#2} + the previous section% + \else + \addtocounter{secnum}{2}% + \ifnum\value{secnum}=\getrefnumber{#2} + the next section% + \else + section~\ref{#2}% + \fi + \fi +} + +% Our own page style: +\pagestyle{fancy} +\addtolength{\headwidth}{\marginparsep} +\addtolength{\headwidth}{0.5\marginparwidth} +\fancyhf{} +\fancyhead[L]{\rightmark} +\fancyhead[R]{\textbf{\thepage}} +\renewcommand{\sectionmark}[1]{\markright{\thesection\quad#1}} + +% Page style for demonstrating struts, \headruleskip and \footruleskip. + +\newcommand{\strutheader}{% + \texttt{\textbackslash strut}: + \rule[-0.3\normalbaselineskip]{10pt}{0.3\normalbaselineskip}% + \rule{10pt}{0.7\normalbaselineskip} + \texttt{\textbackslash headruleskip}$\searrow$ + \raisebox{-0.3\normalbaselineskip}[0pt][0pt]% + {\ifdim \headruleskip>0pt + \rule[-\headruleskip]{10pt}{\headruleskip} + \else + \rule{10pt}{-\headruleskip} + \fi} +} +\newcommand{\strutfooter}{% + \raisebox{0pt}[0pt][0pt]{% + \texttt{\textbackslash strut}: + \rule[-0.3\normalbaselineskip]{10pt}{0.3\normalbaselineskip}% + \rule{10pt}{0.7\normalbaselineskip} + \texttt{\textbackslash footruleskip} $\nearrow$ + \rule[0.7\normalbaselineskip]{10pt}{\footruleskip}}% +} +\fancypagestyle{showstruts}{% + \fancyhead[L]{% + \ifthenelse{\value{page}=\pageref{showstruts}}% + {\strutheader}% + {\rightmark}% + } + \fancyfoot[L]{% + \ifthenelse{\value{page}=\pageref{showstruts}}% + {\strutfooter}% + {}% + } + \fancyheadinit{% + \ifthenelse{\value{page}=\pageref{showstruts}}% + {\renewcommand{\headruleskip}{4pt}}% + {\renewcommand{\headruleskip}{0pt}}% + } + \fancyfootinit{% + \ifthenelse{\value{page}=\pageref{showstruts}}% + {\renewcommand{\footrulewidth}{0.4pt}}% + {\renewcommand{\footrulewidth}{0pt}}% + } +} + +\newcounter{example} +\newcommand{\Example}{% + \refstepcounter{example}% + \marginpar{\vspace{\baselineskip}\hfill Example \theexample\quad\quad}% +} +\newcommand{\FExample}{% + \refstepcounter{example}% + \makebox[0pt][r]{{Example \theexample}\quad\quad}% +} + \begin{document} \DeleteShortVerb{\|} \DocInput{\jobname.dtx} @@ -91,7 +176,7 @@ %</driver> % \fi % -% \CheckSum{1045} +% \CheckSum{0} % % \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 @@ -116,7 +201,7 @@ % % \title{The \Package{fancyhdr} and \Package{extramarks} % packages\\{\normalsize version \fileversion.}} -% \author{Piet van Oostrum\thanks{A considerable part of this documentation was +% \author{Pieter van Oostrum\thanks{A considerable part of this documentation was % written by George % Gr\"atzer (University of Manitoba) in \emph{Notices Amer. Math. Soc.} % Thanks, George!}\\ @@ -127,22 +212,25 @@ % \maketitle % \begin{abstract} % This document describes how to customize the page layout of your LaTeX -% documents, i.e how to change page margings and sizes, +% documents, i.e how to change page margings and sizes, % headers and footers, and the % proper placement of figures and tables (collectively called floats) on -% the page. -% -% This documentation describes version 3.10 or later of the +% the page. +% +% This documentation describes version 4.0 or later of the % \Package{fancyhdr} and \Package{extramarks} packages. The user % documentation is valid for the versions 3.8 or later of the -% \Package{fancyhdr} package and version 2.1 or later of the +% \Package{fancyhdr} package (except for the changes mentioned in +% section~\ref{sec:version-4}), and version 2.1 or later of the % \Package{extramarks} package. -% +% % \end{abstract} +% % \tableofcontents +% \markright{Contents} % %\part{Introduction} -% +% % This document contains four parts: % % Part I is a short documentation on @@ -156,21 +244,54 @@ % % Part IV contains the annotated implementation. % +% This document describes version 4 of \Package{fancyhdr}. This version +% is also described in the forthcoming edition 3 of \textit{The \latex/ Companion}, +% whereas the previous editions describe version 3 of \Package{fancyhdr}. +% There are some significant differences between these versions. These +% are summarized in section~\ref{sec:version-4} on page~\pageref{sec:version-4}. +% Throughout this documentation it is mentioned when a specific feature +% is only available in version 4, or when there are differences between +% version 3 and 4. +% % \section{Installation} % \label{sec:installation} -% +% % The preferred way to install this package is with a package installer. % If you want to install it by hand, then first run the command % \verb+tex fancyhdr.ins+ and then move the files \texttt{fancyhdr.sty}, % \texttt{extramarks.sty} and \texttt{fancyheadings.sty} to a place % where \latex/ can find it, preferably in a directory similar to % \texttt{.../texmf/tex/latex/fancyhdr/} in your \tex/ directory tree. -% +% % \section{Using \Package{fancyhdr}} % % The package \Package{fancyhdr} gives you several commands to define % headers and footers of the pages in a \latex/ document. -% +% You load the package with the following command in the preamble: +% \begin{quote} +% \verb|\usepackage|\oarg{options}|{fancyhdr}| +% \end{quote} +% (Options are available since version~4.0) +% The following options are supported: +% \begin{center} +% \begin{tabular}{ l l } +% \toprule +% Option & Meaning \\ +% \midrule +% \texttt{nocheck} & do not check the heights of the header and footer \\ +% & (see section~\ref{sec:warning} on page~\pageref{page:warning})\\ +% \texttt{compatV3} & keep some behaviour (now considered undesirable) as in version~3 \\ +% & (see section~\ref{sec:options} and section~\ref{sec:warning} on +% page~\pageref{page:warning}) \\ +% \texttt{headings} & redefine the \texttt{headings} page style to be fancy-based \\ +% \texttt{myheadings} & redefine the \texttt{myheadings} page style to be fancy-based \\ +% \bottomrule +% \end{tabular} +% \end{center} +% \OPTindex{nocheck} +% \OPTindex{compatV3} +% \OPTindex{headings} +% \OPTindex{myheadings} % \DescribeMacro{\fancyhead} % \DescribeMacro{\fancyfoot} % \DescribeMacro{\fancyhf} @@ -199,60 +320,67 @@ % These define offsets to let the headers stick into the margin (or to % the inside if negative). Places cannot contain the \texttt{C} % specifier. See section~\ref{sec:book-examples} for more details. -% -% \DescribeMacro{\headrulewidth} +% % \DescribeMacro{\headrulewidth} +% \DescribeMacro{\footrulewidth} +% \DescribeMacro{\headruleskip} +% \DescribeMacro{\footruleskip} % \DescribeMacro{\headrule} % \DescribeMacro{\footrule} % \DescribeMacro{\headwidth} -% \begin{verbatim} -% \headrulewidth -% \footrulewidth -% \headrule -% \footrule -% \headwidth -% \end{verbatim} % -% \cs{headrulewidth} and \cs{headrulewidth} are macros to define the +% \cs{headrulewidth} and \cs{footrulewidth} are macros to define the % thickness of a line under the header and above the footer. -% \cs{headrule} and \cs{footrule} are macros to completely redefines +% \cs{headruleskip} and \cs{footruleskip} are macros that define the +% distance between the lines and the header and footer text, +% respectively. (But \cs{headruleskip} is only available since version~4.0.) +% \cs{headrule} and \cs{footrule} are macros to completely redefine % these lines. And \cs{headwidth} is a length parameter that defines the % total width of the headers and footers. See sections~\ref{sec:simple}, % \ref{sec:fancy} and \ref{sec:book-examples} for more details. % +% \DescribeMacro{\fancyheadinit} +% \DescribeMacro{\fancyfootinit} +% \DescribeMacro{\fancyhfinit} +% +% \cs{fancyheadinit} and \cs{fancyfootinit} can be used to define +% initialisation code for the header and footer, respectively, and +% \cs{fancyhfinit} defines both of these. These commands are only +% available in fancyhdr version~4.0 and later. See section~\ref{sec:change}. +% +% \DescribeMacro{\fancycenter} +% (Only in version~4.0 and later.) The command \cs{fancycenter} packs 3 +% header fields into a full-width header. See section~\ref{sec:fancycenter}. +% % \DescribeMacro{\iftopfloat} % \DescribeMacro{\ifbotfloat} % \DescribeMacro{\iffloatpage} % \DescribeMacro{\iffootnote} -% \begin{verbatim} -% \iftopfloat -% \ifbotfloat -% \iffloatpage -% \iffootnote -% \end{verbatim} % -% These are macros to detect if there is a float on the top or the bottom +% The macros \cs{iftopfloat}, \cs{ifbotfloat}, \cs{iffloatpage}, +% \cs{iffloatpage}, \cs{iffootnote} +% are used to detect if there is a float on the top or the bottom % of the page, or the page is a float page, or if there is a footnote at % the bottom of the page. These can be used to choose different headers % and/or footers if these conditions are met. See % section~\ref{sec:float} for more details. -% +% +% \begin{quote} % \DescribeMacro{\fancypagestyle} -% \begin{verbatim} -% \fancypagestyle{pagestyle}{commands} -% \end{verbatim} +% \verb|\fancypagestyle|\marg{style-name}\oarg{base-style}\marg{definitions} +% \end{quote} % This command lets you (re)define page styles for use in special -% situations. See section~\ref{sec:pagestyle-plain} for more details. +% situations. See section~\ref{sec:fancypagestyle} for more details. % % \section{Using extramarks} % \label{sec:using-extramarks} -% +% % The \Package{extramarks} gives you some extra marks in \latex/, % besides the normal \cs{leftmark} and \cs{rightmark}, that are defined % by the \cs{markboth} and \cs{markright} commands. % % \DescribeMacro{\firstleftmark} -% \DescribeMacro{\firstleftmark} +% \DescribeMacro{\lastrightmark} % \DescribeMacro{\firstrightmark} % \DescribeMacro{\lastleftmark} % \begin{verbatim} @@ -292,9 +420,9 @@ % % \section{Introduction} % \label{sec:intro} -% +% % A page in a \LaTeX{} document is built from various elements as shown in -% figure \ref{fig:layout}. +% figure \ref{fig:layout}. % \begin{figure}[htbp] % \begin{center} % \leavevmode @@ -306,53 +434,53 @@ % \end{figure} % \thispagestyle{plain} % The body contains the main text of the document -% together with the so called floats (tables and figures). -% +% together with the so called floats (tables and figures). +% % The pages are constructed by \LaTeX's output routine, which is quite % complicated and should therefore not be modified. Some of the packages % described in this paper contains small modifications to the output routine % to accomplish things that cannot be done in another way. You should use % these packages to get the desired result rather than fiddling with the % output routine yourself. -% +% % There are a number of things that you must be aware of: % \begin{enumerate} % \item The margins on the left are not called \cs{leftmargin}, but % \cs{evensidemargin} (on even-numbered pages) and \cs{oddsidemargin} -% (on odd-numbered pages). In one-sided documents +% (on odd-numbered pages). In one-sided documents % \cs{oddsidemargin} is used for either. \cs{leftmargin} is also a valid % \latex/ parameter but it has a different use (namely the indentation of -% lists). +% lists). % \item Most of the parameters should not be changed in the middle of a % document. Some changes might work at a pagebreak. If you want to change % the height of a single page, you can use the \cs{enlargethispage} -% command. +% command. % \end{enumerate} -% +% % The margin notes % area contains small pieces of information created by the \cs{marginpar} % command. On twosided documents the margin notes appear on the left and right % alternatively. The margin notes are not on fixed places with respect to the % paper but at approximately the same height as the paragraph in which they % appear. Due to the algorithm used to decide the placement of margin notes, -% in a twosided document unfortunately +% in a twosided document unfortunately % they may appear on the wrong side if they are close % to a page break. % If you want to put information on fixed places in the margins you may use % the technique described in sections \ref{sec:movie} and \ref{sec:thumb}. -% +% % The first part of this paper describes how to change the header and footer % areas. The last part describes how to get your floats at the desired place. -% +% % \section{Page headers and footers} -% +% % The page headers and footers in \LaTeX{} are defined by the % \cs{pagestyle} and \cs{pagenumbering} commands. \cs{pagestyle} % defines the general contents of the headers and footers (e.g. where the % page number will be printed), while % \cs{pagenumbering} defines the format of the page number. % \LaTeX{} has four standard page styles: -% +% % \begin{center} % \noindent % \begin{tabular}{>{\tt}lp{9cm}} @@ -366,13 +494,13 @@ % \bottomrule % \end{tabular} % \end{center} -% +% % Although these are useful styles, they are quite limited. Additional page % styles can be defined by defining commands of the form \cs{ps@xxx}. This % command is executed when a \Cmd{pagestyle\{xxx\}} is given in the document. -% The \cs{ps@xxx} command should define the following +% The \cs{ps@xxx} command should define the following % commands for the contents of the headers and footers: -% +% % \begin{center} % \noindent % \begin{tabular}{lp{9cm}} @@ -386,16 +514,16 @@ % \bottomrule % \end{tabular} % \end{center} -% +% % These are not user commands, but rather ``variables'' that are used by % \latex/'s output routine. % As the command names contain the character '\texttt{@}', they should % be defined in a package file, or otherwise be sandwiched between the commands % \cs{makeatletter} and \cs{makeatother}. -% +% % The \cs{pagenumbering} command defines the layout of the page number. It % has a parameter from the following list: -% +% % \begin{center} % \begin{tabular}{>{\tt}ll} % \toprule @@ -407,19 +535,19 @@ % \bottomrule % \end{tabular} % \end{center} -% +% % The \Cmd{pagenumbering\{xxx\}} defines the command \cs{thepage} to be the -% expansion of the page number in the given notation \texttt{xxx}. +% expansion of the page number in the given notation \texttt{xxx}. % The pagestyle command % then would include \cs{thepage} in the appropriate place. Additionally % the \cs{pagenumbering} command resets the page number to~1. % The \cs{pagestyle} and \cs{pagenumbering} apply to the page that is % being constructed, so they should be used at a location where it is clear % to what page they apply (see section \ref{sec:change}). -% -% +% +% % \section{What is \Package{fancyhdr}} -% +% % The \Package{fancyhdr} macro package allows you to customize % in \latex/ your page headers and footers in an easy way. You can % define: @@ -432,25 +560,25 @@ % \item different headers and footers for chapter pages % \item different headers and footer on pages with floats % \end{itemize} -% +% % Of course, you also have complete control over fonts, uppercase % and lowercase displays, etc. -% +% % \section{Simple use of \Package{fancyhdr}} To use this package % install it is a place where \latex/ can find it (see % section~\ref{sec:installation})\footnote{In most modern \tex/ % installation the package is already included.}, and include in the preamble of your document -% the commands: -% +% the commands: +% % \PSindex{fancy} % \begin{verbatim} % \usepackage{fancyhdr} % \pagestyle{fancy} % \end{verbatim} -% +% % We can visualize the page layout we can create with \Package{fancyhdr} % as follows: -% +% % \begin{fblock} % \noindent\makebox[\textwidth]{LeftHeader\hfill % CenteredHeader\hfill RightHeader}\showrule @@ -459,33 +587,34 @@ % \noindent\makebox[\textwidth]{LeftFooter\hfill % CenteredFooter\hfill RightFooter} % \end{fblock} -% +% % The LeftHeader and LeftFooter are left justified; the % CenteredHeader and CenteredFooter are centered; the % RightHeader and RightFooter are right justified. -% +% % We define each of the six ``fields'' and the two decorative lines % separately. -% +% % \section{A simple example} % \label{sec:simple} -% +% % K. Grant is writing a report to Dean % A. Smith, on ``The performance of new graduates'' with the % following page layout: -% +% % \begin{fblock} % \noindent\makebox[\textwidth]{\hfill\textbf{The performance of new % graduates}}\showrule % \noindent\makebox[\textwidth]{\hfill page body\hfill}\\[\baselineskip] -% \noindent\makebox[\textwidth]{\hrulefill} +% \noindent\makebox[\textwidth]{\rule{\textwidth}{2pt}} % \noindent\makebox[\textwidth]{From: K. Grant\phantom{3}\hfill % To: Dean A. Smith\hfill \phantom{From: K. Grant}3} % \end{fblock} -% +% % \noindent where ``3'' is the page number. The title: ``The -% performance of new graduates'' is bold. -% +% performance of new graduates'' is bold. The rule above the footer is a +% bit thicker (2pt). +% % This is accomplished by these commands following % \Cmd{pagestyle\{fancy\}}\footnote{Note that version 1 of fancyheadings % used the \cs{setlength} command to change the \texttt{\bs...rulewidth} parameters.}: @@ -500,15 +629,15 @@ % \fancyfoot[C]{To: Dean A. Smith} % \fancyfoot[R]{\thepage} % \renewcommand{\headrulewidth}{0.4pt} -% \renewcommand{\footrulewidth}{0.4pt} +% \renewcommand{\footrulewidth}{2pt} % \end{verbatim} % (The \cs{thepage} macro displays the current page number. % \cs{textbf} puts it in bold face.) -% +% % This is now fine, except that the first page does not need % all these headers and footers. To eliminate all but the % centered page number, issue the command -% +% % \CmdIndex{thispagestyle} % \begin{verbatim} % \thispagestyle{plain} @@ -519,44 +648,102 @@ % \CmdIndex{maketitle} % \cs{maketitle} % commands. -% +% % Alternatively, issue % \begin{verbatim} % \thispagestyle{empty} % \end{verbatim} % if you do not want any headers or footers. -% +% % In fact the standard \latex/ classes have the command \cs{maketitle} % defined in such a way that a \Cmd{thispagestyle\{plain\}} is automatically % issued. So if you \emph{do} want the fancy layout on a page containing % \cs{maketitle} you must issue a \Cmd{thispagestyle\{fancy\}} after the % \cs{maketitle}. -% +% +% \section{Fancy Centering} +% \label{sec:fancycenter} +% +% \textbf{Note:} This section only applies to \Package{fancyhdr} version~4.0 +% and later\footnote{This comes from the \Package{nccfancyhdr} +% package by Alexander I. Rozhenko.}. +% +% The marks in a fancy header and footer are prepared using \cs{parbox} +% command. So, you can use multiline marks. In the header, they are +% aligned to the bottom line, but, in the footer, they are aligned to +% the top line. The maximum width of every mark is equal to the +% \cs{headwidth}. This can lead to overlapping of neighbouring marks. +% +% \DescribeMacro{\fancycenter} +% If you want to prepare marks in more traditional way in a line +% not exceeding the \cs{headwidth}, you can use +% the following command in any mark command: +% \begin{quote} +% \cs{fancycenter}\oarg{distance}\oarg{stretch}\\ +% \verb| |\marg{left-mark}\marg{center-mark}\marg{right-mark} +% \end{quote} +% This command works like +% \begin{center} +% \verb|\hbox to\linewidth{|\marg{left-mark}\cs{hfil}\marg{center-mark}\cs{hfil}\marg{right-mark}\verb|}| +% \end{center} +% but does this more carefully trying to exactly center the central part of +% the text if possible. The solution for exact centering +% is applied if the width of \meta{center-mark} is less than +% \begin{quote} +% \verb|\linewidth - 2*(|\meta{stretch}\verb|*|\meta{distance}\verb| +|\\ +% \verb| max(width(|\meta{left-mark}\verb|), width(|\meta{right-mark}\verb|)))|. +% \end{quote} +% Otherwise the \meta{center-mark} will slightly migrate to a shorter item +% (\meta{left-mark} or \meta{right-mark}), but at least \meta{distance} +% space between all parts of line is provided. +% The default values of \meta{distance} and \meta{stretch} +% are 1em and 3. +% +% If the \meta{center-mark} is empty, the \cs{fancycenter} is equivalent to +% the following command: +% \begin{center} +% \verb|\hbox to\linewidth {|\marg{left-mark}\verb|\hfil |\marg{right-mark}\verb|}| +% \end{center} +% +% You would use this in a header for example with +% \begin{quote} +% \verb|\fancyhead[C]{|\cs{fancycenter}\oarg{distance}\oarg{stretch}\\ +% \verb| |\marg{left-mark}\marg{center-mark}\marg{right-mark}\verb|}| +% \end{quote} +% and leave the \texttt{[L,R]} parts empty. +% +% \textbf{Note 1}: If the whole of the \cs{fancycenter} is wider than +% \cs{headheight} it will stick out on the right. See +% section~\ref{sec:longtitles} for possible solutions. +% +% \textbf{Note 2}: The usage of \cs{fancycenter} command is not limited to the +% argument of header/footer marks. You can use it anywhere in your document. +% % \section{An example of two-sided printing}\label{two-sided} -% +% % \TTindex{twoside} % Some document classes, such as \verb|book.cls|, print two-sided by default: the even % pages and the odd pages have different layouts; other document classes % use the \verb|twoside| option to print two-sided. -% +% % Now let us print the report two-sided. Let the above page % layout be used for the odd (right-side) pages, and the % following for the even (left-side) pages: -% +% % \begin{fblock} -% +% % \noindent\makebox[\textwidth]{\textbf{The performance of new % graduates}\hfill}\showrule % \noindent\makebox[\textwidth]{\hfill page body\hfill}\\[\baselineskip] % \noindent\makebox[\textwidth]{\hrulefill} % \noindent\makebox[\textwidth]{4\phantom{To: Dean A. Smith}\hfill % From: K. Grant\hfill \phantom{4}To: Dean A. Smith} -% +% % \end{fblock} % \noindent where ``4'' is the page number. -% +% % Here are the commands: -% +% % \begin{verbatim} % \fancyhead{} % clear all header fields % \fancyhead[RO,LE]{\textbf{The performance of new graduates}} @@ -567,13 +754,13 @@ % \renewcommand{\headrulewidth}{0.4pt} % \renewcommand{\footrulewidth}{0.4pt} % \end{verbatim} -% +% % \CmdIndex{fancyhead} % \CmdIndex{fancyfoot} % The commands \cs{fancyhead} and \cs{fancyfoot} % have an additional parameter between square brackets that specifies % for which pages and/or parts of the header/footer they apply. The first -% \cs{fancyhead} command omits this parameter, and thus applies to all +% \cs{fancyhead} command above omits this parameter, and thus applies to all % header fields. In general this is only useful to get rid of the defaults or % a previous definition, as is done here. Similar the \cs{fancyfoot} command % without square brackets clears all footer fields. In this particular @@ -583,7 +770,7 @@ % \Cmd{fancyhead[LE,RO]\{text\}} % will define the field for both the left header on even pages and the right % header on odd pages. If you don't give an \texttt{E} or \texttt{O} the definition applies to -% both. Similar for \texttt{LRC}. +% both. Similar for \texttt{LRC}. % The selectors may be given as uppercase or lowercase letters. % \begin{figure}[htb] % \begin{center} @@ -605,20 +792,20 @@ % \caption{Selectors} % \label{fig:sel} % \end{figure} -% +% % \CmdIndex{fancyhf} % There is also a more general command \cs{fancyhf} that you can use to % combine the specifications for headers and footers. This allows additional % selectors \texttt{H} (header) and \texttt{F} (footer). In fact \cs{fancyhead} and % \cs{fancyfoot} are just \cs{fancyhf} with \texttt{H} and \texttt{F} pre-specified, respectively. -% +% % Again, you may % use \Cmd{thispagestyle\{plain\}} for a simple page layout for % page~1. -% +% % \section{Redefining page style \texttt{plain}} % \label{sec:pagestyle-plain} -% +% % Some \latex/ commands, like \cs{chapter}, use the \cs{thispagestyle} % command to automatically switch to the \texttt{plain} page style, thus % ignoring the page style currently in effect. @@ -637,8 +824,8 @@ % \cs{ps@plain} command, but \Package{fancyhdr} gives you an easier way % with the \cs{fancypagestyle} command. This command can be used to % redefine existing page styles (like \texttt{plain}) or to define new ones, -% e.g. if part of your document is to use a different page style. This command -% has two parameters: the first one is the name of the page style to be defined, the +% e.g. if part of your document needs a different page style. This command +% has two mandatory parameters: the first one is the name of the page style to be defined, the % second consists of commands that change the headers and/or footers, i.e. % \verb|fancyhead| etc. Also allowed are changes to \cs{headrulewidth} and % \cs{footrulewidth} or even \cs{headrule} and \cs{footrule}. @@ -657,55 +844,206 @@ % \end{verbatim} % Now when these special pages use the \texttt{plain} page style, they use your redefined version. % -% As another example, let us +% As another example, let us % redefine the \texttt{plain} style for the report in Section~\ref{two-sided} by -% making the page number bold. +% making the page number bold and enclosing it in en-dashes without any rules. % \PSindex{plain} -% +% % \begin{verbatim} % \fancypagestyle{plain}{% -% \fancyhf{} % clear all header and footer fields -% \fancyfoot[C]{\textbf{\thepage}} % except the center -% \renewcommand{\headrulewidth}{0pt} -% \renewcommand{\footrulewidth}{0pt}} +% \fancyhf{}% clear all header and footer fields +% \fancyfoot[C]{\textbf{--~\thepage~--}} % except the center +% \renewcommand{\headrulewidth}{0pt}% +% \renewcommand{\footrulewidth}{0pt}% +% } % \end{verbatim} -% -% -% \section{The default layout}\label{default} +% +% +% \section{Defining other page styles} +% \label{sec:fancypagestyle} +% +% Just like redefining the \texttt{plain} page style in the previous +% section, you can define or redefine other page styles based on page +% style \texttt{fancy}. This is also done with the \cs{fancypagestyle} +% command. The general form of this command is: +% \begin{quote} +% \CmdIndex{fancypagestyle} +% \verb|\fancypagestyle|\marg{style-name}\oarg{base-style}\marg{definitions} +% \end{quote} +% As you see, there is an optional argument between the two mandatory arguments. +% +% For example: +% \begin{verbatim} +% \fancypagestyle{toc}{% +% \fancyhf{}% +% \fancyhead[RO]{\thepage}% +% \fancyhead[RO]{\textsl{TABLE OF CONTENTS}}% +% \fancyfoot[C]{\thepage} +% } +% \end{verbatim} +% This defines a special page style \texttt{toc} for use in the table +% of contents with \Cmd{pagestyle\{toc\}}. +% Inside the definition you can define the headers and/or footers, +% change the header and footer rules, and redefine commands like +% \cs{chaptermark} (see section~\ref{sec:options} for an example). The +% headers and footers and marks that are not redefined inside the +% \cs{fancypagestyle} definition, are taken from the global page style +% \texttt{fancy} values. +% +% You can also give an optional base page style to the +% \cs{fancypagestyle} command. Then the new page style will be based on +% the base style. This base style must be a \texttt{fancyhdr}-defined +% style. Also you should take care not to +% create circular dependencies. In this case the order of picking up the +% definitions (headers, footers, marks) is: +% \begin{enumerate} +% \item The definitions from the base style are taken. +% \item The definitions given in the \cs{fancypagestyle} command +% override and/or augment these. +% \item Any definitions that are not given by the two above, are taken +% from the environment at the time the new page style is used. +% \end{enumerate} +% Only the first two parts are embedded in the page style. +% When no base style is given, part 1 is null. +% +% The optional base style argument is only available since version~4.0. In +% this version it is also possible to redefine page style \texttt{fancy} +% in this way. In version~3.x and earlier this was not possible. +% +% If you want to restore the original default definitions +% from page style \texttt{fancy} as described in section~\ref{sec:default}, you can use +% \begin{verbatim} +% \fancypagestyle{myfancy}[fancydefault]{ +% . . . override some here +% } +% \end{verbatim} +% \PSindex{fancydefault} +% Page style \texttt{fancydefault} is the version of page style +% \texttt{fancy} that has all the initialisation embedded. Contrary to +% this, page style \texttt{fancy} as defined in the package uses the +% same defaults, but doesn't have them embedded. It picks them up from +% the environment. So if the environment changes, because you redefine +% headers, footers, mark commands, etc, the functioning of page style +% \texttt{fancy} changes with it. The page style \texttt{fancydefault} +% does not change, however. However, \texttt{fancydefault} is only available +% since fancyhdr version~4.0. +% +% \section{Package options} +% \label{sec:options} +% +% \textbf{NOTE:} This section applies to fancyhdr version~4.0 and later. +% +% You can supply options to the \cs{usepackage} command: +% \begin{quote} +% \verb|\usepackage|\oarg{options}|{fancyhdr}| +% \end{quote} +% % The following options are supported: +% \begin{center} +% \OPTindex{nocheck}\OPTindex{compatV3}\OPTindex{headings}\OPTindex{myheadings} +% \begin{tabular}{ l l } +% \toprule +% Option & Meaning \\ +% \midrule +% \texttt{nocheck} & do not check the heights of the header and footer \\ +% \texttt{compatV3} & keep some behaviour (now considered undesirable) as in version~3 \\ +% \texttt{headings} & redefine the \texttt{headings} page style to be fancy-based \\ +% \texttt{myheadings} & redefine the \texttt{myheadings} page style to be fancy-based \\ +% \bottomrule +% \end{tabular} +% \end{center} +% +% \begin{itemize} +% \item \OPTindex{nocheck}Option \texttt{nocheck} is described in section~\ref{sec:warning} on +% page~\pageref{page:warning}. +% +% \item \OPTindex{compatV3}Option \texttt{compatV3} keeps two fancyhdr +% version~3.x (or earlier) features that are now considered undesirable. +% \begin{enumerate} +% \item The automatic adjustment of \cs{headheight} or \cs{footskip} +% when these are too small. This causes the page layout to become +% inconsistent. See section~\ref{sec:warning} on +% page~\pageref{page:warning}. +% \item In these previous versions the changes to the +% \Package{fancyhdr} headers and footers (including those by +% \cs{fancyhead}, \cs{fancyheadoffset} and similar commands) are +% made globally, except within a page style defined by +% \cs{fancypagestyle}. That is, when these commands are given inside +% a \LaTeX{} group, they affect the whole document, not only the +% group. If your document depends on this behaviour, you can give +% the \texttt{compatV3} package option. However, this is only +% considered a short-time solution. You should change your document +% as soon as possible to work around this problem. In version~4.0 and +% later, without this option, the changes are always local. +% \end{enumerate} +% The option is scheduled to disappear in version~5 of +% \Package{fancyhdr}. +% +% \item \PSindex{headings}\PSindex{myheadings}\OPTindex{headings}\OPTindex{myheadings} +% The options \texttt{headings} and \texttt{myheadings} redefine the +% corresponding page style with fancyhdr commands (including a +% decorative line under the header), so that you can later select this +% page style as the page style for (part of) the +% document\footnote{These options were copied from the +% \texttt{nccfancyhdr} package, but contrary to that package, they are +% not automatically selected.}. +% \end{itemize} +% +% \PSindex{headings} +% The page style \texttt{headings} is in some aspects similar to the default page +% style \texttt{fancy} settings. In the \texttt{fancy} page style, the +% page number is in the footer, but in the \texttt{headings} +% page style it is in the header. The header fields look similar, however. +% +% Please note that these page styles redefine the \cs{chaptermark} and/or +% \cs{[sub]sectionmark} commands (see section~\ref{sec:scoop}), as do the +% standard \latex/ page styles. The consequence is, that if you select +% e.g.\ \Cmd{pagestyle\{headings\}}, the definitions of +% \Cmd{pagestyle\{fancy\}} are overridden. +% Also when you change the headers and/or footers +% while such a page style is in effect, and you then switch back to this +% page style, for +% example with \verb|\pagestyle{headings}|, they revert to the built-in +% settings. Therefore it is not advisable to change the headers or +% footers in this way, but instead define your +% own page style, as explained in section~\ref{sec:fancypagestyle}. +% +% \section{The default layout} +% \label{sec:default} % Let us use the \verb|book.cls| documentclass and the default settings for -% \Package{fancyhdr}; so we only issue the commands -% +% \Package{fancyhdr}; so we don't use any of the page style options in +% the \Cmd{usepackage\{fancyhdr\}} command, and we don't redefine any +% headers or footers. So just: % \begin{verbatim} % \usepackage{fancyhdr} % \pagestyle{fancy} % \end{verbatim} -% and let \Package{fancyhdr} take care of everything. On the -% pages where new chapters start, we get a centered page number in -% the footer; there is no header, and there are no decorative lines. -% +% and let \Package{fancyhdr} take care of everything. As mentioned +% before, we get a layout that is very similar to the page style \texttt{headings}. +% +% On the pages where new chapters start, we get a centered page number +% in the footer; there is no header, and there are no decorative lines. +% % On an even page, we get the layout: -% +% % \begin{fblock} % \noindent\makebox[\textwidth]{\textsl{1.2 EVALUATION}\hfill % \textsl{CHAPTER 1. INTRODUCTION}}\showrule -% \noindent\makebox[\textwidth]{\hfill page body\hfill}\\[\baselineskip] -% \noindent\makebox[\textwidth]{\hrulefill} -% \noindent\makebox[\textwidth]{\hfill4\hfill} +% \noindent\makebox[\textwidth]{\hfill page body\hfill}\\[2\baselineskip] +% \noindent\makebox[\textwidth]{\hfill2\hfill} % \end{fblock} -% +% % On an odd page, we get the layout: -% +% % \begin{fblock} % \noindent\makebox[\textwidth]{\textsl{CHAPTER 1. INTRODUCTION}\hfill % \textsl{1.2 EVALUATION}}\showrule -% \noindent\makebox[\textwidth]{\hfill page body\hfill}\\[\baselineskip] -% \noindent\makebox[\textwidth]{\hrulefill} +% \noindent\makebox[\textwidth]{\hfill page body\hfill}\\[2\baselineskip] % \noindent\makebox[\textwidth]{\hfill % 3\hfill } % \end{fblock} -% +% % \noindent where the header text is slanted uppercase. -% +% % This default layout is produced by the following commands: % \CmdIndex{rightmark} % \CmdIndex{leftmark} @@ -714,45 +1052,52 @@ % \fancyhead[LO,RE]{\textsl{\leftmark}} % \fancyfoot[C]{\thepage} % \end{verbatim} -% +% % The following settings are used for the decorative lines: -% +% % \begin{tabbing} % \CmdIndex{headrulewidth} % \noindent \cs{headrulewidth}\qquad \qquad \qquad \=0.4\=pt\\ % \CmdIndex{footrulewidth} % \Cmd{footrulewidth}\>0\>pt % \end{tabbing} -% -% The header text is turned into all uppercase in \verb|book.cls|. -% -% \section{The scoop on \latex/'s marks}\label{sec:custom} +% +% The header text is turned into all uppercase by the standard \LaTeX{} +% code in \verb|book.cls|. +% +% \section{The scoop on \latex/'s marks} % \label{sec:scoop} -% +% % Usually, for documents of class \verb|book| and \verb|report|, you may % want to use chapter and section information in the headings (chapter only % for one-sided printing), and for documents of class \verb|article|, % section and subsection information (section only for one-sided % printing). \latex/ uses a marker mechanism to remember the chapter and % section (section and subsection) information for a page; this is -% discussed in detail in \textit{The \latex/ Companion}, Section 4.3.1, or +% discussed in detail in \textit{The \latex/ Companion}, Section 4.3.1, or % \textit{The \latex/ Companion, Second Edition}, Section 4.3.4. -% +% % There are two ways you can use and change the higher- and lower-level % sectioning information available to you. The macros: % \CmdIndex{rightmark} % \CmdIndex{leftmark} % \cs{leftmark} % (higher-level) and \cs{rightmark} (lower-level) contain the information -% processed by \latex/, and you can use them directly as shown in -% Section~\ref{default}. -% +% processed by \latex/, and you can use them directly as shown in +% section~\ref{sec:default}. +% +% These marks are set by the commands +% \Cmd{markboth\{leftmark\}\{rightmark\}} and \Cmd{markright\{rightmark\}}. +% These commands are usually used inside commands like \cs{chaptermark} +% and \cs{sectionmark} but they can be also be given directly in your +% document, although this not very usual. +% % The \cs{leftmark} contains the \textbf{L}eft argument of the \emph{\textbf{L}ast} % \cs{markboth} on the page, the \cs{rightmark} contains the \textbf{R}ight % argument of the \emph{fi\textbf{R}st} \cs{markboth} or the only argument of the % \emph{fi\textbf{R}st} \cs{markright} on the page. If no marks are present on a % page they are ``inherited'' from the previous page. -% +% % You can influence how chapter, section, and subsection % information (only two of them!) is displayed by redefining the % \CmdIndex{chaptermark} @@ -764,7 +1109,7 @@ % they are seldom used.}. You must put the redefinition % after the first call of \Cmd{pagestyle\{fancy\}} as this % sets up the defaults. -% +% % Let us illustrate this with chapter info. It is made up of three parts: % \begin{itemize} % \CmdIndex{thechapter} @@ -773,19 +1118,53 @@ % \CmdIndex{chaptername} % \cs{chaptername} % \item the title, contained in the argument of -% \cs{chaptermark}. +% \cs{chapter}. % \end{itemize} -% -% Figure~\ref{fig:markers} shows some variants for ``Chapter 2.\ Do it now'' -% (the last example is appropriate in some non-English languages). The \% +% We combine these below with \cs{markboth} in \cs{chaptermark}. +% +% For the lower-level sectioning information, we do the same with +% \cs{markright} in \cs{sectionmark}. +% +% So if ``2. Implementation'' is the current chapter +% and ``2.1.\ First steps'' is the current section, then +% +% ^^A \Example +% \begin{verbatim} +% \renewcommand{\chaptermark}[1]{% +% \markboth{\chaptername\ \thechapter.\ #1}{}} +% \renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}} +% \end{verbatim} +% will give +% ``Chapter 2. Implementation'' and ``2.1.\ First steps'' +% +% Redefining the \cs{chaptermark} and \cs{sectionmark} commands may +% not eliminate all uppercaseness. E.g.\ the bibliography will have a title +% \CmdIndex{uppercase} +% \index{BIBLIOGRAPHY} +% of \textsc{bibliography} in the header, as the \cs{MakeUppercase} is +% explicitly given in the definition of \cs{thebibliography}. Similar for +% \index{INDEX} +% \textsc{index} etc.\ If you don't want to redefine these commands, you can +% use the \cs{nouppercase} command that \Package{fancyhdr} makes available in the header +% and footer fields. Note that this may screw other things, like uppercase +% roman numerals in your headers, so it should be used with care. Essentially +% this command typesets its argument in an environment where +% \cs{MakeUppercase} and \cs{uppercase} are changed into do-nothing operations. +% +% ^^A \Example +% \begin{verbatim} +% \fancyhead[L]{\nouppercase{\rightmark}} +% \fancyhead[R]{\nouppercase{\leftmark}} +% \end{verbatim} +% +% Figure~\ref{fig:markers} shows some variants for ``Chapter 2.\ Implementation'' +% (the last example is appropriate in some non-English languages). The \texttt{\%} % signs at the end of the lines are to prevent unwanted space. Normally you -% would continue the lines and remove these \% signs\footnote{the \texttt{\bs +% would continue the lines and remove these \texttt{\%} signs\footnote{The \texttt{\bs % MakeUppercase} command is used in \latex/ to generate uppercase text, -% while in \LaTeX{} 2.09 \cs{uppercase} is used. The difference is -% that \cs{MakeUppercase} also deals with non-ASCII letters. -% Fancyhdr defines \cs{MakeUppercase} to be an alias for -% \cs{uppercase} if it isn't defined.}. -% +% while \cs{uppercase} is the plain \TeX{} command for this. The difference is +% that \cs{MakeUppercase} also deals with non-ASCII letters.}. +% % \begin{figure}[tb] % \CmdIndex{chaptermark} % \CmdIndex{uppercase} @@ -819,93 +1198,70 @@ % \verb| \ \chaptername.\ #1}{}}|\\ % Prints:\\ % \mbox{}\\ -% Chapter 2.\ Do it now\\ +% Chapter 2.\ Implementation\\ % \mbox{}\\ % \mbox{}\\ % \mbox{}\\ -% CHAPTER 2.\ Do it now\\ +% CHAPTER 2.\ Implementation\\ % \mbox{}\\ % \mbox{}\\ % \mbox{}\\ % \mbox{}\\ -% CHAPTER 2.\ DO IT NOW\\ +% CHAPTER 2.\ IMPLEMENTATION\\ % \mbox{}\\ % \mbox{}\\ % \mbox{}\\ % \mbox{}\\ -% Do it now\\ +% Implementation\\ % \mbox{}\\ % \mbox{}\\ -% 2.\ Do it now\\ +% 2.\ Implementation\\ % \mbox{}\\ % \mbox{}\\ -% 2.\ Chapter.\ Do it now\\ +% 2.\ Chapter.\ Implementation\\ % \mbox{}\\ % \end{multicols} % \caption{Marker variants}\label{fig:markers} % \end{figure} -% -% -% For the lower-level sectioning information, do the same with -% \cs{markright}. -% -% So if ``Section 2.2.\ First steps'' is the current section, -% then -% -% \begin{verbatim} -% \renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}} -% \end{verbatim} -% will give -% ``2.2.\ First steps'' -% -% Redefining the \cs{chaptermark} and \cs{sectionmark} commands may -% not eliminate all uppercaseness. E.g.\ the bibliography will have a title -% \CmdIndex{uppercase} -% \index{BIBLIOGRAPHY} -% of \textsc{bibliography} in the header, as the \cs{MakeUppercase} is -% explicitly given in the definition of \cs{thebibliography}. Similar for -% \index{INDEX} -% \textsc{index} etc.\ If you don't want to redefine these commands, you can -% use the \cs{nouppercase} command that \Package{fancyhdr} makes available in the header -% and footer fields. Note that this may screw other things, like uppercase -% roman numerals in your headers, so it should be used with care. Essentially -% this command typesets its argument in an environment where -% \cs{MakeUppercase} and \cs{uppercase} are changed into do-nothing operations. -% -% -% \begin{verbatim} -% \fancyhead[L]{\nouppercase{\rightmark}} -% \fancyhead[R]{\nouppercase{\leftmark}} -% \end{verbatim} -% -% +% % It should be noted that the \latex/ marking mechanism works fine with % chapters (which always start on a new page) and sections (which are % reasonably long). It does not work quite as well with short sections and % subsections. This is a problem with \latex/, not with % \Package{fancyhdr}. -% +% % As an example let's take a page layout where the leftmarks are generated by % the sections and the rightmarks by the subsections (as is default in the -% \texttt{article} class). Take a page with some short sections, e.g. -% +% \texttt{article} class). Take a page with some short sections, e.g. +% % \begin{samepage} % \noindent Section 1.\\ % subsection 1.1\\ % subsection 1.2\\ -% Section 2. +% Section 2. % \end{samepage} -% +% % As the leftmark contains the \emph{last} mark of the page it will be % ``Section 2.'', and the rightmark will be ``subsection 1.1'' as it will be -% the \emph{first} mark of the page. So the page header info will combine +% the \emph{first} mark of the page. So the page header info will combine % section 2 with subsection 1.1 which isn't very nice. -% The best you can do in these cases is use only the \cs{rightmark}s and -% redefine \cs{sectionmark} accordingly. A \latex/ command +% One thing you can do in these cases is use only the \cs{rightmark}s and +% redefine \cs{sectionmark} accordingly. +% +% However, the \Package{extramarks} package described in section~\ref{sec:xmarks} +% contains a command % \CmdIndex{firstleftmark} -% \cs{firstleftmark} would also be a nice addition (see the -% \Package{extramarks} package in section~\ref{sec:xmarks}). -% +% \cs{firstleftmark} that can be used to get the first of the leftmarks +% on the page in the header. This might be the best solution in this +% situation. Now the header will contain ``Section 1.'' in the situation +% described above. +% ^^A \Example +% \begin{verbatim} +% \usepackage{extramarks} +% . . . +% \fancyhead[R]{\firstleftmark} +% \end{verbatim} +% % Another problem with the marks in the standard \latex/ classes is that the % higher level sectioning commands (e.g. \cs{chapter}) call % \cs{markboth} with an empty right argument. This means that on the first @@ -918,49 +1274,26 @@ % \cs{markright} commands or redefine the \cs{chaptermark} % (\cs{sectionmark}) commands to issue a \cs{markboth} command with % two decent parameters. -% +% % As a final remark you should also note that the \verb|*| forms of the % \cs{chapter} etc.\ commands do \emph{not} call the mark commands. So if % you want your preface to set the header info but not be numbered nor be put in % the table of contents, you must issue the \cs{markboth} command % yourself, e.g. -% +% % \begin{verbatim} -% \chapter*{Preface\markboth{Preface}{}} +% \chapter*{Preface} +% \markboth{Preface}{} % \end{verbatim} -% -% Entering the \cs{markboth} command inside the \cs{chapter*} insures -% that the mark will not be separated from the title by a page break. Of -% course with \cs{chapter*} this wouldn't be a problem if you put the mark -% command after the chapter title, as the \cs{chapter*} command starts at a -% new page. However with a \cs{section*} it could be dangerous to say: -% +% +% Or in a documentclass without chapters: % \begin{verbatim} % \section*{Preface} % \markboth{Preface}{} % \end{verbatim} -% as a page break may occur between the two commands. Therefore to be -% safe, put the \cs{mark...} command inside the \cs{section} command. -% -% You have to be careful, however, if you do this with a non-starred -% sectioning command. These will be put in the Table of Contents (if you -% have one), and this means the entries are ``moving'' (they move to the -% Table of Contents). The \cs{mark...} commands are ``fragile'', -% which means they will break when moved. Therefore they must be -% \DescribeMacro{\protect} -% \CmdIndex{protect} -% protected with the \cs{protect} command, for example -% -% \begin{verbatim} -% \chapter{Preface\protect\markboth{Preface}{Preface}} -% \end{verbatim} -% In this example we give \cs{markboth} two non-empty arguments -% otherwise it would make no sense to use the \cs{markboth} command -% inside the \cs{chapter} command. It is harmless to use the -% \cs{protect} command when it is not really necessary. -% +% % \section{Dictionary style headers} -% +% % \index{dictionary} % \index{concordance} % Dictionaries and concordances usually have a header containing the first @@ -970,16 +1303,16 @@ % style headers, you cannot use them for chapter and section information, so % if there are also chapters and sections present, you must redefine the % \cs{chaptermark} and \cs{sectionmark} to make them harmless: -% +% % \begin{verbatim} % \renewcommand{\chaptermark}[1]{} % \renewcommand{\sectionmark}[1]{} % \end{verbatim} -% +% % Now you do a \Cmd{markboth\{\#1\}\{\#1\}} for each dictionary or concordance % entry \verb|#1| and use \cs{rightmark} for the first entry defined on % the page and \cs{leftmark} for the last one. -% +% % If you want to use a header entry of the form \textsf{firstword--lastword} % it would be nice if this would be reduced to just the form % \textsf{firstword} if both are the same. This could happen if there is just @@ -988,7 +1321,7 @@ % cannot be compared out of the box with the plain \tex/ \cs{if} commands. % \TTindex{ifthen} % Fortunately the \Package{ifthen} package works well: -% +% % \begin{verbatim} % \newcommand{\mymarks}{ % \ifthenelse{\equal{\leftmark}{\rightmark}} @@ -997,10 +1330,10 @@ % \fancyhead[LE,RO]{\mymarks} % \fancyhead[LO,RE]{\thepage} % \end{verbatim} -% +% % \section{Fancy layouts} -% \label{sec:fancy} -% +% \label{sec:fancy}\label{sec:warning} +% % \index{multi-line} % You can make a multi-line field with the \bsbs{} command. It is also % possible to put extra space in a field with the \cs{vspace} command. @@ -1012,13 +1345,14 @@ % otherwise you may get error messages ``Overfull \cs{vbox} \ldots has % occurred while \cs{output} is active''^^A % \footnote{If you use \texttt{11pt} or \texttt{12pt} you will probably also -% have to do this, because \LaTeX's defaults are quite small}. -% See Section 4.1 of the \latex/ \emph{Companion} for detail. -% +% have to do this, because \LaTeX's defaults are quite small}. See the +% warning below. +% See also Section 4.1 of the \latex/ \emph{Companion} for detail. +% % For instance, the following code will place the section title and the % subsection title of an article in two lines in the upper right hand % corner: -% +% % \begin{verbatim} % \documentclass{article} % \usepackage{fancyhdr} @@ -1028,10 +1362,10 @@ % \renewcommand{\subsectionmark}[1]{\markright{#1}} % \fancyhead[R]{\leftmark\\\rightmark} % \end{verbatim} -% +% % You can also customize the decorative lines. You can make the decorative % line in the header quite thick with -% +% % \CmdIndex{headrulewidth} % \begin{verbatim} % \renewcommand{\headrulewidth}{0.6pt} @@ -1041,12 +1375,12 @@ % \begin{verbatim} % \renewcommand{\footrulewidth}{0pt} % \end{verbatim} -% +% % The decorative lines, themselves, are defined in the two macros % \cs{headrule} and \cs{footrule}. For instance, % if you want a dotted line rather than a solid line in the header, % redefine the command \cs{headrule}: -% +% % \begin{verbatim} % \renewcommand{\headrule}{\vbox to 0pt{\hbox % to\headwidth{\dotfill}\vss}} @@ -1054,21 +1388,42 @@ % % The redefined \cs{headrule} should preferably take up no vertical space, as in the example above, and as in the standard definition. If it does take vertical space, the header may come too close to the text, or even intrude in the text. In that case \Package{fancyhdr} will give you a warning that \cs{headheight} is too small. Like % \begin{verbatim} -% Package Fancyhdr Warning: \headheight is too small (12.0pt): -% Make it at least 14.0pt. -% We now make it that large for the rest of the document. -% This may cause the page layout to be inconsistent, however. +% Package fancyhdr Warning: \headheight is too small (12.0pt): +% (fancyhdr) Make it at least 14.0pt, for example: +% (fancyhdr) \setlength{\headheight}{14.0pt}. +% (fancyhdr) You might also make \topmargin smaller to compensate: +% (fancyhdr) \addtolength{\topmargin}{-2.0pt}. % \end{verbatim} -% As the warning says, \Package{fancyhdr} will change the -% \cs{headheight} itself, but this is too late for the current page. For -% subsequent pages it will have effect, but now the text on these pages -% will come out lower than on this page. So you are strongly advised to +% \label{page:warning}\index{Warning} +% You will probably get this warning on every page. +% \textbf{Note:} Before version 4.0, \Package{fancyhdr} would change the +% \cs{headheight} itself, causing the text on the following pages +% to come out lower than on this page. This appeared to be confusing, so +% since version~4.0 this is no longer done (except when you give the +% \OPTindex{compatV3}% +% \texttt{compatV3} package option. You should not give this as a +% permanent solution, however, but solve the problem). Therefore you are strongly advised to % redefine \cs{headheight} in the preamble, like this: % \begin{verbatim} -% \setlength\headheight{14pt} +% \setlength{\headheight}{14pt} +% \end{verbatim} +% This would cause the main text to be put 2pt lower on the page, which +% might be undesirable. You can compensate this by making \cs{topmargin} +% correspondingly smaller, for example +% \begin{verbatim} +% \addtolength{\topmargin}{-2pt} % \end{verbatim} % A similar change would be necessary for \cs{footskip} if the footer comes out too tall. % +% You can also eliminate this check completely by using the +% \OPTindex{nocheck} +% \texttt{nocheck} option of the package. But this may risk unwanted +% run-ins of the header or footer with other text. So this is generally +% discouraged. It is better to change \cs{headheight}, \cs{footskip}, +% and/or \cs{topmargin}. But in cases where you generate the \latex/ +% code automatically, and the software does not know how tall the header +% or footer will be, this may be handy. +% % As an alternative to changing \cs{headrulewidth} to 0 to have the rule % disappear, you can also make it empty with % \begin{verbatim} @@ -1076,7 +1431,7 @@ % \end{verbatim} % Visually this makes no difference, but it is more difficult to restore % it later to its default value. -% +% % Finally, let us make a real `decorative' line\footnote{Based upon an idea by Wayne Chan.}. % \begin{verbatim} % \usepackage{fourier-orns} @@ -1088,7 +1443,7 @@ % \hrulefill} % \end{verbatim} % This gives us the following headrule: -% +% % \noindent\makebox[\textwidth]{\hrulefill % \raisebox{-2.1pt}[10pt][10pt]{\quad\decofourleft\decotwo\decofourright\quad}\hrulefill} % @@ -1117,15 +1472,41 @@ % of the footer text line. By default it is set to 30\% of the normal line % distance. You may want to adjust it if you use unusally large or small % fonts in the footer. Change it with \cs{renewcommand}. -% +% +% You can also change the distance between the baseline of the header text and the +% decorative line in the header. Normally this distance is determined by +% the maximum depth of possible descenders in the text, which is 30\% of +% the normal line distance. You can increase or decrease this distance +% \CmdIndex{headruleskip} +% \DescribeMacro{\headruleskip} +% by defining the macro \cs{headruleskip}, similar to \cs{footruleskip} +% \footnote{(But \cs{headruleskip} is only available since version~4.0.)}. +% This defines the extra distance. The default value is 0pt, and +% positive values make the distance larger, and negative values make the +% distance shorter. +% Please note that this does not change the position +% of the decorative line with respect to the page, but it shifts the +% header text. If you want to keep the header text fixed, but move the +% decorative line, then you must also change the parameter \cs{headsep} +% (see figure~\ref{fig:layout}). \strut +% +% \pagestyle{showstruts} +% \noindent\begin{minipage}{\textwidth} +% \label{showstruts} +% \indent The header and footer in this page +% show the \emph{strut} (the amount of space in the text area above and +% below the baseline), and the \cs{headruleskip} and \cs{footruleskip}. +% For this page \cs{headruleskip} is 4pt. +% \end{minipage} +% % \section{Two book examples} % \label{sec:book-examples} -% +% % The following definitions give an approximation of the style % used in L. Lamport's \latex/ book. -% +% % Lamport's header overhangs the outside margin. This is done as follows. -% +% % The width of headers and footers is \cs{headwidth}, which by default % equals the width of the text: \cs{textwidth}. You can make the width % \CmdIndex{headwidth} @@ -1136,22 +1517,27 @@ % \CmdIndex{marginparwidth} % printed, add both \cs{marginparsep} and \cs{marginparwidth} to % \cs{headwidth} with the commands: -% +% % \begin{verbatim} % \addtolength{\headwidth}{\marginparsep} % \addtolength{\headwidth}{\marginparwidth} % \end{verbatim} -% +% % \begin{flushleft} -% You must issue these commands \emph{after} the first -% \Cmd{pagestyle\{fancy\}} command as this -% will establish the default for \cs{headwidth}\footnote{In version 2 or -% later of \Package{fancyhdr} it is usually safe to do it before, but it is still -% advised to do after.}. +% It is safest to issue these commands \emph{after} the first +% \Cmd{pagestyle\{fancy\}} command. % \end{flushleft} -% -% And now a complete definition of Lamport's book style: -% +% +% And now a complete definition of Lamport's book style. The header has +% the width of the text plus the marginpar area. The header on even +% pages has the page number on the left, and the chapter title on the +% right. On odd pages it has the section title preceded by the section +% number on the left and the page number on the right. All in boldface. +% There is no footer. The \texttt{plain} style is redefined to have no +% header and no footer. (In the \LaTeX{} book this makes sense because +% each chapter begins with a page that contains only a drawing. In most +% other cases you probably would want a page number on the page.) +% % \begin{verbatim} % \documentclass{book} % \usepackage{fancyhdr} @@ -1170,15 +1556,15 @@ % } % \end{verbatim} % \PSindex{plain} -% +% % Notice that the \cs{chaptermark} and \cs{sectionmark} commands have % been redefined to eliminate the chapter numbers and the uppercaseness. -% +% % For more control about the horizontal position of the headers and/or % footers, \Package{fancyhdr} has additional commands to specify the % offset of the header and/or footer elements. Use -% \Cmd{fancyhfoffset[place]\{length\}} -% \CmdIndex{fancyhfoffset} +% \Cmd{fancyhfoffset[place]\{length\}} +% \CmdIndex{fancyhfoffset} % to offset one or more elements. The \texttt{place} parameter is like % the optional parameter of \cs{fancyhf}, like \texttt{L R E O}, except % that \texttt{C} cannot be used. It specifies for which elements the @@ -1186,70 +1572,71 @@ % actual offset. Positive values move the element outward (into the % margin), negative values inward. There are also specialised commands % \cs{fancyheadoffset} and \cs{fancyfootoffset}, which have the -% \texttt{H} and \texttt{F} parameter pre-applied, respectively. -% \CmdIndex{fancyheadoffset} -% \CmdIndex{fancyfootoffset} -% +% \texttt{H} and \texttt{F} parameter pre-applied, respectively. +% \CmdIndex{fancyheadoffset} +% \CmdIndex{fancyfootoffset} +% % When you use these commands, \latex/ will recalculate \cs{headwidth}, -% based on the given parameters. -% +% based on the given parameters. +% % So the above example could also have been done with (N.B. You can only % use such an expression as a length parameter if the \Package{calc} -% package is used): -% +% package is used): +% % \begin{verbatim} % \fancyheadoffset[LE,RO]{\marginparsep+\marginparwidth} % \end{verbatim} -% +% % For the second example, we take the \amslatex/ book\footnote{George Gratzer, % \textit{Math into LaTeX, An Introduction to \LaTeX{} and \amslatex/}, Birkhauser, Boston.}. -% +% % Chapter pages have no headers or footers. So we declare -% +% % \begin{verbatim} % \thispagestyle{empty} % \end{verbatim} % for every chapter page, and we do not need to redefine plain. -% -% Chapter and section titles appear in the form: 2.\ DO IT NOW, so we have +% +% Chapter and section titles appear in the form: 2.\ IMPLEMENTATION, so we have % to redefine \cs{chaptermark} and \cs{sectionmark} as follows (see -% Section~\ref{sec:custom}): -% +% Section~\ref{sec:scoop}): +% % \begin{verbatim} % \renewcommand{\chaptermark}[1]% % {\markboth{\MakeUppercase{\thechapter.\ #1}}{}} % \renewcommand{\sectionmark}[1]% % {\markright{\MakeUppercase{\thesection.\ #1}}} % \end{verbatim} -% -% In an even-header, the page number is printed as the LeftHeader and -% the chapter info as the RightHeader; in an odd-header, the section info -% is printed as the LeftHeader and the page number as the RightHeader. The -% CenteredHeaders are empty. There are no footers. -% +% +% On an even page, the page number is printed as the left header and +% the chapter info as the right header; on an odd page, the section info +% is printed as the left header and the page number as the right header. The +% center headers are empty. There are no footers. +% % There is a decorative line in the header. It is 0.5pt wide, so we need % the commands: -% +% % \begin{verbatim} % \renewcommand{\headrulewidth}{0.5pt} % \renewcommand{\footrulewidth}{0pt} % \end{verbatim} -% +% % The font used in the headers is 9 pt bold Helvetica. The \PSNFSS\ system % by Sebastian Rahtz uses the short (Karl Berry) name \verb|phv| for % Helvetica, so this font is selected with the commands: % \begin{verbatim} % \fontfamily{phv}\fontseries{b}\fontsize{9}{11}\selectfont % \end{verbatim} -% (See Sections 7.6.1 and 11.9.1 of the \latex/ \emph{Companion}.) +% (See Sections 7.6.1 and 11.9.1 of the \latex/ \emph{Companion} or +% Sections 7.6 and 7.9.1 of \emph{The \latex/ Companion, Second Edition}.) % Let us define a shorthand for this: % \begin{verbatim} % \newcommand{\helv}{% % \fontfamily{phv}\fontseries{b}\fontsize{9}{11}\selectfont} % \end{verbatim} -% +% % Now we are ready for the page layout: -% +% % \begin{verbatim} % \documentclass{book} % \usepackage{fancyhdr} @@ -1267,11 +1654,11 @@ % \fancyhead[LO]{\helv \rightmark} % \fancyhead[RE]{\helv \leftmark} % \end{verbatim} -% -% +% +% % \section{Special page layout for float pages} % \label{sec:float} -% +% % \index{float page} % Some people want to have a special layout for float pages (pages only % containing floats). As these pages @@ -1280,44 +1667,50 @@ % of the page style will at least also affect the page before the float page. % With \Package{fancyhdr}, however, you can specify in each of % the header- or footer fields -% -% \Cmd{iffloatpage\{}value for float page\verb|}{|value for other pages\verb|}| -% +% +% \medskip +% \Cmd{iffloatpage\{}\meta{value for float page}\verb|}{|\meta{value for other pages}\verb|}| +% \medskip +% % You can even use this to get rid of the decorative line on float pages only % by defining: -% +% % \begin{verbatim} % \renewcommand{\headrulewidth}{\iffloatpage{0pt}{0.4pt}} % \end{verbatim} -% +% % Sometimes you may want to change the layout also for pages that contain a % float on the top of the page, a float on the bottom of the page or a footnote on the bottom of the page. -% +% % \Package{fancyhdr} gives you the commands \cs{iftopfloat}, \cs{ifbotfloat} and \cs{iffootnote} -% similar to \cs{iffloatpage}. -% +% similar to \cs{iffloatpage}. For example: +% \begin{verbatim} +% \fancyhead[R]{\iftopfloat{This page has a topfloat} +% {There is no topfloat here}} +% \end{verbatim} +% % Note: Marks in floats will not be visible in \latex/'s output routine, so % it is not useful to put marks in floats. So there is currently no way to % let a float (e.g.\ a figure caption) influence the page header or footer. -% +% % \section{Those blank pages} % \label{sec:blank} -% +% % In the \texttt{book} class when the \texttt{openany} option is not given or % in the \texttt{report} class when the \texttt{openright} option is given, % chapters start at odd-numbered pages, half of the time causing a blank page -% to be inserted. Some people prefer this page to be completely empty, i.e.\ +% to be inserted. Some people prefer this page to be completely empty, i.e.\ % without headers and footers. This cannot be done with \cs{thispagestyle} % as this command would have to be issued on the \emph{previous} page. There % is, however, no magic necessary to get this done: -% +% % \PSindex{empty} % \CmdIndex{clearpage} % \CmdIndex{cleardoublepage} % \begin{verbatim} -% \clearpage{\pagestyle{empty}\cleardoublepage} +% \clearpage\begingroup\pagestyle{empty}\cleardoublepage\endgroup % \end{verbatim} -% +% % As the \Cmd{pagestyle\{empty\}} is enclosed in a group it only affects the % page that may be generated by the \cs{cleardoublepage}. You can of % course put the above in a private command. If you want to have this done @@ -1327,7 +1720,8 @@ % \begin{verbatim} % \makeatletter % \def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else -% \hbox{} +% \begingroup +% \mbox{} % \vspace*{\fill} % \begin{center} % This page intentionally contains only this sentence. @@ -1335,18 +1729,19 @@ % \vspace{\fill} % \thispagestyle{empty} % \newpage -% \if@twocolumn\hbox{}\newpage\fi\fi\fi} +% \if@twocolumn\mbox{}\newpage\fi +% \endgroup\fi\fi} % \makeatother % \end{verbatim} -% +% % \section{\textsf{N} of \textsf{M} style page numbers} % \label{sec:nofm} -% +% % Some document writers prefer the pages to be numbered as \textsf{n} of % \textsf{m} where \textsf{m} is the number of pages in the document. % There is a package \Package{lastpage} % available which you can use with \Package{fancyhdr} as follows: -% +% % \begin{verbatim} % \usepackage{lastpage} % ... @@ -1360,13 +1755,13 @@ % \end{verbatim} % We clear all the headers including its rule. The footer will be % ``inherited'' from the pagestyle \texttt{fancy}. -% +% % The value of the \texttt{LastPage} label can be used to % make different headers or footers on the last page of a document. E.g.\ if % you want the footer of every odd page, except if it is the last one, to % contain the text ``please turn over'', this can be done as % follows: -% +% % \begin{verbatim} % \usepackage{lastpage} % \usepackage{ifthen} @@ -1374,33 +1769,37 @@ % \fancyfoot[R]{\ifthenelse{\isodd{\value{page}} \and \not % \(\value{page}=\pageref{LastPage}\)}{please turn over}{}} % \end{verbatim} -% +% +% In order to get the number of pages correctly used, you usually have +% to do one additional \LaTeX{} run. +% +% % \section{Chapter or section related page numbers} -% +% % In technical documentation very often page numbers are used of the form % 2-10 where the first number is the chapter number and the second is the % pagenumber relative to the chapter. Sometimes section is used rather than -% chapter. The package \Package{chappg} can be used to get this format. -% -% Basically this package redefines \cs{thepage} as +% chapter. The package \Package{chappg} can be used to get this format. +% +% Basically this package redefines \cs{thepage} as % \cs{thechapter}\cs{chappgsep}\Cmd{arabic\{page\}}, where % \cs{chappgsep} by default is `-'. If you want do use a different % separator, you must redefine \cs{chappgsep}, for example to use an % en-dash: -% +% % \begin{verbatim} % \renewcommand{\chappgsep}{--} % \end{verbatim} -% +% % To use a different prefix, for example the section number, use the % \Cmd{pagenumbering\{bychapter\}} command with an optional argument % specifying the prefix. % \CmdIndex{pagenumbering} -% +% % \begin{verbatim} % \pagenumbering[\thesection]{bychapter} % \end{verbatim} -% +% % What the package also does is reset the page number to 1 at the beginning % of each chapter. % @@ -1419,12 +1818,12 @@ % \pagenumbering{bychapter} % \chapter{Introduction} % \end{verbatim} -% +% % There is a caveat when you have appendices in your document. Before the % \cs{appendix} command you should give a \cs{clearpage} or % \cs{cleardoublepage}. See the \Package{chappg} documentation for % details. -% +% % There is a fundamental difference between the page numbering of the style % ``\emph{m} of \emph{n}'' as described in the previous section and the % current one. The \emph{m} of \emph{n} style is only used in the page header @@ -1432,37 +1831,83 @@ % ``\emph{See page \emph{xx}}''. Therefore it does not change the command % \cs{thepage}. The page numbering style ``2-10'', however should be used % in all references to the page number, therefore it must be done by redefining -% \cs{thepage}. -% -% +% \cs{thepage}. +% +% \section{Switching page styles} +% \label{sec:switching} +% +% Page style \texttt{fancy}, if not redefined, does not have the definitions of the +% headers and footers built-in, but they are defined in the document, +% globally, or locally in a group. This also applies to the definitions of the +% \cs{chaptermark} and/or \cs{[sub]sectionmark} commands. So if you want +% to switch from another page style to the \texttt{fancy} page style +% later in the document, and that other page style has changed for +% example the \cs{chaptermark} and/or \cs{[sub]sectionmark} commands, +% you will have to redefine these yourself and maybe also +% the definitions of the headers and footers, at that point. +% For example +% \begin{verbatim} +% \pagestyle{fancy} +% \renewcommand{\chaptermark}[1]{\markboth{Chapter \thechapter. ##1}{}} +% \renewcommand{\sectionmark}[1]{\markright{\thesection\ ##1}} +% \end{verbatim} +% Please note that you have to double the \verb|#| signs, because the +% definitions are inside a macro. +% +% If the previous page style was one of the standard \LaTeX{} page +% styles, or some page style that is not based on \Package{fancyhdr}, +% then the definitions of \cs{fancyhead} or \cs{fancyfoot} are not +% affected. So strictly you don't have to include them. But if it was +% based on \Package{fancyhdr} and had different definitions, you will +% get the wrong headers and/or footers when you switch back to page +% style \texttt{fancy}. So it is safer to include them anyway. +% +% A better possibility is to define your own page style, and include +% these definitions in that page style: +% \begin{verbatim} +% \fancypagestyle{myfancy}{ +% \renewcommand{\chaptermark}[1]{\markboth{Chapter \thechapter. ##1}{}} +% \renewcommand{\sectionmark}[1]{\markright{\thesection\ ##1}} +% \fancyhead{...} +% } +% ... +% \pagestyle{myfancy} +% \end{verbatim} +% +% In general, when you use only one page style \texttt{fancy} in your +% document, with the occasional \cs{thispagestyle} excursion to page +% style \texttt{plain} or \texttt{empty}, you can just keep the +% definitions globally in your document, but as soon as you use more +% than one page style, and swicth between them, it is highly advisable +% to define them (including page style \texttt{fancy}) with +% \cs{fancypagestyle} and put all the relevant definitions inside them. +% +% There is another caveat, when switching page styles, if they have +% different definitions of \cs{chaptermark} in the \texttt{book} or +% \texttt{report} document class or similar ones. When you put the +% \cs{pagestyle} command \emph{after} the \cs{chapter} command, then the +% \cs{chapter} command calls the \cs{chaptermark} of the previous page +% style, which is probably not what you intended. So you must issue the +% \cs{pagestyle} command \emph{before} the \cs{chapter} command. But +% this would probably change the page style of the previous page, which +% is too early. Therefore you would have to give a \cs{newpage}, +% \cs{clearpage} or \cs{cleardoublepage} command +% before the \cs{pagestyle} command, so that the last page will be +% finished with the previous page style. I.e., the proper sequence is: +% \begin{verbatim} +% \newpage % (or \clearpage or \cleardoublepage) +% \pagestyle{newstyle} +% \chapter{My New Chapter} +% \end{verbatim} +% % \section{When to change the headers and footers?} % \label{sec:change} -% -% Sometimes you want to change the header or footer layout in the course of a -% document. Some of these changes can be accomplished by using the mark -% mechanism as may be seen in section~\ref{sec:custom} and \ref{sec:xmarks}. -% However, sometimes we want a more drastic change, e.g.\ to change the page -% numbering from roman to arabic (with \cs{pagenumbering}), to change one of -% \index{page style>changes} -% the \Package{fancyhdr} fields or to change to another page style. -% Sometimes you may be surprised to find the change to occur too early. In -% general the above mentioned changes take effect immediately, i.e.\ on the -% page that is currently being built. If you want the change to take effect -% at the next page you must make sure that the current page is finished. In -% \CmdIndex{clearpage} -% most cases this can be done by issuing a \cs{newpage} or \cs{clearpage} command before -% any of the above mentioned changes. If this is not possible you can use the -% \TTindex{afterpage.sty} -% \Package{afterpage} package with:\\ -% \Cmd{afterpage\{}\Cmd{fancyhead[L]\{new value\}\}} or -% \CmdIndex{pagenumbering} -% \Cmd{afterpage\{}\Cmd{pagenumbering\{roman\}\}}. You cannot use \cs{afterpage} -% to change the \cs{pagestyle} as the commands issued by \cs{afterpage} -% are local in a group, and the \cs{pagestyle} command makes only local -% changes. The \cs{pagenumbering} and the \Package{fancyhdr} commands -% make global changes so they will work, as will the \cs{thispagestyle} -% command. -% +% +% In \smartref{sec:change}{sec:switching} we switched page styles at a +% point that has a clear page break (the beginning of a chapter). +% Sometimes you want to change only a header or footer without changing +% the whole page style. +% % It should be noted that although the \Package{fancyhdr} commands like % \cs{fancyhead} take effect immediately, this does not mean that any % ``variables'' used in these commands get the value they have at the place @@ -1470,37 +1915,285 @@ % the page number that will be inserted in the footer is not the page number % of the page where this command is given, but rather the page number of % the actual page where the footer is constructed. Of course for the page -% number this is what you expect, but it is also true for other commands. -% -% So if you have a book where each chapter is written by a different author -% and you want the name of the author in the lower left-hand corner you can -% use the following commands: -% +% number this is what you expect, but it is also true for other +% commands. There is a difference, however. The page number is +% incremented \emph{after} the page has been constructed. When we have +% our own ``variables'', however, these are usually changed in the +% middle of our text. +% +% As an example we take a book where each chapter is written by a different author. +% If we want the name of the author in the header opposite the chapter +% title, we can use the following commands: +% % \begin{verbatim} % \newcommand{\TheAuthor}{} % \newcommand{\Author}[1]{\renewcommand{\TheAuthor}{#1}} -% \fancyfoot[L]{\TheAuthor} +% \fancyhead[LE,RO]{\TheAuthor} % \end{verbatim} -% -% \noindent and start each chapter with the command +% +% \noindent and start each chapter with the command % \Cmd{Author\{Real Name\}}. -% If however, the author name would be changed before a page is -% completed the wrong author could come in the footer. This would be the case +% If, however, the author name would be changed before a page is +% completed the wrong author could come in the header. This would be the case % if you gave the above command \emph{before} the \cs{chapter} command -% rather than after it. +% rather than after it. So we give the \cs{Author} command after the +% \cs{chapter} command: +% \begin{verbatim} +% \chapter{Chapter Title} +% \Author{Author Name} +% \end{verbatim} +% As a chapter starts on a new page, we can be sure that the \cs{Author} +% command comes at the same page as the chapter start. +% % Another source of problems is the fact that \tex/'s output routine processes % commands ahead, so it may already have processed some commands that produce -% text that will appear on the next page. See the next section for an example. -% +% text that will appear on the next page. So if our book was not divided +% into chapters, but into sections, we cannot use the similar system: +% \begin{verbatim} +% %%% NOTE: This may not work %%%% +% \section{Chapter Title} +% \Author{Author Name} +% \end{verbatim} +% because in this case, when this command comes at the end of a page, +% the ``variable'' \cs{TheAuthor} could be set at that page, but then +% \TeX{} could decide to move the section title to the next page. And +% then the author name would appear one page too early. This problem can +% be solved using marks. In fact this is the whole reason the mark +% mechanism was developed in \TeX. See section~\ref{sec:xmarks}. +% +% The same applies to other changes in the middle of a page, e.g.\ to change the page +% numbering from roman to arabic (with \cs{pagenumbering}). For the same +% reason \Cmd{thispagestyle\{mystyle\}} will not always work in the +% middle of a page. +% +% Some of these changes can be accomplished by using the mark +% mechanism as may be seen in \smartref{sec:change}{sec:scoop} and +% \smartref{sec:change}{sec:xmarks}. +% +% In the remainder of this section we look at two different cases of +% changing the page style in the middle of a page: changing the style of +% the current page and changing the style of the next page. +% +% \subsection{Changing the page style of the current page} +% +% So now we are giving an example how to change the headers and footers, +% only on the current page. In some cases this can be done by the +% \CmdIndex{thispagestyle}% +% \cs{thispagestyle} command. This changes the page style for the +% ``current'' page only. But then we may be hit by the problem mentioned +% above. \LaTeX{} may have a different idea about +% the ``current'' page than you. The use of \cs{thispagestyle} is OK if +% you can be sure that the text where the command \cs{thispagestyle} is +% executed is the same page as where the surrounding text appears. So +% for example directly after a \cs{chapter} command, or after a +% \cs{newpage}. However, when the command is given near the end of a +% page, \LaTeX{} may execute the command, and then decide that the page +% is full and move the text that contains the command to the next page. +% So now the page style is changed on one page earlier than was intended. +% +% A good solution to this problem is to put a label, like +% \Cmd{label\{otherpagestyle\}} in the text where you want the different +% page style, and then in the header and/or footer definitions compare +% the page number with the label page number and choose the proper +% value. For example, if we want to replace the section title on the +% special page with ``MYFANCY SECTION'', like in +% \begin{verbatim} +% \fancypagestyle{myfancy}{ +% \fancyhead[LE,RO]{MYFANCY SECTION} +% } +% \end{verbatim} +% ^^A\Example +% we define a new pagestyle that makes the choice: +% \begin{verbatim} +% \usepackage{ifthen} +% . . . +% \fancypagestyle{switch}{ +% \fancyhead[LE,RO]{% +% \ifthenelse{\value{page}=\pageref{otherpagestyle}} +% {MYFANCY SECTION} +% {\textsl{\rightmark}}} +% } +% \end{verbatim} +% \CmdIndex{ifthenelse} +% where \verb|\textsl{\rightmark}| is the normal value of the header +% field from \Cmd{pagestyle\{fancy\}}. +% Now we choose \Cmd{pagestyle\{switch\}} before our text, or even for +% the whole document. +% +% There can still be some ambiguity on which page gets the different +% header. For example, if the text says: +% \begin{quote} +% This page gets a different header than the surrounding pages. +% \end{quote} +% where do you put the \cs{label}? \LaTeX{} could break the page between +% ``This'' and ``page'', and then would you want the special heading on +% the page where ``This'' appears, or on the page where ``page'' +% appears. It depends on the positioning of the \cs{label} command. +% Probably it is safer to make sure the sentence isn't broken. This can +% be dome by putting the text in a \cs{parbox} or \texttt{minipage} environment. +% \begin{verbatim} +% \noindent +% \begin{minipage}{\textwidth} +% This page should have a different header than the surrounding pages. +% \label{otherpagestyle} +% It is done with the \verb|\pagestyle{switch}| command, that +% has tests in the header field definitions. This chooses the actual +% header depending on the page number. +% \end{minipage} +% \end{verbatim} +% The \cs{noindent} is necessary, otherwise the whole \texttt{minipage} +% will be shifted right by the paragraph indentation. +% +% Note that you cannot reset the page style immediately after this code, +% as this may still influence the current page. If you want to reset it, +% for example to \Cmd{pagestyle\{fancy\}}, you must be sure that it +% happens on a following page. But in this case it isn't even necessary, +% as the special page style acts as the default on all pages except the +% special page. +% +% The special header and footer in page~\pageref{showstruts}, which +% show the struts are done in a similar way, although the header and +% footer are a bit more elaborated there. +% Also there is another complication there, as we also want to make both +% \cs{headruleskip} and \cs{footrulewidth} dependent on the page number. +% Unfortunately, this cannot be done with a simple \cs{ifthenelse} +% \CmdIndex{ifthenelse} +% command. +% Both \cs{headruleskip} and \cs{footrulewidth} are eventually +% used as length parameters, and this requires that they are +% \emph{expandable}. However, the \cs{ifthenelse} construct is not +% expandable, so you will get strange error messages if you use +% something like +% \begin{verbatim} +% %%% NOTE: This does not work %%%% +% \renewcommand{\footrulewidth}{% +% \ifthenelse{\value{page}=\pageref{otherpagestyle}}{0.4pt}{0pt}% +% } +% \end{verbatim} +% For cases like this \Package{fancyhdr} version~4.0 and later has some +% new commands \cs{fancyheadinit}, \cs{fancyfootinit} and \cs{fancyhfinit}. +% \DescribeMacro{\fancyheadinit} +% With \Cmd{fancyheadinit\{\meta{code}\}} you can define some code that will be executed +% just before the construction of the header. As it is executed in the +% header, it can test the correct page number, because the counter +% \texttt{page} is guaranteed to have the correct value in the headers +% and footers. Similarly, the code in \Cmd{fancyfootinit\{\meta{code}\}} is executed in +% \DescribeMacro{\fancyfootinit} +% the footer. And \Cmd{fancyhfinit\{\meta{code}\}} sets its code for both the header +% \DescribeMacro{\fancyhfinit} +% and the footer. Now we can set for example \cs{headruleskip} or +% \cs{footrulewidth} depending on the page number. So instead of putting +% the test inside the definition of \cs{headruleskip}, we can put it +% outside, and then we can use the command \cs{ifthenelse}. So we put +% the following in \Cmd{pagestyle\{switch\}}: +% \begin{verbatim} +% \fancyheadinit{% +% \ifthenelse{\value{page}=\pageref{otherpagestyle}} +% {\renewcommand{\headruleskip}{4pt}} +% {\renewcommand{\headruleskip}{0pt}} +% } +% \fancyfootinit{% +% \ifthenelse{\value{page}=\pageref{otherpagestyle}} +% {\renewcommand{\footrulewidth}{0.4pt}} +% {\renewcommand{\footrulewidth}{0pt}} +% } +% \end{verbatim} +% Now here is the definition of the page style used for page~\pageref{showstruts}. +% \begin{verbatim} +% \fancypagestyle{showstruts}{% +% \fancyhead[L]{% +% \ifthenelse{\value{page}=\pageref{showstruts}}% +% {\strutheader}% +% {\rightmark}% +% } +% \fancyfoot[L]{% +% \ifthenelse{\value{page}=\pageref{showstruts}}% +% {\strutfooter}% +% {}% +% } +% \fancyheadinit{% +% \ifthenelse{\value{page}=\pageref{showstruts}}% +% {\renewcommand{\headruleskip}{4pt}}% +% {\renewcommand{\headruleskip}{0pt}}% +% } +% \fancyfootinit{% +% \ifthenelse{\value{page}=\pageref{showstruts}}% +% {\renewcommand{\footrulewidth}{0.4pt}}% +% {\renewcommand{\footrulewidth}{0pt}}% +% } +% } +% \end{verbatim} +% The label used on that page is \texttt{showstruts}. \cs{strutheader} +% and \cs{strutfooter} are macros that contain the code to draw these +% pictures. In this example the values for \cs{headruleskip} and +% \cs{footrulewidth} in the \emph{else} case are the same as the global +% values. So we could have left these \emph{else} parts empty. Then they +% would keep the global values. +% However, often explicit is better than implicit. +% +% These initialisation commands cannot be used to make global changes to +% the page, for example to \cs{headheight}. Neither can you use them to +% change \cs{fancyhead} or \cs{fancyfoot}, because these have already +% been set up. But you can use it to set the color and font of the +% header and/or footer, for example to get large, red text in the +% headers and footers on this specific page: +% \begin{verbatim} +% \fancyhfinit{% +% \ifthenelse{\value{page}=\pageref{otherpagestyle}} +% {\color{red}\Large} +% {} +% } +% \end{verbatim} +% +% \subsection{Changing the page style of the next page} +% +% If you want the change of the page style to take effect +% at the next page you must make sure that the current page is finished. In +% most cases this can be done by issuing a +% \CmdIndex{clearpage}\CmdIndex{newpage}% +% \cs{newpage} or \cs{clearpage} command before % any changes. However, +% this will immediately end the current page, possibly leaving you with a +% half-empty page, which may be undesirable. +% +% If this is not what you want, you can use the +% \TTindex{afterpage.sty}% +% \Package{afterpage} package with:\\[1ex] +% \CmdIndex{afterpage}\Cmd{afterpage\{}\Cmd{fancyhead[L]\{new value\}\}} or\\ +% \CmdIndex{pagenumbering}\Cmd{afterpage\{}\Cmd{pagenumbering\{roman\}\}}. +% \\[1ex] +% You cannot use \cs{afterpage} +% to change the \cs{pagestyle} as the commands issued by \cs{afterpage} +% are local in a group, and the \cs{pagestyle} command makes only local +% changes. The \cs{pagenumbering} and the \cs{thispagestyle} +% command make global changes, as well as changes to \LaTeX's counters, +% such as \cs{setcounter} and \cs{addtocounter}. +% So these can be used\footnote{In \Package{fancyhdr} version~3 and +% earlier the commands like \cs{fancyhead} and \cs{fancyfoot} also made +% global changes. This is no longer the case in version~4.0 and later.}. +% Here is an example to change the page style of the next page with \cs{afterpage}: +% ^^A \Example +% \begin{verbatim} +% \usepackage{afterpage} +% \usepackage{fancyhdr} +% \fancypagestyle{myfancy}{ +% \fancyhead[LE,RO]{\textbf{MYFANCY SECTION}} +% \fancyhead[LO,RE]{\textbf{MYFANCY CHAPTER}} +% \fancyfoot[C]{\textbf{--~\thepage~--}} +% } +% . . . +% \afterpage{\thispagestyle{myfancy}} +% \end{verbatim} +% Then the page after this code will have the page style \texttt{myfancy}. +% % \section{Headers and footers induced by the text} % \label{sec:xmarks} -% +% % We have seen how we can use \LaTeX's marks to get information from the % document contents to the headers and footers. The marks mechanism is the % only reliable mechanism that you can use to get changing information to the % headers or footers. This is because \latex/ may be processing your document -% ahead before deciding to break the page. -% +% ahead before deciding to break the page. +% % Sometimes the two marks that \latex/ offers are not enough. An example is % the following: % \begin{quote} @@ -1509,14 +2202,14 @@ % \index{Continued\ldots} % first page and ``(Continued\ldots)'' at the top in the margin of the next page. % \end{quote} -% +% % You cannot use \latex/'s mark mechanisms for this if you also want to use % chapter and section information. -% +% % The \Package{extramarks} package gives you % two extra marks that can be used in this situation. % Here is a way to use this package: -% +% % \begin{verbatim} % \usepackage{extramarks} % ... @@ -1529,14 +2222,14 @@ % \extramarks{Continued\ldots}{} %2 % \extramarks{}{} %3 % \end{verbatim} -% +% % \CmdIndex{extramarks} % Note that the \cs{extramarks} command must be close to the text, i.e no % empty lines (paragraph boundaries) should intervene. Otherwise the page may % be broken at that boundary and the extramarks would come on the wrong page. % The final \verb+\extramarks{}{}+ is to prevent the `Continued\ldots' % header to appear on the following pages. -% +% % Explanation: There are two new marks that can be used in the page layout with this % package: If commands of the form % \verb|\extramarks{|$m_1$\verb|}{|$m_2$\verb|}| are given @@ -1551,12 +2244,12 @@ % \cs{extramarks} command (indicated by \texttt{\%3}). % % However, when the page break falls in the block, the mark generated by -% \%1 will be the last one on the first page. Therefore on that page +% \texttt{\%1} will be the last one on the first page. Therefore on that page % \cs{lastxmark} will be `Continued on next page\ldots'. On the second % page, the first mark will be \texttt{\%2}, therefore \cs{firstxmark} will be `Continued\ldots'. % On all the following pages the values of \texttt{\%3} will be used, % i.e. empty ones. Of course in real life you would leave out the \texttt{\%} indicators. -% +% % In case you want the last $m_1$ value or the first $m_2$ value, you % can use the \cs{lastleftxmark} or \cs{firstrightxmark}, respectively. % For symmetry reasons there are also commands \cs{firstleftxmark} @@ -1569,17 +2262,17 @@ % \CmdIndex{lastrightxmark} % \CmdIndex{topleftxmark} % \CmdIndex{toprightxmark} -% +% % The package also gives you the \cs{firstleftmark} and \cs{lastrightmark} % commands that complement the standard \latex/ marks. % \CmdIndex{firstleftmark} % \CmdIndex{lastrightmark} -% +% % To stress the point that marks are the correct way to do this, let me % give you a ``solution'' that will not work\footnote{Actually there is % another way but it requires two \latex/ passes: you can put \cs{label} % commands before and after the text and compare the \cs{pageref}s.}: -% +% % \begin{verbatim} % \fancyhead[L]{Continued} % \fancyfoot[R]{Continued on next page\ldots} @@ -1587,7 +2280,7 @@ % \fancyhead[L]{} % \fancyfoot[R]{} % \end{verbatim} -% +% % You may be tempted to think that the first \cs{fancyhead} and \cs{fancyfoot} % will be in effect when \tex/ breaks the page in the middle of the text, % and the last ones when the page breaks after the text. This is not true as @@ -1600,21 +2293,21 @@ % the first definitions to be in effect when \tex/ decides to break the page % exactly at this boundary. Actually the marks mechanism was invented to get % rid of these kinds of problems. -% +% % In the above example the text ``Continued'' appears in the page header. It % \index{margin} % may be nicer to put it in the margin. This can be easily % accomplished by positioning it at a fixed place relative to the page header. % In plain \tex/ you would use a concoction of \Cmd{hbox to 0pt}, % \Cmd{vbox to 0pt}, \cs{hskip},\cs{vskip}, \cs{hss} and -% \cs{vss} but fortunately +% \cs{vss} but fortunately % \latex/'s \texttt{picture} environment gives a much cleaner way to do this. % In order not to disturb the normal header layout we put the text in a zero-sized % \texttt{picture}. Generally this is the best way to position things on fixed % places on the page. You can then also use the normal headings. See also -% section~\ref{sec:thumb} for another example of +% section~\ref{sec:thumb} for another example of % this technique. -% +% % \TTindex{picture} % \begin{verbatim} % \fancyhead[L]{\setlength{\unitlength}{\baselineskip}% @@ -1622,34 +2315,34 @@ % \put(-2,-3){\makebox(0,0)[r]{\firstxmark}} % \end{picture}\leftmark} % \end{verbatim} -% +% % This solution can of course also be used for the footer. Make sure you put the % \texttt{picture} as the first thing in left-handside entries and last in right-handside % ones. -% +% % Finally you may want to put ``(Continued\ldots)'' in the \emph{text} % rather than in the header or the margin. Then you have to use the % \TTindex{afterpage.sty} % \Package{afterpage} package. We also decide to make a separate % environment for it. -% +% % \begin{verbatim} % \newenvironment{continued}{\par % \extramarks{}{Continued on next page\ldots} % \afterpage{\noindent\firstxmark\vspace{1ex}} % }{\extramarks{(Continued\ldots)}{}\par} % \end{verbatim} -% +% % It is a bit dangerous to use \cs{firstxmark} outside the page layout % routine, but apparently with \cs{afterpage} this works. If you would % need the information further on in the page you must remember the state of % the marks in your own variable. You can set this in one of the % \Package{fancyhdr} fields. For example if you want to add something % \emph{after} the broken piece of text you can use the following: -% +% % \begin{verbatim} % \newcommand{\mysaved}{} -% +% % \newenvironment{continued}{\par % \extramarks{}{Continued on next page\ldots} % }{\extramarks{(Continued\ldots)}{}\par\vspace{1ex}\mysaved} @@ -1658,14 +2351,14 @@ % {\gdef\mysaved{}} % {\gdef\mysaved{\noindent[Continued from previous page]}}} % \end{verbatim} -% +% % If you want to include one of the marks or other varying information in the % saved text, you must use \cs{xdef} rather than \cs{gdef}. -% -% +% +% % \section{A movie} % \label{sec:movie} -% +% % \index{movie} % \TTindex{picture} % If you put at each page on the same place a picture that slightly changes @@ -1674,27 +2367,27 @@ % simplicity we assume that each picture is in a postscript (EPS) file called % \texttt{pic}$\langle n\rangle$.\texttt{ps} where $\langle n\rangle$ is the page number and that we use % the \Package{graphics} or \Package{graphicx} package\footnote{If you use an older version of -% \LaTeX{} you could use the \Package{epsf} or \Package{epsfig} package.}. +% \LaTeX{} you could use the \Package{epsf} or \Package{epsfig} package.}. % \TTindex{graphics} % \TTindex{graphicx} % \TTindex{epsf} % \TTindex{epsfig} % To put the movie in the righthandside bottom corner the following will work: -% +% % \begin{verbatim} % \fancyfoot[R]{\setlength{\unitlength}{1mm} % \begin{picture}(0,0) % \put(5,0){\includegraphics{pic\thepage.ps}} % \end{picture}} % \end{verbatim} -% +% % Notice that the \cs{unitlength} parameter should % be set locally in the fancyhdr field in order to avoid unwanted % interference with its value in the text. -% +% % \section{Thumb-indexes} % \label{sec:thumb} -% +% % \index{bible} % Some railroad guides and expensive bibles have so called % \index{thumb-index} @@ -1705,7 +2398,7 @@ % independent of the contents of the page, we print these blobs as part of % the header in a zero-sized \texttt{picture} as described in the previous % section. -% +% % Of course we have to take care of two-sided printing, and we may want to % have an index page with all the blobs in the correct position. The solution % requires some hand-tuning to get the blobs nicely spaced out vertically. @@ -1715,10 +2408,10 @@ % \cs{unitlength} set to 18~mm. Page numbers are set in the headers at the % outer sides, and the blobs are attached to these. In this example the % section numbers are used to position the blobs, but you can replace this -% with any numeric value. +% with any numeric value. % See figure~\ref{fig:overview} for the resulting % overview page and figure~\ref{fig:thumb} for the code. -% +% % \begin{figure}[htbp] % \setlength{\unitlength}{9mm} % \newcommand{\blob}{\rule[-.2\unitlength]{1\unitlength}{.5\unitlength}} @@ -1727,14 +2420,14 @@ % \put(1,-\value{line}){\blob} % \put(-7.5,-\value{line}){\arabic{line}} % \put(-7,-\value{line}){#1}} -% +% % \newcommand{\overview}{1 % \begin{picture}(0,0) % \secname{Introduction} % \secname{The first year} % \secname{Specialisation} % \end{picture}} -% +% % \begin{center} % \leavevmode % \begin{picture}(11.3,5) @@ -1749,27 +2442,27 @@ % \begin{verbatim} % \setlength{\unitlength}{18mm} % \newcommand{\blob}{\rule[-.2\unitlength]{2\unitlength}{.5\unitlength}} -% +% % \newcommand\rblob{\thepage % \begin{picture}(0,0) % \put(1,-\value{section}){\blob} % \end{picture}} -% +% % \newcommand\lblob{^^A % \begin{picture}(0,0) % \put(-3,-\value{section}){\blob} % \end{picture}^^A % \thepage} -% +% % \pagestyle{fancy} % \fancyfoot[C]{} -% +% % \newcounter{line} % \newcommand{\secname}[1]{\addtocounter{line}{1}^^A % \put(1,-\value{line}){\blob} % \put(-7.5,-\value{line}){\Large \arabic{line}} % \put(-7,-\value{line}){\Large #1}} -% +% % \newcommand{\overview}{\thepage % \begin{picture}(0,0) % \secname{Introduction} @@ -1777,7 +2470,7 @@ % \secname{Specialisation} % ...etc... % \end{picture}} -% +% % \begin{document} % \fancyhead[R]{\overview}\mbox{}\newpage % This produces the overview page % \fancyhead[R]{} % Front matter may follow here @@ -1791,9 +2484,9 @@ % \caption{Thumb-index code} % \label{fig:thumb} % \end{figure} -% +% % \section{Float placement} -% +% % Floats are page elements that float with respect to the rest of the % document. Standard floats are tables and figures, but with the % \Package{float} package you can easily make new ones, like algorithms. Most @@ -1803,7 +2496,7 @@ % however be some pathological cases where it is impossible to convince % \LaTeX{} to do things your way. In the following we will use figures as an % example but everything applies to other floats as well. -% +% % The most encountered problems with floats are: % \begin{enumerate} % \item You want a float at a certain position in the text, but \LaTeX{} @@ -1812,7 +2505,7 @@ % the document or the end of a chapter. % \item \LaTeX{} complains about ``Too many floats''. % \end{enumerate} -% +% % In the first two cases you must first check if you have given the correct % ``placement'' parameter to you float, e.g. \Cmd{begin\{figure\}[htp]} % specifies that your figure may be placed either: Here (i.e. in the text @@ -1821,7 +2514,7 @@ % could also have specified ``b'' for Bottom of the page. The order of the % letters is insignificant, you cannot force \LaTeX{} to try Bottom first % and then Top by specifying \texttt{[bt]}. -% +% % If \LaTeX{} doesn't put the float at the place where you expected it, it is % usually caused by the following: % \begin{enumerate} @@ -1858,13 +2551,13 @@ % \bs bottomfraction & max fraction of page for floats at bottom & 0.3 \\ % \bs textfraction & min fraction of page for text & 0.2 \\ % \bs floatpagefraction & min fraction of floatpage that should have -% floats & 0.5 \\ +% floats & 0.5 \\ % \bottomrule % \end{tabular} % \end{center} -% +% % There are also some others for double column floats in two-column documents. -% +% % The values in the righthand column are the defaults for the standard % \latex/ classes. Other classes could use different defaults. As you see % with the default values a float will not be put in the bottom of a page if @@ -1883,18 +2576,18 @@ % \end{verbatim} % You may want to be careful not to make \cs{floatpagefraction} too small, % otherwise you may get too many small floatpages. -% +% % You can force \latex/ to ignore most of the parameters for one specific float % occurrence by % including an exclamation mark (!) in the placement parameters, e.g. % \begin{verbatim} % \begin{figure}[!htb] % \end{verbatim} -% +% % Floats which contain a ``\texttt{t}'' in the position parameter could be % placed before the place where they are referenced (but on the same page). % This is normal behaviour for \latex/ but some people just don't like it. -% There are a number of ways to prevent this: +% There are a number of ways to prevent this: % \begin{enumerate} % \item Of course deleting the ``\texttt{t}'' will help, but in general this is % undesirable, as you may want the float to be placed at the top of the @@ -1906,20 +2599,20 @@ % moved to the next page. This can also be done with \texttt{[b]} or % without parameter for all floats on this page. % \end{enumerate} -% +% % If in spite of all your attempts \latex/ still moves your floats to the end % of the document or the end of a chapter, you can insert a \cs{clearpage} % command. This will start a new page and insert all pending floats before % continueing. If it is undesirable to have a pagebreak you can use the % \Package{afterpage} package and the following command: % \begin{verbatim} -% \afterpage{clearpage} +% \afterpage{\clearpage} % \end{verbatim} -% +% % This will wait until the current page is finished and then flush all % outstanding floats. In some pathological circumstances \Package{afterpage} % may give strange results, however. -% +% % Finally, if you want a float only at the place where you define it, without % \latex/ moving it whatsoever, you can use the \Package{float} package and % give the command: @@ -1935,7 +2628,7 @@ % \begin{verbatim} % \afterpage{\clearpage \begin{figure}[H] ... \end{figure}} % \end{verbatim} -% +% % Complaints from \latex/ about ``Too many floats'' are usually caused by one % of the above problems: floats not being able to be placed and \latex/ % collecting too many of them. The solutions given above, especially those @@ -1945,9 +2638,9 @@ % this number. If you need still more then you must edit a private copy of % this file, but even then there will be some limit that you cannot pass. % Then your only resort will be to change your document. -% +% % \section{Multipage Floats} -% +% % \LaTeX's floats cannot be split across pages. Sometimes, however, you want % to have a table or figure that doesn't fit on one page. The easiest way is % to split these into multiple table or figure environments, but this has a @@ -1958,12 +2651,12 @@ % \item How do you keep them together? % \item You don't want more than one entry in the list of figures/tables. % \end{itemize} -% +% % Although these problems are not fully solvable in all cases, here are a % couple of suggestions: -% +% % \subsection{Tables} -% +% % For tables longer than a page you can use the \Package{longtable} package. % \TTindex{longtable} % This package defines a \texttt{longtable} environment that is a kind of @@ -1990,16 +2683,16 @@ % \end{verbatim} % The last form has the additional advantage that most of the outstanding % floats will be printed first. -% -% +% +% % \subsection{Figures} -% +% % There isn't an equivalent \texttt{longfigure} solution, so for figures you % will usually have to split it yourself. In general this is less of a % problem. However, the problem you get now is how to keep them together, % i.e. how to get the parts on subsequent pages, and how to get a single % entry in the list of figures. -% +% % You will have to split the figure into pieces and put each part % in a separate \texttt{figure} environment. To keep them together it is best % to use only the \texttt{[p]} placement, so that they will be put on @@ -2027,13 +2720,13 @@ % \end{center} % \end{figure} % \end{verbatim} -% +% % You have to make sure that the last part is big enough, otherwise \LaTeX{} % could decide to postpone it until it has collected some more floats. This % can be done either by making the figure big enough (e.g. by adding some -% \cs{vspace}), or by tweaking the \cs{floatpagefraction} +% \cs{vspace}), or by tweaking the \cs{floatpagefraction} % \CmdIndex{floatpagefraction} parameter. -% +% % If you want your multipage figure to start at a lefthand-side % (even-numbered) page you can use a test in the \cs{afterpage} command % (using the \Package{ifthen} package): @@ -2044,18 +2737,18 @@ % \end{verbatim} % If there are too many floats on the skipped page, this may still fail to % start your multipage figure on an even page, however. -% +% % \section{Deprecated commands} % \label{sec:depr} -% +% % This section contains the description of deprecated commands. These % were parts of the original implementation of \Package{fancyheadings}. -% They continue to work for compatibility reasons, +% They continue to work for compatibility reasons, % but it is recommended not to use them anymore. This description is % given so that you know what they mean and how to convert them to the % standard commands. To be honest, I use these sometimes myself in quick % examples, because \cs{lhead} is less typing than \Cmd{fancyhead[L]}. -% +% % These commands for specifying the header or footer fields and their translation to % the modern commands are given in table~\ref{tab:depr}. % @@ -2108,7 +2801,7 @@ % The \cs{fancyplain} command is only useful within the pagestyle \texttt{fancyplain}. % Nowadays you would just redefine pagestyle \texttt{plain} with the % \Cmd{fancypagestyle\{plain\}\{xxxx\}} command (see section~\ref{sec:pagestyle-plain}). -% +% % \CmdIndex{plainheadrulewidth} % \CmdIndex{plainfootrulewidth} % There are also \cs{plainheadrulewidth} and \cs{plainfootrulewidth} @@ -2118,15 +2811,20 @@ % redefine pagestyle \texttt{plain} with the \cs{fancypagestyle} command. % % \section{Contact information} -% -% Piet van Oostrum\\ -% E-mail: piet@vanoostrum.org \\ -% WWW: http://piet.vanoostrum.org -% +% +% Pieter van Oostrum\\ +% E-mail: pieter@vanoostrum.org \\ +% WWW: http://pieter.vanoostrum.org +% \\[1ex] +% The source code can be found on Github:\\ +% \url{https://github.com/pietvo/fancyhdr}\\ +% Bugs and suggestions for improvements can be reported at\\ +% \url{https://github.com/pietvo/fancyhdr/issues} +% % \section{Version information} % \begin{itemize} -% \item Version 1.0. March 11, 2003. This is the version that was distributed for a -% long time on CTAN. Version history before this has been lost. +% \item Version 1.0. March 11, 2003. This is the version that was distributed for a +% long time on CTAN. Version history before this has been lost. % \item Version 2.0. August 27, 2016: % \begin{itemize} % \item Removed references to fixmarks.sty as that is no longer used. @@ -2171,6 +2869,44 @@ % vertical space outside of the definition of \cs{footrule}. % \end{itemize} % \end{itemize} +% \subsection{Changes in version 4} +% \label{sec:version-4} +% Version 4 is a significant rewrite of the package. It also introduces +% a number of new features. +% \begin{itemize} +% \item Version 4.0, March 15, 2020--Jan 04, 2021 +% \begin{itemize} +% \item Options introduced on the \cs{usepackage} command. +% \item The check whether the header or footer fits in +% \cs{headheight} and \cs{footskip}, respectively, no longer +% adjusts these values for the following pages. This appeared to be too +% confusing. However, when the package option \texttt{compatV3} is given, the old +% behaviour is kept. \\ +% The \texttt{nocheck} option now eliminates these checks completely, on +% your own risk. (See section~\ref{sec:warning} on page~\pageref{page:warning}.) +% \item Eliminated global definitions. All definitions are now local. +% The \cs{global} case was originally so that you could do definitions in +% a group and they would be applied globally. This was a mistake. If +% you make them locally they should stay local. And it caused +% problems with switching page styles, because then the global style +% would be changed, which you generally don't want.\\ +% However, when the package option \texttt{compatV3} is given, the old +% behaviour is kept. (See section~\ref{sec:options}.) +% \item The page style \texttt{fancydefault}. +% \item The \cs{headruleskip} parameter. +% \item The \cs{fancyheadinit}, \cs{fancyfootinit}, and +% \cs{fancyhfinit} commands. +% \item[] \textbf{Note:} The following changes were mostly copied from the +% \texttt{nccfancyhdr} package by Alexander I. Rozhenko. +% \item The \cs{fancycenter} command (section~\ref{sec:fancycenter}). +% \item The \texttt{headings} and \texttt{myheadings} package options +% (see section~\ref{sec:options}). +% \item The \cs{fancypagestyle} command has an optional parameter \oarg{base-style}. +% +% \end{itemize} +% +% \end{itemize} +% % % \StopEventually{% % \PrintChanges @@ -2185,6 +2921,7 @@ % % % \section{Large chapter/section titles} +% \label{sec:longtitles} % % \index{long titles} % Sometimes a chapter or section title is too large to fit in the header @@ -2379,69 +3116,69 @@ % %<*fancyhdr> % \changes{fancyhdr v1.4}{1994/09/16}{Correction for use with \cs{reversemarginpar}} -% +% % \changes{fancyhdr v1.5}{1994/09/29}{Added the \cs{iftopfloat}, % \cs{ifbotfloat} and \cs{iffloatpage} commands} -% +% % \changes{fancyhdr v1.6}{1994/10/04}{Reset single spacing in headers/footers for use with % \Package{setspace.sty} or \Package{doublespace.sty}} -% +% % \changes{fancyhdr v1.7}{1994/10/04}{Changed \cs{let}\cs{@mkboth}\cs{markboth} to % \texttt{\cs{def}\cs{@mkboth}\{\cs{protect}\cs{markboth}\}} to make it more robust.} -% +% % \changes{fancyhdr v1.8}{1994/12/05}{corrections for % \Package{amsbook}/\Package{amsart}: define \cs{@chapapp} and (more % importantly) use the \cs{chapter/sectionmark} definitions from \texttt{ps@headings} if % they exist (which should be true for all standard classes).} -% -% \changes{fancyhdr v1.9}{1995/03/31}{The proposed +% +% \changes{fancyhdr v1.9}{1995/03/31}{The proposed % \texttt{\cs{renewcommand}\{\cs{headrulewidth}\}} \texttt{\{\cs{iffloatpage}\ldots} % construction in the doc did not work properly with the \texttt{fancyplain} style.} -% -% \changes{fancyhdr v1.91}{1995/06/01}{The definition of \cs{@mkboth} wasn't +% +% \changes{fancyhdr v1.91}{1995/06/01}{The definition of \cs{@mkboth} wasn't % restored on subsequent \texttt{\cs{pagestyle}\{fancy\}}'s.} -% +% % \changes{fancyhdr v1.92}{1995/06/01}{The sequence % \texttt{\cs{pagestyle}\{fancyplain\} \cs{pagestyle}\{plain\} % \cs{pagestyle}\{fancy\}} would erroneously select the plain version.} -% +% % \changes{fancyhdr v1.93}{1995/06/01}{\cs{fancypagestyle} command added.} -% +% % \changes{fancyhdr v1.94}{1995/12/11}{(suggested by Conrad Hughes % \texttt{<chughes@maths.tcd.ie!>}): added \cs{footruleskip} to allow control over footrule % position (old hardcoded value of .3\cs{normalbaselineskip} is far too high % when used with very small footer fonts).} -% -% \changes{fancyhdr v1.95}{1996/01/31}{call \cs{@normalsize} in the reset code if that is defined, +% +% \changes{fancyhdr v1.95}{1996/01/31}{call \cs{@normalsize} in the reset code if that is defined, % otherwise \cs{normalsize}. This is to solve a problem with % \Package{ucthesis.cls}, as this doesn't define \cs{@currsize}. % Unfortunately for latex209 calling \cs{normalsize} doesn't % work as this is optimized to do very little, so there \cs{@normalsize} should % be called. Hopefully this code works for all versions of LaTeX known to % mankind.} -% -% \changes{fancyhdr v1.96}{1996/04/25}{Initialize \cs{headwidth} to a +% +% \changes{fancyhdr v1.96}{1996/04/25}{Initialise \cs{headwidth} to a % magic (negative) value to catch most common cases that people change -% it before calling \texttt{\cs{pagestyle}\{fancy\}}. -% Note it can't be initialized when reading in this file, because +% it before calling \texttt{\cs{pagestyle}\{fancy\}}. +% Note it can't be initialised when reading in this file, because % \cs{textwidth} could be changed afterwards. This is quite probable. % We also switch to \cs{MakeUppercase} rather than \cs{uppercase} and introduce a % \cs{nouppercase} command for use in headers. and footers.} -% +% % \changes{fancyhdr v1.97}{1996/05/03}{Two changes: \\ % 1. Undo the change in version 1.8 -% (using the \texttt{\cs{pagestyle}\{headings\}} defaults +% (using the \texttt{\cs{pagestyle}\{headings\}} defaults % for the chapter and section marks). The current version of amsbook and % amsart classes don't seem to need them anymore. Moreover the standard % \LaTeX{} classes don't use \cs{markboth} if twoside isn't selected, and this is % confusing as \cs{leftmark} doesn't work as expected.\\ % 2. Include a call to \cs{ps@empty} -% in \cs{ps@@fancy}. This is to solve a problem +% in \cs{ps@@fancy}. This is to solve a problem % in the amsbook and amsart classes, that make global changes to \cs{topskip}, % which are reset in \cs{ps@empty}. Hopefully this doesn't break other things.} -% +% % \changes{fancyhdr v1.98}{1996/05/07}{Added \% after the line \cs{def}\cs{nouppercase}} -% +% % \changes{fancyhdr v1.99}{1996/05/07}{This is the alpha version of fancyhdr 2.0\\ % Introduced the new commands \cs{fancyhead}, \cs{fancyfoot}, and \cs{fancyhf}. % Changed \cs{headrulewidth}, \cs{footrulewidth}, \cs{footruleskip} to @@ -2450,31 +3187,31 @@ % to have them as length registers unless you want to do calculations with % them, which is unlikely. Note that this may make some uses of them % incompatible (i.e. if you have a file that uses \cs{setlength} or \cs{xxxx}!=)} -% +% % \changes{fancyhdr v1.99a}{1996/05/10}{Added a few more \% signs.} -% +% % \changes{fancyhdr v1.99b}{1996/05/10}{Changed the syntax of % \cs{f@nch@for} to be resistent to catcode changes of \texttt{:!=}.\protect\\ % Removed the \texttt{[1]} from the defs of \cs{lhead} etc. because the parameter is % consumed by the \cs{@[xy]lhead} etc. macros.} -% +% % \changes{fancyhdr v1.99c}{1997/06/24}{Corrected \cs{nouppercase} to -% also include the protected form of \cs{MakeUppercase}.\\ +% also include the protected form of \cs{MakeUppercase}.\\ % \cs{global} added to manipulation of \cs{headwidth}.\\ % \cs{iffootnote} command added.\\ % Some comments added about \cs{f@nch@head} and \cs{f@nch@foot}.} -% +% % \changes{fancyhdr v1.99d}{1998/08/24}{Changed the default % \cs{ps@empty} to \cs{ps@@empty} in order to allow % \texttt{\cs{fancypagestyle}\{empty\}} redefinition.} -% +% % \changes{fancyhdr v2.0}{2000/10/11}{Added LPPL license clause.\\ % A check for \cs{headheight} is added. An errormessage is given (once) if the % header is too large. Empty headers don't generate the error even if % \cs{headheight} is very small or even 0pt. \\ % Warning added for the use of '\texttt{E}' option when twoside option is not used. % In this case the '\texttt{E}' fields will never be used.} -% +% % \changes{fancyhdr v2.1beta}{2002/03/10}{New command: % \texttt{\cs{fancyhfoffset}[place]\{length\}} defines offsets to be applied to % the header/footer to let it stick into the margins (if length $!>$ 0). @@ -2483,9 +3220,9 @@ % area. % \cs{headwidth} will be dynamically calculated in the headers/footers when % this is used.} -% +% % \changes{fancyhdr v2.1beta2}{2002/03/26}{\cs{fancyhfoffset} now also -% takes \texttt{H,F} as possible letters in the argument to +% takes \texttt{H,F} as possible letters in the argument to % allow the header and footer widths to be different.\\ % New commands \cs{fancyheadoffset} and \cs{fancyfootoffset} added comparable to % \cs{fancyhead} and \cs{fancyfoot}.\\ @@ -2502,28 +3239,28 @@ % \changes{fancyhdr v3.1}{2004/10/07}{Added '\texttt{\cs{endlinechar}!=13}' to % \cs{f@nch@reset} to prevent problems with \cs{includegraphics} in % header/footer when \environment{verbatiminput} is active.} -% +% % \changes{fancyhdr v3.2}{2005/03/22}{Reset \cs{everypar} (the real one) % in \cs{f@nch@reset} because spanish.ldf does strange things with % \cs{everypar} between \guillemotleft\ and \guillemotright.} -% +% % \changes{fancyhdr v3.3}{2016/08/20}{Replace -% `\texttt{\cs{@ifundefined}\{chapter\}}' with `\cs{ifx}\cs{chapter}\cs{@undefined}' +% `\texttt{\cs{@ifundefined}\{chapter\}}' with `\cs{ifx}\cs{chapter}\cs{@undefined}' % because the former subtly makes \cs{chapter} equal to \cs{relax}, which may be % undesirable in some cases.} -% +% % \changes{fancyhdr v3.4}{2016/08/21}{Replace \cs{rm} by % \cs{normalfont}\cs{rmfamily} and \cs{sl} by \cs{normalfont}\cs{slshape}.} -% +% % \changes{fancyhdr v3.5}{2016/08/21}{Don't define \cs{footruleskip} if it is already defined.} -% +% % \changes{fancyhdr v3.6}{2016/08/27}{Added a \cs{ProvidesPackage} line.\\ % Updated contact information.} -% +% % \changes{fancyhdr v3.7}{2016/08/28}{Removed \cs{normalfont} from default values, as every field % is already initialised with \cs{normalfont}.\\ % Set \cs{hsize} to \cs{headwidth} in header/footer.} -% +% % \changes{fancyhdr v3.8}{2016/09/06}{Reset \bsbs, \cs{raggedleft}, % \cs{raggedright} and \cs{centering} to their default values to avoid a % clash with the tabu package.\\ @@ -2538,25 +3275,57 @@ % \begin{macro}{\if@nch@mpty} % This macro tests if its argument is empty. % \begin{macrocode} -\def\if@nch@mpty#1{\def\temp@a{#1}\ifx\temp@a\@empty} +\newcommand\if@nch@mpty[1]{\def\temp@a{#1}\ifx\temp@a\@empty} % \end{macrocode} % \end{macro} -% -% \begin{macro}{\f@nch@def} -% This macro defines another macro (usually a header or footer field). -% Depending on the value of \cs{f@nch@gbl} the definition will be -% global or local (the latter case is used in \cs{fancypagestyle}). If -% the value (argument 2) is empty, a \cs{leavevmode} will be substituted. -% If it is not empty, a \cs{strut} will be added. +% +% \begin{macro}{\iff@nch@check} +% Boolean for the \texttt{nocheck} option. +% \changes{fancyhdr v4.0}{2019/03/15}{Implement the \texttt{nocheck} option} +% \OPTindex{nocheck} % \begin{macrocode} -\def\f@nch@def#1#2{\if@nch@mpty{#2}\f@nch@gbl\def#1{\leavevmode}\else - \f@nch@gbl\def#1{#2\strut}\fi} +\newif\iff@nch@check +\f@nch@checktrue +\DeclareOption{nocheck}{% + \f@nch@checkfalse +} % \end{macrocode} % \end{macro} +% +% \begin{macro}{\iff@nch@compatViii} +% Define \cs{iff@nch@compatViii} to track the \texttt{compatV3} option. +% \begin{macrocode} +\newif\iff@nch@compatViii +% \end{macrocode} % \begin{macro}{\f@nch@gbl} -% Initialize \cs{f@nch@gbl} to \cs{global}. +% Initialise \cs{f@nch@gbl} to do nothing (except with the \texttt{compatV3} +% option). +% \changes{fancyhdr v4.0}{2019/03/19}{Remove the \cs{global} in definitions} +% \changes{fancyhdr v4.0}{2019/03/16}{Implement the \texttt{compatV3} option} +% \begin{macrocode} +\let\f@nch@gbl\relax +\DeclareOption{compatV3}{% + \let\f@nch@gbl\global + \f@nch@compatViiitrue +} +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\f@nch@def} +% This macro defines another macro (usually a header or footer field). +% Depending on the value of \cs{f@nch@gbl} the definition will be +% global or local. +% Default it is always local. But with the \texttt{compatV3} option it +% is \cs{global} in the normal definitions, and local in \cs{fancypagestyle}. +% The \cs{global} case is now considered a bug (or at least undesirable). +% +% If the value (argument 2) is empty, a \cs{leavevmode} will be substituted. +% If it is not empty, a \cs{strut} will be added. +% % \begin{macrocode} -\let\f@nch@gbl\global +\newcommand\f@nch@def[2]{\if@nch@mpty{#2}\f@nch@gbl\def#1{\leavevmode}\else + \f@nch@gbl\def#1{#2\strut}\fi} % \end{macrocode} % \end{macro} % @@ -2584,22 +3353,148 @@ % \end{macrocode} % \end{macro} % +% \changes{fancyhdr v4.0}{2019/03/17}{Added \texttt{headings} and +% \texttt{myheadings} options.} +% Standard styles are redefined optionally. These definitions are +% borrowed from the \Package{nccfancyhdr} package by by Alexander I. Rozhenko. +% +% \begin{macro}{\ps@myheadings} +% The redefinition of the \texttt{myheadings} style is conditional. +% We test the existence of the \cs{chapter} command and redefine the +% style accordingly. +% +% \OPTindex{myheadings}\PSindex{myheadings} +% \begin{macrocode} +\DeclareOption{myheadings}{% + \f@nch@ifundefined{chapter}{% +% \end{macrocode} +% An article-like class without chapters: +% \begin{macrocode} + \def\ps@myheadings{\ps@f@nch@fancyproto \let\@mkboth\@gobbletwo + \fancyhf{} + \fancyhead[LE,RO]{\thepage}% + \fancyhead[RE]{\slshape\leftmark}% + \fancyhead[LO]{\slshape\rightmark}% + \let\sectionmark\@gobble + \let\subsectionmark\@gobble + }% + }% +% \end{macrocode} +% A book/report-like class with chapters: +% \begin{macrocode} + {\def\ps@myheadings{\ps@f@nch@fancyproto \let\@mkboth\@gobbletwo + \fancyhf{} + \fancyhead[LE,RO]{\thepage}% + \fancyhead[RE]{\slshape\leftmark}% + \fancyhead[LO]{\slshape\rightmark}% + \let\chaptermark\@gobble + \let\sectionmark\@gobble + }% + }% +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\ps@headings} +% The redefinition of the \texttt{headings} style also differs for +% book-like and article-like classes. It also differs for +% one-side and two-side modes. +% \begin{macrocode} +\DeclareOption{headings}{% + \f@nch@ifundefined{chapter}{% + \if@twoside +% \end{macrocode} +% An article in two-side mode: +% \begin{macrocode} + \def\ps@headings{\ps@f@nch@fancyproto \let\@mkboth\markboth + \fancyhf{} + \fancyhead[LE,RO]{\thepage}% + \fancyhead[RE]{\slshape\leftmark}% + \fancyhead[LO]{\slshape\rightmark}% + \def\sectionmark##1{% + \markboth{\MakeUppercase{% + \ifnum \c@secnumdepth >\z@ \thesection\quad \fi##1}}{}}% + \def\subsectionmark##1{% + \markright{% + \ifnum \c@secnumdepth >\@ne \thesubsection\quad \fi##1}}% + }% + \else +% \end{macrocode} +% An article in one-side mode: +% \begin{macrocode} + \def\ps@headings{\ps@f@nch@fancyproto \let\@mkboth\markboth + \fancyhf{} + \fancyhead[LE,RO]{\thepage}% + \fancyhead[RE]{\slshape\leftmark}% + \fancyhead[LO]{\slshape\rightmark}% + \def\sectionmark##1{% + \markright {\MakeUppercase{% + \ifnum \c@secnumdepth >\z@ \thesection\quad \fi##1}}}% + \let\subsectionmark\@gobble % Not needed but inserted for safety + }% + \fi + }{\if@twoside +% \end{macrocode} +% A book in two-side mode: +% \begin{macrocode} + \def\ps@headings{\ps@f@nch@fancyproto \let\@mkboth\markboth + \fancyhf{} + \fancyhead[LE,RO]{\thepage}% + \fancyhead[RE]{\slshape\leftmark}% + \fancyhead[LO]{\slshape\rightmark}% + \def\chaptermark##1{% + \markboth{\MakeUppercase{% + \ifnum \c@secnumdepth >\m@ne \if@mainmatter + \@chapapp\ \thechapter. \ \fi\fi##1}}{}}% + \def\sectionmark##1{% + \markright {\MakeUppercase{% + \ifnum \c@secnumdepth >\z@ \thesection. \ \fi##1}}}% + }% + \else +% \end{macrocode} +% A book in one-side mode: +% \begin{macrocode} + \def\ps@headings{\ps@f@nch@fancyproto \let\@mkboth\markboth + \fancyhf{} + \fancyhead[LE,RO]{\thepage}% + \fancyhead[RE]{\slshape\leftmark}% + \fancyhead[LO]{\slshape\rightmark}% + \def\chaptermark##1{% + \markright{\MakeUppercase{% + \ifnum \c@secnumdepth >\m@ne \if@mainmatter + \@chapapp\ \thechapter. \ \fi\fi##1}}}% + \let\sectionmark\@gobble % Not needed but inserted for safety + }% + \fi + }% +} +% \end{macrocode} +% \end{macro} +% +% Process the options. +% \changes{fancyhdr v4.0}{2019/03/15}{Process package options.} +% \SpecialUsageIndex{\ProcessOptions} +% \begin{macrocode} +\ProcessOptions* +% \end{macrocode} +% % \begin{macro}{\f@nch@errmsg} % This macro generates an error message. -% \changes{fancyhdr v3.10}{2019/01/25}{Use \cs{\f@nch@ifundefined} instead of \cs{ifx}.} +% \changes{fancyhdr v3.10}{2019/01/25}{Use \cs{f@nch@ifundefined} instead of \cs{ifx}.} % \changes{fancyhdr v3.10}{2019/01/25}{Use \cs{newcommand} instead of \cs{def}.} % \begin{macrocode} \newcommand\f@nch@errmsg[1]{% - \f@nch@ifundefined{PackageError}{\errmessage{#1}}{\PackageError{Fancyhdr}{#1}{}}} + \f@nch@ifundefined{PackageError}{\errmessage{#1}}{\PackageError{fancyhdr}{#1}{}}} % \end{macrocode} % \end{macro} +% % \begin{macro}{\f@nch@warning} % This macro generates a warning. % \changes{fancyhdr v3.10}{2019/01/25}{Use \cs{f@nch@ifundefined} instead of \cs{ifx}.} % \changes{fancyhdr v3.10}{2019/01/25}{Use \cs{newcommand} instead of \cs{def}.} % \begin{macrocode} \newcommand\f@nch@warning[1]{% - \f@nch@ifundefined{PackageWarning}{\errmessage{#1}}{\PackageWarning{Fancyhdr}{#1}{}}} + \f@nch@ifundefined{PackageWarning}{\errmessage{#1}}{\PackageWarning{fancyhdr}{#1}{}}} % \end{macrocode} % \end{macro} % @@ -2610,10 +3505,10 @@ % This is similar to \LaTeX's \cs{@tfor}, but it expands the \texttt{charstring}. % \begin{macrocode} % \changes{fancyhdr v3.10}{2019/01/25}{Use \cs{newcommand} instead of \cs{def}.} -\newcommand{\f@nch@forc}[3]{\expandafter\f@rc\expandafter#1\expandafter{#2}{#3}} -\newcommand{\f@rc}[3]{\def\temp@ty{#2}\ifx\@empty\temp@ty\else +\newcommand{\f@nch@forc}[3]{\expandafter\f@nchf@rc\expandafter#1\expandafter{#2}{#3}} +\newcommand{\f@nchf@rc}[3]{\def\temp@ty{#2}\ifx\@empty\temp@ty\else \f@nch@rc#1#2\f@nch@rc{#3}\fi} -\def\f@nch@rc#1#2#3\f@nch@rc#4{\def#1{#2}#4\f@rc#1{#3}{#4}} +\def\f@nch@rc#1#2#3\f@nch@rc#4{\def#1{#2}#4\f@nchf@rc#1{#3}{#4}} % \end{macrocode} % \end{macro} % \begin{macro}{\f@nch@for} @@ -2641,7 +3536,7 @@ \ifx\@empty#1\def#1{#2}\fi} % \end{macrocode} % \end{macro} -% +% % \begin{macro}{\f@nch@ifin} % Usage: \cs{f@nch@ifin} \meta{char} \meta{set} \meta{truecase} \meta{falsecase} \\ % If \meta{char} is in \meta{set}, then \meta{truecase} else \meta{falsecase}. @@ -2718,14 +3613,14 @@ e\f@nch@warning {\string#1's `E' option without twoside option is useless}\fi\fi \f@nch@default\f@nch@@lcr{lcr}\temp@c \f@nch@default\f@nch@@hf{hf}{#2\temp@c}% - \f@nch@forc\f@nch@eo\f@nch@@eo - {\f@nch@forc\f@nch@lcr\f@nch@@lcr + \f@nch@forc\f@nch@eo\f@nch@@eo + {\f@nch@forc\f@nch@lcr\f@nch@@lcr {\f@nch@forc\f@nch@hf\f@nch@@hf {\expandafter\f@nch@def\csname f@nch@\f@nch@eo\f@nch@lcr\f@nch@hf\endcsname {#4}}}}}} % \end{macrocode} % \end{macro} -% +% % \begin{macro}{\f@nch@fancyhfoffs} % This macro interprets the parameters for the header and footer % offsets.\\ @@ -2739,7 +3634,7 @@ % The header and footer offsets are stored in command sequences with % names of the form: \cs{f@nch@O@}\meta{x}\meta{y}\meta{z} with \meta{x} from % \texttt{[eo]}, \meta{y} from \texttt{[lr]} and \meta{z} from \texttt{[hf]}. -% +% % \begin{macrocode} \def\f@nch@fancyhfoffs#1#2[#3]#4{% \def\temp@c{}% @@ -2753,7 +3648,7 @@ e\f@nch@warning {\string#1's `E' option without twoside option is useless}\fi\fi \f@nch@default\f@nch@@lcr{lr}\temp@c \f@nch@default\f@nch@@hf{hf}{#2\temp@c}% - \f@nch@forc\f@nch@eo\f@nch@@eo + \f@nch@forc\f@nch@eo\f@nch@@eo {\f@nch@forc\f@nch@lcr\f@nch@@lcr {\f@nch@forc\f@nch@hf\f@nch@@hf {\expandafter\setlength\csname @@ -2821,28 +3716,28 @@ % \begin{macro}{\f@nch@headwidth} % Length parameter to be used for \cs{headwidth}. We use this rather % than defining \cs{headwidth} as a length paramater directly to protect -% ourself to someone saying: \verb+\let\headwidth\textwidth+. +% ourself to someone saying: \verb+\let\headwidth\textwidth+. % \begin{macrocode} \newlength{\f@nch@headwidth} \let\headwidth\f@nch@headwidth % \end{macrocode} % \end{macro} -% \begin{macro}{\f@nch@O@elh} -% \begin{macro}{\f@nch@O@erh} +% \begin{macro}{\f@nch@O@elh} +% \begin{macro}{\f@nch@O@erh} % \begin{macro}{\f@nch@O@olh} -% \begin{macro}{\f@nch@O@orh} -% \begin{macro}{\f@nch@O@elf} +% \begin{macro}{\f@nch@O@orh} +% \begin{macro}{\f@nch@O@elf} % \begin{macro}{\f@nch@O@erf} -% \begin{macro}{\f@nch@O@olf} +% \begin{macro}{\f@nch@O@olf} % \begin{macro}{\f@nch@O@orf} % Length parameters for the offsets. % \begin{macrocode} -\newlength{\f@nch@O@elh} -\newlength{\f@nch@O@erh} +\newlength{\f@nch@O@elh} +\newlength{\f@nch@O@erh} \newlength{\f@nch@O@olh} -\newlength{\f@nch@O@orh} -\newlength{\f@nch@O@elf} +\newlength{\f@nch@O@orh} +\newlength{\f@nch@O@elf} \newlength{\f@nch@O@erf} -\newlength{\f@nch@O@olf} +\newlength{\f@nch@O@olf} \newlength{\f@nch@O@orf} % \end{macrocode} % \end{macro} @@ -2853,16 +3748,25 @@ % \end{macro} % \end{macro} % \end{macro} -% +% % \begin{macro}{\headrulewidth} % \begin{macro}{\footrulewidth} % \begin{macrocode} -\newcommand{\headrulewidth}{0.4pt} +\newcommand{\headrulewidth}{0.4pt} \newcommand{\footrulewidth}{0pt} % \end{macrocode} % \end{macro} % \end{macro} -% +% +% \begin{macro}{\headruleskip} +% Don't define \cs{headruleskip} if it is already defined. +% \changes{fancyhdr v4.0}{2019/03/22}{Parameter \cs{headruleskip}.} +% \begin{macrocode} +\f@nch@ifundefined{headruleskip}% + {\newcommand{\headruleskip}{0pt}}{} +% \end{macrocode} +% \end{macro} +% % \begin{macro}{\footruleskip} % Memoir also defines \cs{footruleskip}. % Don't define \cs{footruleskip} if it is already defined. @@ -2871,7 +3775,7 @@ {\newcommand{\footruleskip}{.3\normalbaselineskip}}{} % \end{macrocode} % \end{macro} -% +% % \begin{macro}{\plainheadrulewidth} % \begin{macro}{\plainfootrulewidth} % Fancyplain stuff shouldn't be used anymore (rather @@ -2884,14 +3788,14 @@ % \end{macrocode} % \end{macro} % \end{macro} -% +% % \begin{macro}{\if@fancyplain} % Boolean for the implementation of \cs{fancyplain} % \begin{macrocode} \newif\if@fancyplain \@fancyplainfalse % \end{macrocode} % \end{macro} -% +% % \begin{macro}{\fancyplain} % Deprecated macro % \begin{macrocode} @@ -2900,7 +3804,7 @@ % \end{macro} % % \begin{macro}{\headwidth} -% Initialize \cs{headwidth} with a magic constant. +% Initialise \cs{headwidth} with a magic constant. % \begin{macrocode} \headwidth=-123456789sp % \end{macrocode} @@ -2915,7 +3819,7 @@ % typesetting the headers and footers. Some packages change these to % incompatible values. % \begin{macrocode} -\let\f@nch@raggedleft\raggedleft +\let\f@nch@raggedleft\raggedleft \let\f@nch@raggedright\raggedright \let\f@nch@centering\centering \let\f@nch@everypar\everypar @@ -2952,22 +3856,122 @@ % \end{macrocode} % \end{macro} % -% Initialization of the head and foot text. +% \begin{macro}{\fancycenter} +% \changes{fancyhdr v4.0}{2019/03/15}{Macro \cs{fancycenter} added} +% \cs{fancycenter}\oarg{dist}\oarg{stretch}\marg{left-mark}\marg{center-mark}\marg{right-mark} +% \begin{macrocode} +\newcommand*{\fancycenter}[1][1em]{% + \@ifnextchar[{\f@nch@center{#1}}{\f@nch@center{#1}[3]}% +} +\def\f@nch@center#1[#2]#3#4#5{% +% \end{macrocode} +% At first, we execute the case when the \meta{center-mark} is empty: +% \begin{macrocode} + \def\@tempa{#4}\ifx\@tempa\@empty + \hbox to\linewidth{\color@begingroup{#3}\hfil {#5}\color@endgroup}% + \else +% \end{macrocode} +% All we need to do is to calculate skips inserted before and after +% \meta{center-mark}. We will calculate them in the |\@tempskipa| +% and |\@tempskipb|. At first: +% \begin{quote} +% \verb|\@tempdima:=|\meta{dist};\\ +% \verb|\@tempdimb:=|\meta{dist}\verb|*|\meta{stretch};\\ +% \verb|\@tempdimc:=|\meta{dist}\verb|*|\meta{stretch}\verb|-|\meta{dist};\\ +% \verb|\@tempskipa:=\@tempskipb:=\@tempdimb + 1fil - \@tempdimc|; +% \end{quote} +% \begin{macrocode} + \setlength\@tempdima{#1}% + \setlength{\@tempdimb}{#2\@tempdima}% + \@tempdimc \@tempdimb \advance\@tempdimc -\@tempdima + \setlength\@tempskipa{\@tempdimb \@plus 1fil \@minus \@tempdimc}% + \@tempskipb\@tempskipa +% \end{macrocode} +% At this point, the \cs{@tempskipa} and \cs{@tempskipb} registers +% have the natural size \meta{dist}\verb|*|\meta{stretch}, +% unlimited stretchability, and the minimum size \meta{dist}. +% Now we decrease the minimum size of \cs{@tempskipa} to zero if +% the \meta{left-mark} is empty: +% \begin{macrocode} + \def\@tempa{#3}\ifx\@tempa\@empty + \addtolength\@tempskipa{\z@ \@minus \@tempdima}% + \fi +% \end{macrocode} +% Do the same things with the \cs{@tempskipb} register if the +% \meta{right-mark} is empty: +% \begin{macrocode} + \def\@tempa{#5}\ifx\@tempa\@empty % empty right + \addtolength\@tempskipb{\z@ \@minus \@tempdima}% + \fi +% \end{macrocode} +% Finally, we correct the left and right glues taking into +% account the difference between lengths of \meta{left-mark} +% and \meta{right-mark}. We calculate which mark is shorter +% and increase the natural size of the corresponding register +% by the difference between their lengths. +% \begin{macrocode} + \settowidth{\@tempdimb}{#3}% + \settowidth{\@tempdimc}{#5}% + \ifdim\@tempdimb>\@tempdimc + \advance\@tempdimb -\@tempdimc + \addtolength\@tempskipb{\@tempdimb \@minus \@tempdimb}% + \else + \advance\@tempdimc -\@tempdimb + \addtolength\@tempskipa{\@tempdimc \@minus \@tempdimc}% + \fi +% \end{macrocode} +% The \cs{@tempskipa} and \cs{@tempskipb} have been calculated. +% Put everything in the box. +% \begin{macrocode} + \hbox to\linewidth{\color@begingroup{#3}\hskip \@tempskipa + {#4}\hskip \@tempskipb {#5}\color@endgroup}% + \fi +} +% \end{macrocode} +% \end{macro} % -% The default values still contain \cs{fancyplain} for compatibility: -% lefthead empty on ``plain'' pages, \cs{rightmark} on even, \cs{leftmark} on odd pages; -% evenhead empty on ``plain'' pages, \cs{leftmark} on even, \cs{rightmark} on odd pages. +% \begin{macro}{\fancyheadinit} +% This macro can be used to define initialisation code that will be run +% before the construction of the header. It can for example set the +% color or the font, or change \cs{headrulewidth} or \cs{headruleskip}. +% It cannot make global changes, just changes for the header. +% \begin{macro}{\f@nch@headinit} +% Storage for the header initialisation code. % \begin{macrocode} -\fancyhf{} -\if@twoside - \fancyhead[el,or]{\fancyplain{}{\slshape\rightmark}} - \fancyhead[er,ol]{\fancyplain{}{\slshape\leftmark}} -\else - \fancyhead[l]{\fancyplain{}{\slshape\rightmark}} - \fancyhead[r]{\fancyplain{}{\slshape\leftmark}} -\fi -\fancyfoot[c]{\rmfamily\thepage} % page number +\newcommand{\f@nch@headinit}{} +\newcommand{\fancyheadinit}[1]{% + \def\f@nch@headinit{#1}% +} % \end{macrocode} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\fancyfootinit} +% This macro can be used to define initialisation code that will be run +% before the construction of the footer. It can for example set the +% color or the font, or change \cs{footrulewidth} or \cs{footruleskip}. +% It cannot make global changes, just changes for the footer. +% \begin{macro}{\f@nch@footinit} +% Storage for the footer initialisation code. +% \begin{macrocode} +\newcommand{\f@nch@footinit}{} +\newcommand{\fancyfootinit}[1]{% + \def\f@nch@footinit{#1}% +} +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\fancyhfinit} +% This macro sets both the header and the footer initialisation codes to +% the same value. +% \begin{macrocode} +\newcommand{\fancyhfinit}[1]{% + \def\f@nch@headinit{#1}% + \def\f@nch@footinit{#1}% +} +% \end{macrocode} +% \end{macro} % % \begin{macro}{\f@nch@vbox} % Make a \cs{vbox} with the header or footer. Check whether there is @@ -2980,26 +3984,46 @@ % % \changes{fancyhdr v3.10}{2019/01/25}{Don't use \cs{global}\cs{setlength}.} % \changes{fancyhdr v3.10}{2019/01/26}{Use \cs{newcommand} instead of \cs{def}.} +% \changes{fancyhdr v4.0}{2019/03/15}{Don't adjust the +% \cs{headheight}/\cs{footskip}, except when the \texttt{compatV3} option is given.} +% \changes{fancyhdr v4.0}{2019/03/15}{Don't check when the \texttt{nocheck} option is given.} % \begin{macrocode} \newcommand\f@nch@vbox[2]{% \setbox0\vbox{#2}% \ifdim\ht0>#1\relax - \f@nch@warning{% - \string#1 is too small (\the#1): ^^J% - Make it at least \the\ht0.^^J% - We now make it that large for the rest of the document.^^J% - This may cause the page layout to be inconsistent, however\@gobble - }% - \dimen0=#1\relax - \global#1=\ht0\relax - \ht0=\dimen0 % + \iff@nch@check + \dimen0=#1\advance\dimen0-\ht0 + \f@nch@warning{% + \string#1 is too small (\the#1): \MessageBreak + Make it at least \the\ht0, for example:\MessageBreak + \string\setlength{\string#1}{\the\ht0}% + \iff@nch@compatViii .\MessageBreak + We now make it that large for the rest of the document.\MessageBreak + This may cause the page layout to be inconsistent, however + \fi + \ifx#1\headheight .\MessageBreak + You might also make \topmargin smaller to compensate:\MessageBreak + \string\addtolength{\string\topmargin}{\the\dimen0}% + \fi + \@gobble + }% + \fi + \iff@nch@compatViii + \dimen0=#1\relax + \global#1=\ht0\relax + \ht0=\dimen0 % + \else + \ht0=#1% + \fi \fi \box0} % \end{macrocode} % \end{macro} % % \begin{macro}{\f@nch@head} -% \begin{macro}{\f@nch@foot} +% \changes{fancyhdr v4.0}{2019/03/22}{Parameter \cs{headruleskip}.} +% \changes{fancyhdr v4.0}{2019/03/25}{\cs{fancyheadinit} initialisation +% code added and \cs{f@nch@reset} moved up.} % Put together a header or footer given the left, center and right % text, fillers at left and right and a rule. The \cs{xlap} commands put % the text into an hbox of zero size, so overlapping text does not @@ -3015,12 +4039,15 @@ % This is the right component. \\ % 5. RIGHTSIDE BEARING. This is always \cs{relax} or \cs{hss} % (after expansion). -% +% Before constructing the header or footer, the environment is reset to +% a known state, and then the corresponding initialisation code as given +% in \cs{fancyheadinit} or \cs{fancyfootinit}, respectively, is run. % \begin{macrocode} \newcommand\f@nch@head[5]{% + \f@nch@reset + \f@nch@headinit\relax #1% \hbox to\headwidth{% - \f@nch@reset \f@nch@vbox\headheight{% \hbox{% \rlap{\parbox[b]{\headwidth}{\raggedright#2}}% @@ -3029,6 +4056,7 @@ \hfill \llap{\parbox[b]{\headwidth}{\raggedleft#4}}% }% + \vskip\headruleskip\relax \headrule }% }% @@ -3036,12 +4064,15 @@ } % \end{macrocode} % +% \begin{macro}{\f@nch@foot} % \changes{fancyhdr v3.10}{2019/01/26}{Put \cs{footrule} in a \cs{vbox} % to accommodate for flexible footrules.} % \changes{fancyhdr v3.10}{2019/01/28}{Use \cs{unvbox} on the footrule \cs{vbox} % to preserve vertical spacing.} % \changes{fancyhdr v3.10}{2019/01/28}{Move \cs{footruleskip} outside of the \cs{footrule} % definition.} +% \changes{fancyhdr v4.0}{2019/03/25}{\cs{fancyfootinit} initialisation +% code added and \cs{f@nch@reset} moved up.} % We put the \cs{footrule} in a \cs{vbox} to accommodate for flexible % footrules (e.g. using \cs{hrulefill}), so that the \cs{headwidth} will % be used as the line width. But to preserve the vertical spacing we @@ -3049,9 +4080,10 @@ % % \begin{macrocode} \newcommand\f@nch@foot[5]{% + \f@nch@reset + \f@nch@footinit\relax #1% \hbox to\headwidth{% - \f@nch@reset \f@nch@vbox\footskip{% \setbox0=\vbox{\footrule}\unvbox0 \vskip\footruleskip @@ -3070,113 +4102,179 @@ % \end{macro} % \end{macro} % -% \begin{macro}{\headrule} -% \begin{macrocode} -\def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi - \hrule\@height\headrulewidth\@width\headwidth - \vskip-\headrulewidth}} -% \end{macrocode} -% \end{macro} +% \begin{macro}{\MakeUppercase} +% Define \MakeUppercase for old \LaTeX{}en. Note: we used \cs{def} rather +% than \cs{let}, so that \verb+\let\uppercase\relax+ (from the version 1 +% documentation) will still work. % -% \begin{macro}{\footrule} -% \changes{fancyhdr v3.10}{2019/01/28}{Move \cs{footruleskip} outside of the \cs{footrule} -% definition and remove useless \cs{vskip} at the top.} % \begin{macrocode} -\def\footrule{{\if@fancyplain\let\footrulewidth\plainfootrulewidth\fi - \hrule\@width\headwidth\@height\footrulewidth}} +\f@nch@ifundefined{MakeUppercase}{\def\MakeUppercase{\uppercase}}{}% % \end{macrocode} % \end{macro} % -% \begin{macro}{\ps@fancy} -% Pagestyle \texttt{fancy} +% \begin{macro}{\@chapapp} +% Define \cs{@chapapp} for classes that don't have it, e.g. amsbook % \begin{macrocode} -\def\ps@fancy{% - \f@nch@ifundefined{@chapapp}{\let\@chapapp\chaptername}{}% for amsbook +\f@nch@ifundefined{@chapapp}{\let\@chapapp\chaptername}{}% % \end{macrocode} % \end{macro} -% -% \begin{macro}{\MakeUppercase} -% Define \MakeUppercase for old \LaTeX{}en. Note: we used \cs{def} rather -% than \cs{let}, so that \verb+\let\uppercase\relax+ (from the version 1 -% documentation) will still work. -% +% \begin{macro}{\f@nch@initialise} +% \changes{fancyhdr v4.0}{2019/03/21}{Put all the initialisation code in +% \cs{f@nch@initialise}} +% This macro initialises the headers and footers and \cs{chaptermark} +% and/or \cs{[sub]sectionmark} for pagestyle \texttt{fancy} % \begin{macrocode} -\f@nch@ifundefined{MakeUppercase}{\def\MakeUppercase{\uppercase}}{}% +\def\f@nch@initialise{% % \end{macrocode} -% \end{macro} -% +% % \begin{macro}{\chaptermark} % \begin{macro}{\sectionmark} % \begin{macro}{\subsectionmark} % Standard definitions for \cs{chaptermark}, \cs{sectionmark} and \cs{subsectionmark}. -% +% % \begin{macrocode} -\f@nch@ifundefined{chapter}% - {\def\sectionmark##1{\markboth{\MakeUppercase{\ifnum \c@secnumdepth>\z@ - \thesection\hskip 1em\relax - \fi ##1}}{}}% - \def\subsectionmark##1{\markright {\ifnum \c@secnumdepth >\@ne - \thesubsection\hskip 1em\relax \fi ##1}}}% - {\def\chaptermark##1{\markboth {\MakeUppercase{\ifnum - \c@secnumdepth>\m@ne \@chapapp\ \thechapter. \ \fi ##1}}{}}% -\def\sectionmark##1{\markright{\MakeUppercase{\ifnum \c@secnumdepth >\z@ - \thesection. \ \fi ##1}}}% -} + \f@nch@ifundefined{chapter}% + {\def\sectionmark##1{\markboth{\MakeUppercase{\ifnum \c@secnumdepth>\z@ + \thesection\hskip 1em\relax + \fi ##1}}{}}% + \def\subsectionmark##1{\markright {\ifnum \c@secnumdepth >\@ne + \thesubsection\hskip 1em\relax \fi ##1}}}% + {\def\chaptermark##1{\markboth {\MakeUppercase{\ifnum + \c@secnumdepth>\m@ne \@chapapp\ \thechapter. \ \fi ##1}}{}}% + \def\sectionmark##1{\markright{\MakeUppercase{\ifnum \c@secnumdepth >\z@ + \thesection. \ \fi ##1}}}% + }% % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} -% -% \begin{macro}{\ps@fancy} -% Pagestyle \texttt{fancy}. \cs{ps@@fancy} is the real pagestyle -% \texttt{fancy}, i.e. the non-plain one. +% +% \begin{macro}{\headrule} % \begin{macrocode} -\ps@@fancy -\gdef\ps@fancy{\@fancyplainfalse\ps@@fancy}% + \def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi + \hrule\@height\headrulewidth\@width\headwidth + \vskip-\headrulewidth}}% % \end{macrocode} % \end{macro} -% -% Initialize \cs{headwidth} if the user didn't. If \cs{headwidth} ${}< 0$, -% then the user did not initialize it, or they just added something to +% +% \begin{macro}{\footrule} +% \changes{fancyhdr v3.10}{2019/01/28}{Move \cs{footruleskip} outside of the \cs{footrule} +% definition and remove useless \cs{vskip} at the top.} +% \begin{macrocode} + \def\footrule{{\if@fancyplain\let\footrulewidth\plainfootrulewidth\fi + \hrule\@width\headwidth\@height\footrulewidth}}% +% \end{macrocode} +% \end{macro} +% +% Default values for \cs{headrulewidth}, \cs{footrulewidth}, +% \cs{headruleskip} and \cs{footruleskip}. +% \begin{macrocode} + \def\headrulewidth{0.4pt}% + \def\footrulewidth{0pt}% + \def\headruleskip{0pt}% + \def\footruleskip{0.3\normalbaselineskip}% +% \end{macrocode} +% Initialisation of the head and foot text. +% +% The default values still contain \cs{fancyplain} for compatibility: +% lefthead empty on ``plain'' pages, \cs{rightmark} on even, \cs{leftmark} on odd pages; +% evenhead empty on ``plain'' pages, \cs{leftmark} on even, \cs{rightmark} on odd pages. +% \begin{macrocode} + \fancyhf{}% + \if@twoside + \fancyhead[el,or]{\fancyplain{}{\slshape\rightmark}}% + \fancyhead[er,ol]{\fancyplain{}{\slshape\leftmark}}% + \else + \fancyhead[l]{\fancyplain{}{\slshape\rightmark}}% + \fancyhead[r]{\fancyplain{}{\slshape\leftmark}}% + \fi + \fancyfoot[c]{\rmfamily\thepage}% page number +} +% \end{macrocode} +% Call the initialisation +% \begin{macrocode} +\f@nch@initialise +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\ps@f@nch@fancyproto} +% \cs{ps@f@nch@fancyproto} is the +% initial value for pagestyle \texttt{fancy}. The real page style +% is \cs{ps@f@nch@fancycore} but \cs{ps@f@nch@fancyproto} for the first use +% of \Cmd{pagestyle\{fancy\}} or any of its derivatives. It +% initialises \cs{headwidth}, and then resets itself to +% \cs{ps@f@nch@fancycore}. For backwards compatibility it still +% contains \cs{@fancyplainfalse}. +% The reason we have \cs{ps@f@nch@fancyproto} is so that page style +% \texttt{fancy} can be redefined. +% \changes{fancyhdr v4.0}{2019/03/21}{Reorganise \cs{ps@fancy}} +% \begin{macrocode} +\def\ps@f@nch@fancyproto{% +% \end{macrocode} +% Initialise \cs{headwidth} if the user didn't. If \cs{headwidth} ${}< 0$, +% then the user did not initialise it, or they just added something to % it in the expectation that -% it was initialized to \cs{textwidth}. We compensate this now. This loses if +% it was initialised to \cs{textwidth}. We compensate this now. This loses if % the user intended to multiply it by a factor. But that case is more -% likely done by saying something like \verb+\setlength{\headwidth}{1.2\textwidth}+. -% The documentation says you have to change \cs{headwidth} after the first call to +% likely done by saying something like \verb+\setlength{\headwidth}{1.2\textwidth}+. +% The documentation advises to change \cs{headwidth} after the first call to % \verb+\pagestyle{fancy}+. This code is just to catch the most common cases were -% that requirement is violated. -% +% that is not the case. % \begin{macrocode} -\ifdim\headwidth<0sp + \ifdim\headwidth<0sp \global\advance\headwidth123456789sp\global\advance\headwidth\textwidth -\fi} + \fi +% \end{macrocode} +% Now we reset \cs{ps@f@nch@fancyproto} to \cs{ps@f@nch@fancycore} with \cs{@fancyplainfalse} +% and call that version. +% \begin{macrocode} + \gdef\ps@f@nch@fancyproto{\@fancyplainfalse\ps@f@nch@fancycore}% + \@fancyplainfalse\ps@f@nch@fancycore +}% +% \end{macrocode} +% Let the system know this is a \texttt{fancyhdr} pagestyle. +% \begin{macrocode} +\@namedef{f@nch@ps@f@nch@fancyproto-is-fancyhdr}{} % \end{macrocode} +% \end{macro} +% \begin{macro}{ps@fancy} +% Define \cs{ps@fancy} just to call \cs{ps@f@nch@fancyproto}. +% \begin{macrocode} +\def\ps@fancy{\ps@f@nch@fancyproto} +\@namedef{f@nch@ps@fancy-is-fancyhdr}{} +% \end{macrocode} +% \end{macro} % % \begin{macro}{\ps@fancyplain} % The pagestyle \texttt{fancyplain} (deprecated). -% +% After initializing by calling \cs{ps@f@nch@fancyproto} it sets page style +% \texttt{plain} to our version \cs{ps@plain@fancy}, which just sets +% \cs{@fancyplaintrue} and then calls the page style fancy implementation. +% % \begin{macrocode} -\def\ps@fancyplain{\ps@fancy \let\ps@plain\ps@plain@fancy} -\def\ps@plain@fancy{\@fancyplaintrue\ps@@fancy} +\def\ps@fancyplain{\ps@f@nch@fancyproto \let\ps@plain\ps@plain@fancy} +\def\ps@plain@fancy{\@fancyplaintrue\ps@f@nch@fancycore} % \end{macrocode} % \end{macro} -% -% \begin{macro}{\ps@@empty} +% +% \begin{macro}{\f@nch@ps@empty} % Save the definition of \cs{ps@empty} (pagestyle \texttt{empty}). -% +% \changes{fancyhdr v4.0}{2019/03/21}{Rename \cs{ps@@empty} to \cs{f@nch@ps@empty}} +% % \begin{macrocode} -\let\ps@@empty\ps@empty +\let\f@nch@ps@empty\ps@empty % \end{macrocode} % \end{macro} -% -% \begin{macro}{\ps@@fancy} -% The actual pagestyle \texttt{fancy}. For amsbook/amsart, which do -% strange things with \cs{topskip}, we start with \cs{ps@@empty}. We +% +% \begin{macro}{\ps@f@nch@fancycore} +% \changes{fancyhdr v4.0}{2019/03/21}{Rename \cs{ps@@fancy} to \cs{ps@f@nch@fancycore}} +% The actual implementation of pagestyle \texttt{fancy}. For amsbook/amsart, which do +% strange things with \cs{topskip}, we start with \cs{f@nch@ps@empty}. We % construct the even and odd headers and footers from all the parts that % we have collected. % \begin{macrocode} -\def\ps@@fancy{% - \ps@@empty +\def\ps@f@nch@fancycore{% + \f@nch@ps@empty \def\@mkboth{\protect\markboth}% \def\@oddhead{\f@nch@head\f@nch@Oolh\f@nch@olh\f@nch@och\f@nch@orh\f@nch@Oorh}% \def\@oddfoot{\f@nch@foot\f@nch@Oolf\f@nch@olf\f@nch@ocf\f@nch@orf\f@nch@Oorf}% @@ -3185,7 +4283,22 @@ } % \end{macrocode} % \end{macro} -% +% \begin{macro}{ps@fancydefault} +% \changes{fancyhdr v4.0}{2019/03/21}{Added \cs{ps@fancydefault}} +% This is page style \texttt{fancydefault}. It is in fact page style +% \texttt{fancy} with all the defaults embedded. In contrast with page +% style \texttt{fancy} that gets all its settings from the environment. +% It reruns all initialisations and then calls \cs{ps@f@nch@fancyproto}. +% \begin{macrocode} +\def\ps@fancydefault{% + \f@nch@initialise + \ps@f@nch@fancyproto +} +\@namedef{f@nch@ps@fancydefault-is-fancyhdr}{} +% \end{macrocode} +% +% \end{macro} +% % \begin{macro}{\f@nch@Oolh} % \begin{macro}{\f@nch@Oorh} % \begin{macro}{\f@nch@Oelh} @@ -3201,7 +4314,7 @@ % \begin{macrocode} \def\f@nch@Oolh{\if@reversemargin\hss\else\relax\fi} \def\f@nch@Oorh{\if@reversemargin\relax\else\hss\fi} -\let\f@nch@Oelh\f@nch@Oorh +\let\f@nch@Oelh\f@nch@Oorh \let\f@nch@Oerh\f@nch@Oolh \let\f@nch@Oolf\f@nch@Oolh \let\f@nch@Oorf\f@nch@Oorh @@ -3236,7 +4349,7 @@ % \begin{macro}{\f@nch@offsolh} % \begin{macro}{\f@nch@offselh} % The same for the footer. -% +% % \begin{macrocode} \def\f@nch@offsolf{\headwidth=\textwidth\advance\headwidth\f@nch@O@olf \advance\headwidth\f@nch@O@orf\hskip-\f@nch@O@olf} @@ -3273,7 +4386,7 @@ % We need a boolean \cs{iff@nch@footnote} to capture if there was a footnote. % % \begin{macrocode} -\newif\iff@nch@footnote +\newif\iff@nch@footnote \AtBeginDocument{% \let\latex@makecol\@makecol \def\@makecol{\ifvoid\footins\f@nch@footnotefalse\else\f@nch@footnotetrue\fi @@ -3282,7 +4395,7 @@ % \end{macrocode} % \end{macro} % \end{macro} -% +% % \begin{macro}{\iftopfloat} % \begin{macro}{\ifbotfloat} % \begin{macro}{\iffloatpage} @@ -3301,9 +4414,33 @@ % \end{macro} % % \begin{macro}{\fancypagestyle} +% Define a new page style. The optional second argument is the base page style. +% It defaults to \cs{ps@f@nch@fancyproto}. +% \changes{fancyhdr v4.0}{2019/03/21}{Added optional base style argument.} % \begin{macrocode} -\newcommand{\fancypagestyle}[2]{% - \@namedef{ps@#1}{\let\f@nch@gbl\relax#2\relax\ps@fancy}} +\newcommand{\fancypagestyle}[1]{% + \@ifnextchar[{\f@nch@pagestyle{#1}}{\f@nch@pagestyle{#1}[f@nch@fancyproto]}% +} +% \end{macrocode} +% \end{macro} +% \begin{macro}{\f@nch@pagestyle} +% The actual code for \cs{fancypagestyle}. Build the page style body. +% Declare it as a fancyhdr page style. +% \changes{fancyhdr v4.0}{2019/09/05}{Make the definition of \cs{f@nch@pagestyle} \cs{long}.} +% \begin{macrocode} +\long\def\f@nch@pagestyle#1[#2]#3{% + \f@nch@ifundefined{ps@#2}{% + \f@nch@errmsg{\string\fancypagestyle: Unknown base page style `#2'}% + }{% + \f@nch@ifundefined{f@nch@ps@#2-is-fancyhdr}{% + \f@nch@errmsg{\string\fancypagestyle: Base page style `#2' is not fancyhdr-based}% + }% + {% + \@namedef{ps@#1}{\let\f@nch@gbl\relax\@nameuse{ps@#2}#3\relax}% + \@namedef{f@nch@ps@#1-is-fancyhdr}{}% + }% + }% +}% % \end{macrocode} % \end{macro} %</fancyhdr> @@ -3323,7 +4460,7 @@ % \changes{extramarks v2.1}{2016/08/27}{Added a \cs{ProvidesPackage} line.\\ % Updated contact information.} % \changes{extramarks v3.9}{2016/10/12}{Unify version number with \Package{fancyhdr.sty}.} -% +% % \changes{extramarks v3.9a}{2017/06/30}{Restore \cs{newtoks}\cs{@temptokenb}} % \begin{macro}{\@temptokenb} % A token register to store some marks information @@ -3339,7 +4476,7 @@ \let\protect\@unexpandable@protect \xdef} % \end{macrocode} % \end{macro} -% +% % \begin{macro}{\markboth} % Our own definition of \cs{markboth}, mainly because \cs{@markboth} % gets more parameters. @@ -3357,7 +4494,7 @@ % \begin{macro}{\markright} % We use the standard definition of \cs{markright}. No use to duplicate here. % \end{macro} -% +% % \begin{macro}{\@markboth} % Note: put \texttt{\#3\#4} in toks register. % \begin{macrocode} @@ -3365,7 +4502,7 @@ \unrestored@protected@xdef\@themark{{#5}{#6}\the\@temptokena}} % \end{macrocode} % \end{macro} -% +% % \begin{macro}{\@markright} % Note: put \texttt{\#1} and \texttt{\#3\#4} in toks registers. % Maybe I can get rid of the extra \cs{@temptokenb} by doing the expansion @@ -3381,7 +4518,7 @@ % \begin{macro}{\@rightmark} % Internal macros to get the standard marks. % \begin{macrocode} -\def\@leftmark#1#2#3#4{#1} +\def\@leftmark#1#2#3#4{#1} \def\@rightmark#1#2#3#4{#2} % \end{macrocode} % \end{macro} @@ -3433,7 +4570,7 @@ \if@nobreak\ifvmode\nobreak\fi\fi} % \end{macrocode} % \end{macro} -% +% % \begin{macro}{\@markextra} % Internal macro to store the extra marks in the marks storage.\\ % Note: Put \texttt{\#1\#2} in toks register. @@ -3442,7 +4579,7 @@ \unrestored@protected@xdef\@themark{\the\@temptokena{#5}{#6}}} % \end{macrocode} % \end{macro} -% +% % \begin{macro}{\firstleftxmark} % \begin{macro}{\firstrightxmark} % \begin{macro}{\topleftxmark} @@ -3479,7 +4616,7 @@ % \end{macro} % \end{macro} % \end{macro} -% +% % \begin{macro}{\@tleftxmark} % \begin{macro}{\@rightxmark} % Internal macros to extract the extra marks out of the marks storage. @@ -3489,7 +4626,7 @@ % \end{macrocode} % \end{macro} % \end{macro} -% +% %</extramarks> % % \section{fancyheadings.sty} @@ -3521,7 +4658,7 @@ \MessageBreak fancyhdr is 99 percent compatible with\MessageBreak fancyheadings. The only incompatibility is\MessageBreak - that \protect\headrulewidth\space and \protect\footrulewidth\space + that \protect\headrulewidth\space and \protect\footrulewidth\space and\MessageBreak their \protect\plain... versions are no longer length\MessageBreak parameters, but normal macros (to be changed\MessageBreak diff --git a/macros/latex/contrib/fancyhdr/fancyhdr.ins b/macros/latex/contrib/fancyhdr/fancyhdr.ins index e3f68035da..c601395592 100644 --- a/macros/latex/contrib/fancyhdr/fancyhdr.ins +++ b/macros/latex/contrib/fancyhdr/fancyhdr.ins @@ -1,5 +1,5 @@ %% -%% Copyright (C) 2016 by Piet van Oostrum <piet@vanoostrum.org> +%% Copyright (C) 2016-2019 by Pieter van Oostrum <pieter@vanoostrum.org> %% %% This file may be distributed and/or modified under the conditions of %% the LaTeX Project Public License, either version 1.3 of this license diff --git a/macros/latex/contrib/fancyhdr/fancyhdr.pdf b/macros/latex/contrib/fancyhdr/fancyhdr.pdf Binary files differindex 8c0ff2e9e6..419565512b 100644 --- a/macros/latex/contrib/fancyhdr/fancyhdr.pdf +++ b/macros/latex/contrib/fancyhdr/fancyhdr.pdf diff --git a/macros/latex/contrib/moodle/README.md b/macros/latex/contrib/moodle/README.md index e2ab4cd420..83eb22b4bf 100644 --- a/macros/latex/contrib/moodle/README.md +++ b/macros/latex/contrib/moodle/README.md @@ -1,50 +1,67 @@ -============================================================================== - -The `moodle' package v0.5 -Copyright (C) 2016 Anders Hendrickson (anders.hendrickson@snc.edu) - -This package allows dramatic highlighting of words and phrases -by painting shapes around them. It is chiefly intended for -use in Beamer presentations, but it can be used in other -document classes as well. - -Changes: -- 2016/01/11 Initial version - -============================================================================== - -This work may be distributed and/or modified under the -conditions of the LaTeX Project Public License, either version 1.3 -of this license or (at your option) any later version. -The latest version of this license is in - http://www.latex-project.org/lppl.txt -and version 1.3 or later is part of all distributions of LaTeX -version 2005/12/01 or later. - - -============================================================================== - - This work consists of the files: -README (this file) -moodle.dtx -moodle.ins - and the derived file: -moodle.sty - - The distribution consists of the files: -README (this file) -moodle.dtx -moodle.ins -moodle.pdf (the user manual) - ------------------------------------------------------------------ - - To install the package: -- run: latex moodle.ins (which will generate moodle.sty) -- Move moodle.sty to a location where LaTeX will find it (typically - in a local texmf tree at tex/latex/moodle) and refresh the - file database. See the FAQ on CTAN at help/uk-tex-faq or - http://www.tug.ac.uk/faq for more information on this. - To process the user manual -- run: pdflatex moodle.dtx -- run: pdflatex moodle.dtx +# License + +This work may be distributed and/or modified under the conditions of the +LaTeX Project Public License, either version 1.3 of this license or +(at your option) any later version. The latest version of this license +is in http://www.latex-project.org/lppl.txt and version 1.3 or later is +part of all distributions of LaTeX version 2005/12/01 or later. + +# Authors + +Original contents (2016): [Anders O.F. Hendrickson](/author/hendrickson) ([contact](mailto:anders.o.f.hendricksonATgmail.com)) + +2019-2021: [Matthieu Guerquin-Kern](author/guerquin-kern) ([contact](mailto:guerquin-kernATcrans.org)) + +# Contents + +This work, under version number 0.8, consists of the files +[`moodle.dtx`](/tex-archive/macros/latex/contrib/moodle/moodle.dtx), +[`moodle.ins`](/tex-archive/macros/latex/contrib/moodle/moodle.ins), and the derived documentation +file [`moodle.pdf`](/tex-archive/macros/latex/contrib/moodle/moodle.pdf). + +A TDS archive [moodle.tds.zip](http://mirrors.ctan.org/install/macros/latex/contrib/moodle.tds.zip) is +also available to be conveniently expanded in your local texmf directory. +It contains the derived file `moodle.sty` and a set of test files. + +# Requirements + +This package (`moodle.sty`) requires the following packages: +- [`environ`](/pkg/environ), +- [`xkeyval`](/pkg/xkeyval), +- [`amssymb`](/pkg/amssymb), +- [`trimspaces`](/pkg/trimspaces), +- [`etex`](pkg/etex), +- [`etoolbox`](pkg/etoolbox), +- [`xpatch`](pkg/xpatch), +- [`array`](pkg/array), +- [`ifplatform`](/pkg/ifplatform), +- [`fancybox`](pkg/fancybox), and +- [`getitems`](pkg/getitems). + +In order to manipulate images, the package relies on the following external tools: +- [GhostScript](www.ghostscript.com), +- [ImageMagick](www.imagemagick.org), and +- [optipng](http://optipng.sourceforge.net/). + +In addition, to compile the documentation, the following LaTeX packages are +necessary: +- [`amssymb`](pkg/amssymb), +- [`metalogo`](pkg/metalogo), +- [`multirow`](pkg/multirow), +- [`threeparttable`](pkg/threeparttable), +- [`booktabs`](pkg/booktabs), +- [`hyperref`](pkg/hyperref), +- [`tikz`](pkg/tikz), +- [`minted`](pkg/minted), and +- [`microtype`](pkg/microtype). + +# Building + +The file `moodle.sty` can be generated using the command +```bash +latex moodle.ins +```` +The documentation file `moodle.pdf` can be generated by running twice the command +```bash +lualatex -shell-escape moodle.dtx +``` diff --git a/macros/latex/contrib/moodle/moodle.dtx b/macros/latex/contrib/moodle/moodle.dtx index 02b43f7923..17a7b125b4 100644 --- a/macros/latex/contrib/moodle/moodle.dtx +++ b/macros/latex/contrib/moodle/moodle.dtx @@ -1,7 +1,8 @@ % \iffalse meta-comment % % moodle.dtx -% Copyright 2016 by Anders O.F. Hendrickson (anders.hendrickson@snc.edu) +% Copyright 2016 by Anders O.F. Hendrickson (anders.o.f.hendrickson AT gmail.com) +% and 2019-2021 by Matthieu Guerquin-Kern (guerquin-kern AT crans.org). % % This work may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either version 1.3 @@ -13,7 +14,7 @@ % % This work has the LPPL maintenance status `maintained'. % -% The Current Maintainer of this work is Anders O.F. Hendrickson. +% The Current Maintainer of this work is Matthieu Guerquin-Kern. % % This work consists of the files moodle.dtx and moodle.ins % and the derived files moodle.sty and getitems.sty. @@ -27,27 +28,37 @@ %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] %<package>\ProvidesPackage{moodle} %<*package> - [2016/01/11 v0.5 Moodle quiz XML generation] + [2021/01/04 v0.8 Moodle quiz XML generation] %</package> % %<*driver> -\documentclass{ltxdoc} -\usepackage{moodle} -\usepackage{amssymb} -\usepackage{fancyvrb} +\documentclass[a4paper]{ltxdoc} +\usepackage{iftex} +\ifPDFTeX + \usepackage[utf8]{inputenc} % necessary + \usepackage[T1]{fontenc} % necessary + \usepackage[protrusion=true,expansion]{microtype} + \usepackage[ttscale=.875]{libertine} +\else % assuming LuaLaTeX or XeLaTeX + \usepackage{fontspec} + \setmainfont[Mapping=tex-text]{Linux Libertine O} +\fi +%\usepackage{moodle}[2020/07/09] +\usepackage{amssymb,metalogo,multirow,threeparttable,booktabs,hyperref,tikz,minted,changelog} +\usetikzlibrary{arrows,positioning,decorations.text} +%\usemintedstyle{Wombat} \EnableCrossrefs \CodelineIndex \OnlyDescription \RecordChanges \begin{document} \DocInput{moodle.dtx} - \PrintChanges - %\PrintIndex + %\PrintChanges \end{document} %</driver> % \fi % -% \CheckSum{3827} +% \CheckSum{7442} ^^A Comment \OnlyDescription above to adjust % % \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 @@ -66,9 +77,7 @@ % Right brace \} Tilde \~} % % -% \changes{v0.5}{2016/01/05}{Initial version} -% -% \GetFileInfo{moodle.sty} +% \GetFileInfo{\jobname.dtx} % % \DoNotIndex{\newcommand,\newenvironment,\def} % @@ -77,8 +86,12 @@ % generating Moodle quizzes via \LaTeX% % \thanks{This document % corresponds to \textsf{moodle.sty}~\fileversion, dated \filedate.}} -% \author{Anders Hendrickson\\ St.~Norbert College, De~Pere, WI, USA \\ \url{anders.hendrickson@snc.edu}} -% \date{January 11, 2016} +% \author{Anders Hendrickson\footnote{original author of the package (\texttt{v0.5}), inactive.}\\ +% \texttt{anders.o.f.hendrickson AT gmail.com} \and +% Matthieu Guerquin-Kern\footnote{current maintainer, author of the updates (\texttt{v0.6} +% to \texttt{v0.8}), partially funded by \href{https://www.ensea.fr/en/}{ENSEA Graduate School}, France.}\\ +% \href{mailto:guerquin-kern AT crans.org}{guerquin-kern AT crans.org}} +% \date{January 4, 2021} % % \maketitle % @@ -87,8 +100,8 @@ % \section{Motivation} % % The acronym Moodle stands for ``Modular Object-Oriented Dynamic Learning Environment.'' -% It is an open source learning management system employed by many universities, colleges, -% and high schools to provide digital access to course materials, such as +% It is an open source learning management system (LMS) employed by many universities, +% colleges, and high schools to provide digital access to course materials, such as % notes, video lectures, forums, and the like; see % \url{https://moodle.com/moodle-lms/} for more information. % One of the many useful @@ -148,28 +161,82 @@ % and the PDF may be previewed onscreen or printed out for ease of proofreading. % Mathematical graphics can be integrated within the main file through \TikZ, % and of course \LaTeX\ macros can be customized. -% Using the present \textsf{moodle.sty} package, +% Using the present \textsf{moodle} package, % a quiz author can type a quiz using familiar \LaTeX\ syntax and document % structure. Upon compilation, \LaTeX\ will generate both a well-organized % PDF that is easy to proofread and an XML file that can be uploaded directly % to Moodle. The entire process is far faster than using Moodle's own % web-based editor, makes it easier to catch one's mistakes, % and the ultimate source code of one's work is a human-readable |.tex| file -% that can be archived, browsed, and edited offline. +% that can be archived, versioned, browsed, and edited offline. +% +% Strictly speaking, the \textsf{moodle} package does not generate quizzes: +% it generates question banks that can be imported in the LMS. The teacher +% still needs to compose manually a quiz from the question banks. Hopefully, +% two Moodle features supported by the package make this task easier: +% categories and tags. +% +% In this documentation the LMS is referred to as Moodle (uppercase M and +% roman font) while the \LaTeX\ package that is documented here is referred +% to as \textsf{moodle} (all lower case and sans serif font). % % \section{Workflow} -% The process of creating a quiz in Moodle using this package is as follows: +% The process of creating a quiz in Moodle using this package is depicted in +% Figure~\ref{fig:workflow}. It follows a few steps: % \begin{enumerate} -% \item Write a \LaTeX\ document using |\usepackage{moodle}| as described below. -% \item Compile the document to PDF using pdf\LaTeX. This will also produce the file -% \meta{jobname}|-moodle.xml|. +% \item Write a \LaTeX\ document using |\usepackage{moodle}| as described +% below. +% \item Compile the document to PDF using pdf\LaTeX\, \XeLaTeX\ or \LuaLaTeX. +% This will also produce the file \meta{jobname}|-moodle.xml|. % \item Open Moodle, navigate to the desired course, % and under ``Question bank'' select ``Import.'' % \item Select ``Moodle XML format,'' choose the XML file to upload, and press ``Import.'' % \item After Moodle verifies that the questions have been imported correctly, % you may add them to your quizzes. % \end{enumerate} -% +% \begin{figure}[tbp] +% \centering +% \begin{tikzpicture}[node distance=1,auto,bend +% angle=45,box/.style={rectangle,draw=blue!50,rounded corners=3,top +% color=white,bottom color=black!20,thick,align=center,text +% width=2.5cm},elmt/.style={font=\itshape,align=left}, +% cmnt/.style={font=\footnotesize,align=center}, +% bigcmnt/.style={font=\normalsize,align=center},pre/.style={<-,>=stealth',thick}, +% post/.style={->,>=stealth',thick}, prepost/.style={<->,>=stealth',thick}] +% \draw[white,fill=orange!20,rounded corners=10] +% (-1.5,-.7)--++(0,1.4)--++(10.3,0)--++(0,-3.3)--++(-6.7,0)--++(-.25,1.725)--cycle; +% \node[orange!80!black,above] (dev) at (7.5,-2.6) {\textit{Developpement}}; +% \fill[green,fill opacity=.2,rounded corners=10] +% (-1.5,.7)--++(3,0)--++(0.5,-3.4)--++(6.8,0)--++(0,-2)--++(-10.3,0)--cycle; +% \node[green!80!black,below] (dev) at (7.5,-2.7) {\textit{Publishing}}; +% \node[box,text width=2cm] (tex) {\texttt{.tex} source file}; +% \node[rectangle,fill=white,draw,align=center,text +% width=1.5cm,below=of tex] (compfinal) {\LaTeX{}\\ engine}; +% \node[rectangle,fill=white,draw,align=center,text width=1.5cm,right=of tex,xshift=4.5cm] +% (compdraft) {\LaTeX{}\\ engine}; +% \node[box,right=of compfinal,xshift=.5cm] (pdf) {\texttt{.pdf} file for proofreading}; +% \node[rectangle,fill=white,draw,align=center,text width=2cm,below=of compfinal] (extern) +% {Picture\\processing}; +% \draw (pdf|-extern) node[box,anchor=center] (xml) {\texttt{.xml} file\\\footnotesize(pictures embedded)}; +% \draw (compdraft|-xml) +% node[rectangle,fill=white,draw,align=center,text width=1.5cm,anchor=center] (moodle) +% {Moodle\\Server}; +% \draw (tex) edge [post,bend right=10] node[cmnt,pos=.5,left] {\texttt{final}} (compfinal); +% \draw (tex) edge [post,bend left=10] node[cmnt,pos=.5,below] {\texttt{draft}} (compdraft); +% \draw (compdraft) edge [post,bend left=10] (pdf); +% \draw (compfinal) edge [post] (pdf); +% \draw (compfinal) edge [post,bend left=10] (xml); +% \draw (compfinal) edge [post,bend right=30] node[cmnt,black!40,pos=.5,text width=1cm,left] +% {\texttt{tikz}, \texttt{.png}, \texttt{.jpg}} (extern); +% \draw (extern) edge [post,green,bend right=30] node[cmnt,black!40,pos=.5,below,right] +% {\texttt{base64}} (compfinal); +% \draw (pdf) edge [post,red,bend right=15] node[sloped,cmnt,pos=.5,above] {improve} (tex); +% \draw (xml) edge [post,red] node[cmnt,pos=.5,below] {import} (moodle); +% \end{tikzpicture} +% \caption{Block diagram describing a typical workflow using the \textsf{moodle} package.} +% \label{fig:workflow} +% \end{figure} +% % \section{Usage}\label{sect:usage} % \subsection{Example Document} % @@ -177,35 +244,34 @@ % and editing Moodle quizzes through the web interface. % The |xkeyval| package is used to provide a key-value interface. % Here is a simple example document: -% \begin{verbatim} +% \begin{VerbatimOut}[gobble=1]{minted.doc.out} % \documentclass[12pt]{article} -% \usepackage{moodle} -% +% \usepackage[section]{moodle} +% \moodleregisternewcommands +% \newcommand\monomial[1]{x^{#1}} +% \newcommand\sillyanswer{What!?} % \begin{document} -% % \begin{quiz}{My first quiz} % \begin{numerical}[points=2]{Basic addition} % What is $8+3$? % \item 11 % \end{numerical} -% -% \begin{shortanswer}[case sensitive=true]{Newton's name} +% \begin{shortanswer}[usecase]{Newton's name} % What was Newton's first name? % \item Isaac -% \item[fraction=0, feedback={No, silly!}] Fig -% \item{fraction=0} Sir +% \item[fraction=0, feedback={\sillyanswer}] Fig +% \item[fraction=0] Sir % \end{shortanswer} -% % \begin{multi}[points=3]{A first derivative} -% What is the first derivative of $x^3$? -% \item $\frac{1}{4} x^4+C$ -% \item* $3x^2$ -% \item $51$ +% What is the first derivative of $\monomial{3}$? +% \item $\frac{1}{4}\monomial{4}+C$ +% \item[feedback={yes!}]* $3\monomial{2}$ +% \item[feedback={\sillyanswer}] $51$ % \end{multi} % \end{quiz} -% % \end{document} -% \end{verbatim} +% \end{VerbatimOut} +% \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out} % Key features to note in this first example are that a |quiz| environment % contains several question environments. % Each question takes a name as a mandatory argument, @@ -214,39 +280,102 @@ % such as |itemize| or |enumerate|, in that answers are set off by % |\item|'s, but the question itself is the text that occurs before % the first |\item|. +% +%^^A \DescribeMacro{\moodleregisternewcommands}\DescribeMacro{\htmlregister} +%^^A Calling |\moodleregisternewcommands| tells the package to treat +%^^A specifically the macros defined subsequently. +%^^A This way, the macros that Moodle's \LaTeX\ renderer does not know +%^^A about can be properly expanded in the XML file. +%^^A This mechanism applies only to the macros defined using |\newcommand| +%^^A and \emph{without} optional argument. +%^^A Using |\htmlregister|\marg{macroname}, lets you declare a specific +%^^A macro for expansion. This mechanism, instead, also applies to the +%^^A macros defined using \TeX's primitive |\def|. % +% \subsection{Package Options} % \DescribeMacro{draft} -% If the package option |draft| is invoked, by calling |\usepackage[draft]{moodle}|, -% then no XML file will be generated. This is especially useful while editing a quiz -% containing graphics, so as to avoid the time spent converting image files. +% \DescribeMacro{final} +% If the package option |draft| is invoked, by calling +% |\usepackage[draft]{moodle}| or |\documentclass[draft]{...}|, then no +% XML file will be generated. This is especially useful while editing a +% quiz containing graphics, so as to avoid the time spent converting +% image files. The package option |final| might be useful if one wants +% to avoid the option |draft| to be inherited from the |documentclass|. +% +% \DescribeMacro{handout} +% If the package option |handout| is invoked (|\usepackage[handout]{moodle}|), +% the PDF file is generated clean from teacher-only information (answers, +% points, penalty, feedback, tags) and, hence, can be given to students for +% classroom work. In particular, as would Moodle do, answers in +% \texttt{matching} questions are shuffled and the option \texttt{shuffle} +% triggers the shuffling of choices offered (\texttt{multi} and +% \texttt{matching}). This is achieved thanks to the package +% \texttt{randomlist}, loaded if the option is invoked. +% The XML file is generated as usual. +% +% \DescribeMacro{nostamp} +% By default, the package will output a stamp as a comment in the XML +% file. This stamp contains information gathered about the TeX engine, +% the operating system used and the package version. For instance: +% \begin{quote}\small +% |<!-- This file was generated on 2020-11-30 by LuaLaTeX -->|\\ +% |<!-- running on Linux with the package moodle |\texttt{\fileversion}| -->| +% \end{quote} +% The package option +% |nostamp| prevents this stamp to be written in the XML file. +% +% \DescribeMacro{section} +% \DescribeMacro{section*} +% \DescribeMacro{subsection} +% \DescribeMacro{subsection*} +% If the package option |section| is invoked (|\usepackage[section]{moodle}|), +% then each quiz is represented by a different \LaTeX\ section. Starred +% variants correspond to unnumbered sections or subsections. To preserve +% compatibility with Version 0.5 of this package, the default is |subsection*|. +% Consequently, |\usepackage{moodle}| is equivalent to +% |\usepackage[subsection*]{moodle}|. +% +% \DescribeMacro{tikz} The package option \texttt{tikz} is described in section +% \ref{subsec:tikz}. +% +% \DescribeMacro{svg} The package option \texttt{svg} is described in section +% \ref{subsec:svg}. % -% \newpage % \subsection{Quiz and Question Environments} % % \DescribeMacro{quiz} % A |.tex| document to generate Moodle quizzes contains one or more % |quiz| environments, within which various question environments are nested. -% The required argument to the |quiz| environment names the ``question bank'' -% to which the questions inside will belong after being uploaded to moodle. +% The required argument to the |quiz| environment names a category for Moodles +% ``question bank'': after import, the questions defined in this environment +% will be gathered in this category. % \begin{center} -% |\begin{quiz}|\oarg{options}\marg{question bank name}% +% |\begin{quiz}|\oarg{options}\marg{category name}% % \end{center} % There are no |quiz|-specific options, % but any \meta{options} set with |\begin{quiz}| % will be inherited by all questions contained within that |quiz| environment. % % \DescribeMacro{\moodleset} -% Options may also be set at any time with |\moodleset|\marg{options}; -% these changes are local to \TeX-groups. -% \bigskip +% Options may also be set outside question environments with +% |\moodleset|\marg{options}; these changes are local to \TeX-groups. +% +% \DescribeMacro{\setcategory}\DescribeMacro{\setsubcategory} +% Although the |quiz| environment defines a category by its own, one can change +% the current category inside the quiz environment and in between questions, +% using the macro |\setcategory|\marg{category name}. A subcategory can also be +% defined with |\setsubcategory|\marg{subcategory name}. The categories and +% subcategories are reflected in the PDF file as sections, subsections, or +% subsubsections, in accordance to the package setting |section|, |section*|, +% |subsection|, or |subsection*|. % % The syntax for each question environment is % \begin{quote} % |\begin|\marg{question type}\oarg{question options}\marg{question name} \\ % \rule{2em}{0pt}\meta{question text} \\ -% \rule{2em}{0pt}|\item| \meta{item} \\ +% \rule{2em}{0pt}|\item|\oarg{item options} \meta{item} \\ % \rule{2em}{0pt}\quad$\vdots$ \\ -% \rule{2em}{0pt}|\item| \meta{item} \\ +% \rule{2em}{0pt}|\item|\oarg{item options} \meta{item} \\ % |\end|\marg{question type} % \end{quote} % The meaning of the \meta{item}s varies depending on the question type, @@ -268,13 +397,54 @@ % \DescribeMacro{fraction} % In most question types, it is possible to designate some answers as being % worth partial credit---that is, some fraction of a completely correct answer. -% The |fraction| key may be set to any integer from |0| (entirely wrong) to |100| (entirely correct). +% The |fraction| key may be set to any of the values given in Table~\ref{tab:fraction}, +% from |0| (entirely wrong) to |100| (entirely correct). +% +% \begin{table}[tbp] +% \centering +% \caption{\href{https://github.com/moodle/moodle/blob/MOODLE\_310\_STABLE/question/engine/bank.php\#L339}{Valid positive options} for the \texttt{fraction} key: $100\cdot(p/q)$.} +% \label{tab:fraction} +% \footnotesize +% \begin{tabular}{l*{10}{l}} +% \toprule +% Denominator $q$ & \multicolumn{10}{c}{Numerator $p$}\\ +% \cmidrule{2-11} +% & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\ +% \cmidrule(lr){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4} +% \cmidrule(lr){5-5}\cmidrule(lr){6-6}\cmidrule(lr){7-7}\cmidrule(lr){8-8} +% \cmidrule(lr){9-9}\cmidrule(lr){10-10}\cmidrule(lr){11-11} +% 20 & 0&5&&&&&&&&\\\cmidrule(lr){1-1} +% 10 & &10&20&30&40&50&60&70&80&90\\\cmidrule(lr){1-1} +% 9 & &11.11111&&&&&&&&100\\\cmidrule(lr){1-1} +% 8 & &12.5&&&&&&&100&\\\cmidrule(lr){1-1} +% 7 & &14.28571&&&&&&100&&\\\cmidrule(lr){1-1} +% 6 & &16.66667&&&&83.33333&100&&&\\\cmidrule(lr){1-1} +% 5 & &20&&&80&100&&&&\\\cmidrule(lr){1-1} +% 4 & &25&&75&100&&&&&\\\cmidrule(lr){1-1} +% 3 & &33.33333&66.66667&100&&&&&&\\\cmidrule(lr){1-1} +% 2 & &50&100&&&&&&&\\\cmidrule(lr){1-1} +% 1 & 0&100&&&&&&&&\\\cmidrule(lr){1-1} +% \bottomrule +% \end{tabular} +% \end{table} +% In questions where several choices can be selected (see |multi| with the option +% |multiple|), positive fractions must sum up to exactly 100. It is also possible to set +% negative fractions (from -100 to 0) for wrong choices, in order to prevent the +% selection of all choices from leading to a good grade. +% In this case, the value ranging from -100 to 0 must be the opposite of one of the +% values listed in Table~\ref{tab:fraction}. % +% \DescribeMacro{fractiontol} +% The package tries to match the |fraction| key to one of the admissible values. +% To this end, the tolerance is controlled by the |fractiontol| key. It defaults +% to |0.01| but may be changed. When no admissible fraction value is matched, the +% package throws an error. +% % \DescribeMacro{feedback} % The |feedback| key sets text that will appear to the student after completing the quiz. % For example, one might set % \begin{center} -% |feedback={A question like this will appear on the exam.}| +% |feedback={This question might show up in the final exam.}| % \end{center} % The desired feedback should be included in braces. % @@ -282,13 +452,56 @@ % question, then that feedback will appear to each student regardless of the student's answer. % Answer-specific feedback (perhaps explaining a common mistake) % may also be given by setting the |feedback| key \emph{at the individual answer}. +% +% \DescribeMacro{tags} +% The |tags| key sets a keyword for the question that will be taken into account by Moodle for +% filtering purposes or classification of questions inside the question bank. It is possible +% for instance to build a quiz with questions cherry-picked among the set of questions holding +% a particular tag. +% For example, one might set +% \begin{center} +% |tags={easy}| +% \end{center} +% The desired tag should be included in braces. +% +% Tags can be assigned at two levels. If the |tags| key is set at the quiz level, +% then that tags will be assigned by default to each question of the quiz. +% Question-specific tags can be assigned by setting the |tags| key \emph{at the question level}. +% Since only single tag is supported, the tag a the question-level overrides eventual tags +% specified at the quiz-level. % -% \newpage % \subsection{Question Types} % -% We next discuss the various question types supported by \textsf{moodle.sty} +% We next discuss the various question types supported by \textsf{moodle} % and the options that may be set. +% +%\subsubsection{True/False} +% +% \DescribeMacro{truefalse} +% The syntax for a True/False question is as follows: +% \begin{quote} +% |\begin{truefalse}|\oarg{question options}\marg{question name} \\ +% \rule{2em}{0pt}\meta{question text} \\ +% \rule{2em}{0pt}|\item*| \meta{feedback when ``true" is chosen} \\ +% \rule{2em}{0pt}|\item| \meta{feedback when ``false" is chosen} \\ +% |\end{truefalse}| +% \end{quote} +% The correct answer is designated by the asterisk |*| after the |\item|; +% it need not appear first in the list. +% +% Answer-specific feedback can also be defined as an item option, similarly to +% other types. +% \begin{quote} +% |\begin{truefalse}|\oarg{question options}\marg{question name} \\ +% \rule{2em}{0pt}\meta{question text} \\ +% \rule{2em}{0pt}|\item[feedback={|\meta{When ``true" is chosen}|}]*| \\ +% |\end{truefalse}| +% \end{quote} +% Note that, in this example, no feedback is defined for the incorrect answer +% ``False": the corresponding item can be omitted. % +% With the True/False question type, the |penalty| key has no effect. +% % \subsubsection{Multiple Choice} % % \DescribeMacro{multi} @@ -319,54 +532,66 @@ % which mirror the usual \LaTeX\ syntax: % |alph|, |Alph|, |arabic|, |roman|, |Roman|, and |none|. % Calling |numbering=none| produces an unnumbered list of answers. -% The Moodle syntax of |abc|, |ABC|, |123|, |iii|, and |IIII| is also acceptable, -% but note that it requires \emph{four} |I|'s to obtain upper-case Roman numerals this way. +% The Moodle syntax of |abc|, |ABCD|, |123|, |iii|, and |IIII| is also +% acceptable, +% but note that it requires \emph{four} capital letters to obtain +% upper-case Roman or alphabetic numerals this way. % % \DescribeMacro{fraction} % The |fraction| key can be used to designate some wrong answers % as being worth partial credit. For example, a question might read thus: -% \begin{verbatim} +% \begin{VerbatimOut}[gobble=1]{minted.doc.out} % \begin{multi}{my question} % Compute $\int 4x^3\,dx$. % \item* $x^4+C$ % \item[fraction=50] $x^4$ % \item $12x^2$ % \end{multi} -% \end{verbatim} +% \end{VerbatimOut} +% \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out} % Thus the asterisk |*| is shorthand for |fraction=100|, % whereas a bare |\item| sets |fraction=0|. % -% \DescribeMacro{single}\DescribeMacro{multiple} +% \DescribeMacro{single} % By default, the |multi| environment produces -% a multiple choice question operates with only one correct answer; +% a multiple choice question with only one correct answer; % this is called |single| mode, and on Moodle it appears with radio buttons. -% It is also possible to write questions with more than one correct answer, -% asking the user to check all correct answers. -% To do this, use the key |multiple| or |single=false|. -% +% +% \DescribeMacro{multiple} +% It is also possible to write questions with possibly more than one correct answer, +% asking the user to check all correct answers. To do this, use the key |multiple| +% or |single=false|. % The worth of each correct answers in |multiple| mode may be set by |fraction|, -% but Moodle will require that all the fractions add up to at least 100. -% If you simply designate each correct answer with |\item*|, then \textsf{moodle.sty} -% will divide the 100\% equally among those answers. -% For example, the following two examples produce equivalent results: -% \begin{verbatim} +% but Moodle asks that all the fractions add up to \emph{exactly} 100. +% If you simply designate each correct answer with |\item*|, then \textsf{moodle} +% will divide equally among those answers the points lefts for a sum of 100\%. +% Items that are not given a |fraction| are considered incorrect and selecting them +% results in negative points such that the sum of all incorrect answers is -100\%. +% For example, the following two examples are equivalent: +% \begin{VerbatimOut}[gobble=1]{minted.doc.out} % \begin{multi}[multiple]{my question} % Which numbers are prime? +% \item[fraction=20] 2 % \item* 5 -% \item 6 % \item* 7 +% \item[fraction=-10] 1 +% \item 6 % \item 8 % \end{multi} -% \end{verbatim} -% \begin{verbatim} +% % \begin{multi}[multiple]{my question} % Which numbers are prime? -% \item[fraction=50] 5 -% \item 6 -% \item[fraction=50] 7 -% \item 8 +% \item[fraction=20] 2 +% \item[fraction=40] 5 +% \item[fraction=40] 7 +% \item[fraction=-10] 1 +% \item[fraction=-45] 6 +% \item[fraction=-45] 8 % \end{multi} -% \end{verbatim} +% \end{VerbatimOut} +% \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out} +% Note that, in this example, negative fractions are set for wrong choices. This +% prevents students selecting all options to obtain a good grade with no merit. % % \subsubsection{Numerical} % @@ -387,8 +612,41 @@ % \begin{quote}\footnotesize % |\item[fraction=0,feedback={You forgot to antidifferentiate!}]| \meta{incorrect answer} % \end{quote} +% +% \DescribeMacro{tolerance} +% The |tolerance| key can be used to specify the validity of answers within some margin. +% This key can be set at different levels: quiz, question, item. +% For example, with the question +% \begin{VerbatimOut}[gobble=1]{minted.doc.out} +% \begin{numerical}[tolerance=0.01]{my question} +% Approximate value of $\sqrt{2}$? +% \item[tolerance={1e-1}] 1.4142 +% \item[fraction=20,feedback={twice this!}] 7.0711e-1 +% \item[fraction=0,feedback={Wrong!}] * +% \end{numerical} +% \end{VerbatimOut} +% \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out} +% In this example, +% \begin{itemize} +% \item any answer in the range $[1.4042,1.4242]$ will be validated, +% \item any answer in the range $[0.69711,0.71711]$ will get the specific feedback +% \emph{twice this!} and 20\% of points, +% \item any other answer is incorrect and will get the specific feedback +% \emph{Wrong!}. +% \end{itemize} +% +% When feedback is to be given for any non-specified answer, one can add a \emph{last} answer +% item containing the wilcard character |*| only. In this case, the |tolerance| key is irrelevant. +% +% Both answers and tolerance can be specified with the comma (|,|) as a decimal separator. +% Exponent notation is accepted. After import, Moodle will recognize indifferently |0.000165|, +% |0,000165|, |1.65E-4|, |1.65e-4|, |1,65E-4|, and |1,65e-4|. +% +% If the \textsf{siunitx} package is loaded, \textsf{moodle} will detect it and +% numbers will be rendered nicely in the PDF output. % -% \newpage +% Units, unit-handling and multipliers are currently unsupported. +% % \subsubsection{Short Answer} % A short answer question resembles a numerical question: the student is to fill % in a text box with a missing word or phrase. @@ -403,25 +661,40 @@ % You can make the text box appear as part of the question with the % control sequence |\blank|. For example, % your question might read -% \begin{verbatim} +% \begin{VerbatimOut}[gobble=1]{minted.doc.out} % \begin{shortanswer}{Leibniz} % Newton's rival was Gottfried Wilhelm \blank. % \item Leibniz % \item Leibniz. % \end{shortanswer} -% \end{verbatim} +% \end{VerbatimOut} +% \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out} % Note that as the blank occurred at the end of a sentence, % we included two answers, % lest students get the question wrong merely by % including or omitting a period. % % \DescribeMacro{case sensitive}\DescribeMacro{usecase} -% By default, Moodle ignores the distinction between upper- and lower-case letters -% when grading a short answer question. +% The default setting when creating a Short Answer question in Moodle +% is to ignore the distinction between upper- and lower-case letters +% when grading a short answer question. This default is preserved by +% \textsf{moodle}. % You can make a question case-sensitive with the key |case sensitive| % or its shorter synonym |usecase|. +% +% The wildcard character |*| can used to grab answers that match +% a specific pattern. For instance: +% \begin{itemize} +% \item ``\emph{Sir Isaac Newton}'', ``\emph{Isaac Newton}'' and +% ``\emph{Newton}'' will match the pattern |*Newton|, +% \item ``\emph{Gaston}'' and ``\emph{Wellington}'' will match the +% pattern |*ton|, +% \item ``\emph{Isaac}'' and ``\emph{Isaac Newton}'' will match the +% pattern |Isaac*|, +% \item any non empty answer will match the pattern |*| (wildcard alone). +% \end{itemize} % -% \subsubsection{Essay Questions} +% \subsubsection{Essay}\label{subsubsect:essay} % Instructors may ask essay questions on a Moodle quiz, % although Moodle's software is not up to the task of grading them! % Instead each essay question answer must be graded manually by the @@ -443,22 +716,23 @@ % If the |response required| key is set, Moodle will insist that the student % enter something in the blank before accepting the quiz as completed. % -% \newpage % \DescribeMacro{response format} % Moodle offers five different ways for students to enter and/or upload their % answers to an essay question. You may choose one of these five options: % \begin{description} -% \item[{\tt html}] An editor with the ability to format HTML responses +% \item[{\ttfamily html}] An editor with the ability to format HTML responses % including markup for italics, boldface, etc. This is the default. -% \item[{\tt file}] A file picker allowing the student to upload a file, such as -% a PDF or DOC file, containing the essay. -% \item[{\tt html+file}] The same HTML editor as above, but with the ability -% to upload files as well. This permits some students to type answers -% directly into the web form, and others to compose their essays in -% another program first. -% \item[{\tt text}] This editor allows only for entering plain text without any markup. -% \item[{\tt monospaced}] This yields a plain text editor, without any markup, -% and with a fixed-width font. This could be useful for entering code snippets, for example. +% \item[{\ttfamily file}] A file picker allowing the student to upload a +% file, such as a PDF or DOC file, containing the essay. +% \item[{\ttfamily html+file}] The same HTML editor as above, but with the +% ability to upload files as well. This permits some students to type +% answers directly into the web form, and others to compose their +% essays in another program first. +% \item[{\ttfamily text}] This editor allows only for entering plain text +% without any markup. +% \item[{\ttfamily monospaced}] This yields a plain text editor, without any +% markup, and with a fixed-width font. This could be useful for +% entering code snippets, for example. % \end{description} % % \DescribeMacro{response field lines} @@ -473,16 +747,16 @@ % You may also require the student to upload a certain number of attachments % by setting |attachments required| to |0|, |1|, |2|, or |3|. % -% \DescribeMacro{response template} +% \DescribeMacro{template} % Finally, you may preload the essay question with a template that the student -% will edit and/or type over, with the key |response template=|\marg{template}. +% will edit and/or type over, with the key |template=|\marg{template}. % The \meta{template} should be enclosed in braces. % -% \subsection{Matching Questions} +% \subsubsection{Matching} % % A matching question offers a series of subquestions % and a set of possible answers from which to choose. -% If there are $m$ questions and $n$ possible answers, +% If there are $m$ questions and $n\geq m$ possible answers, % a matching question will look like this: % % \begin{quote} @@ -508,19 +782,18 @@ % permute the questions and answers; by default |shuffle=true|. % % \DescribeMacro{drag and drop}\DescribeMacro{dd} -% Moodle has two formats for matching questions. -% The older matching question offered a dropdown box -% for choosing the answer to each question; -% the newer ``drag and drop matching'' format +% The standard matching question offered by Moodle corresponds to +% a dropdown box for choosing the answer to each question. +% There also exists a ``drag and drop matching'' plugin for Moodle that % shows all questions in one column, % all answers in a second column, and allows students to drag the correct % answer to the question using a mouse. -% To enable drag-and-drop matching, use the key `|drag and drop|' or `|dd|' for -% short. The default is |dd=false|. If you choose the older format, -% then due to the limitations of dropdown boxes, no \LaTeX\ or HTML code can be used -% in the answers. +% In this package, to enable drag-and-drop matching, use the key +% `|drag and drop|' or `|dd|' for short. The default is |dd=false|. +% If you choose the standard format, then due to the limitations of +% dropdown boxes, no \LaTeX\ or HTML code can be used in the answers. % -% \subsection{Cloze Questions} +% \subsubsection{Cloze Questions and Subquestions} % % A ``cloze question'' has one or more subquestions embedded within a passage of text. % For example, you might ask students to fill in several missing words within @@ -528,10 +801,10 @@ % To encode cloze questions in \LaTeX\ using this package is easy: % you simply nest one or more |multi|, |shortanswer|, or |numerical| environments % within a |cloze| environment, as in the following example: -% \begin{verbatim} -% \begin{cloze}{my cloze question} \\ +% \begin{VerbatimOut}[gobble=1]{minted.doc.out} +% \begin{cloze}{my cloze question} % Thanks to calculus, invented by Isaac -% \begin{shortanswer} +% \begin{shortanswer}[usecase] % \item Newton % \end{shortanswer}, % we know that the derivative of $x^2$ is @@ -542,80 +815,207 @@ % \end{multi} % and that $\int_0^2 x^2\,dx$ equals % \begin{numerical} -% \item[tolerance=0.0004] 2.667 +% \item[tolerance={4e-4}] 2.667 % \end{numerical}. % Thanks, Isaac! % \end{cloze} -% \end{verbatim} +% \end{VerbatimOut} +% \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out} % Note that when used as a subquestion within a cloze question, % |\begin{multi}| is \emph{not} followed by name in braces; % the same is true for the |shortanswer| and |numerical| % environments. % -% \DescribeMacro{vertical}\DescribeMacro{horizontal} -% Within a cloze question, by default a multiple choice question is implemented -% as an inline dropdown box. This is visually compact, but it also prevents the -% use of mathematical or HTML formatting. +% \DescribeMacro{single=true}\DescribeMacro{single=false}\DescribeMacro{multiple} +% Before Moodle version 3.5, within a cloze question, a multiple choice question +% was necessarily of type |single|, i.e. with a single good answer. If you intend +% to export your quiz to Moodle 3.5+, the option |multiple| can be used, when +% multiple good answers are to be found. +% +% \DescribeMacro{vertical}\DescribeMacro{horizontal}\DescribeMacro{inline} +% Within a cloze question, by default, a multiple choice question is implemented +% as an |inline| dropdown box. This is visually compact, but it also prevents +% the use of mathematical or HTML formatting. % Adding the option |vertical| displays the subquestion as a vertical column % of radio buttons instead; likewise the option |horizontal| creates a horizontal % row of radio buttons. +% The option |inline| is incompatible with |multiple| or |single=false| +% (dropdown boxes don't let you pick up several answers!). +% +% \DescribeMacro{shuffle} +% Starting from Moodle version 3.0, within a cloze question, the items of a +% multiple choice question can be shuffled. Setting |shuffle=false| will +% guarantee that the answer appear in the order they were typed; the +% default is |shuffle=true|. +% +% \DescribeMacro{case sensitive}\DescribeMacro{usecase} +% Within a cloze question, the short answer question can be made case sensitive. +% This option, disabled by default, is selected with |case sensitive| or |usecase|. +% +%\subsubsection{Description} +% +% The Moodle description type is not really a question. It is more like a label. +% One can set a |feedback| that the student gets when reviewing the submission. +% Tags can be set as well. +% +% For descriptions, \textsf{moodle} redefines the existing |description| environment. +% +% The syntax for a Description question is as follows: +% \begin{quote} +% |\begin{description}|\oarg{question options}\marg{question name} \\ +% \rule{2em}{0pt}\meta{question text} \\ +% |\end{description}| +% \end{quote} +% +% \subsection{Summary of the Key Options} +% +% Table~\ref{tab:key-options} summarizes the key options available at the question +% and answer levels depending on the question type. For the essay questions, +% please refer to section~\ref{subsubsect:essay}. +% +% \begin{table}[tbp] +% \centering +% \caption{Options offered at the question and answer levels for each question type.} +% \label{tab:key-options} +% \small +% \begin{tabular}{*{14}{l}} +% \toprule +% & \multicolumn{10}{l}{Question} & \multicolumn{3}{l}{Answer}\\ +% \cmidrule(lr){2-11}\cmidrule(lr){12-14} +% Question type & \rotatebox{90}{points} & +% \rotatebox{90}{penalty} & \rotatebox{90}{feedback} & \rotatebox{90}{tags} & +% \rotatebox{90}{shuffle} & \rotatebox{90}{numbering} & \rotatebox{90}{multiple} & +% \rotatebox{90}{usecase} & \rotatebox{90}{tolerance} &\rotatebox{90}{dd} & +% \rotatebox{90}{fraction} & \rotatebox{90}{feedback} & +% \rotatebox{90}{tolerance}\\\cmidrule(lr){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3} +% \cmidrule(lr){4-4}\cmidrule(lr){5-5}\cmidrule(lr){6-6}\cmidrule(lr){7-7} +% \cmidrule(lr){8-8}\cmidrule(lr){9-9}\cmidrule(lr){10-10}\cmidrule(lr){11-11} +% \cmidrule(lr){12-12}\cmidrule(lr){13-13}\cmidrule(lr){14-14} +% \href{https://docs.moodle.org/35/en/Multiple_Choice_question_type} +% {Multichoice} & $\bullet$ & $\bullet$ & $\bullet$ & $\bullet$ & +% $\bullet$ & $\bullet$ & $\bullet$ & & & & $\bullet$ & $\bullet$ \\ +% \href{https://docs.moodle.org/35/en/Numerical_question_type}{Numerical} +% & $\bullet$ & $\bullet$ & $\bullet$ & $\bullet$ & & & +% & & $\bullet$ & & $\bullet$ & $\bullet$ & $\bullet$ \\ +% \href{https://docs.moodle.org/35/en/Short-Answer_question_type}{Short +% Answer} & $\bullet$ & $\bullet$ & $\bullet$ & $\bullet$ & & & +% & $\bullet$ & & & $\bullet$ & $\bullet$ \\ +% \href{https://docs.moodle.org/35/en/Matching_question_type}{Matching} +% & $\bullet$ & $\bullet$ & $\bullet$ & $\bullet$ & $\bullet$ & & +% & & & $\bullet$ & $\bullet$ & \\ +% \href{https://docs.moodle.org/35/en/True/False_question_type} +% {True/False} & $\bullet$ & & $\bullet$ & $\bullet$ & & & +% & & & & & $\bullet$ \\ +% \href{https://docs.moodle.org/35/en/Description_question_type} +% {Description} & & & $\bullet$ & $\bullet$ & & & +% & & & & & \\ +% ^^A\href{https://docs.moodle.org/35/en/Essay_question_type}{Essay} & \\\hline% +% \href{https://docs.moodle.org/35/en/Embedded_Answers_(Cloze)_question_type}{Cloze} +% & $\bullet$ & $\bullet$ & $\bullet$ & $\bullet$ & & & +% & & & & & \\\cmidrule(lr){1-1} +% \hspace{1em}Numerical & $\bullet$ & & & & & & +% & &$\bullet$ & & $\bullet$ & $\bullet$ & $\bullet$ \\ +% \hspace{1em}Short Answer & $\bullet$ & & & & & & +% & $\bullet$ & & & $\bullet$ & $\bullet$ \\ +% \hspace{1em}Multi (regular) & $\bullet$ & & & & $\bullet$ & & $\bullet$ +% & & & & $\bullet$ & $\bullet$ \\ +% \hspace{1em}Multi (horizontal)& $\bullet$ & & & & $\bullet$ & & $\bullet$ +% & & & & $\bullet$ & $\bullet$ \\ +% \hspace{1em}Multi (vertical)& $\bullet$ & & & & $\bullet$ & & +% & & & & $\bullet$ & $\bullet$ \\ +% \bottomrule +% \end{tabular} +% \end{table} % % \section{Conversion to HTML} % % Questions should be typed as usual for \LaTeX, -% including |\$| to obtain dollar signs, |$|'s for math shifts, -% |$$|'s for display math, et cetera. +% including |\$| to obtain dollar signs, |$|'s or |\(|...|\)| for math shifts, +% |$$|'s or |\[|...|\]| for display math, et cetera. % The package \textsf{moodle.sty} automatically converts % this \LaTeX\ code into HTML for web display. % -% The following table lists \LaTeX\ commands and environments that -% will be converted to HTML: -% \begin{center} -% \begin{tabular}{lll} -% |~| & |\#| & |\$| \\ -% |\&| & |\\| & |\S| \\ -% |\{| & |\}| & {\tt\catcode`\ =12\relax\catcode`\\=12\relax\ }\\ -% |\emph| & |\textbf| & |\par| \\ -% |\ldots| & |\dots| & |\relax| \\ -% |\euro| & |\texteuro| \\ -% |\begin{center}| \\ -% |\begin{enumerate}| \\ -% |\begin{itemize}| \\ -% |\begin{tikzpicture}| \\ -% \end{tabular} -% \end{center} -% Single and double quotation marks and the diacritical commands |\^|, |\'|, |\`|, |\"|, |\~|, and |\H| are also handled, -% as are the characters |\aa|, |\ae|, |\o|, |\ss|, |\l|, and their capitalizations. +% Table~\ref{tab:html} lists \LaTeX\ macros, commands, and environments that +% are specifically converted to HTML. +% \begin{table}[tbp] +% \centering +% \caption{Conversion of \LaTeX\ material to HTML.} +% \label{tab:html} +% \begin{tabular}{llll} +% \toprule +% \multicolumn{2}{l}{Macros} & Commands & Environnments \\ +% \cmidrule(lr){1-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4} +% |~| & |\#| &|\emph{}| & |\begin{center}|\\ +% |\$| & |\&| &|\textbf{}| & |\begin{enumerate}|\\ +% |\\| & |\par| &|\textit{}| & |\begin{itemize}|\\ +% |\&| & |\S| & |\texttt{}| & |\begin{tikzpicture}|\\ +% |\{| & |\}| & |\textsc{}| & \\ +% |\|\textvisiblespace & |\relax| & |\underline{}| &\\ +% |\,| & |\thinspace| & |\textsuperscript{}| & \\ +% |\dots| & |\ldots| & |\up{}| & \\ +% |\euro| & |\texteuro| & |\fup{}| & \\ +% |\TeX| & |\LaTeX|& |\textsubscript{}| & \\ +% |\_| & |\textbackslash| & |\url{}| & \\ +% & & |\href{}{}| & \\ +% & & |\tikz[]{}| & \\ +% & & |\includegraphics[]{}| & \\ +% & & |\verbatiminput{}| & \\ +% & & |\VerbatimInput[]{}| & \\ +% & & |\LVerbatimInput[]{}| & \\ +% & & |\BVerbatimInput[]{}| & \\ +% & & |\inputminted[]{}{}| & \\ +% \bottomrule +% \end{tabular} +% \end{table} +% Single and double quotation marks, french quotation marks, inverted exclamation and +% question marks, and the diacritical +% commands |\^|, |\'|, |\`|, |\"|, |\~|, |\c|, |\H|, |\u| and |\v| are also handled, +% as are the characters |\aa|, |\ae|, |\l|, |\oe|, |\o|, |\ss|, and their +% capitalizations. See Tables~\ref{tab:diacritical}, \ref{tab:ligatures}, and +% \ref{tab:other} for more details. % % In addition, |<| and |>| will be converted to |<| and |>| \emph{within math mode only}. % If they should be typed outside of math mode, they will be passed as typed to % the HTML, and probably interpreted by students' browsers as HTML tags % or other unpredicated results. % -% Be aware that \emph{\textsf{moodle.sty} does not know how to convert any +% Be aware that \emph{\textsf{moodle} does not know how to convert any % other \TeX\ or \LaTeX\ commands to HTML.} % If other sequences are used, they may be passed verbatim to the XML file % or may cause unpredicted results. +% \DescribeMacro{\htmlregister}The |\htmlregister| command lets you specify +% the macros that must be expanded in the XML file. It works only when no +% optional argument is used. +% +% \DescribeMacro{\moodleregisternewcommands} +% When the list of macros is long, it becomes cumbersome to record them +% individually for expansion. +% Calling |\moodleregisternewcommands| triggers the automatic +% expansion of macros defined subsequently using |\newcommand|, +% |\renewcommand|, |\providecommand|, or their starred variants. +% Again, this works only if the macros are defined \emph{without} optional +% argument. % % If you think of another \LaTeX\ command that should be changed to an HTML equivalent, -% please contact the author at \url{anders.hendrickson@snc.edu} +% please contact the maintainer at \url{guerquin-kern AT crans.org} % so that it may be added to a future revision of the package. % % \section{Graphics} -% The \textsf{moodle.sty} package can handle two kinds of graphics seamlessly. +% The \textsf{moodle} package can handle two kinds of graphics seamlessly. % External graphics files may be included with the |\includegraphics| command -% from the |graphicx| package, -% and graphics may be generated internally using \TikZ. In either case, the -% graphics will be embedded in base-64 encoding directly within +% from the |graphicx| package, and graphics may be generated internally using \TikZ. +% In either case, the graphics will be embedded in base-64 encoding directly within % the Moodle~XML produced. This prevents the hassle of managing separate % graphics files on the Moodle server, as Moodle will store the picture % within the question in the question bank. % +% \subsection{Default \texttt{includegraphics}} % \DescribeMacro{\includegraphics}\DescribeMacro{height}\DescribeMacro{width} % When using |\includegraphics|, the only options currently supported % are |height| and |width|. Attempts to use other |\includegraphics| options, % such as |scale| or |angle|, will affect the PDF but not the XML output. -% The dimensions set by |height| and |width| are \TeX\ dimensions such as |4in| or |2.3cm|. +% The dimensions set by |height| and |width| are \TeX\ dimensions such as \texttt{4\,in} +% or \texttt{2.3\,cm}. % In order to prepare the image for web viewing, this package converts those % dimensions to pixels using a default of % 103 pixels per inch.\footnote{This @@ -627,11 +1027,50 @@ % That value may be changed by setting the |ppi| key (e.g., |ppi=72|); % this is probably best done for the entire document with a |\moodleset| command, % rather than image-by-image. -% -% The mechanism used is somewhat fragile and relies upon one \TikZ\ library and three free external programs. +% \DescribeMacro{\graphicspath} +% You can use |\graphicspath{{|\emph{path}|}}| to specify a directory where the +% pictures to be included are located. +% +% A special rule was added for the inclusion of GIF pictures (|.gif| extension). +% These files are passed as-is to the XML, preserving potential animations. +% However, as pdf\TeX\ engines do not support the GIF format, the picture is +% passed to the PDF output after a conversion to the PNG format. When the GIF +% file is animated, only its first frame is passed to the PDF. +% +%^^A \DescribeMacro{\DeclareGraphicsAlien} Users may declare other graphic +%^^A formats with the command |\DeclareGraphicsAlien|\marg{alien extension} +%^^A \marg{native extension}\marg{command line for conversion}. +% +% \subsection{\TikZ\ Pictures} +% When \TikZ\ is loaded and used to define pictures, \textsf{moodle} invokes +% the |external| \TikZ\ library, so that each |tikzpicture| environment is compiled +% to a freestanding PDF file. +% +% \subsection{Package Option \texttt{tikz}}\label{subsec:tikz} +% \DescribeMacro{tikz} +% The \textsf{moodle} package admits a \texttt{tikz} option which has the following effects: +% \begin{itemize} +% \item the package \texttt{tikz} is loaded. +% \item \texttt{includegraphics} is embedded in a \TikZ\ picture. Consequences are that +% \begin{itemize} +% \item the pictures encoded in the XML file are resampled. This prevents encoding +% images at a higher resolution than rendered by Moodle. +% \item the full set of \texttt{includegraphics} options is accessible, +% e.g.~|scale=.5|, |angle=90|, or |width=.2\textwidth|. +% \end{itemize} +% \item \DescribeMacro{\embedaspict} a macro |\embedaspict{...}| is provided for the +% inclusion of inline \LaTeX\ material as images. This can serve as a workaround to +% overcome limitations of this package---like the conversion of tabulars to HTML--- +% or limitations of Moodle itself. +% For the definition of this macro, the package \texttt{varwidth} is loaded. +% \item optimizations of the \TikZ-external library are disabled. Compilation might get +% sensibly slower. +% \end{itemize} +% +% \subsection{External Tools} +% The mechanisms used for handling graphics are somewhat fragile and rely upon +% three free external programs. % \begin{enumerate} -% \item \textsf{moodle.sty} invokes |\usetikzlibrary{external}|, -% so that each |tikzpicture| environment is compiled to a freestanding PDF file. % \item GhostScript (\url{www.ghostscript.com}) is used to convert the PDF output % from \TikZ\ into a PNG raster graphics file. % The default command line is presumed to be |gswin64c.exe| @@ -639,75 +1078,459 @@ % or |gs| (if |\ifwindows| returns false). % If your system requires a different command line to invoke Ghostscript, % \DescribeMacro{\ghostscriptcommand} -% you may change it by invoking |\ghostscriptcommand|\marg{executable filename}. -% \item When external graphics files such as JPG or GIF are included, +% you may change it by invoking: +% \begin{quote} +% |\ghostscriptcommand|\marg{executable filename} +% \end{quote} +% \item When external graphics files such as PDF are included, % the open-source ImageMagick software (\url{www.imagemagick.org}) % converts each file to PNG format. % The command line for ImageMagick is the nondescript word |convert|, % \DescribeMacro{\imagemagickcommand} % but may be changed by invoking |\imagemagickcommand|\marg{executable filename}. -% \item Finally, the OpenSSL toolkit (\url{www.openssl.org}) is used to base64-encode -% the PNG file so that it can be included directly in the text of the XML file. -% The command line is presumed to be |openssl|, but can be changed with -% \DescribeMacro{\opensslcommand} -% |\opensslcommand|\marg{executable filename}. +% \item OptiPNG (\url{http://optipng.sourceforge.net/}) is used to optimize the PNG images. +% The command line is presumed to be |optipng|, but can be changed with +% \DescribeMacro{\optipngcommand} |\optipngcommand|\marg{executable filename}. % \end{enumerate} % % Please note the following vital points to make the graphics handling work: % \begin{itemize} % \item As of now, graphics are only supported when compiling directly to a PDF -% with |pdflatex|. Including PS graphics or using \TikZ\ with the DVI$\to$PS workflow is not +% with |pdflatex|. Including PS graphics or using \TikZ\ with the DVI$\to$PS workflow is not % yet supported. -% \item Filenames should not contains spaces or special characters like |_| or |\|. -% \item You must have Ghostscript, ImageMagick, and OpenSSL installed on your system -% to fully use the graphics-handling capabilities of \textsf{moodle.sty}. +%^^A \item Filenames should not contains spaces or, under windows, special characters like |_| or |\|. +% \item You must have Ghostscript and ImageMagick installed on your system +% to fully use the graphics-handling capabilities of \textsf{moodle}. +% \item If OptiPNG is not installed, the corresponding system calls will fail with otherwise no +% impact on the compilation process: PNG files are passed unoptimized to the XML output. % \item \LaTeX\ must be able to call system commands; that is, |\write18| must be enabled. % For Mik\TeX, this means adding |--enable-write18| to the command line of |pdflatex|; % for \TeX Live, this means adding |--shell-escape=true|. +% \item Due to security issues with old versions of Ghostcript, some systems default to a +% policy that prevents the conversion of PDF and PS to PNG. Assuming that, as a user of +% \textsf{moodle} which requires shell escape capabilities, you either use a sandboxed +% environment or trust the files handled at the system-level, you may want to disable this +% over-zelous security policy. For example, +% \href{https://stackoverflow.com/a/52661288/14608059}{see this}. +% \item Users of the |circuitikz| package must enclose their circuits' \TikZ\ code in the +% |tikzpicture| environment instead of |circuitikz|. That is required, +% as of \TikZ\ 2.1, by the |external| library. % \end{itemize} +% +% \subsection{Package Option \texttt{svg}}\label{subsec:svg} +% +% \paragraph{Important Notice} \emph{The \texttt{svg} option is an experimental feature +% introduced in \textsf{moodle} v0.8. It has been tested exclusively under Linux, with +% TeXLive 2020, Inkscape v1.0.1 and Scour 0.38.2.} +% +% \DescribeMacro{svg} The \textsf{moodle} package admits an experimental \texttt{svg} +% option which has the following effects: +% \begin{itemize} +% \item |\includegraphics| can be used to import SVG graphic files directly +% (extension |.svg| or |.SVG|). In this case, the SVG file is passed as-is to the +% XML output and is converted using \href{https://inkscape.org/} +% {Inkscape} (must be installed) for inclusion in the PDF output. +% \item the graphic files in PDF format are converted to the SVG format using +% \href{https://inkscape.org/}{Inkscape} (must be installed), rather than beeing +% rasterized. Before inclusion to the XML output, the SVG file is optimized using +% the \href{https://github.com/scour-project/scour}{Scour} utility. This +% optimization step is optional in the sense that, if the Scour call fails, +% the unoptimized SVG file will be passed to the XML output. +% Two processes benefit from this PDF$\to$SVG conversion: +% \begin{itemize} +% \item inclusion of PDF graphics with |\includegraphics|, and +% \item Tikz pictures that are externalized. +% \end{itemize} +% \end{itemize} +% +% \DescribeMacro{\PDFtoSVGcommand}\DescribeMacro{\SVGtoPDFcommand} +% \DescribeMacro{\optiSVGcommand} The call of external tools can be changed using +% the macros |\PDFtoSVGcommand| \marg{\dots}, |\SVGtoPDFcommand|\marg{\dots} and +% |\optiSVGcommand|\marg{\dots}. +% +% \section{Verbatim Code} +% Because, for HTML translation, \textsf{moodle} parses the body of questions, the use of +% verbatim code results in compilation errors. This is why the use of |\verb|, +% |\begin{verbatim}| and other standard utilities is not supported. +% +% However, using the following three utilities, verbatim code can be imported from an external file: +% \begin{enumerate} +% \item \DescribeMacro{\verbatiminput}|\verbatiminput|\marg{filename} from the \textsf{verbatim} +% package inserts verbatim code in both the PDF and the XML for moodle, without fancy additions. +% \item \DescribeMacro{\VerbatimInput}The macro |\VerbatimInput|\marg{options}\marg{filename} from +% \textsf{fancyvrb} or \textsf{fvextra} does more, with several options and settings offered +% (see below). +% The variants \DescribeMacro{\BVerbatimInput}|\VBerbatimInput| and +% \DescribeMacro{\LVerbatimInput}|\LVerbatimInput| are also supported, with identical +% effect on the XML output. +% The variants with a star are unsupported and result in errors when used. +% \item \DescribeMacro{\inputminted}On top of that |\inputminted|\oarg{options}\marg{lang} +% \marg{filename}from the \textsf{minted} package offers syntaxic highlighting tailored to the +% specified language. +% \end{enumerate} +% The \textsf{moodle} package handles these three commands to pass the code in the output XML. +% +% With |\VerbatimInput| and |\inputminted|, the options that are taken care of for XML +% generation are listed in Table~\ref{tab:verbatim-options}. Using |\fvset|\marg{key=value,...}, +% options can be set globally. Equivalently, with \textsf{minted}, +% |\setminted|\oarg{lang}\marg{key=value,...} is available. +% +% \begin{table}[tbp] +% \centering +% \begin{threeparttable}[b] +% \caption{Options and corresponding values considered for XML generation of verbatim material +% with \texttt{VerbatimInput} and \texttt{inputminted}.} +% \label{tab:verbatim-options} +% \begin{tabular}{ll} +% \toprule +% Option keys & Possible values\\\cmidrule(lr){1-1}\cmidrule(lr){2-2} +% ^^A\texttt{commentchar} & \meta{character}\\ +% \texttt{gobble} & \meta{integer}\\ +% \texttt{autogobble}\tnote{1} & \texttt{true} or \texttt{false}\\ +% \texttt{tabsize} & \meta{integer}\\ +% \texttt{numbers} & \texttt{none}, \texttt{left}, \texttt{right}, or \texttt{both}\tnote{2}\\ +% \texttt{firstnumber} & \texttt{auto}, \texttt{last}, or \meta{integer}\\ +% \texttt{firstline} & \meta{integer}\\ +% \texttt{lastline} & \meta{integer}\\ +% \texttt{numberblanklines} & \texttt{true} or \texttt{false}\\ +% \texttt{highlightlines}\tnote{2} & \marg{coma-separated list of integers or ranges}\\ +% \texttt{style}\tnote{1} & \meta{string}\\ +% \bottomrule +% \end{tabular} +%\begin{tablenotes} +%\item[1] \texttt{autogobble}, \texttt{numbers=both}, and \texttt{style} are offered only by \textsf{minted}. +%\item[2] line highlighting is offered only with \textsf{fvextra} or \textsf{minted} loaded. +%\end{tablenotes} +%\end{threeparttable} +%\end{table} +% +% In order to define the verbatim code from the \LaTeX\ document itself, it is still possible +% to use, outside the scope of the \textsf{moodle} questions, the environments |filecontents*| (from the +% \textsf{filecontents} package or \LaTeX\ kernel itself since 2019) or |VerbatimOut| +% (from the \textsf{fancyvrb} and \textsf{fvextra} packages). +% +% When code decorated with left-side line numbers is placed in question items, the output PDF could +% show a collision between numbers of the item and the first line. To avoid this, |\LVerbatimInput| or +% |\BVerbatimInput| can be used. Instead, when \textsf{minted} is used, the ``left-right'' mode can be +% enforced with the \LaTeX\ command: +% \begin{quote} +% |\RecustomVerbatimEnvironment{Verbatim}{LVerbatim}{}| +% \end{quote} +% +% When using utilies from \textsf{fancyvrb}, \textsf{fvextra}, or \textsf{minted}, \textsf{moodle} sets +% framing options for the display of code in the output PDF: +% \begin{quote} +% |\fvset{frame=lines,label={[Beginning of code]End of code},|\\ +% | framesep=3mm,numbersep=9pt}| +% \end{quote} +% These settings can be overidden using |\fvset| after the preamble. +% +% \section{Calculated Questions} +% Moodle's calculated questions are not supported by this package. +% +% However, as \href{https://github.com/avohns/python-latex-moodle-quiz}{demonstrated by A. +% Vohns}, an advanced scripting language may be used to generate a series of questions sharing +% the same prototype. +% +% We suggest to apply a specific tag to these questions. After import in Moodle, when creating +% a quizz, this tag can be selected to narrow down a random selection of question. +% This would mimic the behavior of calculated questions while bringing the flexibility of your +% favorite scripting language. +% +% Here are two examples inspired from the work of A. Wohns. The first one relies on the +% native Lua capabilities of \LuaLaTeX. +% \begin{VerbatimOut}[gobble=1]{minted.doc.out} +% \begin{quiz}[tags={calculated}]{Example Quiz} +% \directlua{ +% \end{VerbatimOut} +% \inputminted[gobble=2,frame=topline]{latex}{minted.doc.out} +% \begin{VerbatimOut}[gobble=1]{minted.doc.out} +% function clozenum_print(pair,op,result) +% tex.print("\\begin{numerical}$"..pair[1].." "..op.." "..pair[2].." +% =$".."\\item ",result,"\\end{numerical}") +% end +% function cloze_print(pair,points) +% tex.print("\\begin{cloze}[points="..points.."]{Arithmetic Quiz +% ("..pair[1]..", "..pair[2]..")}Solve the following tasks!\\\\") +% clozenum_print(pair,"+",pair[1]+pair[2]) +% clozenum_print(pair,"-",pair[1]-pair[2]) +% clozenum_print(pair,"*",pair[1]*pair[2]) +% if pair[1]/pair[2]==math.floor(pair[1]/pair[2]) then +% clozenum_print(pair,":",math.floor(pair[1]/pair[2])) +% end +% tex.print("\\end{cloze}") +% end +% for x = 2,4 do +% for y = 2,4 do +% if x>y then +% if x/y==math.floor(x/y) then points=4 else points=3 end +% cloze_print({x,y},points) +% end +% end +% end +% \end{VerbatimOut} +% \inputminted[]{lua}{minted.doc.out} +% \begin{VerbatimOut}[gobble=1]{minted.doc.out} +% } +% \end{quiz} +% \end{VerbatimOut} +% \inputminted[gobble=2,frame=bottomline]{latex}{minted.doc.out} +% The second example makes use of the \textsf{python} package (|\usepackage{python}|). +% \begin{VerbatimOut}[gobble=1]{minted.doc.out} +% \begin{quiz}[tags={calculated}]{Example Quiz} +% \begin{python} +% \end{VerbatimOut} +% \inputminted[gobble=2,frame=topline]{latex}{minted.doc.out} +% \begin{VerbatimOut}[gobble=1]{minted.doc.out} +% def clozenum_print(pair,op,result): +% print(rf"""\begin{{numerical}} +% ${pair[0]} {op} {pair[1]} =$\item {result} +% \end{{numerical}}""") +% def cloze_print(pair,points): +% print(rf"""\begin{{cloze}}[points={points}]{{Arithmetic Quiz +% {(pair[0],pair[1])}}}Solve the following tasks!\\""") +% clozenum_print([x,y],"+",x+y) +% clozenum_print([x,y],"-",x-y) +% clozenum_print([x,y],"*",x*y) +% if pair[0]/pair[1] == pair[0]//pair[1]: +% clozenum_print([x,y],":",x//y) +% print("\end{cloze}") +% for x in range(2,5): +% for y in range(2,5): +% if x > y: +% if x/y == x//y: +% points=4 +% else: +% points=3 +% cloze_print([x,y],points) +% \end{VerbatimOut} +% \inputminted[]{python}{minted.doc.out} +% \begin{VerbatimOut}[gobble=1]{minted.doc.out} +% \end{python} +% \end{quiz} +% \end{VerbatimOut} +% \inputminted[gobble=2,frame=bottomline]{latex}{minted.doc.out} +% These two codes yield the same XML content. % -% \newpage % \section{Known Limitations and Call for Bug Reports} -% Some features of Moodle quizzes have not yet been implemented in \textsf{moodle.sty}. +% Table~\ref{tab:support-limitations} lists some different features supported, limitations, and +% bugs. +% +%\begin{table}[tbp] +%\centering +%\begin{threeparttable}[b] +%\caption{Content enrichment (pictures, equations) support after XML import in Moodle v3.5.7, +% depending on the question type.} +%\label{tab:support-limitations} +%\begin{tabular}{lccc} +% \toprule +% & \multicolumn{3}{l}{XML rendering in\dots}\\\cmidrule(lr){2-4} +%Question type & Question & Answer & Feedback\\\cmidrule(lr){1-1}\cmidrule(lr){2-2} +%\cmidrule(lr){3-3}\cmidrule(lr){4-4} +% \href{https://docs.moodle.org/35/en/Multiple_Choice_question_type}{Multichoice} +%& yes & yes & yes \\ +% \href{https://docs.moodle.org/35/en/Numerical_question_type}{Numerical} +%& yes & no\tnote{1} & yes \\ +% \href{https://docs.moodle.org/35/en/Short-Answer_question_type}{Short Answer} +% & yes & no\tnote{1} & yes \\ +% Matching (\href{https://docs.moodle.org/35/en/Matching_question_type}{std}) +%& yes & no\tnote{2} & no\tnote{3} \\ +% Matching (\href{https://docs.moodle.org/35/en/Drag_and_drop_matching_question_type}{dd}) +% & yes & yes\tnote{4} & no\tnote{3} \\ +% \href{https://docs.moodle.org/35/en/Essay_question_type}{Essay} +%& yes & yes\tnote{5,6} & yes\tnote{5} \\ +% \href{https://docs.moodle.org/35/en/True/False_question_type}{True/False} +%& yes & no & yes \\ +% \href{https://docs.moodle.org/35/en/Description_question_type}{Description} +%& yes & $\varnothing$ & yes \\ +%\href{https://docs.moodle.org/35/en/Embedded_Answers_(Cloze)_question_type}{Cloze} & +%yes & $\varnothing$& $\varnothing$ \\\cmidrule(lr){1-1} +%\hspace{1em}Numerical & yes & no\tnote{1} & yes \\ +%\hspace{1em}Short Answer & yes & no\tnote{1} & yes\tnote{7} \\ +%\hspace{1em}Multi (regular) & yes & no\tnote{2} & yes\tnote{7} \\ +%\hspace{1em}Multi (horizontal) & yes & yes & yes \\ +%\hspace{1em}Multi (vertical) & yes & yes & yes \\\bottomrule +%\end{tabular} +%\begin{tablenotes} +%\item[1] Moodle prompts the student for an answer and then compares it to the +%solutions provided. This is text-only. +%\item[2] Moodle uses a dropdown list to let one choose among the possible +%answers. This forbids either picture inclusion and \LaTeX\ rendering. +%\item[3] Not supported by Moodle (in this context, answer-specific feedback +%represents lots of possible combinations). +%\item[4] The drag-and-drop-matching plugin seems broken before version 1.6 +%20190409. Moodle's XML import fails with a \textsf{dmlwriteexception} when +%the field content exceeds few hundreds characters. This prevents the inclusion +%of most base64 images and maybe some complicated equations. +%\item[5] For this question type and in the context of XML generation, the +%Answer column represents the ``template" while the Feedback column represents +%the ``notes for the grader". Obviously, the grading process is not automatic +%and there is no answer-specific feedback. +%\item[6] Picture and \LaTeX\ rendering could be done, but only after +%submission and only if the keyval ``response format" is set to ``html". +%\item[7] Moodle only reveals the feedback when hovering the checkmark or X +%mark with the mouse. +%\end{tablenotes} +%\end{threeparttable} +%\end{table} +% +% Tables~\ref{tab:diacritical}, \ref{tab:ligatures}, and \ref{tab:other} describe the current +% support for some special characters, accents and other diacritical marks. +% +%\begin{table}[tbp] +% \centering +% \caption{Support for diacritical marks +% in a UTF8-coded \TeX~document compiled with (pdf)\LaTeX\ (packages +% \texttt{inputenc} with option \texttt{utf8} and \texttt{fontenc} with option \texttt{T1}), +% \LuaLaTeX\ or \XeLaTeX\ (package \texttt{fontspec}).} +% \label{tab:diacritical} +% \begin{threeparttable}[t] +% \begin{tabular}{*{6}{l}} +% \toprule +% \multicolumn{4}{l}{Input type} & \multicolumn{2}{l}{Engine support}\\ +% \cmidrule(lr){1-4}\cmidrule(lr){5-6} +% \multicolumn{2}{l}{Unicode} & \multicolumn{2}{l}{\LaTeX} & \XeLaTeX\ or \LuaLaTeX & (pdf)\LaTeX \\ +% \cmidrule(lr){1-2}\cmidrule(lr){3-4}\cmidrule(lr){5-5}\cmidrule(lr){6-6} +% \aa & \AA & \verb|\aa| & \verb|\AA| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \`a & \`A & \verb|\`a| & \verb|\`A| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \^a & \^A & \verb|\^a| & \verb|\^A| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \~a & \~A & \verb|\~a| & \verb|\~A| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \'e & \'E & \verb|\'e| & \verb|\'E| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \`e & \`E & \verb|\`e| & \verb|\`E| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \"e & \"E & \verb|\"e| & \verb|\"E| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \^e & \^E & \verb|\^e| & \verb|\^E| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \^i & \^I & \verb|\^i| & \verb|\^I| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \"i & \"I & \verb|\"i| & \verb|\"I| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \~n & \~N & \verb|\~n| & \verb|\~N| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \~o & \~O & \verb|\~o| & \verb|\~O| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \"o & \"O & \verb|\"o| & \verb|\"O| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \^o & \^O & \verb|\^o| & \verb|\^O| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \`u & \`U & \verb|\`u| & \verb|\`U| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \"u & \"U & \verb|\"u| & \verb|\"U| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \^u & \^U & \verb|\^u| & \verb|\^U| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \c{c} & \c{C} & \verb|\c{c}| & \verb|\c{C}| & Unicode and \LaTeX & Unicode and \LaTeX \\ +% \c{s} & \c{S} & \verb|\c{s}| & \verb|\c{S}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \c{t} & \c{T} & \verb|\c{t}| & \verb|\c{T}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \H{o} & \H{O} & \verb|\H{o}| & \verb|\H{O}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \H{u} & \H{U} & \verb|\H{u}| & \verb|\H{U}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \"y & \"Y & \verb|\"y| & \verb|\"Y| & Unicode and \LaTeX & \LaTeX only\\ +% \u{a} & \u{A} & \verb|\u{a}| & \verb|\u{A}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \u{e} & \u{E} & \verb|\u{e}| & \verb|\u{E}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \u{g} & \u{G} & \verb|\u{g}| & \verb|\u{G}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \u{\i} & \u{I} & \verb|\u{\i}| & \verb|\u{I}| & Unicode and \LaTeX & \LaTeX\ only\tnote{1}\\ +% \u{o} & \u{O} & \verb|\u{o}| & \verb|\u{O}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \v{c} & \v{C} & \verb|\v{c}| & \verb|\v{C}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \v{d} & \v{D} & \verb|\v{d}| & \verb|\v{D}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \v{e} & \v{E} & \verb|\v{e}| & \verb|\v{E}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \v{l} & \v{L} & \verb|\v{l}| & \verb|\v{L}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \v{n} & \v{N} & \verb|\v{n}| & \verb|\v{N}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \v{r} & \v{R} & \verb|\v{r}| & \verb|\v{R}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \v{s} & \v{S} & \verb|\v{s}| & \verb|\v{S}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \v{t} & \v{T} & \verb|\v{t}| & \verb|\v{T}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \v{z} & \v{Z} & \verb|\v{z}| & \verb|\v{Z}| & Unicode and \LaTeX & \LaTeX\ only\\ +% \bottomrule +% \end{tabular} +% \begin{tablenotes} +% \item[1] \XeLaTeX\ renders correctly |\u{i}|, that is, without a superscript dot. +% Instead, with (pdf)\LaTeX\ the rendering of |\u{i}| is flawed by the +% superposition of the superscript dot and the breve diacritical mark. +% Both engines render |\u{\i}| as expected. +% \end{tablenotes} +% \end{threeparttable} +% \end{table} +% +%\begin{table}[tbp] +% \centering +% \begin{threeparttable}[t] +% \caption{Support for ligatures in a UTF8-coded \TeX~document compiled with (pdf)\LaTeX\ (packages +% \texttt{inputenc} with option \texttt{utf8}, \texttt{fontenc} with option \texttt{T1}), +% \LuaLaTeX\ or \XeLaTeX\ (package \texttt{fontspec}).} +% \label{tab:ligatures} +% \begin{tabular}{llllll} +% \toprule +% \multicolumn{4}{l}{Input type} & \multicolumn{2}{l}{Engine support}\\ +% \cmidrule(lr){1-4}\cmidrule(lr){5-6} +% \multicolumn{2}{l}{Unicode} & \multicolumn{2}{l}{\LaTeX} & \XeLaTeX \ or \LuaLaTeX& (pdf)\LaTeX \\ +% \cmidrule(lr){1-2}\cmidrule(lr){3-4}\cmidrule(lr){5-6}\cmidrule(lr){6-6} +% \ae & \AE & \verb|\ae| & \verb|\AE| & Unicode and \LaTeX & \LaTeX\ only\\ +% \oe & \OE & \verb|\oe| & \verb|\OE| & Unicode and \LaTeX & \LaTeX\ only\\ +% \ss & \SS & \verb|\ss| & \verb|\SS| & Unicode and \LaTeX\tnote{1} & \LaTeX\ only\tnote{2}\\ +% \bottomrule +% \end{tabular} +% \begin{tablenotes}[b] +% \item[1] the Libertine font, used in this documentation and available for instance via the +% package |libertine|, defines the glyph \SS. Most fonts do not define this glyph. +% \item[2] \LaTeX\ defines the \verb|\SS| macro but (pdf)\LaTeX\ renders it as a doubled capital S. +% \end{tablenotes} +% \end{threeparttable} +% \end{table} +% +%\begin{table}[tbp] +% \centering +% \begin{threeparttable}[b] +% \caption{Support for other glyphs and punctuation marks in a UTF8-coded \TeX~document compiled +% with (pdf)\LaTeX\ (packages \texttt{inputenc} with option \texttt{utf8}, \texttt{fontenc} with +% option \texttt{T1}), \LuaLaTeX\ or \XeLaTeX\ (package \texttt{fontspec}).} +% \label{tab:other} +% \begin{tabular}{llllll} +% \toprule +% \multicolumn{4}{l}{Input type} & \multicolumn{2}{l}{Engine support}\\ +% \cmidrule(lr){1-4}\cmidrule(lr){5-6} +% \multicolumn{2}{l}{Unicode} & \multicolumn{2}{l}{\LaTeX} & \XeLaTeX\ or \LuaLaTeX & (pdf)\LaTeX \\ +% \cmidrule(lr){1-2}\cmidrule(lr){3-4}\cmidrule(lr){5-5}\cmidrule(lr){6-6} +% \l & \L & \verb|\l| & \verb|\L| & Unicode and \LaTeX & \LaTeX\ only\\ +% \o & \O & \verb|\o| & \verb|\O| & Unicode and \LaTeX & \LaTeX\ only\\ +% « & & \verb|\guillemotleft|\tnote{1} & & Unicode and \LaTeX & \LaTeX\ only\\ +% » & & \verb|\guillemotright|\tnote{1} & & Unicode and \LaTeX & \LaTeX\ only\\ +% ¿ & & \verb|\textquestiondown| & & Unicode and \LaTeX & \LaTeX\ only\\ +% ¡ & & \verb|\textexclamdown| & & Unicode and \LaTeX & \LaTeX\ only\\ +% \bottomrule +% \end{tabular} +% \begin{tablenotes} +% \item[1] the package |babel| loaded with option |french| defines |\og| and |\fg| for +% the same symbols. These are also supported by \textsf{moodle}. +% \end{tablenotes} +% \end{threeparttable} +% \end{table} +% Some features of Moodle quizzes have not yet been implemented in \textsf{moodle}. % Here is a non-exhaustive list. % \begin{itemize} % \item Moodle's feature of designating feedback for correct, % partially correct, and incorrect answers. -% \item Calculated questions; that is, automatically generated numerical questions -% using randomly chosen numbers. +%^^A \item Calculated questions; that is, automatically generated numerical questions +%^^A using randomly chosen numbers. % \item Hints -% \item Keywords -% \item So-called ``description'' questions. -% \item Shuffled answers in multiple choice cloze subquestions. +% \item Multiple keywords (tags) for questions % \end{itemize} -% I have used Version 0.5 for one semester's teaching, -% but if other users adopt this package, I fully expect them to find bugs. -% \emph{Please} send all bugs you find to \url{anders.hendrickson@snc.edu}, -% so that I can fix them for subsequent versions. +% The authors have used this package together with a limited number of colleagues +% for a few semesters of teaching. If other users adopt this package, we fully expect them +% to find bugs. \emph{Please} send all bugs you find to \url{guerquin-kern@crans.org}, +% so that we can fix them for subsequent versions. % % \section{Compatibility} -% This package has been written for and tested with the implementation of +% This package has been originally written for and tested with the implementation of % Moodle 2.9 run by Moodlerooms for St.~Norbert College in January 2016. -% Future versions of this package will probably include some support for -% specifying your version of Moodle in the |.tex| file to help ensure compatability. +% Since then, it has been successfully combined with Moodle 3.5. +% Future versions of this package might include some support for +% specifying your version of Moodle in the |.tex| file to help ensure compatibility. % % As the ultimate purpose of this package is the generation of XML files, -% future versions of \textsf{moodle.sty} will attempt to maintain backwards -% compatability with earlier versions of regarding the XML output, apart from +% future versions of \textsf{moodle} will attempt to maintain backwards +% compatability with earlier versions regarding the XML output, apart from % bug fixes. % Backwards compatibility of the PDF output is not yet guaranteed, however, % in case the author or users discover better ways for the PDF to display % the underlying XML data to be proofread. % % In other words, compiling your current |.tex| file with a future version -% of \textsf{moodle.sty} should produce the same XML file it does now +% of \textsf{moodle} should produce the same XML file it does now % (apart from bug fixes), % but it might produce a more informative, and hence different, % PDF output. % % % \section{Unrelated Tip: Quality of Moodle \TeX\ Images} -% This has nothing to do with |moodle.sty|, but is a Frequently Asked Question +% This has nothing to do with \textsf{moodle}, but is a Frequently Asked Question % in is own right. % On some servers, at least, Moodle's default ``\TeX\ Filter'' for % displaying mathematical notation is of abysmally poor quality, rending mathematics @@ -716,40 +1539,201 @@ % but turn ``MathJax'' \emph{on}. This forces \TeX\ code to be rendered by MathJax % instead of Moodle, producing much higher-quality results. % +% ^^A\clearpage +% \changes{v0.5}{2016/01/05}{Initial version} +% \changes{v0.6}{2019/02/18}{Bux-fixing release} +% \changes{v0.7}{2020/07/09}{Feature extensions} +% \changes{v0.8}{2021/01/04}{Bug fixes and feature extensions} +% \begin{changelog}[title={Version History},author={Matthieu Guerquin-Kern}] +% \begin{version}[version=0.8,date=2021-01-04] +% \added +% \item Support for inclusion of GIF pictures. +% \item Added package option |svg| to avoid the rasterization of vector graphics. +% \item New macro |\setsubcategory| to define subcategories, reflected in PDF and XML. +% \item Package option |handout| for sharing PDF with students. +% \item Extensions can be omitted when including pictures. +% \item Description question type. +% \item \LuaLaTeX\ is now supported (and recommended for UTF8-coded sources). +% \item Examples of ways to reproduce the behavior of calculated questions. +% \item Command to trigger the automatic recording of new commands. +% \item Mechanism to match |fraction| key to values accepted by Moodle. +% \item A |fractiontol| key to control the tolerance in this mechanism. +% \item Support for inverted punctuation marks |¿| and |¡|. +% \item Support for |\_| and |\textbackslash|. +% \item Support for the wildcard character as an answer in numerical questions. +% \changed +% \item Template of Essay questions is now shown in PDF. +% \item The macro |\setcategory| is reflected by a new section in PDF. +% \item In matching questions, warnings are raised if the number of items is insufficient. +% \item Improved display of matching questions in PDF. +% \item The package \textsf{iftex} is now required. +% \item An error is thrown when |fraction| is set to an invalid value. +% \item In numerical questions, the tolerance can be set in exponent form. +% \item Nicer PDF rendering of numbers in numerical questions if \textsf{siunitx} is loaded. +% \item Included PNG and JPEG files are now directly converted to base64. +% \fixed +% \item TeX's inline math (|$...$|) can now contain escaped dollar signs (|\$|). +% \item Closing braces escaped in cloze subquestions outside math environment. +% \item The scope of the |tolerance| key is now respected. +% \end{version} +% \begin{version}[version=0.7,date=2020-09-06] +% \added +% \item Support for inclusion of verbatim code. +% \item Package option \texttt{tikz}. +% \item Support for |\"Y| and |\"y|. +% \item New commands converted to XML. +% \item Adding a stamp comment in XML, package option offered to disable +% this behavior. +% \item Support for the |\tikz| command. +% \item A different directory can be specified for picture inclusion. +% \item Warn user of the \texttt{babel} package set for french that autospacing +% must be deactivated. +% \item Square bracket math delimiters are recognized and converted properly. +% \item Support of breve and caron diacritical marks. +% \changed +% \item In multi with multiple answers allowed, choosing all options no longer +% results in a good grade. An automatic penalty mechanism is introduced. +% Can be overridden by manually setting fractions. +% \removed +% \item Irrelevant \texttt{penalty} tag in cloze subquestions. +% \fixed +% \item Non-integer fractions can now be specified in cloze subquestions. +% \item Signifiantly squeeze PNG images size by skipping ancillary data. +% \item Enumerate or itemize environment can now be nested in question items. +% \item Several pictures can be included in a question without being mixed +% in the XML file. +% \item management and rendering of fraction in questions. +% \item Correctly handling a \LaTeX\ starting the last item of a question. +% \item Closing braces escaped in cloze subquestions. This allows \LaTeX\ +% equations or images to be included. +% \item Image inclusion with MacOS. +% \end{version} +% \begin{version}[version=0.6b,date=2019-11-27] +% \added +% \item New package options to set section or subsection at the quiz level. +% \item True/False question type is now supported. +% \item Moodle tags can now be specified for questions (and rendered in PDF +% as well). +% \item In cloze questions, the \texttt{multiresponse} subquestion type is +% now supported. +% \removed +% \item External dependency on \texttt{OpenSSL}. +% \item Irrelevant tags were written in XML for matching questions. +% \fixed +% \item \TikZ\ externalization now works when using \XeLaTeX. +% \item It is now possible to set points manually among several correct +% answers in multichoice questions. +% \item General feedbacks can now contain backslashes. +% \item Several quizzes can now be defined in a single source file, each +% specifying a category for Moodle's question bank. +% \item Correct encoding information in now written in XML depending on +% the \LaTeX\ compiler used. +% \end{version} +% \begin{version}[version=0.6a,date=2019-06-21] +% \added +% \item \XeLaTeX\ is now recommended when using UTF8-encoded sources (support +% of accents). +% \item Feedbacks are now displayed in the PDF file produced. +% \item The \texttt{optipng} utility is used (and required) to reduce the size +% of images embedded in the XML file. +% \item Question options and settings are now displayed in the PDF file +% \item Supporting more \LaTeX\ macros for symbols and accents (mostly +% diacritical marks and ligatures). +% \item Introduce shuffle options in cloze-multi subquestions. +% \item Package option \texttt{final}. +% \changed +% \item In draft mode, \TikZ\ externalization in no longer triggered. +% \fixed +% \item In the different question types, the feedback fields are now converted +% for HTML allowing \LaTeX\ equation and images. +% \item Documentation improvements (limitations and previously undocumented +% features). +% \end{version} +% \shortversion{version=0.5,date=2016-01-05,simple,changes=Initial version,author={Anders O.F. Hendrickson}} +% \end{changelog} +% % \StopEventually{} % % \section{Implementation} % \subsection{Packages, Options, and Utilities} % \begin{macrocode} \newif\ifmoodle@draftmode +\newif\ifmoodle@handout +\newif\ifmoodle@stampmode +\newif\ifmoodle@tikz \newif\ifmoodle@tikzloaded +\newif\ifmoodle@svg +\newif\ifmoodle@section +\newif\ifmoodle@subsection +\newif\ifmoodle@numbered %%DECLARATION OF OPTIONS \DeclareOption{draft}{\moodle@draftmodetrue} +\DeclareOption{handout}{\moodle@handouttrue} +\DeclareOption{final}{\moodle@draftmodefalse} +\DeclareOption{nostamp}{\moodle@stampmodefalse} +\DeclareOption{tikz}{\moodle@tikztrue} +\DeclareOption{svg}{\moodle@svgtrue} +\DeclareOption{section}{\moodle@sectiontrue\moodle@numberedtrue} +\DeclareOption{section*}{\moodle@sectiontrue\moodle@numberedfalse} +\DeclareOption{subsection}{\moodle@sectionfalse\moodle@numberedtrue} +\DeclareOption{subsection*}{\moodle@sectionfalse\moodle@numberedfalse} \moodle@draftmodefalse +\moodle@handoutfalse +\moodle@stampmodetrue +\moodle@tikzfalse \moodle@tikzloadedfalse +\moodle@svgfalse +\moodle@subsectiontrue +\moodle@numberedfalse \ProcessOptions \RequirePackage{environ} %To be able to take environment body as a macro argument \RequirePackage{xkeyval} %For key-handling \RequirePackage{amssymb} %For \checkmark symbol -\RequirePackage{trimspaces} %To remove extra spaces from strings +%\RequirePackage{trimspaces} %To remove extra spaces from strings (loaded by environ) \RequirePackage{etex} %Expansion control, detokenization, etc. \RequirePackage{etoolbox}%List management \RequirePackage{xpatch} %To patch commands easily in HTML mode \RequirePackage{array} %For formatting tables in the LaTeX mode of Clozes \RequirePackage{ifplatform} % To choose Ghostscript commands -\RequirePackage{ifpdf} % Needed to know whether we can convert output from PDF to PNG - +\@ifpackageloaded{iftex}{}{\RequirePackage{iftex}} +% iftex already required by recent versions of ifplatform. Needed to know: +% 1) whether we can convert output from PDF to PNG (ifpdf), +% 2) when output pdf is latin1-encoded (ifpdf) +% 3) when output xml is utf8-encoded (if?tex) +\@ifundefined{ifpdf}{\RequirePackage{ifpdf}}{}% old iftex would not define the conditional +\RequirePackage{shellesc} %Luatex-compatible way of getting system access +\RequirePackage{fancybox} %For fancy LaTeX tags \RequirePackage{getitems} %To gather the header and items +\ifmoodle@handout + \RequirePackage[seed=42]{randomlist} %To randomize answers in matching questions +\fi +\ifmoodle@svg + \RequirePackage{graphicx} %To include graphics +\fi \let\xa=\expandafter \def\@star{*}% \def\@hundred{100}% +\def\@fifty{50}% \def\@moodle@empty{}% \def\@relax{\relax}% +\def\@moodle@par{\par}% + +% Taken from https://tex.stackexchange.com/questions/47576/combining-ifxetex-and-ifluatex-with-the-logical-or-operation +\@ifundefined{ifTUTeX}{ + \newif\ifTUTeX % a new conditional starts as false + \ifnum 0\ifXeTeX 1\fi\ifLuaTeX 1\fi>0% + \TUTeXtrue + \fi +}{}% +\newif\ifpdfoutput % a new conditional starts as false +\ifnum 0\ifTUTeX 1\fi\ifPDFTeX\ifpdf 1\fi\fi>0% + \pdfoutputtrue +\fi % \end{macrocode} % As the package involves a fair bit of file processing, % we automate the naming of auxiliary files. @@ -787,9 +1771,42 @@ \newwrite\moodle@outfile \def\openmoodleout{% \immediate\openout\moodle@outfile=\outputfilename\relax - \writetomoodle{<?xml version="1.0" encoding="UTF-8"?>}% + \ifPDFTeX % latin1-based engines (pdflatex or latex) + \writetomoodle{<?xml version="1.0" encoding="iso-8859-1"?>}% + \else + \ifTUTeX % UTF8-based engines (XeTeX or LuaTeX) + \writetomoodle{<?xml version="1.0" encoding="UTF-8"?>}% + \else % what shall we do? + \writetomoodle{<?xml version="1.0" encoding="UTF-8"?>}% + %\stop + \fi + \fi + \ifmoodle@stampmode + \def\moodle@stamp{This file was generated on \the\year-\two@digits\month-\two@digits\day} + \ifPDFTeX % pdflatex or latex + \ifpdf % pdflatex + \g@addto@macro{\moodle@stamp}{ by pdfLaTeX }% + \else % latex + \g@addto@macro{\moodle@stamp}{ by LaTeX }% + \fi + \else + \ifXeTeX % xetex + \g@addto@macro{\moodle@stamp}{ by XeLaTeX }% + \else + \ifLuaTeX % luatex + \g@addto@macro{\moodle@stamp}{ by LuaLaTeX }% + \else + \g@addto@macro{\moodle@stamp}{ a TeX engine }% + \fi + \fi + \fi + \writetomoodle{<!-- \moodle@stamp -->}% + \def\moodle@stamp{running on \platformname}% + \g@addto@macro{\moodle@stamp}{ with the package moodle v0.8 }% + \writetomoodle{<!-- \moodle@stamp -->}% + \fi + \immediate\write\moodle@outfile{}% \writetomoodle{<quiz>}% - \writetomoodle{ }% }% \def\closemoodleout{% \writetomoodle{ }% @@ -797,6 +1814,7 @@ \immediate\closeout\moodle@outfile }% % \end{macrocode} +% % To both make this |.sty| file and the XML output more readable, % we create a mechanism for writing to the output file with indents. % The macro |\calculateindent|\marg{$n$} globally defines @@ -836,27 +1854,71 @@ % We now create the main |quiz| environment that will contain % the questions we write. It outputs to XML as a |<question type="category">| tag. % \begin{macrocode} -\newenvironment{quiz}[2][]% - {\setkeys{moodle}{#1}% - \@moodle@ifgeneratexml{% - \openmoodleout% - \setcategory{#2}% - }{}% - \subsection*{#2}% - \begin{enumerate}% - } - {\end{enumerate}% - \@moodle@ifgeneratexml{\closemoodleout}{}} - -{\catcode`\$=12\catcode`\ =12% -\gdef\setcategory#1{% +{\catcode`\$=12\catcode`\ =12% in this context we cannot indent with spaces... +\gdef\moodle@write@category@xml#1{% +\@moodle@ifgeneratexml{% +\writetomoodle{ }% \writetomoodle{<question type="category">}% \writetomoodle{ <category>}% -\writetomoodle{ <text>$module$/#1</text>}% +\writetomoodle{ <text>$course$/top/#1</text>}% \writetomoodle{ </category>}% \writetomoodle{</question>}% \writetomoodle{ }% +}{}% }}% +\newcommand*\@enumeratename{enumerate}% +\newenvironment{quiz}[2][]{% + \setkeys{moodle}{#1}% + \gdef\setcategory##1{% + % At first call (end of \begin{quiz}) enumerate is not started yet + \ifx\@currenvir\@enumeratename + % In case no question is defined between two calls of \setcategory + \def\@noitemerr{\@latex@warning{Empty question list}}% + \end{enumerate}% + \fi + \gdef\moodle@currentcategory{##1}% + \moodle@write@category@xml{##1}% + \ifmoodle@section + \ifmoodle@numbered + \section{##1}% + \else + \section*{##1}% + \fi + \else + \ifmoodle@numbered + \subsection{##1}% + \else + \subsection*{##1}% + \fi + \fi + \begin{enumerate}% + }% + \gdef\setsubcategory##1{% + \def\@noitemerr{\@latex@warning{Empty question list}}% + \end{enumerate}% + \moodle@write@category@xml{\moodle@currentcategory/##1}% + \ifmoodle@section + \ifmoodle@numbered + \subsection{##1}% + \else + \subsection*{##1}% + \fi + \else + \ifmoodle@numbered + \subsubsection{##1}% + \else + \subsubsection*{##1}% + \fi + \fi + \begin{enumerate}% + }% + \setcategory{#2}% +}{% + \end{enumerate}% + \let\setcategory\relax + \let\setsubcategory\relax +}% + % \end{macrocode} % The next utility takes a single macro control sequence |#1|, % and allows that macro's current value to persist @@ -888,6 +1950,19 @@ }% } % \end{macrocode} +% Now the macros |openmoodleout| and |closemoodleout| are triggered at Begin and End Document, respectively +% \begin{macrocode} +\AfterEndPreamble{ + \@moodle@ifgeneratexml{% + \openmoodleout% + }{}% +} +\AtEndDocument{ + \@moodle@ifgeneratexml{% + \closemoodleout% + }{}% +} +% \end{macrocode} % % \subsection{Key-Value Pairs for Quiz Questions} % @@ -902,7 +1977,7 @@ % to the output XML file. % % The ordinary version |\generate@moodle@write@code| passes its output text |#3| -% through the HTMLizer, producing HTML code, while the starred version +% through the HTMLizer, producing HTML code, while the starred variant % |\generate@moodle@write@code*| passes |#3| verbatim as text. % % For example, @@ -951,6 +2026,23 @@ }% }% +\def\generate@moodle@write@html@noptag#1<#2>#3{% + % No <P>..</P> introduced + % #1 = NAME for \moodle@writeNAME + % #2 = HTML tag + % #3 = what, exactly, to write + \xa\gdef\csname moodle@write#1\endcsname{% + \xa\def\xa\test@iii\xa{#3}% + \ifx\test@iii\@moodle@empty + \writetomoodle[2]{ <#2 format="html"><text/></#2>}% + \else + \xa\converttohtmlmacro\xa\moodle@htmltowrite\xa{#3}% + \writetomoodle[2]{ <#2 format="html">}% + \writetomoodle[4]{ <text><![CDATA[\moodle@htmltowrite]]></text>}% + \writetomoodle[2]{ </#2>}% + \fi + }% +}% \def\generate@moodle@write@data*#1<#2>#3{% % #1 = NAME for \moodle@writeNAME @@ -961,16 +2053,33 @@ }% }% +\def\generate@moodle@write@tags#1{% + % #1 = NAME for \moodle@writeNAME + % #3 = what, exactly, to write + \xa\gdef\csname moodle@writetags\endcsname{% + %\xa\xa\xdef\xa\xa\ds\xa\xa{Encountered '\string #1'}\show\ds + \xa\xdef\xa\test@iii\xa{\moodle@tags}% + \ifx\test@iii\@moodle@empty\relax\else + \xa\converttohtmlmacro\xa\moodle@htmltowrite\xa{\moodle@tags}% + \writetomoodle[2]{ <tags>}% + \writetomoodle[4]{ <tag><text><![CDATA[\moodle@htmltowrite]]></text></tag>}% + \writetomoodle[2]{ </tags>}% + \fi + }% +}% + % \end{macrocode} % \subsubsection{Keys for all question types} % \begin{macrocode} %% QUESTIONNAME \define@cmdkey{moodle}[moodle@]{questionname}{}% - \gdef\moodle@writequestionname{% - \writetomoodle[2]{<name>}% - \writetomoodle[4]{ <text>\moodle@questionname</text>}% - \writetomoodle[2]{</name>}% - }% +% \gdef\moodle@writequestionname{% +% \writetomoodle[2]{<name>}% +% \writetomoodle[4]{ <text>\moodle@questionname</text>}% +% \writetomoodle[2]{</name>}% +% }% +%\generate@moodle@write@code{questionname}<name>{\moodle@questionname}% +\generate@moodle@write@html@noptag{questionname}<name>{\moodle@questionname}% %% QUESTIONTEXT %I tried to use questiontext as a key, but it doesn't seem to work. @@ -986,9 +2095,9 @@ \generate@moodle@write@code{questiontext}<questiontext>{\moodle@questiontext}%{% %% PENALTY FOR WRONG ATTEMPT - \define@cmdkey{moodle}[moodle@]{penalty}[0.1000000]{}% + \define@cmdkey{moodle}[moodle@]{penalty}[0.10]{}% \generate@moodle@write@code*{penalty}<penalty>{\moodle@penalty}% - \moodleset{penalty}% + \moodleset{penalty=0.10}% %% FEEDBACK % Moodle allows for feedback tailored to each question, @@ -1002,7 +2111,7 @@ \define@cmdkey{moodle}[moodle@]{feedback}[]{}% \generate@moodle@write@code{generalfeedback}<generalfeedback>{\moodle@feedback}% \generate@moodle@write@code{feedback}<feedback>{\moodle@feedback}% - \moodleset{feedback}% + \moodleset{feedback={}}% %% DEFAULT GRADE %The next line creates \moodle@defaultgrade, @@ -1028,7 +2137,14 @@ \moodle@writehidden% }% -% TO DO: 'tags' (i.e., keywords) +%% TAGS + %The next line creates \moodle@tags, + %which defines a "tag" (i.e., keyword) for the question. + %Key calls like [tags={random}] set \moodle@tags. + \define@cmdkey{moodle}[moodle@]{tags}[]{}% + \generate@moodle@write@tags{\csname moodle@tags\endcsname}% + \moodleset{tags}% +% TODO: handle multiple 'tags' for one question % \end{macrocode} % \subsubsection{Keys for all answers} @@ -1039,13 +2155,18 @@ %the XML within the answer tag, like <answer fraction="75">. \moodleset{fraction=100} %This sets the default. % \end{macrocode} +% \begin{macrocode} +%% FRACTIONTOL -- the tolerance for fractions with respect to valid values + \define@cmdkey{moodle}[moodle@]{fractiontol}[0.1]{}% + \moodleset{fractiontol=0.1} %This sets the default. +% \end{macrocode} % \subsubsection{Keys for multiple choice questions} % \begin{macrocode} %% SINGLE and MULTIPLE -- for multichoice, is there 1 right answer or more than 1? \define@boolkey{moodle}[moodle@]{single}[true]{}% \generate@moodle@write@code*{single}<single>{\ifmoodle@single true\else false\fi}% - \moodleset{single}% + \moodleset{single=true}% %The key 'multiple' is an antonym to 'single'. \define@boolkey{moodle}[moodle@]{multiple}[true]{\ifmoodle@multiple\moodle@singlefalse\else\moodle@singletrue\fi}% @@ -1054,15 +2175,15 @@ \generate@moodle@write@code*{shuffle}<shuffleanswers>{\ifmoodle@shuffle 1\else 0\fi}% \moodleset{shuffle=true}% -%% TO DO: CORRECTFEEDBACK -%% TO DO: PARTIALLYCORRECTFEEDBACK -%% TO DO: INCORRECTFEEDBACK -%% TO DO: NUMCORRECT key +%% TODO: CORRECTFEEDBACK +%% TODO: PARTIALLYCORRECTFEEDBACK +%% TODO: INCORRECTFEEDBACK +%% TODO: NUMCORRECT key %% NUMBERING -- for numbering of multichoice questions \define@choicekey{moodle}{numbering}% {alpha,alph,Alpha,Alph,arabic,roman,Roman,% - abc,ABC,123,iii,IIII,none}[abc]{% + abc,ABCD,123,iii,IIII,none}[abc]{% \def\moodle@numbering{#1}% \def\test@@i{#1}% \ifx\test@@i\@moodle@alpha @@ -1070,9 +2191,9 @@ \ifx\test@@i\@moodle@alph \def\moodle@numbering{abc}\fi \ifx\test@@i\@moodle@Alpha - \def\moodle@numbering{ABC}\fi + \def\moodle@numbering{ABCD}\fi \ifx\test@@i\@moodle@Alph - \def\moodle@numbering{ABC}\fi + \def\moodle@numbering{ABCD}\fi \ifx\test@@i\@moodle@arabic \def\moodle@numbering{123}\fi \ifx\test@@i\@moodle@roman @@ -1094,7 +2215,7 @@ \def\@moodle@roman{roman}% \def\@moodle@Roman{Roman}% \def\@moodle@abc{abc}% - \def\@moodle@ABC{ABC}% + \def\@moodle@ABCD{ABCD}% \def\@moodle@arabicnumbers{123}% \def\@moodle@iii{iii}% \def\@moodle@IIII{IIII}% @@ -1103,7 +2224,7 @@ \ifx\moodle@numbering\@moodle@abc \renewcommand\theenumii{\alph{enumii}}% \fi - \ifx\moodle@numbering\@moodle@ABC + \ifx\moodle@numbering\@moodle@ABCD \renewcommand\theenumii{\Alph{enumii}}% \fi \ifx\moodle@numbering\@moodle@arabicnumbers @@ -1119,7 +2240,7 @@ \renewcommand\labelenumii{$\bullet$~}% \fi } - %TO DO: * In the PDF, how should 'none' in a multi look different from + %TODO: * In the PDF, how should 'none' in a multi look different from % short answer or numerical options? % * Instead of \theenumi and \labelenumi, % use \@enumdepth to automatically set the correct depth. @@ -1140,7 +2261,7 @@ %tolerance is given within the answer tag, %like <answer fraction=100 tolerance=0.03>. -% TO DO: implement unit-handling for numerical questions! +% TODO: implement unit-handling for numerical questions! % \end{macrocode} % \subsubsection{Keys for short answer questions} % \begin{macrocode} @@ -1215,7 +2336,7 @@ %% RESPONSE REQUIRED \define@boolkey{moodle}[moodle@]{response required}[true]{}% - % TO DO: Make synonym 'required' + % TODO: Make synonym 'required' \generate@moodle@write@code*{responserequired}<responserequired>{\csname ifmoodle@response required\endcsname 1\else 0\fi}% \moodleset{response required=false}% @@ -1245,7 +2366,7 @@ %% RESPONSE TEMPLATE \define@key{moodle}{template}{\long\def\moodle@responsetemplate{#1}}% - \generate@moodle@write@code{responsetemplate}<responsetemplate>{\moodle@responsetemplate} + \generate@moodle@write@html@noptag{responsetemplate}<responsetemplate>{\moodle@responsetemplate} \moodleset{template={}}% % \end{macrocode} % \subsubsection{Hint tags} @@ -1269,7 +2390,7 @@ }% \moodleset{clearwrong=false}% -% TO DO: Implement hints +% TODO: Implement hints % \end{macrocode} % % \subsection{Answer handling} @@ -1305,21 +2426,6 @@ % \subsubsection{Not yet implemented} % % \begin{macrocode} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TRUE/FALSE QUESTIONS %%%%%%%%%%%%%%%%% - -% TODO: implement the \writetruefalsequestion -% and a front-end. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% DESCRIPTION 'QUESTIONS' %%%%%%%%%%%%% - -% TODO: implement the \writedescription and a suitable front-end. -% Should this be \begin{description}...\end{description}, -% or should \begin{quiz}...\end{quiz} just scoop up all -% text outside question environments and package it in descriptions? - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% CALCULATED %%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1354,48 +2460,142 @@ % \end{Verbatim} % % \begin{macrocode} -\def\moodle@makefrontend#1{% + +\def\moodle@makelatextagbox#1{% +% \ifmoodle@tikzloaded +% \tikzset{external/export next=false} +% \tikz[baseline]{\node[draw,minimum height=1.2em,rounded corners,fill=black!20] {\tiny #1};} +% % Fancy but interferes with the tikzexternalize counter +% \else + \Ovalbox{\tiny #1} + %\ovalbox{\tiny #1} + %\shadowbox{\tiny #1} +% \fi +}% + +\def\moodle@makelatextag@qtype#1{% + \doublebox{\tiny \textsc{#1}} +}% + +\def\moodle@makelatextag@value#1#2{% + \moodle@makelatextagbox{\csname moodle@#1\endcsname~#2} +}% + +\def\moodle@makelatextag@key#1{% + \moodle@makelatextagbox{\csname moodle@#1\endcsname} +}% + +\def\moodle@marks#1{point\ifdim#1pt=1pt \else s\fi} + +\def\moodle@makefrontend#1#2{% \NewEnviron{#1}[2][]{% \bgroup \setkeys{moodle}{##1,questionname={##2}}% \expandafter\gatheritems\xa{\BODY}% \let\moodle@questionheader=\gatheredheader %First, the LaTeX processing - \item \textbf{\moodle@questionname}\par + \item \textbf{\moodle@questionname} + \ifmoodle@handout + \moodle@makelatextag@qtype{#1} + \else + \xa\xdef\xa\test@iii\xa{\moodle@tags}% + \ifx\test@iii\@moodle@empty\relax\else + \hfill tags: \texttt{\moodle@tags} + \fi + \par + \noindent + \moodle@makelatextag@qtype{#1} + \moodle@makelatextag@value{default grade}{\moodle@marks{\csname moodle@default grade\endcsname}} + \moodle@makelatextag@value{penalty}{penalty} + \fi + #2\par \noindent \moodle@questionheader + \edef\moodle@generalfeedback{\expandonce\moodle@feedback} \csname moodle@#1@latexprocessing\endcsname %Now, writing information to XML \@moodle@ifgeneratexml{% \xa\questiontext\xa{\moodle@questionheader}% Save the question text. + \csname write#1question\endcsname \bgroup \gdef\moodle@answers@xml{}% \setkeys{moodle}{feedback={}}% \xa\loopthroughitemswithcommand\xa{\csname save#1answer\endcsname}% \passvalueaftergroup{\moodle@answers@xml}% \egroup - \csname write#1question\endcsname + \moodle@writeanswers% + \moodle@writetags% + \writetomoodle{</question>}% }{}% \egroup }% } % \end{macrocode} % -% \subsubsection{Essay Question Front-End} -% The essay question is the only question type whose front end +% \subsubsection{Description Question Front-End} +% Description and essay questions are the only question types whose front end % is not yet created by |\moodle@makefrontend|. -% This is because of what it must do with its |\item|'s. +% This is because of what need to be done with their contents. +% +% Description blocks can be empty. In this case, nothing is done. +% +% \begin{macrocode} +\let\description\relax% remove the meaning of existing \description and \enddescription +\let\enddescription\relax +\NewEnviron{description}[2][]{% + \bgroup + \setkeys{moodle}{#1,questionname={#2}}% + \let\moodle@questiontext=\BODY + \trim@spaces@in\moodle@questiontext + \ifx\moodle@questiontext\@empty\relax\else% + %First, the LaTeX processing. + \item \textbf{\moodle@questionname} + \ifmoodle@handout\else + \xa\xdef\xa\test@iii\xa{\moodle@tags}% + \ifx\test@iii\@moodle@empty\relax\else + \hfill tags: \texttt{\moodle@tags}% + \fi + \par + \noindent + \fi + \moodle@makelatextag@qtype{description}\par + \noindent + \moodle@questiontext\par + \ifmoodle@handout\else + \ifx\moodle@feedback\@empty\relax\else + \fbox{\parbox{\linewidth}{\emph{\moodle@feedback}}}% + \fi + \fi + %Now, writing information to memory. + \@moodle@ifgeneratexml{% + \writetomoodle{<question type="description">}% + \moodle@writecommondata + \moodle@writetags% + \writetomoodle{</question>}% + }{}% + \fi + \egroup +}% +% \end{macrocode} +% +% \subsubsection{Essay Question Front-End} +% The front end is not yet created by |\moodle@makefrontend| because of +% what must must be done with the |\item|'s. % % \begin{macrocode} \def\moodle@essay@latexprocessing{% % Moodle cannot automatically grade an essay, % but if the user puts \item's in, we can list them in an itemize as notes. + \par\noindent \emph{Notes for grader:} + \moodle@questionheader \ifnum\c@numgathereditems>0\relax - \par\noindent Notes: (not included in XML) \begin{itemize} \setlength\itemsep{0pt}\setlength\parskip{0pt}% \loopthroughitemswithcommand{\moodle@print@essay@answer}% \end{itemize}% \fi + \ifx\moodle@generalfeedback\@empty\relax\else% + \fbox{\parbox{\linewidth}{\emph{\moodle@generalfeedback}}}% + \fi } \NewEnviron{essay}[2][]{% @@ -1404,13 +2604,35 @@ \expandafter\gatheritems\expandafter{\BODY}% \let\moodle@questionheader=\gatheredheader %First, the LaTeX processing. - \item \textbf{\moodle@questionname}\par + \item \textbf{\moodle@questionname} + \ifmoodle@handout + \moodle@makelatextag@qtype{essay} + \else + \xa\xdef\xa\test@iii\xa{\moodle@tags}% + \ifx\test@iii\@moodle@empty\relax\else + \hfill tags: \texttt{\moodle@tags} + \fi + \par + \noindent + \moodle@makelatextag@qtype{essay} + \moodle@makelatextag@value{default grade}{\moodle@marks{\csname moodle@default grade\endcsname}} + \moodle@makelatextag@value{penalty}{penalty} + \moodle@makelatextag@key{responseformat} + \fi + \par \noindent - \moodle@questionheader - \csname moodle@essay@latexprocessing\endcsname + \ifx\moodle@responsetemplate\@empty\relax\else% + \par\noindent \emph{Template:} + \par\fbox{\parbox{\linewidth}{\moodle@responsetemplate}}\par + \fi + \edef\moodle@generalfeedback{\expandonce\moodle@feedback} + \ifmoodle@handout\else + \csname moodle@essay@latexprocessing\endcsname + \fi %Now, writing information to memory. \@moodle@ifgeneratexml{% \xa\questiontext\xa{\moodle@questionheader}% Save the question text. + \writeessayquestion \bgroup \gdef\moodle@answers@xml{}% % @@ -1430,12 +2652,15 @@ % \passvalueaftergroup{\moodle@answers@xml}% \egroup - \writeessayquestion + \moodle@writeanswers% The 'answers' XML really contains the grader info. + \moodle@writeresponsetemplate% + \moodle@writetags% + \writetomoodle{</question>}% }{}% \egroup }% -%%%% TO DO +%%%% TODO %%%% To make essay work will be tough. %%%% Every line from \ifnum\c@numgathereditems=0\relax through its \else and \fi, %%%% with the exception of @@ -1477,9 +2702,6 @@ \moodle@writeresponsefieldlines% \moodle@writeattachmentsallowed% \moodle@writeattachmentsrequired% - \moodle@writeanswers% The 'answers' XML really contains the grader info. - \moodle@writeresponsetemplate% - \writetomoodle{</question>}% }% \def\moodle@print@essay@answer#1{% @@ -1488,6 +2710,7 @@ \def\moodle@savegraderinfo#1{% + %\def\ds{#1}\show\ds \bgroup \moodle@savegraderinfo@int#1\moodle@answer@rdelim \passvalueaftergroup{\moodle@answers@xml}% @@ -1498,7 +2721,8 @@ \moodle@savegraderinfo@int@int% }% \def\moodle@savegraderinfo@int@int#1\moodle@answer@rdelim{% - \xa\converttohtmlmacro\xa\moodle@answertext@html\xa{#1}% + \def\moodle@answertext{#1} + \xa\converttohtmlmacro\xa\moodle@answertext@html\xa{\moodle@answertext}% %\trim@spaces@in\moodle@answertext \ifnum\c@numgathereditems>1\relax \addto@xml[6]{\moodle@answers@xml}{<li>\moodle@answertext@html</li>}% @@ -1512,17 +2736,21 @@ % % \begin{macrocode} \def\blank{\rule{1in}{0.5pt}}% -% TO DO: Make an optional argument for width? This wouldn't affect Moodle, +% TODO: Make an optional argument for width? This wouldn't affect Moodle, % only the appearance in the PDF. It doesn't seem worth it. -% \NewEnviron{shortanswer}[2][]{% +%\NewEnviron{shortanswer}[2][]{% % \bgroup % \setkeys{moodle}{#1,questionname={#2}}% % \expandafter\gatheritems\xa{\BODY}% % \let\moodle@questionheader=\gatheredheader % %First, the LaTeX processing. -% \bigskip\par\noindent -% \fbox{\textbf{\moodle@questionname}}\par +% \item \textbf{\moodle@questionname} +% \csname ifmoodle@case sensitive\endcsname +% \framebox{\tiny Case-Sensitive}\relax +% \fi +% \framebox{\tiny\csname moodle@default grade\endcsname~points} +% \framebox{\tiny\csname moodle@penalty\endcsname~penalty}\par % \noindent % \moodle@questionheader % \csname moodle@shortanswer@latexprocessing\endcsname @@ -1532,7 +2760,8 @@ % \bgroup % \gdef\moodle@answers@xml{}% % \setkeys{moodle}{feedback={}}% -% \xa\loopthroughitemswithcommand\xa{\csname saveshortansweranswer\endcsname}% +% \xa\loopthroughitemswithcommand\xa{\csname +% saveshortansweranswer\endcsname}% % \passvalueaftergroup{\moodle@answers@xml}% % \egroup % \csname writeshortanswerquestion\endcsname @@ -1540,16 +2769,33 @@ % \egroup % }% -\moodle@makefrontend{shortanswer}% +\moodle@makefrontend{shortanswer}{\moodle@makelatextag@shortanswer}% % LATEX PROCESSING -\def\moodle@shortanswer@latexprocessing{% - \begin{itemize} \setlength\itemsep{0pt}\setlength\parskip{0pt}% - \loopthroughitemswithcommand{\moodle@print@shortanswer@answer}% - \end{itemize}% + +\def\moodle@makelatextag@shortanswer{% + \csname ifmoodle@case sensitive\endcsname + \moodle@makelatextagbox{Case-Sensitive}\relax + \else + \moodle@makelatextagbox{Case-Insensitive}\relax + \fi } +\ifmoodle@handout + \let\moodle@shortanswer@latexprocessing\relax +\else + \def\moodle@shortanswer@latexprocessing{% + \begin{itemize} \setlength\itemsep{0pt}\setlength\parskip{0pt}% + \loopthroughitemswithcommand{\moodle@print@shortanswer@answer}% + \end{itemize}% + \ifx\moodle@generalfeedback\@empty\relax\else% + \fbox{\parbox{\linewidth}{\emph{\moodle@generalfeedback}}}% + \fi + } +\fi + \def\moodle@print@shortanswer@answer#1{% + \let\moodle@feedback=\@empty \moodle@print@shortanswer@answer@int#1\@rdelim }% \newcommand\moodle@print@shortanswer@answer@int[1][]{% @@ -1558,9 +2804,13 @@ }% \def\moodle@print@shortanswer@answer@int@int#1\@rdelim{% \ifx\moodle@fraction\@hundred - \item #1\quad$\checkmark$% + \item #1$~\checkmark$% \else - \item #1\quad (\moodle@fraction\%)% + \moodle@checkfraction + \item #1$~(\moodle@fraction\%)$% + \fi + \ifx\moodle@feedback\@empty\relax\else + \hfill \emph{$\rightarrow$ \moodle@feedback} \fi }% @@ -1577,10 +2827,14 @@ }% \def\saveshortansweranswer@int@int#1\moodle@answer@rdelim{% \def\moodle@answertext{#1}% + \trim@spaces@in\moodle@answertext + \moodle@checkfraction \addto@xml[2]{\moodle@answers@xml}{<answer fraction="\moodle@fraction" format="plain_text">}% \addto@xml[4]{\moodle@answers@xml}{ <text>\moodle@answertext</text>}% \ifx\moodle@feedback\@empty\relax\else - \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback</p>]]></text></feedback>}% + \trim@spaces@in\moodle@feedback + \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{\moodle@feedback}% + \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text></feedback>}% \fi \addto@xml[2]{\moodle@answers@xml}{</answer>}% }% @@ -1590,40 +2844,63 @@ \writetomoodle{<question type="shortanswer">}% \moodle@writecommondata% \moodle@writeusecase% - \moodle@writeanswers% - \writetomoodle{</question>}% }% % \end{macrocode} % % \subsubsection{Numerical Question Front-End} % % \begin{macrocode} -\moodle@makefrontend{numerical}% +\moodle@makefrontend{numerical}{\moodle@makelatextag@numerical}% % LATEX PROCESSING -\def\moodle@numerical@latexprocessing{% - \begin{itemize} \setlength\itemsep{0pt}\setlength\parskip{0pt}% - \loopthroughitemswithcommand{\moodle@print@numerical@answer}% - \end{itemize}% + +\def\moodle@makelatextag@numerical{} + +\AtEndPreamble{ + \@ifpackageloaded{siunitx}{\def\moodle@printnum{\num[omit-uncertainty,copy-decimal-marker]}}{\let\moodle@printnum\trim@spaces}% } +\ifmoodle@handout + \let\moodle@numerical@latexprocessing\relax +\else + \def\moodle@numerical@latexprocessing{% + \begin{itemize} \setlength\itemsep{0pt}\setlength\parskip{0pt}% + \loopthroughitemswithcommand{\moodle@print@numerical@answer}% + \end{itemize}% + \ifx\moodle@generalfeedback\@empty\relax\else% + \fbox{\parbox{\linewidth}{\emph{\moodle@generalfeedback}}}% + \fi + } +\fi + \def\moodle@print@numerical@answer#1{% - \moodle@print@numerical@answer@int#1\@rdelim + \let\moodle@feedback=\@empty + \bgroup + \moodle@print@numerical@answer@int#1\@rdelim + \egroup }% \newcommand\moodle@print@numerical@answer@int[1][]{% \setkeys{moodle}{#1}% \moodle@print@numerical@answer@int@int% }% \def\moodle@print@numerical@answer@int@int#1\@rdelim{% - \ifdim0pt=\moodle@tolerance pt\relax - \def\moodle@numericalprint@tolerance{}% + \xdef\test@i{\trim@spaces{#1}}% + \ifx\test@i\@star + \item \test@i \else - \edef\moodle@numericalprint@tolerance{\noexpand\pm\moodle@tolerance}% + \item \moodle@printnum{#1}% + \ifnum\z@=\moodle@tolerance\else + $\,\pm\,$\moodle@printnum{\moodle@tolerance}% + \fi \fi \ifx\moodle@fraction\@hundred - \item $#1\moodle@numericalprint@tolerance\quad\checkmark$% + $~\checkmark$% \else - \item $#1\moodle@numericalprint@tolerance$\quad (\moodle@fraction\%)% + \moodle@checkfraction + $~(\moodle@fraction\%)$% + \fi + \ifx\moodle@feedback\@empty\relax\else + \hfill \emph{$\rightarrow$ \moodle@feedback}% \fi }% @@ -1640,11 +2917,17 @@ }% \def\savenumericalanswer@int@int#1\moodle@answer@rdelim{% \def\moodle@answertext{#1}% + \trim@spaces@in\moodle@answertext + \moodle@checkfraction \addto@xml[2]{\moodle@answers@xml}{<answer fraction="\moodle@fraction" format="plain_text">}% \addto@xml[4]{\moodle@answers@xml}{ <text>\moodle@answertext</text>}% - \addto@xml[4]{\moodle@answers@xml}{ <tolerance>\moodle@tolerance</tolerance>}% + \ifx\moodle@answertext\@star\else + \addto@xml[4]{\moodle@answers@xml}{ <tolerance>\moodle@tolerance</tolerance>}% + \fi \ifx\moodle@feedback\@empty\relax\else - \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback</p>]]></text></feedback>}% + \trim@spaces@in\moodle@feedback + \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{\moodle@feedback}% + \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text></feedback>}% \fi \addto@xml[2]{\moodle@answers@xml}{</answer>}% }% @@ -1654,8 +2937,6 @@ \gdef\writenumericalquestion{% \writetomoodle{<question type="numerical">}% \moodle@writecommondata% - \moodle@writeanswers% - \writetomoodle{</question>}% }% % \end{macrocode} % @@ -1670,57 +2951,155 @@ % \item 11 % \end{multi}% -\moodle@makefrontend{multi} +\moodle@makefrontend{multi}{\moodle@makelatextag@multi}% % LATEX PROCESSING + +\def\moodle@makelatextag@multi{% + \ifmoodle@multiple + \moodle@makelatextagbox{Multiple}\relax% + \else + \moodle@makelatextagbox{Single}\relax% + \fi + \ifmoodle@handout\else + \ifmoodle@shuffle + \moodle@makelatextagbox{Shuffle}\relax% + \fi + \fi +} + \def\moodle@multi@latexprocessing{% - \moodle@countcorrectanswers - \begin{enumerate}\moodle@obeynumberingstyle - %\renewcommand{\theenumi}{\alph{enumi}}% - \setlength\itemsep{0pt}\setlength\parskip{0pt}% - \loopthroughitemswithcommand{\moodle@print@multichoice@answer}% - \end{enumerate}% + \moodle@countcorrectanswers% + \ifmoodle@handout\NewList{answerlist}\fi + \begin{enumerate}\moodle@obeynumberingstyle% + %\renewcommand{\theenumi}{\alph{enumi}}% + \setlength\itemsep{0pt}\setlength\parskip{0pt}% + \loopthroughitemswithcommand{\moodle@print@multichoice@answer}% + \ifmoodle@handout + \ifmoodle@shuffle + \let\moodle@multi@loop=\ForEachRandomItem + \else + \let\moodle@multi@loop=\ForEachFirstItem + \fi + \moodle@multi@loop{answerlist}{Answer}{\Answer}% + \fi + \end{enumerate}% + \ifmoodle@handout\else + \ifx\moodle@generalfeedback\@empty\relax\else% + \fbox{\parbox{\linewidth}{\emph{\moodle@generalfeedback}}}% + \fi + \fi } \def\moodle@print@multichoice@answer#1{% - \moodle@print@multichoice@answer@int#1\@rdelim + \let\moodle@feedback=\@empty% + \moodle@print@multichoice@answer@int#1 \@rdelim% }% \newcommand\moodle@print@multichoice@answer@int[1][]{% - \setkeys{moodle}{fraction=0,#1}% - \moodle@print@multichoice@answer@int@int + \let\moodle@fraction\@empty% + \setkeys{moodle}{#1}% + \moodle@print@multichoice@answer@int@int% }% \def\moodle@print@multichoice@answer@int@int#1#2\@rdelim{% \def\test@i{#1}% - \ifmoodle@single - \ifx\test@i\@star - \item #2$~\checkmark$% + \def\test@ii{#2}% + \def\moodle@answertext{\item }% + \ifx\test@i\@star% + \g@addto@macro\moodle@answertext{#2}% + \ifmoodle@single% + \setkeys{moodle}{fraction=100}% \else - \item #1#2% + \setkeys{moodle}{fraction=\moodle@autopoints}% \fi \else - \ifx\test@i\@star - \item #2% - \setkeys{moodle}{fraction=\moodle@autopoints}% - \else - \item #1#2% + \g@addto@macro\moodle@answertext{#1#2}% + \fi + \trim@spaces@in\moodle@answertext% + \trim@spaces@in\moodle@answertext% + \ifmoodle@handout\else + \ifmoodle@single% + \ifx\moodle@fraction\@empty\relax% + \setkeys{moodle}{fraction=0}% + \fi + \ifx\moodle@fraction\@hundred% + \trim@spaces@in\moodle@answertext% + \g@addto@macro\moodle@answertext{$~\checkmark$}% + \else + \moodle@checkfraction + \ifdim0pt=\moodle@fraction pt\relax\else% + \g@addto@macro\moodle@answertext{$~(\moodle@fraction\%)$}% + \fi + \fi + \else% multiple + \ifx\moodle@fraction\@empty\relax% + \setkeys{moodle}{fraction=\moodle@autosanctions}% + \fi + \moodle@checkfraction + \g@addto@macro\moodle@answertext{$~(\moodle@fraction\%)$}% \fi - $~(\moodle@fraction\%)$ + \fi + \ifmoodle@handout + \def\temp{\InsertLastItem{answerlist}}% + \xa\temp\xa{\moodle@answertext}% + \else + \ifx\moodle@feedback\@empty\relax\else% + \g@addto@macro\moodle@answertext{\hfill \emph{$\rightarrow$ \moodle@feedback}}% + \fi + \moodle@answertext \fi }% -% COMMON UTILITY: COUNTING CORRECT ANSWERS - \newcounter{moodle@numcorrectanswers}% +% COMMON UTILITY: COUNTING CORRECT ANSWERS (AND A BIT MORE...) + \newcounter{moodle@numcorrectanswers}% count the stars + \newcounter{moodle@numincorrectanswers}% count the items without fraction key indicated \newlength{\moodle@pointspercorrect}% + \newlength{\moodle@pointsperincorrect}% + \newlength{\moodle@sumofpositivefractions}% sums user-set positive fractions + \newlength{\moodle@sumofnegativefractions}% sums user-set negative fractions \def\moodle@countcorrectanswers{% \setcounter{moodle@numcorrectanswers}{0}% + \setcounter{moodle@numincorrectanswers}{0}% \global\setlength{\moodle@pointspercorrect}{100pt}% + \global\setlength{\moodle@pointsperincorrect}{-100pt}% + \global\setlength{\moodle@sumofpositivefractions}{0pt}% + \global\setlength{\moodle@sumofnegativefractions}{0pt}% \loopthroughitemswithcommand{\moodle@countcorrectanswers@a}% - \ifnum0=\c@moodle@numcorrectanswers\relax - \PackageError{moodle}{No correct answers given for multiple choice question.}{Please mark at least one answer correct.}% - \gdef\moodle@autopoints{0}% + \global\advance\moodle@pointspercorrect by-\moodle@sumofpositivefractions\relax% + \def\ds{\strip@pt\moodle@sumofpositivefractions}% + \ifnum0=\c@moodle@numcorrectanswers\relax% + % autopoints will never be used but we check if the sum of positive fractions is 100% + \ifdim\moodle@pointspercorrect<-\moodle@fractiontol pt\relax% + \PackageWarning{moodle}{Positive fractions sum up to more than 100 (here: \ds)}% + \else + \ifdim\moodle@pointspercorrect>\moodle@fractiontol pt\relax% + \PackageError{moodle}{Positive fractions sum up to less than 100 (here: \ds)}% + \fi + \fi \else - \global\divide\moodle@pointspercorrect by \c@moodle@numcorrectanswers\relax - \edef\moodle@autopoints{\strip@pt\moodle@pointspercorrect}% + \ifdim0pt<\moodle@pointspercorrect\relax\else% + % we have starred items so the sum of user-set positive fractions must be less than 100% + % otherwise, starred items would lead to penalties + \PackageError{moodle}{Positive fractions sum up to 100 or more (here: \ds): + there is no positive points left to be given to starred items.}% + \fi + \global\divide\moodle@pointspercorrect by \c@moodle@numcorrectanswers\relax% \fi + \gdef\moodle@autopoints{\strip@pt\moodle@pointspercorrect}% + \global\advance\moodle@pointsperincorrect by-\moodle@sumofnegativefractions\relax% + \def\ds{\strip@pt\moodle@sumofnegativefractions}% + \ifnum0=\c@moodle@numincorrectanswers\relax% + % autosanctions will never be used and + % we do not care about the sum of negative fractions (might be less than -100) + \else + \ifdim0pt<\moodle@pointsperincorrect\relax% + % we have items without fractions set: to prevent auto sanctions from becoming bonuses, + % such items are neutralized. + \PackageWarning{moodle}{Negative fractions sum up to -100 or less (here: \ds): + items with no fraction key set will be considered as neutral.}% + \global\setlength{\moodle@pointsperincorrect}{0pt}% + \fi + \global\divide\moodle@pointsperincorrect by \c@moodle@numincorrectanswers\relax% + \fi + \gdef\moodle@autosanctions{\strip@pt\moodle@pointsperincorrect}% } \def\moodle@countcorrectanswers@a#1{% %The grouping is to keep key answer-specific key changes local. @@ -1729,34 +3108,79 @@ \egroup }% \newcommand\moodle@countcorrectanswers@b[1][]{% - \setkeys{moodle}{fraction=0,#1}% - \moodle@countcorrectanswers@c% + %\ifx&% + \let\moodle@fraction\@empty% + \setkeys{moodle}{#1}% + \moodle@countcorrectanswers@c% + %\fi }% \def\moodle@countcorrectanswers@c#1#2\moodle@answer@rdelim{% \def\test@i{#1}% \ifx\test@i\@star \stepcounter{moodle@numcorrectanswers}% \else - \global\addtolength{\moodle@pointspercorrect}{-\moodle@fraction pt}% + \ifx\moodle@fraction\@empty\relax% + \stepcounter{moodle@numincorrectanswers}% + \else + \ifdim0pt<\moodle@fraction pt\relax% + \global\addtolength{\moodle@sumofpositivefractions}{\moodle@fraction pt}% + \else + \global\addtolength{\moodle@sumofnegativefractions}{\moodle@fraction pt}% + \fi + \fi \fi }% - \def\moodle@setautopoints#1pt{% - \gdef\moodle@autopoints{#1}% + \newlength{\test@fraction}% + \newlength{\test@lower}% + \newlength{\test@upper}% + \def\moodle@fractionerror{% + \def\ds{\moodle@fraction}% + \PackageError{moodle}{the current fraction is not a valid value (here: \ds)}% + } + {\catcode`|=3\relax + \gdef\moodle@validfractionlist{0|5|10|11.11111|12.5|14.28571|16.66667|20|25|30|33.33333|40|50|60|66.66667|70|75|80|83.33333|90|100}}% + \def\moodle@isfractionnear#1{% + \setlength{\test@lower}{#1 pt}% + \addtolength{\test@lower}{-\moodle@fractiontol pt}% + \setlength{\test@upper}{#1 pt}% + \addtolength{\test@upper}{\moodle@fractiontol pt}% + \ifdim\test@upper>\test@fraction\relax + \ifdim\test@lower<\test@fraction\relax + \gdef\test@fractionmatched{#1}% + \fi + \fi + } + \def\moodle@checkfraction{% + %\def\test@i{#1}% + \setlength{\test@fraction}{\moodle@fraction pt}% + % take the absolute value + \ifdim0pt>\test@fraction\relax% + \setlength{\test@fraction}{-\moodle@fraction pt}% + \fi + % test if the fraction is an admissible value + \let\test@fractionmatched\@empty + \forlistloop{\moodle@isfractionnear}{\moodle@validfractionlist}% + \ifx\test@fractionmatched\@empty\relax + \moodle@fractionerror% + \fi + \ifdim\moodle@fraction pt<-\moodle@fractiontol pt\relax% + \setkeys{moodle}{fraction=-\test@fractionmatched}% + \else + \setkeys{moodle}{fraction=\test@fractionmatched}% + \fi } - -% TODO: What if rounding errors make the percentages not add to 100%? Will Moodle complain? -% TODO: Verify that negative scores are handled correctly. % TODO: Put these macros in same order as other sections'. % SAVING ANSWERS TO MEMORY \def\savemultianswer#1{% \bgroup - \savemultianswer@int#1\moodle@answer@rdelim + \savemultianswer@int#1 \moodle@answer@rdelim \passvalueaftergroup{\moodle@answers@xml}% \egroup }% \newcommand\savemultianswer@int[1][]{% - \setkeys{moodle}{fraction=0,#1}% + \let\moodle@fraction\@empty% + \setkeys{moodle}{#1}% \savemultianswer@int@int% }% \def\savemultianswer@int@int#1#2\moodle@answer@rdelim{% @@ -1771,12 +3195,23 @@ \else \def\moodle@answertext{#1#2}% \fi + \ifx\moodle@fraction\@empty\relax% + \ifmoodle@single\relax + \setkeys{moodle}{fraction=0}% + \else% multiple + \setkeys{moodle}{fraction=\moodle@autosanctions}% + \fi + \fi + \trim@spaces@in\moodle@answertext \trim@spaces@in\moodle@answertext + \moodle@checkfraction \addto@xml[2]{\moodle@answers@xml}{<answer fraction="\moodle@fraction" format="html">}% \xa\converttohtmlmacro\xa\moodle@answertext@html\xa{\moodle@answertext}% \addto@xml[4]{\moodle@answers@xml}{ <text><![CDATA[<p>\moodle@answertext@html</p>]]></text>}% \ifx\moodle@feedback\@empty\relax\else - \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback</p>]]></text></feedback>}% + \trim@spaces@in\moodle@feedback + \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{\moodle@feedback}% + \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text></feedback>}% \fi \addto@xml[2]{\moodle@answers@xml}{</answer>}% }% @@ -1788,50 +3223,351 @@ \moodle@writesingle% \moodle@writeshuffle% \moodle@writeanswernumbering% - \moodle@writeanswers% - \writetomoodle{</question>}% }% % \end{macrocode} % -% \subsubsection{Matching Question Front-End} +% \subsubsection{True/False Question Front-End} % % \begin{macrocode} -\let\answer=\hfill +% True/False has structure +% \begin{truefalse}[options]{name}% +% This is a matching question. +% \item[feedback={feedback for student answering incorrectly "true"}] % first item is for true +% \item* this is an other way of specifying answer-specific feedback +% \end{truefalse}% + +%\moodle@makefrontend{truefalse}{}% We dont use the generic frontend because truefalse has no tunable penalty -\moodle@makefrontend{matching} +\NewEnviron{truefalse}[2][]{% + \bgroup + \setkeys{moodle}{#1,questionname={#2}}% + \expandafter\gatheritems\xa{\BODY}% + \let\moodle@questionheader=\gatheredheader + %First, the LaTeX processing + \item \textbf{\moodle@questionname} + \ifmoodle@handout + \moodle@makelatextag@qtype{truefalse} + \else + \xa\xdef\xa\test@iii\xa{\moodle@tags}% + \ifx\test@iii\@moodle@empty\relax\else + \hfill tags: \texttt{\moodle@tags} + \fi + \par + \noindent + \moodle@makelatextag@qtype{truefalse} + \moodle@makelatextag@value{default grade}{\moodle@marks{\csname moodle@default grade\endcsname}} + \fi + \par + \noindent + \moodle@questionheader + \edef\moodle@generalfeedback{\expandonce\moodle@feedback} + \moodle@truefalse@latexprocessing + %Now, writing information to XML + \@moodle@ifgeneratexml{% + \setkeys{moodle}{penalty=1}% + \xa\questiontext\xa{\moodle@questionheader}% Save the question text. + \csname writetruefalsequestion\endcsname + \bgroup + \gdef\moodle@answers@xml{}% + \setkeys{moodle}{feedback={}}% + \xa\loopthroughitemswithcommand\xa{\xa\savetruefalseanswer}% + \ifnum\c@numgathereditems=1\relax% + \setcounter{currentitemnumber}{2}% + \savetruefalseanswer{} + \fi + \passvalueaftergroup{\moodle@answers@xml}% + \egroup + \moodle@writeanswers% + \moodle@writetags% + \writetomoodle{</question>}% + }{}% + \egroup + }% % LATEX PROCESSING -\def\moodle@matching@latexprocessing{% + +\def\moodle@truefalse@latexprocessing{% +% \ifnum\c@numgathereditems>2\relax% +% \PackageError{moodle}{Expecting at max two answers with truefalse type} +% \fi + \setcounter{moodle@numcorrectanswers}{0}% + \begin{itemize} \setlength\itemsep{0pt}\setlength\parskip{0pt}% + \loopthroughitemswithcommand{\moodle@print@truefalse@answer}% + \ifnum\c@currentitemnumber=2% + \item \textbf{False}% + \fi + \end{itemize} + \ifmoodle@handout\else + \ifx\moodle@generalfeedback\@empty\relax\else% + \fbox{\parbox{\linewidth}{\emph{\moodle@generalfeedback}}}% + \fi + \fi + \ifnum\c@moodle@numcorrectanswers=0\relax% + \PackageError{moodle}{No answer is explicitly marked as correct (*). Be sure one answer leads to points.}% + \fi + \ifnum\c@moodle@numcorrectanswers>1\relax% + \PackageError{moodle}{Two answers are explicitly marked as correct (*). Be sure only one answer leads to points.}% + \fi +} + + \def\moodle@print@truefalse@answer#1{% here # is all what comes after "\item", that is "[options]* text" + \let\moodle@feedback=\@empty + \moodle@print@truefalse@answer@int#1\@rdelim % add an end delimiter: + }% + \newcommand\moodle@print@truefalse@answer@int[1][]{% with the optional argument, catch options and set them as keys + \setkeys{moodle}{#1}% + \moodle@print@truefalse@answer@int@int% applies to the rest: "* text\@rdelim" + }% + \def\moodle@print@truefalse@answer@int@int#1\@rdelim{% this is just to treat appart the case where nothing follows + \def\test@i{#1} + \trim@spaces@in\test@i + \ifx\test@i\@empty\relax + \moodle@print@truefalse@answer@int@int@empty + \else + \moodle@print@truefalse@answer@int@int@int#1\@rdelim + \fi + }% + \def\moodle@print@truefalse@answer@int@int@empty{% + \ifnum\c@currentitemnumber=1% + \def\moodle@answertext{True}% + \fi + \ifnum\c@currentitemnumber=2% + \def\moodle@answertext{False}% + \fi + \item \textbf{\moodle@answertext}% + \ifmoodle@handout\else + \ifx\moodle@feedback\@empty\relax\else + ~\hfill \emph{$\rightarrow$ \moodle@feedback}% + \fi + \fi + }% + \def\moodle@print@truefalse@answer@int@int@int#1#2\@rdelim{% + \ifnum\c@currentitemnumber=1% + \def\moodle@answertext{True}% + \fi + \ifnum\c@currentitemnumber=2% + \def\moodle@answertext{False}% + \fi + \item \textbf{\moodle@answertext}% + \ifnum\c@currentitemnumber<3% + \def\test@i{#1}% + %\trim@spaces@in\test@i + \ifx\test@i\@star + \ifmoodle@handout\else + ~$\checkmark$% + \fi + \stepcounter{moodle@numcorrectanswers}% + \else + ~% + \fi + \ifmoodle@handout\else + \ifx\moodle@feedback\@empty\relax + \def\test@ii{#2}% + \trim@spaces@in\test@ii + \ifx\test@ii\@empty\relax\else + \ifx\test@i\@star% + \hfill \emph{$\rightarrow$ #2}% + \else% + \hfill \emph{$\rightarrow$ #1#2}% + \fi + \fi + \else + \hfill \emph{$\rightarrow$ \moodle@feedback}% + \fi + \fi + \fi + }% + +% SAVING ANSWERS TO MEMORY +\def\savetruefalseanswer#1{% \bgroup - \let\answer=\hfill - \begin{enumerate}\renewcommand{\theenumi}{\alph{enumi}}\setlength\itemsep{0pt}\setlength\parskip{0pt}% - \loopthroughitemswithcommand{\moodle@print@matching@answer}% - \end{enumerate}% + \savetruefalseanswer@int#1\moodle@answer@rdelim + \passvalueaftergroup{\moodle@answers@xml}% \egroup -} - \long\def\moodle@print@matching@answer#1{% - \moodle@print@matching@answer@int#1\@rdelim +}% + \newcommand\savetruefalseanswer@int[1][]{% + \setkeys{moodle}{#1}% + \savetruefalseanswer@int@int% }% - \newcommand\moodle@print@matching@answer@int[1][]{% - \moodle@print@matching@answer@int@int\relax + \def\savetruefalseanswer@int@int#1\moodle@answer@rdelim{% + \def\test@i{#1} + \trim@spaces@in\test@i + \ifx\test@i\@empty\relax + \savetruefalseanswer@int@int@empty + \else + \savetruefalseanswer@int@int@int#1\moodle@answer@rdelim + \fi + }% + \def\savetruefalseanswer@int@int@empty{% + \setkeys{moodle}{fraction=0}% + \ifnum\c@currentitemnumber=1% + \def\moodle@answertext{true}% + \fi + \ifnum\c@currentitemnumber=2% + \def\moodle@answertext{false}% + \fi + \ifnum\c@currentitemnumber<3% + \addto@xml[2]{\moodle@answers@xml}{<answer fraction="\moodle@fraction" format="plain_text">}% + \addto@xml[4]{\moodle@answers@xml}{ <text>\moodle@answertext</text>}% + \ifx\moodle@feedback\@empty\relax\else + \trim@spaces@in\moodle@feedback + \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{\moodle@feedback}% + \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text></feedback>}% + \fi + \addto@xml[2]{\moodle@answers@xml}{</answer>}% + \fi }% - \long\def\moodle@print@matching@answer@int@int#1\answer#2\@rdelim{% - \item #1\hfill #2% + \def\savetruefalseanswer@int@int@int#1#2\moodle@answer@rdelim{% + \def\test@i{#1}% + \ifx\test@i\@star + \setkeys{moodle}{fraction=100}% + \else + \setkeys{moodle}{fraction=0}% + \fi + \ifnum\c@currentitemnumber=1% + \def\moodle@answertext{true}% + \fi + \ifnum\c@currentitemnumber=2% + \def\moodle@answertext{false}% + \fi + \ifnum\c@currentitemnumber<3% + \addto@xml[2]{\moodle@answers@xml}{<answer fraction="\moodle@fraction" format="plain_text">}% + \addto@xml[4]{\moodle@answers@xml}{ <text>\moodle@answertext</text>}% + \ifx\moodle@feedback\@empty\relax + \def\test@ii{#2} + \ifx\test@ii\@empty\relax\else + \ifx\test@i\@star + \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{#2}% + \else% + \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{#1#2}% + \fi% + \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text></feedback>}% + \fi + \else + \trim@spaces@in\moodle@feedback + \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{\moodle@feedback}% + \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text></feedback>}% + \fi + \addto@xml[2]{\moodle@answers@xml}{</answer>}% + \fi }% +% WRITING QUESTION TO XML FILE +\gdef\writetruefalsequestion{% + \writetomoodle{<question type="truefalse">}% + \moodle@writecommondata% +}% +% \end{macrocode} +% +% \subsubsection{Matching Question Front-End} +% +% \begin{macrocode} +%\let\answer=\hfill + +\moodle@makefrontend{matching}{\moodle@makelatextag@matching}% + +% LATEX PROCESSING + +\def\moodle@makelatextag@matching{% + \ifmoodle@handout\else + \ifmoodle@draganddrop + \moodle@makelatextagbox{Drag and drop}\relax% + \fi + \ifmoodle@shuffle + \moodle@makelatextagbox{Shuffle}\relax% + \fi + \fi +} + +\def\moodle@matching@latexprocessing{% + \bgroup + %\let\answer=\hfill + \par%\noindent + \ifmoodle@handout + \NewList{questionlist} + \NewList{answerlist} + \fi + \def\matching@table@text{}% + % \ifnum\c@numgathereditems>2\relax% +% \PackageError{moodle}{Expecting at max two answers with truefalse type} +% \fi + \setcounter{moodle@numcorrectanswers}{0}% Here this counter is for "questions" (items on the left column) + \loopthroughitemswithcommand{\moodle@print@matching@answer}% + \ifnum\c@numgathereditems<3% + \PackageWarning{moodle}{Moodle expects at least three "answers" with matching type} + \fi + \ifnum\c@moodle@numcorrectanswers<2% + \PackageWarning{moodle}{Moodle expects at least two "questions" with the matching type} + \fi + \ifmoodle@handout + \ifmoodle@shuffle + \let\moodle@matching@loop=\ForEachRandomItem + \else + \let\moodle@matching@loop=\ForEachFirstItem + \fi + \moodle@matching@loop{questionlist}{Question}{ + \xdef\test@i{\Question}% + \ExtractRandomItem{answerlist}{Answer}% + \ifx\test@i\@empty + \xdef\matching@table@text{\expandonce\matching@table@text & & $\bullet$~\expandonce\Answer\\}% + \else + \xdef\matching@table@text{\expandonce\matching@table@text\expandonce\Question~$\bullet$ & & $\bullet$~\expandonce\Answer\\}% + \fi + }% + \fi + \begin{tabular}{@{}>{\raggedleft}p{.45\linewidth}p{.1\linewidth}p{.45\linewidth}@{}}% + \matching@table@text + \end{tabular}% + \par + \ifmoodle@handout\else + \ifx\moodle@generalfeedback\@empty\relax\else% + \fbox{\parbox{\linewidth}{\emph{\moodle@generalfeedback}}}% + \fi + \fi + \egroup +} + +\long\def\moodle@print@matching@answer#1{% + \moodle@print@matching@answer@int#1 \@rdelim +}% +\newcommand\moodle@print@matching@answer@int[1][]{% + \moodle@print@matching@answer@int@int +}% +\long\def\moodle@print@matching@answer@int@int#1\answer#2\@rdelim{% + %\typeout{\string#1 \answer \string#2}% + \def\test@i{#1}% + \trim@spaces@in\test@i + \ifmoodle@handout + \ifx\test@i\@empty + \InsertLastItem{questionlist}{\@empty}% + \else + \InsertLastItem{questionlist}{#1}% + \fi + \InsertLastItem{answerlist}{#2}% + \else + \ifx\test@i\@empty + \g@addto@macro\matching@table@text{&&$\bullet$~#2\\}% + \else + \stepcounter{moodle@numcorrectanswers}% + \xa\g@addto@macro\xa\matching@table@text\xa{\test@i~$\bullet$&\leavevmode\cleaders\hb@xt@.44em{\hss$\cdot$\hss}\hfill\kern\z@&$\bullet$~#2\\}% + \fi + \fi +}% + % SAVING ANSWERS TO MEMORY \long\def\savematchinganswer#1{% \bgroup - \savematchinganswer@int#1\moodle@answer@rdelim% + \savematchinganswer@int#1 \moodle@answer@rdelim% \passvalueaftergroup{\moodle@answers@xml}% \egroup }% \newcommand\savematchinganswer@int[1][]{% \setkeys{moodle}{#1}% - \xa\savematchinganswer@int@int\space% + \savematchinganswer@int@int%\space }% \long\def\savematchinganswer@int@int#1\answer#2\moodle@answer@rdelim{% + %\typeout{\string#1 \answer \string#2}% % Note that #1 may simply be \relax. \def\moodle@subquestiontext{#1}% \def\moodle@subanswertext{#2}% @@ -1854,9 +3590,12 @@ % \show\moodle@subanswertext \addto@xml[4]{\moodle@answers@xml}{ <answer><text>\moodle@subanswertext</text></answer>}% \fi - \ifx\moodle@feedback\@empty\relax\else - \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback</p>]]></text></feedback>}% - \fi +% \ifx\moodle@feedback\@empty\relax\else +% \trim@spaces@in\moodle@feedback +% \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{\moodle@feedback}% +% \addto@xml[4]{\moodle@answers@xml}{ <feedback +%format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text></feedback>}% +% \fi \addto@xml[2]{\moodle@answers@xml}{</subquestion>}% }% @@ -1868,12 +3607,9 @@ \writetomoodle{<question type="matching">}% \fi \moodle@writecommondata% - \moodle@writesingle% +% \moodle@writesingle% %irrelevant for the matching type \moodle@writeshuffle% - \moodle@writeanswernumbering% - \moodle@writeanswers% - \writetomoodle{</question>}% -% \gdef\moodle@answ +% \moodle@writeanswernumbering% %irrelevant for the matching type }% % \end{macrocode} % @@ -1896,6 +3632,8 @@ % LATEX PROCESSING % SAVING ANSWERS TO MEMORY +\newif\ifmoodle@clozemode +\moodle@clozemodefalse \NewEnviron{cloze}[2][]{% \bgroup \setkeys{moodle}{default grade=1}% @@ -1903,9 +3641,30 @@ % A cloze question won't have any \item's in it, so we just use \BODY. \moodle@enableclozeenvironments %First, the LaTeX processing. - \item \textbf{\moodle@questionname}\par + \item \textbf{\moodle@questionname} + \ifmoodle@handout + \moodle@makelatextag@qtype{cloze} + \else + \xa\xdef\xa\test@iii\xa{\moodle@tags}% + \ifx\test@iii\@moodle@empty\relax\else + \hfill tags: \texttt{\moodle@tags} + \fi + \par + \noindent + \moodle@makelatextag@qtype{cloze} + \moodle@makelatextag@value{default grade}{\moodle@marks{\csname moodle@default grade\endcsname}} + \moodle@makelatextag@value{penalty}{penalty} + \fi + \par \noindent \BODY + \edef\moodle@generalfeedback{\expandonce\moodle@feedback} + %\csname moodle@cloze@latexprocessing\endcsname + \ifmoodle@handout\else + \ifx\moodle@generalfeedback\@empty\relax\else% + \fbox{\parbox{\linewidth}{\emph{\moodle@generalfeedback}}}% + \fi + \fi %Now, writing information to memory. \@moodle@ifgeneratexml{% \xa\questiontext\xa{\BODY}% Save the question text as HTML. @@ -1927,6 +3686,7 @@ \gdef\writeclozequestion{% \writetomoodle{<question type="cloze">}% \moodle@writecommondata% + \moodle@writetags% \writetomoodle{</question>}% }% % \end{macrocode} @@ -1934,7 +3694,6 @@ % \subsubsection{Cloze Multiple Choice Questions} % % \begin{macrocode} -% TODO: Guard against [single=false] option \NewEnviron{clozemulti}[1][]{% \bgroup @@ -1947,40 +3706,88 @@ \def\moodle@clozemulti@output{}% \xa\g@addto@macro\xa\moodle@clozemulti@output\xa{\moodle@questionheader}% \def\clozemulti@coding{}% - \edef\clozemulti@coding{\otherlbrace\csname moodle@default grade\endcsname:}% + \edef\clozemulti@coding{\csname moodle@default grade\endcsname:}% + \ifmoodle@multiple + \PackageWarning{moodle}{Cloze Multiresponse only supported by Moodle 3.5+} + \g@addto@macro{\clozemulti@coding}{MULTIRESPONSE}% + \else + \g@addto@macro{\clozemulti@coding}{MULTICHOICE}% + \fi \ifcase\moodle@multi@mode\relax - % Case 0: dropdown box style - \g@addto@macro{\clozemulti@coding}{MULTICHOICE:}% + % Case 0: dropdown box style + \ifmoodle@shuffle + \g@addto@macro{\clozemulti@coding}{_}% + \fi \or % Case 1: vertical style - \g@addto@macro{\clozemulti@coding}{MULTICHOICE_V:}% + \ifmoodle@multiple + \PackageError{moodle}{Vertical mode (dropdown box) incompatible with multiresponse.} + \else + \g@addto@macro{\clozemulti@coding}{_V}% + \fi \else % Case 2: horizontal radio buttons - \g@addto@macro{\clozemulti@coding}{MULTICHOICE_H:}% + \g@addto@macro{\clozemulti@coding}{_H}% + \fi + \ifmoodle@shuffle + \PackageWarning{moodle}{Cloze Multi Shuffling only supported by Moodle 3.0+} + \g@addto@macro{\clozemulti@coding}{S:}% + \else + \g@addto@macro{\clozemulti@coding}{:}% \fi \bgroup \setkeys{moodle}{feedback={}}% \loopthroughitemswithcommand{\saveclozemultichoiceanswer}% \egroup - \xa\g@addto@macro\xa\clozemulti@coding\xa{\otherrbrace}% - \xa\g@addto@macro\xa\moodle@clozemulti@output\xa{\clozemulti@coding}% + %\xa\g@addto@macro\xa\clozemulti@coding\xa{\clozerbrace}% + \xa\g@addto@macro\xa\moodle@clozemulti@output\xa{\xa\clozelbrace\clozemulti@coding\clozerbrace}% + %\show\moodle@clozemulti@output \xa\gdef\xa\htmlize@afteraction@hook\xa{\moodle@clozemulti@output}% \def\endclozemulti@code{\htmlize@patchendenvironment}% \else %LaTeX version \moodle@questionheader% %Any introductory text just continues to be typeset. + \par + \noindent + \moodle@makelatextag@qtype{multi} + \ifmoodle@handout\else + \moodle@makelatextag@value{default grade}{\moodle@marks{\csname moodle@default grade\endcsname}} + \moodle@makelatextag@multi + \fi \def\cloze@multichoice@table@text{}% + \ifmoodle@handout\NewList{answerlist}\fi + %\let\moodle@feedback=\@empty \loopthroughitemswithcommand{\moodle@print@clozemultichoice@answer}% + \ifmoodle@handout + \ifmoodle@shuffle + \let\moodle@clozemult@loop=\ForEachRandomItem + \else + \let\moodle@clozemult@loop=\ForEachFirstItem + \fi + \moodle@clozemult@loop{answerlist}{Answer}{ + \xdef\cloze@multichoice@table@text{\expandonce\cloze@multichoice@table@text\expandonce\Answer}% + }% + \fi \ifcase\moodle@multi@mode\relax %Case 0: dropdown box style - \begin{tabular}[t]{|l|}\firsthline% (\firsthline is from the array package.) + \par\noindent + \ifmoodle@handout + \begin{tabular}[t]{|p{.45\linewidth}|} + \else + \begin{tabular}[t]{|p{.45\linewidth}|p{.45\linewidth}|} +% answer & feedback \\\hline\hline + \fi + \firsthline% (\firsthline is from the array package.) \cloze@multichoice@table@text% \end{tabular}% + \par% \or %Case 1: vertical style + \par\noindent \begin{itemize}\setlength\itemsep{0pt}\setlength\parskip{0pt}% \cloze@multichoice@table@text% \end{itemize}% + \par% \else %Case 2: horizontal radio buttons \par{\cloze@multichoice@table@text}\par% @@ -1994,40 +3801,75 @@ \def\moodle@print@clozemultichoice@answer#1{% - \moodle@print@clozemultichoice@answer@int#1\@rdelim% + \let\moodle@feedback=\@empty + \moodle@print@clozemultichoice@answer@int#1 \@rdelim% }% \newcommand\moodle@print@clozemultichoice@answer@int[1][]{% + \setkeys{moodle}{fraction=0,#1}% \moodle@print@clozemultichoice@answer@int@int% }% \def\moodle@print@clozemultichoice@answer@int@int#1#2\@rdelim{% + \def\moodle@answertext{}% % Case 0: "(answer) \\ \hline" % Case 1: "\item (answer)" % Case 2: "$\bullet~$(answer)\hfill" \ifcase\moodle@multi@mode\relax \relax% Case 0 \or - \g@addto@macro\cloze@multichoice@table@text{\item}% Case 1 + \g@addto@macro\moodle@answertext{\item}% Case 1 \else - \g@addto@macro\cloze@multichoice@table@text{$\bullet~$}% Case 2 + \g@addto@macro\moodle@answertext{$\bullet~$}% Case 2 \fi \def\test@i{#1}% \ifx\test@i\@star - \g@addto@macro\cloze@multichoice@table@text{#2$~\checkmark$}% + \setkeys{moodle}{fraction=100}% + \g@addto@macro\moodle@answertext{#2}% \else - \g@addto@macro\cloze@multichoice@table@text{#1#2}% + \g@addto@macro\moodle@answertext{#1#2}% + \fi + \trim@spaces@in\moodle@answertext + \trim@spaces@in\moodle@answertext + \ifmoodle@handout\else + \ifx\moodle@fraction\@hundred + \g@addto@macro\moodle@answertext{$~\checkmark$}% + \else + \moodle@checkfraction + \ifdim0pt=\moodle@fraction pt\relax\else + \xdef\moodle@answertext{\expandonce\moodle@answertext$~(\moodle@fraction\%)$}% + \fi + \fi \fi \ifcase\moodle@multi@mode\relax - \g@addto@macro{\cloze@multichoice@table@text}{\\ \hline}% Case 0 - \or - \relax% Case 1 + % Case 0 + \ifmoodle@handout\else + \xdef\moodle@answertext{\expandonce\moodle@answertext &\expandonce\emph{\expandonce\moodle@feedback}}% + \fi + \g@addto@macro\moodle@answertext{\\\hline} + \or % Case 1 + \ifmoodle@handout\else + \ifx\moodle@feedback\@empty\relax\else + \xdef\moodle@answertext{\expandonce\moodle@answertext \hfill \expandonce\emph{$\rightarrow$ \expandonce\moodle@feedback}}% + \fi + \fi + \else % otherwise + \ifmoodle@handout\else + \ifx\moodle@feedback\@empty\relax\else + \xdef\moodle@answertext{\expandonce\moodle@answertext\,\expandonce\emph{$\rightarrow$ \expandonce\moodle@feedback}}% + \fi + \fi + \g@addto@macro\moodle@answertext{\hfill}% Case 2 + \fi + \ifmoodle@handout + \def\temp{\InsertLastItem{answerlist}}% + \xa\temp\xa{\moodle@answertext}% \else - \g@addto@macro{\cloze@multichoice@table@text}{\hfill}% Case 2 + \xdef\cloze@multichoice@table@text{\expandonce\cloze@multichoice@table@text\expandonce\moodle@answertext}% \fi }% \def\saveclozemultichoiceanswer#1{% \bgroup - \saveclozemultichoiceanswer@int#1\moodle@answer@rdelim + \saveclozemultichoiceanswer@int#1 \moodle@answer@rdelim \egroup }% \newcommand\saveclozemultichoiceanswer@int[1][]{% @@ -2046,17 +3888,18 @@ \def\moodle@answertext{#1#2}% \fi \trim@spaces@in\moodle@answertext + \trim@spaces@in\moodle@answertext \ifx\moodle@fraction\@hundred \g@addto@macro\clozemulti@coding{=}% - \fi - \ifnum0<\moodle@fraction\relax - \ifnum\moodle@fraction<100\relax + \else + \moodle@checkfraction + \ifdim0pt=\moodle@fraction pt\relax\else \xdef\clozemulti@coding{\expandonce\clozemulti@coding\otherpercent\moodle@fraction\otherpercent}% \fi \fi \xdef\clozemulti@coding{\expandonce\clozemulti@coding\expandonce\moodle@answertext}% \ifx\moodle@feedback\@empty\else - \xdef\clozemulti@coding{\expandonce\clozemulti@coding\otherbackslash\otherhash\moodle@feedback}% + \xdef\clozemulti@coding{\expandonce\clozemulti@coding\otherbackslash\otherhash\expandonce\moodle@feedback}% \fi }% % \end{macrocode} @@ -2075,23 +3918,35 @@ \def\moodle@clozenumerical@output{}% \xa\g@addto@macro\xa\moodle@clozenumerical@output\xa{\moodle@questionheader}% \def\clozenumerical@coding{}% - \edef\clozenumerical@coding{\otherlbrace\csname moodle@default grade\endcsname:NUMERICAL:}% + \edef\clozenumerical@coding{\csname moodle@default grade\endcsname:NUMERICAL:}% \bgroup \setkeys{moodle}{feedback={}}% \loopthroughitemswithcommand{\saveclozenumericalanswer}% \egroup - \xa\g@addto@macro\xa\clozenumerical@coding\xa{\otherrbrace}% - \xa\g@addto@macro\xa\moodle@clozenumerical@output\xa{\clozenumerical@coding}% + %\xa\g@addto@macro\xa\clozenumerical@coding\xa{\otherrbrace}% + \xa\g@addto@macro\xa\moodle@clozenumerical@output\xa{\xa\clozelbrace\clozenumerical@coding\clozerbrace}% \xa\gdef\xa\htmlize@afteraction@hook\xa{\moodle@clozenumerical@output}% \def\endclozenumerical@code{\htmlize@patchendenvironment}% \else %LaTeX version \moodle@questionheader% %Any introductory text just continues to be typeset. - \def\cloze@numerical@table@text{}% - \loopthroughitemswithcommand{\moodle@print@clozenumerical@answer}% - \begin{tabular}[t]{|ll|}\firsthline - \cloze@numerical@table@text\hline% - \end{tabular}% + \par + \noindent + \moodle@makelatextag@qtype{numerical} + \ifmoodle@handout\else + \moodle@makelatextag@value{default grade}{\moodle@marks{\csname moodle@default grade\endcsname}} + \moodle@makelatextag@numerical + \par + \noindent + \def\cloze@numerical@table@text{}% + \loopthroughitemswithcommand{\moodle@print@clozenumerical@answer}% + \begin{tabular}[t]{|p{.45\linewidth}|p{.45\linewidth}|} + \firsthline% (\firsthline is from the array package.) +% answer & feedback \\\hline\hline + \cloze@numerical@table@text% + \end{tabular}% + \par% + \fi \def\endclozenumerical@code{\relax}% \fi \passvalueaftergroup\endclozenumerical@code% @@ -2100,6 +3955,7 @@ }[\endclozenumerical@code]% \def\moodle@print@clozenumerical@answer#1{% + \let\moodle@feedback=\@empty \bgroup \moodle@print@clozenumerical@answer@int#1\@rdelim \egroup @@ -2110,17 +3966,23 @@ }% \def\moodle@print@clozenumerical@answer@int@int#1\@rdelim{% \ifx\moodle@fraction\@hundred - \def\moodle@clozenumericalprint@fraction{$\checkmark$}% + \def\moodle@clozenumericalprint@fraction{$~\checkmark$}% \else - \edef\moodle@clozenumericalprint@fraction{(\moodle@fraction\%)}% + \moodle@checkfraction + \edef\moodle@clozenumericalprint@fraction{$(~\moodle@fraction\%)$}% \fi - \ifdim0pt=\moodle@tolerance pt\relax + \ifnum\z@=\moodle@tolerance \def\moodle@clozenumericalprint@tolerance{}% \else - \edef\moodle@clozenumericalprint@tolerance{\noexpand\pm\moodle@tolerance}% + \edef\moodle@clozenumericalprint@tolerance{$\,\pm\,$\moodle@printnum{\moodle@tolerance}}% \fi - \xdef\moodle@clozenumericalprint@line{$#1\moodle@clozenumericalprint@tolerance$ & \moodle@clozenumericalprint@fraction}% - \xa\g@addto@macro\xa\cloze@numerical@table@text\xa{\moodle@clozenumericalprint@line \\}% + \xdef\test@i{\trim@spaces{#1}}% + \ifx\test@i\@star + \xdef\moodle@clozenumericalprint@line{#1~\moodle@clozenumericalprint@fraction & \expandonce\emph{\expandonce\moodle@feedback}}% + \else + \xdef\moodle@clozenumericalprint@line{\moodle@printnum{#1}\moodle@clozenumericalprint@tolerance~\moodle@clozenumericalprint@fraction & \expandonce\emph{\expandonce\moodle@feedback}}% + \fi + \xa\g@addto@macro\xa\cloze@numerical@table@text\xa{\moodle@clozenumericalprint@line \\\hline}% }% @@ -2142,15 +4004,20 @@ \trim@spaces@in\moodle@answertext \ifx\moodle@fraction\@hundred \g@addto@macro\clozenumerical@coding{=}% - \fi - \ifnum0<\moodle@fraction\relax - \ifnum\moodle@fraction<100\relax + \else + \moodle@checkfraction + \ifdim0pt=\moodle@fraction pt\relax\else \xdef\clozenumerical@coding{\expandonce\clozenumerical@coding\otherpercent\moodle@fraction\otherpercent}% \fi \fi - \xdef\clozenumerical@coding{\expandonce\clozenumerical@coding\moodle@answertext:\moodle@tolerance}% + \ifx\moodle@answertext\@star + \xdef\clozenumerical@coding{\expandonce\clozenumerical@coding\moodle@answertext}% + \else + \xdef\clozenumerical@coding{\expandonce\clozenumerical@coding\moodle@answertext:\moodle@tolerance}% + \fi \ifx\moodle@feedback\@empty\else - \xdef\clozenumerical@coding{\expandonce\clozenumerical@coding\otherbackslash\otherhash\moodle@feedback}% + %\trim@spaces@in\moodle@feedback + \xdef\clozenumerical@coding{\expandonce\clozenumerical@coding\otherbackslash\otherhash\expandonce\moodle@feedback}% \fi }% % \end{macrocode} @@ -2177,29 +4044,38 @@ \xa\g@addto@macro\xa\moodle@clozeshortanswer@output\xa{\moodle@questionheader}% \def\clozeshortanswer@coding{}% \ifnum\count0=1\relax - \edef\clozeshortanswer@coding{\otherlbrace\csname moodle@default grade\endcsname:SHORTANSWER_C:}% + \edef\clozeshortanswer@coding{\csname moodle@default grade\endcsname:SHORTANSWER_C:}% \else - \edef\clozeshortanswer@coding{\otherlbrace\csname moodle@default grade\endcsname:SHORTANSWER:}% + \edef\clozeshortanswer@coding{\csname moodle@default grade\endcsname:SHORTANSWER:}% \fi \bgroup \setkeys{moodle}{feedback={}}% \loopthroughitemswithcommand{\saveclozeshortansweranswer}% \egroup - \xa\g@addto@macro\xa\clozeshortanswer@coding\xa{\otherrbrace}% - \xa\g@addto@macro\xa\moodle@clozeshortanswer@output\xa{\clozeshortanswer@coding}% + %\xa\g@addto@macro\xa\clozeshortanswer@coding\xa{\otherrbrace}% + \xa\g@addto@macro\xa\moodle@clozeshortanswer@output\xa{\xa\clozelbrace\clozeshortanswer@coding\clozerbrace}% \xa\gdef\xa\htmlize@afteraction@hook\xa{\moodle@clozeshortanswer@output}% \def\endclozeshortanswer@code{\htmlize@patchendenvironment}% \else %LaTeX version \moodle@questionheader% %Any introductory text just continues to be typeset. - \def\cloze@shortanswer@table@text{}% - \loopthroughitemswithcommand{\moodle@print@clozeshortanswer@answer}% - \ifnum\count0=1\relax - \marginpar{\tiny\mbox{(Case-Sensitive)}}% + \par + \noindent + \moodle@makelatextag@qtype{shortanswer} + \ifmoodle@handout\else + \moodle@makelatextag@value{default grade}{\moodle@marks{\csname moodle@default grade\endcsname}} + \moodle@makelatextag@shortanswer + \par + \noindent + \def\cloze@shortanswer@table@text{}% + \loopthroughitemswithcommand{\moodle@print@clozeshortanswer@answer}% + \begin{tabular}[t]{|p{.45\linewidth}|p{.45\linewidth}|} + \firsthline% (\firsthline is from the array package.) +% answer & feedback \\\hline\hline + \cloze@shortanswer@table@text% + \end{tabular}% + \par% \fi - \begin{tabular}[t]{|ll|}\firsthline - \cloze@shortanswer@table@text\hline% - \end{tabular}% \def\endclozeshortanswer@code{\relax}% \fi \passvalueaftergroup\endclozeshortanswer@code% @@ -2208,6 +4084,7 @@ }[\endclozeshortanswer@code]% \def\moodle@print@clozeshortanswer@answer#1{% + \let\moodle@feedback=\@empty \bgroup \moodle@print@clozeshortanswer@answer@int#1\@rdelim \egroup @@ -2218,12 +4095,13 @@ }% \def\moodle@print@clozeshortanswer@answer@int@int#1\@rdelim{% \ifx\moodle@fraction\@hundred - \def\moodle@clozeshortanswerprint@fraction{$\checkmark$}% + \def\moodle@clozeshortanswerprint@fraction{$~\checkmark$}% \else - \edef\moodle@clozeshortanswerprint@fraction{(\moodle@fraction\%)}% + \moodle@checkfraction + \edef\moodle@clozeshortanswerprint@fraction{$~(\moodle@fraction\%)$}% \fi - \xdef\moodle@clozeshortanswerprint@line{#1 & \moodle@clozeshortanswerprint@fraction}% - \xa\g@addto@macro\xa\cloze@shortanswer@table@text\xa{\moodle@clozeshortanswerprint@line \\}% + \xdef\moodle@clozeshortanswerprint@line{#1~\moodle@clozeshortanswerprint@fraction & \expandonce\emph{\expandonce\moodle@feedback}}% + \xa\g@addto@macro\xa\cloze@shortanswer@table@text\xa{\moodle@clozeshortanswerprint@line \\\hline}% }% @@ -2245,15 +4123,15 @@ \trim@spaces@in\moodle@answertext \ifx\moodle@fraction\@hundred \g@addto@macro\clozeshortanswer@coding{=}% - \fi - \ifnum0<\moodle@fraction\relax - \ifnum\moodle@fraction<100\relax + \else + \moodle@checkfraction + \ifdim0pt=\moodle@fraction pt\relax\else \xdef\clozeshortanswer@coding{\expandonce\clozeshortanswer@coding\otherpercent\moodle@fraction\otherpercent}% \fi \fi \xdef\clozeshortanswer@coding{\expandonce\clozeshortanswer@coding\moodle@answertext}% \ifx\moodle@feedback\@empty\else - \xdef\clozeshortanswer@coding{\expandonce\clozeshortanswer@coding\otherbackslash\otherhash\moodle@feedback}% + \xdef\clozeshortanswer@coding{\expandonce\clozeshortanswer@coding\otherbackslash\otherhash\expandonce\moodle@feedback}% \fi }% % \end{macrocode} @@ -2270,15 +4148,20 @@ \catcode`\&=12\gdef\otherampersand{&}% \catcode`\^=12\gdef\othercaret{^}% \catcode`\$=12\gdef\otherdollar{$}% - \catcode`\%=12\gdef\otherpercent{%}}% + \catcode`\%=12\gdef\otherpercent{%} + \catcode`\%=12\gdef\otherlbracket{[} + \catcode`\%=12\gdef\otherrbracket{]}}% {\catcode`\ =12\gdef\otherspace{ }}% -{\tt\catcode`\|=0\catcode`\\=12\relax|gdef|otherbackslash{\}}% +{\ttfamily\catcode`\|=0\catcode`\\=12\relax|gdef|otherbackslash{\}}% {\catcode`\[=1\catcode`\]=2\catcode`\{=12\catcode`\}=12% - \gdef\otherlbrace[{]\gdef\otherrbrace[}]] - + \gdef\otherlbrace[{]\gdef\otherrbrace[}]\gdef\clozelbrace[{]\gdef\clozerbrace[}]]% \edef\@otherlbrace{\otherlbrace}% \edef\@otherrbrace{\otherrbrace}% +\edef\@otherlbracket{\otherlbracket}% +\edef\@otherrbracket{\otherrbracket}% +\edef\@clozelbrace{\clozelbrace}% +\edef\@clozerbrace{\clozerbrace}% \edef\@otherdollar{\otherdollar}% \edef\@otherbackslash{\otherbackslash}% \edef\@othertilde{\othertilde}% @@ -2381,9 +4264,16 @@ % \end{macrocode} % % \subsection{Level-Tracking} +% +% \subsubsection{TeX groups} +% While parsing, we'll need to keep track of how deeply nested in \TeX\ groups we are. +% \begin{macrocode} +\newcount\grouplevel +% \end{macrocode} +% +% \subsubsection{Math mode} % While parsing, we'll need to keep track of whether -% we are in math mode (and how many levels deep the math mode might be nested), -% and also how deeply nested in \TeX\ groups we are. +% we are in math mode (and how many levels deep the math mode might be nested). % \begin{macrocode} \newcount\moodle@mathmodedepth \moodle@mathmodedepth=0\relax @@ -2393,12 +4283,15 @@ \else #2% \fi -} - -\newcount\grouplevel +}% +% \end{macrocode} +% +% \subsubsection{Nested Lists} +% While parsing, we'll need to keep track levels of nested list. +% \begin{macrocode} +\newcount\moodle@listdepth +\moodle@listdepth=0\relax -\newif\ifhtmlizer@active -\htmlizer@activefalse % \end{macrocode} % % \subsection{Separation} @@ -2436,6 +4329,8 @@ % \subsection{Main Code: the HTMLizer} % % \begin{macrocode} +\newif\ifhtmlizer@active +\htmlizer@activefalse \newif\ifhtmlize@actioncs \newif\ifhtmlize@expandcs \newif\ifhtmlize@passcs @@ -2456,7 +4351,7 @@ \advance\grouplevel by 1\relax \bgroup \ultradetokenize@to@macro\htmlize@texttoscan{#1}% - \xa\htmlize@recursive@i\htmlize@texttoscan\@htmlize@stop\@htmlize@stop\@htmlize@stop\htmlize@rdelim@i + \xa\htmlize@recursive@i\htmlize@texttoscan\@htmlize@stop\@htmlize@stop\@htmlize@stop\htmlize@rdelim@i% \egroup \advance\grouplevel by -1\relax }% @@ -2502,7 +4397,13 @@ \gdef\htmlize@scrap{\converttohtml@int}% \xa\g@addto@macro\xa\htmlize@scrap\xa{\xa{\htmlize@blockinbraces}}% \g@addto@macro\htmlize@scrap{\g@addto@macro\htmlize@output}% - \xa\g@addto@macro\xa\htmlize@scrap\xa{\xa{\otherrbrace}}% + \ifmoodle@clozemode + \xa\g@addto@macro\xa\htmlize@scrap\xa{\xa{\otherbackslash\otherrbrace}}% +% \moodle@ifmathmode{\xa\g@addto@macro\xa\htmlize@scrap\xa{\xa{\otherbackslash}}}% +% {}% + \else + \xa\g@addto@macro\xa\htmlize@scrap\xa{\xa{\otherrbrace}}% + \fi \g@addto@macro\htmlize@scrap{\htmlize@recursive@i}% \xa\g@addto@macro\xa\htmlize@scrap\xa{\htmlize@remainder@detokenized\@htmlize@stop\@htmlize@stop\@htmlize@stop\htmlize@rdelim@i}% % Okay, that's done. It's stored in a global macro. @@ -2519,10 +4420,10 @@ \htmlize@displaymathshift@replace#1#2#3\htmlize@rdelim@iii% \else % Single dollar sign, so we're entering inline math mode. - % We grab everything between $$...$$, sanitize it, and add it verbatim to + % We grab everything between $...$, sanitize it, and add it verbatim to % our output. \htmlize@inlinemathshift@replace#1#2#3\htmlize@rdelim@iii% - \fi + \fi% \ifx\test@ii\@otherdollar % Now we resume work. % The \htmlize@xxxxxxmathshift@replace macro stored the remaining text in \htmlize@remaining@text. % Note that since we never detokenized and retokenized #1#2#3, @@ -2647,9 +4548,9 @@ %\edef\ds{Must pass on \xa\string\@htmlize@cs}\show\ds \g@addto@macro\htmlize@output{#1}% \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}% - \fi - \fi - \fi + \fi% \ifhtmlize@expandcs + \fi% \ifhtmlize@actioncs + \fi% \ifx\@htmlize@cs\@@begin@cs \else% \ifx\test@i\@othertilde% % The ~ becomes non-breaking space @@ -2664,7 +4565,7 @@ \else \g@addto@macro\htmlize@output{\otherampersand lsquo;}% \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}% - \fi + \fi% \ifx\test@ii\@lsinglequote% \else \ifx\test@i\@rsinglequote% \ifx\test@ii\@rsinglequote% @@ -2674,7 +4575,7 @@ \else \g@addto@macro\htmlize@output{\otherampersand rsquo;}% \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}% - \fi + \fi% \ifx\test@ii\@rsinglequote% \else \ifx\test@i\@doublequote \g@addto@macro\htmlize@output{\otherampersand rdquo;}% @@ -2689,20 +4590,20 @@ \moodle@ifmathmode{\g@addto@macro\htmlize@output{\otherampersand gt;}}% {\g@addto@macro\htmlize@output{>}}% \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}% - \else + \else % Default case: write first token to output, call self on remaining tokens. \g@addto@macro\htmlize@output{#1}% \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}% - \fi - \fi - \fi - \fi - \fi - \fi - \fi - \fi - \fi - \fi + \fi% \ifx\test@i\@gt + \fi% \ifx\test@i\@lt + \fi% \ifx\test@i\@doublequote + \fi% \ifx\test@i\@rsinglequote% + \fi% \ifx\test@i\@lsinglequote% + \fi% \ifx\test@i\@othertilde% + \fi% \ifx\test@i\@otherbackslash% + \fi% \ifx\test@i\@otherdollar% + \fi% \ifx\test@i\@otherlbrace% + \fi% \ifx\test@i\@@htmlize@stop \htmlize@next@i }% @@ -2721,16 +4622,38 @@ \edef\inlinemathleftdelim{\otherbackslash(}% \def\inlinemathrightdelim#1{\advancemathmodecounter{-1}% \g@addto@macro\htmlize@output{\otherbackslash)}}% -\edef\displaymathleftdelim{<CENTER>\otherbackslash[}% +\edef\displaymathleftdelim{\otherbackslash[}% \def\displaymathrightdelim#1{\advancemathmodecounter{-1}% - \g@addto@macro\htmlize@output{\otherbackslash]</CENTER>}}% + \g@addto@macro\htmlize@output{\otherbackslash]}}% +\long\def\htmlize@inlinemath@recursive@i#1#2#3\htmlize@rdelim@i{% + % inspired by \htmlize@recursive@i + \def\test@i{#1}% + \ifx\test@i\@@htmlize@stop + \let\htmlize@next@i=\relax + \else + \ifx\test@i\@otherbackslash + \g@addto@macro\mathtext{#1#2}% + \def\htmlize@next@i{\xa\htmlize@inlinemath@recursive@i#3\htmlize@rdelim@i}% + \else + \ifx\test@i\@otherdollar + \let\htmlize@next@i=\relax + \g@addto@macro\aftertext{#2#3}% + \else + \g@addto@macro\mathtext{#1}% + \def\htmlize@next@i{\xa\htmlize@inlinemath@recursive@i#2#3\htmlize@rdelim@i}% + \fi + \fi + \fi + \htmlize@next@i +} {\catcode`\$=12\relax% - \gdef\htmlize@inlinemathshift@replace$#1$#2\htmlize@rdelim@iii{% + \gdef\htmlize@inlinemathshift@replace#1#2\htmlize@rdelim@iii{% %\def\ds{inline math shift has '#1' and '#2'}\show\ds \xa\g@addto@macro\xa\htmlize@output\xa{\inlinemathleftdelim}% \advancemathmodecounter{1}% - \def\mathtext{#1}% - \def\aftertext{#2}% + \gdef\mathtext{}% + \gdef\aftertext{}% + \htmlize@inlinemath@recursive@i#2\htmlize@rdelim@i% \xdef\htmlize@remaining@text{\expandonce\mathtext% \otherbackslash inlinemathrightdelim{}% \expandonce\aftertext}% @@ -2746,6 +4669,7 @@ \expandonce\aftertext}% }% } + % \end{macrocode} % % \subsection{Engines for Control Sequences} @@ -2847,6 +4771,25 @@ \xa\g@addto@macro\xa\htmlize@activate@css\xa{\htmlize@scrap}% \xa\def\csname html@\string#1\endcsname% %And this \def\html@\oldcsname is follows by the remainder of the definition. } +\def\html@action@newcommand#1[#2][#3]#4{% + %\message{>>> Defining #1[#2][#3]{...} ^^J} + \ifmoodle@draftmode + \else + \xa\html@action@def\csname #1\endcsname{\csname moodle@#1@int\endcsname}% + \fi + % Note that \htmlize@do@actioncs will 'patch' this by putting + % '\xa\htmlize@proceedwiththerest\htmlize@afteraction@hook' + % at the end. We want those 3 tokens to occur instead after + % the graphics filename. + \xa\csdef{moodle@#1@int}##1##2##3{\csname moodle@#1@int@int\endcsname}% + % This gobbles up those three spurious tokens, + % which we will re-insert after our work is done. + \xa\newcommand\csname moodle@#1@int@int\endcsname[#2][#3]{% + #4% + % Now we re-insert the code to get the HTMLizing going again. + \xa\htmlize@proceedwiththerest\htmlize@afteraction@hook + }% +} % \end{macrocode} % % \subsubsection{Engine for expansion control sequences} @@ -2868,6 +4811,24 @@ } \let\htmlregister=\htmlize@record@expand % \end{macrocode} +% Often users define a list of macros at the end of the preamble. +% It can be cumbersome to record individually these macros for expansion. +% By calling |\moodleregisternewcommands| they trigger the automatic +% expansion of macros defined subsequently using |\newcommand|, +% |\renewcommand|, |\providecommand| or their starred variants. +% \begin{macrocode} +\def\moodleregisternewcommands{% + %% INSPIRED FROM + %https://tex.stackexchange.com/questions/73271/how-to-redefine-or-patch-the-newcommand-command + \newcommand*{\saved@ifdefinable}{} + \let\saved@ifdefinable\@ifdefinable + \renewcommand{\@ifdefinable}[2]{% + \saved@ifdefinable{##1}{##2}% + \htmlregister{##1} + }% + \let\@@ifdefinable\@ifdefinable +}% +% \end{macrocode} % On the other hand, if an alternate version of the macro is % needed for HTML purposes, you can define its HTML version with % |\html@def\mymacro...| @@ -2901,20 +4862,50 @@ \htmlize@record@environment{shortanswer} \html@newenvironment{center}{\xdef\htmlize@afteraction@hook{<CENTER>\expandonce\BODY</CENTER>}}% -\html@newenvironment{enumerate}{% - \xa\gatheritems\xa{\BODY}% - \gdef\htmlize@afteraction@hook{<OL>}% - \loopthroughitemswithcommand{\moodle@itemtoLI}% - \g@addto@macro\htmlize@afteraction@hook{</OL>}% -}% -\html@newenvironment{itemize}{% - \xa\gatheritems\xa{\BODY}% - \gdef\htmlize@afteraction@hook{<UL>}% - \loopthroughitemswithcommand{\moodle@itemtoLI}% - \g@addto@macro\htmlize@afteraction@hook{</UL>}% + +\def\moodle@save@getitems@state{% + \global\xa\xdef\csname moodle@currentitemnumber@level@\the\moodle@listdepth\xa\endcsname\xa{\thecurrentitemnumber}% + \global\xa\xdef\csname moodle@numgathereditems@level@\the\moodle@listdepth\xa\endcsname\xa{\thenumgathereditems}% + \moodle@saveitems{\thenumgathereditems}% +}% +\def\moodle@restore@getitems@state{% + \setcounter{numgathereditems}{\csname moodle@numgathereditems@level@\the\moodle@listdepth\endcsname}% + \setcounter{currentitemnumber}{\csname moodle@currentitemnumber@level@\the\moodle@listdepth\endcsname}% + \moodle@restoreitems{\thenumgathereditems}% +}% +\def\moodle@saveitems#1{% + \ifnum#1>0% + \global\csletcs{moodle@level@\the\moodle@listdepth @item@#1}{getitems@item@#1}% + \xa\moodle@saveitems\xa{\number\numexpr#1-1\expandafter}% + \fi +}% +\def\moodle@restoreitems#1{% + \ifnum#1>0% + \global\csletcs{getitems@item@#1}{moodle@level@\the\moodle@listdepth @item@#1}% + \global\xa\let\csname moodle@level@\the\moodle@listdepth @item@#1\endcsname=\@undefined + \xa\moodle@restoreitems\xa{\number\numexpr#1-1\expandafter}% + \fi +}% +\def\moodle@makelistenv#1#2{% + \html@newenvironment{#1}{% + \advance\moodle@listdepth by 1\relax + \moodle@save@getitems@state% + \xa\gatheritems\xa{\BODY}% + \gdef\htmlize@afteraction@hook{<#2>}% + \loopthroughitemswithcommand{\moodle@itemtoLI}% + \g@addto@macro\htmlize@afteraction@hook{</#2>}% + \moodle@restore@getitems@state% + \advance\moodle@listdepth by -1\relax + }% }% + +\moodle@makelistenv{enumerate}{OL}% +\moodle@makelistenv{itemize}{UL}% + \def\moodle@itemtoLI#1{% - \g@addto@macro\htmlize@afteraction@hook{<LI>#1</LI>}% + \g@addto@macro\htmlize@afteraction@hook{<LI>#1}% + \trim@spaces@in\htmlize@afteraction@hook% + \g@addto@macro\htmlize@afteraction@hook{</LI>}% }% % \end{macrocode} @@ -2925,11 +4916,15 @@ \def\advancemathmodecounter#1{% \global\advance\moodle@mathmodedepth by #1\relax } +\def\openclozemode{% + \global\moodle@clozemodetrue\relax +} +\def\endclozemode{% + \global\moodle@clozemodefalse\relax +} \htmlize@record@action{\advancemathmodecounter}% - - - - +\htmlize@record@action{\openclozemode}% +\htmlize@record@action{\endclozemode}% \htmlize@record@action{\relax}% \html@action@def\#{\g@addto@macro\htmlize@output{\otherhash}}% @@ -2942,15 +4937,32 @@ }% \html@action@def\}{% \moodle@ifmathmode{\g@addto@macro\htmlize@output{\otherbackslash\otherrbrace}}% - {\g@addto@macro\htmlize@output{\otherrbrace}}% + {\ifmoodle@clozemode\g@addto@macro\htmlize@output{\otherbackslash}\fi + \g@addto@macro\htmlize@output{\otherrbrace}}% + }% +\html@action@def\[{% + \advancemathmodecounter{1} + \g@addto@macro\htmlize@output{\otherbackslash\otherlbracket}% + }% +\html@action@def\]{% + \g@addto@macro\htmlize@output{\otherbackslash\otherrbracket}% + \advancemathmodecounter{-1} + }% +\html@action@def\({% + \advancemathmodecounter{1} + \g@addto@macro\htmlize@output{\otherbackslash(}% + }% +\html@action@def\){% + \g@addto@macro\htmlize@output{\otherbackslash)}% + \advancemathmodecounter{-1} }% \html@action@def\ldots{% \moodle@ifmathmode{\g@addto@macro\htmlize@output{\string\ldots}}% - {\g@addto@macro\htmlize@output{...}}% + {\g@addto@macro\htmlize@output{\otherampersand hellip\othersemicol}}% }% \html@action@def\dots{% \moodle@ifmathmode{\g@addto@macro\htmlize@output{\string\dots}}% - {\g@addto@macro\htmlize@output{...}}% + {\g@addto@macro\htmlize@output{\otherampersand hellip\othersemicol}}% }% \html@action@def\ {% \moodle@ifmathmode{\g@addto@macro\htmlize@output{\otherbackslash\otherspace}}% @@ -2959,12 +4971,25 @@ \html@action@def\${% \g@addto@macro\htmlize@output{\otherdollar}% }% - \html@action@def\clozetilde{% \xa\g@addto@macro\xa\htmlize@output\xa{\othertilde}% }% +\html@action@def\clozelbrace{% + \openclozemode + \xa\g@addto@macro\xa\htmlize@output\xa{\otherlbrace}% + }% +\html@action@def\clozerbrace{% + \xa\g@addto@macro\xa\htmlize@output\xa{\otherrbrace}% + \endclozemode + }% +\html@action@def\TeX{% + \g@addto@macro\htmlize@output{\otherbackslash(\otherbackslash rm\otherbackslash TeX\otherbackslash)} + }% +\html@action@def\LaTeX{% + \g@addto@macro\htmlize@output{\otherbackslash(\otherbackslash rm\otherbackslash LaTeX\otherbackslash)} + }% - +{\catcode`;=12\relax\gdef\othersemicol{;}} %Diacritical marks over vowels {\catcode`|=3\relax @@ -2974,32 +4999,40 @@ \g@addto@macro\htmlize@activate@css{% \def#1##1{% \ifinlist{##1}{\htmlize@vowels}% - {\g@addto@macro\htmlize@output{\otherampersand##1#2;}}% + {\g@addto@macro\htmlize@output{\otherampersand##1#2\othersemicol}}% {\xa\g@addto@macro\htmlize@output\xa{\string#1##1}}% }% }% } \htmlize@define@diacritic{\^}{circ}% \htmlize@define@diacritic{\'}{acute}% -\htmlize@define@diacritic{\"}{uml}% \htmlize@define@diacritic{\`}{grave}% +%Diaeresis/Tréma/Umlaut +{\catcode`|=3\relax + \gdef\htmlize@diaeresis{a|e|i|o|u|y|A|E|I|O|U|Y|}} +\html@action@def\"#1{% + \ifinlist{#1}{\htmlize@diaeresis}% + {\g@addto@macro\htmlize@output{\otherampersand#1uml\othersemicol}}% + {\xa\g@addto@macro\htmlize@output\xa{\string\"#1}}% +}% + %Hungarian long-umlaut diacritics \def\@o{o}\def\@O{O}\def\@u{u}\def\@U{U}% \html@action@def\H#1{% \bgroup \def\test@i{#1}% \ifx\test@i\@O - \def\toadd{\otherampersand\otherhash337;}% + \def\toadd{\otherampersand\otherhash336\othersemicol}% \else \ifx\test@i\@o - \def\toadd{\otherampersand\otherhash337;}% + \def\toadd{\otherampersand\otherhash337\othersemicol}% \else - \ifx\test@i\U - \def\toadd{\otherampersand\otherhash368;}% + \ifx\test@i\@U + \def\toadd{\otherampersand\otherhash368\othersemicol}% \else - \ifx\test@i\u - \def\toadd{\otherampersand\otherhash369;}% + \ifx\test@i\@u + \def\toadd{\otherampersand\otherhash369\othersemicol}% \else \def\toadd{\otherbackslash\otherlbrace#1\otherrbrace}% \fi @@ -3010,50 +5043,275 @@ \egroup }% +%Cedilla +\def\@c{c}\def\@C{C}\def\@s{s}\def\@S{S}\def\@t{t}\def\@T{T}% +\html@action@def\c#1{% + \bgroup + \def\test@i{#1}% + \ifx\test@i\@c + \def\toadd{\otherampersand ccedil\othersemicol}% + \else + \ifx\test@i\@C + \def\toadd{\otherampersand Ccedil\othersemicol}% + \else + \ifx\test@i\@s + \def\toadd{\otherampersand\otherhash351\othersemicol}% + \else + \ifx\test@i\@S + \def\toadd{\otherampersand\otherhash350\othersemicol}% + \else + \ifx\test@i\@t + \def\toadd{\otherampersand\otherhash355\othersemicol}% + \else + \ifx\test@i\@T + \def\toadd{\otherampersand\otherhash354\othersemicol}% + \else + \def\toadd{\otherbackslash\otherlbrace#1\otherrbrace}% + \fi + \fi + \fi + \fi + \fi + \fi + \xa\g@addto@macro\xa\htmlize@output\xa{\toadd}% + \egroup +}% %Tilde over a, n, o {\catcode`|=3\relax \gdef\htmlize@tilde{A|N|O|a|n|o|}} \html@action@def\~#1{% \ifinlist{#1}{\htmlize@tilde}% - {\g@addto@macro\htmlize@output{\otherampersand#1tilde;}}% + {\g@addto@macro\htmlize@output{\otherampersand#1tilde\othersemicol}}% {\xa\g@addto@macro\htmlize@output\xa{\string\~#1}}% - }% +}% + +% breve diacritics +{\catcode`|=3\relax + \gdef\htmlize@breve{A|G|U|a|g|u|}} +\def\@e{e}\def\@E{E}\def\@i{i}\def\@ii{\i}\def\@I{I}\def\@o{o}\def\@O{O}% +\html@action@def\u#1{% + \ifinlist{#1}{\htmlize@breve}% + {\g@addto@macro\htmlize@output{\otherampersand#1breve\othersemicol}}% + { + \bgroup + \def\test@i{#1}% + \ifx\test@i\@E + \def\toadd{\otherampersand\otherhash276\othersemicol}% + \else + \ifx\test@i\@e + \def\toadd{\otherampersand\otherhash277\othersemicol}% + \else + \ifx\test@i\@I + \def\toadd{\otherampersand\otherhash300\othersemicol}% + \else + \ifx\test@i\@i + \def\toadd{\otherampersand\otherhash301\othersemicol}% + \else + \ifx\test@i\@ii + \def\toadd{\otherampersand\otherhash301\othersemicol}% + \else + \ifx\test@i\@O + \def\toadd{\otherampersand\otherhash334\othersemicol}% + \else + \ifx\test@i\@o + \def\toadd{\otherampersand\otherhash335\othersemicol}% + \else + \def\toadd{\otherbackslash\otherlbrace#1\otherrbrace}% + \fi + \fi + \fi + \fi + \fi + \fi + \fi + \xa\g@addto@macro\xa\htmlize@output\xa{\toadd}% + \egroup + }% +}% + +% caron diacritics +{\catcode`|=3\relax + \gdef\htmlize@caron{C|D|E|L|N|R|S|T|Z|c|d|e|l|n|r|s|t|z|}} +\html@action@def\v#1{% + \ifinlist{#1}{\htmlize@caron}% + {\g@addto@macro\htmlize@output{\otherampersand#1caron\othersemicol}}% + {\xa\g@addto@macro\htmlize@output\xa{\string\v#1}}% +}% % \end{macrocode} % % \subsubsection{Command sequences for Expansion} % % \begin{macrocode} -\html@def\underline#1{<SPAN STYLE="text-decoration: underline;">#1</SPAN>} +\html@def\underline#1{<SPAN STYLE=\&\#34;text-decoration: underline;\&\#34;>#1</SPAN>} \html@def\emph#1{<EM>#1</EM>}% +\html@def\textit#1{<I>#1</I>}% \html@def\textbf#1{<B>#1</B>}% +\html@def\texttt#1{<CODE>#1</CODE>}% +\html@def\textsc#1{<SPAN STYLE=\&\#34;font-variant: small-caps;\&\#34;>#1</SPAN>} +\html@def\url#1{<A href=\&\#34;#1\&\#34;>#1</A>}% +\html@def\href#1#2{<A href=\&\#34;#1\&\#34;>#2</A>}% +\html@def\textsuperscript#1{<SUP>#1</SUP>}% +\html@def\up#1{<SUP>#1</SUP>}% +\html@def\fup#1{<SUP>#1</SUP>}% +\html@def\textsubscript#1{<SUB>#1</SUB>}% \html@def\blank{____________}% \html@def\par{</P><P>}% \html@def\aa{\å}% \html@def\AA{\Å}% \html@def\ae{\æ}% \html@def\AE{\Æ}% +\html@def\oe{\œ}% +\html@def\OE{\Œ}% \html@def\S{\§}% \html@def\euro{\€}% \html@def\texteuro{\€}% \html@def\o{\ø}% \html@def\O{\Ø}% \html@def\ss{\ß}% +\html@def\SS{\&\#7838;}% \html@def\l{\ł}% \html@def\L{\Ł}% +\html@def\og{\«\&\#8239;}% +\html@def\guillemotleft{\«\&\#8239;}% +\html@def\fg{\&\#8239;\»}% +\html@def\guillemotright{\&\#8239;\»}% +\html@def\,{\&\#8239;}% +\html@def\thinspace{\&\#8239;}% +\html@def\textbackslash{\&\#92;}% +\html@def\_{\&\#95;}% +\html@def\textquestiondown{\¿}% +\html@def\textexclamdown{\¡}% % AH CUSTOM MACROS TO EXPAND --- remove these before publishing! -\htmlize@record@expand{\inv}% -\htmlize@record@expand{\rec}% +%\htmlize@record@expand{\inv}% +%\htmlize@record@expand{\rec}% \htmlize@record@action\inlinemathrightdelim \htmlize@record@action\displaymathrightdelim - % \end{macrocode} % -% \subsection{Graphics via {\tt\string\includegraphics}} +% \subsection{Graphics via {\ttfamily\string\includegraphics}} % +% \subsubsection{Finding Media Files} +% The following code is adapted from the command |\Ginclude@graphics| as +% found in |graphics.sty|. +% Calling |\moodle@media@find|\marg{filename} looks for the file the +% same way |\includegraphics| does, with or without extension provided, +% in the current folder and in folders specified with |\graphicspath{}|. +% The allowed extensions and their relative priorities can be set +% via |\DeclareGraphicsExtensions{}|. +% The outcome is that the macros |\moodle@media@base| and |\moodle@media@ext| +% are set with the basename, including path, and extension, respectively. +% +% \begin{macrocode} +\def\moodle@media@find#1{% + \ifx\detokenize\@undefined\else + \edef\Gin@extensions{\detokenize\expandafter{\Gin@extensions}}% + \fi + \begingroup + \let\input@path\Ginput@path + \set@curr@file{#1}% + \expandafter\filename@parse\expandafter{\@curr@file}% + \ifx\filename@ext\Gin@gzext + \expandafter\filename@parse\expandafter{\filename@base}% + \ifx\filename@ext\relax + \let\filename@ext\Gin@gzext + \else + \edef\Gin@ext{\Gin@ext\Gin@sepdefault\Gin@gzext}% + \fi + \fi + \ifx\filename@ext\relax + \@for\Gin@temp:=\Gin@extensions\do{% + \ifx\Gin@ext\relax + \Gin@getbase\Gin@temp + \fi}% + \else + \Gin@getbase{\Gin@sepdefault\filename@ext}% + \ifnum0% + \ifx\Gin@ext\relax 1% + \else \@ifundefined{Gin@rule@\Gin@ext}{1}{0}% + \fi >0 + \let\Gin@ext\relax + \let\Gin@savedbase\filename@base + \let\Gin@savedext\filename@ext + \edef\filename@base{\filename@base\Gin@sepdefault\filename@ext}% + \let\filename@ext\relax + \@for\Gin@temp:=\Gin@extensions\do{% + \ifx\Gin@ext\relax + \Gin@getbase\Gin@temp + \fi}% + \ifx\Gin@ext\relax + \let\filename@base\Gin@savedbase + \let\filename@ext\Gin@savedext + \fi + \fi + \ifx\Gin@ext\relax + \@warning{File `#1' not found}% + \def\Gin@base{\filename@area\filename@base}% + \edef\Gin@ext{\Gin@sepdefault\filename@ext}% + \fi + \fi + \ifx\Gin@ext\relax + \@latex@error{File `#1' not found}% + {I could not locate the file with any of these extensions:^^J% + \Gin@extensions^^J\@ehc}% + \else + % begin modified part + \xdef\moodle@media@base{\detokenize\xa{\Gin@base}}% + \xdef\moodle@media@ext{\detokenize\xa{\Gin@ext}}% + % end modfied part + \fi + \endgroup +} +% \end{macrocode} +% \begin{macrocode} +%See +% * https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types +% * https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Containers +\def\moodle@media@formats{} +\newcommand{\DeclareMediaFormat}[3]{% + \xdef\moodle@media@formats{\ifx\moodle@media@formats\empty\else\moodle@media@formats,\fi#1}% + \csgdef{moodle@media@#1list}{#2}% + \csgdef{moodle@media@#1mime}{#3}% +}% +% Image Formats +\DeclareMediaFormat{PNG}{.png,.PNG}{image/png}% +\DeclareMediaFormat{JPEG}{.jpg,.JPG,.jpeg,.JPEG}{image/jpeg}% +\DeclareMediaFormat{SVG}{.svg,.SVG}{image/svg+xml}% +\DeclareMediaFormat{GIF}{.gif}{image/gif}% +% Audio Formats +\DeclareMediaFormat{WAV}{.wav,.WAV}{audio/wave}% +\DeclareMediaFormat{MP3}{.mp3,.MP3}{audio/mpeg}% +\DeclareMediaFormat{OGG}{.ogg,.opus,.og&}{audio/ogg}% +%\DeclareMediaFormat{FLAC}{.flac,.FLAC}{audio/flac}% +% Video Formats +\DeclareMediaFormat{WEBM}{.webm,.webm}{video/webm}% +\DeclareMediaFormat{MP4}{.mp4,.MP4,.m4v,.M4V}{video/mp4}% +\DeclareMediaFormat{OGV}{.ogv,.OGV}{video/ogg}% +% \end{macrocode} +% \begin{macrocode} +\def\moodle@media@mime@identify#1{% + \edef\test@i{\detokenize\xa{#1}}% + \let\moodle@media@mime@current\relax + \edef\moodle@media@formats{\detokenize\xa{\moodle@media@formats}}% + \@for\@format:=\moodle@media@formats\do{% + \edef\@templist{\csname moodle@media@\@format list\endcsname}% + \@for\@ext:=\@templist\do{% + \ifx\moodle@media@mime@current\relax + \edef\@ext{\detokenize\xa{\@ext}}% + \ifx\test@i\@ext + \message{<<extension \@ext (\@format) identified>>^^J}% + \xdef\moodle@media@mime@current{\csname moodle@media@\@format mime\endcsname}% + \xdef\moodle@media@ext@current{#1}% + \fi + \fi + }% + }% +} +% \end{macrocode} +% % \subsubsection{External program command lines} % We first set up commands for the external programs. % \begin{macrocode} @@ -3068,20 +5326,65 @@ \expandafter\def\htmlize@executable@macro{#1}% } -\def\ghostscriptcommand{\htmlize@setexecutable\gs} -\def\opensslcommand{\htmlize@setexecutable\openssl} -\def\imagemagickcommand{\htmlize@setexecutable\htmlize@imagemagick@convert} +\def\ghostscriptcommand{\htmlize@setexecutable\gs}% +\def\baselxivcommand{\htmlize@setexecutable\baselxiv}% +\def\imagemagickcommand{\htmlize@setexecutable\htmlize@imagemagick@convert}% +\def\optipngcommand{\htmlize@setexecutable\optipng}% +\def\PDFtoSVGcommand{\htmlize@setexecutable\PDFtoSVG}% +\def\SVGtoPDFcommand{\htmlize@setexecutable\SVGtoPDF}% +\def\optiSVGcommand{\htmlize@setexecutable\optiSVG}% +\def\DeleteFilecommand{\htmlize@setexecutable\DeleteFiles}% \ifwindows% - \ghostscriptcommand{gswin64c.exe}% + \ghostscriptcommand{gswin64c.exe -dBATCH -dNOPAUSE -sDEVICE=pngalpha}% + \baselxivcommand{certutil}% + \DeleteFilecommand{del}% \else% - \ghostscriptcommand{gs}% + \ghostscriptcommand{gs -dBATCH -dNOPAUSE -sDEVICE=pngalpha}% + \baselxivcommand{base64}% + \DeleteFilecommand{rm -f}% \fi% -\opensslcommand{openssl}% -\imagemagickcommand{convert}% +\imagemagickcommand{convert -colorspace RGB}% +\optipngcommand{optipng -clobber -strip all -quiet}% +\PDFtoSVGcommand{inkscape --export-type=svg --export-area-page --vacuum-defs}%--pdf-poppler +% remove the "--pdf-poppler" import option if you want to preserve text (avoid conversion to path) +\SVGtoPDFcommand{inkscape --export-type=pdf --export-area-page}% +\optiSVGcommand{scour -q --enable-id-stripping --enable-comment-stripping + --shorten-ids --indent=none --remove-descriptive-elements}% % \end{macrocode} % +% \subsubsection{Conversion and inclusion of non-native formats} +% \begin{macrocode} +\AtEndPreamble{% + \@ifpackageloaded{graphicx}{% + \def\@firstofthree#1#2#3{#1}% + \def\@secondofthree#1#2#3{#2}% + \newcommand{\DeclareGraphicsAlien}[3]{% + \edef\Gin@extensions{\Gin@extensions,#1}% + \DeclareGraphicsRule{#1}{\@gobble#1}{#1}{}% + \csdef{Gread@\@gobble#1}##1{% + \edef\SourceFile{\Gin@base\Gin@ext}% + \edef\Gin@base{\Gin@base-\@gobble#1-converted-to}% + \edef\Gin@ext{#2}% + \edef\OutputFile{\Gin@base\Gin@ext}% + \edef\targetfmt{\expandafter\expandafter\expandafter + \@firstofthree\csname Gin@rule@\Gin@ext\endcsname\relax}% + \edef\targetext{\expandafter\expandafter\expandafter + \@secondofthree\csname Gin@rule@\Gin@ext\endcsname\relax}% + \IfFileExists{\OutputFile}{}{\ShellEscape{#3}}% + \csletcs{Ginclude@\@gobble#1}{Ginclude@\targetfmt}% + \csname Gread@\targetfmt\endcsname{\Gin@base\targetext}% + }% + }% +% Support for GIF files: passed as-is in XML but converted in PNG for PDF output. +% In case the GIF is animated, we pick up the first frame in this conversion. +% While the picture will be animated after Moodle import, it will not be in the PDF +% output, whatever the viewer is. + \DeclareGraphicsAlien{.gif}{.png}{\htmlize@imagemagick@convert\otherspace '\SourceFile[0]' \OutputFile}% + }{}% +}% +% \end{macrocode} % \subsubsection{Graphics key-handling} % Next, we get ready to handle keys like |height=4cm| or |width=3cm| or |ppi=72|. % \begin{macrocode} @@ -3110,25 +5413,58 @@ % \end{macrocode} % % \subsubsection{Graphics conversion to HTML} +% If the |tikz| option is loaded, we define the |embedaspict| command. +% Furthermore, |includegraphics| is packed into a TikZ node. +% This allows externalization with regular options for |includegraphics|. +% Otherwise, |includegraphics| is redefined with a limited set of options supported. +% +% Option SVG % \begin{macrocode} -\html@action@def\includegraphics{\moodle@includegraphics@int}% - % Note that \htmlize@do@actioncs will 'patch' this by putting - % '\xa\htmlize@proceedwiththerest\htmlize@afteraction@hook' - % at the end. We want those 3 tokens to occur instead after - % the graphics filename. -\def\moodle@includegraphics@int#1#2#3{\moodle@includegraphics@int@int}% - % This gobbles up those three spurious tokens, - % which we will re-insert after our work is done. -\newcommand\moodle@includegraphics@int@int[2][]{% +\ifmoodle@svg + \AtEndPreamble{% +% Declaring SVG to PDF conversion rule for includegraphics +% \edef\Gin@extensions{\Gin@extensions,.svg,.SVG}% +% \DeclareGraphicsRule{.svg}{pdf}{.pdf}{% +% `\SVGtoPDF\otherspace '#1' \noexpand\Gin@base-svg-converted-to.pdf}% +% \DeclareGraphicsRule{.SVG}{pdf}{.pdf}{% +% `\SVGtoPDF\otherspace '#1' \noexpand\Gin@base-SVG-converted-to.pdf}% + \DeclareGraphicsAlien{.svg}{.pdf}{% + \SVGtoPDF\otherspace '\SourceFile' -o '\OutputFile' 2>/dev/null}% + \DeclareGraphicsAlien{.SVG}{.pdf}{% + \SVGtoPDF\otherspace '\SourceFile' -o '\OutputFile' 2>/dev/null}% + }% +\fi + +\ifmoodle@tikz +\AfterEndPreamble{% + %\htmlize@record@expand{\embedaspict}% + \let\oldincludegraphics=\includegraphics + % patching includegraphics to trigger externalization + \renewcommand{\includegraphics}[2][]{% + %\message{moodle.sty: Processing \string\includegraphics[#1]{#2} for HTML^^J}% + \tikz{\node[inner sep=0pt]{\oldincludegraphics[#1]{#2}};}% + }% + % externalized images must be included with the regular command + \pgfkeys{/pgf/images/include external/.code={\oldincludegraphics{#1}}}% + \html@action@newcommand{includegraphics}[2][]{% + \message{moodle.sty: Processing \string\includegraphics[#1]{#2} ^^J} + \global\advance\numpicturesread by 1\relax + \edef\htmlize@imagetag{<IMG SRC="data:\TikzExportMIME;base64,\csname picbaselxiv@\the\numpicturesread\endcsname">}% + \xa\g@addto@macro\xa\htmlize@output\xa{\htmlize@imagetag}% + }% +}% +\else +\html@action@newcommand{includegraphics}[2][]{% \bgroup% The grouping is to localize the changes caused by \setkeys. \message{moodle.sty: Processing \string\includegraphics[#1]{#2} for HTML...^^J} \setkeys*{moodle@includegraphics}{#1}% % Height or width should be given in TeX dimensions like cm or pt or in, % and are converted to pixels for web use using the ppi key. - % TO DO: Can we modify \includegraphics to accept height or width in + % TODO: Can we modify \includegraphics to accept height or width in % pixels? - % TO DO: What about \includegraphics[scale=0.7] ? + % TODO: What about \includegraphics[scale=0.7] ? % Other keys: keepaspectratio=true|false, angle (rotation), clip & trim + % -> the package option 'tikz' offers a workaround for this \ifnum\moodle@graphics@height@pixels=0\relax \ifnum\moodle@graphics@width@pixels=0\relax % No size specified. Default to height of 200 pixels. @@ -3150,28 +5486,89 @@ \edef\moodle@graphics@htmlgeometry{width=\number\moodle@graphics@width@pixels\otherspace height=\number\moodle@graphics@height@pixels}% \fi \fi - %First, convert it to PNG - \edef\cmdline{\htmlize@imagemagick@convert\otherspace #2 -resize \moodle@graphics@geometry\otherspace #2.png}% - \message{moodle.sty: Converting '#2' to PNG...^^J}% - \expandafter\immediate\expandafter\write18\expandafter{\cmdline}% - %Next, convert the PNG to base64 encoding - \def\cmdline{\openssl\otherspace enc -base64 -in #2.png -out #2.enc}% - \message{moodle.sty: Converting '#2.png' to base64...^^J}% - \expandafter\immediate\expandafter\write18\expandafter{\cmdline}% + %Look for the file, even if no extension is provided + \moodle@media@find{#2}% + %\message{<<\moodle@media@base>>^^J} + %\message{<<\moodle@media@ext>>^^J} + %Try to identify corresponding MIME-type + \moodle@media@mime@identify{\moodle@media@ext}% + \ifx\moodle@media@mime@current\relax + % conversion needed + \edef\moodle@media@pdf{\detokenize{.pdf}}% + \edef\moodle@media@ext{\detokenize\xa{\moodle@media@ext}}% + \ifnum0\ifx\moodle@media@ext\moodle@media@pdf1\fi\ifmoodle@svg1\fi=11% PDF file and SVG option active + \def\moodle@media@ext@current{.svg}% + \edef\moodle@media@mime@current{\moodle@media@SVGmime}% + \edef\cmdline{\PDFtoSVG\otherspace "\moodle@media@base\moodle@media@ext" -o "\moodle@media@base\moodle@media@ext@current" 2>/dev/null}% + \message{moodle.sty: Converting '#2' to SVG...^^J}% + \xa\ShellEscape\xa{\cmdline}% + %Next, optimize inline + \ifwindows\else + \edef\cmdline{\optiSVG < "\moodle@media@base\moodle@media@ext@current" > + "\moodle@media@base.tmp.svg" && mv "\moodle@media@base.tmp.svg" + "\moodle@media@base\moodle@media@ext@current"}% + \message{moodle.sty: Optimizing '\moodle@media@base\moodle@media@ext@current'...^^J}% + \xa\ShellEscape\xa{\cmdline}% + \fi + \else% call ImageMagick + \def\moodle@media@ext@current{.png}% + \def\moodle@media@mime@current{image/png}% + \edef\cmdline{\htmlize@imagemagick@convert\otherspace "\moodle@media@base\moodle@media@ext" -resize \moodle@graphics@geometry\otherspace "\moodle@media@base\moodle@media@ext@current"}% + \message{moodle.sty: Converting '#2' to PNG...^^J}% + \xa\ShellEscape\xa{\cmdline}% + %Next, optimize inline + \edef\cmdline{\optipng\otherspace "\moodle@media@base\moodle@media@ext@current"}% + \message{moodle.sty: Optimizing '\moodle@media@base\moodle@media@ext@current'...^^J}% + \xa\ShellEscape\xa{\cmdline}% + \fi + \fi + %Next, convert the file to base64 encoding + \ConvertToBaseLXIV{\moodle@media@base}{\moodle@media@ext@current}% %Now, save that base64 encoding in a TeX macro \def\moodle@newpic@baselxiv{}% - \message{moodle.sty: Reading base64 file '#2.enc'...^^J}% - \openin\baseLXIVdatafile=#2.enc\relax + \message{moodle.sty: Reading base64 file '\moodle@media@base.enc'...^^J}% + \openin\baseLXIVdatafile="\moodle@media@base.enc" \savebaselxivdata@recursive \closein\baseLXIVdatafile + %Clean up files + \ifx\moodle@media@ext@current\moodle@media@ext + \ShellEscape{\DeleteFiles\otherspace "\moodle@media@base.enc"}% + \else + \ShellEscape{\DeleteFiles\otherspace "\moodle@media@base.enc" "\moodle@media@base\moodle@media@ext@current"}% + \fi \xa\global\xa\let\csname picbaselxiv@graphics@#2\endcsname=\moodle@newpic@baselxiv% - \edef\htmlize@imagetag{<IMG \moodle@graphics@htmlgeometry\otherspace SRC="data:image/png;base64,\csname picbaselxiv@graphics@#2\endcsname">}% + \edef\htmlize@imagetag{<IMG \moodle@graphics@htmlgeometry\otherspace SRC="data:\moodle@media@mime@current;base64,\csname picbaselxiv@graphics@#2\endcsname">}% \xa\g@addto@macro\xa\htmlize@output\xa{\htmlize@imagetag}% \message{moodle.sty: <IMG> tag inserted.^^J}% \egroup - % Now we re-insert the code to get the HTMLizing going again. - \xa\htmlize@proceedwiththerest\htmlize@afteraction@hook -} +}% +\fi +% \end{macrocode} +% This macro is in charge of throwing a system call to convert local files to base64. +% \begin{macrocode} +\ifwindows + \def\ConvertToBaseLXIV#1#2{% + \def\cmdline{\baselxiv\otherspace -encode "#1#2"\otherspace tmp.b64 && findstr /vbc:"---" tmp.b64 > "#1" && del tmp.b64"}% + \message{moodle.sty: Converting '#1#2' to base64...^^J}% + \xa\ShellEscape\xa{\cmdline}% + % Starting from Windows 7, CertUtil is included by default. There should be no windows XP still running + }% +\else + \ifmacosx + \def\ConvertToBaseLXIV#1#2{% + \def\cmdline{\baselxiv\otherspace -b 64 -i "#1#2"\otherspace -o "#1.enc"}% + \message{moodle.sty: Converting '#1#2' to base64...^^J}% + \xa\ShellEscape\xa{\cmdline}% + }% + \else % Linux, Cygwin + \def\ConvertToBaseLXIV#1#2{% + \def\cmdline{\baselxiv\otherspace "#1#2"\otherspace > "#1.enc"}% + \message{moodle.sty: Converting '#1#2' to base64...^^J}% + \xa\ShellEscape\xa{\cmdline}% + }% + % base64 is part of coreutils, add "-w 64" to get exactly the previous behavior % + \fi +\fi % \end{macrocode} % The following code accomplishes the reading of an |.enc| file into memory. % It is also used by the \TikZ\ code below. @@ -3201,32 +5598,57 @@ % are undefined. % Our solution is to wait until |\AtBeginDocument| and then test whether % \TikZ\ is loaded. If so, we make the appropriate definitions. +% \begin{macro}{TikZ} +% \changes{v0.7}{2020/07/14}{Support \emph{tikz}\ command} % \begin{macrocode} -\newif\ifmoodle@tikzloaded -\moodle@tikzloadedfalse \AtBeginDocument{ \ifx\tikzpicture\@undefined \moodle@tikzloadedfalse \else \moodle@tikzloadedtrue \fi + \ifmoodle@draftmode + \long\def\tikzifexternalizing#1#2{#2}% + \else \ifmoodle@tikzloaded - \usetikzlibrary{external} + \usetikzlibrary{external}% \tikzexternalize% \tikzset{external/force remake}% - - \ifpdf - \def\pdftopng{\edef\gscmdline{\gs\otherspace -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=\tikzexternalrealjob-tikztemp-\the\numconvertedpictures.png -r200 \tikzexternalrealjob-tikztemp-\the\numconvertedpictures.pdf}% - \expandafter\immediate\expandafter\write18\expandafter{\gscmdline}}% + \def\moodle@basename{\tikzexternalrealjob-tikztemp-\the\numconvertedpictures}% + \ifmoodle@svg + \def\TikzExportExtension{.svg}% + \def\TikzExportMIME{image/svg+xml}% + \ifpdfoutput% tex engines defaulting to PDF output (pdflatex, xelatex, lualatex) + \def\ExportTikz{ \message{moodle.sty: Converting picture '\moodle@basename.pdf' to SVG...^^J}% + \edef\cmdline{\PDFtoSVG\otherspace "\moodle@basename.pdf" -o "\moodle@basename\TikzExportExtension" 2>/dev/null}% + \xa\ShellEscape\xa{\cmdline}}% + \else % latex + \def\ExportTikz{ \message{moodle.sty: Converting picture '\moodle@basename.ps' to SVG...^^J}% + \edef\cmdline{\PDFtoSVG\otherspace "\moodle@basename.ps" -o "\moodle@basename\TikzExportExtension" 2>/dev/null}% + \xa\ShellEscape\xa{\cmdline}}% + \fi + \def\OptimizeExport{ \message{moodle.sty: Optimizing '\moodle@basename.svg'...^^J}% + \edef\cmdline{\optiSVG\otherspace < "\moodle@basename\TikzExportExtension" > + "\moodle@basename.tmp.svg" && mv "\moodle@basename.tmp.svg" + "\moodle@basename\TikzExportExtension" }% + \xa\ShellEscape\xa{\cmdline}}% \else - \def\pstopng{\edef\gscmdline{\gs\otherspace -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=\tikzexternalrealjob-tikztemp-\the\numconvertedpictures.png -r200 \tikzexternalrealjob-tikztemp-\the\numconvertedpictures.ps}% - \expandafter\immediate\expandafter\write18\expandafter{\gscmdline}}% + \def\TikzExportExtension{.png}% + \def\TikzExportMIME{image/png}% + \ifpdfoutput% tex engines defaulting to PDF output (pdflatex, xelatex, lualatex) + \def\ExportTikz{ \message{moodle.sty: Converting picture '\moodle@basename.pdf' to PNG...^^J}% + \edef\gscmdline{\gs\otherspace -sOutputFile=\moodle@basename\TikzExportExtension\otherspace -r150 \moodle@basename.pdf}% + \xa\ShellEscape\xa{\gscmdline}}% + \else % latex + \def\ExportTikz{ \message{moodle.sty: Converting picture '\moodle@basename.ps' to PNG...^^J}% + \edef\gscmdline{\gs\otherspace -sOutputFile=\moodle@basename\TikzExportExtension\otherspace -r150 \\moodle@basename.ps}% + \xa\ShellEscape\xa{\gscmdline}}% + \fi + \def\OptimizeExport{ \message{moodle.sty: Optimizing '\moodle@basename.png'...^^J}% + \edef\cmdline{\optipng\otherspace \moodle@basename\TikzExportExtension}% + \xa\ShellEscape\xa{\cmdline}}% \fi - \def\pngtobaselxiv{\edef\opensslcmdline{\openssl\otherspace enc -base64 -in \tikzexternalrealjob-tikztemp-\the\numconvertedpictures.png -out \tikzexternalrealjob-tikztemp-\the\numconvertedpictures.enc}% - \expandafter\immediate\expandafter\write18\expandafter{\opensslcmdline}}% - \let\moodle@oldtikzpicture=\tikzpicture - %The following code lets us run things *before* the normal \begin{tikzpicture}. \renewenvironment{tikzpicture}{% \global\advance\numconvertedpictures by 1\relax @@ -3238,43 +5660,63 @@ % However, the tikz externalize library does *not* run \end{tikzpicture}. % In order to run commands after the tikz picture is done compiling, we need to % use a hook into \tikzexternal@closeenvironments. - \g@addto@macro{\tikzexternal@closeenvironments}{% \moodle@endtikzpicture@hook } +% The following could replace calls to \pdftopng, \pngoptim and \pngtobaselxiv +% \tikzset{external/system call/.add={}{; +% gs -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile="\image.png" -r150 "\image.pdf"; +% optipng -clobber -strip all -quiet "\image.png"; +% base64 "\image.png" > "\image.enc" +% } +% } +% With the following mechanism, we could trigger something when the externalized images are included back. +% \pgfkeys{/pgf/images/include external/.code={\pgfimage{#1}\@moodle@ifgeneratexml{\savebaselxivdata}{}}} +% \def\moodle@endtikzpicture@hook{% \@moodle@ifgeneratexml{% - \ifpdf - \message{moodle.sty: Converting picture '\tikzexternalrealjob-tikztemp-\the\numconvertedpictures.pdf' to PNG...^^J}% - \pdftopng - \else - \pstopng - \fi - \message{moodle.sty: Converting '\tikzexternalrealjob-tikztemp-\the\numconvertedpictures.png' to base64...^^J}% - \pngtobaselxiv + \ExportTikz + \OptimizeExport + \ConvertToBaseLXIV{\moodle@basename}{\TikzExportExtension}% \message{moodle.sty: Reading base64 file '\tikzexternalrealjob-tikztemp-\the\numconvertedpictures.enc'...^^J}% \savebaselxivdata \message{moodle.sty: base64 data saved.^^J}% }{}% } - \tikzset{external/optimize=true} - \tikzset{external/optimize command away={\VerbatimInput}{1}} + \ifmoodle@tikz + \tikzset{external/optimize=false}% due to redefinition, includegraphics must not be optimized away + \else + \tikzset{external/optimize=true}% + \tikzset{external/optimize command away={\VerbatimInput}{1}}% + \fi % % The HTMLizer version of the tikzpicture environment, % which writes an <IMG> tag to the XML file. - \htmlize@record@environment{tikzpicture} + \htmlize@record@environment{tikzpicture}% \g@addto@macro\htmlize@activate@environments{% \let\tikzpicture\relax\let\endtikzpicture\relax \NewEnviron{tikzpicture}[1][]{% \global\advance\numpicturesread by 1\relax - \edef\htmlize@imagetag{<IMG SRC="data:image/png;base64,\csname picbaselxiv@\the\numpicturesread\endcsname">}% + \edef\htmlize@imagetag{<IMG SRC="data:\TikzExportMIME;base64,\csname picbaselxiv@\the\numpicturesread\endcsname">}% \xa\g@addto@macro\xa\htmlize@output\xa{\htmlize@imagetag}% }[\htmlize@patchendenvironment]% }% + \html@action@newcommand{tikz}[2][]{% +% \message{>>> Processing \string\tikz[#1]{...} ^^J} + \global\advance\numpicturesread by 1\relax + \edef\htmlize@imagetag{<IMG SRC="data:\TikzExportMIME;base64,\csname picbaselxiv@\the\numpicturesread\endcsname">}% + \xa\g@addto@macro\xa\htmlize@output\xa{\htmlize@imagetag}% + }% \else %TikZ not loaded. Provide dummy definitions for commands. \long\def\tikzifexternalizing#1#2{#2}% \fi + \fi + \ifmoodle@tikz + \tikzstyle{moodlepict}=[minimum height=1em,inner sep=0pt,execute at begin node={\begin{varwidth}{\linewidth}},execute at end node={\end{varwidth}}] + \newcommand\embedaspict[1]{\tikz[baseline=-\the\dimexpr\fontdimen22\textfont2\relax]{\node[moodlepict]{\mbox{#1}};}} + \htmlize@record@expand{\embedaspict} + \fi } \newcount\numconvertedpictures @@ -3290,27 +5732,464 @@ \xa\global\xa\let\csname picbaselxiv@\the\numconvertedpictures\endcsname=\moodle@newpic@baselxiv% } -\def\@moodle@par{\par}% +\ifmoodle@tikz + \ifmoodle@tikzloaded + \PackageWarning{moodle}{With package option 'tikz', you should not load TikZ manually.}% + \fi + \RequirePackage{tikz}% + \RequirePackage{varwidth}% for the command |embedaspict| +\fi % \end{macrocode} % Finally, we clean up our mess by deleting the temporary PDF, PNG, and ENC % files we created. +% With XeTeX, we cannot clean pictures pdf's because they are actually included in the final pdf afterwards, by xdvipdfmx. +% With LuaTeX, it looks like |\AtEndDocument| is too early to for this cleaning step. % \begin{macrocode} -\AtEndDocument{% +\AfterEndDocument{% \ifmoodle@tikzloaded \@moodle@ifgeneratexml{% - \ifwindows - \immediate\write18{del \tikzexternalrealjob-tikztemp-*.*}% + \ifXeTeX + % we must keep picture pdf's for subsequent linking (xdvipdfmx) + \ifwindows + \ShellEscape{powershell.exe -noexit "del * -include \tikzexternalrealjob-tikztemp-*.* -exclude *.pdf}% + \else + \ShellEscape{find . -type f -name "\tikzexternalrealjob-tikztemp-*.*" -not -name "*.pdf" -delete}% + \fi \else - \immediate\write18{rm \tikzexternalrealjob-tikztemp-*.*}% + \ShellEscape{\DeleteFiles\otherspace \tikzexternalrealjob-tikztemp-*.*}% \fi }{}% \fi } - -% TO DO: +% \end{macrocode} +% TODO: % * sizing options for TikZ pictures? -% * In cloze multi, how to handle HTML or TeX in answers? In particular, what about ~? +%\end{macro} +% +% \subsection{Other Media} +% Support for other media comes through the |\url|\marg{link} and |\href|\marg{link}\marg{text} +% commands. +\AtEndPreamble{% + \@ifpackageloaded{hyperref}{% + \let\oldhref\href + \let\oldurl\url + \def\moodle@hyper@readexternallink#1#2#3#4:#5:#6\\#7{% +% 1) The link type (the string "link" in the cases I observed) +% 2) The URL fragment (i.e. what comes after # in the end), +% 3) the text replacement, +% 4) the URL scheme (http, https, mailto, file, run etc), +% 5) the URL details (in general, that is whole authority + path + query). +% If the URL contains a column (specification of a password in userinfo or a +% port in authority), we get here whatever comes before the first column (:) +% 6) empty is URL contains no column. Otherwise, filled with whatever follows +% a first column (:) after the scheme, +% 7) the whole URL again (fragment removed). + \def\filename@ext{}% + \def\filename@area{}% + \def\filename@base{}% + \ifx\\#6\\% if ##6 is empty (the URL contains no column -> no scheme -> local) + %\@hyper@linkfile file:#7\\{#3}{#2}{#7}% local file + %Local file (##1|##2|##3|##4|##5|##6): ##7\par + \filename@parse{#4}% + \ConvertToBaseLXIV{\filename@area\filename@base}{.\filename@ext}% + \else + \ifx\\#4\\%if ##4 is empty (no scheme was specified -> local file) +% %\@hyper@linkfile file:#7\\{#3}{#2}{#7}% Mac filename ? +% Local file (Mac? ##1|##2|##3|##4|##5|##6): ##7\par + \filename@parse{#4}% + \ConvertToBaseLXIV{\filename@area\filename@base}{.\filename@ext}% + \else + \def\@pdftempa{#4}% + \ifx\@pdftempa\@pdftempwordfile% scheme is "file:" +% %\@hyper@linkfile#7\\{#3}{#2}{#7}% file +% Local file (no column ##1|##2|##3|##4|##5|##6): ##7\par + \filename@parse{#5}% + \ConvertToBaseLXIV{\filename@area\filename@base}{.\filename@ext}% + \else + \ifx\@pdftempa\@pdftempwordrun% scheme is "run:" + \ifHy@pdfa + \Hy@Error{% + PDF/A: Launch action is prohibited% + }\@ehc + \begingroup + \leavevmode +% ##2% + \endgroup + \else% not in PDF/A mode -> run is allowed + %\@hyper@launch#7\\{#3}{#2}% run local file +% Run local file (##1|##2|##3|##4|##5|##6): ##7\par + \filename@parse{#5}% + \ConvertToBaseLXIV{\filename@area\filename@base}{.\filename@ext}% + \fi + \else% scheme is neither "file" nor "run", assuming it is a web protocol + %\hyper@linkurl{#3}{#7\ifx\\#2\\\else\hyper@hash#2\fi}% URL +% URL (##1|##2|##3|##4|##5|##6): ##7\par + \filename@parse{#7}% + \fi + \fi + \fi + \fi + \xdef\moodle@media@ext{.\filename@ext}% + \xdef\moodle@media@base{\filename@area\filename@base}% + }% +% \html@action@newcommand{href}[3][]{% +% \bgroup% The grouping is to localize the changes caused by \setkeys. +% \message{moodle.sty: Processing \string\href[#1]{#2}{#3} for HTML...^^J}% +% the following macro is a modified version of hyperref's |\hyper@readexternallink| +% \let\@hyper@readexternallink\moodle@hyper@readexternallink +% \oldhref[#1]{#2}{#3}% + %\message{<<\moodle@media@base>>^^J} + %\message{<<\moodle@media@ext>>^^J} + %Try to identify corresponding MIME-type +% \moodle@media@mime@identify{\moodle@media@ext}% + %\edef\moodle@media@mime@current{\detokenize\xa{\moodle@media@mime@current}}% +% \xa\message\xa{moodle.sty: \moodle@media@mime@current^^J}% +% \ifx\moodle@media@mime@current\relax +% \xa\g@addto@macro\xa\htmlize@output\xa{<A href=\otherampersand\otherhash34;\moodle@media@base\moodle@media@ext\otherampersand\otherhash34;>#3</A>}% +% \message{moodle.sty: <A> tag inserted.^^J}% +% \else +% \filename@parse{\moodle@media@mime@current}% +% \def\@tmp{audio/} +% \ifx\filename@area\@tmp +% \IfFileExists{\moodle@media@base.enc}{% +% \def\moodle@newpic@baselxiv{}% +% \openin\baseLXIVdatafile=\moodle@media@base.enc\relax +% \savebaselxivdata@recursive +% \closein\baseLXIVdatafile +% \xa\g@addto@macro\xa\htmlize@output\xa{<audio controls src="data:\moodle@media@mime@current;base64,\moodle@newpic@baselxiv">#3</audio>}% +% }{% +% \xa\g@addto@macro\xa\htmlize@output\xa{<audio controls src="\moodle@media@base\moodle@media@ext">#3</audio>}% +% }% +% \message{moodle.sty: <audio> tag inserted.^^J}% +% \else +% \def\@tmp{video/} +% \ifx\filename@area\@tmp +% \IfFileExists{\moodle@media@base.enc}{% +% \def\moodle@newpic@baselxiv{}% +% \openin\baseLXIVdatafile=\moodle@media@base.enc\relax +% \savebaselxivdata@recursive +% \closein\baseLXIVdatafile +% \xa\g@addto@macro\xa\htmlize@output\xa{<video controls src="data:\moodle@media@mime@current;base64,\moodle@newpic@baselxiv">#3</video>}% +% }{% +% \xa\g@addto@macro\xa\htmlize@output\xa{<video controls src="\moodle@media@base\moodle@media@ext">#3</video>}% +% }% +% \message{moodle.sty: <video> tag inserted.^^J}% +% \else +% \PackageWarning{moodle}{cannot recognize MIME type of #2. Ignoring it.}% +% \fi +% \fi +% \fi +% \egroup +% }% +% \html@action@def\url#1{% +% \bgroup% The grouping is to localize the changes caused by \setkeys. +% \message{moodle.sty: Processing \string\url{#1} for HTML...^^J}% +% the following macro is a modified version of hyperref's |\hyper@readexternallink| +% \let\@hyper@readexternallink\moodle@hyper@readexternallink +% \oldhref{#1}{#1}% +% \xa\g@addto@macro\xa\htmlize@output\xa{<A href=\otherampersand\otherhash34;\moodle@media@base\moodle@media@ext\otherampersand\otherhash34;>#1</A>}% +% \message{moodle.sty: <A> tag inserted.^^J}% +% \egroup +% }% + }{}% +}% +% +% \subsection{Verbatim Code} +% +% We start by defining a macro to parameter a style for code box display in Moodle +% \begin{macrocode} +\def\xmlDisplayVerbatimBox{border-top: thin solid; border-bottom: thin solid}% +% \end{macrocode} +% First, let us handle |\verbatiminput| from the `verbatim' package +% \begin{macrocode} +\html@action@def\verbatiminput#1{% + \message{moodle.sty: Processing \string\verbatiminput{#1} for HTML ^^J}% + \g@addto@macro\htmlize@output{<PRE style="\xmlDisplayVerbatimBox"><CODE>}% + %%%%%%%%%%%%%% from verbatim %%%%%%%%%%%%%%%%% + \@bsphack + \let\do\@makeother\dospecials + \catcode`\^^M\active + \def\verbatim@processline{\xa\g@addto@macro\xa\htmlize@output\xa{\the\verbatim@line<BR/>}} + \verbatim@readfile{#1}% + \@esphack + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \g@addto@macro\htmlize@output{</CODE></PRE>}% +}% +% \end{macrocode} +% Second, we deal with |\VerbatimInput| from `fancyvrb' or `fvextra' +% \begin{macrocode} +\@ifpackageloaded{minted}{\PackageError{moodle}{'moodle' should be loaded before 'minted'.}% +{'moodle' loads 'fancybox' which, unfortunately, redefines verbatim commands.}}{\relax}% +\@ifpackageloaded{fvextra}{\PackageError{moodle}{'moodle' should be loaded before 'fvextra'.}% +{'moodle' loads 'fancybox' which, unfortunately, redefines verbatim commands.}}{\relax}% +\@ifpackageloaded{fancyvrb}{\PackageError{moodle}{'moodle' should be loaded before 'fancyvrb'.}% +{'moodle' loads 'fancybox' which, unfortunately, redefines verbatim commands.}}{\relax}% + +\html@action@newcommand{VerbatimInput}[2][]{% + \message{moodle.sty: Processing \string\VerbatimInput[#1]{#2} for HTML ^^J}% + \def\FV@KeyValues{#1}% + \FV@UseKeyValues% import options defined in #1 + \moodle@VerbatimInput{#2}% +}% +\html@action@newcommand{LVerbatimInput}[2][]{% + \message{moodle.sty: Processing \string\LVerbatimInput[#1]{#2} for HTML ^^J}% + \def\FV@KeyValues{#1}% + \FV@UseKeyValues% import options defined in #1 + \moodle@VerbatimInput{#2}% +}% +\html@action@newcommand{BVerbatimInput}[2][]{% + \message{moodle.sty: Processing \string\BVerbatimInput[#1]{#2} for HTML ^^J}% + \def\FV@KeyValues{#1}% + \FV@UseKeyValues% import options defined in #1 + \moodle@VerbatimInput{#2}% +}% +\def\moodle@VerbatimInput#1{% + \g@addto@macro\htmlize@output{<PRE style="\xmlDisplayVerbatimBox"><CODE>}% + %%%%%%%% using material from fancyvrb and fvextra %%%%%%%% + %\begingroup + \def\moodle@verbatim@addlinenumber##1{% + \g@addto@macro\htmlize@output{<span style="font-size: 80\otherpercent; + background-color: \otherhash f0f0f0; padding: 0 5px 0 5px; display: + inline-block; width: 16pt; ##1">}% + \if@FV@NumberBlankLines + \xa\g@addto@macro\xa\htmlize@output\xa{\the\c@FancyVerbLine</span>}% + \else + \ifx\FV@Line\empty + \xa\g@addto@macro\xa\htmlize@output\xa{\otherampersand nbsp;</span>}% + \else + \xa\g@addto@macro\xa\htmlize@output\xa{\the\c@FancyVerbLine</span>}% + \fi + \fi + } + % redefine the ProcessLine routine ('fancyvrb' and 'fvextra') for XML output + \def\FV@ProcessLine##1{% + \ifcsname FV@HighlightLine:\number\c@FancyVerbLine\endcsname + \xdef\moodle@FV@tagB{<mark>}% fvextra triggered highlighting for this line + \xdef\moodle@FV@tagE{</mark>}% + \else + \xdef\moodle@FV@tagB{}% no highlighting + \xdef\moodle@FV@tagE{}% + \fi + \catcode`\`=12% + \def\FV@Line{##1}% + \ifx\FV@LeftListNumber\relax + + \else% line numbers displayed on the left side + \moodle@verbatim@addlinenumber{text-align: right}% + \fi + \xa\g@addto@macro\xa\htmlize@output\xa{\moodle@FV@tagB}% + \xa\g@addto@macro\xa\htmlize@output\xa{\FV@Line}% + \xa\g@addto@macro\xa\htmlize@output\xa{\moodle@FV@tagE}% + \ifx\FV@RightListNumber\relax\else% line numbers on the right side + \moodle@verbatim@addlinenumber{text-align: left; float: right}% + \fi + \g@addto@macro\htmlize@output{<BR/>}%linebreak + } + \global\FV@CodeLineNo\z@% reset codeline counter + \frenchspacing% Cancels special punctuation spacing. + \FV@DefineWhiteSpace + \def\FV@Space{\space} + \FV@DefineTabOut% replace tabs with a series a whitespaces + \ifdefined\FV@HighlightLinesPrep + \FV@HighlightLinesPrep% prepare highlighting if 'fvextra' is loaded + \fi + \FV@Input{#1}% + %\endgroup + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \g@addto@macro\htmlize@output{</CODE></PRE>}% +}% +\AtEndPreamble{% + \@ifpackageloaded{fancyvrb}{% + % custom settings for display + \fvset{frame=lines,label={[Beginning of code]End of code},framesep=3mm,numbersep=9pt}% + }{\relax}% +} +% \end{macrocode} +% Third, we patch `minted' so that it also calls pygmentize to generate HTML code. +% \begin{macrocode} +\AtEndPreamble{% this definition should prevail because `minted' gets loaded after `moodle' +\@ifpackageloaded{minted}{% + \newcounter{moodle@pygmentizecounter}% + \renewcommand{\minted@pygmentize}[2][\minted@outputdir\minted@jobname.pyg]{% + \minted@checkstyle{\minted@get@opt{style}{default}}% + \stepcounter{minted@pygmentizecounter}% + \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}% + {\def\minted@codefile{\minted@outputdir\minted@jobname.pyg}}% + {\def\minted@codefile{#1}}% + \ifthenelse{\boolean{minted@isinline}}% + {\def\minted@optlistcl@inlines{% + \minted@optlistcl@g@i + \csname minted@optlistcl@lang\minted@lang @i\endcsname}}% + {\let\minted@optlistcl@inlines\@empty}% + \def\minted@cmdtemplate##1##2{% + \ifminted@kpsewhich + \ifwindows + \detokenize{for /f "usebackq tokens=*"}\space\@percentchar\detokenize{a + in (`kpsewhich}\space\minted@codefile\detokenize{`) do}\space + \fi + \fi + \MintedPygmentize\space -l #2 -f ##1 -F tokenmerge + \minted@optlistcl@g \csname minted@optlistcl@lang\minted@lang\endcsname + \minted@optlistcl@inlines + \minted@optlistcl@cmd -o \minted@outputdir##2\space + \ifminted@kpsewhich + \ifwindows + \@percentchar\detokenize{a}% + \else + \detokenize{`}kpsewhich \minted@codefile\space + \detokenize{||} \minted@codefile\detokenize{`}% + \fi + \else + \minted@codefile + \fi}% + \def\minted@cmd{\minted@cmdtemplate{latex -P commandprefix=PYG}{\minted@infile}} + % For debugging, uncomment: %%%% + \immediate\typeout{\minted@cmd}% + % %%%% + \def\minted@cmdHTML{\minted@cmdtemplate{html -P noclasses -P + nowrap -P hl_lines="\FV@HighlightLinesList" -P + style="\minted@get@opt{style}{default}"}{\csname minted@infileHTML\the\c@minted@pygmentizecounter\endcsname}}% + \def\minted@cmdPNG{\minted@cmdtemplate{png -P + line_numbers=True}{\minted@infilePNG}}% + \def\minted@cmdSVG{\minted@cmdtemplate{svg -P + linenos=True}{\minted@infileSVG}}% + \ifthenelse{\boolean{minted@cache}}% + {% + \ifminted@frozencache + \else + \ifx\XeTeXinterchartoks\minted@undefined + \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}% + {\edef\minted@hash{\pdf@filemdfivesum{#1}% + \pdf@mdfivesum{\minted@cmd autogobble(\ifx\FancyVerbStartNum\z@ + 0\else\FancyVerbStartNum\fi-\ifx\FancyVerbStopNum\z@ + 0\else\FancyVerbStopNum\fi)}}}% + {\edef\minted@hash{\pdf@filemdfivesum{#1}% + \pdf@mdfivesum{\minted@cmd}}}% + \else + \ifx\mdfivesum\minted@undefined + \immediate\openout\minted@code\minted@jobname.mintedcmd\relax + \immediate\write\minted@code{\minted@cmd}% + \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}% + {\immediate\write\minted@code{autogobble(\ifx\FancyVerbStartNum\z@ + 0\else\FancyVerbStartNum\fi-\ifx\FancyVerbStopNum\z@ + 0\else\FancyVerbStopNum\fi)}}{}% + \immediate\closeout\minted@code + \edef\minted@argone@esc{#1}% + \StrSubstitute{\minted@argone@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted@argone@esc]% + \StrSubstitute{\minted@argone@esc}{"}{\@backslashchar"}[\minted@argone@esc]% + \edef\minted@tmpfname@esc{\minted@outputdir\minted@jobname}% + \StrSubstitute{\minted@tmpfname@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted@tmpfname@esc]% + \StrSubstitute{\minted@tmpfname@esc}{"}{\@backslashchar"}[\minted@tmpfname@esc]% + %Cheating a little here by using ASCII codes to write `{` and `}` + %in the Python code + \def\minted@hashcmd{% + \detokenize{python -c "import hashlib; import os; + hasher = hashlib.sha1(); + f = + open(os.path.expanduser(os.path.expandvars(\"}\minted@tmpfname@esc.mintedcmd\detokenize{\")), + \"rb\"); + hasher.update(f.read()); + f.close(); + f = + open(os.path.expanduser(os.path.expandvars(\"}\minted@argone@esc\detokenize{\")), + \"rb\"); + hasher.update(f.read()); + f.close(); + f = + open(os.path.expanduser(os.path.expandvars(\"}\minted@tmpfname@esc.mintedmd5\detokenize{\")), + \"w\"); + macro = \"\\edef\\minted@hash\" + chr(123) + hasher.hexdigest() + + chr(125) + \"\"; + f.write(\"\\makeatletter\" + macro + + \"\\makeatother\\endinput\n\"); + f.close();"}}% + \ShellEscape{\minted@hashcmd}% + \minted@input{\minted@outputdir\minted@jobname.mintedmd5}% + \else + \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}% + {\edef\minted@hash{\mdfivesum file {#1}% + \mdfivesum{\minted@cmd autogobble(\ifx\FancyVerbStartNum\z@ + 0\else\FancyVerbStartNum\fi-\ifx\FancyVerbStopNum\z@ + 0\else\FancyVerbStopNum\fi)}}}% + {\edef\minted@hash{\mdfivesum file {#1}% + \mdfivesum{\minted@cmd}}}% + \fi + \fi + \edef\minted@infile{\minted@cachedir/\minted@hash.pygtex}% + \edef\minted@temp@infileHTML{\minted@cachedir/\minted@hash.html}% + \global\cslet{minted@infileHTML\the\c@minted@pygmentizecounter}{\minted@temp@infileHTML}% + %\global\edef\minted@infilePNG{\minted@cachedir/\minted@hash.png}% + %\global\edef\minted@infileSVG{\minted@cachedir/\minted@hash.svg}% + \IfFileExists{\minted@infile}{}{% + \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}{% + \minted@autogobble{#1}}{}% + \ShellEscape{\minted@cmd}% + \ShellEscape{\minted@cmdHTML}% + %\ShellEscape{\minted@cmdPNG}% + %\ShellEscape{\minted@cmdSVG}% + }% + \fi + \ifthenelse{\boolean{minted@finalizecache}}% + {% + \edef\minted@cachefilename{listing\arabic{minted@pygmentizecounter}.pygtex}% + \edef\minted@actualinfile{\minted@cachedir/\minted@cachefilename}% + \ifwindows + \StrSubstitute{\minted@infile}{/}{\@backslashchar}[\minted@infile@windows] + \StrSubstitute{\minted@actualinfile}{/}{\@backslashchar}[\minted@actualinfile@windows] + \ShellEscape{move /y + \minted@outputdir\minted@infile@windows\space\minted@outputdir\minted@actualinfile@windows}% + \else + \ShellEscape{mv -f + \minted@outputdir\minted@infile\space\minted@outputdir\minted@actualinfile}% + \fi + \let\minted@infile\minted@actualinfile + \expandafter\minted@addcachefile\expandafter{\minted@cachefilename}% + }% + {\ifthenelse{\boolean{minted@frozencache}}% + {% + \edef\minted@cachefilename{listing\arabic{minted@pygmentizecounter}.pygtex}% + \edef\minted@infile{\minted@cachedir/\minted@cachefilename}% + \expandafter\minted@addcachefile\expandafter{\minted@cachefilename}}% + {\expandafter\minted@addcachefile\expandafter{\minted@hash.pygtex}}% + }% + \minted@inputpyg}% + {% + \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}{% + \minted@autogobble{#1}}{}% + \ShellEscape{\minted@cmd}% + \ShellEscape{\minted@cmdHTML}% + %\ShellEscape{\minted@cmdPNG}% + %\ShellEscape{\minted@cmdSVG}% + \minted@inputpyg}% + }% +}{}% +}% +\html@action@newcommand{inputminted}[3][]{% + \message{moodle.sty: Processing \string\inputminted[#1]{#2}{#3} for HTML ^^J}% + % arguments #2 and #3 are thrown away: the job is done previously by minted when + % calling pygmentize. The file |\minted@infileHTML| generated with our hack will be used. + % Since minted is based upon `fvextra' the macro |\moodle@VerbatimInput| works here. + \minted@configlang{#2}% grab options set for this specific language + \setkeys{minted@opt@cmd}{#1}% grab options in #1 + \minted@fvset% import options + \stepcounter{moodle@pygmentizecounter} + \xa\moodle@VerbatimInput\xa{\csname minted@infileHTML\the\c@moodle@pygmentizecounter\endcsname}% +}% % \end{macrocode} % +% \subsection{Warning users of \texttt{babel}} +% Users of the |babel| package loaded with the 'french' option may experience problems +% related to autospacing when using |pdfLaTeX|. We shall warn them. +% \begin{macrocode} +\AtBeginDocument{% + \ifPDFTeX % pdflatex or latex + \@ifpackagewith{babel}{french}{% + \PackageWarning{moodle}{Be careful when using LaTeX, moodle, and the babel package with option 'french'. Autospacing produces in undesired symbols in the XML. You can either 1) compile with xelatex/lualatex or 2) add '\NoAutoSpacing' after '\begin{quiz}'.}% + }{\relax}% + \fi +}% +% \end{macrocode} +% +% % \Finale \endinput diff --git a/macros/latex/contrib/moodle/moodle.ins b/macros/latex/contrib/moodle/moodle.ins index 16afd4503b..b118c1beab 100644 --- a/macros/latex/contrib/moodle/moodle.ins +++ b/macros/latex/contrib/moodle/moodle.ins @@ -1,5 +1,6 @@ %% moodle.ins -%% Copyright 2016 by Anders O.F. Hendrickson +%% Copyright 2016 by Anders O.F. Hendrickson and 2019-2021 +%% by Matthieu Guerquin-Kern. %% %% This work may be distributed and/or modified under the %% conditions of the LaTeX Project Public License, either version 1.3 @@ -11,7 +12,7 @@ %% %% This work has the LPPL maintenance status `maintained'. %% -%% The Current Maintainer of this work is Anders O.F. Hendrickson. +%% The Current Maintainer of this work is Matthieu Guerquin-Kern. %% %% This work consists of the files moodle.dtx and moodle.ins %% and the derived file moodle.sty. @@ -25,7 +26,8 @@ This is a generated file. -Copyright (C) 2016 by Anders Hendrickson <anders.hendrickson@snc.edu> +Copyright 2016 by Anders O.F. Hendrickson (anders.o.f.hendrickson AT gmail.com) +and 2019-2021 by Matthieu Guerquin-Kern (guerquin-kern AT crans.org). This work may be distributed and/or modified under the conditions of the LaTeX Project Public License, either version 1.3 diff --git a/macros/latex/contrib/moodle/moodle.pdf b/macros/latex/contrib/moodle/moodle.pdf Binary files differindex f5dd6cae3c..1c047103cd 100644 --- a/macros/latex/contrib/moodle/moodle.pdf +++ b/macros/latex/contrib/moodle/moodle.pdf |