% \iffalse meta-comment
%
% Transformed from classpack.xml by ClassPack db2dtx.xsl
% version 1.28 (2024-02-21) on Monday 4 March 2024 at 22:35:19
%
% classpack.dtx is copyright © 2009-2024 by Peter Flynn <peter@silmaril.ie>
%
% 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 has the LPPL maintenance status ‘maintained’.
% 
% The current maintainer of this work is Peter Flynn <peter@silmaril.ie>
%
% This work consists of the files classpack.dtx and classpack.ins,
% the derived files classpack.sty, doctexbook.dtd, db2dtx.xsl, db2bibtex.xsl, figtab2latex.xsl, db2md.xsl, classpack.make, decommentbbl.awk, chunk.sh, chunk.awk, 
% and any other ancillary files listed in the MANIFEST.
%
% \fi
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[2015/01/01]
%<package>\ProvidesPackage{classpack}[2024/02/21 v1.28
%<package>  Package code for supporting ClassPack documentation]
%<*driver>
\RequirePackage{fix-cm}% because "" :: "attributes"
\PassOptionsToPackage{svgnames}{xcolor}% because dependencies dox hypdoc hyperref classpack requires svgnames
\PassOptionsToPackage{noprint}{dox}% because requests  requires 
\PassOptionsToPackage{obeyspaces,spaces}{url}% because requests  requires 
\providecommand{\CPKdocname}{classpack}
\providecommand{\CPKdoctype}{package}
\PassOptionsToPackage{british}{babel}% use of other (non-en-IE) languages
\documentclass[11pt]{ltxdoc}
%%
%% Packages for documentation
%%
\usepackage{dox}%
  \newcommand{\LabelFont}[2][\relax]{\strut
            {\fontencoding\encodingdefault
             \fontfamily{lmtt}\fontseries{lc}#1\selectfont#2}}
  \let\CPKmacro\macro\let\CPKendmacro\endmacro
  \let\CPKenvironment\environment\let\CPKendenvironment\endenvironment
  \doxitem[idxtype=attribute]{Attribute}{CPKattribute}{attributes}
  \def\PrintAttributeName#1{\LabelFont{@#1}}
  \doxitem[idxtype=attvalue]{AttValue}{CPKattributevalue}{attribute values}
  \def\PrintAttributeValueName#1{\LabelFont{@#1}}
  \doxitem[idxtype=class]{Class}{CPKclass}{classs}
  \def\PrintClassName#1{\LabelFont[\fontfamily{lmss}]{#1}}
  \doxitem[idxtype=comment]{Comment}{CPKcomment}{comments}
  \def\PrintCommentName#1{\LabelFont[\color{LightGrey}]{#1}}
  \doxitem[idxtype=counter]{Counter}{CPKcounter}{counters}
  \def\PrintCounterName#1{\LabelFont{#1}}
  \doxitem[idxtype=DTD]{DTD}{CPKdtd}{DTDs/Schemas}
  \def\PrintDTDName#1{\LabelFont{#1}}
  \doxitem[idxtype=element]{Element}{CPKelement}{element types}
  \def\PrintElementName#1{\LabelFont{<#1>}}
  \doxitem[idxtype=entity]{Entity}{CPKentity}{entities}
  \def\PrintEntityName#1{\LabelFont{\&#1;}}
  \doxitem[idxtype=file]{File}{CPKfile}{files}
  \def\PrintFileName#1{\LabelFont{#1}}
  \doxitem[idxtype=function]{Function}{CPKfunction}{functions}
  \def\PrintFunctionName#1{\LabelFont[\bfseries\itshape]{#1}}
  \doxitem[idxtype=length]{Length}{CPKlength}{lengths}
  \def\PrintLengthName#1{\LabelFont{#1}}
  \doxitem[idxtype=option]{Option}{CPKoption}{options}
  \def\PrintOptionName#1{\LabelFont{#1}}
  \doxitem[idxtype=package]{Package}{CPKpackage}{packages}
  \def\PrintPackageName#1{\LabelFont{#1}}
  \doxitem[idxtype=parameter]{Parameter}{CPKparameter}{parameters}
  \def\PrintParameterName#1{\LabelFont{#1}}
  \doxitem[idxtype=setting]{Setting}{CPKsetting}{settings}
  \def\PrintSettingName#1{\LabelFont{#1}}
  \doxitem[idxtype=template]{Template}{CPKtemplate}{templates}
  \def\PrintTemplateName#1{\LabelFont{#1}}
  \doxitem[idxtype=variable]{Variable}{CPKvariable}{variables}
  \def\PrintVariableName#1{\LabelFont{#1}}
\usepackage{fix-cm}%
\usepackage{fontspec}%
  \makeatletter
  \newcommand{\printexternalcurrentfont}{%
  \expandafter\format@externalcurrentfont\fontname\font:\@nil}%
  \def\format@externalcurrentfont[#1]:#2\@nil{%
  \texttt{\@ifnextchar"{\@gobble}{}#1}%
}%	  
  \makeatother
%% fontenc (1.006) omitted in favour of fontspec
%% inputenc (1.007) omitted in favour of fontspec
%% inputenc (1.009) omitted in favour of fontspec
\usepackage{noto}%
\usepackage{bbding}%
\usepackage{mflogo}%
\usepackage[british]{babel}%
\usepackage[backend=biber,doi=true,
  isbn=true,url=true,uniquename=false,style=apa]{biblatex}%
  \makeatletter
  \AtBeginDocument{%
	    \setlength{\bibitemsep}{1ex}%
	    \setlength{\bibnamesep}{1.5\itemsep}%
	    \defbibheading{shortbib}[References]%
	      {\section{#1}\parindent0pt}}
	  \@ifpackagewith{babel}{british}{%
	    \DeclareLanguageMapping{british}%
	      {british-apa}}{\relax}
  \makeatother
  \makeatletter
  \providetoggle{blx@skipbiblist}
  \makeatother
\usepackage{csquotes}%
\usepackage{array}%
\usepackage{calc}%
  \makeatletter
  {\scriptsize
	    \global\advance\@totalleftmargin by1em
	    \global\advance\MacroIndent by.5em}
  \makeatother
\usepackage{ccaption}%
  \captionnamefont{\bfseries}
  \captionstyle{\raggedright}
\usepackage[inline]{enumitem}%
  \setlist[description]{style=unboxed,font=\sffamily\bfseries}
  \setlist[itemize]{leftmargin=2em}
  \setlist[enumerate]{leftmargin=2em}
\usepackage{fancybox}%
\usepackage{fancyvrb}%
\usepackage{relsize}%
\usepackage{textcase}%
\usepackage{float}%
  \renewcommand{\topfraction}{.85}
  \renewcommand{\bottomfraction}{.7}
  \renewcommand{\textfraction}{.15}
  \renewcommand{\floatpagefraction}{.66}
  \renewcommand{\dbltopfraction}{.66}
  \renewcommand{\dblfloatpagefraction}{.66}
  \setcounter{topnumber}{9}
  \setcounter{bottomnumber}{9}
  \setcounter{totalnumber}{20}
  \setcounter{dbltopnumber}{9}
\usepackage[level]{fmtcount}%
\usepackage[a4paper,left=35mm,top=25mm,
  textwidth=150mm,textheight=229mm,headheight=15pt]{geometry}%
\usepackage{fancyhdr}%
  \renewcommand{\MakeUppercase}{\relax}
  \pagestyle{fancy}
  \fancyhead[L]{\sffamily\footnotesize\rightmark}
  \fancyhead[R]{\sffamily\footnotesize\thepage}
  \fancyfoot[C]{}
  \fancyfoot[L]{\sffamily\footnotesize\leftmark}
  \fancyfoot[R]{\sffamily\footnotesize The \LaTeX\
    \textrm{\CPKdocname} \CPKdoctype}
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
\usepackage{graphicx}%
\usepackage{listings}%
  \lstset{defaultdialect=LaTeXe,frame=single,
	    framesep=.5em,backgroundcolor=\color{AliceBlue},
	    rulecolor=\color{LightSteelBlue},framerule=1pt}
	  
  \lstnewenvironment{listingsdoc}
	    {\lstset{language={[LaTeX]TeX}}}
	    {}
  \newcommand\basicdefault[1]{\footnotesize
	    \color{Black}\ttfamily#1}
	  
  \lstset{basicstyle=\basicdefault{\spaceskip.5em}}
  \lstset{literate=
	    {§}{{\S}}1
	    {©}{{\raisebox{.125ex}{\copyright}\enspace}}1
	    {«}{{\guillemotleft}}1
	    {»}{{\guillemotright}}1
	    {Á}{{\'A}}1
	    {Ä}{{\"A}}1
	    {É}{{\'E}}1
	    {Í}{{\'I}}1
	    {Ó}{{\'O}}1
	    {Ö}{{\"O}}1
	    {Ú}{{\'U}}1
	    {Ü}{{\"U}}1
	    {ß}{{\ss}}2
	    {à}{{\`a}}1
	    {á}{{\'a}}1
	    {ä}{{\"a}}1
	    {é}{{\'e}}1
	    {í}{{\'i}}1
	    {ó}{{\'o}}1
	    {ö}{{\"o}}1
	    {ú}{{\'u}}1
	    {ü}{{\"u}}1
	    {¹}{{\textsuperscript1}}1
            {²}{{\textsuperscript2}}1
            {³}{{\textsuperscript3}}1
	    {ı}{{\i}}1
	    {—}{{---}}1
	    {’}{{'}}1
	    {…}{{\dots}}1
	    {➝}{{$leftarrow$}}1
            {⮠}{{$\hookleftarrow$}}1
	    {␣}{{\textvisiblespace}}1,
	    keywordstyle=\color{DarkCyan}\bfseries,
	    identifierstyle=\color{DarkRed},
	    commentstyle=\color{Gray}\upshape,
	    stringstyle=\color{DarkBlue}\upshape,
	    emphstyle=\color{DarkGreen}\upshape,
	    showstringspaces=false,
	    columns=fullflexible,
	    keepspaces=true}
  \lstdefinelanguage{LaTeXe}[LaTeX]{TeX}{%
	    morekeywords = {selectlanguage,foreignlanguage,
	    textbrokenbar,textlangle,textrangle,subsection,url,
	    chapter,tableofcontents,part,subsubsection,paragraph,
	    subparagraph,maketitle,setlength,listoffigures,
	    listoftables,color,arraybackslash,includegraphics,
	    textcite,parencite,graphicspath,lstinline,doxitem,
	    DeclareLanguageMapping,textcolor,definecolor,colorbox,
	    fcolorbox,RequirePackage,PassOptionsToPackage}%
	    }
  \lstdefinelanguage{XPath}{morekeywords={ordinal}}
  \lstdefinelanguage{bash}{%
	    morestring=[s]{[]},morekeywords={exit,logout,yes,no,@,
	    password,ssh,URL,cd,dvips,latex,ls,makeindex,man,mkdir,
	    pdflatex,sudo,texconfig,texdoc,updmap,xelatex,biber,
	    latexmk,bibtex}%
	    }
  \lstdefinelanguage{Makefile}{%
	    otherkeywords={.PHONY,.DEFAULT},%
	    morekeywords={PHONY,DEFAULT,shell,ifeq,else,endif},%
	    keywordsprefix={.},%
	    moredelim=[l][\color{Green}]{:},%
	    morecomment=[l]{\#},%
	    moredelim=[s][\color{Blue}]{\$(}{)}%
	    }
  \lstdefinelanguage{DTD}[]{XML}{%
	    morekeywords={ELEMENT,ENTITY,ATTLIST,CDATA,ID,REQUIRED,
	    IMPLIED,PCDATA}%
	    }
  \lstdefinelanguage{BiBTeX}{%
	    morestring=[s]{\{\}},morekeywords={Article,Book,
	    BookInBook,Booklet,Collection,InBook,InCollection,
	    InProceedings,InReference,MVBook,MVCollection,
	    MVProceedings,MVReference,Manual,Misc,Online,Patent,
	    Periodical,Proceedings,Reference,Report,SuppBook,
	    SuppCollection,SuppPeriodical,Thesis,Unpublished,
	    address,annote,author,booktitle,chapter,crossref,
	    edition,editor,howpublished,institution,journal,
	    key,month,note,number,organization,pages,publisher,
	    location,school,institution,series,title,type,volume,
            year,date},morestring=[b]%
	    }
  \lstloadlanguages{LaTeXe,XSLT,XML,XPath,bash,Makefile,DTD,BiBTeX,awk}
\usepackage{ltxcmds}%
\usepackage{makeidx}%
  \makeindex
\usepackage{parskip}%
\usepackage{ragged2e}%
\usepackage{sectsty}%
  \allsectionsfont{\sffamily\raggedright}
  \renewcommand*{\descriptionlabel}[1]{\hspace\labelsep
	    \sffamily\bfseries #1}
\usepackage[normalem]{ulem}%
\usepackage{url}%
  \AtBeginDocument{\urlstyle{tt}}
\usepackage{varioref}%
  \vrefwarning
  \labelformat{appendix}{Appendix~#1}
  \makeatletter
  \labelformat{chapter}{\@chapapp~#1}
  \makeatother
  \labelformat{section}{section~#1}
  \labelformat{subsection}{section~#1}
  \labelformat{subsubsection}{section~#1}
  \labelformat{paragraph}{section~#1}
  \labelformat{figure}{Figure~#1}
  \labelformat{table}{Table~#1}
  \labelformat{item}{item~#1}
  \renewcommand{\reftextcurrent}{on this page}
  \def\reftextafter{on the
	    \reftextvario{next}{following} page}
\usepackage{xcolor}%
  \makeatletter
  \@ifundefined{T}{%
	    \newcommand{\T}[2]{{\fontencoding{T1}%
	      \selectfont#2}}}{}
  \makeatother
\usepackage{classpack}%
\usepackage{hypdoc}%
  \hypersetup{linkcolor=DarkGreen,citecolor=DarkRed,urlcolor=Blue,colorlinks=true}
  \makeatletter
  \@ifpackageloaded{biblatex}{%
  \makeatother
  \ExecuteBibliographyOptions{maxcitenames=1}
  \DeclareFieldFormat{citehyperref}{%
	    \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
	    \bibhyperref{#1}}
  \DeclareFieldFormat{textcitehyperref}{%
	    \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
	    \bibhyperref{%
	    #1%
	    \ifbool{cbx:parens}
	    {\bibcloseparen\global\boolfalse{cbx:parens}}
	    {}}}
  \savebibmacro{cite}
  \savebibmacro{textcite}
  \renewbibmacro*{cite}{%
	    \printtext[citehyperref]{%
	    \restorebibmacro{cite}%
	    \usebibmacro{cite}}}
  \renewbibmacro*{textcite}{%
	    \ifboolexpr{
	    ( not test {\iffieldundef{prenote}} and
	    test {\ifnumequal{\value{citecount}}{1}} )
	    or
	    ( not test {\iffieldundef{postnote}} and
	    test {\ifnumequal{\value{citecount}}{\value{citetotal}}} )
	    }
	    {\DeclareFieldAlias{textcitehyperref}{noformat}}
	    {}%
	    \printtext[textcitehyperref]{%
	    \restorebibmacro{textcite}%
	    \usebibmacro{textcite}}}
  }{\relax}
\usepackage{hyperref}%
  \hypersetup{linkcolor=DarkGreen,citecolor=DarkRed,
  urlcolor=Blue,colorlinks=true}
  \AtBeginDocument{\renewcommand{\UrlFont}{\ttfamily}}
\usepackage{menukeys}%
  \renewmenumacro{\menu}[>]{roundedmenus}
  \renewmenumacro{\directory}[/]{pathswithblackfolder}
  \renewmenumacro{\keys}{shadowedroundedkeys}
\usepackage[ragged]{footmisc}%
\addbibresource{classpack.bib}
\hypersetup{pdfauthor={Peter Flynn},
        pdftitle={The classpack LaTeX2e document package},
        pdfsubject={XML mastering for \LaTeX{} classes and packages},
        pdfkeywords={latex,typesetting,package,class,xml,management,document},
        pdfproducer={XeLateX with hyperref},
        pdfcreator={Emacs/psgml, ClassPack/Saxon, LaTeX/TeX Live}}
\setmonofont{AnkaCoder-C75}[ Scale=MatchLowercase, Extension= .ttf, UprightFont = *-r, ItalicFont = *-i, BoldFont = *-b, BoldItalicFont = *-bi ]
%
%%
%% Settings for docstrip and ltxdoc 
%%
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}\raggedright
  \DocInput{classpack.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{2448}
%
% \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
%   Lower-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
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!  Double quote  \"  Hash (number) \#
%   Dollar        \$  Percent       \%  Ampersand     \&
%   Acute accent  \'  Left paren    \(  Right paren   \)
%   Asterisk      \*  Plus          \+  Comma         \,
%   Minus         \-  Point         \.  Solidus       \/
%   Colon         \:  Semicolon     \;  Less than     \<
%   Equals        \=  Greater than  \>  Question mark \?
%   Commercial at \@  Left bracket  \[  Backslash     \\
%   Right bracket \]  Circumflex    \^  Underscore    \_
%   Grave accent  \`  Left brace    \{  Vertical bar  \|
%   Right brace   \}  Tilde         \~}
% 
% \changes{v1.28}{2024/02/21}{1) Full regression test on all maintained packages. AutoPackage methoology being documented separately; 2) The code for the widening of the LH margin in mid-document (removed in 1.27) remains in abeyance until some of the discrepancies with fancyhdr headings are resolved; 3) The problem with the dox package interpreting end{macrocode} when it occurs in mid-code and mid-line has been temporarily circumvented by splitting the relevant xsl:text to output the command in two pieces; 4) Additional discrepancy discovered of Doc\TeX{} parsing an ifcase command mentioned in a comment behind a double percent signs in the .dtx file. The package text has been reworded to avoid this until we find out what's happening; 5) The hard-coded list of annotation types in prepost.xml (also used in inline element types like varname) has been replaced by a lookup using the otherwise unused arg element in cmdsynopsis for the dox package in the postpackage part of prepost.xml. This is used to create doxitem commands only for those annotation types that are actually used in the document; 6) In a similar manner, the language list for the listings package (again in the postpackage part of prepost.xml) has been given xml:ids so that only those languages referenced in a document find their way into the .dtx file.}
% \changes{v1.27}{2024/01/30}{1) Rewrite of the way in which packages are detected and handled for the AutoPackage mechanism; 2) Removed (commented out) the code for the widening of the LH margin in mid-document to accommodate long macro names. For the moment it uses fixed margins all the way through. The adjustment feature may return if problems with the formatting of other page elements (particularly running headers and footers) can be resolved.; 3) Ongoing work to find out why the dox package is interpreting end{macrocode} when it occurs in mid-code and not at the start of the line.; 4) Minor corrections to formatting.}
% \changes{v1.26}{2023/12/30}{Regression release for revised db2dtx.xsl 3.1.}
% \changes{v1.25}{2023/10/06}{Added db:book alone as an extra test in attribute-value-match so that a condition for book/@status="draft" would be picked up (all the other tests started too far down the tree)..}
% \changes{v1.24}{2023/07/04}{1) Rationalised the transformation of autopackage packages from prepost.xml format to document format; 2) Split the XPath that finds them into six segments so that the finds can be categorised properly; 3) Rewrote the transformation from the packages tree into the \LaTeX{} serialisation (with new routines for preliminary RequirePackage and for PassOptionsToPackage), using the rationalised attributes on the new packages tree..}
% \changes{v1.23}{2023/06/05}{Finished repairs to the extracting routines for code, added a bypass to allow for deferred comments at the top of shell scripts to avoid trampling on the hashbang.Renamed the development package back to classpack and re-ran all tests..}
% \changes{v1.22}{2023/05/16}{Rearranged documentation order, moved regular classpack.sty code back into the document in preparation for merging the dev code and going back to a single package. Corrected errors in autopackage and rewrote the XPath for detecting matches from prepost.xsl..}
% \changes{v1.21}{2020/06/16}{Re-ordered and documented font selection in prepost.xml.}
% \changes{v1.20}{2020/06/12}{Major edit of user documentation to remove duplications..}
% \changes{v1.19}{2020/05/24}{1) Added hypdoc package as default for documentation in prepost.xml to overcome makeindex bug using hyperref (thanks to Ulrike Fischer on c.t.t); 2) Replaced the tabular used for the forced inclusion of the first three lines of the class or package in (in order to maintain the line-count) with three plain lines because something in hyperref was messing with Doc\TeX{} in a way that hypdoc doesn’t; 3) Rewrote documentation about how makepackages constructs the list of candidate element types.}
% \changes{v1.18}{2020/04/01}{1) Replaced conformance with YYYY-MM-DD on all date elements in the revision history. This means a complete regression run after editing all source masters to use this change; 2) Fixed bug in makechapapp where it failed to add the filetype before substringing the full name of the document; 3) Split project into classpack and classpack-dev so as not to overload the regular user with stuff they don’t need.}
% \changes{v1.17}{2020/03/19}{1) Documentation nearly finished; 2) Added remaining XSLT files and scripts; 3) Recoded the distinction between appendixes in the code part and chapters in the files part..}
% \changes{v1.16}{2019/10/20}{1) Documentation ongoing; 2) Added detection of options on url and xcolor; 3) Changed order of packages in prepost.xml to prevent option clashes.}
% \changes{v1.15}{2019/10/10}{1) Started massive documentation effort on XSLT; 2) Order of templates changed in XSLT.}
% \changes{v1.14}{2019/07/25}{1) Updated the Markdown driver for the README to produce code that displays correctly in the Markdown Viewer 3.6 extension for Chrome and conforms to the CTAN rules.; 2) Added details of ClassPack to the MD file header; 3) Some reorganisation of topics; 4) More annotation-level documentation on the XSLT code.}
% \changes{v1.13}{2019/02/18}{1) Created commentchar and termcommentchar functions; 2) Untested invocation in sect1 template.}
% \changes{v1.12}{2019/02/17}{1) Started tidying up sentinel and fence; 2) Involves rationalising the use of chapter and appendix within part; 3) parameterised a makesentinel, maketermsentinel, and makefence in sect1 but they don’t get called because of [2] above.}
% \changes{v1.11}{2019/02/13}{1) Fixed numerous bugs in handling of listings; 2) Moved DTD annotations to doc as chapter while logic for appendixes not working properly; 3) Finished PE chunking of db2dtx.xsl and doctexbook-master.dtd; 4) Finished writing the chunk script.}
% \changes{v1.10}{2019/01/22}{1) Added attributes to programlisting for fragmentary listings; 2) Changed emphasis with role=bold to be plain bold, not bold italic; 3) Changed blockquotes to blue in the PDF, added recognition of xlink:href to give source ack as URI.}
% \changes{v1.09}{2018/07/07}{Skipped the application of headers to appendix files: 1) Files written from the appendix element no longer get the LaTeX headers prepended; 2) The sentinel value for comments in scripts now reflects the double hash; 3) Added the remark element to db2md.xsl (with plain para); 4) Ongoing updates and explanation.}
% \changes{v1.08}{2018/02/07}{Moved RFC2119 warning, and did some minor rewording: 1) Removed RFC2119 warning text from db2dtx.xsl to rfc2119.xml, creating a section to hold it and the bibliography. Rewrote the templates for bibliolist, biblioentry, bibliography, and section/title to accommodate this.; 2) Ongoing updates and explanation.}
% \changes{v1.07}{2018/01/12}{Minor adaptations to quoted chunks of code: Updated to use \XeLaTeX{}.}
% \changes{v1.06}{2017/06/16}{Maintenance release: Rearranged output so that change log and index always get printed.}
% \changes{v1.05}{2017/04/03}{Maintenance: 1) Updated documentation; 2) Tested additional outputs.}
% \changes{v1.04}{2016/12/20}{Reusable code blocks: 1) Added an attribute reuse to the annotation element for use in Appendixes which generate additional \LaTeX{} class or package files, which points at an xml:id attribute on an existing annotation element already used elsewhere so that the same documentation text can be included. Also added an omit attribute to the seglistitem elements in the constraintdef element for class packages which specifies that the relevant package is not required for the additional class or package being generated.; 2) Changed the documentation font to Noto..}
% \changes{v1.03}{2016/08/13}{Bundle identifiers: 1) Added a line to the Makefile to pick out the date of the most-recently-updated file and put it in a file called VERSION (suggestion from Petra Rübe-Pugliese at CTAN based on their docs).; 2) Regularised the identity of the version date from a global variable date, rather than working it out each time..}
% \changes{v1.025}{2016/08/12}{README: Title and identity moved to a template and deleted from readme.xml.}
% \changes{v1.02}{2016/07/05}{Moved specification for babel to pre-options: 1) The babel package is now pre-specified with the PassOptionsToPackage command, to avoid conflicts with options later; 2) Now using \XeLaTeX{} and biber.}
% \changes{v1.01}{2016/06/12}{Edited out duplications in documentation: 1) Tidied explanations and documented the markup in more detail; 2) Now using \XeLaTeX{} and biber.}
% \changes{v1.0}{2016/06/12}{Tidied up the processing and greatly extended documentation: 1) Rewrote almost all the description of how to create the basic XML file; 2) The RFC2119 Note now automatically includes the relevant \BibTeX{} entry in the .bib file (done in the Makefile).}
% \changes{v0.92}{2016/05/12}{Major changes to the way the .dtx code is created: 1) Moved the specification of the processor from an attribute on the root element to the part start-tag for documentation; 2) Switched from the build file to a Makefile (still incomplete).; 3) Enabled the use of \XeLaTeX{} for the documentation in the .dtx file; 4) Largely rewrote the code for auto-detecting and adding packages, combining the auto-detect packages with those specified by the author. It now includes: a] negatable crosslinks specified in the remap on the constructorsynopsis start-tag (eg specifying the use of \XeLaTeX{} automatically invokes fontspec and defeats the autoload of the inputenc and fontenc packages), b] addition of the use of the arch and condition attributes on the bibliography start-tag to hold the \BibTeX{} package (biblatex) and the \BibTeX{} engine (biber), c] changes from the text-mode README to a MarkdownREADME.md to accommodate TUG’s submission process; 5) The layout of the zip files has been significantly changed to accord with the submission requirements of CTAN; 6) A Bibliography of the documentation is now extracted to disk directly in the XSLT process, rather than via the VerbatimOut environment in the .dtx file; 7) The RFC2119 Note now automatically includes the relevant \BibTeX{} entry in the .bib file (done in the Makefile).}
% \changes{v0.915}{2016/05/11}{Merged: Merged default packages with author-requested ones..}
% \changes{v0.91}{2016/05/10}{Regenerated: Recreated package with new classpack code to create zip file to the CTAN standard.}
% \changes{v0.905}{2015/10/06}{Enhanced: Added support for \XeLaTeX{}.}
% \changes{v0.9}{2015/12/19}{Removed fixltx2e: The code from the fixltx2e package has now been merged into the kernel, so the preload of this package is no longer needed..}
% \changes{v0.82}{2014/03/31}{Fixed hline bug: Should have been renewcommand not def.}
% \changes{v0.81}{2014/03/14}{Added more logo commands: XeTeX, XeLaTeX.}
% \changes{v0.80}{2014/03/10}{Moved doc commands from XSLT2: ToC settings and revmarg.}
% \changes{v0.79}{2014/03/07}{Editorial update: Small corrections.}
% \changes{v0.78}{2014/03/06}{Changed default code color: MacroFont now DarkBlue.}
% \changes{v0.77}{2013/05/28}{Removed unwanted definitions: classorpackage.}
% \changes{v0.76}{2013/05/05}{Modified documentation: Started working on Makefile.}
% \changes{v0.75}{2013/03/14}{Added secondary files: Secondary output files possible; reversed usage of role attribute on keywords;.}
% \changes{v0.74}{2013/02/21}{Added experimental autopackage: This implements automated package inclusion based on the markup used by the author..}
% \changes{v0.73}{2012/06/19}{Added readme.xml and db2plaintext.xsl: This implements dynamic README generation..}
% \changes{v0.72}{2012/02/11}{Wrote internal documentation: Created the classpack.xml template as an example..}
% \changes{v0.71}{2012/02/08}{First time this was used to document itself: The title element and subtitle element are now subsumed beneath the generated title in the output..}
% \changes{v0.7}{2012/01/19}{Testing for self-replication: Danger, Will Robinson!.}
% \changes{v0.6}{2011/12/27}{Changes to date calculations: More use of functions.}
% \changes{v0.5}{2011/08/14}{Bugfixes: Cleaned up XSLT code.}
% \changes{v0.4}{2011/05/09}{Added options: Mostly for controlling appearance.}
% \changes{v0.3}{2011/04/07}{More work with UCC thesis class: Added links to bibliographic styles.}
% \changes{v0.2}{2010/05/22}{Used UCC thesis class as test: Devised method for creating bulk options.}
% \changes{v0.1}{2009/10/22}{First draft: 1) Construction of .dtx file working; 2) Tested with personal class.}
%
% \GetFileInfo{classpack.dtx}
%
% \DoNotIndex{\@,\@@par,\@beginparpenalty,\@empty}
% \DoNotIndex{\@flushglue,\@gobble,\@input,\@makefnmark}
% \DoNotIndex{\@makeother,\@maketitle,\@namedef,\@ne}
% \DoNotIndex{\@spaces,\@tempa,\@tempb,\@tempswafalse}
% \DoNotIndex{\@tempswatrue,\@thanks,\@thefnmark,\@topnum}
% \DoNotIndex{\@@,\@elt,\@forloop,\@fortmp,\@gtempa}
% \DoNotIndex{\@totalleftmargin,\",\/,\@ifundefined,\@nil}
% \DoNotIndex{\@verbatim,\@vobeyspaces,\|,\~,\ ,\active}
% \DoNotIndex{\advance,\aftergroup,\begingroup,\bgroup}
% \DoNotIndex{\mathcal,\csname,\def,\documentstyle}
% \DoNotIndex{\dospecials,\edef,\egroup,\else,\endcsname}
% \DoNotIndex{\endgroup,\endinput,\endtrivlist}
% \DoNotIndex{\expandafter,\fi,\fnsymbol,\futurelet,\gdef}
% \DoNotIndex{\global,\hbox,\hss,\if,\if@inlabel}
% \DoNotIndex{\if@tempswa,\if@twocolumn,\ifcase,\ifcat}
% \DoNotIndex{\iffalse,\ifx,\ignorespaces,\index,\input}
% \DoNotIndex{\item,\jobname,\kern,\leavevmode,\leftskip}
% \DoNotIndex{\let,\llap,\lower,\m@ne,\next,\newpage}
% \DoNotIndex{\nobreak,\noexpand,\nonfrenchspacing}
% \DoNotIndex{\obeylines,\or,\protect,\raggedleft}
% \DoNotIndex{\rightskip,\rm,\sc,\setbox,\setcounter}
% \DoNotIndex{\small,\space,\string,\strut,\strutbox}
% \DoNotIndex{\thefootnote,\thispagestyle,\topmargin}
% \DoNotIndex{\trivlist,\tt,\twocolumn,\typeout,\vss,\vtop}
% \DoNotIndex{\xdef,\z@,\,,\@bsphack,\@esphack,\@noligs}
% \DoNotIndex{\@vobeyspaces,\@xverbatim,\`,\catcode,\end}
% \DoNotIndex{\escapechar,\frenchspacing,\glossary}
% \DoNotIndex{\hangindent,\hfil,\hfill,\hskip,\hspace,\ht}
% \DoNotIndex{\it,\langle,\leaders,\long,\makelabel}
% \DoNotIndex{\marginpar,\markboth,\mathcode,\mathsurround}
% \DoNotIndex{\mbox,\newcount,\newdimen,\newskip}
% \DoNotIndex{\nopagebreak,\parfillskip,\parindent}
% \DoNotIndex{\parskip,\penalty,\raise,\rangle,\section}
% \DoNotIndex{\setlength,\TeX,\topsep,\underline,\unskip}
% \DoNotIndex{\verb,\vskip,\vspace,\widetilde,\\,\%,\@date}
% \DoNotIndex{\@defpar,\[,\{,\},\],\count@,\ifnum,\loop}
% \DoNotIndex{\today,\uppercase,\uccode,\baselineskip}
% \DoNotIndex{\begin,\tw@,\a,\b,\c,\d,\e,\f,\g,\h,\i,\j,\k}
% \DoNotIndex{\l,\m,\n,\o,\p,\q,\r,\s,\t,\u,\v,\w,\x,\y,\z}
% \DoNotIndex{\A,\B,\C,\D,\E,\F,\G,\H,\I,\J,\K,\L,\M,\N,\O}
% \DoNotIndex{\P,\Q,\R,\S,\T,\U,\V,\W,\X,\Y,\Z,\1,\2,\3,\4}
% \DoNotIndex{\5,\6,\7,\8,\9,\0,\!,\#,\$,\&,\',\(,\)}
% \DoNotIndex{\+,\.,\:,\;,\<,\=,\>,\?,\_,\discretionary}
% \DoNotIndex{\immediate,\makeatletter,\makeatother}
% \DoNotIndex{\meaning,\newenvironment,\par,\relax}
% \DoNotIndex{\renewenvironment,\repeat,\scriptsize}
% \DoNotIndex{\selectfont,\the,\undefined,\arabic,\do}
% \DoNotIndex{\makeindex,\null,\number,\show,\write,\@ehc}
% \DoNotIndex{\@author,\@ehc,\@ifstar,\@sanitize,\@title}
% \DoNotIndex{\everypar,\if@minipage,\if@restonecol,\ifeof}
% \DoNotIndex{\ifmmode,\lccode,\newtoks,\onecolumn,\openin}
% \DoNotIndex{\p@,\SelfDocumenting,\settowidth}
% \DoNotIndex{\@resetonecoltrue,\@resetonecolfalse,\bf}
% \DoNotIndex{\clearpage,\closein,\lowercase,\@tempdima}
% \DoNotIndex{\@inlabelfalse,\selectfont,\mathcode}
% \DoNotIndex{\newmathalphabet,\rmdefault,\bfdefault}
% \DoNotIndex{\DeclareRobustCommand,\@ifpackagewith}
% \DoNotIndex{\#,\%,\&,\*,\-,\^,\_,\|,\~,\$}
% \DoNotIndex{\acro,\addbibresource,\addcontentsline,\addtolength}
% \DoNotIndex{\allowbreak,\alph,\@Alph,\and,\appendix,\arrayrulewidth}
% \DoNotIndex{\ast,\baselinestretch,\bfseries,\bgroup,\Bib,\BibTeX}
% \DoNotIndex{\BiBTeX,\BIBTeX,\bigskip,\box,\caption,\centering,\char}
% \DoNotIndex{\CharacterTable,\CheckSum,\citeyear,\cjktext,\ClassError}
% \DoNotIndex{\classorpackage,\CodelineIndex,\color,\colorbox}
% \DoNotIndex{\columnsep,\columnwidth,\Con,\ConTeXt}
% \DoNotIndex{\CPKannotationindent,\CPKdocname,\CPKdoctype,\CPKmenusep}
% \DoNotIndex{\CPKpoststrut,\CPKprestrut,\CPKrevmarg,\CPKrunningecho}
% \DoNotIndex{\CPKthisjob,\CPKthispackage,\CPKvstrut,\c@section}
% \DoNotIndex{\@currsize,\DeclareOption,\declarepostamble}
% \DoNotIndex{\declarepreamble,\DescribeColor,\DescribeEnv}
% \DoNotIndex{\DescribeError,\DescribeOption,\DescribePackage}
% \DoNotIndex{\DescribeTemplate,\descriptionlabel,\divide,\DoNotIndex}
% \DoNotIndex{\dotfill,\dots,\@dottedtocline,\DoubleperCent,\doxitem}
% \DoNotIndex{\dp,\egroup,\emph,\empty,\EnableCrossrefs}
% \DoNotIndex{\encodingdefault,\endbatchfile,\endpreamble,\enspace}
% \DoNotIndex{\ensuremath,\fa,\fbox,\fboxrule,\fboxsep,\file,\Finale}
% \DoNotIndex{\flushright,\fnote,\font,\fontdimen,\fontencoding}
% \DoNotIndex{\fontfamily,\fontseries,\fontshape,\fontsize,\footnote}
% \DoNotIndex{\footnotesize,\from,\generate,\GetFileInfo,\HandRight}
% \DoNotIndex{\@height,\@@hline,\href,\hrule,\hsize,\huge,\Huge}
% \DoNotIndex{\hyperref,\hypersetup,\hyphenation,\ifdim,\@ifnextchar}
% \DoNotIndex{\itshape,\keepsilent,\keys,\labelenumi,\LabelFont}
% \DoNotIndex{\labelformat,\large,\Large,\LARGE,\LaTeX,\LaTeXe}
% \DoNotIndex{\leftmark,\lfoot,\lhead,\longestline,\lstloadlanguages}
% \DoNotIndex{\l@subsection,\l@subsubsection,\ltx@ifpackageloaded}
% \DoNotIndex{\LyX,\MacroFont,\marginfont,\marginnote,\medskip}
% \DoNotIndex{\menu,\menusep,\message,\MF,\@minus,\MP,\Msg}
% \DoNotIndex{\multirow,\NeedsTeXFormat,\newcommand,\newcounter}
% \DoNotIndex{\newgeometry,\newlength,\newwrite,\nicefrac,\noalign}
% \DoNotIndex{\nocite,\noindent,\nolinkurl,\nopreamble,\normalfont}
% \DoNotIndex{\normalsize,\numberstring,\obeyspaces,\ordinal}
% \DoNotIndex{\PackageError,\pageref,\phantomsection,\@plus}
% \DoNotIndex{\@pnumwidth,\preamble,\PrintChanges}
% \DoNotIndex{\printexternalcurrentfont,\PrintIndex,\Provides}
% \DoNotIndex{\qquad,\quad,\raisebox,\RecordChanges,\reflectbox}
% \DoNotIndex{\refname,\renewcommand,\renewmenumacro,\reserved@a}
% \DoNotIndex{\rightarrow,\rightmark,\rmfamily,\rotatebox,\rule}
% \DoNotIndex{\school,\sloppy,\smallskip,\SMC,\SMC@unknown@warning}
% \DoNotIndex{\Square,\stanza,\star,\@startsection,\stepcounter}
% \DoNotIndex{\StopEventually,\subsubsection,\tableofcontents}
% \DoNotIndex{\textbackslash,\textbf,\textdegree,\texteiad}
% \DoNotIndex{\textheight,\textit,\textlangle,\textrangle,\textsf}
% \DoNotIndex{\textSMC,\textsuperscript,\texttt,\TheSbox}
% \DoNotIndex{\thesection,\thinspace,\tiny,\@tocrmarg}
% \DoNotIndex{\tubhideheight,\tubreflect,\uline,\updefault}
% \DoNotIndex{\upshape,\use@babel,\@usebib,\usedir,\usepostamble}
% \DoNotIndex{\usepreamble,\vbox,\vfill,\vrefrange,\vrule}
% \DoNotIndex{\Xe,\XeLaTeX,\XeTeX,\@xhline}
% \DoNotIndex{\xsl:text}
% \DoNotIndex{\ifcase}
% \DoNotIndex{\doxitem}
% \DoNotIndex{\PassOptionsToPackage}
% \DoNotIndex{\RaggedRight}
% \DoNotIndex{\varname}
% \DoNotIndex{\RequirePackage}
% \DoNotIndex{\raggedright}
% \DoNotIndex{\sffamily}
% \DoNotIndex{\usepackage}
% \DoNotIndex{\title}
% \DoNotIndex{\author}
% \DoNotIndex{\abstractname}
% \DoNotIndex{\changes}
% \DoNotIndex{\section}
% \DoNotIndex{\subsection}
% \DoNotIndex{\MacroFont}
% \DoNotIndex{\newif}
% \DoNotIndex{\definecolor}
% \DoNotIndex{\DocInput}
% \DoNotIndex{\PassOptionsToClass}
% \DoNotIndex{\LoadClass}
% \DoNotIndex{\@@doxdescribe}
% \DoNotIndex{\makeatletter}
% \DoNotIndex{\makeatother}
% \DoNotIndex{\make}
% \DoNotIndex{\makeindex}
% \DoNotIndex{\ref}
% \DoNotIndex{\maketitle}
% \DoNotIndex{\label}
% \DoNotIndex{\small}
% \DoNotIndex{\ttfamily}
% \DoNotIndex{\scriptsize}
% \DoNotIndex{\parskip}
% \DoNotIndex{\url}
% \DoNotIndex{\vref}
% \DoNotIndex{\vpageref}
% \DoNotIndex{\vrange}
% \DoNotIndex{\bibname}
% \DoNotIndex{\subsubsection}
% \DoNotIndex{\hline}
% \DoNotIndex{\endinput}
% \DoNotIndex{\Print*Name}
% \DoNotIndex{\decorule}
% \DoNotIndex{\ProvidesFile}
% \DoNotIndex{\ProvidesClass}
% \DoNotIndex{\ProvidesPackage}
% \DoNotIndex{\documentclass}
% \DoNotIndex{\thanks}
% \DoNotIndex{\fileversion}
% \DoNotIndex{\filedate}
% \DoNotIndex{\appendix}
% \DoNotIndex{\paragraph}
% \DoNotIndex{\subparagraph}
% \DoNotIndex{\par}
% \DoNotIndex{\item}
% \DoNotIndex{\verb}
% \DoNotIndex{\DescribeClass}
% \DoNotIndex{\DescribeMacro}
% \DoNotIndex{\foreignlanguage}
% \DoNotIndex{\DescribeFunction}
% \DoNotIndex{\includegraphics}
% \DoNotIndex{\changemenucolor}
% \DoNotIndex{\hyperlink}
% \DoNotIndex{\lstlisting}
% \DoNotIndex{\oarg}
% \DoNotIndex{\marg}
% \DoNotIndex{\Describe}
% \DoNotIndex{\lstinputlisting}
% \DoNotIndex{\basicstyle}
% \DoNotIndex{\textsc}
% \DoNotIndex{\lstdefinelanguage}
% \DoNotIndex{\lstloadlanguages}
% \DoNotIndex{\Describe*}
% \DoNotIndex{\parencite}
% \DoNotIndex{\fullcite}
% \DoNotIndex{\citetitle}
% \DoNotIndex{\cite}
% \DoNotIndex{\textcite}
% \DoNotIndex{\printbibliography}
% \DoNotIndex{\bibliography}
% \DoNotIndex{\bibliographystyle}
% \DoNotIndex{\multicolumn}
% \DoNotIndex{\arraybackslash}
% \DoNotIndex{\widthof}
% \DoNotIndex{\vstrut}
% \DoNotIndex{\includepdf}
% \DoNotIndex{\yes}
% \setcounter{tocdepth}{5}
% \setcounter{secnumdepth}{5}
% \makeatletter
% \def\@@doxdescribe#1#2{\endgroup \ifdox@noprint\else\marginpar{\raggedleft \@nameuse{PrintDescribe#1}{\LabelFont[\color{DarkRed}]{#2}}}\fi \ifdox@noindex\else \@nameuse{Special#1Index}{#2}\fi \endgroup\@esphack\ignorespaces}
% \makeatother
%
% \def\fileversion{1.28}
% \def\filedate{2024/02/21}
% \title{The  \textsf{classpack} \LaTeXe\ package\thanks{%
% This document corresponds to \textsf{classpack}
% \textit{v.}\ \fileversion , dated \filedate.}
% \\[1em]\Large 
% XML mastering for \LaTeX{} classes and packages
% \\[1ex]\large 
% Literate-programming solution \\
%       for class and package maintenance}
% \author{Peter Flynn\\\normalsize Silmaril Consultants\\[-.25ex]\normalsize Textual Therapy Division\\\normalsize(\url{peter@silmaril.ie})}
% \maketitle
% \renewcommand{\abstractname}{Summary}\thispagestyle{empty}
% \begin{abstract}
% \parskip=0.5\baselineskip
% \advance\parskip by 0pt plus 2pt
% \parindent=0pt% \noindent
% \LaTeX{} document classes and packages are conventionally
% created, maintained, and distributed in Doc\TeX{}
% ({\ttfamily{}.dtx}) format using the 
% \textsf{ltxdoc} class, which provides for
% interleaved code and documentation (`literate
%   programming'). However, the accurate construction of
% these files is technically challenging, and editing them is
% tedious and error-prone.\par
% \emph{ClassPack} allows a \LaTeX{}
% developer to create a \emph{DocBook5} \textsc{xml} document for a class or package,
% containing the code interleaved with annotations, plus a
% section for the documentation. It provides an
% \textsc{xslt3} script to generate the
% {\ttfamily{}.dtx}\thinspace, {\ttfamily{}.ins}\thinspace, and
% other files, which can be suitably zipped up
% for submission to \textsc{ctan}\index{CTAN}.\par
% This is a development system for class and package
% authors. The {\ttfamily{}classpack.sty} file contains
% typographic adjustments and utilities only needed to typeset
% the documentation of
% \emph{ClassPack}-produced classes or
% packages.\par
% This software is a work-in-progress. It has been in
% development at Silmaril since 1998, and in production use
% since 2008. This release includes completion of the rewrite of
% the \emph{AutoPackage} algorithms,
% improved Makefile control, and a detailed update of the
% annotation of the \textsc{xslt} code. A paper
% describing an earlier version was presented at a Balisage
% markup conference in Montréal \parencite{flynn2013}.\par
% \par\centering
%     \includegraphics[width=.666\columnwidth]{codepage-crop.pdf}
% \end{abstract}
% \clearpage
% \tableofcontents
% \subsection*{Note on required and optional features}
% In this document, the keywords
%     {\sffamily \textsc{must}}, {\sffamily \textsc{must not}}, {\sffamily \textsc{required}},
%     {\sffamily \textsc{shall}}, {\sffamily \textsc{shall not}}, {\sffamily \textsc{should}},
%     {\sffamily \textsc{should not}},
%     {\sffamily \textsc{recommended}},
%     {\sffamily \textsc{may}}, and
%     {\sffamily \textsc{optional}} have a specific
%     meaning when shown in {\sffamily \textsc{this typestyle}}, and
%     {\sffamily \textsc{must}} be interpreted as described in
%     RFC 2119 \parencite{rfc2119}.\par
% When shown in normal type, these words keep their conventional
%     contextual degree of meaning.\par
% \clearpage
% \subsection*{Typographic representation}\label{typorep}
% In this document, the following information items are shown in
%   this way:\par
% \par\medskip{\sffamily\rmfamily
% \small\sffamily
% \begingroup
% \centering
% \begin{tabular}{@{}%
%   l%
%   >{\renewcommand{\baselinestretch}{0.8}\selectfont{}\raggedright{}\renewcommand{\baselinestretch}{0.8}\selectfont{}\CPKprestrut\arraybackslash}p{12cm}<{}%
%   @{}}
% \multicolumn{1}{@{}>{\renewcommand{\baselinestretch}{0.8}\selectfont{}\raggedright{}\CPKprestrut}b{\widthof{environments}}<{}}{\sffamily\bfseries Item}&
% \multicolumn{1}{>{\renewcommand{\baselinestretch}{0.8}\selectfont{}\raggedright{}\CPKprestrut\arraybackslash}b{12cm}<{}@{}}{\sffamily\bfseries Description}\\[2pt]\hline
% \CPKvstrut 
% \index{class@\textsf{class} (class)}\index{classes:!class@\textsf{class}}\textsf{class}&name of a \LaTeX{} document class\\
% \texttt{code}&word or phrase in a programming language\\
% {\ttfamily{}\textbackslash{}command}&name of a \LaTeX{} `command'
%     (\TeX{} macro or control sequence)\\
% \texttt{environment}&name of a \LaTeX{} environment\\
% {\ttfamily{}filename}\thinspace&name of a file\\
% \textbf{\emph{firstterm}}\index{firstterm|textbf}&first significant use of a technical term\\
% \texttt{function}&name of a function in a programming language\\
% {\changemenucolor{keys}{bg}%  {HTML}{CDCDCD}\renewmenumacro{\keys}%  {roundedkeys}\keys{button}}&a button in a \textsc{gui}\\
% {\renewmenumacro{\keys}{angularkeys}\keys{label}}&a label in a \textsc{gui}\\
% \menu{menu}&a top-level menu entry in a \textsc{gui}\\
% \keys{keycap}&a keycap (single key)\\
% \texttt{template}&name of a template in an \textsc{xslt} script\\
% \textbf{\texttt{option}}&name of an option to a \LaTeX{} command, environment,
%     class, or package\\
% \textsf{package}&name of a \LaTeX{} package\\
% {\ttfamily{}\$parameter}&name of a parameter to a \LaTeX{} command or environment, or
%     to an \textsc{xslt} script\\
% \emph{productname}&a product name\\
% \uline{replaceable}&a mnemonic for a user-replaceable string in a
%   paradigm of a command or procedure\\
% {\ttfamily{}systemitem}\thinspace&a computer system item (eg hostname or data value)\\
% \texttt{<tag/>}\index{tag=\texttt{\char'074 tag/\char'076 } (empty element)}\index{empty elements:!tag=\texttt{\char'074 tag/\char'076}}&a tag name in a markup language (eg \textsc{xml})\\
% {\ttfamily{}varname}&a variable name in a supported language\\[2pt]\hline
% \end{tabular}
% \par\endgroup
% }
% \par
% \clearpage
% \section*{Latest changes}
% \subsection*{v.1.28 (2024-02-21)}
% \begin{itemize}
% \item Full regression test on all maintained packages.
% \emph{AutoPackage} methoology
% being documented separately;
% \item The code for the widening of the LH margin in
% mid-document (removed in 1.27) remains in abeyance
% until some of the discrepancies with
% \textsf{fancyhdr} headings are
% resolved;
% \item The problem with the \textsf{dox}
% package interpreting \verb|\end{macrocode}|
% when it occurs in mid-code and mid-line has been
% temporarily circumvented by splitting the relevant
% {\ttfamily{}xsl:text} to output
% the command in two pieces;
% \item Additional discrepancy discovered of Doc\TeX{}
% parsing an {\ttfamily{}\textbackslash{}ifcase} command mentioned
% in a comment behind a double percent signs in the
% {\ttfamily{}.dtx} file. The package text has
% been reworded to avoid this until we find out what's
% happening;
% \item The hard-coded list of annotation types in
% {\ttfamily{}prepost.xml} (also used in inline
% element types like \texttt{<varname>}\index{varname=\texttt{\char'074 varname\char'076 } (element)}\index{elements:!varname=\texttt{\char'074 varname\char'076 }}) has been
% replaced by a lookup using the otherwise unused
% \texttt{<arg>}\index{arg=\texttt{\char'074 arg\char'076 } (element)}\index{elements:!arg=\texttt{\char'074 arg\char'076 }} element in \texttt{<cmdsynopsis>}\index{cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 } (element)}\index{elements:!cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 }} for
% the \textsf{dox} package in the
% \texttt{"postpackage"}\index{postpackage=\texttt{"postpackage"} (attribute value)}\index{attribute values:!postpackage=\texttt{"postpackage"}} part of
% {\ttfamily{}prepost.xml}\thinspace. This is used to
% create {\ttfamily{}\textbackslash{}doxitem} commands only for
% those annotation types that are actually used in the
% document;
% \item In a similar manner, the language list for the
% \textsf{listings} package (again in the
% \texttt{<postpackage>}\index{postpackage=\texttt{\char'074 postpackage\char'076 } (element)}\index{elements:!postpackage=\texttt{\char'074 postpackage\char'076 }} part of
% {\ttfamily{}prepost.xml}) has been given \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}}\kern1pt{}s so that only those
% languages referenced in a document find their way into
% the {\ttfamily{}.dtx} file.
% \end{itemize}
% \subsection*{v.1.27 (2024-01-30)}
% \begin{itemize}
% \item Rewrite of the way in which packages are detected
% and handled for the
% \emph{AutoPackage}
% mechanism;
% \item Removed (commented out) the code for the widening
% of the LH margin in mid-document to accommodate long
% macro names. For the moment it uses fixed margins all
% the way through. The adjustment feature may return if
% problems with the formatting of other page elements
% (particularly running headers and footers) can be
% resolved.\par
% \item Ongoing work to find out why the
% \textsf{dox} package is interpreting
% \verb|\end{macrocode}| when it occurs in
% mid-code and \emph{not} at the start of
% the line.\par
% \item Minor corrections to formatting.
% \end{itemize}
% \subsection*{v.1.26 (2023-12-30)}
% \begin{itemize}
% \item Regression release for revised db2dtx.xsl 3.1.
% \end{itemize}
% \subsection*{v.1.25 (2023-10-06)}
% \begin{itemize}
% \item Added db:book alone as an extra test in
% attribute-value-match so that a condition for
% book/@status="draft" would be picked up (all the other
% tests started too far down the tree).\par
% \end{itemize}
% \par\bigskip
%     See p.\thinspace\pageref{changehistory} for earlier changes.
% \section{Summary of the \emph{ClassPack} code
% management system}\label{pkgintro}
% \emph{ClassPack} is an
% \textsc{xml}-based class and package management
% system for \LaTeX{} described in this document
% ({\ttfamily{}classpack.pdf}).\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily
% \subsubsection*{Packages and document classes}
% For newcomers to \LaTeX{}, a \textbf{\emph{document
%     class}}\index{document class|textbf} is a template (a
%   {\ttfamily{}.cls} file) — it specifies margins,
%   fonts, spacing, layout, and any extra page and content
%   design features for a particular type of document (eg
%   report, article, book, etc), and any extra commands needed
%   to make use of it; a \textbf{\emph{package}}\index{package|textbf} is a
%   plugin (a {\ttfamily{}.sty} file) which provides a
%   specific type of formatting (eg a new font or family, an
%   extra feature, a new way to typeset something, a variant on
%   a theme, a utility to simplify complex work, etc) that can
%   be used with many different document classes.\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% \emph{ClassPack} itself is neither an
% actual document class, nor a package for end-users, but an
% \textsc{xml} system for developers to
% \emph{generate} \LaTeX{} classes and packages. It
% \emph{does} provide a small
% {\ttfamily{}classpack.sty} \emph{package} file which provides some
% presentational styling and utilities used in formatting the
% documentation like this, generated by
% \emph{ClassPack}, but it is not used or
% required anywhere else. For the benefit of readers, this
% \textsf{classpack} package is summarised very
% briefly in \vref{cpsum}).\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily
% The \textsf{classpack} package gets used
%   automatically \emph{only} during the
%   formatting of the \emph{documentation} of
%   \emph{ClassPack}-generated packages and
%   classes. It does \emph{not} (and for safety
%   {\sffamily \textsc{must not}}) get used in the
%   \LaTeX{} code of any packages and classes which you write or
%   maintain in \emph{ClassPack}, only in
%   your \emph{documentation} for them. The users
%   of your classes and packages developed using
%   \emph{ClassPack} do
%   \emph{not} need the
%   \textsf{classpack} package at any stage unless
%   they wish to re-typeset your documentation themselves.\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% \subsection{Code management features in
%   \emph{ClassPack}}\label{cpmgt}
% The features of the development environment are mainly
%   implemented in \textsc{xml} and
%   \textsc{xslt}, with a few dependencies executed in
%   \LaTeX{} in the {\ttfamily{}.dtx} file.\par
% \begin{description}[style=unboxed]
% \item[Changes to the \emph{DocBook} \textsc{dtd}\index{DTD}:]\emph{ClassPack} uses
% \emph{DocBook}, probably the most
% popular general-purpose XML markup system for
% computing documentation. Its widespread use means it
% is strongly supported by toolchains and has extensive
% support from vendors. More details are in \vref{whyxml}\par 
% There are some changes to attribute types (and
% some new ones added), plus some character entities to
% facilitate \LaTeX{}: there are no new element types.
% You use the attributes to indicate identity, to
% distinguish between the different parts of your
% \LaTeX{} class or package, and to signal required
% behaviour. These changes are documented in \vref{dtdchanges} and annotated in the code in
% \vref{cpdtddoc}.\par
% \item[Helpful features for authors and
%       maintainers:]A number of other features are implemented in the
% \textsc{xslt} code rather than in the
% specifications in the \hyperref[DTD]{\textsc{dtd}}\index{DTD} because
% they require computation more suited to
% \textsc{xslt} than \LaTeX{} (for example,
% look-ahead). These features are intended to let the
% author `just write', and have the
% system handle any underlying complexity. These are
% documented in \vref{content} and annotated
% in the code for the scripts in the Appendices.\par
% \item[\emph{AutoPackage}:]This is an automated mechanism added in 2013 for
% detecting and including required \LaTeX{} packages in
% documentation, and for normalising the inclusion of
% packages in your own classes and packages. It lets you
% create your own preferred way of working for how you
% write documentation and design your classes and
% packages. This is documented in \vref{autopackage}
% and annotated in \vref{makepack}.\par
% \item[Packaging:]The standard \emph{make}\thinspace(1)
% Unix/\textsc{gnu} Linux utility
% ({\ttfamily{}Makefile}) included with
% \emph{ClassPack} builds the
% {\ttfamily{}.dtx} and
% {\ttfamily{}.ins} files, typesets the
% \textsc{pdf} documentation, installs the
% class or package in the author’s Personal \TeX{}
% Directory, and creates both \hyperref[CTAN]{\textsc{ctan}}\index{CTAN}
% and \textsc{tds} zip files for distribution.
% Details are annotated in \vref{usemakefile}. There is currently no
% equivalent method implemented for Windows.\par
% \end{description}
% \subsection{Presentation features
% in the \textsf{classpack} package itself}\label{cpsum}
% The formatting of \emph{ClassPack}
%   documentation implements the following differences from
%   standard Doc\TeX{}:\par
% \subsubsection{Features adjusted for ease of reading}\label{cppref}
% Details of the annotated code are in \vref{pkgmacros}. They cover the following formatting
%     changes:\par
% \label{reading}
% \begin{enumerate}
% \item Two-column index instead of three-column;
% \item Dark Blue colour for annotated code;
% \item Recalculation of the left-hand margin in
% documentation to accommodate long variable
% names;
% \item Wider space for the section numbers and page
% numbers in the Table of Contents, and ragged-right
% setting for section titles to prevent
% hyphenation;
% \item Appendixes (used for annotated code for ancillary
% files) are styled at section level, not chapter
% level;
% \item Definitions for the Con\TeX t{}, \XeTeX{} and
% \XeLaTeX{}, and Lua\TeX{} and Lua\LaTeX{} logos (borrowed
% from the TUGboat style);
% \item Fake small caps (also from TUGboat) for the
% \BibTeX{} logo for fonts without them;
% \item New struts for adjusting table spacing;
% \item Some hyphenation oddities fixed (see code).
% \end{enumerate}
% \subsubsection{Features adjusted for ease of writing}\label{cppack}
% \par
% \label{writing}
% \begin{enumerate}
% \item A fix for \LaTeX{}’s broken description
% environment, using \textsf{enumitem};
% \item The \textsf{array} package for
% re-spacing tables;
% \item Menu items in documentation now use the graphical
% features of the \textsf{menukeys}
% package;
% \item Raggedright setting of footnotes from the
% \textsf{footmisc} package;
% \item Running headers and footers from the
% \textsf{fancyhdr} package;
% \item The {\ttfamily{}\textbackslash{}RaggedRight} (hyphenating)
% ragged-right setting for bibliographies from the
% \textsf{ragged2e} package;
% \item The \textsf{graphicx} package is added
% to allow the definitions for \XeTeX{} etc to
% work;
% \item A counter to be used when calculating the number
% of items in a list.
% \end{enumerate}
% \par\begingroup
%   \fboxsep1em\centering
%   \fbox{\begin{minipage}{0.8\columnwidth}\sffamily
%  \raggedright\parindent0pt
%  \parskip=.5\baselineskip
% An end-user of your classes or packages
%     {\sffamily \textsc{should not}} normally need 
%     the \textsf{classpack} package unless
%     they want to re-typeset the documentation.\par
% \end{minipage}}\par\endgroup
% \clearpage
% \section{Introduction}\label{intro}
% \LaTeX{} document classes (layout templates) and packages
% (formatting styles) are traditionally distributed as pairs of
% {\ttfamily{}.dtx} and{\ttfamily{}.ins} files,
% written to the specifications and recommendations of the
% \textsf{doc}, \textsf{ltxdoc}, and
% \textsf{clsguide} packages.\par
% \begin{itemize}
% \item The {\ttfamily{}.dtx} (Doc\TeX{}) file is a
%     \textbf{\emph{literate-programming}}\index{literate-programming|textbf} document,
%     containing modular code and documentation interleaved in
%     such a way that each fragment of code and its explanation
%     are adjacent.\par
% This broadly parallels the
%     \emph{web} literate-programming system
%     due to \textcite{knuthweb}
%     used in the production of the original \TeX{} system and
%     its documentation;
% \item \label{ins}The {\ttfamily{}.ins} file is an installer:
%     when run through \LaTeX{}, it extracts the programming code
%     from the {\ttfamily{}.dtx} file into the relevant
%     class ({\ttfamily{}.cls}), package
%     ({\ttfamily{}.sty}), and other files;
% \item Running \LaTeX{} on the {\ttfamily{}.dtx} file
%     itself extracts and typesets the documentation.
% \end{itemize}
% The construction of a {\ttfamily{}.dtx} document
% is quite complex, with a special set of tags and conventions
% to allow documentation to be separately identifiable to code.
% The file format relies on the documentation being shielded by
% a leading percent–space armour (\verb|%␣|) 
% on each line to prevent it being interpreted as part of the
% code; and the environment surrounding the code itself
% must be shielded by four such spaces
% (\verb|%␣␣␣␣|). Apart from the
% documentation, the treatment of the code and control
% statements resembles more a data specification (which in some
% ways it is) than a conventional text document.\par
% \subsection{XML}\label{whyxml}
% \textsc{xml}, particularly in its traditional
%   `document' mode, as distinct from its
%   use as an exchange format for rectangular data, offers many
%   similar features to \LaTeX{} (for example, the named
%   identification of document components), but with a rigid and
%   invariable syntax that can be checked programmatically by
%   any validating \textsc{xml} processor. By
%   contrast, a \LaTeX{} document (and more specifically, a
%   {\ttfamily{}.dtx} document) can only be proved by
%   running it through \LaTeX{} itself: there is no equivalent to
%   the `pre-flight' type of standalone parsing
%   or validating available with \textsc{xml},
%   although there are several
%   \emph{lint}-like utilities which check
%   basic syntax \parencite{chktex,lacheck,check}, and some \LaTeX{} editors include
%   syntax-checking.\par
% The \emph{DocBook} vocabulary of
%   \textsc{xml} is designed for technical
%   documentation in computing. It provides markup both for
%   textual material and for data-like structures that occur in
%   computer documentation, making it a suitable candidate for
%   describing a literate-programming type of document such as
%   Doc\TeX{}.\par
% \subsection{\emph{ClassPack}}
% The \emph{ClassPack} system is an
%   ongoing experiment or work-in-progress using
%   \emph{DocBook} \textsc{xml} as
%   the storage format for \LaTeX{} class and package source code
%   and documentation, and the \textsc{xlst2} language
%   to transform the \textsc{xml} file into the pairs
%   of {\ttfamily{}.dtx} and {\ttfamily{}.ins}
%   files traditionally used for \LaTeX{} class and package
%   installation. There are several advantages to this
%   approach:\par
% \begin{itemize}
% \item \textsc{xml}’s syntax and document
%       construction is extremely robust, and the design of the
%       language means that an \textsc{xml} file can
%       be machine-checked for errors of syntax and
%       construction at the editing stage;
% \item \textsc{xml} markup is traditionally
%       self-descriptive, with element types being named
%       according to what they are intended to
%       contain.\footnote{%
% This approach has long been a source of
%   philosophical contention, however; see \textcite{holman2013} and
%   \textcite{kay2013}.\par} For example, in
%       \emph{DocBook}, a variable name (for
%       example a \LaTeX{} length like \DescribeLength{pagelen}{\ttfamily{}\textbackslash{}pagelen}) can be marked up as
%       \verb|<varname role="length">pagelen</varname>|\thinspace, and
%       Doc\TeX{} can flag it (unheralded, ie no backslash,
%       dollar sign, etc) in the margin.\par
% (While it is perfectly possible to create a
%       {\ttfamily{}\textbackslash{}varname} control sequence (macro) to
%       do the same in \LaTeX{}, it is rarely done by authors.
%       Instead, authors have typically preferred to use visual
%       formatting like \verb|\textit{foo}|
%       for italics or \verb|\verb+foo+| for
%       monospace type. This method means the variable reference
%       is not immediately identifiable programmatically as
%       containing a variable name — it could be
%       anything.);
% \item Given suitably-descriptive markup and a modular
%       construction, sharing document fragments between
%       applications can be done programmatically. Thus a
%       fragment implementing a \LaTeX{} feature (with its
%       associated documentation) can be re-used in other class
%       and package applications \emph{at the
% \textsc{xml} level} (eg with
%       XInclude, or as an external parsed entity) without the
%       need for manual cutting and pasting, and with the
%       assurance that the latest version is always being
%       included;
% \item \label{xmltools}There is a very wide range of software (editors and
%       processors, both free and non-free) available to handle
%       \textsc{xml} documents, including a lot of
%       useful tools for validation, document management, and
%       information extraction.
% \end{itemize}
% Everything comes at a cost. The drawbacks of using
%   \textsc{xml} for this include:\par
% \begin{itemize}
% \item It’s another language to learn. Despite being so
%       widespread, \textsc{xml} and
%       \textsc{xslt} are not yet common skills in
%       either the programmer community or the \LaTeX{} community
%       of package authors or maintainers;
% \item Programmers in particular believe they dislike
%       [`document']
%       \textsc{xml} because it’s a markup language,
%       not a programming language (although
%       \textsc{xsl} is implemented in
%       \textsc{xml}), and the syntax is different
%       from that of most programming languages.\par
% (There is a cure for this: ask them to write their
%       thesis in \textsc{json} and
%       \textsc{xml} and judge which one is more
%       suitable.);
% \item Although there is plenty of software for editing
%       \textsc{xml}, it is not well-developed for
%       writing or editing text documents in synchronous
%       typographic form (often misleadingly called
%       \textsc{wysiwyg}) \parencite{flynn2014}; despite many recent advances,
%       even the best or most expensive editors are designed for
%       \textsc{xml} experts, not for the average user
%     \parencite{flynn2009} and not even for the
%       sophisticated user like a \LaTeX{} class or package
%       author or maintainer.
% \end{itemize}
% The \emph{ClassPack} framework is
%     enabled by three main software components:\par
% \begin{enumerate}
% \item An \textsc{xml} vocabulary (a
%       \hyperref[DTD]{\textsc{dtd}}\index{DTD}) used for naming the
%       component parts of documentation and code, and
%       specifying where they belong and how they fit together.
%       This is implemented in the file
%       {\ttfamily{}doctexbook.dtd}\thinspace, which is a
%       lightly-modified \emph{DocBook5}
%       documented in \vref{xmldesc} and \vref{dtdchanges};
% \item An \textsc{xslt} script to implement the
%       logic of combination and separation needed to create the
%       {\ttfamily{}.dtx} and {\ttfamily{}.ins}
%       files. This is implemented in the files
%       {\ttfamily{}db2dtx.xsl}\thinspace,
%       {\ttfamily{}db2bibtex.xsl}\thinspace,
%       {\ttfamily{}figtab2latex.xsl}\thinspace, and
%       {\ttfamily{}db2md.xsl}\thinspace, annotated in the
%       Appendices and explained throughout this document;
% \item A lookup table of commonly-used \LaTeX{} packages,
%       with brief descriptions, setup commands, and an optional
%       set of dependency specifications to automate their
%       invocation with the
%       \emph{AutoPackage} feature. This in
%       essence a database implemented as the
%       \textsc{xml} file
%       {\ttfamily{}prepost.xml}\thinspace, and  documented in
%       \vref{autospec}.\par
% This file can be edited by individual class/package
%       authors or maintainers to reflect their personal tastes
%       and way of working.
% \end{enumerate}
% \subsubsection{Use of XML}\label{xmldesc}
% The \textsc{xml} vocabulary used is
%     \emph{DocBook} \parencite{docbook5}, which is in widespread use for the
%     documentation of computer systems, and is well-supported
%     on all platforms. The current
%     \emph{ClassPack} system uses
%     version 5. Although it is highly modular and easily
%     adapted for many purposes, only a few minor changes have
%     been made for its use, but a number of element types have
%     been put to uses not envisaged by the developers. The
%     current version implements only a \hyperref[DTD]{\textsc{dtd}}\index{DTD};
%     a future version will also use \textsc{rng}, and
%     will create a customisation layer to replace the current
%     \hyperref[DTD]{\textsc{dtd}}\index{DTD} shim.\par
% This habit of using (some say, abusing)
%     \textsc{xml} markup for different purposes than
%     intended is very common, and widely deprecated because it
%     is usually undocumented and because the resulting schema
%     is arguably not the type of document the original
%     designer[s] envisaged. This document explains in \vref{cpdtddoc} what has been [ab]used and for what
%     reasons. Once \emph{ClassPack} settles
%     down, a more formal expression of the vocabulary can be
%     made from the \textsc{rng} source, removing the
%     parts that are not required, and making it simpler to edit
%     with.\par
% The adaptation of \emph{DocBook}
%     in this version subsists mainly in the addition of some
%     attributes and entity declarations to allow the conversion
%     to \LaTeX{} of special characters and other features that
%     would otherwise involve extensive re-parsing of the
%     character data content (text). The changes also implement
%     a few modifications to the way the \LaTeX{} code is output
%     by the \textsc{xslt} script for typographical
%     purposes.\par
% The modifications to the \hyperref[DTD]{\textsc{dtd}}\index{DTD}
%     explained below are annotated in \vref{cpdtddoc}, and the file is extracted as
%     {\ttfamily{}doctexbook.dtd} when processing this
%     document class, and it can be referenced as such in your
%     \emph{ClassPack} documents (see
%     \vref{invocation}).\par
% \subsubsection{Changes to the DocBook DTD}\label{dtdchanges}
% The changes to the \emph{DocBook5} \hyperref[DTD]{\textsc{dtd}}\index{DTD} are mainly to enable the
%     reinterpretation of some element types and attributes for
%     use in the Doc\TeX{} environment. They also add some
%     aspects of linking, cross-referencing, annotating, and
%     formatting that are not normally provided for in
%     \emph{DocBook}.\par
% \par\begingroup
%   \fboxsep1em\centering
%   \fbox{\begin{minipage}{0.8\columnwidth}\sffamily
%  \raggedright\parindent0pt
%  \parskip=.5\baselineskip
% Some of the changes should be considered
%       `tag-abuse', as they hijack existing
%       attributes for unconventional purposes. A separate and
%       more fundamental set of changes is planned for a future
%       date, using a shim for \textsc{rng}.\par
% \end{minipage}}\par\endgroup
% \begin{enumerate}
% \item \texttt{<html:form>}\index{html:form=\texttt{\char'074 html:form\char'076 } (element)}\index{elements:!html:form=\texttt{\char'074 html:form\char'076 }} is not used;
% \item \label{yyyy-mm-dd}The \texttt{<date>}\index{date=\texttt{\char'074 date\char'076 } (element)}\index{elements:!date=\texttt{\char'074 date\char'076 }}, \texttt{<year>}\index{year=\texttt{\char'074 year\char'076 } (element)}\index{elements:!year=\texttt{\char'074 year\char'076 }},
% \texttt{<confdates>}\index{confdates=\texttt{\char'074 confdates\char'076 } (element)}\index{elements:!confdates=\texttt{\char'074 confdates\char'076 }}, and \texttt{<biblioid>}\index{biblioid=\texttt{\char'074 biblioid\char'076 } (element)}\index{elements:!biblioid=\texttt{\char'074 biblioid\char'076 }} element
% types get a mandatory \texttt{@YYYY-MM-DD}\index{YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD} (attribute)}\index{attributes:!YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD}} attribute
% (suffixed {\ttfamily{}-from} and
% {\ttfamily{}-to} in the case of conference
% dates), so the elements {\sffamily \textsc{should be}} used \texttt{EMPTY}\index{EMPTY=\texttt{EMPTY} (local name)}\index{local names:!EMPTY=\texttt{EMPTY}} (content
% will be ignored). The attribute value
% {\sffamily \textsc{must}} be a valid
% \textsc{iso} 8601 date. For
% \texttt{<biblioid>}\index{biblioid=\texttt{\char'074 biblioid\char'076 } (element)}\index{elements:!biblioid=\texttt{\char'074 biblioid\char'076 }} this is the date the resource was
% retrieved;
% \item The \texttt{<blockquote>}\index{blockquote=\texttt{\char'074 blockquote\char'076 } (element)}\index{elements:!blockquote=\texttt{\char'074 blockquote\char'076 }} and \texttt{<quote>}\index{quote=\texttt{\char'074 quote\char'076 } (element)}\index{elements:!quote=\texttt{\char'074 quote\char'076 }}
% element types get optional \texttt{@units}\index{units=\texttt{\char'100 units} (attribute)}\index{attributes:!units=\texttt{\char'100 units}}, \texttt{@begin}\index{begin=\texttt{\char'100 begin} (attribute)}\index{attributes:!begin=\texttt{\char'100 begin}}, and \texttt{@end}\index{end=\texttt{\char'100 end} (attribute)}\index{attributes:!end=\texttt{\char'100 end}} attributes for
% specifying page or other ranges when a citation key is
% provided in \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}}, eg
% {\ttfamily{}units="p" begin="22" end="34"}\thinspace;
% \item The \texttt{<xref>}\index{xref=\texttt{\char'074 xref\char'076 } (element)}\index{elements:!xref=\texttt{\char'074 xref\char'076 }} and \texttt{<biblioref>}\index{biblioref=\texttt{\char'074 biblioref\char'076 } (element)}\index{elements:!biblioref=\texttt{\char'074 biblioref\char'076 }}
% element types’ attribute \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} is changed from
% \texttt{<IDREF>}\index{IDREF=\texttt{\char'074 IDREF\char'076 } (element)}\index{elements:!IDREF=\texttt{\char'074 IDREF\char'076 }} to \texttt{<IDREFS>}\index{IDREFS=\texttt{\char'074 IDREFS\char'076 } (element)}\index{elements:!IDREFS=\texttt{\char'074 IDREFS\char'076 }} to allow
% multiple citations at a single point;
% \item The \texttt{<bibliography>}\index{bibliography=\texttt{\char'074 bibliography\char'076 } (element)}\index{elements:!bibliography=\texttt{\char'074 bibliography\char'076 }} element type is given
% a \texttt{@label}\index{label=\texttt{\char'100 label} (attribute)}\index{attributes:!label=\texttt{\char'100 label}} and \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} for the name of
% the reference style and any ancillary style file name,
% respectively.\par
% \item On the \texttt{<biblioentry>}\index{biblioentry=\texttt{\char'074 biblioentry\char'076 } (element)}\index{elements:!biblioentry=\texttt{\char'074 biblioentry\char'076 }} element type, an
% \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute is
% mandatory, and the \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} attribute
% {\sffamily \textsc{must}} contain one of the
% valid \textsf{biblatex} entry types;
% \item For code annotations, the \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }}
% element type has a mandatory \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute to provide
% the type of object being documented. See the list in \vref{annotypes} for a list of values. The name
% of the object being documented
% {\sffamily \textsc{must}} be given in the
% \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} attribute, and
% a new attribute \texttt{@reuse}\index{reuse=\texttt{\char'100 reuse} (attribute)}\index{attributes:!reuse=\texttt{\char'100 reuse}} is
% added to provide the \texttt{<IDREFS>}\index{IDREFS=\texttt{\char'074 IDREFS\char'076 } (element)}\index{elements:!IDREFS=\texttt{\char'074 IDREFS\char'076 }} of annotations
% to copy from elsewhere (see \vref{reuse});
% \item The \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} element type now has
% an \texttt{@endinglinenumber}\index{endinglinenumber=\texttt{\char'100 endinglinenumber} (attribute)}\index{attributes:!endinglinenumber=\texttt{\char'100 endinglinenumber}}
% attribute for reference to segments of an external
% file being annotated;
% \item The \texttt{<remark>}\index{remark=\texttt{\char'074 remark\char'076 } (element)}\index{elements:!remark=\texttt{\char'074 remark\char'076 }} element type (used for
% flagging changes) has mandatory \texttt{@version}\index{version=\texttt{\char'100 version} (attribute)}\index{attributes:!version=\texttt{\char'100 version}} and \texttt{@revision}\index{revision=\texttt{\char'100 revision} (attribute)}\index{attributes:!revision=\texttt{\char'100 revision}} attributes which
% {\sffamily \textsc{must}} match a version
% number and a revision date in the revision
% history;
% \item A list of computer languages supported by the
% \textsf{listings} package (as extended in the
% {\ttfamily{}prepost.xml} database) is defined, and
% applied as a \texttt{@language}\index{language=\texttt{\char'100 language} (attribute)}\index{attributes:!language=\texttt{\char'100 language}}
% attribute on \texttt{<classname>}\index{classname=\texttt{\char'074 classname\char'076 } (element)}\index{elements:!classname=\texttt{\char'074 classname\char'076 }},
% \texttt{<cmdsynopsis>}\index{cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 } (element)}\index{elements:!cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 }}, \texttt{<command>}\index{command=\texttt{\char'074 command\char'076 } (element)}\index{elements:!command=\texttt{\char'074 command\char'076 }},
% \texttt{<envar>}\index{envar=\texttt{\char'074 envar\char'076 } (element)}\index{elements:!envar=\texttt{\char'074 envar\char'076 }}, \texttt{<function>}\index{function=\texttt{\char'074 function\char'076 } (element)}\index{elements:!function=\texttt{\char'074 function\char'076 }},
% \texttt{<literal>}\index{literal=\texttt{\char'074 literal\char'076 } (element)}\index{elements:!literal=\texttt{\char'074 literal\char'076 }}, \texttt{<literallayout>}\index{literallayout=\texttt{\char'074 literallayout\char'076 } (element)}\index{elements:!literallayout=\texttt{\char'074 literallayout\char'076 }},
% \texttt{<option>}\index{option=\texttt{\char'074 option\char'076 } (element)}\index{elements:!option=\texttt{\char'074 option\char'076 }}, \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }},
% \texttt{<screen>}\index{screen=\texttt{\char'074 screen\char'076 } (element)}\index{elements:!screen=\texttt{\char'074 screen\char'076 }}, \texttt{<varname>}\index{varname=\texttt{\char'074 varname\char'076 } (element)}\index{elements:!varname=\texttt{\char'074 varname\char'076 }}, and
% \texttt{<parameter>}\index{parameter=\texttt{\char'074 parameter\char'076 } (element)}\index{elements:!parameter=\texttt{\char'074 parameter\char'076 }} element types. The default value
% is {\ttfamily{}LaTeXe} (warning: not
% {\ttfamily{}LaTeX});
% \item The \texttt{<varname>}\index{varname=\texttt{\char'074 varname\char'076 } (element)}\index{elements:!varname=\texttt{\char'074 varname\char'076 }} element type gets a \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute to hold the
% type of variable being documented
% ({\ttfamily{}counter}\thinspace,
% {\ttfamily{}length}\thinspace,
% {\ttfamily{}prog}\thinspace,
% {\ttfamily{}color}\thinspace,
% {\ttfamily{}template}\thinspace,
% {\ttfamily{}variable}\thinspace,
% {\ttfamily{}parameter}\thinspace,
% {\ttfamily{}field}\thinspace, and
% {\ttfamily{}entrytype});
% \item The \texttt{<type>}\index{type=\texttt{\char'074 type\char'076 } (element)}\index{elements:!type=\texttt{\char'074 type\char'076 }} element type is hijacked
% wholesale to handle typographic variance for use in
% annotating typographic changes. Eight attributes are
% added:\par
% \begin{enumerate}[noitemsep]
% \item \texttt{@fontencoding}\index{fontencoding=\texttt{\char'100 fontencoding} (attribute)}\index{attributes:!fontencoding=\texttt{\char'100 fontencoding}}
%     ({\ttfamily{}T1}\thinspace,
%     {\ttfamily{}OT1}\thinspace,
%     {\ttfamily{}U}) as the only ones
%     needing to change from the default;
% \item \texttt{@fontface}\index{fontface=\texttt{\char'100 fontface} (attribute)}\index{attributes:!fontface=\texttt{\char'100 fontface}} is
%     \emph{either} a
%     `Karl Berry\index{Berry!Karl}'
%     typeface name (see the \textsf{fontname}
%     package for details) \emph{or} the
%     name of a typeface to be used locally;
% \item \texttt{@fontfamily}\index{fontfamily=\texttt{\char'100 fontfamily} (attribute)}\index{attributes:!fontfamily=\texttt{\char'100 fontfamily}} is one
%     of {\ttfamily{}roman}\thinspace,
%     {\ttfamily{}sans}\thinspace, or
%     {\ttfamily{}monospace}\thinspace;
% \item \texttt{@fontseries}\index{fontseries=\texttt{\char'100 fontseries} (attribute)}\index{attributes:!fontseries=\texttt{\char'100 fontseries}} is one
%     of \verb+k|r|m|n|b|bx|it|sl|l|c+
%     as defined in the \textsf{fontname}
%     package;
% \item \texttt{@fontshape}\index{fontshape=\texttt{\char'100 fontshape} (attribute)}\index{attributes:!fontshape=\texttt{\char'100 fontshape}} is one
%     of {\ttfamily{}up}\thinspace,
%     {\ttfamily{}it}\thinspace, or
%     {\ttfamily{}sc}\thinspace;
% \item \texttt{@fontsize}\index{fontsize=\texttt{\char'100 fontsize} (attribute)}\index{attributes:!fontsize=\texttt{\char'100 fontsize}} is a
%     size in a dimension known to \LaTeX{};
% \item \texttt{@fontalign}\index{fontalign=\texttt{\char'100 fontalign} (attribute)}\index{attributes:!fontalign=\texttt{\char'100 fontalign}} is
%     {\ttfamily{}yes} or
%     {\ttfamily{}no} (default is no,
%     currently unused);
% \item \texttt{@fontcolor}\index{fontcolor=\texttt{\char'100 fontcolor} (attribute)}\index{attributes:!fontcolor=\texttt{\char'100 fontcolor}} is a
%     color name known to the \textsf{xcolor}
%     package or defined earlier in the document.
% \end{enumerate}
% \item The \texttt{<seglistitem>}\index{seglistitem=\texttt{\char'074 seglistitem\char'076 } (element)}\index{elements:!seglistitem=\texttt{\char'074 seglistitem\char'076 }} has an \texttt{@omit}\index{omit=\texttt{\char'100 omit} (attribute)}\index{attributes:!omit=\texttt{\char'100 omit}} attribute to specify
% temporary omission.
% \end{enumerate}
% A Parameter Entity switch is used to list both \LaTeX{}
%     and \hyperref[HTML]{\textsc{html}}\index{HTML} expansions of a long list of
%     character entities.\par
% \clearpage
% \section{Setting up a \emph{ClassPack}
% document}\label{setupcp}
% Using \emph{ClassPack} to create and
% maintain \LaTeX{} classes and packages requires the following
% initial steps. These are only done once, at the start of a new
% class or package.\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily\label{dirnames}
% In the current version it is
%       {\sffamily \textsc{essential}} that you keep
%       each class or package you manage in a separate
%       directory, named after the class or package.
%       Specifically, the directory name, the
%       \textsc{xml} filename, and the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} value of the root
%       element {\sffamily \textsc{must}} all be the
%       same name.\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% A file {\ttfamily{}template.xml} is provided to
% help you get started: it contains comments and
% `placeholder' values to help the
% construction of a new document. Create a new directory for the
% class or package, open {\ttfamily{}template.xml} in
% your \textsc{xml} editor, and save it with the same
% name and the filetype {\ttfamily{}.xml} in the new
% directory.\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily
% \subsubsection*{Tooling up}
% You need the following tools:\par% \begin{itemize}
% \item a full installation of \LaTeX{};
% \item this package;
% \item an \textsc{xml} editor: I use
%       \emph{Emacs} with
%       \emph{psgml-mode} and
%       \emph{xxml-mode}, but any competent
%       \textsc{xml} editor will do;
% \item a copy of the \emph{DocBook5} \textsc{dtd}\index{DTD} from \href{https://docbook.org/xml/5.0/dtd/}{\nolinkurl{https://docbook.org/xml/5.0/dtd/}}\thinspace;
% \item an \textsc{xslt} processor: I use
%       \emph{Saxon} (which in turn requires
%       \emph{Java});
% \item a \textsc{pdf} reader;
% \item some \textsc{xml} tools: I find the
%       \emph{LTxml2} toolkit from Edinburgh
%       University invaluable for ad-hoc querying of documents.
%       It also gets used in the
%       {\ttfamily{}Makefile}\thinspace.\par
% \end{itemize}
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% To start a new document, you
% {\sffamily \textsc{must}} set up:\par
% \begin{enumerate}
% \item the configuration (see \vref{setup}) to
%     specify the name, date, version, type, audience, status,
%     and other key values in the root element;
% \item the documentary metadata (see \vref{metadata}) such as the package title, author
%     name[s], contact details, abstract, and the initial entry
%     in the revision history, exactly as you would do for an
%     article or any document (including a
%     {\ttfamily{}.dtx} file) that you would edit
%     manually;
% \item two \emph{separate} lists of
%     packages:\par
% \begin{enumerate}[noitemsep]
% \item any packages you need for the documentation that
% will \emph{not} be invoked automatically
% by \emph{AutoPackage};
% \item \label{packlist}any packages needed by the class or package
% code itself.
% \end{enumerate}
% (see \vref{packages}). It is
%     \emph{essential} that these are set up
%     exactly.
% \end{enumerate}
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily
% Note that you do \emph{not} put the list
%   of packages required by the class or package itself (item~\ref{packlist} in the list on p.\thinspace\pageref{packlist}) as manual
%   {\ttfamily{}\textbackslash{}RequirePackage} commands in the annotated
%   code of your class or package. You give them separately, and
%   specify where in your code they are to be included, as
%   described in \vref{packages}.\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% You {\sffamily \textsc{may}} also provide any
% extra \LaTeX{} commands you need for your documentation (see
% \vref{addsetup}), although the introduction of the
% {\ttfamily{}prepost.xml} \emph{AutoPackage} database or lookup file
% lets you automate much of this.\par
% When you update a class or package already in
% \emph{ClassPack}, you need to
% change:\par
% \begin{enumerate}
% \item the version number and/or revision number in the root
%     element attributes \texttt{@version}\index{version=\texttt{\char'100 version} (attribute)}\index{attributes:!version=\texttt{\char'100 version}}
%     and \texttt{@revision}\index{revision=\texttt{\char'100 revision} (attribute)}\index{attributes:!revision=\texttt{\char'100 revision}} (see ‘\textbf{\textsf{\texttt{@version}\index{version=\texttt{\char'100 version} (attribute)}\index{attributes:!version=\texttt{\char'100 version}}}}’\vpageref{verno});
% \item the corresponding \texttt{@version}\index{version=\texttt{\char'100 version} (attribute)}\index{attributes:!version=\texttt{\char'100 version}}
%     attribute on the relevant \texttt{<revision>}\index{revision=\texttt{\char'074 revision\char'076 } (element)}\index{elements:!revision=\texttt{\char'074 revision\char'076 }} element in
%     the revision history to match the version and revision
%     above (see ‘\textbf{\textsf{\texttt{<revhistory>}\index{revhistory=\texttt{\char'074 revhistory\char'076 } (element)}\index{elements:!revhistory=\texttt{\char'074 revhistory\char'076 }}}}’\vpageref{revhist});
% \item the Doc\TeX{} checksum in the root element \texttt{@security}\index{security=\texttt{\char'100 security} (attribute)}\index{attributes:!security=\texttt{\char'100 security}} attribute, if
%     used (see ‘\textbf{\textsf{\texttt{@security}\index{security=\texttt{\char'100 security} (attribute)}\index{attributes:!security=\texttt{\char'100 security}}}}’\vpageref{checksum}).
% \end{enumerate}
% If these values do not all match, the class or package
% will not build.\par
% \subsection{XML editing}\label{invocation}
% To create or edit a \emph{ClassPack}
%   XML document you {\sffamily \textsc{must}} have a
%   copy of the \emph{DocBook5} Document Type Definition\phantomsection\label{DTD} ({\small\raisebox{-.5ex}{\textcolor{Red}{\HandRight}}}\textsc{dtd})\index{Document Type Definition|see{DTD}}\index{DTD|textbf} \emph{and} the
%   \emph{ClassPack} \textsc{dtd}\index{DTD}
%   customisation shim ({\ttfamily{}doctexbook.dtd})
%   installed on your computer in a location that is known to or
%   visible to your \textsc{xml} editor. See your
%   editor’s documentation for how to do this — the
%   {\ttfamily{}template.xml} file assumes that the
%   {\ttfamily{}doctexbook.dtd} file is in the directory
%   (folder) \emph{above} the document you are
%   editing (see the note in \vref{dirnames}).\par
% \begin{enumerate}
% \item The \emph{DocBook5} \textsc{dtd}\index{DTD} can be downloaded from the \href{https://docbook.org/xml/5.0/dtd/docbook.dtd}{DocBook 
% web site}\thinspace;
% \item The file {\ttfamily{}doctexbook.dtd} is
%       included with this \textsf{classpack}
%       package.
% \end{enumerate}
% In extreme cases putting the \textsc{dtd}\index{DTD}s in
%   the same directory as your
%   \emph{ClassPack} document will work if
%   you edit its location in the Document Type Declaration (the
%   line beginning \verb|<!DOCTYPE book|),
%   but it means you would need a separate copy in every class
%   or package directory you maintain.\par
% The Document Type Declaration illustrated below is for
%   reference only: the included file
%   {\ttfamily{}template.xml} already has this set up,
%   but you {\sffamily \textsc{must}} edit the
%   location of the \textsc{dtd}\index{DTD} shim
%   {\ttfamily{}doctexbook.dtd} to be wherever you keep
%   it on your system, and edit that file to specify whereabouts
%   the main {\ttfamily{}docbook.dtd} file is on your
%   system.\par
% Your class or package documents
%   {\sffamily \textsc{should}} start with the
%   \textsc{xml} Declaration giving the version of
%   \textsc{xml} as \texttt{"1.0"}\index{1.0=\texttt{"1.0"} (attribute value)}\index{attribute values:!1.0=\texttt{"1.0"}}.
%   With a \textsc{dtd}\index{DTD}, you
%   {\sffamily \textsc{must}} give the
%   \textbf{\emph{Document Type Declaration}}\index{Document Type Declaration|textbf} on the next
%   line of your \textsc{xml} file. If your
%   \textsc{xml} editor omits the
%   \textsc{xml} Declaration, then your Document Type
%   Declaration will of course be the first line of the file.
%   There are two forms for expressing the Document Type
%   Declaration (different editors may use one or the
%   other):\par
% \begin{description}[style=unboxed]
% \item[\emph{either}:]with the \texttt{PUBLIC}\index{PUBLIC=\texttt{PUBLIC} (local name)}\index{local names:!PUBLIC=\texttt{PUBLIC}}
% keyword and the Formal Public
%   Identifier\phantomsection\label{FPI} ({\small\raisebox{-.5ex}{\textcolor{Red}{\HandRight}}}\textsc{fpi})\index{Formal Public Identifier|see{FPI}}\index{FPI|textbf} shown, plus the system filename
% of the \textsc{dtd}\index{DTD}:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<?xml version="1.0"?>
<!DOCTYPE book PUBLIC 
  "+//Silmaril//DTD DocBook 5.0 for DocTeX ClassPack//EN" 
  "../doctexbook.dtd">
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% \item[\emph{or}:]you can omit the \textsc{fpi}\index{FPI} and
% specify the \textsc{dtd}\index{DTD} after the \texttt{SYSTEM}\index{SYSTEM=\texttt{SYSTEM} (local name)}\index{local names:!SYSTEM=\texttt{SYSTEM}} keyword:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<?xml version="1.0"?>
<!DOCTYPE book SYSTEM "../doctexbook.dtd">
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% \end{description}
% The \textsc{dtd}\index{DTD} file
%   {\ttfamily{}doctexbook.dtd} can be anywhere on your
%   system, provided your editor is capable of reading it: in
%   these examples it is assumed to be in the directory above
%   the one where your document is. If you store it elsewhere,
%   just give the full filepath, for example:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<?xml version="1.0"?>
<!DOCTYPE book SYSTEM "/usr/local/lib/xml/dtds/doctexbook.dtd">
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% You will also need to edit the location of the
%   \emph{DocBook} \textsc{dtd}\index{DTD} in
%   your copy of {\ttfamily{}doctexbook.dtd} because it
%   will be in a different place on your system. The
%   distribution file says:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<!ENTITY % db5dtd SYSTEM
         "/dtds/docbook/docbook-5.0/dtd/docbook.dtd">
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% Just change this to wherever your copy is stored.\par
% Now when you open your document, any conformant
%   \textsc{xml} editor will find the
%   {\ttfamily{}doctexbook.dtd} and read it, so that it
%   then knows the names of all the element types that you can
%   use, and how they fit together into a document, and will
%   create menus for adding markup as you write.\par
% \subsection{\emph{ClassPack} document
%   structure}\label{struct}
% Every \textsc{xml} document
%   {\sffamily \textsc{must}} have one outermost
%   enclosing element (the `root'
%   element) which contains everything else. The root element
%   type used in a \emph{ClassPack} document
%   is \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (start-tag)}\index{start-tags:!book=\texttt{\char'074 book\char'076}}, one of the built-in
%   document types provided by
%   \emph{DocBook}.\par
% Within the \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} element there are five main
%   areas:\par
% \begin{description}[style=unboxed]
% \item[configuration:]attributes on the \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} element itself
% which hold the configuration data for your class or
% package; see \vref{setup}.\par
% \item[metadata:](information \emph{about} the
% document) is held in an \texttt{<info>}\index{info=\texttt{\char'074 info\char'076 } (start-tag)}\index{start-tags:!info=\texttt{\char'074 info\char'076}} subelement; see \vref{metadata};
% \item[user documentation:]is held in a \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (start-tag)}\index{start-tags:!part=\texttt{\char'074 part\char'076}}
% element with the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}}
% attribute \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}}; see
% \vref{userdoc};
% \item[annotated code:]is held in a second \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (start-tag)}\index{start-tags:!part=\texttt{\char'074 part\char'076}} element, with the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}}; see \vref{annocode};
% \item[\emph{unannotated} ancillary files:]{\sffamily \textsc{optional}}; are held
% in a third \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (start-tag)}\index{start-tags:!part=\texttt{\char'074 part\char'076}} element
% with the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute
% \texttt{"files"}\index{files=\texttt{"files"} (attribute value)}\index{attribute values:!files=\texttt{"files"}}. These are files
% that are to be recreated as-is when the package or
% class is installed by a user, such as sample data or
% example documents (see \vref{ancfiles}).\par
% \end{description}
% The two \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (start-tag)}\index{start-tags:!part=\texttt{\char'074 part\char'076}} elements with
%   the specific ID values \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}} and
%   \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}} are
%   {\sffamily \textsc{compulsory}} and
%   {\sffamily \textsc{must}} occur exactly once each
%   only.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<?xml version="1.0"?>
<!DOCTYPE book SYSTEM "doctexbook.dtd">
<book xml:id="...">
  <info coverart="">...</info>
  <part xml:id="doc">...</part>
  <part xml:id="code">...</part>
  <part xml:id="files">...</part>
</book>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% Within each \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }}, there is a specific
%   structure used:\par
% \begin{description}[style=unboxed]
% \item[doc:]can use prefaces, chapters, sections, subsections,
% tables, figures, paragraphs, lists, block quotes,
% cross-references, bibliographic references, etc as any
% normal text document does;
% \item[code:]your principal class or package goes in one or
% more \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} elements; any additional
% \emph{annotated} files each go in
% separate \texttt{<appendix>}\index{appendix=\texttt{\char'074 appendix\char'076 } (element)}\index{elements:!appendix=\texttt{\char'074 appendix\char'076 }} elements;
% \item[files:]each \emph{unannotated} file goes in
% its own \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} element.
% \end{description}
% \subsection{Configuration for a new class or package}\label{setup}
% The \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} element is the outermost container
%   for the document. Its attributes are used to carry the
%   configuration information, for example:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML,emph={xml:id,version,xml:base,remap,arch,audience,condition,conformance,os,revision,security,userlevel,vendor,annotations,xlink:role}]
<book xml:id="classpack" version="1" xml:base="classpack"
  remap="12pt" arch="package" audience="lppl" condition="2015-01-01"
  conformance="LaTeX2e" os="all" revision="10" security="259"
  userlevel="sty" vendor="Silmaril Consultants"
  annotations="\raggedright" xlink:role="">
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% \begin{description}[style=unboxed]
% \item[\texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}}:]\label{rootid}This {\sffamily \textsc{must}} be the
% one-word name of the class or package. It will be used
% as the \LaTeX{} filename (with
% {\ttfamily{}.cls} or {\ttfamily{}.sty}
% and {\ttfamily{}.dtx} and
% {\ttfamily{}.ins} added automatically), so it
% {\sffamily \textsc{should}} by preference be
% all lowercase and {\sffamily \textsc{must}}
% consist of letters, digits, and hyphens only, starting
% with a letter. Spaces and other types of character are
% not allowed here.\par
% The \textsc{xml} rules for IDs require
% this restriction, which means
% \emph{ClassPack} cannot be used
% to maintain a class or packages whose
% name begins with a digit.\par
% \item[\texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}}:]\label{arch}The `architecture' of the
% document, which defines the type of file you are going
% to produce; this {\sffamily \textsc{must}}
% be either \texttt{"class"}\index{class=\texttt{"class"} (attribute value)}\index{attribute values:!class=\texttt{"class"}}, \texttt{"package"}\index{package=\texttt{"package"} (attribute value)}\index{attribute values:!package=\texttt{"package"}} or \texttt{"script"}\index{script=\texttt{"script"} (attribute value)}\index{attribute values:!script=\texttt{"script"}}. This
% {\sffamily \textsc{must}} correspond with
% the value of the \texttt{<userlevel>}\index{userlevel=\texttt{\char'074 userlevel\char'076 } (element)}\index{elements:!userlevel=\texttt{\char'074 userlevel\char'076 }} attribute below,
% which provides the filetype.\par
% \item[\texttt{@userlevel}\index{userlevel=\texttt{\char'100 userlevel} (attribute)}\index{attributes:!userlevel=\texttt{\char'100 userlevel}}:]\label{userlevel}The filetype of the output class or package
% document or script; this
% {\sffamily \textsc{must}} correspond with
% the value of the \texttt{<arch>}\index{arch=\texttt{\char'074 arch\char'076 } (element)}\index{elements:!arch=\texttt{\char'074 arch\char'076 }} attribute above, and
% be either \texttt{"cls"}\index{cls=\texttt{"cls"} (attribute value)}\index{attribute values:!cls=\texttt{"cls"}}, \texttt{"sty"}\index{sty=\texttt{"sty"} (attribute value)}\index{attribute values:!sty=\texttt{"sty"}}, or a script language
% extension such as \texttt{"bash"}\index{bash=\texttt{"bash"} (attribute value)}\index{attribute values:!bash=\texttt{"bash"}} (the
% Bourne-Again Shell, the only value supported in this
% version), \texttt{"py"}\index{py=\texttt{"py"} (attribute value)}\index{attribute values:!py=\texttt{"py"}}
% (\emph{Python}), \texttt{"pl"}\index{pl=\texttt{"pl"} (attribute value)}\index{attribute values:!pl=\texttt{"pl"}}
% (\emph{Perl}), etc.\par
% \item[\texttt{@version}\index{version=\texttt{\char'100 version} (attribute)}\index{attributes:!version=\texttt{\char'100 version}}:]\label{verno}The major version of the class, package, or
% script. Conventionally, early-development
% (\(\alpha\)) or pre-release (\(\beta\)) versions of software start at
% version zero. See \texttt{<status>}\index{status=\texttt{\char'074 status\char'076 } (element)}\index{elements:!status=\texttt{\char'074 status\char'076 }} below;
% \item[\texttt{@revision}\index{revision=\texttt{\char'100 revision} (attribute)}\index{attributes:!revision=\texttt{\char'100 revision}}:]\label{revno}The sub-version or release of your class or
% package or script. This is combined with the major
% version number above, separated by a dot, to produce the
% complete version number.\par
% The most recent revision history entry gets tested
% against this when the file is processed, and an error
% message is displayed if the version numbers do not
% match, as a warning that you have updated one without
% updating the other, and may therefore have forgotten
% to document a change (see the \texttt{<revision>}\index{revision=\texttt{\char'074 revision\char'076 } (element)}\index{elements:!revision=\texttt{\char'074 revision\char'076 }}
% element in ‘\textbf{\textsf{\texttt{<revhistory>}\index{revhistory=\texttt{\char'074 revhistory\char'076 } (element)}\index{elements:!revhistory=\texttt{\char'074 revhistory\char'076 }}}}’, the last item in the list in \vref{revhist}).\par
% \item[\texttt{@status}\index{status=\texttt{\char'100 status} (attribute)}\index{attributes:!status=\texttt{\char'100 status}}:]The development status of the class or package, eg
% \texttt{"alpha"}\index{alpha=\texttt{"alpha"} (attribute value)}\index{attribute values:!alpha=\texttt{"alpha"}}, \texttt{"beta"}\index{beta=\texttt{"beta"} (attribute value)}\index{attribute values:!beta=\texttt{"beta"}}, \texttt{"rc"}\index{rc=\texttt{"rc"} (attribute value)}\index{attribute values:!rc=\texttt{"rc"}} (release candidate), \texttt{"draft"}\index{draft=\texttt{"draft"} (attribute value)}\index{attribute values:!draft=\texttt{"draft"}}, \texttt{"final"}\index{final=\texttt{"final"} (attribute value)}\index{attribute values:!final=\texttt{"final"}}, etc. Use the letter
% `p' for production
% versions.\par
% \item[\texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}}:]The \TeX{} format required to process the
% {\ttfamily{}.dtx} document. Only the value
% \texttt{"LaTeX2e"}\index{LaTeX2e=\texttt{"LaTeX2e"} (attribute value)}\index{attribute values:!LaTeX2e=\texttt{"LaTeX2e"}} is supported at
% the moment.\par
% \item[\texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}}:]The version of the format identified in \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}}, expressed as an
% \textsc{iso} 8601 date
% ({\ttfamily{}yyyy-mm-dd}).\par
% Note that this is \emph{not} in the
% \LaTeX{} format
% ({\ttfamily{}yyyy/mm/dd}).\par
% \item[\texttt{@os}\index{os=\texttt{\char'100 os} (attribute)}\index{attributes:!os=\texttt{\char'100 os}}:]The operating system[s] for which the class or
% package is relevant. Currently, only the value \texttt{"all"}\index{all=\texttt{"all"} (attribute value)}\index{attribute values:!all=\texttt{"all"}} is supported.\par
% \item[\texttt{@audience}\index{audience=\texttt{\char'100 audience} (attribute)}\index{attributes:!audience=\texttt{\char'100 audience}}:]The licence under which the class or package is
% made available. For normal publicly-available \LaTeX{}
% classes or packages which will be uploaded to the
% Comprehensive \TeX{} Archive
%   Network\phantomsection\label{CTAN} ({\small\raisebox{-.5ex}{\textcolor{Red}{\HandRight}}}\textsc{ctan})\index{Comprehensive \TeX{} Archive Network|see{CTAN}}\index{CTAN|textbf}, use the value \texttt{"lppl"}\index{lppl=\texttt{"lppl"} (attribute value)}\index{attribute values:!lppl=\texttt{"lppl"}} (\LaTeX{} Project Public
% Licence).\par
% A copy of the \textsc{lppl} (currently
% version 1.3c) is distributed with
% \emph{ClassPack} in a file called
% {\ttfamily{}lppl.xml}\thinspace, which must be copied or
% soft-linked (aliased) to each directory in which you
% process \emph{ClassPack}
% documents needing to use it.\par
% Classes or packages for private or commercial use
% will probably need to use another value, but the value
% is used as a filename, so a {\ttfamily{}.xml}
% file with that name
% {\sffamily \textsc{must}} exist in the
% directory in which your
% \emph{ClassPack} document is
% processed. It {\sffamily \textsc{must}}
% contain a \emph{DocBook} \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} element containing the text of the
% licence, which will be included at the end of the
% documentation. See the supplied
% {\ttfamily{}lppl.xml} as an example.\par
% \item[\texttt{@security}\index{security=\texttt{\char'100 security} (attribute)}\index{attributes:!security=\texttt{\char'100 security}}:]\label{checksum}The checksum value emitted by
% \textsf{ltxdoc} when it processes your class
% or package to format your documentation. See the
% documentation for the \textsf{ltxdoc} package for details.\par
% Setting this to zero avoids the \LaTeX{} error
% message during early development, when every edit
% would change the checksum. As with the version values,
% you {\sffamily \textsc{must}} update this
% value, if non-zero, to match the one that
% \textsf{ltxdoc} reports.\par
% \item[\texttt{@vendor}\index{vendor=\texttt{\char'100 vendor} (attribute)}\index{attributes:!vendor=\texttt{\char'100 vendor}}:]Your name, or the name of the organisation
% responsible for the work on this class or package.\par
% \item[\texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}}:]Any class options to pass to the
% \textsf{ltxdoc} package, such as
% \textbf{\texttt{a4paper}}, \textbf{\texttt{12pt}},
% etc.\par
% This, and the following \texttt{<annotations>}\index{annotations=\texttt{\char'074 annotations\char'076 } (element)}\index{elements:!annotations=\texttt{\char'074 annotations\char'076 }}
% attribute, make it easier to change the global
% formatting of the documentation.\par
% \item[\texttt{@annotations}\index{annotations=\texttt{\char'100 annotations} (attribute)}\index{attributes:!annotations=\texttt{\char'100 annotations}}:]Any \LaTeX{} commands required for global
% application at the start of the documentation that
% cannot easily be included anywhere else (eg
% {\ttfamily{}\textbackslash{}raggedright},
% {\ttfamily{}\textbackslash{}sffamily}, etc);
% \item[\texttt{@xml:base}\index{xml:base=\texttt{\char'100 xml:base} (attribute)}\index{attributes:!xml:base=\texttt{\char'100 xml:base}}:]The name of the \emph{subdirectory}
% where the resulting {\ttfamily{}.cls} or
% {\ttfamily{}.sty} file should be installed in
% a \textsc{tds}-compliant \TeX{} installation,
% \emph{relative to the
%   {\ttfamily{}texmf/tex/latex}
%   directory}. For most packages, this means
% the name of the directory you want created by the
% installation {\ttfamily{}.tds.zip} file, in
% which the {\ttfamily{}.cls} or
% {\ttfamily{}.sty} file will be put. This
% {\sffamily \textsc{should}} normally be the
% same as the name of the class or package, and
% therefore the same as the name of the ID value in the
% \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute
% above.\par
% \item[\texttt{@xlink:role}\index{xlink:role=\texttt{\char'100 xlink:role} (attribute)}\index{attributes:!xlink:role=\texttt{\char'100 xlink:role}}:]\label{selfspec}{\sffamily \textsc{optional}}. If this
% is present (null or non-null),
% \emph{and} the document being written is
% a package, not a class, then the package itself will
% be included in the \LaTeX{} Preamble for the
% documentation (usually so that it can be used in
% examples). If a value is given, it will be used as
% an optional argument to the generated
% {\ttfamily{}\textbackslash{}usepackage} command.\par
% If the package is required with no options, use
% this attribute but set it to null (eg \texttt{""}\index{=\texttt{""} (attribute value)}\index{attribute values:!=\texttt{""}}). The date constraint is
% added automatically, using the current package date as
% defined by the most recent entry in the
% \texttt{<revhistory>}\index{revhistory=\texttt{\char'074 revhistory\char'076 } (element)}\index{elements:!revhistory=\texttt{\char'074 revhistory\char'076 }} (see ‘\textbf{\textsf{\texttt{<revhistory>}\index{revhistory=\texttt{\char'074 revhistory\char'076 } (element)}\index{elements:!revhistory=\texttt{\char'074 revhistory\char'076 }}}}’, the last item in the list in \vref{revhist}).\par
% Note that this only works for packages, not
% classes. Classes cannot not be documented using
% themselves in \emph{ClassPack}.\par
% \end{description}
% It is essential to get these values correct, otherwise
%   subsequent processing will produce unexpected
%   results, or no results at all.\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily\label{moveproc}
% Note that the experimental use of \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} in earlier versions to
%     define the \LaTeX{} processor to be used for the
%     documentation has been moved to the \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} attribute on the
%     \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (start-tag)}\index{start-tags:!part=\texttt{\char'074 part\char'076}} start-tag for
%     documentation (see \vref{hierarchy}).\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% \subsection{Metadata}\label{metadata}
% The titling, specification of packages (separately for
%   the documentation and for the class or package itself),
%   revision history, abstract, copyright, and availability are
%   all kept at the top of the document in an element called
%   \texttt{<info>}\index{info=\texttt{\char'074 info\char'076 } (element)}\index{elements:!info=\texttt{\char'074 info\char'076 }}, immediately inside the \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (start-tag)}\index{start-tags:!book=\texttt{\char'074 book\char'076}} start-tag:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<info coverart="somepic.jpg">
  <cover>...</cover>
  <!-- THE METADATA STARTS HERE -->
  <title>XML mastering for &LaTeX; document classes...
  <author>...
  <copyright>...
  <releaseinfo>http://latex.silmaril.ie/packages/</releaseinfo>
  <annotation>...
  <abstract>...
  <revhistory>...
</info>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% Of these, the \texttt{<cover>}\index{cover=\texttt{\char'074 cover\char'076 } (element)}\index{elements:!cover=\texttt{\char'074 cover\char'076 }} element is the most
%   complex, as it is used to hold all the details of
%   packages and settings required for the class or package
%   \emph{and} for the production of the
%   documentation. It therefore gets the whole of
%   \vref{packages} to itself.\par
% The other metadata element types within the
%   \texttt{<cover>}\index{cover=\texttt{\char'074 cover\char'076 } (element)}\index{elements:!cover=\texttt{\char'074 cover\char'076 }} element are more obvious, and use the
%   conventional \emph{DocBook}
%   structure.\par
% \begin{description}[style=unboxed]
% \item[\texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }}:]This contains the title of your class or package in
% natural language.\par
% This is \emph{not} the content of
% the \LaTeX{} {\ttfamily{}\textbackslash{}title} command in the
% {\ttfamily{}.dtx} file, which is automatically
% preset to the standard phrase `The
%   \textsf{\uline{name}}
%   \LaTeXe{} document class' (or
% `package') where
% \uline{name} is the name of your
% class or package as specified in the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute of the
% \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} root element.\par
% The title you give in
% \emph{this}~\texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }}
% element is the explanatory
% \emph{subtitle} which appears
% \emph{under} the automatically-generated
% one on the first page of the typeset
% documentation.\par
% \item[\texttt{<author>}\index{author=\texttt{\char'074 author\char'076 } (element)}\index{elements:!author=\texttt{\char'074 author\char'076 }}:]The \texttt{<author>}\index{author=\texttt{\char'074 author\char'076 } (element)}\index{elements:!author=\texttt{\char'074 author\char'076 }} element provides identity
% markup for the author[s], using a
% \texttt{<personname>}\index{personname=\texttt{\char'074 personname\char'076 } (element)}\index{elements:!personname=\texttt{\char'074 personname\char'076 }} element for each author,
% containing subelements for firstname, surname, and
% other forms of naming; optionally followed by an
% \texttt{<affiliation>}\index{affiliation=\texttt{\char'074 affiliation\char'076 } (element)}\index{elements:!affiliation=\texttt{\char'074 affiliation\char'076 }} element, where you can identify
% employer or other status; address; email; and
% \textsc{uri}, as in the following example.
% The name, affiliation, and email address are used in
% the {\ttfamily{}\textbackslash{}author} command of the
% {\ttfamily{}.dtx} file.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<author role="maintainer">
  <personname>
    <firstname>Peter</firstname> 
    <surname>Flynn</surname>
  </personname>
  <affiliation>
    <orgname>Silmaril Consultants</orgname>
    <orgdiv>Textual Therapy Division</orgdiv>
  </affiliation>
  <address>Cork, Ireland</address>
  <email>peter@silmaril.ie</email>
  <uri>http://blogs.silmaril.ie/peter</uri>
  <contrib role="sponsor">UCC</contrib>
</author>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% For multiple authors, you must enclose multiple
% \texttt{<author>}\index{author=\texttt{\char'074 author\char'076 } (element)}\index{elements:!author=\texttt{\char'074 author\char'076 }} elements (one per author) in an
% \texttt{<authorgroup>}\index{authorgroup=\texttt{\char'074 authorgroup\char'076 } (element)}\index{elements:!authorgroup=\texttt{\char'074 authorgroup\char'076 }} container element, for example:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX}]
<authorgroup>
  <author role="maintainer">
    ...
  </author>
  <author>
    ...
  </author>
  ...etc...
</authorgroup>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% At least one
% of the authors must be identified as the maintainer of
% the package or class, by adding the \texttt{<role>}\index{role=\texttt{\char'074 role\char'076 } (element)}\index{elements:!role=\texttt{\char'074 role\char'076 }}
% attribute with the value \texttt{"maintainer"}\index{maintainer=\texttt{"maintainer"} (attribute value)}\index{attribute values:!maintainer=\texttt{"maintainer"}}.\par
% A \texttt{<contrib>}\index{contrib=\texttt{\char'074 contrib\char'076 } (element)}\index{elements:!contrib=\texttt{\char'074 contrib\char'076 }} element with a \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute set to \texttt{"sponsor"}\index{sponsor=\texttt{"sponsor"} (attribute value)}\index{attribute values:!sponsor=\texttt{"sponsor"}} can be added in an
% \texttt{<author>}\index{author=\texttt{\char'074 author\char'076 } (element)}\index{elements:!author=\texttt{\char'074 author\char'076 }} block, to give the
% name of an organisation sponsoring the development of
% the class or package.\par
% \item[\texttt{<copyright>}\index{copyright=\texttt{\char'074 copyright\char'076 } (element)}\index{elements:!copyright=\texttt{\char'074 copyright\char'076 }}:]This element lets you identify the \texttt{<year>}\index{year=\texttt{\char'074 year\char'076 } (element)}\index{elements:!year=\texttt{\char'074 year\char'076 }}
% and the name of the \texttt{<holder>}\index{holder=\texttt{\char'074 holder\char'076 } (element)}\index{elements:!holder=\texttt{\char'074 holder\char'076 }} (you, your
% employer, or some other entity).\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<copyright>
  <year YYYY-MM-DD="2020"/>
  <holder>ACME Consulting</holder>
</copyright>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% \item[\texttt{<releaseinfo>}\index{releaseinfo=\texttt{\char'074 releaseinfo\char'076 } (element)}\index{elements:!releaseinfo=\texttt{\char'074 releaseinfo\char'076 }}:]In the absence of other ways of identifying where
% to find your class or package (assuming it will
% eventually find its way onto \textsc{ctan}\index{CTAN}),
% this element can be used to hold the
% \textsc{uri} of a location where it can be
% downloaded, such as your personal or business web
% site.\par
% \item[\texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }}:]This element is used for a warning or notice you
% want placed in the Preamble of the
% {\ttfamily{}.ins} file, which is used for
% extracting your class or package from the
% {\ttfamily{}.dtx} file, where it will be seen
% by users installing the software.\par
% \par\begingroup
%   \fboxsep1em\centering
%   \fbox{\begin{minipage}{0.8\columnwidth}\sffamily
%  \raggedright\parindent0pt
%  \parskip=.5\baselineskip
% This use case of \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} in this
%   location is \emph{different} from the
%   one described in \vref{annotatedcode}.\par
% \end{minipage}}\par\endgroup
% \item[\texttt{<abstract>}\index{abstract=\texttt{\char'074 abstract\char'076 } (element)}\index{elements:!abstract=\texttt{\char'074 abstract\char'076 }}:]The Abstract is formatted on the front page of
% your documentation. Like any abstract, it should
% summarise what the class or package does, and who
% might want to use it.\par
% The \texttt{<abstract>}\index{abstract=\texttt{\char'074 abstract\char'076 } (element)}\index{elements:!abstract=\texttt{\char'074 abstract\char'076 }} element
% {\sffamily \textsc{may}} start with an
% optional \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }} element, which (if present)
% will be used to change the value of the
% {\ttfamily{}\textbackslash{}abstractname} in the
% {\ttfamily{}.dtx} file
% (`Summary' is a common
% choice).\par
% The rest of the abstract is basically just
% paragraphs; note that lists, block quotations,
% figures, tables, etc cannot be used in a
% \emph{DocBook} Abstract.\par
% \item[\texttt{<revhistory>}\index{revhistory=\texttt{\char'074 revhistory\char'076 } (element)}\index{elements:!revhistory=\texttt{\char'074 revhistory\char'076 }}:]\label{revhist}This holds the top-level information about each
% major and minor revision, outlining the main changes.
% The version number of the most recent revision, as
% identified by the latest value of the \texttt{@YYYY-MM-DD}\index{YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD} (attribute)}\index{attributes:!YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD}} attribute of the
% \texttt{<date>}\index{date=\texttt{\char'074 date\char'076 } (element)}\index{elements:!date=\texttt{\char'074 date\char'076 }} element,
% {\sffamily \textsc{must}} match the version
% number composed from the major version and the
% revision in the \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} root element
% attributes (see	‘\textbf{\textsf{\texttt{@revision}\index{revision=\texttt{\char'100 revision} (attribute)}\index{attributes:!revision=\texttt{\char'100 revision}}}}’, the fifth item in the list in \vref{revno}).\par
% \changes{v1.18}{2020/04/01}{This changed from the conformance attribute to the YYYY-MM-DD attribute. Updated all master documents.}
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<revision version="0.72">
  <date YYYY-MM-DD="2012-02-11"/>
  <revdescription>
    <itemizedlist>
      <title>Wrote internal documentation</title>
      <listitem>
        <para>Created the classpack.xml template 
                 as an example.</para>
      </listitem>
    </itemizedlist>
  </revdescription>
</revision>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% The four most recent entries are printed after the
% Table of Contents as `Recent
%   Changes'.\par
% Comments on individual changes to the code should
% be documented \emph{at the code
%   location}, using the \texttt{<remark>}\index{remark=\texttt{\char'074 remark\char'076 } (element)}\index{elements:!remark=\texttt{\char'074 remark\char'076 }}
% element (see \vref{maintenance}), eg\par 
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<remark version="0.70" revision="2018-05-29">Added timestamp</remark>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% These \texttt{<remark>}\index{remark=\texttt{\char'074 remark\char'076 } (element)}\index{elements:!remark=\texttt{\char'074 remark\char'076 }} elements get collated as
% {\ttfamily{}\textbackslash{}changes} commands \emph{in your
%   class or package}, and gathered together
% in the changelog by \textsf{ltxdoc} during
% processing, along with all the other revision
% elements.\par
% \changes{v1.06}{2016/06/14}{Checked operation of StopEventually}
% \end{description}
% \subsection{Part \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}}: the user
%   documentation}\label{userdoc}
% The documentation for the end user is normal descriptive
%   text which explains how to use the package or class. It is,
%   in effect, the manual for your class or package, aimed at
%   the \LaTeX{} user (author) who needs to know what it does and
%   how it works.\par
% \subsubsection{Hierarchical structure}
% Your documentation goes in the
%     \emph{ClassPack} \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}} part in 
%     \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} elements, which can contain \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }}
%     sections, which in turn can contain \texttt{<sect2>}\index{sect2=\texttt{\char'074 sect2\char'076 } (element)}\index{elements:!sect2=\texttt{\char'074 sect2\char'076 }}
%     subsections, and so on. This hierarchical structure is
%   described in \vref{hierarchy}.\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily
% Because the \textsf{latexdoc} package is
%       based on the \textsf{article} package, the
%       \emph{ClassPack} \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }}\kern1pt{}s
%       actually become \textsf{latexdoc} {\ttfamily{}\textbackslash{}section}s and the \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }}\kern1pt{}s
%       become \textsf{latexdoc} {\ttfamily{}\textbackslash{}subsection}s, etc, for the purposes of
%       formatting the documentation.\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% \subsubsection{Structural markup}
% Within your chapters and sections, you can use most of
%     the conventional structural features of any DocBook
%     document: paragraphs, lists, figures, tables, and examples
%     of code. Note that code examples in the documentation part
%     of a \emph{ClassPack} document do
%     \emph{not} get extracted into the class or
%     package file.\par
% Most of the specialist constructs of
%     \emph{DocBook} for documenting
%     programming languages are \emph{not} used in
%     \emph{ClassPack} except for a few
%     which are hijacked in the \texttt{<info>}\index{info=\texttt{\char'074 info\char'076 } (element)}\index{elements:!info=\texttt{\char'074 info\char'076 }} section for
%     setup purposes, and some [ab]used in the
%     {\ttfamily{}prepost.xml} database file for technical
%     reasons. The pool of structural markup elements supported is
%   described in \vref{pool}.\par
% \subsubsection{Inline markup}
% Within the text itself (eg in paragraphs) there are
%     many elements supported to allow you to identify and
%     format your documentation with minimal effort. These
%     inline or `flow' elements are
%     described in \vref{flow}.  Many of them
%     implement time-saving automation features.\par
% \subsection{Part \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}}: the annotated
%   code}\label{annocode}
% In the code \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }}, you provide the actual
%   \LaTeX{} code of your class or package, separated into chunks
%   that you can annotate to explain how it works or why you
%   wrote it that way. You can use \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }}\kern1pt{}s and
%   \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }}\kern1pt{}s etc to structure your annotations in a
%   readable manner: this has no effect on the class or package
%   code extracted into the {\ttfamily{}.dtx} file, only
%   on the formatting of the printed annotation.\par
% \subsubsection{Annotations}\label{annotatedcode}
% Your code {\sffamily \textsc{should}} be
%     documented in a modular way using the
%     \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} element to identify the macro or
%     environment or other object you are describing, using the
%     \texttt{<role>}\index{role=\texttt{\char'074 role\char'076 } (element)}\index{elements:!role=\texttt{\char'074 role\char'076 }} and \texttt{<xreflabel>}\index{xreflabel=\texttt{\char'074 xreflabel\char'076 } (element)}\index{elements:!xreflabel=\texttt{\char'074 xreflabel\char'076 }} attributes. You
%     then give the explanatory annotation in a \texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }}
%     element and the actual code in a \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }}
%     element. Here is an example of the documentation of a
%     rewriting of the macro {\ttfamily{}\textbackslash{}MacroFont} (the
%     output is given on the code \vpageref{macrofont-code} and \vpageref{macrofont-doc}):\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<annotation role="macro" xreflabel="MacroFont">
  <para>The <package>doc</package> and <package>docx</package>
    packages use the <command>MacroFont</command> command for
    the marginal labelling of code annotation. We add here the
    colour DarkBlue from the <option>svgnames</option> option
    to the <package>xcolor</package> package.</para>
  <programlisting>
\def\MacroFont{\fontencoding\encodingdefault
  \ttfamily\fontseries{m}\fontshape\updefault
  \small\selectfont\color{DarkBlue}}%
  </programlisting>
</annotation>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% Each such \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} element
%     {\sffamily \textsc{should}} describe a single
%     macro or environment or other code object such as a
%     dimension, counter, etc listed below. In the default
%     Doc\TeX{} system, only macros and environments can be
%     identified (the \texttt{macro} and
%     \texttt{environment} values, see \textcite[][p\thinspace 6]{docpkg}).\par
% \begin{description}[style=unboxed,noitemsep]\label{annotypes}
% \item[macro:]the original Doc\TeX{} usage;
% \item[environment:]the original Doc\TeX{} usage.
% \end{description}
% \emph{ClassPack} extends this to
%     handle the following list of values for the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute of the
%     \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} element for \LaTeX{} and other
%     related structures. These are the values declared in
%     {\ttfamily{}prepost.xml} as extensions to the
%     \textsf{doc} package.\par
% \begin{description}[style=unboxed,noitemsep]
% \item[attribute:]describing an attribute in an
%   \textsc{xml} document;
% \item[attvalue:]describing an attribute
%   \emph{value} in an
%   \textsc{xml} document;
% \item[box:]describing a new box;
% \item[class:]describing a new class;
% \item[color:]defining a new colour;
% \item[comment:]describing a comment inserted in a
%   file;
% \item[counter:]describing a new counter;
% \item[dtd:]documenting a \textsc{dtd}\index{DTD};
% \item[element:]documenting an \textsc{xml} element
%   type declaration;
% \item[entity:]documenting an \textsc{xml} entity
%   declaration;
% \item[error:]defining an error;
% \item[field:]documenting a data field (eg in \BibTeX{});
% \item[file:]describing a new file;
% \item[font:]describing a new font (not a new typeface; see
%   below);
% \item[function:]documenting a function in a language;
% \item[language:]describing a new [computer] language (eg in
%   \textsf{listings});
% \item[length:]describing a new length;
% \item[mode:]documenting a mode of operation (eg in
%   \textsc{xml});
% \item[option:]defining a new option;
% \item[package:]defining a new package;
% \item[parameter:]describing a parameter passed to a module (eg in
%   \textsc{xslt});
% \item[rubric:]defining a new rubric;
% \item[setting:]describing a setting or block of settings such
%   as initial values or switches ;
% \item[switch:]describing a new switch (\TeX{}’s
%   {\ttfamily{}\textbackslash{}newif});
% \item[template:]describing a template (eg in
%   \textsc{xslt});
% \item[typeface:]describing a new typeface;
% \item[variable:]describing a variable in a language.
% \end{description}
% In the above example, the result
%     of processing the \textsc{xml} \emph{ClassPack} document is a
%     fragment in the {\ttfamily{}.dtx} file:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX},label=macrofont-code]
% \begin{CPK@macro}{\MacroFont}\label{ann-MacroFont}
% The \textsf{doc} and \textsf{docx}
%     packages use the {\ttfamily{}\textbackslash{}MacroFont} command for
%     the marginal labelling of code annotation. We add here the
%     colour DarkBlue (from the \textbf{\texttt{svgnames}} option
%     to the \textsf{xcolor} package).\par
%    \begin{macrocode}
\def\MacroFont{\fontencoding\encodingdefault
  \ttfamily\fontseries{m}\fontshape\updefault
  \small\selectfont\color{DarkBlue}}%
%    \end{macrocode}
% \end{CPK@macro}
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% The result of extracting the {\ttfamily{}.sty}
%   file during installation is therefore the \LaTeX{} code…\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX}]
\def\MacroFont{\fontencoding\encodingdefault
  \ttfamily\fontseries{m}\fontshape\updefault
  \small\selectfont\color{DarkBlue}}
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% …and the result of typesetting the
%   {\ttfamily{}.dtx} file is, of course, the typeset
%     text in the documentation:\par
% \begin{quotation}\label{macrofont-doc}\small\sffamily\parindent0pt
%   \parskip.5\baselineskip
%   \color{DarkBlue}\normalfont\noindent
% The \textsf{doc} and
%       \textsf{docx} packages use the
%       {\ttfamily{}\textbackslash{}MacroFont} command for the marginal
%       labelling of code annotation. We add here the colour
%       DarkBlue from the \textbf{\texttt{svgnames}} option to
%       the \textsf{xcolor} package.\par
% \end{quotation}
% There are two special cases of the
%   \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} element: colours and reusability:\par
% \paragraph[Specifying colours]{Specifying colours :}\label{speccols}
% When using an \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} element to
%       document a colour (eg a {\ttfamily{}\textbackslash{}definecolor}
%       command from the \textsf{xcolor} package), in
%       addition to the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} and
%       \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} attributes
%       described above, you {\sffamily \textsc{must}}
%       add the the colour space (eg \textbf{\texttt{rgb}},
%       \textbf{\texttt{cmyk}}, \textbf{\texttt{HTML}}, etc, as
%       defined in the \textsf{xcolor} documentation)
%       in the \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}} attribute;
%       \emph{and} the colour code to use in the
%       \texttt{@audience}\index{audience=\texttt{\char'100 audience} (attribute)}\index{attributes:!audience=\texttt{\char'100 audience}} attribute. This is
%       required to allow Doc\TeX{} to predefine the colour for
%       use in the documentation itself, as well as having it
%       defined for your class or package. For example (from the
%       \textsf{euflag} package document)\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
        <annotation role="color" xreflabel="PantoneReflexBlue"
          arch="HTML" audience="003399">
          <para>As specified in the web page.</para>
          <programlisting>
\definecolor{PantoneReflexBlue}{HTML}{003399}
%\definecolor{PantoneReflexBlue}{cmyk}{1.00,.67,0,.40}
          </programlisting>
        </annotation>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% \paragraph[Reusability]{Reusability :}\label{reuse}
% To avoid the need for annotations to be repeated
%       verbatim in annotated files such as
%       {\ttfamily{}.sty} files that accompany a
%       {\ttfamily{}.cls} file, there is a \texttt{@reuse}\index{reuse=\texttt{\char'100 reuse} (attribute)}\index{attributes:!reuse=\texttt{\char'100 reuse}} attribute on the \texttt{annotation}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} element type,
%       declared as \texttt{<IDREFS>}\index{IDREFS=\texttt{\char'074 IDREFS\char'076 } (element)}\index{elements:!IDREFS=\texttt{\char'074 IDREFS\char'076 }}. This is for a
%       space-separated list of \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} values of
%       \emph{existing} \texttt{annotation}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} elements elsewhere in
%       the \emph{same} document. The relevant
%       \texttt{annotation}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }}\kern1pt{}s will then  be
%       included in at the new location as well, exactly as if
%       they had been physically present in the source code.
%       When using this attribute, the \texttt{<annotation/>}\index{annotation=\texttt{\char'074 annotation/\char'076 } (empty element)}\index{empty elements:!annotation=\texttt{\char'074 annotation/\char'076}} element
%       {\sffamily \textsc{must}} be
%       \texttt{EMPTY}\index{EMPTY=\texttt{EMPTY} (local name)}\index{local names:!EMPTY=\texttt{EMPTY}}.\par
% Work is ongoing to support the use of XLink to allow
%       this type of retrieval across different documents.\par
% \subsubsection{Ancillary annotated files}
% Ancillary files which you want to annotate
%     \emph{and} have extracted along with the
%     class or package file {\sffamily \textsc{must}}
%     each go in their own \texttt{<appendix>}\index{appendix=\texttt{\char'074 appendix\char'076 } (element)}\index{elements:!appendix=\texttt{\char'074 appendix\char'076 }} element, starting
%     after the last \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} element of the package
%     or class in the \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}} part. You
%     write them and code them exactly as for the main code of
%     your primary file in the preceding chapter[s]. Each such
%     \texttt{<appendix>}\index{appendix=\texttt{\char'074 appendix\char'076 } (element)}\index{elements:!appendix=\texttt{\char'074 appendix\char'076 }} element
%     {\sffamily \textsc{must}} contain at least one
%     \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }} element where you put the documentary
%     \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }}\kern1pt{}s.\par
% These files would typically be style packages,
%     scripts, or data samples accompanying a class or style
%     file, whose code needs documenting. Files for extraction
%     which do \emph{not} need documenting are
%     called \emph{unannotated} ancillary files.
%     They {\sffamily \textsc{must}} be stored in the
%     \texttt{"files"}\index{files=\texttt{"files"} (attribute value)}\index{attribute values:!files=\texttt{"files"}} \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }} as
%     described in \vref{ancfiles}.\par
% The \texttt{<appendix>}\index{appendix=\texttt{\char'074 appendix\char'076 } (element)}\index{elements:!appendix=\texttt{\char'074 appendix\char'076 }} element
%     {\sffamily \textsc{requires}} the following
%     attributes:\par
% \begin{description}[style=unboxed]
% \item[\texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}}:]This is a unique identifier for the file. It
%   {\sffamily \textsc{must not}} be the
%   filename.\par
% \item[\texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}}:]This describes the architecture of the file. The
%   range of values is as given in ‘\textbf{\textsf{\texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}}}}’, the second item in the list in \vref{arch} plus the value \texttt{"document"}\index{document=\texttt{"document"} (attribute value)}\index{attribute values:!document=\texttt{"document"}}.\par
% \item[\texttt{@userlevel}\index{userlevel=\texttt{\char'100 userlevel} (attribute)}\index{attributes:!userlevel=\texttt{\char'100 userlevel}}:]This describes the type of file being extracted.
%   The range of values is as given in ‘\textbf{\textsf{\texttt{@userlevel}\index{userlevel=\texttt{\char'100 userlevel} (attribute)}\index{attributes:!userlevel=\texttt{\char'100 userlevel}}}}’, the third item in the list in \vref{userlevel} plus values such as \texttt{"dtd"}\index{dtd=\texttt{"dtd"} (attribute value)}\index{attribute values:!dtd=\texttt{"dtd"}}, \texttt{"xsl"}\index{xsl=\texttt{"xsl"} (attribute value)}\index{attribute values:!xsl=\texttt{"xsl"}}, or \texttt{"awk"}\index{awk=\texttt{"awk"} (attribute value)}\index{attribute values:!awk=\texttt{"awk"}}, corresponding to the
%   output filetype. See also below.\par
% \item[\texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}}:]This is the filename of the file which will be
%   extracted at installation, containing all the
%   content of \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} elements in
%   this appendix.\par
% \end{description}
% The special value \texttt{"cp"}\index{cp=\texttt{"cp"} (attribute value)}\index{attribute values:!cp=\texttt{"cp"}} is
%     supported in the \texttt{@userlevel}\index{userlevel=\texttt{\char'100 userlevel} (attribute)}\index{attributes:!userlevel=\texttt{\char'100 userlevel}}
%     attribute for the handling of a Makefile, because the
%     \textsf{doc} package cannot preserve
%     {\ttfamily{}TAB} characters in an extracted
%     document. Normally this does not matter too much, but in a
%     Makefile, a {\ttfamily{}TAB} character is
%     critical to the functionality of a recipe. Because of
%     this, a documented, otherwise extractable Makefile in a
%     \emph{ClassPack} appendix with this
%     \texttt{"cp"}\index{cp=\texttt{"cp"} (attribute value)}\index{attribute values:!cp=\texttt{"cp"}} value for the \texttt{@userlevel}\index{userlevel=\texttt{\char'100 userlevel} (attribute)}\index{attributes:!userlevel=\texttt{\char'100 userlevel}} \emph{will not be
%       extracted} and
%     {\sffamily \textsc{must}} be included in the
%     Manifest as a static file (see \vref{manifestfiles}).\par
% \subsection{Part \texttt{"files"}\index{files=\texttt{"files"} (attribute value)}\index{attribute values:!files=\texttt{"files"}}: unannotated
%   ancillary files}\label{ancfiles}
% This part is for ancillary files which just need to be
%   extracted whole, along with the class or package,
%   and do not have any annotations.\par
% These would typically be self-documenting example
%   documents, default configuration files, shell scripts
%   documented elsewhere, and other non-\LaTeX{} files.\par
% Each one goes in a \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} container
%   element within a \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} which
%   {\sffamily \textsc{must}} give the
%   filename to be created in the \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} attribute, and
%   {\sffamily \textsc{must}} have a
%   unique \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} to identify it
%   within \emph{ClassPack}.\par
% The \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} element
%   {\sffamily \textsc{may}} have its own \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} attribute which points
%   at an external file (eg a template) which is to be included
%   at this point. In this case the \texttt{<programlisting/>}\index{programlisting=\texttt{\char'074 programlisting/\char'076 } (empty element)}\index{empty elements:!programlisting=\texttt{\char'074 programlisting/\char'076}} element is
%   empty.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX}]
<part xml:id="files">
  <title>Ancillary files</title>
  <chapter xml:id="testdoc" xlink:href="testdoc.tex">
    <title>Test document</title>
    <para>You can use this document to test the class.</para>
    <programlisting language="LaTeXe">
%&lt;&lt;COMMENT
% !TEX TS-program = xelatex
% !TEX encoding = UTF-8 Unicode
% !BIB TS-program = biber
%COMMENT
    </programlisting>
    <programlisting language="LaTeXe">
\documentclass[12pt,a4paper]{myclass}
\begin{document}
Some testing stuff
\end{document}
    </programlisting>
  </chapter>
</part>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% In the example, the \TeX{} editor signals block is
%   included as a separate \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} element
%   \emph{before} the one containing the
%   code. This lets editors and other software identify which
%   processors to use.\par
% \subsection{The README.md file}\label{readmemd}
% One additional user file is produced automatically by
%   the \textsc{xslt} scripts: the
%   \emph{Markdown} file called
%   {\ttfamily{}README.md} which accompanies all classes
%   and packages for display on \textsc{ctan}\index{CTAN}. The
%   default file contains a brief description of usage and
%   installation, for the benefit of people who cannot or will
%   not read the \textsc{pdf} documentation, with the
%   package or class name and the Abstract of the documentation
%   automatically inserted for the current document.\par
% This is generated automatically from the file
%   {\ttfamily{}readme.xml}\thinspace, which is a
%   \emph{DocBook5} \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }}
%   document supplied as part of
%   \emph{ClassPack}. It contains some
%   changes to the character entities to accommodate plain text,
%   and some locations signalled for the replacement values of
%   class or package name and the Abstract.\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily
% Note that this document does \emph{not}
%     use the special {\ttfamily{}doctexbook.dtd} used
%     for your normal \emph{ClassPack} \textsc{xml} documents; instead it uses the
%     plain, unmodified \emph{DocBook} which
%     underlies the {\ttfamily{}doctexbook.dtd}\thinspace, with a
%     few entity declarations and a couple of extra attributes
%     in the local subset.\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% The {\ttfamily{}readme.xml} file  uses the
%   \texttt{<olink>}\index{olink=\texttt{\char'074 olink\char'076 } (element)}\index{elements:!olink=\texttt{\char'074 olink\char'076 }} element type to act as a placeholder for
%   transcluded atomic information from the main document
%   (pending implementation of the proposed
%   \emph{DocBook} Transclusions method).
%   This element {\sffamily \textsc{must}} have a
%   \texttt{<targetptr>}\index{targetptr=\texttt{\char'074 targetptr\char'076 } (element)}\index{elements:!targetptr=\texttt{\char'074 targetptr\char'076 }} and a \texttt{<type>}\index{type=\texttt{\char'074 type\char'076 } (element)}\index{elements:!type=\texttt{\char'074 type\char'076 }} attribute
%   specifying (respectively) the name of the element type in
%   the main document and the relevant attribute. For example,
%   to include the name of the class or package, we use:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX}]
<olink targetptr="book" type="xml:id"/>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% Two other element types have also had
%   \texttt{<targetptr>}\index{targetptr=\texttt{\char'074 targetptr\char'076 } (element)}\index{elements:!targetptr=\texttt{\char'074 targetptr\char'076 }} and \texttt{<type>}\index{type=\texttt{\char'074 type\char'076 } (element)}\index{elements:!type=\texttt{\char'074 type\char'076 }} attributes
%   added: \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }} and \texttt{<anchor>}\index{anchor=\texttt{\char'074 anchor\char'076 } (element)}\index{elements:!anchor=\texttt{\char'074 anchor\char'076 }}. These are
%   used to specify the inclusion of whole sections or
%   fragments of the main document, such as the Abstract or
%   the Copyright.\par
% The text is reformatted into
%   \emph{Markdown} by the
%   templates in
%   {\ttfamily{}db2md.xsl}\thinspace. Only a few element types
%   have been implemented for this in this version: enough to
%   convert the Abstracts of packages under the author’s care
%   and the {\ttfamily{}readme.xml} file itself.\par
% The resulting {\ttfamily{}README.md} file
%   therefore includes the Abstract from your class or package
%   document as the first section. The
%   {\ttfamily{}db2md.xsl} script uses a template called
%   \texttt{normtext} to create
%   long single lines of \emph{Markdown}
%   text from elements such as titles and paragraphs. This
%   handles the conversion of entities which occur in your
%   Abstract (those declared in
%   {\ttfamily{}doctexbook.dtd}): by default, \texttt{\&TeX;}\index{TeX=\texttt{\&TeX;} (general entity)}\index{general entities:!TeX=\texttt{\&TeX;}}, \texttt{\&LaTeX;}\index{LaTeX=\texttt{\&LaTeX;} (general entity)}\index{general entities:!LaTeX=\texttt{\&LaTeX;}}, and \texttt{\&thinsp;}\index{thinsp=\texttt{\&thinsp;} (general entity)}\index{general entities:!thinsp=\texttt{\&thinsp;}} are catered for, but if you
%   use any others, you must modify the code in this template to
%   deal with them, using the nested \texttt{replace()} functions. The
%   {\ttfamily{}db2md.xsl} script handles all the
%   element markup currently used in
%   {\ttfamily{}readme.xml}\thinspace, plus the \texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }}
%   and \texttt{<literallayout>}\index{literallayout=\texttt{\char'074 literallayout\char'076 } (element)}\index{elements:!literallayout=\texttt{\char'074 literallayout\char'076 }} elements used in the author’s
%   Abstracts. Any additional abstract elements required should
%   be notified to the author.\par
% \subsection{Other output}
% Three other files are generated during processing:\par
% \begin{description}[style=unboxed]
% \item[{\ttfamily{}MANIFEST}\thinspace:]\label{manifestlist}This is a list of all files in the package,
% \emph{excluding} those which will be
% generated by the installation procedure in the
% {\ttfamily{}.ins} file. It is used to create
% the zip files, and it itself a part of the
% package.\par
% \item[{\ttfamily{}autopack.xml}\thinspace:]\label{apx}For the purposes of package tracking, the
% in-memory list of packages computed by the
% \emph{AutoPackage} mechanism is
% serialised to an \textsc{xml} document in
% {\ttfamily{}autopack.xml}\thinspace.\par
% \item[{\ttfamily{}index.html}\thinspace:]This is the sample entry for a web page about your
% package. Currently the formatting is used for the
% author’s pages at \href{https://latex.silmaril.ie/packages/}{\nolinkurl{https://latex.silmaril.ie/packages/}}
% but could easily be adapted in the
% \emph{db2dtx} script (see \vref{indexhtml}).\par
% \end{description}
% \subsection{Worked example}
% The file {\ttfamily{}template.xml} included in
%   the package distribution contains examples of the structures
%   in a \emph{ClassPack} application, with
%   comments to remind the author of what goes where.\par
% \subsubsection{Startup}
% The file starts with the \textsc{xml}
%     Declaration followed by the Document Type Declaration for
%     the modified version of \emph{DocBook}\thinspace(5) supplied with
%     \emph{ClassPack}.\par
% \lstinputlisting[language=XML]{applicationtemplate-decl.frag}
% \label{decl}
% \subsubsection{Root element specifications}
% The start-tag for the \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} element shows
%     the attributes explained in \vref{setup} which
%     will
%     need editing for each new application, and revising for
%     updates, especially the \texttt{@version}\index{version=\texttt{\char'100 version} (attribute)}\index{attributes:!version=\texttt{\char'100 version}}, \texttt{@revision}\index{revision=\texttt{\char'100 revision} (attribute)}\index{attributes:!revision=\texttt{\char'100 revision}}, and \texttt{@security}\index{security=\texttt{\char'100 security} (attribute)}\index{attributes:!security=\texttt{\char'100 security}} attributes.\par
% \lstinputlisting[language=XML]{applicationtemplate-book.frag}
% \label{book}
% \subsubsection{Packages for the documentation}
% A filename for artwork for a cover for the
%     documentation can be specified in the optional \texttt{@coverart}\index{coverart=\texttt{\char'100 coverart} (attribute)}\index{attributes:!coverart=\texttt{\char'100 coverart}} attrbute of the
%     \texttt{<info>}\index{info=\texttt{\char'074 info\char'076 } (element)}\index{elements:!info=\texttt{\char'074 info\char'076 }} element. The packages needed for your
%     documentation (at least, those which do not get added
%     automatically by \emph{AutoPackage})
%     go in the \texttt{<seg>}\index{seg=\texttt{\char'074 seg\char'076 } (element)}\index{elements:!seg=\texttt{\char'074 seg\char'076 }} element of \texttt{<seglistitem>}\index{seglistitem=\texttt{\char'074 seglistitem\char'076 } (element)}\index{elements:!seglistitem=\texttt{\char'074 seglistitem\char'076 }}
%     elements:\par
% \lstinputlisting[language=XML]{applicationtemplate-docp.frag}
% \label{docp}
% \paragraph[Ancillary startup commands for the
%       documentation]{Ancillary startup commands for the
%       documentation :}
% [DEPRECATED] The mechanism of earlier versions to
%       provide for the computed construction of commands is no
%       longer in use (see the warning in \vref{deprecated-cmdsynopses},
%       the code \vpageref{dtxmainextras}, and the code \vpageref{cmdsynopsis}). It is retained here for
%       historical compatibility and will be removed in a future
%       version.\par
% \lstinputlisting[language=XML]{applicationtemplate-newc.frag}
% \label{newc}
% Code for the documentation which needs to be
%       executed at the end of the Preamble but before the
%       beginning of the document goes in a
%       \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} element with the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} \texttt{\unskip="atendpreamble"}\index{atendpreamble=\texttt{"atendpreamble"} (attribute value)}\index{attribute values:!atendpreamble=\texttt{"atendpreamble"}}. By this time all
%       packages will normally have been loaded.\par
% \lstinputlisting[language=XML]{applicationtemplate-atendp.frag}
% \label{atendp}
% Code for the documentation which needs to be
%       executed at the beginning of the document goes in a
%       \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} element with the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} \texttt{\unskip="atbegindoc"}\index{atbegindoc=\texttt{"atbegindoc"} (attribute value)}\index{attribute values:!atbegindoc=\texttt{"atbegindoc"}}. This will be
%       executed \emph{after} \verb|\begin{document}|, that is, during the
%       absorption phase of the {\ttfamily{}.dtx} file
%       as it is run by the {\ttfamily{}\textbackslash{}DocInput} command
%       of the \textsf{doc} package.\par
% \lstinputlisting[language=XML]{applicationtemplate-atbegd.frag}
% \label{atbegd}
% \subsubsection{Packages for the class or style package}\label{clsstypkg}
% Packages required for your class or style package are
%     specified in the same way as those for the documentation.
%     Not that these packages do \emph{not} get
%     passed through \emph{AutoPackage}: it
%     is considered that the author is controlling the inclusion
%     of packages manually as part of the design. The \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} attribute on the
%     \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} element
%     {\sffamily \textsc{must}} match a section in the
%     code part: the package list will be output before or after
%     that section, as determined by the value of the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute.\par
% \lstinputlisting[language=XML]{applicationtemplate-clsp.frag}
% \label{clsp}
% \subsubsection{The Manifest}
% The rules for package governance at
%     \textsc{ctan}\index{CTAN} require a file called
%     {\ttfamily{}MANIFEST} containing a complete lst of
%     all files in the downloadable zip file submitted.
%     \emph{ClassPack} constructs this file
%     automatically for those files it is managing directly, but
%     this is the place to list any others that need
%     including.\par
% \lstinputlisting[language=XML]{applicationtemplate-manif.frag}
% \label{manif}
% \subsubsection{Metadata}
% The title of the document being created is generated
%     automatically to be \emph{The
%       \uline{name} \LaTeXe{}
%       package} (or `class'
%     as appropriate). The \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }} needed here is in
%     effect an explanatory subtitle, a one-line explanation of
%     what this package or class is for. There can be multiple
%     authors, in which case they
%     {\sffamily \textsc{must}} be enclosed in an
%     \texttt{<authorgroup>}\index{authorgroup=\texttt{\char'074 authorgroup\char'076 } (element)}\index{elements:!authorgroup=\texttt{\char'074 authorgroup\char'076 }} element. Keywords are recommended,
%     as they also get used in the \textsc{pdf}
%     metadata, which gets indexed by search engines. If the
%     copyright date is given in ISO format in the \texttt{@YYYY-MM-DD}\index{YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD} (attribute)}\index{attributes:!YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD}} attribute, no content
%     in the element is necessary. Both email address and name
%     of the copyright holder
%     {\sffamily \textsc{should}} be given. The
%     downloadable location of the package (eg
%     \textsc{ctan}\index{CTAN} or the author's web site)
%     {\sffamily \textsc{should}} be given in the
%     \texttt{<releaseinfo>}\index{releaseinfo=\texttt{\char'074 releaseinfo\char'076 } (element)}\index{elements:!releaseinfo=\texttt{\char'074 releaseinfo\char'076 }} element.\par
% \lstinputlisting[language=XML]{applicationtemplate-meta.frag}
% \label{meta}
% The admonition to report corrections
%     {\sffamily \textsc{should}} be left
%     as-is.\par
% \lstinputlisting[language=XML]{applicationtemplate-admon.frag}
% \label{admon}
% The Abstract (renamed here
%     `Summary')
%     {\sffamily \textsc{must}} be short enough to fit
%     about half of the front page of the documentation: two or
%     three short paragraphs are plenty to explain what this
%     class or package is and why you might want to use it. The
%     optional image file in the \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} attribute will be
%     placed on the front page below the Summary.\par
% \lstinputlisting[language=XML]{applicationtemplate-abst.frag}
% \label{abst}
% The revision history is essential and must be
%     completed after each change. The version number given
%     {\sffamily \textsc{must}} match the \texttt{@version}\index{version=\texttt{\char'100 version} (attribute)}\index{attributes:!version=\texttt{\char'100 version}} and \texttt{@revision}\index{revision=\texttt{\char'100 revision} (attribute)}\index{attributes:!revision=\texttt{\char'100 revision}} values on the document
%     root \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} element. For minor changes, the
%     \texttt{<revdescription>}\index{revdescription=\texttt{\char'074 revdescription\char'076 } (element)}\index{elements:!revdescription=\texttt{\char'074 revdescription\char'076 }} element content can be a single
%     \texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }} element.\par
% \lstinputlisting[language=XML]{applicationtemplate-revh.frag}
% \label{revh}
% \subsubsection{Documentation}
% The ID \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}} is
%     {\sffamily \textsc{mandatory}}. The \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} {\sffamily \textsc{must}} give the name of the
%     \LaTeX{} executable to be used
%     (\emph{xelatex},
%     \emph{lualatex}, or
%     \emph{pdflatex}). Beyond that, you
%     write your documentation in
%     \emph{DocBook}, using the supported
%     markup as described in \vref{content}.\par
% \lstinputlisting[language=XML]{applicationtemplate-partd.frag}
% \label{partd}
% Bibliographic references follow the documentation.
%     Each entry {\sffamily \textsc{must}} be in a
%     \texttt{<biblioentry>}\index{biblioentry=\texttt{\char'074 biblioentry\char'076 } (element)}\index{elements:!biblioentry=\texttt{\char'074 biblioentry\char'076 }} element.\par
% \lstinputlisting[language=XML]{applicationtemplate-bib.frag}
% \label{bib}
% \subsubsection{Code}
% The first \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} of the code
%     {\sffamily \textsc{must}} give the name of the
%     file to which it is to be extracted from the
%     {\ttfamily{}.dtx} file. This will be the package
%     name with the file extension {\ttfamily{}.cls} or
%     {\ttfamily{}.sty} as appropriate. This must match
%     the computed name derived from the name of the application
%     directory plus the filetype. Code can be structured in any
%     suitable way: an \texttt{"options"}\index{options=\texttt{"options"} (attribute value)}\index{attribute values:!options=\texttt{"options"}}
%     section would be common…\par
% \lstinputlisting[language=XML]{applicationtemplate-partc.frag}
% \label{partc}
% …as would one with an ID that can be matched by the
%     value of the \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}}
%     attribute on the \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} element with the
%     \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} \texttt{\unskip="clspackages"}\index{clspackages=\texttt{"clspackages"} (attribute value)}\index{attribute values:!clspackages=\texttt{"clspackages"}} (or \texttt{"stypackages"}\index{stypackages=\texttt{"stypackages"} (attribute value)}\index{attribute values:!stypackages=\texttt{"stypackages"}} as appropriate) as
%     shown in \vref{clsstypkg}. The base class (if
%     relevant) can be given in the
%     {\ttfamily{}\textbackslash{}PassOptionsToClass} and
%     {\ttfamily{}\textbackslash{}LoadClass} commands; otherwise that code
%     block can be omitted. The use of the \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }}
%     element is described in \vref{annocode}.\par
% \lstinputlisting[language=XML]{applicationtemplate-partcpack.frag}
% \label{partcpack}
% \subsubsection{Extractable \emph{annotated}
%     files}
% Files for extraction that are annotated with
%     documentation go in \texttt{<appendix>}\index{appendix=\texttt{\char'074 appendix\char'076 } (element)}\index{elements:!appendix=\texttt{\char'074 appendix\char'076 }} elements within
%     the code part. As with the main class or package, the code
%     can be inline within the \textsc{xml} document,
%     or referenced by line numbers or by fragments created by
%     the \emph{chunk}\thinspace(1) utility
%     supplied (see item~\ref{chunking} in the list on p.\thinspace\pageref{chunking}).\par
% \lstinputlisting[language=XML]{applicationtemplate-partcanc.frag}
% \label{partcanc}
% \subsubsection{Extractable files without annotation}
% Files for extraction that are supplied as-is
%     {\sffamily \textsc{must}} go in
%     \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} elements in the files part. The
%     filename to extract \emph{to} {\sffamily \textsc{must}} be given in the \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} of the
%     \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} element. If the files are to be brought
%     in from an external source rather than supplied inline,
%     that file name {\sffamily \textsc{must}} go in
%     the \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} on the
%     \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} element.\par
% \lstinputlisting[language=XML]{applicationtemplate-partf.frag}
% \label{partf}
% \clearpage
% \section{Package management}\label{packages}
% As mentioned above, the \texttt{<cover>}\index{cover=\texttt{\char'074 cover\char'076 } (element)}\index{elements:!cover=\texttt{\char'074 cover\char'076 }} element is used
% to provide places where packages and other \LaTeX{}
% preliminaries can be specified. Using this structure means
% each entry is separately editable, and the same structure,
% with different content, is used both for packages for the
% documentation \emph{and} packages for the class
% or package being created.\par
% It would of course have been possible just to allow a slab
% of {\ttfamily{}\textbackslash{}usepackage} commands at these points, but
% that would have made commenting and documentation harder, and
% would also have made it more difficult to perform an
% \textsc{xml} editor’s element-copy–element-paste or
% an XInclude when using one package’s or class’s settings as
% the basis for another.\par
% However, the most important reason is that specifying
% package lists as separately-identifiable values makes it
% possible to automate the documentation of frequently-used
% packages, and to automate the inclusion of parameters,
% options, settings, additional commands, and even
% documentation, which you can store separately for re-use in
% each class or package you maintain by adding your own
% modifications that you like to have included whenever you use
% a particular package.\par
% The \emph{AutoPackage} feature added
% to \emph{ClassPack} in v0.74 means that
% packages needed for your documentation on a regular basis can
% now be detected automatically on the basis of features you use
% in your documentation, making it unnecessary to specify them
% by hand at all: full details are in \vref{autospec}.  For example, if you use compact lists
% (\emph{DocBook}’s \texttt{spacing}\index{spacing=\texttt{\char'100 spacing} (attribute)}\index{attributes:!spacing=\texttt{\char'100 spacing}}=\texttt{"compact"}\index{compact=\texttt{"compact"} (attribute value)}\index{attribute values:!compact=\texttt{"compact"}} attribute),
% \emph{ClassPack} will detect this and add
% the \textsf{enumitem} package so that \LaTeX{} can
% implement compact spacing.\par
% The \emph{db2dtx} script also uses
% this feature in order to modify the behaviour of standard
% \LaTeX{} at several points (such as fixing the broken abstract
% formatting when the \textsf{parskip} package is
% used, and fixing the broken formatting of long item label
% values in the \texttt{description} environment).\par
% It is important to note that
% \emph{AutoPackage} applies
% \emph{only} to the selection of packages for
% your documentation. Although the same \textsc{xml}
% structure is used to hold the package list for your class or
% style package, it leaves the selection to you as the author
% because there is no text on which to base decisions about
% inclusion or exclusion.\par
% \subsection{Where to put the lists of packages}\label{packagelists}
% Packages you need {\sffamily \textsc{must}} be
%   specified in the \texttt{<cover>}\index{cover=\texttt{\char'074 cover\char'076 } (element)}\index{elements:!cover=\texttt{\char'074 cover\char'076 }} element in a
%   \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} element with one of the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} values \texttt{"docpackages"}\index{docpackages=\texttt{"docpackages"} (attribute value)}\index{attribute values:!docpackages=\texttt{"docpackages"}}, \texttt{"clspackages"}\index{clspackages=\texttt{"clspackages"} (attribute value)}\index{attribute values:!clspackages=\texttt{"clspackages"}}, or \texttt{"stypackages"}\index{stypackages=\texttt{"stypackages"} (attribute value)}\index{attribute values:!stypackages=\texttt{"stypackages"}}.\par
% At the moment, only one of the \texttt{"clspackages"}\index{clspackages=\texttt{"clspackages"} (attribute value)}\index{attribute values:!clspackages=\texttt{"clspackages"}} or \texttt{"stypackages"}\index{stypackages=\texttt{"stypackages"} (attribute value)}\index{attribute values:!stypackages=\texttt{"stypackages"}} lists can be used in a
%   single \emph{ClassPack} document,
%   because you are either creating a class
%   \emph{or} a style package, not both.\par
% \changes{v1.08}{2018/02/07}{Replaced ‘three’ with ‘two’ uses now that section 2.7 has been removed.}
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<constraintdef xml:id="docpackages">
 ...packages needed for the user documentation go here...
</constraintdef>

<constraintdef xml:id="clspackages" linkend="options">
 ...packages needed for the class you are writing go here...
</constraintdef>

<constraintdef xml:id="stypackages" linkend="options">
 ...packages needed for the package you are writing go here...
</constraintdef>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% The exact \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} values
%   given are {\sffamily \textsc{mandatory}} on the
%   relevant \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} elements: the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} values are used by
%   \emph{db2dtx}, matching the first three
%   letters with the three-letter filetype used as the value of
%   the \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}} attribute that you
%   specified on the \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} root element; see
%   ‘\textbf{\textsf{\texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}}}}’, the second item in the list in \vref{arch}).\par
% \par\begingroup
%   \fboxsep1em\centering
%   \fbox{\begin{minipage}{0.8\columnwidth}\sffamily
%  \raggedright\parindent0pt
%  \parskip=.5\baselineskip\label{tagwarn}%
% Note that there are two other, unrelated, uses for the
%     \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} element, dealt with in \vref{addsetup} and \vref{manifestfiles}, which
%     must not be confused with this one.\par
% \end{minipage}}\par\endgroup
% \subsection{Listing the packages}\label{listpack}
% The method is identical for all three cases: each
%   \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} element holds a
%   \texttt{<segmentedlist>}\index{segmentedlist=\texttt{\char'074 segmentedlist\char'076 } (element)}\index{elements:!segmentedlist=\texttt{\char'074 segmentedlist\char'076 }} to specify the packages required.
%   It {\sffamily \textsc{must}} have a title to label
%   it.\par
% Within the list, each package goes in a
%   \texttt{<seglistitem>}\index{seglistitem=\texttt{\char'074 seglistitem\char'076 } (element)}\index{elements:!seglistitem=\texttt{\char'074 seglistitem\char'076 }} element in a \texttt{<seg>}\index{seg=\texttt{\char'074 seg\char'076 } (element)}\index{elements:!seg=\texttt{\char'074 seg\char'076 }}
%   subelement.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML,emph={role}]
<constraintdef xml:id="docpackages">
  <segmentedlist>
    <segtitle>Packages required for documentation</segtitle>
    <seglistitem role="Use the Charter typeface for documentation."> 
      <seg version="2005-04-12">charter</seg>
    </seglistitem>
    <seglistitem role="Use Helvetica as the sans-serif, but scale it
       to fit">
      <seg role="scaled=0.8333">helvet</seg>
    </seglistitem>
    <seglistitem>
      <seg role="svgnames">xcolor</seg>
    </seglistitem>
    <seglistitem>
      <seg>array</seg>
    </seglistitem>
    ...
  </segmentedlist>
</constraintdef>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% The rules are:\par
% \begin{itemize}
% \item As noted earlier, of the two values \texttt{"clspackages"}\index{clspackages=\texttt{"clspackages"} (attribute value)}\index{attribute values:!clspackages=\texttt{"clspackages"}} and \texttt{"stypackages"}\index{stypackages=\texttt{"stypackages"} (attribute value)}\index{attribute values:!stypackages=\texttt{"stypackages"}}, only one can be
%       used in a single \emph{ClassPack}
%       document.\par
% This will be fixed in a later version, as it
%       interferes with the generation of additional package
%       files to accompany a single class.\par
% \item An \texttt{<segtitle>}\index{segtitle=\texttt{\char'074 segtitle\char'076 } (element)}\index{elements:!segtitle=\texttt{\char'074 segtitle\char'076 }} element
%       {\sffamily \textsc{must}} start each such
%       list. It will be used as a comment (for the
%       documentation) or a subheading (classes or
%       packages);
% \item Each \texttt{<seglistitem>}\index{seglistitem=\texttt{\char'074 seglistitem\char'076 } (element)}\index{elements:!seglistitem=\texttt{\char'074 seglistitem\char'076 }} {\sffamily \textsc{may}} have a documentary
%       comment in the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}}
%       attribute about why this package is being used. In the
%       case of the packages for your own class or package, this
%       comment is reproduced in the documentation of the
%       code.\par
% If an \emph{AutoPackage}
%       included package is specified, this comment is included
%       \emph{after} any documentation that gets
%       added by the \emph{AutoPackage}
%       mechanism (see
%       \vref{autopackage} for details);
% \item If the package must conform to a specific version,
%       the date {\sffamily \textsc{must}} be provided
%       in \textsc{iso} 8601 format in the \texttt{@version}\index{version=\texttt{\char'100 version} (attribute)}\index{attributes:!version=\texttt{\char'100 version}} attribute;
% \item \label{autooverride}Where a package will be included automatically with
%       specific options by the
%       \emph{AutoPackage} mechanism, and
%       you want to override them, give the specification you
%       want in the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute
%       of the \texttt{<seg>}\index{seg=\texttt{\char'074 seg\char'076 } (element)}\index{elements:!seg=\texttt{\char'074 seg\char'076 }} element as normal, but set the
%       \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} attribute to \texttt{"only"}\index{only=\texttt{"only"} (attribute value)}\index{attribute values:!only=\texttt{"only"}}, and ensure that there is
%       an entry for the specification you want in
%       {\ttfamily{}prepost.xml} positioned earlier than
%       the one which would otherwise have been autoincluded.
%       Currently the only candidate for this is the
%       \textsf{inputenc} package, for which
%       \textbf{\texttt{utf8x}} would be the normal default; but
%       its inclusion with the \textbf{\texttt{utf8}} (no
%       {\ttfamily{}x}) is achieved by this
%       method;
% \item \label{xlinkrole}If you want the package you are maintaining to
%       be included in its own documentation (perhaps so you can
%       use it for examples), you do it by setting the \texttt{@xlink:role}\index{xlink:role=\texttt{\char'100 xlink:role} (attribute)}\index{attributes:!xlink:role=\texttt{\char'100 xlink:role}} attribute on the
%       \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} root element to null as described in
%       ‘\textbf{\textsf{\texttt{@xlink:role}\index{xlink:role=\texttt{\char'100 xlink:role} (attribute)}\index{attributes:!xlink:role=\texttt{\char'100 xlink:role}}}}’, the last item in the list in \vref{selfspec}. You do
%       \emph{not} include it in the list of
%       packages described here. If you want specific options,
%       they can be given as the content of the \texttt{@xlink:role}\index{xlink:role=\texttt{\char'100 xlink:role} (attribute)}\index{attributes:!xlink:role=\texttt{\char'100 xlink:role}} attribute.
% \end{itemize}
% Order is significant \emph{except} for
%   packages for which there is an entry in the
%   {\ttfamily{}prepost.xml} database file (see \vref{autopackage} for details). Those matching
%   packages are always invoked first, \emph{in the order in
%     which they occur in
%     {\ttfamily{}prepost.xml}\thinspace}, and any
%   remaining (unmatched) packages come afterwards. The
%   \textsf{dox} package is a special case: it always
%   comes first.\par
% The resulting order is therefore:  \begin{enumerate*}[label=\emph{\alph*}),itemjoin={{; }},itemjoin*={{; and }}]
% \item \textsf{dox}\par
% \item packages requested in the
% \emph{Classpack} document which
% match {\ttfamily{}prepost.xml} packages,
% merged and sorted in the order in which they occur in
% {\ttfamily{}prepost.xml}\thinspace\par
% \item any other packages requested in the
% \emph{Classpack} document\par
% \end{enumerate*}. For example, for this document
%   (\emph{ClassPack}’s own documentation),
%   {\ttfamily{}classpack.xml} says:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
      <constraintdef xml:id="docpackages"> 
	<segmentedlist>
	  <segtitle>Packages required for the documentation</segtitle>
	  <seglistitem>
	    <seg role="ragged">footmisc</seg>
	  </seglistitem>
	  <seglistitem>
	    <seg>bbding</seg>
	  </seglistitem>
	  <seglistitem>
	    <seg role="obeyspaces,spaces">url</seg>
	  </seglistitem>
	</segmentedlist>
      </constraintdef>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% The console log of the process shows what was actually
%   included: first the results of the package-detection phase,
%   showing why each package was being selected:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=bash,breaklines=true,basicstyle=\fontsize{8}{9}\selectfont\color{Black}\ttfamily,]
This is DB2DTX, Version 1.27 (2024-01-30).
Making index.html for web site
Making package classpack
dox (1.001) default 
fix-cm (1.002) attribute-match=1 type/
fontspec (1.003) attribute-value match=1 part/@conformance=xelatex:
fontenc (1.006) default will be omitted because of fontspec
inputenc (1.007) attribute-value match=1 bibliography/@arch=biblatex:
inputenc (1.009) default will be omitted because of fontspec
noto (1.019) default 
bbding (1.038) element-match=176 acronym
mflogo (1.041) default 
babel (1.044) default 
biblatex (1.045) element-match=154 biblioref,exceptionname,citetitle
biblatex (1.045) attribute-value match=1 bibliography/@arch=biblatex:
csquotes (1.047) attribute-value match=1 bibliography/@arch=biblatex:
array (1.051) default 
calc (1.057) default 
ccaption (1.060) default 
enumitem (1.065) element-match=31 variablelist
enumitem (1.065) attribute-value match=6 orderedlist/@spacing=compact:@spacing=compact:,itemizedlist/@spacing=compact:@spacing=compact:@spacing=compact:@spacing=compact:
fancybox (1.066) element-match=14 note
fancyvrb (1.068) element-match=1 bibliography
relsize (1.073) element-match=176 acronym
textcase (1.076) default 
float (1.078) default 
fmtcount (1.079) attribute-value-pointer (37) xref/@linkend→varlistentry; @linkend→listitem; 
geometry (1.080) default 
fancyhdr (1.082) default 
graphicx (1.086) attribute-value match=1 part/@conformance=xelatex:
listings (1.092) element-match=73 programlisting
ltxcmds (1.094) default 
makeidx (1.095) default 
parskip (1.104) default 
ragged2e (1.106) attribute-value match=1 bibliography/@remap=shortbib:
sectsty (1.107) default 
ulem (1.114) element-match=3 link
url (1.115) element-match=12 email,uri,link
varioref (1.118) element-match=139 xref
xcolor (1.126) attribute-match=1 type/
xcolor (1.126) dependency match dox hypdoc hyperref classpack
classpack (1.130) default 
hypdoc (1.132) default 
hyperref (1.133) dependency match hypdoc
menukeys (1.134) element-match=5 guibutton,guilabel,guimenu,guisubmenu,guimenuitem
Passing options "svgnames" to package xcolor
Passing options "obeyspaces,spaces" to package url
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% In the resolution phase, packages are sorted in the
%   order determined in the {\ttfamily{}prepost.xml}
%   file, with multiple detections collapsed to a single
%   {\ttfamily{}\textbackslash{}usepackage} command.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX}]
  1.001. Package 'dox' (1×) being included
  1.002. Package 'fix-cm' (1×) being included
  1.003. Package 'fontspec' (1×) being included
  1.006. Package 'fontenc' (1×) omitted: transcluded by fontspec
  1.007. Package 'inputenc' (1×) omitted: transcluded by fontspec
  1.009. Package 'inputenc' (1×) omitted: transcluded by fontspec
  1.019. Package 'noto' (1×) being included
  1.038. Package 'bbding' (2×) being included
  1.041. Package 'mflogo' (1×) being included
  1.044. Package 'babel' (1×) being included
  1.045. Package 'biblatex' (2×) being included
  1.047. Package 'csquotes' (1×) being included
  1.051. Package 'array' (1×) being included
  1.057. Package 'calc' (1×) being included
  1.060. Package 'ccaption' (1×) being included
  1.065. Package 'enumitem' (2×) being included
  1.066. Package 'fancybox' (1×) being included
  1.068. Package 'fancyvrb' (1×) being included
  1.073. Package 'relsize' (1×) being included
  1.076. Package 'textcase' (1×) being included
  1.078. Package 'float' (1×) being included
  1.079. Package 'fmtcount' (1×) being included
  1.080. Package 'geometry' (1×) being included
  1.082. Package 'fancyhdr' (1×) being included
  1.086. Package 'graphicx' (1×) being included
  1.092. Package 'listings' (1×) being included
  1.094. Package 'ltxcmds' (1×) being included
  1.095. Package 'makeidx' (1×) being included
  1.104. Package 'parskip' (1×) being included
  1.106. Package 'ragged2e' (1×) being included
  1.107. Package 'sectsty' (1×) being included
  1.114. Package 'ulem' (1×) being included
  1.115. Package 'url' (2×) being included
  1.118. Package 'varioref' (1×) being included
  1.126. Package 'xcolor' (2×) being included
  1.130. Package 'classpack' (1×) being included
  1.132. Package 'hypdoc' (1×) being included
  1.133. Package 'hyperref' (1×) being included
  1.134. Package 'menukeys' (1×) being included
  1.069. Package 'footmisc' (1×) being included
Creating package 'classpack' (v1.27) with checksum 2409.
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% Some of these packages are included by default because I
%   have specified in my personal copy of the
%   {\ttfamily{}prepost.xml} database that they should
%   be, because I tend to use them in all my packages. Others
%   are included because I have used some document feature, for
%   example \texttt{<tgroup>}\index{tgroup=\texttt{\char'074 tgroup\char'076 } (element)}\index{elements:!tgroup=\texttt{\char'074 tgroup\char'076 }} for specifying a table layout
%   implies that I will need the \textsf{array}
%   package. This makes it much easier just to
%   \emph{write}, and let
%   \emph{ClassPack} take care of using the
%   right packages.\par
% New users should modify the
%   {\ttfamily{}prepost.xml} database contents and sort
%   order to suit their particular style and way of
%   working.\par
% \subsection{Specifying where in the {\ttfamily{}.dtx}
%   file to output packages}\label{dtxloc}
% Because the list of packages is stored out of line with
%   respect to the rest of your class or package code,
%   \emph{ClassPack} needs to be told
%   \emph{where} the relevant
%   {\ttfamily{}\textbackslash{}RequirePackage} commands must be added to
%   the {\ttfamily{}.dtx} file. Your class or package
%   design may also include preliminary commands needed before
%   packages are included or before a base class is loaded. You
%   specify the place in the {\ttfamily{}.dtx} file to
%   include packages by using the \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} attribute on the
%   \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} element which holds the package
%   list to give the value of an \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} on a particular
%   \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} or \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }} in your annotated
%   code (see example below).\par
% \par\begingroup
%   \fboxsep1em\centering
%   \fbox{\begin{minipage}{0.8\columnwidth}\sffamily
%  \raggedright\parindent0pt
%  \parskip=.5\baselineskip
% There is no default: you
%     {\sffamily \textsc{must}} specify this
%     link yourself, otherwise the list of required
%     packages will not be output.\par
% \end{minipage}}\par\endgroup
% \begin{itemize}
% \item If the \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} or \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }} which
%       you specify is non-empty (ie has content (text) in it),
%       the {\ttfamily{}\textbackslash{}RequirePackage} commands are
%       output as the content of a new \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} or
%       \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }} immediately preceding or following it,
%       as specified by the value of the \texttt{<role>}\index{role=\texttt{\char'074 role\char'076 } (element)}\index{elements:!role=\texttt{\char'074 role\char'076 }}
%       attribute on the same \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} element
%       (set to \texttt{"before"}\index{before=\texttt{"before"} (attribute value)}\index{attribute values:!before=\texttt{"before"}} or \texttt{"after"}\index{after=\texttt{"after"} (attribute value)}\index{attribute values:!after=\texttt{"after"}}).\par
% \item If the \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} or \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }} you
%       have specified is empty (no text content), the
%       {\ttfamily{}\textbackslash{}RequirePackage} commands are output
%       \emph{as if they were the content} of that
%       \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} or \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }}.\par
% \end{itemize}
% As an example, suppose you specify the
%   \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} for the packages for a class with:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<constraintdef xml:id="clspackages" linkend="options" role="after">
  ...
</constraintdef>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% There {\sffamily \textsc{must}} then be a
%     \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} or \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }} in your annotated
%     code with the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} value of
%     \texttt{"options"}\index{options=\texttt{"options"} (attribute value)}\index{attribute values:!options=\texttt{"options"}}. If it is empty of any
%     text (no character data content) like this:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<sect1 xml:id="options">
  <title/>
  <para/>
</sect1>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% then the list of {\ttfamily{}\textbackslash{}RequirePackage}
%   commands will be output \emph{in its place}.
%   (Note that the empty title and paragraph are required by
%   \emph{DocBook} for validity.)\par
% If, on the other hand, the specified section has text
%   and code of its own:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<sect1 xml:id="options">
    <title>Options</title>
    <para>text...</para>
    <programlisting>
\some{code}
    </programlisting>
</sect1>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% then the list of {\ttfamily{}\textbackslash{}RequirePackage}
%   commands will be output immediately after it (because \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} says \texttt{"after"}\index{after=\texttt{"after"} (attribute value)}\index{attribute values:!after=\texttt{"after"}}), as a new
%   \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }}.\par
% In both cases, the \texttt{<segtitle>}\index{segtitle=\texttt{\char'074 segtitle\char'076 } (element)}\index{elements:!segtitle=\texttt{\char'074 segtitle\char'076 }} of the
%   \texttt{<segmentedlist>}\index{segmentedlist=\texttt{\char'074 segmentedlist\char'076 } (element)}\index{elements:!segmentedlist=\texttt{\char'074 segmentedlist\char'076 }} in the \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} (if
%   there is one) will be used as the title of the
%   section.\par
% \subsection{Additional setup commands for documentation}\label{addsetup}
% In the documentation for a class or package, there is
%   sometimes a need to use individual \LaTeX{} commands to
%   adjust document settings more finely than a package
%   provides, either in the Preamble of the
%   {\ttfamily{}.dtx} file or even immediately after the
%   \verb|\begin{document}| command.\par
% There would typically not be many of these, as the
%   default format for Doc\TeX{} documents is the (fairly plain)
%   \index{ltxdoc@\textsf{ltxdoc} (class)}\index{classes:!ltxdoc@\textsf{ltxdoc}}\textsf{ltxdoc} class, based on the
%   \index{article@\textsf{article} (class)}\index{classes:!article@\textsf{article}}\textsf{article} class, and rarely varied. In
%   the case where an in-house documentation style is needed, or
%   an author prefers to use a different style with the
%   \index{ltxdoc@\textsf{ltxdoc} (class)}\index{classes:!ltxdoc@\textsf{ltxdoc}}\textsf{ltxdoc} class, the changes would
%   normally be implemented in a separate package, so there
%   would equally not be many individual commands to
%   implement here.\par
% When there is a need for setup commands, they go in
%   \emph{additional} \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }}
%   elements (this is the first of two additional use cases
%   mentioned in the warning in \vref{tagwarn}: the other is
%   in \vref{manifestfiles}).\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily
% Note that commands that you want implemented
%     \emph{every time you use a particular
%       package} should go in your
%     {\ttfamily{}prepost.xml} database file, as
%     described in \vref{autospec}.\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% \subsubsection{\LaTeX{} commands to appear in the documentation
%     Preamble}
% Use the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} value of
%     \texttt{"atendpreamble"}\index{atendpreamble=\texttt{"atendpreamble"} (attribute value)}\index{attribute values:!atendpreamble=\texttt{"atendpreamble"}} on the
%     \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} element. Commands are output to
%     the {\ttfamily{}.dtx} file immediately after the
%     documentation’s {\ttfamily{}\textbackslash{}usepackage}
%     commands.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<constraintdef xml:id="atendpreamble">
  <procedure>
    <step>
      <cmdsynopsis>
        <command>\setmonofont[Scale=MatchLowercase]{Inconsolata}</command>
    </step>
  </procedure>
</constraintdef>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% In this case, the Inconsolata font is not available
%     as a package, so a separate command is needed.\par
% \subsubsection{\LaTeX{} commands to appear before the start of the
%     documentation text}
% If the commands have to go after the Preamble, set the
%     \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute to \texttt{"atbegindoc"}\index{atbegindoc=\texttt{"atbegindoc"} (attribute value)}\index{attribute values:!atbegindoc=\texttt{"atbegindoc"}} on the
%     \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} element. Commands in this
%     category are output at the start of the documentation text
%     \emph{after} the
%     \verb|\begin{document}| command (where they
%     will be executed during the {\ttfamily{}\textbackslash{}DocInput}
%     phase of Doc\TeX{} processing). For example:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<constraintdef xml:id="atbegindoc">
  <procedure>
    <step>
      <cmdsynopsis>
        <command>\setcounter{tocdepth}{5}</command>
	    <command>\setcounter{secnumdepth}{5}</command>
        <command>\def\@@doxdescribe#1#2{\endgroup
    \ifdox@noprint\else\marginpar{\raggedleft
      \@nameuse{PrintDescribe#1}{\LabelFont[\color{DarkRed}]{#2}}}\fi
    \ifdox@noindex\else
       \@nameuse{Special#1Index}{#2}\fi
    \endgroup\@esphack\ignorespaces}</command>
      </cmdsynopsis>
    </step>
  </procedure>
</constraintdef>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily
% The new \textsf{dtxdescribe} package now
%       provides much of this functionality; A future version of
%       \textsf{ClassPack} will drop this code and
%       switch to using \textsf{dtxdescribe}.\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% (The {\ttfamily{}\textbackslash{}@@doxdescribe} command is an
%     oddity here: all it does is redefine the marginal print
%     value for ibline documentation to use a narrow red font
%     for reference purposes, but it does not work if placed in
%     the {\ttfamily{}prepost.xml} database
%     file.)\par
% Commands specified in this category are automatically
%     tested for the presence of {\ttfamily{}@}
%     signs, and enclosed in {\ttfamily{}\textbackslash{}makeatletter} and
%     {\ttfamily{}\textbackslash{}makeatother} commands.\par
% \subsection{The Manifest}\label{manifestfiles}
% \changes{v1.08}{2018/02/07}{Changed reference to ‘last’ variant to ‘second’ now that the section on mechanically-constructed commands has been removed.}
% The second variant of the \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} element
%   (with the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute of
%   \texttt{"manifest"}\index{manifest=\texttt{"manifest"} (attribute value)}\index{attribute values:!manifest=\texttt{"manifest"}}) is very simple. It is
%   a list of the names of any separate files that you want
%   included in the Zip file that the {\ttfamily{}make} command produces. This
%   means anything other than the {\ttfamily{}.dtx}\thinspace,
%   {\ttfamily{}.ins}\thinspace, {\ttfamily{}.pdf}\thinspace, and
%   {\ttfamily{}README.md} files that get included
%   automatically.\par
% The content of this element is a \texttt{<simplelist>}\index{simplelist=\texttt{\char'074 simplelist\char'076 } (element)}\index{elements:!simplelist=\texttt{\char'074 simplelist\char'076 }},
%   containing \texttt{<member>}\index{member=\texttt{\char'074 member\char'076 } (element)}\index{elements:!member=\texttt{\char'074 member\char'076 }} elements, one per file, for
%   example:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<constraintdef xml:id="manifest">
  <simplelist>
    <member>doctexbook.dtd</member>
    <member>db2dtx.xsl</member>
    <member>db2bibtex.xsl</member>
    <member>figtab2latex.xsl</member>
    <member>db2md.xsl</member>
    <member>prepost.xml</member>
    <member>lppl.xml</member>
    <member>decommentbbl.awk</member>
    <member>readme.xml</member>
    <member>Makefile</member>
  </simplelist>
</constraintdef>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% \clearpage
% \section{Automated package inclusion}\label{autospec}
% There are several reasons for automating the inclusion
% of packages, especially in documentation:\par
% \begin{itemize}
% \item Many \LaTeX{} authors and maintainers have favourite
%     packages or settings that they like to use every time they
%     write class or package documentation.\par
% \item Some options have now become the \emph{de
%       facto} convention for their package (for
%     example, the \textbf{\texttt{utf8x}} option on the
%     \textsf{inputenc} package and the
%     \textbf{\texttt{T1}} option on the
%     \textsf{fontenc} package);
% \item Authors and maintainers may have their own per-package
%     preferences to suit their way of writing.\par
% \item There are \emph{de jure}
%     commands that have to be used whenever a particular
%     package is invoked (for example, using the
%     \textsf{makeidx} package means you
%     {\sffamily \textsc{must}} add the
%     {\ttfamily{}\textbackslash{}makeindex} command to the
%     Preamble).\par
% \item Some packages depend on aspects of the documentation;
%     that is, they only become necessary when a particular
%     formatting feature is used (for example certain tabular
%     alignment column types like {\ttfamily{}m} or
%     {\ttfamily{}b} {\sffamily \textsc{require}} the
%     \textsf{array} package; or using
%     \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }} or \texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }} \emph{inside} a paragraph
%     {\sffamily \textsc{requires}} the
%     \textsf{enumitem} package, which enables inline
%     lists with automated punctuation). This avoids the author
%     having to remember to include a specific package when such
%     a feature is used, or to remember to remove it if the
%     feature is no longer used.\par
% \item Some packages are \emph{dependencies} on
%     other packages. Most of these are handled within those
%     packages, but (for example) if you want a specific colour
%     palette option like \textbf{\texttt{svgnames}} in the
%     \textsf{xcolor} package when using
%     \textsf{hyperref}, you need to signal this to
%     \textsf{xcolor} beforehand with a
%     {\ttfamily{}\textbackslash{}PassOptionsToPackage} command, as in
%     \vref{preloads}.\par
% \end{itemize}
% \emph{AutoPackage} uses the
% \textsc{xml} structure of the document to detect
% when specific packages are needed, via the
% {\ttfamily{}prepost.xml} file, which acts as a
% lookup.\par
% \subsection{Packages preloaded before the document class declaration}\label{preloads}
% One package (\textsf{fix-cm}) is invariably
%   preloaded \emph{before} the document class
%   (\index{ltxdoc@\textsf{ltxdoc} (class)}\index{classes:!ltxdoc@\textsf{ltxdoc}}\textsf{ltxdoc}) is declared, and two further
%   packages have an option pre-specified with the
%   {\ttfamily{}\textbackslash{}PassOptionsToPackage} in certain
%   circumstances. These are currently:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX}]
\RequirePackage{fix-cm}
\PassOptionsToPackage{svgnames}{xcolor}
\PassOptionsToPackage{british}{babel}
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% \begin{itemize}
% \item The \textsf{fix-cm} package removes the
%       lock on using \emph{only} the predefined
%       step-sizes of type specified in the Font Definition
%       files for Computer Modern (and followed for many other
%       fonts).\footnote{%
% This may be replaced at a future date with the
%   \textsf{anyfontsize} package.\par}\par
% This package allows arbitrary font sizes to be
%       specified, which is useful — even essential — in
%       the documentation of code blocks (in the
%       \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} element), where a block with
%       an unavoidably long line may need a carefully-chosen
%       smaller font size to fit. This is required even with
%       \XeLaTeX{}. See ‘\textbf{\textsf{\texttt{@wordsize}\index{wordsize=\texttt{\char'100 wordsize} (attribute)}\index{attributes:!wordsize=\texttt{\char'100 wordsize}}}}’, the second item in the list in \vref{wordsize} for details of
%       how to do this;
% \item We prefer to use the \textsc{svg} colour
%       palette by default; the \textsf{hyperref}
%       package does not, making it hard to respecify a palette
%       once it is loaded. Passing the option to
%       \textsf{xcolor} in advance overrides this
%       problem. This option is specified by default, because
%       \textsf{xcolor} is required by
%       \textsf{hyperref}, which we use by default as
%       it gets loaded by \textsf{hypdoc}; and also by
%       \emph{ClassPack}’s modifications to
%       the \textsf{dox} package. This option should
%       probably be configurable.\par
% \item The \textsf{url} package used to be
%       preloaded with the \textbf{\texttt{hyphens}} option, but
%       this code was removed in v1.16 because it was felt to be
%       problematic as a piece of automation (it applies to
%       breaking on hyphens in \textsc{uri}s, which is
%       deprecated).\par
% \item \label{babeload}The \textsf{babel} package used to be
%       loaded automatically from
%       {\ttfamily{}prepost.xml} with the single option
%       \textbf{\texttt{british}} as a result of using
%       \textsf{biblatex}, and then loaded again if
%       multiple languages were detected. This led to option
%       clashes, so now the multiple languages are detected from
%       the use of the \texttt{@xml:lang}\index{xml:lang=\texttt{\char'100 xml:lang} (attribute)}\index{attributes:!xml:lang=\texttt{\char'100 xml:lang}}
%       attribute in the document, and the relevant
%       {\ttfamily{}\textbackslash{}PassOptionsToPackage} command created.
%       If there were no \texttt{@xml:lang}\index{xml:lang=\texttt{\char'100 xml:lang} (attribute)}\index{attributes:!xml:lang=\texttt{\char'100 xml:lang}}
%       attributes, this command is not issued.\par
% The default value for English-language \LaTeX{} is
%       {\ttfamily{}en-US} (American English). To
%       change this, specify a new value in the \texttt{@xml:lang}\index{xml:lang=\texttt{\char'100 xml:lang} (attribute)}\index{attributes:!xml:lang=\texttt{\char'100 xml:lang}} attribute on the
%       document root element, \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }}. Note that the
%       order of entries in the
%       {\ttfamily{}languages.xml} file is
%       \emph{significant} and that where there is
%       ambiguity, the \emph{last} matching value
%       wins.\par
% \end{itemize}
% These features are currently all implemented in the
%   \textsc{xslt} code: a future version may move
%   them to a configuration file, perhaps
%   {\ttfamily{}prepost.xml}\thinspace.\par
% \subsection{The {\ttfamily{}prepost.xml} lookup file}\label{prepost-setup}
% To automate package loading, an ancillary lookup file
%   {\ttfamily{}prepost.xml} is used as a database. This
%   file is a \emph{DocBook} document with a
%   \texttt{<refsection>}\index{refsection=\texttt{\char'074 refsection\char'076 } (element)}\index{elements:!refsection=\texttt{\char'074 refsection\char'076 }} root element type containing exactly
%   two \texttt{<procedure>}\index{procedure=\texttt{\char'074 procedure\char'076 } (element)}\index{elements:!procedure=\texttt{\char'074 procedure\char'076 }} elements, as shown below.\par
% The location of the {\ttfamily{}prepost.xml}
%   file is specified in the {\ttfamily{}\$(CPP)} variable
%   in the {\ttfamily{}Makefile}\thinspace. It would typically be
%   a shared copy, located in the parent directory (that is, one
%   level above the directories used for individual class and
%   package projects), but it {\sffamily \textsc{may}}
%   equally be a per-project file in the project directories
%   themselves; so long as the {\ttfamily{}Makefile}
%   points at the right copy, all shall be well.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<refsection>
  <title>Commands to use before and after packages being loaded</title>
  <procedure xml:id="prepackage">
    ...steps...
  </procedure>
  <procedure xml:id="postpackage">
    ...steps...
  </procedure>
</refsection>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% \begin{enumerate}
% \item Each entry for a package goes in a \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }}
%       element with the \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}}
%       attribute set to the name of the package, and the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} attribute containing
%       a space-separated list of use cases (\texttt{doc},
%       \texttt{cls}, and \texttt{sty}). See the example
%       below and the description in \vref{prepost-spec}.\par
% \item A package {\sffamily \textsc{may}} be
%       set up in either \texttt{<procedure>}\index{procedure=\texttt{\char'074 procedure\char'076 } (element)}\index{elements:!procedure=\texttt{\char'074 procedure\char'076 }} section, or
%       both.\par
% \begin{itemize}[noitemsep]
% \item The \texttt{"prepackage"}\index{prepackage=\texttt{"prepackage"} (attribute value)}\index{attribute values:!prepackage=\texttt{"prepackage"}}
%   section is for packages with additional commands
%   which need to be executed
%   \emph{before} the package is
%   invoked.\par
% \item The \texttt{"postpackage"}\index{postpackage=\texttt{"postpackage"} (attribute value)}\index{attribute values:!postpackage=\texttt{"postpackage"}}
%   section is for packages with additional commands
%   which need to be executed \emph{after}
%   the package is invoked. \par
% \end{itemize}
% \item If a package requires neither type of additional
%       command[s], it {\sffamily \textsc{may}} be
%       put in either \texttt{<procedure>}\index{procedure=\texttt{\char'074 procedure\char'076 } (element)}\index{elements:!procedure=\texttt{\char'074 procedure\char'076 }} section.\par
% \item An entry for a package
%       {\sffamily \textsc{should}} also contain a
%       sentence of documentation in a \texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }}
%       subelement, which will be used in the documentation of
%       the code.\par
% \item Order is \emph{critical}: the order in
%       which packages are written to the
%       {\ttfamily{}.dtx} file (and therefore the order
%       in which they are loaded in \LaTeX{}) is determined by
%       the order of the \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} elements in this
%       file.\par
% This frees the author from having to consider what
%       order to specify package in, but it imposes a duty on
%       the \emph{ClassPack} maintainers to
%       keep the order of \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} elements
%       correct.\par
% \end{enumerate}
% Here is a simple example of an entry for the
%   \textsf{bbding} package for assorted dingbats,
%   icons, and symbols:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<step condition="doc cls sty" remap="bbding">
  <para>Collection of dingbats (icons).</para>
</step>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% This specifies that the \textsf{dingbats}
%   package may be requested by the author and it may be loaded
%   for documentation, a class, or a package; and that the
%   specified sentence of documentation will be included in the
%   documentation, in the list of packages loaded.\footnote{%
% Apart from the sentence of documentation, this entry
%       is largely redundant, as any package requested by an
%       author, and not present in
%       {\ttfamily{}prepost.xml}\thinspace, will be included
%       anyway.\par}\par
% Packages are output to the {\ttfamily{}.dtx}
%   file using {\ttfamily{}\textbackslash{}RequirePackage} commands (for
%   the documentation) or {\ttfamily{}\textbackslash{}usepackage} commands
%   (for the class or package itself), \emph{in the order in
%     which they occur in the {\ttfamily{}prepost.xml}
%     file, \textbf{\upshape regardless of the order in which they were
%       given in the document}} (that it, in
%   the \texttt{<segmentedlist>}\index{segmentedlist=\texttt{\char'074 segmentedlist\char'076 } (element)}\index{elements:!segmentedlist=\texttt{\char'074 segmentedlist\char'076 }} element where they were
%   specified: see \vref{listpack}). The console log
%   shows the entry number in {\ttfamily{}prepost.xml}
%   for reference, and this also appears in the
%   {\ttfamily{}autopack.xml} log file in the \texttt{@userlevel}\index{userlevel=\texttt{\char'100 userlevel} (attribute)}\index{attributes:!userlevel=\texttt{\char'100 userlevel}} attribute (see ‘\textbf{\textsf{{\ttfamily{}autopack.xml}\thinspace}}’, the second item in the list in \vref{apx}).\par
% This allows {\ttfamily{}prepost.xml} to impose a
%   known required sequence of some packages which
%   {\sffamily \textsc{must}} be loaded before
%   others — for example, \textsf{hyperref} being
%   loaded last of all, except for
%   \textsf{glossaries}, which needs to come after
%   that; and font packages under \XeLaTeX{} or Lua\LaTeX{}, which
%   may need a specific order of invocation.\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily\label{xescale}
% \subsubsection*{Scaling fonts with \XeLaTeX{} and Lua\LaTeX{}}
% Some sans-serif and monospace fonts may need scaling
%     to match the document’s serif font, so they
%     {\sffamily \textsc{must}} be loaded
%     \emph{after} the serif font. Font packages
%     in {\ttfamily{}prepost.xml} are therefore grouped
%     using the \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}} attribute:
%     \texttt{"serif"}\index{serif=\texttt{"serif"} (attribute value)}\index{attribute values:!serif=\texttt{"serif"}}, \texttt{"sans"}\index{sans=\texttt{"sans"} (attribute value)}\index{attribute values:!sans=\texttt{"sans"}}, \texttt{"mono"}\index{mono=\texttt{"mono"} (attribute value)}\index{attribute values:!mono=\texttt{"mono"}}, \texttt{"math"}\index{math=\texttt{"math"} (attribute value)}\index{attribute values:!math=\texttt{"math"}}, \texttt{"hand"}\index{hand=\texttt{"hand"} (attribute value)}\index{attribute values:!hand=\texttt{"hand"}}, and \texttt{"symbol"}\index{symbol=\texttt{"symbol"} (attribute value)}\index{attribute values:!symbol=\texttt{"symbol"}}. The scaling can be done
%     with the option
%     {\ttfamily{}Scale=MatchLowercase} in the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute of the
%     \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} for the package.\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% The exception to this ordering is packages you specify
%   in the document for which no entry in
%   {\ttfamily{}prepost.xml} [yet] exists. These are
%   loaded last of all, which is a known risk.  A warning
%   message is issued to the console during the processing of
%   the \textsc{xslt} script if a package is specified
%   which has no entry in {\ttfamily{}prepost.xml}\thinspace, and
%   they are shown with the number 666.\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily
% We {\sffamily \textsc{strongly recommend}}
%     developers to add all missing packages which they use to
%     their local copy of {\ttfamily{}prepost.xml}\thinspace; to
%     document and pay careful attention to where in the file
%     they locate them; and periodically to upload the file to
%     Silmaril so that others can benefit from their research.
%     The \texttt{@vendor}\index{vendor=\texttt{\char'100 vendor} (attribute)}\index{attributes:!vendor=\texttt{\char'100 vendor}} attribute can be
%     used to add the developer’s username or number so that
%     acknowledgement can be given.\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% \subsection{Specifying known packages and default options}\label{prepost-spec}
% Within the two \texttt{<procedure>}\index{procedure=\texttt{\char'074 procedure\char'076 } (element)}\index{elements:!procedure=\texttt{\char'074 procedure\char'076 }} elements, each
%   package is identified in a \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} element.\par
% \begin{itemize}[noitemsep]
% \item the \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}} attribute
%       holds the package name;
% \item the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}}
%       attribute holds the type[s] of use this entry is intended
%       to be effective for, \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}}, \texttt{"cls"}\index{cls=\texttt{"cls"} (attribute value)}\index{attribute values:!cls=\texttt{"cls"}}, or \texttt{"sty"}\index{sty=\texttt{"sty"} (attribute value)}\index{attribute values:!sty=\texttt{"sty"}} (space-separated if
%       more than one);
% \item the optional \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}}
%       attribute holds any default options (comma-separated,
%       exactly as they would be if typed into a \LaTeX{}
%       document) that should be applied when the package is
%       invoked;
% \item the optional \texttt{@revision}\index{revision=\texttt{\char'100 revision} (attribute)}\index{attributes:!revision=\texttt{\char'100 revision}}
%       attribute can hold a date (in
%       \textsc{iso} 8601, not \LaTeX{} format) used to
%       impose a version-date restriction on the loading of the
%       package.\par
% Note that a date specified for a package listed in a
%       \texttt{<seglistitem>}\index{seglistitem=\texttt{\char'074 seglistitem\char'076 } (element)}\index{elements:!seglistitem=\texttt{\char'074 seglistitem\char'076 }} in the
%       \emph{ClassPack} document itself
%       will override any date specified in the
%       {\ttfamily{}prepost.xml} file;
% \item the optional \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}} used
%       to identify the class of a font package: \texttt{"serif"}\index{serif=\texttt{"serif"} (attribute value)}\index{attribute values:!serif=\texttt{"serif"}}, \texttt{"sans"}\index{sans=\texttt{"sans"} (attribute value)}\index{attribute values:!sans=\texttt{"sans"}}, \texttt{"mono"}\index{mono=\texttt{"mono"} (attribute value)}\index{attribute values:!mono=\texttt{"mono"}}, or \texttt{"math"}\index{math=\texttt{"math"} (attribute value)}\index{attribute values:!math=\texttt{"math"}}or \texttt{"hand"}\index{hand=\texttt{"hand"} (attribute value)}\index{attribute values:!hand=\texttt{"hand"}}or \texttt{"symbol"}\index{symbol=\texttt{"symbol"} (attribute value)}\index{attribute values:!symbol=\texttt{"symbol"}} (see the note in \vref{xescale}).\par
% \item the optional \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} attribute can hold
%       a coded warning that some additional processing is
%       needed. Only one value is currently supported, \texttt{"nosc"}\index{nosc=\texttt{"nosc"} (attribute value)}\index{attribute values:!nosc=\texttt{"nosc"}}, to signal that a font has
%       no Caps and Small Caps variant; so that if the document
%       markup invokes a feature known to require small caps, an
%       alternative can be provided. This is experimental and
%       may be dropped or superseded.\par
% \end{itemize}
% The \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} element
%   {\sffamily \textsc{must}} contain a
%   \texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }} subelement holding a short explanation of
%   what the package does. This is added as a comment to the
%   annotated code, when invoked by a package listed in a
%   \texttt{<seglistitem>}\index{seglistitem=\texttt{\char'074 seglistitem\char'076 } (element)}\index{elements:!seglistitem=\texttt{\char'074 seglistitem\char'076 }} in the \texttt{"stypackages"}\index{stypackages=\texttt{"stypackages"} (attribute value)}\index{attribute values:!stypackages=\texttt{"stypackages"}} or \texttt{"clspackages"}\index{clspackages=\texttt{"clspackages"} (attribute value)}\index{attribute values:!clspackages=\texttt{"clspackages"}} \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} settings (see \vref{listpack}).\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<step role="utf8x" remap="inputenc" condition="cls doc sty"
      revision="2008-03-30">
  <para>UTF-8 is the default character set, to allow for use of
        any character in any writing system. Some characters 
        are not	specified for all fonts, so may have to be 
        specified manually.</para>
</step>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% In the example above, specifying
%   \textsf{inputenc} in a
% \emph{ClassPack} document, in a
%   \texttt{<seg>}\index{seg=\texttt{\char'074 seg\char'076 } (element)}\index{elements:!seg=\texttt{\char'074 seg\char'076 }} element as described in \vref{listpack}, results in the package being
%   added to the class or package code with the option
%   \textbf{\texttt{utf8x}} and the date constraint:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX}]
\RequirePackage[utf8x]{inputenc}[2008/03/30]
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% A \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} element may occur in the
%   {\ttfamily{}prepost.xml} file up to three times in
%   each \texttt{<procedure>}\index{procedure=\texttt{\char'074 procedure\char'076 } (element)}\index{elements:!procedure=\texttt{\char'074 procedure\char'076 }} section in
%   {\ttfamily{}prepost.xml}\thinspace, with different settings
%   (one for a class, one for a package, and one for the
%   documentation). In the post-package section, the package
%   would only appear to specify command code to include
%   \emph{after} the package gets loaded, not for
%   any other purpose. A documentation paragraph only need occur
%   once, even if the package is entered both in the pre- and
%   post-package sections, but in the post-package section, the
%   paragraph typically describes the additional commands that
%   are being included.\par
% \subsection{Automating inclusion}\label{autopackage}
% To make a package load automatically into every class or
%   package or documentation, according to specified conditions,
%   add one or more \texttt{<constructorsynopsis>}\index{constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 } (element)}\index{elements:!constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 }} elements
%   within the \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} element for a package
%   (\emph{after} the \texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }} element)
%   \emph{in the pre-package section}.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<step condition="doc" remap="varioref">
  <para>Provides extended formatting of cross-references.</para>
  <constructorsynopsis condition="xref"/>
</step>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% These \texttt{<constructorsynopsis>}\index{constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 } (element)}\index{elements:!constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 }} elements specify
%   the condition(s) under which the package will automatically
%   be included \emph{without the author needing to specify
%     it} in a \texttt{<seg>}\index{seg=\texttt{\char'074 seg\char'076 } (element)}\index{elements:!seg=\texttt{\char'074 seg\char'076 }} element in the document
%   itself (as described in \vref{listpack}).\par
% The \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} attribute on
%   the \texttt{<constructorsynopsis>}\index{constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 } (element)}\index{elements:!constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 }} element specifies a
%   \emph{DocBook} \textsc{xml}
%   element type name. If this element type occurs anywhere in
%   the relevant \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }} of the
%   \emph{ClassPack} document (as specified
%   in the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} attribute of
%   the parent \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }}), the package is included.\par
% In the example above, the \textsf{varioref}
%   package will be added if an \texttt{<xref>}\index{xref=\texttt{\char'074 xref\char'076 } (element)}\index{elements:!xref=\texttt{\char'074 xref\char'076 }} element is
%   present anywhere in the documentation.\par
% There are six ways in which a package can be
%   specified for inclusion:\par
% \subsubsection{Default inclusion (unconditional)}
% If the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}}
%     attribute is present but empty (set to \texttt{""}),
%     the package will always be included in the type of output
%     (\texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}}, \texttt{"cls"}\index{cls=\texttt{"cls"} (attribute value)}\index{attribute values:!cls=\texttt{"cls"}}, or \texttt{"sty"}\index{sty=\texttt{"sty"} (attribute value)}\index{attribute values:!sty=\texttt{"sty"}}) specified in the parent
%     \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} element start-tag.\par
% \subsubsection{Inclusion when a particular element type is
%     used}
% If the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}}
%     attribute holds the name of a
%     \emph{DocBook} element type, the
%     package will be included automatically if this element
%     type if used anywhere in the documentation part of the
%     \emph{ClassPack} document (see example
%     above).\par
% \subsubsection{Inclusion when an attribute on an element type is
%     used}
% If one or more \texttt{<methodparam>}\index{methodparam=\texttt{\char'074 methodparam\char'076 } (element)}\index{elements:!methodparam=\texttt{\char'074 methodparam\char'076 }} subelements
%     are present, they specify attribute conditions on the
%     element type named in the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} attribute.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX}]
<step condition="cls sty" remap="graphicx">
  <para>Provide for graphics (PNG, JPG, or PDF format (only) for
	pdflatex; EPS format (only) for standard &LaTeX;).</para>
  <constructorsynopsis condition="imagedata">
    <methodparam>
      <parameter>fileref</parameter>
    </methodparam>
  </constructorsynopsis>
</step>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% The \texttt{<parameter>}\index{parameter=\texttt{\char'074 parameter\char'076 } (element)}\index{elements:!parameter=\texttt{\char'074 parameter\char'076 }} element specifies
%     the name of an attribute. If no \texttt{<modifier>}\index{modifier=\texttt{\char'074 modifier\char'076 } (element)}\index{elements:!modifier=\texttt{\char'074 modifier\char'076 }}
%     element is present, the package will be included
%     automatically if the attribute is present in the document
%     on the specified element type, regardless of its value.\par
% In the example above, the \textsf{graphicx}
%     package will be included if the class or style package
%     code includes an \texttt{<imagedata>}\index{imagedata=\texttt{\char'074 imagedata\char'076 } (element)}\index{elements:!imagedata=\texttt{\char'074 imagedata\char'076 }} element with a \texttt{@fileref}\index{fileref=\texttt{\char'100 fileref} (attribute)}\index{attributes:!fileref=\texttt{\char'100 fileref}} attribute.\par
% \subsubsection{Inclusion when an attribute on an element type
%     has a specific value}
% A \texttt{<modifier>}\index{modifier=\texttt{\char'074 modifier\char'076 } (element)}\index{elements:!modifier=\texttt{\char'074 modifier\char'076 }} element specifies a value
%     for the attribute named in the \texttt{<parameter>}\index{parameter=\texttt{\char'074 parameter\char'076 } (element)}\index{elements:!parameter=\texttt{\char'074 parameter\char'076 }}
%     element; the package will be included automatically if
%     the attribute is used with this value in the document
%     on the specified element type.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<step remap="dcolumn" condition="doc">
  <constructorsynopsis condition="colspec">
    <methodparam>
      <parameter>align</parameter>
      <modifier>char</modifier>
    </methodparam>
  </constructorsynopsis>
</step>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% In the example above, a \texttt{<colspec>}\index{colspec=\texttt{\char'074 colspec\char'076 } (element)}\index{elements:!colspec=\texttt{\char'074 colspec\char'076 }} element
%     anywhere in the documentation with an \texttt{@align}\index{align=\texttt{\char'100 align} (attribute)}\index{attributes:!align=\texttt{\char'100 align}} attribute equal to
%     \texttt{"char"}\index{char=\texttt{"char"} (attribute value)}\index{attribute values:!char=\texttt{"char"}} will cause the
%     \textsf{dcolumn} package to be included
%     automatically (that package handles decimal-column
%     alignment).\par
% In this version of
%     \emph{ClassPack}, multiple instances
%     of the \texttt{<methodparam>}\index{methodparam=\texttt{\char'074 methodparam\char'076 } (element)}\index{elements:!methodparam=\texttt{\char'074 methodparam\char'076 }} selector are treated as
%     alternatives: the package will be included if just one of
%     them is true. There is no provision at the moment for
%     applying a Boolean {\ttfamily{}AND} to this
%     selection mechanism.\par
% \subsubsection{Inclusion when an element references a specific
%     element type via the ID/IDREF mechanism}
% This is a special case involving the use of the \texttt{@funcparams}\index{funcparams=\texttt{\char'100 funcparams} (attribute)}\index{attributes:!funcparams=\texttt{\char'100 funcparams}} subelement
%     \emph{instead of} the \texttt{@parameter}\index{parameter=\texttt{\char'100 parameter} (attribute)}\index{attributes:!parameter=\texttt{\char'100 parameter}} attribute. This
%     specifies that an \texttt{IDREF}\index{IDREF=\texttt{IDREF} (local name)}\index{local names:!IDREF=\texttt{IDREF}}
%     attribute must be checked for the
%     \emph{type} of element it refers to.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<step condition="doc" remap="fmtcount">
  <constructorsynopsis condition="xref">
    <methodparam>
      <funcparams>linkend</funcparams>
      <modifier>varlistentry</modifier>
    </methodparam>
    <methodparam>
      <funcparams>linkend</funcparams>
      <modifier>listitem</modifier>
    </methodparam>
  </constructorsynopsis>
</step>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% In this example, the \textsf{fmtcount}
%     package will be included if there is an
%     \texttt{<xref>}\index{xref=\texttt{\char'074 xref\char'076 } (element)}\index{elements:!xref=\texttt{\char'074 xref\char'076 }} element anywhere in the documentation
%     with a \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} attribute
%     which points at an \emph{element type}
%     of \texttt{<varlistentry>}\index{varlistentry=\texttt{\char'074 varlistentry\char'076 } (element)}\index{elements:!varlistentry=\texttt{\char'074 varlistentry\char'076 }} or \texttt{<listitem>}\index{listitem=\texttt{\char'074 listitem\char'076 } (element)}\index{elements:!listitem=\texttt{\char'074 listitem\char'076 }}
%     (rather than an element with a specified value, as
%     would be the case with using \texttt{<parameter>}\index{parameter=\texttt{\char'074 parameter\char'076 } (element)}\index{elements:!parameter=\texttt{\char'074 parameter\char'076 }});
%     that is, if there is a \texttt{<varlistentry>}\index{varlistentry=\texttt{\char'074 varlistentry\char'076 } (element)}\index{elements:!varlistentry=\texttt{\char'074 varlistentry\char'076 }} or
%     \texttt{<listitem>}\index{listitem=\texttt{\char'074 listitem\char'076 } (element)}\index{elements:!listitem=\texttt{\char'074 listitem\char'076 }} with an \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute which is
%     referenced from some \texttt{<xref>}\index{xref=\texttt{\char'074 xref\char'076 } (element)}\index{elements:!xref=\texttt{\char'074 xref\char'076 }} element’s \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} value, the
%     \textsf{fmtcount} package will be included
%     (that package enables
%     ordinal counting, needed when making a reference to an
%     item in a list that is not numbered, or when counting the
%     number of items for a \texttt{<coref>}\index{coref=\texttt{\char'074 coref\char'076 } (element)}\index{elements:!coref=\texttt{\char'074 coref\char'076 }} element type: see
%     ‘\textbf{\textsf{\texttt{<coref>}\index{coref=\texttt{\char'074 coref\char'076 } (element)}\index{elements:!coref=\texttt{\char'074 coref\char'076 }}}}’, the seventh item in the list in \vref{corefs}).\par
% \subsubsection{Restricting the loading of conflicting packages}
% If the \texttt{<constructorsynopsis>}\index{constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 } (element)}\index{elements:!constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 }} element has
%     a \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}} value containing
%     one or more package names (separated by spaces), then
%     the autoloading of this package will
%     \emph{prevent} the autoloading of the
%     named packages, \emph{even if they have been
%       requested by the author}. This is to
%     prevent known conflicts, of which the following is a
%     good example:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<step condition="doc" remap="fontspec">
  <para>Font specification setup for use with &XeLaTeX;.</para>
  <constructorsynopsis remap="inputenc fontenc" condition="part">
    <methodparam>
      <parameter>conformance</parameter>
      <modifier>xelatex</modifier>
    </methodparam>
  </constructorsynopsis>
</step>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% If you have specified to use \XeLaTeX{} for the
%     documentation, by setting the \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} attribute on the
%     \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}} \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }} element to
%     \texttt{"xelatex"}\index{xelatex=\texttt{"xelatex"} (attribute value)}\index{attribute values:!xelatex=\texttt{"xelatex"}}, the
%     \textsf{fontspec} package will be autoloaded,
%     but the \textsf{inputenc} and
%     \textsf{fontenc} packages will not be, even if
%     you have requested them, because you cannot use them in
%     the same document as \textsf{fontenc}.\par
% \subsection{Adding setup commands before or after a package}\label{addtosetup}
% Each \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} may also contain one or more
%   \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} elements containing
%   \texttt{<cmdsynopsis>}\index{cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 } (element)}\index{elements:!cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 }} elements containing
%   \texttt{<command>}\index{command=\texttt{\char'074 command\char'076 } (element)}\index{elements:!command=\texttt{\char'074 command\char'076 }} elements to hold \LaTeX{} code to be
%   inserted, in exactly the same format as shown in \vref{packages}.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<step remap="apacite" condition="doc">
  <constraintdef>
    <cmdsynopsis>
      <command>\AtBeginDocument{\edef\ApaciteRestoreAtCode%
    {\catcode`@=\the\catcode`@\relax}}</command>
    </cmdsynopsis>
  </constraintdef>
</step>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% \begin{itemize}
% \item If the step is given in the \texttt{"prepackage"}\index{prepackage=\texttt{"prepackage"} (attribute value)}\index{attribute values:!prepackage=\texttt{"prepackage"}} section, the code is
%       inserted \emph{before} the package is
%       invoked;
% \item if the step is given in the \texttt{"postpackage"}\index{postpackage=\texttt{"postpackage"} (attribute value)}\index{attribute values:!postpackage=\texttt{"postpackage"}} section, the code
%       is inserted \emph{after} the package is
%       invoked;\par
% \end{itemize}
%  that is, before or after the
%   {\ttfamily{}\textbackslash{}RequirePackage} or
%   {\ttfamily{}\textbackslash{}usepackage} command is output.\par
% \clearpage
% \section{Using \emph{ClassPack} to write the
% documentation}\label{content}
% The text of your documentation goes in a \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }}
% element with the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute
% set to \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}}.\par
% The tag-set of \emph{DocBook} is very
% large, and only a part of it is needed for this purpose,
% although support for additional elements can be added in
% the \textsc{xslt} scripts.\par
% The following sections describe the elements and
% attributes that are currently supported for the three classes
% of markup:\par
% \begin{enumerate}
% \item \label{hiersum}the document \textbf{\emph{hierarchy}}\index{hierarchy|textbf}: the
%     structure of the document (chapters, sections,
%     subsections, etc);
% \item \label{poolsum}the document \textbf{\emph{pool}}\index{pool|textbf}: block-level
%     structure used \emph{within} the hierarchy
%     made up of paragraphs, tables, figures, lists, code
%     examples, etc;
% \item \label{flowsum}the text \textbf{\emph{flow}}\index{flow|textbf}: the inline
%     markup which occurs in \textbf{\emph{mixed
%       content}}\index{mixed content|textbf} (text and markup intermingled
%     \emph{within} the pool elements), such as
%     emphasis, acronyms, \textsc{gui} objects, links,
%     product names, foreign words, \textsc{uri}s, cross-references, and the
%     names of packages, options, variables, classes, files,
%     etc\footnote{%
% The terms `hierarchy',
% `pool', and
% `flow' are taken from the
% design conventions of \hyperref[DTD]{\textsc{dtd}}\protect\index{DTD} \parencite{maler}, whose authors derive
% them from an Open Software Foundation
% \hyperref[DTD]{\textsc{dtd}}\protect\index{DTD} design committee. They are in
% widespread use and occur in the specifications for
% both \emph{DocBook} and
% \textsc{html}\protect\index{HTML}, although they appear much
% earlier under the terms
% `hierarchy',
% `containment', and
% `sequence' in \textcite[][sec\thinspace 3]{Southall1989}.\par}\par
% \end{enumerate}
% Some of the inline element types have extended features
% which are described in the next section. There is a separate
% section on bibliographic markup, as its usage differs
% significantly from normal document text.\par
% \subsection{Writing assistance in \textsc{xslt}}
% The following features are designed to help authors
%   by automating some common tasks which otherwise cause
%   unnecessary work when editing.\par
% \begin{description}[style=unboxed]
% \item[Punctuation:]You {\sffamily \textsc{may}} omit the
% terminating punctuation in the \texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }} in a
% \texttt{<listitem>}\index{listitem=\texttt{\char'074 listitem\char'076 } (element)}\index{elements:!listitem=\texttt{\char'074 listitem\char'076 }} in an \texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }},
% \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }}, \texttt{<procedure>}\index{procedure=\texttt{\char'074 procedure\char'076 } (element)}\index{elements:!procedure=\texttt{\char'074 procedure\char'076 }}, or
% \texttt{<variablelist>}\index{variablelist=\texttt{\char'074 variablelist\char'076 } (element)}\index{elements:!variablelist=\texttt{\char'074 variablelist\char'076 }}. In the case of an item with
% more than one paragraph, this rule affects
% \emph{only} the last \texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }} in
% the \texttt{<listitem>}\index{listitem=\texttt{\char'074 listitem\char'076 } (element)}\index{elements:!listitem=\texttt{\char'074 listitem\char'076 }}.\par
% A semicolon will be added after all such items in
% the list \emph{except} the last, when a
% full point (period) will be used,
% \emph{unless} you have already provided
% punctuation as the final character, or the text node
% \emph{immediately following} the end of
% the list starts with a punctuation character (for
% example, after an inline list where the sentence
% continues). See	\vref{autopunct} for the
% annotated code.\par
% \item[Inline lists:]This applies particularly to inline lists using an
% \texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }} or \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }} \emph{inside} a \texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }} element,
% where \emph{inline}, not vertical,
% formatting is created. These items are
%    \begin{enumerate*}[label=\emph{\alph*}),itemjoin={{; }},itemjoin*={{; and }}]
% \item lettered in italics\par
% \item fenced with upright parentheses\par
% \item punctuated with semicolons\par
% \item the final item separated with
%       `and' (for an
%       \texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }}) or
%       `or' (for an
%       \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }})\par
% \end{enumerate*}. See \vref{listcode} for
% the annotated code.\par
% \item[Cross-references:]\label{xrefs}The \texttt{<xref>}\index{xref=\texttt{\char'074 xref\char'076 } (element)}\index{elements:!xref=\texttt{\char'074 xref\char'076 }} element type with a \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} \texttt{<IDREFS>}\index{IDREFS=\texttt{\char'074 IDREFS\char'076 } (element)}\index{elements:!IDREFS=\texttt{\char'074 IDREFS\char'076 }}
% attribute makes cross-references to one or more
% elements in your documentation with the matching \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute value[s].\par
% The {\ttfamily{}.dtx} file then uses the
% \textsf{varioref} \LaTeX{} package to
% identify the name of the target object for an extended
% reference where possible, such as `chapter
%   7', `section 13.9', or
% `Figure 3.4'. For those objects that
% \textsf{varioref} is unable to identify,
% like lists, sidepars, individual paragraphs, and
% others, the \emph{db2dtx} script
% provides the additional text and computation to form
% an extended reference (noted with an asterisk below).\par
% Supported target element types are:\par
% \begin{description}[style=unboxed]
% \item[Sectioning:]\texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }}, \texttt{<section>}\index{section=\texttt{\char'074 section\char'076 } (element)}\index{elements:!section=\texttt{\char'074 section\char'076 }},
%       \texttt{<subsection>}\index{subsection=\texttt{\char'074 subsection\char'076 } (element)}\index{elements:!subsection=\texttt{\char'074 subsection\char'076 }}, etc;
% \item[Floats:]floating objects like \texttt{<figure>}\index{figure=\texttt{\char'074 figure\char'076 } (element)}\index{elements:!figure=\texttt{\char'074 figure\char'076 }},
%       \texttt{<table>}\index{table=\texttt{\char'074 table\char'076 } (element)}\index{elements:!table=\texttt{\char'074 table\char'076 }}, and \texttt{<sidebar>}\index{sidebar=\texttt{\char'074 sidebar\char'076 } (element)}\index{elements:!sidebar=\texttt{\char'074 sidebar\char'076 }};
% \item[\llap{\ensuremath{\ast}\ }Whole lists:]\texttt{<variablelist>}\index{variablelist=\texttt{\char'074 variablelist\char'076 } (element)}\index{elements:!variablelist=\texttt{\char'074 variablelist\char'076 }},
%       \texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }}, \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }},
%       and \texttt{<procedure>}\index{procedure=\texttt{\char'074 procedure\char'076 } (element)}\index{elements:!procedure=\texttt{\char'074 procedure\char'076 }};
% \item[\llap{\ensuremath{\ast}\ }List items:]\texttt{<varlistentry>}\index{varlistentry=\texttt{\char'074 varlistentry\char'076 } (element)}\index{elements:!varlistentry=\texttt{\char'074 varlistentry\char'076 }}, \texttt{<listitem>}\index{listitem=\texttt{\char'074 listitem\char'076 } (element)}\index{elements:!listitem=\texttt{\char'074 listitem\char'076 }}
%       in \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }} and
%       \texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }}, and \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} in
%       \texttt{<procedure>}\index{procedure=\texttt{\char'074 procedure\char'076 } (element)}\index{elements:!procedure=\texttt{\char'074 procedure\char'076 }}\footnote{%
% \LaTeX{} does indeed supply a
%   {\ttfamily{}\textbackslash{}ref} value for labelled
%   items in an enumerated list, but not for
%   those in other lists.\par}\par
% \item[\llap{\ensuremath{\ast}\ }Examples:]\texttt{<blockquote>}\index{blockquote=\texttt{\char'074 blockquote\char'076 } (element)}\index{elements:!blockquote=\texttt{\char'074 blockquote\char'076 }},
%       \texttt{<informaltable>}\index{informaltable=\texttt{\char'074 informaltable\char'076 } (element)}\index{elements:!informaltable=\texttt{\char'074 informaltable\char'076 }}, and
%       \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }};
% \item[\llap{\ensuremath{\ast}\ }Admonishments:]\texttt{<note>}\index{note=\texttt{\char'074 note\char'076 } (element)}\index{elements:!note=\texttt{\char'074 note\char'076 }}, \texttt{<warning>}\index{warning=\texttt{\char'074 warning\char'076 } (element)}\index{elements:!warning=\texttt{\char'074 warning\char'076 }};
% \item[\llap{\ensuremath{\ast}\ }Text:]\texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }}.
% \end{description}
% For a \texttt{<listitem>}\index{listitem=\texttt{\char'074 listitem\char'076 } (element)}\index{elements:!listitem=\texttt{\char'074 listitem\char'076 }} in an
% \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }} \emph{ClassPack} will compute the
% ordinal number of the item. The automated labelling is
% omitted if \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} is set to
% \texttt{"short"}\index{short=\texttt{"short"} (attribute value)}\index{attribute values:!short=\texttt{"short"}}. The page number is
% included by default: if \texttt{@xrefstyle}\index{xrefstyle=\texttt{\char'100 xrefstyle} (attribute)}\index{attributes:!xrefstyle=\texttt{\char'100 xrefstyle}}=\texttt{"page"}\index{page=\texttt{"page"} (attribute value)}\index{attribute values:!page=\texttt{"page"}} then
% \emph{only} a page reference is
% given.\par
% You {\sffamily \textsc{may}} use
% multiple \texttt{<ID>}\index{ID=\texttt{\char'074 ID\char'076 } (element)}\index{elements:!ID=\texttt{\char'074 ID\char'076 }} values in the \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} attribute. See \vref{ann-xref} for the annotated code.\par
% \item[Bibliographic citations:]A \texttt{<biblioref>}\index{biblioref=\texttt{\char'074 biblioref\char'076 } (element)}\index{elements:!biblioref=\texttt{\char'074 biblioref\char'076 }} element with a \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} attribute makes a
% citation of the \texttt{<biblioentry>}\index{biblioentry=\texttt{\char'074 biblioentry\char'076 } (element)}\index{elements:!biblioentry=\texttt{\char'074 biblioentry\char'076 }} with that \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}}[s] value, which
% {\sffamily \textsc{must}} exist in the
% \texttt{<bibliography>}\index{bibliography=\texttt{\char'074 bibliography\char'076 } (element)}\index{elements:!bibliography=\texttt{\char'074 bibliography\char'076 }}. The default citation format
% (set for \textsf{biblatex} in
% {\ttfamily{}prepost.xml}) is author-year in
% parentheses like this:
% \parencite{knuthweb}. If you want to use the
% author’s name as part of the text of the surrounding sentence,
% like the book written by \textcite{knuthweb}, set the \texttt{@xrefstyle}\index{xrefstyle=\texttt{\char'100 xrefstyle} (attribute)}\index{attributes:!xrefstyle=\texttt{\char'100 xrefstyle}} attribute to \texttt{"text"}\index{text=\texttt{"text"} (attribute value)}\index{attribute values:!text=\texttt{"text"}} so that the parentheses
% enclose only the year. Multiple space-separated
% values in \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}}
% produce multiple citations like \parencite{knuthweb,flynn2009,holman2013}. See \vref{bibs} for details, and \vref{citations} for the annotated code.\par
% \item[Identification of terms (for indexing):]The following element types are used for the names
% of components:\par
% \begin{itemize}[noitemsep]\label{foo}
% \item \texttt{<classname>}\index{classname=\texttt{\char'074 classname\char'076 } (element)}\index{elements:!classname=\texttt{\char'074 classname\char'076 }} for document classes like
%     \index{article@\textsf{article} (class)}\index{classes:!article@\textsf{article}}\textsf{article};
% \item \texttt{<command>}\index{command=\texttt{\char'074 command\char'076 } (element)}\index{elements:!command=\texttt{\char'074 command\char'076 }} for commands (macros) like
%     {\ttfamily{}\textbackslash{}maketitle};
% \item \texttt{<envar>}\index{envar=\texttt{\char'074 envar\char'076 } (element)}\index{elements:!envar=\texttt{\char'074 envar\char'076 }} for environments like
%     \texttt{quotation};
% \item \texttt{<function>}\index{function=\texttt{\char'074 function\char'076 } (element)}\index{elements:!function=\texttt{\char'074 function\char'076 }} for functions in computer
%     languages other than \TeX{};
% \item \texttt{<option>}\index{option=\texttt{\char'074 option\char'076 } (element)}\index{elements:!option=\texttt{\char'074 option\char'076 }} for options like
%     \textbf{\texttt{12pt}};
% \item \texttt{<package>}\index{package=\texttt{\char'074 package\char'076 } (element)}\index{elements:!package=\texttt{\char'074 package\char'076 }} for packages like
%     \textsf{geometry};
% \item \texttt{<parameter>}\index{parameter=\texttt{\char'074 parameter\char'076 } (element)}\index{elements:!parameter=\texttt{\char'074 parameter\char'076 }} for parameters like
%     \url{#3};
% \item \texttt{<varname>}\index{varname=\texttt{\char'074 varname\char'076 } (element)}\index{elements:!varname=\texttt{\char'074 varname\char'076 }} for variable names like
%     {\ttfamily{}\textbackslash{}textwidth}.
% \end{itemize}
% See the full descriptions in \vref{flow}.\par
% \end{description}
% \subsection{Document markup}
% This section is structured to correspond to the
%   annotated code in \vref{patterns}.\par
% \subsubsection{Hierarchy}\label{hierarchy}
% The outline top-level structure is described in \vref{struct} and \vref{setup}.\par
% The \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }} elements containing the
%     documentation, annotated code, and any additional files do
%     not have any \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }} element or direct textual
%     content themselves: they just act as containers to keep
%     them separately identifiable by the
%     \textsc{xslt} script.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<part xml:id="doc" conformance="xelatex">
  <chapter xml:id="ui">
    <title>User interface</title>
    ...
    <sect1>
      <title>Font selection</title>
      ...
    </sect1>
    <sect1 xml:id="margins">
      <title>Margins and spacing</title>
      ...
    </sect1>
  </chapter>
  ...
</part>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% Within a \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }}, the
%     {\sffamily \textsc{required}} top-level division
%     is the \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }}, which equates to a
%     {\ttfamily{}\textbackslash{}section} in the
%     {\ttfamily{}.dtx} file. Each \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }} (user
%     documentation, documented code, and additional files)
%     {\sffamily \textsc{must}} have at least one
%     \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} element.\par
% The first chapter {\sffamily \textsc{may}}
%     be preceded by one or more \texttt{<preface>}\index{preface=\texttt{\char'074 preface\char'076 } (element)}\index{elements:!preface=\texttt{\char'074 preface\char'076 }} elements,
%     where a preface, foreword, introduction or other
%     preliminary material is needed.\par
% Within chapters, the \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }},
%     \texttt{<sect2>}\index{sect2=\texttt{\char'074 sect2\char'076 } (element)}\index{elements:!sect2=\texttt{\char'074 sect2\char'076 }}, \texttt{<sect3>}\index{sect3=\texttt{\char'074 sect3\char'076 } (element)}\index{elements:!sect3=\texttt{\char'074 sect3\char'076 }} etc elements
%     {\sffamily \textsc{must}} be used to hold your
%     sections, subsections, and subsubsections. In a
%     \texttt{<preface>}\index{preface=\texttt{\char'074 preface\char'076 } (element)}\index{elements:!preface=\texttt{\char'074 preface\char'076 }}, \emph{DocBook}
%     allows only the \texttt{<section>}\index{section=\texttt{\char'074 section\char'076 } (element)}\index{elements:!section=\texttt{\char'074 section\char'076 }}, but this can be nested
%     if required.\par
% You can use as many or as few of these as you feel you
%     need to organise your writing in the documentation part.
%     In the annotated code part, the whole point is to
%     modularise your class or package, so that you can group
%     annotations together to describe each part of the code in
%     a logical and consistent manner.\par
% Each of these hierarchical divisions
%     {\sffamily \textsc{must}} have a
%     \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }} element, and
%     {\sffamily \textsc{may}} also have an \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute to act as a
%     target (like a \LaTeX{} {\ttfamily{}\textbackslash{}label}) for
%     cross-referencing.\par
% In the \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}} part (only),
%     the \texttt{<conformance>}\index{conformance=\texttt{\char'074 conformance\char'076 } (element)}\index{elements:!conformance=\texttt{\char'074 conformance\char'076 }} attribute
%     {\sffamily \textsc{should}} be set to the name
%     of the \LaTeX{} processor to be used for producing the
%     documentation. In the example above this is \texttt{"xelatex"}\index{xelatex=\texttt{"xelatex"} (attribute value)}\index{attribute values:!xelatex=\texttt{"xelatex"}}; the default is still
%     \texttt{"pdflatex"}\index{pdflatex=\texttt{"pdflatex"} (attribute value)}\index{attribute values:!pdflatex=\texttt{"pdflatex"}}.\par
% \subsubsection{Pool}\label{pool}
% Inside your chapters, sections, subsections, etc, you
%     can have any arrangement or mixture of paragraphs, tables,
%     lists, figures, quotations, code samples, and other
%     conventional document components that will be familiar to
%     you from \LaTeX{} and from other \textsc{xml}
%     environments.\par
% The only requirement in
%   \emph{DocBook} is that each hierarchical
%   division {\sffamily \textsc{must}} contain at
%   least one such structural component. Supported element types
%   at this level are:\par
% \begin{itemize}[noitemsep]
% \item \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }}, see \vref{annocode};
% \item \texttt{<blockquote>}\index{blockquote=\texttt{\char'074 blockquote\char'076 } (element)}\index{elements:!blockquote=\texttt{\char'074 blockquote\char'076 }}, see \vref{titletext};
% \item \texttt{<bridgehead>}\index{bridgehead=\texttt{\char'074 bridgehead\char'076 } (element)}\index{elements:!bridgehead=\texttt{\char'074 bridgehead\char'076 }}, see \vref{subsections};
% \item \texttt{<figure>}\index{figure=\texttt{\char'074 figure\char'076 } (element)}\index{elements:!figure=\texttt{\char'074 figure\char'076 }}, see \vref{figtab};
% \item \texttt{<informaltable>}\index{informaltable=\texttt{\char'074 informaltable\char'076 } (element)}\index{elements:!informaltable=\texttt{\char'074 informaltable\char'076 }}, see \vref{figtab};
% \item \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }}, see \vref{lists};
% \item \texttt{<note>}\index{note=\texttt{\char'074 note\char'076 } (element)}\index{elements:!note=\texttt{\char'074 note\char'076 }}, see \vref{admonishments};
% \item \texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }}, see \vref{lists};
% \item \texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }}, see \vref{titletext};
% \item \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }}, see \vref{codelist};
% \item \texttt{<remark>}\index{remark=\texttt{\char'074 remark\char'076 } (element)}\index{elements:!remark=\texttt{\char'074 remark\char'076 }}, see \vref{blockmeta};
% \item \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }} / \texttt{<sect2>}\index{sect2=\texttt{\char'074 sect2\char'076 } (element)}\index{elements:!sect2=\texttt{\char'074 sect2\char'076 }} /
%       \texttt{<sect3>}\index{sect3=\texttt{\char'074 sect3\char'076 } (element)}\index{elements:!sect3=\texttt{\char'074 sect3\char'076 }}, see \vref{subsections};
% \item \texttt{<sidebar>}\index{sidebar=\texttt{\char'074 sidebar\char'076 } (element)}\index{elements:!sidebar=\texttt{\char'074 sidebar\char'076 }}, see \vref{admonishments};
% \item \texttt{<subtitle>}\index{subtitle=\texttt{\char'074 subtitle\char'076 } (element)}\index{elements:!subtitle=\texttt{\char'074 subtitle\char'076 }}, see \vref{titletext};
% \item \texttt{<table>}\index{table=\texttt{\char'074 table\char'076 } (element)}\index{elements:!table=\texttt{\char'074 table\char'076 }}, see \vref{figtab};
% \item \texttt{<task>}\index{task=\texttt{\char'074 task\char'076 } (element)}\index{elements:!task=\texttt{\char'074 task\char'076 }}, see \vref{blockmeta};
% \item \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }}, see \vref{titletext};
% \item \texttt{<variablelist>}\index{variablelist=\texttt{\char'074 variablelist\char'076 } (element)}\index{elements:!variablelist=\texttt{\char'074 variablelist\char'076 }}, see \vref{lists};
% \item \texttt{<warning>}\index{warning=\texttt{\char'074 warning\char'076 } (element)}\index{elements:!warning=\texttt{\char'074 warning\char'076 }}, see \vref{admonishments}.
% \end{itemize}
% The \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} element is a special case, and
%   is only used in the \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}}
%   part (see \vref{annocode}).\par
% \paragraph[Titles, paragraphs, and quotations]{Titles, paragraphs, and quotations :}\label{titletext}
% \begin{description}[style=unboxed]
% \item[\texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }}:]\label{title}a title is
%   {\sffamily \textsc{required}} in all
%   chapters, [sub]sections, figures, and tables; it is
%   {\sffamily \textsc{optional}} in lists,
%   notes, warnings, and other block-level element
%   types.\par
% \item[\texttt{<subtitle>}\index{subtitle=\texttt{\char'074 subtitle\char'076 } (element)}\index{elements:!subtitle=\texttt{\char'074 subtitle\char'076 }}:]A \texttt{<subtitle>}\index{subtitle=\texttt{\char'074 subtitle\char'076 } (element)}\index{elements:!subtitle=\texttt{\char'074 subtitle\char'076 }} element can be used for a
%   short-form caption which \LaTeX{} will use as the
%   optional argument for the Table of Contents;
% \item[\texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }}:]for normal paragraphs, For tagged content, see
% \vref{flow};
% \item[\texttt{<blockquote>}\index{blockquote=\texttt{\char'074 blockquote\char'076 } (element)}\index{elements:!blockquote=\texttt{\char'074 blockquote\char'076 }}:]\label{blockquote}The \texttt{<blockquote>}\index{blockquote=\texttt{\char'074 blockquote\char'076 } (element)}\index{elements:!blockquote=\texttt{\char'074 blockquote\char'076 }} element is for
%   quotations from other documents included as
%   \texttt{<biblioitem>}\index{biblioitem=\texttt{\char'074 biblioitem\char'076 } (element)}\index{elements:!biblioitem=\texttt{\char'074 biblioitem\char'076 }}\kern1pt{}s in your
%   \texttt{<bibliography>}\index{bibliography=\texttt{\char'074 bibliography\char'076 } (element)}\index{elements:!bibliography=\texttt{\char'074 bibliography\char'076 }} (see \vref{bibs}), such as useful reference text
%   about why the readers might choose to do things one
%   way in your class or package rather than another. It
%   normally just contains a paragraph or two.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML,emph={annotations,linkend,blockquote,para}]
<blockquote annotations="in comp.fonts" linkend="pfnut">
  <para>[How do we] persuade new users that spreading
    fonts across the page like peanut butter across
    hot toast is not necessarily the route to
    typographic excellence?</para>
</blockquote>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% The \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} value of
%   the \texttt{<biblioentry>}\index{biblioentry=\texttt{\char'074 biblioentry\char'076 } (element)}\index{elements:!biblioentry=\texttt{\char'074 biblioentry\char'076 }} where the document
%   reference is given goes in the
%   \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} attribute of
%   the \texttt{<blockquote>}\index{blockquote=\texttt{\char'074 blockquote\char'076 } (element)}\index{elements:!blockquote=\texttt{\char'074 blockquote\char'076 }}.\par
% \begin{quotation}\small\sffamily\parindent0pt
%   \parskip.5\baselineskip
%   \color{DarkBlue}\noindent
% [How do we] persuade new users that spreading
%     fonts across the page like peanut butter across
%     hot toast is not necessarily the route to
%     typographic excellence?\par
% \hfill\begingroup\parencite[][\thinspace in comp.fonts]{pfnut}\parfillskip=0pt\parskip=0pt\par\endgroup
% \end{quotation}
% As with normal citation, you can give additional
%   details of chapter or page [range], and precite or
%   postcite comments (see ‘\textbf{\textsf{\texttt{<biblioref>}\index{biblioref=\texttt{\char'074 biblioref\char'076 } (element)}\index{elements:!biblioref=\texttt{\char'074 biblioref\char'076 }}}}’, the fifth item in the list in \vref{bibrefs} for details), but the format in
%   block quotations is always (Author, Year).
% \end{description}
% \paragraph[Lists]{Lists :}\label{lists}
% \begin{description}[style=unboxed]
% \item[\texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }}:]for random-order (bulleted) lists — each
%   \texttt{<listitem>}\index{listitem=\texttt{\char'074 listitem\char'076 } (element)}\index{elements:!listitem=\texttt{\char'074 listitem\char'076 }} contains one or more
%   \texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }} elements;
% \item[\texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }}:]for lists where the sequence numbering of items
%   is important; or for lists in which you want
%   numbered items for reference purposes — the
%   structure is the same as for
%   \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }};
% \item[\texttt{<variablelist>}\index{variablelist=\texttt{\char'074 variablelist\char'076 } (element)}\index{elements:!variablelist=\texttt{\char'074 variablelist\char'076 }}:]for description-style lists like this one — the
%   \texttt{<term>}\index{term=\texttt{\char'074 term\char'076 } (element)}\index{elements:!term=\texttt{\char'074 term\char'076 }} element in each
%   \texttt{<varlistentry>}\index{varlistentry=\texttt{\char'074 varlistentry\char'076 } (element)}\index{elements:!varlistentry=\texttt{\char'074 varlistentry\char'076 }} holds the reference term;
%   the descriptive part is in the same
%   \texttt{<listitem>}\index{listitem=\texttt{\char'074 listitem\char'076 } (element)}\index{elements:!listitem=\texttt{\char'074 listitem\char'076 }} structure as for itemized and
%   ordered lists.
% \end{description}
% Use the attribute \texttt{@spacing}\index{spacing=\texttt{\char'100 spacing} (attribute)}\index{attributes:!spacing=\texttt{\char'100 spacing}}=\texttt{"compact"}\index{compact=\texttt{"compact"} (attribute value)}\index{attribute values:!compact=\texttt{"compact"}} on any of
%     \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }}, \texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }}, or
%     \texttt{<variablelist>}\index{variablelist=\texttt{\char'074 variablelist\char'076 } (element)}\index{elements:!variablelist=\texttt{\char'074 variablelist\char'076 }} for tighter vertical
%     spacing.\par
% If you want to refer to an item in an itemized or
%     ordered list, the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}}
%     attribute {\sffamily \textsc{must}} be on the
%     \texttt{<listitem>}\index{listitem=\texttt{\char'074 listitem\char'076 } (element)}\index{elements:!listitem=\texttt{\char'074 listitem\char'076 }} element; in variable lists, the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute
%     {\sffamily \textsc{must}} be on the
%     \texttt{<varlistentry>}\index{varlistentry=\texttt{\char'074 varlistentry\char'076 } (element)}\index{elements:!varlistentry=\texttt{\char'074 varlistentry\char'076 }} element.\par
% \paragraph[Subsections]{Subsections :}\label{subsections}
% \begin{description}[style=unboxed]
% \item[\texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }}, \texttt{<sect2>}\index{sect2=\texttt{\char'074 sect2\char'076 } (element)}\index{elements:!sect2=\texttt{\char'074 sect2\char'076 }},
% \texttt{<sect3>}\index{sect3=\texttt{\char'074 sect3\char'076 } (element)}\index{elements:!sect3=\texttt{\char'074 sect3\char'076 }}:]Creates a section inside a chapter. A title
%   element is {\sffamily \textsc{mandatory}},
%   plus one further structural element type.\par
% \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }} may contain one or more
%   \texttt{<sect2>}\index{sect2=\texttt{\char'074 sect2\char'076 } (element)}\index{elements:!sect2=\texttt{\char'074 sect2\char'076 }} elements, which in turn may contain
%   \texttt{<sect3>}\index{sect3=\texttt{\char'074 sect3\char'076 } (element)}\index{elements:!sect3=\texttt{\char'074 sect3\char'076 }} elements;
% \item[\texttt{<bridgehead>}\index{bridgehead=\texttt{\char'074 bridgehead\char'076 } (element)}\index{elements:!bridgehead=\texttt{\char'074 bridgehead\char'076 }}:]Creates a cross-head used to break up very long
%   [sub]sections without the need to create a new
%   sub-level.
% \end{description}
% \paragraph[Code listings]{Code listings :}\label{codelist}
% Use the \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} element for listings
%     of code. The \texttt{@language}\index{language=\texttt{\char'100 language} (attribute)}\index{attributes:!language=\texttt{\char'100 language}}
%     attribute {\sffamily \textsc{must}} give the
%     computer language except for \LaTeX{} (see below).\par
% \begin{enumerate}
% \item In the \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}} part of a
% \emph{ClassPack} document (the
% annotated code which is the \LaTeX{} code of your class
% or package), use this element type
% \emph{without} attributes.\par
% \item In the \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}} part, the
% basic style is formatted by default (specified in
% {\ttfamily{}prepost.xml}) as
% {\ttfamily{}\textbackslash{}small} type, black text, and
% {\ttfamily{}\textbackslash{}ttfamily} font. Other attributes can
% be used to control the appearance:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX},frame=single,framesep=1em,emphstyle=\itshape,emph={gdef},xrightmargin=1em,xleftmargin=1em]
<programlisting language="LaTeXe" wordsize="8/9" 
     arch="framed" remap="\itshape" annotations="gdef">
\def\@subtitle{\relax}
\newcommand{\subtitle}[1]{\gdef\@subtitle{#1}}
</programlisting>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% \begin{description}[style=unboxed]
% \item[\texttt{@language}\index{language=\texttt{\char'100 language} (attribute)}\index{attributes:!language=\texttt{\char'100 language}}:]the language of the code. The default is
%       \texttt{"LaTeXe"}\index{LaTeXe=\texttt{"LaTeXe"} (attribute value)}\index{attribute values:!LaTeXe=\texttt{"LaTeXe"}}. This is
%       passed to the \textsf{listings}
%       package for formatting, but there are some
%       extras and redefinitions in the
%       {\ttfamily{}prepost.xml} entry for that
%       package to add to the language support
%       offered;
% \item[\texttt{@wordsize}\index{wordsize=\texttt{\char'100 wordsize} (attribute)}\index{attributes:!wordsize=\texttt{\char'100 wordsize}}:]\label{wordsize}specifies a different font size, given as
%       the point size and baseline height separated by
%       a slash, eg \texttt{8/10}. It will also
%       cause the option
%       \textbf{\texttt{breaklines=true}} to be passed to
%       the \textsf{listings} package.\par
% If the file or fragment being listed is
%       known to have overlong lines, but font size
%       adjustment is not possible or not wanted,
%       including this attribute with a null value will
%       still invoke line-breaking but leave the font
%       size unchanged.\par
% Note that code listings within the \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}} part of a document
%       which are \emph{not} for
%       extraction into the class or package (examples,
%       for example) the \texttt{Verbatim}
%       environment is used for formatting the
%       \textsc{pdf} instead of the
%       \texttt{macrocode} environment. In these
%       cases a font size and baseline size
%       {\sffamily \textsc{cannot}} be used,
%       and a \LaTeX{} step-size
%       {\sffamily \textsc{must}} be used
%       instead (eg
%       {\ttfamily{}\textbackslash{}scriptsize});
% \item[\texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}}:]\label{condition}In code listings within the \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}} part of a document
%       which are \emph{not} for
%       extraction into the class or package (examples,
%       for example) this attribute
%       {\sffamily \textsc{must}} be set to
%       \texttt{"ignore"}\index{ignore=\texttt{"ignore"} (attribute value)}\index{attribute values:!ignore=\texttt{"ignore"}} in order to
%       prevent it being extracted into the class or
%       package;
% \item[\texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}}:]\label{codearch}may be set to \texttt{"framed"}\index{framed=\texttt{"framed"} (attribute value)}\index{attribute values:!framed=\texttt{"framed"}} to specify a
%       frame drawn round the code;
% \item[\texttt{@annotations}\index{annotations=\texttt{\char'100 annotations} (attribute)}\index{attributes:!annotations=\texttt{\char'100 annotations}}:]\label{annotations}a comma-separated list of additional
%       keywords that you want highlighted in the code
%       (passed to the \textsf{listings}
%       package);
% \item[\texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}}:]\label{remap}a \LaTeX{} command or sequence of commands to
%       modify the highlighting of the keywords given in
%       the \texttt{@annotations}\index{annotations=\texttt{\char'100 annotations} (attribute)}\index{attributes:!annotations=\texttt{\char'100 annotations}}
%       attribute.
% \end{description}
% \item \label{chunking}For documenting a long file in the annotated code,
% it is easier to do it chunk by chunk, including the
% chunks (fragments) directly from the file itself by
% start/end line number, instead of retyping them or
% copying and pasting.\par
% This is done by giving the file name in the \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} attribute with
% the \texttt{@startinglinenumber}\index{startinglinenumber=\texttt{\char'100 startinglinenumber} (attribute)}\index{attributes:!startinglinenumber=\texttt{\char'100 startinglinenumber}}
% and \texttt{@endinglinenumber}\index{endinglinenumber=\texttt{\char'100 endinglinenumber} (attribute)}\index{attributes:!endinglinenumber=\texttt{\char'100 endinglinenumber}} set
% to the line-numbers of the lines to start and end the
% chunk (inclusive). In this mode, the
% \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} element is \texttt{EMPTY}\index{EMPTY=\texttt{EMPTY} (local name)}\index{local names:!EMPTY=\texttt{EMPTY}}
% (no content).\par
% \begin{description}[style=unboxed]
% \item[\texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}}:]name of the file from which to take the code
%       (and path, if the file is not in the same
%       directory as the document);
% \item[\texttt{@startinglinenumber}\index{startinglinenumber=\texttt{\char'100 startinglinenumber} (attribute)}\index{attributes:!startinglinenumber=\texttt{\char'100 startinglinenumber}}:]a line number to start a fragmentary listing
%       at; \emph{or} a label (see
%       below);
% \item[\texttt{@endinglinenumber}\index{endinglinenumber=\texttt{\char'100 endinglinenumber} (attribute)}\index{attributes:!endinglinenumber=\texttt{\char'100 endinglinenumber}}:]a line number to stop a fragmentary listing
%       at; \emph{or} a label (see
%       below).
% \end{description}
% However, as start/end line-number references mean
% the numbers have to be updated every time the file is
% edited, the two attributes \texttt{@startinglinenumber}\index{startinglinenumber=\texttt{\char'100 startinglinenumber} (attribute)}\index{attributes:!startinglinenumber=\texttt{\char'100 startinglinenumber}} and \texttt{@endinglinenumber}\index{endinglinenumber=\texttt{\char'100 endinglinenumber} (attribute)}\index{attributes:!endinglinenumber=\texttt{\char'100 endinglinenumber}} can instead
% be set to labels (one-word strings), and the labels
% {\sffamily \textsc{must}} be inserted in the
% file as comments, shown in the table below
%  \begin{enumerate*}[label=\emph{\alph*}),itemjoin={{; }},itemjoin*={{; and }}]
% \item on a line by themselves\par
% \item starting in character position 1\par
% \item with a single space character where
%       shown\par
% \item label values must be unique within the
%       file\par
% \end{enumerate*}.\par
% \par\medskip{\sffamily\small\label{boundaries}
% \small\sffamily
% \begingroup
% \centering
% \begin{tabular}{@{}%
%   l%
%   l%
%   l<{}%
%   @{}}
% \multicolumn{1}{@{}>{\renewcommand{\baselinestretch}{0.8}\selectfont{}\raggedright{}\CPKprestrut}b{\widthof{XML and XSLTs}}<{}}{\sffamily\bfseries Language}&
% \multicolumn{1}{>{\renewcommand{\baselinestretch}{0.8}\selectfont{}\raggedright{}\CPKprestrut}b{\widthof{Processing Instruction (PI)s}}<{}}{\sffamily\bfseries Label format}&
% \multicolumn{1}{>{\renewcommand{\baselinestretch}{0.8}\selectfont{}\raggedright{}\CPKprestrut}b{\widthof{<?cpdoc label?>s}}<{}@{}}{\sffamily\bfseries Example}\\[2pt]\hline
% \CPKvstrut 
% \LaTeX{}&Double comment character&\url{%% label %%}\thinspace\\
% \emph{bash}\thinspace(1)
% script&Double comment character&\url{#### label ####}\thinspace\\
% \textsc{xml} and
% \textsc{xslt}&Processing Instruction
% (\textsc{pi}\index{PI})&\verb|<?cpdoc label?>|\thinspace\\
% \textsc{css}&Start- and end-comment&{\ttfamily{}/* label */}\thinspace\\[2pt]\hline
% \end{tabular}
% \par\endgroup
% }
% If the code being reproduced has been pre-chunked
% into separate files (see item~\ref{chunking} below and the note in \vref{chunkbug}), set the
% \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} attribute to
% \texttt{"frag"}\index{frag=\texttt{"frag"} (attribute value)}\index{attribute values:!frag=\texttt{"frag"}} (currently the only
% value supported).\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily\label{chunkbug}
% \subsubsection*{Listing bug in chunking}
% The \textsf{listings} package
%   currently (v.1.6 of 2015/06/04) has a bug in
%   interpreting labels in \textsc{xml}
%   documents under certain circumstances. To overcome
%   this, the utility script
%   \emph{chunk} provided with
%   \emph{ClassPack} can be used to
%   split the file into separate chunks. In this case,
%   the labels at the start and end of a chunk
%   {\sffamily \textsc{must}} be the same (ie
%   they must be in pairs). Each chunk file gets named
%   after the original file plus the name of the label
%   (eg {\ttfamily{}foobar-intro}), and the
%   extension {\ttfamily{}.frag}\thinspace, which
%   {\sffamily \textsc{must}} be specified in
%   the \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}}
%   attribute. In this circumstance,
%   \emph{only} the \texttt{@startinglinenumber}\index{startinglinenumber=\texttt{\char'100 startinglinenumber} (attribute)}\index{attributes:!startinglinenumber=\texttt{\char'100 startinglinenumber}} need be
%   used, set to the label which has become part of the
%   fragment’s filename; there is no need for the \texttt{@endinglinenumber}\index{endinglinenumber=\texttt{\char'100 endinglinenumber} (attribute)}\index{attributes:!endinglinenumber=\texttt{\char'100 endinglinenumber}}\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% \end{enumerate}
% \paragraph[Figures and tables]{Figures and tables :}\label{figtab}
% \begin{description}[style=unboxed]
% \item[\texttt{<figure>}\index{figure=\texttt{\char'074 figure\char'076 } (element)}\index{elements:!figure=\texttt{\char'074 figure\char'076 }}:]for Figures, using the structure shown:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML,emphstyle=\itshape,emph={mypic,png}]
<figure floatstyle="hb" xml:id="me">
  <title>A picture</title>
  <mediaobject>
    <imageobject>
      <imagedata fileref="mypic.png" width="90%"/>
    </imageobject>
  </mediaobject>
</figure>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% The \texttt{@floatstyle}\index{floatstyle=\texttt{\char'100 floatstyle} (attribute)}\index{attributes:!floatstyle=\texttt{\char'100 floatstyle}}
%   attribute is used to specify the float parameter
%   option for the \LaTeX{} \texttt{figure}
%   environment; the image filename
%   {\sffamily \textsc{must}} go in the \texttt{@fileref}\index{fileref=\texttt{\char'100 fileref} (attribute)}\index{attributes:!fileref=\texttt{\char'100 fileref}} attribute of an
%   \texttt{<imagedata>}\index{imagedata=\texttt{\char'074 imagedata\char'076 } (element)}\index{elements:!imagedata=\texttt{\char'074 imagedata\char'076 }} element in an
%   \texttt{<imageobject>}\index{imageobject=\texttt{\char'074 imageobject\char'076 } (element)}\index{elements:!imageobject=\texttt{\char'074 imageobject\char'076 }} element in a
%   \texttt{<mediaobject>}\index{mediaobject=\texttt{\char'074 mediaobject\char'076 } (element)}\index{elements:!mediaobject=\texttt{\char'074 mediaobject\char'076 }} element; and the \texttt{@width}\index{width=\texttt{\char'100 width} (attribute)}\index{attributes:!width=\texttt{\char'100 width}} attribute
%   {\sffamily \textsc{may}} be used to give
%   the width as a percentage (as shown) or in any
%   acceptable \LaTeX{} unit (default is full width of
%   the text).\par
% \item[\texttt{<table>}\index{table=\texttt{\char'074 table\char'076 } (element)}\index{elements:!table=\texttt{\char'074 table\char'076 }}:]for formal Tables, using the structure:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<table floatstyle="p" xml:id="costs">
  <title>Example</title>
  <tgroup cols="3">
    <colspec align="left"/>
    <colspec align="center"/>
    <colspec align="right"/>
		  ...
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% In addition to the column alignments shown,
%   other attributes can be used on the
%   \texttt{<colspec>}\index{colspec=\texttt{\char'074 colspec\char'076 } (element)}\index{elements:!colspec=\texttt{\char'074 colspec\char'076 }} element type to control the
%   formation of the \LaTeX{} column
%   specification:\par
% \begin{description}[style=unboxed]
% \item[\texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}}:]\LaTeX{} commands to be executed at the
% start of each cell in this column;
% \item[\texttt{@colwidth}\index{colwidth=\texttt{\char'100 colwidth} (attribute)}\index{attributes:!colwidth=\texttt{\char'100 colwidth}}:]specifies the width of the column as a
% percentage (of available width) or in any
% acceptable \LaTeX{} unit;
% \item[\texttt{@char}\index{char=\texttt{\char'100 char} (attribute)}\index{attributes:!char=\texttt{\char'100 char}}:]the vertical alignment of a paragraphic
% (multi-line) column; the default is
% {\ttfamily{}p} (top-aligned) but
% may{\sffamily \textsc{}} be
% {\ttfamily{}m} (middle-aligned) or
% {\ttfamily{}b} (bottom-aligned)
% for columns with a width specified, as
% implemented in the \textsf{array}
% package. The {\ttfamily{}d} value
% for decimal alignment is only partially
% implemented in this version;
% \item[\texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}}:]\LaTeX{} commands to be executed at the end
% of each cell in this column.
% \end{description}
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
    <thead>
      <row>
        <entry>Item</entry>
        <entry>Code</entry>
        <entry>Cost</entry>
      </row>
    </thead>
    <tfoot>
      <row>
        <entry>Total</entry>
        <entry></entry>
        <entry>100</entry>
      </row>
    </tfoot>
		  ...
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% Note that the \texttt{<tfoot>}\index{tfoot=\texttt{\char'074 tfoot\char'076 } (element)}\index{elements:!tfoot=\texttt{\char'074 tfoot\char'076 }} {\sffamily \textsc{must}} come before the
%   \texttt{<tbody>}\index{tbody=\texttt{\char'074 tbody\char'076 } (element)}\index{elements:!tbody=\texttt{\char'074 tbody\char'076 }}.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
    <tbody>
      <row>
        <entry>&LaTeX;</entry>
        <entry>LA</entry>
        <entry>0</entry>
      </row>
      <row>
        <entry>Word</entry>
        <entry>WD</entry>
        <entry>100</entry>
      </row>
    </tbody>
  </tgroup>
</table>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% Columns can be spanned by using the \texttt{@spanname}\index{spanname=\texttt{\char'100 spanname} (attribute)}\index{attributes:!spanname=\texttt{\char'100 spanname}} attribute to give
%   the number of columns to span (the unused cells
%   {\sffamily \textsc{must}} still be
%   included, empty). There is no provision in this
%   version for row spanning.\par
% The \texttt{@align}\index{align=\texttt{\char'100 align} (attribute)}\index{attributes:!align=\texttt{\char'100 align}},
%   \texttt{<colwidth>}\index{colwidth=\texttt{\char'074 colwidth\char'076 } (element)}\index{elements:!colwidth=\texttt{\char'074 colwidth\char'076 }}, and \texttt{@wordsize}\index{wordsize=\texttt{\char'100 wordsize} (attribute)}\index{attributes:!wordsize=\texttt{\char'100 wordsize}} attributes
%   {\sffamily \textsc{may}} also be used on
%   the \texttt{<entry>}\index{entry=\texttt{\char'074 entry\char'076 } (element)}\index{elements:!entry=\texttt{\char'074 entry\char'076 }} element to change the
%   alignment, column width, and font size for
%   individual cells, as with the \texttt{<colspec>}\index{colspec=\texttt{\char'074 colspec\char'076 } (element)}\index{elements:!colspec=\texttt{\char'074 colspec\char'076 }}
%   element. The \texttt{@wordsize}\index{wordsize=\texttt{\char'100 wordsize} (attribute)}\index{attributes:!wordsize=\texttt{\char'100 wordsize}}
%   works the same way as for code listings, see ‘\textbf{\textsf{\texttt{@wordsize}\index{wordsize=\texttt{\char'100 wordsize} (attribute)}\index{attributes:!wordsize=\texttt{\char'100 wordsize}}}}’, the second item in the list in \vref{wordsize}.\par
% A \texttt{<row>}\index{row=\texttt{\char'074 row\char'076 } (element)}\index{elements:!row=\texttt{\char'074 row\char'076 }} element
%   {\sffamily \textsc{may}} have a \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} of \texttt{"header"}\index{header=\texttt{"header"} (attribute value)}\index{attribute values:!header=\texttt{"header"}} to specify that a
%   row is to be used as a crosshead (set in bold type
%   by default).\par
% If the \texttt{@rowsep}\index{rowsep=\texttt{\char'100 rowsep} (attribute)}\index{attributes:!rowsep=\texttt{\char'100 rowsep}}
%   attribute on a \texttt{<row>}\index{row=\texttt{\char'074 row\char'076 } (element)}\index{elements:!row=\texttt{\char'074 row\char'076 }} element is set to \texttt{"1"}\index{1=\texttt{"1"} (attribute value)}\index{attribute values:!1=\texttt{"1"}}, the row will be given
%   1 ex of vertical separation \emph{from the
%     preceding row} (no other value is
%   possible in this version).\par
% \item[\texttt{<informaltable>}\index{informaltable=\texttt{\char'074 informaltable\char'076 } (element)}\index{elements:!informaltable=\texttt{\char'074 informaltable\char'076 }}:]A tabular array without a caption or number, and
%   which does not float, is done with the
%   \texttt{<informaltable>}\index{informaltable=\texttt{\char'074 informaltable\char'076 } (element)}\index{elements:!informaltable=\texttt{\char'074 informaltable\char'076 }} element. This contains a
%   \texttt{<tgroup>}\index{tgroup=\texttt{\char'074 tgroup\char'076 } (element)}\index{elements:!tgroup=\texttt{\char'074 tgroup\char'076 }} which is structured identically to
%   the formal table described above.\par
% \end{description}
% \paragraph[Admonishments]{Admonishments :}\label{admonishments}
% \begin{description}[style=unboxed]
% \item[\texttt{<note>}\index{note=\texttt{\char'074 note\char'076 } (element)}\index{elements:!note=\texttt{\char'074 note\char'076 }}:]for note blocks (framed and centred) giving
%   special or unusual information about the current
%   topic;
% \item[\texttt{<sidebar>}\index{sidebar=\texttt{\char'074 sidebar\char'076 } (element)}\index{elements:!sidebar=\texttt{\char'074 sidebar\char'076 }}:]for sidebars (floating panels neither figures
%   nor tables, usually holding ancillary explanatory
%   text); a \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }} is recommended;
% \item[\texttt{<warning>}\index{warning=\texttt{\char'074 warning\char'076 } (element)}\index{elements:!warning=\texttt{\char'074 warning\char'076 }}:]for warning blocks (framed and centred).
% \end{description}
% \paragraph[Tasks to do, and remarks when done]{Tasks to do, and remarks when done :}\label{blockmeta}
% \begin{description}[style=unboxed]
% \item[\texttt{<task>}\index{task=\texttt{\char'074 task\char'076 } (element)}\index{elements:!task=\texttt{\char'074 task\char'076 }}:]This element is used to mark note-to-self TODO
%   tasks in your code or documentation. They display in
%   white on black so they stand out.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX}]
	  <task>
	    <procedure>
	      <step>
		<para>The <package>babelfish</package>
		seems to be redundant here now</para>
	      </step>
	    </procedure>
	  </task>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% The \texttt{<task>}\index{task=\texttt{\char'074 task\char'076 } (element)}\index{elements:!task=\texttt{\char'074 task\char'076 }} element
%   {\sffamily \textsc{must}} contain a
%   \texttt{<procedure>}\index{procedure=\texttt{\char'074 procedure\char'076 } (element)}\index{elements:!procedure=\texttt{\char'074 procedure\char'076 }} subitem containing at least one
%   \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }}, with the text in a
%   \texttt{<para>}\index{para=\texttt{\char'074 para\char'076 } (element)}\index{elements:!para=\texttt{\char'074 para\char'076 }};
% \item[\texttt{<remark>}\index{remark=\texttt{\char'074 remark\char'076 } (element)}\index{elements:!remark=\texttt{\char'074 remark\char'076 }}:]This element is used for notes and comments
% about changes and bug fixes to your code which you
% want included in the change log.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX}]
<remark version="3.44" revision="2021-04-01">Fixed bug 
where the counter was not being checked for range</remark>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% The \texttt{@version}\index{version=\texttt{\char'100 version} (attribute)}\index{attributes:!version=\texttt{\char'100 version}} and
%   \texttt{@revision}\index{revision=\texttt{\char'100 revision} (attribute)}\index{attributes:!revision=\texttt{\char'100 revision}} attributes
%   {\sffamily \textsc{must}} give the version
%   number and the date, respectively.\par
% \end{description}
% \subsubsection{Flow}\label{flow}
% This covers inline markup (elements mixed with text).
%     Element types marked with a star (\ensuremath{\ast}) are intended for
%     use primarily in annotations, as they generate special
%     \textsf{dox} package commands defined in
%     {\ttfamily{}prepost.xml} for adding \LaTeX{} (and
%     \textsc{xml}) terms to the index, and
%     highlighting them in the left-hand margin to flag their
%     argument. To annul this when used elsewhere, set the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} attribute to \texttt{"nodesc"}\index{nodesc=\texttt{"nodesc"} (attribute value)}\index{attribute values:!nodesc=\texttt{"nodesc"}} on these starred
%     elements.\par
% \begin{description}[style=unboxed]\label{flowlist}
% \item[\texttt{<acronym>}\index{acronym=\texttt{\char'074 acronym\char'076 } (element)}\index{elements:!acronym=\texttt{\char'074 acronym\char'076 }}:]\label{acronyms-doc}Identifies an acronym and formats it in a
%   small-caps font. To mark the defining instance, give
%   the acronym itself in the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute and give
%   the text expansion as the element content. All other
%   occurrences for a defined acronym
%   {\sffamily \textsc{must}} just give the
%   acronym as the element content.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
Here we look at <acronym xml:id="HTML">HyperText Markup Language</acronym>.
...
There are some <acronym>HTML</acronym> elements which are obsolete...
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% This might render as\par 
% \begin{quotation}\small\sffamily\parindent0pt
%   \parskip.5\baselineskip
%   \color{DarkBlue}\noindent
% Here we look at HyperText Markup
%       Language\phantomsection\label{HTML} ({\small\raisebox{-.5ex}{\textcolor{Red}{\HandRight}}}\textsc{html})\index{HyperText Markup Language|see{HTML}}\index{HTML|textbf}.\par
% There are some \textsc{html}\index{HTML}
%     elements which are obsolete...\par
% \end{quotation}
% \begin{itemize}
% \item If a defining instance for an acronym exists
%       elsewhere in the document, the content becomes a
%       link to it and the defining instance is prefixed
%       with a hand to make it stand out,
%       \emph{provided that} the defining
%       instance is in another chapter and is
%       \emph{not} given in the
%       \texttt{<term>}\index{term=\texttt{\char'074 term\char'076 } (element)}\index{elements:!term=\texttt{\char'074 term\char'076 }} element of a
%       \texttt{<variablelist>}\index{variablelist=\texttt{\char'074 variablelist\char'076 } (element)}\index{elements:!variablelist=\texttt{\char'074 variablelist\char'076 }}.\par
% \item A defining instance whose expansion needs to
%       be in quotes is defined with \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}} \texttt{\unskip="quoted"}\index{quoted=\texttt{"quoted"} (attribute value)}\index{attribute values:!quoted=\texttt{"quoted"}}.\par
% \item If an acronym needs to be expressed in the
%       plural, such as \hyperref[DTD]{\textsc{dtd}}\index{DTD},
%       give the plural suffix in the \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}} attribute.\par
% \item (There is unimplemented provision for
%       signalling to the script that the intended
%       typeface lacks small capitals, so that a
%       typographic conversion to scaled capitals can be
%       done.);
% \item Acronyms are indexed.\par
% \end{itemize}
% The annotated code is in \vref{acronyms}.\par
% \item[\texttt{<citetitle>}\index{citetitle=\texttt{\char'074 citetitle\char'076 } (element)}\index{elements:!citetitle=\texttt{\char'074 citetitle\char'076 }}:]\label{citetitles-doc}The title of a document being mentioned, without
%   being a formal citation; by default this is
%   formatted in italics.\par
% If the element is empty, with a \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} attribute pointing
%   to the \texttt{<xml:id>}\index{xml:id=\texttt{\char'074 xml:id\char'076 } (element)}\index{elements:!xml:id=\texttt{\char'074 xml:id\char'076 }} of an entry in the
%   Bibliography, the title of the reference will be
%   reproduced the same way as for \texttt{<biblioref>}\index{biblioref=\texttt{\char'074 biblioref\char'076 } (element)}\index{elements:!biblioref=\texttt{\char'074 biblioref\char'076 }}
%   with an \texttt{@xrefstyle}\index{xrefstyle=\texttt{\char'100 xrefstyle} (attribute)}\index{attributes:!xrefstyle=\texttt{\char'100 xrefstyle}} \texttt{\unskip="title"}\index{title=\texttt{"title"} (attribute value)}\index{attribute values:!title=\texttt{"title"}} (in which case it is
%   italicised for monographs and in quotes for
%   articles).\par
% The annotated code is in \vref{citetitles}.\par
% \item[\texttt{<code>}\index{code=\texttt{\char'074 code\char'076 } (element)}\index{elements:!code=\texttt{\char'074 code\char'076 }} (inline):]\label{inlinecode-doc}Use this for words, fragments, or short phrases
%   of inline programming or data code. The \texttt{@language}\index{language=\texttt{\char'100 language} (attribute)}\index{attributes:!language=\texttt{\char'100 language}} {\sffamily \textsc{should}} be set to the
%   language used, if a representation for it exists for
%   the \textsf{listings} in
%   {\ttfamily{}prepost.xml}\thinspace.\par
% \item[\texttt{<classname>}\index{classname=\texttt{\char'074 classname\char'076 } (element)}\index{elements:!classname=\texttt{\char'074 classname\char'076 }}:]A \LaTeX{} document class name like
%   \index{article@\textsf{article} (class)}\index{classes:!article@\textsf{article}}\textsf{article}. This is rendered in
%   sans-serif type.\par
% \item[\texttt{<biblioref>}\index{biblioref=\texttt{\char'074 biblioref\char'076 } (element)}\index{elements:!biblioref=\texttt{\char'074 biblioref\char'076 }}:]\label{bibrefs}A citation of an item in the Bibliography; the
%   \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} attribute
%   {\sffamily \textsc{must}} be the value of
%   an \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} value of the
%   \texttt{<biblioentry>}\index{biblioentry=\texttt{\char'074 biblioentry\char'076 } (element)}\index{elements:!biblioentry=\texttt{\char'074 biblioentry\char'076 }} element to which the citation
%   refers (see \vref{bibs}). Multiple
%   entries can be cited: separate the values in \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} with
%   white-space.\par
% The citation style can be specified by setting the
%   \texttt{@xrefstyle}\index{xrefstyle=\texttt{\char'100 xrefstyle} (attribute)}\index{attributes:!xrefstyle=\texttt{\char'100 xrefstyle}} attribute to
%   one of:\par
% \begin{itemize}[label={},noitemsep]
% \item[]\texttt{"text"}\index{text=\texttt{"text"} (attribute value)}\index{attribute values:!text=\texttt{"text"}} [the Author
%     (Year) style]
% \item[]\texttt{"paren"}\index{paren=\texttt{"paren"} (attribute value)}\index{attribute values:!paren=\texttt{"paren"}} [the
%     (Author, Year) style, the default]
% \item[]\texttt{"full"}\index{full=\texttt{"full"} (attribute value)}\index{attribute values:!full=\texttt{"full"}}
% \item[]\texttt{"title"}\index{title=\texttt{"title"} (attribute value)}\index{attribute values:!title=\texttt{"title"}}
% \item[]\texttt{"shorttitle"}\index{shorttitle=\texttt{"shorttitle"} (attribute value)}\index{attribute values:!shorttitle=\texttt{"shorttitle"}}
% \item[]\texttt{"author"}\index{author=\texttt{"author"} (attribute value)}\index{attribute values:!author=\texttt{"author"}}
% \item[]\texttt{"shortauthor"}\index{shortauthor=\texttt{"shortauthor"} (attribute value)}\index{attribute values:!shortauthor=\texttt{"shortauthor"}}
% \item[]\texttt{"field"}\index{field=\texttt{"field"} (attribute value)}\index{attribute values:!field=\texttt{"field"}}, with the
%     \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}} attribute set
%     to the \BibTeX{} name of the field
%     required
% \end{itemize}
% If the citation is of a specific location in the
%   document referenced, set the \texttt{@units}\index{units=\texttt{\char'100 units} (attribute)}\index{attributes:!units=\texttt{\char'100 units}} attribute to \texttt{"ch"}\index{ch=\texttt{"ch"} (attribute value)}\index{attribute values:!ch=\texttt{"ch"}} (chapter), \texttt{"p"}\index{p=\texttt{"p"} (attribute value)}\index{attribute values:!p=\texttt{"p"}} (page) or \texttt{"§"}\index{§=\texttt{"§"} (attribute value)}\index{attribute values:!§=\texttt{"§"}} (section), and set the
%   \texttt{@begin}\index{begin=\texttt{\char'100 begin} (attribute)}\index{attributes:!begin=\texttt{\char'100 begin}} attribute to the
%   number of the unit (and optionally set the \texttt{@end}\index{end=\texttt{\char'100 end} (attribute)}\index{attributes:!end=\texttt{\char'100 end}} attribute for the end
%   of a range).\par
% Note that this usage applies also to the
%   \texttt{<blockquote>}\index{blockquote=\texttt{\char'074 blockquote\char'076 } (element)}\index{elements:!blockquote=\texttt{\char'074 blockquote\char'076 }} element when used for
%   quotations from a cited source (see ‘\textbf{\textsf{\texttt{<blockquote>}\index{blockquote=\texttt{\char'074 blockquote\char'076 } (element)}\index{elements:!blockquote=\texttt{\char'074 blockquote\char'076 }}}}’, the last item in the list in \vref{blockquote}).\par
% \item[\texttt{<command>}\index{command=\texttt{\char'074 command\char'076 } (element)}\index{elements:!command=\texttt{\char'074 command\char'076 }}:]\label{commands-doc}a \LaTeX{} or other computer command, such as
%   {\ttfamily{}\textbackslash{}parskip}. In the (default) case of
%   \LaTeX{}, you {\sffamily \textsc{must not}}
%   give the backslash, as it is added automatically;
%   other languages
%   {\sffamily \textsc{require}} the \texttt{@language}\index{language=\texttt{\char'100 language} (attribute)}\index{attributes:!language=\texttt{\char'100 language}} attribute giving
%   the name of a language (eg \texttt{"bash"}\index{bash=\texttt{"bash"} (attribute value)}\index{attribute values:!bash=\texttt{"bash"}}, \texttt{"XML"}\index{XML=\texttt{"XML"} (attribute value)}\index{attribute values:!XML=\texttt{"XML"}}, \texttt{"XSLT"}\index{XSLT=\texttt{"XSLT"} (attribute value)}\index{attribute values:!XSLT=\texttt{"XSLT"}}, etc) as defined in
%   {\ttfamily{}prepost.xml}\thinspace;
% \item[\texttt{<coref>}\index{coref=\texttt{\char'074 coref\char'076 } (element)}\index{elements:!coref=\texttt{\char'074 coref\char'076 }}:]\label{corefs}This is used as a function to return the number
%   of items in a list. The \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} of the target list
%   {\sffamily \textsc{must}} be given in the
%   \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} attribute, and
%   the name of the element type to count
%   {\sffamily \textsc{must}} be given in the
%   \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} attribute.
%   Example: \texttt{<coref linkend="flowlist"
%     xreflabel="varlistentry"} (this list)
%   will return the value \setcounter{CPKcoref}{63}\makeatletter\ifnum\c@CPKcoref<10 \numberstring{CPKcoref}\else\theCPKcoref\fi\makeatother{} (spelled out if the
%   number is under 10);
% \item[\texttt{<emphasis>}\index{emphasis=\texttt{\char'074 emphasis\char'076 } (element)}\index{elements:!emphasis=\texttt{\char'074 emphasis\char'076 }}:]emphasis according to the surrounding style,
%   usually italics but roman when the surrounding text
%   is already italic;
% \item[\texttt{<envar>}\index{envar=\texttt{\char'074 envar\char'076 } (element)}\index{elements:!envar=\texttt{\char'074 envar\char'076 }}:]\label{environments-doc}a \LaTeX{} environment name like
%   \texttt{enumerate};
% \item[\texttt{<exceptionname>}\index{exceptionname=\texttt{\char'074 exceptionname\char'076 } (element)}\index{elements:!exceptionname=\texttt{\char'074 exceptionname\char'076 }}:]\label{exceptionnames-doc}This {\sffamily \textsc{should}} be
%   used for the keywords of RFC2119 in formal
%   admonishments;
% \item[\texttt{<filename>}\index{filename=\texttt{\char'074 filename\char'076 } (element)}\index{elements:!filename=\texttt{\char'074 filename\char'076 }}:]\label{filenames-doc}name of a file, a full directory or file path,
%   or just a part of the name (eg a filetype);
% \item[\texttt{<firstterm>}\index{firstterm=\texttt{\char'074 firstterm\char'076 } (element)}\index{elements:!firstterm=\texttt{\char'074 firstterm\char'076 }}:]the defining instance of a specialist term; it
%   {\sffamily \textsc{may}} or
%   {\sffamily \textsc{may not}} actually be
%   the first occurrence;
% \par\smallskip\leavevmode
% \CPKrunningecho{firstterm}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Make this work like acronyms}}\par\smallskip
% \item[\texttt{<footnote>}\index{footnote=\texttt{\char'074 footnote\char'076 } (element)}\index{elements:!footnote=\texttt{\char'074 footnote\char'076 }}:]\label{footnotes-doc}a footnote;
% \item[\texttt{<foreignphrase>}\index{foreignphrase=\texttt{\char'074 foreignphrase\char'076 } (element)}\index{elements:!foreignphrase=\texttt{\char'074 foreignphrase\char'076 }}:]\label{foreign-doc}for foreign-language expressions, usually
%   italicised. You {\sffamily \textsc{must}}
%   identify the language with the two-letter
%   \textsc{iso} 639–1 code in the \texttt{@xml:lang}\index{xml:lang=\texttt{\char'100 xml:lang} (attribute)}\index{attributes:!xml:lang=\texttt{\char'100 xml:lang}} attribute. The
%   \textsf{babel} package will be loaded by
%   \emph{AutoPackage} for all
%   languages referenced.\par
% \item[\texttt{<function>}\index{function=\texttt{\char'074 function\char'076 } (element)}\index{elements:!function=\texttt{\char'074 function\char'076 }}:]\label{functions-doc}Marks a function name in a programming
%   language identified in the \texttt{@language}\index{language=\texttt{\char'100 language} (attribute)}\index{attributes:!language=\texttt{\char'100 language}} attribute;
% \item[\texttt{<guibutton>}\index{guibutton=\texttt{\char'074 guibutton\char'076 } (element)}\index{elements:!guibutton=\texttt{\char'074 guibutton\char'076 }}:]\label{gui-doc}represents an on-screen clickable
%   {\changemenucolor{keys}{bg}%  {HTML}{CDCDCD}\renewmenumacro{\keys}%  {roundedkeys}\keys{Button}} (round corners) in an
%   interface;
% \item[\texttt{<guilabel>}\index{guilabel=\texttt{\char'074 guilabel\char'076 } (element)}\index{elements:!guilabel=\texttt{\char'074 guilabel\char'076 }}:]represents an on-screen
%   {\renewmenumacro{\keys}{angularkeys}\keys{Label}} (square corners) for a
%   piece of an interface;
% \item[GUI menus:]the sequence of elements
%   \texttt{<guimenu>}\index{guimenu=\texttt{\char'074 guimenu\char'076 } (element)}\index{elements:!guimenu=\texttt{\char'074 guimenu\char'076 }} \texttt{<guisubmenu>}\index{guisubmenu=\texttt{\char'074 guisubmenu\char'076 } (element)}\index{elements:!guisubmenu=\texttt{\char'074 guisubmenu\char'076 }} \texttt{<guimenuitem>}\index{guimenuitem=\texttt{\char'074 guimenuitem\char'076 } (element)}\index{elements:!guimenuitem=\texttt{\char'074 guimenuitem\char'076 }} 
%   (with optionally repeatable \texttt{<guisubmenu>}\index{guisubmenu=\texttt{\char'074 guisubmenu\char'076 } (element)}\index{elements:!guisubmenu=\texttt{\char'074 guisubmenu\char'076 }})
%   with {\sffamily \textsc{no}} spaces
%   between the elements is represented as an arrowed
%   menu tree:
%   \menu{Menu>Sub-menu>Menu 
%     Item}.\par
% \item[\texttt{<inlineequation>}\index{inlineequation=\texttt{\char'074 inlineequation\char'076 } (element)}\index{elements:!inlineequation=\texttt{\char'074 inlineequation\char'076 }}:]\label{inlinemath-doc}\LaTeX{} code for a mathematical expression to be
%   rendered inline {\sffamily \textsc{must}}
%   go in the \texttt{<mathphrase>}\index{mathphrase=\texttt{\char'074 mathphrase\char'076 } (element)}\index{elements:!mathphrase=\texttt{\char'074 mathphrase\char'076 }} sub-element;
% \item[\texttt{<inlinemediaobject>}\index{inlinemediaobject=\texttt{\char'074 inlinemediaobject\char'076 } (element)}\index{elements:!inlinemediaobject=\texttt{\char'074 inlinemediaobject\char'076 }}:]include a text-sized image, for example an icon
%   unavailable by other means. This
%   {\sffamily \textsc{requires}} the
%   \texttt{<imageobject>}\index{imageobject=\texttt{\char'074 imageobject\char'076 } (element)}\index{elements:!imageobject=\texttt{\char'074 imageobject\char'076 }}/\texttt{<imagedata>}\index{imagedata=\texttt{\char'074 imagedata\char'076 } (element)}\index{elements:!imagedata=\texttt{\char'074 imagedata\char'076 }}
%   subelements just like the images in
%   \texttt{<figure>}\index{figure=\texttt{\char'074 figure\char'076 } (element)}\index{elements:!figure=\texttt{\char'074 figure\char'076 }} do;
% \item[\texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }}:]an \emph{inline} list with
%   `or' before the final item,
%   formatted within the paragraph, with italic
%   lowercase letters and a parenthesis denoting the
%   items. The separating semicolon and terminating
%   `or' are automatic (courtesy
%   of the \textsf{enumitem} package) and
%   {\sffamily \textsc{must not}} be
%   typed;
% \item[\texttt{<keycap>}\index{keycap=\texttt{\char'074 keycap\char'076 } (element)}\index{elements:!keycap=\texttt{\char'074 keycap\char'076 }}:]portrays a specific key on the keyboard such as
%   \keys{\#} when other means are
%   inadequate;
% \item[\texttt{<link>}\index{link=\texttt{\char'074 link\char'076 } (element)}\index{elements:!link=\texttt{\char'074 link\char'076 }}:]\label{link}an external reference to a
%   \textsc{uri} using the \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} attribute. If
%   the element has content, it is formatted as a link;
%   if the element is empty, the \textsc{uri}
%   is shown as the link text;
% \item[\texttt{<literal>}\index{literal=\texttt{\char'074 literal\char'076 } (element)}\index{elements:!literal=\texttt{\char'074 literal\char'076 }}/\texttt{<literallayout>}\index{literallayout=\texttt{\char'074 literallayout\char'076 } (element)}\index{elements:!literallayout=\texttt{\char'074 literallayout\char'076 }}:]identifies a literal string of \LaTeX{} code on
%   which no interpretation is to be performed in
%   \textsc{xml} (markup characters like
%   backslashes and curly braces will not be escaped but
%   passed through to the {\ttfamily{}.dtx} file
%   untouched); the \texttt{@xml:lang}\index{xml:lang=\texttt{\char'100 xml:lang} (attribute)}\index{attributes:!xml:lang=\texttt{\char'100 xml:lang}} attribute can be
%   set to the name of the language (eg \texttt{"TeX"}\index{TeX=\texttt{"TeX"} (attribute value)}\index{attribute values:!TeX=\texttt{"TeX"}}, \texttt{"LaTeX"}\index{LaTeX=\texttt{"LaTeX"} (attribute value)}\index{attribute values:!LaTeX=\texttt{"LaTeX"}}, etc);
% \item[\texttt{<markup>}\index{markup=\texttt{\char'074 markup\char'076 } (element)}\index{elements:!markup=\texttt{\char'074 markup\char'076 }}:]identifies markup in languages \emph{other
%     than} \textsc{xml} or \LaTeX{}.
%   Use the \texttt{@language}\index{language=\texttt{\char'100 language} (attribute)}\index{attributes:!language=\texttt{\char'100 language}}
%   attribute to give the language;
% \item[\texttt{<methodname>}\index{methodname=\texttt{\char'074 methodname\char'076 } (element)}\index{elements:!methodname=\texttt{\char'074 methodname\char'076 }}:]identifies a template or method in a programming
%   language (eg \textsc{xslt}). Use the \texttt{@language}\index{language=\texttt{\char'100 language} (attribute)}\index{attributes:!language=\texttt{\char'100 language}} attribute to give
%   the language;
% \item[olink:]used as a pointer in the
%   {\ttfamily{}readme.xml}\thinspace: see \vref{readmemd};
% \item[\llap{\ensuremath{\ast}\ }\texttt{<option>}\index{option=\texttt{\char'074 option\char'076 } (element)}\index{elements:!option=\texttt{\char'074 option\char'076 }}:]a \LaTeX{} option to a class, package, or
%   command, like \textbf{\texttt{a4paper}};
% \item[\texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }}:]an \emph{inline} list with
%   `and' before the final item,
%   formatted within the paragraph, with italic
%   lowercase letters and a parenthesis denoting the
%   items. The separating semicolon and terminating
%   `and' are automatic (courtesy
%   of the \textsf{enumitem} package) and
%   {\sffamily \textsc{must not}} be
%   typed;
% \item[\llap{\ensuremath{\ast}\ }\texttt{<package>}\index{package=\texttt{\char'074 package\char'076 } (element)}\index{elements:!package=\texttt{\char'074 package\char'076 }}:]a \LaTeX{} package name like
%   \textsf{fancybox};
% \item[\llap{\ensuremath{\ast}\ }\texttt{<parameter>}\index{parameter=\texttt{\char'074 parameter\char'076 } (element)}\index{elements:!parameter=\texttt{\char'074 parameter\char'076 }}:]used in annotating \textsc{xslt}
%   parameters; behaves as \texttt{@varname}\index{varname=\texttt{\char'100 varname} (attribute)}\index{attributes:!varname=\texttt{\char'100 varname}} \texttt{\unskip="parameter"}\index{parameter=\texttt{"parameter"} (attribute value)}\index{attribute values:!parameter=\texttt{"parameter"}};
% \item[personname:]this is for highlighting the names of people,
%   usually contributors or authors of other classes or
%   packages. It {\sffamily \textsc{must}}
%   contain their \texttt{<firstname>}\index{firstname=\texttt{\char'074 firstname\char'076 } (element)}\index{elements:!firstname=\texttt{\char'074 firstname\char'076 }} and
%   \texttt{<surname>}\index{surname=\texttt{\char'074 surname\char'076 } (element)}\index{elements:!surname=\texttt{\char'074 surname\char'076 }} and it will create an index entry
%   for them as well as being in the text;
% \item[\texttt{<phrase>}\index{phrase=\texttt{\char'074 phrase\char'076 } (element)}\index{elements:!phrase=\texttt{\char'074 phrase\char'076 }}:]marks a phrase used as-is (ie not a quote from
%   anyone in particular) by enclosing it in quotation
%   marks;
% \item[\texttt{<productname>}\index{productname=\texttt{\char'074 productname\char'076 } (element)}\index{elements:!productname=\texttt{\char'074 productname\char'076 }}:]marks a product name in italics. Can also be
%   used for system commands, eg \emph{make}\thinspace(1). The \texttt{@userlevel}\index{userlevel=\texttt{\char'100 userlevel} (attribute)}\index{attributes:!userlevel=\texttt{\char'100 userlevel}} attribute can be
%   set to the chapter number of the
%   \textsc{unix} manual pages for the
%   command;
% \item[\texttt{<quote>}\index{quote=\texttt{\char'074 quote\char'076 } (element)}\index{elements:!quote=\texttt{\char'074 quote\char'076 }}:]marks a quote from someone by putting it in
%   quotation marks;
% \item[\texttt{<replaceable>}\index{replaceable=\texttt{\char'074 replaceable\char'076 } (element)}\index{elements:!replaceable=\texttt{\char'074 replaceable\char'076 }}:]identifies text, commands, or keywords to be
%   typed by the user in an example, \emph{for which
%     the user must substitute a meaningful
%     value}, eg
%   \uline{password} (shown in
%   italics when within a monospace example, or
%   underlined if in normal text);
% \item[\texttt{<systemitem>}\index{systemitem=\texttt{\char'074 systemitem\char'076 } (element)}\index{elements:!systemitem=\texttt{\char'074 systemitem\char'076 }}:]identifies generic computer-related strings such
%   as system commands, hostnames, Regular Expressions,
%   etc which need to be printed in monospace to
%   eliminate any confusion over 1/l/I, 0/O, etc;
% \item[\texttt{<tag>}\index{tag=\texttt{\char'074 tag\char'076 } (element)}\index{elements:!tag=\texttt{\char'074 tag\char'076 }}:]\label{markuptags}an \textsc{xml} element, attribute,
%   attribute value, or entity name: the type is
%   specified in the \texttt{@class}\index{class=\texttt{\char'100 class} (attribute)}\index{attributes:!class=\texttt{\char'100 class}}
%   attribute and is one of the predetermined list
%   provided automatically by
%   \emph{DocBook} (your
%   \textsc{xml} editor will guide
%   you).\par
% To suppress the automated
%   `at'
%   ({\ttfamily{}@}) prefix on attributes,
%   set \texttt{conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}}=\texttt{"noat"}\index{noat=\texttt{"noat"} (attribute value)}\index{attribute values:!noat=\texttt{"noat"}}.\par
% \item[\texttt{<type>}\index{type=\texttt{\char'074 type\char'076 } (element)}\index{elements:!type=\texttt{\char'074 type\char'076 }}:]\label{type}marks a span of text for which specific
%   typographical treatment is needed, such as examples
%   of output. The following attributes control the
%   appearance:\par
% \begin{description}[style=unboxed]
% \item[\texttt{@fontencoding}\index{fontencoding=\texttt{\char'100 fontencoding} (attribute)}\index{attributes:!fontencoding=\texttt{\char'100 fontencoding}}:]one of the values
% {\ttfamily{}T1}\thinspace,
% {\ttfamily{}OT1}\thinspace, or
% {\ttfamily{}U}\thinspace. The default is not
% to change the current encoding setting;
% \item[\texttt{@fontfamily}\index{fontfamily=\texttt{\char'100 fontfamily} (attribute)}\index{attributes:!fontfamily=\texttt{\char'100 fontfamily}}:]one of \texttt{"roman"}\index{roman=\texttt{"roman"} (attribute value)}\index{attribute values:!roman=\texttt{"roman"}},
% \texttt{"sans"}\index{sans=\texttt{"sans"} (attribute value)}\index{attribute values:!sans=\texttt{"sans"}}, or \texttt{"monospace"}\index{monospace=\texttt{"monospace"} (attribute value)}\index{attribute values:!monospace=\texttt{"monospace"}} for
% selecting that family from among the three
% always available in \LaTeX{}.\par
% If this is the only attribute, and the
% element is empty, it will cause the name of
% the current font family to be output;
% \item[\texttt{@fontface}\index{fontface=\texttt{\char'100 fontface} (attribute)}\index{attributes:!fontface=\texttt{\char'100 fontface}}:]the
% `Karl Berry\index{Berry!Karl}' 
% font family name of an installed font such as
% {\ttfamily{}ptm} (Times),
% {\ttfamily{}bch} (Charter),
% etc;
% \item[\texttt{@fontshape}\index{fontshape=\texttt{\char'100 fontshape} (attribute)}\index{attributes:!fontshape=\texttt{\char'100 fontshape}}:]one of \texttt{"it"}\index{it=\texttt{"it"} (attribute value)}\index{attribute values:!it=\texttt{"it"}}
% (italic) or \texttt{"up"}\index{up=\texttt{"up"} (attribute value)}\index{attribute values:!up=\texttt{"up"}}
% (upright) or \texttt{"sc"}\index{sc=\texttt{"sc"} (attribute value)}\index{attribute values:!sc=\texttt{"sc"}}
% (small caps).\par
% \item[\texttt{@fontseries}\index{fontseries=\texttt{\char'100 fontseries} (attribute)}\index{attributes:!fontseries=\texttt{\char'100 fontseries}}:]one of \texttt{"k"}\index{k=\texttt{"k"} (attribute value)}\index{attribute values:!k=\texttt{"k"}}
% (book), \texttt{"r"}\index{r=\texttt{"r"} (attribute value)}\index{attribute values:!r=\texttt{"r"}}
% (regular), \texttt{"m"}\index{m=\texttt{"m"} (attribute value)}\index{attribute values:!m=\texttt{"m"}}
% (medium), \texttt{"n"}\index{n=\texttt{"n"} (attribute value)}\index{attribute values:!n=\texttt{"n"}}
% (normal), \texttt{"b"}\index{b=\texttt{"b"} (attribute value)}\index{attribute values:!b=\texttt{"b"}}
% (bold), \texttt{"bx"}\index{bx=\texttt{"bx"} (attribute value)}\index{attribute values:!bx=\texttt{"bx"}} (extra
% bold), \texttt{"it"}\index{it=\texttt{"it"} (attribute value)}\index{attribute values:!it=\texttt{"it"}}
% (italic), \texttt{"sl"}\index{sl=\texttt{"sl"} (attribute value)}\index{attribute values:!sl=\texttt{"sl"}}
% (slanted), \texttt{"l"}\index{l=\texttt{"l"} (attribute value)}\index{attribute values:!l=\texttt{"l"}}
% (light), or \texttt{"c"}\index{c=\texttt{"c"} (attribute value)}\index{attribute values:!c=\texttt{"c"}}
% (heavy). Others may be used if you know that
% your font setup supports them;
% \item[\texttt{@fontsize}\index{fontsize=\texttt{\char'100 fontsize} (attribute)}\index{attributes:!fontsize=\texttt{\char'100 fontsize}}:]\emph{either} the font size
% in the format
% \uline{pp}/\uline{bb} 
% for the point size and the baseline height
% (same as for ‘\textbf{\textsf{\texttt{@wordsize}\index{wordsize=\texttt{\char'100 wordsize} (attribute)}\index{attributes:!wordsize=\texttt{\char'100 wordsize}}}}’, the second item in the list in \vref{wordsize});
% \emph{or} just a point size, in
% which case the baseline height will be set to
% zero.\par
% Note that if \texttt{@fontsize}\index{fontsize=\texttt{\char'100 fontsize} (attribute)}\index{attributes:!fontsize=\texttt{\char'100 fontsize}} is used
% with the slash syntax, the content of the
% element will be terminated by a paragraph
% break in order to honour the baseline
% height.\par
% \item[\texttt{@fontcolor}\index{fontcolor=\texttt{\char'100 fontcolor} (attribute)}\index{attributes:!fontcolor=\texttt{\char'100 fontcolor}}:]a colour name from an installed palette of
% the \textsf{xcolor} package, default
% \textbf{\texttt{svgnames}}.
% \end{description}
% For example, {\color{CornflowerBlue}\sffamily \itshape\fontseries{b}\fontsize{16}{0}\selectfont CornflowerBlue, bold,
%     italic, sans-serif, 16pt}\par 
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
 <type
		  fontfamily="sans" fontcolor="CornflowerBlue"
		  fontseries="b" fontshape="it"
		  fontsize="16">CornflowerBlue, bold, italic,
		  sans-serif, 16pt</type>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% These are experimental and may change slightly
%   in future versions. The terminology (except \texttt{@fontcolor}\index{fontcolor=\texttt{\char'100 fontcolor} (attribute)}\index{attributes:!fontcolor=\texttt{\char'100 fontcolor}}) is standard
%   \LaTeX{}.\par
% \item[\texttt{<uri>}\index{uri=\texttt{\char'074 uri\char'076 } (element)}\index{elements:!uri=\texttt{\char'074 uri\char'076 }}:](deprecated) marks a \textsc{uri}
%   (formats it with the {\ttfamily{}\textbackslash{}url} macro).
%   This is being replaced by the \texttt{<link>}\index{link=\texttt{\char'074 link\char'076 } (element)}\index{elements:!link=\texttt{\char'074 link\char'076 }}
%   element type (see ‘\textbf{\textsf{\texttt{<link>}\index{link=\texttt{\char'074 link\char'076 } (element)}\index{elements:!link=\texttt{\char'074 link\char'076 }}}}’, the 23rd item in this list).\par
% \item[\llap{\ensuremath{\ast}\ }\texttt{<varname>}\index{varname=\texttt{\char'074 varname\char'076 } (element)}\index{elements:!varname=\texttt{\char'074 varname\char'076 }}:]a \LaTeX{} variable, like a length or a counter,
%   or a variable in another language specified in the
%   \texttt{@language}\index{language=\texttt{\char'100 language} (attribute)}\index{attributes:!language=\texttt{\char'100 language}} attribute. The
%   \texttt{<role>}\index{role=\texttt{\char'074 role\char'076 } (element)}\index{elements:!role=\texttt{\char'074 role\char'076 }} attribute is used to specify the
%   type of variable: for \LaTeX{} the value is usually
%   \texttt{"length"}\index{length=\texttt{"length"} (attribute value)}\index{attribute values:!length=\texttt{"length"}} or \texttt{"counter"}\index{counter=\texttt{"counter"} (attribute value)}\index{attribute values:!counter=\texttt{"counter"}}, but there is a
%   special case of \texttt{"color"}\index{color=\texttt{"color"} (attribute value)}\index{attribute values:!color=\texttt{"color"}}
%   (note spelling, and see \vref{speccols}).
%   The backslash on length names {\sffamily \textsc{must not}} be typed (same rule as with
%   macro names in the \texttt{<command>}\index{command=\texttt{\char'074 command\char'076 } (element)}\index{elements:!command=\texttt{\char'074 command\char'076 }} element above)
%   as it will be added automatically so that the name
%   can be indexed properly. For \BibTeX{} field names,
%   use the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} value \texttt{"field"}\index{field=\texttt{"field"} (attribute value)}\index{attribute values:!field=\texttt{"field"}}. Use the \texttt{@language}\index{language=\texttt{\char'100 language} (attribute)}\index{attributes:!language=\texttt{\char'100 language}} attribute for
%   \texttt{"BiBTeX"}\index{BiBTeX=\texttt{"BiBTeX"} (attribute value)}\index{attribute values:!BiBTeX=\texttt{"BiBTeX"}}, \texttt{"bash"}\index{bash=\texttt{"bash"} (attribute value)}\index{attribute values:!bash=\texttt{"bash"}}, \texttt{"XML"}\index{XML=\texttt{"XML"} (attribute value)}\index{attribute values:!XML=\texttt{"XML"}}, \texttt{"XSLT"}\index{XSLT=\texttt{"XSLT"} (attribute value)}\index{attribute values:!XSLT=\texttt{"XSLT"}}, etc.\par
% When used in annotations, the name of the
%   variable is echoed unheralded in the margin. If the
%   element is used in the first line of an annotation,
%   this echo may overtype the name of the annotation;
%   \emph{ClassPack} tries to avoid
%   this but the echo can be suppressed manually by
%   setting the ;
% \item[\texttt{<wordasword>}\index{wordasword=\texttt{\char'074 wordasword\char'076 } (element)}\index{elements:!wordasword=\texttt{\char'074 wordasword\char'076 }}:]marks a word that is being used as itself
%   (usually for purposes of clarification), so it goes
%   in quotation marks;
% \item[\texttt{<xref>}\index{xref=\texttt{\char'074 xref\char'076 } (element)}\index{elements:!xref=\texttt{\char'074 xref\char'076 }}:]\label{xref}a cross-reference using the \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} attribute to point
%   to one or more elements with an \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute somewhere
%   else in the document; the mechanism is identical to
%   \LaTeX{}’s
%   {\ttfamily{}\textbackslash{}label}\dots{}{\ttfamily{}\textbackslash{}ref} 
%   but the presentation uses (mainly) the extended
%   labelling features of the
%   \textsf{varioref} package to enable the
%   labelling of cross-references with the name of the
%   target object. A cross-reference to a Figure, for
%   example, is automatically labelled
%   `Figure…' — you do not
%   (indeed {\sffamily \textsc{must not}})
%   type the name of the target.\par
% Some target element types are not recognised by
%   \textsf{varioref} and are therefore
%   compensated for in the \textsc{xslt}
%   script (see \vref{ann-xref}).\par
% \par\begingroup
%   \fboxsep1em\centering
%   \fbox{\begin{minipage}{0.8\columnwidth}\sffamily
%  \raggedright\parindent0pt
%  \parskip=.5\baselineskip
% Note that these automations are a
%     work-in-progress. In particular they are not yet
%     consistent, and insufficiently
%     context-sensitive.\par
% \end{minipage}}\par\endgroup
% \begin{description}[style=unboxed]
% \item[\texttt{<varlistentry>}\index{varlistentry=\texttt{\char'074 varlistentry\char'076 } (element)}\index{elements:!varlistentry=\texttt{\char'074 varlistentry\char'076 }}:]formats the term in bold, in quotes, and
% calculates the ordinal position in the list as
% a number if over 12 or as a word if under; and
% then uses \textsf{varioref} to
% provide the section and page reference; eg the
% entry for the \texttt{<type>}\index{type=\texttt{\char'074 type\char'076 } (element)}\index{elements:!type=\texttt{\char'074 type\char'076 }} element earlier
% would read:
% ‘\textbf{\textsf{\texttt{<type>}\index{type=\texttt{\char'074 type\char'076 } (element)}\index{elements:!type=\texttt{\char'074 type\char'076 }}}}’, the 39th item in the list in \vref{type}\par
% \item[\texttt{<listitem>}\index{listitem=\texttt{\char'074 listitem\char'076 } (element)}\index{elements:!listitem=\texttt{\char'074 listitem\char'076 }} in
%       \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }}:]calculates the ordinal position in the
% same way as for \texttt{<varlistentry>}\index{varlistentry=\texttt{\char'074 varlistentry\char'076 } (element)}\index{elements:!varlistentry=\texttt{\char'074 varlistentry\char'076 }} above;
% and then uses \textsf{varioref} to
% provide the section and page reference; eg the
% entry for the {\ttfamily{}.ins} file
% at the start of this document would read:
% the \ordinalstringnum{2} item in the list in \vref{ins}\par
% \item[\texttt{<listitem>}\index{listitem=\texttt{\char'074 listitem\char'076 } (element)}\index{elements:!listitem=\texttt{\char'074 listitem\char'076 }} in
%       \texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }}:]uses the item counter and the page
% reference with a standard
% {\ttfamily{}\textbackslash{}ref}; eg the entry
% explaining `flow'
% elements would read: item~\ref{flowsum} in the list on p.\thinspace\pageref{flowsum}\par
% \item[\texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} in
%       \texttt{<procedure>}\index{procedure=\texttt{\char'074 procedure\char'076 } (element)}\index{elements:!procedure=\texttt{\char'074 procedure\char'076 }}:]works the same way as \texttt{<listitem>}\index{listitem=\texttt{\char'074 listitem\char'076 } (element)}\index{elements:!listitem=\texttt{\char'074 listitem\char'076 }}
% in \texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }}.
% \end{description}
% List references should add
%   `above' or
%   `below' if the target is in
%   the same list, but this has not been evenly
%   implemented yet.\par
% \begin{description}[style=unboxed]
% \item[\texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }}:]for a whole ordered list with a title, the
% reference quotes the title and gives a section
% reference using
% \textsf{varioref};
% \item[\texttt{<informaltable>}\index{informaltable=\texttt{\char'074 informaltable\char'076 } (element)}\index{elements:!informaltable=\texttt{\char'074 informaltable\char'076 }}:]refers to `the table' and
% uses \textsf{varioref} for the
% section and page;
% \item[\texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }}:]refers to `the code' and uses
% \textsf{varioref} for the
% page;
% \item[\texttt{<note>}\index{note=\texttt{\char'074 note\char'076 } (element)}\index{elements:!note=\texttt{\char'074 note\char'076 }}, \texttt{<warning>}\index{warning=\texttt{\char'074 warning\char'076 } (element)}\index{elements:!warning=\texttt{\char'074 warning\char'076 }},
%       \texttt{<sidebar>}\index{sidebar=\texttt{\char'074 sidebar\char'076 } (element)}\index{elements:!sidebar=\texttt{\char'074 sidebar\char'076 }}:]refers to the name of the element and uses
% \textsf{varioref} for the
% page;
% \item[\texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }}:]references to a location inside an
% extractable file in the
% `files' part
% experimentally creates a hyperlink to the
% target;
% \item[all others:]use {\ttfamily{}\textbackslash{}vref}.
% \end{description}
% There are some exceptions:\par
% \begin{description}[style=unboxed]
% \item[\texttt{@xrefstyle}\index{xrefstyle=\texttt{\char'100 xrefstyle} (attribute)}\index{attributes:!xrefstyle=\texttt{\char'100 xrefstyle}}=\texttt{"page"}\index{page=\texttt{"page"} (attribute value)}\index{attribute values:!page=\texttt{"page"}}:]this attribute value forces a page
% reference only (the default for
% \texttt{<informaltable>}\index{informaltable=\texttt{\char'074 informaltable\char'076 } (element)}\index{elements:!informaltable=\texttt{\char'074 informaltable\char'076 }} or
% \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }}) using
% {\ttfamily{}\textbackslash{}vpageref};
% \item[Ranges:]if the target is \emph{not} \texttt{<orderedlist/listitem>}\index{orderedlist/listitem=\texttt{\char'074 orderedlist/listitem\char'076 } (element)}\index{elements:!orderedlist/listitem=\texttt{\char'074 orderedlist/listitem\char'076 }} \emph{and
%   not} a \texttt{<procedure/step>}\index{procedure/step=\texttt{\char'074 procedure/step\char'076 } (element)}\index{elements:!procedure/step=\texttt{\char'074 procedure/step\char'076 }} \emph{and not} a location in the
% \texttt{"files"}\index{files=\texttt{"files"} (attribute value)}\index{attribute values:!files=\texttt{"files"}} \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }}, and if the \texttt{@endterm}\index{endterm=\texttt{\char'100 endterm} (attribute)}\index{attributes:!endterm=\texttt{\char'100 endterm}} is present,
% use {\ttfamily{}\textbackslash{}vrange} on \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} and \texttt{@endterm}\index{endterm=\texttt{\char'100 endterm} (attribute)}\index{attributes:!endterm=\texttt{\char'100 endterm}};
% \item[\texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}}:]if there is an \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} attribute
% present, put the content of the target’s first
% subelement named in that \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} in
% (parentheses).
% \end{description}
% \end{description}
% \subsection{Bibliographic markup}\label{bibs}
% If you use bibliographic citation and reference in your
%   documentation, the references themselves
%   {\sffamily \textsc{must}} be stored in a
%   \texttt{<bibliography>}\index{bibliography=\texttt{\char'074 bibliography\char'076 } (element)}\index{elements:!bibliography=\texttt{\char'074 bibliography\char'076 }} element immediately after the last
%   \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} element in the \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}} part. This
%   {\sffamily \textsc{must}} contain a
%   \texttt{<biblioentry>}\index{biblioentry=\texttt{\char'074 biblioentry\char'076 } (element)}\index{elements:!biblioentry=\texttt{\char'074 biblioentry\char'076 }} element for each reference you wish
%   to cite (for how to make a citation, see
%   ‘\textbf{\textsf{\texttt{<biblioref>}\index{biblioref=\texttt{\char'074 biblioref\char'076 } (element)}\index{elements:!biblioref=\texttt{\char'074 biblioref\char'076 }}}}’, the fifth item in the list in \vref{bibrefs}).\par
% This enables your \textsc{xml} editor to use
%   the \texttt{<ID>}\index{ID=\texttt{\char'074 ID\char'076 } (element)}\index{elements:!ID=\texttt{\char'074 ID\char'076 }}/\texttt{<IDREF>}\index{IDREF=\texttt{\char'074 IDREF\char'076 } (element)}\index{elements:!IDREF=\texttt{\char'074 IDREF\char'076 }} links between
%   \texttt{<biblioref>}\index{biblioref=\texttt{\char'074 biblioref\char'076 } (element)}\index{elements:!biblioref=\texttt{\char'074 biblioref\char'076 }} and \texttt{<biblioentry>}\index{biblioentry=\texttt{\char'074 biblioentry\char'076 } (element)}\index{elements:!biblioentry=\texttt{\char'074 biblioentry\char'076 }} for
%   validation, and to ensure you don’t cite something not in
%   your references, and that only references that are cited get
%   output.\par
% \subsubsection{The \texttt{<bibliography>}\index{bibliography=\texttt{\char'074 bibliography\char'076 } (element)}\index{elements:!bibliography=\texttt{\char'074 bibliography\char'076 }} element}
% The attributes on the \texttt{<bibliography>}\index{bibliography=\texttt{\char'074 bibliography\char'076 } (element)}\index{elements:!bibliography=\texttt{\char'074 bibliography\char'076 }}
%     start-tag identify the type of bibliographic formatting
%     required:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML]
<bibliography arch="biblatex" condition="biber" label="apa" 
  xlink:href="foo.bib">
  <biblioentry...>
    ...
  </biblioentry>
  ...
</bibliography>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% \begin{description}[style=unboxed]
% \item[\texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}}:]specifies which type of handler is to be used,
%   either \texttt{"biblatex"}\index{biblatex=\texttt{"biblatex"} (attribute value)}\index{attribute values:!biblatex=\texttt{"biblatex"}} for the
%   \textsf{biblatex} package, or \texttt{"bibtex"}\index{bibtex=\texttt{"bibtex"} (attribute value)}\index{attribute values:!bibtex=\texttt{"bibtex"}} for the
%   \emph{bibtex} program. The
%   default is \texttt{"biblatex"}\index{biblatex=\texttt{"biblatex"} (attribute value)}\index{attribute values:!biblatex=\texttt{"biblatex"}};
% \item[\texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}}:]specifies the bibliographic processor (program)
%   to use, either \texttt{"biber"}\index{biber=\texttt{"biber"} (attribute value)}\index{attribute values:!biber=\texttt{"biber"}} or
%   \texttt{"bibtex"}\index{bibtex=\texttt{"bibtex"} (attribute value)}\index{attribute values:!bibtex=\texttt{"bibtex"}}; this is only
%   meaningful in the case of
%   {\ttfamily{}arch="biblatex"}\thinspace, and is
%   otherwise ignored. The default is \texttt{"biber"}\index{biber=\texttt{"biber"} (attribute value)}\index{attribute values:!biber=\texttt{"biber"}};
% \item[\texttt{@label}\index{label=\texttt{\char'100 label} (attribute)}\index{attributes:!label=\texttt{\char'100 label}}:]specifies the bibliographic style of reference.
%   This {\sffamily \textsc{must}} be the name
%   of an installed style recognised by
%   \emph{biblatex} or
%   \emph{bibtex}, whichever was
%   specified in \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}}
%   above. The default is \texttt{"apa"}\index{apa=\texttt{"apa"} (attribute value)}\index{attribute values:!apa=\texttt{"apa"}} for
%   \emph{biblatex} and \texttt{"apacite"}\index{apacite=\texttt{"apacite"} (attribute value)}\index{attribute values:!apacite=\texttt{"apacite"}} for \BibTeX{};
% \par\smallskip\leavevmode
% \CPKrunningecho{label}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Maybe add all valid style names to the DTD}}\par\smallskip
% \item[\texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}}:]{\sffamily \textsc{optional}} gives the
%   name of the output \BibTeX{} file
%   (\emph{including} the
%   {\ttfamily{}.bib} filetype) to which the
%   references should be written by the
%   \textsc{xslt} script. The default is the
%   same as the name of the class or package being
%   created. This attribute would typically be used only
%   where the package or class being documented is part
%   of a suite.\par
% \item[\texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}}:]gives the name of any required ancillary package
%   for the style specified in the \texttt{@label}\index{label=\texttt{\char'100 label} (attribute)}\index{attributes:!label=\texttt{\char'100 label}} attribute above
%   (often called by the same name, eg
%   \textsf{apacite},
%   \textsf{natbib},
%   \textsf{chicago}, etc). Note that this is
%   currently used \emph{only} when using
%   \BibTeX{}, \emph{not} \emph{biblatex}.
% \par\smallskip\leavevmode
% \CPKrunningecho{xreflabel}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Add all possible names to the DTD?}}\par\smallskip
% \end{description}
% If the \texttt{<bibliography>}\index{bibliography=\texttt{\char'074 bibliography\char'076 } (element)}\index{elements:!bibliography=\texttt{\char'074 bibliography\char'076 }} element immediately
%     contains a \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }} element, the value is used as
%     the {\ttfamily{}\textbackslash{}bibname} for the heading on the
%     bibliography.\par
% \subsubsection{Bibliographic entries}
% Every \texttt{<biblioentry>}\index{biblioentry=\texttt{\char'074 biblioentry\char'076 } (element)}\index{elements:!biblioentry=\texttt{\char'074 biblioentry\char'076 }} element
%     {\sffamily \textsc{must}} have
%     \emph{both} an \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute by which it can
%     be cited with the \texttt{<biblioref>}\index{biblioref=\texttt{\char'074 biblioref\char'076 } (element)}\index{elements:!biblioref=\texttt{\char'074 biblioref\char'076 }} element
%     \emph{and} an \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} attribute classifying
%     it with one of the standard \BibTeX{} or
%     \emph{biblatex} document types
%     (article, book, incollection, etc, as specified in the
%     \textsf{biblatex} documentation).
%     Currently-supported values can be found in the
%     \hyperref[DTD]{\textsc{dtd}}\index{DTD} and will be displayed by your
%     \textsc{xml} editor.\par
% The key to successful citation and reference is to
%     ensure that documents are accurately described. The most
%     common types are shown in \vref{entrytab}.\par
% \setlength{\CPKtabwid}{0pt + \widthof{\sffamily{}inproceedings} + 6cm + 2cm + 2.7cm + 3\tabcolsep}
% \begin{table}[hb]
% \caption{Common \BibTeX{} entry types}\label{entrytab}\smallskip
% \small\sffamily
% \begingroup
% \centering
% \begin{tabular}{@{}%
%   >{\sffamily\CPKprestrut}l%
%   >{\renewcommand{\baselinestretch}{0.8}\selectfont{}\raggedright{}\renewcommand{\baselinestretch}{0.8}\selectfont{}\CPKprestrut}p{6cm}%
%   >{\renewcommand{\baselinestretch}{0.8}\selectfont{}\raggedright{}\renewcommand{\baselinestretch}{0.8}\selectfont{}\CPKprestrut}p{2cm}%
%   >{\renewcommand{\baselinestretch}{0.8}\selectfont{}\raggedright{}\renewcommand{\baselinestretch}{0.8}\selectfont{}\CPKprestrut\arraybackslash}p{2.7cm}<{}%
%   @{}}
% \multicolumn{1}{@{}>{\renewcommand{\baselinestretch}{0.8}\selectfont{}\raggedright{}\CPKprestrut}b{\widthof{inproceedingss}}}{\sffamily\bfseries Entry type}&
% \multicolumn{1}{>{\renewcommand{\baselinestretch}{0.8}\selectfont{}\raggedright{}\CPKprestrut}b{6cm}}{\sffamily\bfseries Used for}&
% \multicolumn{1}{>{\renewcommand{\baselinestretch}{0.8}\selectfont{}\raggedright{}\CPKprestrut}b{2cm}}{\sffamily\bfseries Analytic relation}&
% \multicolumn{1}{>{\renewcommand{\baselinestretch}{0.8}\selectfont{}\raggedright{}\CPKprestrut\arraybackslash}b{2.7cm}<{}@{}}{\sffamily\bfseries Monographic relation}\\[2pt]\hline
% \CPKvstrut 
% \texttt{article}&Article in a journal&\texttt{"article"}\index{article=\texttt{"article"} (attribute value)}\index{attribute values:!article=\texttt{"article"}}&\texttt{"journal"}\index{journal=\texttt{"journal"} (attribute value)}\index{attribute values:!journal=\texttt{"journal"}}\\
% \texttt{book}&Books&&\\
% \texttt{inbook}&Chapter in a book all written by the same
%     author&\texttt{"chapter"}\index{chapter=\texttt{"chapter"} (attribute value)}\index{attribute values:!chapter=\texttt{"chapter"}}&\texttt{"book"}\index{book=\texttt{"book"} (attribute value)}\index{attribute values:!book=\texttt{"book"}}\\
% \texttt{incollection}&Article in a book all written by different
%     people&\texttt{"article"}\index{article=\texttt{"article"} (attribute value)}\index{attribute values:!article=\texttt{"article"}}&\texttt{"book"}\index{book=\texttt{"book"} (attribute value)}\index{attribute values:!book=\texttt{"book"}}\\
% \texttt{inproceedings}&Paper given at a conference and published in
%     Proceedings&\texttt{"paper"}\index{paper=\texttt{"paper"} (attribute value)}\index{attribute values:!paper=\texttt{"paper"}}&\texttt{"proceedings"}\index{proceedings=\texttt{"proceedings"} (attribute value)}\index{attribute values:!proceedings=\texttt{"proceedings"}}\\
% \texttt{manual}&Documentation, especially for another class
%   or package&&\\
% \texttt{online}&Web page or downloaded document&&\\
% \texttt{report}&Technical report&&\\
% \texttt{standard}&International or national standards&&\\
% \texttt{thesis}&Doctor’s or Master’s dissertation or
%     thesis&&\\[2pt]\hline
% \end{tabular}
% \par\endgroup
% \end{table}
% Care is needed \emph{in particular} for
%     those entries for documents contained within other
%     documents, eg article in journal, chapter in book, article
%     in collection, paper at conference, etc. Use the
%     \texttt{<biblioset>}\index{biblioset=\texttt{\char'074 biblioset\char'076 } (element)}\index{elements:!biblioset=\texttt{\char'074 biblioset\char'076 }} element to keep the two parts of such
%     entry separate as in this example:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=XML,label=article-example]
  <biblioentry xml:id="tb97" xreflabel="article">
    <biblioset relation="article">
      <author>
        <personname>
          <surname>Flynn</surname>
          <firstname>Peter</firstname>
        </personname>
      </author> 
      <title>Typographers’ Inn</title>
      <subtitle>Where have all the flowers gone?</subtitle>
      <artpagenums>21-22</artpagenums>
    </biblioset>
    <biblioset relation="journal">
      <title>TUGboat</title>
      <volumenum>31</volumenum>
      <issuenum>1</issuenum>
      <date YYYY-MM-DD="2010"/>
    </biblioset>
  </biblioentry>
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% The bibliographic \textsc{xslt}
%     transformation to \BibTeX{} is encoded in
%     {\ttfamily{}db2bibtex.xsl}\thinspace, annotated in \vref{db2bibtexscript}.\par
% \begin{description}[style=unboxed]
% \item[Items with containers:]Articles in journals, articles (by different
%   authors) in collections, chapters in books, and
%   papers at conferences all require two
%   \texttt{<biblioset>}\index{biblioset=\texttt{\char'074 biblioset\char'076 } (element)}\index{elements:!biblioset=\texttt{\char'074 biblioset\char'076 }} elements as in the example
%   above: one (`analytic') to
%   hold the title and author of the article, chapter,
%   or paper, and its page range; and one
%   (`monographic') to hold the
%   details of the publication or conference. The value
%   of the \texttt{@relation}\index{relation=\texttt{\char'100 relation} (attribute)}\index{attributes:!relation=\texttt{\char'100 relation}}
%   attribute for the two \texttt{<biblioset>}\index{biblioset=\texttt{\char'074 biblioset\char'076 } (element)}\index{elements:!biblioset=\texttt{\char'074 biblioset\char'076 }} elements
%   is given in \vref{entrytab}.\par
% \item[Items without containers:]All other types of reference, eg books, manuals,
%   reports, standards, whole issues of periodicals or
%   proceedings, theses, and standalone online
%   resources, etc do not require a \texttt{<biblioset>}\index{biblioset=\texttt{\char'074 biblioset\char'076 } (element)}\index{elements:!biblioset=\texttt{\char'074 biblioset\char'076 }}
%   element.\par
% \end{description}
% \paragraph[Title and subtitle]{Title and subtitle :}
% Use the \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }} element for the title of a
%       document. If there is a subtitle (often separated from
%       the title by an em-rule or a colon) put that in a
%       \texttt{<subtitle>}\index{subtitle=\texttt{\char'074 subtitle\char'076 } (element)}\index{elements:!subtitle=\texttt{\char'074 subtitle\char'076 }} element.\par
% In the items shown in \vref{entrytab},
%       there will normally be a \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }} in
%       \emph{both} \texttt{<biblioset>}\index{biblioset=\texttt{\char'074 biblioset\char'076 } (element)}\index{elements:!biblioset=\texttt{\char'074 biblioset\char'076 }} elements: one for
%       the title of the article, chapter, or paper; and one for
%       the title of the journal or book (for conferences there
%       is a separate \texttt{<conftitle>}\index{conftitle=\texttt{\char'074 conftitle\char'076 } (element)}\index{elements:!conftitle=\texttt{\char'074 conftitle\char'076 }} element).\par
% If the title is long, the \texttt{<titleabbrev>}\index{titleabbrev=\texttt{\char'074 titleabbrev\char'076 } (element)}\index{elements:!titleabbrev=\texttt{\char'074 titleabbrev\char'076 }}
%       element {\sffamily \textsc{may}} be used to
%       give a shortened version of the title.\par
% \paragraph[Authors and editors]{Authors and editors :}\label{authed}
% Single-author documents just use the
%       \texttt{<author>}\index{author=\texttt{\char'074 author\char'076 } (element)}\index{elements:!author=\texttt{\char'074 author\char'076 }} element. For a named person, use
%       the \texttt{<personname>}\index{personname=\texttt{\char'074 personname\char'076 } (element)}\index{elements:!personname=\texttt{\char'074 personname\char'076 }} sub-element to hold the
%       \texttt{<firstname>}\index{firstname=\texttt{\char'074 firstname\char'076 } (element)}\index{elements:!firstname=\texttt{\char'074 firstname\char'076 }}, \texttt{<othername>}\index{othername=\texttt{\char'074 othername\char'076 } (element)}\index{elements:!othername=\texttt{\char'074 othername\char'076 }} (optional),
%       and \texttt{<surname>}\index{surname=\texttt{\char'074 surname\char'076 } (element)}\index{elements:!surname=\texttt{\char'074 surname\char'076 }} elements. For a corporate author
%       (company name), use the \texttt{<orgname>}\index{orgname=\texttt{\char'074 orgname\char'076 } (element)}\index{elements:!orgname=\texttt{\char'074 orgname\char'076 }} instead of
%       \texttt{<personname>}\index{personname=\texttt{\char'074 personname\char'076 } (element)}\index{elements:!personname=\texttt{\char'074 personname\char'076 }}; if there is
%       a division or office name, put it in an
%       \texttt{<orgdiv>}\index{orgdiv=\texttt{\char'074 orgdiv\char'076 } (element)}\index{elements:!orgdiv=\texttt{\char'074 orgdiv\char'076 }} element.\par
% For multi-authored documents you
%       {\sffamily \textsc{must}} enclose
%       \emph{all} the \texttt{<author>}\index{author=\texttt{\char'074 author\char'076 } (element)}\index{elements:!author=\texttt{\char'074 author\char'076 }} elements
%       in an \texttt{<authorgroup>}\index{authorgroup=\texttt{\char'074 authorgroup\char'076 } (element)}\index{elements:!authorgroup=\texttt{\char'074 authorgroup\char'076 }} container element.\par
% An \texttt{<affiliation>}\index{affiliation=\texttt{\char'074 affiliation\char'076 } (element)}\index{elements:!affiliation=\texttt{\char'074 affiliation\char'076 }} element
%       {\sffamily \textsc{may}} be used
%       \emph{after} the \texttt{<personname>}\index{personname=\texttt{\char'074 personname\char'076 } (element)}\index{elements:!personname=\texttt{\char'074 personname\char'076 }}
%       element where it is important to identify it.\par
% The same rules apply to editors (usually only for
%       conference proceedings and books of articles by
%       different authors). These go in the monographic
%       \texttt{<biblioset>}\index{biblioset=\texttt{\char'074 biblioset\char'076 } (element)}\index{elements:!biblioset=\texttt{\char'074 biblioset\char'076 }}.  For multiple editors, enclose
%       them in an \texttt{<authorgroup>}\index{authorgroup=\texttt{\char'074 authorgroup\char'076 } (element)}\index{elements:!authorgroup=\texttt{\char'074 authorgroup\char'076 }} element — there is no
%       \texttt{<editorgroup>}\index{editorgroup=\texttt{\char'074 editorgroup\char'076 } (element)}\index{elements:!editorgroup=\texttt{\char'074 editorgroup\char'076 }} element in
%       \emph{DocBook}!\par
% \par
% \paragraph[Publication metadata]{Publication metadata :}
% There will in all cases be a \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }}
%       element in a monographic \texttt{<biblioset>}\index{biblioset=\texttt{\char'074 biblioset\char'076 } (element)}\index{elements:!biblioset=\texttt{\char'074 biblioset\char'076 }}, as
%       explained above (and maybe a \texttt{<subtitle>}\index{subtitle=\texttt{\char'074 subtitle\char'076 } (element)}\index{elements:!subtitle=\texttt{\char'074 subtitle\char'076 }} and a
%       \texttt{<titleabbrev>}\index{titleabbrev=\texttt{\char'074 titleabbrev\char'076 } (element)}\index{elements:!titleabbrev=\texttt{\char'074 titleabbrev\char'076 }}). There may also be editors, as
%       explained in \vref{authed}. Not all the other
%       metadata listed here will apply to all entries.\par
% \begin{description}[style=unboxed]
% \item[Dates:]Use the \texttt{<date>}\index{date=\texttt{\char'074 date\char'076 } (element)}\index{elements:!date=\texttt{\char'074 date\char'076 }} element but put the
%     date into the \texttt{@YYYY-MM-DD}\index{YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD} (attribute)}\index{attributes:!YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD}} attribute in
%     that format (ISO 8601 standard date with hyphens
%     separating the two-digit month and day).
%     {\sffamily \textsc{do not}} use the
%     \LaTeX{} form separating the month and the day with
%     slashes. There {\sffamily \textsc{should not}} be any text content in a
%     \texttt{<date>}\index{date=\texttt{\char'074 date\char'076 } (element)}\index{elements:!date=\texttt{\char'074 date\char'076 }} element (it will be ignored). If
%     an exact date is not available, use the year and
%     give the month if known, or 12 for December and 31
%     fyor the day: it
%     {\sffamily \textsc{must}} still be a
%     valid ISO 8601 date.\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily
% The \texttt{@YYYY-MM-DD}\index{YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD} (attribute)}\index{attributes:!YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD}}
%       attribute is an addition in
%       \emph{ClassPack} as
%       described in item~\ref{yyyy-mm-dd} in the list on p.\thinspace\pageref{yyyy-mm-dd}, and
%       is not standard
%       \emph{DocBook}.\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% \item[Publisher:]Use the \texttt{<publisher>}\index{publisher=\texttt{\char'074 publisher\char'076 } (element)}\index{elements:!publisher=\texttt{\char'074 publisher\char'076 }} element with the
%     sub-elements \texttt{<publishername>}\index{publishername=\texttt{\char'074 publishername\char'076 } (element)}\index{elements:!publishername=\texttt{\char'074 publishername\char'076 }} for the name
%     and \texttt{<address>}\index{address=\texttt{\char'074 address\char'076 } (element)}\index{elements:!address=\texttt{\char'074 address\char'076 }} for the location. The
%     address is normally just the city (and state or
%     country if needed).\par
% \item[Other organisations:]Where there is no formal publisher, but the
%     document is issued by or obtainable from an
%     institution or organisation (as for example with a
%     thesis or report), use the \texttt{<org>}\index{org=\texttt{\char'074 org\char'076 } (element)}\index{elements:!org=\texttt{\char'074 org\char'076 }} element with the
%     sub-elements \texttt{<orgname>}\index{orgname=\texttt{\char'074 orgname\char'076 } (element)}\index{elements:!orgname=\texttt{\char'074 orgname\char'076 }} for the name,
%     \texttt{<orgdiv>}\index{orgdiv=\texttt{\char'074 orgdiv\char'076 } (element)}\index{elements:!orgdiv=\texttt{\char'074 orgdiv\char'076 }} for the division or section, and
%     \texttt{<address>}\index{address=\texttt{\char'074 address\char'076 } (element)}\index{elements:!address=\texttt{\char'074 address\char'076 }} for the location (same rule as
%     for Publisher above).\par
% This is also suitable for the informal
%     publication of web pages such as personal blogs,
%     giving the hosting provider if the site is not the
%     owner’s own host.\par
% \item[Edition:]Use the \texttt{<edition>}\index{edition=\texttt{\char'074 edition\char'076 } (element)}\index{elements:!edition=\texttt{\char'074 edition\char'076 }} element and give the
%     cardinal number (eg 1, 2, 3),
%     \emph{not} the ordinal (1st, 2nd,
%     3rd).\par
% \item[Volume and issue numbers:]Use \texttt{<volumenum>}\index{volumenum=\texttt{\char'074 volumenum\char'076 } (element)}\index{elements:!volumenum=\texttt{\char'074 volumenum\char'076 }} and
%     \texttt{<issuenum>}\index{issuenum=\texttt{\char'074 issuenum\char'076 } (element)}\index{elements:!issuenum=\texttt{\char'074 issuenum\char'076 }} for the volume and issue of
%     journal articles.\par
% Where an item has a number that is not a
%     volume or issue, such as with a report, use the
%     \texttt{<biblioid>}\index{biblioid=\texttt{\char'074 biblioid\char'076 } (element)}\index{elements:!biblioid=\texttt{\char'074 biblioid\char'076 }} element described in
%     ‘\textbf{\textsf{Identity}}’, the last item in this list.\par
% \item[Page numbers:]For the page number or range of pages for an
%     article or chapter, use \texttt{<artpagenums>}\index{artpagenums=\texttt{\char'074 artpagenums\char'076 } (element)}\index{elements:!artpagenums=\texttt{\char'074 artpagenums\char'076 }} in
%     the analytic \texttt{<biblioset>}\index{biblioset=\texttt{\char'074 biblioset\char'076 } (element)}\index{elements:!biblioset=\texttt{\char'074 biblioset\char'076 }}.\par
% For the page count (total number of pages in a
%     book), use \texttt{<pagenums>}\index{pagenums=\texttt{\char'074 pagenums\char'076 } (element)}\index{elements:!pagenums=\texttt{\char'074 pagenums\char'076 }} in the monographic
%     \texttt{<biblioset>}\index{biblioset=\texttt{\char'074 biblioset\char'076 } (element)}\index{elements:!biblioset=\texttt{\char'074 biblioset\char'076 }}.\par
% \item[Identity:]\label{bibident}For official numbering schemes (eg
%     \textsc{isbn}, \textsc{issn},
%     \textsc{doi}, etc), and for
%     \textsc{uri}s and in-house numbering
%     schemes, use the \texttt{<biblioid>}\index{biblioid=\texttt{\char'074 biblioid\char'076 } (element)}\index{elements:!biblioid=\texttt{\char'074 biblioid\char'076 }} element and
%     set the \texttt{@class}\index{class=\texttt{\char'100 class} (attribute)}\index{attributes:!class=\texttt{\char'100 class}}
%     attribute appropriately.\par
% If there is no appropriate value for the \texttt{@class}\index{class=\texttt{\char'100 class} (attribute)}\index{attributes:!class=\texttt{\char'100 class}} attribute, use
%     \texttt{"other"}\index{other=\texttt{"other"} (attribute value)}\index{attribute values:!other=\texttt{"other"}} and set the
%     \texttt{<otherclass>}\index{otherclass=\texttt{\char'074 otherclass\char'076 } (element)}\index{elements:!otherclass=\texttt{\char'074 otherclass\char'076 }} to a suitable value of your
%     own.\par
% For online resources (eg \texttt{"uri"}\index{uri=\texttt{"uri"} (attribute value)}\index{attribute values:!uri=\texttt{"uri"}}), set the \texttt{@YYYY-MM-DD}\index{YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD} (attribute)}\index{attributes:!YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD}} attribute to
%     the date when you retrieved or downloaded the page
%     or document.\par
% \end{description}
% \paragraph[Conference metadata]{Conference metadata :}
% Conference information is slightly different from
%       other types of publication. It
%       {\sffamily \textsc{must}} all be contained
%       within a \texttt{<confgroup>}\index{confgroup=\texttt{\char'074 confgroup\char'076 } (element)}\index{elements:!confgroup=\texttt{\char'074 confgroup\char'076 }} element.\par
% \begin{description}[style=unboxed]
% \item[Conference title (name):]Conference titles may range from simple
%     abbreviations or single words (often including the
%     year) up to entire sentences several lines long.
%     In \emph{Classpack}
%     processing, the \BibTeX{} field value is prefixed
%     automatically with `In
%       Proc.' (proceedings), so you
%     {\sffamily \textsc{must not}} include
%     those words in the title.\par
% If the \texttt{<confnum>}\index{confnum=\texttt{\char'074 confnum\char'076 } (element)}\index{elements:!confnum=\texttt{\char'074 confnum\char'076 }} element is present
%     (see below), any year value at the start or end of
%     the title (eg \texttt{"2014 EPDIC"}\index{2014 EPDIC=\texttt{"2014 EPDIC"} (attribute value)}\index{attribute values:!2014 EPDIC=\texttt{"2014 EPDIC"}} or \texttt{"TUG’95"}\index{TUG’95=\texttt{"TUG’95"} (attribute value)}\index{attribute values:!TUG’95=\texttt{"TUG’95"}}) is removed by
%     \emph{ClassPack} and
%     replaced with the full year or sequence value from
%     the \texttt{<confnum>}\index{confnum=\texttt{\char'074 confnum\char'076 } (element)}\index{elements:!confnum=\texttt{\char'074 confnum\char'076 }} element.\par
% \item[Conference sponsor:]A sponsor name in the \texttt{<confsponsor>}\index{confsponsor=\texttt{\char'074 confsponsor\char'076 } (element)}\index{elements:!confsponsor=\texttt{\char'074 confsponsor\char'076 }}
%     element is assumed to be the hosting
%     organisation, and the value is passed to the
%     \texttt{organisation} \BibTeX{}
%     field.\par
% \item[Conference number:]The \texttt{<confnum>}\index{confnum=\texttt{\char'074 confnum\char'076 } (element)}\index{elements:!confnum=\texttt{\char'074 confnum\char'076 }} element
%     {\sffamily \textsc{may}} contain either a
%     year or a sequence value;
% \item[Conference dates:]The date attributes for the
%     \texttt{<confdates>}\index{confdates=\texttt{\char'074 confdates\char'076 } (element)}\index{elements:!confdates=\texttt{\char'074 confdates\char'076 }} element are
%     \emph{different} from the normal
%     \texttt{@YYYY-MM-DD}\index{YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD} (attribute)}\index{attributes:!YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD}} found on
%     other dates. Instead there are two: \texttt{@YYYY-MM-DD-from}\index{YYYY-MM-DD-from=\texttt{\char'100 YYYY-MM-DD-from} (attribute)}\index{attributes:!YYYY-MM-DD-from=\texttt{\char'100 YYYY-MM-DD-from}} and \texttt{@YYYY-MM-DD-to}\index{YYYY-MM-DD-to=\texttt{\char'100 YYYY-MM-DD-to} (attribute)}\index{attributes:!YYYY-MM-DD-to=\texttt{\char'100 YYYY-MM-DD-to}} for the
%     begin and end dates. Both
%     {\sffamily \textsc{must}} be ISO 8601
%     dates. The element is \texttt{EMPTY}\index{EMPTY=\texttt{EMPTY} (local name)}\index{local names:!EMPTY=\texttt{EMPTY}} (any
%     content is ignored).\par
% \item[Conference location:]Use the \texttt{<address>}\index{address=\texttt{\char'074 address\char'076 } (element)}\index{elements:!address=\texttt{\char'074 address\char'076 }} element.\par
% \end{description}
% \clearpage
% \section{Producing your class or package}\label{production}
% At the simplest level, the {\ttfamily{}.dtx} and
% {\ttfamily{}.ins} files (and any ancillary files
% specified) can be generated by running the
% \emph{db2dtx.xsl} script on your
% \emph{ClassPack} \textsc{xml}
% document, using Java and Saxon with a command such as the one
% given below, substituting the name of your package or class
% file and the paths to your package or class and to
% \emph{ClassPack}’s \textsc{xslt}
% program and files. It could equally well be done using the
% built-in \textsc{api} in many \textsc{xml}
% editors such as \emph{oXygen}.\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language=bash,emphstyle=\itshape,emph={mypackage,path,to,classpack}]
java -Djdk.xml.entityExpansionLimit=0 \
     -jar saxon9he.jar \
     -xi:on \
     -s:mypackage.xml \
     -o:mypackage.dtx \
     -dtd:on \
     -xsl:db2dtx.xsl \
     appdir=/path/to/mypackage \
     cpdir=/path/to/classpack
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% As mentioned in the note in \vref{dirnames}, you
% {\sffamily \textsc{must}} keep each class or
% package you manage in separate directories, named after the
% class or package, and that name must also be the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} value of the root element
% of the document.\par
% \subsection{Maintaining your class or package}\label{maintenance}
% The things to check each time you make an update
%   are:\par
% \begin{enumerate}
% \item update the \texttt{@version}\index{version=\texttt{\char'100 version} (attribute)}\index{attributes:!version=\texttt{\char'100 version}} and
%       \texttt{@revision}\index{revision=\texttt{\char'100 revision} (attribute)}\index{attributes:!revision=\texttt{\char'100 revision}} attributes on the
%       \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} root element;
% \item add a new \texttt{<revision>}\index{revision=\texttt{\char'074 revision\char'076 } (element)}\index{elements:!revision=\texttt{\char'074 revision\char'076 }} element in the
%       \texttt{<revhistory>}\index{revhistory=\texttt{\char'074 revhistory\char'076 } (element)}\index{elements:!revhistory=\texttt{\char'074 revhistory\char'076 }}, setting the \texttt{@version}\index{version=\texttt{\char'100 version} (attribute)}\index{attributes:!version=\texttt{\char'100 version}} attribute to the
%       compound of the version and revision specified above,
%       and setting the \texttt{<date>}\index{date=\texttt{\char'074 date\char'076 } (element)}\index{elements:!date=\texttt{\char'074 date\char'076 }} subelement’s \texttt{@YYYY-MM-DD}\index{YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD} (attribute)}\index{attributes:!YYYY-MM-DD=\texttt{\char'100 YYYY-MM-DD}} attribute to
%       today’s date in ISO format;
% \item after processing the document once, set the
%       \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} root element’s \texttt{@security}\index{security=\texttt{\char'100 security} (attribute)}\index{attributes:!security=\texttt{\char'100 security}} attribute to the
%       checksum displayed by \LaTeX{};
% \item process the document again and the security checksum
%       should now match.
% \end{enumerate}
% \nocite{*}
% \clearpage
% \raggedright
% \RaggedRight\markboth{\refname}{\refname}\printbibliography[heading=shortbib]\clearpage
% \StopEventually{\label{endcode}%
%   \clearpage
%   \addcontentsline{toc}{section}{Change History}%
%   \label{changehistory}%
%   \PrintChanges
%   \clearpage
%   \label{codeindex}%
%   \addcontentsline{toc}{section}{Index}%
%   \PrintIndex}
% \clearpage\subsection*{Code for the Package code for supporting
%       \emph{ClassPack} documentation}
% \iffalse
%<*package>
% \fi
% \section{The \textsf{classpack} macros and
% settings}\label{pkgmacros}
% \iffalse
%% 
%% The _classpack_ macros and settings
% \fi
% \subsection{Auto-initialisation}\label{pkgmacros:autoinit}
% This section is added automatically by \textit{ClassPack} 
% as a preamble to all classes and style packages.
% For details see the \textsf{ltxdoc} package documentation.
% \par\smallskip
% 
% \begingroup\color{DarkRed}\footnotesize
% \leavevmode\enspace{\scriptsize1}\quad{\ttfamily\textbackslash NeedsTeXFormat\{LaTeX2e\}[2015/01/01]}\\
% \leavevmode\enspace{\scriptsize2}\quad{\ttfamily\textbackslash ProvidesPackage\{classpack\}[2024/02/21 v1.28}\\
% \leavevmode\enspace{\scriptsize3}\qquad{\ttfamily Package code for supporting ClassPack documentation]}\\\endgroup
% \setcounter{CodelineNo}{3}
%\iffalse
%%
%% Packages required for the package
%% 
% \fi
% \subsection{Packages required for the
%     \textsf{classpack} package itself (used
%     \emph{only} when producing documentation for
%     packages authored using
%     \emph{ClassPack})}\label{stypackages}
% Packages required for operation:
% \begin{CPKpackage}{noto}
% Sets the Google NoTo typeface as the default.
% \iffalse
%% Sets the Google NoTo typeface as the default.
% \fi
%    \begin{macrocode}
\RequirePackage{noto}%
%    \end{macrocode}
% \end{CPKpackage}
% \begin{CPKpackage}{fancyhdr}
% Provide for running headers and footers.
% \iffalse
%% Provide for running headers and footers.
% \fi
%    \begin{macrocode}
\RequirePackage{fancyhdr}%
%    \end{macrocode}
% \end{CPKpackage}
% \begin{CPKpackage}{ltxcmds}
% Some \LaTeX{} kernel commands for general use, 
% but in the case of \emph{ClassPack},
% particularly
% {\ttfamily{}\textbackslash{}ltx@ifpackageloaded}.
% \iffalse
%% Some \LaTeX{} kernel commands for general use, but in the case of ClassPack, particularly ltx@ifpackageloaded.
% \fi
%    \begin{macrocode}
\RequirePackage{ltxcmds}%
%    \end{macrocode}
% Define the ltx@ifpackageloaded command.
%    \begin{macrocode}
\ifdefined\IfPackageLoaded\relax
  \else\newcommand{\IfPackageLoaded}[3]{%
    \ltx@ifpackageloaded{#1}{#2}{#3}}\fi
%    \end{macrocode}
% \end{CPKpackage}
% \begin{CPKpackage}{parskip}
% Creates paragraphs separated by white-space with no
% indentation.
% \iffalse
%% Creates paragraphs separated by white-space with no indentation.
% \fi
%    \begin{macrocode}
\RequirePackage{parskip}%
%    \end{macrocode}
% \end{CPKpackage}
% \begin{CPKpackage}{graphicx}
% Provide for graphics (PNG, JPG, or PDF format (only) for
% pdflatex; EPS format (only) for standard \LaTeX{}); and for 
% reflection and rotation features.
% \iffalse
%% Provide for graphics (PNG, JPG, or PDF format (only) for pdflatex; EPS format (only) for standard \LaTeX{}); and for reflection and rotation features.
% \fi
%    \begin{macrocode}
\RequirePackage{graphicx}%
%    \end{macrocode}
% \end{CPKpackage}
% \begin{CPKpackage}{marginnote}
% Adds more flexibility to marginal notes.
% \iffalse
%% Adds more flexibility to marginal notes.
% \fi
%    \begin{macrocode}
\RequirePackage[fulladjust,quiet]{marginnote}%
%    \end{macrocode}
% \end{CPKpackage}
% 
% \subsection{Index settings}\label{index}
% \iffalse
%% 
%% ****************************************************************** 
%% 
%% Index settings
% \fi
% \begin{CPKcounter}{IndexColumns}\label{counter--IndexColumns1}
% The \textsf{doctex} package uses a default
%     three-column index for the documentation, which is too
%     narrow for most purposes. We therefore make the index in
%     two columns, and space them slightly farther apart. We
%     test first for the existence of the counter, in case this
%     gets used in a document other than a
%     {\ttfamily{}.dtx} file. No such test is needed for
%     \DescribeLength{columnsep}{\ttfamily{}\textbackslash{}columnsep} because it is
%     defined in the \LaTeX{} kernel.\par
% \iffalse
%% 
%% The _doctex_ package uses a default three-column index for the documentation, which is too narrow for most purposes. We therefore make the index in two columns, and space them slightly farther apart. We test first for the existence of the counter, in case this gets used in a document other than a `.dtx` file. No such test is needed for `columnsep` because it is defined in the LaTeX kernel.
% \fi
%    \begin{macrocode}
\@ifundefined{c@IndexColumns}{}{\setcounter{IndexColumns}{2}}
\setlength{\columnsep}{3pc}
%    \end{macrocode}
% \end{CPKcounter}
% \subsection{Annotation settings}\label{annset}
% \iffalse
%% 
%% ****************************************************************** 
%% 
%% Annotation settings
% \fi
% \begin{CPKmacro}{\MacroFont}\label{macro--MacroFont}
% The \textsf{doc} and \textsf{docx}
%     packages use the {\ttfamily{}\textbackslash{}MacroFont} command for
%     the annotated code. We redefine it
%     here to add the colour DarkBlue (from the
%     \textbf{\texttt{svgnames}} option to the
%     \textsf{xcolor} package).\par
% \iffalse
%% 
%% The _doc_ and _docx_ packages use the `\MacroFont` command for the annotated code. We redefine it here to add the colour DarkBlue (from the **`svgnames`** option to the _xcolor_ package).
% \fi
%    \begin{macrocode}
\def\MacroFont{%\fontencoding\encodingdefault
  \ttfamily\fontseries{m}\fontshape\updefault
  \small\selectfont\color{DarkBlue}}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKlength}{CPKannotationindent}\label{length--CPKannotationindent}
% Where an annotation occurs inside an indented
%     container like a list, provide for some additional
%     indentation.\par
% \iffalse
%% 
%% Where an annotation occurs inside an indented container like a list, provide for some additional indentation.
% \fi
%    \begin{macrocode}
\newlength{\CPKannotationindent}
\setlength{\CPKannotationindent}{0pt}
%    \end{macrocode}
% \end{CPKlength}
% \begin{CPKmacro}{\CPKrunningecho}\label{macro--CPKrunningecho}
% This allows alignment of the current annotation name
%     (from \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}}) as a
%     reminder in a marginal note in a fake subheading
%     implemented by a \texttt{<bridgehead>}\index{bridgehead=\texttt{\char'074 bridgehead\char'076 } (element)}\index{elements:!bridgehead=\texttt{\char'074 bridgehead\char'076 }} element. Again, no
%     at-sign for a user-mode command.\par
% \iffalse
%% 
%% This allows alignment of the current annotation name (from `xreflabel`) as a reminder in a marginal note in a fake subheading implemented by a `bridgehead` element. Again, no at-sign for a user-mode command.
% \fi
%    \begin{macrocode}
\newcommand{\CPKrunningecho}[1]{\leavevmode
  \marginnote[\sloppy\raggedleft\color{Grey}%
              \hspace{0pt}\LabelFont{#1}]%
             {\sloppy\raggedright\color{Grey}%
              \hspace{0pt}\LabelFont{#1}}%
}
\let\marginfont\ttfamily
%    \end{macrocode}
% \end{CPKmacro}
% \subsection{Table of Contents}
% \iffalse
%% 
%% ****************************************************************** 
%% 
%% Table of Contents
% \fi
% \begin{CPKmacro}{\l@subsection}\label{macro--l@subsection}
% Documentation can sometimes have more than nine
%     subdivisions in sections, subsections, etc, and over 99
%     pages; and the default widths in the ToC are too narrow
%     for this, so we widen the space for the subsection number
%     by 0.4em:\par
% \iffalse
%% 
%% Documentation can sometimes have more than nine subdivisions in sections, subsections, etc, and over 99 pages; and the default widths in the ToC are too narrow for this, so we widen the space for the subsection number by 0.4em:
% \fi
%    \begin{macrocode}
\renewcommand*\l@subsection{%
  \@dottedtocline{2}{1.5em}{2.7em}}% was {2}{3.8em}{3.2em}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\l@subsubsection}\label{macro--l@subsubsection}
% Similarly we increase the subsection number space by
%     0.4em, and its margin, so they align:\par
% \iffalse
%% 
%% Similarly we increase the subsection number space by 0.4em, and its margin, so they align:
% \fi
%    \begin{macrocode}
\renewcommand*\l@subsubsection{%
  \@dottedtocline{3}{4.2em}{3.6em}}% was {3}{7.0em}{4.1em}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\l@paragraph}\label{macro--l@paragraph}
% And lastly, the numbered paragraph and numbered
%     subparagraph number spaces:\par
% \iffalse
%% 
%% And lastly, the numbered paragraph and numbered subparagraph number spaces:
% \fi
%    \begin{macrocode}
\renewcommand*\l@paragraph{%
  \@dottedtocline{4}{7.8em}{4.5em}}% was {4}{10em}{5em}
\renewcommand*\l@subparagraph{%
  \@dottedtocline{5}{12.2em}{5em}}% was {5}{12em}{6em}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\@pnumwidth}\label{macro--@pnumwidth}
% The page number width is set to 3em instead of 1.55em:\par
% \iffalse
%% 
%% The page number width is set to 3em instead of 1.55em:
% \fi
%    \begin{macrocode}
\renewcommand{\@pnumwidth}{3em}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\@tocrmarg}\label{macro--@tocrmarg}
% And the right margin space goes up from 2.55em to 3em;
%   the addition of 1fil makes the section titles typeset
%   raggedright, so that hyphenation will not occur.\par
% \iffalse
%% 
%% And the right margin space goes up from 2.55em to 3em; the addition of 1fil makes the section titles typeset raggedright, so that hyphenation will not occur.
% \fi
%    \begin{macrocode}
\renewcommand{\@tocrmarg}{4em plus1fil}
%    \end{macrocode}
% \end{CPKmacro}
% \subsection{Lower-level sectioning}
% \iffalse
%% 
%% ****************************************************************** 
%% 
%% Lower-level sectioning
% \fi
% \begin{CPKmacro}{\subsubsection}\label{macro--subsubsection}
% The {\ttfamily{}\textbackslash{}subsubsection} command is used
%     in bridgehead mode, so needs less space above and
%     below.\par
% \iffalse
%% 
%% The `\subsubsection` command is used in bridgehead mode, so needs less space above and below.
% \fi
%    \begin{macrocode}
\renewcommand\subsubsection{%
  \@startsection{subsubsection}{3}{\z@}%
    {-1ex\@plus -.25ex \@minus -.25ex}%
    {1ex \@plus .25ex}%
    {\sffamily\normalsize\bfseries}}
%    \end{macrocode}
% \end{CPKmacro}
% \subsection{Appendix settings}
% \iffalse
%% 
%% ****************************************************************** 
%% 
%% Appendix settings
% \fi
% \begin{CPKmacro}{\appendix}\label{macro--appendix}
% Change the way the appendix command works so that
%     appendixes get section-type styling in documentation.\par
% \iffalse
%% 
%% Change the way the appendix command works so that appendixes get section-type styling in documentation.
% \fi
%    \begin{macrocode}
\renewcommand\appendix{\par
  \setcounter{section}{0}%
  \setcounter{subsection}{0}%
  \gdef\thesection{\@Alph\c@section}}
%    \end{macrocode}
% \end{CPKmacro}
% \subsection{\TeX{} and other logos}
% \iffalse
%% 
%% ****************************************************************** 
%% 
%% TeX and other logos
% \fi
% \TeX{} and \LaTeX{} are defined in the \LaTeX{} kernel, but
%   most of the others are not. The following definitions are
%   taken from the \textsf{ltugboat} package, used for
%   typesetting the TUGboat journal.\par
% \iffalse
%% 
%% TeX and LaTeX are defined in the LaTeX kernel, but most of the others are not. The following definitions are taken from the _ltugboat_ package, used for typesetting the TUGboat journal.
% \fi
% \begin{CPKmacro}{\ConTeXt}\label{macro--ConTeXt}
% Con\TeX t{} is a typography and typesetting system meant
%     to provide users easy and consistent access to advanced
%     typographical control \parencite{wp-context}.\par
% \iffalse
%% 
%% Con\TeX t{} is a typography and typesetting system meant to provide users easy and consistent access to advanced typographical control (Hagen, 2001).
% \fi
%    \begin{macrocode}
\def\ConTeXt{C\kern-.0333emon\-\kern-.0667em\TeX
  \kern-.0333emt}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\tubreflect}\label{macro--tubreflect}
% Borrow the reflection code from TUGboat.\par
% \iffalse
%% 
%% Borrow the reflection code from TUGboat.
% \fi
%    \begin{macrocode}
\def\tubreflect#1{%
  \@ifundefined{reflectbox}{%
    \PackageError{classpack}%
      {A graphics package must be loaded for \string\XeTeX}%
      {Add the graphicx package to your Preamble}%
  }{% otherwise OK
    \ifdim \fontdimen1\font>0pt
      \raise 1.75ex \hbox{\kern.1em
        \rotatebox{180}{#1}}\kern-.1em
    \else
      \reflectbox{#1}%
    \fi
  }%
}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\tubhideheight}\label{macro--tubhideheight}
% Borrow the method of hiding the height from TUGboat
%     as well.\par
% \iffalse
%% 
%% Borrow the method of hiding the height from TUGboat as well.
% \fi
%    \begin{macrocode}
\def\tubhideheight#1{\setbox0=\hbox{#1}%
  \ht0=0pt \dp0=0pt \box0 }
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\XeTeX}\label{macro--XeTeX}
% Start by defining the first part of \XeTeX{} and
%     \XeLaTeX{}.\par
% \iffalse
%% 
%% Start by defining the first part of XeTeX and XeLaTeX.
% \fi
%    \begin{macrocode}
\DeclareRobustCommand\Xe[1]{\leavevmode
  \tubhideheight{\hbox{X%
    \setbox0=\hbox{\TeX}\setbox1=\hbox{E}%
    \lower\dp0\hbox{\raise\dp1\hbox{%
      \kern-.125em\tubreflect{E}}}%
    \kern-.1667em #1}}}
\def\XeTeX{\Xe\TeX}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\XeLaTeX}\label{macro--XeLaTeX}
% Define \XeLaTeX{} using the existing macros.\par
% \iffalse
%% 
%% Define XeLaTeX using the existing macros.
% \fi
%    \begin{macrocode}
\def\XeLaTeX{\Xe{\,\LaTeX}}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\LyX}\label{macro--LyX}
% Define the \LyX{} logo.\par
% \iffalse
%% 
%% Define the LyX logo.
% \fi
%    \begin{macrocode}
\def\LyX{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\SMC}\label{macro--SMC}
% Define a new small caps for use in \BibTeX{}, and an
%     error message to go with it (from the
%     \textsf{ltugboat} package).\par
% \iffalse
%% 
%% Define a new small caps for use in BiBTeX, and an error message to go with it (from the _ltugboat_ package).
% \fi
%    \begin{macrocode}
\DeclareRobustCommand\SMC{%
  \ifx\@currsize\normalsize\small\else
   \ifx\@currsize\small\footnotesize\else
    \ifx\@currsize\footnotesize\scriptsize\else
     \ifx\@currsize\large\normalsize\else
      \ifx\@currsize\Large\large\else
       \ifx\@currsize\LARGE\Large\else
        \ifx\@currsize\scriptsize\tiny\else
         \ifx\@currsize\tiny\tiny\else
          \ifx\@currsize\huge\LARGE\else
           \ifx\@currsize\Huge\huge\else
            \small\SMC@unknown@warning
 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
}
\newcommand\SMC@unknown@warning{\PackageError{classpack}%
  {\string\SMC: can't find small caps for nonstandard 
  text font size command -- using \string\small}%
  {Check the font size or scaling for \the\@currsize}}
\newcommand\textSMC[1]{{\SMC #1}}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\BIBTeX}\label{macro--BIBTeX}
% Finally, define \BibTeX{} in various forms.\par
% \iffalse
%% 
%% Finally, define BiBTeX in various forms.
% \fi
%    \begin{macrocode}
	    \def\Bib{%
  \ifdim \fontdimen1\font>0pt
     B{\SMC\SMC IB}%
  \else
     \textsc{Bib}%
  \fi
}
\def\BibTeX{\Bib\kern-.08em \TeX}
\let\BiBTeX\BibTeX
\let\BIBTeX\BibTeX
%    \end{macrocode}
% \end{CPKmacro}
% \par\begingroup
%   \fboxsep1em\centering
%   \fbox{\begin{minipage}{0.8\columnwidth}\sffamily
%  \raggedright\parindent0pt
%  \parskip=.5\baselineskip
% \subsubsection*{\sffamily The \textsf{flexlogo} package}
% The \textsf{flexlogo} package (under
%   development) will make this section obsolete, as it allows
%   for the complete redefining of the \TeX{}, \LaTeX{}, and
%   related logos for non-CM fonts.\par
% \end{minipage}}\par\endgroup
% \subsection{Formatting additions}
% \iffalse
%% 
%% ****************************************************************** 
%% 
%% Formatting additions
% \fi
% \begin{CPKmacro}{\CPKvstrut}\label{macro--CPKvstrut}
% Define a strut that adjusts to the size of type, for
%   use in spacing table headers and footers.\par
% \iffalse
%% 
%% Define a strut that adjusts to the size of type, for use in spacing table headers and footers.
% \fi
%    \begin{macrocode}
\newcommand{\CPKvstrut}{\vrule height1.2em 
                        depth.6667ex width0pt}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\CPKmenusep}\label{macro--CPKmenusep}
% Define a macro to format an arrow between documentary
%     menu items. Probably no longer needed now that the
%     \textsf{menukeys} package is available\par
% \iffalse
%% 
%% Define a macro to format an arrow between documentary menu items. Probably no longer needed now that the _menukeys_ package is available
% \fi
%    \begin{macrocode}
\def\CPKmenusep{\thinspace$\rightarrow$\thinspace
                \allowbreak}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\CPKprestrut}\label{macro--CPKprestrut}
% Also a strut to precede paragraph cells\dots{}\par
% \iffalse
%% 
%% Also a strut to precede paragraph cells\dots{}
% \fi
%    \begin{macrocode}
\newcommand{\CPKprestrut}{\vrule height1em width0pt}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\CPKpoststrut}\label{macro--CPKpoststrut}
% \dots{}and one to follow them.\par
% \iffalse
%% 
%% \dots{}and one to follow them.
% \fi
%    \begin{macrocode}
\newcommand{\CPKpoststrut}{\vrule depth.5ex width0pt}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\hrule}\label{macro--hrule}
% Give the {\ttfamily{}\textbackslash{}hline} command an optional
%   thickness (height) argument.\par
% \iffalse
%% 
%% Give the `\hline` command an optional thickness (height) argument.
% \fi
%    \begin{macrocode}
\def\hline{\noalign{\ifnum0=`}\fi
  \@ifnextchar[{\@@hline}{\@@hline[\arrayrulewidth]}}
\def\@@hline[#1]{\hrule \@height#1 \futurelet
  \reserved@a\@xhline}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKcounter}{secnumdepth}\label{counter--secnumdepth}
%    \begin{macrocode}
\setcounter{secnumdepth}{5}
%    \end{macrocode}
% \end{CPKcounter}
% \begin{CPKcounter}{tocdepth}\label{counter--tocdepth}
%    \begin{macrocode}
\setcounter{tocdepth}{5}
%    \end{macrocode}
% \end{CPKcounter}
% \begin{CPKcounter}{IndexColumns}\label{counter--IndexColumns2}
%    \begin{macrocode}
\@ifundefined{c@IndexColumns}{}{\setcounter{IndexColumns}{2}}
%    \end{macrocode}
% \end{CPKcounter}
% \begin{CPKlength}{columnsep}\label{length--columnsep}
%    \begin{macrocode}
\setlength{\columnsep}{3pc}
%    \end{macrocode}
% \end{CPKlength}
% \begin{CPKlength}{CPKtabwid}\label{length--CPKtabwid}
% Measurement of table width, to allow for notes (see
%     {\ttfamily{}figtab2latex.xsl}).\par
% \iffalse
%% 
%% Measurement of table width, to allow for notes (see `figtab2latex.xsl`).
% \fi
%    \begin{macrocode}
\newlength{\CPKtabwid}
%    \end{macrocode}
% \end{CPKlength}
% \begin{CPKcounter}{CPKfnote}\label{counter--CPKfnote}
% Define a counter for left-hang notes.\par
% \iffalse
%% 
%% Define a counter for left-hang notes.
% \fi
%    \begin{macrocode}
\newcounter{CPKfnote}
%    \end{macrocode}
% \end{CPKcounter}
% \begin{CPKmacro}{\fnote}\label{macro--fnote}
% Define a left-hang note to protrude into the left
%   space beside a table cell with an italic number.\par
% \iffalse
%% 
%% Define a left-hang note to protrude into the left space beside a table cell with an italic number.
% \fi
%    \begin{macrocode}
\newcommand{\fnote}{%
  \stepcounter{CPKfnote}\llap{%
    \footnotesize\textsuperscript{%
      \itshape\alph{CPKfnote}\upshape)}\thinspace}}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\hyphenation}\label{macro--hyphenation}
% Add some hyphenation oddities.\par
% \iffalse
%% 
%% Add some hyphenation oddities.
% \fi
%    \begin{macrocode}
\hyphenation{ele-ment ele-ments attri-bute attri-butes 
  docu-ment docu-ments docu-men-tation primi-tive 
  primi-tives name-space name-spaces helico-pter}
%    \end{macrocode}
% \end{CPKmacro}
% \begin{CPKmacro}{\descriptionlabel}\label{macro--descriptionlabel}
% This has been replaced by the
%     \textsf{enumitem} package as specified in
%     {\ttfamily{}prepost.xml}\thinspace.\par
% \iffalse
%% 
%% This has been replaced by the _enumitem_ package as specified in `prepost.xml`.
% \fi
% \end{CPKmacro}
% \begin{CPKcounter}{CPKcoref}\label{counter--CPKcoref}
% Add the counter to enable the use of \texttt{<coref>}\index{coref=\texttt{\char'074 coref\char'076 } (element)}\index{elements:!coref=\texttt{\char'074 coref\char'076 }}
%     list counters in generated code.\par
% \iffalse
%% 
%% Add the counter to enable the use of `coref` list counters in generated code.
% \fi
%    \begin{macrocode}
\newcounter{CPKcoref}
%    \end{macrocode}
% \end{CPKcounter}
% An {\ttfamily{}\textbackslash{}endinput} command is automatically
%   appended to this file.\par
% \iffalse
%% 
%% An `\endinput` command is automatically appended to this file.
% \fi
% \iffalse
%</package>
% \fi
% \iffalse
%<*cpdtddoc>
% \fi
% \clearpage
% \section{DocBook DTD shim}\label{cpdtddoc}
% \setcounter{CodelineNo}{0}
% This is a customisation layer (shim) for the
% \emph{DocBook5} \textsc{dtd}\index{DTD}.
% There are no changes to the element structure, only the
% addition or modification of attributes. The availability of
% \texttt{<html:form>}\index{html:form=\texttt{\char'074 html:form\char'076 } (element)}\index{elements:!html:form=\texttt{\char'074 html:form\char'076 }} is closed off by declaring it
% {\ttfamily{}EMPTY}\thinspace.\par
% This file is in effect a driver, allowing the
% predeclaration of values \emph{before} the main
% \textsc{dtd}\index{DTD} is read; under the rules of
% \textsc{iso} 8859 inherited by
% \textsc{xml}, this prevents those declarations from
% being subsequently overwritten when the main file is
% loaded.\par
% \par\begingroup
%   \fboxsep1em\centering
%   \fbox{\begin{minipage}{0.8\columnwidth}\sffamily
%  \raggedright\parindent0pt
%  \parskip=.5\baselineskip
% This will at some stage be replaced by a formal
%   modification layer to the \textsc{rng} version of
%   DocBook.\par
% \end{minipage}}\par\endgroup
% \begin{CPKcomment}{cpdtddoc-comment}\label{comment-cpdtddoc}
% Identify the file origin,
% date, time, etc.\par
%    \begin{macrocode}
<!-- DocBook DTD shim (from the classpack package v.1.28, 2024-02-21) -->
<!-- Generated by ClassPack v.1.28 (2024-02-21) on 24-03-04T22:35:19 -->
%    \end{macrocode}
% These lines are automatically prepended to the file
% and may be removed if necessary,
% using a suitable editor.
% \end{CPKcomment}
% \subsection{Set up the invocation and disable HTML forms}
% \begin{CPKentity}{db5dtd}\label{entity-doctexbook-db5dtd}
% Create a Parameter
%               Entity\phantomsection\label{PE} ({\small\raisebox{-.5ex}{\textcolor{Red}{\HandRight}}}\textsc{pe})\index{Parameter Entity|see{PE}}\index{PE|textbf} by which we can invoke the
%             \textsc{dtd}\index{DTD} at the end.\par
%    \begin{macrocode}
<!ENTITY % db5dtd SYSTEM
         "/dtds/docbook/docbook-5.0/dtd/docbook.dtd">
%    \end{macrocode}
% \end{CPKentity}
% \begin{CPKdtd}{html}\label{dtd-doctexbook-html}
% Nullify the \textsc{html}\index{HTML} \texttt{<form>}\index{form=\texttt{\char'074 form\char'076 } (element)}\index{elements:!form=\texttt{\char'074 form\char'076 }}.\par
%    \begin{macrocode}
<!ELEMENT html:form EMPTY>
%    \end{macrocode}
% \end{CPKdtd}
% \begin{CPKtemplate}{info}\label{template-doctexbook-info}
% Provide an attribute for the cover artwork image.\par
%    \begin{macrocode}
<!ATTLIST info coverart CDATA #IMPLIED>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsection{Changes to attribute lists}
% \begin{CPKattribute}{YYYY-MM-DD}\label{attribute-doctexbook-YYYY-MM-DD}
% Add a human-validatable attribute for the ISO date to
%             the three element types used for dates.\par
%    \begin{macrocode}
<!ATTLIST date YYYY-MM-DD CDATA #IMPLIED>
<!ATTLIST confdates YYYY-MM-DD-from CDATA #IMPLIED
                    YYYY-MM-DD-to CDATA #IMPLIED>
<!ATTLIST year YYYY-MM-DD CDATA #REQUIRED>
%    \end{macrocode}
% \end{CPKattribute}
% \begin{CPKattribute}{units}\label{attribute-doctexbook-units}
% Quotations and block quotations already have a
%             \texttt{<linkend>}\index{linkend=\texttt{\char'074 linkend\char'076 } (element)}\index{elements:!linkend=\texttt{\char'074 linkend\char'076 }} attribute for citing a source, so add
%             units and limits for ranges.\par
%    \begin{macrocode}
<!ATTLIST blockquote units CDATA #IMPLIED
                     begin CDATA #IMPLIED
                     end CDATA #IMPLIED>
<!ATTLIST quote units CDATA #IMPLIED
                begin CDATA #IMPLIED
                end CDATA #IMPLIED>
%    \end{macrocode}
% \end{CPKattribute}
% \begin{CPKattribute}{linkend}\label{attribute-doctexbook-linkend}
% Allow cross-references to have multiple
%             targets.\par
%    \begin{macrocode}
<!ATTLIST xref linkend IDREFS #REQUIRED>
<!ATTLIST biblioref linkend IDREFS #REQUIRED>
%    \end{macrocode}
% \end{CPKattribute}
% \begin{CPKattribute}{label}\label{attribute-doctexbook-label}
% Add the attributes and data types needed for a
%     functional bibliography entry. The \texttt{@label}\index{label=\texttt{\char'100 label} (attribute)}\index{attributes:!label=\texttt{\char'100 label}} attribute holds the name
%     of the reference style (a supported
%     \textsf{biblatex} style name). The \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} attribute is for the
%     name of any ancillary package required by the
%     style.\par
%    \begin{macrocode}
<!ATTLIST bibliography label CDATA #REQUIRED
                       xreflabel CDATA #IMPLIED>
<!ATTLIST biblioentry xml:id ID #REQUIRED xreflabel
 (article|book|booklet|collection|inbook|incollection|
  inproceedings|inreference|manual|mastersthesis|misc|
  online|patent|periodical|phdthesis|proceedings|
  reference|report|standard|thesis|bookinbook|suppbook|
  suppcollection|suppperiodical|mvbook|mvcollection|
  mvproceedings|mvreference|unpublished)
  #REQUIRED>
<!ATTLIST biblioid YYYY-MM-DD CDATA #IMPLIED>
%    \end{macrocode}
% \end{CPKattribute}
% \begin{CPKattribute}{role}\label{attribute-doctexbook-role}
% Provide the new data types for annotated code, along
%     with the attributes for the name of the object and the
%     reuse flag.\par
%    \begin{macrocode}
<!ATTLIST annotation role (attribute|attvalue|box|class|
  color|comment|counter|dtd|element|entity|environment|error|field|
  file|font|function|language|length|macro|mode|option|
  package|parameter|rubric|setting|switch|template|typeface|
  variable|UNUSED) #REQUIRED
          xreflabel CDATA #REQUIRED
          reuse IDREFS #IMPLIED>
%    \end{macrocode}
% \end{CPKattribute}
% \begin{CPKattribute}{version}\label{attribute-doctexbook-version1}
% Remark is used for notes about edits and bug
%     fixes.\par
%    \begin{macrocode}
<!ATTLIST remark version CDATA #REQUIRED
                 revision CDATA #REQUIRED>
%    \end{macrocode}
% \end{CPKattribute}
% \begin{CPKattribute}{language}\label{attribute-doctexbook-language}
% Extend the languages used in a dozen or so element
%     types, add an ending line-number for program listings, and
%     add values for the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}}
%     attribute on the \texttt{<varname>}\index{varname=\texttt{\char'074 varname\char'076 } (element)}\index{elements:!varname=\texttt{\char'074 varname\char'076 }} element.\par
%    \begin{macrocode}
<!ENTITY % langs "language (
  CGI|C|bash|TeX|LaTeXe|LaTeX|XML|XSLT|XLST3|HTML|XPath|BiBTeX|
  awk|Java|man|Makefile|METAFONT|DTD) 'LaTeXe'">
<!ATTLIST classname %langs;>
<!ATTLIST cmdsynopsis %langs;>
<!ATTLIST command %langs;>
<!ATTLIST envar %langs;>
<!ATTLIST function %langs;>
<!ATTLIST literal %langs;>
<!ATTLIST literallayout %langs;>
<!ATTLIST option %langs;>
<!ATTLIST programlisting %langs;
          endinglinenumber CDATA #IMPLIED>
<!ATTLIST screen %langs;>
<!ATTLIST varname %langs;
          role (counter|length|prog|color|template|
                variable|parameter|field|entrytype) #IMPLIED>
<!ATTLIST parameter %langs;>
%    \end{macrocode}
% \end{CPKattribute}
% \begin{CPKattribute}{fontface}\label{attribute-doctexbook-fontface}
% Add the attributes needed for typographic
%     annotation.\par
%    \begin{macrocode}
<!ATTLIST type fontencoding (T1|OT1|U) #IMPLIED
               fontface CDATA #IMPLIED
               fontfamily (roman|sans|monospace) #IMPLIED
               fontseries (k|r|m|n|b|bx|it|sl|l|c) #IMPLIED
               fontshape (up|it|sc) #IMPLIED
               fontsize CDATA #IMPLIED
               fontalign (yes|no) #IMPLIED
               fontcolor CDATA #IMPLIED>
%    \end{macrocode}
% \end{CPKattribute}
% \begin{CPKattribute}{omit}\label{attribute-doctexbook-omit}
% Add the omission attribute to the package
%     specifications and provide type values for the \texttt{@class}\index{class=\texttt{\char'100 class} (attribute)}\index{attributes:!class=\texttt{\char'100 class}} attribute on the
%     \texttt{<tag>}\index{tag=\texttt{\char'074 tag\char'076 } (element)}\index{elements:!tag=\texttt{\char'074 tag\char'076 }} element.\par
%    \begin{macrocode}
<!ATTLIST seglistitem omit IDREFS #IMPLIED>
<!ATTLIST tag class (attribute|attvalue|element|emptytag|
endtag|declaration|genentity|localname|namespace|
numcharref|paramentity|pi|prefix|comment|starttag|xmlpi)
	#IMPLIED>
%    \end{macrocode}
% \end{CPKattribute}
% \begin{CPKattribute}{arg}\label{attribute-doctexbook-arg}
% Add \texttt{@pre}\index{pre=\texttt{\char'100 pre} (attribute)}\index{attributes:!pre=\texttt{\char'100 pre}} and \texttt{@post}\index{post=\texttt{\char'100 post} (attribute)}\index{attributes:!post=\texttt{\char'100 post}} attributes to the
%     \texttt{<arg>}\index{arg=\texttt{\char'074 arg\char'076 } (element)}\index{elements:!arg=\texttt{\char'074 arg\char'076 }} element type for use in storing the \LaTeX{}
%     before-and-after to generate for the
%     {\ttfamily{}\textbackslash{}Print*Name} commands for
%     \textsf{dox}.\par
%    \begin{macrocode}
<!ATTLIST arg pre CDATA #IMPLIED post CDATA #IMPLIED>
%    \end{macrocode}
% \end{CPKattribute}
% \subsection{Parameter Entity switch for character
%   entities}
% \begin{CPKentity}{OUTPUT}\label{entity-doctexbook-OUTPUT}
% Use the conventional \textsc{pe}\index{PE}-based switching
%     mechanism for \LaTeX{} \emph{vs} \textsc{html}\index{HTML} output (only \LaTeX{} implemented
%     so far).\par
%    \begin{macrocode}
<!ENTITY % OUTPUT "LaTeX">
<!ENTITY % %OUTPUT; "INCLUDE">
<!ENTITY % LaTeX "IGNORE">
%    \end{macrocode}
% \end{CPKentity}
% \begin{CPKentity}{LaTeX}\label{entity-doctexbook-LaTeX}
% List the character entities needed for \LaTeX{}.\par
%    \begin{macrocode}
<![%LaTeX;[
<!ENTITY ampers "\&#38;#38;">
<!ENTITY BiBTeX "\BibTeX{}">
<!ENTITY BibTeX "\BibTeX{}">
<!ENTITY BIBTeX "\BibTeX{}">
<!ENTITY ConTeXt "Con\TeX t{}">
<!ENTITY LaTeX "\LaTeX{}">
<!ENTITY LaTeX2e "\LaTeXe{}">
<!ENTITY XeTeX "\XeTeX{}">
<!ENTITY XeLaTeX "\XeLaTeX{}">
<!ENTITY LuaTeX "Lua\TeX{}">
<!ENTITY LuaLaTeX "Lua\LaTeX{}">
<!ENTITY LyX "\LyX{}">
<!ENTITY METAFONT "\MF{}">
<!ENTITY METAPOST "\MP{}">
<!ENTITY TeX "\TeX{}">
<!ENTITY bsol "{\texttt{\textbackslash}}">
<!ENTITY bsq "\rule{1.2ex}{1.2ex}">
<!ENTITY date "\filedate{}">
<!ENTITY degree "\textdegree{}">
<!ENTITY doctype "\classorpackage{}">
<!ENTITY dollar "\$">
<!ENTITY hash "\#">
<!ENTITY filler "\hfil{}">
<!ENTITY frac12 "\nicefrac12">
<!ENTITY frac13 "\nicefrac13">
<!ENTITY frac23 "\nicefrac23">
<!ENTITY hellip "\dots{}">
<!ENTITY mdash "~--- ">
<!ENTITY mldr "\dotfill{}">
<!ENTITY nbsp "~">
<!ENTITY ndash "--">
<!ENTITY percnt "\&#x0025;">
<!ENTITY square "\raisebox{-1pt}{\Square}">
<!ENTITY star "\ensuremath{\ast}">
<!ENTITY thinsp "\thinspace{}">
<!ENTITY times "×">
<!ENTITY specialUuml
  '{\normalfont\"{\fontfamily{cdr}\selectfont U}}'>
<!ENTITY verbar "\menusep{}">
<!ENTITY version "\fileversion{}">
<!ENTITY decorule "\decorule{}">
<!ENTITY % HTML "IGNORE">
]]>
%    \end{macrocode}
% The commands which are non-standard are implemented in
%     the \textsf{classpack} package, or (in the case
%     of {\ttfamily{}\textbackslash{}decorule}) in a package
%     (\textsf{decorule}) implemented by
%     \emph{ClassPack}, and only used in the
%     circumstance of their inclusion.\par
% \centering
% \includegraphics[width=0.5\columnwidth]{decorule-crop.pdf}
% \end{CPKentity}
% \begin{CPKentity}{HTML}\label{entity-doctexbook-HTML}
% List the character entities needed for
%     \textsc{html}\index{HTML}. The illegal inclusion of element
%     markup in attribute values renders this invalid, although
%     it is parsed and accepted by Saxon.\par
%    \begin{macrocode}
<![%HTML;[
<!ENTITY ampers "&#38;amp;">
<!ENTITY BiBTeX  '<span class="BIBTeX">B<span
         class="I">I</span>B<span class="TEX">T<span
         class="E">E</span>X</span></span>'>
<!ENTITY BibTeX  '<span class="BIBTeX">B<span
         class="I">I</span>B<span class="TEX">T<span
         class="E">E</span>X</span></span>'>
<!ENTITY BIBTeX  '<span class="BIBTeX">B<span
         class="I">I</span>B<span class="TEX">T<span
         class="E">E</span>X</span></span>'>
<!ENTITY ConTeXt 'Con<span class="TEX">T<span
         class="E">E</span>X</span>t'>
<!ENTITY LaTeX   '<span class="LATEX">L<span
         class="A">A</span><span class="TEX">T<span
         class="E">E</span>X</span></span>'>
<!ENTITY LaTeX2e '<span class="LATEX">L<span
         class="A">A</span><span class="TEX">T<span
         class="E">E</span>X</span>2&#x3b5;</span>'>
<!ENTITY XeTeX   '<span class="XETEX">X<span
         class="E">E</span><span class="TEX">T<span
         class="E">E</span>X</span></span>'>
<!ENTITY XeLaTeX '<span class="XETEX">X<span
         class="E">E</span><span class="LATEX">L<span
         class="A">A</span><span class="TEX">T<span
         class="E">E</span>X</span></span></span>'>
<!ENTITY LuaTeX   '<span class="LUATEX">Lua<span
         class="TEX">T<span
         class="E">E</span>X</span></span>'>
<!ENTITY LuaLaTeX '<span class="LUATEX">Lua<span
         class="LATEX">L<span
         class="A">A</span><span class="TEX">T<span
         class="E">E</span>X</span></span></span>'>
<!ENTITY LyX     '<span class="LyX">L<span
         class="Y">Y</span>X</span>'>
<!ENTITY METAFONT '<span class="MF">METAFONT</span>'>
<!ENTITY METAPOST '<span class="MP">METAPOST</span>'>
<!ENTITY TeX     '<span class="TEX">T<span
         class="E">E</span>X</span>'>
<!ENTITY bsol "\">
<!ENTITY bsq "&#x25A0;">
<!ENTITY date "">
<!ENTITY degree "°">
<!ENTITY doctype "">
<!ENTITY dollar "$">
<!ENTITY filler "">
<!ENTITY frac12 "½">
<!ENTITY frac13 "&#x2153;">
<!ENTITY frac23 "&#x2154;">
<!ENTITY hash "&#x23;">
<!ENTITY hellip "…">
<!ENTITY mdash " — ">
<!ENTITY mldr "…">
<!ENTITY nbsp " ">
<!ENTITY ndash "–">
<!ENTITY percnt "&#x0025;">
<!ENTITY square "&#x25a1;">
<!ENTITY star "❉">
<!ENTITY thinsp " ">
<!ENTITY times "×">
<!ENTITY specialUuml 'Ü'>
<!ENTITY verbar "|">
<!ENTITY version "">
<!ENTITY decorule
  "<inlinemediaobject><imageobject><imagedata
   fileref='decorule.png'
   width='2in'/></imageobject></inlinemediaobject>">
]]>
%    \end{macrocode}
% \end{CPKentity}
% \subsection{Invocation}
% \begin{CPKentity}{invocation}\label{entity-doctexbook-invocation}
% Finally, invoke
%     \emph{DocBook}.\par
%    \begin{macrocode}
  %db5dtd;
%    \end{macrocode}
% \end{CPKentity}
% \iffalse
%</cpdtddoc>
% \fi
% \iffalse
%<*db2dtxscript>
% \fi
% \clearpage
% \section{The \emph{db2dtx.xsl} script}\label{db2dtxscript}
% \setcounter{CodelineNo}{0}
% While the core of your class or package is the
% \emph{DocBook} \textsc{xml}
% document containing your \LaTeX{} code and documentation, the
% core of the \emph{ClassPack} system is the
% program or script that turns your \textsc{xml} file
% into {\ttfamily{}.dtx} and {\ttfamily{}.ins}
% files for distribution as combined code and documentation.
% This is that script.\par
% The {\ttfamily{}db2dtx.xsl} script is written in
% \textsc{xslt3}, a declarative language for
% processing \textsc{xml} \parencite{xslt3}.  It consists of a set of templates, each
% of which matches a markup pattern in your
% \textsc{xml} document. These templates are usually
% written to match an element type, or an element type in a
% particular position or with a particular attribute value or
% subelement, but some are just referenced by name, and act as
% subroutines which can be reused in many circumstances.\par
% The advantage of using a declarative language is that the
% script doesn’t need to know when and where each element will
% occur in your file: the \textsc{xml} parser will
% feed them to the \textsc{xslt} script as they occur
% in document order (or as otherwise specified), and the script
% will then apply any matching template.\par
% The description in this section explains how the script
% produces your class or package (and other) files.\par
% \begin{CPKcomment}{db2dtxscript-comment}\label{comment-db2dtxscript}
% Identify the file origin,
% date, time, etc.\par
%    \begin{macrocode}
<!-- The db2dtx.xsl script (from the classpack package v.1.28, 2024-02-21) -->
<!-- Generated by ClassPack v.1.28 (2024-02-21) on 24-03-04T22:35:19 -->
%    \end{macrocode}
% These lines are automatically prepended to the file
% and may be removed if necessary,
% using a suitable editor.
% \end{CPKcomment}
% \subsection{XML Declaration, namespaces, and setup}
% \begin{CPKelement}{xsl:stylesheet}\label{element-db2dtx-stylesheet}
% The script starts with a comment describing the other
%     files on which the code depends. There is then the
%     \texttt{<xsl:stylesheet>}\index{xsl:stylesheet=\texttt{\char'074 xsl:stylesheet\char'076 } (element)}\index{elements:!xsl:stylesheet=\texttt{\char'074 xsl:stylesheet\char'076 }} start-tag with the namespace
%     declarations:\par
%    \begin{macrocode}
<!-- DEPENDENCIES: doctexbook.dtd, docbook5.dtd,
     db2bibtex.xsl, db2md.xsl, figtab2latex.xsl,
     rfc2119.xml, classpack.xml, prepost.xml, 
     languages.xml, readme.xml, representation.xml,
     lppl.xml (or other specified licence).
     This program accompanies v1.26 of ClassPack.
-->
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:db="http://docbook.org/ns/docbook"
  xmlns:sil="http://xml.silmaril.ie/identity/functions"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  version="3.1"
  exclude-result-prefixes="xsl db xlink sil xs">
%    \end{macrocode}
% The namespaces identify the origin of various features
%     of the script, but for simplicity they are suppressed in
%     the output. Note that this is an \textsc{xslt3}
%     script and requires an \textsc{xslt3}
%     processor.\par
% \end{CPKelement}
% \begin{CPKelement}{xsl:output}\label{element-db2dtx-output}
% This identifies the output methods for  \begin{enumerate*}[label=\emph{\alph*}),itemjoin={{; }},itemjoin*={{; and }}]
% \item the default output (\LaTeX{} is just regarded as
%   text until someone writes a dedicated
%   \textbf{\texttt{latex}} method for
%   \textsc{xslt})\par
% \item several formats for the different ancillary
%   files generated during processing (the use of
%   \texttt{<xsl:result-document>}\index{xsl:result-document=\texttt{\char'074 xsl:result-document\char'076 } (element)}\index{elements:!xsl:result-document=\texttt{\char'074 xsl:result-document\char'076 }} requires a named
%   method separate from the default)\par
% \end{enumerate*}.\par
%    \begin{macrocode}
  <xsl:output method="text"/>
  <xsl:output method="text" name="textFormat"/>
  <xsl:output method="xml" name="xmlFormat" indent="yes"
    doctype-system="../doctexbook.dtd"/>
  <xsl:output method="xml" name="htmlFormat" indent="yes"
    doctype-system="about:legacy-compat" omit-xml-declaration="yes"/>
    
  <xsl:strip-space elements="*"/>
  
  <xsl:include href="db2bibtex.xsl"/>
  <xsl:include href="db2md.xsl"/>
  <xsl:include href="figtab2latex.xsl"/>
%    \end{macrocode}
% We also request the stripping of unwanted white-space
%     from around all elements, and we include three additional
%     \textsc{xslt} modules, the files  \begin{enumerate*}[label=\emph{\alph*}),itemjoin={{; }},itemjoin*={{; and }}]
% \item {\ttfamily{}db2bibtex.xsl} for handling
%   bibliographic formatting\par
% \item {\ttfamily{}db2md.xsl} for outputting
%   the \emph{MarkDown} which
%   \textsc{ctan}\index{CTAN} requires for the
%   {\ttfamily{}README.md} file\par
% \item {\ttfamily{}figtab2latex.xsl} which
%   handles the calculations and positioning required
%   for figures and tables\par
% \end{enumerate*}. These are annotated later in this
%     document.\par
% \end{CPKelement}
% \subsection{Parameters and variables}
% \begin{CPKparameter}{armour}\label{parameter-db2dtx-armour}
% The {\ttfamily{}\$armour}
%     parameter is  the percent–space combination used at the
%     start of lines in the {\ttfamily{}dtx} file which
%     are destined for the documentation. It could have been
%     hard-coded as a variable, but to provide for other formats
%     in future, it was thought better to pass it as a parameter
%     with the percent-space as the default value.\par
% The \DescribeVariable{shield}{\ttfamily{}\$shield} variable is used
%     similarly when constructing figures and tables in the
%     {\ttfamily{}figtab2latex.xsl} module, which can be
%     used independently of
%     \emph{ClassPack}, and is therefore not
%     parameterised.\par
%    \begin{macrocode}
  <xsl:param name="armour">
    <xsl:text>% </xsl:text>
  </xsl:param>
  <xsl:variable name="shield">
    <xsl:text>%</xsl:text>
  </xsl:variable>
  <xsl:param name="trace"/>

  <!-- path to the classpack directory -->
  <xsl:param name="cpdir"/>
  <!-- path to the project’s app dev directory -->
  <xsl:param name="appdir"/>
%    \end{macrocode}
% The \DescribeVariable{cpdir}{\ttfamily{}\$cpdir} and \DescribeVariable{appdir}{\ttfamily{}\$appdir}
%     parameters are values passed from the command-line or
%     {\ttfamily{}Makefile} for
%      \begin{enumerate*}[label=\emph{\alph*}),itemjoin={{; }},itemjoin*={{; and }}]
% \item the path to the
%   \emph{ClassPack} installation
%   directory\par
% \item the current class or package’s project
%   directory\par
% \end{enumerate*}. In a development setting, typically
%     {\ttfamily{}\$cpdir}
%     could be something like
%     {\ttfamily{}/usr/local/src/classpack} and {\ttfamily{}\$appdir} might
%     be more like
%     \url{~/texmf/dev/foobar}\thinspace.\par
% \end{CPKparameter}
% \subsubsection{Versioning}
% \begin{CPKvariable}{thisversion}\label{variable-db2dtx-thisversion}
% The version and version date of
%       \emph{Classpack} are extracted from
%       the currently-installed
%       \emph{ClassPack} documentation
%       \textsc{xml} (used to generate what you are
%       reading now).\par
%    \begin{macrocode}
  <xsl:variable name="thisversion"
    select="document(concat($cpdir,
                            '/classpack/classpack.xml'))
            /db:book/db:info/db:revhistory/db:revision
            [not(../db:revision/@version > @version)]
            /@version"/>
  <xsl:variable name="thisverdate"
    select="document(concat($cpdir,
                            '/classpack/classpack.xml'))
            /db:book/db:info/db:revhistory/db:revision
            [not(../db:revision/@version > @version)]
            /db:date/@YYYY-MM-DD"/>
%    \end{macrocode}
% \par\smallskip\leavevmode
% \CPKrunningecho{thisversion}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Move version and date elsewhere}}\par\smallskip
% \end{CPKvariable}
% \subsubsection{Lookup files}\label{lookups}
% There are \setcounter{CPKcoref}{5}\makeatletter\ifnum\c@CPKcoref<10 \numberstring{CPKcoref}\else\theCPKcoref\fi\makeatother{} variables defined as reference
%     lookups into other files which
%     {\sffamily \textsc{must}} be present for this
%     script to work:\par
% \label{lookuplist}
% \begin{enumerate}[noitemsep]
% \item \DescribeVariable{prepost}{\ttfamily{}\$prepost} is the
% {\ttfamily{}prepost.xml} file of package
% data\par
% \item \DescribeVariable{langs}{\ttfamily{}\$langs} is a file
% {\ttfamily{}languages.xml} of languages
% supported by \textsf{babel}\par
% \item \DescribeVariable{readme}{\ttfamily{}\$readme} is the
% {\ttfamily{}readme.xml} template for
% generating {\ttfamily{}README.md}\thinspace\par
% \item \DescribeVariable{licence}{\ttfamily{}\$licence} is the software
% licence or copyright text \textsc{xml} file
% (eg {\ttfamily{}lppl.xml}) which gets included
% at the end of the documentation\par
% \item \DescribeVariable{thisdoc}{\ttfamily{}\$thisdoc} is a global name
% for the whole \emph{ClassPack}
% document being processed so that it can be referred to
% from within the scope of a different node-set such as
% an \emph{XPath} \texttt{tokenize} loop or the
% processing of an external document.\par
% \end{enumerate}
%    \begin{macrocode}
  <xsl:variable name="prepost" 
    select="document(concat($cpdir,'/prepost.xml'))
    /db:refsection"/>
  <xsl:variable name="langs" 
    select="document(concat($cpdir,'/languages-master.xml'))
            /languages"/>
  <xsl:variable name="readme" 
    select="document(concat($cpdir,'/readme-master.xml'))
            /db:chapter"/>
  <xsl:variable name="licence" 
    select="document(concat($appdir,'/',
            /db:book/@audience,'.xml'))
            /db:chapter"/>
  <xsl:variable name="thisdoc" select="/"/>
%    \end{macrocode}
% \subsubsection{Naming}
% We define variables \DescribeVariable{maxcodelen}{\ttfamily{}\$maxcodelen}, used in the
%     \DescribeTemplate{breakline}{\ttfamily{}breakline} named template (see
%     the code \vpageref{breakline}) which handles line-length for
%     plaintext output; and \DescribeVariable{docname}{\ttfamily{}\$docname}, which is the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} of the
%     \emph{ClassPack} document being
%     processed.\par
%    \begin{macrocode}
  <xsl:variable name="maxcodelen">
    <xsl:text>40</xsl:text>
  </xsl:variable>

  <xsl:variable name="docname" select="/db:book/@xml:id"/>
  <xsl:variable name="doctitle">
    <xsl:call-template name="detex">
      <xsl:with-param name="string"
        select="/db:book/db:info/db:title/node()"/>
    </xsl:call-template>
  </xsl:variable>

  <xsl:variable name="firstverdate"
    select="/db:book/db:info/db:revhistory/db:revision
            [not(../db:revision/@version &lt; @version)]
            /db:date/@YYYY-MM-DD"/>
%    \end{macrocode}
% \subsubsection{Document metadata}
% The \DescribeVariable{name}{\ttfamily{}\$name} of the output document
%     may be affected by the value of the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} of the first \texttt{chapter}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} element in the
%     `code' part; otherwise it’s the
%     document \texttt{<ID>}\index{ID=\texttt{\char'074 ID\char'076 } (element)}\index{elements:!ID=\texttt{\char'074 ID\char'076 }} extracted above.\par
%    \begin{macrocode}
  <xsl:variable name="name">
    <xsl:choose>
      <!-- if there is more than one code appendix, 
           use the ID of the first chapter in the code part 
           as the 'name' of this bundle -->
      <xsl:when
        test="count(/db:book/db:part[@xml:id='code']
                    //db:appendix
                    [substring-after(@xlink:href,'.')
                    = 'cls'])>1">
        <xsl:value-of
          select="/db:book/db:part[@xml:id='code']
                  /db:chapter[1]/@xml:id"/>
      </xsl:when>
      <!-- otherwise use the ID of this document -->
      <xsl:otherwise>
        <xsl:value-of select="$docname"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
%    \end{macrocode}
% Extract the document metadata from the attributes of
%     the \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} (root) element. These are explained in
%     detail in \vref{setup}.\par
%    \begin{macrocode}
  <xsl:variable name="doctype" select="/db:book/@arch"/>
  <xsl:variable name="version" select="/db:book/@version"/>
  <xsl:variable name="revision" select="/db:book/@revision"/>
  <xsl:variable name="filetype" select="/db:book/@userlevel"/>
  <xsl:variable name="date"
    select="/db:book/db:info/db:revhistory/db:revision
            [not(../db:revision/@version > @version)]
            /db:date/@YYYY-MM-DD"/>
  <xsl:variable name="latestrevhist" 
    select="/db:book/db:info/db:revhistory/db:revision
            [not(../db:revision/@version > @version)]
            /@version"/>
%    \end{macrocode}
% \subsubsection{Text control}\label{textcontrol}
% A comment character is declared, selected from the
%     \DescribeVariable{commentchars}{\ttfamily{}\$commentchars} variable: in most
%     cases (\LaTeX{} code) this is the
%     \url{%} sign, but
%     \emph{ClassPack} can also be used to
%     maintain and manage Bash shell scripts using
%     \url{#}\thinspace.\par
% We set up a variable of assorted comment characters in
%     \DescribeVariable{commentchars}{\ttfamily{}\$commentchars} that we can use
%     for dividing sections of a generated file.\par
% On that basis, also set up a \DescribeVariable{sentinel}{\ttfamily{}\$sentinel} variable consisting
%     of two comment characters and a space, for use in adding
%     inline (text) documentation to an extracted
%     document.\par
%    \begin{macrocode}
  <!-- comment characters depend on file type 
       so extractable chapters/appendixes MUST have
       an xlink:href ending with one of these filetypes -->
  <xsl:variable name="commentchars">
    <class    filetype="cls">%</class>
    <document filetype="bib">%</document>
    <document filetype="tex">%</document>
    <document filetype="cnf">%</document>
    <document filetype="def">%</document>
    <document filetype="dtd" term="--&gt;">&lt;!--</document>
    <document filetype="xml" term="--&gt;">&lt;!--</document>
    <package  filetype="sty">%</package>
    <script   filetype="cp">#</script>
    <script   filetype="sh">#</script>
    <script   filetype="awk">#</script>
    <script   filetype="xsl" term="--&gt;">&lt;!--</script>
  </xsl:variable>

  <!-- Default shield is double delimiter plus space -->
  <xsl:variable name="sentinel"
    select="concat(
            $commentchars/*[name()=current()/db:book/@arch]
            [@filetype=current()/db:book/@userlevel],
            $commentchars/*[name()=current()/db:book/@arch]
            [@filetype=current()/db:book/@userlevel],' ')"/>
%    \end{macrocode}
% \subsubsection{Process control}
% The default \LaTeX{} processor for the documentation or
%     the class/package is still
%     \emph{pdflatex} but the variable
%     \DescribeVariable{latexprog}{\ttfamily{}\$latexprog} could be set to the
%     value specified in the \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}}
%     attribute of the relevant package list (see \vref{packagelists}). This has been superseded by
%     placing the processor name in the \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} attribute of the
%     relevant \texttt{part}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }} element (see
%     the note in \vref{moveproc}).\par
%    \begin{macrocode}
  <xsl:variable name="latexprog">
    <xsl:choose>
      <xsl:when
        test="/db:book/db:info/db:cover/db:constraintdef
        [@xml:id=concat(/db:book/@userlevel,'packages')]
        /@arch!=''">
        <xsl:value-of
          select="/db:book/db:info/db:cover
          /db:constraintdef
          [@xml:id=concat(/db:book/@userlevel,'packages')]
          /@arch"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>pdflatex</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
%    \end{macrocode}
% \par\smallskip\leavevmode
% \CPKrunningecho{}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Remove unused traces of the build system The specification of the processor is now kept elsewhere. Delete them}}\par\smallskip
% \subsection{Creating the {\ttfamily{}.dtx} file
%   structure}
% This is the template matching the document root, where
%   all the preparatory work is done.\par
% Start with the program identity in the normal way, then
%   check that version and revision in the root element match
%   the latest revision history\par
%    \begin{macrocode}
  <xsl:template match="/">
   <xsl:message>
      <xsl:text>This is DB2DTX, Version </xsl:text>
      <xsl:value-of select="$thisversion"/>
      <xsl:text> (</xsl:text>
      <xsl:value-of select="$thisverdate"/>
      <xsl:text>).</xsl:text>
    </xsl:message>
    <xsl:variable name="fence">
      <xsl:call-template name="makefence"/>
    </xsl:variable>
    <!-- stop if the version numbers don't accord -->
    <xsl:choose>
      <xsl:when test="concat($version,'.',$revision)
                      != $latestrevhist">
        <xsl:message>
          <xsl:text>! Declared version </xsl:text>
          <xsl:value-of
            select="concat($version,'.',$revision)"/>
          <xsl:text> does not match latest </xsl:text>
          <xsl:text>revision history </xsl:text>
          <xsl:value-of select="$latestrevhist"/>
          <xsl:text>&#xa;  I'm sorry, </xsl:text>
          <xsl:text>I can't go on </xsl:text>
          <xsl:text>until you fix this.</xsl:text>
        </xsl:message>
      </xsl:when>
%    \end{macrocode}
% \subsubsection{Installer, README, and MANIFEST}
% Call templates to create the {\ttfamily{}.ins}
%     file, the {\ttfamily{}README} file, and the
%     {\ttfamily{}MANIFEST} file. The first is done via
%     the template for the \texttt{<info>}\index{info=\texttt{\char'074 info\char'076 } (element)}\index{elements:!info=\texttt{\char'074 info\char'076 }} element (see \vref{insfile}), the other two
%     by named templates (see \vref{makereadme} and
%     \vref{makemanifest}).\par
%    \begin{macrocode}
      <xsl:otherwise>
        <!-- output the .ins file first -->
        <xsl:apply-templates
          select="/db:book/db:info" mode="ins"/>
        <!-- then the README.md -->
        <xsl:call-template name="readme"/>
        <!-- and then the MANIFEST -->
        <xsl:call-template name="manifest"/>
        <!-- and then the index.html for the Silmaril site -->
        <xsl:call-template name="webindex"/>
%    \end{macrocode}
% \par\smallskip\leavevmode
% \CPKrunningecho{}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Makefile needs to manage ancillary and test files properly Find a way to test the code and pass conditions to the Makefile for other files}}\par\smallskip
% \subsubsection{Copyright}
% The {\ttfamily{}.dtx} file starts with the
%     switch to enable commenting, and the boilerplate of the
%     copyright statement, which is called as a named template
%     (see \vref{copyright}).\par
%    \begin{macrocode}
        <!-- start creating the .dtx file -->
        <xsl:message>
          <xsl:text>Making </xsl:text>
          <xsl:value-of select="$doctype"/>
          <xsl:text> </xsl:text>
          <xsl:value-of select="$docname"/>
        </xsl:message>
        <xsl:text>% \iffalse meta-comment&#xa;%&#xa;</xsl:text>
        <xsl:call-template
          name="copyright-statement">
          <xsl:with-param name="ftype">
            <xsl:text>dtx</xsl:text>
          </xsl:with-param>
        </xsl:call-template>
        <xsl:text>%
% \fi
% \iffalse&#xa;</xsl:text>
%    \end{macrocode}
% \subsubsection{Special for class files}
% Document classes need a
%     {\ttfamily{}\textbackslash{}ProvidesFile} command.\par
%    \begin{macrocode}
        <!-- SPECIAL EXCEPTION FOR CLASSES: 
             needs \ProvidesFile -->
        <xsl:if test="$doctype='class'">
          <xsl:text>%&lt;*driver>
\ProvidesFile{</xsl:text>
          <xsl:value-of select="$docname"/>
          <xsl:text>.dtx}
%&lt;/driver>
</xsl:text>
        </xsl:if>
%    \end{macrocode}
% \subsubsection{Special for shell scripts}
% As mentioned in \vref{textcontrol},
%     \emph{ClassPack} can also be used to
%     manage and maintain shell scripts. This section deals with
%     the extra code needed to generate the header of a
%     script.\par
% \paragraph[Shell call]{Shell call :}
% Construct the `shebang' line
%       at the top with the path to the shell binary. The first
%       line we output is the Doc\TeX{} tag to start extraction,
%       followed by the shebang.\par
%    \begin{macrocode}
        <xsl:choose>
          <!-- SPECIAL EXCEPTION FOR SHELL SCRIPTS: -->
          <xsl:when test="$doctype='script'">
            <!-- shell call -->
            <xsl:text>%&lt;</xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>></xsl:text>
            <xsl:value-of select="$commentchars"/>
            <xsl:text>! /bin/</xsl:text>
            <xsl:value-of select="/db:book/@userlevel"/>
            <xsl:text>&#xa;</xsl:text>
%    \end{macrocode}
% \paragraph[Script author]{Script author :}
% Next comes the author and date.\par
%    \begin{macrocode}
            <!-- author, affil, date -->
            <xsl:text>%&lt;</xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>></xsl:text>
            <xsl:value-of select="$fence"/>
            <xsl:text>%&lt;</xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>></xsl:text>
            <xsl:value-of select="$sentinel"/>
            <xsl:value-of
              select="/db:book/db:info/db:author[1]
                      /db:personname/db:firstname"/>
            <xsl:text> </xsl:text>
            <xsl:value-of
              select="/db:book/db:info/db:author[1]
                      /db:personname/db:surname"/>
            <xsl:text>, </xsl:text>
            <xsl:value-of
              select="/db:book/db:info/db:author[1]
                      /db:affiliation/db:orgname"/>
            <xsl:text>, </xsl:text>
            <xsl:value-of 
              select="format-date(
                      /db:book/db:info
                      /db:revhistory/db:revision
                      [@version=max(parent::db:revhistory
                                    /db:revision/@version)]
                      /db:date/@YYYY-MM-DD,
                      '[D] [MNn] [Y]')"/>
            <xsl:text>&#xa;</xsl:text>
%    \end{macrocode}
% \paragraph[Script history]{Script history :}
% Output the development and maintenance
%       history\par
%    \begin{macrocode}
            <!-- history -->
            <xsl:text>%&lt;</xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>></xsl:text>
            <xsl:value-of select="$fence"/>
            <xsl:for-each
              select="/db:book/db:info
                      /db:revhistory/db:revision">
              <xsl:sort select="@version"
                order="ascending"/>
              <xsl:text>%&lt;</xsl:text>
              <xsl:value-of select="$doctype"/>
              <xsl:text>></xsl:text>
              <xsl:value-of select="$sentinel"/>
              <xsl:value-of select="@version"/>
              <xsl:text> </xsl:text>
              <xsl:value-of 
                select="db:revdescription/db:itemizedlist
                        /db:title"/>
              <xsl:text>: </xsl:text>
              <xsl:for-each 
                select="db:revdescription/db:itemizedlist
                        /db:listitem">
                <xsl:value-of select="normalize-space(.)"/>
              </xsl:for-each>
              <xsl:text> </xsl:text>
              <xsl:value-of select="db:date/@YYYY-MM-DD"/>
              <xsl:text>&#xa;</xsl:text>
            </xsl:for-each>
%    \end{macrocode}
% \paragraph[Script version]{Script version :}
% Maintain the version data and output.\par
%    \begin{macrocode}
            <xsl:text>%&lt;</xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>></xsl:text>
            <xsl:value-of select="$fence"/>
            <!-- version and date -->
            <xsl:text>%&lt;</xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>>VERSION=</xsl:text>
            <xsl:value-of 
              select="/db:book/db:info
                      /db:revhistory/db:revision
                      [@version=max(parent::db:revhistory
                                    /db:revision/@version)]
                      /@version"/>
            <xsl:text>&#xa;</xsl:text>
            <xsl:text>%&lt;</xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>>VERSDATE=</xsl:text>
            <xsl:value-of 
              select="/db:book/db:info
                      /db:revhistory/db:revision
                      [@version=max(parent::db:revhistory
                                    /db:revision/@version)]
                      /db:date/@YYYY-MM-DD"/>
            <xsl:text>&#xa;</xsl:text>
%    \end{macrocode}
% \paragraph[Script name]{Script name :}
% Identify the script.\par
%    \begin{macrocode}
            <xsl:text>%&lt;</xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>>PROGRAM=`echo $0 |</xsl:text>
            <xsl:text>awk -F/ '{print $NF}' |</xsl:text>
            <xsl:text>awk -F. '{print $1}'`</xsl:text>
            <xsl:text>&#xa;</xsl:text>
            <xsl:text>%&lt;</xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>></xsl:text>
            <xsl:value-of select="$fence"/>
          </xsl:when>
          <!-- end of block for shell scripts -->
%    \end{macrocode}
% \subsubsection{File header}
% Other document types (classes or packages) need the
%     Doc\TeX{} `tags' which delimit code
%     extraction, and the \TeX{} format control limits. This is
%     raw code generated automatically, not something derived
%     from the documentation. It also needs to be called by any
%     appendix that contains an extractable code file (eg a
%     style accompanying a class).\par
% \paragraph[Document type tag]{Document type tag :}
% We create the named start-tag for code extraction, plus the
%       minimum (earliest-dated) \LaTeX{} format needed to
%       process it, which we get from the the document start-tag
%       attributes \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} and
%       \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}}.\par
%    \begin{macrocode}
          <!-- ELSE FOR PACKAGES AND CLASSES -->
          <xsl:otherwise>
            <xsl:text>%&lt;</xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>>\NeedsTeXFormat{</xsl:text>
            <xsl:value-of select="/db:book/@conformance"/>
            <xsl:text>}[</xsl:text>
            <xsl:value-of
              select="translate(/db:book/@condition,
                                '-','/')"/>
            <xsl:text>]&#xa;</xsl:text>
%    \end{macrocode}
% Generate the end-tag; then emit the
%       {\ttfamily{}\textbackslash{}ProvidesClass} or
%       {\ttfamily{}\textbackslash{}ProvidesPackage} command using the
%       name of the document, but allowing an override with the
%       ID of the first code chapter.\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily
% This override has been temporarily suppressed as
% it causes a package naming conflict in certain
% circumstances,\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% Add the date and the title of the
%       document (with \LaTeX{} logos replaced by plain
%       text), repeating the tag for a second line.\par
%    \begin{macrocode}
            <xsl:text>%&lt;</xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>>\Provides</xsl:text>
            <xsl:value-of
              select="upper-case(substring($doctype,1,1))"/>
            <xsl:value-of select="substring($doctype,2)"/>
            <xsl:text>{</xsl:text>
            <xsl:value-of select="$docname"/>
            <xsl:text>}[</xsl:text>
            <!-- use latest rev date as distro date -->
            <xsl:value-of
              select="translate($date,'-','/')"/>
            <xsl:text> v</xsl:text>
            <xsl:value-of select="/db:book/@version"/>
            <xsl:text>.</xsl:text>
            <xsl:value-of select="/db:book/@revision"/>
            <xsl:text>&#xa;%&lt;</xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>>  </xsl:text>
            <xsl:variable name="title">
              <xsl:choose>
                <!-- use TeX-parsed content for code title -->
                <xsl:when test="//db:part[@xml:id='code']
                                /db:title">
                  <xsl:value-of
                    select="normalize-space(replace(
                            //db:part[@xml:id='code']
                            /db:title,
                            '\\LaTeX\{\}','LaTeX'))"/>
                </xsl:when>
                <xsl:when test="//db:info/db:subtitle">
                  <xsl:value-of
                    select="normalize-space(
                            //db:info/db:subtitle)"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of
                    select="normalize-space(
                            //db:info/db:title)"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <xsl:call-template name="delogify">
              <xsl:with-param name="string"
                select="$title"/>
            </xsl:call-template>
            <xsl:text>]&#xa;</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
%    \end{macrocode}
% \paragraph[Constructing the list of packages]{Constructing the list of packages :}\label{makepkglist}
% The autoloading of a package is specified in
%       {\ttfamily{}prepost.xml} by one of six
%       methods:\par
% \begin{enumerate}
% \item \emph{by default}, using a null
%   value for \texttt{<constructorsynopsis>}\index{constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 } (element)}\index{elements:!constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 }} \texttt{\unskip/@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}}.\par
%    \begin{macrocode}
<step condition="doc" remap="makeidx">
  <para>Package for creating indexes.</para>
  <constructorsynopsis condition=""/>
</step>
%    \end{macrocode}
% In this example, the \textsf{makeidx}
%   package will be included in the documentation for
%   every \emph{ClassPack} class or
%   package produced.\par
% \item by match\emph{}, using a
%   \texttt{<constructorsynopsis>}\index{constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 } (element)}\index{elements:!constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 }} \texttt{\unskip/@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} whose value is
%   the local-name of a
%   \emph{DocBook} element type
%   which occurs in the documentation section of the
%   \emph{ClassPack} document being
%   processed.\par
%    \begin{macrocode}
<step remap="url" condition="doc">
  <para>Handling of URI formatting.</para>
  <constructorsynopsis condition="link"/>
  <constructorsynopsis condition="uri"/>
  <constructorsynopsis condition="email"/>
</step>
%    \end{macrocode}
% In this example, the \textsf{url}
%   package is included if a \texttt{link}\index{link=\texttt{\char'074 link\char'076 } (element)}\index{elements:!link=\texttt{\char'074 link\char'076 }}, \texttt{uri}\index{uri=\texttt{\char'074 uri\char'076 } (element)}\index{elements:!uri=\texttt{\char'074 uri\char'076 }}, or \texttt{email}\index{email=\texttt{\char'074 email\char'076 } (element)}\index{elements:!email=\texttt{\char'074 email\char'076 }} element occurs in the
%   documentation.\par
% \end{enumerate}
% An optional \texttt{<methodparam>}\index{methodparam=\texttt{\char'074 methodparam\char'076 } (element)}\index{elements:!methodparam=\texttt{\char'074 methodparam\char'076 }} element
%       with \texttt{<parameter>}\index{parameter=\texttt{\char'074 parameter\char'076 } (element)}\index{elements:!parameter=\texttt{\char'074 parameter\char'076 }} and \texttt{<modifier>}\index{modifier=\texttt{\char'074 modifier\char'076 } (element)}\index{elements:!modifier=\texttt{\char'074 modifier\char'076 }}
%       subelements can be used to specify what attribute and
%       value on the identified element to test for inclusion.
%       For example,\par
% \iffalse
%<*ignore>
% \fi
% \begingroup\advance\hsize by-1em
% \begin{Verbatim}[frame=single,framesep=1em,
%  fontsize=\small]
<step remap="array" condition="cls sty doc">
  <constructorsynopsis condition="tgroup"/>
</step>
% \end{Verbatim}
% \endgroup
% \iffalse
%</ignore>
% \fi
% means `add the \textsf{array}
% package if the documentation uses the
% \texttt{<tgroup>}\index{tgroup=\texttt{\char'074 tgroup\char'076 } (element)}\index{elements:!tgroup=\texttt{\char'074 tgroup\char'076 }} element type' — because if an
%       author uses tables, it’s likely that the features of the
%       \textsf{array} package will be needed. A more
%       complex example is:\par
% \iffalse
%<*ignore>
% \fi
% \begingroup\advance\hsize by-1em
% \begin{Verbatim}[frame=single,framesep=1em,
%  fontsize=\small]
<step condition="cls sty doc" remap="csquotes">
  <para>Adds correct curly quotes for cited titles when using
    <package>biblatex</package></para>
  <constructorsynopsis condition="bibliography">
    <methodparam>
      <parameter>arch</parameter>
      <modifier>biblatex</modifier>
    </methodparam>
  </constructorsynopsis>
</step>
% \end{Verbatim}
% \endgroup
% \iffalse
%</ignore>
% \fi
% meaning `add the \textsf{csquotes}
% package if there is a \texttt{<bibliography>}\index{bibliography=\texttt{\char'074 bibliography\char'076 } (element)}\index{elements:!bibliography=\texttt{\char'074 bibliography\char'076 }} element
% with an \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}} attribute
% set to \texttt{"biblatex"}\index{biblatex=\texttt{"biblatex"} (attribute value)}\index{attribute values:!biblatex=\texttt{"biblatex"}}'.\par
% We go through the PRE and POST halves of
%       {\ttfamily{}prepost.xml} and get every
%       subelement \texttt{<constructorsynopsis>}\index{constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 } (element)}\index{elements:!constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 }} of those
%       \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} elements (packages) which are tagged for
%       \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}} usage.\par
%    \begin{macrocode}
        <!-- AUTOPACKAGE STARTS HERE -->
        <!-- 1. CREATE THE LIST OF PACKAGES NEEDED FOR DOCUMENTATION -->
        <xsl:variable name="packages">
          <!-- Create a list of <seglistitem>s -->
          <xsl:call-template name="makepackages"/>
        </xsl:variable>
        <!-- 2. OUTPUT THE LIST FOR REFERENCE, unsorted and unpruned -->
        <xsl:result-document format="xmlFormat" 
          href="autopack.xml">
          <db:segmentedlist arch="{$doctype}" remap="{$docname}">
            <xsl:copy-of select="$packages"/>
          </db:segmentedlist>
        </xsl:result-document>
%    \end{macrocode}
% \paragraph[Preloaded packages and options]{Preloaded packages and options :}\label{maincls}
% At this stage we are ready to work out what packages
%       are needed, both author-specified and automated;
%       \emph{ but not} those marked for deferral
%       to a later section identified by an ID in \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}}. This is done to allow
%       some package declarations to wait until after options
%       are processed and perhaps a base class loaded.\par
%    \begin{macrocode}
        <!-- 3. NON-DEFERRED PACKAGES (u/s) -->
        <xsl:call-template name="nondeferredpackages"/>
        <!-- unsure about them -->
        <!-- 4. START THE CODE FOR THE DOCUMENTATION (the "driver") -->
        <xsl:text>%&lt;*driver>&#xa;</xsl:text>
%    \end{macrocode}
% This marks the end of the common preamble (for
%     scripts and \LaTeX{} classes or packages) — from here on we
%     work on the documentation.\par
% \paragraph[Special treatment for packages needing preloading]{Special treatment for packages needing preloading :}\label{requirepackage}
% A few packages might need preloading. The only
%       common one is \textsf{fix-cm} package, which
%       is still needed to liberate font size changes from the
%       original Computer Modern step-size defaults, even with
%       \XeLaTeX{} and Lua\LaTeX{}. This can be avoided by using
%       the {\ttfamily{}\textbackslash{}RequirePackage} command
%       \emph{at the start of the document},
%       before the {\ttfamily{}\textbackslash{}documentclass}
%       command.\par
% The \textsf{fix-cm} package is therefore
%       still included by default in the author’s own packages.
%       Regardless of the typeface an author chooses for
%       documentation, someone may want to reproduce the
%       documentation using Computer Modern and may still be
%       using the \textsf{fontenc} and
%       \textsf{inputenc} packages in their
%       \emph{ClassPack}-generated
%       code.\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily
% The  \textsf{anysizefont} package may
% supersede \textsf{fix-cm} at some future
% stage, as that package does not require
% preloading.\par% The \textsf{fixltx2e} package is no
% longer required for preloading, as all its provisions
% are now included in the \LaTeX{} kernel.\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
%    \begin{macrocode}
        <!-- 5a. do the compulsory preloads first -->
        <xsl:for-each select="$packages/db:seglistitem
                              [db:seg/@annotations='required']">
          <!-- note that the inverse of this condition is needed 
               later to PREVENT this package being loaded on a 
               second or subsequent time -->
          <xsl:text>\RequirePackage</xsl:text>
          <xsl:if test="db:seg/@role!=''">
            <xsl:text>[</xsl:text>
            <xsl:value-of select="db:seg/@role"/>
            <xsl:text>]</xsl:text>
          </xsl:if>
          <xsl:text>{</xsl:text>
          <xsl:value-of select="db:seg"/>
          <xsl:text>}% </xsl:text>
          <xsl:text>because "</xsl:text>
          <xsl:value-of select="@role"/>
          <xsl:text>" :: "</xsl:text>
          <xsl:value-of select="@arch"/>
          <xsl:text>"&#xa;</xsl:text>
        </xsl:for-each>
        <!-- end of compulsory preloads -->
%    \end{macrocode}
% \paragraph[Special treatment for conflicting package options]{Special treatment for conflicting package options :}\label{passoptionstopackage}
% The error message `Option clash for
% package …' means that some other package being
%       loaded needs different options to any the author has
%       specified (or not). This can be avoided by using the
%       {\ttfamily{}\textbackslash{}PassOptionsToPackage} command
%       \emph{at the start of the document},
%       before the {\ttfamily{}\textbackslash{}documentclass}
%       command.\par
% Possibly the most common occurrence is with
%       \textsf{xcolor}, where the author wants one
%       palette loaded and \textsf{hyperref} wants
%       another, for example\par
% \begin{enumerate}
% \item the \textbf{\texttt{svgnames}} option to the
%   \textsf{xcolor} package can passed to
%   \textsf{xcolor} even if it is loaded later
%   with a different option requested\par
% \item similarly, the \textbf{\texttt{hyphens}} option
%   to the \textsf{url} package (more of a
%   convenience to authors than a specific requirement)
%   can be passed to the \textsf{url} package
%   even if it is loaded later with no options
%   requested\par
% \end{enumerate}
%    \begin{macrocode}
        <!-- @arch here is the class of autopackage mapping -->
        <!--      |
                  $packages/db:seglistitem
                    [db:seg=$thisdoc//db:constraintdef
                    [@xml:id='stypackages']//db:seg[@role]]
             this was removed to stop it affecting sty packages -->
        <xsl:for-each-group
          select="$packages/db:seglistitem
                    [@arch='dependencies']
                    [db:seg/@annotations='optional']
                  |
                  $packages/db:seglistitem
                    [@arch='requests']
                    [db:seg[@role]=$packages/db:seglistitem
                                     [@arch!='requests']/db:seg]
                  |
                  $packages/db:seglistitem
                    [@arch='defaults']
                    [db:seg=$prepost/db:procedure
                              [@xml:id='prepackage']
                              /db:step[@role and @performance]
                              /@remap]"
          group-by="db:seg">
          <xsl:text>\PassOptionsToPackage{</xsl:text>
          <!-- use the @role on the <seg>, at least one of them has one 
               but create them as a variable so we can group them -->
          <xsl:variable name="options">
            <xsl:for-each select="current-group()">
              <xsl:if test="db:seg/@role">
                <xsl:for-each select="tokenize(db:seg/@role,' ')">
                  <opt>
                    <xsl:value-of select="."/>
                  </opt>
                </xsl:for-each>
              </xsl:if>
              <xsl:if test="@arch='dependencies'
                            and @audience
                            and @role">
                <xsl:for-each select="tokenize(@role,' ')">
                  <opt>
                    <xsl:value-of select="."/>
                  </opt>
                </xsl:for-each>
              </xsl:if>
            </xsl:for-each>
            <!-- also use the @role in the <seglistitem> -->
            <xsl:for-each select="tokenize(@role,' ')">
              <opt>
                <xsl:value-of select="."/>
              </opt>
            </xsl:for-each>
          </xsl:variable>
          <xsl:for-each-group select="$options" group-by="opt">
            <xsl:if test="position()>1">
              <xsl:text>,</xsl:text>
            </xsl:if>
            <xsl:value-of select="current-grouping-key()"/>
          </xsl:for-each-group>
          <!-- say what -->
          <xsl:message>
            <xsl:text>Passing options "</xsl:text>
             <xsl:for-each-group select="$options" group-by="opt">
            <xsl:if test="position()>1">
              <xsl:text>,</xsl:text>
            </xsl:if>
            <xsl:value-of select="current-grouping-key()"/>
          </xsl:for-each-group>
          <xsl:text>" to package </xsl:text>
            <xsl:value-of select="db:seg"/>
          </xsl:message>
          <xsl:text>}{</xsl:text>
          <xsl:value-of select="db:seg"/>
          <xsl:text>}% because </xsl:text>
          <xsl:value-of select="@arch"/>
          <xsl:text> </xsl:text>
          <xsl:value-of select="@audience | @condition"/>
          <xsl:text> requires </xsl:text>
          <xsl:value-of select="@role"/>
          <xsl:text>&#xa;</xsl:text>
        </xsl:for-each-group>
        <!-- end of 5b. passing options to packages -->
        <!-- 6. ADD COMMANDS to hold the docname and doctype -->
        <xsl:text>\providecommand{\CPKdocname}{</xsl:text>
        <xsl:value-of select="/db:book/@xml:id"/>
        <xsl:text>}&#xa;\providecommand{\CPKdoctype}{</xsl:text>
        <xsl:value-of select="/db:book/@arch"/>
        <xsl:text>}&#xa;</xsl:text>
%    \end{macrocode}
% \paragraph[Language preloads for the \textsf{babel}
%       package]{Language preloads for the \textsf{babel}
%       package :}
% The \textsf{babel} package needs
%       individual attention because the languages need to be
%       preloaded, and it interacts with
%       \textsf{biblatex} as well. The base language
%       of the document comes last, so we record it in a
%       variable here, then fish out any other languages, and
%       list them into the argument of
%       {\ttfamily{}\textbackslash{}PassOptionsToPackage}, followed by the
%       base language. The console message identifies the
%       languages by human name from the node-set in \DescribeVariable{langs}{\ttfamily{}\$langs}, taken
%       from the ancillary file
%       {\ttfamily{}languages.xml}\thinspace.\par
%    \begin{macrocode}
        <!-- SPECIAL FOR BABEL, other languages preloaded
             This kind of dependency can't be expressed in 
             prepost.xml -->
        <xsl:variable name="baselang">
          <xsl:choose>
            <xsl:when test="/db:book/@xml:lang">
              <xsl:value-of select="/db:book/@xml:lang"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>en-IE</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <!-- see what other langs are used: only in the 'doc'
             part and its descendants; if @xml:lang is
             given *and* if it's non-null *and* if it's
             not the $baselang we already snagged above -->
        <xsl:if test="/db:book/db:part[@xml:id='doc']
                      /descendant-or-self::*[@xml:lang]
                      [@xml:lang!='']
                      [@xml:lang!=$baselang]
                      or
                      /db:book/@xml:lang">
          <xsl:text>\PassOptionsToPackage{</xsl:text>
          <xsl:variable name="loadedlangs">
            <xsl:for-each-group group-by="."
              select="/db:book/db:part[@xml:id='doc']
                      /descendant-or-self::*[@xml:lang]
                      [@xml:lang!='']
                      [@xml:lang!=$baselang]/@xml:lang">
              <xsl:value-of 
                select="$langs/language
                        [(string-length(current-grouping-key())>2
                          and concat(@Lang,'-',@Country)
                             =current-grouping-key())
                         or
                         (string-length(current-grouping-key())=2
                          and
                          @Lang=current-grouping-key())]
                        [position()=last()]/@BabelName"/>
              <xsl:text>,</xsl:text>
            </xsl:for-each-group>
            <xsl:value-of
              select="$langs/language
                      [(string-length($baselang)>2
                        and concat(@Lang,'-',@Country)
                        =$baselang)
                       or
                       (string-length($baselang)=2
                        and
                        @Lang=$baselang)]
                      [position()=last()]/@BabelName"/>
          </xsl:variable>
          <xsl:value-of select="$loadedlangs"/>
          <xsl:text>}{babel}% use of other (non-</xsl:text>
          <xsl:value-of select="$baselang"/>
          <xsl:text>) languages&#xa;</xsl:text>
        </xsl:if>
%    \end{macrocode}
% \paragraph[The \textsf{ltxdoc} {\ttfamily{}\textbackslash{}documentclass}]{The \textsf{ltxdoc} {\ttfamily{}\textbackslash{}documentclass} :}
% Finally, output the {\ttfamily{}\textbackslash{}documentclass}
%       command for \textsf{ltxdoc}, with any options
%       taken from the \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}}
%       attribute on the document root element.\par
%    \begin{macrocode}
        <xsl:text>\documentclass</xsl:text>
        <xsl:if test="/db:book/@remap">
          <xsl:text>[</xsl:text>
          <xsl:value-of select="/db:book/@remap"/>
          <xsl:text>]</xsl:text>
        </xsl:if>
        <xsl:text>{ltxdoc}&#xa;</xsl:text>
%    \end{macrocode}
% \subsubsection{Automated package management}
% \emph{AutoPackage} creates a
%     node-set variable called \DescribeVariable{packages}{\ttfamily{}\$packages} listing
%     \emph{all} the packages required
%     \emph{for the documentation}, both those
%     detected by settings in {\ttfamily{}prepost.xml}
%     and those specified manually in the document by the
%     author.\par
% This node-set is in the form of a
%     \texttt{<seglistitem>}\index{seglistitem=\texttt{\char'074 seglistitem\char'076 } (element)}\index{elements:!seglistitem=\texttt{\char'074 seglistitem\char'076 }} for each package — the same format
%     as used in a \emph{ClassPack} file for
%     declaring the author-required packages (see \vref{packagelists}) but using additional
%     attributes to control the loading.\par
% \iffalse
%<*ignore>
% \fi
% \begingroup\advance\hsize by-1em
% \begin{Verbatim}[frame=single,framesep=1em,
%  fontsize=\small]
<seglistitem
    arch="WHY IT’S BEING INSERTED" 
    remap="EXCLUSIONS"
    conformance="{@conformance}" 
    condition="{'off'=DO NOT LOAD}"
    userlevel="LOCATION IN PREPOST.XML"
    annotations="DEPENDENCIES">
  <seg version="YYYY-MM-DD" 
       condition="DOC|CLS|STY"
       role="OPTIONS">PACKAGENAME</seg>
 </seglistitem>
% \end{Verbatim}
% \endgroup
% \iffalse
%</ignore>
% \fi
% The capitalised mnemonics in this template example
%     represent the following values brought over from
%      \begin{enumerate*}[label=\emph{\alph*}),itemjoin={{; }},itemjoin*={{; and }}]
% \item the {\ttfamily{}prepost.xml}
%   database\par
% \item the author’s requests in the document\par
% \end{enumerate*}. The attributes on the \texttt{seglistitem}\index{seglistitem=\texttt{\char'074 seglistitem\char'076 } (element)}\index{elements:!seglistitem=\texttt{\char'074 seglistitem\char'076 }} are:\par
% \begin{enumerate}
% \item \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}} is the
% \emph{AutoPackage} mapping class
% in which the entry in {\ttfamily{}prepost.xml}
% was found that matched, and resulted in this package
% being marked for inclusion;
% \item \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}} is a list of
% package names that will need to be excluded if the
% current package is loaded; for example,
% \textsf{inputenc} and
% \textsf{fontenc} are excluded if
% \textsf{fontspec} is selected (the default
% anyway);
% \item \texttt{@annotations}\index{annotations=\texttt{\char'100 annotations} (attribute)}\index{attributes:!annotations=\texttt{\char'100 annotations}} is a list
% of external dependencies that say how the
% document must be processed, like \texttt{"xelatex"}\index{xelatex=\texttt{"xelatex"} (attribute value)}\index{attribute values:!xelatex=\texttt{"xelatex"}} or \texttt{"biblatex"}\index{biblatex=\texttt{"biblatex"} (attribute value)}\index{attribute values:!biblatex=\texttt{"biblatex"}}.\par
% \item \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} is a copy
% of the \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}}
% attribute on a \texttt{step}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} element
% in {\ttfamily{}prepost.xml} signalling that
% additional code may be required (see \vref{prepost-spec}). This is experimental and
% may be dropped or superseded.\par
% \item \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} if set to
% \texttt{"off"}\index{off=\texttt{"off"} (attribute value)}\index{attribute values:!off=\texttt{"off"}}, the package will not be
% loaded. Not currently used.\par
% \item \texttt{@userlevel}\index{userlevel=\texttt{\char'100 userlevel} (attribute)}\index{attributes:!userlevel=\texttt{\char'100 userlevel}} is a
% decimal number signifying the location in
% {\ttfamily{}prepost.xml} where the packaga
% data was found. The integer part should always be 1,
% representing the first \texttt{procedure}\index{procedure=\texttt{\char'074 procedure\char'076 } (element)}\index{elements:!procedure=\texttt{\char'074 procedure\char'076 }} element
% (pre-package); the decimal part is the numeric
% location of the \texttt{step}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }}
% element within that \texttt{procedure}\index{procedure=\texttt{\char'074 procedure\char'076 } (element)}\index{elements:!procedure=\texttt{\char'074 procedure\char'076 }}. This is used to
% sort the selected packages before output, because
% order in {\ttfamily{}prepost.xml} is
% \emph{significant}.
% \end{enumerate}
% The attributes on the \texttt{seg}\index{seg=\texttt{\char'074 seg\char'076 } (element)}\index{elements:!seg=\texttt{\char'074 seg\char'076 }}
%     element are:\par
% \begin{enumerate}
% \item \texttt{@version}\index{version=\texttt{\char'100 version} (attribute)}\index{attributes:!version=\texttt{\char'100 version}} (optional)
% the version of the package needed to support the
% document being written;
% \item \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} (optional) any
% options needed for loading this package;
% \item \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} is the list
% of document types (\texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}},
% \texttt{"cls"}\index{cls=\texttt{"cls"} (attribute value)}\index{attribute values:!cls=\texttt{"cls"}}, or \texttt{"sty"}\index{sty=\texttt{"sty"} (attribute value)}\index{attribute values:!sty=\texttt{"sty"}}) from
% {\ttfamily{}prepost.xml}\thinspace;
% \item The text content of the \texttt{seg}\index{seg=\texttt{\char'074 seg\char'076 } (element)}\index{elements:!seg=\texttt{\char'074 seg\char'076 }} element is the name of the
% package.
% \end{enumerate}
% The whole tree of the \DescribeVariable{packages}{\ttfamily{}\$packages} variable (all the
%     generated \texttt{seglistitem}\index{seglistitem=\texttt{\char'074 seglistitem\char'076 } (element)}\index{elements:!seglistitem=\texttt{\char'074 seglistitem\char'076 }}\kern1pt{}s is
%     output to the file {\ttfamily{}autopack.xml} as a
%     log of what was used. This is useful when tracing oddities
%     like packages being (or not being) included (or
%     excluded).\par
% \paragraph[Implement the packages]{Implement the packages :}
% If, after all that, there is something to do, output
%       the {\ttfamily{}\textbackslash{}RequirePackage} commands
%       needed.\par
% Go through each package recorded in \DescribeVariable{packages}{\ttfamily{}\$packages}.
%       There may be many matches (multiple ways for a package
%       to be included), but we only want to load the package
%       once, so we group them by name, and sort them by their
%       location in {\ttfamily{}prepost.xml}\thinspace; this lets
%       us control the order (eg the \textsf{dox}
%       package always comes first).\par
% While we’re doing this, we test for how one package
%       can be used to prevent another one from loading
%       (conflicted inclusion): we exclude any package mentioned
%       in the \texttt{<constructorsynopsis>}\index{constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 } (element)}\index{elements:!constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 }} \texttt{\unskip/@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}} of
%       \emph{another} package in the list; this
%       lets us exclude, for example,
%       \textsf{inputenc} and
%       \textsf{fontenc} when
%       \textsf{fontspec} has been selected by the
%       author. We also test for packages to be
%       \emph{excluded} on the grounds of their
%       \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} value.\par
% The inclusion code is generated by the named
%       template \texttt{<packages>}\index{packages=\texttt{\char'074 packages\char'076 } (element)}\index{elements:!packages=\texttt{\char'074 packages\char'076 }} (it gets called
%       from elsewhere in the script as well).\par
%    \begin{macrocode}
        <!-- RATIONALISATION OF ANY PACKAGES DETECTED -->
        <xsl:if test="count($packages/db:seglistitem)>0">
          <!-- They need to be handled in the order in which they occur
               in prepost.xml because that determines the sequence in 
               which packages get loaded. Because packages may occur 
               more than once in $packages (eg loaded by deduction, 
               and loaded by request) we can use grouping to make sure
               multiple entries get handled together. The order from
               prepost.xml is carried in the @userlevel attribute BUT
               this used to be overridden for any packages requested 
               by the author, in order to ensure they come last, but 
               this is probably A Bad Idea and has been reverted, 
               see under APauthorreq -->
          <xsl:text>%%
%% Packages for documentation
%%&#xa;</xsl:text>
          <!-- sort by package userlevel for the order from prepost.xml 
               because it's unique, although a package can still get
               specified multiple times, so within it, sort by 
               @security, which hold the package name requested by 
               the author -->
          <!-- grouping by @userlevel lets us identify duplicates -->
          <xsl:for-each-group select="$packages/db:seglistitem"
            group-by="@userlevel">
            <xsl:sort select="@security"/>
            <!-- maxlevel should no longer be needed -->
            <xsl:variable name="maxlevel"
              select="current-group()
                      [not(current-group()/@userlevel
                           &lt; @userlevel)][1]/@userlevel"/>
            <xsl:choose>
              <!-- OMIT if another entry (not this one)
                   has this package name specified in @remap 
                   eg fontspec will mention inputenc and fontenc
                   both of which need omitting if fontspec is used -->
              <xsl:when
                test="$packages/db:seglistitem
                      [not(@userlevel=current-grouping-key())]
                      [contains(@remap,current-group()[1]/db:seg)]">
                <xsl:text>%% </xsl:text>
                <xsl:value-of select="current-group()[1]/db:seg"/>
                <xsl:text> (</xsl:text>
                <xsl:value-of select="$maxlevel"/>
                <xsl:text>) omitted in favour of </xsl:text>
                <xsl:value-of
                  select="$packages/db:seglistitem
                          [not(@userlevel=current-grouping-key())]
                          [contains(@remap,current-group()[1]/db:seg)]
                          /db:seg"/>
                <xsl:text>&#xa;</xsl:text>
                <xsl:message>
                  <xsl:if test="$maxlevel&lt;100">
                    <xsl:text> </xsl:text>
                    <xsl:if test="$maxlevel&lt;10">
                      <xsl:text> </xsl:text>
                    </xsl:if>
                  </xsl:if>
                  <xsl:value-of select="$maxlevel"/>
                  <xsl:text>. Package '</xsl:text>
                  <xsl:value-of
                    select="current-group()"/>
                  <xsl:text>' (</xsl:text>
                  <xsl:value-of
                    select="count(current-group())"/>
                  <xsl:text>×) omitted: transcluded by </xsl:text>
                  <xsl:value-of
                    select="$packages/db:seglistitem
                            [contains(@remap,current-group()[1]/db:seg)]
                            /db:seg"/>
                </xsl:message>
              </xsl:when>
%    \end{macrocode}
% Where the package has been flagged in the \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} attribute, omit
%       it.\par
%    \begin{macrocode}
              <!-- OMIT packages flagged in conformance 
                   (eg nosc, unclear legacy) -->
              <!--
              <xsl:when
                test="$packages/db:seglistitem
                      [db:seg=current()/@conformance]">
                <xsl:message>
                  <xsl:value-of select="$maxlevel"/>
                  <xsl:text>. Package '</xsl:text>
                  <xsl:value-of
                    select="current-grouping-key()"/>
                  <xsl:text>' (</xsl:text>
                  <xsl:value-of
                    select="count(current-group())"/>
                  <xsl:text>×) omit: </xsl:text>
                  <xsl:text>(conformance="</xsl:text>
                  <xsl:value-of
                    select="$packages/db:seglistitem
                            /db:seg"/>
                  <xsl:text>")</xsl:text>
                </xsl:message>
              </xsl:when>
              -->
              <!-- OTHERWISE USE THE PACKAGE -->
              <xsl:otherwise>
                <xsl:message>
                  <xsl:if test="number($maxlevel)&lt;100">
                    <xsl:text> </xsl:text>
                    <xsl:if test="number($maxlevel)&lt;10">
                      <xsl:text> </xsl:text>
                    </xsl:if>
                  </xsl:if>
                  <xsl:value-of select="$maxlevel"/>
                  <xsl:text>. Package '</xsl:text>
                  <xsl:value-of
                    select="current-group()[1]/db:seg"/>
                  <xsl:text>' (</xsl:text>
                  <xsl:value-of
                    select="count(current-group())"/>
                  <xsl:text>×) being included</xsl:text>
                  <xsl:if
                    test="current-group()[1]/db:seg='inputenc'">
                    <xsl:text>:</xsl:text>
                    <xsl:for-each
                      select="current-group()[@userlevel=$maxlevel][1]">
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="position()"/>
                      <xsl:text>) </xsl:text>
                      <xsl:value-of select="name()"/>
                      <xsl:text>/</xsl:text>
                      <xsl:value-of select="db:seg/@role"/>
                      <xsl:text>:</xsl:text>
                      <xsl:value-of select="$maxlevel"/>
                    </xsl:for-each>
                  </xsl:if>
                </xsl:message>
                <!-- ADD THE PACKAGE -->
                <xsl:call-template name="packages">
                  <!-- for multiply-recurrent packages, ***FIX THIS *** 
                       use the one with the highest userlevel -->
                  <xsl:with-param name="pkg"
                    select="current-group()[@userlevel=$maxlevel][1]"/>
                  <xsl:with-param name="dest" select="'doc'"/>
                  <!-- no cmdblocks on doc packages yet -->
                </xsl:call-template>                
              </xsl:otherwise>
            </xsl:choose>
          </xsl:for-each-group>
        </xsl:if>
%    \end{macrocode}
% \paragraph[Load the current package itself if needed]{Load the current package itself if needed :}
% If the class or package requires itself (perhaps for
%       demonstration or examples) this must be flagged in the
%       \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} root element of the
%       \emph{ClassPack} document by
%       including the \texttt{@xlink:role}\index{xlink:role=\texttt{\char'100 xlink:role} (attribute)}\index{attributes:!xlink:role=\texttt{\char'100 xlink:role}}
%       attribute, set to null (or to the value of options, if
%       required).\par
%    \begin{macrocode}
        <!-- INCLUDE THE PACKAGE BEING CREATED? -->
        <xsl:if test="$doctype='package'
                      and
                      /db:book/@xlink:role">
          <xsl:message>
            <xsl:text>Adding </xsl:text>
            <xsl:value-of select="$name"/>
            <xsl:text> as specified</xsl:text>
          </xsl:message>
          <xsl:text>\usepackage</xsl:text>
          <xsl:if test="/db:book/@xlink:role!=''">
            <xsl:text>[</xsl:text>
            <xsl:value-of select="/db:book/@xlink:role"/>
            <xsl:text>]</xsl:text>
          </xsl:if>
          <xsl:text>{</xsl:text>
          <xsl:value-of select="$name"/>
          <xsl:text>}[</xsl:text>
          <!-- use latest rev date as the distro date -->
          <xsl:value-of select="translate($date,'-','/')"/>
          <xsl:text>]% added by spec&#xa;</xsl:text>
        </xsl:if>
        <!-- End of autopackage -->
%    \end{macrocode}
% \subsubsection{Additional setup commands}
% \paragraph[From the user document]{From the user document :}\label{cmdsynopses}
% \emph{ClassPack} allows authors
%       to add setup commands as shown in \vref{addtosetup}. These are
%       \texttt{<cmdsynopsis>}\index{cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 } (element)}\index{elements:!cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 }} elements at the end of the
%       \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} for \texttt{"docpackages"}\index{docpackages=\texttt{"docpackages"} (attribute value)}\index{attribute values:!docpackages=\texttt{"docpackages"}} — this is where
%       they get added to the {\ttfamily{}.dtx}
%       file.\par
% \label{dtxmainextras}
%    \begin{macrocode}
        <xsl:apply-templates
          select="/db:book/db:info/db:cover
                  /db:constraintdef[@xml:id='docpackages']
                  /db:cmdsynopsis[.!='']"/>
%    \end{macrocode}
% \paragraph[Include the bibliography file]{Include the bibliography file :}
% Add the name of the {\ttfamily{}.bib} file
%       for \textsf{biblatex}, either from the \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} attribute on the
%       \texttt{<bibliography>}\index{bibliography=\texttt{\char'074 bibliography\char'076 } (element)}\index{elements:!bibliography=\texttt{\char'074 bibliography\char'076 }} element, or using the name of
%       the package.\par
%    \begin{macrocode}
        <xsl:if test="//db:bibliography[@arch='biblatex']">
          <xsl:text>\addbibresource{</xsl:text>
          <xsl:choose>
            <xsl:when
              test="//db:bibliography[@arch='biblatex']
                                     [@xlink:href]">
              <xsl:value-of
                select="//db:bibliography[@arch='biblatex']
                        /@xlink:href"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="$docname"/>
              <xsl:text>.bib</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:text>}&#xa;</xsl:text>
        </xsl:if>
%    \end{macrocode}
% \paragraph[Extras from the {\ttfamily{}prepost.xml} 
%       file]{Extras from the {\ttfamily{}prepost.xml} 
%       file :}
% Documentation start-up commands to be executed
%       \emph{before} \verb|\begin{document}| (ie during the
%       Preamble of the {\ttfamily{}.dtx} file) are
%       taken from the {\ttfamily{}prepost.xml}
%       file. The \textsc{pdf} metadata is also
%       inserted here, taking its values from the document, so
%       that it gets processed before the remaining Doc\TeX{}
%       settings and the \verb|\begin{document}|.\par
%    \begin{macrocode}
        <xsl:text>\hypersetup{pdfauthor={</xsl:text>
        <xsl:value-of
          select="normalize-space(/db:book/db:info
                  /db:author/db:personname/db:firstname)"/>
        <xsl:text> </xsl:text>
        <xsl:value-of
          select="normalize-space(/db:book/db:info
                  /db:author/db:personname/db:surname)"/>
        <xsl:text>},
        pdftitle={The </xsl:text>
        <xsl:value-of select="$docname"/>
        <xsl:text> LaTeX2e document </xsl:text>
        <xsl:value-of select="$doctype"/>
        <xsl:text>},
        pdfsubject={</xsl:text>
        <xsl:value-of
          select="normalize-space(/db:book/db:info
                  /db:title)"/>
        <xsl:text>},
        pdfkeywords={</xsl:text>
        <xsl:for-each
          select="/db:book/db:info
                  /db:keywordset/db:keyword">
          <xsl:if test="preceding-sibling::db:keyword">
            <xsl:text>,</xsl:text>
          </xsl:if>
          <xsl:value-of select="."/>
        </xsl:for-each>
        <xsl:text>},
        pdfproducer={XeLateX with hyperref},
        pdfcreator={Emacs/psgml, ClassPack/Saxon, LaTeX/TeX Live}}
</xsl:text>
        <xsl:for-each 
          select="/db:book/db:info/db:cover/db:constraintdef
                    [@xml:id='atendpreamble']
                  /db:procedure/db:step
                   [normalize-space(.)!='']
                  /db:cmdsynopsis/db:command">
          <xsl:value-of select="normalize-space(.)"/>
          <xsl:text>&#xa;</xsl:text>
        </xsl:for-each>
        <xsl:text>%&#xa;</xsl:text>
%    \end{macrocode}
% \paragraph[DocStrip and \LaTeX{}doc settings]{DocStrip and \LaTeX{}doc settings :}
%    \begin{macrocode}
        <xsl:text>%%
%% Settings for docstrip and ltxdoc 
%%
\EnableCrossrefs
\CodelineIndex
\RecordChanges&#xa;</xsl:text>
%    \end{macrocode}
% \paragraph[The {\ttfamily{}\textbackslash{}documentclass} command]{The {\ttfamily{}\textbackslash{}documentclass} command :}
% Any stray commands that cannot conveniently be
%       stored in the proper places but which need to be emitted
%       \emph{immediately} after the
%       \verb|\begin{document}| command are taken
%       from the \texttt{@annotations}\index{annotations=\texttt{\char'100 annotations} (attribute)}\index{attributes:!annotations=\texttt{\char'100 annotations}}
%       attribute on the \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }} root element.\par
%    \begin{macrocode}
        <xsl:text>\begin{document}</xsl:text>
        <xsl:value-of
          select="normalize-space(db:book/@annotations)"/>
        <xsl:text>&#xa;  \DocInput{</xsl:text>
        <xsl:value-of select="$docname"/>
        <xsl:text>.dtx}&#xa;\end{document}&#xa;</xsl:text>
%    \end{macrocode}
% \paragraph[Character-set controls]{Character-set controls :}
% After closing the driver tag that was opened in
%     \vref{maincls}, the checksum is computed and
%       checked, and the character table used as a check on file
%       corruption.\par
%    \begin{macrocode}
        <xsl:text>%&lt;/driver>
% \fi
%
% \CheckSum{</xsl:text>
        <xsl:value-of select="/db:book/@security"/>
        <xsl:text>}
%
% \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
%   Lower-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
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!  Double quote  \"  Hash (number) \#
%   Dollar        \$  Percent       \%  Ampersand     \&amp;
%   Acute accent  \'  Left paren    \(  Right paren   \)
%   Asterisk      \*  Plus          \+  Comma         \,
%   Minus         \-  Point         \.  Solidus       \/
%   Colon         \:  Semicolon     \;  Less than     \&lt;
%   Equals        \=  Greater than  \>  Question mark \?
%   Commercial at \@  Left bracket  \[  Backslash     \\
%   Right bracket \]  Circumflex    \^  Underscore    \_
%   Grave accent  \`  Left brace    \{  Vertical bar  \|
%   Right brace   \}  Tilde         \~}
% &#xa;</xsl:text>
%    \end{macrocode}
% \paragraph[Revision history]{Revision history :}
% Document changes recorded in the
%       \texttt{<revhistory>}\index{revhistory=\texttt{\char'074 revhistory\char'076 } (element)}\index{elements:!revhistory=\texttt{\char'074 revhistory\char'076 }} elements are emitted here for use
%       in the changes section of the documentation.\par
%    \begin{macrocode}
        <xsl:for-each
          select="/db:book/db:info/db:revhistory
                  /db:revision">
          <xsl:text>% \changes{v</xsl:text>
          <xsl:value-of select="@version"/>
          <xsl:text>}{</xsl:text>
          <xsl:value-of
            select="translate(db:date/@YYYY-MM-DD,
                              '-','/')"/>
          <xsl:text>}{</xsl:text>
          <xsl:if test="db:revdescription/
                        (db:itemizedlist|db:orderedlist)
                        /db:title">
            <xsl:value-of 
              select="normalize-space(
                      db:revdescription/
                      (db:itemizedlist|db:orderedlist)
                      /db:title)"/>
            <xsl:text>: </xsl:text>
          </xsl:if>
          <xsl:choose>
            <xsl:when test="db:revdescription/db:para">
              <xsl:for-each select="db:revdescription/db:para">
                <xsl:value-of
                  select="normalize-space(.)"/>
                <xsl:if test="position()>1">
                  <xsl:text> ¶ </xsl:text>
                </xsl:if>
              </xsl:for-each>
            </xsl:when>
            <xsl:when
              test="count(db:revdescription
                    /db:itemizedlist/db:listitem)=1">
              <xsl:value-of 
                select="normalize-space(db:revdescription
                        /db:itemizedlist/db:listitem)"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:for-each 
                select="db:revdescription/db:itemizedlist
                        /db:listitem">
                <xsl:number/>
                <xsl:text>) </xsl:text>
                <xsl:value-of
                  select="normalize-space(db:para)"/>
                <xsl:if
                  test="db:itemizedlist|db:orderedlist">
                  <xsl:text>: </xsl:text>
                  <xsl:for-each
                    select="(db:itemizedlist|db:orderedlist)
                            /db:listitem">
                    <xsl:number format="a"/>
                    <xsl:text>] </xsl:text>
                    <xsl:value-of
                      select="normalize-space(db:para)"/>
                    <xsl:if test="position()!=last()">
                      <xsl:text>, </xsl:text>
                    </xsl:if>
                  </xsl:for-each>
                </xsl:if>
                <xsl:if test="position()!=last()">
                  <xsl:text>; </xsl:text>
                </xsl:if>
              </xsl:for-each>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:text>.}&#xa;</xsl:text>
        </xsl:for-each>
%    \end{macrocode}
% \paragraph[Indexing setup]{Indexing setup :}
% The very long list of indexing
%       \emph{exclusions} is used here to prevent
%       Plain \TeX{} and common \LaTeX{} commands (normally
%       indexed) from being indexed. To this are added any
%       commands in the documentation in the \texttt{<command>}\index{command=\texttt{\char'074 command\char'076 } (element)}\index{elements:!command=\texttt{\char'074 command\char'076 }}
%       elements unless they have a \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute. The intention
%       is that only commands used in the actual class or
%       package should get indexed.\par
%    \begin{macrocode}
        <xsl:text>%
% \GetFileInfo{</xsl:text>
        <xsl:value-of select="$docname"/>
        <xsl:text>.dtx}&#xa;</xsl:text>
        <xsl:text>%
% \DoNotIndex{\@,\@@par,\@beginparpenalty,\@empty}
% \DoNotIndex{\@flushglue,\@gobble,\@input,\@makefnmark}
% \DoNotIndex{\@makeother,\@maketitle,\@namedef,\@ne}
% \DoNotIndex{\@spaces,\@tempa,\@tempb,\@tempswafalse}
% \DoNotIndex{\@tempswatrue,\@thanks,\@thefnmark,\@topnum}
% \DoNotIndex{\@@,\@elt,\@forloop,\@fortmp,\@gtempa}
% \DoNotIndex{\@totalleftmargin,\",\/,\@ifundefined,\@nil}
% \DoNotIndex{\@verbatim,\@vobeyspaces,\|,\~,\ ,\active}
% \DoNotIndex{\advance,\aftergroup,\begingroup,\bgroup}
% \DoNotIndex{\mathcal,\csname,\def,\documentstyle}
% \DoNotIndex{\dospecials,\edef,\egroup,\else,\endcsname}
% \DoNotIndex{\endgroup,\endinput,\endtrivlist}
% \DoNotIndex{\expandafter,\fi,\fnsymbol,\futurelet,\gdef}
% \DoNotIndex{\global,\hbox,\hss,\if,\if@inlabel}
% \DoNotIndex{\if@tempswa,\if@twocolumn,\ifcase,\ifcat}
% \DoNotIndex{\iffalse,\ifx,\ignorespaces,\index,\input}
% \DoNotIndex{\item,\jobname,\kern,\leavevmode,\leftskip}
% \DoNotIndex{\let,\llap,\lower,\m@ne,\next,\newpage}
% \DoNotIndex{\nobreak,\noexpand,\nonfrenchspacing}
% \DoNotIndex{\obeylines,\or,\protect,\raggedleft}
% \DoNotIndex{\rightskip,\rm,\sc,\setbox,\setcounter}
% \DoNotIndex{\small,\space,\string,\strut,\strutbox}
% \DoNotIndex{\thefootnote,\thispagestyle,\topmargin}
% \DoNotIndex{\trivlist,\tt,\twocolumn,\typeout,\vss,\vtop}
% \DoNotIndex{\xdef,\z@,\,,\@bsphack,\@esphack,\@noligs}
% \DoNotIndex{\@vobeyspaces,\@xverbatim,\`,\catcode,\end}
% \DoNotIndex{\escapechar,\frenchspacing,\glossary}
% \DoNotIndex{\hangindent,\hfil,\hfill,\hskip,\hspace,\ht}
% \DoNotIndex{\it,\langle,\leaders,\long,\makelabel}
% \DoNotIndex{\marginpar,\markboth,\mathcode,\mathsurround}
% \DoNotIndex{\mbox,\newcount,\newdimen,\newskip}
% \DoNotIndex{\nopagebreak,\parfillskip,\parindent}
% \DoNotIndex{\parskip,\penalty,\raise,\rangle,\section}
% \DoNotIndex{\setlength,\TeX,\topsep,\underline,\unskip}
% \DoNotIndex{\verb,\vskip,\vspace,\widetilde,\\,\%,\@date}
% \DoNotIndex{\@defpar,\[,\{,\},\],\count@,\ifnum,\loop}
% \DoNotIndex{\today,\uppercase,\uccode,\baselineskip}
% \DoNotIndex{\begin,\tw@,\a,\b,\c,\d,\e,\f,\g,\h,\i,\j,\k}
% \DoNotIndex{\l,\m,\n,\o,\p,\q,\r,\s,\t,\u,\v,\w,\x,\y,\z}
% \DoNotIndex{\A,\B,\C,\D,\E,\F,\G,\H,\I,\J,\K,\L,\M,\N,\O}
% \DoNotIndex{\P,\Q,\R,\S,\T,\U,\V,\W,\X,\Y,\Z,\1,\2,\3,\4}
% \DoNotIndex{\5,\6,\7,\8,\9,\0,\!,\#,\$,\&amp;,\',\(,\)}
% \DoNotIndex{\+,\.,\:,\;,\&lt;,\=,\>,\?,\_,\discretionary}
% \DoNotIndex{\immediate,\makeatletter,\makeatother}
% \DoNotIndex{\meaning,\newenvironment,\par,\relax}
% \DoNotIndex{\renewenvironment,\repeat,\scriptsize}
% \DoNotIndex{\selectfont,\the,\undefined,\arabic,\do}
% \DoNotIndex{\makeindex,\null,\number,\show,\write,\@ehc}
% \DoNotIndex{\@author,\@ehc,\@ifstar,\@sanitize,\@title}
% \DoNotIndex{\everypar,\if@minipage,\if@restonecol,\ifeof}
% \DoNotIndex{\ifmmode,\lccode,\newtoks,\onecolumn,\openin}
% \DoNotIndex{\p@,\SelfDocumenting,\settowidth}
% \DoNotIndex{\@resetonecoltrue,\@resetonecolfalse,\bf}
% \DoNotIndex{\clearpage,\closein,\lowercase,\@tempdima}
% \DoNotIndex{\@inlabelfalse,\selectfont,\mathcode}
% \DoNotIndex{\newmathalphabet,\rmdefault,\bfdefault}
% \DoNotIndex{\DeclareRobustCommand,\@ifpackagewith}
% \DoNotIndex{\#,\%,\&amp;,\*,\-,\^,\_,\|,\~,\$}
% \DoNotIndex{\acro,\addbibresource,\addcontentsline,\addtolength}
% \DoNotIndex{\allowbreak,\alph,\@Alph,\and,\appendix,\arrayrulewidth}
% \DoNotIndex{\ast,\baselinestretch,\bfseries,\bgroup,\Bib,\BibTeX}
% \DoNotIndex{\BiBTeX,\BIBTeX,\bigskip,\box,\caption,\centering,\char}
% \DoNotIndex{\CharacterTable,\CheckSum,\citeyear,\cjktext,\ClassError}
% \DoNotIndex{\classorpackage,\CodelineIndex,\color,\colorbox}
% \DoNotIndex{\columnsep,\columnwidth,\Con,\ConTeXt}
% \DoNotIndex{\CPKannotationindent,\CPKdocname,\CPKdoctype,\CPKmenusep}
% \DoNotIndex{\CPKpoststrut,\CPKprestrut,\CPKrevmarg,\CPKrunningecho}
% \DoNotIndex{\CPKthisjob,\CPKthispackage,\CPKvstrut,\c@section}
% \DoNotIndex{\@currsize,\DeclareOption,\declarepostamble}
% \DoNotIndex{\declarepreamble,\DescribeColor,\DescribeEnv}
% \DoNotIndex{\DescribeError,\DescribeOption,\DescribePackage}
% \DoNotIndex{\DescribeTemplate,\descriptionlabel,\divide,\DoNotIndex}
% \DoNotIndex{\dotfill,\dots,\@dottedtocline,\DoubleperCent,\doxitem}
% \DoNotIndex{\dp,\egroup,\emph,\empty,\EnableCrossrefs}
% \DoNotIndex{\encodingdefault,\endbatchfile,\endpreamble,\enspace}
% \DoNotIndex{\ensuremath,\fa,\fbox,\fboxrule,\fboxsep,\file,\Finale}
% \DoNotIndex{\flushright,\fnote,\font,\fontdimen,\fontencoding}
% \DoNotIndex{\fontfamily,\fontseries,\fontshape,\fontsize,\footnote}
% \DoNotIndex{\footnotesize,\from,\generate,\GetFileInfo,\HandRight}
% \DoNotIndex{\@height,\@@hline,\href,\hrule,\hsize,\huge,\Huge}
% \DoNotIndex{\hyperref,\hypersetup,\hyphenation,\ifdim,\@ifnextchar}
% \DoNotIndex{\itshape,\keepsilent,\keys,\labelenumi,\LabelFont}
% \DoNotIndex{\labelformat,\large,\Large,\LARGE,\LaTeX,\LaTeXe}
% \DoNotIndex{\leftmark,\lfoot,\lhead,\longestline,\lstloadlanguages}
% \DoNotIndex{\l@subsection,\l@subsubsection,\ltx@ifpackageloaded}
% \DoNotIndex{\LyX,\MacroFont,\marginfont,\marginnote,\medskip}
% \DoNotIndex{\menu,\menusep,\message,\MF,\@minus,\MP,\Msg}
% \DoNotIndex{\multirow,\NeedsTeXFormat,\newcommand,\newcounter}
% \DoNotIndex{\newgeometry,\newlength,\newwrite,\nicefrac,\noalign}
% \DoNotIndex{\nocite,\noindent,\nolinkurl,\nopreamble,\normalfont}
% \DoNotIndex{\normalsize,\numberstring,\obeyspaces,\ordinal}
% \DoNotIndex{\PackageError,\pageref,\phantomsection,\@plus}
% \DoNotIndex{\@pnumwidth,\preamble,\PrintChanges}
% \DoNotIndex{\printexternalcurrentfont,\PrintIndex,\Provides}
% \DoNotIndex{\qquad,\quad,\raisebox,\RecordChanges,\reflectbox}
% \DoNotIndex{\refname,\renewcommand,\renewmenumacro,\reserved@a}
% \DoNotIndex{\rightarrow,\rightmark,\rmfamily,\rotatebox,\rule}
% \DoNotIndex{\school,\sloppy,\smallskip,\SMC,\SMC@unknown@warning}
% \DoNotIndex{\Square,\stanza,\star,\@startsection,\stepcounter}
% \DoNotIndex{\StopEventually,\subsubsection,\tableofcontents}
% \DoNotIndex{\textbackslash,\textbf,\textdegree,\texteiad}
% \DoNotIndex{\textheight,\textit,\textlangle,\textrangle,\textsf}
% \DoNotIndex{\textSMC,\textsuperscript,\texttt,\TheSbox}
% \DoNotIndex{\thesection,\thinspace,\tiny,\@tocrmarg}
% \DoNotIndex{\tubhideheight,\tubreflect,\uline,\updefault}
% \DoNotIndex{\upshape,\use@babel,\@usebib,\usedir,\usepostamble}
% \DoNotIndex{\usepreamble,\vbox,\vfill,\vrefrange,\vrule}
% \DoNotIndex{\Xe,\XeLaTeX,\XeTeX,\@xhline}
</xsl:text>
        <!-- add entry for examples unless with spaces -->
        <xsl:for-each-group
          select="//db:command
                  [not(@role)]
                  [not(contains(.,' ') or contains(.,'{'))]" 
          group-by="normalize-space(.)">
          <xsl:text>% \DoNotIndex{\</xsl:text>
          <xsl:value-of select="current-grouping-key()"/>
          <xsl:text>}&#xa;</xsl:text>
        </xsl:for-each-group>
%    \end{macrocode}
% \paragraph[Deferred commands from the user document]{Deferred commands from the user document :}
% Lastly, any startup commands which need to be
%       emitted after the \verb|\begin{document}|
%       command are output here, shielded with
%       {\ttfamily{}\textbackslash{}makeatletter} if needed.\par
%    \begin{macrocode}
        <!-- Documentation start-up commands to execute 
             *after* \begin{document} (ie during the 
             absorption phase of the .dtx file running 
             from \DocInput) -->
        <xsl:for-each 
          select="/db:book/db:info/db:cover
                  /db:constraintdef
                    [@xml:id='atbegindoc']
                  /db:procedure/db:step
                   [normalize-space(.)!='']
                  /db:cmdsynopsis/db:command">
          <xsl:if test="contains(.,'@')">
            <xsl:text>% \makeatletter&#xa;</xsl:text>
          </xsl:if>
          <xsl:text>% </xsl:text>
          <xsl:value-of select="normalize-space(.)"/>
          <xsl:text>&#xa;</xsl:text>
          <xsl:if test="contains(.,'@')">
            <xsl:text>% \makeatother&#xa;</xsl:text>
          </xsl:if>
        </xsl:for-each>
        <xsl:text>%&#xa;</xsl:text>
%    \end{macrocode}
% \subsubsection{Process the document parts}
%    \begin{macrocode}
        <!-- now the fun starts -->
        <xsl:apply-templates 
          select="db:book/db:info | 
                  db:book/db:part[@xml:id='doc'] |
                  db:book/db:part[@xml:id='code'] |
                  db:book/db:part[@xml:id='files']"/>
        <xsl:text>&#xa;</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- end of root templae -->
%    \end{macrocode}
% \subsection{XSLT templates}\label{patterns}
% These templates comprise the transformation mechanism
%   that turns interleaved \textsc{xml} documentation
%   and code into a {\ttfamily{}.dtx} file (and its
%   associates).\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily\label{trace}
% \subsubsection*{Tracing and debugging}
% Many templates (and some recursions within templates)
%     are prefixed by a small amount of tracing code:\par% \iffalse
%<*ignore>
% \fi
% \begingroup\advance\hsize by-1em
% \begin{Verbatim}[frame=single,framesep=1em,
%  fontsize=\small]
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
% \end{Verbatim}
% \endgroup
% \iffalse
%</ignore>
% \fi
% If the parameter \DescribeParameter{trace}{\ttfamily{}\$trace} is passed to the
%     \emph{Saxon} (or other processor) on
%     the command line or in an \textsc{ide}
%     invocation, with any non-null value, tracing will be
%     performed to the console, giving the name of the
%     \emph{DocBook} element type being
%     processed (and its parent element type name, to help in
%     locating it).\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% \subsubsection{Metadata (Preamble)}\label{themetadata}
% This section covers the Abstract and titling, plus a
%     large amount of status-setting and preliminary material
%     that can be specified in the document \texttt{<info>}\index{info=\texttt{\char'074 info\char'076 } (element)}\index{elements:!info=\texttt{\char'074 info\char'076 }}
%     element.\par
% \paragraph[Abstract]{Abstract :}\label{theabstract}
% \begin{CPKtemplate}{db:abstract}\label{template-db2dtx-abstract}
% Create the Abstract as standard \LaTeX{}, changing the
% title if given, and resetting the paragraph gap and
% indent if the \textsf{parskip} package has
% been used.\par
%    \begin{macrocode}
  <xsl:template match="db:info/db:abstract[@role='CTAN']"/>
  
  <xsl:template match="db:legalnotice"/>
  
  <xsl:template match="db:info/db:abstract[not(@role='CTAN')]">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="db:title">
      <xsl:text>% \renewcommand{\abstractname}{</xsl:text>
      <xsl:apply-templates select="db:title/node()"/>
      <xsl:text>}\thispagestyle{empty}&#xa;</xsl:text>
    </xsl:if>
    <xsl:text>% \begin{abstract}&#xa;</xsl:text>
    <!-- if parskip has not been specified, fake it here -->
    <xsl:if
      test="not(//db:constraintdef[@xml:id='docpackages']//
            db:seglistitem/db:seg[.='parskip']
            [@condition='off'])">
      <xsl:text>% \parskip=0.5\baselineskip
% \advance\parskip by 0pt plus 2pt
% \parindent=0pt</xsl:text>
    </xsl:if>
    <xsl:text>% \noindent&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:if test="@xlink:href and not(@xlink:show='none')">
      <xsl:text>% \par\centering
%     \includegraphics[width=.666\columnwidth]{</xsl:text>
      <xsl:value-of select="@xlink:href"/>
      <xsl:text>}&#xa;</xsl:text>
    </xsl:if>
    <xsl:text>% \end{abstract}
% \clearpage
% \tableofcontents&#xa;</xsl:text>
    <xsl:if test="//db:exceptionname">
      <xsl:apply-templates
        select="document('rfc2119.xml')/db:section"/>
    </xsl:if>
    <xsl:apply-templates
      select="document('representation.xml')/db:section"/>
  </xsl:template>
%    \end{macrocode}
% After the Abstract, start a new page and invoke
% the Table of Contents. If there are any uses of
% \texttt{<exceptionname>}\index{exceptionname=\texttt{\char'074 exceptionname\char'076 } (element)}\index{elements:!exceptionname=\texttt{\char'074 exceptionname\char'076 }} in the document, include the
% warning text from {\ttfamily{}rfc2119.xml}\thinspace.
% Finally, include the list of special meanings for
% typographic representation from
% {\ttfamily{}representation.xml}\thinspace.\par
% \end{CPKtemplate}
% \paragraph[Special user definitions]{Special user definitions :}\label{cmysynopses}
% These were a way to deconstruct \LaTeX{} commands in
%       order to provide for greater reusability. However,
%       testing has revealed a low uptake.\par
% \par\begingroup
%   \fboxsep1em\centering
%   \fbox{\begin{minipage}{0.8\columnwidth}\sffamily
%  \raggedright\parindent0pt
%  \parskip=.5\baselineskip\label{deprecated-cmdsynopses}%
% This usage is deprecated as of version 1.18 of
% \emph{ClassPack}. Whole definition
% commands {\sffamily \textsc{should}} now go
% in the code verbatim.\par
% \end{minipage}}\par\endgroup
% \begin{CPKtemplate}{db:cmdsynopsis}\label{template-db2dtx-cmdsynopsis}
% The \texttt{<cmdsynopsis>}\index{cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 } (element)}\index{elements:!cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 }} element holds any special
% user definitions for the documentation, called in \vref{cmdsynopses}.\par
% Start this block with
% {\ttfamily{}\textbackslash{}makeatletter} if the command contains
% an `at' sign
% ({\ttfamily{}@}), then proceed by
% category.\par
% \label{cmdsynopsis}
%    \begin{macrocode}
  <xsl:template match="db:cmdsynopsis">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="position()=1
                  and
                  ../db:cmdsynopsis[contains(.,'@')]">
      <xsl:text>\makeatletter&#xa;</xsl:text>
    </xsl:if>
%    \end{macrocode}
% Commands to be emitted as they stand.\par
%    \begin{macrocode}
    <xsl:choose>
      <xsl:when test="db:command/@role='asis'">
        <xsl:value-of select="db:command"/>
        <xsl:text>&#xa;</xsl:text>
      </xsl:when>
%    \end{macrocode}
% New output files.\par
%    \begin{macrocode}
      <!-- new \write files: new: no arg -->
      <xsl:when test="db:command/@remap='write'">
        <xsl:text>\newwrite\</xsl:text>
        <xsl:value-of select="db:command"/>
        <xsl:text>&#xa;</xsl:text>
      </xsl:when>
%    \end{macrocode}
% New counters.\par
%    \begin{macrocode}
      <!-- new counters -->
      <xsl:when test="db:command/@remap='counter'">
        <xsl:text>\newcounter{</xsl:text>
        <xsl:value-of select="db:command"/>
        <xsl:text>}</xsl:text>
        <xsl:if test="db:arg">
          <xsl:text>\setcounter{</xsl:text>
          <xsl:value-of select="db:command"/>
          <xsl:text>}{</xsl:text>
          <xsl:value-of select="db:arg"/>
          <xsl:text>}</xsl:text>
        </xsl:if>
        <xsl:text>&#xa;</xsl:text>
      </xsl:when>
%    \end{macrocode}
% New lengths.\par
%    \begin{macrocode}
      <!-- new lengths -->
      <xsl:when test="db:command/@remap='length'">
        <xsl:text>\newlength{\</xsl:text>
        <xsl:value-of select="db:command"/>
        <xsl:text>}</xsl:text>
        <xsl:if test="db:arg">
          <xsl:text>\setlength{\</xsl:text>
          <xsl:value-of select="db:command"/>
          <xsl:text>}{</xsl:text>
          <xsl:value-of select="db:arg"/>
          <xsl:text>}</xsl:text>
        </xsl:if>
        <xsl:text>&#xa;</xsl:text>
      </xsl:when>
%    \end{macrocode}
% Plain \TeX{} commands, possibly with arguments.\par
%    \begin{macrocode}
      <!-- plain TeX commands -->
      <xsl:when test="@language='TeX'">
        <xsl:if test="@role='long'">
          <xsl:text>\long</xsl:text>
        </xsl:if>
        <xsl:text>\def\</xsl:text>
        <xsl:value-of select="db:command"/>
        <xsl:if test="db:arg/@wordsize">
          <xsl:call-template name="repeatarg">
            <xsl:with-param name="limit"
              select="db:arg/@wordsize"/>
            <xsl:with-param name="prefix" 
              select="substring(db:arg/@annotations,1,
                      (string-length(db:arg/@annotations)
                      div 2))"/>
            <xsl:with-param name="suffix" 
              select="substring(db:arg/@annotations,
                      (string-length(db:arg/@annotations)
                      div 2)+1)"/>
          </xsl:call-template>
        </xsl:if>
        <xsl:choose>
          <xsl:when test="db:arg/@remap">
            <xsl:text>{</xsl:text>
            <xsl:value-of 
              select="/db:book/@*[name()=current()
                                  /db:arg/@remap]"/>
            <xsl:text>}&#xa;</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>{%&#xa;&#9;</xsl:text>
            <xsl:value-of select="db:arg"/>
            <xsl:text>}&#xa;</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
%    \end{macrocode}
% New or renewed \LaTeX{} environments.\par
%    \begin{macrocode}
      <xsl:when test="db:command/@remap='environment'
                      and count(db:command/db:arg)=2">
        <xsl:choose>
          <xsl:when test="db:command/@role='renew'">
            <xsl:text>\renewenvironment{</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>\newenvironment{</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:value-of select="db:command"/>
        <xsl:text>}</xsl:text>
        <!-- number of arguments, if any -->
        <xsl:if test="db:arg[1]/@wordsize">
          <xsl:text>[</xsl:text>
          <xsl:value-of select="db:arg[1]/@wordsize"/>
          <xsl:text>]</xsl:text>
        </xsl:if>
        <xsl:text>{%&#xa;&#9;</xsl:text>
        <xsl:value-of select="db:arg[1]"/>
        <xsl:text>}&#xa;</xsl:text>
        <xsl:text>{%&#xa;&#9;</xsl:text>
        <xsl:value-of select="db:arg[2]"/>
        <xsl:text>}&#xa;</xsl:text>
      </xsl:when>
%    \end{macrocode}
% Anything else is considered a new or renewed \LaTeX{}
% command.\par
%    \begin{macrocode}
      <!-- LaTeX commands -->
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="db:command/@role='renew'">
            <xsl:text>\renewcommand{\</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>\newcommand{\</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:value-of select="db:command"/>
        <xsl:text>}</xsl:text>
        <!-- number of arguments, if any -->
        <xsl:if test="db:arg/@wordsize">
          <xsl:text>[</xsl:text>
          <xsl:value-of select="db:arg/@wordsize"/>
          <xsl:text>]</xsl:text>
          <xsl:if test="db:arg/@condition">
          <xsl:text>[</xsl:text>
          <xsl:value-of select="db:arg/@condition"/>
          <xsl:text>]</xsl:text>            
          </xsl:if>
        </xsl:if>
        <xsl:choose>
          <!-- remap is a reference to an attribute of the
               root element, eg arch means use @arch -->
          <xsl:when test="db:arg/@remap">
            <xsl:text>{</xsl:text>
            <xsl:value-of 
              select="/db:book/@*[name()=
                              current()/db:arg/@remap]"/>
            <xsl:text>}&#xa;</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>{%&#xa;&#9;</xsl:text>
            <xsl:value-of select="db:arg"/>
            <xsl:text>}&#xa;</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
%    \end{macrocode}
% End the block with {\ttfamily{}\textbackslash{}makeatother} if
% needed.\par
%    \begin{macrocode}
    </xsl:choose>
    <xsl:if test="position()=last()
                  and
                  ../db:cmdsynopsis[contains(.,'@')]">
      <xsl:text>\makeatother&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[User notification of start]{User notification of start :}\label{notification}
% \begin{CPKtemplate}{db:info}\label{template-db2dtx-info}
% Issue notification of the document type and
% version, then process the contents of the
% \texttt{<info>}\index{info=\texttt{\char'074 info\char'076 } (element)}\index{elements:!info=\texttt{\char'074 info\char'076 }} element.\par
%    \begin{macrocode}
   <xsl:template match="db:info">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:message>
      <xsl:text>Creating </xsl:text>
      <xsl:value-of select="$doctype"/>
      <xsl:text> '</xsl:text>
      <xsl:value-of select="$docname"/>
      <xsl:text>' (v</xsl:text>
      <xsl:value-of select="$version"/>
      <xsl:text>.</xsl:text>
      <xsl:value-of select="$revision"/>
      <xsl:text>) with checksum </xsl:text>
      <xsl:value-of select="/db:book/@security"/>
      <xsl:text>.</xsl:text>
    </xsl:message>
    <xsl:apply-templates/>
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Finished </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
  </xsl:template>

  <!-- <cover> has already been processed at the start -->
  <xsl:template match="db:cover"/>
%    \end{macrocode}
% We omit the the cover settings, which were done
% earlier as part of the titling.\par
% \end{CPKtemplate}
% \paragraph[Document title and author]{Document title and author :}\label{titling}
% The title block on the class or package
%       documentation starts with a fixed-format title
%       `The \uline{docname} \LaTeXe{}
% \uline{doctype}', with the
%       content of the \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }} and \texttt{<subtitle>}\index{subtitle=\texttt{\char'074 subtitle\char'076 } (element)}\index{elements:!subtitle=\texttt{\char'074 subtitle\char'076 }}
%       elements from the \texttt{<info>}\index{info=\texttt{\char'074 info\char'076 } (element)}\index{elements:!info=\texttt{\char'074 info\char'076 }} element of the
%       \textsc{xml} document being added as separate
%       lines. The {\ttfamily{}\textbackslash{}thanks} footnotes are
%       inserted after the fixed-format title. Author is less
%       intricate; the date is always the default \LaTeX{}
%       date.\par
% \subparagraph[Document date and version for titling]{Document date and version for titling  ◦}\label{datever}
% \begin{CPKtemplate}[noprint]{db:title}\label{template-db2dtx-title1}
% \begingroup\raggedright[in \url{db:info/} 
% ]\par\endgroup
% For the metadata title (title of the class or
%   package), if this is a class, or a package which has not
%   been preloaded for the documentation, ensure the
%   {\ttfamily{}\textbackslash{}fileversion} and
%   {\ttfamily{}\textbackslash{}filedate} values are made
%   available.\par
%    \begin{macrocode}
  <xsl:template match="db:info/db:title">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="/db:book/@arch='package' or
                  not(/db:book/@xlink:role)">
      <xsl:text>% \def\fileversion{</xsl:text>
      <xsl:value-of select="/db:book/@version"/>
      <xsl:text>.</xsl:text>
      <xsl:value-of select="/db:book/@revision"/>
      <xsl:text>}&#xa;% \def\filedate{</xsl:text>
      <xsl:value-of 
        select="translate(/db:book/db:info
                /db:revhistory/db:revision
                [@version=max(parent::db:revhistory
                              /db:revision/@version)]
                /db:date/@YYYY-MM-DD,'-','/')"/>
      <xsl:text>}&#xa;</xsl:text>
    </xsl:if>
%    \end{macrocode}
% \end{CPKtemplate}
% \subparagraph[Fixed title]{Fixed title  ◦}\label{fixedtitle}
% \begin{CPKtemplate}[noprint]{db:title}\label{template-db2dtx-title2}
% Construct the formal {\ttfamily{}\textbackslash{}title},
%   with the name of the document type.\par
%    \begin{macrocode}
    <xsl:text>% \title{The </xsl:text>
    <xsl:text> \textsf{</xsl:text>
    <xsl:value-of select="$docname"/>
    <xsl:text>} </xsl:text>
    <xsl:choose>
      <xsl:when test="/db:book/@arch='script'">
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>\LaTeXe\ </xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="$doctype='class'">
        <xsl:text>document class</xsl:text>
        <xsl:if
          test="count(//db:part//db:appendix
                [substring-after(@xlink:href,'.')
                 = 'cls'])>1">
          <xsl:text>es</xsl:text>
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$doctype"/>
      </xsl:otherwise>
    </xsl:choose>
%    \end{macrocode}
% \end{CPKtemplate}
% \subparagraph[Footnotes for title page]{Footnotes for title page  ◦}\label{thanks}
% \begin{CPKtemplate}[noprint]{db:title}\label{template-db2dtx-title3}
% Add a {\ttfamily{}\textbackslash{}thanks} footnote for the
%   version, and another if there is a sponsor to
%   credit.\par
%    \begin{macrocode}
    <xsl:text>\thanks{%
% This document corresponds to </xsl:text>
    <xsl:text>\textsf{</xsl:text>
    <xsl:value-of select="$docname"/>
    <xsl:text>}&#xa;% \textit{v.}\ \fileversion </xsl:text>
    <xsl:choose>
      <xsl:when test="/db:book/@status='alpha' or
                      /db:book/@status='beta'">
        <xsl:text>$\</xsl:text>
        <xsl:value-of select="/db:book/@status"/>
        <xsl:text>$</xsl:text>
      </xsl:when>
      <!-- alpha, beta, delta (draft), phi (final), 
           or pi (production) -->
      <xsl:when test="/db:book/@status='α' or
                      /db:book/@status='β' or
                      /db:book/@status='δ' or
                      /db:book/@status='φ' or
                      /db:book/@status='π'">
        <xsl:value-of select="/db:book/@status"/>
      </xsl:when>
      <xsl:when test="/db:book/@status">
        <xsl:value-of select="/db:book/@status"/>
      </xsl:when>
    </xsl:choose>
    <xsl:text>, dated \filedate.}</xsl:text>
    <!-- add second note for sponsors -->
    <xsl:if test="ancestor::db:info/descendant::db:author/
                  db:contrib[@role='sponsor']">
      <xsl:text>\enspace\thanks{%
% Supported by </xsl:text>
      <xsl:for-each 
        select="ancestor::db:info/descendant::db:author/
                db:contrib[@role='sponsor']">
        <xsl:if test="position()>1">
          <xsl:text>, </xsl:text>
          <xsl:if test="position()=last()">
            <xsl:text>and </xsl:text>
          </xsl:if>
        </xsl:if>
        <xsl:apply-templates/>
      </xsl:for-each>
      <xsl:text>.}</xsl:text>
    </xsl:if>
%    \end{macrocode}
% \end{CPKtemplate}
% \subparagraph[Explanatory title]{Explanatory title  ◦}\label{subtitling}
% \begin{CPKtemplate}[noprint]{db:title}\label{template-db2dtx-title4}
% Use the contents of the
%   \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }} element as the explanatory subtitle
%   (and any \texttt{<subtitle>}\index{subtitle=\texttt{\char'074 subtitle\char'076 } (element)}\index{elements:!subtitle=\texttt{\char'074 subtitle\char'076 }} as a second line; exclude
%   the \texttt{<subtitle>}\index{subtitle=\texttt{\char'074 subtitle\char'076 } (element)}\index{elements:!subtitle=\texttt{\char'074 subtitle\char'076 }} from additional processing).\par
%    \begin{macrocode}
    <xsl:text>&#xa;% \\[1em]\Large &#xa;% </xsl:text>
    <xsl:apply-templates/>
    <xsl:if test="following-sibling::db:subtitle
                  [not(@role='labelonly')]">
      <xsl:text>&#xa;% \\[1ex]\large &#xa;% </xsl:text>
      <xsl:apply-templates
        select="following-sibling::db:subtitle/node()"/>
    </xsl:if>
    <xsl:text>}&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="db:info/db:subtitle"/>
  <xsl:template match="db:info/db:titleabbrev"/>
  
  <xsl:variable name="shorttitle">
    <xsl:choose>
      <xsl:when test="/db:book/db:info/db:titleabbrev">
        <xsl:value-of select="/db:book/db:info/db:titleabbrev/node()"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="/db:book/db:info/db:title/node()"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
%    \end{macrocode}
% A \texttt{<titleabbrev>}\index{titleabbrev=\texttt{\char'074 titleabbrev\char'076 } (element)}\index{elements:!titleabbrev=\texttt{\char'074 titleabbrev\char'076 }} element can be used to
%   mark a short title used in the spotlight metadata of
%   the associated web page.\par
% \end{CPKtemplate}
% \subparagraph[Authors]{Authors  ◦}\label{authoring}
% \begin{CPKtemplate}[noprint]{db:author}\label{template-db2dtx-author}
% \begingroup\raggedright[in \url{db:info//} 
% ]\par\endgroup
% To cater for multiple authors, output the
%   {\ttfamily{}\textbackslash{}author} command before the first
%   author, process the names, add titles and/or
%   affiliations, then repeat for next author, and
%   output the {\ttfamily{}\textbackslash{}maketitle} after the last
%   one.\par
%    \begin{macrocode}
  <xsl:template match="db:info//db:author">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="count(preceding-sibling::db:author)=0">
      <xsl:text>% \author{</xsl:text>
    </xsl:if>
    <xsl:for-each select="db:personname/db:*">
      <xsl:apply-templates/>
      <xsl:if test="position()!=last()">
        <xsl:text> </xsl:text>
      </xsl:if>
    </xsl:for-each>
    <xsl:apply-templates
      select="db:honorific | db:affiliation"/>
    <xsl:if test="db:email">
      <xsl:text>\\\normalsize(\url{</xsl:text>
      <xsl:value-of select="db:email"/>
      <xsl:text>})</xsl:text>
    </xsl:if>
    <xsl:choose>
      <xsl:when test="following-sibling::db:author">
        <xsl:text>&#xa;% \and&#xa;% </xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>}&#xa;% \maketitle&#xa;</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}[noprint]{db:honorific}\label{template-db2dtx-honorific}
% Decapitalise honorifics (eg degrees) so they can
%   go in small caps.\par
%    \begin{macrocode}
  <xsl:template match="db:honorific">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:text> \textsc{</xsl:text>
    <xsl:value-of
      select="translate(.,
              'ABCDEFGHIJKLMN0PQRSTUVWXYZ',
              'abcdefghijklmn0pqrstuvwxyz')"/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}[noprint]{db:affiliation}\label{template-db2dtx-affiliation}
% Capitalise affiliations likewise, on separate
%   lines. This is legacy code from UCC and may not be
%   needed any more.\par
%    \begin{macrocode}
  <xsl:template match="db:affiliation">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:text>\\\normalsize </xsl:text>
    <xsl:for-each select="db:*">
      <xsl:value-of select="normalize-space(.)"/>
      <!-- capitalisation for Centre, Hospital, Unit,
           Project, and maybe others -->
      <xsl:if test="@remap">
        <xsl:text> </xsl:text>
        <xsl:value-of 
          select="translate(substring(@remap,1,1),
                  'cuhp','CUHP')"/>
        <xsl:value-of select="substring(@remap,2)"/>
      </xsl:if>
      <xsl:if test="position()!=last()">
        <xsl:text>\\[-.25ex]\normalsize </xsl:text>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subparagraph[Elements ignores in document order]{Elements ignores in document order  ◦}\label{defaults}
% \begin{CPKtemplate}[noprint]{db:releaseinfo}\label{template-db2dtx-releaseinfo}
% \begingroup\raggedright[in \url{db:info/} 
% and \url{db:info/db:annotation} 
% and \url{db:info/db:revhistory} 
% and \url{db:info/db:copyright} 
% ]\par\endgroup
% Ignore elements handled elsewhere.\par
%    \begin{macrocode}
  <xsl:template match="db:info/db:releaseinfo | 
                       db:info/db:annotation |
                       db:info/db:revhistory |
                       db:info/db:copyright"/>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection{Hierarchy}\label{thehierarchy}
% \begin{CPKtemplate}{db:preface}\label{template-db2dtx-preface}
% Normal prefaces have a title and get a ToC entry.
%       With no title they are treated informally and centered
%       (eg for `thanks'
%       sections). An \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} will
%     be used as a label, if present.\par
%    \begin{macrocode}
  <xsl:template match="db:preface">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:choose>
      <xsl:when test="db:title">
        <xsl:text>% \clearpage\section*{</xsl:text>
        <xsl:apply-templates select="db:title/node()"/>
        <xsl:text>}\addcontentsline{toc}</xsl:text>
        <xsl:text>{subsection}{</xsl:text>
        <xsl:apply-templates select="db:title/node()"/>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>% \clearpage\null\vfill</xsl:text>
        <xsl:text>\begingroup\centering</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:if test="not(db:title)">
      <xsl:text>% \par\endgroup\vfill&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:part}\label{template-db2dtx-part}
% There are three possible parts, identified in their
%       \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute as \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}}, \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}}, and \texttt{"files"}\index{files=\texttt{"files"} (attribute value)}\index{attribute values:!files=\texttt{"files"}}, as explained in \vref{struct}.\par
%    \begin{macrocode}
  <xsl:template match="db:part">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:choose>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:part}\quad}Documentation}\label{partdoc}\addcontentsline{toc}{subparagraph}{Documentation}
% For the documentation, output a `Latest
%     changes' section first, before the content, and
%     add the bibliography at the end if needed.\par
%    \begin{macrocode}
      <xsl:when test="@xml:id='doc'">
        <xsl:text>% \clearpage&#xa;</xsl:text>
        <xsl:text>% \section*{Latest changes}&#xa;</xsl:text>
        <xsl:apply-templates
          select="//db:revhistory/db:revision
                  [@version=$latestrevhist]"/>
        <xsl:for-each
          select="//db:revhistory/db:revision
                  [@version!=$latestrevhist]">
          <xsl:sort select="db:date/@YYYY-MM-DD"
            order="descending"/>
          <xsl:if test="position()&lt;4">
            <xsl:apply-templates select="."/>
          </xsl:if>
        </xsl:for-each>
        <xsl:text>% \par\bigskip
%     See p.\thinspace\pageref{</xsl:text>
        <xsl:value-of
          select="/db:book/db:info/db:revhistory/@xml:id"/>
        <xsl:text>} for earlier changes.&#xa;</xsl:text>
        <xsl:apply-templates/>
        <xsl:if
          test="not(db:bibliography) and
                descendant::db:exceptionname and
                (not(@conformance)
                 or
                 (@conformance!='xelatex' and
                  @conformance!='lualatex'))">
          <xsl:text>% \bibliography{</xsl:text>
          <xsl:value-of select="$docname"/>
          <xsl:text>}\bibliographystyle{apalike}%&#xa;</xsl:text>
        </xsl:if>
      </xsl:when>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:part}\quad}Code}\label{partcode}\addcontentsline{toc}{subparagraph}{Code}
% Output the termination for the documentation,
%     resetting the margin width and
%     including the change history and the index.\par
%    \begin{macrocode}
      <xsl:when test="@xml:id='code'"> 
      <!-- the invocation of \newgeometry has been withdrawn -->
      <xsl:text>% \StopEventually{\label{endcode}%
%   \clearpage
%   \addcontentsline{toc}{section}{Change History}%
%   \label{</xsl:text>
        <xsl:value-of
          select="/db:book/db:info/db:revhistory/@xml:id"/>
        <xsl:text>}%
%   \PrintChanges
%   \clearpage
%   \label{codeindex}%
%   \addcontentsline{toc}{section}{Index}%
%   \PrintIndex}&#xa;</xsl:text>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:part}\quad}Margin width
%       calculation}\label{margwidth}\addcontentsline{toc}{subparagraph}{Margin width calculation}
% \label{calcwidth}The margin width is recalculated
%       to take account of the widest marginal macro or other
%       tag name, outputting it as a \LaTeX{} length to be set at
%       run time. The longest length is found by iteration
%       through commands and environment variables to be
%       referenced, in order of length, longest first.\par
%    \begin{macrocode}
        <!-- Calculate margin width from longest string -->
        <!-- WITHDRAWN 2024-02-04
        <xsl:for-each-group group-by="normalize-space(.)"
          select="descendant::db:command
                  [@role and not(@xml:lang or 
                   contains(.,'[') or contains(.,'{'))]
                  | 
                  descendant::db:envar
                  [@role and not(@xml:lang or 
                   contains(.,'[') or contains(.,'{'))]
                  |
                  descendant::db:tag[@role]
                  |
                  descendant::db:varname[@role]
                  |
                  descendant::db:classname[@role]
                  |
                  descendant::db:package[@role]
                  |
                  descendant::db:annotation/@xreflabel">
          <xsl:sort
            select="string-length(current-grouping-key())" 
            data-type="number" order="descending"/>
          <xsl:if test="position()=1">
            <xsl:text>% \divide\CPKrevmarg by2 &#xa;</xsl:text>
            <xsl:text>% \addtolength{\CPKrevmarg}{%&#xa;</xsl:text>
            <xsl:text>%   \widthof{\LabelFont{</xsl:text>
            <xsl:value-of select="current-grouping-key()"/>
            <xsl:text>}}}
% \newgeometry{left=\CPKrevmarg}&#xa;</xsl:text>
            <xsl:text>% \message{Margin reset to </xsl:text>
            <xsl:text>\the\CPKrevmarg, to fit &lt;</xsl:text>
            <xsl:value-of select="current-grouping-key()"/>
            <xsl:text>>}&#xa;</xsl:text>
            <xsl:text>% \makeatletter\ltx@ifpackageloaded{fancyhdr}
% {\lhead{\footnotesize\rightmark}\lfoot{\footnotesize\leftmark}}
% {\relax}\makeatother&#xa;</xsl:text>
          </xsl:if>
        </xsl:for-each-group>
        end of withdrawn margin recalc code -->
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:part}\quad}Code content}\label{codecont}\addcontentsline{toc}{subparagraph}{Code content}
% The code part could be a monolith (no chapters) so
%       it would all be one package or class. But if (usually)
%       it has chapters, the tags for the primary output need to
%       be set round the chapters, and any appendices will be
%       separately-annotated ancillary files.\par
% Prerequisites like the \textsf{fix-cm}
%       package\footnote{%
% The \textsf{fixltx2e} package is no
%   longer needed as it is now coded into the
%   kernel.\par} and any \textsf{xcolor} swatch
%       options need to be output here, before anything else, so
%       they get handled while we process the content of this
%       part, starting with the chapters which are the primary
%       content (see \vref{chapter}).\par
%    \begin{macrocode}
        <xsl:if test="count(db:chapter)=0">
          <xsl:text>% \label{</xsl:text>
          <xsl:value-of select="@xml:id"/>
          <xsl:text>}&#xa;</xsl:text>
          <xsl:call-template name="start-tag">
            <xsl:with-param name="identity">
              <xsl:value-of select="$doctype"/>
            </xsl:with-param>
          </xsl:call-template>
        </xsl:if>
        <xsl:text>% \clearpage\subsection*{Code for the </xsl:text>
        <xsl:apply-templates select="db:title/node()"/>
        <xsl:text>}&#xa;</xsl:text>
        <xsl:apply-templates/>
        <xsl:if test="count(db:chapter) +
                      count(db:appendix) = 0">
          <xsl:call-template name="end-tag">
            <xsl:with-param name="identity">
              <xsl:value-of select="$doctype"/>
            </xsl:with-param>
          </xsl:call-template>
        </xsl:if>
%    \end{macrocode}
% Again, if there were no chapters or appendixes,
%       output the end-tag now.\par
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:part}\quad}Licence}\label{licence}\addcontentsline{toc}{subparagraph}{Licence}
% Once the code has been done, and before any
%       standalone ancillary files are processed, we output the
%       Licence as an appendix. As we are in a \texttt{<part>}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }},
%       the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute may
%       contain the white-space-separated name[s] of [an]
%       externally-generated \emph{DocBook}
%       document[s] to be included as an annexes (with their own
%       generated markup at the \texttt{<chapter>}\index{chapter=\texttt{\char'074 chapter\char'076 } (element)}\index{elements:!chapter=\texttt{\char'074 chapter\char'076 }} level to
%       ensure formatting as appendices.\par
% \label{partcodelicence}
%    \begin{macrocode}
        <xsl:if test="not(//db:appendix)">
          <xsl:text>% \appendix&#xa;</xsl:text>
        </xsl:if>
        <!-- WITHDRAWN 2024-02-04
        <xsl:text>% \newgeometry{left=3cm}
% \makeatletter\ltx@ifpackageloaded{fancyhdr}
% {\lhead{\leavevmode\kern-\CPKrevmarg\footnotesize\rightmark}
%  \lfoot{\leavevmode\kern-\CPKrevmarg\footnotesize\leftmark}}
% {\relax}\makeatother&#xa;</xsl:text>
        -->
        <xsl:apply-templates select="$licence"/>
        <xsl:if test="@role">
          <xsl:for-each
            select="tokenize(normalize-space(@role),
                    ' ')">
            <xsl:apply-templates
              select="document(concat($appdir,'/',.,'.xml'))
                      /db:chapter"/>
          </xsl:for-each>
        </xsl:if>
      </xsl:when>
%    \end{macrocode}
% OMITTED: any delayed-output extractable files from
%       the code part (these need no accompanying text as
%       they’re just re-given here for extraction).\par
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:part}\quad}Files}\label{fileshead}\addcontentsline{toc}{subparagraph}{Files}
% Here we output any plain files that do not require
%       Doc\TeX{}-style pre- or postamble.\par
% There can in fact (\texttt{<xsl:otherwise>}\index{xsl:otherwise=\texttt{\char'074 xsl:otherwise\char'076 } (element)}\index{elements:!xsl:otherwise=\texttt{\char'074 xsl:otherwise\char'076 }}) be a
%       fourth kind of part, currently used only in the
%       \textsf{uccthesis} package: a \texttt{"data"}\index{data=\texttt{"data"} (attribute value)}\index{attribute values:!data=\texttt{"data"}} part, currently
%       undocumented.\par
%    \begin{macrocode}
      <xsl:when test="@xml:id='files'">
        <xsl:apply-templates mode="files"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message>
          <xsl:text>WARNING: part element being used </xsl:text>
          <xsl:text>that is not doc/code/files</xsl:text>
        </xsl:message>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="count(following-sibling::db:part
                  [@xml:id!='data'])=0">
      <xsl:text>% \Finale&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="db:part[@xml:id='code']/db:subtitle"/>
%    \end{macrocode}
% If there are only non-\texttt{"data"}\index{data=\texttt{"data"} (attribute value)}\index{attribute values:!data=\texttt{"data"}} parts following, we’re
%       done.\par
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:chapter}\label{chapter}
% If this is the first chapter of a \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}} or \texttt{"files"}\index{files=\texttt{"files"} (attribute value)}\index{attribute values:!files=\texttt{"files"}} part, output the
%       start-tag. Check for the location of
%       \emph{AutoPackage} output.\par
%    \begin{macrocode}
  <xsl:template match="db:chapter[not(@condition='draft')]">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
        <xsl:text>@</xsl:text>
        <xsl:value-of select="@xml:id"/>
      </xsl:message>
    </xsl:if>
    <!-- non-empty only -->
    <xsl:if test="normalize-space(.)!=''">
      <xsl:choose>
        <!-- first one in code is THE package or class 
             so use that value as the tag -->
        <xsl:when
          test="parent::db:part[@xml:id='code'] and
                count(preceding-sibling::db:chapter)=0">
          <xsl:call-template name="start-tag">
            <xsl:with-param name="identity">
              <xsl:value-of select="$doctype"/>
            </xsl:with-param>
          </xsl:call-template>
        </xsl:when>
        <!-- in files, use the ID as the tag -->
        <xsl:when
          test="parent::db:part[@xml:id='files']
                and
                db:programlisting
                and
                @xml:id
                and
                @xlink:href">
          <xsl:call-template name="start-tag"/>
        </xsl:when>
      </xsl:choose>
      <xsl:call-template name="checkpackages">
        <xsl:with-param name="pos" select="'before'"/>
        <xsl:with-param name="loc" select="."/>
      </xsl:call-template>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:chapter}\quad}Chapter starts}\label{chapstart}\addcontentsline{toc}{subparagraph}{Chapter starts}
% Chapters are the normal subdivision within each
%       part, output as \LaTeX{} {\ttfamily{}\textbackslash{}section}s;
%       there may be an optional subtitle, version, and
%       label.\par
%    \begin{macrocode}
      <xsl:if test="count(preceding-sibling::db:chapter)>0">
        <xsl:text>% \clearpage&#xa;</xsl:text>
      </xsl:if>
      <xsl:text>% \section</xsl:text>
      <!-- subtitle is used for short title -->
      <xsl:if test="db:subtitle">
        <xsl:text>[</xsl:text>
        <xsl:apply-templates select="db:subtitle/node()"/>
        <xsl:text>]</xsl:text>
      </xsl:if>
      <xsl:text>{</xsl:text>
      <xsl:apply-templates select="db:title/node()"/>
      <xsl:if test="db:subtitle">
        <xsl:text>~--- </xsl:text>
        <xsl:apply-templates select="db:subtitle/node()"/>
      </xsl:if>
      <xsl:if test="@version">
        <xsl:text> (v\thinspace{}</xsl:text>
        <xsl:value-of select="@version"/>
        <xsl:text>)</xsl:text>
      </xsl:if>
      <xsl:text>}</xsl:text>
      <xsl:if test="@xml:id">
        <xsl:text>\label{</xsl:text>
        <xsl:value-of select="@xml:id"/>
        <xsl:text>}</xsl:text>
      </xsl:if>
      <xsl:text>&#xa;</xsl:text>
      <!-- echo the title/subtitle into comments
           IFF this is NOT a DTD, XML, or XSL file -->
      <xsl:if 
        test="parent::db:part[@xml:id='code']
              and @xlink:href 
              and @xml:id 
              and not(substring-after(@xlink:href,'.')='dtd' 
                or substring-after(@xlink:href,'.')='xml' 
                or substring-after(@xlink:href,'.')='xsl')">
        <xsl:text>% \iffalse&#xa;</xsl:text>
        <xsl:value-of select="$sentinel"/>
        <xsl:text>&#xa;</xsl:text>
        <xsl:apply-templates select="db:title|db:subtitle" 
          mode="readme"/>
        <xsl:text>% \fi&#xa;</xsl:text>
      </xsl:if>
      <!-- start the chapter -->
      <xsl:call-template name="makechapapp"/>
    </xsl:if>
%    \end{macrocode}
% The title is also output as a plaintext comment if
%       this is a chapter in code with an ID and a link for
%       output that is not \textsc{xml},
%       \textsc{xslt}, or
%       \textsc{dtd}\index{DTD}.\par
% The actual output of chapter content is handled by
%       the \DescribeTemplate{makechapapp}{\ttfamily{}makechapapp} template (see
%       \vref{makechapapp}).\par
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:chapter}\quad}Chapter ends}\label{chapend}\addcontentsline{toc}{subparagraph}{Chapter ends}
% Regardless of whether or not it had any content,
%       close the Doc\TeX{} tag if this is the last chapter, or
%       close the {\ttfamily{}files} tag if this
%       chapter is in the \texttt{"files"}\index{files=\texttt{"files"} (attribute value)}\index{attribute values:!files=\texttt{"files"}}
%       part.\par
%    \begin{macrocode}
    <xsl:choose>
      <xsl:when 
        test="parent::db:part[@xml:id='code'] and
              count(following-sibling::db:chapter)=0">
        <xsl:call-template name="end-tag">
          <xsl:with-param name="identity">
            <xsl:value-of select="$doctype"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:when 
        test="parent::db:part[@xml:id='files'] 
              and
              db:programlisting 
              and 
              @xml:id 
              and 
              @xlink:href">
        <xsl:call-template name="end-tag"/>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:appendix}\label{template-db2dtx-appendix}
% Appendixes can be used in documentation, but are
%       also used to hold annotated extractable ancillary files,
%       as part of a \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}}
%       part.\par
% If this is the first appendix, issue the
%       {\ttfamily{}\textbackslash{}appendix} \LaTeX{} switch for the
%       documentation, and adjust the automated cross-reference
%       name for sections to `Appendix'.
%       If this is in the code part, and the appendix also
%       contains code, and has an ID and a link, tag it for
%       extraction. Create the title, with optional subtitle and
%       label.\par
%    \begin{macrocode}
  <!-- ANNOTATED FILES ARE APPENDIXES
       in the code part
       (in the file part, unannotated files are chapters)
       but you might have documentary appendices in the
       documentation -->
  <xsl:template match="db:appendix">
    <!-- ignore empty (placeholder) appendixes -->
    <xsl:if test="normalize-space(.)!=''">
      <!-- LaTeX switch to appendix handling in docs
           for the first one -->
      <xsl:if 
        test="count(preceding-sibling::db:appendix)=0 and
              ancestor::db:part/@xml:id='doc'">
        <xsl:text>% \appendix\labelformat{section}</xsl:text>
        <xsl:text>{Appendix~#1}&#xa;</xsl:text>
      </xsl:if>
      <!-- insert latexdoc start-tag for annotated code -->
      <xsl:if test="parent::db:part[@xml:id='code'] 
                    and 
                    descendant::db:programlisting 
                    and 
                    @xlink:href
                    and 
                    @xml:id">
        <xsl:call-template name="start-tag"/>
      </xsl:if>
      <!-- TITLE and SUBTITLE -->
      <xsl:text>% \clearpage&#xa;% \section</xsl:text>
      <xsl:if test="db:subtitle">
        <xsl:text>[</xsl:text>
        <xsl:apply-templates select="db:title/node()"/>
        <xsl:text>]</xsl:text>
      </xsl:if>
      <xsl:text>{</xsl:text>
      <xsl:apply-templates select="db:title/node()"/>
      <xsl:if test="db:subtitle">
        <xsl:text>~--- </xsl:text>
        <xsl:apply-templates select="db:subtitle/node()"/>
      </xsl:if>
      <xsl:text>}</xsl:text>
      <!-- LABEL -->
      <xsl:if test="@xml:id">
        <xsl:text>\label{</xsl:text>
        <xsl:value-of select="@xml:id"/>
        <xsl:text>}</xsl:text>
      </xsl:if>
      <xsl:text>&#xa;</xsl:text>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:appendix}\quad}Processing}\label{appproc}\addcontentsline{toc}{subparagraph}{Processing}
% Finally, call \DescribeTemplate{makechapapp}{\ttfamily{}makechapapp} for the content
%       as with chapters.\par
%    \begin{macrocode}
      <!-- start the appendix -->
      <xsl:call-template name="makechapapp"/>
      <xsl:if
        test="parent::db:part[@xml:id='code'] 
              and descendant::db:programlisting 
              and @xlink:href and @xml:id">
        <xsl:call-template name="end-tag"/>
      </xsl:if>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{startappcomment}\label{template-db2dtx-startappcomment}
% Prefix extracted files with a comment to show
%       provenance, date, and time.\par
%    \begin{macrocode}
  <xsl:template name="startappcomment">
    <xsl:param name="scriptflag"/>
      <!-- non-script = 'no'
           script, first line not done yet = 'wait'
           script, first line done = "go" -->
    <!-- prefix extracted files with a comment to show
         provenance, date, and time (context is <appendix>);
         THE EXCEPTION is shell scripts where the comment is
         delayed until after the first line for hashbang 
         reasons -->
    <xsl:if test="$scriptflag='no' or $scriptflag='go'">
      <xsl:text>% \begin{CPKcomment}{</xsl:text>
      <xsl:value-of select="ancestor-or-self::db:appendix/@xml:id"/>
      <xsl:text>-comment}</xsl:text>
      <xsl:text>\label{comment-</xsl:text>
      <xsl:value-of select="ancestor-or-self::db:appendix/@xml:id"/>
      <xsl:text>}&#xa;</xsl:text>
      <!-- IDENTITY COMMENT -->
      <xsl:text>% Identify the file origin,
% date, time, etc.\par&#xa;</xsl:text>
      <xsl:text>%    \begin</xsl:text>
      <xsl:text>{macrocode}&#xa;</xsl:text>
      <xsl:value-of select="sil:sentinel(.)"/>
      <xsl:text> </xsl:text>
      <xsl:value-of select="normalize-space(
        ancestor-or-self::db:appendix/db:title)"/>
      <xsl:if test="ancestor-or-self::db:appendix/db:subtitle">
        <xsl:text>: </xsl:text>
        <xsl:value-of select="normalize-space(
          ancestor-or-self::db:appendix/db:subtitle)"/>
      </xsl:if>
      <xsl:text> (from the </xsl:text>
      <xsl:value-of select="$docname"/>
      <xsl:text> </xsl:text>
      <xsl:value-of select="$doctype"/>
      <xsl:text> v.</xsl:text>
      <xsl:value-of select="$version"/>
      <xsl:text>.</xsl:text>
      <xsl:value-of select="$revision"/>
      <xsl:text>, </xsl:text>
      <xsl:value-of select="$date"/>
      <xsl:text>) </xsl:text>
      <xsl:value-of select="sil:termcommentchar(.)"/>
      <xsl:text>&#xa;</xsl:text>
      <xsl:value-of select="sil:sentinel(.)"/>
      <xsl:text> Generated by ClassPack v.</xsl:text>
      <xsl:value-of select="$thisversion"/>
      <xsl:text> (</xsl:text>
      <xsl:value-of select="$thisverdate"/>
      <xsl:text>) on </xsl:text>
      <!--
      <xsl:value-of
        select="format-dateTime(current-dateTime(),
                '[D] [MNn] [Y] at [H]:[m]:[s] ')"/>
      -->
      <xsl:value-of
        select="format-dateTime(current-dateTime(),
                '[Y03]-[M01]-[D01]T[H01]:[m01]:[s01] ')"/>
      <xsl:value-of select="sil:termcommentchar(.)"/>
      <xsl:text>&#xa;</xsl:text>
      <xsl:text>%    \end</xsl:text>
      <xsl:text>{macrocode}&#xa;</xsl:text>
      <xsl:text>% These lines are automatically prepended to the file
% and may be removed if necessary,
% using a suitable editor.&#xa;</xsl:text>
      <xsl:text>% \end{CPKcomment}&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% This also gets called from the routine handling
%       extracted fragments of a shell script, to preserve the
%       hashbang line.\par
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:sect1}\label{template-db2dtx-sect11}
% In sections, check the package insertions, and allow
%       a new page. In code parts, add the title in comments as
%       for chapters. After handling content, check package
%       insertions again.\par
%    \begin{macrocode}
  <xsl:template match="db:sect1">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="normalize-space(.)!=''">
      <xsl:call-template name="checkpackages">
        <xsl:with-param name="pos" select="'before'"/>
        <xsl:with-param name="loc" select="."/>
      </xsl:call-template>
      <xsl:if test="@condition='newpage'">
        <xsl:text>% \clearpage&#xa;</xsl:text>
      </xsl:if>
      <xsl:text>% \subsection</xsl:text>
      <!-- is @label for a * or an [alt]? -->
      <xsl:value-of select="@label"/>
      <xsl:text>{</xsl:text>
      <xsl:apply-templates select="db:title/node()"/>
      <xsl:text>}</xsl:text>
      <xsl:if test="@xml:id">
        <xsl:text>\label{</xsl:text>
        <xsl:value-of select="@xml:id"/>
        <xsl:text>}</xsl:text>
      </xsl:if>
      <xsl:text>&#xa;</xsl:text>
      <xsl:if test="ancestor::db:part[@xml:id='code']">
        <xsl:choose>
          <xsl:when test="ancestor-or-self::db:chapter">
            <xsl:text>% \iffalse&#xa;%% &#xa;</xsl:text>
            <xsl:call-template name="makefence"/>
            <xsl:text>%% &#xa;</xsl:text>
            <xsl:apply-templates mode="readme"
              select="db:title|db:subtitle"/>
            <xsl:if test="@xml:id='options'
                          and not(db:annotation)
                          and count(db:para)=1">
              <xsl:text>%%
%% There are no package options.&#xa;</xsl:text>
            </xsl:if>
            <xsl:text>% \fi&#xa;</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <!--
            <xsl:value-of select="sil:commentchar(.)"/>
            <xsl:apply-templates mode="readme"
              select="db:title|db:subtitle"/>
            <xsl:value-of select="sil:termcommentchar(.)"/>
            -->
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
      <!-- process sect1 content -->
      <xsl:apply-templates/>
      <xsl:if test="@xml:id='options'">
        <xsl:text>% Now invoke the options.\par
% \iffalse
%% Now invoke the options.
% \fi
%    \begin{macrocode}
\ExecuteOptions{</xsl:text>
        <xsl:value-of
          select="descendant::db:annotation
                  [@condition='default']/@xreflabel"/>
        <xsl:text>}
        \ProcessOptions\relax&#xa;%    \end</xsl:text>
        <xsl:text>{macrocode}&#xa;</xsl:text>
      </xsl:if>
      <xsl:call-template name="checkpackages">
        <xsl:with-param name="pos" select="'after'"/>
        <xsl:with-param name="loc" select="."/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:sect2}\label{template-db2dtx-sect2}
% Works the same way as for \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }}, but
%       outputting content only for non-\textsc{xml}
%       files (and \textsc{xsl}/\textsc{dtd}\index{DTD}
%       files).\par
%    \begin{macrocode}
  <xsl:template match="db:sect2">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="normalize-space(.)!=''">
      <xsl:call-template name="checkpackages">
        <xsl:with-param name="pos" select="'before'"/>
        <xsl:with-param name="loc" select="."/>
      </xsl:call-template>
      <xsl:text>% \subsubsection{</xsl:text>
      <xsl:apply-templates select="db:title/node()"/>
      <xsl:text>}</xsl:text>
      <xsl:if test="@xml:id">
        <xsl:text>\label{</xsl:text>
        <xsl:value-of select="@xml:id"/>
        <xsl:text>}</xsl:text>
      </xsl:if>
      <xsl:text>&#xa;</xsl:text>
      <xsl:if 
        test="ancestor::db:part[@xml:id='code'] and
              ancestor::db:chapter/@xlink:href  and
              ancestor::db:chapter/@xml:id and
              not(substring-after(
               ancestor::db:chapter/@xlink:href,'.')='dtd' 
            or substring-after(
               ancestor::db:chapter/@xlink:href,'.')='xml' 
            or substring-after(
               ancestor::db:chapter/@xlink:href,'.')='xsl')">
        <xsl:text>% \iffalse&#xa;%% &#xa;</xsl:text>
        <xsl:apply-templates mode="readme"
          select="db:title|db:subtitle"/>
        <xsl:text>% \fi&#xa;</xsl:text>
      </xsl:if>
      <xsl:apply-templates/>
      <xsl:call-template name="checkpackages">
        <xsl:with-param name="pos" select="'after'"/>
        <xsl:with-param name="loc" select="."/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:sect3}\label{template-db2dtx-sect3}
% These output like \texttt{<sect2>}\index{sect2=\texttt{\char'074 sect2\char'076 } (element)}\index{elements:!sect2=\texttt{\char'074 sect2\char'076 }} but as
%       {\ttfamily{}\textbackslash{}paragraph} commands, and add a colon
%       when there is no existing terminating punctuation.\par
%    \begin{macrocode}
  <xsl:template match="db:sect3">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="normalize-space(.)!=''">
      <xsl:call-template name="checkpackages">
        <xsl:with-param name="pos" select="'before'"/>
        <xsl:with-param name="loc" select="."/>
      </xsl:call-template>
      <xsl:text>% \paragraph[</xsl:text>
      <xsl:apply-templates select="db:title/node()"/>
      <xsl:text>]{</xsl:text>
      <xsl:apply-templates select="db:title/node()"/>
      <xsl:if test="not(matches(normalize-space(db:title),
                    '[:\-–—•]$'))">
        <xsl:text> :</xsl:text>
      </xsl:if>
      <xsl:text>}</xsl:text>
      <xsl:if test="@xml:id">
        <xsl:text>\label{</xsl:text>
        <xsl:value-of select="@xml:id"/>
        <xsl:text>}</xsl:text>
      </xsl:if>
      <xsl:text>&#xa;</xsl:text>
      <xsl:apply-templates/>
      <xsl:call-template name="checkpackages">
        <xsl:with-param name="pos" select="'after'"/>
        <xsl:with-param name="loc" select="."/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:sect4}\label{template-db2dtx-sect4}
% The {\ttfamily{}\textbackslash{}subparagraph} does exactly the
%       same, but with a different bullet.\par
%    \begin{macrocode}
  <xsl:template match="db:sect4">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="normalize-space(.)!=''">
      <xsl:call-template name="checkpackages">
        <xsl:with-param name="pos" select="'before'"/>
        <xsl:with-param name="loc" select="."/>
      </xsl:call-template>
      <xsl:text>% \subparagraph[</xsl:text>
      <xsl:apply-templates select="db:title/node()"/>
      <xsl:text>]{</xsl:text>
      <xsl:apply-templates select="db:title/node()"/>
      <xsl:if test="not(matches(normalize-space(db:title),
                    '[:\-–—•]$'))">
        <xsl:text>  ◦</xsl:text>
      </xsl:if>
      <xsl:text>}</xsl:text>
      <xsl:if test="@xml:id">
        <xsl:text>\label{</xsl:text>
        <xsl:value-of select="@xml:id"/>
        <xsl:text>}</xsl:text>
      </xsl:if>
      <xsl:text>&#xa;</xsl:text>
      <xsl:apply-templates/>
      <xsl:call-template name="checkpackages">
        <xsl:with-param name="pos" select="'after'"/>
        <xsl:with-param name="loc" select="."/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:section}\label{template-db2dtx-section}
% The \texttt{<section>}\index{section=\texttt{\char'074 section\char'076 } (element)}\index{elements:!section=\texttt{\char'074 section\char'076 }} element can only be used in
%     prelims (eg Prefaces).\par
%    \begin{macrocode}
  <xsl:template
    match="db:section/db:title
           [name(parent::db:section/parent::*[1])='']"/>
           
  <xsl:template match="db:section">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:if test="@role='newpage'">
      <xsl:text>% \clearpage&#xa;</xsl:text>
    </xsl:if>
    <xsl:text>% \subsection*{</xsl:text>
    <xsl:apply-templates select="db:title/node()"/>
    <xsl:text>}</xsl:text>
    <xsl:if test="@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
    <xsl:apply-templates/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:title}\label{template-db2dtx-title5}
% \begingroup\raggedright[in \url{db:info/db:abstract/} 
% and \url{db:preface/db:title} 
% and \url{db:preface/db:section/db:title} 
% and \url{db:part/db:title} 
% and \url{db:chapter/db:title} 
% and \url{db:chapter/db:subtitle} 
% and \url{db:chapter/db:sect1/db:title} 
% and \url{db:chapter//db:sect2/db:title} 
% and \url{db:chapter//db:sect3/db:title} 
% and \url{db:chapter//db:sect4/db:title} 
% and \url{db:appendix/db:title} 
% and \url{db:appendix/db:sect1/db:title} 
% and \url{db:appendix//db:sect2/db:title} 
% and \url{db:appendix//db:sect3/db:title} 
% and \url{db:appendix//db:sect4/db:title} 
% ]\par\endgroup
% Titles within hierarchy elements are handled within
%       the code for their parent element, so they must be
%       excluded from being processed in document order.\par
%    \begin{macrocode}
  <xsl:template
    match="db:info/db:abstract/db:title | 
           db:preface/db:title |
           db:preface/db:section/db:title |
           db:part/db:title |
           db:chapter/db:title | db:chapter/db:subtitle |
           db:chapter/db:sect1/db:title |
           db:chapter//db:sect2/db:title |
           db:chapter//db:sect3/db:title |
           db:chapter//db:sect4/db:title |
           db:appendix/db:title |
           db:appendix/db:subtitle |
           db:appendix/db:sect1/db:title |
           db:appendix//db:sect2/db:title |
           db:appendix//db:sect3/db:title |
           db:appendix//db:sect4/db:title"/>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection{Pool}\label{thepool}
% These are the document components inside the hierarchy
%     elements. The author selects the elements required from
%     this pool.\par
% \paragraph[Acknowledgements]{Acknowledgements :}\label{acknowledgements}
% \begin{CPKtemplate}{db:acknowledgements}\label{template-db2dtx-acknowledgements}
% Acknowledgements are just a subsection of the
% documentation. Like all sections/subsections, the
% location for handling the
% \emph{AutoPackage} call is tested
% after processing to see if this is the place.\par
%    \begin{macrocode}
  <xsl:template match="db:acknowledgements">
    <xsl:text>% \subsection*{Acknowledgments}</xsl:text>
    <xsl:if test="@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:call-template name="checkpackages">
      <xsl:with-param name="pos" select="'after'"/>
      <xsl:with-param name="loc" select="."/>
    </xsl:call-template>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Paragraphs]{Paragraphs :}\label{para}
% \begin{CPKtemplate}{db:para}\label{template-db2dtx-para1}
% This handles all paragraphs at any level. See
% below for details of automated list-item
% punctuation.\par
% Normally (in the \texttt{<xsl:otherwise>}\index{xsl:otherwise=\texttt{\char'074 xsl:otherwise\char'076 } (element)}\index{elements:!xsl:otherwise=\texttt{\char'074 xsl:otherwise\char'076 }}) a
% percent-space is output, and also if this paragraph is
% coming from a procedure from the
% {\ttfamily{}prepost.xml} file; but omit it for
% the first paragraph in a list item or a table cell
% because it has already been handled by the
% container.\par
%    \begin{macrocode}
  <xsl:template match="db:para">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:choose>
      <!-- paras from prepost.xml need shielding -->
      <xsl:when
        test="ancestor::db:procedure
              [@xml:id='prepackage'
               or
               @xml:id='postpackage']">
        <xsl:text>% </xsl:text>
      </xsl:when>
      <!-- first paras in list items do nothing WHY? -->
      <xsl:when
        test="(parent::db:listitem or parent::db:step) and
               count(preceding-sibling::db:para)=0">
        <xsl:text></xsl:text>
      </xsl:when>
      <!-- first paras in table cells likewise -->
      <xsl:when test="parent::db:entry and position()=1">
        <xsl:text></xsl:text>
      </xsl:when>
      <!-- all others get a shield -->
      <xsl:otherwise>
        <xsl:text>% </xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <!-- labels on paras (rare) get output at start -->
    <xsl:if test="@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <!-- any typographic mods start here, end afterwards -->
    <xsl:if test="@remap">
      <xsl:text>{</xsl:text>
      <xsl:value-of select="@remap"/>
    </xsl:if>
    <!-- now the content -->
    <xsl:apply-templates/>
%    \end{macrocode}
% Add a label if there was an \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}}, and add any manual
% reformatting in the \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}}
% attribute, then process the content.\par
% \end{CPKtemplate}
% \subparagraph[Auto-punctuation for list items]{Auto-punctuation for list items  ◦}\label{autopunct}
% \begin{CPKtemplate}[noprint]{autopunct}\label{template-db2dtx-autopunct}
% Add punctuation if this is the sole or last
%   paragraph in a list item, and it does
%   \emph{not} end with its own
%   punctuation, and it is not followed by punctuation
%   \emph{immediately} at the end of its
%   scope (eg manually-supplied punctuation after the
%   end-tag of an inline list [within a
%   paragraph]).\par
% The punctuation added is a semicolon (to all but
%   the last paragraph), or a full point (to the last
%   paragraph).\par
% None of this applies if the list is
%   \emph{inside} a paragraph (an inline
%   list) because the inline features of \LaTeX{}'s
%   \textsf{enumitem} package already handle
%   it correctly.\par
%    \begin{macrocode}
    <!-- then the fun starts -->
    <xsl:choose>
      <!-- AUTOPUNCT: para elements in lists (NOT inline) which 
             * do NOT end with their own punctuation 
               AND 
             * the container does NOT start with punctuation 
               OR
             * there is nothing in scope after the container
           -->
      <xsl:when
        test="(parent::db:listitem[not(ancestor::db:para)]
               or
              parent::db:step[not(ancestor::db:para)])
              and 
              not(contains(',.;:!?',
                  substring(normalize-space(.),
                  string-length(normalize-space(.)))))
              and
              (
                not(contains(',.;:!?',
                  substring(normalize-space(
                    (
                    ancestor::db:itemizedlist[1] | 
                    ancestor::db:orderedlist[1] |
                    ancestor::db:variablelist[1] |
                    ancestor::db:procedure[1]
                    )[1]/
                    following-sibling::node()[1]),1,1)))
                or
                not(  (
                    ancestor::db:itemizedlist[1] | 
                    ancestor::db:orderedlist[1] |
                    ancestor::db:variablelist[1] |
                    ancestor::db:procedure[1]
                    )[1]/
                    following-sibling::node())
              )">
        <!-- if that is TRUE then munge the punct -->
        <xsl:choose>
          <!-- if last in the item, add semicolon or period -->
          <xsl:when
            test="not(following-sibling::db:para)">
            <xsl:choose>
              <xsl:when
                test="parent::db:listitem/
                      following-sibling::db:listitem
                      or
                      ancestor::db:varlistentry[1]/
                      following-sibling::db:varlistentry
                      or
                      parent::db:step/
                      following-sibling::db:step">
                <xsl:text>;</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>.</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <!-- if not the last one, use a \par -->
          <xsl:otherwise>
            <xsl:text>\par </xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- paras in prepost.xml don't get autopunct -->
      <xsl:when 
        test="(parent::db:step/parent::db:procedure
              [@xml:id='prepackage']
              or
              parent::db:step/parent::db:procedure
              [@xml:id='postpackage'])
              and
              not(following-sibling::db:para)">
        <xsl:text></xsl:text>
      </xsl:when>
      <!-- everything else gets a \par -->
      <xsl:otherwise>
        <xsl:text>\par</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <!-- close off any formatting changes -->
    <xsl:if test="@remap">
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:if test="not(parent::db:note
                      or 
                      parent::db:footnote
                      or 
                      parent::db:entry)">
      <xsl:text>&#xa;</xsl:text>
      <xsl:if test="parent::db:entry">
        <xsl:text> </xsl:text>
      </xsl:if>
    </xsl:if>
%    \end{macrocode}
% Omit the {\ttfamily{}\textbackslash{}par} if this is the
%   last or sole paragraph in an auto-included
%   documentation chunk from
%   {\ttfamily{}prepost.xml}\thinspace, otherwise output
%   it. Terminate any local formatting.\par
% In the case of notes, footnotes, and cell
%   content we don’t even want a newline, but we do need
%   a space after {\ttfamily{}\textbackslash{}par} in the case of
%   cell content.\par
% \end{CPKtemplate}
% \subparagraph[Inline documentation in code]{Inline documentation in code  ◦}\label{inlinedoc}
% \begin{CPKtemplate}[noprint]{inlinedoc}\label{template-db2dtx-inlinedoc}
% The inline documentation echo (except for
%   footnotes, which get done inline in
%   {\ttfamily{}db2md.xsl}) which gets added to
%   the {\ttfamily{}dtx} file as comments, is
%   done in {\ttfamily{}readme} mode.\par
%    \begin{macrocode}
  <!-- add plaintext documentation that will go through to the 
       class or style file being generated. Don't do this here
       for the para of a warning or sidebar because that will
       still be inside a minipage. See the warning|sidebar
       template.
       IFF
       * it's in the code
       * it's not a footnote
       * it's in a chapter being output
       * it's in an ID'd chapter
       * it's not DTD/XML/XSL
       * it's not in a warning or sidebar
       (these are ANDed, so it means all of them!) -->
    <xsl:if 
      test="ancestor::db:part[@xml:id='code'] 
            and not(parent::db:footnote)
            and ancestor::db:chapter[@xlink:href]
            and ancestor::db:chapter[@xml:id]
            and not(
            substring-after(ancestor::db:chapter
             /@xlink:href,'.')='dtd' 
         or substring-after(ancestor::db:chapter
             /@xlink:href,'.')='xml' 
         or substring-after(ancestor::db:chapter
             /@xlink:href,'.')='xsl')
            and not(parent::db:warning)
            and not(parent::db:sidebar)">
      <xsl:text>% \iffalse&#xa;</xsl:text>
      <xsl:apply-templates select="." mode="readme"/>
      <xsl:text>% \fi&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% Note that this only affects paragraphs in the
%   \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}} part which are
%   \emph{not} in footnotes but
%   \emph{are} in a chapter with a \texttt{@href}\index{href=\texttt{\char'100 href} (attribute)}\index{attributes:!href=\texttt{\char'100 href}} and \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} and are
%   \emph{not} part of a
%   \textsc{dtd}\index{DTD}, \textsc{xml}, or
%   \textsc{xsl} document.\par
% \end{CPKtemplate}
% \paragraph[Inline literals]{Inline literals :}
% \begin{CPKtemplate}{db:literal}\label{template-db2dtx-literal}
% Literals are formatted in a monospace font except
% those flagged as \LaTeX{}, which are passed through
% as-is for processing.\par
%    \begin{macrocode}
  <xsl:template match="db:literal[not(@language='LaTeXe')
                       and not(@language='LaTeX')]">
    <xsl:call-template name="avoidverb"/>
  </xsl:template>

  <xsl:template match="db:literal[@language='LaTeXe'
                       or @language='LaTeX']">
    <xsl:value-of select="."/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Block quotations]{Block quotations :}
% \begin{CPKtemplate}{db:blockquote}\label{template-db2dtx-blockquote}
% Block quotes use the \texttt{quotation}
% environment, with an optional citation and link at the
% end.\par
%    \begin{macrocode}
  <xsl:template match="db:blockquote">
    <xsl:text>% \begin{quotation}</xsl:text>
    <xsl:if test="@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>\small\sffamily\parindent0pt
%   \parskip.5\baselineskip
%   \color{DarkBlue}</xsl:text>
    <xsl:if test="@remap">
      <xsl:value-of select="@remap"/>
    </xsl:if>
    <xsl:text>\noindent&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:if test="@linkend">
      <xsl:text>% \hfill\begingroup</xsl:text>
      <xsl:call-template name="makeref"/>
      <xsl:text>\parfillskip=0pt\parskip=0pt\par</xsl:text>
      <xsl:text>\endgroup&#xa;</xsl:text>
    </xsl:if>
    <xsl:if test="@xlink:href">
      <xsl:text>% \hfill\begingroup
%   \scriptsize\color{Black}\url{</xsl:text>
      <xsl:value-of select="@xlink:href"/>
      <xsl:text>}\parfillskip=0pt\par</xsl:text>
      <xsl:text>\endgroup&#xa;</xsl:text>
    </xsl:if>
    <xsl:text>% \end{quotation}&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Warnings and sidebars]{Warnings and sidebars :}
% \begin{CPKtemplate}{db:warning}\label{template-db2dtx-warning1}
% \begingroup\raggedright[\url{db:warning} 
% and \url{db:sidebar} 
% and \url{db:warning/db:title} 
% and \url{db:sidebar/db:title} 
% and \url{db:sidebar/db:address} 
% and \url{db:bridgehead} 
% ]\par\endgroup
% Warnings and sidebars are handled similarly, the
% difference being that sidebars use a drop-shadow box.
% The width of the box can be controlled with the \texttt{@wordsize}\index{wordsize=\texttt{\char'100 wordsize} (attribute)}\index{attributes:!wordsize=\texttt{\char'100 wordsize}} attribute, holding
% a percentage of the text width (default
% 80\%).\footnote{%
% Note that this is a different usage to that in
%     tables, where the attribute affects \emph{font
%       size}.\par}\par
%    \begin{macrocode}
  <xsl:template match="db:warning | db:sidebar">
    <xsl:call-template name="sidewarn"/>
  </xsl:template>

  <!-- named template used to allow "files" chapters 
       to share this code from within mode="files" -->

  <xsl:template name="sidewarn">
    <xsl:text>% \par\begingroup
%   \fboxsep1em\centering&#xa;%   \</xsl:text>
    <xsl:choose>
      <xsl:when test="name()='sidebar'">
        <xsl:text>shadowbox</xsl:text>
      </xsl:when>
      <xsl:when test="name()='warning'">
        <xsl:text>fbox</xsl:text>
      </xsl:when>
    </xsl:choose>
    <xsl:text>{\begin{minipage}{</xsl:text>
    <xsl:choose>
      <xsl:when test="@wordsize">
        <xsl:value-of 
          select="number(substring-before(@wordsize,'%'))
                  div 100"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>0.8</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>\columnwidth}\sffamily
%  \raggedright\parindent0pt
%  \parskip=.5\baselineskip</xsl:text>
    <xsl:if test="@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}%</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>% \end{minipage}}\par\endgroup&#xa;</xsl:text>
    <!-- now is the time to output the content in a form
         that will pass through to the sty or cls file. -->
    <!-- not working yet
    <xsl:text>% \iffalse&#xa;%% !!! </xsl:text>
    <xsl:apply-templates select="db:para" mode="readme"/>
    <xsl:text>% \fi&#xa;</xsl:text>
-->
  </xsl:template>

  <xsl:template match="db:warning/db:title
                       |
                       db:sidebar/db:title">
    <xsl:text>% \subsubsection*{\sffamily </xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="db:sidebar/db:address">
    <xsl:text>% \par\raggedleft </xsl:text>
    <xsl:apply-templates/>
    <xsl:text>\par&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="db:bridgehead">
    <xsl:text>% \subsubsection*{</xsl:text>
    <xsl:if test="parent::db:annotation">
      <!--
      <xsl:text>\protect\CPKrunningecho{</xsl:text>
      <xsl:value-of
        select="parent::db:annotation/@xreflabel"/>
      <xsl:text>}</xsl:text>
      -->
      <xsl:text>\llap{\color{OliveDrab}\LabelFont{</xsl:text>
      <xsl:value-of
        select="parent::db:annotation/@xreflabel"/>
      <xsl:text>}\quad}</xsl:text>
    </xsl:if>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
    <xsl:if test="@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}\addcontentsline{toc}</xsl:text>
      <xsl:text>{subparagraph}{</xsl:text>
      <xsl:value-of select="normalize-space(.)"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% Titles, addresses, and bridgeheads (for embedded
% headings) are subsubsection-level elements or
% paragraphs.\par
% \end{CPKtemplate}
% \paragraph[Annotations]{Annotations :}
% \begin{CPKtemplate}{db:annotation}\label{noreuseannotation}
% \begingroup\raggedright[\url{db:annotation} with \url{[not(@reuse)] [@role and @role!='' and @xreflabel] [not(@annotations)][not(ancestor::db:info)]} 
% ]\par\endgroup
% The \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} element is used to
% document a code fragment, often a whole macro
% definition. The \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}}
% attribute holds the type of operation being annotated
% (eg macro, environment, template, etc) and the \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} attribute holds
% the name of the operation.\par
% But first, if this is a colour declaration, we
% need to fake up a pre-definition for the colour,
% because the \textsf{dox} package appears to
% want it, and goes looking for it ahead of time (\texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}} holds the colourspace
% and \texttt{@audience}\index{audience=\texttt{\char'100 audience} (attribute)}\index{attributes:!audience=\texttt{\char'100 audience}} holds the
% colour definition).\par
% \par\smallskip\leavevmode
% \CPKrunningecho{db:annotation}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Remove conflict in colour definition specs/attribs}}\par\smallskip
%    \begin{macrocode}
  <xsl:template match="db:annotation
                       [not(@reuse)]
                       [@role and @role!='unused' and
                        @xreflabel and @xreflabel!='']
                       [not(@annotations)]
                       [not(ancestor::db:info)]">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:variable name="role" select="@role"/>
    <xsl:if test="$role='color'">
      <xsl:if test="not(@arch) or not(@audience)">
        <xsl:message>
          <xsl:text>CPK: no colour code given for </xsl:text>
          <xsl:value-of select="@xreflabel"/>
        </xsl:message>
      </xsl:if>
      <xsl:if test="parent::db:listitem">
        <xsl:text>&#xa;</xsl:text>
      </xsl:if>
      <xsl:text>% \definecolor{</xsl:text>
      <xsl:value-of select="@xreflabel"/>
      <xsl:text>}{</xsl:text>
      <xsl:value-of select="@arch"/>
      <xsl:text>}{</xsl:text>
      <xsl:value-of select="@audience"/>
      <xsl:text>}&#xa;</xsl:text>
    </xsl:if>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:annotation}\quad}Start the
% definition}\label{cpkstart}\addcontentsline{toc}{subparagraph}{Start the definition}
% The {\ttfamily{}CPK} prefix on defined
% names is local to \emph{ClassPack}
% and keeps the namespace out of the way of other
% packages. The object name is passed without a
% backslash, so this is added for macros (also in
% earlier versions, switches, but this fails), or where
% the entry in the {\ttfamily{}prepost.xml} file
% has a command fulfilling the constraints listed
% below.\par
%    \begin{macrocode}
    <xsl:if test="parent::db:listitem and not(@role='color')">
      <xsl:text>&#xa;</xsl:text>
    </xsl:if>
    <xsl:text>% \begin{CPK</xsl:text>
    <xsl:value-of select="$role"/>
    <xsl:text>}{</xsl:text>
    <!-- does it get a backslash? (used to include switches) -->
    <xsl:if test="$role='macro' or
                  $prepost//db:arg
                    [lower-case(@xml:id)=$role]
                    [contains(@role,'macrolike')]">
      <xsl:text>\</xsl:text>
    </xsl:if>
    <xsl:value-of select="@xreflabel"/>
    <xsl:text>}</xsl:text>
%    \end{macrocode}
% The marginal echo of the \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} attribute is
% omitted within \texttt{<sect4>}\index{sect4=\texttt{\char'074 sect4\char'076 } (element)}\index{elements:!sect4=\texttt{\char'074 sect4\char'076 }} elements, as these
% tend to be small, and a large number of marginals
% overflows \LaTeX{}'s buffers.\par
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:annotation}\quad}Label the
% definition}\label{cpklabel}\addcontentsline{toc}{subparagraph}{Label the definition}
% If this annotation is not called upon for reuse
% anywhere else, create a label for it with an prefix of
% the current \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}}
% attribute and the current filename (minus the
% extension).\par
%    \begin{macrocode}
    <xsl:if test="not(//db:annotation[@reuse=current()/@xml:id])">
      <xsl:text>\label{</xsl:text>
      <xsl:choose>
        <xsl:when test="@xml:id">
          <xsl:value-of select="@xml:id"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@role"/>
          <xsl:text>-</xsl:text>
          <xsl:value-of
            select="substring-before(db:programlisting[1]
                    /@xlink:href,'.')"/>
          <xsl:text>-</xsl:text>
          <xsl:choose>
            <xsl:when test="contains(@xreflabel,':')">
              <xsl:value-of
                select="substring-after(@xreflabel,':')"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="@xreflabel"/>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:if
            test="count(//db:annotation[@xreflabel=current()
                  /@xreflabel])>1">
            <xsl:value-of
              select="count(preceding::db:annotation
                      [@xreflabel=current()/@xreflabel])+1"/>
          </xsl:if>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:annotation}\quad}Add to Table of
% Contents}\label{cpktoc}\addcontentsline{toc}{subparagraph}{Add to Table of Contents}
% If the \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}} attribute
% is used, use it to specify the level at which the ToC
% entry will be made (eg section, paragraph, etc
% **CONFLICT**).\par
%    \begin{macrocode}
  <!--
    <xsl:if test="@arch">
      <xsl:text>% \addcontentsline{toc}{</xsl:text>
      <xsl:value-of select="@arch"/>
      <xsl:text>}{\texttt{</xsl:text>
      <xsl:choose>
        <xsl:when test="contains(@xreflabel,':')">
          <xsl:value-of
            select="substring-after(@xreflabel,':')"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@xreflabel"/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>}</xsl:text>
      <xsl:if test="contains(@condition,'|')">
        <xsl:text> and others</xsl:text>
      </xsl:if>
      <xsl:text>}&#xa;</xsl:text>
    </xsl:if>
-->
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:annotation}\quad}Additional path
% conditions}\label{cpkcond}\addcontentsline{toc}{subparagraph}{Additional path conditions}
% If the \texttt{<condition>}\index{condition=\texttt{\char'074 condition\char'076 } (element)}\index{elements:!condition=\texttt{\char'074 condition\char'076 }} is
% used, it should hold the full \texttt{@match}\index{match=\texttt{\char'100 match} (attribute)}\index{attributes:!match=\texttt{\char'100 match}} value of the
% \textsc{xslt} template being matched,
% including alternation, predicates and
% namespaces.\par
%    \begin{macrocode}
    <xsl:if test="@condition">
      <xsl:text>% \begingroup\raggedright[</xsl:text>
      <xsl:for-each
        select="tokenize(replace(normalize-space(@condition),
                         'xxx:',''),'\|')">
        <xsl:variable name="subject">
          <xsl:choose>
            <xsl:when test="contains(.,'[')">
              <xsl:value-of
                select="replace(substring-before(
                        normalize-space(.),'['),'//','/→/')"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="normalize-space(.)"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:variable name="predicate">
          <xsl:if test="contains(.,'[')">
            <xsl:value-of
              select="concat('[',
                      substring-after(normalize-space(.),'['))"/>
          </xsl:if>
        </xsl:variable>
        <xsl:if test="position()>1">
          <xsl:text>and </xsl:text>
        </xsl:if>
        <xsl:choose>
          <xsl:when
            test="contains($subject,'/') and position()=1">
            <xsl:text>in \url{</xsl:text>
            <xsl:variable name="lastone"
              select="concat(tokenize($subject,'/')
                      [position()=last()],'$')"/>
            <xsl:value-of
              select="replace($subject,$lastone,'')"/>
            <xsl:text>} </xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>\url{</xsl:text>
            <xsl:value-of select="$subject"/>
            <xsl:text>} </xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:if test="$predicate!=''">
          <xsl:text>with \url{</xsl:text>
          <xsl:value-of select="$predicate"/>
          <xsl:text>} </xsl:text>
        </xsl:if>
        <xsl:text>&#xa;% </xsl:text>
      </xsl:for-each>
      <xsl:text>]\par\endgroup&#xa;</xsl:text>
    </xsl:if>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:annotation}\quad}End the
% definition}\label{cpkend}\addcontentsline{toc}{subparagraph}{End the definition}
% Apply content, and terminate the CPK block.\par
%    \begin{macrocode}
    <xsl:apply-templates/>
    <xsl:text>% \end{CPK</xsl:text>
    <xsl:value-of select="$role"/>
    <xsl:text>}&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection*{Reuse of annotations}
% \begin{CPKtemplate}{db:constraintdef}\label{template-db2dtx-constraintdef}
% \begingroup\raggedright[\url{db:constraintdef} with \url{[@reuse]} 
% ]\par\endgroup
% Reuse in annotated Appendixes (extractable code)
% of previously-defined macros in \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }}
% elements can be done using a \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }}
% element. The \texttt{@reuse}\index{reuse=\texttt{\char'100 reuse} (attribute)}\index{attributes:!reuse=\texttt{\char'100 reuse}} is
% declared as IDREFS, so it allows the IDs of multiple
% \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} elements to be referenced
% (space-separated).\par
% Find out which appendix we’re in, and the type of
% document we’re writing, and write a comment in the
% {\ttfamily{}.dtx} file about it.\par
% Iterate over the packages specified, excluding any
% marked for omission for this application, adding in
% any documentation from the
% {\ttfamily{}prepost.xml} file, and any added
% locally in the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}}
% attribute.\par
% Then write the {\ttfamily{}\textbackslash{}RequirePackage}
% in the same way as done for normally-included
% packages.\par
% \par\smallskip\leavevmode
% \CPKrunningecho{db:constraintdef}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Make this a routine}}\par\smallskip
%    \begin{macrocode}
  <xsl:template match="db:constraintdef[@reuse]">
    <xsl:variable name="thisapp"
      select="ancestor::db:appendix/@xml:id"/>
    <xsl:variable name="thisdoctype"
      select="substring-after(
              ancestor::db:appendix/@xlink:href,'.')"/>
    <xsl:text>% This is a subset of packages </xsl:text>
    <xsl:text>required for the \texttt{.</xsl:text>
    <xsl:value-of select="$filetype"/>
    <xsl:text>} file.&#xa;</xsl:text>
    <xsl:for-each
      select="//db:constraintdef[@xml:id=current()/@reuse]
              //descendant::db:seglistitem
                [not(contains(@omit,$thisapp))]">
      <xsl:apply-templates
        select="$prepost/db:procedure[@xml:id='prepackage']
                /db:step[contains(@condition,$thisdoctype)]
                [@remap=current()/db:seg]/db:para"/>
      <xsl:if test="@role">
        <xsl:text>% </xsl:text>
        <xsl:value-of select="normalize-space(@role)"/>
        <xsl:text>&#xa;</xsl:text>
      </xsl:if>
      <xsl:text>%    </xsl:text>
      <xsl:text>\begin</xsl:text>
      <xsl:text>{macrocode}</xsl:text>
      <xsl:for-each select="db:seg">
        <!-- should only be one of these per seglistitem -->
        <xsl:text>&#xa;\RequirePackage</xsl:text>
        <xsl:if test="@role">
          <xsl:text>[</xsl:text>
          <xsl:value-of select="normalize-space(@role)"/>
          <xsl:text>]</xsl:text>
        </xsl:if>
        <xsl:text>{</xsl:text>
        <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>}</xsl:text>
        <xsl:if test="@version">
          <xsl:text>[</xsl:text>
          <xsl:value-of select="translate(@version,'-','/')"/>
          <xsl:text>]</xsl:text>
        </xsl:if>
        <xsl:text>&#xa;%    </xsl:text>
        <xsl:text>\end</xsl:text>
        <xsl:text>{macrocode}&#xa;</xsl:text>
      <xsl:apply-templates
        select="$prepost/db:procedure[@xml:id='postpackage']
                /db:step[contains(@condition,$thisdoctype)]
                        [@remap=current()/db:seg]/db:para"/>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:annotation}\label{reuseannotation}
% \begingroup\raggedright[\url{db:annotation} with \url{[@reuse]} 
% ]\par\endgroup
% This template is for the case of reusability of
% existing annotated code, eg in a package when it is
% already defined for a class. The \texttt{@reuse}\index{reuse=\texttt{\char'100 reuse} (attribute)}\index{attributes:!reuse=\texttt{\char'100 reuse}} attribute is IDREFS,
% so it can hold a space-separated list of \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}}\kern1pt{}s pointing at the
% \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }}\kern1pt{}s to reuse.\par
%    \begin{macrocode}
  <xsl:template match="db:annotation[@reuse]">
    <xsl:for-each select="tokenize(normalize-space(@reuse),' ')">
      <xsl:variable name="block" select="."/>
      <xsl:apply-templates
        select="$thisdoc//db:annotation[@xml:id=$block]"/>
    </xsl:for-each>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Remarks]{Remarks :}
% \begin{CPKtemplate}{db:remark}\label{template-db2dtx-remark}
% The \texttt{<remark>}\index{remark=\texttt{\char'074 remark\char'076 } (element)}\index{elements:!remark=\texttt{\char'074 remark\char'076 }} element holds comments
% inserted at change-points which need to be preserved
% for accumulation by Doc\TeX{}’s change-documentation
% mechanism.\par
%    \begin{macrocode}
  <xsl:template match="db:remark">
    <xsl:text>% \changes{v</xsl:text>
    <xsl:value-of select="@version"/>
    <xsl:text>}{</xsl:text>
    <xsl:choose>
      <xsl:when test="@revision">
        <xsl:value-of select="translate(@revision,'-','/')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of 
          select="translate(
                  //db:revhistory/db:revision
                    [@version=current()/@version]
                  /db:date/@YYYY-MM-DD,'-','/')"/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>}{</xsl:text>
    <xsl:value-of select="normalize-space(.)"/>
    <xsl:text>}&#xa;</xsl:text>
    <!-- also reproduce the comments in plaintext as comments -->
    <xsl:if 
      test="ancestor::db:part[@xml:id='code']
            and ancestor::db:chapter/@xlink:href 
            and ancestor::db:chapter/@xml:id 
            and not(substring-after(
              ancestor::db:chapter/@xlink:href,'.')='dtd' 
                 or substring-after(
              ancestor::db:chapter/@xlink:href,'.')='xml' 
                 or substring-after(
              ancestor::db:chapter/@xlink:href,'.')='xsl')">
      <xsl:text>% \iffalse&#xa;</xsl:text>
      <xsl:value-of select="$sentinel"/>
      <xsl:text>CHANGE for v</xsl:text>
      <xsl:value-of select="@version"/>
      <xsl:text> (</xsl:text>
      <xsl:choose>
        <xsl:when test="@revision">
          <xsl:value-of select="translate(@revision,'-','/')"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of 
            select="translate(
                    //db:revhistory/db:revision
                      [@version=current()/@version]
                    /db:date/@YYYY-MM-DD,'-','/')"/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>):</xsl:text>
      <xsl:text>&#xa;</xsl:text>
      <xsl:apply-templates select="." mode="readme"/>
      <xsl:text>% \fi&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Programming code listings]{Programming code listings :}
% \begin{CPKtemplate}{db:programlisting}\label{template-db2dtx-programlisting1}
% This template manages the reproduction of code
% listings, both from external files or from verbatim
% chunks in the document. The listings themselves are
% produced by the \DescribeTemplate{makelistings}\texttt{makelistings}
% named template. There are a \emph{lot}
% of controls, expressed as attributes:\par
% \begin{itemize}[label={},noitemsep]
% \item[†]\texttt{@annotations}\index{annotations=\texttt{\char'100 annotations} (attribute)}\index{attributes:!annotations=\texttt{\char'100 annotations}} for the list
%   of keywords to be highlighted
% \item[†]\texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}}
%   for signalling framed output
% \item[]\texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} set
%   when a listing is to be ignored (only used for
%   documentation, not for the class or
%   package)
% \item[]\texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} for
%   how the listing is included (values \texttt{"frag"}\index{frag=\texttt{"frag"} (attribute value)}\index{attribute values:!frag=\texttt{"frag"}} or \texttt{"file"}\index{file=\texttt{"file"} (attribute value)}\index{attribute values:!file=\texttt{"file"}})
% \item[†]\texttt{@endinglinenumber}\index{endinglinenumber=\texttt{\char'100 endinglinenumber} (attribute)}\index{attributes:!endinglinenumber=\texttt{\char'100 endinglinenumber}} end
%   boundary of a fragmentary listing
% \item[]\texttt{@language}\index{language=\texttt{\char'100 language} (attribute)}\index{attributes:!language=\texttt{\char'100 language}} any of
%   the \textsf{listings} languages (as
%   modified in
%   \emph{ClassPack})
% \item[†]\texttt{@linenumbering}\index{linenumbering=\texttt{\char'100 linenumbering} (attribute)}\index{attributes:!linenumbering=\texttt{\char'100 linenumbering}} turns line
%   numbering on
% \item[†]\texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}}
%   font control for highlighting keywords
% \item[]\texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} specifies a
%   title for the listing (rare)
% \item[]\texttt{@startinglinenumber}\index{startinglinenumber=\texttt{\char'100 startinglinenumber} (attribute)}\index{attributes:!startinglinenumber=\texttt{\char'100 startinglinenumber}} start
%   boundary of a fragmentary listing, or name of a file
%   fragment
% \item[†]\texttt{@wordsize}\index{wordsize=\texttt{\char'100 wordsize} (attribute)}\index{attributes:!wordsize=\texttt{\char'100 wordsize}} specifies listing
%   font size
% \item[]\texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} name
%   of an external file to list
% \item[]\texttt{@xlink:show}\index{xlink:show=\texttt{\char'100 xlink:show} (attribute)}\index{attributes:!xlink:show=\texttt{\char'100 xlink:show}} used
%   in \vref{insfile} (and possibly in
%     the code \vpageref{partcodelicence}) to get the
%   filename for installation.
% \item[]\texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} use for a
%   label
% \end{itemize}
% Those attributes marked with a dagger (†) are only
% accessed by the named template
% \DescribeTemplate{makelisting}\texttt{makelisting} (see the code \vpageref{makelisting}).\par
% The whole template is a choice between
%    \begin{enumerate*}[label=\emph{\alph*}),itemjoin={{; }},itemjoin*={{; and }}]
% \item its principal use in generating DoC\TeX{}
%       macrocode\par
% \item listings in documentation \emph{which
% contain embedded markup} (eg
%       mnemonic tokens requiring italicisation)\par
% \item code examples not required in class or
%       package output\par
% \item other uses in documentation or ancillary
%       files\par
% \end{enumerate*}\par
%    \begin{macrocode}
  <xsl:template match="db:programlisting">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <!-- Handles code in annotated and unannotated blocks -->
    <xsl:variable name="curapp"
      select="generate-id(ancestor::db:appendix[1])"/>
    <!-- count the prior listing blocks within this appendix -->
    <xsl:variable name="nthproglist"
      select="count(preceding::db:programlisting
              [generate-id(ancestor::db:appendix[1])=$curapp]) + 1"/>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:programlisting}\quad}Generating \texttt{macrocode}
% fragments for the package or class}
% This occurs only in the \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}} part or in
% \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} elements with an \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} attribute.\par
% Any fragments required as external files specified
% in the \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}} part (eg
% \textsc{dtd}\index{DTD}s, \textsc{xslt}, etc,
% get output here as extractables at the end of the
% {\ttfamily{}.dtx} file, as separate Doc\TeX{}
% tagging can’t be nested inside class or package tags.
% Otherwise (see end of section) they just get output
% as-is (trimmed fore and aft).\par
% \par\begingroup
%   \fboxsep1em\centering
%   \fbox{\begin{minipage}{0.8\columnwidth}\sffamily
%  \raggedright\parindent0pt
%  \parskip=.5\baselineskip
% Due to a bug in the \textsf{listings}
%   package when handling string-delimited fragments in
%   very large files, it is necessary to split the file
%   into fragments and process them individually (as is
%   done for this document). The \emph{chunk}\thinspace(1) utility does the
%   splitting.\par
% \end{minipage}}\par\endgroup
%    \begin{macrocode}
  <!-- programlisting within an annotation 
       OR anywhere in the code part -->
    <xsl:choose>
      <xsl:when test="(parent::db:annotation[@xreflabel]
                      or
                      ancestor::db:part[@xml:id='code'])
                      and not(@condition='ignore')">
        <xsl:if test="@xml:id">
          <xsl:text>% \label{</xsl:text>
          <xsl:value-of select="@xml:id"/>
          <xsl:text>}&#xa;</xsl:text>
        </xsl:if>
        <xsl:choose>
          <!-- EXTERNAL FRAGMENT whatever the language -->
          <xsl:when test="@xlink:href">
            <xsl:choose>
              <!-- frag means file has been pre-split into pieces -->
              <xsl:when test="@conformance='frag'">
                <!-- get the original source filename, strip dir  -->
                <xsl:variable name="fn">
                  <xsl:choose>
                    <xsl:when test="contains(@xlink:href,'/')">
                      <xsl:value-of
                        select="tokenize(@xlink:href,'/')
                                [position()=last()]"/>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="@xlink:href"/>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:variable>
                <!-- get the path to use on the fragment -->
                <xsl:variable name="dir">
                  <xsl:if test="contains(@xlink:href,'/')">
                    <xsl:for-each
                      select="tokenize(@xlink:href,'/')
                              [not(position()=last())]">
                      <xsl:value-of select="."/>
                      <xsl:text>/</xsl:text>
                    </xsl:for-each>
                  </xsl:if>
                </xsl:variable>
                <!-- construct the fragment filename, format is
                     directory path, slash
                     filename minus the extension
                     MINUS
                     fragname (@startinglinenumber string)
                     DOT
                     value of @conformance ('frag')
                     -->
                <xsl:variable name="fragfn">
                  <xsl:value-of select="$appdir"/>
                  <xsl:text>/</xsl:text>
                  <xsl:value-of select="$dir"/>
                  <xsl:value-of
                    select="substring-before($fn,'.')"/>
                  <xsl:text>-</xsl:text>
                  <xsl:value-of
                    select="@startinglinenumber"/>
                  <xsl:text>.</xsl:text>
                  <xsl:value-of select="@conformance"/>
                </xsl:variable>
                <!-- pass to the routine that decide if this is a shell
                     script or not, and if it's the first fragment or
                     not, and outputs the hashbang first, THEN the 
                     comment and then the rest of the file. 
                     Or just the file. -->
                <xsl:call-template name="extinc">
                  <xsl:with-param name="extfile" select="$fragfn"/>
                  <xsl:with-param name="nthproglist"
                    select="$nthproglist"/>
                </xsl:call-template>
              </xsl:when>
              <!-- non-frag PART OF FILE RETRIEVED FROM WHOLE FILE -->
              <xsl:when test="@startinglinenumber
                              and
                              @endinglinenumber">
                <xsl:call-template name="makelisting"/>
              </xsl:when>
              <!-- WHOLE FILE NOT A FRAGMENT -->
              <xsl:otherwise>
                <xsl:variable name="wholefn">
                  <xsl:value-of select="$appdir"/>
                  <xsl:text>/</xsl:text>
                  <xsl:value-of select="@xlink:href"/>
                </xsl:variable>
                <!-- pass to the routine that decide if this is a shell
                     script or not, and if it's the first fragment or
                     not, and outputs the hashbang first, THEN the 
                     comment and then the rest of the file. 
                     Or just the file. -->
                <xsl:call-template name="extinc">
                  <xsl:with-param name="extfile" select="$wholefn"/>
                  <xsl:with-param name="nthproglist"
                    select="$nthproglist"/>
                </xsl:call-template>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <!-- NORMAL EMBEDDED LISTING -->
          <xsl:otherwise>
            <xsl:text>%    </xsl:text>
            <xsl:text>\begin</xsl:text>
            <xsl:text>{macrocode}&#xa;</xsl:text>
            <xsl:call-template name="lrtrim">
              <xsl:with-param name="text" select="."/>
            </xsl:call-template>
            <xsl:text>&#xa;%    </xsl:text>
            <xsl:text>\end</xsl:text>
            <xsl:text>{macrocode}&#xa;</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:programlisting}\quad}Interpretable content in documentation
% (embedded markup)}
% Where the code has embedded markup (\texttt{@token}\index{token=\texttt{\char'100 token} (attribute)}\index{attributes:!token=\texttt{\char'100 token}} or \texttt{@xref}\index{xref=\texttt{\char'100 xref} (attribute)}\index{attributes:!xref=\texttt{\char'100 xref}}) requiring syntactic
% representation, we use the \texttt{Verbatim}
% environment from the \textsf{fancyverb}
% package.\par
%    \begin{macrocode}
  <!-- programlisting containing token or xref (!) 
       ILLUSTRATIONS ONLY, NOT EXTRACTABLE CODE -->
      <xsl:when test="db:token or db:xref">
        <xsl:text>% \iffalse
%&lt;*ignore>
% \fi
% \begin{Verbatim}[frame=single,framesep=1em,
%  commandchars=\\\{\},fontsize=</xsl:text>
        <xsl:choose>
          <xsl:when test="@wordsize and not(contains(@wordsize,'/'))">
            <xsl:value-of select="@wordsize"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>\small</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:if test="@xml:id and @role">
          <xsl:text>,label=</xsl:text>
          <xsl:value-of select="@xml:id"/>
          <xsl:text>,title={</xsl:text>
          <xsl:value-of select="normalize-space(@role)"/>
          <xsl:text>}</xsl:text>
        </xsl:if>
        <xsl:text>]&#xa;</xsl:text>
        <xsl:apply-templates/>
        <xsl:text>&#xa;% \end{Verbatim}
% \iffalse
%&lt;/ignore>
% \fi&#xa;</xsl:text>
      </xsl:when>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:programlisting}\quad}Examples in code that are
% \emph{not} for inclusion in the class or
% package}
% This works the same way but using
% \texttt{<xsl:value-of>}\index{xsl:value-of=\texttt{\char'074 xsl:value-of\char'076 } (element)}\index{elements:!xsl:value-of=\texttt{\char'074 xsl:value-of\char'076 }} to output the content as-is,
% instead of \texttt{<xsl:apply-templates>}\index{xsl:apply-templates=\texttt{\char'074 xsl:apply-templates\char'076 } (element)}\index{elements:!xsl:apply-templates=\texttt{\char'074 xsl:apply-templates\char'076 }} to parse
% it.\par
%    \begin{macrocode}
  <!-- programlisting set to be ignored (!) 
       ILLUSTRATIONS ONLY, NOT EXTRACTABLE CODE -->
      <xsl:when test="@condition='ignore'">
        <xsl:text>% \iffalse
%&lt;*ignore>
% \fi
% \begingroup\advance\hsize by-1em
% \begin{Verbatim}[frame=single,framesep=1em,
%  fontsize=</xsl:text>
        <xsl:choose>
          <xsl:when test="@wordsize and not(contains(@wordsize,'/'))">
            <xsl:value-of select="@wordsize"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>\small</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>]&#xa;</xsl:text>
        <xsl:call-template name="lrtrim">
          <xsl:with-param name="text" select="."/>
        </xsl:call-template>
        <xsl:text>
% \end{Verbatim}
% \endgroup
% \iffalse
%&lt;/ignore>
% \fi&#xa;</xsl:text>
      </xsl:when>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{db:programlisting}\quad}Use in documentation or ancillary files
% (default)}
% In otherwise unadorned examples, eg non-\LaTeX{},
% non-Doc\TeX{}, this allows use of \texttt{<userinput>}\index{userinput=\texttt{\char'074 userinput\char'076 } (element)}\index{elements:!userinput=\texttt{\char'074 userinput\char'076 }}
% subelements.\par
%    \begin{macrocode}
  <!-- ALL OTHER PROGRAMLISTINGS 
       especially those using start–end from a whole file -->
      <xsl:otherwise>
        <xsl:call-template name="makelisting"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{extinc}\label{template-db2dtx-extinc}
% This named template handles the case of a file
% being input for extraction in fragments which is a
% shell script, and which therefore requires the first
% line (which contains the
% `hashbang' directive to te
% operating system) to be preserved as the first line,
% and not prefixed by the comment lines usually imposed
% by \emph{ClassPack}.\par
%    \begin{macrocode}
  <!-- EXTERNAL FILE INCLUSION -->
  <xsl:template name="extinc">
    <!-- context is a <programlisting> element in an <appendix> -->
    <xsl:param name="extfile"/>
    <xsl:param name="nthproglist"/>
    <xsl:choose>
      <!-- if it's a first fragment, AND it's a shell script,
           output the hashbang line, then the CP header 
           followed by the rest -->
      <xsl:when test="ancestor::db:part[@xml:id='code']
                      and
                      ancestor::db:appendix[@arch='script'
                          and @userlevel='bash']
                      and
                      $nthproglist=1">
        <!-- output first line -->
        <xsl:text>%    \begin</xsl:text>
        <xsl:text>{macrocode}&#xa;</xsl:text>
        <xsl:value-of
          select="substring-before(unparsed-text($extfile),'&#xa;')"/>
        <xsl:text>&#xa;%    \end</xsl:text>
        <xsl:text>{macrocode}&#xa;</xsl:text>
        <xsl:text>% \label{</xsl:text>
        <xsl:if test="number(@startinglinenumber)">
          <xsl:text>frag-</xsl:text>
        </xsl:if>
        <xsl:value-of select="@startinglinenumber"/>
        <xsl:text>}&#xa;</xsl:text>
        <!-- go back and do the header comment -->
        <xsl:call-template name="startappcomment">
          <xsl:with-param name="scriptflag">
            <xsl:text>go</xsl:text>
          </xsl:with-param>
        </xsl:call-template>
        <!-- then the remainder -->
        <xsl:text>%    \begin</xsl:text>
        <xsl:text>{macrocode}&#xa;</xsl:text>
        <xsl:call-template name="lrtrim">
          <xsl:with-param name="text"
            select="substring-after(unparsed-text($extfile),'&#xa;')"/>
        </xsl:call-template>
        <xsl:text>&#xa;%    \end</xsl:text>
        <xsl:text>{macrocode}&#xa;</xsl:text>
      </xsl:when>
      <!-- ELSE either it's not a bash script, or not a first file -->
      <xsl:otherwise>
        <!-- otherwise just output it -->
        <xsl:text>%    \begin</xsl:text>
        <xsl:text>{macrocode}&#xa;</xsl:text>
        <xsl:call-template name="lrtrim">
          <xsl:with-param name="text" 
            select="unparsed-text($extfile)"/>
        </xsl:call-template>
        <xsl:text>&#xa;%    \end</xsl:text>
        <xsl:text>{macrocode}&#xa;</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% It does this by testing for the type of file, and
% that this is the first fragment of it. In this case it
% outputs the first line, calls the startappcomment
% named template, and then outputs the remainder of the
% fragment.\par
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:userinput}\label{template-db2dtx-userinput}
% User input example needing emphasis
% (\emph{outside} the program
% listing).\par
%    \begin{macrocode}
  <xsl:template
    match="db:userinput[not(parent::db:programlisting)]">
    <xsl:text>\emph{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Lists]{Lists :}\label{listcode}
% The six conventional types of list are
%       supported:\par
% \begin{enumerate}[noitemsep]
% \item bulleted (itemized)
%   \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }};
% \item numbered (enumerated)
%   \texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }};
% \item definition (description)
%   \texttt{<variablelist>}\index{variablelist=\texttt{\char'074 variablelist\char'076 } (element)}\index{elements:!variablelist=\texttt{\char'074 variablelist\char'076 }};
% \item procedures (steps) \texttt{<procedure>}\index{procedure=\texttt{\char'074 procedure\char'076 } (element)}\index{elements:!procedure=\texttt{\char'074 procedure\char'076 }};
% \item simple (unnumbered, unbulleted)
%   \texttt{<simplelist>}\index{simplelist=\texttt{\char'074 simplelist\char'076 } (element)}\index{elements:!simplelist=\texttt{\char'074 simplelist\char'076 }};
% \item inline (optional or inclusive)
%   \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }}/\texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }}
%   inside a paragraph.\par
% \end{enumerate}
% The first three map directly to the three \LaTeX{}
%       types. Procedures are enumerated lists, and simple lists
%       are itemized. Inline lists are done by using the
%       \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }} or \texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }} inside
%       a paragraph: the only difference is that
%       \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }} causes the final item to be
%       separated with `or' whereas
%       \texttt{<orderedlist>}\index{orderedlist=\texttt{\char'074 orderedlist\char'076 } (element)}\index{elements:!orderedlist=\texttt{\char'074 orderedlist\char'076 }} causes the final item to be
%       separated with `and'. Punctuation
%       in all cases is automatic (see \vref{autopunct}).\par
% \subparagraph[Itemized (bulleted) lists]{Itemized (bulleted) lists  ◦}\label{itemized}
% \begin{CPKtemplate}[noprint]{db:itemizedlist}\label{template-db2dtx-itemizedlist}
% If this is inside a paragraph (inline list),
%   start with a newline. If there’s a title, make it a
%   \texttt{paragraph*}
%   (\texttt{subparagraph*} if this is a nested
%   list). For an inline list, use
%   \texttt{enumerate*} with automated
%   punctuation, otherwise just a normal
%   \texttt{itemize}. For compact spacing, set the
%   \textbf{\texttt{noitemsep}} option.\par
%    \begin{macrocode}
  <xsl:template match="db:itemizedlist">
    <xsl:if test="parent::db:para">
      <xsl:text>&#xa;</xsl:text>
    </xsl:if>
    <xsl:if test="db:title">
      <xsl:text>% \</xsl:text>
      <xsl:if test="ancestor::db:itemizedlist
                    or
                    ancestor::db:orderedlist">
        <xsl:text>sub</xsl:text>
      </xsl:if>
      <xsl:text>paragraph*{</xsl:text>
      <xsl:apply-templates select="db:title/node()"/>
      <xsl:text>}&#xa;</xsl:text>
    </xsl:if>
    <xsl:choose>
      <xsl:when test="parent::db:para">
        <xsl:text>% \begin{enumerate*}</xsl:text>
        <xsl:text>[label=\emph{\alph*}),</xsl:text>
        <xsl:text>itemjoin={{; }},</xsl:text>
        <xsl:text>itemjoin*={{; or }}]</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>% \begin{itemize}</xsl:text>
        <xsl:if test="@spacing='compact'">
          <xsl:text>[noitemsep]</xsl:text>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:choose>
      <xsl:when test="parent::db:para">
        <xsl:text>% \end{enumerate*}</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>% \end{itemize}</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="not(parent::db:para or parent::db:note)">
      <xsl:text>&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="db:itemizedlist/db:title"/>

  <xsl:template
    match="db:varlistentry | 
           db:varlistentry/db:listitem | 
           db:authorgroup">
    <xsl:apply-templates/>
  </xsl:template>
%    \end{macrocode}
% Suppress the title when it is presented in
%   document order, and pass through everything in
%   variable list entries.\par
% \end{CPKtemplate}
% \subparagraph[Ordered (enumerated) lists]{Ordered (enumerated) lists  ◦}\label{enumerate}
% \begin{CPKtemplate}[noprint]{db:orderedlist}\label{template-db2dtx-orderedlist}
% \begingroup\raggedright[\url{db:orderedlist} 
% and \url{db:procedure} 
% and \url{db:simplelist} with \url{[@arch='enumerate']} 
% ]\par\endgroup
% Numbered lists (including Procedures and simple
%   lists with the \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}}
%   attribute set to say so). For inline lists, set
%   additional armour. Allow a two-column layout, and
%   allow for suspend/resume. Otherwise similar to the
%   \texttt{<itemizedlist>}\index{itemizedlist=\texttt{\char'074 itemizedlist\char'076 } (element)}\index{elements:!itemizedlist=\texttt{\char'074 itemizedlist\char'076 }}.\par
%    \begin{macrocode}
  <xsl:template match="db:orderedlist | 
                       db:procedure |
                       db:simplelist[@arch='enumerate']">
    <xsl:variable name="armour">
      <xsl:choose>
        <xsl:when test="parent::db:para">
          <xsl:text></xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>%</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!-- check format for twocol wrapper -->
    <xsl:if test="@role='twocol'">
      <xsl:value-of select="$armour"/>
      <xsl:text> \begin{multicols}{2}&#xa;</xsl:text>
    </xsl:if>
    <xsl:if test="db:title">
      <xsl:text>% \</xsl:text>
      <xsl:if test="ancestor::db:itemizedlist
                    or
                    ancestor::db:orderedlist">
        <xsl:text>sub</xsl:text>
      </xsl:if>
      <xsl:text>paragraph*{</xsl:text>
      <xsl:apply-templates select="db:title/node()"/>
      <xsl:text>}&#xa;</xsl:text>
    </xsl:if>
    <xsl:if test="@xml:id">
      <xsl:value-of select="$armour"/>
      <xsl:text> \label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}&#xa;</xsl:text>
    </xsl:if>
    <xsl:value-of select="$armour"/>
    <xsl:text> \begin{enumerate</xsl:text>
    <xsl:if test="parent::db:para">
      <xsl:text>*</xsl:text>
    </xsl:if>
    <xsl:text>}</xsl:text>
    <!-- check for options needed -->
    <xsl:if test="parent::db:para 
                  or
                  (@linkend and
                   preceding::db:orderedlist
                     [@xml:id=current()/@linkend]) 
                  or
                  @spacing='compact'
                  or
                  local-name()='simplelist'
                  or
                  @startingnumber
                  or
                  db:listitem/db:annotation">
      <xsl:text>[</xsl:text>
      <!-- inline -->
      <xsl:if test="parent::db:para">
        <xsl:text>label=\emph{\alph*}),</xsl:text>
        <xsl:text>itemjoin={{; }},</xsl:text>
        <xsl:text>itemjoin*={{; and }}</xsl:text>
      </xsl:if>
      <!-- resumption -->
      <xsl:if
        test="@linkend and
              preceding::db:orderedlist
              [@xml:id=current()/@linkend]">
        <xsl:if test="parent::db:para">
          <xsl:text>,</xsl:text>
        </xsl:if>
        <xsl:text>resume</xsl:text>
      </xsl:if>
      <!-- spacing -->
      <xsl:if test="@spacing='compact'
                    or
                    local-name()='simplelist'">
        <xsl:if
          test="parent::db:para or
                (@linkend and
                 preceding::db:orderedlist
                  [@xml:id=current()/@linkend])">
          <xsl:text>,</xsl:text>
        </xsl:if>
        <xsl:text>noitemsep</xsl:text>
      </xsl:if>
      <!-- numbering -->
      <xsl:if test="@startingnumber">
        <xsl:if
          test="parent::db:para or
                (@linkend and
                 preceding::db:orderedlist
                  [@xml:id=current()/@linkend])
                or
                @spacing='compact'
                or
                local-name()='simplelist'">
          <xsl:text>,</xsl:text>
        </xsl:if>
        <xsl:text>start=</xsl:text>
        <xsl:value-of select="@startingnumber"/>
      </xsl:if>
      <!-- no indent if there's an annotation to come -->
      <xsl:if test="db:listitem/db:annotation">
        <xsl:if test="parent::db:para 
                  or
                  (@linkend and
                   preceding::db:orderedlist
                     [@xml:id=current()/@linkend]) 
                  or
                  @spacing='compact'
                  or
                  local-name()='simplelist'
                  or
                  @startingnumber">
          <xsl:text>,</xsl:text>
        </xsl:if>
        <xsl:text>leftmargin=0.5em</xsl:text>
      </xsl:if>
      <xsl:text>]</xsl:text>
    </xsl:if>
    <!-- set indent if the list contains annotations -->
    <xsl:if test="db:listitem/db:annotation">
      <xsl:text>\setlength{\CPKannotationindent}{1em}</xsl:text>
    </xsl:if>
    <!-- do list -->
    <xsl:text>&#xa;</xsl:text>
    <xsl:apply-templates/>
    <!-- no withdrawal of armour needed 
         for inline list termination
         because the end of a list item para 
         will have created a newline -->
    <xsl:text>% \end{enumerate</xsl:text>
    <xsl:if test="parent::db:para">
      <xsl:text>*</xsl:text>
    </xsl:if>
    <xsl:text>}</xsl:text>
    <!-- unset indent if the list contains annotations -->
    <xsl:if test="db:listitem/db:annotation">
      <xsl:text>\setlength{\CPKannotationindent}{0pt}</xsl:text>
    </xsl:if>
    <xsl:if test="not(parent::db:para)">
      <xsl:text>&#xa;</xsl:text>
    </xsl:if>
    <!-- check format -->
    <xsl:if test="@role='twocol'">
      <xsl:text>% \end{multicols}&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template
    match="db:orderedlist/db:title | 
           db:procedure/db:title |
           db:simplelist[@arch='enumerate']/db:title"/>
%    \end{macrocode}
% Suppress any title when it is presented in
%   document order.\par
% \end{CPKtemplate}
% \subparagraph[Definition (description) lists]{Definition (description) lists  ◦}
% \begin{CPKtemplate}[noprint]{db:variablelist}\label{template-db2dtx-variablelist1}
% Definition lists. Map exactly to the
%   \texttt{description} environment.\par
%    \begin{macrocode}
  <xsl:template match="db:variablelist">
    <xsl:if test="db:title">
      <xsl:value-of select="$armour"/>
      <xsl:text>% \</xsl:text>
      <xsl:if
        test="ancestor::db:itemizedlist
              or
              ancestor::db:orderedlist">
        <xsl:text>sub</xsl:text>
      </xsl:if>
      <xsl:text>paragraph*{</xsl:text>
      <xsl:apply-templates select="db:title/node()"/>
      <xsl:text>}&#xa;</xsl:text>
    </xsl:if>
    <xsl:text>% \begin{description}[style=unboxed</xsl:text>
    <xsl:if test="@spacing='compact'">
      <xsl:text>,noitemsep</xsl:text>
    </xsl:if>
    <xsl:if test="db:varlistentry/db:listitem/db:annotation">
      <xsl:text>,leftmargin=0.5em</xsl:text>
    </xsl:if>
    <xsl:text>]</xsl:text>
    <!-- set indent if the list contains annotations -->
    <xsl:if test="db:varlistentry/db:listitem/db:annotation">
      <xsl:text>\setlength{\CPKannotationindent}{1em}</xsl:text>
    </xsl:if>
    <xsl:if test="@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>% \end{description}</xsl:text>
    <!-- unset indent if the list contains annotations -->
    <xsl:if test="db:varlistentry/db:listitem/db:annotation">
      <xsl:text>\setlength{\CPKannotationindent}{0pt}</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="db:variablelist/db:title"/>
%    \end{macrocode}
% \end{CPKtemplate}
% \subparagraph[Simple lists]{Simple lists  ◦}\label{simplist}
% \begin{CPKtemplate}[noprint]{db:simplelist}\label{template-db2dtx-simplelist}
% \begingroup\raggedright[\url{db:simplelist} with \url{[@role='twocol']} 
% and \url{db:simplelist} with \url{[@role]} 
% and \url{db:member} with \url{[parent::db:simplelist[@role]]} 
% ]\par\endgroup
% Simple lists are bulleted lists with tight
%   spacing and no bullet preset. The \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} can specify
%   two-column layout. \par
%    \begin{macrocode}
  <xsl:template match="db:simplelist[@role='twocol']">
    <xsl:text>% \begin{multicols}{2}</xsl:text>
    <xsl:if test="@xreflabel">
      <xsl:text>[\paragraph*{</xsl:text>
      <xsl:value-of select="normalize-space(@xreflabel)"/>
      <xsl:text>}]</xsl:text>
    </xsl:if>
    <xsl:text>\begin{itemize}[noitemsep]&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>% \end{itemize}
% \end{multicols}&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="db:simplelist[not(@role)
                       and
                       not(@arch)]">
    <xsl:text>% \begin{itemize}</xsl:text>
    <xsl:text>[label={},noitemsep]&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>% \end{itemize}&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="db:simplelist[@role]">
    <xsl:text>&#xa;% \</xsl:text>
    <xsl:value-of select="@role"/>
    <xsl:if test="@remap='longest'">
      <xsl:text>\longestline{</xsl:text>
      <xsl:value-of
        select="normalize-space(db:member
                [not(../db:member/string-length()
                      >string-length(.))][1])"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>\stanza&#xa;</xsl:text>
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template
    match="db:member[parent::db:simplelist[@role]]">
    <xsl:text>% </xsl:text>
    <xsl:apply-templates/>
    <xsl:if test="position()=last()">
      <xsl:text>\</xsl:text>
    </xsl:if>
    <xsl:text>&amp;&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subparagraph[List items]{List items  ◦}\label{items}
% \begin{CPKtemplate}[noprint]{db:listitem}\label{template-db2dtx-listitem}
% \begingroup\raggedright[in \url{db:itemizedlist/} 
% and \url{db:orderedlist/db:listitem} 
% and \url{db:procedure/db:step} 
% and \url{db:simplelist} with \url{[not(@role)]/db:member} 
% ]\par\endgroup
% Items allow for variation of the bullet or
%   number, and for a label from the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute. This
%   template does not match for \texttt{<variablelist>}\index{variablelist=\texttt{\char'074 variablelist\char'076 } (element)}\index{elements:!variablelist=\texttt{\char'074 variablelist\char'076 }}
%   elements, see the \DescribeTemplate{term}\texttt{term}
%   template below.\par
%    \begin{macrocode}
  <xsl:template
    match="db:itemizedlist/db:listitem |
           db:orderedlist/db:listitem |
           db:procedure/db:step |
           db:simplelist[not(@role)]/db:member">
    <xsl:text>% \item</xsl:text>
    <xsl:choose>
      <!-- remap a bullet or number -->
      <xsl:when test="@remap or parent::db:simplelist">
        <xsl:text>[</xsl:text>
        <xsl:value-of select="@remap"/>
        <xsl:text>]</xsl:text>
      </xsl:when>
      <!-- or prefix the number with a symbol 
           (what was this for?!) -->
      <xsl:when test="@role">
        <xsl:text>\leavevmode\llap{</xsl:text>
        <xsl:value-of select="@role"/>
        <xsl:text>\thinspace}</xsl:text>
      </xsl:when>
      <!-- normally just a space -->
      <xsl:otherwise>
        <xsl:text> </xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <!-- label it if needed -->
    <xsl:if test="@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:apply-templates/>
    <!-- syntactic punctuation now handled by db:para template 
         except for db:member, which needs terminating -->
    <xsl:if test="local-name()='member'">
      <xsl:text>&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subparagraph[Definition list terms]{Definition list terms  ◦}\label{terms}
% \begin{CPKtemplate}[noprint]{db:term}\label{template-db2dtx-term1}
% The \texttt{<term>}\index{term=\texttt{\char'074 term\char'076 } (element)}\index{elements:!term=\texttt{\char'074 term\char'076 }} is the label of a definition
%   or description list, so in \LaTeX{} it needs to usurp
%   the {\ttfamily{}\textbackslash{}item} command and place its
%   content into what is normally the optional argument
%   to {\ttfamily{}\textbackslash{}item}. The
%   \DescribeTemplate{listitem}\texttt{listitem} \emph{template} (above) does not match
%   the \texttt{<listitem>}\index{listitem=\texttt{\char'074 listitem\char'076 } (element)}\index{elements:!listitem=\texttt{\char'074 listitem\char'076 }} child
%   \emph{elements} of a
%   \texttt{<varlistentry>}\index{varlistentry=\texttt{\char'074 varlistentry\char'076 } (element)}\index{elements:!varlistentry=\texttt{\char'074 varlistentry\char'076 }} element for this
%   reason.\par
%    \begin{macrocode}
  <xsl:template match="db:term">
    <xsl:if 
      test="ancestor::db:part[@xml:id='code']
            and ancestor::db:chapter/@xlink:href 
            and ancestor::db:chapter/@xml:id 
            and not(substring-after(
                    ancestor::db:chapter/@xlink:href,'.')='dtd' 
                 or substring-after(
                    ancestor::db:chapter/@xlink:href,'.')='xml' 
                 or substring-after(
                    ancestor::db:chapter/@xlink:href,'.')='xsl')">
      <xsl:text>% \iffalse&#xa;</xsl:text>
      <xsl:value-of select="$sentinel"/>
      <xsl:text>&#xa;</xsl:text>
      <xsl:apply-templates select="." mode="readme"/>
      <xsl:text>% \fi&#xa;</xsl:text>
    </xsl:if>
    <xsl:text>% \item[</xsl:text>
    <xsl:if test="@annotations">
      <xsl:text>\llap{</xsl:text>
      <xsl:value-of select="@annotations"/>
      <xsl:text>\ }</xsl:text>
    </xsl:if>
    <xsl:if test="ancestor::db:variablelist[@role='numbered']">
      <xsl:number count="db:varlistentry" format="1"/>
      <xsl:text>. </xsl:text>
    </xsl:if>
    <xsl:apply-templates/>
    <xsl:if test="not(db:command[@conformance or @condition])">
      <xsl:text>:</xsl:text>
    </xsl:if>
    <xsl:text>]</xsl:text>
    <xsl:if test="following-sibling::db:listitem/db:annotation">
      <xsl:text>\par </xsl:text>
    </xsl:if>
    <xsl:if test="../@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="../@xml:id"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
  
  <xsl:template match="db:termdef">
    <xsl:text>\textbf{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}\index{</xsl:text>
    <xsl:value-of select="normalize-space(.)"/>
    <xsl:text>|textbf}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subparagraph[Lists in an Abstract]{Lists in an Abstract  ◦}\label{abstractlists}
% \begin{CPKtemplate}[noprint]{db:formalpara}\label{template-db2dtx-formalpara1}
% In normal text, this uses the \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }}
%   subelement as a heading. However, in the
%   \texttt{<abstract>}\index{abstract=\texttt{\char'074 abstract\char'076 } (element)}\index{elements:!abstract=\texttt{\char'074 abstract\char'076 }}, (where lists are not allowed by
%   \emph{DocBook}), it gets
%   abused/transformed to a one-item bulleted list with
%   vertical spacing suppressed.\par
%    \begin{macrocode}
  <xsl:template match="db:formalpara[not(parent::db:abstract)]">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="db:formalpara/db:title">
    <xsl:text>% \par\textbf{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}\par\noindent\ignorespaces </xsl:text>
  </xsl:template>

  <xsl:template match="db:formalpara[parent::db:abstract]">
    <xsl:text>% \begin{itemize}[nosep]&#xa;%   \item </xsl:text>
    <xsl:apply-templates/>
    <xsl:text>% \end{itemize}&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection{Flow}\label{theflow}
% These templates all match element types that occur
%     \emph{within} the flow of normal text (eg
%     inside paragraphs).\par
% \par\begingroup
%   \fboxsep1em\centering
%   \fbox{\begin{minipage}{0.8\columnwidth}\sffamily
%  \raggedright\parindent0pt
%  \parskip=.5\baselineskip
% Because of the design flaw in \textsc{xsl}
%       in removing white-space nodes in mixed content
%       \emph{even when a \textsc{dtd}\index{DTD}/schema is
% in use}, almost all these templates start
%       with the detection of an immediately-preceding element,
%       and in most cases compensate for the missing
%       white-space.\par
% \end{minipage}}\par\endgroup
% \paragraph[Acronyms]{Acronyms :}\label{acronyms}
% \begin{CPKtemplate}{db:acronym}\label{template-db2dtx-acronym1}
% If there is an \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}}
% attribute present, this is taken as a defining
% instance, with the content being the expansion, so it
% is formatted as the expansion first and the acronym in
% parentheses afterwards, and indexed as such.\par
% When there is no \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute present, it
% is assumed that the content is the acronym, and
% formatted accordingly and added to the index.\par
%    \begin{macrocode}
  <xsl:template match="db:acronym">
    <xsl:call-template name="compensate-space"/>
    <xsl:choose>
      <!-- ID present: defining instance -->
      <xsl:when test="@xml:id">
        <!-- output the content (the expansion), 
             quoted if required -->
        <xsl:if test="@remap='quoted'">
          <xsl:text>‘</xsl:text>
        </xsl:if>
        <xsl:apply-templates/>
        <xsl:text>\phantomsection\label{</xsl:text>
        <xsl:value-of select="@xml:id"/>
        <xsl:text>}</xsl:text>
        <xsl:if test="not(ancestor::db:table
                      or ancestor::db:informaltable
                      or ancestor::db:figure)">
          <xsl:text>\marginpar{\small\HandRight}</xsl:text>
        </xsl:if>
        <!-- output any plural specified in @role -->
        <xsl:if test="@role">
          <xsl:value-of select="@role"/>
        </xsl:if>
        <!-- end quote -->
        <xsl:if test="@remap='quoted'">
          <xsl:text>’</xsl:text>
        </xsl:if>
        <!-- output the acronym in parentheses -->
        <xsl:text> (</xsl:text>
        <xsl:choose>
          <!-- use a logo -->
          <xsl:when test="@remap">
            <xsl:value-of select="@remap"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="casestyle">
              <xsl:with-param name="text"
                select="normalize-space(@xml:id)"/>
            </xsl:call-template>
            <!-- pluralise the acronym too if needed -->
            <xsl:choose>
              <xsl:when test="@role">
                <xsl:value-of select="@role"/>
              </xsl:when>
              <xsl:when test="@arch='plural'">
                <xsl:text>s</xsl:text>
              </xsl:when>
            </xsl:choose>
          </xsl:otherwise>
        </xsl:choose>
        <!-- index it as the locus classicus 
             NOT index the acro, see expansion
             BUT index expansion, see acro
-->
        <xsl:text>)\index{</xsl:text>
        <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>|see{</xsl:text>
        <xsl:value-of select="upper-case(@xml:id)"/>
        <xsl:text>}}\index{</xsl:text>
        <xsl:value-of select="upper-case(@xml:id)"/>
        <xsl:text>|textbf}</xsl:text>
      </xsl:when>
      <!-- no ID: normal use -->
      <xsl:otherwise>
        <!-- output the acronym -->
        <xsl:variable name="definst"
          select="//db:acronym[@xml:id=current()/.]"/>
        <xsl:choose>
          <!-- logo? -->
          <xsl:when test="$definst and @remap">
            <xsl:value-of
              select="//db:acronym[@xml:id=current()/.]
                      /@remap"/>
            <xsl:text>{}</xsl:text>
          </xsl:when>
          <!-- not in the same chapter, and never within the
               term argument to a description list -->
          <xsl:when test="$definst
                          and
                          count($definst/ancestor::db:chapter
                          | 
                          ./ancestor::db:chapter)>1
                          and not(ancestor::db:term)">
            <xsl:text>\hyperref[</xsl:text>
            <xsl:value-of select="."/>
            <xsl:text>]{</xsl:text>
            <xsl:call-template name="casestyle">
              <xsl:with-param name="text"
                select="normalize-space(.)"/>
            </xsl:call-template>
            <xsl:text>}</xsl:text>
            <!-- pluralised if necessary -->
            <xsl:choose>
              <xsl:when test="@role">
                <xsl:value-of select="@role"/>
              </xsl:when>
              <xsl:when test="@arch='plural'">
                <xsl:text>s</xsl:text>
              </xsl:when>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="casestyle">
              <xsl:with-param name="text"
                select="normalize-space(.)"/>
            </xsl:call-template>
            <!-- pluralised if necessary -->
            <xsl:if test="@role">
              <xsl:value-of select="@role"/>
            </xsl:if>
          </xsl:otherwise>
        </xsl:choose>
        <!-- index it -->
        <xsl:if test="//db:acronym[@xml:id=current()/.]">
          <xsl:if test="ancestor::db:footnote">
            <xsl:text>\protect</xsl:text>
          </xsl:if>
          <xsl:text>\index{</xsl:text>
          <xsl:value-of select="normalize-space(.)"/>
          <xsl:text>}</xsl:text>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Inline titles]{Inline titles :}\label{citetitles}
% \begin{CPKtemplate}{db:citetitle}\label{citetitle}
% Cites the title of a bibliographic reference. If
% there is no \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} {\ttfamily{}IDREF}\thinspace, or if the reference is
% to a book, the title is italicised, otherwise it goes
% in quotes. If the link is present, the title text is
% taken from the bibliographic entry and the element
% content is ignored. The title is followed by a
% citation in parentheses.\par
%    \begin{macrocode}
  <xsl:template match="db:citetitle">
    <xsl:call-template name="compensate-space"/>
    <xsl:choose>
      <xsl:when
        test="not(@linkend) or
              //*[@xml:id=current()/@linkend]/@areflabel='book'">
        <xsl:text>\emph{</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>“</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="@linkend">
        <xsl:apply-templates 
          select="//*[@xml:id=current()/@linkend]/db:title/node()"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when
        test="not(@linkend) or
              //*[@xml:id=current()/@linkend]/@areflabel='book'">
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>”</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="//db:biblioentry[@xml:id=current()/@linkend]">
      <xsl:text> \parencite{</xsl:text>
      <xsl:value-of
        select="translate(normalize-space(@linkend),' ',',')"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Inline code]{Inline code :}\label{inlinecode}
% \begin{CPKtemplate}{db:code}\label{template-db2dtx-code}
% Inline words of program code. Specified languages
% use \LaTeX{}’s {\ttfamily{}\textbackslash{}verb} command; others
% are just set in monospace type.\par
%    \begin{macrocode}
  <xsl:template match="db:code">
    <xsl:call-template name="compensate-space"/>
    <xsl:choose>
      <xsl:when test="@language='RE'">
        <xsl:text>\verb`/</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>/`</xsl:text>
      </xsl:when>
      <xsl:when test="@language='Cocoon'">
        <xsl:text>\verb`{</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>}`</xsl:text>
      </xsl:when>
      <xsl:when test="@language='bash'">
        <xsl:text>\verb`</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>`</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>\texttt{</xsl:text>
        <xsl:apply-templates/>
        <xsl:text>}</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Document classes]{Document classes :}\label{classes}
% \begin{CPKtemplate}{db:classname}\label{template-db2dtx-classname}
% This element type is used to identify a \LaTeX{}
% document class, generated using the
% {\ttfamily{}\textbackslash{}DescribeClass} command. Its use is
% limited to certain contexts in the \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}} part (not in footnotes,
% titles, or terms; not when it is already the current
% annotation name; and not twice in the same context).
% An example of usage can be set up by using the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} attribute to hold
% a sample optional argument, and the \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} attribute to
% hold the package name mnemonic, eg \DescribeClass{euroflag}\textsf{euroflag}\oarg{option}\marg{packagename}\par
%    \begin{macrocode}
  <xsl:template match="db:classname">
    <xsl:call-template name="compensate-space"/>
    <xsl:choose>
      <xsl:when
        test="ancestor::db:part[@xml:id='code'] and
              not(ancestor::db:footnote) and
              not(ancestor::db:title) and
              not(ancestor::db:term) and 
              not(.=ancestor::db:annotation/@xreflabel) and
              (@language='TeX'
              or @language='LaTeXe'
              or @language='LaTeX'
              or not(@language))
              and not(preceding-sibling::db:classname
                      [.=current()/.])">
        <xsl:text>\DescribeClass{</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>\index{</xsl:text>
        <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>@\textsf{</xsl:text>
        <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>} (class)</xsl:text>
        <xsl:text>}</xsl:text>
        <xsl:text>\index{classes:!</xsl:text>
        <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>@\textsf{</xsl:text>
        <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>}}</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <!-- always sans -->
    <xsl:text>\textsf{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
    <xsl:if test="@condition">
      <xsl:text>\oarg{</xsl:text>
      <xsl:value-of select="normalize-space(@condition)"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:if test="@conformance">
      <xsl:text>\marg{</xsl:text>
      <xsl:value-of select="normalize-space(@conformance)"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Commands]{Commands :}\label{commands}
% \begin{CPKtemplate}{db:command}\label{template-db2dtx-command1}
% This identifies a command in various syntaxes. A
% command occurring in documentation uses the
% {\ttfamily{}\textbackslash{}DescribeMacro}, or whatever other
% predefined equivalent is given in the \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}} attribute (eg \texttt{"counter"}\index{counter=\texttt{"counter"} (attribute value)}\index{attribute values:!counter=\texttt{"counter"}}, \texttt{"switch"}\index{switch=\texttt{"switch"} (attribute value)}\index{attribute values:!switch=\texttt{"switch"}}, \texttt{"length"}\index{length=\texttt{"length"} (attribute value)}\index{attribute values:!length=\texttt{"length"}}, etc: see
% {\ttfamily{}prepost.xml}). The \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute specifies
% that the command does not belong to the current
% package and is only mentioned incidentally, and
% therefore requires no indexing.\par
% The backslash is added programmatically: it must
% not be typed — it gets faked up when in
% \texttt{<term>}\index{term=\texttt{\char'074 term\char'076 } (element)}\index{elements:!term=\texttt{\char'074 term\char'076 }} (definition list) or when being used
% as an example (not for indexing); otherwise it uses
% {\ttfamily{}\textbackslash{}verb} if needed. The named template
% \DescribeTemplate{avoidverb}\texttt{avoidverb} is called to ensure
% a delimiter is chosen that does not interfere with the
% content.\par
%    \begin{macrocode}
  <xsl:template match="db:command">
    <xsl:call-template name="compensate-space"/>
    <xsl:if
      test="@role and not(.='TeX') and not(.='LaTeX') and
            not(ancestor::db:term) and 
            not(.=ancestor::db:annotation/@xreflabel) and
            (@language='TeX'
            or @language='LaTeXe'
            or @language='LaTeX'
            or not(@language))
            and not(preceding-sibling::db:command[.=current()/.])">
      <xsl:text>\DescribeMacro{\</xsl:text>
      <xsl:choose>
        <xsl:when 
          test="@language='TeX' or
                @language='LaTeXe' or
                @language='LaTeX' or
                not(@language)
                and contains(.,'{')">
          <xsl:value-of
            select="substring-before(normalize-space(.),'{')"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="normalize-space(.)"/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:choose>
      <xsl:when
        test="(@language='TeX' or
              @language='LaTeXe' or
              @language='LaTeX' or
              not(@language))
              and (not(@role) or parent::db:term)">
        <xsl:if test="parent::db:term and
                      @userlevel!='optional'">
          <xsl:text>\llap{$\star$\enspace}</xsl:text>
        </xsl:if>
        <xsl:choose>
          <xsl:when test="parent::db:term">
            <xsl:text>\texttt{\textbackslash{}</xsl:text>
            <xsl:apply-templates/>
            <xsl:text>}</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="avoidverb"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- use \verb for TeX commands if needed -->
      <xsl:when
        test="@language='TeX' or
              @language='LaTeXe' or
              @language='LaTeX' or
              not(@language)">
        <xsl:call-template name="avoidverb"/>
      </xsl:when>
      <!-- bash -->
      <xsl:when test="@language='bash'">
        <xsl:call-template name="avoidverb"/>
        <xsl:if test="@userlevel">
          <xsl:text>\thinspace(</xsl:text>
          <xsl:value-of select="@userlevel"/>
          <xsl:text>)</xsl:text>
        </xsl:if>
      </xsl:when>
      <!-- other language commands have no backslash -->
      <xsl:when test="@condition='nolit'">
        <xsl:call-template name="avoidverb"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="avoidverb"/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="@condition and
                  @condition!='nolit'">
      <xsl:text>\oarg{</xsl:text>
      <xsl:value-of
        select="normalize-space(@condition)"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:if test="@conformance">
      <xsl:text>\marg{</xsl:text>
      <xsl:value-of
        select="normalize-space(@conformance)"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Emphasis]{Emphasis :}\label{emphasis}
% \begin{CPKtemplate}{db:emphasis}\label{template-db2dtx-emphasis}
% Simple italicisation by default, or bold when the
% \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute is \texttt{"strong"}\index{strong=\texttt{"strong"} (attribute value)}\index{attribute values:!strong=\texttt{"strong"}}.\par
%    \begin{macrocode}
  <xsl:template match="db:emphasis">
    <xsl:call-template name="compensate-space"/>
    <xsl:choose>
      <xsl:when test="@role='strong'">
        <xsl:text>\textbf{</xsl:text>
      </xsl:when>
      <xsl:when test="ancestor::db:emphasis">
        <xsl:text>\textbf{\upshape </xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>\emph{</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Email addresses]{Email addresses :}\label{emails}
% \begin{CPKtemplate}{db:email}\label{template-db2dtx-email}
% This occurs in the metadata for the title page and
% just needs formatting as a
% \textsc{uri}.\par
%    \begin{macrocode}
  <xsl:template match="db:email">
    <xsl:text>\url{</xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Environments]{Environments :}\label{environments}
% \begin{CPKtemplate}{db:envar}\label{template-db2dtx-envar}
% This element is used to identify a \LaTeX{}
% environment. As with the \texttt{<command>}\index{command=\texttt{\char'074 command\char'076 } (element)}\index{elements:!command=\texttt{\char'074 command\char'076 }} element,
% the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute
% specifies the command does not belong to this package
% or class and is only mentioned incidentally. And as
% with \texttt{<classname>}\index{classname=\texttt{\char'074 classname\char'076 } (element)}\index{elements:!classname=\texttt{\char'074 classname\char'076 }}, the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} and \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} attributes are
% used to add metadata for describing the
% example.\par
%    \begin{macrocode}
  <xsl:template match="db:envar">
    <xsl:call-template name="compensate-space"/>
    <xsl:if test="@role and 
                  not(ancestor::db:term) and 
                  not(.=ancestor::db:annotation/@xreflabel) and
                  (@language='TeX'
                  or @language='LaTeXe'
                  or @language='LaTeX'
                  or not(@language))
                  and not(preceding-sibling::db:envar
                          [.=current()/.])">
      <xsl:text>\DescribeEnv{</xsl:text>
        <xsl:apply-templates/>
        <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>\texttt{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
    <xsl:if test="@condition">
      <xsl:text>\oarg{</xsl:text>
      <xsl:value-of select="normalize-space(@condition)"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:if test="@conformance">
      <xsl:text>\marg{</xsl:text>
      <xsl:value-of select="normalize-space(@conformance)"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Error messages]{Error messages :}\label{errors}
% \begin{CPKtemplate}{db:errortext}\label{template-db2dtx-errortext}
% Formal error text (error messages) can be
% identified and will be reproduced and indexed using
% Doc\TeX{}.\par
%    \begin{macrocode}
  <xsl:template match="db:errortext">
    <xsl:call-template name="compensate-space"/>
    <xsl:text>\DescribeError{</xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>}\textsf{</xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Action words]{Action words :}\label{actionwords}
% \begin{CPKtemplate}{db:exceptionname}\label{template-db2dtx-exceptionname1}
% This element is used to identify the action words
% of RFC 2119 ({\sffamily \textsc{must}},
% {\sffamily \textsc{must not}},
% {\sffamily \textsc{required}},
% {\sffamily \textsc{shall}},
% {\sffamily \textsc{shall not}},
% {\sffamily \textsc{should}},
% {\sffamily \textsc{should not}},
% {\sffamily \textsc{recommended}},
% {\sffamily \textsc{may}}, and
% {\sffamily \textsc{optional}}). Its use is
% detected in processing and the warning text
% automatically included in the preamble to the
% documentation.\par
%    \begin{macrocode}
  <xsl:template match="db:exceptionname">
    <xsl:call-template name="compensate-space"/>
    <xsl:text>{\sffamily </xsl:text>
    <xsl:call-template name="casestyle">
      <xsl:with-param name="text" select="normalize-space(.)"/>
    </xsl:call-template>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[File names]{File names :}\label{filenames}
% \begin{CPKtemplate}{db:filename}\label{template-db2dtx-filename}
% \begingroup\raggedright[\url{db:filename} 
% and \url{db:systemitem} 
% ]\par\endgroup
% Both share the same model and use the
% \DescribeTemplate{avoidverb}\texttt{avoidverb} named template to
% format in the monospace font.\par
%    \begin{macrocode}
  <xsl:template match="db:filename | db:systemitem">
    <xsl:call-template name="compensate-space"/>
    <xsl:call-template name="avoidverb"/>
    <xsl:if
      test="contains('.,;:?!',
            substring(following-sibling::node()[1],1,1))">
      <xsl:text>\thinspace</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[First occurrences of terms]{First occurrences of terms :}\label{firstterms}
% \begin{CPKtemplate}{db:firstterm}\label{template-db2dtx-firstterm}
% Used to identify the first occurrence of a
% specialist term that need explanation (bold
% italics).\par
%    \begin{macrocode}
  <xsl:template match="db:firstterm">
    <xsl:call-template name="compensate-space"/>
    <xsl:text>\textbf{\emph{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}}\index{</xsl:text>
    <xsl:value-of select="normalize-space(.)"/>
    <xsl:text>|textbf}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Footnotes]{Footnotes :}\label{footnotes}
% \begin{CPKtemplate}{db:footnote}\label{template-db2dtx-footnote1}
% Identified footnotes.\par
%    \begin{macrocode}
  <xsl:template match="db:footnote">
    <xsl:text>\footnote{%&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Foreign words]{Foreign words :}\label{foreign}
% \begin{CPKtemplate}{db:foreignphrase}\label{template-db2dtx-foreignphrase}
% Identifies a word or phrase in a language other
% than the base language of the document (italicised,
% but \textsc{cjk} is recognised; others use
% the {\ttfamily{}\textbackslash{}foreignlanguage} command of the
% \textsf{babel} package).\par
%    \begin{macrocode}
  <xsl:template match="db:foreignphrase">
    <xsl:call-template name="compensate-space"/>
    <xsl:choose>
      <xsl:when test="@xml:lang='jp'">
        <xsl:text>\cjktext{</xsl:text>
        <xsl:apply-templates/>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:when test="@xml:lang='ga'">
        <!--        <xsl:text>\texteiad{</xsl:text>-->
        <xsl:text>{</xsl:text>
        <xsl:value-of select="@remap"/>
        <xsl:apply-templates/>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:when test="@xml:lang!=/db:book/@xml:lang">
        <xsl:text>\foreignlanguage{</xsl:text>
        <xsl:value-of 
          select="$langs/language[concat(@Lang,'-',@Country)
                  =current()/@xml:lang]/@babel"/>
        <xsl:text>}{</xsl:text>
        <xsl:choose>
          <xsl:when test="$langs/language
                          [@iso=current()/@xml:lang]
                          /@wsys='la'">
            <xsl:text>\emph{</xsl:text>
            <xsl:apply-templates/>
            <xsl:text>}</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>\emph{</xsl:text>
        <xsl:apply-templates/>
        <xsl:text>}</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Functions]{Functions :}\label{functions}
% \begin{CPKtemplate}{db:function}\label{template-db2dtx-function}
% Identifies computer language functions, including
% \textsc{xslt} templates. Without the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} and \texttt{@language}\index{language=\texttt{\char'100 language} (attribute)}\index{attributes:!language=\texttt{\char'100 language}} attributes, the
% function is formatted and indexed with the
% {\ttfamily{}\textbackslash{}DescribeFunction} command.\par
%    \begin{macrocode}
  <xsl:template match="db:function">
    <xsl:call-template name="compensate-space"/>
    <xsl:if test="not(@role) and not(@language)">
      <xsl:text>\DescribeFunction{</xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>\texttt{</xsl:text>
    <xsl:value-of select="."/>
    <xsl:if test="@language='XSLT'">
      <xsl:text>()</xsl:text>
    </xsl:if>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[GUI widgets]{GUI widgets :}\label{gui}
% \begin{CPKtemplate}{db:guimenu}\label{template-db2dtx-guimenu}
% Identifies a named menu in a
% \textsc{gui}. Menu formatting is done with
% the \textsf{menukeys} package: adjacent
% elements in the \texttt{<gui*>}\index{gui*=\texttt{\char'074 gui*\char'076 } (element)}\index{elements:!gui*=\texttt{\char'074 gui*\char'076 }} group are formatted
% together.\par
%    \begin{macrocode}
  <!-- gui menu stuff -->
  <xsl:template match="db:guimenu">
    <xsl:call-template name="compensate-space"/>
    <xsl:choose>
      <xsl:when
        test="starts-with(local-name(
              preceding-sibling::node()[1]),'gui')">
        <xsl:message>
          <xsl:text>ERROR: top-level guimenu "</xsl:text>
          <xsl:value-of select="."/>
          <xsl:text>" preceded by </xsl:text>
          <xsl:value-of select="name(preceding-sibling::*[1])"/>
        </xsl:message>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>\menu{</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates/>
    <xsl:if
      test="not(starts-with(local-name(
            following-sibling::node()[1]),'gui'))">
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:guisubmenu}\label{template-db2dtx-guisubmenu}
% Identifies a named submenu in a
% \textsc{gui}. See note above.\par
%    \begin{macrocode}
  <xsl:template match="db:guisubmenu">
    <xsl:choose>
      <xsl:when
        test="starts-with(local-name(
              preceding-sibling::node()[1]),'gui')">
        <xsl:text>></xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>\menu{</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates/>
    <xsl:if
      test="not(starts-with(local-name(
            following-sibling::node()[1]),'gui'))">
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:guimenuitem}\label{template-db2dtx-guimenuitem}
% Identifies a named menu item in a
% \textsc{gui}. See note above.\par
%    \begin{macrocode}
  <xsl:template match="db:guimenuitem">
    <xsl:choose>
      <xsl:when
        test="starts-with(local-name(
              preceding-sibling::node()[1]),'gui')">
        <xsl:text>></xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>\menu{</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates/>
    <xsl:if
      test="not(starts-with(local-name(
            following-sibling::node()[1]),'gui'))">
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:guiicon}\label{template-db2dtx-guiicon}
% Uses the \emph{FontAwesome}
% icon if one is named in the \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}} attribute, otherwise
% uses the \texttt{@annotations}\index{annotations=\texttt{\char'100 annotations} (attribute)}\index{attributes:!annotations=\texttt{\char'100 annotations}} (for
% options) and \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}}
% (for filename) attributes to construct an
% {\ttfamily{}\textbackslash{}includegraphics} command.\par
%    \begin{macrocode}
  <xsl:template match="db:guiicon">
    <xsl:call-template name="compensate-space"/>
    <xsl:choose>
      <!-- use FontAwesome icon -->
      <xsl:when test="@remap">
        <xsl:text>\fa</xsl:text>
        <xsl:value-of select="@remap"/>
        <xsl:text>{}</xsl:text>
      </xsl:when>
      <!-- otherwise supplied image -->
      <xsl:otherwise>
        <xsl:text>\includegraphics</xsl:text>
        <xsl:if test="@annotations">
          <xsl:text>[</xsl:text>
          <xsl:value-of select="@annotations"/>
          <xsl:text>]</xsl:text>
        </xsl:if>
        <xsl:text>{</xsl:text>
        <xsl:value-of select="@xlink:href"/>
        <xsl:text>}</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <!-- element is normally empty -->
    <xsl:apply-templates/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:guilabel}\label{template-db2dtx-guilabel}
% Uses the angular keys of the
% \textsf{menukeys} package to represent icons
% in a \textsc{gui}.\par
%    \begin{macrocode}
  <xsl:template match="db:guilabel">
    <xsl:call-template name="compensate-space"/>
    <xsl:text>{\renewmenumacro{\keys}{angularkeys}\keys{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:guibutton}\label{template-db2dtx-guibutton}
% Uses the {\ttfamily{}\textbackslash{}changemenucolor} of the
% \textsf{menukeys} package to represent
% on-screen buttons in a \textsc{gui}.\par
%    \begin{macrocode}
  <xsl:template match="db:guibutton">
    <xsl:call-template name="compensate-space"/>
    <xsl:text>{\changemenucolor{keys}{bg}%</xsl:text>
    <xsl:text>  {HTML}{CDCDCD}\renewmenumacro{\keys}%</xsl:text>
    <xsl:text>  {shadowedangularkeys}\keys{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Importance]{Importance :}\label{importance}
% \begin{CPKtemplate}{db:important}\label{template-db2dtx-important}
% Identifies a segment of text of high importance
% and formats it in bold sans-serif type.\par
%    \begin{macrocode}
  <xsl:template match="db:important">
    <xsl:text>\begingroup\sffamily\bfseries&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>%   \endgroup </xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Indexing]{Indexing :}\label{indexing}
% \begin{CPKtemplate}{db:indexterm}\label{template-db2dtx-indexterm}
% Identifies a word or phrase needing indexing. With
% an \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute, it
% puts the page number in bold in the index.\par
%    \begin{macrocode}
  <xsl:template match="db:indexterm">
    <xsl:text>% \index{</xsl:text>
    <xsl:apply-templates/>
    <xsl:choose>
      <xsl:when test="@xml:id and not(db:see)">
        <xsl:text>|textbf</xsl:text>
      </xsl:when>
    </xsl:choose>
    <xsl:text>}&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Keyboard keys]{Keyboard keys :}\label{keycaps}
% \begin{CPKtemplate}{db:keycap}\label{template-db2dtx-keycap}
% Identifies a single key cap on the keyboard for
% the implication that the user presses it.\par
%    \begin{macrocode}
  <xsl:template match="db:keycap">
    <xsl:call-template name="compensate-space"/>
    <xsl:text>\keys{</xsl:text>
    <xsl:choose>
      <xsl:when test="contains('$%&#38;#',.)">
        <xsl:text>\</xsl:text>
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:when test=".='^' or .='~'">
        <xsl:text>\</xsl:text>
        <xsl:apply-templates/>
        <xsl:text>{}</xsl:text>
      </xsl:when>
      <xsl:when test="contains('{&lt;|&gt;}',/)">
        <xsl:text>\[</xsl:text>
        <xsl:apply-templates/>
        <xsl:text>\]</xsl:text>
      </xsl:when>
      <xsl:when test=".='\\'">
        <xsl:text>\textbackslash</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="."/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Links]{Links :}\label{links}
% \begin{CPKtemplate}{db:link}\label{template-db2dtx-link}
% Identifies a link to an external resource,
% typically a \textsc{uri}. If the
% \textsf{hyperref} package has been requested
% for the documentation, use the
% {\ttfamily{}\textbackslash{}hyperlink} command for the \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} attribute,
% otherwise use {\ttfamily{}\textbackslash{}url} for the \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} attribute; but if
% the content is non-null, just make it blue and
% underlined.\par
%    \begin{macrocode}
  <xsl:template match="db:link">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:call-template name="compensate-space"/>
    <xsl:choose>
      <!-- with hyperref or hypdoc either explicit or implicit -->
      <xsl:when
        test="//db:seg[.='hyperref' or .='hypdoc']
              or
              $prepost/db:procedure[@xml:id='prepackage']
              /db:step[@remap='hypdoc'
                       and
                       contains(@condition,'doc')]
                       [db:constructorsynopsis='']">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>using hyperlink</xsl:text>
      </xsl:message>
    </xsl:if>
        <xsl:text>\href{</xsl:text>
        <xsl:value-of select="@xlink:href"/>
        <xsl:text>}{</xsl:text>
        <xsl:choose>
          <xsl:when test="normalize-space(.)=''">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>molinkurl</xsl:text>
      </xsl:message>
    </xsl:if>
            <xsl:text>\nolinkurl{</xsl:text>
            <xsl:value-of
              select="replace(@xlink:href,'#','\\#')"/>
            <xsl:text>}</xsl:text>
          </xsl:when>
          <xsl:otherwise>
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>parsed character data ‘</xsl:text>
        <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>’</xsl:text>
      </xsl:message>
    </xsl:if>
            <xsl:apply-templates/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:otherwise>
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>using non-hyperlink</xsl:text>
      </xsl:message>
    </xsl:if>
        <xsl:choose>
          <!-- empty link text -->
          <xsl:when test=".=''">
            <xsl:text>\url{</xsl:text>
            <xsl:value-of select="@xlink:href"/>
            <xsl:text>}</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>{\color{blue}\uline{</xsl:text>
            <xsl:apply-templates/>
            <xsl:text>}}\footnote{\protect\url{</xsl:text>
            <xsl:value-of select="@xlink:href"/>
            <xsl:text>}}</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if
    test="contains('.,;:?!',
                    substring(following-sibling::node()[1],1,1))">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>test following sibling starting ‘</xsl:text>
        <xsl:value-of select="substring(following-sibling::node()[1],1,1)"/>
        <xsl:text>’</xsl:text>
      </xsl:message>
    </xsl:if>
      <xsl:text>\thinspace</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Literals]{Literals :}\label{literals}
% \begin{CPKtemplate}{db:literallayout}\label{template-db2dtx-literallayout1}
% This element enables the inclusion of \LaTeX{} code
% that is to be passed through to the
% {\ttfamily{}.dtx} file untouched, for the sake
% of special effects or functions that cannot be
% modelled in \emph{DocBook} \textsc{xml}. It also enables
% \emph{bash} code to be passed to
% the output file as well as set in the documentation
% using the {\ttfamily{}\textbackslash{}lstlisting} command (in
% restricted circumstances). Setting the
% \texttt{<audience>}\index{audience=\texttt{\char'074 audience\char'076 } (element)}\index{elements:!audience=\texttt{\char'074 audience\char'076 }} attribute to \texttt{<none>}\index{none=\texttt{\char'074 none\char'076 } (element)}\index{elements:!none=\texttt{\char'074 none\char'076 }} is
% unimplemented intended for use with a future
% \textsc{html}\index{HTML} output where the \LaTeX{} code
% would be irrelevant.\par
%    \begin{macrocode}
  <xsl:template match="db:literallayout[not(@audience='none')]">
    <xsl:if test="parent::db:para">
      <xsl:call-template name="compensate-space"/>
    </xsl:if>
    <xsl:choose>
      <xsl:when test="@language='LaTeXe' or
                      @language='LaTeX' or
                      @language='TeX' or
                      not(@language)">
        <xsl:value-of select="."/>
      </xsl:when>
      <xsl:when test="@language='bash'">
        <xsl:if 
          test="ancestor::db:part[@xml:id='code'] and
                ancestor::db:chapter/@xlink:href and
                ancestor::db:chapter/@xml:id and
                not(substring-after(
                    ancestor::db:chapter/@xlink:href,'.')='dtd' 
                 or substring-after(
                    ancestor::db:chapter/@xlink:href,'.')='xml' 
                 or substring-after(
                    ancestor::db:chapter/@xlink:href,'.')='xsl')">
          <xsl:text>% \iffalse&#xa;</xsl:text>
          <xsl:value-of select="$sentinel"/>
          <xsl:text>&#xa;</xsl:text>
          <xsl:apply-templates select="." mode="readme"/>
          <xsl:text>% \fi&#xa;</xsl:text>
        </xsl:if>
        <xsl:text>% \iffalse
%&lt;*ignore>
% \fi
</xsl:text>
        <xsl:text>\begin{lstlisting}</xsl:text>
        <xsl:text>[basicstyle=\small\color{DarkGreen}</xsl:text>
        <xsl:text>\ttfamily,language=</xsl:text>
        <xsl:value-of select="/db:book/@userlevel"/>
        <xsl:text>]&#xa;</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>\end{lstlisting}&#xa;</xsl:text>
        <xsl:text>% \iffalse
%&lt;/ignore>
% \fi
</xsl:text>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Templates]{Templates :}\label{templates}
% \begin{CPKtemplate}{db:methodname}\label{template-db2dtx-methodname}
% Used to identify a template in documenting
% \textsc{xslt}.\par
%    \begin{macrocode}
  <xsl:template match="db:methodname">
    <xsl:call-template name="compensate-space"/>
    <xsl:if test="not(@role) and not(ancestor::db:tgroup)">
      <xsl:text>\DescribeTemplate{</xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>\texttt{</xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Notes]{Notes :}\label{notes}
% \begin{CPKtemplate}{db:note}\label{template-db2dtx-note1}
% \begingroup\raggedright[\url{db:note} with \url{[not(parent::db:para)]} 
% ]\par\endgroup
% Creates a sidebar box for a note.\par
%    \begin{macrocode}
  <xsl:template match="db:note[not(parent::db:para)]">
    <xsl:text>% \begin{Sbox}\begin{minipage}</xsl:text>
    <xsl:text>{.85\columnwidth}\raggedright\sffamily</xsl:text>
    <xsl:if test="@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>&#xa;% \end{minipage}\end{Sbox}</xsl:text>
    <xsl:text>{\fboxsep1em\centering\fbox{\TheSbox}</xsl:text>
    <xsl:text>\par\smallskip}&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:note}\label{template-db2dtx-note2}
% \begingroup\raggedright[\url{db:note} with \url{[parent::db:para]} 
% ]\par\endgroup
% Creates a sidebar box for a note.\par
%    \begin{macrocode}
  <xsl:template match="db:note[parent::db:para]">
    <xsl:choose>
      <xsl:when test="@role='marginal'">
        <xsl:text>\marginnote{\raggedright </xsl:text>
        <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="compensate-space"/>
        <xsl:text>{\bfseries </xsl:text>
        <xsl:apply-templates/>
        <xsl:text>}</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Options]{Options :}\label{options}
% \begin{CPKtemplate}{db:option}\label{template-db2dtx-option}
% Identifies an optional command or value, usually
% to a \LaTeX{} command if there is a \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute specified,
% and the element does not occur within a title, term,
% footnote, table, or figure. It is formatted separately
% using the exemplar commands {\ttfamily{}\textbackslash{}oarg}
% and {\ttfamily{}\textbackslash{}marg} where values are provided;
% otherwise output in bold monospace type.\par
%    \begin{macrocode}
  <xsl:template match="db:option">
    <xsl:call-template name="compensate-space"/>
    <xsl:if test="@role and
                  not(ancestor::db:title) and 
                  not(ancestor::db:term) and 
                  not(ancestor::db:footnote) and 
                  not(ancestor::db:table) and 
                  not(ancestor::db:informaltable) and 
                  not(ancestor::db:figure)
                  and not(preceding-sibling::db:option
                          [.=current()/.])">
      <xsl:text>\DescribeOption{</xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:choose>
      <xsl:when test="@condition">
        <xsl:text>\oarg{</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:when test="@conformance">
        <xsl:text>\marg{</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <!-- otherwise it’s for a package or command -->
      <xsl:otherwise>
        <xsl:text>\textbf{\texttt{</xsl:text>
        <xsl:if test="@language='bash'">
          <xsl:text>-</xsl:text>
        </xsl:if>
        <xsl:apply-templates/>
        <xsl:if test="@language='bash' and @conformance='colon'">
          <xsl:text>:</xsl:text>
        </xsl:if>
        <xsl:text>}}</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Packages]{Packages :}\label{latex-packages}
% \begin{CPKtemplate}{db:package}\label{template-db2dtx-package}
% Identifies a \LaTeX{} package and formats in
% sans-serif type. May also be used for other systems’
% packages, eg \emph{bash}.\par
%    \begin{macrocode}
  <xsl:template match="db:package">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:call-template name="compensate-space"/>
    <xsl:if
      test="@role and
            not(ancestor::db:title) and 
            not(ancestor::db:abstract) and 
            not(ancestor::db:acknowledgements) and 
            not(ancestor::db:term) and 
            not(ancestor::db:footnote) and 
            not(ancestor::db:table) and 
            not(ancestor::db:informaltable) and 
            not(ancestor::db:figure) and
            not(preceding-sibling::db:package[.=current()/.])">
      <xsl:if test="$trace">
        <xsl:message>
          <xsl:text>describing package </xsl:text>
          <xsl:value-of select="."/>
        </xsl:message>
      </xsl:if>
      <xsl:text>\DescribePackage{</xsl:text>
      <xsl:choose>
        <xsl:when test=".=''">
          <xsl:value-of select="/*[1]/@xml:id"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="."/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <!-- use sf but heavier when already sf -->
    <xsl:text>\textsf{</xsl:text>
    <xsl:choose>
      <xsl:when test=".=''">
        <xsl:value-of select="/*[1]/@xml:id"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>}</xsl:text>
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>done package</xsl:text>
      </xsl:message>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Personal names]{Personal names :}\label{personname}
% \begin{CPKtemplate}{db:personname}\label{template-db2dtx-personname}
% Identifies a person’s name for indexing. The
% \texttt{<firstname>}\index{firstname=\texttt{\char'074 firstname\char'076 } (element)}\index{elements:!firstname=\texttt{\char'074 firstname\char'076 }} and \texttt{<surname>}\index{surname=\texttt{\char'074 surname\char'076 } (element)}\index{elements:!surname=\texttt{\char'074 surname\char'076 }}
% subelements {\sffamily \textsc{must}} occur
% in that order, even if the individual’s culture
% usually reverses them (eg Hungary).\par
%    \begin{macrocode}
  <xsl:template match="db:personname">
    <xsl:call-template name="compensate-space"/>
    <xsl:apply-templates/>
    <xsl:text>\index{</xsl:text>
    <xsl:value-of select="normalize-space(db:surname)"/>
    <xsl:text>!</xsl:text>
    <xsl:value-of select="normalize-space(db:firstname)"/>
    <xsl:if test="db:othername">
      <xsl:text> </xsl:text>
      <xsl:value-of select="normalize-space(db:othername)"/>
    </xsl:if>
    <xsl:text>}</xsl:text>
  </xsl:template>

  <xsl:template match="db:personname/db:firstname">
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="db:personname/db:othername">
    <xsl:if test="preceding-sibling::node()!=' '">
      <xsl:text> </xsl:text>
    </xsl:if>
    <xsl:value-of select="."/>
    <xsl:if
      test="string-length(normalize-space(.)) = 1
            or 
            (.=upper-case(.)
             and
             substring(.,string-length(.))!='.')">
      <xsl:text>.</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="db:personname/db:surname">
    <xsl:if test="preceding-sibling::node()!=' '">
      <xsl:text> </xsl:text>
    </xsl:if>
    <xsl:value-of select="."/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Primary index keywords]{Primary index keywords :}\label{primary}
% \begin{CPKtemplate}{db:primary}\label{template-db2dtx-primary}
% Within an \texttt{<indexterm>}\index{indexterm=\texttt{\char'074 indexterm\char'076 } (element)}\index{elements:!indexterm=\texttt{\char'074 indexterm\char'076 }}, identifies the
% word as the primary term.\par
%    \begin{macrocode}
  <xsl:template match="db:primary">
    <xsl:value-of select="normalize-space(.)"/>
    <xsl:if test="@sortas">
      <xsl:text>@</xsl:text>
      <xsl:value-of select="normalize-space(@sortas)"/>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Product names]{Product names :}\label{prod}
% \begin{CPKtemplate}{db:productname}\label{template-db2dtx-productname}
% Identifies a product name, either commercial or
% Open Source, especially program names. The \texttt{@userlevel}\index{userlevel=\texttt{\char'100 userlevel} (attribute)}\index{attributes:!userlevel=\texttt{\char'100 userlevel}} attribute can be
% used for the chapter of the
% Unix/\textsc{gnu} Linux manual.\par
%    \begin{macrocode}
  <xsl:template match="db:productname">
    <xsl:call-template name="compensate-space"/>
    <xsl:text>\emph{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
    <xsl:if test="@userlevel">
      <xsl:text>\thinspace(</xsl:text>
      <xsl:value-of select="@userlevel"/>
      <xsl:text>)</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Quotations]{Quotations :}\label{quotes}
% \begin{CPKtemplate}{db:quotes}\label{template-db2dtx-quotes}
% \begingroup\raggedright[\url{db:quote} 
% and \url{db:phrase} 
% and \url{db:wordasword} 
% ]\par\endgroup
% Identifies quotes, words, or phrases which require
% quotation marks.\par
%    \begin{macrocode}
  <xsl:template match="db:quote | db:phrase | db:wordasword">
    <xsl:call-template name="compensate-space"/>
    <xsl:if test="count(preceding-sibling::node())=0">
      <xsl:text>\leavevmode\llap</xsl:text>
    </xsl:if>
    <xsl:text>`</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>'</xsl:text>
    <xsl:if test="@linkend">
      <xsl:text>&#x0a;</xsl:text>
      <xsl:call-template name="makeref"/>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Replaceable text]{Replaceable text :}\label{replaceable}
% \begin{CPKtemplate}{db:replaceable}\label{template-db2dtx-replaceable}
% Like \texttt{<token>}\index{token=\texttt{\char'074 token\char'076 } (element)}\index{elements:!token=\texttt{\char'074 token\char'076 }}, this represents variable
% information (usually mnemonic, like `your
%   username') for use in a
% \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} element.\par
%    \begin{macrocode}
  <xsl:template match="db:replaceable">
    <xsl:call-template name="compensate-space"/>
    <!-- make sure we use the same delimiter 
         as the parent element does -->
    <xsl:variable name="delim">
      <!-- in order of preference -->
      <xsl:choose>
        <xsl:when test="not(contains(.,'|'))">
          <xsl:text>|</xsl:text>
        </xsl:when>
        <xsl:when test="not(contains(.,'+'))">
          <xsl:text>+</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>`</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:choose>
      <!-- stop-start \verb when in a command or systemitem -->
      <xsl:when test="parent::db:command 
                      or parent::db:systemitem
                      or parent::db:filename">
        <xsl:value-of select="$delim"/>
        <xsl:text>{\ttfamily\itshape </xsl:text>
        <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>}</xsl:text>
        <xsl:text>\verb</xsl:text>
        <xsl:value-of select="$delim"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>\uline{</xsl:text>
        <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>}</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Secondary index keywords]{Secondary index keywords :}\label{secondary}
% \begin{CPKtemplate}{secondary}\label{template-db2dtx-secondary}
% \begingroup\raggedright[\url{db:secondary} 
% and \url{db:tertiary} 
% ]\par\endgroup
% Within an \texttt{<indexterm>}\index{indexterm=\texttt{\char'074 indexterm\char'076 } (element)}\index{elements:!indexterm=\texttt{\char'074 indexterm\char'076 }}, identifies the
% word as the secondary (or tertiary) term for a
% multi-level index.\par
%    \begin{macrocode}
  <xsl:template match="db:secondary | db:tertiary">
    <xsl:text>!</xsl:text>
    <xsl:value-of select="normalize-space(.)"/>
    <xsl:if test="@sortas">
      <xsl:text>@</xsl:text>
      <xsl:value-of select="normalize-space(@sortas)"/>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[See also in indexes]{See also in indexes :}\label{seealso}
% \begin{CPKtemplate}{db:see}\label{template-db2dtx-see}
% Within an \texttt{<indexterm>}\index{indexterm=\texttt{\char'074 indexterm\char'076 } (element)}\index{elements:!indexterm=\texttt{\char'074 indexterm\char'076 }}, identifies the
% word to be the target of a
% `see' link.\par
%    \begin{macrocode}
  <xsl:template match="db:see">
    <xsl:text>|see{</xsl:text>
    <xsl:value-of select="normalize-space(.)"/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Superscripts]{Superscripts :}\label{super}
% \begin{CPKtemplate}{db:superscript}\label{template-db2dtx-superscript}
% Identifies a superscript.\par
%    \begin{macrocode}
  <xsl:template match="db:superscript">
    <xsl:text>\textsuperscript{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Tag markup]{Tag markup :}\label{tags}
% \begin{CPKtemplate}{db:markup}\label{template-db2dtx-markup}
% Identifies an element of markup in a
% non-\textsc{xml} language.\par
%    \begin{macrocode}
  <xsl:template match="db:markup">
    <xsl:call-template name="compensate-space"/>
    <xsl:text>\texttt{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:tag}\label{template-db2dtx-tag1}
% Identifies an item of \textsc{xml}
% construction. {\sffamily \textsc{only}} the
% name is given as content: the punctuation for
% elements, tags, attributes, etc, is added, based on
% the \texttt{@class}\index{class=\texttt{\char'100 class} (attribute)}\index{attributes:!class=\texttt{\char'100 class}} attribute.
% Different functions from Doc\TeX{} are used to format
% it, depending on this data, if the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute is
% non-null.\par
%    \begin{macrocode}
  <xsl:template match="db:tag">
    <xsl:call-template name="compensate-space"/>
    <xsl:variable name="tagval" select="normalize-space(.)"/>
    <!-- unclear what @role was destined for -->
    <xsl:if
      test="@role and
            not(ancestor::db:title) and 
            not(ancestor::db:term) and 
            not(ancestor::db:footnote) and 
            not(ancestor::db:table) and 
            not(ancestor::db:informaltable) and 
            not(ancestor::db:figure)
            and not(preceding-sibling::db:tag[.=$tagval])">
      <xsl:text>\Describe</xsl:text>
      <xsl:choose>
        <xsl:when test="@class='element' or not(@class)">
          <xsl:text>Element</xsl:text>
        </xsl:when>
        <xsl:when test="@class='attribute'">
          <xsl:text>Attribute</xsl:text>
        </xsl:when>
        <xsl:when test="@class='attvalue'">
          <xsl:text>AttributeValue</xsl:text>
        </xsl:when>
        <xsl:when test="@class='genentity'">
          <xsl:text>Entity</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>Error</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>{</xsl:text>
      <xsl:apply-templates/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>\texttt{</xsl:text>
    <xsl:choose>
      <xsl:when test="@class='starttag'
                      or
                      @class='emptytag'
                      or
                      @class='endtag'
                      or
                      not(@class)">
        <xsl:text>&lt;</xsl:text>
        <xsl:if test="@class='endtag'">
          <xsl:text>/</xsl:text>
        </xsl:if>
      </xsl:when>
      <xsl:when test="@class='attvalue'">
        <xsl:if
          test="name(preceding-sibling::node()[1])='tag'
                and preceding-sibling::*[1]/@class='attribute'">
          <xsl:text>\unskip=</xsl:text>
        </xsl:if>
        <xsl:text>"</xsl:text>
      </xsl:when>
      <xsl:when
        test="@class='attribute' and not(@conformance='noat')">
        <xsl:if
          test="name(preceding-sibling::node()[1])='tag'
                and (
                preceding-sibling::*[1]/@class='element' or
                preceding-sibling::*[1]/@class='emptytag' or
                preceding-sibling::*[1]/@class='starttag' or
                preceding-sibling::*[1][not(@class)]
                )">
          <xsl:text>\unskip/</xsl:text>
        </xsl:if>
        <xsl:text>@</xsl:text>
      </xsl:when>
      <xsl:when test="@class='genentity'">
        <xsl:text>\&amp;</xsl:text>
      </xsl:when>
      <xsl:when test="@class='declaration'">
        <xsl:text>!</xsl:text>
      </xsl:when>
      <xsl:when test="@class='numcharref'">
        <xsl:text>\&amp;\#x</xsl:text>
      </xsl:when>
    </xsl:choose>
    <xsl:value-of select="$tagval"/>
    <xsl:choose>
      <xsl:when test="@class='starttag'
                      or
                      @class='emptytag'
                      or
                      @class='endtag'
                      or
                      not(@class)">
        <xsl:if test="@class='emptytag'">
          <xsl:text>/</xsl:text>
        </xsl:if>
        <xsl:text>&gt;</xsl:text>
      </xsl:when>
      <xsl:when test="@class='attvalue'">
        <xsl:text>"</xsl:text>
      </xsl:when>
      <xsl:when test="@class='genentity' or @class='numcharref'">
        <xsl:text>;</xsl:text>
      </xsl:when>
    </xsl:choose>
    <xsl:text>}</xsl:text>
    <!-- INDEXING MARKUP -->
    <xsl:text>\index{</xsl:text>
    <!-- sort value -->
    <xsl:value-of select="$tagval"/>
    <!-- style for entry (different delimiter to makeindex default) -->
    <xsl:text>=\texttt{</xsl:text>
    <!-- STAGO -->
    <xsl:choose>
      <xsl:when test="@class='element' or not(@class)">
        <xsl:text>\char'074 </xsl:text>
      </xsl:when>
      <!-- safety first in outputting an @ sign in an index -->
      <xsl:when test="@class='attribute'">
        <xsl:text>\char'100 </xsl:text>
      </xsl:when>
      <xsl:when test="@class='attvalue'">
        <xsl:text>"</xsl:text>
      </xsl:when>
      <xsl:when test="@class='emptytag'">
        <xsl:text>\char'074 </xsl:text>
      </xsl:when>
      <xsl:when test="@class='genentity'">
        <xsl:text>\&amp;</xsl:text>
      </xsl:when>
      <xsl:when test="@class='localname'">
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:when test="@class='starttag'">
        <xsl:text>\char'074 </xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>?</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:value-of select="$tagval"/>
    <!-- TAGC -->
    <xsl:choose>
      <xsl:when test="@class='element' or not(@class)">
        <xsl:text>\char'076 </xsl:text>
      </xsl:when>
      <xsl:when test="@class='attribute'">
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:when test="@class='attvalue'">
        <xsl:text>"</xsl:text>
      </xsl:when>
      <xsl:when test="@class='emptytag'">
        <xsl:text>/\char'076 </xsl:text>
      </xsl:when>
      <xsl:when test="@class='genentity'">
        <xsl:text>;</xsl:text>
      </xsl:when>
      <xsl:when test="@class='localname'">
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:when test="@class='starttag'">
        <xsl:text>\char'076 </xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>?</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>} (</xsl:text>
    <!-- human names -->
    <xsl:choose>
      <xsl:when test="@class='element' or not(@class)">
        <xsl:text>element</xsl:text>
      </xsl:when>
      <xsl:when test="@class='attribute'">
        <xsl:text>attribute</xsl:text>
      </xsl:when>
      <xsl:when test="@class='attvalue'">
        <xsl:text>attribute value</xsl:text>
      </xsl:when>
      <xsl:when test="@class='emptytag'">
        <xsl:text>empty element</xsl:text>
      </xsl:when>
      <xsl:when test="@class='genentity'">
        <xsl:text>general entity</xsl:text>
      </xsl:when>
      <xsl:when test="@class='localname'">
        <xsl:text>local name</xsl:text>
      </xsl:when>
      <xsl:when test="@class='starttag'">
        <xsl:text>start-tag</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="@class"/>
      </xsl:otherwise>
    </xsl:choose>
    <!-- two-level index -->
    <xsl:text>)}\index{</xsl:text>
    <!-- top level: pluralised class with colon -->
    <xsl:choose>
      <xsl:when test="@class='element' or not(@class)">
        <xsl:text>elements</xsl:text>
      </xsl:when>
      <xsl:when test="@class='attribute'">
        <xsl:text>attributes</xsl:text>
      </xsl:when>
      <xsl:when test="@class='attvalue'">
        <xsl:text>attribute values</xsl:text>
      </xsl:when>
      <xsl:when test="@class='emptytag'">
        <xsl:text>empty elements</xsl:text>
      </xsl:when>
      <xsl:when test="@class='genentity'">
        <xsl:text>general entities</xsl:text>
      </xsl:when>
      <xsl:when test="@class='localname'">
        <xsl:text>local names</xsl:text>
      </xsl:when>
      <xsl:when test="@class='starttag'">
        <xsl:text>start-tags</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="@class"/>
        <xsl:text>s</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <!-- colon and second-level delimiter -->
    <xsl:text>:!</xsl:text>
    <!-- sort value -->
    <xsl:value-of select="$tagval"/>
    <xsl:text>=\texttt{</xsl:text>
    <!-- STAGO -->
    <xsl:choose>
      <xsl:when test="@class='element' or not(@class)">
        <xsl:text>\char'074 </xsl:text>
      </xsl:when>
      <xsl:when test="@class='attribute'">
        <xsl:text>\char'100 </xsl:text>
      </xsl:when>
      <xsl:when test="@class='attvalue'">
        <xsl:text>"</xsl:text>
      </xsl:when>
      <xsl:when test="@class='emptytag'">
        <xsl:text>\char'074 </xsl:text>
      </xsl:when>
      <xsl:when test="@class='genentity'">
        <xsl:text>\&amp;</xsl:text>
      </xsl:when>
      <xsl:when test="@class='localname'">
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:when test="@class='starttag'">
        <xsl:text>\char'074 </xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>?</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:value-of select="$tagval"/>
    <!-- TAGC -->
    <xsl:choose>
      <xsl:when test="@class='element' or not(@class)">
        <xsl:text>\char'076 </xsl:text>
      </xsl:when>
      <xsl:when test="@class='attribute'">
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:when test="@class='attvalue'">
        <xsl:text>"</xsl:text>
      </xsl:when>
      <xsl:when test="@class='emptytag'">
        <xsl:text>/\char'076</xsl:text>
      </xsl:when>
      <xsl:when test="@class='genentity'">
        <xsl:text>;</xsl:text>
      </xsl:when>
      <xsl:when test="@class='localname'">
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:when test="@class='starttag'">
        <xsl:text>\char'076</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>?</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>}}</xsl:text>
    <xsl:if
      test="name(following-sibling::node()[1])='' and
            starts-with(following-sibling::node()[1],'s')">
      <xsl:text>\kern1pt{}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[TODO tasks]{TODO tasks :}\label{TODO}
% \begin{CPKtemplate}{db:task}\label{template-db2dtx-task}
% Highlights TODO notes like\par
% \par\smallskip\leavevmode
% \CPKrunningecho{db:task}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Collate these into a plan}}\par\smallskip
%    \begin{macrocode}
  <xsl:template match="db:task">
    <xsl:text>% \par\smallskip\leavevmode
% \CPKrunningecho{</xsl:text>
    <xsl:value-of
      select="parent::db:annotation/@xreflabel
              |
              ancestor::db:varlistentry/db:term"/>
    <xsl:text>}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO:</xsl:text>
    <xsl:for-each select="*">
      <xsl:text> </xsl:text>
      <xsl:value-of select="normalize-space(.)"/>
    </xsl:for-each>
    <xsl:text>}}\par\smallskip&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Titles to Notes]{Titles to Notes :}\label{note-title}
% \begin{CPKtemplate}{db:title}\label{template-db2dtx-title6}
% \begingroup\raggedright[in \url{db:note/} 
% ]\par\endgroup
% Makes the title of a note a subsubsection level
% heading.\par
%    \begin{macrocode}
  <xsl:template match="db:note/db:title">
    <xsl:text>% \subsubsection*{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Highlights in listings]{Highlights in listings :}\label{tokens}
% \begin{CPKtemplate}{db:token}\label{template-db2dtx-token}
% Identifies atomic values within the text of a
% \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} element and highlights them
% in italics.\par
%    \begin{macrocode}
  <xsl:template match="db:token">
    <xsl:call-template name="compensate-space"/>
    <xsl:text>{\normalfont\itshape</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Typographic rendering]{Typographic rendering :}\label{typography}
% \begin{CPKtemplate}{db:type}\label{template-db2dtx-type}
% \begingroup\raggedright[\url{} with \url{[@role='font' or not(@role)]} 
% ]\par\endgroup
% Usurped to represent typographic variation when
% documenting typesetting. See the
% {\ttfamily{}doctexbook.dtd} for details of the
% attributes added.\par
%    \begin{macrocode}
  <xsl:template match="db:type[@role='font' or not(@role)]">
    <xsl:text>{</xsl:text>
    <xsl:choose>
      <!-- empty and fontfamily means identify the font -->
      <xsl:when test=".='' and @fontfamily">
        <xsl:choose>
          <xsl:when test="@fontfamily='sans'">
            <xsl:text>\sffamily </xsl:text>
          </xsl:when>
          <xsl:when test="@fontfamily='roman'">
            <xsl:text>\rmfamily </xsl:text>
          </xsl:when>
          <xsl:when test="@fontfamily='monospace'">
            <xsl:text>\ttfamily </xsl:text>
          </xsl:when>
        </xsl:choose>
        <xsl:text>\printexternalcurrentfont</xsl:text>
      </xsl:when>
      <!-- otherwise format something -->
      <xsl:otherwise>
        <xsl:if test="@fontcolor">
          <xsl:text>\color</xsl:text>
          <xsl:if test="@conformance">
            <xsl:text>[</xsl:text>
            <xsl:value-of select="@conformance"/>
            <xsl:text>[</xsl:text>
          </xsl:if>
          <xsl:text>{</xsl:text>
          <xsl:value-of select="@fontcolor"/>
          <xsl:text>}</xsl:text>
        </xsl:if>
        <xsl:if test="@fontencoding">
          <xsl:text>\fontencoding{</xsl:text>
          <xsl:value-of select="upper-case(@fontencoding)"/>
          <xsl:text>}</xsl:text>
        </xsl:if>
        <xsl:if test="@fontfamily">
          <!-- special cases -->
          <xsl:choose>
            <xsl:when test="@fontfamily='sans'">
              <xsl:text>\sffamily </xsl:text>
            </xsl:when>
            <xsl:when test="@fontfamily='roman'">
              <xsl:text>\rmfamily </xsl:text>
            </xsl:when>
            <xsl:when test="@fontfamily='monospace'">
              <xsl:text>\ttfamily </xsl:text>
            </xsl:when>
          </xsl:choose>
        </xsl:if>
        <xsl:if test="@fontface">
          <xsl:text>\fontfamily{</xsl:text>
          <xsl:value-of select="@fontface"/>
          <xsl:text>}</xsl:text>
        </xsl:if>
        <xsl:if test="@fontshape">
          <xsl:text>\</xsl:text>
          <xsl:value-of select="@fontshape"/>
          <xsl:text>shape</xsl:text>
        </xsl:if>
        <xsl:if test="@fontseries">
          <xsl:text>\fontseries{</xsl:text>
          <xsl:value-of select="@fontseries"/>
          <xsl:text>}</xsl:text>
        </xsl:if>
        <xsl:if test="@fontsize">
          <xsl:text>\fontsize{</xsl:text>
          <xsl:choose>
            <xsl:when test="contains(@fontsize,'/')">
              <xsl:value-of
                select="substring-before(@fontsize,'/')"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="@fontsize"/>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:text>}{</xsl:text>
          <xsl:choose>
            <xsl:when test="contains(@fontsize,'/')">
              <xsl:value-of
                select="substring-after(@fontsize,'/')"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>0</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:text>}</xsl:text>
        </xsl:if>
        <xsl:text>\selectfont </xsl:text>
        <xsl:apply-templates/>
        <xsl:if test="@fontsize and contains(@fontsize,'/')">
          <xsl:text>\par</xsl:text>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:typecol}\label{template-db2dtx-typecol}
% \begingroup\raggedright[\url{db:type} with \url{[@role='color']} 
% ]\par\endgroup
% Used when the \texttt{<type>}\index{type=\texttt{\char'074 type\char'076 } (element)}\index{elements:!type=\texttt{\char'074 type\char'076 }} element invokes
% colour alone, and generates the requested colour for
% use with the \textsf{xcolor} package\par
%    \begin{macrocode}
  <xsl:template match="db:type[@role='color']">
    <xsl:call-template name="compensate-space"/>
    <xsl:text>\DescribeColor{</xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>}\texttt{</xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[URIs]{URIs :}\label{uris}
% \begin{CPKtemplate}{db:uri}\label{template-db2dtx-uri1}
% with an \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} \textsc{uri} \emph{and} text
% content, this formats the content followed by a
% footnote to the \textsc{uri}. Without the
% attribute, the content itself is assumed by be a
% \textsc{uri} and is formatted inline. An
% optional \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}}
% attribute holding a Usenet News group name, with the
% \texttt{@type}\index{type=\texttt{\char'100 type} (attribute)}\index{attributes:!type=\texttt{\char'100 type}} attribute set to
% \texttt{"news"}\index{news=\texttt{"news"} (attribute value)}\index{attribute values:!news=\texttt{"news"}}, will add a reference
% to the group.\par
%    \begin{macrocode}
  <xsl:template match="db:uri">
    <xsl:call-template name="compensate-space"/>
    <xsl:choose>
      <xsl:when test="@xlink:href and .!=''">
        <xsl:apply-templates/>
        <xsl:text>\footnote{\url{</xsl:text>
        <xsl:value-of select="@xlink:href"/>
        <xsl:text>}}</xsl:text>
      </xsl:when>
      <xsl:when test="not(@xlink:href) and .!=''">
        <xsl:text>\url{</xsl:text>
        <xsl:if test="@type">
          <xsl:value-of select="@type"/>
          <xsl:text>:</xsl:text>
        </xsl:if>
        <xsl:apply-templates/>
        <xsl:text>}</xsl:text>
      </xsl:when>
    </xsl:choose>
    <xsl:if test="@xreflabel and @type='news'">
      <xsl:text> at \textlangle\verb`</xsl:text>
      <xsl:value-of select="@xreflabel"/>
      <xsl:text>`\textrangle{}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Variables]{Variables :}\label{vars}
% \begin{CPKtemplate}{db:varname}\label{varparlen}
% \begingroup\raggedright[\url{db:varname} with \url{[ancestor::db:footnote or ancestor::db:abstract]} 
% and \url{db:parameter} with \url{[ancestor::db:footnote or ancestor::db:abstract]} 
% ]\par\endgroup
% Identifies variables and parameters, especially
% for \LaTeX{} with the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}}
% set to \texttt{"counter"}\index{counter=\texttt{"counter"} (attribute value)}\index{attribute values:!counter=\texttt{"counter"}}, \texttt{"length"}\index{length=\texttt{"length"} (attribute value)}\index{attribute values:!length=\texttt{"length"}}, \texttt{"template"}\index{template=\texttt{"template"} (attribute value)}\index{attribute values:!template=\texttt{"template"}}; or \texttt{"variable"}\index{variable=\texttt{"variable"} (attribute value)}\index{attribute values:!variable=\texttt{"variable"}} or
% \texttt{<parameter>}\index{parameter=\texttt{\char'074 parameter\char'076 } (element)}\index{elements:!parameter=\texttt{\char'074 parameter\char'076 }} (for \textsc{xslt}),
% using the relevant {\ttfamily{}\textbackslash{}Describe} macro
% to put the unheralded name in the margin. For other
% values (color and prog), this invokes the
% \DescribeTemplate{avoidverb}\texttt{avoidverb} named template for
% formatting.\par
% A feature is the avoidance of clashes with a
% containing \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} for the same role and
% name: the {\ttfamily{}\textbackslash{}Describe} macro is invoked
% only where the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}}
% attribute is non-null \\\emph{and} the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} is
% \emph{not} set to \texttt{"nodesc"}\index{nodesc=\texttt{"nodesc"} (attribute value)}\index{attribute values:!nodesc=\texttt{"nodesc"}}\\\emph{and} it is not in the first
% paragraph of the \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }}\\\emph{and} the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} (or, in the case of the
% \texttt{<parameter>}\index{parameter=\texttt{\char'074 parameter\char'076 } (element)}\index{elements:!parameter=\texttt{\char'074 parameter\char'076 }}, the name) is not the same value
% of the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute on
% the \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }}\\\emph{and} the content is not the
% same as the \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }}’s \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} attribute.\par
%    \begin{macrocode}
  <!-- Counters and Lengths and Variables,
       not in footnotes or the abstract -->
  <xsl:template
    match="db:varname[not(ancestor::db:footnote
                       or ancestor::db:abstract)]
           |
           db:parameter[not(ancestor::db:footnote
                         or ancestor::db:abstract)]">
    <xsl:call-template name="compensate-space"/>
    <xsl:if
      test="@role and @role!=''
            and
            not(@condition='nodesc')
            and
            not(count(parent::db:para
                      /preceding-sibling::db:para) = 0
                and
                ancestor::db:annotation
                    [(@role=current()/@role
                     or
                     @role=current()/name())
                     and
                     @xreflabel=current()/.])
            and 
            not(preceding-sibling::db:varname
                [.=current()/.]
                [@role=current()/@role])">
      <xsl:text>\Describe</xsl:text>
      <!-- Capitalise the type of variable for the \Describe* macro:
           Counter Function Length Template Variable Parameter -->
      <xsl:value-of
        select="translate(
                substring(@role,1,1),'cfltvp','CFLTVP')"/>
      <xsl:value-of select="substring(@role,2)"/>
      <xsl:text>{</xsl:text>
      <xsl:value-of select="normalize-space(.)"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:call-template name="avoidverb"/>
  </xsl:template>

  <!-- variable names in footnotes and the abstract -->
  <xsl:template
    match="db:varname[ancestor::db:footnote
                      or
                      ancestor::db:abstract]
           |
           db:parameter[ancestor::db:footnote
                        or
                        ancestor::db:abstract]">
    <xsl:call-template name="compensate-space"/>
    <xsl:call-template name="avoidverb"/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Enumerated references]{Enumerated references :}\label{enumrefs}
% \begin{CPKtemplate}{corefs}\label{template-db2dtx-corefs}
% Counted (enumerated) references (corefs) are for
% assigning a number to items in an unnumbered list so
% that they can be referenced with an ordinal.\par
%    \begin{macrocode}
  <xsl:template match="db:coref">
    <xsl:text>\setcounter{CPKcoref}{</xsl:text>
    <xsl:value-of 
      select="count(//*[@xml:id=current()/@linkend]
              /descendant::*[name()=current()/@xreflabel])"/>
    <xsl:text>}\numberstring{CPKcoref}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Revisions]{Revisions :}\label{revs}
% \begin{CPKtemplate}{revision}\label{template-db2dtx-revision}
% List the revisions as unnumbered subsections,
% showing the version and date; if there’s only one
% linked change, use a bullet; otherwise use
% numbers.\par
%    \begin{macrocode}
  <xsl:template match="db:revision">
    <xsl:text>% \subsection*{v.</xsl:text>
    <xsl:value-of select="@version"/>
    <xsl:text> (</xsl:text>
    <xsl:value-of select="db:date/@YYYY-MM-DD"/>
    <xsl:text>)}&#xa;</xsl:text>
    <xsl:apply-templates select="db:revdescription/*"/>
    <xsl:if test="//*[@revisionflag and
                     @revision=current()/db:date/@YYYY-MM-DD]">
      <xsl:text>% \begin{</xsl:text>
      <xsl:choose>
        <xsl:when
          test="count(//*[@revisionflag and
                @revision=current()/db:date/@YYYY-MM-DD])&gt;1">
          <xsl:text>enumerate</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>itemize</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>}[nosep]&#xa;</xsl:text>
      <xsl:for-each
        select="//*[@revisionflag and
                   @revision=current()/db:date/@YYYY-MM-DD]">
        <xsl:text>%   \item \vref{</xsl:text>
        <xsl:value-of select="@xml:id"/>
        <xsl:text>}</xsl:text>
        <xsl:value-of select="@revisionflag"/>
        <xsl:text>: </xsl:text>
        <xsl:value-of select="normalize-space(@annotations)"/>
        <xsl:text>&#xa;</xsl:text>
      </xsl:for-each>
      <xsl:text>% \end{</xsl:text>
      <xsl:choose>
        <xsl:when
          test="count(//*[@revisionflag
                          and
                          @revision=current()
                            /db:date/@YYYY-MM-DD])&gt;1">
          <xsl:text>enumerate</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>itemize</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>}&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Inline mathematics]{Inline mathematics :}\label{inlineeq}
% \begin{CPKtemplate}{inlineequation}\label{template-db2dtx-inlineequation}
% Inline equations
% {\sffamily \textsc{must}} contain \LaTeX{}
% math code, so they are rendered within inline math
% delimiters.\par
%    \begin{macrocode}
  <xsl:template match="db:inlineequation">
    <xsl:apply-templates/>
    <xsl:if test="@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="db:mathphrase">
    <xsl:choose>
      <!-- assume @remap is LaTeX -->
      <xsl:when test="@remap">
        <xsl:text>\(</xsl:text>
        <xsl:value-of select="@remap"/>
        <xsl:text>\)</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Cross-references]{Cross-references :}\label{crossrefs}
% \begin{CPKtemplate}{db:xref}\label{template-db2dtx-xref1}
% \label{ann-xref}Cross-references are done in the
% standard
% \textsc{id}/\textsc{idref} manner,
% except that the \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}}
% attribute on the \texttt{<xref>}\index{xref=\texttt{\char'074 xref\char'076 } (element)}\index{elements:!xref=\texttt{\char'074 xref\char'076 }} element type has been
% redeclared as {\ttfamily{}IDREFS} to allow
% references to multiple targets, although this is not
% yet fully implemented.\par
%    \begin{macrocode}
  <xsl:template match="db:xref[@linkend]">
    <xsl:call-template name="compensate-space"/>
    <!-- remember where we started -->
    <xsl:variable name="context" select="."/>
    <!-- visit each target in turn -->
    <xsl:for-each select="tokenize(normalize-space(@linkend),' ')">
      <xsl:variable name="idref" select="."/>
      <xsl:variable name="target" 
        select="$thisdoc//*[@xml:id=$idref]"/>
      <xsl:if test="position()>1">
        <xsl:if test="position()!=last()">
          <xsl:text>; </xsl:text>
        </xsl:if>
        <xsl:if test="position()=last()">
          <xsl:text> and </xsl:text>
        </xsl:if>
      </xsl:if>
%    \end{macrocode}
% The targets which the \textsf{varioref}
% package does not yet handle come first in the
% choose/when, and the remainder afterwards. Catch items
% in a description list before anything else, and give
% them an ordinal number.\par
%    \begin{macrocode}
      <!-- for normal references -->
      <xsl:if test="not($context/@role='short')">
        <xsl:choose>
          <!-- WHOLE DESCRIPTION LIST -->
          <xsl:when test="name($target)='variablelist'">
            <xsl:text>the list in </xsl:text>
          </xsl:when>
          <!-- DESCRIPTION LIST ENTRY-->
          <xsl:when test="name($target)='varlistentry'">
            <xsl:text>‘\textbf{\textsf{</xsl:text>
            <xsl:apply-templates
              select="$target/db:term/node()"/>
            <xsl:text>}}’</xsl:text>
            <!-- add ordinal if NOT a pageref -->
            <xsl:if test="not($context/@xrefstyle='page')">
              <xsl:text>, the </xsl:text>
              <xsl:variable name="nth" 
                select="number(count($target/
                        preceding-sibling::db:varlistentry)+1)"/>
              <xsl:choose>
                <!-- 1st -->
                <xsl:when test="$nth = 1">
                  <xsl:text>first</xsl:text>
                </xsl:when>
                <!-- last -->
                <xsl:when
                  test="$nth = count($target/
                        parent::db:variablelist/db:varlistentry)">
                  <xsl:text>last</xsl:text>
                </xsl:when>
                <!-- digits over 12 -->
                <xsl:when test="$nth > 12">
                  <xsl:number value="$nth"
                    ordinal="yes" format="1"/>
                </xsl:when>
                <!-- words under/= 12 -->
                <xsl:otherwise>
                  <xsl:number value="$nth"
                    ordinal="yes" format="w"/>
                </xsl:otherwise>
              </xsl:choose>
              <xsl:text> item in </xsl:text>
              <xsl:choose>
                <!-- same list -->
                <xsl:when
                  test="generate-id($context
                        /ancestor::db:variablelist[1])
                        =
                        generate-id($target
                        /parent::db:variablelist)">
                  <xsl:text>this list</xsl:text>
                </xsl:when>
                <!-- different list -->
                <xsl:otherwise>
                  <xsl:text>the list in </xsl:text>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:if>
            <!-- add afterwards, on p.nn or in sec ss-->
          </xsl:when><!-- END DESC LIST ENTRY -->
%    \end{macrocode}
% Unnumbered list items also need an ordinal
% reference.\par
%    \begin{macrocode}
          <!-- UNNUMBERED LIST ITEMS NEED HELP -->
          <xsl:when
            test="name($target)='listitem' and 
                  name($target/ancestor::*[1])='itemizedlist'">
            <xsl:text>the </xsl:text>
            <xsl:variable name="nth" 
              select="number(count($target/
                      preceding-sibling::db:listitem)+1)"/>
            <xsl:choose>
              <xsl:when test="$nth=1">
                <xsl:text>first</xsl:text>
              </xsl:when>
              <xsl:when
                test="$nth=count($target/
                      ancestor::db:itemizedlist[1]/db:listitem)">
                <xsl:text>last</xsl:text>
              </xsl:when>
              <!-- from the fmtcount package -->
              <xsl:otherwise>
                <xsl:text>\ordinal</xsl:text>
                <xsl:if test="$nth &lt; 10">
                  <xsl:text>string</xsl:text>
                </xsl:if>
                <xsl:text>num{</xsl:text>
                <xsl:value-of select="$nth"/>
                <xsl:text>}</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:text> item in the list </xsl:text>
            <xsl:if test="not($context/@xrefstyle='page')">
              <xsl:text>in </xsl:text>
            </xsl:if>
          </xsl:when>
%    \end{macrocode}
% Ordered lists and procedures already have
% numbers.\par
%    \begin{macrocode}
          <!-- ORDERED LIST ITEMS or PROCEDURE STEPS -->
          <xsl:when
            test="(local-name($target)='listitem' and 
                  local-name($target/parent::*[1])='orderedlist')
                  or
                  (local-name($target)='step' and 
                  local-name($target/parent::*[1])='procedure')">
            <xsl:choose>
              <xsl:when test="$target/ancestor::procedure">
                <xsl:text>step</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>item</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:text>~\ref{</xsl:text>
            <xsl:value-of select="$idref"/>
            <xsl:text>}</xsl:text>
            <xsl:choose>
              <!-- same list -->
              <xsl:when
                test="($target/ancestor::db:procedure and
                      generate-id($context
                              /ancestor::db:procedure[1])=
                      generate-id($target
                              /parent::db:procedure)
                      )
                      or
                      ($context/ancestor::db:orderedlist and
                      generate-id($context
                              /ancestor::db:orderedlist[1])=
                      generate-id($target
                              /parent::db:orderedlist))">
                <xsl:choose>
                  <xsl:when 
                    test="count($context/preceding::*
                          |
                          $target)=count($context/preceding::*)">
                    <xsl:text> above</xsl:text>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:text> below</xsl:text>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:when>
              <!-- elsewhere -->
              <xsl:otherwise>
                <xsl:text> in the list on </xsl:text>
                <xsl:text>p.\thinspace\pageref{</xsl:text>
                <xsl:value-of select="$idref"/>
                <xsl:text>}</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
%    \end{macrocode}
% References to \emph{whole} ordered
% lists, informal tables, code listings, and notes,
% warnings, and sidebars just need an identity.\par
%    \begin{macrocode}
          <!-- TITLED LISTS -->
          <xsl:when
            test="(local-name($target)='orderedlist'
                   or
                   local-name($target)='itemizedlist')
                  and $target/db:title">
            <xsl:text>the list `</xsl:text>
            <xsl:apply-templates
              select="$target/db:title/node()"/>
            <xsl:text>' in </xsl:text>
          </xsl:when>
          <!-- UNTITLED LISTS -->
          <xsl:when
            test="local-name($target)='orderedlist'
                  or
                  local-name($target)='itemizedlist'">
            <xsl:text>the list in </xsl:text>
          </xsl:when>
          <!-- INFORMAL TABLES -->
          <xsl:when
            test="local-name($target)='informaltable'">
            <xsl:text>the table </xsl:text>
          </xsl:when>
          <!-- PROGRAMLISTING/@condition="ignore" 
               in package code -->
          <xsl:when
            test="local-name($target)='programlisting'">
            <xsl:text>the code </xsl:text>
          </xsl:when>
          <!-- NOTE, WARNING, SIDEBAR -->
          <xsl:when
            test="local-name($target)='note' or
                  local-name($target)='warning' or
                  local-name($target)='sidebar'">
            <xsl:text>the </xsl:text>
            <xsl:value-of select="local-name($target)"/>
            <xsl:text> in </xsl:text>
          </xsl:when>
          <!-- there is no otherwise -->
        </xsl:choose>
      </xsl:if>
%    \end{macrocode}
% References to extractable files, and page
% references; but omit the automated reference for the
% list items already done.\par
%    \begin{macrocode}
      <!-- AUTOMATED or special case of ref to extractable file -->
      <xsl:choose>
        <xsl:when
          test="$target/ancestor::db:part[@xml:id='files']
                and
                $target/@xlink:href">
          <xsl:text>\url{</xsl:text>
          <xsl:value-of select="$target/@xlink:href"/>
          <xsl:text>}</xsl:text>
        </xsl:when>
        <xsl:when
          test="$context/@xrefstyle='page' 
                or local-name($target)='informaltable'
                or local-name($target)='programlisting'">
          <xsl:text>\vpageref</xsl:text>
        </xsl:when>
        <!-- omit numbered list items done manually above -->
        <xsl:when
          test="(local-name($target)='listitem' and 
                local-name($target/ancestor::*[1])='orderedlist') 
                or
                ($context/ancestor::db:procedure and
                generate-id($context/ancestor::db:procedure)=
                generate-id($target/parent::db:procedure))">
          <xsl:text></xsl:text>
        </xsl:when>
        <!-- exclude link when varlistentries are 
             in the same variablelist (so no \vref) -->
        <xsl:when
          test="$context/ancestor::db:variablelist
                and
                name($target)='varlistentry'
                and
                generate-id($context/ancestor::db:variablelist[1])
                =
                generate-id($target/parent::db:variablelist)">
          <xsl:text></xsl:text>
        </xsl:when>
        <!-- everything else except ranges, done below -->
        <xsl:when test="not($context/@endterm)">
          <xsl:text>\vref</xsl:text>
          <!-- defeat added space when preceding character 
               was open-paren -->
          <xsl:if
            test="contains('([{&lt;',
                  substring($context/
                             preceding-sibling::node()[1],
                            string-length(
                            $context/
                             preceding-sibling::node()[1])))">
            <xsl:text>*</xsl:text>
          </xsl:if>
        </xsl:when>
        <xsl:when test="$context/@endterm">
          <xsl:text></xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>\ClassError{</xsl:text>
          <xsl:value-of select="$name"/>
          <xsl:text>}{xref attributes:</xsl:text>
          <xsl:for-each select="$context/@*">
            <xsl:text> </xsl:text>
            <xsl:value-of select="name()"/>
            <xsl:text>="</xsl:text>
            <xsl:value-of select="normalize-space(.)"/>
            <xsl:text>"</xsl:text>
          </xsl:for-each>
          <xsl:text>do not parse: contact author}</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
%    \end{macrocode}
% Automate page range references, excluding the
% items already done; and enable a deep reference to a
% portion of a target structure.\par
%    \begin{macrocode}
      <!-- now the argument[s]: not wanted for list items 
           done manually or for filename refs to extractable 
           files in part/files or when source and target in 
           same variablelist -->
      <xsl:if
        test="not(local-name($target)='listitem' and
              local-name($target/ancestor::*[1])='orderedlist') 
              and
              not($context/ancestor::db:procedure
              and
              $target/parent::db:procedure)
              and
              not($target/ancestor::db:part[@xml:id='files'] and
              $target/@xlink:href)
              and
              not(name($target)='varlistentry'
              and
              generate-id($context/ancestor::db:variablelist[1])
              =
              generate-id($target/parent::db:variablelist))">
        <xsl:if test="$context/@endterm">
          <xsl:text>\vrefrange</xsl:text>
        </xsl:if>
        <xsl:text>{</xsl:text>
        <xsl:value-of select="$idref"/>
        <xsl:text>}</xsl:text>
        <xsl:if test="$context/@endterm">
          <xsl:text>{</xsl:text>
          <xsl:value-of select="$context/@endterm"/>
          <xsl:text>}</xsl:text>
        </xsl:if>
      </xsl:if>
      <xsl:if test="$context/@xreflabel">
        <xsl:text> (</xsl:text>
        <xsl:apply-templates 
          select="($target/child::*[local-name()=$context//
                  @xreflabel])[1]/node()"/>
        <xsl:text>)</xsl:text>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Processing Instructions]{Processing Instructions :}\label{pis}
% \begin{CPKtemplate}{db:pi}\label{template-db2dtx-pi}
% Processing Instructions for \LaTeX{} allow the
% inclusion of direct code for formatting fixups.\par
%    \begin{macrocode}
  <xsl:template match="processing-instruction('LaTeX')">
    <xsl:value-of select="."/>
  </xsl:template>
  <xsl:template match="processing-instruction('cp')">
    <xsl:variable name="args"
      select="tokenize(normalize-space(.),' ')"/>
    <xsl:choose>
      <xsl:when test="$args[1]='include'">
        <xsl:apply-templates
          select="document($args[2])//*[@xml:id=$args[3]]"/>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection{Special-purpose templates and utilities}
% \begin{CPKtemplate}{db:annotation}\label{template-db2dtx-annotation3}
% \begingroup\raggedright[\url{db:annotation} with \url{[@annotations]} 
% ]\par\endgroup
% For the UCC Thesis document class, this usage of
%       \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} is quite different to normal, and
%       allows to pull option declaration data from the
%       specification tree held in the special \texttt{"data"}\index{data=\texttt{"data"} (attribute value)}\index{attribute values:!data=\texttt{"data"}} part. OBSOLETE soon, I
%       hope.\par
%    \begin{macrocode}
  <!-- Former UCC bulk declarations now used for options 
       Must have a para of explanation and the code in @annotations -->
  <xsl:template match="db:annotation[@annotations and @role='option']">
    <xsl:apply-templates select="db:para"/>
    <xsl:text>% \begin{CPKoption}{</xsl:text>
    <xsl:value-of select="@xreflabel"/>
    <xsl:text>}&#xa;%    </xsl:text>
    <xsl:text>\begin</xsl:text>
    <xsl:text>{macrocode}&#xa;\DeclareOption{</xsl:text>
    <xsl:value-of select="@xreflabel"/>
    <xsl:text>}{%&#xa;  </xsl:text>
    <xsl:value-of select="@annotations"/>
    <xsl:text>%&#xa;}&#xa;</xsl:text>
    <xsl:text>%    </xsl:text>
    <xsl:text>\end</xsl:text>
    <xsl:text>{macrocode}</xsl:text>
    <xsl:text>&#xa;% \end{CPKoption}&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="db:annotation/db:title">
    <xsl:text>% \subsection{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:declopts}\label{template-db2dtx-declopts}
% OBSOLETE. This used \texttt{<methodsynopsis>}\index{methodsynopsis=\texttt{\char'074 methodsynopsis\char'076 } (element)}\index{elements:!methodsynopsis=\texttt{\char'074 methodsynopsis\char'076 }} to
%       express the \LaTeX{} options for the very long lists of
%       colleges, schools, departments, and their degrees, in an
%       attempt to model the classes use by UCC for the thesis
%       class.\par
%    \begin{macrocode}
  <xsl:template match="db:methodsynopsis" mode="declareoption">
    <!-- make a low-level title -->
    <xsl:text>% \paragraph{</xsl:text>
    <xsl:value-of 
      select="normalize-space(db:methodparam[last()]
                              /db:parameter)"/>
    <!-- start a Code block for the option -->
    <xsl:text>}&#xa;% \begin{CPKoption}{</xsl:text>
    <xsl:value-of select="@xml:id"/>
    <xsl:text>}&#xa;% </xsl:text>
    <!-- now the descriptive text as a paragraph -->
    <!-- multiple parameters only for divisions, not degrees -->
    <!-- in document order, which is hierarchical top-down -->
    <xsl:for-each select="db:methodparam/db:parameter">
      <xsl:sort select="position()" order="descending"/>
      <xsl:if test="position()>1">
        <xsl:text> in </xsl:text>
      </xsl:if>
      <xsl:value-of select="normalize-space(.)"/>
      <xsl:if test="not(@role='degree')">
        <xsl:text> (</xsl:text>
        <xsl:value-of select="@role"/>
        <xsl:text>)</xsl:text>
      </xsl:if>
    </xsl:for-each>
    <xsl:text>; </xsl:text>
    <xsl:if test="not(db:methodparam/db:parameter/@role='degree')">
      <xsl:text>&#xa;% using the </xsl:text>
      <!-- langs in methodsynopsis/@language for babel -->
      <xsl:value-of select="normalize-space(db:methodname)"/>
      <xsl:text> citation format&#xa;% from the \verb`</xsl:text>
      <xsl:value-of select="db:methodparam[1]/db:initializer"/>
      <xsl:text>.bst` \BibTeX\ style</xsl:text>
      <xsl:if test="db:methodparam[1]/db:modifier">
        <xsl:text> with the </xsl:text>
        <xsl:for-each select="db:methodparam[1]/db:modifier">
          <xsl:if test="preceding-sibling::db:modifier">
            <xsl:text> and </xsl:text>
          </xsl:if>
          <xsl:text>\textsf{</xsl:text>
          <xsl:value-of select="."/>
          <xsl:text>}</xsl:text>
        </xsl:for-each>
        <xsl:text> package</xsl:text>
        <xsl:if test="count(db:methodparam[1]/db:modifier)>1">
          <xsl:text>s</xsl:text>
        </xsl:if>
      </xsl:if>
      <xsl:choose>
        <xsl:when test="contains(@xlink:href,'@')">
          <xsl:text> (confirmed by \url{</xsl:text>
          <xsl:value-of select="@xlink:href"/>
          <xsl:text>})</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text> (unconfirmed)</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
    <!-- followed by the actual code for the declared option -->
    <xsl:text>.&#xa;%    </xsl:text>
    <xsl:text>\begin</xsl:text>
    <xsl:text>{macrocode}&#xa;\DeclareOption{</xsl:text>
    <xsl:value-of select="@xml:id"/>
    <xsl:text>}{%&#xa;</xsl:text>
    <!-- order doesn't matter here, 
         but the line length does (maxcodelen) -->
    <!-- so does duplication, 
         because biblatex entries are replacements,
         not additions, but as \school etc use \gdef, 
         there shouldn't be errors 
         when they are duplicated -->
    <xsl:for-each select="db:methodparam/db:parameter">
      <xsl:text>  \</xsl:text>
      <xsl:value-of select="@role"/>
      <xsl:if test="@remap=''">
        <xsl:text>[]</xsl:text>
      </xsl:if>
      <xsl:text>{</xsl:text>
      <!-- break at parenthesis if present -->
      <xsl:choose>
        <xsl:when test="contains(.,'(')">
          <xsl:value-of
            select="normalize-space(substring-before(.,'('))"/>
          <xsl:text>&#xa;          (</xsl:text>
          <xsl:value-of
            select="normalize-space(substring-after(.,'('))"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="normalize-space(.)"/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>}&#xa;</xsl:text>
    </xsl:for-each>
    <!-- use found for \@usebib 4th param -->
    <xsl:if test="db:methodparam[1]/db:modifier or
                  db:methodparam[1]/db:initializer">
      <xsl:text>  \@usebib</xsl:text>
      <!-- optional first param is package name[s] -->
      <xsl:if test="db:methodparam[1]/db:modifier">
        <xsl:text>[</xsl:text>
        <xsl:for-each select="db:methodparam[1]/db:modifier">
          <xsl:if test="position()>1">
            <xsl:text>,</xsl:text>
          </xsl:if>
          <xsl:value-of select="."/>
        </xsl:for-each>
        <xsl:text>]</xsl:text>
      </xsl:if>
      <!-- second param is bib[la]tex style name -->
      <xsl:text>{</xsl:text>
      <xsl:value-of select="db:methodparam[1]/db:initializer"/>
      <!-- third param is human-readable name of the style -->
      <xsl:text>}{</xsl:text>
      <xsl:value-of select="db:methodname"/>
      <!-- fourth param is experimental signal for biblatex-->
      <xsl:text>}{</xsl:text>
      <xsl:choose>
        <xsl:when test="db:methodparam/@role">
          <xsl:value-of select="db:methodparam/@role"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>\relax</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>}&#xa;</xsl:text>
    </xsl:if>
    <!-- dept-specific languages one day 
    <xsl:if test="@xml:lang">
      <xsl:text>  \use@babel[</xsl:text>
      <xsl:value-of 
        select="translate(normalize-space(@xml:lang),' ',',')"/>
      <xsl:text>]{</xsl:text>
      <xsl:text>british</xsl:text>
      <xsl:text>}&#xa;</xsl:text>
      <xsl:variable name="langsused">
        <xsl:value-of select="normalize-space(@xml:lang)"/>
      </xsl:variable>
      <xsl:if test="@audience">
        <xsl:for-each select="tokenize(@audience,' ')">
          <xsl:variable name="curtok" select="position()"/>
          <xsl:text>  \def\</xsl:text>
          <xsl:value-of select="upper-case(.)"/>
          <xsl:text>{\foreignlanguage{</xsl:text>
          <xsl:value-of 
            select="tokenize($langsused,' ')
                             [position()=$curtok]"/>
          <xsl:text>}}&#xa;</xsl:text>
        </xsl:for-each>
      </xsl:if>
    </xsl:if>
-->
    <xsl:text>}&#xa;</xsl:text>
    <xsl:text>%    </xsl:text>
    <xsl:text>\end</xsl:text>
    <xsl:text>{macrocode}
% \end{CPKoption}&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection{Text}
% \begin{CPKtemplate}{text}\label{template-db2dtx-text1}
% Parse all text being shipped out for special
%       handling in two cases:  \begin{enumerate*}[label=\emph{\alph*}),itemjoin={{; }},itemjoin*={{; and }}]
% \item shell script fragments in documentation (save
%     space by removing initial newline and trailing
%     space)\par
% \item text of inline commands (and bibliography
%     entries being handled by
%     {\ttfamily{}db2bibtex.xsl}): normalise
%     spaces but preserve one leading and one trailing
%     space if given\par
% \end{enumerate*}. Otherwise, pass the string to the
%       \DescribeTemplate{dtxtext}{\ttfamily{}dtxtext} template for
%       handling of percent signs.\par
%    \begin{macrocode}
  <xsl:template match="text()">
    <xsl:choose>
      <xsl:when
        test="ancestor::db:programlisting[@language='bash']">
        <xsl:choose>
          <!-- remove leading newlines from initial strings -->
          <xsl:when test="count(preceding-sibling::text())=0
                          and starts-with(.,'&#xa;')">
            <xsl:value-of select="substring(.,2)"/>
          </xsl:when>
          <!-- remove trailing space from terminals -->
          <xsl:when test="count(following-sibling::text())=0
                          and matches(.,'\n[\s]*$')">
            <xsl:value-of select="replace(.,'\n[\s]*$','')"/>
          </xsl:when>
          <!-- otherwise don't prefix or suffix -->
          <xsl:otherwise>
            <xsl:value-of select="."/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:when
        test="ancestor::db:command or ancestor::db:biblioentry">
        <!-- replace a single leading WS token with a space -->
        <xsl:if test="starts-with(.,' ') or 
                      starts-with(.,'&#x9;') or 
                      starts-with(.,'&#xa;')">
          <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:value-of select="normalize-space(.)"/>
        <!-- replace a single trailing WS token with a space -->
        <xsl:if test="substring(.,string-length(.))=' ' or
                      substring(.,string-length(.))='&#x9;' or
                      substring(.,string-length(.))='&#xa;'">
          <xsl:text> </xsl:text>
        </xsl:if>
      </xsl:when>
      <!-- otherwise check for percent prefixes -->
      <xsl:otherwise>
        <xsl:call-template name="dtxtext">
          <xsl:with-param name="text" select="."/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection{Unhandled element types}
% \begin{CPKtemplate}{default}\label{template-db2dtx-default1}
% Catches everything not defined elsewhere and tells
%       the user.\par
%    \begin{macrocode}
  <xsl:template match="*">
    <xsl:message>
      <xsl:text>Element default: </xsl:text>
      <xsl:for-each select="ancestor::*">
        <xsl:sort select="count(ancestor::*)"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="local-name()"/>
      </xsl:for-each>
      <xsl:text>/</xsl:text>
      <xsl:value-of select="local-name()"/>
      <xsl:text> ("</xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>")</xsl:text>
    </xsl:message>
    <xsl:apply-templates/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection{Named templates}
% The biggest of these by far is \DescribeTemplate{makepackages}{\ttfamily{}makepackages},
%     the procedure for creating a node-set of all the elements
%     for the \emph{AutoPackage} mechanism;
%     that is, those for which an inclusion condition exists in
%     {\ttfamily{}prepost.xml}\thinspace.\par
% \paragraph[Node-set of elements for
%       \emph{AutoPackage}]{Node-set of elements for
%       \emph{AutoPackage} :}\label{makepack}
% To collect these, we go through every
%       \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }}’s \texttt{<constructorsynopsis>}\index{constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 } (element)}\index{elements:!constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 }} element
%       and look in:\par
% \label{inclist}
% \begin{enumerate}[noitemsep]
% \item the \emph{documentation} (the \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}} part), for any element
%   whose name matches the current
%   \texttt{<constructorsynopsis>}\index{constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 } (element)}\index{elements:!constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 }}’ \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}}
%   attribute:\par
% \item the \emph{metadata} (title,
%   author, abstract, annotation) for elements matching
%   as in [1] above;
% \item the \emph{licence} (eg
%   \textsc{lppl}) for elements matching as in
%   [1].
% \end{enumerate}
% the \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}} part itself is
%       abused as a signal for when the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} attribute is
%       supplied but null, which means `always include
% the package'; that is, its use stands duty for
%       `everywhere'. This also tests for
%       the specific case of \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} being \texttt{"xelatex"}\index{xelatex=\texttt{"xelatex"} (attribute value)}\index{attribute values:!xelatex=\texttt{"xelatex"}} while processing the
%       entry for the \textsf{fontspec}
%       package.\par
% the \emph{bibliography} is abused in a
%       similar way when the \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}}
%       attribute holds the name of a bibliographic package (eg
%       \textsf{biblatex}.\par
% This used to be used for a style package in the \texttt{@xreflabel}\index{xreflabel=\texttt{\char'100 xreflabel} (attribute)}\index{attributes:!xreflabel=\texttt{\char'100 xreflabel}} attribute, but the
%       use of old \BibTeX{} is slowly being deprecated.\par
% \subparagraph[Conditions for inclusion]{Conditions for inclusion  ◦}
% Look in the \texttt{<constructorsynopsis>}\index{constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 } (element)}\index{elements:!constructorsynopsis=\texttt{\char'074 constructorsynopsis\char'076 }} element
% of each \texttt{<step>}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} (package) flagged for
% documentation in the \texttt{<prepackage>}\index{prepackage=\texttt{\char'074 prepackage\char'076 } (element)}\index{elements:!prepackage=\texttt{\char'074 prepackage\char'076 }} section of
% the {\ttfamily{}prepost.xml} file.\par
%    \begin{macrocode}
  <!-- Called from the document root template -->
  <xsl:template name="makepackages">
    <!-- Go through every PRE-step in prepost.xml for DOC part
         and see if any of them match known conditions for use.
         We are creating $packages here.
         The CONTEXT here is <step> for the purposes of detection,
         but we create <seglistitem>s in the result tree
         so that they can be processed on a par with any author
         requests for packages in the document -->
    <xsl:for-each 
      select="$prepost/db:procedure
              [@xml:id='prepackage']
              /db:step[contains(@condition,'doc')]">
%    \end{macrocode}
% \subparagraph[Assemble the elements for each condition]{Assemble the elements for each condition  ◦}
% These are the items in the list in \vref{inclist}.\par
% Note that \DescribeVariable{thisdoc}{\ttfamily{}\$thisdoc} is the current
% \textsc{xml} \emph{ClassPack} document, so this
% variable \DescribeVariable{elements}{\ttfamily{}\$elements} will, in effect,
% contain all the printable content elements of the
% documentation\footnote{%
% \leavevmode\llap`Documentation' here,
%     and in the following sections on package
%     selection, includes your package documentation;
%     the Abstract and any note in an \texttt{annotation}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} element in the
%     metadata; and the text of the License under which
%     your package is issued.\par} matching the value of the current \texttt{@constructorsynopsis}\index{constructorsynopsis=\texttt{\char'100 constructorsynopsis} (attribute)}\index{attributes:!constructorsynopsis=\texttt{\char'100 constructorsynopsis}}
% attribute value from
% {\ttfamily{}prepost.xml}\thinspace.\par
% There are six nodesets to be combined, computed
% separately for ease of maintenance: the first four are
% each composed of the union of three nodesets, taken
% from the documentation text, the abstract, and the
% licence.\par
% \begin{enumerate}[leftmargin=0.5em]\setlength{\CPKannotationindent}{1em}
% \item \label{element-match}
% \begin{CPKvariable}[noprint]{elementmatch}\label{variable-db2dtx-elementmatch}
% Selects packages from
%       {\ttfamily{}prepost.xml} which specify
%       an element type (only) from the author’s
%       document; for example the
%       \textsf{listings} package would be
%       selected if a \texttt{programlisting}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} element
%       is present in the document:\par
%    \begin{macrocode}
      <!-- context here is db:step[@condition='doc'] -->
      <xsl:variable name="element-match"
        select="$thisdoc/db:book/db:part[@xml:id='doc']/
                  descendant-or-self::*
                  [for $c in current()/db:constructorsynopsis
                       [@condition!='' and not(db:methodparam)]
                       return (.[name()=$c/@condition])]
                |
                $thisdoc/db:book/db:info/
                  (db:title|db:author|
                   db:abstract|db:annotation)/
                  descendant-or-self::*
                  [for $c in current()/db:constructorsynopsis
                       [@condition!='' and not(db:methodparam)]
                       return (.[name()=$c/@condition])]
                |
                $licence/descendant-or-self::*
                  [for $c in current()/db:constructorsynopsis
                       [@condition!='' and not(db:methodparam)]
                       return (.[name()=$c/@condition])]
                "/>
%    \end{macrocode}
% \end{CPKvariable}
% \item \label{attribute-match}
% \begin{CPKvariable}[noprint]{attribmatch}\label{variable-db2dtx-attribmatch}
% Selects packages from
%       {\ttfamily{}prepost.xml} which specify
%       an element type \emph{with} an
%       attribute from the author’s document (regardless
%       of the value of the attribute); for example the
%       \textsf{graphicx} package would be
%       selected if an \texttt{imagedata}\index{imagedata=\texttt{\char'074 imagedata\char'076 } (element)}\index{elements:!imagedata=\texttt{\char'074 imagedata\char'076 }} element is
%       present in the document with a \texttt{@fileref}\index{fileref=\texttt{\char'100 fileref} (attribute)}\index{attributes:!fileref=\texttt{\char'100 fileref}}
%       attribute:\par
%    \begin{macrocode}
      <!-- context here is db:step[@condition='doc'] -->
      <xsl:variable name="attribute-match"
        select="$thisdoc/db:book/db:part[@xml:id='doc']/
                descendant-or-self::*
                [for $c in current()/db:constructorsynopsis
                     [@condition!='' and
                      db:methodparam[db:parameter and
                      not(db:modifier)]]
                 return (.[name()=$c/@condition and
                        @*[name()=$c/db:methodparam/db:parameter]])]
                |
                $thisdoc/db:book/db:info/
                  (db:title|db:author|
                   db:abstract|db:annotation)/
                  descendant-or-self::*
                [for $c in current()/db:constructorsynopsis
                     [@condition!='' and
                      db:methodparam[db:parameter and
                      not(db:modifier)]]
                 return (.[name()=$c/@condition and
                        @*[name()=$c/db:methodparam/db:parameter]])]
                |
                $licence/descendant-or-self::*
                [for $c in current()/db:constructorsynopsis
                     [@condition!='' and
                      db:methodparam[db:parameter and
                      not(db:modifier)]]
                 return (.[name()=$c/@condition and
                        @*[name()=$c/db:methodparam/db:parameter]])]
                "/>
%    \end{macrocode}
% \end{CPKvariable}
% \item \label{attribute-value-match}
% \begin{CPKvariable}[noprint]{attvalmatch}\label{variable-db2dtx-attvalmatch}
% Selects packages from
%       {\ttfamily{}prepost.xml} which specify
%       an element type \emph{with} an
%       attribute containing a specific value from the
%       author’s document; for example the
%       \textsf{fontspec} package would be
%       selected if a \texttt{part}\index{part=\texttt{\char'074 part\char'076 } (element)}\index{elements:!part=\texttt{\char'074 part\char'076 }}
%       element is present in the document with a \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} attribute
%       set to the value \texttt{"xelatex"}\index{xelatex=\texttt{"xelatex"} (attribute value)}\index{attribute values:!xelatex=\texttt{"xelatex"}} or \texttt{"lualatex"}\index{lualatex=\texttt{"lualatex"} (attribute value)}\index{attribute values:!lualatex=\texttt{"lualatex"}}:\par
%    \begin{macrocode}
      <!-- context here is db:step[@condition='doc'] -->
      <xsl:variable name="attribute-value-match"
        select="$thisdoc/db:book/db:part[@xml:id='doc']/
                 descendant-or-self::*
                 [for $c in current()/db:constructorsynopsis
                     [@condition!='' and
                      db:methodparam[db:parameter and
                      db:modifier]]
                  return (.[name()=$c/@condition and
                          @*[name()=$c/db:methodparam/db:parameter]=
                            $c/db:methodparam/db:modifier])]
                |
                $thisdoc/db:book/db:info/
                  (db:title|db:author|
                   db:abstract|db:annotation)/
                  descendant-or-self::*
                 [for $c in current()/db:constructorsynopsis
                     [@condition!='' and
                      db:methodparam[db:parameter and
                      db:modifier]]
                  return (.[name()=$c/@condition and
                          @*[name()=$c/db:methodparam/db:parameter]=
                            $c/db:methodparam/db:modifier])]
                |
                $licence/descendant-or-self::*
                 [for $c in current()/db:constructorsynopsis
                     [@condition!='' and
                      db:methodparam[db:parameter and
                      db:modifier]]
                  return (.[name()=$c/@condition and
                          @*[name()=$c/db:methodparam/db:parameter]=
                            $c/db:methodparam/db:modifier])]
                |
                $thisdoc/db:book
                [for $c in current()/db:constructorsynopsis
                     [@condition!='' and
                      db:methodparam[db:parameter and
                      db:modifier]]
                  return (.[name()=$c/@condition and
                          @*[name()=$c/db:methodparam/db:parameter]=
                            $c/db:methodparam/db:modifier])]
                "/>
      <!-- added db:book alone to handle matches 
           to (eg) status="draft" -->
%    \end{macrocode}
% \end{CPKvariable}
% \item \label{attribute-value-pointer-match}
% \begin{CPKvariable}[noprint]{attvalptrmatch}\label{variable-db2dtx-attvalptrmatch}
% Selects packages from
%       {\ttfamily{}prepost.xml} which specify
%       an element type with an IDREF or IDREFS
%       attribute which links to an element of the
%       specified type in the author’s document; for
%       example the \textsf{fmtcount} package
%       would be selected if an \texttt{xref}\index{xref=\texttt{\char'074 xref\char'076 } (element)}\index{elements:!xref=\texttt{\char'074 xref\char'076 }} element is present
%       in the document with a \texttt{@linkend}\index{linkend=\texttt{\char'100 linkend} (attribute)}\index{attributes:!linkend=\texttt{\char'100 linkend}} attribute
%       linking to a \texttt{varlistentry}\index{varlistentry=\texttt{\char'074 varlistentry\char'076 } (element)}\index{elements:!varlistentry=\texttt{\char'074 varlistentry\char'076 }} element
%       type (because the formatting of the link will
%       need ordinal numbering):\par
%    \begin{macrocode}
      <!-- context here is db:step[@condition='doc'] -->
      <xsl:variable name="attribute-value-pointer"
        select="$thisdoc/db:book/db:part[@xml:id='doc']
                  /descendant-or-self::*
                  [name()=current()/db:constructorsynopsis/@condition]
                  [for $m in
                       current()/db:constructorsynopsis/db:methodparam,
                       $e in tokenize(@*[name()=$m/db:funcparams])
                   return (id($e)[name()=$m/db:modifier])]
                |
                $thisdoc/db:book/db:info/
                  (db:title|db:author|db:abstract|db:annotation)/
                  descendant-or-self::*[name()=
                    current()/db:constructorsynopsis/@condition]
                  [for $m in
                       current()/db:constructorsynopsis/db:methodparam,
                       $e in tokenize(@*[name()=$m/db:funcparams])
                   return (id($e)[name()=$m/db:modifier])]
                |
                $licence/descendant-or-self::*
                  [name()=current()/db:constructorsynopsis/@condition]
                  [for $m in
                       current()/db:constructorsynopsis/db:methodparam,
                       $e in tokenize(@*[name()=$m/db:funcparams])
                   return (id($e)[name()=$m/db:modifier])]
                "/>
%    \end{macrocode}
% \end{CPKvariable}
% \item \label{default-match}
% \begin{CPKvariable}[noprint]{defaultmatch}\label{variable-db2dtx-defaultmatch}
% Selects packages from
%       {\ttfamily{}prepost.xml} which have a
%       null value for \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}}, meaning the
%       package is to be selected every time:\par
%    \begin{macrocode}
      <!-- context here is db:step[@condition='doc'] -->
      <xsl:variable name="defaults"
        select="$thisdoc/db:book/db:part[@xml:id='doc']
                [current()/db:constructorsynopsis/@condition='']
                "/>
%    \end{macrocode}
% \end{CPKvariable}
% \item \label{dependency-match}
% \begin{CPKvariable}[noprint]{dependencymatch}\label{variable-db2dtx-dependencymatch}
% Selects packages from
%       {\ttfamily{}prepost.xml} which are a
%       known dependency on a package specified by the
%       author; for example the \textsf{url}
%       package would be included if the
%       \textsf{guit} package has been
%       requested, because \textsf{guit} is
%       known to require the \textsf{url}
%       package with the \textbf{\texttt{hyphens}}
%       option:\par
%    \begin{macrocode}
      <!-- context here is db:step[@condition='doc'] -->
      <!-- A dependency is signalled in prepost.xml when a package
           has a constructorsynopsis/@role AND a 
           constructorsynopsis/methodname, meaning that IF a 
           package in <methodname> (space-separated) is requested, 
           OR a package in <methodname> is one that is also 
           required BY DEFAULT, then the current package will 
           become required, with the @role option (if non-null). 
           So the package dependency MAY be signalled by using a 
           null @role, meaning that no specific option is required, 
           just the package. 
       -->
      <xsl:variable name="dependencies"
        select="$thisdoc//db:constraintdef[@xml:id='docpackages']//
                db:seglistitem
                [db:seg=tokenize(normalize-space(
                 current()/db:constructorsynopsis[@role]
                 /db:methodname),' ')]
                |
                current()[
                $prepost/db:procedure[@xml:id='prepackage']/db:step
                [db:constructorsynopsis/@condition='']
                [@remap=tokenize(normalize-space(
                 current()/db:constructorsynopsis[@role]
                 /db:methodname),' ')]]
                 "/>
%    \end{macrocode}
% \end{CPKvariable}
% \end{enumerate}\setlength{\CPKannotationindent}{0pt}
% \begin{CPKvariable}[noprint]{elements}\label{makenodeset}
% Finally, create a nodeset of a union of all the
%   above; these are the conditions by which the current
%   package is going to be required.\par
%    \begin{macrocode}
      <xsl:variable name="elements"
        select="
                $element-match |
                $attribute-match |
                $attribute-value-match |
                $attribute-value-pointer |
                $defaults |
                $dependencies
                "/>
%    \end{macrocode}
% \end{CPKvariable}
% \subparagraph[Create a result tree of packages]{Create a result tree of packages  ◦}
% The list of required packages is expressed
% internally as a sequence of \texttt{<seglistitem>}\index{seglistitem=\texttt{\char'074 seglistitem\char'076 } (element)}\index{elements:!seglistitem=\texttt{\char'074 seglistitem\char'076 }}
% elements so that it can be processed the same way as
% the list of packages requested manually by the author.
% An instance of the element will added IFF there was at
% least one of the specified document elements found and
% recorded in one of the six component nodesets of the
% \DescribeVariable{elements}{\ttfamily{}\$elements} variable created
% above.\par
% We will need to echo to the console what packages
% were found and under what conditions, so we create a
% \DescribeVariable{prepostno}{\ttfamily{}\$prepostno} variable which
% gives the section of {\ttfamily{}prepost.xml}
% and the sequence number of the \texttt{step}\index{step=\texttt{\char'074 step\char'076 } (element)}\index{elements:!step=\texttt{\char'074 step\char'076 }} entry.\par
%    \begin{macrocode}
      <!-- REMINDER: context is still <step> in prepost, 
           but the "elements" variable now contains every 
           element FROM THE DOCUMENT which meets the conditions 
           needed to justify the current package's inclusion.
           Process this ONLY IFF any elements at all were selected: 
           this is where we create the result tree -->
      <xsl:if test="count($elements)>0">
        <!-- IDENTIFY THE CURRENT PACKAGE AND WHY [DE-]SELECTED -->
        <xsl:variable name="prepostno">
          <!-- this represents the number of the procedure in
               prepost.xml (1=pre, 2=post) followed by the 
               (3-digit decimal) sequence of the position of 
               the package (the seglistitem element type), 
               so for example, 'dox' is 1.001 and fontawesome 
               is 1.127 -->
          <xsl:value-of
            select="count(parent::db:procedure/
                    preceding-sibling::db:procedure) + 1"/>
          <xsl:text>.</xsl:text>
          <xsl:value-of
            select="format-integer(
                    count(preceding-sibling::db:step)+1,
                    '999')"/>
        </xsl:variable>
        <!-- still in context <step> for the moment -->
        <xsl:variable name="thispackage" select="@remap"/>
%    \end{macrocode}
% In the following constructions, the attributes
% created by the \vref{makeseg} named
% template reflect the values that are being persisted
% from the {\ttfamily{}prepost.xml} file.\par
% \begin{description}[style=unboxed,leftmargin=0.5em]\setlength{\CPKannotationindent}{1em}
% \item[Element match:]\par 
% \begin{CPKelement}[noprint]{seglistitem}\label{element-db2dtx-seglistitem1}
% Package included because an element was
% used in the document.\par
%    \begin{macrocode}
        <!-- 1. ELEMENTS -->
        <xsl:if test="count($element-match)>0">
          <xsl:message>
            <xsl:value-of select="@remap"/>
            <xsl:text> (</xsl:text>
            <xsl:value-of select="$prepostno"/>
            <xsl:text>)</xsl:text>
            <xsl:text> element-match=</xsl:text>
            <xsl:value-of select="count($element-match)"/>
            <xsl:text> </xsl:text>
            <!-- element-match just needs element type name[s] -->
            <xsl:for-each-group select="$element-match"
              group-by="name()">
              <xsl:if test="position()>1">
                <xsl:text>,</xsl:text>
              </xsl:if>
              <xsl:value-of select="current-grouping-key()"/>
            </xsl:for-each-group>
          </xsl:message>
          <xsl:call-template name="makeseg">
            <xsl:with-param name="arch" select="'elements'"/>
            <xsl:with-param name="prepostno" select="$prepostno"/>
          </xsl:call-template>
        </xsl:if>
%    \end{macrocode}
% \end{CPKelement}
% \item[Element and attribute match:]\par 
% \begin{CPKelement}[noprint]{seglistitem}\label{element-db2dtx-seglistitem2}
% Package included because an element with
% an attribute was used in the document.\par
%    \begin{macrocode}
        <!-- 2. ATTRIBUTES -->
        <xsl:if test="count($attribute-match)>0">
          <xsl:message>
            <xsl:value-of select="@remap"/>
            <xsl:text> (</xsl:text>
            <xsl:value-of select="$prepostno"/>
            <xsl:text>)</xsl:text>
            <xsl:text> attribute-match=</xsl:text>
            <xsl:value-of select="count($attribute-match)"/>
            <xsl:text> </xsl:text>
            <!-- attribute-match needs element/@attribute -->
            <xsl:for-each-group select="$attribute-match"
              group-by="name()">
              <xsl:if test="position()>1">
                <xsl:text>,</xsl:text>
              </xsl:if>
              <xsl:value-of select="current-grouping-key()"/>
              <xsl:text>/</xsl:text>
              <!-- variable contains entries which are the 
                   whole elements within which an attribute 
                   match was found, so iterate over the 
                   attributes as groups and only print the 
                   one which matches -->
              <xsl:variable name="element-key"
                select="current-grouping-key()"/>
              <xsl:variable name="attribs">
                <xsl:for-each select="current-group()">
                  <xsl:for-each select="@*">
                    <att>
                      <xsl:value-of select="name()"/>
                    </att>
                  </xsl:for-each>
                </xsl:for-each>
              </xsl:variable>
              <xsl:for-each-group select="$attribs/*"
                                  group-by="name()">
                <xsl:if
                  test=".=
                        $prepost/db:procedure/db:step
                          [@remap=$thispackage]
                        /db:constructorsynopsis
                          [@condition=$element-key]
                        /db:methodparam/db:parameter">
                  <xsl:text>@</xsl:text>
                  <xsl:value-of
                    select="$prepost/db:procedure/db:step
                              [@remap=$thispackage]
                            /db:constructorsynopsis
                              [@condition=$element-key]
                            /db:methodparam/db:parameter"/>
                </xsl:if>
              </xsl:for-each-group>
            </xsl:for-each-group>
          </xsl:message>
          <xsl:call-template name="makeseg">
            <xsl:with-param name="arch" select="'attributes'"/>
            <xsl:with-param name="prepostno" select="$prepostno"/>
          </xsl:call-template>
        </xsl:if>
%    \end{macrocode}
% \end{CPKelement}
% \item[Element and attribute match with value:]\par 
% \begin{CPKelement}[noprint]{seglistitem}\label{element-db2dtx-seglistitem3}
% Package was included because an element
% with an attribute set to a value was used in
% the document.\par
%    \begin{macrocode}
        <!-- 3. ATTRIBUTE VALUES -->
        <xsl:if test="count($attribute-value-match)>0">
          <xsl:message>
            <xsl:value-of select="@remap"/>
            <xsl:text> (</xsl:text>
            <xsl:value-of select="$prepostno"/>
            <xsl:text>)</xsl:text>
            <xsl:text> attribute-value match=</xsl:text>
            <xsl:value-of select="count($attribute-value-match)"/>
            <xsl:text> </xsl:text>
            <xsl:for-each-group select="$attribute-value-match"
              group-by="name()">
              <xsl:if test="position()>1">
                <xsl:text>,</xsl:text>
              </xsl:if>
              <xsl:value-of select="current-grouping-key()"/>
              <xsl:text>/</xsl:text>
              <xsl:for-each select="current-group()">
                <xsl:variable name="matchgi" select="."/>
                <xsl:for-each
                  select="$prepost/db:procedure/db:step
                            [@remap=$thispackage]
                          /db:constructorsynopsis
                            [@condition=current-grouping-key()]
                          /db:methodparam">
                  <xsl:if
                    test="$matchgi/@*
                          [name()=current()/db:parameter]
                            =current()/db:modifier">
                    <xsl:text>@</xsl:text>
                    <xsl:value-of select="db:parameter"/>
                    <xsl:text>=</xsl:text>
                    <xsl:value-of select="db:modifier"/>
                    <xsl:text>:</xsl:text>
                  </xsl:if>
                </xsl:for-each>
              </xsl:for-each>
            </xsl:for-each-group>
          </xsl:message>
          <xsl:call-template name="makeseg">
            <xsl:with-param name="arch" select="'attvals'"/>
            <xsl:with-param name="prepostno" select="$prepostno"/>
          </xsl:call-template>
        </xsl:if>
%    \end{macrocode}
% \end{CPKelement}
% \item[Element refers to another by IDREF:]\par 
% \begin{CPKelement}[noprint]{seglistitem}\label{element-db2dtx-seglistitem4}
% Package was included because an element in
% the document referenced by IDREF another
% element in the document known to require
% features from the package.\par
%    \begin{macrocode}
        <!-- 4. ATTRIBUTE VALUE POINTERS -->
        <xsl:if test="count($attribute-value-pointer)>0">
          <xsl:message>
            <xsl:value-of select="@remap"/>
            <xsl:text> (</xsl:text>
            <xsl:value-of select="$prepostno"/>
            <xsl:text>)</xsl:text>
            <xsl:text> attribute-value-pointer (</xsl:text>
            <xsl:value-of select="count($attribute-value-pointer)"/>
            <xsl:text>) </xsl:text>
            <xsl:for-each-group select="$attribute-value-pointer"
              group-by="name()">
              <xsl:if test="position()>1">
                <xsl:text>,</xsl:text>
              </xsl:if>
              <xsl:value-of select="current-grouping-key()"/>
              <xsl:text>/</xsl:text>
              <xsl:variable name="elementname"
                select="current-grouping-key()"/>
              <xsl:for-each
                select="$prepost/db:procedure/db:step
                          [@remap=$thispackage]
                        /db:constructorsynopsis
                          [@condition=current-grouping-key()]
                        /db:methodparam">
                <!-- any element in the document with an xml:id 
                     pointed TO by one of the current group
                     which element is of the type specified -->
                <xsl:if
                  test="count(current-group()/@*
                        [name()=current()/db:funcparams]
                        [id(.)/name()=current()/db:modifier])>0">
                  <xsl:text>@</xsl:text>
                  <xsl:value-of select="db:funcparams"/>
                  <xsl:text>→</xsl:text>
                  <xsl:value-of select="db:modifier"/>
                  <xsl:text>; </xsl:text>
                </xsl:if>
              </xsl:for-each>
            </xsl:for-each-group>
          </xsl:message>
          <xsl:call-template name="makeseg">
            <xsl:with-param name="arch" select="'attvalidrefs'"/>
            <xsl:with-param name="prepostno" select="$prepostno"/>
          </xsl:call-template>
        </xsl:if>
%    \end{macrocode}
% \end{CPKelement}
% \item[Requested package requires another
%     (dependency):]\par 
% \begin{CPKelement}[noprint]{seglistitem}\label{element-db2dtx-seglistitem5}
% Package was included because it is known
% to be required by another package requested by
% the author.\par
%    \begin{macrocode}
        <!-- 5. DEPENDENCIES match seglistitems from user requests 
                or from other packages included as defaults -->
        <xsl:if test="count($dependencies)>0">
          <xsl:message>
            <xsl:value-of select="@remap"/>
            <xsl:text> (</xsl:text>
            <xsl:value-of select="$prepostno"/>
            <xsl:text>)</xsl:text>
            <xsl:text> dependency match </xsl:text>
            <xsl:for-each-group select="$dependencies"
              group-by="name()">
              <xsl:if test="position()>1">
                <xsl:text>,</xsl:text>
              </xsl:if>
              <xsl:value-of
                select="db:constructorsynopsis/db:methodname"/>
            </xsl:for-each-group>
          </xsl:message>
          <xsl:call-template name="makeseg">
            <xsl:with-param name="arch" select="'dependencies'"/>
            <xsl:with-param name="prepostno" select="$prepostno"/>
          </xsl:call-template>
        </xsl:if>
%    \end{macrocode}
% \end{CPKelement}
% \item[Package included by default:]\par 
% \begin{CPKelement}[noprint]{seglistitem}\label{element-db2dtx-seglistitem6}
% Package was included because it is needed
% in all \emph{ClassPack}
% classes and packages.\par
%    \begin{macrocode}
        <!-- 6. DEFAULT -->
        <xsl:if test="count($defaults)>0">
          <xsl:message>
            <xsl:value-of select="@remap"/>
            <xsl:text> (</xsl:text>
            <xsl:value-of select="$prepostno"/>
            <xsl:text>)</xsl:text>
            <xsl:text> default </xsl:text>
            <xsl:if test="$prepost/db:procedure[@xml:id='prepackage']
                          /db:step[db:constructorsynopsis
                          [contains(@remap,current()/@remap)]]">
              <xsl:text>will be omitted because of </xsl:text>
              <xsl:value-of
                select="$prepost/db:procedure[@xml:id='prepackage']
                          /db:step[db:constructorsynopsis
                        [contains(@remap,current()/@remap)]]/@remap"/>
            </xsl:if>
          </xsl:message>
          <xsl:call-template name="makeseg">
            <xsl:with-param name="arch" select="'defaults'"/>
            <xsl:with-param name="prepostno" select="$prepostno"/>
          </xsl:call-template>
        </xsl:if>
      </xsl:if>
    </xsl:for-each>
%    \end{macrocode}
% \end{CPKelement}
% \end{description}\setlength{\CPKannotationindent}{0pt}
% \subparagraph[Packages explicitly included  by the
% author]{Packages explicitly included  by the
% author  ◦}
% Packages named in the \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }}
% element ID’d as \texttt{"docpackages"}\index{docpackages=\texttt{"docpackages"} (attribute value)}\index{attribute values:!docpackages=\texttt{"docpackages"}} and not set to
% \texttt{"off"}\index{off=\texttt{"off"} (attribute value)}\index{attribute values:!off=\texttt{"off"}} are positioned at the
% end of the list (numbered 9999) unless a \texttt{@userlevel}\index{userlevel=\texttt{\char'100 userlevel} (attribute)}\index{attributes:!userlevel=\texttt{\char'100 userlevel}} value sets this
% differently. The \textsf{url} and
% \textsf{xcolor} packages are excluded, as
% they will have been preloaded.\par
%    \begin{macrocode}
    <!-- 7. FINALLY, ADD PACKAGES REQUESTED BY THE AUTHOR 
         in the document itself for use in the documentation.
         The list is accessed via the 'doc' pre packages,
         matching those mentioned in the author's document.
         This ensures that the context is <step> as earlier.
         The $authorloc variable points at the matching entry
         in the author's document so that options from BOTH
         $prepost AND the author's document can be merged. -->
    <xsl:for-each 
      select="$prepost/
              db:procedure[@xml:id='prepackage']/
              db:step[contains(@condition,'doc')]
              [@remap=
                $thisdoc/db:book/db:info/db:cover
                /db:constraintdef[@xml:id='docpackages']
                /db:segmentedlist/db:seglistitem
                [not(db:seg/@condition='off')]/db:seg]">
      <xsl:variable name="prepostno">
        <xsl:value-of
          select="count(parent::db:procedure/
                  preceding-sibling::db:procedure) + 1"/>
        <xsl:text>.</xsl:text>
        <xsl:value-of
          select="format-integer(
                  count(preceding-sibling::db:step)+1,
                  '999')"/>
      </xsl:variable>
      <xsl:variable name="authorloc"
        select="$thisdoc/db:book/db:info/db:cover
                /db:constraintdef[@xml:id='docpackages']
                /db:segmentedlist/db:seglistitem
                [db:seg=current()/@remap]"/>
      <!-- These WERE flagged by making $prepostno 999 + 
           the author's <seglistitem> but now with ordering
           in prepost.xml, this has reverted to 1 + -->
      <xsl:call-template name="makeseg">
        <xsl:with-param name="arch" select="'requests'"/>
        <!--
        <xsl:with-param name="prepostno">
          <xsl:text>999.</xsl:text>
          <xsl:value-of
            select="format-integer(
                    count($authorloc/preceding-sibling::db:seglistitem)
                      +1,'999')"/>
        </xsl:with-param>
        -->
        <xsl:with-param name="prepostno" select="$prepostno"/>
        <xsl:with-param name="authorloc" select="$authorloc"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template>
  <!-- end of makepackages -->
%    \end{macrocode}
% \subparagraph[Constructing the list]{Constructing the list  ◦}\label{makeseg}
% Named template to assemble the data into a \texttt{seglistitem}\index{seglistitem=\texttt{\char'074 seglistitem\char'076 } (element)}\index{elements:!seglistitem=\texttt{\char'074 seglistitem\char'076 }} format.\par
%    \begin{macrocode}
  <!-- called from within makepackages 
       with context db:step from prepost.xml -->
  <xsl:template name="makeseg">
    <xsl:param name="arch"/>
    <xsl:param name="prepostno"/>
    <xsl:param name="authorloc"/>
    <!-- $authorloc is the <seglistitem> from the author's document
         where this package is being requested (requests only) 
         OR from prepost.xml entry where the methodname contained
         a required package (doc only) -->
    <db:seglistitem arch="{$arch}" userlevel="{$prepostno}">
      <!-- add @condition to reflect an attribute match
           OR a package match for a dependency -->
      <xsl:choose>
        <xsl:when test="($arch='attributes' or $arch='attvals')
                        and db:constructorsynopsis/@condition">
          <xsl:attribute name="condition"
            select="db:constructorsynopsis/@condition"/>
        </xsl:when>
        <xsl:when test="$arch='dependencies'">
          <xsl:attribute name="condition"
            select="current()/db:constructorsynopsis[@role]
                    /db:methodname"/>
        </xsl:when>
      </xsl:choose>
      <!-- SOMETHING WRONG HERE: role being included when not 
           needed eg hyphens on url -->
      <!-- specify dependency option as @role only when non-null
           (a null @role may have been used to signal a dependency
           but without the need for any specific option)... -->
      <xsl:if
        test="db:constructorsynopsis/@role
              and db:constructorsynopsis/@role!=''
              and $arch='dependencies'
              or (db:constructorsynopsis/db:methodname
              and db:constructorsynopsis/db:methodname=$authorloc)">
        <xsl:attribute name="role"
          select="db:constructorsynopsis/@role"/>
      </xsl:if>
      <!-- ...so when setting a dependency as a result of another 
           package, the methodname must really have been used, 
           so we check the author location -->
      <xsl:if
        test="db:constructorsynopsis/@role
              and $arch='dependencies'
              and db:constructorsynopsis/db:methodname
              and db:constructorsynopsis/db:methodname=$authorloc">
        <xsl:attribute name="audience"
          select="db:constructorsynopsis/db:methodname"/>
      </xsl:if>
      <xsl:if test="db:constructorsynopsis/@remap">
        <xsl:attribute name="remap"
          select="db:constructorsynopsis/@remap"/>
      </xsl:if>
      <!-- only add @conformance when it's an attribute 
           or attval match -->
      <xsl:if
        test="($arch='attributes' or $arch='attvals')
               and
               db:constructorsynopsis/db:methodparam/db:parameter">
        <xsl:attribute name="conformance"
          select="db:constructorsynopsis/db:methodparam
                  /db:parameter"/>
      </xsl:if>
      <!-- @annotations in <seglistitem> is DIFFERENT to 
           @annotations in <seg> -->
      <xsl:if
        test="db:constructorsynopsis/db:methodparam/db:modifier">
        <xsl:attribute name="annotations"
          select="db:constructorsynopsis/db:methodparam
                  /db:modifier"/>
      </xsl:if>
      <xsl:if
        test="db:constructorsynopsis/db:methodparam/db:funcparams">
        <xsl:attribute name="xreflabel"
          select="db:constructorsynopsis/db:methodparam
          /db:funcparams"/>
      </xsl:if>
      <db:seg>
        <xsl:if test="(@performance and $arch='dependencies') or
                       @performance='required'">
          <xsl:attribute name="annotations" select="@performance"/>
        </xsl:if>
        <!-- $authorloc is missing EXCEPT when doing author-specified 
             packages so here we create an @role attribute (options)
             if the @role is present (whether or not $authorloc is 
             present) but we ADD any author-supplied options if 
             $authorloc IS pesent (that is, if the author requested 
             any options for a package that is already in $prepost 
             with default options) -->
        <xsl:if test="$authorloc">
          <xsl:attribute name="security">
            <xsl:value-of select="normalize-space($authorloc)"/>
          </xsl:attribute>
        </xsl:if>
        <xsl:choose>
          <!-- @role only: use it -->
          <xsl:when test="@role and not($authorloc)">
            <xsl:attribute name="role">
              <xsl:value-of select="@role"/>
            </xsl:attribute>
          </xsl:when>
          <!-- no @role but $authorloc has a @role of its own -->
          <xsl:when test="$authorloc and
                          not(@role) and
                          $authorloc/db:seg/@role">
            <xsl:attribute name="role">
              <xsl:value-of select="$authorloc/db:seg/@role"/>
            </xsl:attribute>
          </xsl:when>
          <!-- @role and $authorloc and $authorloc has a 
               @role of its own -->
          <xsl:when test="@role and
                          $authorloc and
                          $authorloc/db:seg/@role">
            <xsl:attribute name="role">
              <xsl:value-of select="@role | $authorloc/db:seg/@role"/>
            </xsl:attribute>
          </xsl:when>
          <!-- neither @role nor $authorloc means no @role needed 
          <xsl:otherwise>
            <xsl:attribute name="security">
              <xsl:if test="@role">
                <xsl:value-of select="@role"/>
                <xsl:text> role</xsl:text>
              </xsl:if>
              <xsl:if test="$authorloc and $authorloc/db:seg/@role!=''">
                <xsl:value-of select="$authorloc/db:seg/@role"/>
                <xsl:text> authorloc</xsl:text>
              </xsl:if>
            </xsl:attribute>              
          </xsl:otherwise>
          -->
        </xsl:choose>
        <xsl:if test="@revision">
          <xsl:attribute name="revision" select="@revision"/>
        </xsl:if>
        <xsl:if test="@conformance">
          <xsl:attribute name="conformance" select="@conformance"/>
        </xsl:if>
        <xsl:if test="@condition">
          <xsl:attribute name="condition" select="@condition"/>
        </xsl:if>
        <xsl:value-of select="@remap"/>
      </db:seg>
    </db:seglistitem>
  </xsl:template>
%    \end{macrocode}
% \paragraph[Making listings]{Making listings :}
% \begin{CPKtemplate}{makelisting}\label{template-db2dtx-makelisting}
% This is a tricky one:
% \emph{ClassPack} has to handle the
% code listings both for Doc\TeX{}
% \texttt{macrocode} environments and for
% documentation listings in a consistent manner. This
% template gets invoked at various points in the
% handling of \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} elements.\par
% Start by getting the file type (extension) of any
% \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}}
% attribute.\par
% \label{makelisting}
%    \begin{macrocode}
  <!-- context is still programlisting -->
  <xsl:template name="makelisting">
    <xsl:variable name="fileext"
      select="tokenize(@xlink:href,'\.')[position()=last()]"/>
    <xsl:choose>
%    \end{macrocode}
% If the \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}}
% attribute was present, it means we need to read the
% content from the named external file, and use the
% {\ttfamily{}\textbackslash{}lstinputlisting} command. The
% language argument always gets set first because it’s
% compulsory (also useful because it means all
% subsequent arguments can be preceded by their comma).
% These are languages supported by the
% \textsf{listings} package, as amended by
% \emph{Classpack} in
% {\ttfamily{}prepost.xml}\thinspace.\par
%    \begin{macrocode}
      <xsl:when test="@xlink:href">
        <xsl:text>% \lstinputlisting[</xsl:text>
        <xsl:text>language=</xsl:text>
        <xsl:choose>
          <xsl:when test="@language='LaTeXe'
                          or @language='LaTeX'
                          or not(@language)">
            <xsl:text>{LaTeXe}</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="@language"/>
          </xsl:otherwise>
        </xsl:choose>
%    \end{macrocode}
% If we are using line-range marker labels (ie start
% and end) \emph{and} \textbf{not} using fragments
% (generated by \emph{chunk}\thinspace(1), we need to
% specify the syntax of the range prefix and suffix
% (\url{&&} for \TeX{} and
% \BibTeX{}; a
% \verb|<?cpdoc...?>| PI
% for \textsc{xml} and \textsc{xsl};
% or a \url{##} for scripts).\par
%    \begin{macrocode}
        <xsl:if test="@startinglinenumber or @endinglinenumber">
          <xsl:if
            test="(not(number(@startinglinenumber))
                  or
                  not(number(@endinglinenumber)))
                  and
                  not(@conformance='frag')">
            <xsl:choose>
              <xsl:when test="$fileext='tex'
                              or
                              $fileext='bib'">
                <xsl:text>,rangeprefix=\%\%\ </xsl:text>
                <xsl:text>,rangesuffix=\ \%\%</xsl:text>
              </xsl:when>
              <xsl:when test="$fileext='xml'
                              or
                              $fileext='xsl'
                              or
                              $fileext='xmap'">
                <xsl:text>,rangeprefix={\&lt;?cpdoc\ }</xsl:text>
                <xsl:text>,rangesuffix={?\>}</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>,rangeprefix=\#\#\ </xsl:text>
                <xsl:text>,rangesuffix=\ \#\#</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:if>
%    \end{macrocode}
% Set the from and to boundaries, unless the file is
% being done in fragments.\par
%    \begin{macrocode}
          <xsl:if test="not(@conformance='frag')">
            <!-- from -->
            <xsl:choose>
              <xsl:when test="@startinglinenumber">
                <xsl:choose>
                  <xsl:when
                    test="number(@startinglinenumber)">
                    <xsl:text>,firstline=</xsl:text>
                    <xsl:value-of
                      select="@startinglinenumber"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:text>,linerange=</xsl:text>
                    <xsl:value-of
                      select="@startinglinenumber"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>,firstline=1</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
            <!-- to -->
            <xsl:choose>
              <xsl:when test="@endinglinenumber">
                <xsl:choose>
                  <xsl:when
                    test="number(@endinglinenumber)
                          or
                          number(@startinglinenumber)">
                    <xsl:text>,lastline=</xsl:text>
                    <xsl:value-of
                      select="@endinglinenumber"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:text>-</xsl:text>
                    <xsl:value-of
                      select="@endinglinenumber"/>
                    <xsl:text>,includerangemarker=false</xsl:text>
                    <xsl:text>,showlines=false</xsl:text>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text></xsl:text>
              </xsl:otherwise>
            </xsl:choose>
            <!-- both -->
            <xsl:text>,numbers=left</xsl:text>
            <xsl:text>,numberstyle=\ttfamily</xsl:text>
            <xsl:text>\scriptsize\color{Blue}</xsl:text>
            <xsl:variable name="thisapp"
              select="(ancestor::db:chapter
                      |
                      ancestor::db:appendix)/@xml:id"/>
            <xsl:variable name="pth"
              select="count(preceding::db:programlisting
                      [@xlink:href=current()/@xlink:href]
                      [(ancestor::db:chapter|ancestor::db:appendix)
                        /@xml:id=$thisapp])+1"/>
            <xsl:variable name="proglistgroup">
              <xsl:value-of select="$thisapp"/>
              <xsl:text>-</xsl:text>
              <xsl:value-of select="$pth"/>
            </xsl:variable>
            <xsl:choose>
              <!-- if this is the first of more than one -->
              <xsl:when
                test="$pth=1
                      and
                      count(following::db:programlisting
                      [@xlink:href=current()/@xlink:href]
                      [(ancestor::db:chapter|ancestor::db:appendix)
                        /@xml:id=$thisapp])>0">
                <xsl:text>,name=</xsl:text>
                <xsl:value-of select="$proglistgroup"/>
                <xsl:text>,firstnumber=1</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>,name=</xsl:text>
                <xsl:value-of select="$proglistgroup"/>
                <xsl:text>,firstnumber=last</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:if>
        </xsl:if>
      </xsl:when>
        <!-- still waiting for the closing square bracket -->
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{makelisting}\quad}Starting the listing
% environment.}
% An extreme case to do first is to test for
% documenting the \texttt{lstlisting} itself (see
% the \textsf{listings} manual for details).
% There is a matching tag at the end of this
% template.\par
%    \begin{macrocode}
      <xsl:when test="contains(.,'\begin{lstlisting}')">
        <xsl:text>% \iffalse
%&lt;*ignore>
% \fi&#xa;</xsl:text>
        <xsl:text>\begin{listingsdoc}</xsl:text>
      </xsl:when>
%    \end{macrocode}
% Otherwise the start is similar but for the
% environment name.\par
%    \begin{macrocode}
      <!-- otherwise do a begin and end -->
      <xsl:otherwise>
        <xsl:text>% \iffalse
%&lt;*ignore>
% \fi&#xa;</xsl:text>
        <xsl:text>\begin{lstlisting}[</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
%    \end{macrocode}
% If there is \emph{no} external file,
% specify the language first, for the same reasons as
% above.\par
%    \begin{macrocode}
    <xsl:if test="not(@xlink:href)">
      <xsl:text>language=</xsl:text>
      <xsl:choose>
        <xsl:when test="@language='LaTeXe'
                        or @language='LaTeX'
                        or not(@language)">
          <xsl:text>{[LaTeX]TeX}</xsl:text>
        </xsl:when>
        <xsl:when test="@language='DocBook'">
          <xsl:text>DocBook</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@language"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
%    \end{macrocode}
% Now (for all cases except the documentation of the
% \texttt{lstlisting} itself, see above), go
% through the possible controls.\par
% Whether the file is external or not, the
% {\ttfamily{}\textbackslash{}basicstyle} (the default) is preset
% to
% \verb|\footnotesize\color{Black}\ttfamily| 
% in the {\ttfamily{}prepost.xml} configuration
% for \textsf{listings}.\par
% \begin{itemize}
% \item The \texttt{@wordsize}\index{wordsize=\texttt{\char'100 wordsize} (attribute)}\index{attributes:!wordsize=\texttt{\char'100 wordsize}}
%     attribute is used to change the font size (either
%     a size and baseline separated by a slash, eg \texttt{"12/14"}\index{12/14=\texttt{"12/14"} (attribute value)}\index{attribute values:!12/14=\texttt{"12/14"}}) or a whole new
%     {\ttfamily{}\textbackslash{}basicstyle} definition);
% \item The \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}} \texttt{\unskip="framed"}\index{framed=\texttt{"framed"} (attribute value)}\index{attribute values:!framed=\texttt{"framed"}} attribute signals
%     a framed display (default is no frame);
% \item The \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}}
%     attribute changes the style (eg italics) of any
%     keywords given in the \texttt{@annotations}\index{annotations=\texttt{\char'100 annotations} (attribute)}\index{attributes:!annotations=\texttt{\char'100 annotations}} attribute
%     (below);
% \item The \texttt{@annotations}\index{annotations=\texttt{\char'100 annotations} (attribute)}\index{attributes:!annotations=\texttt{\char'100 annotations}}
%     attribute specifies key words (or any
%     \texttt{<userinput>}\index{userinput=\texttt{\char'074 userinput\char'076 } (element)}\index{elements:!userinput=\texttt{\char'074 userinput\char'076 }}content) needing special
%     emphasis.\par
% \item The \texttt{@linenumbering}\index{linenumbering=\texttt{\char'100 linenumbering} (attribute)}\index{attributes:!linenumbering=\texttt{\char'100 linenumbering}}
%     attribute specifies line numbering;
% \item The \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}}
%     attribute requests a label.
% \end{itemize}
% Finally, some adjustments are made to the width to
% allow for numbering, framing, etc.\par
%    \begin{macrocode}
    <xsl:if test="not(contains(.,'\begin{lstlisting}'))">
      <!-- font size -->
      <xsl:if test="@wordsize">
        <xsl:text>,breaklines=true</xsl:text>
        <xsl:text>,basicstyle=</xsl:text>
        <xsl:if test="@wordsize!=''">
          <xsl:choose>
            <xsl:when test="contains(@wordsize,'/')">
              <xsl:text>\fontsize{</xsl:text>
              <xsl:value-of
                select="substring-before(@wordsize,'/')"/>
              <xsl:text>}{</xsl:text>
              <xsl:value-of
                select="substring-after(@wordsize,'/')"/>
              <xsl:text>}\selectfont</xsl:text>
            </xsl:when>
            <xsl:when test="number(@wordsize)">
              <xsl:text>\fontsize{</xsl:text>
              <xsl:value-of select="@wordsize"/>
              <xsl:text>}{</xsl:text>
              <xsl:value-of
                select="number(@wordsize) * 1.2"/>
              <xsl:text>}\selectfont</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="@wordsize"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:if>
        <xsl:text>\color{Black}\ttfamily,</xsl:text>
      </xsl:if>
      <!-- default is unframed -->
      <xsl:if test="@arch='framed'">
        <xsl:text>,frame=single,framesep=1em</xsl:text>
      </xsl:if>
      <!-- remap changes style of "emphasis" keywords -->
      <xsl:if test="@remap">
        <xsl:text>,emphstyle=</xsl:text>
        <xsl:value-of select="@remap"/>
      </xsl:if>
      <!-- the emphasis keywords themselves -->
      <xsl:if test="@annotations or db:userinput">
        <xsl:text>,emph={</xsl:text>
        <xsl:value-of select="@annotations"/>
        <xsl:if test="db:userinput">
          <xsl:for-each select="db:userinput">
            <xsl:if test="not(preceding-sibling::db:userinput
                              [.=current()/.])">
              <xsl:if test="(position()=1 and ../@annotations) 
                            or
                            position()&gt;1">
                <xsl:text>,</xsl:text>
              </xsl:if>
              <xsl:value-of select="."/>
            </xsl:if>
          </xsl:for-each>
        </xsl:if>
        <xsl:text>}</xsl:text>
      </xsl:if>
      <!-- numbering -->
      <xsl:if test="@linenumbering='numbered'">
        <xsl:text>,numbers=left</xsl:text>
        <xsl:text>,numberstyle=\sffamily\footnotesize</xsl:text>
        <xsl:text>,numbersep=2em</xsl:text>
      </xsl:if>
      <!-- label -->
      <xsl:if test="@xml:id">
        <xsl:text>,label=</xsl:text>
        <xsl:value-of select="@xml:id"/>
      </xsl:if>
      <xsl:if test="@linenumbering='numbered' or @arch='framed'">
        <xsl:if test="@arch='framed'">
          <xsl:text>,xrightmargin=1em</xsl:text>
        </xsl:if>
        <xsl:choose>
          <xsl:when
            test="@linenumbering='numbered' and @arch='framed'">
            <xsl:text>,xleftmargin=3.5em</xsl:text>
          </xsl:when>
          <xsl:when test="@linenumbering='numbered'">
            <xsl:text>,xleftmargin=2.5em</xsl:text>
          </xsl:when>
          <xsl:when test="@arch='framed'">
            <xsl:text>,xleftmargin=1em</xsl:text>
          </xsl:when>
        </xsl:choose>
      </xsl:if>
      <xsl:text>]</xsl:text>
    </xsl:if>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{makelisting}\quad}Then the filename or content}
% If a filename was specified, add it as an argument
% to the {\ttfamily{}\textbackslash{}lstinputlisting} command
% generated above. If we are using fragments, the
% filename is catenated with a hyphen from the given
% filename and the \texttt{@startinglinenumber}\index{startinglinenumber=\texttt{\char'100 startinglinenumber} (attribute)}\index{attributes:!startinglinenumber=\texttt{\char'100 startinglinenumber}} string
% value, which is what the \emph{chunk}\thinspace(1) script
% creates.\par
%    \begin{macrocode}
    <xsl:choose>
      <!-- for an included file, here’s the filename -->
      <xsl:when test="@xlink:href">
        <xsl:text>{</xsl:text>
        <xsl:choose>
          <xsl:when test="@conformance='frag'">
            <xsl:variable name="fn">
              <xsl:choose>
                <xsl:when test="contains(@xlink:href,'/')">
                  <xsl:value-of
                    select="tokenize(@xlink:href,'/')
                            [position()=last()]"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="@xlink:href"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <!-- add directory prefix if needed -->
            <xsl:if test="contains(@xlink:href,'/')">
              <xsl:for-each
                select="tokenize(@xlink:href,'/')
                        [not(position()=last())]">
                <xsl:value-of select="."/>
                <xsl:text>/</xsl:text>
              </xsl:for-each>
            </xsl:if>
            <xsl:value-of
              select="substring-before($fn,'.')"/>
            <xsl:text>-</xsl:text>
            <xsl:value-of select="@startinglinenumber"/>
            <!--
            <xsl:text>-</xsl:text>
            <xsl:value-of select="@endinglinenumber"/>
            -->
            <xsl:text>.</xsl:text>
            <xsl:value-of select="@conformance"/>
            <!--
            <xsl:value-of select="$fileext"/>
            -->
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="@xlink:href"/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>}&#xa;</xsl:text>
      </xsl:when>
%    \end{macrocode}
% Otherwise (no file), we use content, so we must
% start with a newline. The
% \DescribeTemplate{lrtrim}\texttt{lrtrim} named template handles
% the normalisation of the start and end of data, and
% also adds a 2–space indent if the content has any of
% the three environment end-commands specified.\par
%    \begin{macrocode}
      <xsl:otherwise>
        <xsl:text>&#xa;</xsl:text>
        <!-- output the content -->
        <xsl:call-template name="lrtrim">
          <xsl:with-param name="text" select="."/>
          <xsl:with-param name="indent">
            <xsl:choose>
              <xsl:when
                test="contains(.,'\end{lstlisting}') or
                      contains(.,'\end{verbatim}') or
                      contains(.,'\end{Verbatim}')">
                <xsl:text>  </xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text></xsl:text>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:with-param>
        </xsl:call-template>
%    \end{macrocode}
% Finally, output the closing tags to match those
% added earlier.\par
%    \begin{macrocode}
        <xsl:choose>
          <xsl:when
            test="contains(.,'\begin{lstlisting}')">
            <xsl:text>&#xa;\end{listingsdoc}&#xa;</xsl:text>
        <xsl:text>% \iffalse
%&lt;/ignore>
% \fi&#xa;</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>&#xa;\end{lstlisting}&#xa;</xsl:text>
        <xsl:text>% \iffalse
%&lt;/ignore>
% \fi&#xa;</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="@conformance='frag'">
      <xsl:text>% \label{</xsl:text>
      <xsl:if test="number(@startinglinenumber)">
        <xsl:text>frag-</xsl:text>
      </xsl:if>
      <xsl:value-of select="@startinglinenumber"/>
      <xsl:text>}&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{casestyle}\label{template-db2dtx-casestyle}
% This handles small caps for typefaces that don’t
% have them (they must be flagged in
% {\ttfamily{}prepost.xml}). This is usually
% easier than trying to get \LaTeX{} to do it. Create a
% variable holding the declared package entry in the
% document matching any known non-small-cap typefaces
% (eg Gotham, DejaVu) from
% {\ttfamily{}prepost.xml}\thinspace. If there’s a match,
% use a smaller size and all upper-case, otherwise use
% {\ttfamily{}\textbackslash{}textsc} as normal.\par
%    \begin{macrocode}
  <xsl:template name="casestyle">
    <!-- disabled temporarily: just emits \textsc{...} -->
    <xsl:param name="text"/>
    <xsl:variable name="nosc">
      <xsl:for-each
        select="$prepost//db:step[@conformance='nosc']">
        <xsl:value-of
          select="$thisdoc//db:constraintdef
                  [@xml:id='docpackages']
                  //db:seg[.=current()/@remap]"/>
      </xsl:for-each>
    </xsl:variable>
    <!--
    <xsl:choose>
      <xsl:when test="count($nosc)>0">
        <xsl:text>\SMC{</xsl:text>
        <xsl:value-of select="lower-case($text)"/>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        -->
        <xsl:text>\textsc{</xsl:text>
        <xsl:value-of select="lower-case($text)"/>
        <xsl:text>}</xsl:text>
        <!--
      </xsl:otherwise>
    </xsl:choose>
    -->
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection*{AutoPackage}
% \begin{CPKtemplate}{nondeferred}\label{template-db2dtx-nondeferred}
% \emph{AutoPackage} provides
% for two modes of inclusion:\par
% \begin{enumerate}[noitemsep]
% \item deferred — the
%     {\ttfamily{}\textbackslash{}RequirePackage} commands are not
%     processed until (selectably) before or after a
%     specific section of the class or package code,
%     specified by the author;
% \item non-deferred — all
%     {\ttfamily{}\textbackslash{}RequirePackage} commands are
%     issued at the start of the class or package
%     Preamble in the normal way.
% \end{enumerate}
% This template provides for the second (default)
% mode. These are all called inline from the template
% which processes the document root, so their context
% node is {\ttfamily{}/}\thinspace. The primary
% condition in the template checks that there are indeed
% some packages to process (those
% \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} packages for the current
% document type which are \emph{not}
% re-use links, and whose \texttt{<seg>}\index{seg=\texttt{\char'074 seg\char'076 } (element)}\index{elements:!seg=\texttt{\char'074 seg\char'076 }} subelement is
% non-null), so that it can output the Doc\TeX{} package
% tag, then processes each of them.\par
%    \begin{macrocode}
  <!-- CURRENTLY NON-OPERATIONAL -->
  <xsl:template name="nondeferredpackages">
    <!-- if there are any authorial non-null <seg> requests -->
    <xsl:if
      test="/db:book/db:info/db:cover/db:constraintdef
            [@xml:id=concat($filetype,'packages')]
            [not(@linkend)]
            /db:segmentedlist/db:seglistitem[db:seg!='']">
      <xsl:text>%&lt;package>%
%&lt;package>% Packages invoked at start, before options
%&lt;package>%&#xa;</xsl:text>
      <!-- call packages on each seglistitem -->
      <xsl:for-each 
        select="/db:book/db:info/db:cover/db:constraintdef
                [@xml:id=concat($filetype,'packages')]
                [not(@linkend)]
                /db:segmentedlist/db:seglistitem
                  [db:seg!='']">
        <xsl:call-template name="packages">
          <xsl:with-param name="pkg" select="."/>
          <xsl:with-param name="dest" select="$filetype"/>
        </xsl:call-template>
      </xsl:for-each>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{packages}\label{template-db2dtx-packages}
% This template is the key to the
% \emph{AutoPackage} mechanism. The
% \texttt{<seglistitem>}\index{seglistitem=\texttt{\char'074 seglistitem\char'076 } (element)}\index{elements:!seglistitem=\texttt{\char'074 seglistitem\char'076 }} elements from
% {\ttfamily{}prepost.xml} and the user's
% document containing the names of the packages needed
% are passed into this template in the \DescribeParameter{pkg}{\ttfamily{}\$pkg}
% parameter, along with their destination (\DescribeParameter{dest}{\ttfamily{}\$dest}
% being the current document type \texttt{"doc"}\index{doc=\texttt{"doc"} (attribute value)}\index{attribute values:!doc=\texttt{"doc"}}, \texttt{"cls"}\index{cls=\texttt{"cls"} (attribute value)}\index{attribute values:!cls=\texttt{"cls"}}, or \texttt{"pkg"}\index{pkg=\texttt{"pkg"} (attribute value)}\index{attribute values:!pkg=\texttt{"pkg"}}), whether this call is
% for deferred mode or non-deferred mode (\DescribeParameter{mode}{\ttfamily{}\$mode}),
% and the element from which this template was called
% (\DescribeParameter{loc}{\ttfamily{}\$loc}).\par
%    \begin{macrocode}
  <xsl:template name="packages">
    <xsl:param name="pkg"/>
    <xsl:param name="dest"/>
    <xsl:param name="cmdblocks"/>
    <xsl:param name="mode">
      <xsl:text></xsl:text>
    </xsl:param>
    <xsl:param name="loc"/>
%    \end{macrocode}
% If the package for loading in a class or style is
% explicitly mentioned in its own \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }}
% element (ie manually), it will get loaded there, so
% just output a comment here.\par
%    \begin{macrocode}
    <xsl:choose>
      <!-- OMIT BECAUSE THE PACKAGE IS ADDED MANUALLY -->
      <xsl:when
        test="($dest='cls' or $dest='sty')
              and
              $loc/ancestor::db:part[@xml:id='code']
              and
              ($loc/ancestor::db:chapter
                /descendant::db:annotation
                [@xreflabel=$pkg/db:seg][@role='package']
               or
               $loc/ancestor::db:appendix
                /descendant::db:annotation
               [@xreflabel=$pkg/db:seg][@role='package'])">
        <xsl:text>% Package \textsf{</xsl:text>
        <xsl:value-of select="$pkg/db:seg"/>
        <xsl:text>} omitted here (coded manually)</xsl:text>
        <xsl:text> on p.\pageref{ann-</xsl:text>
        <xsl:value-of select="$pkg/db:seg"/>
        <xsl:text>}.\par&#xa;%% Package \textsf{</xsl:text>
        <xsl:value-of select="$pkg/db:seg"/>
        <xsl:text>} omitted (coded manually)&#xa;</xsl:text>
      </xsl:when>
      <!-- no need now we have ifpackageloaded
      <xsl:when test="$dest='sty'
                      and
                      $thisdoc/db:book/@xlink:role
                      and
                      $pkg/db:seg='xcolor'">
        <xsl:text>% Package \textsf{</xsl:text>
        <xsl:value-of select="$pkg/db:seg"/>
        <xsl:text>} may get omitted to avoid clashes&#xa;</xsl:text>
      </xsl:when>
      -->
%    \end{macrocode}
% If this is [normal]
% `deferred' mode, start the
% documentation block with any documentation for the
% package from the {\ttfamily{}prepost.xml} file
% (and if none, output a comment to that effect); then
% add any supplied by the user in the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute. Repeat the
% documentation for the package from the
% {\ttfamily{}prepost.xml} file as a comment as
% well.\par
%    \begin{macrocode}
      <!-- OTHERWISE NORMAL INCLUSION -->
      <xsl:otherwise>
        <xsl:if test="$mode='deferred'">
          <xsl:text>% \begin{CPKpackage}{</xsl:text>
          <xsl:value-of select="$pkg/db:seg"/>
          <xsl:text>}&#xa;</xsl:text>
          <xsl:apply-templates
            select="$prepost/db:procedure
                    [@xml:id='prepackage']
                    /db:step[contains(@condition,$dest)]
                    [@remap=$pkg/db:seg]/db:para"/>
          <!-- warn about package not in prepost -->
          <xsl:if 
            test="count($prepost/db:procedure
                        [@xml:id='prepackage']
                        /db:step[contains(@condition,$dest)]
                        [@remap=$pkg/db:seg]/db:para)=0">
            <xsl:message>
              <xsl:text>WARNING: Package </xsl:text>
              <xsl:value-of select="$pkg/db:seg"/>
              <xsl:text> for </xsl:text>
              <xsl:value-of select="$filetype"/>
              <xsl:text> has no doc in prepost.xml</xsl:text>
            </xsl:message>
          </xsl:if>
          <!-- add comment from ClassPack document -->
          <xsl:if test="@role">
            <xsl:text>% </xsl:text>
            <xsl:value-of select="normalize-space(@role)"/>
            <xsl:text>&#xa;</xsl:text>        
          </xsl:if>
          <!-- add explanation from prepost.xml if present -->
          <xsl:if test="count($prepost/db:procedure
                        [@xml:id='prepackage']
                        /db:step[contains(@condition,$dest)]
                        [@remap=$pkg/db:seg]/db:para)>0">
            <xsl:text>% \iffalse&#xa;%% </xsl:text>
            <xsl:value-of
              select="normalize-space(
                        $prepost/db:procedure
                        [@xml:id='prepackage']
                        /db:step[contains(@condition,$dest)]
                        [@remap=$pkg/db:seg]/db:para)"/>
            <xsl:text>&#xa;% \fi&#xa;</xsl:text>
          </xsl:if>
          <xsl:text>%    </xsl:text>
          <xsl:text>\begin</xsl:text>
          <xsl:text>{macrocode}&#xa;</xsl:text>
        </xsl:if>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{packages}\quad}Commands needed before package
% load}
% Check if any special
% \emph{pre}processing is needed before
% invoking the package: this comes from
% {\ttfamily{}prepost.xml} in \texttt{<command>}\index{command=\texttt{\char'074 command\char'076 } (element)}\index{elements:!command=\texttt{\char'074 command\char'076 }}
% elements in the \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} element in
% the \texttt{"prepackage"}\index{prepackage=\texttt{"prepackage"} (attribute value)}\index{attribute values:!prepackage=\texttt{"prepackage"}}
% section.\par
%    \begin{macrocode}
        <!-- output pre-commands -->
        <xsl:for-each 
          select="$prepost/db:procedure
                    [@xml:id='prepackage']
                  /db:step[contains(@condition,$dest)]
                  [@remap=$pkg/db:seg]
                  /db:constraintdef/db:cmdsynopsis
                    /db:command">
          <!-- check to escape internals in doc mode -->
          <xsl:if test="contains(.,'@') and $mode=''">
            <xsl:text>  \makeatletter&#xa;</xsl:text>
          </xsl:if>
          <xsl:text>  </xsl:text>
          <xsl:value-of select="replace(.,'^&#x9;','')"/>
          <xsl:text>&#xa;</xsl:text>
          <!-- end of escaping internals in doc mode -->
          <xsl:if test="contains(.,'@') and $mode=''">
            <xsl:text>  \makeatother&#xa;</xsl:text>
          </xsl:if>
        </xsl:for-each>
%    \end{macrocode}
% In classes and packages, we need to use
% {\ttfamily{}\textbackslash{}RequirePackage}; in documentation
% but {\ttfamily{}\textbackslash{}usepackage} in the class or
% style package code itself. In non-deferred mode in
% classes and packages, the command needs armour and
% {\ttfamily{}\textbackslash{}RequirePackage} to be
% extractable.\par
%    \begin{macrocode}
        <xsl:if test="$dest='sty' and (
                      $pkg/db:seg='xcolor'
                      or
                      $pkg/db:seg='hyperref'
                      or
                      $pkg/db:seg='url'
                      )">
          <xsl:text>\IfPackageLoaded{</xsl:text>
          <xsl:value-of select="$pkg"/>
          <xsl:text>}{\relax}{%&#xa;  </xsl:text>
          <!-- .true. requirepackage/usepackage goes here,
               .false. relax occurs further down -->
        </xsl:if>
        <xsl:choose>
          <xsl:when test="$mode='deferred'">
            <xsl:text>\RequirePackage</xsl:text>
          </xsl:when>
          <xsl:when test="$dest=$filetype">
            <xsl:text>%&lt;</xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>>\RequirePackage</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>\usepackage</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{packages}\quad}Package options}
% Options get output both for autodetected package
% and for those specified by the author, but not if the
% \texttt{<role>}\index{role=\texttt{\char'074 role\char'076 } (element)}\index{elements:!role=\texttt{\char'074 role\char'076 }} attribute was explicitly set to null.
% An exclusion omits the \textbf{\texttt{hyphens}} option
% from the \textsf{url} package and the
% \textbf{\texttt{svgnames}} options from the
% \textsf{xcolor} package,
% \emph{but} \begin{enumerate*}[label=\emph{\alph*}),itemjoin={{; }},itemjoin*={{; and }}]
% \item \textbf{\texttt{hyphens}} must now be a
%       {\ttfamily{}\textbackslash{}documentclass} option in the
%       application document\par
% \item \textbf{\texttt{svgnames}} may need including
%       if \texttt{@xlink:role}\index{xlink:role=\texttt{\char'100 xlink:role} (attribute)}\index{attributes:!xlink:role=\texttt{\char'100 xlink:role}} is
%       specified on the master document root element
%       \texttt{<book>}\index{book=\texttt{\char'074 book\char'076 } (element)}\index{elements:!book=\texttt{\char'074 book\char'076 }}\par
% \end{enumerate*}. If the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} attribute is set
% to \texttt{"only"}\index{only=\texttt{"only"} (attribute value)}\index{attribute values:!only=\texttt{"only"}}, just use the
% options specified by the author, and none from
% {\ttfamily{}prepost.xml}\thinspace.\par
% \par\smallskip\leavevmode
% \CPKrunningecho{packages}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Switch to remap if audience is biblatex and biblatex is specified.}}\par\smallskip
%    \begin{macrocode}
        <xsl:if
          test="$pkg/db:seg/@role 
                or
                $prepost/db:procedure[@xml:id='prepackage']/
                db:step[contains(@condition,$dest)]
                [@remap=$pkg/db:seg]/@role">
          <xsl:choose>
            <!-- elide null options -->
            <xsl:when test="$pkg/db:seg/@role and $pkg/db:seg/@role=''
                            and
                            $prepost/db:procedure[@xml:id='prepackage']/
                            db:step[contains(@condition,$dest)]
                            [@remap=$pkg/db:seg]/@role=''">
              <xsl:text></xsl:text>
            </xsl:when>
            <!-- disallow options on package url disabled 2023-06-19
            <xsl:when test="$pkg/db:seg[.='url']">
              <xsl:text></xsl:text>
            </xsl:when>
            -->
            <!-- auto add svgnames option for xcolor 
                 when package requires itself in doc -->
            <xsl:when test="$pkg/db:seg='xcolor' and
                            /db:book/@xlink:role and
                            $filetype='sty'">
              <xsl:text>[svgnames]</xsl:text>
            </xsl:when>
            <!-- look no further -->
            <xsl:when
              test="$pkg/db:seg/@role
                    and
                    $pkg/db:seg/@condition='only'">
              <xsl:text>[</xsl:text>
              <xsl:value-of select="$pkg/db:seg/@role"/>
              <xsl:text>]</xsl:text>
            </xsl:when>
%    \end{macrocode}
% For all other cases, deduplicate the options
% specified in the author’s package list and those found
% in {\ttfamily{}prepost.xml}\thinspace.\par
%    \begin{macrocode}
            <xsl:otherwise>
              <!-- DEDUPLICATE -->
              <!-- string both sources together -->
              <xsl:variable name="reqs">
                <xsl:value-of
                  select="normalize-space($pkg/db:seg/@role)"/>
                <xsl:text>,</xsl:text>
                <xsl:value-of
                  select="normalize-space($prepost/db:procedure
                          [@xml:id='prepackage']/db:step
                            [contains(@condition,$dest)]
                            [@remap=$pkg/db:seg]
                            [contains('$pkg/db:seg/@role',@role)]
                            /@role)"/>
              </xsl:variable>
              <!-- catch any null values -->
              <xsl:variable name="args">
                <xsl:for-each
                  select="tokenize($reqs,',')[.!='']">
                  <arg>
                    <xsl:value-of select="normalize-space(.)"/>
                  </arg>
                </xsl:for-each>
              </xsl:variable>
              <xsl:if test="count($args/arg[.!=''])>0">
                <xsl:text>[</xsl:text>
                <xsl:call-template name="rewrap">
                  <xsl:with-param name="text">
                    <xsl:for-each 
                      select="$args/arg[.!='']
                              [not(preceding-sibling::arg=.)]">
                      <xsl:if test="position()>1">
                        <xsl:text>,</xsl:text>
                      </xsl:if>
                      <xsl:value-of select="."/>
                    </xsl:for-each>
                  </xsl:with-param>
                </xsl:call-template>
                <xsl:text>]</xsl:text>
              </xsl:if>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:if>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{packages}\quad}Package name}
% Output the package name and version if needed: an
% author-specified date trumps any
% {\ttfamily{}prepost.xml} default.\par
%    \begin{macrocode}
        <!-- PACKAGE NAME -->
        <xsl:text>{</xsl:text>
        <xsl:value-of select="$pkg/db:seg"/>
        <xsl:text>}</xsl:text>
        <!-- POST-OPTIONS -->
        <xsl:if test="($pkg/db:seg/@version
                       and
                       $pkg/db:seg/@version!='')
                      or 
                      $prepost/db:procedure
                        [@xml:id='prepackage']/
                      db:step[contains(@condition,$dest)]
                        [@remap=$pkg/db:seg]/@revision">
          <xsl:text>[</xsl:text>
          <xsl:choose>
            <xsl:when test="$pkg/db:seg/@version[.!='']">
              <xsl:value-of 
                select="translate(substring(
                        $pkg/db:seg/@version,1,10),
                        '-','/')"/>
            </xsl:when>
            <xsl:when
              test="$prepost/db:procedure
                    [@xml:id='prepackage']/
                    db:step[contains(@condition,$dest)]
                    [@remap=$pkg/db:seg]
                    [@role=$pkg/db:seg/@role]/@revision">
              <xsl:value-of 
                select="translate(substring(
                        $prepost/db:procedure
                        [@xml:id='prepackage']/db:step
                          [contains(@condition,$dest)]
                          [@remap=$pkg/db:seg]
                          [@role=$pkg/db:seg/@role]
                        /@revision,1,10),'-','/')"/>
            </xsl:when>
          </xsl:choose>
          <xsl:text>]</xsl:text>
        </xsl:if>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{packages}\quad}Comments}
% Comments only get appended in non-deferred mode;
% deferred ones were added earlier as text.\par
%    \begin{macrocode}
        <xsl:if test="$pkg/@role and $mode=''">
          <xsl:text>% </xsl:text>
          <xsl:value-of
            select="normalize-space($pkg/@role)"/>
          <xsl:if test="@userlevel">
            <xsl:text> (</xsl:text>
            <xsl:value-of select="@userlevel"/>
            <xsl:text>)</xsl:text>
          </xsl:if>
        </xsl:if>
        <xsl:text>%&#xa;</xsl:text>
        <!-- complete the enclosure of ifpackageloaded -->
        <xsl:if test="$dest='sty' and
                      ($pkg/db:seg='xcolor'
                       or $pkg/db:seg='hyperref'
                       or $pkg/db:seg='url')">
          <xsl:text>}%&#xa;</xsl:text>
        </xsl:if>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{packages}\quad}Commands needed after package
% load}
% If there are any \texttt{<command>}\index{command=\texttt{\char'074 command\char'076 } (element)}\index{elements:!command=\texttt{\char'074 command\char'076 }} elements in a
% \texttt{<cmdsynopsis>}\index{cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 } (element)}\index{elements:!cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 }}, output them now, enclosing
% them in {\ttfamily{}\textbackslash{}makeatletter} and
% {\ttfamily{}\textbackslash{}makeatother} if they contain an
% {\ttfamily{}@} sign.\par
%    \begin{macrocode}
        <xsl:if test="not($pkg/db:seg/@condition='only')">
          <!-- go through any supplied commands 
               that are not excluded -->
          <xsl:for-each
            select="$prepost/db:procedure
                    [@xml:id='postpackage']/db:step
                      [contains(@condition,$dest)]
                      [@remap=$pkg/db:seg]
                    /db:constraintdef/db:cmdsynopsis
                    /db:command">
            <!-- exclude commands because of another package -->
            <xsl:if test="not(current()/@conformance=$cmdblocks)">
              <xsl:variable name="matchconditions"
                select="$prepost/db:procedure
                        [@xml:id='prepackage']
                        /db:step
                        [contains(@condition,$dest)]
                        [@remap=$pkg/db:seg]
                        /db:constructorsynopsis"/>
              <!-- load any command without an xml:id
                   OR
                   with an xml:id matching a condition from 
                   the prepost section (ie programlisting
                   with a language whose name matches this
                   xml:id
                   OR
                   with an xml:id starting with the string "lang_".
                   Silent if no matches. -->
              <xsl:if
                test="not(@xml:id)
                      or
                      @xml:id=$thisdoc//*
                      [name()=$matchconditions/@condition]
                      /@*
                      [name()=$matchconditions
                      /db:methodparam/db:parameter]
                      or
                      starts-with(@xml:id,'lang_')">
                <xsl:if test="contains(.,'@') and $mode=''">
                  <xsl:text>  \makeatletter&#xa;</xsl:text>
                </xsl:if>
                <xsl:text>  </xsl:text>
                <xsl:value-of
                  select="replace(.,'^&#x9;','')"/>
                <xsl:text>&#xa;</xsl:text>
                <xsl:if test="contains(.,'@') and $mode=''">
                  <xsl:text>  \makeatother&#xa;</xsl:text>
                </xsl:if>
              </xsl:if>
            </xsl:if>
          </xsl:for-each>
%    \end{macrocode}
% If the current package is the
% \textsf{listings} package, make the
% {\ttfamily{}\textbackslash{}lstdefinelanguage} commands needed
% to enable any languages defined in
% {\ttfamily{}prepost.xml} and used in the
% document that are not built into the
% \textsf{listings} package, and then invoke
% all the languages needed in a
% {\ttfamily{}\textbackslash{}lstloadlanguages} command.\par
% Go through each language marked in any of the
% elements that use them, and find a definition for the
% language among the \texttt{<arg>}\index{arg=\texttt{\char'074 arg\char'076 } (element)}\index{elements:!arg=\texttt{\char'074 arg\char'076 }} elements in the
% \textsf{listings} package entry in
% {\ttfamily{}prepost.xml} and construct the
% {\ttfamily{}\textbackslash{}lstdefinelanguage} command from the
% data given. Languages predefined in the
% \textsf{listings} package need no definition
% here; only those for which a definition exists in
% {\ttfamily{}prepost.xml}\thinspace.\par
% Then repeat a similar process and construct the
% {\ttfamily{}\textbackslash{}lstloadlanguages} command with an
% entry for all the languages used in the document, both
% those predefined in the \textsf{listings}
% package and those for which a definition exists in
% {\ttfamily{}prepost.xml}\thinspace.\par
%    \begin{macrocode}
          <xsl:if test="$pkg/db:seg='listings'">
            <xsl:message>
              <xsl:text>Checking listings language needs:</xsl:text>
            </xsl:message>
            <xsl:for-each-group group-by="@language"
              select="$thisdoc//
                      (db:classname
                      |db:cmdsynopsis
                      |db:command
                      |db:envar
                      |db:function
                      |db:literallayout
                      |db:option
                      |db:parameter
                      |db:programlisting
                      |db:varname)[@language]">
              <!-- langs used but not defined must be among
                   those PREdefined by the listings package -->
              <xsl:message>
                <xsl:text> * </xsl:text>
                <xsl:value-of select="current-grouping-key()"/>
              </xsl:message>
              <xsl:for-each
                select="$prepost/db:procedure
                        [@xml:id='postpackage']/db:step
                        [contains(@condition,$dest)]
                        [@remap=$pkg/db:seg]
                        /db:constraintdef/db:cmdsynopsis
                        /db:arg[@xml:id=
                        concat('lang_',current-grouping-key())]">
                <xsl:text>  \lstdefinelanguage{</xsl:text>
                <xsl:value-of select="current-grouping-key()"/>
                <xsl:text>}</xsl:text>
                <xsl:choose>
                  <xsl:when test="contains(@arch,'[')
                                  or
                                  contains(@arch,'{')">
                    <xsl:value-of select="@arch"/>
                  </xsl:when>
                  <xsl:when test="@arch">
                    <xsl:text>[]{</xsl:text>
                    <xsl:value-of select="@arch"/>
                    <xsl:text>}</xsl:text>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:text></xsl:text>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:value-of select="."/>
                <xsl:text>&#xa;</xsl:text>
              </xsl:for-each>
            </xsl:for-each-group>
            <!-- now load all the ones defined above -->
            <xsl:text>  \lstloadlanguages{</xsl:text>
            <xsl:for-each-group group-by="@language"
              select="$thisdoc//
                      (db:classname
                      |db:cmdsynopsis
                      |db:command
                      |db:envar
                      |db:function
                      |db:literallayout
                      |db:option
                      |db:parameter
                      |db:programlisting
                      |db:varname)[@language]">
              <xsl:if test="position()>1">
                <xsl:text>,</xsl:text>
              </xsl:if>
              <!-- find language in prepost.xml where the xml:id
                   has the form lang_LANG -->
              <xsl:variable name="thislang"
                select="$prepost/db:procedure
                        [@xml:id='postpackage']/db:step
                        [contains(@condition,$dest)]
                        [@remap=$pkg/db:seg]
                        /db:constraintdef/db:cmdsynopsis
                        /db:command[tokenize(@xml:id,'_')[2] =
                        current-grouping-key()]/@xml:id"/>
              <!-- xml:id used to have the form 
                   lang:LANG[-BASEDIALECT]-BASE] no longer needed -->
              <xsl:choose>
                <!-- pre-existing language 
                     (no match in prepost.xml)  -->
                <xsl:when test="$thislang='' or not($thislang)">
                  <xsl:value-of select="current-grouping-key()"/>
                </xsl:when>
                <!-- new languages -->
                <xsl:otherwise>
                  <xsl:value-of select="tokenize($thislang,'_')[2]"/>
                </xsl:otherwise>
                <!-- old code retained unused for now 2024-02-28
                <xsl:when test="count(tokenize($thislang,'_'))=3">
                  <xsl:text>[</xsl:text>
                  <xsl:value-of select="tokenize($thislang,'_')[2]"/>
                  <xsl:text>]</xsl:text>
                  <xsl:value-of select="tokenize($thislang,'_')[3]"/>
                </xsl:when>
                <xsl:when test="count(tokenize($thislang,'_'))=4">
                  <xsl:text>[</xsl:text>
                  <xsl:value-of select="tokenize($thislang,'_')[2]"/>
                  <xsl:text>]{</xsl:text>
                  <xsl:text>[</xsl:text>
                  <xsl:value-of select="tokenize($thislang,'_')[3]"/>
                  <xsl:text>]</xsl:text>
                  <xsl:value-of select="tokenize($thislang,'_')[4]"/>
                  <xsl:text>}</xsl:text>
                </xsl:when>
                -->
              </xsl:choose>
            </xsl:for-each-group>
            <xsl:text>}&#xa;</xsl:text>
          </xsl:if>
%    \end{macrocode}
% If the current package is the
% \textsf{dox} package, make the
% {\ttfamily{}\textbackslash{}doxitem} commands needed to create
% the {\ttfamily{}\textbackslash{}Describe*} and
% {\ttfamily{}\textbackslash{}Print*Name} commands for marginal
% annotation ({\ttfamily{}*} being the
% object name).\par
% Go through the \texttt{<arg>}\index{arg=\texttt{\char'074 arg\char'076 } (element)}\index{elements:!arg=\texttt{\char'074 arg\char'076 }} elements in the
% \textsf{dox} package entry in
% {\ttfamily{}prepost.xml}\thinspace, and if there is a
% matching \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} \texttt{\unskip/@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} and \texttt{<tag>}\index{tag=\texttt{\char'074 tag\char'076 } (element)}\index{elements:!tag=\texttt{\char'074 tag\char'076 }} \texttt{\unskip/@class}\index{class=\texttt{\char'100 class} (attribute)}\index{attributes:!class=\texttt{\char'100 class}} attribute, construct a
% command (given in the \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}}; currently only
% {\ttfamily{}\textbackslash{}doxitem} is supported) with options
% and arguments taken from the \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} attribute and others;
% and also create the {\ttfamily{}\textbackslash{}Print*Name}
% command using the \texttt{@pre}\index{pre=\texttt{\char'100 pre} (attribute)}\index{attributes:!pre=\texttt{\char'100 pre}} and
% \texttt{@post}\index{post=\texttt{\char'100 post} (attribute)}\index{attributes:!post=\texttt{\char'100 post}} attributes.\par
%    \begin{macrocode}
          <xsl:if test="$pkg/db:seg='dox'">
            <xsl:message>
              <xsl:text>Checking dox formatting needs:</xsl:text>
            </xsl:message>
            <xsl:for-each
              select="$prepost/db:procedure
                      [@xml:id='postpackage']/db:step
                      [contains(@condition,$dest)]
                      [@remap=$pkg/db:seg]
                      /db:constraintdef/db:cmdsynopsis
                      /db:arg">
              <xsl:if
                test="$thisdoc//db:annotation
                      [@role=lower-case(current()/@xml:id)]
                      or
                      $thisdoc//db:tag
                      [@class=lower-case(current()/@xml:id)]
                      or
                      @xml:id='Option'
                      or
                      @xml:id='Package'
                      or
                      @xml:id='Class'
                      or
                      @xml:id='Comment'">
                <xsl:message>
                  <xsl:text> * </xsl:text>
                  <xsl:choose>
                    <xsl:when test=".=''">
                      <xsl:value-of select="lower-case(@xml:id)"/>
                      <xsl:text>s</xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="."/>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:message>
                <xsl:text>  \</xsl:text>
                <xsl:value-of select="@arch"/>
                <xsl:text>[idxtype=</xsl:text>
                <xsl:choose>
                  <xsl:when test="@xml:id=upper-case(@xml:id)">
                    <xsl:value-of select="@xml:id"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="lower-case(@xml:id)"/>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:if test="@role">
                  <xsl:text>,</xsl:text>
                  <xsl:value-of select="@role"/>
                </xsl:if>
                <xsl:text>]{</xsl:text>
                <xsl:value-of select="@xml:id"/>
                <xsl:text>}{CPK</xsl:text>
                <xsl:choose>
                  <xsl:when test="@remap">
                    <xsl:value-of select="lower-case(@remap)"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="lower-case(@xml:id)"/>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:text>}{</xsl:text>
                <xsl:choose>
                  <xsl:when test=".=''">
                    <xsl:value-of select="lower-case(@xml:id)"/>
                    <xsl:text>s</xsl:text>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="."/>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:text>}&#xa;  \def\Print</xsl:text>
                <xsl:choose>
                  <xsl:when test="@remap">
                    <xsl:value-of select="@remap"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="@xml:id"/>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:text>Name#1{</xsl:text>
                <xsl:value-of select="@pre"/>
                <xsl:value-of select="'#1'"/>
                <xsl:value-of select="@post"/>
                <xsl:text>}&#xa;</xsl:text>
              </xsl:if>
            </xsl:for-each>
          </xsl:if>
        </xsl:if>
%    \end{macrocode}
% In deferred mode, terminate the code and output
% any postpackage documentation.\par
%    \begin{macrocode}
        <xsl:if test="$mode='deferred'">
          <xsl:text>%    </xsl:text>
          <xsl:text>\end</xsl:text>
          <xsl:text>{macrocode}&#xa;</xsl:text>
          <!-- post-package comments from prepost.xml -->
          <xsl:apply-templates
            select="$prepost/db:procedure
                    [@xml:id='postpackage']
                    /db:step[contains(@condition,$dest)]
                    [@remap=current()/db:seg]/db:para"/>
          <xsl:text>% \end{CPKpackage}&#xa;</xsl:text>
        </xsl:if>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{packages}\quad}Self-loading}
% Finally, see if the package we are documenting
% needs itself loading for the documentation (eg for
% examples). This only applies in non-deferred
% mode.\par
%    \begin{macrocode}
        <xsl:if test="$mode=''
                      and
                      $dest='doc'
                      and
                      $doctype='package'
                      and
                      /db:book/@role">
          <xsl:text>% \usepackage</xsl:text>
          <xsl:if test="/db:book/@role!=''">
            <xsl:text>[</xsl:text>
            <xsl:value-of select="/db:book/@role"/>
            <xsl:text>]</xsl:text>
          </xsl:if>
          <xsl:text>{</xsl:text>
          <xsl:value-of select="$docname"/>
          <xsl:text>}% added by spec.&#xa;</xsl:text>
        </xsl:if>        
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{rewrap}\label{template-db2dtx-rewrap}
% Rewrapping is designed for a long options list in
% {\ttfamily{}\textbackslash{}RequirePackage}. The {\ttfamily{}\$text} parameter is a
% comma-separated vector or arguments; the {\ttfamily{}\$maxlen} parameter is the
% maximum line length to output: the default is 32 but
% the value becomes 50 after the first line.\par
%    \begin{macrocode}
  <xsl:template name="rewrap">
    <xsl:param name="text"/>
    <xsl:param name="maxlen">
      <xsl:text>32</xsl:text>
    </xsl:param>
    <xsl:choose>
      <!-- if text is an overlong string 
           but contains a comma -->
      <xsl:when
        test="string-length($text)>$maxlen
        and contains($text,',')">
        <!-- see if there is a comma 
             within the first $maxlen chars -->
        <xsl:variable name="prelastcomma">
          <xsl:choose>
            <xsl:when
              test="contains(substring($text,1,$maxlen),
                    ',')">
              <xsl:analyze-string
                select="substring($text,1,$maxlen)"
                regex="^(.*)(,)([^,]*)$">
                <xsl:matching-substring>
                  <xsl:value-of
                    select="concat(regex-group(1),',')"/>
                </xsl:matching-substring>
                <xsl:non-matching-substring>
                  <xsl:text>NO "," IN SUBSTRING</xsl:text>
                </xsl:non-matching-substring>
              </xsl:analyze-string>
            </xsl:when>
            <!-- No comma in range, 
                 test whole string -->
            <xsl:otherwise>
              <xsl:analyze-string select="$text"
                regex="^(.*)(,)([^,]*)$">
                <xsl:matching-substring>
                  <xsl:value-of
                    select="concat(regex-group(1),',')"/>
                </xsl:matching-substring>
                <xsl:non-matching-substring>
                  <xsl:text>NO "," IN STRING</xsl:text>
                </xsl:non-matching-substring>
              </xsl:analyze-string>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:value-of select="$prelastcomma"/>
        <xsl:choose>
          <xsl:when
            test="ancestor::db:constraintdef
                  [@xml:id=concat($filetype,'packages')]">
            <xsl:text>&#xa;  </xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>&#xa;  </xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:call-template name="rewrap">
          <xsl:with-param name="text" 
            select="normalize-space(
                    substring-after(
                    $text,$prelastcomma))"/>
          <xsl:with-param name="maxlen">
            <xsl:text>50</xsl:text>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \changes{v1.18}{2020/04/01}{Fixed bug where it failed to add the filetype before substringing the full name of the document}
% \begin{CPKtemplate}{makechapapp}\label{template-db2dtx-makechapapp}
% \label{makechapapp}This template handles the
% code needed to set up a chapter or appendix. It gets
% called from the \DescribeTemplate{chapter}{\ttfamily{}chapter} and \DescribeTemplate{appendix}{\ttfamily{}appendix}
% templates, which pass the variables\par
% \begin{itemize}[noitemsep]
% \item \DescribeVariable{thisdocfullname}{\ttfamily{}\$thisdocfullname}, which
%     is the document name itself, unless there is an
%     attribute \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}},
%     in which case that’s the filename;
% \item \DescribeVariable{thisdocname}{\ttfamily{}\$thisdocname}, which is
%     the full name without the filetype;
% \item \DescribeVariable{thisdoctype}{\ttfamily{}\$thisdoctype}, which is
%     the filetype;
% \item \DescribeVariable{thisdocfulltype}{\ttfamily{}\$thisdocfulltype}, which
%     is the name {\ttfamily{}Class}\thinspace,
%     {\ttfamily{}Package}\thinspace, or
%     {\ttfamily{}File}\thinspace;
% \item \DescribeVariable{thisdocid}{\ttfamily{}\$thisdocid}, which is
%     the \texttt{<ID>}\index{ID=\texttt{\char'074 ID\char'076 } (element)}\index{elements:!ID=\texttt{\char'074 ID\char'076 }} of the chapter or appendix, or
%     (if none) the \texttt{<ID>}\index{ID=\texttt{\char'074 ID\char'076 } (element)}\index{elements:!ID=\texttt{\char'074 ID\char'076 }} of the
%     document.\par
% \end{itemize}
% The variables will have no meaning in included
% external files like the licence documentation.\par
%    \begin{macrocode}
  <xsl:template name="makechapapp">
    <!-- output contents of chapter or appendix -->
    <!-- full output file name -->
    <xsl:variable name="thisdocfullname">
      <xsl:choose>
        <xsl:when test="@xlink:href">
          <xsl:value-of
            select="tokenize(@xlink:href,'/')
                    [position()=last()]"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$docname"/>
          <xsl:text>.</xsl:text>
          <xsl:value-of select="$filetype"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="thisdocname"
      select="tokenize($thisdocfullname,'\.')[1]"/>
    <xsl:variable name="thisdoctype"
      select="tokenize($thisdocfullname,'\.')
              [position()=last()]"/>
    <xsl:variable name="thisdocfulltype">
      <xsl:choose>
        <xsl:when test="$thisdoctype='cls'">
          <xsl:text>Class</xsl:text>
        </xsl:when>
        <xsl:when test="$thisdoctype='sty'">
          <xsl:text>Package</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>File</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="thisdocid">
      <xsl:choose>
        <xsl:when test="@xml:id">
          <xsl:value-of select="@xml:id"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="/db:book/@xml:id"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
%    \end{macrocode}
% Documentation is simply passed through with no
% other action.\par
%    \begin{macrocode}
    <!-- choices are: 'doc', 'code', and otherwise -->
    <xsl:choose>
      <!-- EXTRACT ALL THE DOCUMENTATION -->
      <xsl:when test="parent::db:part[@xml:id='doc']">
        <xsl:apply-templates/>
      </xsl:when>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{makechapapp}\quad}Code}
% Extractable \TeX{} files need a double comment
% character at the start of the lines that will be
% included in the file preamble, and need to be tagged
% with their own name and the file metadata. This means
% resetting the line counter now, not when the code
% proper starts.\par
% \par\smallskip\leavevmode
% \CPKrunningecho{makechapapp}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Does this really apply only to ‘main’ chapters?}}\par\smallskip
% In the \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}} part, for
% the main chapter, any preliminary material (preceding
% any \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }}) needs to be output here, because
% the rest is done after auto-initialisation — provided
% it does not include any code at that stage (if it
% does, it’ll get done later).\par
%    \begin{macrocode}
      <xsl:when test="parent::db:part[@xml:id='code']">
        <!-- CODE COUNTER NEEDS TO BE RESET to 0 here -->
        <xsl:if test="$thisdoctype='dtd' or
                      $thisdoctype='xml' or
                      $thisdoctype='xsl' or
                      $thisdoctype='awk' or
                      $thisdoctype='sh' or
                      $thisdoctype='cp' or
                      $thisdoctype='bash'">
          <xsl:text>% \setcounter{CodelineNo}{0}</xsl:text>
          <xsl:text>&#xa;</xsl:text>
        </xsl:if>
        <!-- OUTPUT ANYTHING BEFORE THE FIRST <sect1>
             (usually some kind of preamble or explanation)
             provided there is NO code -->
        <xsl:if test="not(db:sect1[1]/preceding-sibling::*/
                      descendant-or-self::db:programlisting)">
          <xsl:apply-templates 
            select="db:sect1[1]/preceding-sibling::*"/>
          <!-- if there is no sect1, or if there IS code, 
               this does nothing -->
        </xsl:if>
        <!-- if there is a programlisting and an output 
             filename and an ID, start with a comment. -->
        <xsl:if test="ancestor-or-self::db:appendix
                      [descendant::db:programlisting
                      and @xlink:href 
                      and @xml:id]">
          <!--- use sentinel to enclose the comment of
               identity in the right format -->
          <xsl:call-template name="startappcomment">
            <xsl:with-param name="scriptflag">
              <xsl:choose>
                <xsl:when test="@arch='script' and @userlevel='bash'">
                  <xsl:text>wait</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:text>no</xsl:text>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:with-param>
          </xsl:call-template>
        </xsl:if>
%    \end{macrocode}
% The auto-initialisation for classes and packages
% starts with a documentary explanation of what we are
% doing. For extracted appendices, it resets the code
% line counter to zero.\par
%    \begin{macrocode}
        <xsl:if test="$thisdoctype!='dtd' and
                      $thisdoctype!='xml' and
                      $thisdoctype!='xsl' and
                      $thisdoctype!='awk' and
                      $thisdoctype!='sh' and
                      $thisdoctype!='cp' and
                      $thisdoctype!='bash'">
          <xsl:text>% \subsection{Auto-initialisation}</xsl:text>
          <xsl:text>\label{</xsl:text>
          <xsl:value-of select="@xml:id"/>
          <xsl:text>:autoinit}
% This section is added automatically by \textit{ClassPack} 
% as a preamble to all classes and style packages.
% For details see the \textsf{ltxdoc} package documentation.
% \par\smallskip
% &#xa;</xsl:text>
          <!-- reset the counter if this is being done 
               from an <appendix>, because the counter 
               will still show the last line of the main 
               (<chapter>) block of code -->
          <xsl:if test="name()='appendix'">
            <!-- it should probably be reset anyway -->
            <xsl:text>% \setcounter{CodelineNo}{0}</xsl:text>
            <xsl:text>&#xa;</xsl:text>
          </xsl:if>
%    \end{macrocode}
% Because we are auto-generating some code before
% the actual code, starts, we need the code presented as
% a fake in the form of a table, to allow Doc\TeX{} to
% fulfil the documentation requirement to start
% numbering at the right line (we add three to the
% counter).\par
% \par\smallskip\leavevmode
% \CPKrunningecho{makechapapp}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: For ancillaries, should be their own version}}\par\smallskip
% \label{fakeblock}
%    \begin{macrocode}
  <!-- working on ways to make this use lstlisting
       as it doesn't need macrocode, having been tagged 
       <*package> or <*class> earlier -->
          <xsl:text>% \begingroup\color{DarkRed}</xsl:text>
          <xsl:text>\footnotesize&#xa;% \leavevmode</xsl:text>
          <!-- removed leading \enspace as it now interferes
               with the alignment of the first line 2023-05-15.
               Put it back 2023-05-16 -->
          <xsl:text>\enspace{\scriptsize1}\quad</xsl:text>
          <xsl:text>{\ttfamily\textbackslash </xsl:text>
          <xsl:text>NeedsTeXFormat\{</xsl:text>
          <xsl:value-of select="/db:book/@conformance"/>
          <xsl:text>\}[</xsl:text>
          <xsl:value-of
            select="translate(/db:book/@condition,'-','/')"/>
          <xsl:text>]}\\&#xa;% \leavevmode</xsl:text>
          <xsl:text>\enspace{\scriptsize2}\quad</xsl:text>
          <xsl:text>{\ttfamily\textbackslash </xsl:text>
          <xsl:text>Provides</xsl:text>
          <xsl:value-of select="$thisdocfulltype"/>
          <xsl:text>\{</xsl:text>
          <xsl:value-of select="$thisdocname"/>
          <xsl:text>\}[</xsl:text>
          <xsl:value-of select="translate($date,'-','/')"/>
          <xsl:text> v</xsl:text>
          <xsl:value-of select="/db:book/@version"/>
          <xsl:text>.</xsl:text>
          <xsl:value-of select="/db:book/@revision"/>
          <xsl:text>}\\&#xa;% \leavevmode</xsl:text>
          <xsl:text>\enspace{\scriptsize3}\qquad</xsl:text>
          <xsl:text>{\ttfamily </xsl:text>
          <xsl:choose>
            <xsl:when
              test="//db:part[@xml:id='code']/db:title">
              <xsl:value-of
                select="normalize-space(replace(
                        //db:part[@xml:id='code']/db:title,
                        '\\LaTeX\{\}','LaTeX'))"/>
            </xsl:when>
            <xsl:when test="name()='appendix'">
              <xsl:value-of
                select="normalize-space(replace(db:title,
                        '\\LaTeX\{\}','LaTeX'))"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of
                select="normalize-space(/db:book/db:info
                        /db:title)"/>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:text>]}\\\endgroup
% \setcounter{CodelineNo}{3}&#xa;</xsl:text>
%    \end{macrocode}
% The actual startup code can now be output in
% normal Doc\TeX{} form. This ends the initialisation
% phase.\par
%    \begin{macrocode}
          <!-- APPENDICES ONLY -->
          <xsl:if
            test="ancestor-or-self::db:appendix and (
                  ancestor-or-self::db:appendix/@userlevel='tex' or
                  ancestor-or-self::db:appendix/@userlevel='sty' or
                  ancestor-or-self::db:appendix/@userlevel='cls'
                        )">
            <xsl:text>% \iffalse&#xa;%&lt;</xsl:text>
            <xsl:value-of select="$thisdocid"/>
            <xsl:text>>\NeedsTeXFormat{LaTeX2e}</xsl:text>
            <xsl:text>[2015/01/01]% </xsl:text>
            <xsl:value-of select="name()"/>
            <xsl:text>/</xsl:text>
            <xsl:value-of select="@xml:id"/>
            <xsl:text>&#xa;%&lt;</xsl:text>
            <xsl:value-of select="$thisdocid"/>
            <xsl:text>>\Provides</xsl:text>
            <xsl:value-of select="$thisdocfulltype"/>
            <xsl:text>{</xsl:text>
            <xsl:value-of select="$thisdocname"/>
            <xsl:text>}[</xsl:text>
            <xsl:value-of
              select="translate($date,'-','/')"/>
            <xsl:text> v</xsl:text>
            <xsl:value-of select="/db:book/@version"/>
            <xsl:text>.</xsl:text>
            <xsl:value-of select="/db:book/@revision"/>
            <xsl:text>&#xa;</xsl:text>
            <xsl:text>%&lt;</xsl:text>
            <xsl:value-of select="$thisdocid"/>
            <xsl:text>>  </xsl:text>
            <xsl:value-of
              select="normalize-space(replace(
                      db:title,'\\LaTeX\{\}','LaTeX'))"/>
            <xsl:text>]&#xa;% \fi&#xa;</xsl:text>
          </xsl:if>
        </xsl:if>
        <!-- end of selective chapcpk -->
%    \end{macrocode}
% Implement a hard-wired class-specific preload: the
% \textsf{fix-cm} package, without which all
% font sizes are restricted to the step-sizes of the
% original \LaTeX{}.\par
% \par\smallskip\leavevmode
% \CPKrunningecho{makechapapp}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Long-term, move these to a mechanism similar to prepost}}\par\smallskip
%    \begin{macrocode}
        <!-- CLASSES ONLY -->
        <xsl:if test="$doctype='class'
                      and
                      not(name()='appendix')">
          <xsl:text>% \begin{CPKpackage}{fix-cm}
% Preloaded functions to override the default \LaTeX\
% step-size font sizes (which can still be used,
% but are no longer restrictions).\par
%    </xsl:text>
          <xsl:text>\begin</xsl:text>
          <xsl:text>{macrocode}
\RequirePackage{fix-cm}
%    </xsl:text>
          <xsl:text>\end</xsl:text>
          <xsl:text>{macrocode}
% \end{CPKpackage}&#xa;</xsl:text>
        </xsl:if>
%    \end{macrocode}
% Document first how we handle the autogeneration of
% {\ttfamily{}\textbackslash{}PassOptionsToPackage} commands
% unless overridden manually. We should here be in the
% first chapter of the \texttt{"code"}\index{code=\texttt{"code"} (attribute value)}\index{attribute values:!code=\texttt{"code"}}
% part.\par
% \par\smallskip\leavevmode
% \CPKrunningecho{makechapapp}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: This should really be generated, not embedded verbatim}}\par\smallskip
% The only candidate is the
% \textsf{xcolor} package for which
% \emph{ClassPack} uses the
% \textbf{\texttt{svgnames}} option. This needs
% preloading to prevent a clash with other packages (eg
% \textsf{hyperref}). There is an exclusion
% for packages which use themselves in their own
% documentation (eg for examples). The action is also
% echoed to the terminal when the package is
% used.\par
%    \begin{macrocode}
        <xsl:choose>
          <xsl:when test="@condition='noauto'">
            <xsl:text>% \par Auto-generation of options to
% pass to packages is suppressed in this file.&#xa;</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <!-- special handling for [svgnames]{xcolor} -->
            <xsl:if
              test="//db:constraintdef[@xml:id='clspackages']
                    //db:seg[.='xcolor']
                    [contains(@role,'svgnames')
                     or
                     not(@role)]
                    [not(@condition='only')]">
              <xsl:text>% \begin{CPKoption}{svgnames}
% Pass the \textbf{\texttt{svgnames}} option to the
% \textsf{xcolor} package if that gets loaded later.
% This avoids a conflict with any other packages in the class
% (eg \textsf{hyperref}) which use their own default
% when they load \textsf{xcolor}.\par&#xa;</xsl:text>
<!-- EXCEPTION HANDLER WHEN PACKAGE ITSELF INCLUDED removed 
              <xsl:if test="/db:book/@xlink:role
                            and
                            $filetype='sty'">
                <xsl:text>% However, we have to make
% an exception in this case because the package gets
% used in its own documentation, which would cause a
% duplicate \verb+\PassOptionsToPackage+, so we code
% around it by testing the current package name against
% the job name of the calling \verb+.dtx+ file~— if 
% they are the same, then this is the case in point, 
% and the \verb+\PassOptionsToPackage+ command is 
% \emph{not} executed; otherwise it it OK to include it.\par
%    </xsl:text>
                <xsl:text>\begin</xsl:text>
                <xsl:text>{macrocode}
\def\CPKthispackage{</xsl:text>
                <xsl:value-of select="$docname"/>
                <xsl:text>}
\edef\CPKthispackage{\meaning\CPKthispackage}
\edef\CPKthisjob{\jobname}
\edef\CPKthisjob{\meaning\CPKthisjob}
\ifx\CPKthispackage\CPKthisjob
%% this is the documentation: omit PassOptionsToPackage
  \PackageWarning{classpack}{Option svgnames has not 
  been passed ^^Jto package xcolor (because this is 
  the package documentation)}
\else
%% this is a user job: include PassOptionsToPackage
  \PackageWarning{classpack}{Option svgnames is being 
  passed ^^Jto package xcolor (to avoid later clashes)}
%    </xsl:text>
                <xsl:text>\end</xsl:text>
                <xsl:text>{macrocode}&#xa;</xsl:text>
              </xsl:if>
-->
%    \end{macrocode}
% Now do the actual preloading. The nested embedded
% conditional switch technique is due to user zeroth at
% \href{https://tex.stackexchange.com/questions/44499/how-to-test-jobname-compilation-option-within-latex-file/54895}{\nolinkurl{https://tex.stackexchange.com/questions/44499/how-to-test-jobname-compilation-option-within-latex-file/54895}}\thinspace. 
% Note that the earlier automation of the
% \textbf{\texttt{hyphens}} option to the
% \textsf{url} package must now be a
% {\ttfamily{}\textbackslash{}documentclass} option.\par
%    \begin{macrocode}
              <xsl:text>%    </xsl:text>
              <xsl:text>\begin</xsl:text>
              <xsl:text>{macrocode}
  \PassOptionsToPackage{svgnames}{xcolor}
%    </xsl:text>
              <xsl:text>\end</xsl:text>
              <xsl:text>{macrocode}&#xa;</xsl:text>
              <!--
              <xsl:if 
                test="/db:book/@xlink:role 
                      and 
                      $filetype='sty'">
                <xsl:text>%    </xsl:text>
                <xsl:text>\begin</xsl:text>
                <xsl:text>{macrocode}
\fi
%    </xsl:text>
                <xsl:text>\end</xsl:text>
                <xsl:text>{macrocode}&#xa;</xsl:text>
              </xsl:if>
-->
              <xsl:text>% \end{CPKoption}&#xa;</xsl:text>
            </xsl:if>
          </xsl:otherwise>
        </xsl:choose>
%    \end{macrocode}
% Any preliminary non-\texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }} material was
% already output before the auto-initialisation, so now
% do the rest of the chapter/appendix. After the call to
% \DescribeTemplate{checkpackages}{\ttfamily{}checkpackages}, if the
% current document is a shell script, make sure it
% terminates here, because DoC\TeX{} will output an
% {\ttfamily{}\textbackslash{}endinput} and two \LaTeX{} comment
% lines which will confuse a script. This ends
% processing for a code chapter.\par
%    \begin{macrocode}
        <xsl:choose>
          <!-- we did anything prior to the sect1 earlier
               so now do the sect1 and everything following -->
          <xsl:when test="db:sect1">
            <xsl:apply-templates 
              select="db:sect1[1] | 
                      db:sect1[1]/following-sibling::*"/>
          </xsl:when>
          <!-- if there is no sect1, nothing will have been
               output earlier, so do it all now -->
          <xsl:otherwise>
            <xsl:apply-templates/>
          </xsl:otherwise>
        </xsl:choose>
        <!-- Unclear if this is still necessary -->
        <xsl:call-template name="checkpackages">
          <xsl:with-param name="pos" select="'after'"/>
          <xsl:with-param name="loc" select="."/>
        </xsl:call-template>
        <!-- scripts only -->
        <xsl:if test="$doctype='script'">
          <xsl:text>% [Exit added by \textit{ClassPack} 
% to shield shell from \textsf{Doc\TeX}.]\par
% \iffalse&#xa;##
## Exit added by ClassPack to shield shell from DocTeX.
% \fi&#xa;%    </xsl:text>
          <xsl:text>\begin</xsl:text>
          <xsl:text>{macrocode}&#xa;exit 0</xsl:text>
          <xsl:text>&#xa;%    </xsl:text>
          <xsl:text>\end</xsl:text>
          <xsl:text>{macrocode}&#xa;</xsl:text>
        </xsl:if>
      </xsl:when><!-- end of dealing with part/code -->
%    \end{macrocode}
% Other circumstances probably include the licence
% document, passed through untouched.\par
%    \begin{macrocode}
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{checkpackages}\label{template-db2dtx-checkpackages}
% This template checks whether the current document
% location is the correct place for deferred packages to
% be included. The {\ttfamily{}\$pos} parameter is the
% \texttt{"before"}\index{before=\texttt{"before"} (attribute value)}\index{attribute values:!before=\texttt{"before"}} or \texttt{"after"}\index{after=\texttt{"after"} (attribute value)}\index{attribute values:!after=\texttt{"after"}} \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} value passed from the
% call; the {\ttfamily{}\$loc}
% parameter is the location in the document (ID) where
% this call was made from.\par
% If there is a matching class or style package
% \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} whose \texttt{<IDREF>}\index{IDREF=\texttt{\char'074 IDREF\char'076 } (element)}\index{elements:!IDREF=\texttt{\char'074 IDREF\char'076 }}
% matches this section’s \texttt{<ID>}\index{ID=\texttt{\char'074 ID\char'076 } (element)}\index{elements:!ID=\texttt{\char'074 ID\char'076 }} and whose \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute matches
% {\ttfamily{}\$pos} (or if
% there is no \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} at all),
% do this template.\par
%    \begin{macrocode}
  <xsl:template name="checkpackages">
    <xsl:param name="pos"/><!-- before or after -->
    <xsl:param name="loc"/><!-- name of calling element type -->
    <xsl:variable name="thisgi"
      select="$thisdoc/db:book/db:info/db:cover/db:constraintdef
              [@xml:id=concat($filetype,'packages')]/@linkend"/>
    <xsl:variable name="thisrole"
      select="$thisdoc/db:book/db:info/db:cover/db:constraintdef
              [@xml:id=concat($filetype,'packages')]/@role"/>
    <!--
    <xsl:text>%% Checking in </xsl:text>
    <xsl:value-of select="name()"/>
    <xsl:text>/</xsl:text>
    <xsl:value-of select="@xml:id"/>
    <xsl:text> for package location </xsl:text>
    <xsl:value-of select="$pos"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="name()"/>
    <xsl:text>/</xsl:text>
    <xsl:value-of select="$thisgi"/>
    <xsl:text>&#xa;</xsl:text>
    -->
    <xsl:if 
      test="$thisgi
            and 
            current()/@xml:id 
            and 
            $thisgi=current()/@xml:id
            and
            ($pos=$thisrole 
             or 
             not($thisrole))">
      <xsl:variable name="gi" select="local-name()"/>
      <xsl:text>%\iffalse
%%&#xa;</xsl:text>
      <!--
      <xsl:text>%% [in checkpackages with pos=</xsl:text>
      <xsl:value-of select="$pos"/>
      <xsl:text>, loc=</xsl:text>
      <xsl:value-of select="substring($loc,1,32)"/>
      <xsl:text>, thisgi=</xsl:text>
      <xsl:value-of select="$thisgi"/>
      <xsl:text>, thisrole=</xsl:text>
      <xsl:value-of select="$thisrole"/>
      <xsl:text>&#xa;</xsl:text>
      -->
      <xsl:text>%% Packages required for the </xsl:text>
      <xsl:value-of select="$doctype"/>
      <xsl:text>
%% 
% \fi
% \</xsl:text>
      <xsl:choose>
        <!-- $gi is the element type nominated by the @linkend
             attribute in the stypackage or clspackages
             constraintdef where the class/package packages
             are declared -->
        <xsl:when test="$gi='chapter' or $gi='appendix'">
          <xsl:text>clearpage&#xa;% \section</xsl:text>
        </xsl:when>
        <xsl:when test="$gi='sect1'">
          <xsl:text>subsection</xsl:text>
        </xsl:when>
        <xsl:when test="$gi='sect2'">
          <xsl:text>subsubsection</xsl:text>
        </xsl:when>
        <xsl:when test="$gi='sect3'">
          <xsl:text>paragraph</xsl:text>
        </xsl:when>
        <xsl:when test="$gi='sect4'">
          <xsl:text>subparagraph</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:message>
            <xsl:text>WARNING: </xsl:text>
            <xsl:value-of select="$gi"/>
            <xsl:text> is an unidentifiable </xsl:text>
            <xsl:text>place to declare packages</xsl:text>
          </xsl:message>
          <xsl:text>\PackageWarning{classpack}{Unidentifiable place `</xsl:text>
          <xsl:value-of select="$thisgi"/>
          <xsl:text>' to declare packages}</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>{</xsl:text>
      <xsl:choose>
        <xsl:when 
          test="/db:book/db:info/db:cover
                /db:constraintdef
                 [@linkend=current()/@xml:id]
                /db:segmentedlist/db:segtitle">
          <xsl:apply-templates 
            select="/db:book/db:info/db:cover
                    /db:constraintdef
                     [@linkend=current()/@xml:id]
                    /db:segmentedlist/db:segtitle/node()"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>Packages loaded</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>}\label{</xsl:text>
      <xsl:value-of 
        select="/db:book/db:info/db:cover
                /db:constraintdef
                 [@linkend=current()/@xml:id]
                /@xml:id"/>
      <xsl:text>}&#xa;</xsl:text>
      <!-- INCLUDE COMPULSORY PACKAGE[s] for cls/sty -->
      <xsl:if test="($filetype='cls' or $filetype='sty')
                    and
                    count($prepost/db:procedure[@xml:id='prepackage']
                      /db:step[contains(@condition,$filetype)]
                      [db:constructorsynopsis/@condition='']) > 0">
        <xsl:text>% Packages required for operation:&#xa;</xsl:text>
        <xsl:for-each
          select="$prepost/db:procedure[@xml:id='prepackage']
                  /db:step[contains(@condition,$filetype)]
                  [db:constructorsynopsis/@condition='']">
          <xsl:text>% \begin{CPKpackage}{</xsl:text>
          <xsl:value-of select="@remap"/>
          <xsl:text>}&#xa;</xsl:text>
          <xsl:apply-templates select="db:para"/>
          <xsl:text>% \iffalse&#xa;%% </xsl:text>
          <xsl:value-of select="normalize-space(db:para[1])"/>
          <xsl:text>&#xa;% \fi&#xa;</xsl:text>
          <xsl:text>%    \begin{macrocode}&#xa;</xsl:text>
          <xsl:text>\RequirePackage{</xsl:text>
          <xsl:value-of select="@remap"/>
          <xsl:text>}%&#xa;</xsl:text>
          <xsl:if
            test="db:constraintdef[db:cmdsynopsis[db:command]]">
            <xsl:for-each
              select="db:constraintdef/db:cmdsynopsis/db:command">
              <xsl:value-of select="."/>
              <xsl:text>&#xa;</xsl:text>
            </xsl:for-each>
          </xsl:if>
          <xsl:text>%    \end</xsl:text>
          <xsl:text>{macrocode}&#xa;</xsl:text>
          <!-- and add on any code from the postpackage section -->
          <xsl:for-each
            select="$prepost/db:procedure[@xml:id='postpackage']
                      /db:step[contains(@condition,$filetype)]
                      [@remap=current()/@remap]">
            <xsl:text>% </xsl:text>
            <xsl:value-of select="normalize-space(db:para[1])"/>
            <xsl:text>&#xa;</xsl:text>
            <xsl:text>%    \begin{macrocode}&#xa;</xsl:text>
            <xsl:if
              test="db:constraintdef[db:cmdsynopsis[db:command]]">
              <xsl:for-each
                select="db:constraintdef/db:cmdsynopsis/db:command">
                <xsl:value-of select="."/>
                <xsl:text>&#xa;</xsl:text>
              </xsl:for-each>
            </xsl:if>
            <xsl:text>%    \end</xsl:text>
            <xsl:text>{macrocode}&#xa;</xsl:text>
          </xsl:for-each>
          <xsl:text>% \end{CPKpackage}&#xa;</xsl:text>
        </xsl:for-each>
      </xsl:if><!-- end of required packages for cls/sty -->
      <!-- now each requested package -->
      <xsl:for-each 
        select="/db:book/db:info/db:cover
                /db:constraintdef
                 [@linkend=current()/@xml:id]
                /db:segmentedlist/db:seglistitem
                 [db:seg!='']">
        <xsl:call-template name="packages">
          <!-- context is seglistitem from cls/sty packages -->
          <xsl:with-param name="pkg" select="."/>
          <xsl:with-param name="dest" select="$filetype"/>
          <xsl:with-param name="cmdblocks"
            select="$prepost/db:procedure[@xml:id='postpackage']/
                    db:step[@remap=current()/db:seg]/
                    db:constraintdef/db:cmdsynopsis/
                    db:command/@conformance"/> 
          <xsl:with-param name="mode" select="'deferred'"/>
          <xsl:with-param name="loc" select="$loc"/>
        </xsl:call-template>
      </xsl:for-each>
      <xsl:text>% &#xa;</xsl:text>
      <xsl:if 
        test="/db:book/db:info/db:cover
              /db:constraintdef
               [@linkend=current()/@xml:id]
              /@xml:id!='stypackages' 
              and 
              /db:book/db:info/db:cover
              /db:constraintdef
               [@linkend=current()/@xml:id]
              /@xml:id!='clspackages'">
        <xsl:message>
          <xsl:text>WARNING: packages listed in "</xsl:text>
          <xsl:value-of select="$gi"/>
          <xsl:text>" that doesn't belong to this </xsl:text>
          <xsl:value-of select="$doctype"/>
          <xsl:text> (xml:id="</xsl:text>
          <xsl:value-of select="@xml:id"/>
          <xsl:text>").</xsl:text>
        </xsl:message>
        <xsl:text>% WARNING: packages listed in a \verb`</xsl:text>
        <xsl:value-of select="$gi"/>
        <xsl:text>` element of the master document </xsl:text>
        <xsl:text>that was not flagged as belonging to this </xsl:text>
        <xsl:value-of select="$doctype"/>
        <xsl:text> (\verb`xml:id="</xsl:text>
        <xsl:value-of select="@xml:id"/>
        <xsl:text>"`).&#xa;</xsl:text>
      </xsl:if>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[External files]{External files :}
% \begin{CPKtemplate}{readme}\label{makereadme}
% This template creates the
% {\ttfamily{}README.md} file from the
% boilerplate in {\ttfamily{}readme.xml}\thinspace. This
% uses the {\ttfamily{}readme} mode and the
% special indirections described in \vref{makereadme} for inserting values from the
% user’s \emph{ClassPack} document
% into the {\ttfamily{}README.md} file.\par
%    \begin{macrocode}
  <xsl:template name="readme">
    <xsl:variable name="file">
      <xsl:text>README.md</xsl:text>
    </xsl:variable>
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
        <xsl:text>@</xsl:text>
        <xsl:value-of select="@xml:id"/>
        <xsl:text> (README.md)</xsl:text>
      </xsl:message>
    </xsl:if>
    <xsl:result-document format="textFormat" 
      href="{$file}">
      <xsl:text>&#xa;[//]: # (the </xsl:text>
      <xsl:value-of select="$docname"/>
      <xsl:text> LaTeX </xsl:text>
      <xsl:value-of select="$doctype"/>
      <xsl:text>)&#xa;&#xa;# The </xsl:text>
      <xsl:value-of select="$docname"/>
      <xsl:text> LaTeX2ε package&#xa;&#xa;This is the </xsl:text>
      <xsl:value-of select="$file"/>
      <xsl:text> file for the </xsl:text>
      <xsl:value-of select="$docname"/>
      <xsl:text> LaTeX </xsl:text>
      <xsl:value-of select="$doctype"/>
      <xsl:text> v</xsl:text>
      <xsl:value-of select="$latestrevhist"/>
      <xsl:text> (</xsl:text>
      <xsl:value-of select="$date"/>
      <xsl:text>)&#xa;generated by ClassPack v.</xsl:text>
      <xsl:value-of select="$thisversion"/>
      <xsl:text> (</xsl:text>
      <xsl:value-of select="$thisverdate"/>
      <xsl:text>) on </xsl:text>
      <xsl:value-of 
        select="format-dateTime(current-dateTime(),
                '[D] [MNn] [Y] at [H]:[m]:[s] ')"/>
      <xsl:text>&#xa;</xsl:text>
      <xsl:apply-templates select="$readme/*" 
        mode="readme"/>
      <xsl:if test="$readme//db:footnote">
        <xsl:text>---&#xa;#### Footnotes&#xa;</xsl:text>
        <xsl:for-each select="$readme//db:footnote">
          <xsl:number format="1." count="db:footnote"
            level="any"/>
          <xsl:apply-templates select="node()"
            mode="inline"/>
          <xsl:text>&#xa;</xsl:text>
        </xsl:for-each>
      </xsl:if>
    </xsl:result-document>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{manifest}\label{makemanifest}
% In a similar manner to the
% {\ttfamily{}README.md}\thinspace, this template creates
% the {\ttfamily{}MANIFEST} file, but has no
% formatting requirements, only listed content. Three
% files are always present:
% {\ttfamily{}README.md}\thinspace,
% {\ttfamily{}MANIFEST}\thinspace, and
% {\ttfamily{}VERSION}\thinspace. The
% \textsc{tds} file, which was previously
% embedded in the non-\textsc{tds}
% distribution, is no longer included. The remaining
% files are included as needed:
% {\ttfamily{}.dtx}\thinspace, {\ttfamily{}.ins}\thinspace,
% {\ttfamily{}.pdf}\thinspace, any ancillary files
% generated, and any additional files listed manually by
% the author; but \emph{not} the class or
% style file itself: that is generated by the user
% extracting it from the {\ttfamily{}.dtx}
% file.\par
% \par\smallskip\leavevmode
% \CPKrunningecho{manifest}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Add generated secondary files, and automate images from the doc}}\par\smallskip
%    \begin{macrocode}
  <xsl:template name="manifest">
    <xsl:variable name="file">
      <xsl:text>MANIFEST</xsl:text>
    </xsl:variable>
    <xsl:result-document format="textFormat"
      href="{$file}">
      <!-- THESE THREE ALWAYS -->
      <xsl:text>README.md
MANIFEST
VERSION&#xa;</xsl:text>
      <!-- always the PDF, DTX, and INS -->
      <xsl:value-of select="$docname"/>
      <xsl:text>.dtx&#xa;</xsl:text>
      <xsl:value-of select="$docname"/>
      <xsl:text>.ins&#xa;</xsl:text>
      <xsl:value-of select="$docname"/>
      <xsl:text>.pdf&#xa;</xsl:text>
      <!-- the style or class file, obv -->
      <xsl:value-of select="$docname"/>
      <xsl:text>.</xsl:text>
      <xsl:value-of select="$filetype"/>
      <xsl:text>&#xa;</xsl:text>
      <!-- annotated appendix files and standalone
           unannotated files (the Makefile
           omits scripts from packaging )-->
      <xsl:for-each
        select="/db:book/db:part[@xml:id='code']
                /db:appendix[@xml:id
                and @xlink:href
                and descendant::db:programlisting
                and not(matches(@xlink:href,'\.cls$'))
                and not(matches(@xlink:href,'\.sty$'))]
                |
                /db:book/db:part[@xml:id='files']
                /db:chapter[@xml:id and @xlink:href
                and db:programlisting]">
        <xsl:value-of select="@xlink:href"/>
        <xsl:text>&#xa;</xsl:text>
      </xsl:for-each>
      <!-- IMAGE FOR DOC, should be in cover/artwork -->
      <xsl:if
        test="/db:book/db:info/db:abstract/@xlink:href
              and
              not(/db:book/db:info/db:abstract/@xlink:show='none')">
        <xsl:value-of
          select="/db:book/db:info/db:abstract/@xlink:href"/>
        <xsl:text>&#xa;</xsl:text>
      </xsl:if>
      <!-- ANY SPECIAL REQUESTS -->
      <xsl:for-each
        select="/db:book/db:info/db:cover
                /db:constraintdef[@xml:id='manifest']
                /db:simplelist/db:member[.!='']">
        <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>&#xa;</xsl:text>
      </xsl:for-each>
    </xsl:result-document>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Utilities]{Utilities :}\label{commentchars}
% \begin{CPKtemplate}{makecommentchar}\label{template-db2dtx-makecommentchar}
% Set the comment character to be the one  whose
% name matches the \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}}
% attribute of the closest chapter, appendix, or book
% (root) ancestor and whose \texttt{@filetype}\index{filetype=\texttt{\char'100 filetype} (attribute)}\index{attributes:!filetype=\texttt{\char'100 filetype}} attribute matches
% the \texttt{@userlevel}\index{userlevel=\texttt{\char'100 userlevel} (attribute)}\index{attributes:!userlevel=\texttt{\char'100 userlevel}} attribute
% of the same ancestor, all using the \DescribeVariable{commentchars}{\ttfamily{}\$commentchars}
% variable.\par
%    \begin{macrocode}
  <xsl:template name="makecommentchar">
    <xsl:variable name="closest"
      select="(ancestor::db:book |
               ancestor::db:chapter |
               ancestor::db:appendix)[1]"/>
    <xsl:value-of
      select="$commentchars/*
              [name()=$closest/@arch]
              [@filetype=$closest/@userlevel]"/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{makesentinel}\label{template-db2dtx-makesentinel}
% This does the same as {\ttfamily{}makecommentchar} but
% excludes the terminator for non-\textsc{xml}
% file types.\par
%    \begin{macrocode}
  <xsl:template name="makesentinel">
    <xsl:variable name="closest"
      select="(ancestor::db:book |
               ancestor::db:chapter |
               ancestor::db:appendix)[1]"/>
    <xsl:variable name="filetype"
      select="$commentchars/*
              [name()=$closest/@arch]
              [@filetype=$closest/@userlevel]"/>
    <xsl:value-of select="$filetype"/>
    <!-- repeat for non-XML file types -->
    <xsl:if test="$filetype[not(@term)]">
      <xsl:value-of select="$filetype"/>
    </xsl:if>
    <xsl:text> </xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{maketermsentinel}\label{template-db2dtx-maketermsentinel}
% This template creates the terminator for {\ttfamily{}makesentinel}.\par
%    \begin{macrocode}
  <xsl:template name="maketermsentinel">
    <xsl:variable name="closest"
      select="(ancestor::db:book |
               ancestor::db:chapter |
               ancestor::db:appendix)[1]"/>
    <xsl:variable name="filetype"
      select="$commentchars/*
              [name()=$closest/@arch]
              [@filetype=$closest/@userlevel]"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="$filetype/@term"/>
    <!-- repeat for non-XML file types -->
    <xsl:if test="$filetype[not(@term)]">
      <xsl:value-of select="$filetype/@term"/>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{makefence}\label{template-db2dtx-makefence}
% Make a fence (line of repeated characters) from
% the appropriate \emph{local} \DescribeVariable{sentinel}{\ttfamily{}\$sentinel}
% character and its terminator by repeating it 66
% times.\par
%    \begin{macrocode}
  <xsl:template name="makefence">
    <xsl:variable name="sentinel">
      <xsl:call-template name="makesentinel"/>      
    </xsl:variable>
    <xsl:variable name="termsentinel">
      <xsl:call-template name="maketermsentinel"/>      
    </xsl:variable>
    <xsl:value-of select="$sentinel"/>
    <xsl:for-each select="for $i in 1 to 66 return $i">
      <xsl:text>*</xsl:text>
    </xsl:for-each>
    <xsl:value-of select="$termsentinel"/>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{starttag}\label{template-db2dtx-starttag}
% Output a Doc\TeX{} start-tag which delimits
% extractable text, either using the ID of the document,
% or some other value passed as the parameter {\ttfamily{}\$identity}.\par
%    \begin{macrocode}
  <xsl:template name="start-tag">
    <xsl:param name="identity">
      <xsl:value-of select="@xml:id"/>
    </xsl:param>
    <xsl:text>% \iffalse&#xa;%&lt;*</xsl:text>
    <xsl:value-of select="$identity"/>
    <xsl:text>>&#xa;% \fi&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{endtag}\label{template-db2dtx-endtag}
% Output a Doc\TeX{} end-tag on the same basis as the
% start-tag.\par
%    \begin{macrocode}
  <xsl:template name="end-tag">
    <xsl:param name="identity">
      <xsl:value-of select="@xml:id"/>
    </xsl:param>
    <xsl:text>% \iffalse&#xa;%&lt;/</xsl:text>
    <xsl:value-of select="$identity"/>
    <xsl:text>>&#xa;% \fi&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{silcommentchar}\label{template-db2dtx-silcommentchar}
% This template and its related terminator and
% sentinel are used where the standard comment
% character, terminator, and sentinel are already in
% use, and an ancillary document is being output (eg in
% an appendix) which requires a different syntax.\par
%    \begin{macrocode}
  <xsl:function name="sil:commentchar">
    <xsl:param name="context"/>
    <xsl:variable name="closest"
      select="($context/ancestor-or-self::db:book[1] |
               $context/ancestor-or-self::db:chapter[1] |
               $context/ancestor-or-self::db:appendix[1])[last()]"/>
    <xsl:variable name="thisdoctype"
      select="tokenize($closest/@xlink:href,'\.')
                  [last()]"/>
    <xsl:value-of
      select="($commentchars/*[name()=$closest/@arch][1] |
               $commentchars/*[@filetype=$closest/@userlevel][1] |
               $commentchars/*[@filetype=$thisdoctype][1])[last()]"/>
  </xsl:function>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{siltermcommentchar}\label{template-db2dtx-siltermcommentchar}
% As above\par
%    \begin{macrocode}
  <xsl:function name="sil:termcommentchar">
    <xsl:param name="context"/>
    <!-- no parameters: evaluates using current context -->
    <xsl:variable name="closest"
      select="$context/ancestor-or-self::*
              [name()='book'
               or
               name()='chapter'
               or
               name()='appendix'][1]"/>
    <xsl:variable name="filetype"
      select="$commentchars/*
               [name()=$closest/@arch]
               [@filetype=$closest/@userlevel][1]"/>
    <xsl:value-of select="$filetype/@term"/>
  </xsl:function>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{silsentinel}\label{template-db2dtx-silsentinel}
% As above\par
%    \begin{macrocode}
  <xsl:function name="sil:sentinel">
    <xsl:param name="context"/>
    <xsl:value-of select="sil:commentchar($context)"/>
    <xsl:if test="sil:commentchar($context)!='&lt;!--'">
      <xsl:value-of select="sil:commentchar($context)"/>
    </xsl:if>
  </xsl:function>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{avoidverb}\label{avoidverb}
% Try to output monospace filenames,
% \textsc{uri}s, etc while avoiding the use of
% {\ttfamily{}\textbackslash{}verb}. Start by picking a delimiter
% to use if we really do have to use
% {\ttfamily{}\textbackslash{}verb}. In each case, a prefix and
% suffix may be added depending on the language the
% token belongs to.\par
%    \begin{macrocode}
  <xsl:template name="avoidverb">
    <!-- delimiter for normal textual strings, based on absence of
         the character in the argument: pref=|, or=+, else=` -->
    <xsl:variable name="delim">
      <xsl:choose>
        <xsl:when test="not(contains(.,'|'))">
          <xsl:text>|</xsl:text>
        </xsl:when>
        <xsl:when test="not(contains(.,'+'))">
          <xsl:text>+</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>`</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{avoidverb}\quad}Verbatim with \TeX{} special
% characters}
% If the content contains any of \TeX{}’s special
% characters or the visible space\par
% ( \verb+\ $ ^ { } < | > ␣+ )\par
% that are also invalid or uncomfortable in
% \textsc{uri}s, we will have to use
% {\ttfamily{}\textbackslash{}verb}.\par
%    \begin{macrocode}
  <!-- however, if the argument contains $^{}<|>␣ -->
    <xsl:choose>
      <xsl:when test="matches(.,'.*[\\\$\^{}&lt;\|&gt;␣].*')
                      and not(ancestor::db:title)
                      and not(ancestor::db:footnote)
                      and not(ancestor::db:term)">
%    \end{macrocode}
% If the content contains a \texttt{<replaceable>}\index{replaceable=\texttt{\char'074 replaceable\char'076 } (element)}\index{elements:!replaceable=\texttt{\char'074 replaceable\char'076 }}
% element or has the specific exclusion condition \texttt{"nolit"}\index{nolit=\texttt{"nolit"} (attribute value)}\index{attribute values:!nolit=\texttt{"nolit"}}, it will need to be
% split into abutting fragments by using
% \texttt{<xsl:apply-templates>}\index{xsl:apply-templates=\texttt{\char'074 xsl:apply-templates\char'076 } (element)}\index{elements:!xsl:apply-templates=\texttt{\char'074 xsl:apply-templates\char'076 }}.\par
%    \begin{macrocode}
        <xsl:choose>
          <!-- use \verb with the delimiter for 
               replaceable or non-literal strings -->
          <xsl:when 
            test="db:replaceable or @condition='nolit'">
            <xsl:text>\verb</xsl:text>
            <xsl:value-of select="$delim"/>
            <!-- PREFIXING -->
            <xsl:if test="(name()='command' 
                           or 
                           @role='length')
                          and
                          (@language='TeX' 
                           or 
                           @language='LaTeXe' 
                           or 
                           @language='LaTeX' 
                           or 
                           not(@language))">
              <xsl:text>\</xsl:text>
            </xsl:if>
            <xsl:if test="@language='XSLT' 
                          and
                          (name()='varname' and
                            (@role='variable' or 
                             @role='parameter'))
                          or 
                          name()='parameter'">
              <xsl:text>$</xsl:text>
            </xsl:if>
            <xsl:if test="name()='varname' 
                          and
                          @language='Makefile' 
                          and
                          @role='variable'">
              <xsl:text>$(</xsl:text>
            </xsl:if>
            <xsl:if test="name()='varname' 
                          and
                          @language='BiBTeX' 
                          and
                          @role='entrytype'">
              <xsl:text>@</xsl:text>
            </xsl:if>
            <xsl:apply-templates/>
            <!-- SUFFIXING -->
            <xsl:if test="@xlink:type">
              <xsl:text>.</xsl:text>
              <xsl:value-of select="@xlink:type"/>
            </xsl:if>
            <xsl:if test="name()='varname' 
                          and
                          @language='Makefile' 
                          and
                          @role='variable'">
              <xsl:text>)</xsl:text>
            </xsl:if>
            <xsl:value-of select="$delim"/>
          </xsl:when>
%    \end{macrocode}
% Otherwise just the plain {\ttfamily{}\textbackslash{}verb}
% is used with \texttt{normalize-space} of the
% content.\par
%    \begin{macrocode}
          <!-- otherwise the same, but wtf -->
          <xsl:otherwise>
            <xsl:text>\verb</xsl:text>
            <xsl:value-of select="$delim"/>
            <xsl:if test="(name()='command'
                           or
                           @role='length')
                          and
                          (@language='TeX' 
                           or 
                           @language='LaTeXe'
                           or 
                           @language='LaTeX' 
                           or 
                           not(@language))">
              <xsl:text>\</xsl:text>
            </xsl:if>
            <xsl:if test="@language='XSLT' 
                          and
                          (name()='varname' and
                            (@role='variable' or 
                             @role='parameter'))
                          or 
                          name()='parameter'">
              <xsl:text>$</xsl:text>
            </xsl:if>
            <xsl:if test="name()='varname' 
                          and
                          @language='Makefile' 
                          and
                          @role='variable'">
              <xsl:text>$(</xsl:text>
            </xsl:if>
            <xsl:if test="name()='varname' 
                          and
                          @language='BiBTeX' 
                          and
                          @role='entrytype'">
              <xsl:text>@</xsl:text>
            </xsl:if>
            <xsl:value-of select="normalize-space(.)"/>
            <xsl:if test="@xlink:type">
              <xsl:text>.</xsl:text>
              <xsl:value-of select="@xlink:type"/>
            </xsl:if>
            <xsl:if test="name()='varname' 
                          and
                          @language='Makefile' 
                          and
                          @role='variable'">
              <xsl:text>)</xsl:text>
            </xsl:if>
            <xsl:value-of select="$delim"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{avoidverb}\quad}Verbatim in titles}
% The use of verbatim text in titles, footnotes, and
% the terms of variable lists is not yet fully tested.
% so it is implemented with the {\ttfamily{}\textbackslash{}url}
% command.\par
% \par\smallskip\leavevmode
% \CPKrunningecho{avoidverb}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Needs more testing}}\par\smallskip
%    \begin{macrocode}
  <!-- special for verb in titles, footnotes, or terms -->
      <xsl:when test="matches(.,'.*[\\\$\^{}&lt;\|&gt;].*')
                      and 
                      (ancestor::db:title or 
                       ancestor::db:footnote or
                       ancestor::db:term)">
        <xsl:message>
          <xsl:text>Warning: verbatim in </xsl:text>
          <xsl:value-of select="name(ancestor::*[3])"/>
          <xsl:text>/</xsl:text>
          <xsl:value-of select="name(ancestor::*[2])"/>
          <xsl:text>/</xsl:text>
          <xsl:value-of select="name(ancestor::*[1])"/>
          <xsl:text> for "</xsl:text>
          <xsl:value-of select="normalize-space(.)"/>
          <xsl:text>"</xsl:text>
        </xsl:message>
        <xsl:text>\url{</xsl:text>
        <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>}</xsl:text>
      </xsl:when>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{avoidverb}\quad}Basic monospace for non-special
% content}
% Test for the presence of \textsc{uri}
% specials
% ( \url{& _ ~ # %} ).\par
%    \begin{macrocode}
      <!-- all the rest need a special feature -->
      <xsl:otherwise>
        <xsl:choose>
          <!-- containing &_~#% use \url-->
          <xsl:when 
            test="matches(.,'.*[&amp;_~#%].*')
                  and 
                  not(db:replaceable or @condition='nolit')">
            <xsl:text>\url{</xsl:text>
            <xsl:value-of select="normalize-space(.)"/>
            <xsl:text>}</xsl:text>
          </xsl:when>
%    \end{macrocode}
% The same test for use of \texttt{<repleaceable>}\index{repleaceable=\texttt{\char'074 repleaceable\char'076 } (element)}\index{elements:!repleaceable=\texttt{\char'074 repleaceable\char'076 }}
% is needed as above.\par
%    \begin{macrocode}
          <!-- otherwise plain \tt -->
          <xsl:when 
            test="db:replaceable or @condition='nolit'">
            <xsl:if 
              test="(name()='command' 
                     or
                     @role='length')
                    and
                    (@language='TeX' 
                     or 
                     @language='LaTeXe' 
                     or 
                     @language='LaTeX' 
                     or 
                     not(@language))">
              <xsl:text>\textbackslash{}</xsl:text>
            </xsl:if>
            <xsl:if test="@language='XSLT' 
                          and
                          (name()='varname' and
                            (@role='variable' or 
                             @role='parameter'))
                          or 
                          name()='parameter'">
              <xsl:text>\$</xsl:text>
            </xsl:if>
            <xsl:if test="name()='varname' 
                          and
                          @language='Makefile' 
                          and
                          @role='variable'">
              <xsl:text>\$(</xsl:text>
            </xsl:if>
            <xsl:if test="name()='varname' 
                          and
                          @language='BiBTeX' 
                          and
                          @role='entrytype'">
              <xsl:text>@</xsl:text>
            </xsl:if>
            <xsl:apply-templates/>
            <xsl:if test="@xlink:type">
              <xsl:text>.</xsl:text>
              <xsl:value-of select="@xlink:type"/>
            </xsl:if>
            <xsl:if test="name()='varname' 
                          and
                          @language='Makefile' 
                          and
                          @role='variable'">
              <xsl:text>)</xsl:text>
            </xsl:if>
            <xsl:text>}</xsl:text>
          </xsl:when>
%    \end{macrocode}
% Failing all else, it’s just plain
% monospace.\par
%    \begin{macrocode}
          <xsl:otherwise>
            <xsl:text>{\ttfamily{}</xsl:text>
            <xsl:if 
              test="(name()='command' 
                     or
                     @role='length')
                    and
                    (@language='TeX' 
                     or 
                     @language='LaTeXe' 
                     or 
                     @language='LaTeX' 
                     or 
                     not(@language))">
              <xsl:text>\textbackslash{}</xsl:text>
            </xsl:if>
            <xsl:if test="@language='XSLT' 
                          and
                          (name()='varname' and
                            (@role='variable' or 
                             @role='parameter'))
                          or 
                          name()='parameter'">
              <xsl:text>\$</xsl:text>
            </xsl:if>
            <xsl:if test="name()='varname' 
                          and
                          @language='bash' 
                          and
                          @role='variable'">
              <xsl:text>\$</xsl:text>
            </xsl:if>
            <xsl:if test="name()='varname' 
                          and
                          @language='Makefile' 
                          and
                          @role='variable'">
              <xsl:text>\$(</xsl:text>
            </xsl:if>
            <xsl:if test="name()='varname' 
                          and
                          @language='BiBTeX' 
                          and
                          @role='entrytype'">
              <xsl:text>@</xsl:text>
            </xsl:if>
            <xsl:value-of select="normalize-space(.)"/>
            <xsl:if test="@xlink:type">
              <xsl:text>.</xsl:text>
              <xsl:value-of select="@xlink:type"/>
            </xsl:if>
            <xsl:if test="name()='varname' 
                          and
                          @language='Makefile' 
                          and
                          @role='variable'">
              <xsl:text>)</xsl:text>
            </xsl:if>
            <xsl:text>}</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
%    \end{macrocode}
% \subsubsection*{\llap{\color{OliveDrab}\LabelFont{avoidverb}\quad}Indexed entries}
% Indexing has been tested for syntax, but has not
% been implemented for semantics.\par
%    \begin{macrocode}
    <!-- finally, does it need an index entry? 
    <xsl:variable name="gi" select="local-name()"/>
    <xsl:if test="tokenize(/db:book/@xreflabel,':')[.=$gi]
                  and not(ancestor::db:warning)">
      <xsl:text>\index{</xsl:text>
      <xsl:value-of select="replace(.,'_','\\_')"/>
      <xsl:text>@\textbf{</xsl:text>
      <xsl:value-of select="replace(.,'_','\\_')"/>
      <xsl:text>}}</xsl:text>
    </xsl:if>
    -->
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{htrim}\label{template-db2dtx-htrim}
% Perform horizontal trimming of a span of text
% passed in the parameter. Unlike normalization, this
% only replaces multiple spaces and TAB characters with
% a single space, and leaves leading and trailing spaces
% (and other types of white-space) alone.\par
%    \begin{macrocode}
  <xsl:template name="htrim">
    <xsl:param name="text"/>
    <xsl:variable name="TEXT" 
      select="translate($text,'&#x9;',' ')"/>
    <xsl:choose>
      <xsl:when test="contains($TEXT,'  ')">
        <xsl:call-template name="htrim">
          <xsl:with-param name="text">
            <xsl:value-of 
              select="substring-before($TEXT,'  ')"/>
            <xsl:text> </xsl:text>
            <xsl:value-of 
              select="substring-after($TEXT,'  ')"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($TEXT,'&#xa; ')">
        <xsl:call-template name="htrim">
          <xsl:with-param name="text">
            <xsl:value-of 
              select="substring-before($TEXT,'&#xa; ')"/>
            <xsl:text>&#xa;</xsl:text>
            <xsl:value-of 
              select="substring-after($TEXT,'&#xa; ')"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$TEXT"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{lrtrim}\label{template-db2dtx-lrtrim}
% Left/right trimming does the reverse: it removes
% leading and trailing spaces but preserves embedded
% space. As this may be called on text within text, we
% pass an {\ttfamily{}\$indent}
% parameter which triggers a call to \DescribeTemplate{addindent}{\ttfamily{}addindent}.\par
% Text in \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} elements almost
% always begins with a newline, the one that comes right
% after the start-tag, and equally often has a newline
% and TAB or space character after the last printable
% character.\par
% After treatment, however, we need to paste on any
% indent passed by the calling routine, usually to avoid
% trouble with documentation that references the
% commands \verb|\end{lstlisting}| or
% \verb|\end{verbatim}| \emph{within} the text of the verbatim
% block.\par
%    \begin{macrocode}
  <xsl:template name="lrtrim">
    <xsl:param name="text"/>
    <xsl:param name="indent"/>
    <xsl:variable name="extent" 
      select="string-length($text)"/>
    <xsl:choose>
      <xsl:when test="substring($text,1,1)='&#xa;'">
        <xsl:call-template name="lrtrim">
          <xsl:with-param name="text" 
            select="substring($text,2)"/>
          <xsl:with-param name="indent" 
            select="$indent"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="substring($text,$extent)=' ' or
                      substring($text,$extent)='&#xa;' or
                      substring($text,$extent)='&#x9;'">
        <xsl:call-template name="lrtrim">
          <xsl:with-param name="text" 
            select="substring($text,1,($extent - 1))"/>
          <xsl:with-param name="indent" select="$indent"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$indent!=''">
        <xsl:call-template name="addindent">
          <xsl:with-param name="text" select="$text"/>
          <xsl:with-param name="indent" select="$indent"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{addindent}\label{template-db2dtx-addindent}
% Adds the indent (spaces) given in {\ttfamily{}\$indent} before every
% newline in {\ttfamily{}\$text}.\par
%    \begin{macrocode}
  <xsl:template name="addindent">
    <xsl:param name="text"/>
    <xsl:param name="indent"/>
    <xsl:value-of select="$indent"/>
    <xsl:choose>
      <xsl:when test="contains($text,'&#xa;')">
        <xsl:value-of 
          select="substring-before($text,'&#xa;')"/>
        <xsl:text>&#xa;</xsl:text>
        <xsl:call-template name="addindent">
          <xsl:with-param name="text" 
            select="substring-after($text,'&#xa;')"/>
          <xsl:with-param name="indent" 
            select="$indent"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{breakline}\label{template-db2dtx-breakline}
% Perform line-breaking at space tokens to bring a
% chunk of text to within {\ttfamily{}\$max}
% spaces wide (default is the value of \DescribeVariable{maxcodelen}{\ttfamily{}\$maxcodelen}).\par
% \label{breakline}
%    \begin{macrocode}
  <xsl:template name="breakline">
    <xsl:param name="string"/>
    <xsl:param name="max">
      <xsl:value-of select="$maxcodelen"/>
    </xsl:param>
    <xsl:choose>
      <xsl:when test="string-length($string)>$max">
        <!-- see if there is a substring that will fit -->
        <xsl:choose>
          <!-- if no spaces, we're stuck, so use as-is -->
          <xsl:when test="not(contains($string,' '))">
            <xsl:value-of select="$string"/>
          </xsl:when>
          <!-- if first substring fits, output/repeat -->
          <xsl:when 
            test="string-length(substring-before($string,
                                ' '))&lt;=$max">
            <xsl:value-of select="$max"/>
            <xsl:text>/</xsl:text>
            <xsl:value-of 
              select="string-length(substring-before($string,
                                    ' '))"/>
            <xsl:value-of 
              select="substring-before($string,' ')"/>
            <xsl:text> </xsl:text>
            <!-- see how much we have left -->
            <xsl:choose>
              <xsl:when 
                test="($max - 1 -
                      string-length(substring-before($string,
                                    ' ')))
                      &lt; 
                      string-length(substring-before(
                                    substring-after($string,
                                    ' '), ' '))">
                <xsl:text>&#xa;   </xsl:text>
                <xsl:call-template name="breakline">
                  <xsl:with-param name="string" 
                    select="substring-after($string,' ')"/>
                </xsl:call-template>
              </xsl:when>
              <xsl:otherwise>
                <xsl:call-template name="breakline">
                  <xsl:with-param name="string" 
                    select="substring-after($string,' ')"/>
                  <xsl:with-param name="max" 
                    select="$max - 1 -
                            string-length(substring-before(
                            $string,' '))"/>
                </xsl:call-template>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$string"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{compspace}\label{template-db2dtx-compspace}
% This compensates for deficient space-stripping
% where significant white-space-only nodes in mixed
% content are removed by the parser. It tests to see if
% the immediately preceding sibling node (if any) is an
% element, and if so, outputs a space.\par
%    \begin{macrocode}
  <xsl:template name="compensate-space">
    <xsl:if test="preceding-sibling::node() and
                  preceding-sibling::* and
                  count(preceding-sibling::node()[1] |
                        preceding-sibling::*[1])=1">
      <xsl:text> </xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{repeatarg}\label{template-db2dtx-repeatarg}
% Generates {\ttfamily{}\$limit} repeated \TeX{}
% arguments when forming a generated command in a
% \texttt{<cmdsynopsis>}\index{cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 } (element)}\index{elements:!cmdsynopsis=\texttt{\char'074 cmdsynopsis\char'076 }}.\par
%    \begin{macrocode}
  <xsl:template name="repeatarg">
    <xsl:param name="limit"/>
    <xsl:param name="count">
      <xsl:text>0</xsl:text>
    </xsl:param>
    <xsl:param name="prefix"/>
    <xsl:param name="suffix"/>
    <xsl:if test="$count&lt;$limit">
      <xsl:value-of select="$prefix"/>
      <xsl:text>#</xsl:text>
      <xsl:value-of select="$count + 1"/>
      <xsl:value-of select="$suffix"/>
      <xsl:call-template name="repeatarg">
        <xsl:with-param name="limit" select="$limit"/>
        <xsl:with-param name="count" select="$count + 1"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Copyright]{Copyright :}\label{copyright}
% \begin{CPKtemplate}{copyright}\label{template-db2dtx-copyright}
% This template generates the copyright and
% boilerplate information block at the top of every
% extractable \LaTeX{} file.\par
%    \begin{macrocode}
  <xsl:template name="copyright-statement">
    <xsl:param name="ftype"/>
    <xsl:text>% Transformed from </xsl:text>
    <xsl:value-of select="$docname"/>
    <xsl:text>.xml by ClassPack db2dtx.xsl
% version </xsl:text>
    <xsl:value-of select="$thisversion"/>
    <xsl:text> (</xsl:text>
    <xsl:value-of select="$thisverdate"/>
    <xsl:text>) on </xsl:text>
    <xsl:value-of 
      select="format-dateTime(current-dateTime(),
              '[FNn] [D] [MNn] [Y] at [H]:[m]:[s]')"/>
    <xsl:text>&#xa;%&#xa;% </xsl:text>
    <xsl:value-of select="$docname"/>
    <xsl:text>.</xsl:text>
    <xsl:value-of select="$ftype"/>
    <xsl:text> is copyright © </xsl:text>
    <xsl:variable name="copyright-first">
      <xsl:for-each 
        select="//db:info/db:revhistory/db:revision">
        <xsl:sort select="@version" order="descending"/>
        <xsl:if test="position()=last()">
          <xsl:value-of 
            select="substring(db:date/@YYYY-MM-DD,1,4)"/>
        </xsl:if>
      </xsl:for-each>
    </xsl:variable>
    <xsl:value-of select="$copyright-first"/>
    <xsl:variable name="copyright-latest" 
      select="substring($date,1,4)"/>
    <xsl:if test="$copyright-latest > $copyright-first">
      <xsl:text>-</xsl:text>
      <xsl:value-of select="$copyright-latest"/>
    </xsl:if>
    <xsl:text> by </xsl:text>
    <!-- RIGHTS -->
    <xsl:choose>
      <xsl:when test="/db:book/@audience='lppl'">
        <xsl:value-of 
          select="normalize-space(//db:info//db:author[1]/
                  db:personname/db:firstname)"/>
        <xsl:text> </xsl:text>
        <xsl:value-of 
          select="normalize-space(//db:info//db:author[1]/
                  db:personname/db:surname)"/>
        <xsl:text> &lt;</xsl:text>
        <xsl:value-of 
          select="//db:info//db:author[1]/db:email"/>
        <xsl:text>>&#xa;</xsl:text>
        <xsl:text>%
% 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 has the LPPL maintenance status ‘maintained’.
% &#xa;</xsl:text>        
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of 
          select="normalize-space(
                  //db:info/db:copyright/db:holder)"/>
        <xsl:text> &lt;</xsl:text>
        <xsl:value-of 
          select="substring-after(
                  //db:info/db:copyright/db:holder
                  /@xlink:href,'mailto:')"/>
        <xsl:text>>&#xa;</xsl:text>
        <xsl:text>%
% This work may not be copied or re-used without the express
% written permission of the copyright holder[s]. Access to 
% this work is restricted to the copyright holder[s] and 
% their authorised employees, contractors, or agents.
% &#xa;</xsl:text>        
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>% The current maintainer of this work is </xsl:text>
    <xsl:choose>
      <xsl:when 
        test="//db:info//db:author[@role='maintainer']">
        <xsl:for-each 
          select="//db:info//db:author
                  [@role='maintainer']">
          <xsl:value-of 
            select="normalize-space(
                    db:personname/db:firstname)"/>
          <xsl:text> </xsl:text>
          <xsl:value-of 
            select="normalize-space(
                    db:personname/db:surname)"/>
          <xsl:text> &lt;</xsl:text>
          <xsl:value-of select="db:email"/>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of 
          select="normalize-space(
                  //db:info//db:author/
                  db:personname/db:firstname)"/>
        <xsl:text> </xsl:text>
        <xsl:value-of 
          select="normalize-space(
                  //db:info//db:author/
                  db:personname/db:surname)"/>
        <xsl:text> &lt;</xsl:text>
        <xsl:value-of 
          select="//db:info//db:author/db:email"/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>>&#xa;</xsl:text>
    <xsl:text>%
% This work consists of the files </xsl:text>
    <xsl:value-of select="$docname"/>
    <xsl:text>.dtx and </xsl:text>
    <xsl:value-of select="$docname"/>
    <xsl:text>.ins,</xsl:text>
    <xsl:if test="/db:book/db:part
                  [@xml:id='code']
                  /db:appendix">
      <xsl:text>&#xa;% the derived file</xsl:text>
      <xsl:if test="count(/db:book/db:part
                    [@xml:id='code']
                    /db:appendix)>0">
        <xsl:text>s</xsl:text>
      </xsl:if>
      <xsl:text> </xsl:text>
      <xsl:for-each 
        select="db:book/db:part
                [@xml:id='code']
                /(db:chapter|db:appendix)[@xlink:href]">
        <xsl:value-of select="@xlink:href"/>
        <xsl:text>, </xsl:text>
      </xsl:for-each>
    </xsl:if>
    <xsl:text>&#xa;% and any other ancillary files </xsl:text>
    <xsl:text>listed in the MANIFEST.&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \paragraph[Doc\TeX{} text]{Doc\TeX{} text :}
% \begin{CPKtemplate}{dtxtext}\label{template-db2dtx-dtxtext}
% Output text for the {\ttfamily{}.dtx}
% file. Elide empty and white-space-only strings; remove
% leading TABs. An earlier version replaced an initial
% newline in \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} content with a
% percent sign, but this has been lost in the
% workflow.\par
% Strings containing newlines get output with a
% leading percent sign as Doc\TeX{}’s normal armour.
% Underscores in filenames get replaced with their
% \LaTeX{} escape.\par
%    \begin{macrocode}
  <xsl:template name="dtxtext">
    <xsl:param name="text"/>
    <xsl:choose>
      <xsl:when test="normalize-space(.)=''">
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:when test="starts-with($text,'&#x9;')">
        <xsl:call-template name="dtxtext">
          <xsl:with-param name="text" 
            select="substring($text,2)"/>
        </xsl:call-template>
      </xsl:when>
      <!-- if it starts with a newline AND
           it’s in a <programlisting> element AND
           this is the first span of its type, prefix 
           a percent -->
      <xsl:when test="starts-with($text,'&#xa;') and 
                      parent::db:programlisting and 
                      count(preceding-sibling::text())=0">
        <xsl:text>% </xsl:text>
        <xsl:call-template name="dtxtext">
          <xsl:with-param name="text" 
            select="substring($text,2)"/>
        </xsl:call-template>
      </xsl:when>
      <!-- break strings containing newlines -->
      <xsl:when test="contains($text,'&#xa;')">
        <xsl:value-of 
          select="substring-before($text,'&#xa;')"/>
        <xsl:choose>
          <xsl:when 
            test="normalize-space(substring-after(
                                  $text,'&#xa;'))='' 
                  and
                  parent::db:programlisting 
                  and 
                  count(following-sibling::text())=0">
            <xsl:text></xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>&#xa;% </xsl:text>
            <xsl:call-template name="dtxtext">
              <xsl:with-param name="text" 
                select="substring-after($text,'&#xa;')"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- convert underscores in filenames -->
      <xsl:when 
        test="ancestor::db:filename[db:replaceable] and
              contains($text,'_')">
        <xsl:value-of select="substring-before($text,'_')"/>
        <xsl:text>\_</xsl:text>
        <xsl:call-template name="dtxtext">
          <xsl:with-param name="text" 
            select="substring-after($text,'_')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{delogify}\label{template-db2dtx-delogify}
% Routine to replace \TeX{}/\LaTeX{} logos with
% plaintext versions.\par
%    \begin{macrocode}
  <xsl:template name="delogify">
    <xsl:param name="string"/>
    <xsl:choose>
      <xsl:when test="contains($string,'\LaTeXe{}')">
        <xsl:call-template name="delogify">
          <xsl:with-param name="string">
            <xsl:value-of 
              select="substring-before($string,'\LaTeXe{}')"/>
            <xsl:text>LaTeX2e</xsl:text>
            <xsl:value-of 
              select="substring-after($string,'\LaTeXe{}')"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($string,'\LaTeX{}')">
        <xsl:call-template name="delogify">
          <xsl:with-param name="string">
            <xsl:value-of 
              select="substring-before($string,'\LaTeX{}')"/>
            <xsl:text>LaTeX</xsl:text>
            <xsl:value-of 
              select="substring-after($string,'\LaTeX{}')"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($string,'\TeX{}')">
        <xsl:call-template name="delogify">
          <xsl:with-param name="string">
            <xsl:value-of 
              select="substring-before($string,'\TeX{}')"/>
            <xsl:text>TeX</xsl:text>
            <xsl:value-of 
              select="substring-after($string,'\TeX{}')"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$string"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsection{Modes}
% \begin{CPKtemplate}{insfile}\label{insfile}
% Creates the {\ttfamily{}.ins} installer file,
%     named after the main file. After the copyright block, it
%     follows the standard pattern documented in
%     \textcite[][section\thinspace 2]{dtxtut}. The preamble is omitted when
%     outputting a script, as it would have no meaning.\par
%    \begin{macrocode}
  <xsl:template match="db:info" mode="ins">
    <xsl:variable name="file">
      <xsl:value-of select="$docname"/>
      <xsl:text>.ins</xsl:text>
    </xsl:variable>
    <xsl:result-document format="textFormat" href="{$file}">
      <xsl:call-template name="copyright-statement">
        <xsl:with-param name="ftype">
          <xsl:text>ins</xsl:text>
        </xsl:with-param>
      </xsl:call-template>
      <xsl:text>%
\input docstrip.tex
\keepsilent
\usedir{</xsl:text>
      <xsl:choose>
        <xsl:when test="/db:book/@xml:base">
          <xsl:value-of select="/db:book/@xml:base"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>tex/latex</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>}&#xa;</xsl:text>
      <xsl:choose>
        <xsl:when test="$doctype='script'">
          <xsl:text>\nopreamble&#xa;</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>\preamble

This is a generated file.

Copyright © </xsl:text>
          <xsl:value-of 
            select="format-date(db:copyright
                    /db:year/@YYYY-MM-DD,'[Y]')"/>
          <!-- omit range if copyright is this year -->
          <xsl:if 
            test="number(
                  substring(
                  db:copyright/db:year/@YYYY-MM-DD,1,4))
                  &lt; year-from-date(current-date())">
            <xsl:text>-</xsl:text>
            <xsl:value-of
              select="format-date(current-date(),'[Y]')"/>
          </xsl:if>
          <xsl:text> by </xsl:text>
          <xsl:value-of 
            select="normalize-space(db:copyright
                    /db:holder)"/>
          <xsl:text>&#xa;&#xa;</xsl:text>
          <xsl:for-each select="db:annotation/*">
            <xsl:call-template name="htrim">
              <xsl:with-param name="text">
                <xsl:call-template name="lrtrim">
                  <xsl:with-param name="text" select="."/>
                </xsl:call-template>
              </xsl:with-param>
            </xsl:call-template>
            <xsl:text>&#xa;&#xa;</xsl:text>
          </xsl:for-each>
          <xsl:text>\endpreamble&#xa;</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
%    \end{macrocode}
% The following fragment is not active (commented out)
%     as it appears to generate errors and is not needed.\par
%    \begin{macrocode}
        <!-- inactive due to errors
        <xsl:for-each
          select="/db:book/db:part[@xml:id='files']
                  /db:chapter[db:programlisting]">
          <xsl:variable name="ext"
            select="substring-after(@xlink:href,'.')"/>
          <xsl:text>\declarepreamble\</xsl:text>
          <xsl:value-of select="@xml:id"/>
          <xsl:text>
\DoubleperCent\space This is file </xsl:text>
          <xsl:value-of select="@xlink:href"/>
          <xsl:text>&#xa;\endpreamble&#xa;</xsl:text>
          <xsl:text>\declarepostamble\</xsl:text>
          <xsl:value-of select="@xml:id"/>
          <xsl:text>
\DoubleperCent\space End of file </xsl:text>
          <xsl:value-of select="@xlink:href"/>
          <xsl:text>&#xa;\endpreamble&#xa;</xsl:text>
        </xsl:for-each>
        -->
%    \end{macrocode}
% Generate the extractor for the main file.\par
%    \begin{macrocode}
        <xsl:text>\generate{</xsl:text>
        <!-- 1. Generate the main file (cls or sty) first -->
        <xsl:text>\file{</xsl:text>
        <xsl:value-of select="$name"/>
        <xsl:text>.</xsl:text>
        <xsl:value-of select="$filetype"/>
        <xsl:text>}{\from{</xsl:text>
        <xsl:value-of select="$docname"/>
        <xsl:text>.dtx}{</xsl:text>
        <xsl:value-of select="$doctype"/>
        <xsl:text>}}&#xa;</xsl:text>
%    \end{macrocode}
% Add any file fragments from the documentation needing
%     to be output on their own; these are identified as a
%     \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} with an ID, an \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}},
%     \emph{and} \texttt{@show}\index{show=\texttt{\char'100 show} (attribute)}\index{attributes:!show=\texttt{\char'100 show}}
%     set to \texttt{"new"}\index{new=\texttt{"new"} (attribute value)}\index{attribute values:!new=\texttt{"new"}}.\par
%    \begin{macrocode}
        <!-- 2. Then any new files FROM WITHIN THE DOCUMENTATION (!)
             specially designated -->
        <xsl:for-each 
          select="//db:programlisting
                  [@xml:id 
                   and 
                   @xlink:show='new' 
                   and 
                   @xlink:href]">
          <xsl:variable name="ext" 
            select="substring-after(@xlink:href,'.')"/>
          <xsl:choose>
            <xsl:when test="$ext='tex'">
              <xsl:text>          \usepreamble\</xsl:text>
              <xsl:value-of select="@xml:id"/>
              <xsl:text>preamble\usepostamble\</xsl:text>
              <xsl:value-of select="@xml:id"/>
              <xsl:text>postamble</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>          </xsl:text>
              <xsl:text>\usepreamble\empty</xsl:text>
              <xsl:text>\usepostamble\empty</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:text>&#xa;          \file{</xsl:text>
          <xsl:value-of select="@xlink:href"/>
          <xsl:text>}{\from{</xsl:text>
          <xsl:value-of select="$docname"/>
          <xsl:text>.dtx}{</xsl:text>
          <xsl:value-of select="@xml:id"/>
          <xsl:text>}}&#xa;</xsl:text>
        </xsl:for-each>
%    \end{macrocode}
% Add any \emph{annotated} ancillary files
%     from code appendices.\par
%    \begin{macrocode}
        <!-- 3. Then the files with annotations -->
        <xsl:for-each 
          select="/db:book/db:part[@xml:id='code']
                  /db:appendix
                    [descendant::db:programlisting 
                     and 
                     @xml:id 
                     and 
                     @xlink:href
                     and
                     not(@userlevel='cp')]">
          <!-- check omitted cp files are in manifest -->
          <xsl:if test="@userlevel='cp' and
                        id('manifest')/db:simplelist/db:member
                          [.=current()/@xlink:href]">
            <xsl:message>
              <xsl:text>Warning: file </xsl:text>
              <xsl:value-of select="@xlink:href"/>
              <xsl:text>not being generated but in manifest</xsl:text>
            </xsl:message>
          </xsl:if>
          <xsl:variable name="ext" 
            select="substring-after(@xlink:href,'.')"/>
          <xsl:choose>
            <xsl:when test="$ext='tex'">
              <xsl:text>          \usepreamble\</xsl:text>
              <xsl:value-of select="@xml:id"/>
              <xsl:text>preamble\usepostamble\</xsl:text>
              <xsl:value-of select="@xml:id"/>
              <xsl:text>postamble&#xa;</xsl:text>
            </xsl:when>
            <xsl:when test="$ext='cls' or $ext='sty'">
<!--
  <xsl:text>          \usepreamble\usepostamble</xsl:text>
-->
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>          </xsl:text>
              <xsl:text>\usepreamble\empty</xsl:text>
              <xsl:text>\usepostamble\empty&#xa;</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:text>          \file{</xsl:text>
          <xsl:value-of select="@xlink:href"/>
          <xsl:text>}{\from{</xsl:text>
          <xsl:value-of select="$docname"/>
          <xsl:text>.dtx}{</xsl:text>
          <xsl:value-of select="@xml:id"/>
          <xsl:text>}}&#xa;</xsl:text>
        </xsl:for-each>
%    \end{macrocode}
% Add any \emph{unannotated} ancillary
%     files from chapters in the files part.\par
%    \begin{macrocode}
        <!-- 4. Then the files extracted whole without annotation -->
        <xsl:for-each 
          select="/db:book/db:part[@xml:id='files'] 
                  /db:chapter
                  [db:programlisting 
                   and 
                   @xml:id 
                   and @xlink:href]">
          <xsl:variable name="ext"  
            select="substring-after(@xlink:href,'.')"/>
          <xsl:choose>
            <xsl:when test="$ext='TeX'">
              <xsl:text>          \usepreamble\</xsl:text>
              <xsl:value-of select="@xml:id"/>
              <xsl:text>preamble\usepostamble\</xsl:text>
              <xsl:value-of select="@xml:id"/>
              <xsl:text>postamble</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>          </xsl:text>
              <xsl:text>\usepreamble\empty</xsl:text>
              <xsl:text>\usepostamble\empty</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:text>&#xa;          \file{</xsl:text>
          <xsl:value-of select="@xlink:href"/>
          <xsl:text>}{\from{</xsl:text>
          <xsl:value-of select="$docname"/>
          <xsl:text>.dtx}{</xsl:text>
          <xsl:value-of select="@xml:id"/>
          <xsl:text>}}&#xa;</xsl:text>
        </xsl:for-each>
%    \end{macrocode}
% Generate the console message to the user. A lot of
%     time is taken here trying to get it to self-adjust to the
%     file name lengths so that it looks right.\par
%    \begin{macrocode}
        <xsl:text>}
\obeyspaces
\Msg{********************************************************}
\Msg{**                                                    **}
\Msg{** Read the documentation before using </xsl:text>
        <xsl:choose>
          <xsl:when 
            test="not(db:part[@xml:id='class']
                  /descendant::db:appendix[@xml:id])">
            <xsl:text>this </xsl:text>
            <xsl:value-of select="$doctype"/>
            <xsl:text>.    </xsl:text>
          </xsl:when>
          <xsl:when 
            test="$doctype='cls' and
                  not(db:part[@xml:id='class']
                  /descendant::db:appendix[@xml:id]
                  [substring-after(@xlink:href,'.')!='cls'])">
            <xsl:text>these classes. </xsl:text>
          </xsl:when>
          <xsl:when 
            test="$doctype='sty' and
                  not(db:part[@xml:id='class']
                  /descendant::db:appendix[@xml:id]
                  [substring-after(@xlink:href,'.')!='sty'])">
            <xsl:text>these packages.</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>these files.   </xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>**}
\Msg{**                                                    **}
\Msg{** To finish the installation you have to move the    **}
\Msg{** following file</xsl:text>
        <xsl:if 
          test="count(/db:book/db:part[@xml:id='files']
                      /db:chapter[db:programlisting and 
                                  @xml:id and @xlink:href]) +
                count(/db:book/db:part[@xml:id='code']
                      /db:appendix[db:programlisting and 
                                   @xml:id and @xlink:href]) + 1
                &gt; 1">
          <xsl:text>s</xsl:text>
        </xsl:if>
        <xsl:text> into a directory searched by TeX:  </xsl:text>
        <xsl:if 
          test="count(/db:book/db:part[@xml:id='files']
                      /db:chapter[db:programlisting and 
                                  @xml:id and @xlink:href]) +
                count(/db:book/db:part[@xml:id='code']
                      /db:appendix[db:programlisting and 
                                   @xml:id and @xlink:href]) + 1
                = 1">
          <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:text>**}
\Msg{**                                                    **}
</xsl:text>
        <!-- class or package first -->
        <xsl:text>\Msg{**     </xsl:text>
        <xsl:value-of 
          select="/db:book/db:part
                  [@xml:id='code']
                  /db:chapter[1]/@xlink:href"/>
        <xsl:variable name="spacetaken" 
          select="4 +
                  string-length(/db:book/db:part[@xml:id='code']
                                /db:chapter[1]/@xlink:href)
                  + 4"/>
        <xsl:value-of 
          select="for $s in (1 to 
                    xs:integer((50 - $spacetaken) div 2))
                  return '&#x20;'"/>
        <xsl:text>      **}</xsl:text>
        <!-- remaining files -->
        <xsl:for-each 
          select="/db:book/db:part[@xml:id='files'] 
                  /db:chapter[descendant::db:programlisting 
                              and
                              @xml:id and @xlink:href] 
                  |
                  /db:book/db:part[@xml:id='code']
                  /db:appendix[descendant::db:programlisting 
                               and
                               @xml:id and @xlink:href]">
          <xsl:text>&#xa;\Msg{**     </xsl:text>
          <xsl:value-of select="@xlink:href"/>
          <xsl:variable name="spacetaken" 
            select="string-length(@xlink:href)"/>
          <xsl:value-of 
            select="for $s in (1 to 
                    xs:integer((46 - $spacetaken) div 2))
                    return '&#x20;'"/>
          <xsl:if test="($spacetaken div 2) != 
                        (xs:integer($spacetaken) div 2)">
            <xsl:text>    </xsl:text>
          </xsl:if>
          <xsl:text>  **}</xsl:text>
        </xsl:for-each>
        <xsl:text>
\Msg{**                                                    **}
\Msg{** To produce the documentation run the file          **}
\Msg{** </xsl:text>
        <xsl:value-of select="$docname"/>
        <xsl:text>.dtx through </xsl:text>
        <!-- space available is 50 chars less the word 'through' (7)
             and the two spaces either side, less the width of the
             class/package name plus 4 for the extension, less the
             width of the program names and their spaces -->
        <xsl:choose>
          <xsl:when test="//db:part[@conformance='lualatex']">
            <xsl:text>XeLaTeX and biber</xsl:text>
            <xsl:variable name="spacetaken" 
              select="string-length($docname) + 4 + 9 + 17"/>
            <xsl:value-of 
              select="for $s in (1 to 
                        xs:integer((50 - $spacetaken) div 2))
                      return '&#x20;'"/>
          </xsl:when>
          <xsl:when test="//db:part[@conformance='xelatex']">
            <xsl:text>XeLaTeX and biber</xsl:text>
            <xsl:variable name="spacetaken" 
              select="string-length($docname) + 4 + 9 + 17"/>
            <xsl:value-of 
              select="for $s in (1 to 
                        xs:integer((50 - $spacetaken) div 2))
                      return '&#x20;'"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>pdfLaTeX and BiBTeX</xsl:text>
            <xsl:variable name="spacetaken" 
              select="string-length($docname) + 4 + 9 + 19"/>
            <xsl:value-of 
              select="for $s in (1 to 
                        xs:integer((50 - $spacetaken) div 2))
                      return ' '"/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>   **}
\Msg{**                                                    **}
\Msg{** Happy LaTeXing!                                    **}
\Msg{**                                                    **}
\Msg{********************************************************}
\endbatchfile
</xsl:text>
    </xsl:result-document>
  </xsl:template>
%    \end{macrocode}
% \par\smallskip\leavevmode
% \CPKrunningecho{insfile}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: what about stuff in the data part?}}\par\smallskip
% \end{CPKtemplate}
% \begin{CPKtemplate}{files}\label{template-db2dtx-files}
% When extracting unannotated files (eg examples or
%     configs), elide the titles in parts and chapters. The sole
%     other component of such chapters, apart from the title,
%     must be the \texttt{<programlisting>}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} element holding the
%     code. This is output as a Doc\TeX{}
%     \texttt{macrocode} block.\par
%    \begin{macrocode}
  <!--
  <xsl:template 
    match="db:part/db:title | 
           db:chapter/db:title |
           db:chapter/db:subtitle |
           db:chapter/db:para" mode="files"/>
-->

  <xsl:template match="db:part/db:title" mode="files">
    <xsl:text>% \section{</xsl:text>
    <xsl:apply-templates mode="files"/>
    <xsl:text>}\label{</xsl:text>
    <xsl:value-of select="../@xml:id"/>
    <xsl:text>}&#xa;</xsl:text>
  </xsl:template>
  
  <xsl:template match="db:chapter" mode="files">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:apply-templates mode="files"/>
  </xsl:template>

  <xsl:template match="db:chapter/db:title" mode="files">
    <xsl:text>% \subsection{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}\label{</xsl:text>
    <xsl:value-of select="../@xml:id"/>
    <xsl:text>}&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="db:warning" mode="files">
    <xsl:call-template name="sidewarn"/>
  </xsl:template>
  
  <xsl:template match="db:chapter/db:para
                       |
                       db:part/db:para" mode="files">
    <xsl:text>% </xsl:text>
    <xsl:apply-templates/>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>

  <!--
emphasis
filename
package
productname
tag
xref
-->
  
  <xsl:template match="db:programlisting" mode="files">
    <xsl:choose>
      <xsl:when test="ancestor::db:part[@xml:id='files']">
        <xsl:text>% \iffalse&#xa;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>%    </xsl:text>
        <xsl:text>\begin</xsl:text>
        <xsl:text>{macrocode}&#xa;</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <!-- create the latexdoc tag -->
    <xsl:text>%&lt;*</xsl:text>
    <xsl:value-of select="parent::db:chapter/@xml:id"/>
    <xsl:text>>&#xa;</xsl:text>
    <xsl:call-template name="lrtrim">
      <xsl:with-param name="text"
        select="unparsed-text(concat($docname,'/',@xlink:href))"/>
    </xsl:call-template>
    <!-- end tag -->
    <xsl:text>&#xa;%&lt;/</xsl:text>
    <xsl:value-of select="parent::db:chapter/@xml:id"/>
    <xsl:text>>&#xa;</xsl:text>
    <xsl:choose>
      <xsl:when test="ancestor::db:part[@xml:id='files']">
        <xsl:text>% \fi&#xa;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>%    </xsl:text>
        <xsl:text>\end</xsl:text>
        <xsl:text>{macrocode}&#xa;</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsection{Creating the web page}\label{indexhtml}
% This named template creates the web page
%   ({\ttfamily{}index.html}) for the class or package
%   to go on the author’s web site.\par
% \begin{CPKtemplate}{index}\label{template-db2dtx-index}
% Currently this reflects the
%   style used on the Silmaril site.\par
%    \begin{macrocode}
  <xsl:variable name="TeX">
    <span class="TeX">T<span 
    class="E">E</span>X</span>
  </xsl:variable>
  <xsl:variable name="LaTeX">
    <span class="LaTeX">L<span 
    class="A">A</span><span 
    class="TeX">T<span 
    class="E">E</span>X</span></span>
  </xsl:variable>
  <xsl:template name="webindex">
    <xsl:message>
      <xsl:text>Making index.html for web site</xsl:text>
    </xsl:message>
    <xsl:result-document format="htmlFormat" href="index.html">
      <html>
        <head>
          <title>LaTeX Packages and Document Classes 
          from Silmaril</title>
          <meta charset="utf-8"/>
          <meta name="viewport" 
            content="width=device-width,initial-scale=1,
                     user-scalable=no"/>
          <link rel="stylesheet" href="../assets/css/main.css"/>
          <noscript>
            <link rel="stylesheet" 
              href="../assets/css/noscript.css"/>
          </noscript>
        </head>
        <body class="is-preload">
          <section id="top" class="wrapper style2">
            <header class="major">
              <h2>
                <xsl:copy-of select="$LaTeX"/>
                <xsl:text> style packages and document classes 
                from Silmaril</xsl:text>
              </h2>
              <ul class="icons labeled">
                <li>
                  <span class="icon solid fa-book">
                    <span class="label">
                      <a href="../#downloads">Index</a>
                    </span>
                  </span>
                </li>
                <li>
                  <span class="icon solid fa-book-open">
                    <span class="label">
                      <a href="../#more">About</a>
                    </span>
                  </span>
                </li>
              </ul>
            </header>
            <div class="inner alt">
              <section class="spotlight" id="{$docname}">
                <div class="image">
                  <a href="{$docname}.png" target="_new">
                    <img src="{$docname}.png" alt="{$shorttitle}"/>
                  </a>
                </div>
                <div class="content">
                  <h3>
                    <xsl:text>The </xsl:text>
                    <a href="http://ctan.org/pkg/{$docname}">
                      <xsl:value-of select="$docname"/>
                    </a>
                    <xsl:text> package</xsl:text>
                  </h3>
                  <h4 class="subtitle">
                    <xsl:text>v </xsl:text>
                    <xsl:value-of select="/db:book/@version"/>
                    <xsl:text>.</xsl:text>
                    <xsl:value-of select="/db:book/@revision"/>
                    <xsl:text> of </xsl:text>
                    <xsl:value-of 
                      select="/db:book/db:info
                              /db:revhistory/db:revision
                              [@version=max(parent::db:revhistory
                              /db:revision/@version)]
                              /db:date/@YYYY-MM-DD"/>
                    <xsl:text> </xsl:text>
                    <span class="reversed">©</span>
                    <xsl:text> </xsl:text>
                    <xsl:value-of 
                      select="format-date($firstverdate,'[Y]')"/>
                    <xsl:text>–</xsl:text>
                    <xsl:value-of 
                      select="format-date(current-date(),'[Y]')"/>
                    <xsl:text> </xsl:text>
                    <a href="www.latex-project.org/lppl/lppl-1-3c/">LPPL 
                      1.3c</a>
                  </h4>
                  <p>
                    <xsl:value-of select="/db:book/db:info/db:title"/>
                  </p>
                  <div class="table-wrapper">
                    <table>
                      <thead>
                        <tr>
                          <th>File</th>
                          <th>Description</th>
                        </tr>
                      </thead>
                      <tbody>
                        <!-- ZIP -->
                        <tr>
                          <td>
                            <tt>
                              <a href="{$docname}-{/db:book/@version}.{
                                       /db:book/@revision}.zip">
                                <xsl:value-of 
                                  select="$docname"/>
                                <xsl:text>-</xsl:text>
                                <xsl:value-of 
                                  select="/db:book/@version"/>
                                <xsl:text>.</xsl:text>
                                <xsl:value-of 
                                  select="/db:book/@revision"/>
                                <xsl:text>.zip</xsl:text>
                              </a>
                            </tt>
                          </td>
                          <td>Zip file of the CTAN distribution</td>
                        </tr>
                        <!-- TDS ZIP -->
                        <tr>
                          <td>
                            <tt>
                              <a href="{$docname}-{/db:book/@version}.{
                                       /db:book/@revision}.tds.zip">
                                <xsl:value-of 
                                  select="$docname"/>
                                <xsl:text>-</xsl:text>
                                <xsl:value-of 
                                  select="/db:book/@version"/>
                                <xsl:text>.</xsl:text>
                                <xsl:value-of 
                                  select="/db:book/@revision"/>
                                <xsl:text>.tds.zip</xsl:text>
                              </a>
                            </tt>
                          </td>
                          <td>TeX Directory Structure (TDS) zipfile</td>
                        </tr>
                        <!-- DTX -->
                        <tr>
                          <td>
                            <tt>
                              <a href="{$docname}.dtx">
                                <xsl:value-of select="$docname"/>
                                <xsl:text>.dtx</xsl:text>
                              </a>
                            </tt>
                          </td>
                          <td>
                            <xsl:text>Doc</xsl:text>
                            <xsl:copy-of select="$TeX"/>
                            <xsl:text> combined code and 
                              documentation</xsl:text>
                          </td>
                        </tr>
                        <!-- INS -->
                        <tr>
                          <td>
                            <tt>
                              <a href="{$docname}.ins">
                                <xsl:value-of select="$docname"/>
                                <xsl:text>.ins</xsl:text>
                              </a>
                            </tt>
                          </td>
                          <td>
                            <xsl:text>Doc</xsl:text>
                            <xsl:copy-of select="$TeX"/>
                            <xsl:text> installer</xsl:text>
                          </td>
                        </tr>
                        <!-- PDF -->
                        <tr>
                          <td>
                            <tt>
                              <a href="{$docname}.pdf">
                                <xsl:value-of select="$docname"/>
                                <xsl:text>.pdf</xsl:text>
                              </a>
                            </tt>
                          </td>
                          <td>
                            <xsl:text>PDF documentation</xsl:text>
                          </td>
                        </tr>
                        <!-- CLS/STY -->
                        <tr>
                          <td>
                            <tt>
                              <a
                                href="{$docname}.{/db:book/@userlevel}">
                                <xsl:value-of select="$docname"/>
                                <xsl:text>.</xsl:text>
                                <xsl:value-of 
                                  select="/db:book/@userlevel"/>
                              </a>
                            </tt>
                          </td>
                          <td>
                            <xsl:text>the </xsl:text>
                            <xsl:value-of select="/db:book/@arch"/>
                            <xsl:text> file</xsl:text>
                          </td>
                        </tr>
                        <!-- PNG -->
                        <!-- convert \
                             -density 300 <docname>.pdf[0] \
                             -quality 100 \
                             -flatten \
                             -sharpen 0x1.0 <docname>.png
                        -->
                        <tr>
                          <td>
                            <tt>
                              <a href="{$docname}.png">
                                <xsl:value-of select="$docname"/>
                                <xsl:text>.png</xsl:text>
                              </a>
                            </tt>
                          </td>
                          <td>associated image</td>
                        </tr>
                        <!-- extractables -->
                        <xsl:if
                          test="/db:book/db:part[@xml:id='files']">
                          <tr>
                            <xsl:for-each
                              select="/db:book/db:part
                                      [@xml:id='files']
                                      /db:chapter[@xml:id
                                      and
                                      @xlink:href
                                      and
                                      db:programlisting]">
                              <td>
                                <tt>
                                  <a href="{@xlink:href}">
                                    <xsl:value-of
                                      select="@xlink:href"/>
                                  </a>
                                </tt>
                              </td>
                              <td>
                                <xsl:value-of select="@role"/>
                              </td>
                            </xsl:for-each>
                          </tr>
                        </xsl:if>
                        <xsl:if
                          test="/db:book/db:info/db:cover
                                /db:constraintdef[@xml:id='manifest']">
                          <xsl:for-each 
                            select="/db:book/db:info/db:cover/
                                    db:constraintdef
                                    [@xml:id='manifest']/
                                    db:simplelist/db:member">
                            <tr>
                              <td>
                                <tt>
                                  <a href="{.}">
                                    <xsl:value-of select="."/>
                                  </a>
                                </tt>
                              </td>
                              <td>
                                <xsl:value-of select="@role"/>
                              </td>
                            </tr>
                          </xsl:for-each>
                        </xsl:if>
                      </tbody>
                    </table>
                  </div>
                  <p>
                    <xsl:text>Use the CTAN zip file with 
                      automated installers like </xsl:text>
                    <em>tlmgr</em> 
                    <xsl:text> and MiK</xsl:text>
                    <xsl:copy-of select="$TeX"/>
                    <xsl:text>. Use the TDS zip file when 
                      installing to your </xsl:text>
                    <a href="{concat('http://latex.silmaril.ie',
                             '/formattinginformation/personal.html')}">
                      <xsl:text>Personal </xsl:text>
                      <xsl:copy-of select="$TeX"/>
                      <xsl:text> Directory</xsl:text>
                    </a>
                    <xsl:text>. The individual DTX and INS files are 
                      for manual installation.</xsl:text>
                  </p>
                  <ul class="icons">
                    <li>
                      <a href="MANIFEST">MANIFEST</a>
                    </li>
                    <li>
                      <a href="VERSION">VERSION</a>
                    </li>
                    <li>
                      <a href="README.md">README.md</a>
                    </li>
                    <li class="generated">
                      <xsl:text>ClassPack v </xsl:text>
                      <xsl:value-of select="$thisversion"/>
                      <br/>
                      <xsl:value-of select="format-date(current-date(),
                                            '[D01]-[M01]-[Y03]')"/>
                    </li>
                  </ul>
                  <ul class="actions">
                    <li>
                      <a class="button small primary scrolly" 
                        href="#downloads">Downloads</a>
                    </li>
                    <li>
                      <a class="button small scrolly" 
                        href="#more">Learn More</a>
                    </li>
                    <li>
                      <a class="button small scrolly" 
                        href="#contact">Contact us</a>
                    </li>
                    <li>
                      <a class="button small scrolly" 
                        href="#header">Home</a>
                    </li>
                  </ul>
                </div>
              </section>
            </div>
          </section>
          <footer id="footer">
            <ul class="icons">
              <li>
                <a href="news:comp.text.tex"
                  title="Usenet support" 
                  style="font-family:monospace;" 
                  class="icon solid fa-newspaper">
                  <span class="label">comp.text.tex</span>
                </a>
              </li>
              <li>
                <a href="https://mastodon.ie/@latex" 
                  title="Talk to @latex on Mastodon"
                  class="icon brands fa-deskpro">
                  <span class="label">Mastodon</span>
                </a>
              </li>
              <li>
                <a href="https://twitter.com/silmaril_ie" 
                  title="Talk to @silmaril_ie on Twitter"
                  class="icon brands fa-twitter">
                  <span class="label">Twitter</span>
                </a>
              </li>
              <li>
                <a 
                  href="mailto:latex@silmaril.ie?subject=LaTeX support" 
                  style="font-family:monospace;" 
                  title="Email latex@silmaril.ie" 
                  class="icon solid fa-envelope-open">
                  <span class="label">latex@silmaril.ie</span>
                </a>
              </li>
            </ul>
            <p class="copyright">
              <xsl:text>© </xsl:text>
              <xsl:value-of select="format-date($firstverdate,'[Y]')"/>
              <xsl:text>–</xsl:text>
              <xsl:value-of select="format-date(current-date(),'[Y]')"/>
              <xsl:text> </xsl:text>
              <a href="http://www.silmaril.ie/">Silmaril Consultants</a>
              <xsl:text>. Design: </xsl:text>
              <a href="http://html5up.net">HTML5 UP</a>
            </p>
          </footer>
          <script src="../assets/js/jquery.min.js"/>
          <script src="../assets/js/jquery.scrolly.min.js"/>
          <script src="../assets/js/browser.min.js"/>
          <script src="../assets/js/breakpoints.min.js"/>
          <script src="../assets/js/util.js"/>
          <script src="../assets/js/main.js"/>
        </body>
      </html>
    </xsl:result-document>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsection{Ending}
% \begin{CPKtemplate}{end}\label{template-db2dtx-end1}
% End of the \textsc{xslt} script.\par
%    \begin{macrocode}
  <xsl:template match="db:keywordset | db:keyword"/>
</xsl:stylesheet>
%    \end{macrocode}
% \end{CPKtemplate}
% \iffalse
%</db2dtxscript>
% \fi
% \iffalse
%<*db2bibtexscript>
% \fi
% \clearpage
% \section{The {\ttfamily{}db2bibtex.xsl} script}\label{db2bibtexscript}
% \setcounter{CodelineNo}{0}
% The templates for converting reference data to \BibTeX{}
% are kept in a separate file,
% {\ttfamily{}db2bibtex.xsl}\thinspace, because they can be reused
% with any \textsc{xslt} script handling
% \emph{DocBook} documents which use a
% bibliography. This file is \texttt{<xsl:include>}\index{xsl:include=\texttt{\char'074 xsl:include\char'076 } (element)}\index{elements:!xsl:include=\texttt{\char'074 xsl:include\char'076 }}d in \vref{db2dt-setup}.\par
% \begin{CPKcomment}{db2bibtexscript-comment}\label{comment-db2bibtexscript}
% Identify the file origin,
% date, time, etc.\par
%    \begin{macrocode}
<!-- The db2bibtex.xsl script (from the classpack package v.1.28, 2024-02-21) -->
<!-- Generated by ClassPack v.1.28 (2024-02-21) on 24-03-04T22:35:19 -->
%    \end{macrocode}
% These lines are automatically prepended to the file
% and may be removed if necessary,
% using a suitable editor.
% \end{CPKcomment}
% \subsection{XML Declaration, namespaces, and setup}
% The namespaces are the same as for the calling routine,
%   {\ttfamily{}db2dtx.xsl}\thinspace.\par
% \begin{CPKtemplate}{init}\label{template-db2bibtex-init1}
% Set up the namespaces, the same as for the main script.\par
%    \begin{macrocode}
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:db="http://docbook.org/ns/docbook"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  version="3.0">
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{vars}\label{template-db2bibtex-vars}
% We will need to test for apostrophes preceding
%     abbreviated years in conference titles, so for simplicity
%     we define it as a variable so it can be used in an
%     argument delimited by apostrophes in an attribute
%     delimited by double quotes, containing an \texttt{\&apos;}\index{apos=\texttt{\&apos;} (general entity)}\index{general entities:!apos=\texttt{\&apos;}}.\par
%    \begin{macrocode}
  <xsl:variable name="apostrophe">'</xsl:variable>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection{Citations}\label{citations}
% \begin{CPKtemplate}{db:biblioref}\label{template-db2bibtex-biblioref1}
% The \texttt{<biblioref>}\index{biblioref=\texttt{\char'074 biblioref\char'076 } (element)}\index{elements:!biblioref=\texttt{\char'074 biblioref\char'076 }} element type is used for
%       all citations, and passed directly to the \DescribeTemplate{makeref}{\ttfamily{}makeref}
%       named template. Attributes are [ab]used to provide for
%       the features available in \BibTeX{} and
%       \emph{biblatex}.\par
%    \begin{macrocode}
  <xsl:template match="db:biblioref">
    <xsl:call-template name="compensate-space"/>
    <xsl:call-template name="makeref"/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% Citations are formed by the named template \DescribeTemplate{makeref}{\ttfamily{}makeref}. It
%     expects values for attributes on the calling
%     \texttt{<biblioref>}\index{biblioref=\texttt{\char'074 biblioref\char'076 } (element)}\index{elements:!biblioref=\texttt{\char'074 biblioref\char'076 }} element as detailed in ‘\textbf{\textsf{\texttt{<biblioref>}\index{biblioref=\texttt{\char'074 biblioref\char'076 } (element)}\index{elements:!biblioref=\texttt{\char'074 biblioref\char'076 }}}}’, the fifth item in the list in \vref{bibrefs}.\par
% \begin{CPKtemplate}{makeref}\label{template-db2bibtex-makeref}
% This named template deals with the exceptions in
%       handling citations, and the variations allowed. There
%       are no checks for matching \texttt{<IDREF>}\index{IDREF=\texttt{\char'074 IDREF\char'076 } (element)}\index{elements:!IDREF=\texttt{\char'074 IDREF\char'076 }} and
%       \texttt{<ID>}\index{ID=\texttt{\char'074 ID\char'076 } (element)}\index{elements:!ID=\texttt{\char'074 ID\char'076 }} values, as these have already been tested
%       by the \textsc{xml} parser.\par
%    \begin{macrocode}
  <xsl:template name="makeref">
    <xsl:choose>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection*{Direct commands (multicite and fullcite)}
% \begin{CPKtemplate}{multicite}\label{template-db2bibtex-multicite}
% The first test is for citing multiple sources: in
%       \textsc{xml}, multiple \texttt{<IDREFS>}\index{IDREFS=\texttt{\char'074 IDREFS\char'076 } (element)}\index{elements:!IDREFS=\texttt{\char'074 IDREFS\char'076 }}
%       tokens are delimited by spaces, so these need converting
%       to the commas required by \LaTeX{}. Multiple references
%       at a single point always use the
%       {\ttfamily{}\textbackslash{}parencite} command, which encloses the
%       entire thing in a single set of parentheses.\par
%    \begin{macrocode}
      <xsl:when
        test="contains(normalize-space(@linkend),' ')">
        <xsl:text>\parencite{</xsl:text>
        <xsl:value-of
          select="translate(
                  normalize-space(@linkend),' ',',')"/>
        <xsl:text>}</xsl:text>
      </xsl:when>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{fullcite}\label{template-db2bibtex-fullcite}
% Full citation (long-form reference) is likewise
%       handled by a command, {\ttfamily{}\textbackslash{}fullcite}. The
%       use of partial references in footnoted citations is not
%       supported in
%       \emph{ClassPack}.\par
%    \begin{macrocode}
      <xsl:when test="@xrefstyle='full'">
        <xsl:text>\fullcite{</xsl:text>
        <xsl:value-of select="@linkend"/>
        <xsl:text>}</xsl:text>
      </xsl:when>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection*{Computed citations (full title,
%     short title, and authors)}
% \begin{CPKtemplate}{citedetail}\label{template-db2bibtex-citedetail}
% All remaining forms are handled by testing the
%       actual reference data in the relevant
%       \texttt{<biblioentry>}\index{biblioentry=\texttt{\char'074 biblioentry\char'076 } (element)}\index{elements:!biblioentry=\texttt{\char'074 biblioentry\char'076 }} element.\par
%    \begin{macrocode}
      <xsl:otherwise>
        <xsl:variable name="target" 
          select="//db:biblioentry
                  [@xml:id=current()/@linkend]"/>
        <xsl:choose>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{citetitle}\label{template-db2bibtex-citetitle}
% Citations of titles handled here are
%       \emph{full} titles: the default
%       {\ttfamily{}\textbackslash{}citetitle} in the next section
%       provides only the short title.\par
% Note that this is \emph{different}
%       from the {\ttfamily{}\textbackslash{}citetitle} element type of
%       \emph{DocBook} in
%       \vref{citetitle} which cites the \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }}
%       element of the entry but also allows a manually-typed
%       title (ie one for which there is no bibliographic entry
%       in the document).\par
%    \begin{macrocode}
          <xsl:when test="@xrefstyle='title'
                          or
                          @xrefstyle='titlecite'">
            <xsl:choose>
              <xsl:when
                test="$target/@xreflabel='article' or 
                      $target/@xreflabel='inbook' or 
                      $target/@xreflabel='incollection' or
                      $target/@xreflabel='inreference'">
                <xsl:text>`</xsl:text>
                <xsl:apply-templates 
                  select="($target/descendant::db:title)
                          [1]/node()"/>
                <xsl:text>'</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>\emph{</xsl:text>
                <xsl:apply-templates 
                  select="($target/descendant::db:title)
                          [1]/node()"/>
                <xsl:text>}</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:if test="@xrefstyle='titlecite'">
              <xsl:text>~(\citeyear{</xsl:text>
              <xsl:value-of select="@linkend"/>
              <xsl:text>})</xsl:text>
            </xsl:if>
          </xsl:when>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{citeshort}\label{template-db2bibtex-citeshort}
% Separate citation of the short title is done by
%       forming the citation manually.\par
%    \begin{macrocode}
          <xsl:when
            test="@xrefstyle='shorttitle'">
            <xsl:choose>
              <xsl:when
                test="$target/@xreflabel='article' or 
                      $target/@xreflabel='inbook' or 
                      $target/@xreflabel='incollection' or
                      $target/@xreflabel='inreference'">
                <xsl:text>`</xsl:text>
                <xsl:choose>
                  <xsl:when
                    test="$target
                          /descendant::db:titleabbrev">
                    <xsl:apply-templates 
                      select="($target
                              /descendant::db:titleabbrev)
                              [1]/node()"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:apply-templates 
                      select="($target
                              /descendant::db:title)
                              [1]/node()"/>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:text>'</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>\emph{</xsl:text>
                <xsl:choose>
                  <xsl:when
                    test="$target
                          /descendant::db:titleabbrev">
                    <xsl:apply-templates 
                      select="($target
                              /descendant::db:titleabbrev)
                              [1]/node()"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:apply-templates 
                      select="($target
                              /descendant::db:title)
                              [1]/node()"/>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:text>}</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:if test="@xrefstyle='titlecite'">
              <xsl:text>~(\citeyear{</xsl:text>
              <xsl:value-of select="@linkend"/>
              <xsl:text>})</xsl:text>
            </xsl:if>
          </xsl:when>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{citeauthors}\label{template-db2bibtex-citeauthors}
% Author citation just lists the authors in order.\par
%    \begin{macrocode}
          <xsl:when
            test="@xrefstyle='author' or
                  @xrefstyle='authors'">
            <xsl:for-each
              select="$target//db:author">
              <xsl:if
                test="preceding-sibling::db:author">
                <xsl:choose>
                  <xsl:when
                    test="following-sibling::db:author">
                    <xsl:if
                      test="count(../db:author)>2">
                      <xsl:text>, </xsl:text>
                    </xsl:if>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:if test="count(../db:author)>2">
                      <xsl:text>,</xsl:text>
                    </xsl:if>
                    <xsl:text> and </xsl:text>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:if>
              <xsl:apply-templates
                select="db:personname
                        /db:firstname/node() |
                        db:orgname/node() |
                        db:personname
                        /db:othername/node()"/>
              <xsl:text> </xsl:text>
              <xsl:value-of
                select="db:personname
                        /db:surname/node() |
                        db:orgdiv/node()"/>
            </xsl:for-each>
          </xsl:when>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{citesurnames}\label{template-db2bibtex-citesurnames}
% Surname-only citation likewise.\par
% \par\smallskip\leavevmode
% \CPKrunningecho{citesurnames}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Add punctuation and spacing for multiple authors}}\par\smallskip
%    \begin{macrocode}
          <xsl:when
            test="@xrefstyle='shortauthor' or
                  @xrefstyle='shortauthors'">
            <xsl:for-each
              select="$target//db:author
                      /db:personname">
              <xsl:value-of
                select="db:surname"/>
            </xsl:for-each>
          </xsl:when>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection*{Standard commands (cite, parencite,
%     textcite)}
% \begin{CPKtemplate}{citeother}\label{template-db2bibtex-citeother}
% Everything else is handled by the standard commands
%       ({\ttfamily{}\textbackslash{}cite}, {\ttfamily{}\textbackslash{}parencite},
%       and {\ttfamily{}\textbackslash{}textcite}).\par
%    \begin{macrocode}
          <xsl:otherwise>
            <xsl:if
              test="(//db:bibliography[@arch='biblatex']
                    or
                    //db:bibliolist[@arch='biblatex'])
                    and @xrefstyle='field'
                    and contains(@remap,'title')">
              <xsl:text>\emph{</xsl:text>
            </xsl:if>
            <xsl:text>\</xsl:text>
            <xsl:choose>
              <xsl:when
                test="(//db:bibliography[@arch='biblatex']
                       or
                       //db:bibliolist[@arch='biblatex'])
                      and
                      (@xrefstyle='text'
                       or
                       @xrefstyle='paren'
                       or
                       @xrefstyle='author(year)'
                       or
                       @xrefstyle='foot')">
                <xsl:value-of select="@xrefstyle"/>
              </xsl:when>
              <xsl:when
                test="(//db:bibliography[@arch='biblatex']
                       or
                       //db:bibliolist[@arch='biblatex'])
                      and not(@xrefstyle)">
                <xsl:text>paren</xsl:text>
              </xsl:when>
              <xsl:when
                test="ancestor::db:section and @xrefstyle">
                <xsl:value-of select="@xrefstyle"/>
              </xsl:when>
            </xsl:choose>
            <xsl:text>cite</xsl:text>
            <xsl:choose>
              <xsl:when
                test="(//db:bibliography[@arch='biblatex']
                      or
                      //db:bibliolist[@arch='biblatex'])
                      and @xrefstyle='field' and @remap">
                <xsl:text>field</xsl:text>
              </xsl:when>
              <xsl:when
                test="(//db:bibliography[@arch='biblatex']
                      or
                      //db:bibliolist[@arch='biblatex'])
                      and @xrefstyle='citetitle'">
                <xsl:text>title</xsl:text>
              </xsl:when>
              <xsl:when
                test="//db:bibliography
                      [@arch='bibtex' or not(@arch)]
                      and
                      @xrefstyle='text'">
                <xsl:text>A</xsl:text>
              </xsl:when>
            </xsl:choose>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{precite}\label{template-db2bibtex-precite}
% If \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} is given
%       explicitly, make it the pre-citation value.\par
%    \begin{macrocode}
            <xsl:if test="@role">
              <xsl:text>[</xsl:text>
              <xsl:choose>
                <xsl:when test="@role='firstname'">
                  <xsl:value-of
                    select="//db:bibliography
                            /db:biblioentry
                            [@xml:id=current()/@linkend]
                            //db:author[1]//db:firstname"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="@role"/>
                </xsl:otherwise>
              </xsl:choose>
              <xsl:text>]</xsl:text>
            </xsl:if>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{citeunits}\label{template-db2bibtex-citeunits}
% Units (pages, chapters, etc) must be done as the
%     optional argument.\par
%    \begin{macrocode}
            <xsl:if test="(@units and @begin)
                          or @annotations">
              <xsl:if test="not(@role)">
                <xsl:text>[]</xsl:text>
              </xsl:if>
              <xsl:text>[</xsl:text>
              <xsl:value-of select="@units"/>
              <xsl:if test="@units='p' and @end">
                <xsl:text>p.</xsl:text>
              </xsl:if>
              <xsl:text>\thinspace </xsl:text>
              <xsl:value-of select="@begin"/>
              <xsl:if test="@end">
                <xsl:text>--</xsl:text>
                <xsl:value-of select="@end"/>
              </xsl:if>
              <xsl:if test="@annotations">
                <xsl:if test="@units and @begin">
                  <xsl:text>, </xsl:text>
                </xsl:if>
                <xsl:value-of 
                  select="normalize-space(
                          @annotations)"/>
              </xsl:if>
              <xsl:text>]</xsl:text>
            </xsl:if>
            <!-- floating URI afterwards -->
            <xsl:if test="@xlink:href">
              <xsl:text>[\protect\url{</xsl:text>
              <xsl:value-of 
                select="replace(@xlink:href,'#','\\#')"/>
              <xsl:text>}]</xsl:text>
            </xsl:if>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{citelink}\label{template-db2bibtex-citelink}
% The final part is the actual identity token.\par
%    \begin{macrocode}
            <xsl:text>{</xsl:text>
            <xsl:value-of 
              select="translate(
                      normalize-space(@linkend),
                      ' ',',')"/>
            <xsl:text>}</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if
      test="(//db:bibliography[@arch='biblatex']
            or
            //db:bibliolist[@arch='biblatex'])
            and @xrefstyle='field' and @remap">
      <xsl:text>{</xsl:text>
      <xsl:value-of select="@remap"/>
      <xsl:text>}</xsl:text>
      <xsl:if test="contains(@remap,'title')">
        <xsl:text>}</xsl:text>
      </xsl:if>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{bibliolist}\label{template-db2bibtex-bibliolist}
% A \texttt{<bibliolist>}\index{bibliolist=\texttt{\char'074 bibliolist\char'076 } (element)}\index{elements:!bibliolist=\texttt{\char'074 bibliolist\char'076 }} can occur elsewhere in the
%       document, so we omit it here; and the exclusion for
%       \texttt{<section>}\index{section=\texttt{\char'074 section\char'076 } (element)}\index{elements:!section=\texttt{\char'074 section\char'076 }} is for the warnings in
%       RFC2119.\par
%    \begin{macrocode}
  <xsl:template match="db:bibliolist
                       [parent::db:section]"/>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{bibliography}\label{template-db2bibtex-bibliography}
% The bibliography container may have a title, so use
%       it.\par
%    \begin{macrocode}
  <xsl:template 
    match="db:bibliography | 
           db:bibliolist
           [not(ancestor::db:bibliography) 
            and
            not(parent::db:section)]">
    <xsl:if test="db:title">
      <xsl:value-of select="$armour"/>
      <xsl:text>\renewcommand{\bibname}{</xsl:text>
      <xsl:value-of select="db:title"/>
      <xsl:text>}&#xa;</xsl:text>
    </xsl:if>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{biblioallcite}\label{template-db2bibtex-biblioallcite}
% If there are some \texttt{<exceptionname>}\index{exceptionname=\texttt{\char'074 exceptionname\char'076 } (element)}\index{elements:!exceptionname=\texttt{\char'074 exceptionname\char'076 }}\kern1pt{}s but no
%       direct references to RFC2119, \emph{or}
%       if there are no actual citations (\texttt{<biblioref>}\index{biblioref=\texttt{\char'074 biblioref\char'076 } (element)}\index{elements:!biblioref=\texttt{\char'074 biblioref\char'076 }},
%       \texttt{<citetitle>}\index{citetitle=\texttt{\char'074 citetitle\char'076 } (element)}\index{elements:!citetitle=\texttt{\char'074 citetitle\char'076 }}, or \texttt{<blockquote>}\index{blockquote=\texttt{\char'074 blockquote\char'076 } (element)}\index{elements:!blockquote=\texttt{\char'074 blockquote\char'076 }}), then
%       list everything provided.\par
%    \begin{macrocode}
    <xsl:if 
      test="(//db:exceptionname 
             and not(//db:biblioref
                      [@linkend='rfc2119'])) 
            or
            (count(//db:biblioref) +
             count(//db:citetitle[@linkend]) +
             count(//db:blockquote[@linkend])=0)">
      <xsl:value-of select="$armour"/>
      <xsl:text>\nocite{*}&#xa;</xsl:text>
    </xsl:if>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{biblionewpage}\label{template-db2bibtex-biblionewpage}
% When called from {\ttfamily{}db2dtx.xsl}\thinspace,
%       start a new page and set the right-hand margin ragged
%       (based on \DescribeVariable{armour}{\ttfamily{}\$armour} being non-null in
%       \emph{ClassPack}).\par
%    \begin{macrocode}
    <xsl:if test="$armour!=''">
      <xsl:value-of select="$armour"/>
      <xsl:text>\clearpage&#xa;</xsl:text>
      <xsl:value-of select="$armour"/>
      <xsl:text>\raggedright&#xa;</xsl:text>
    </xsl:if>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{bibliofile}\label{template-db2bibtex-bibliofile}
% Set the name for the output \BibTeX{} file: either
%       specified in \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} or
%       inherited from the \DescribeVariable{name}{\ttfamily{}\$name} variable.\par
%    \begin{macrocode}
    <xsl:variable name="file">
      <xsl:choose>
        <xsl:when test="@xlink:href">
          <xsl:value-of select="@xlink:href"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$name"/>
          <xsl:text>.bib</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{biblioprintbiblatex}\label{template-db2bibtex-biblioprintbiblatex}
% The default is to assume \textsf{biblatex}
%       is used: any other \textsf{biblatex}
%       specifications {\sffamily \textsc{must}} be
%       given in the Preamble. The \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}} attribute may hold the
%       name of an alternative
%       {\ttfamily{}\textbackslash{}printbibliography} header format
%       defined elsewhere, in which case use the
%       {\ttfamily{}\textbackslash{}RaggedRight} from
%       \textsf{ragged2e}; otherwise just use normal
%       {\ttfamily{}\textbackslash{}raggedright}.\par
%    \begin{macrocode}
    <xsl:choose>
      <xsl:when test="local-name()='bibliography' and
                      (@arch='biblatex' or not(@arch))">
        <xsl:value-of select="$armour"/>
        <xsl:choose>
          <!-- @remap can specify an alternate style like shortbib -->
          <xsl:when test="@remap">
            <xsl:text>\RaggedRight</xsl:text>
            <xsl:text>\markboth{\refname}{\refname}</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>\raggedright</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>\printbibliography</xsl:text>
        <xsl:if test="@remap">
          <xsl:text>[heading=</xsl:text>
          <xsl:value-of select="@remap"/>
          <xsl:text>]</xsl:text>
        </xsl:if>
        <xsl:text>\clearpage&#xa;</xsl:text>
      </xsl:when>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{biblioprintbibtex}\label{template-db2bibtex-biblioprintbibtex}
% For old \BibTeX{} support (soon to be deprecated in
%       \emph{ClassPack}), construct the
%       {\ttfamily{}\textbackslash{}bibliography} and
%     {\ttfamily{}\textbackslash{}bibliographystyle} commands. The default
%       style is \textsc{apa}.\par
%    \begin{macrocode}
      <xsl:when 
        test="local-name()='bibliography'
              and @arch='bibtex'">
        <xsl:value-of select="$armour"/>
        <xsl:text>\bibliography{</xsl:text>
        <xsl:value-of 
          select="substring-before($file,'.bib')"/>
        <xsl:text>}&#xa;</xsl:text>
        <xsl:value-of select="$armour"/>
        <xsl:text>\bibliographystyle{</xsl:text>
        <xsl:choose>
          <xsl:when test="@label">
            <xsl:value-of select="@label"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>apacite</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>}&#xa;</xsl:text>
      </xsl:when>
    </xsl:choose>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{bibliodata}\label{template-db2bibtex-bibliodata}
% Output the bibliography in \BibTeX{} format, grouping
%       the entries by type for convenience, and sorting by
%       surname of first author.\par
% Added
%       inclusion of RFC2119.\par
%    \begin{macrocode}
    <xsl:result-document format="textFormat" 
      href="{$file}">
      <xsl:for-each-group group-by="@xreflabel"
        select="db:biblioentry">
        <xsl:sort select="current-grouping-key()"/>
        <xsl:text>&#xa;%% </xsl:text>
        <xsl:value-of 
          select="upper-case(current-grouping-key())"/>
        <xsl:text>&#xa;</xsl:text>
        <xsl:apply-templates select="current-group()">
          <xsl:sort 
            select="descendant::db:author[1]
                    /db:personname/db:surname
                    |
                    descendant::db:author[1]
                    /db:orgname"/>
          <xsl:sort select="db:date/@YYYY-MM-DD"/>
        </xsl:apply-templates>
      </xsl:for-each-group>
      <xsl:if test="//db:exceptionname 
                    and not(db:biblioentry[@xml:id='rfc2119'])">
        <xsl:text>%% Added automatically</xsl:text>
        <xsl:apply-templates 
          select="document('rfc2119.xml')
                  /db:section/db:bibliolist
                  /db:biblioentry"/>
      </xsl:if>
    </xsl:result-document>
  </xsl:template>

  <xsl:template match="db:bibliography/db:title"/>

%    \end{macrocode}
% The title has already been dealt with above, so
%       ignore it here.\par
% \end{CPKtemplate}
% \subsubsection{Bibliographic entries}
% All fields are output in the standard \BibTeX{}
%   format.\par
% \begin{CPKtemplate}{biblioentry}\label{template-db2bibtex-biblioentry}
% Some interventions are needed to accommodate
%       standards, patents, and web pages. After the field data,
%       there is scope to use the content of the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute for the
%       publisher of a standard, something not otherwise
%       provided for. Similarly, for an article in a Proceedings
%       where the publisher is not given, add the value
%       `Unpublished'. Also, if a date is
%       not given, but conference dates
%       \emph{are}, try to detect the
%       `right' date.\par
%    \begin{macrocode}
  <xsl:template match="db:biblioentry">
    <xsl:text>&#xa;@</xsl:text>
    <xsl:choose>
      <xsl:when test="@xreflabel='standard' and @role">
        <xsl:text>techreport</xsl:text>
      </xsl:when>
      <xsl:when test="@xreflabel='patent' 
                      or 
                      @xreflabel='webpage'">
        <xsl:text>misc</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="@xreflabel"/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>{</xsl:text>
    <xsl:value-of select="@xml:id"/>
    <xsl:apply-templates/>
    <xsl:if test="@xreflabel='standard' and @role">
      <xsl:text>,&#xa;  publisher &#x9; = {</xsl:text>
      <xsl:value-of select="@role"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:if test="(@xreflabel='inproceedings' 
                   or 
                   @xreflabel='inreference')
                  and not(descendant::db:publisher) 
                  and not(descendant::db:publishername) 
                  and not(descendant::db:orgname)
                  and not(descendant::db:volumenum)
                  and not(descendant::db:issuenum)">
      <xsl:text>,&#xa;  publisher &#x9; = {Unpublished}</xsl:text>
    </xsl:if>
    <xsl:if test="not(descendant::db:date) 
              and not(descendant::db:confnum[number(.)>999])
              and descendant::db:confdates">
      <xsl:for-each select="descendant::db:confdates[1]">
        <xsl:call-template name="dodate"/>
      </xsl:for-each>
    </xsl:if>
    <xsl:text>&#xa;}&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{bibliomisc}\label{template-db2bibtex-bibliomisc}
% If the \texttt{bibliomisc}\index{bibliomisc=\texttt{\char'074 bibliomisc\char'076 } (element)}\index{elements:!bibliomisc=\texttt{\char'074 bibliomisc\char'076 }} element
%       type is used, make it the reference type.\par
%    \begin{macrocode}
  <xsl:template match="db:bibliomisc">
    <xsl:text>,&#xa;  type &#x9; = {</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{bibliosets}\label{template-db2bibtex-bibliosets}
% The \texttt{<biblioset>}\index{biblioset=\texttt{\char'074 biblioset\char'076 } (element)}\index{elements:!biblioset=\texttt{\char'074 biblioset\char'076 }} element keeps article- or
%       chapter-specific data separate from that of the
%       enclosing journal, book, etc. In this case, a special
%       treatment is needed for facsimiles and topic-chapters in
%       books.\par
% \par\smallskip\leavevmode
% \CPKrunningecho{bibliosets}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Use of bibliosets needs rewriting}}\par\smallskip
%    \begin{macrocode}
  <xsl:template match="db:biblioset | db:bibliomset">
    <xsl:choose>
      <xsl:when test="@relation='facsimile'">
        <xsl:text>,&#xa;  note &#x9; = {</xsl:text>
        <xsl:text>Facsimile edition </xsl:text>
        <xsl:if test="db:title[@role='translation']">
          <xsl:text>`</xsl:text>
          <xsl:value-of select="db:title"/>
          <xsl:text>'</xsl:text>
        </xsl:if>
        <xsl:if test="db:publisher">
          <xsl:text>, </xsl:text>
          <xsl:value-of 
            select="db:publisher/db:publishername"/>
          <xsl:text>, </xsl:text>
          <xsl:value-of select="db:publisher/db:address"/>
        </xsl:if>
        <xsl:if test="db:date">
          <xsl:text>, </xsl:text>
          <xsl:value-of select="db:date"/>
        </xsl:if>
        <xsl:if test="db:address">
          <xsl:text>, in </xsl:text>
          <xsl:value-of select="db:address"/>
        </xsl:if>
        <xsl:text>.}</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:if test="@relation='inbook' and @remap">
          <xsl:text>,&#xa;  chapter &#x9; = {</xsl:text>
          <xsl:value-of select="@remap"/>
          <xsl:text>}</xsl:text>
        </xsl:if>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection*{Authors}
% \begin{CPKtemplate}{biblioauthgroup}\label{template-db2bibtex-biblioauthgroup}
% For multiple authors, write the names first, then
%       try to group affiliations so as not to duplicate
%       them.\par
% \par\smallskip\leavevmode
% \CPKrunningecho{biblioauthgroup}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Rewrite this using grouping}}\par\smallskip
%    \begin{macrocode}
  <xsl:template match="db:biblioentry//db:authorgroup">
    <xsl:apply-templates/>
    <xsl:if test="(db:author|db:editor)//db:affiliation">
      <xsl:text>,&#xa;  affiliation &#x9; = {</xsl:text>
      <xsl:for-each 
        select="(db:author|db:editor)//db:affiliation">
        <xsl:variable name="bibentry"
          select="generate-id(ancestor::db:biblioentry)"/>
        <xsl:if 
          test="count(preceding::db:affiliation
                [generate-id(ancestor::db:biblioentry)
                 =$bibentry]) > 0">
          <xsl:text> and </xsl:text>
        </xsl:if>
        <xsl:if test="db:orgdiv">
          <xsl:apply-templates select="db:orgdiv/node()"/>
          <xsl:text>, </xsl:text>
        </xsl:if>
        <xsl:apply-templates select="db:orgname/node()"/>
        <xsl:if test="db:address">
          <xsl:text>, </xsl:text>
          <xsl:apply-templates select="db:address/node()"/>
        </xsl:if>
      </xsl:for-each>
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{biblioauthed}\label{template-db2bibtex-biblioauthed}
% For authors and editors, start by detecting the
%       first of its type and punctuate accordingly.\par
%    \begin{macrocode}
  <xsl:template 
    match="db:biblioentry//db:author | 
           db:biblioentry//db:editor |
           db:biblioentry//db:authorgroup/db:author | 
           db:biblioentry//db:authorgroup/db:editor">
    <!-- label if first -->
    <xsl:if 
      test="count(preceding-sibling::*
            [name()=current()/name()])=0">
      <xsl:text>,&#xa;  </xsl:text>
      <xsl:value-of select="name()"/>
      <xsl:text> &#x9; = {</xsl:text>
    </xsl:if>
    <!-- separator otherwise -->
    <xsl:if 
      test="preceding-sibling::*[name()=current()/name()]">
      <xsl:text> and </xsl:text>
    </xsl:if>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{biblioauthsolo}\label{template-db2bibtex-biblioauthsolo}
% Do each person one at a time: first name first, then
%       any other name, then surname. Organisations as authors
%       get tested for acronym status. Names containing spaces,
%       or signalled by the \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}}
%       attribute, get additional curly braces for protection
%       against capitalising routines in \BibTeX{}.\par
%    \begin{macrocode}
    <!-- each person, if there are any (maybe orgname) -->
    <xsl:for-each select="db:personname">
      <!-- normal first name -->
      <xsl:if test="db:firstname">
        <xsl:choose>
          <xsl:when test="db:firstname/@role='as-is'">
            <xsl:text>{</xsl:text>
            <xsl:value-of select="db:firstname"/>
            <xsl:text>}</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="db:firstname"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
      <!-- optional other name -->
      <xsl:if test="db:othername">
        <xsl:text> {</xsl:text>
        <xsl:value-of select="db:othername"/>
        <xsl:text>}</xsl:text>
      </xsl:if>
      <!-- special handling of spaces and punctuation in surnames -->
      <xsl:choose>
        <xsl:when 
          test="contains(db:surname,' ') 
                or 
                contains(db:surname,' ')">
          <xsl:text> {</xsl:text>
          <xsl:value-of select="db:surname"/>
          <xsl:text>}</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text> </xsl:text>
          <xsl:value-of select="db:surname"/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:if test="db:honorific">
        <xsl:text> </xsl:text>
        <xsl:value-of select="db:honorific"/>
      </xsl:if>
    </xsl:for-each>
    <xsl:choose>
      <!-- institutional organisation name -->
      <xsl:when test="db:orgname">
        <xsl:text>{</xsl:text>
        <xsl:choose>
          <!-- acronym -->
          <xsl:when test=".=upper-case(.)">
            <xsl:text>\acro{</xsl:text>
            <xsl:apply-templates/>
            <xsl:text>}</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:if test="db:orgdiv">
          <xsl:text> {</xsl:text>
          <xsl:apply-templates 
            select="db:orgdiv/node()"/>
          <xsl:text>}</xsl:text>
        </xsl:if>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <!-- just text? -->
      <xsl:otherwise>
        <xsl:text> </xsl:text>
      </xsl:otherwise>
    </xsl:choose>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{biblioauthterm}\label{template-db2bibtex-biblioauthterm}
% Terminate the authors with the curly
%     brace. Affiliations have already been dealt with.\par
%    \begin{macrocode}
    <xsl:if test="count(following-sibling::*
                  [name()=current()/name()])=0">
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="db:biblioentry//db:affiliation"/>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{bibliocorpauth}\label{template-db2bibtex-bibliocorpauth}
% Handle corporate authors the same as human authors,
%       and provide a short author field if there is a value in
%       \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}}.\par
%    \begin{macrocode}
  <xsl:template match="db:biblioentry//db:corpauthor">
    <xsl:if 
      test="count(preceding-sibling::db:author |
                  preceding-sibling::db:corpauthor)=0">
      <xsl:text>,&#xa;  author &#x9; = {{</xsl:text>
    </xsl:if>
    <xsl:if test="preceding-sibling::db:author |
                  preceding-sibling::db:corpauthor">
      <xsl:text> and </xsl:text>
    </xsl:if>
    <xsl:choose>
      <xsl:when test="@remap">
        <xsl:value-of select="@remap"/>
      </xsl:when>
      <xsl:when test="not(@remap)">
        <xsl:text>{</xsl:text>
        <xsl:apply-templates/>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if 
      test="count(following-sibling::db:author |
                  following-sibling::db:corpauthor)=0">
      <xsl:text>}}</xsl:text>
      <xsl:if 
        test="@remap and 
              count(preceding-sibling::db:author |
                    preceding-sibling::db:corpauthor)=0">
        <xsl:text>,&#xa;  shortauthor &#x9; = {{</xsl:text>
        <xsl:value-of select="@remap"/>
        <xsl:text>}}</xsl:text>
      </xsl:if>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{biblioorgs}\label{template-db2bibtex-biblioorgs}
% Organisations map to
%     {\ttfamily{}institution} and can have
%       divisions (like a subtitle). \par
%    \begin{macrocode}
  <xsl:template match="db:org">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="db:org/db:orgname">
    <xsl:text>,&#xa;  institution &#x9; = {{</xsl:text>
    <xsl:apply-templates/>
    <xsl:if test="following-sibling::db:orgdiv">
      <xsl:text>, </xsl:text>
      <xsl:apply-templates 
        select="following-sibling::db:orgdiv/node()"/>
    </xsl:if>
    <xsl:text>}}</xsl:text>
  </xsl:template>

  <xsl:template match="db:org/db:orgdiv | db:author/db:orgdiv"/>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{bibliotitles}\label{template-db2bibtex-bibliotitles}
% This template tries to deal with all titles
%       anywhere, using position to dictate the field name. A
%       \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} can override the field
%       name; article titles are inside their own
%       \texttt{<biblioset>}\index{biblioset=\texttt{\char'074 biblioset\char'076 } (element)}\index{elements:!biblioset=\texttt{\char'074 biblioset\char'076 }}; a title in an article entry which
%       is \emph{outside} a \texttt{<biblioset>}\index{biblioset=\texttt{\char'074 biblioset\char'076 } (element)}\index{elements:!biblioset=\texttt{\char'074 biblioset\char'076 }}
%       is the name of the {\ttfamily{}journal}…\par
% \par\smallskip\leavevmode
% \CPKrunningecho{bibliotitles}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: This needs to use biblioset for journals}}\par\smallskip
% …books, collections, and proceedings similarly use
%       {\ttfamily{}booktitle}. Titles
%       {\sffamily \textsc{may}} contain markup, so
%       this template distinguishes. That deals with naming and
%       content,\par
%    \begin{macrocode}
  <xsl:template match="db:biblioentry//db:title">
    <xsl:text>,&#xa;  </xsl:text>
    <xsl:choose>
      <xsl:when test="@role">
        <xsl:value-of select="@role"/>
      </xsl:when>
      <xsl:when 
        test="parent::db:biblioset[@relation='article']">
        <xsl:text>title</xsl:text>
      </xsl:when>
      <xsl:when 
        test="parent::db:biblioentry/@xreflabel='article' 
              or
              parent::db:biblioset[@relation='journal']">
        <xsl:text>journaltitle</xsl:text>
      </xsl:when>
      <xsl:when 
        test="(parent::db:biblioset/@relation='book' or
               parent::db:biblioset/@relation='reference')
              and (
                ancestor::db:biblioentry/
                          @xreflabel='incollection' 
                or
                ancestor::db:biblioentry/
                          @xreflabel='inproceedings'
                or
                ancestor::db:biblioentry/
                          @xreflabel='inreference')">
        <xsl:text>booktitle</xsl:text>
      </xsl:when>
      <xsl:when 
        test="parent::db:biblioentry and 
              parent::db:biblioentry/db:biblioset
              [@relation='article']">
        <xsl:text>booktitle</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>title</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text> &#x9; = {{</xsl:text>
    <xsl:choose>
      <xsl:when test="count(*)=0">
        <xsl:value-of select="normalize-space(.)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{bibliosubtitles}\label{template-db2bibtex-bibliosubtitles}
% If the application is using [old] \BibTeX{} (not
%       \textsf{biblatex}) — as evidenced by the \texttt{@label}\index{label=\texttt{\char'100 label} (attribute)}\index{attributes:!label=\texttt{\char'100 label}} set to \texttt{"apacite"}\index{apacite=\texttt{"apacite"} (attribute value)}\index{attribute values:!apacite=\texttt{"apacite"}} — append any subtitle
%       separated by a colon. This is non-relevant when using
%       \textsf{biblatex} which has its own {\ttfamily{}subtitle} field.\par
%    \begin{macrocode}
    <xsl:if test="ancestor::db:bibliography
                  /@label='apacite'">
      <xsl:for-each 
        select="following-sibling::db:subtitle
                [@role=current()/@role or 
                (not(@role) and not(current()/@role))]">
        <xsl:choose>
          <xsl:when test="starts-with(.,'(')">
            <xsl:text> </xsl:text>
          </xsl:when>
          <xsl:when test="@remap">
            <xsl:text> \emph{</xsl:text>
            <xsl:value-of select="@remap"/>
            <xsl:text>} </xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>: </xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>&#xa; &#x9; </xsl:text>
        <xsl:choose>
          <xsl:when test="count(*)=0">
            <xsl:value-of select="normalize-space(.)"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </xsl:if>
    <xsl:text>}}</xsl:text>
  </xsl:template>

  <xsl:template 
    match="db:biblioentry//db:subtitle
           [ancestor::db:bibliography
            /@label='apacite']"/>

  <xsl:template 
    match="db:biblioentry//db:subtitle
           [not(ancestor::db:bibliography
                /@label='apacite')]">
    <xsl:choose>
      <xsl:when 
        test="parent::db:biblioset
              [@relation='book' 
               or 
               @relation='article']">
        <xsl:text>,&#xa;  subtitle &#x9; = {{</xsl:text>
      </xsl:when>
      <xsl:when 
        test="parent::db:biblioset
              [@relation='journal']">
        <xsl:text>,&#xa;  journalsubtitle &#x9; = {{</xsl:text>
      </xsl:when>
      <xsl:when 
        test="parent::db:biblioentry
              [@xreflabel='inbook' 
               or 
               @xreflabel='incollection' 
               or 
               @xreflabel='inreference']
              and
              parent::db:biblioentry/db:biblioset
              [@relation='article']">
        <xsl:text>,&#xa;  booksubtitle &#x9; = {{</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>,&#xa;  subtitle &#x9; = {{</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates/>
    <xsl:text>}}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{biblioshorttitles}\label{template-db2bibtex-biblioshorttitles}
% Known short titles are retained
%       (\textsf{biblatex} only; ignored by
%       \BibTeX{}).\par
%    \begin{macrocode}
  <xsl:template match="db:titleabbrev">
    <xsl:text>,&#xa;  shorttitle &#x9; = {{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{bibliosources}\label{template-db2bibtex-bibliosources}
% \begingroup\raggedright[\url{db:biblioid} 
% and \url{db:isbn} 
% and \url{db:issn} 
% ]\par\endgroup
% Support for source references
%       (\textsc{isbn}, \textsc{issn},
%       \textsc{doi}, etc) differs between \BibTeX{}
%       and \textsf{biblatex}. First, set the
%       fieldname according to the way it is encoded; then add
%       extra curly braces for a {\ttfamily{}titleaddon} to prevent it
%       being interfered with; then add any prefix needed (eg
%       LoC); add a {\ttfamily{}\textbackslash{}url} command if it’s a
%       \textsc{uri} in a different field; and finally
%       add the date accessed, if any.\par
%    \begin{macrocode}
  <xsl:template 
    match="db:biblioid | db:isbn | db:issn">
    <xsl:text>,&#xa;  </xsl:text>
    <!-- fieldname -->
    <xsl:choose>
      <xsl:when test="@class='uri'">
        <xsl:text>url</xsl:text>
      </xsl:when>
      <xsl:when test="@class='doi'">
        <xsl:value-of select="@class"/>
      </xsl:when>
      <xsl:when test="@class='pubsnumber'">
        <xsl:text>titleaddon</xsl:text>
      </xsl:when>
      <xsl:when test="@class='other'">
        <xsl:text>titleaddon</xsl:text>
      </xsl:when>
      <xsl:when 
        test="local-name()='isbn' or 
              @class='isbn' or
              ancestor::db:biblioentry/@xreflabel='book'">
        <xsl:text>isbn</xsl:text>
      </xsl:when>
      <xsl:when 
        test="local-name()='issn' or
              @class='issn' or
              ancestor::db:biblioentry/@xreflabel='article'">
        <xsl:text>issn</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>number</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text> &#x9; = {</xsl:text>
    <!-- shield -->
    <xsl:if test="@class='pubsnumber'">
      <xsl:text>{</xsl:text>
    </xsl:if>
    <!-- contents -->
    <xsl:choose>
      <xsl:when test="@class='other' and @otherclass">
        <xsl:value-of select="@otherclass"/>
        <xsl:text> </xsl:text>
      </xsl:when>
      <xsl:when test="@class='libraryofcongress'">
        <xsl:text>LoC</xsl:text>
        <xsl:text>: </xsl:text>
      </xsl:when>
    </xsl:choose>
    <!-- if content is a URI but it's not a URI field -->
    <xsl:if 
      test="matches(.,'^http[s]?://') 
            and 
            not(@class='uri')">
      <xsl:text>\url{</xsl:text>
    </xsl:if>
    <!-- now the actual value -->
    <xsl:choose>
      <xsl:when test="@xlink:href">
        <xsl:value-of select="@xlink:href"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="."/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if 
      test="matches(.,'^http[s]?://') 
            and 
            not(@class='uri')">
      <xsl:text>}</xsl:text>
    </xsl:if>
    <!-- shield -->
    <xsl:if test="@class='pubsnumber'">
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>}</xsl:text>
    <!-- generate additional fields: urldate -->
    <xsl:choose>
      <xsl:when 
        test="@YYYY-MM-DD 
              and 
              (ancestor::db:bibliography/@label='apacite'
               or 
               ancestor::db:bibliography/@label='apa')">
        <xsl:choose>
          <xsl:when 
            test="ancestor::db:bibliography/@label='apacite'">
            <xsl:text>,&#xa;  lastchecked &#x9; = {</xsl:text>
            <xsl:value-of 
              select="format-date(@YYYY-MM-DD,'[D] [MNn] [Y]')"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>,&#xa;  urldate &#x9; = {</xsl:text>
            <xsl:value-of select="@YYYY-MM-DD"/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:when 
        test="@YYYY-MM-DD 
              and 
              not(ancestor::db:biblioentry//db:date)">
        <xsl:text>,&#xa;  year &#x9; = {</xsl:text>
        <xsl:value-of 
          select="format-date(@YYYY-MM-DD,'[Y]')"/>
        <xsl:text>}</xsl:text>
        <xsl:if test="string-length(@YYYY-MM-DD)>5">
          <xsl:text>,&#xa;  month &#x9; = {</xsl:text>
          <!-- month with MNn is wrong for biber -->
          <xsl:value-of 
            select="format-date(@YYYY-MM-DD,'[M]')"/>
          <xsl:text>}</xsl:text>
        </xsl:if>
      </xsl:when>
    </xsl:choose>
    <!-- note when it's a Usenet newsgroup -->
    <xsl:if test="matches(.,'^news:')">
      <xsl:text>,&#xa;  note &#x9; = {</xsl:text>
      <xsl:text>In Usenet newsgroup \texttt{</xsl:text>
      <xsl:value-of 
        select="replace(substring-after(.,'news:')
                          ,'[^a-z\.].*$','')"/>
      <xsl:text>}, also available from Google Groups</xsl:text>
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection*{Publishers}
% \begin{CPKtemplate}{publisher}\label{template-db2bibtex-publisher}
% For the {\ttfamily{}misc} document type,
%       use the {\ttfamily{}howpublished} field;
%       otherwise pass through to the content elements.\par
%    \begin{macrocode}
  <xsl:template match="db:publisher">
    <xsl:choose>
      <xsl:when 
        test="ancestor::db:biblioentry/@xreflabel='misc'">
        <xsl:text>,&#xa;  howpublished &#x9; = {</xsl:text>
        <xsl:apply-templates select="db:address/node()"/>
        <xsl:text>: </xsl:text>
        <xsl:apply-templates 
          select="db:publishername/node()"/>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{publishername}\label{template-db2bibtex-publishername}
% Again, set the field names for exceptions first.\par
%    \begin{macrocode}
  <xsl:template match="db:publishername">
    <xsl:text>,&#xa;  </xsl:text>
    <xsl:choose>
      <xsl:when 
        test="ancestor::db:biblioentry/
              @xreflabel='techreport' 
              or
              ancestor::db:biblioentry/
              @xreflabel='standard'
              or
              ancestor::db:biblioentry/
              @xreflabel='manual'">
        <xsl:text>organization</xsl:text>
      </xsl:when>
      <xsl:when 
        test="ancestor::db:biblioentry/
              @xreflabel='phdthesis' 
              or
              ancestor::db:biblioentry/
              @xreflabel='mastersthesis'">
        <xsl:text>institution</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>publisher</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text> &#x9; = {</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{pubaddress}\label{template-db2bibtex-pubaddress}
% Detect network addresses and handle separately.\par
%    \begin{macrocode}
  <xsl:template match="db:publisher/db:address">
    <xsl:text>,&#xa;  </xsl:text>
    <xsl:choose>
      <xsl:when 
        test="starts-with(normalize-space(.),'http://') or
              starts-with(normalize-space(.),'ftp://') or
              starts-with(normalize-space(.),'mailto:') or
              starts-with(normalize-space(.),'https://')">
        <xsl:text>url</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>address</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text> &#x9; = {</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{version}\label{template-db2bibtex-version2}
% Abuse the \texttt{<releaseinfo>}\index{releaseinfo=\texttt{\char'074 releaseinfo\char'076 } (element)}\index{elements:!releaseinfo=\texttt{\char'074 releaseinfo\char'076 }} element to hold a
%     software package version number.\par
%    \begin{macrocode}
  <xsl:template match="db:releaseinfo">
    <xsl:text>,&#xa;  version &#x9; = {</xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection*{Conferences}
% \begin{CPKtemplate}{confgroup}\label{template-db2bibtex-confgroup}
% Conference group data passes through but conference
%       number is done separately within the conference
%       title.\par
%    \begin{macrocode}
  <xsl:template match="db:confgroup">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="db:confnum"/>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{conftitle}\label{template-db2bibtex-conftitle}
% Try to align conference numbers with titles that
%       have the year embedded.\par
%    \begin{macrocode}
  <xsl:template match="db:conftitle">
    <xsl:text>,&#xa;  booktitle &#x9; = {{Proc. </xsl:text>
    <xsl:choose>
      <xsl:when test="../db:confnum">
        <xsl:choose>
          <xsl:when 
            test="matches(.,'$apostrophe[0-9][0-9]$')">
            <xsl:value-of 
              select="replace(.,
                      '$apostrophe[0-9][0-9]$','')"/>
          </xsl:when>
          <xsl:when 
            test="matches(.,'’[0-9][0-9]$')">
            <xsl:value-of 
              select="replace(.,'’[0-9][0-9]$','')"/>
          </xsl:when>
          <xsl:when 
            test="matches(.,'[0-9][0-9]$')">
            <xsl:value-of 
              select="replace(.,'[0-9][0-9]$','')"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates/>
          </xsl:otherwise>
        </xsl:choose>
        <!-- now add the real year/number -->
        <xsl:choose>
          <xsl:when test="number(../db:confnum)>999">
            <xsl:text> </xsl:text>
            <xsl:value-of select="../db:confnum"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates 
              select="../db:confnum/node()"/>
            <xsl:text>: </xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- otherwise it's just the name of the conf -->
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
    <!-- if there are dates, use biblatex -->    
    <xsl:text>}}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{confsponsor}\label{template-db2bibtex-confsponsor}
% The conference sponsor is the organisation.\par
%    \begin{macrocode}
  <xsl:template match="db:confsponsor">
    <xsl:text>,&#xa;  organization &#x9; = {</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{orguri}\label{template-db2bibtex-orguri}
% Organisation \textsc{uri}.\par
%    \begin{macrocode}
  <xsl:template match="db:org/db:uri">
    <xsl:text>,&#xa;  uri &#x9; = {</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{conforgaddress}\label{template-db2bibtex-conforgaddress}
% Conference organiser address or location becomes the
%       conference address.\par
%    \begin{macrocode}
  <xsl:template match="db:confgroup/db:address">
    <xsl:text>,&#xa;  venue &#x9; = {</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
  <xsl:template match="db:org/db:address">
    <xsl:text>,&#xa;  location &#x9; = {</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{confdates}\label{template-db2bibtex-confdates}
% Real conference dates use the
%       {\ttfamily{}eventdate} field.\par
%    \begin{macrocode}
  <xsl:template match="db:confdates">
    <xsl:text>,&#xa;  eventdate &#x9; = {</xsl:text>
    <xsl:choose>
      <xsl:when test="@YYYY-MM-DD-from">
        <xsl:value-of select="@YYYY-MM-DD-from"/>
        <xsl:if test="@YYYY-MM-DD-to">
          <xsl:text>/</xsl:text>
          <xsl:value-of select="@YYYY-MM-DD-to"/>
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="."/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{dates}\label{template-db2bibtex-dates}
% Original date field gets parsed separately.\par
%    \begin{macrocode}
  <xsl:template match="db:date">
    <xsl:call-template name="dodate"/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{dodate}\label{template-db2bibtex-dodate}
% Separate out year and month for the right fields.\par
%    \begin{macrocode}
  <xsl:template name="dodate">
    <xsl:text>,&#xa;  year &#x9; = {</xsl:text>
    <xsl:choose>
      <xsl:when test="@YYYY-MM-DD!=''">
        <xsl:value-of 
          select="format-date(xs:date(
                  @YYYY-MM-DD),'[Y]')"/>
      </xsl:when>
      <xsl:when test="@YYYY-MM-DD-from!=''">
        <xsl:value-of 
          select="format-date(xs:date(
                  @YYYY-MM-DD-from),'[Y]')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>}</xsl:text>
    <xsl:choose>
      <xsl:when test="@YYYY-MM-DD!=''">
        <xsl:text>,&#xa;  month &#x9; = {</xsl:text>
        <xsl:value-of 
          select="format-date(xs:date(
                  @YYYY-MM-DD),'[M]')"/>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <xsl:when test="@YYYY-MM-DD-from!=''">
        <xsl:text>,&#xa;  month &#x9; = {</xsl:text>
        <xsl:value-of 
          select="format-date(xs:date(
                  @YYYY-MM-DD-from),'[M]')"/>
        <xsl:text>}</xsl:text>
      </xsl:when>
    </xsl:choose>
    <xsl:if test="ancestor::db:biblioentry/@xreflabel='pc'">
      <xsl:text>,&#xa;  howpublished &#x9; = {</xsl:text>
      <xsl:text>Pers.\ Comm.}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{pagenums}\label{template-db2bibtex-pagenums}
% Pages (range and count)\par
% \par\smallskip\leavevmode
% \CPKrunningecho{pagenums}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Separate page count (books) from page range}}\par\smallskip
%    \begin{macrocode}
  <xsl:template match="db:pagenums | db:artpagenums">
    <xsl:choose>
      <xsl:when test="local-name()='pagenums'">
        <xsl:text>,&#xa;  pagetotal &#x9; = {</xsl:text>
      </xsl:when>
      <xsl:when test="local-name()='artpagenums'">
        <xsl:text>,&#xa;  pages &#x9; = {</xsl:text>
      </xsl:when>
    </xsl:choose>
    <xsl:choose>
      <!-- en-dash already present -->
      <xsl:when test="contains(.,'–')">
        <xsl:value-of select="substring-before(.,'–')"/>
        <xsl:text>--</xsl:text>
        <xsl:value-of select="substring-after(.,'–')"/>
      </xsl:when>
      <!-- double-hyphen -->
      <xsl:when test="contains(.,'--')">
        <xsl:value-of select="."/>
      </xsl:when>
      <!-- single hyphen -->
      <xsl:when test="contains(.,'-')">
        <xsl:value-of select="substring-before(.,'-')"/>
        <xsl:text>--</xsl:text>
        <xsl:value-of select="substring-after(.,'-')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="."/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{volumenum}\label{template-db2bibtex-volumenum}
% Volume of a journal\par
%    \begin{macrocode}
  <xsl:template match="db:volumenum">
    <xsl:choose>
      <xsl:when test="ancestor::db:biblioentry/@xreflabel='book'">
        <xsl:text>,&#xa;  volumes &#x9; = {</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>,&#xa;  volume &#x9; = {</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{issuenum}\label{template-db2bibtex-issuenum}
% \begingroup\raggedright[\url{db:issuenum} 
% and \url{db:productnumber} 
% ]\par\endgroup
% Issue number of a journal. The
%       \texttt{<productnumber>}\index{productnumber=\texttt{\char'074 productnumber\char'076 } (element)}\index{elements:!productnumber=\texttt{\char'074 productnumber\char'076 }} element can be used for
%       conference numbers to avoid them being encoded as
%       issues.\par
%    \begin{macrocode}
  <xsl:template match="db:issuenum | db:productnumber">
    <xsl:text>,&#xa;  number &#x9; = {</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{edition}\label{template-db2bibtex-edition}
% Edition of a book\par
% \par\smallskip\leavevmode
% \CPKrunningecho{edition}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Recode to use ordinal}}\par\smallskip
%    \begin{macrocode}
  <xsl:template match="db:edition">
    <xsl:text>,&#xa;  edition &#x9; = {</xsl:text>
    <xsl:choose>
      <xsl:when test="not(number(.))">
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
        <xsl:choose>
          <xsl:when
            test="substring(.,string-length(.))='1' and 
                  substring(.,string-length(.)-1)!='11'">
            <xsl:text>st</xsl:text>
          </xsl:when>
          <xsl:when
            test="substring(.,string-length(.))='2' and
                  substring(.,string-length(.)-1)!='12'">
            <xsl:text>nd</xsl:text>
          </xsl:when>
          <xsl:when
            test="substring(.,string-length(.))='3' and
                  substring(.,string-length(.)-1)!='13'">
            <xsl:text>rd</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>th</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{abstract}\label{template-db2bibtex-abstract}
% Abstracts in references are uncommon, but record one if it is provided.\par
%    \begin{macrocode}
  <xsl:template match="db:abstract">
    <xsl:text>,&#xa;  abstract &#x9; = {</xsl:text>
    <xsl:value-of select="normalize-space(.)"/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{address}\label{template-db2bibtex-address}
% An address which is not part of a publisher element,
%       or a conference group, or an organisation is given the
%       {\ttfamily{}location} field
%       type.\par
%    \begin{macrocode}
  <xsl:template
    match="db:address[
           not(parent::db:publisher)
           and not(parent::db:confgroup)
           and not(parent::db:org)]">
    <xsl:text>,&#xa;  location &#x9; = {</xsl:text>
    <xsl:value-of select="normalize-space(.)"/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{orgname}\label{template-db2bibtex-orgname}
% Organisation names (ie explicitly not publishers) are
%       usually academic or research institutions.\par
%    \begin{macrocode}
  <xsl:template
    match="db:orgname[
           not(parent::db:author)
           and not(parent::db:org)]">
    <xsl:text>,&#xa;  institution &#x9; = {</xsl:text>
    <xsl:value-of select="normalize-space(.)"/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{series}\label{template-db2bibtex-series}
% Series are just series.\par
%    \begin{macrocode}
  <xsl:template match="db:seriesvolnums |
                       db:biblioset[@relation='series']">
    <xsl:text>,&#xa;  series &#x9; = {</xsl:text>
    <xsl:value-of select="normalize-space(.)"/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{coverage}\label{template-db2bibtex-coverage}
% The \texttt{bibliocoverage}\index{bibliocoverage=\texttt{\char'074 bibliocoverage\char'076 } (element)}\index{elements:!bibliocoverage=\texttt{\char'074 bibliocoverage\char'076 }}
%       element type is used to express a part of a cited
%       document like a chapter.\par
%    \begin{macrocode}
  <xsl:template match="db:bibliocoverage">
    <xsl:text>,&#xa;  chapter &#x9; = {</xsl:text>
    <xsl:value-of select="normalize-space(.)"/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{done}\label{template-db2bibtex-done}
% The End.\par
%    \begin{macrocode}
</xsl:stylesheet>
%    \end{macrocode}
% \end{CPKtemplate}
% \iffalse
%</db2bibtexscript>
% \fi
% \iffalse
%<*figtabscript>
% \fi
% \clearpage
% \section{The {\ttfamily{}figtab2latex.xsl} script}\label{figtabscript}
% \setcounter{CodelineNo}{0}
% \begin{CPKcomment}{figtabscript-comment}\label{comment-figtabscript}
% Identify the file origin,
% date, time, etc.\par
%    \begin{macrocode}
<!-- The figtab2latex.xsl script (from the classpack package v.1.28, 2024-02-21) -->
<!-- Generated by ClassPack v.1.28 (2024-02-21) on 24-03-04T22:35:19 -->
%    \end{macrocode}
% These lines are automatically prepended to the file
% and may be removed if necessary,
% using a suitable editor.
% \end{CPKcomment}
% Figure and tables in documentation share some common
% features and are handled by code in a separate
% \textsc{xslt} file included from
% {\ttfamily{}db2dtx.xsl}\thinspace.\par
% \begin{CPKtemplate}{init}\label{template-figtab2latex-init2}
% The file starts with the \textsc{xslt}
%   declaration and the output type setting.\par
%    \begin{macrocode}
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:db="http://docbook.org/ns/docbook"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  version="3.0">

  <xsl:output method="text"/>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection*{Tables}
% \begin{CPKtemplate}{table}\label{template-figtab2latex-table}
% Output a \LaTeX{} \texttt{table} environment, with
%   each physical line shielded from Doc\TeX{} with the current
%   value of the variable \DescribeVariable{shield}{\ttfamily{}\$shield}. Honour the float style,
%   defaulting to \textbf{\texttt{ht}}. Tables are set in the
%   current sans-serif type, one step-size smaller than the body
%   text.\par
%    \begin{macrocode}
  <xsl:template match="db:table">
    <!-- number of columns -->
    <xsl:variable name="ncols" select="db:tgroup/@cols"/>
    <!-- work out total table width -->
    <xsl:value-of select="$shield"/>
    <xsl:text> \setlength{\CPKtabwid}{</xsl:text>
    <xsl:call-template name="colwidths">
      <xsl:with-param name="loc" select="db:tgroup"/>
    </xsl:call-template>
    <xsl:text> + </xsl:text>
    <xsl:value-of select="$ncols - 1"/>
    <xsl:text>\tabcolsep}&#xa;</xsl:text>
    <!-- size and font control -->
    <xsl:if test="@wordsize">
    <xsl:value-of select="$shield"/>
      <xsl:text> \fontsize{</xsl:text>
      <xsl:value-of
        select="tokenize(@wordsize,'/')[1]"/>
      <xsl:text>}{</xsl:text>
      <xsl:value-of
        select="tokenize(@wordsize,'/')[2]"/>
      <xsl:text>}\selectfont</xsl:text>
    </xsl:if>
    <xsl:if test="@role">
      <xsl:if test="not(@wordsize)">
        <xsl:value-of select="$shield"/>
        <xsl:text> </xsl:text>
      </xsl:if>
      <xsl:value-of select="@role"/>
    </xsl:if>
    <xsl:if test="@wordsize or @role">
      <xsl:text>&#xa;</xsl:text>
    </xsl:if>
    <!-- start the table -->
    <xsl:value-of select="$shield"/>
    <xsl:text> \begin{</xsl:text>
    <xsl:value-of select="@condition"/><!-- eg 'long' -->
    <xsl:text>table}</xsl:text>
    <xsl:choose>
      <xsl:when test="@condition='long'">
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:when test="@floatstyle">
        <xsl:text>[</xsl:text>
        <xsl:value-of select="@floatstyle"/>
        <xsl:text>]</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>[ht]</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <!-- longtable has to do column parse BEFORE caption etc -->
      <xsl:when test="@condition='long'">
        <xsl:for-each select="db:tgroup">
          <xsl:call-template name="colparse"/>
          <xsl:apply-templates select="../db:title|../db:subtitle"/>
          <xsl:apply-templates
            select="
                    db:thead|
                    db:tbody|
                    db:tfoot
                    "/>
        </xsl:for-each>
      </xsl:when>
      <!-- normal table -->
      <xsl:otherwise>
        <xsl:text>&#xa;</xsl:text>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
    <!-- any prefaratory test gets output as the last row of tabular 
         at the end of the tgroup template; longtables get it here -->
    <xsl:if test="db:textobject[@role='footer'] and @condition='long'">
      <xsl:value-of select="$shield"/>
      <xsl:text> \multicolumn{</xsl:text>
      <xsl:value-of select="$ncols"/>
      <xsl:text>}{>{\renewcommand{\baselinestretch}{0.8}</xsl:text>
      <xsl:text>\selectfont{}\centering{}\CPKprestrut}</xsl:text>
      <xsl:text>p{\CPKtabwid}}{\footnotesize&#xa;</xsl:text>
      <xsl:apply-templates
        select="db:textobject[@role='footer']/*"/>
      <xsl:value-of select="$shield"/>
      <xsl:text> }&#xa;</xsl:text>
      <xsl:value-of select="$shield"/>
      <xsl:text> \\&#xa;</xsl:text>
    </xsl:if>
    <xsl:value-of select="$shield"/>
    <xsl:text> \end{</xsl:text>
    <xsl:value-of select="@condition"/><!-- eg 'long' -->
    <xsl:text>table}&#xa;</xsl:text>
    <!-- size and font control -->
    <xsl:if test="@wordsize">
      <xsl:value-of select="$shield"/>
      <xsl:text> \normalsize</xsl:text>
    </xsl:if>
    <xsl:if test="@role">
      <xsl:if test="not(@wordsize)">
        <xsl:value-of select="$shield"/>
        <xsl:text> </xsl:text>
      </xsl:if>
      <xsl:text>\normalfont</xsl:text>
    </xsl:if>
    <xsl:if test="@wordsize or @role">
      <xsl:text>&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="db:table/db:textobject
                       [@role='footer']"/>
%    \end{macrocode}
% If there is a \texttt{<textobject>}\index{textobject=\texttt{\char'074 textobject\char'076 } (element)}\index{elements:!textobject=\texttt{\char'074 textobject\char'076 }} element present,
%   with a \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} of \texttt{"footer"}\index{footer=\texttt{"footer"} (attribute value)}\index{attribute values:!footer=\texttt{"footer"}}, use it \emph{within the
%     \texttt{table} environment} in smaller
%   type, without adding any footnote number or symbol. This
%   element will then be ignored when it is encountered in
%   document order.\par
% \end{CPKtemplate}
% \begin{CPKtemplate}{tabletitle}\label{template-figtab2latex-tabletitle}
% Make the table \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }} into the caption. A
%   subtitle is not currently implemented. The \texttt{@xml:id}\index{xml:id=\texttt{\char'100 xml:id} (attribute)}\index{attributes:!xml:id=\texttt{\char'100 xml:id}} is used as the \LaTeX{}
%   {\ttfamily{}\textbackslash{}label}, if present.\par
%    \begin{macrocode}
  <xsl:template match="db:table/db:title[1]
                       |
                       db:figure/db:title[1]">
    <xsl:value-of select="$shield"/>
    <xsl:text> \caption</xsl:text>
      <!-- a second title is used for short caption -->
      <xsl:if test="following-sibling::db:title">
        <xsl:text>[</xsl:text>
        <xsl:apply-templates
          select="following-sibling::db:title/node()"/>
        <xsl:text>]</xsl:text>
      </xsl:if>
    <xsl:text>{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
    <xsl:if test="../@xml:id
                  and
                  not(parent::db:table/@condition='long')">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="../@xml:id"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:choose>
      <xsl:when test="parent::db:table/@condition='long'">
        <xsl:text>\\&#xa;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>\smallskip&#xa;</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template
    match="db:table/db:title[position()>1]
           |
           db:figure/db:title[position()>1]"/>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{informaltable}\label{template-figtab2latex-informaltable}
% Informal tables are unnumbered and uncaptioned, in
%   sans-serif type, and by default smaller size, but the \texttt{@wordsize}\index{wordsize=\texttt{\char'100 wordsize} (attribute)}\index{attributes:!wordsize=\texttt{\char'100 wordsize}} attribute can be used to
%   specify a font size with tow numbers separated by a slash,
%   for the font size and baseline height, eg \texttt{"7/8"}\index{7/8=\texttt{"7/8"} (attribute value)}\index{attribute values:!7/8=\texttt{"7/8"}} for 7pt type on an 8pt
%   baseline. The \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}} attribute
%   can be used to hold specific \LaTeX{} commands if needed. The
%   content is a \texttt{<tgroup>}\index{tgroup=\texttt{\char'074 tgroup\char'076 } (element)}\index{elements:!tgroup=\texttt{\char'074 tgroup\char'076 }} element, formatted the same
%   way as a formal table.\par
%    \begin{macrocode}
  <xsl:template match="db:informaltable">
    <xsl:value-of select="$shield"/>
    <xsl:text> \par\medskip{\sffamily</xsl:text>
    <xsl:choose>
      <xsl:when test="@role">
        <xsl:value-of select="@role"/>
      </xsl:when>
      <xsl:when test="@wordsize">
        <xsl:text>\fontsize{</xsl:text>
        <xsl:value-of
          select="tokenize(@wordsize,'/')[1]"/>
        <xsl:text>}{</xsl:text>
        <xsl:value-of
          select="tokenize(@wordsize,'/')[2]"/>
        <xsl:text>}\selectfont</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>\small</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="@xml:id"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:value-of select="$shield"/>
    <xsl:text> }&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{informaltableinfo}\label{template-figtab2latex-informaltableinfo}
% The \texttt{<info>}\index{info=\texttt{\char'074 info\char'076 } (element)}\index{elements:!info=\texttt{\char'074 info\char'076 }} and \texttt{<title>}\index{title=\texttt{\char'074 title\char'076 } (element)}\index{elements:!title=\texttt{\char'074 title\char'076 }} elements in an
%   informal table can be used for a heading if required.\par
%    \begin{macrocode}
  <xsl:template
    match="db:informaltable/db:info">
    <xsl:text>\begin{center}</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>\end{center}</xsl:text>
  </xsl:template>

  <xsl:template
    match="db:informaltable/db:info/db:title">
    <xsl:text>\textbf{</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>}</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{tgroup}\label{template-figtab2latex-tgroup}
% The \texttt{<tgroup>}\index{tgroup=\texttt{\char'074 tgroup\char'076 } (element)}\index{elements:!tgroup=\texttt{\char'074 tgroup\char'076 }} is the tabular component of formal
%   and informal tables. It typically holds a set of
%   \texttt{<colspec>}\index{colspec=\texttt{\char'074 colspec\char'076 } (element)}\index{elements:!colspec=\texttt{\char'074 colspec\char'076 }} elements which specify the column types
%   and widths, a \texttt{<thead>}\index{thead=\texttt{\char'074 thead\char'076 } (element)}\index{elements:!thead=\texttt{\char'074 thead\char'076 }} for the column headings, a
%   \texttt{<tbody>}\index{tbody=\texttt{\char'074 tbody\char'076 } (element)}\index{elements:!tbody=\texttt{\char'074 tbody\char'076 }} for the body, and optionally a
%   \texttt{<tfoot>}\index{tfoot=\texttt{\char'074 tfoot\char'076 } (element)}\index{elements:!tfoot=\texttt{\char'074 tfoot\char'076 }} for totals.\par
% The \DescribeTemplate{tabstart}{\ttfamily{}tabstart} named template handles
%   the column settings. If there is no \texttt{<thead>}\index{thead=\texttt{\char'074 thead\char'076 } (element)}\index{elements:!thead=\texttt{\char'074 thead\char'076 }}, a line
%   is drawn across all columns. The body and foot are processed
%   in that order (\emph{DocBook} specifies
%   that the \texttt{<tfoot>}\index{tfoot=\texttt{\char'074 tfoot\char'076 } (element)}\index{elements:!tfoot=\texttt{\char'074 tfoot\char'076 }} element occur earlier).\par
%    \begin{macrocode}
  <xsl:template match="db:tgroup">
    <!-- formal and informal tables get their tabular-start here;
         longtable already did it -->
    <xsl:if test="not(ancestor::db:table/@condition='long')">
      <xsl:text>% \small\sffamily&#xa;</xsl:text>
      <xsl:call-template name="tabstart"/>
    </xsl:if>
    <!-- process the head lines if any -->
    <xsl:apply-templates select="db:thead"/>
    <!-- if there wasn't one, draw a rule -->
    <xsl:if test="not(db:thead)">
      <xsl:value-of select="$shield"/>
      <xsl:text> \hline&#xa;</xsl:text>
    </xsl:if>
    <!-- then do the body and the foot -->
    <xsl:apply-templates select="db:tbody"/>
    <xsl:apply-templates select="db:tfoot"/>
    <!-- formal and informal tables get their tabular-end here -->
    <xsl:if test="not(ancestor::db:table/@condition='long')">
      <!-- any prefaratory test gets output as the last row of longtable 
           in the table template; normal tables get it here -->
      <xsl:if test="ancestor::db:table/db:textobject[@role='footer']
                    and not(ancestor::db:table/@condition='long')">
        <xsl:value-of select="$shield"/>
        <xsl:text> \multicolumn{</xsl:text>
        <xsl:value-of select="count(db:colspec)"/>
        <xsl:text>}{>{\renewcommand{\baselinestretch}{0.8}</xsl:text>
        <xsl:text>\selectfont{}\centering{}\CPKprestrut}</xsl:text>
        <xsl:text>p{\CPKtabwid}}{\footnotesize&#xa;</xsl:text>
        <xsl:apply-templates
          select="ancestor::db:table/db:textobject[@role='footer']/*"/>
        <xsl:value-of select="$shield"/>
        <xsl:text> }&#xa;</xsl:text>
        <xsl:value-of select="$shield"/>
        <xsl:text> \\&#xa;</xsl:text>
      </xsl:if>
      <xsl:value-of select="$shield"/>
      <xsl:text> \end{tabular}&#xa;</xsl:text>
    </xsl:if>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{tgroupfakefootnotes}\label{template-figtab2latex-tgroupfakefootnotes}
% WARNING: Experimental and unsupported option\par
% In document classes with a very large number of options
% (typically university theses, with options for subjects and
% types of degree), the tables describing them need extensive
%   annotation. If the \texttt{<tbody>}\index{tbody=\texttt{\char'074 tbody\char'076 } (element)}\index{elements:!tbody=\texttt{\char'074 tbody\char'076 }} has a \texttt{@xlink:href}\index{xlink:href=\texttt{\char'100 xlink:href} (attribute)}\index{attributes:!xlink:href=\texttt{\char'100 xlink:href}} attribute starting with the
%   string \texttt{"affil"}\index{affil=\texttt{"affil"} (attribute value)}\index{attribute values:!affil=\texttt{"affil"}} and a matching set
%   of \texttt{<constraintdef>}\index{constraintdef=\texttt{\char'074 constraintdef\char'076 } (element)}\index{elements:!constraintdef=\texttt{\char'074 constraintdef\char'076 }} elements in the \texttt{"data"}\index{data=\texttt{"data"} (attribute value)}\index{attribute values:!data=\texttt{"data"}} part of the document, use them as
% values for a list of explanations.\par
%    \begin{macrocode}
    <xsl:if
      test="starts-with(db:tbody/@xlink:href,'affil')
            and
            count(//db:part[@xml:id='data']
                  //db:constraintdef
                  [@xml:id=concat(substring-before(
                     current()/db:tbody/@xlink:href,'-'),
                           'options')]
                  /db:methodsynopsis[tokenize(@arch,' ')=
                     substring-after(
                     current()/db:tbody/@xlink:href,'-')]
                  [db:modifier])>0">
      <xsl:value-of select="$shield"/>
      <xsl:text> \scriptsize&#xa;</xsl:text>
      <xsl:value-of select="$shield"/>
      <xsl:text> \renewcommand{\labelenumi}{</xsl:text>
      <xsl:text>\itshape\alph{enumi}\upshape)}&#xa;</xsl:text>
      <xsl:text> \begin{enumerate}[noitemsep]&#xa;</xsl:text>
      <xsl:for-each 
        select="//db:part[@xml:id='data']
                //db:constraintdef[@xml:id=
                concat(substring-before(
                   current()/db:tbody/@xlink:href,'-'),
                        'options')]
                /db:methodsynopsis[tokenize(@arch,' ')=
                   substring-after(
                   current()/db:tbody/@xlink:href,'-')]
                /db:modifier">
        <xsl:value-of select="$shield"/>
        <xsl:text>   \item The \texttt{</xsl:text>
        <xsl:value-of select="../@xml:id"/>
        <xsl:text>} option </xsl:text>
        <xsl:apply-templates/>
        <xsl:text>&#xa;</xsl:text>
      </xsl:for-each>
      <xsl:value-of select="$shield"/>
      <xsl:text> \end{enumerate}&#xa;</xsl:text>
      <xsl:value-of select="$shield"/>
      <xsl:text> \setcounter{fnote}{0}&#xa;</xsl:text>
    </xsl:if>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{tgroupend}\label{template-figtab2latex-tgroupend}
% Terminate the \TeX{} group started earlier in the
%   {\ttfamily{}tabstart} named template.\par
%    \begin{macrocode}
    <xsl:value-of select="$shield"/>
    <xsl:text> \par\endgroup&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{tabstart}\label{template-figtab2latex-tabstart}
% This template is called from within a \texttt{<tgroup>}\index{tgroup=\texttt{\char'074 tgroup\char'076 } (element)}\index{elements:!tgroup=\texttt{\char'074 tgroup\char'076 }}
%   to handle column settings. It starts a \TeX{} group which is
%   terminated at the end of the template for the
%   \texttt{<tgroup>}\index{tgroup=\texttt{\char'074 tgroup\char'076 } (element)}\index{elements:!tgroup=\texttt{\char'074 tgroup\char'076 }} element.\par
% Any local settings in the form of \LaTeX{} commands in
%   the \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}} attribute get
%   honoured first. The tabular material is centred horizontally
%   in the page, and the default shoulders are omitted unless
%   the \texttt{@tgroupstyle}\index{tgroupstyle=\texttt{\char'100 tgroupstyle} (attribute)}\index{attributes:!tgroupstyle=\texttt{\char'100 tgroupstyle}} is set to \texttt{"overhang"}\index{overhang=\texttt{"overhang"} (attribute value)}\index{attribute values:!overhang=\texttt{"overhang"}}.\par
% The \texttt{<colspec>}\index{colspec=\texttt{\char'074 colspec\char'076 } (element)}\index{elements:!colspec=\texttt{\char'074 colspec\char'076 }} elements are handled in order by
%   the three named templates \DescribeTemplate{colprefix}{\ttfamily{}colprefix}, \DescribeTemplate{colsettings}{\ttfamily{}colsettings}, and
%   \DescribeTemplate{colsuffix}{\ttfamily{}colsuffix}, so the elements are
%   ignored when they come up in document order.\par
%    \begin{macrocode}
  <xsl:template name="tabstart">
    <xsl:param name="loc">
      <xsl:text></xsl:text>
    </xsl:param>
    <!-- called in the context of db:tgroup -->
    <xsl:value-of select="$shield"/>
    <xsl:text> \begingroup</xsl:text>
    <xsl:value-of
      select="parent::db:table/@remap |
              parent::db:informaltable/@remap"/>
    <xsl:text>&#xa;</xsl:text>
    <xsl:value-of select="$shield"/>
    <xsl:text> \centering&#xa;</xsl:text>
    <xsl:value-of select="$shield"/>
    <xsl:text> \begin{tabular}</xsl:text>
    <xsl:call-template name="colparse"/>
  </xsl:template>
  
  <!-- colparse now separated out because of longtable support -->
  <xsl:template name="colparse">
    <xsl:param name="loc">
      <xsl:text></xsl:text>
    </xsl:param>
    <!-- WARNING: if you edit this, don't forget to mirror the edits
         in the colwidths template later on -->
    <xsl:text>{</xsl:text>
    <xsl:choose>
      <xsl:when test="@tgroupstyle='overhang' or @colsep='1'">
        <xsl:text>@{\quad}</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>@{}</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:value-of select="$shield"/>
    <xsl:text>&#xa;</xsl:text>
    <xsl:value-of select="$shield"/>
    <!-- try to indent each column spec on its own line -->
    <xsl:text>   </xsl:text>
    <xsl:for-each select="db:colspec">
      <xsl:choose>
        <xsl:when test="@colsep='0'">
          <xsl:text>@{\enspace}</xsl:text>
        </xsl:when>
        <xsl:when test="@colsep='1'">
          <xsl:text>@{\qquad}</xsl:text>
        </xsl:when>
      </xsl:choose>
      <xsl:call-template name="colprefix">
        <xsl:with-param name="loc" select="$loc"/>
      </xsl:call-template>
      <xsl:call-template name="colsettings">
        <xsl:with-param name="loc" select="$loc"/>
      </xsl:call-template>
      <xsl:call-template name="colsuffix">
        <xsl:with-param name="loc" select="$loc"/>
      </xsl:call-template>
      <xsl:value-of select="$shield"/>
      <xsl:text>&#xa;</xsl:text>
      <xsl:value-of select="$shield"/>
      <xsl:text>   </xsl:text>
    </xsl:for-each>
    <xsl:choose>
      <xsl:when test="@tgroupstyle='overhang'">
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>@{}</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>}&#xa;</xsl:text>
  </xsl:template>

  <!-- don't process the colspecs inline: they get managed as above -->
  <xsl:template match="db:colspec"/>
%    \end{macrocode}
% Experimental. The \DescribeParameter{loc}{\ttfamily{}\$loc} parameter is tested in the
%   column handler named templates for the value \texttt{"thead"}\index{thead=\texttt{"thead"} (attribute value)}\index{attribute values:!thead=\texttt{"thead"}} in order to prevent
%   typographic modification of the column header text.\par
% \end{CPKtemplate}
% \begin{CPKtemplate}{colprefix}\label{template-figtab2latex-colprefix}
% This template handles the prefixing of a \LaTeX{} column
%   specification with default formatting as provided for by the
%   \textsf{array} package:\par
% \begin{itemize}[noitemsep]
% \item \texttt{@align}\index{align=\texttt{\char'100 align} (attribute)}\index{attributes:!align=\texttt{\char'100 align}} {\sffamily \textsc{should}} specify the column
%       alignment (left/right/center). The default is
%       left-aligned\par
% \item \texttt{@colwidth}\index{colwidth=\texttt{\char'100 colwidth} (attribute)}\index{attributes:!colwidth=\texttt{\char'100 colwidth}} {\sffamily \textsc{may}} specify the column
%       width in some units or as a percentage (using the
%       \verb|\%| after the
%       number)\par
% \item \texttt{@wordsize}\index{wordsize=\texttt{\char'100 wordsize} (attribute)}\index{attributes:!wordsize=\texttt{\char'100 wordsize}} {\sffamily \textsc{may}} specify the font size
%       as two numbers separated by a slash (font size and
%       baseline spacing)\par
% \item \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} {\sffamily \textsc{may}} specify additional
%       \LaTeX{} formatting commands\par
% \end{itemize}
%    \begin{macrocode}
  <xsl:template name="colprefix">
    <xsl:param name="loc">
      <xsl:text></xsl:text>
    </xsl:param>
    <!-- @colwidth in <colspec>
         @condition for fonts, uses LaTeX code
         @wordsize in <entry>, here and below 
         BUT header cells with no attributes 
         masquerade as their colspec to get the
         settings, but set $loc to 'thead' -->
    <xsl:if test="@arch='leftrule'">
      <xsl:text>|</xsl:text>
    </xsl:if>
    <xsl:if test="@condition or @colwidth or @wordsize
                  or ancestor::db:thead or $loc='thead'">
      <xsl:text>>{</xsl:text>
      <xsl:variable name="nth">
        <xsl:choose>
          <xsl:when test="name()='colspec'">
            <xsl:value-of
              select="count(preceding-sibling::db:colspec)+1"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of
              select="count(preceding-sibling::db:entry)+1"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:choose>
        <!-- go raggedright by default and
             narrow the linespacing for multiline columns -->
        <xsl:when
          test="(@align='left'
                 or
                 ancestor::db:tgroup/db:colspec
                   [position()=$nth]/@align='left')
                and
                (@colwidth
                 or
                 @wordsize
                 or
                 ancestor::db:thead or $loc='thead')">
          <xsl:text>\renewcommand{\baselinestretch}{0.8}</xsl:text>
          <xsl:text>\selectfont{}\raggedright{}</xsl:text>
        </xsl:when>
        <xsl:when
          test="(@align='right'
                 or
                 ancestor::db:tgroup/db:colspec
                   [position()=$nth]/@align='right')
                and
                (@colwidth
                 or
                 @wordsize
                 or
                 ancestor::db:thead or $loc='thead')">
          <xsl:text>\renewcommand{\baselinestretch}{0.8}</xsl:text>
          <xsl:text>\selectfont{}\raggedleft{}</xsl:text>
        </xsl:when>
        <xsl:when test="(@align='center'
                 or
                 ancestor::db:tgroup/db:colspec
                   [position()=$nth]/@align='center')
                and
                (@colwidth
                 or
                 @wordsize
                 or
                 ancestor::db:thead or $loc='thead')">
          <xsl:text>\renewcommand{\baselinestretch}{0.8}</xsl:text>
          <xsl:text>\selectfont{}\centering{}</xsl:text>
        </xsl:when>
        <!-- default is justified anyway, 
             and char is inapplicable -->
        <xsl:when test="ancestor::db:thead">
          <xsl:text>\renewcommand{\baselinestretch}{0.8}</xsl:text>
          <xsl:text>\selectfont{}\raggedright{}</xsl:text>
        </xsl:when>
      </xsl:choose>
      <!-- condition is for typographic changes -->
      <xsl:if test="not($loc='thead')">
        <xsl:value-of select="@condition"/>
        <xsl:if test="@colwidth">
          <xsl:text>\renewcommand{\baselinestretch}{0.8}</xsl:text>
          <xsl:text>\selectfont{}</xsl:text>
        </xsl:if>
      </xsl:if>
      <xsl:text>\CPKprestrut</xsl:text>
      <xsl:if
        test="@wordsize and not($loc='thead')">
        <xsl:text>\fontsize{</xsl:text>
        <xsl:value-of
          select="tokenize(@wordsize,'/')[1]"/>
        <xsl:text>}{</xsl:text>
        <xsl:value-of
          select="tokenize(@wordsize,'/')[2]"/>
        <xsl:text>}\selectfont</xsl:text>
      </xsl:if>
      <xsl:if
        test="@align
              and
              (
                (name()='colspec'
                  and
                  count(following-sibling::db:colspec)=0)
                or
                 (name()='entry'
                  and
                  count(following-sibling::db:entry)=0)
              )
              and
              (@colwidth or @wordsize or @condition)">
        <xsl:text>\arraybackslash</xsl:text>
        <!--
        <xsl:text>align=</xsl:text>
        <xsl:value-of select="@align"/>
        <xsl:text>,name=</xsl:text>
        <xsl:value-of select="name()"/>
        <xsl:text>,cols=</xsl:text>
        <xsl:value-of select="count(following-sibling::db:colspec)"/>
        <xsl:text>,entries=</xsl:text>
        <xsl:value-of select="count(following-sibling::db:entry)"/>
        <xsl:text>,width=</xsl:text>
        <xsl:value-of select="@colwidth"/>
        <xsl:text>,size=</xsl:text>
        <xsl:value-of select="@wordsize"/>
        <xsl:text>,cond=</xsl:text>
        <xsl:value-of select="@condition"/>
        -->
      </xsl:if>
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% The final (only) column specification (or heading
%   {\ttfamily{}\textbackslash{}multicolumn}) gets the command
%   {\ttfamily{}\textbackslash{}arraybackslash} to prevent formatting
%   leaking into the column management environment.\par
% \end{CPKtemplate}
% \begin{CPKtemplate}{colsettings}\label{template-figtab2latex-colsettings}
% This template sets the column type (left/right/centered)
%   and vertical alignment if the width is specified. Headings
%   are always aligned on the baseline, to allow multi-word
%   headings to stack properly; otherwise the value of the \texttt{@char}\index{char=\texttt{\char'100 char} (attribute)}\index{attributes:!char=\texttt{\char'100 char}} attribute is used: \texttt{"m"}\index{m=\texttt{"m"} (attribute value)}\index{attribute values:!m=\texttt{"m"}} or \texttt{"b"}\index{b=\texttt{"b"} (attribute value)}\index{attribute values:!b=\texttt{"b"}}
%   for middle-alignment or bottom-alignment; the default is
%   alignment on the top line of the cell.\par
% The \texttt{@colwidth}\index{colwidth=\texttt{\char'100 colwidth} (attribute)}\index{attributes:!colwidth=\texttt{\char'100 colwidth}} value (in
%   length units or a percent) specifies a paragraphic
%   (potentially multi-line) column; a value of \texttt{"widest"}\index{widest=\texttt{"widest"} (attribute value)}\index{attribute values:!widest=\texttt{"widest"}} specifies a setting of the
%   widest value in the row entries, taken as the content passed
%   to the {\ttfamily{}\textbackslash{}widthof} command.\par
%    \begin{macrocode}
  <xsl:template name="colsettings">
    <xsl:param name="loc">
      <xsl:text></xsl:text>
    </xsl:param>
    <!-- this is the type of column (p|m|b) and width -->
    <xsl:choose>
      <xsl:when test="@colwidth">
        <xsl:choose>
          <!-- for db:thead it's always 'b' -->
          <xsl:when test="$loc='thead'">
            <xsl:text>b</xsl:text>
          </xsl:when>
          <xsl:when test="@char='m' or @char='b'">
            <xsl:value-of select="@char"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>p</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>{</xsl:text>
        <xsl:choose>
          <xsl:when test="@colwidth='widest'">
            <xsl:text>\widthof{</xsl:text>
            <xsl:call-template name="getlongest"/>
            <xsl:text>}</xsl:text>
          </xsl:when>
          <xsl:when test="contains(@colwidth,'%')">
            <xsl:value-of 
              select="number(substring-before(
                      @colwidth,'%'))
                      div 100"/>
            <xsl:text>\columnwidth</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="@colwidth"/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>}</xsl:text> 
      </xsl:when>
      <!-- otherwise width not specified -->
      <xsl:otherwise>
        <xsl:choose>
          <!-- for db:thead it's always 'b' -->
          <xsl:when test="$loc='thead'">
            <xsl:text>b{\widthof{</xsl:text>
            <xsl:call-template name="getlongest"/>
            <!-- make this the longest tbody entry, not thead -->
            
            <!-- this doesn't work: 
            <xsl:value-of
              select="following-sibling::db:tbody
                      /db:row/db:entry[position()=$nth]
                       [not(../db:row/db:entry[position()=$nth]
                        /string-length()
                        > current()/string-length())]"/>
            -->
            <!-- and Saxon PE needed for this one:
              select="sort(following-sibling::db:tbody
                           /db:row/db:entry[position()=$nth],
                           function($c) 
                           {string-length($c)})[last()]"/>
            -->
                 
            <!-- append 's' to account for 
                 extra width of bold type 2020-04-24 -->
            <xsl:text>s}}</xsl:text>
          </xsl:when>
          <xsl:when test="@align='left' or
                          @align='right' or
                          @align='center'">
            <xsl:value-of
              select="substring(@align,1,1)"/>
          </xsl:when>
          <xsl:when test="@align='char'">
            <xsl:text>d</xsl:text>
          </xsl:when>
          <!-- justified is implied by 
               @colwidth above -->
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% Experimental: an \texttt{@align}\index{align=\texttt{\char'100 align} (attribute)}\index{attributes:!align=\texttt{\char'100 align}}
%   value of \texttt{"char"}\index{char=\texttt{"char"} (attribute value)}\index{attribute values:!char=\texttt{"char"}} specifies decimal
%   alignment.\par
% \end{CPKtemplate}
% \begin{CPKtemplate}{colsuffix}\label{template-figtab2latex-colsuffix}
% This template implements the value of the \texttt{@conformance}\index{conformance=\texttt{\char'100 conformance} (attribute)}\index{attributes:!conformance=\texttt{\char'100 conformance}} attribute (usually a
%   \LaTeX{} command) on a \texttt{<colspec>}\index{colspec=\texttt{\char'074 colspec\char'076 } (element)}\index{elements:!colspec=\texttt{\char'074 colspec\char'076 }} or header
%   \texttt{<entry>}\index{entry=\texttt{\char'074 entry\char'076 } (element)}\index{elements:!entry=\texttt{\char'074 entry\char'076 }} element as a suffix to the column
%   specification.\par
%    \begin{macrocode}
  <xsl:template name="colsuffix">
    <xsl:param name="loc">
      <xsl:text></xsl:text>
    </xsl:param>
    <xsl:if test="@conformance
                  or
                  (@align!='left'
                   and
                   @align!='right'
                   and
                   @align!='center')
                  or
                  count(following-sibling::db:colspec)=0">
      <xsl:text>&lt;{</xsl:text>
      <xsl:value-of
        select="normalize-space(@conformance)"/>
      <xsl:if test="@align!='left' and
                    @align!='right' and
                    @align!='center'">
        <xsl:text>\CPKpoststrut</xsl:text>
      </xsl:if>
      <!-- why was this needed in colsuffixes? 
      <xsl:if test="count(following-sibling::db:colspec)=0">
        <xsl:text>\arraybackslash</xsl:text>
      </xsl:if>
      -->
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{thead}\label{template-figtab2latex-thead}
% The table header (column headers row) is terminated by
%   2pt extra space and a horizontal rule across all
%   columns.\par
%    \begin{macrocode}
  <xsl:template match="db:thead">
    <xsl:apply-templates/>
    <xsl:text>[2pt]\hline</xsl:text>
    <xsl:if test="ancestor::db:table/@condition='long'">
      <xsl:text>\endhead</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{tbody}\label{template-figtab2latex-tbody}
% The table body contains just rows. The first one gets a
%   {\ttfamily{}\textbackslash{}vstrut} for spacing away from the rule
%   just issued by the \texttt{<thead>}\index{thead=\texttt{\char'074 thead\char'076 } (element)}\index{elements:!thead=\texttt{\char'074 thead\char'076 }} unless the cell is the
%   start of a multi-row span. The specialist code for embedding
%   data from the \texttt{"data"}\index{data=\texttt{"data"} (attribute value)}\index{attribute values:!data=\texttt{"data"}} part is
%   experimental and not for normal use.\par
%    \begin{macrocode}
  <xsl:template match="db:tbody">
    <xsl:value-of select="$shield"/>
    <xsl:text> </xsl:text>
    <xsl:if test="not(db:row[1]/db:entry[1]/@spanname)">
      <xsl:text>\CPKvstrut </xsl:text>
    </xsl:if>
    <xsl:if test="ancestor::db:table/@condition='long'
                  and
                  ancestor::db:table/@xml:id">
      <xsl:text>\label{</xsl:text>
      <xsl:value-of select="ancestor::db:table/@xml:id"/>
      <xsl:text>}%</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
    <!-- obsolete, was used in ucc thesis
         eg, xlink:href='deg-acsss' 
         to use the external tables  
    <xsl:choose>
      <xsl:when
        test="@xlink:href and @xlink:show='embed'">
        <xsl:apply-templates mode="row"
          select="//db:part[@xml:id='data']
                  //db:constraintdef[@xml:id=
                  concat(substring-before(
                     current()/@xlink:href,'-'),
                         'options')]
                  /db:methodsynopsis
                  [tokenize(@arch,' ')=
                   substring-after(
                      current()/@xlink:href,'-')]">
          <xsl:sort select="@xml:id"/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
    -->
    <xsl:apply-templates/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{methodsynopsis}\label{template-figtab2latex-methodsynopsis}
% Experimental. This element holds data for specifying
%   large numbers of academic options for thesis
%   templates.\par
%    \begin{macrocode}
  <xsl:template match="db:methodsynopsis" mode="row">
    <!-- each of these produces one row of the table -->
    <xsl:value-of select="$shield"/>
    <xsl:text> </xsl:text>
    <!-- signal a footnote if needed -->
    <xsl:if test="db:modifier">
      <xsl:text>\fnote{}</xsl:text>
    </xsl:if>
    <!-- col 1: token for option -->
    <xsl:value-of select="@xml:id"/>
    <xsl:text>&amp;%&#xa;</xsl:text>
    <!-- col 2: division[s], 
         may be multiple methodparam elements -->
    <xsl:for-each select="db:methodparam/db:parameter">
      <xsl:value-of select="$shield"/>
      <xsl:text>&#x9;</xsl:text>
      <!-- @remap is a prefix 
           except for institutes and centres -->
      <xsl:if test="not(@remap='') and
                    @role!='institute' and
                    @role!='centre'">
        <xsl:value-of
          select="normalize-space(@remap)"/>
        <xsl:text> </xsl:text>
      </xsl:if>
      <!-- the name -->
      <xsl:apply-templates/>
      <!-- @remap is a suffix for 
           institutes and centres -->
      <xsl:if test="not(@remap='') and
                       (@role='institute' or
                        @role='centre')">
        <xsl:text> </xsl:text>
        <xsl:value-of
          select="normalize-space(@remap)"/>
      </xsl:if>
      <!-- any following divisions involved 
           (only for affiliations) -->
      <xsl:choose>
        <xsl:when test="position()!=last()">
          <xsl:text>; </xsl:text>
        </xsl:when>
        <!-- dummy to terminate 
             degree options cleanly -->
        <xsl:when test="@role='degree'">
          <xsl:text></xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>&amp;%&#xa;</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
    <!-- citation format -->
    <xsl:if
      test="not(db:methodparam/db:parameter
                /@role='degree')">
      <xsl:value-of select="$shield"/>
      <xsl:text>&#x9;</xsl:text>
      <xsl:value-of select="db:methodname"/>
    </xsl:if>
    <xsl:text>\\\hline[.1pt]%&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{row}\label{template-figtab2latex-row}
% Table rows are output to terminate with the \LaTeX{} double
%   backslash as normal. Attributes in the \texttt{<row>}\index{row=\texttt{\char'074 row\char'076 } (element)}\index{elements:!row=\texttt{\char'074 row\char'076 }}
%   element control usage:\par
% \begin{itemize}
% \item \texttt{@role}\index{role=\texttt{\char'100 role} (attribute)}\index{attributes:!role=\texttt{\char'100 role}}=\texttt{"header"}\index{header=\texttt{"header"} (attribute value)}\index{attribute values:!header=\texttt{"header"}} creates 2pt more space
%       above and below the row\par
% \item \texttt{@rowsep}\index{rowsep=\texttt{\char'100 rowsep} (attribute)}\index{attributes:!rowsep=\texttt{\char'100 rowsep}}=\texttt{"1"}\index{1=\texttt{"1"} (attribute value)}\index{attribute values:!1=\texttt{"1"}}add 1ex of additional space
%       below the row\par
% \item \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}}=\texttt{"newpage"}\index{newpage=\texttt{"newpage"} (attribute value)}\index{attribute values:!newpage=\texttt{"newpage"}} causes the table to be
%       stopped and restarted with repeated headings over a
%       page-break\par
% \item \label{testinc}\texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}}=\texttt{"test"}\index{test=\texttt{"test"} (attribute value)}\index{attribute values:!test=\texttt{"test"}}, when the sole content of
%       the first \texttt{<entry>}\index{entry=\texttt{\char'074 entry\char'076 } (element)}\index{elements:!entry=\texttt{\char'074 entry\char'076 }} cell is a marked-up element
%       type name, causes the row to be included when the named
%       element occurs at least once in the main document\par
% \item If the \texttt{<tbody>}\index{tbody=\texttt{\char'074 tbody\char'076 } (element)}\index{elements:!tbody=\texttt{\char'074 tbody\char'076 }} attribute \texttt{@style}\index{style=\texttt{\char'100 style} (attribute)}\index{attributes:!style=\texttt{\char'100 style}} is set to \texttt{"ruled"}\index{ruled=\texttt{"ruled"} (attribute value)}\index{attribute values:!ruled=\texttt{"ruled"}} the table will be ruled
%       horizontally and vertically\par
% \end{itemize}
%    \begin{macrocode}
  <!-- omit rows with @condition and some weird zero value -->
  <xsl:template
    match="db:row[@condition
           and
           count($thisdoc//*
                 [name()=name(current()/db:entry[1]/*[1])])
                 = 0]"/>
  <!-- normal rows -->
  <xsl:template
    match="db:row[not(@condition)
           or
           count($thisdoc//*
                 [name()=name(current()/db:entry[1]/*[1])])
                 > 0]">
    <xsl:value-of select="$shield"/>
    <xsl:text> </xsl:text>
    <xsl:if test="@role='header'">
      <!-- extra space except on first row -->
      <xsl:if test="count(preceding-sibling::db:row) > 1">
        <xsl:text>[2pt]\hline&#xa;</xsl:text>
        <xsl:value-of select="$shield"/>
        <xsl:text> </xsl:text>
      </xsl:if>
    </xsl:if>
    <xsl:if test="@role='groupstart'">
      <xsl:if test="count(preceding-sibling::db:row) > 1">
        <xsl:text>[2pt]\hline\hline&#xa;</xsl:text>
        <xsl:value-of select="$shield"/>
        <xsl:text> </xsl:text>
      </xsl:if>
    </xsl:if>
    <xsl:apply-templates/>
    <xsl:text>\\</xsl:text>
    <xsl:choose>
      <xsl:when test="starts-with(@role,'sep')">
        <xsl:text>[</xsl:text>
        <xsl:value-of select="substring-after(@role,'sep')"/>
        <xsl:text>]</xsl:text>
      </xsl:when>
      <xsl:when test="@role='header'">
        <xsl:text>[2pt]\hline\CPKvstrut</xsl:text>
      </xsl:when>
      <xsl:when
        test="(ancestor::db:tbody or ancestor::db:tfoot) 
              and position()=last()">
        <xsl:text>[2pt]\hline</xsl:text>
      </xsl:when>
      <xsl:when
        test="parent::*[1]/db:row[1][@rowsep='1']">
        <xsl:text>[1ex]</xsl:text>
      </xsl:when>
      <xsl:when
        test="ancestor::db:tbody/@style='ruled'">
        <xsl:text>\hline</xsl:text>
      </xsl:when>
    </xsl:choose>
    <xsl:if test="not(ancestor::db:thead)">
      <xsl:text>&#xa;</xsl:text>
    </xsl:if>
    <xsl:if test="@remap='newpage'">
      <xsl:value-of select="$shield"/>
      <xsl:text> \end{tabular}\par\vfill\flushright</xsl:text>
      <xsl:text>[continued…\par\endgroup\clearpage&#xa;</xsl:text>
      <xsl:for-each select="ancestor::db:tgroup[1]">
        <xsl:call-template name="tabstart"/>
      </xsl:for-each>
      <xsl:for-each select="ancestor::db:tgroup/db:thead[1]">
        <xsl:apply-templates/>
        <xsl:text>[2pt]\hline</xsl:text>
        <xsl:if test="ancestor::db:table/@condition='long'">
          <xsl:text>\endhead</xsl:text>
        </xsl:if>
        <xsl:text>&#xa;</xsl:text>
      </xsl:for-each>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{entryheadfoot}\label{template-figtab2latex-entryheadfoot}
% Table cells (the \texttt{<entry>}\index{entry=\texttt{\char'074 entry\char'076 } (element)}\index{elements:!entry=\texttt{\char'074 entry\char'076 }} elements) in the
%   \texttt{<thead>}\index{thead=\texttt{\char'074 thead\char'076 } (element)}\index{elements:!thead=\texttt{\char'074 thead\char'076 }} and \texttt{<tfoot>}\index{tfoot=\texttt{\char'074 tfoot\char'076 } (element)}\index{elements:!tfoot=\texttt{\char'074 tfoot\char'076 }} are turned into
%   {\ttfamily{}\textbackslash{}multicolumn}s because they may contain
%   heading text longer than the normal content of a body cell,
%   and therefore need to wrap to extra lines. This uses the
%   same code as for the standard table startup, using bottom
%   alignment.\par
%    \begin{macrocode}
  <xsl:template
    match="db:entry[ancestor::db:thead or
                    ancestor::db:tfoot]">
    <xsl:if test="preceding-sibling::db:entry">
      <xsl:text>&amp;&#xa;</xsl:text>
      <xsl:value-of select="$shield"/>
      <xsl:text> </xsl:text>
    </xsl:if>
    <!-- allow empty headers -->
    <xsl:if test="normalize-space(.)!=''">
      <!-- identify the column number -->
      <xsl:variable name="colpos"
        select="count(preceding-sibling::db:entry) + 1"/>
      <!-- ALWAYS make headers paragraphic, 
           which means \multicolumn{1}...
           because we don't know how 
           they need to be formatted -->
      <xsl:text>\multicolumn{</xsl:text>
      <xsl:choose>
        <xsl:when test="@spanname">
          <xsl:value-of select="@spanname"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>1</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>}{</xsl:text>
      <!-- omit LH shoulder on first column -->
      <xsl:if test="$colpos=1">
        <xsl:text>@{}</xsl:text>
      </xsl:if>
      <xsl:choose>
        <!-- if alignment or width is specified 
             in the heading cell itself, 
             use local settings, 
             honouring local prefix/suffix -->
        <xsl:when test="@align or @colwidth or @wordsize">
          <xsl:call-template name="colprefix">
            <xsl:with-param name="loc" select="'thead'"/>
          </xsl:call-template>
          <xsl:call-template name="colsettings">
            <xsl:with-param name="loc" select="'thead'"/>
          </xsl:call-template>
          <xsl:call-template name="colsuffix">
            <xsl:with-param name="loc" select="'thead'"/>
          </xsl:call-template>
        </xsl:when>
        <!-- otherwise use the column default, 
             but use local prefix/suffix by preference -->
        <xsl:otherwise>
          <!-- test for the prefix -->
          <xsl:choose>
            <xsl:when 
              test="ancestor::db:tgroup/db:colspec
                    [$colpos]/@condition
                    or 
                    ancestor::db:tgroup/db:colspec
                    [$colpos]/@colwidth
                    or 
                    ancestor::db:tgroup/db:colspec
                    [$colpos]/@wordsize">
              <xsl:for-each 
                select="ancestor::db:tgroup/db:colspec
                        [$colpos]">
                <xsl:call-template name="colprefix">
                  <xsl:with-param name="loc"
                    select="'thead'"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:when>
            <xsl:otherwise>
              <xsl:call-template name="colprefix"/>
            </xsl:otherwise>
          </xsl:choose>
          <!-- switch context to the colspec 
               to get the settings -->
          <xsl:for-each 
            select="ancestor::db:tgroup/db:colspec
                    [$colpos]">
            <xsl:call-template name="colsettings">
              <xsl:with-param name="loc"
                select="'thead'"/>
            </xsl:call-template>
          </xsl:for-each>
          <!-- test for the suffix -->
          <xsl:choose>
            <xsl:when 
              test="ancestor::db:tgroup/db:colspec
                    [position()=$colpos]/@condition
                    or 
                    ancestor::db:tgroup/db:colspec
                    [position()=$colpos]/@colwidth
                    or 
                    ancestor::db:tgroup/db:colspec
                    [position()=$colpos]/@wordsize">
              <xsl:for-each 
                select="ancestor::db:tgroup/db:colspec
                        [position()=$colpos]">
                <xsl:call-template name="colsuffix"/>
              </xsl:for-each>
            </xsl:when>
            <xsl:otherwise>
              <xsl:call-template name="colsuffix"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:if
        test="count(following-sibling::db:entry)=0">
        <xsl:text>@{}</xsl:text>
      </xsl:if>
      <xsl:text>}{\sffamily\bfseries </xsl:text>
      <xsl:apply-templates/>
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \par\smallskip\leavevmode
% \CPKrunningecho{entryheadfoot}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Entry head/foot code needs moving to a named template}}\par\smallskip
% \end{CPKtemplate}
% \begin{CPKtemplate}{entrybody}\label{template-figtab2latex-entrybody}
% Cells in the table body are check for multicolumn spans,
% overhangs, bold for crossheads, and row spans.\par
%    \begin{macrocode}
  <xsl:template match="db:entry[ancestor::db:tbody]">
    <xsl:variable name="colpos"
      select="count(preceding-sibling::db:entry) + 1"/>
    <xsl:if test="preceding-sibling::db:entry">
      <xsl:text>&amp;</xsl:text>
    </xsl:if>
    <xsl:if test="@spanname">
      <xsl:text>\multicolumn{</xsl:text>
      <xsl:value-of select="@spanname"/>
      <xsl:text>}{</xsl:text>
      <xsl:if
        test="count(preceding-sibling::db:entry)=0">
        <xsl:text>@{}</xsl:text>
      </xsl:if>
      <xsl:choose>
        <!-- if alignment or width is specified, 
             use local settings -->
        <xsl:when test="@align or @wordsize">
          <xsl:call-template name="colprefix"/>
          <xsl:call-template name="colsettings"/>
          <xsl:call-template name="colsuffix"/>
        </xsl:when>
        <!-- otherwise use default, 
             but check local pre and post -->
        <xsl:otherwise>
          <xsl:call-template name="colprefix"/>
          <xsl:for-each 
            select="ancestor::db:tgroup/db:colspec
                    [position()=$colpos]">
            <xsl:call-template name="colsettings"/>
          </xsl:for-each>
          <xsl:call-template name="colsuffix"/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:if
        test="count(following-sibling::db:entry)=0">
        <xsl:text>@{}</xsl:text>
      </xsl:if>
      <xsl:text>}{</xsl:text>
    </xsl:if>
    <!-- check for hangouts -->
    <xsl:if test="@annotations">
      <xsl:text>\llap{\normalfont </xsl:text>
      <xsl:value-of select="@annotations"/>
      <xsl:text>}</xsl:text>
    </xsl:if>
    <!-- text for headers is in bold -->
    <xsl:if test="../@role='header'">
      <xsl:text>\CPKvstrut\bfseries </xsl:text>
    </xsl:if>
    <!-- check for row-spanned brace-collected -->
    <xsl:if test="@morerows">
      <xsl:if test="@charoff and @char">
        <xsl:text>\llap{</xsl:text>
        <xsl:value-of select="@char"/>
        <xsl:text>{</xsl:text>
        <xsl:value-of select="@morerows"/>
        <xsl:text>}{</xsl:text>
        <xsl:value-of select="@charoff"/>
        <xsl:text>}</xsl:text>
        <xsl:text>}%&#xa;</xsl:text>
        <xsl:value-of select="$shield"/>
        <xsl:text> &#x9;</xsl:text>
      </xsl:if>
      <xsl:text>\multirow{</xsl:text>
      <xsl:value-of select="@morerows"/>
      <xsl:text>}{</xsl:text>
      <xsl:value-of select="@wordsize"/>
      <xsl:text>}{</xsl:text>
    </xsl:if>
    <!-- now we're in the content at last -->
    <xsl:if test="@condition">
      <xsl:value-of select="@condition"/>
      <xsl:text>{}</xsl:text>
    </xsl:if>
    <xsl:choose>
      <!-- mldr &#x2026; on its own (\dotfill) 
           needs a \hbox -->
      <xsl:when test=".='\dotfill{}' and @wordsize">
        <xsl:text>\hbox to </xsl:text>
        <xsl:value-of select="@wordsize"/>
        <xsl:text>{</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>}</xsl:text>
      </xsl:when>
      <!-- hardwired exceptions to special characters -->
      <xsl:when test="@conformance">
        <xsl:value-of select="@conformance"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
    <!-- additional manual extras before end of cell -->
    <xsl:value-of select="@userlevel"/>
    <!-- end of entry, before any grouping -->
    <xsl:if 
      test="ancestor::db:tbody/db:row[1][@rowsep='1']
            and 
            ancestor::db:tgroup/db:colspec
            [position()=$colpos][@colwidth]
            and
            not(position()=last())">
      <xsl:text>\vrule depth1em width0pt</xsl:text>
    </xsl:if>
    <xsl:if test="@morerows">
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:if test="@spanname">
      <xsl:text>}</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsubsection*{Figures}
% \begin{CPKtemplate}{figure}\label{template-figtab2latex-figure}
% A whole-page PDF illustration gets a forced page-break
%   before and after, to ensure it occurs where it is requested,
%   rather than floating to later. The remainder of the
%   \texttt{figure} environment is constructed similarly
%   to the tables, but any changes to fonts are left to the
%   content.\par
%    \begin{macrocode}
  <xsl:template match="db:figure">
    <xsl:if
      test="@floatstyle='p'
            and
            descendant::db:imagedata
              [@format='pdf' and @condition]">
      <xsl:value-of select="$shield"/>
      <xsl:text> \clearpage&#xa;</xsl:text>
    </xsl:if>
    <xsl:value-of select="$shield"/>
    <xsl:text> \begin{figure}[</xsl:text>
    <xsl:choose>
      <xsl:when test="@floatstyle">
        <xsl:value-of select="@floatstyle"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>ht</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>]</xsl:text>
    <xsl:text>\small\sffamily&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:value-of select="$shield"/>
    <xsl:text> \end{figure}&#xa;</xsl:text>
    <xsl:if test="@floatstyle='p'
                  and
                  descendant::db:imagedata
                    [@format='pdf' and @condition]">
      <xsl:value-of select="$shield"/>
      <xsl:text> \clearpage&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{informalfigure}\label{template-figtab2latex-informalfigure}
% An informal figure is just a centred image.\par
%    \begin{macrocode}
  <xsl:template match="db:informalfigure">
    <xsl:value-of select="$shield"/>
    <xsl:text> \begin{center}&#xa;</xsl:text>
    <xsl:apply-templates/>
    <xsl:value-of select="$shield"/>
    <xsl:text> \end{center}&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{mediaobject}\label{template-figtab2latex-mediaobject}
% Images themselves can be framed, and the width adjusted
%   for the border and rule thickness.\par
%    \begin{macrocode}
  <xsl:template match="db:mediaobject
                       [not(parent::db:figure)]">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="db:figure/db:mediaobject | 
                       db:informalfigure/db:mediaobject">
    <xsl:if test="@role='framed'">
      <xsl:value-of select="$shield"/>
      <xsl:text> \fbox{\vbox{%</xsl:text>
      <xsl:value-of select="$shield"/>
      <xsl:text>   \advance\hsize by-2\fboxsep</xsl:text>
      <xsl:text>\advance\hsize by-2\fboxrule&#xa;</xsl:text>
    </xsl:if>
    <xsl:apply-templates/>
    <xsl:if test="@role='framed'">
      <xsl:value-of select="$shield"/>
      <xsl:text> }}&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{imageobject}\label{template-figtab2latex-imageobject}
% This element controls for the presence of multiple
%   images, which can be stacked left-to-right, or allowed to
%   occur vertically.\par
%    \begin{macrocode}
  <xsl:template match="db:imageobject">
    <xsl:choose>
      <!-- detect a previous image -->
      <xsl:when test="preceding-sibling::*[1]
                      [local-name()='imageobject']">
        <xsl:choose>
          <xsl:when test="@dir='ltr'">
            <xsl:value-of select="$shield"/>
            <xsl:text> \quad\vrule\quad&#xa;</xsl:text>
          </xsl:when>
          <xsl:when test="ancestor::db:figure">
            <xsl:value-of select="$shield"/>
            <xsl:text> \par&#xa;</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$shield"/>
            <xsl:text> \\&#xa;</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text></xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{imagedata}\label{template-figtab2latex-imagedata}
% The \texttt{<imagedata>}\index{imagedata=\texttt{\char'074 imagedata\char'076 } (element)}\index{elements:!imagedata=\texttt{\char'074 imagedata\char'076 }} specifies the image file,
%   alignment, framing of non-PDF images, width, depth, and
%   scale.\par
% The default alignment, like tables, is centering. Images
%   may be framed by setting the \texttt{@arch}\index{arch=\texttt{\char'100 arch} (attribute)}\index{attributes:!arch=\texttt{\char'100 arch}} to \texttt{"framed"}\index{framed=\texttt{"framed"} (attribute value)}\index{attribute values:!framed=\texttt{"framed"}}.\par
%    \begin{macrocode}
  <xsl:template match="db:imagedata">
    <!-- alignment -->
    <xsl:choose>
      <xsl:when test="@align='center' or not(@align)">
        <xsl:value-of select="$shield"/>
        <xsl:text> \centering&#xa;</xsl:text>
      </xsl:when>
      <xsl:when test="@align='right'">
        <xsl:value-of select="$shield"/>
        <xsl:text> \flushright&#xa;</xsl:text>
      </xsl:when>
    </xsl:choose>
    <!-- reframe non-PDFs ??? -->
    <xsl:if test="@arch='framed' and not(@format='pdf')">
      <xsl:value-of select="$shield"/>
      <xsl:text> </xsl:text>
      <xsl:if test="@contentdepth">
        <xsl:text>\fboxsep</xsl:text>
        <xsl:value-of select="@contentdepth"/>
      </xsl:if>
      <xsl:text>\fbox{%&#xa;</xsl:text>
    </xsl:if>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{imagedatafiles}\label{template-figtab2latex-imagedatafiles}
% The \texttt{@fileref}\index{fileref=\texttt{\char'100 fileref} (attribute)}\index{attributes:!fileref=\texttt{\char'100 fileref}} attribute holds
%   the filename. \textsc{pdf} page images are
%   included with the {\ttfamily{}\textbackslash{}includepdf} command from
%   the \textsf{pdfpages} package; otherwise the
%   normal {\ttfamily{}\textbackslash{}includegraphics} command from the
%   \textsf{graphicx} package is used. The \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} can be used to hold
%   optional arguments for the {\ttfamily{}\textbackslash{}includepdf}
%   command for \textsc{pdf} images; otherwise the
%   \texttt{@width}\index{width=\texttt{\char'100 width} (attribute)}\index{attributes:!width=\texttt{\char'100 width}} and \texttt{@depth}\index{depth=\texttt{\char'100 depth} (attribute)}\index{attributes:!depth=\texttt{\char'100 depth}} attributes are used for
%   width and height (in units or percent of the textwidth or
%   textheight).\par
%    \begin{macrocode}
    <xsl:choose>
      <xsl:when test="@fileref">
        <xsl:choose>
          <xsl:when test="@format='pdf' and @condition">
            <xsl:value-of select="$shield"/>
            <xsl:text> \includepdf</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$shield"/>
            <xsl:text> \includegraphics</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>[</xsl:text>
        <xsl:choose>
          <xsl:when test="@condition">
            <xsl:value-of
              select="normalize-space(@condition)"/>
            <xsl:if
              test="@arch='framed' and @format='pdf'">
              <xsl:text>,frame</xsl:text>
            </xsl:if>
          </xsl:when>
          <xsl:when test="@width">
            <xsl:text>width=</xsl:text>
            <xsl:choose>
              <xsl:when test="contains(@width,'%')">
                <xsl:value-of 
                  select="number(substring-before
                          (@width,'%'))
                          div 100"/>
                <xsl:text>\columnwidth</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="@width"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:when test="@depth">
            <xsl:text>height=</xsl:text>
            <xsl:choose>
              <xsl:when test="contains(@depth,'%')">
                <xsl:value-of 
                  select="number(substring-before
                          (@depth,'%'))
                          div 100"/>
                <xsl:text>\textheight</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="@depth"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:when test="@scalefit='1'">
            <xsl:text>width=.5\columnwidth</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:variable name="numpix"
              select="count(ancestor::db:mediaobject
                            /db:imageobject)"/>
            <xsl:variable name="numpixfrac"
              select="1 div $numpix"/>
            <xsl:text>width=</xsl:text>
            <xsl:value-of select="$numpixfrac"/>
            <xsl:text>\columnwidth</xsl:text>
            <!-- allow for the \quad\vrule\quad 
                 between multiple images 
                 for which we use the 
                 notional value 2.2em -->
            <xsl:if test="$numpix>1">
              <xsl:text> - </xsl:text>
              <xsl:value-of select="($numpix - 1)*2.2"/>
              <xsl:text>em</xsl:text>
            </xsl:if>
            <xsl:if test="@arch='framed'">
              <xsl:text> - 2\fboxsep - 1\fboxrule</xsl:text>
            </xsl:if>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>]</xsl:text>
        <xsl:text>{</xsl:text>
        <xsl:value-of select="@fileref"/>
        <xsl:text>}</xsl:text>
      </xsl:when>
%    \end{macrocode}
% In the case of multiple \texttt{<imageobject>}\index{imageobject=\texttt{\char'074 imageobject\char'076 } (element)}\index{elements:!imageobject=\texttt{\char'074 imageobject\char'076 }} elements
%   for multiple images, they are scaled to fit
%   side-by-side.\par
% \end{CPKtemplate}
% \begin{CPKtemplate}{imagedataremap}\label{template-figtab2latex-imagedataremap}
% If no filename is specified, the contents of the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} and \texttt{@remap}\index{remap=\texttt{\char'100 remap} (attribute)}\index{attributes:!remap=\texttt{\char'100 remap}} attributes are output, if
%   present; otherwise the word `IMAGE'
%   is used as a placeholder.\par
%    \begin{macrocode}
      <xsl:when test="@remap">
        <xsl:value-of select="$shield"/>
        <xsl:text> </xsl:text>
        <xsl:if test="@condition">
          <xsl:text>{</xsl:text>
          <xsl:value-of
            select="normalize-space(@condition)"/>
        </xsl:if>
        <xsl:value-of select="@remap"/>
        <xsl:if test="@condition">
          <xsl:text>}</xsl:text>
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>IMAGE</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="@arch='framed'
                  and
                  not(@format='pdf')">
      <xsl:text>}</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{textobject}\label{template-figtab2latex-textobject}
% Textual figure are done with the \texttt{<textobject>}\index{textobject=\texttt{\char'074 textobject\char'076 } (element)}\index{elements:!textobject=\texttt{\char'074 textobject\char'076 }}
%   element.\par
%    \begin{macrocode}
  <xsl:template match="db:textobject">
    <xsl:text>\\[3pt]\raggedright&#xa;</xsl:text>
    <xsl:apply-templates/>
  </xsl:template>

</xsl:stylesheet>
%    \end{macrocode}
% \end{CPKtemplate}
% \iffalse
%</figtabscript>
% \fi
% \iffalse
%<*db2mdscript>
% \fi
% \clearpage
% \section{The {\ttfamily{}db2md.xsl} script}\label{db2mdscript}
% \setcounter{CodelineNo}{0}
% These are templates used to generate the
% {\ttfamily{}README.md} file required by
% \textsc{ctan}\index{CTAN} submissions. They use the boilerplate
% text in {\ttfamily{}readme.xml}\thinspace. This tries to follow
% the CTAN requirements documented at \href{https://ctan.org/help/markdown/style}{\nolinkurl{https://ctan.org/help/markdown/style}}\thinspace.\par
% \begin{CPKcomment}{db2mdscript-comment}\label{comment-db2mdscript}
% Identify the file origin,
% date, time, etc.\par
%    \begin{macrocode}
<!-- The db2md.xsl script (from the classpack package v.1.28, 2024-02-21) -->
<!-- Generated by ClassPack v.1.28 (2024-02-21) on 24-03-04T22:35:19 -->
%    \end{macrocode}
% These lines are automatically prepended to the file
% and may be removed if necessary,
% using a suitable editor.
% \end{CPKcomment}
% \subsection{XML Declaration, namespaces, and setup}
% The namespaces are the same as for the calling routine,
%   {\ttfamily{}db2dtx.xsl}\thinspace.\par
% \begin{CPKtemplate}{init}\label{template-db2md-init3}
% Set up the namespaces, the same as for the main script.\par
%    \begin{macrocode}
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:db="http://docbook.org/ns/docbook"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:sil="http://xml.silmaril.ie/identity/functions"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  version="3.0">
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{setup}\label{db2dt-setup}
% Use the current context to remember what the main
%   document was; and be nice to editors with the line width.\par
%    \begin{macrocode}
  <xsl:variable name="maindoc" select="."/>

  <xsl:variable name="width">
    <xsl:text>72</xsl:text>
  </xsl:variable>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{plaintext}\label{template-db2md-plaintext}
% \begingroup\raggedright[\url{db:title} with \url{[not(parent::db:chapter) and not(parent::db:sect1) and not(parent::db:sect2) and not(parent::db:sect3) and not(parent::db:warning) and not(parent::db:formalpara)]} 
% and \url{db:para} with \url{[not(parent::db:listitem) and not(ancestor::db:variablelist) and not(parent::db:warning) and not(parent::db:formalpara)]} 
% and \url{db:remark} 
% ]\par\endgroup
% Plain titles and plain paras and remarks (used for
%     documentation of the documentation). Note that Abstract
%     paragraphs match this template.\par
%    \begin{macrocode}
  <xsl:template mode="readme"
    match="db:title[not(parent::db:chapter) and
                    not(parent::db:sect1) and
                    not(parent::db:sect2) and
                    not(parent::db:sect3) and
                    not(parent::db:warning) and
                    not(parent::db:formalpara)]
                    | 
           db:para[not(parent::db:listitem) and
                   not(parent::db:warning) and
                   not(parent::db:formalpara)]
                   |
           db:remark">
    <xsl:variable name="content">
      <xsl:apply-templates select="node()" mode="inline"/>
    </xsl:variable>
    <!-- blank line (previously elided in rendering MD???) -->
    <xsl:value-of select="$sentinel"/>
    <xsl:text>&#xa;</xsl:text>
    <!-- call the prefix-generator to handle the flag -->
    <xsl:call-template name="markup"/>
    <xsl:call-template name="normtext">
      <xsl:with-param name="content"
        select="normalize-space($content)"/>
      <xsl:with-param name="indent">
        <xsl:if
          test="ancestor::db:part[@xml:id='code']
                or
                ancestor::db:procedure
                [@xml:id='prepackage']">
          <xsl:value-of select="$sentinel"/>
        </xsl:if>
      </xsl:with-param>
    </xsl:call-template>
    <xsl:if test="ancestor::db:part[@xml:id!='code']">
      <xsl:text>&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:title}\label{template-db2md-title7}
% \begingroup\raggedright[in \url{db:chapter/} 
% and \url{db:sect1/db:title} 
% and \url{db:sect2/db:title} 
% and \url{db:sect3/db:title} 
% and \url{db:bridgehead} 
% ]\par\endgroup
% Section titles all work the same way (increasing
%     numbers of hash marks): chapter, section, subsection,
%     subsubsection and bridgeheads. In each case make the
%     content with markup, make the markup, normalize the
%     output, and indent it as needed.\par
%    \begin{macrocode}
  <xsl:template match="db:chapter/db:title" mode="readme">
    <xsl:variable name="content">
      <xsl:apply-templates select="node()" mode="inline"/>
    </xsl:variable>
    <xsl:call-template name="markup">
      <xsl:with-param name="flag" select="'#'"/>
    </xsl:call-template>
    <xsl:call-template name="normtext">
      <xsl:with-param name="content"
        select="normalize-space($content)"/>
      <xsl:with-param name="indent">
        <xsl:if
          test="ancestor::db:part[@xml:id='code'] or
                ancestor::db:procedure[@xml:id='prepackage']">
          <xsl:value-of select="$sentinel"/>
        </xsl:if>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="db:sect1/db:title" mode="readme">
    <xsl:variable name="content">
      <xsl:apply-templates select="node()" mode="inline"/>
    </xsl:variable>
    <xsl:call-template name="markup">
      <xsl:with-param name="flag" select="'##'"/>
    </xsl:call-template>
    <xsl:call-template name="normtext">
      <xsl:with-param name="content"
        select="normalize-space($content)"/>
      <xsl:with-param name="indent">
        <xsl:if
          test="ancestor::db:part[@xml:id='code'] or
                ancestor::db:procedure[@xml:id='prepackage']">
          <xsl:value-of select="$sentinel"/>
        </xsl:if>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="db:sect2/db:title" mode="readme">
    <xsl:variable name="content">
      <xsl:apply-templates select="node()" mode="inline"/>
    </xsl:variable>
    <xsl:call-template name="markup">
      <xsl:with-param name="flag" select="'###'"/>
    </xsl:call-template>
    <xsl:call-template name="normtext">
      <xsl:with-param name="content"
        select="normalize-space($content)"/>
      <xsl:with-param name="indent">
        <xsl:if
          test="ancestor::db:part[@xml:id='code'] or
                ancestor::db:procedure[@xml:id='prepackage']">
          <xsl:value-of select="$sentinel"/>
        </xsl:if>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="db:sect3/db:title" mode="readme">
    <xsl:variable name="content">
      <xsl:apply-templates select="node()" mode="inline"/>
    </xsl:variable>
    <xsl:call-template name="markup">
      <xsl:with-param name="flag" select="'####'"/>
    </xsl:call-template>
    <xsl:call-template name="normtext">
      <xsl:with-param name="content"
        select="normalize-space($content)"/>
      <xsl:with-param name="indent">
        <xsl:if
          test="ancestor::db:part[@xml:id='code'] or
                ancestor::db:procedure[@xml:id='prepackage']">
          <xsl:value-of select="$sentinel"/>
        </xsl:if>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="db:bridgehead" mode="readme">
    <xsl:variable name="content">
      <xsl:apply-templates select="node()" mode="inline"/>
    </xsl:variable>
    <xsl:call-template name="markup">
      <xsl:with-param name="flag" select="'#####'"/>
    </xsl:call-template>
    <xsl:call-template name="normtext">
      <xsl:with-param name="content"
        select="normalize-space($content)"/>
      <xsl:with-param name="indent">
        <xsl:if
          test="ancestor::db:part[@xml:id='code'] or
                ancestor::db:procedure[@xml:id='prepackage']">
          <xsl:value-of select="$sentinel"/>
        </xsl:if>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:warning}\label{template-db2md-warning2}
% \begingroup\raggedright[\url{db:warning} 
% and \url{db:warning/db:title} 
% ]\par\endgroup
% Warning titles work the same way but with a
%     greater-than prefix to the hash marks.\par
%    \begin{macrocode}
  <xsl:template match="db:warning" mode="readme">
    <xsl:if test="not(db:title)">
      <xsl:text>&#xa;> #### WARNING</xsl:text>
    </xsl:if>
    <xsl:apply-templates mode="readme"/>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="db:warning/db:title" mode="readme">
    <xsl:variable name="content">
      <xsl:apply-templates select="node()" mode="inline"/>
    </xsl:variable>
    <xsl:call-template name="markup">
      <xsl:with-param name="flag" select="'&#xa;> #### '"/>
    </xsl:call-template>
    <xsl:call-template name="normtext">
      <xsl:with-param name="content"
        select="normalize-space($content)"/>
      <xsl:with-param name="indent">
        <xsl:if
          test="ancestor::db:part[@xml:id='code'] or
                ancestor::db:procedure[@xml:id='prepackage']">
          <xsl:value-of select="$sentinel"/>
        </xsl:if>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{parawarn}\label{template-db2md-parawarn}
% \begingroup\raggedright[\url{db:para} with \url{[parent::db:warning or parent::db:formalpara]} 
% ]\par\endgroup
% Warning paragraphs and formal paragraphs are also
%     output with the greater-than markup.\par
% \par\smallskip\leavevmode
% \CPKrunningecho{parawarn}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: Not supported in code annotations (yet!)}}\par\smallskip
%    \begin{macrocode}
  <!-- This has to cope with being called from 
       within db2dtx.xsl as well, to generate inline 
       documentation that passes through to 
       the .sty or .cls file -->
  <xsl:template
    match="db:para[parent::db:warning or
                   parent::db:formalpara]" mode="readme">
    <xsl:variable name="content">
      <xsl:apply-templates select="node()" mode="inline"/>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="ancestor::db:chapter[@xml:id='readme']">
        <xsl:text>> </xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>&#xa;% </xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:value-of select="normalize-space($content)"/>
    <xsl:choose>
      <xsl:when test="ancestor::db:chapter[@xml:id='readme']">
        <xsl:text>&#xa;> </xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>&#xa;% &#xa;</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:formalpara}\label{template-db2md-formalpara2}
% \begingroup\raggedright[in \url{db:formalpara/} 
% ]\par\endgroup
% The \texttt{<formalpara>}\index{formalpara=\texttt{\char'074 formalpara\char'076 } (element)}\index{elements:!formalpara=\texttt{\char'074 formalpara\char'076 }} structure is used in the
%   same way as warnings.\par
%    \begin{macrocode}
  <xsl:template match="db:formalpara/db:title" mode="readme">
    <xsl:variable name="content">
      <xsl:apply-templates select="node()" mode="inline"/>
    </xsl:variable>
    <xsl:call-template name="markup">
      <xsl:with-param name="flag" select="'> #### '"/>
    </xsl:call-template>
    <xsl:call-template name="normtext">
      <xsl:with-param name="content"
        select="normalize-space($content)"/>
      <xsl:with-param name="indent">
        <xsl:if
          test="ancestor::db:part[@xml:id='code'] or
                ancestor::db:procedure[@xml:id='prepackage']">
          <xsl:value-of select="$sentinel"/>
        </xsl:if>
      </xsl:with-param>
    </xsl:call-template>
    <xsl:call-template name="markup">
      <xsl:with-param name="flag"
        select="' ####&#xa;> &#xa;'"/>
    </xsl:call-template>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:programlisting}\label{template-db2md-programlisting2}
% We determine the type of document (class or package)
%     so that, if the \texttt{@condition}\index{condition=\texttt{\char'100 condition} (attribute)}\index{attributes:!condition=\texttt{\char'100 condition}} is
%     not specified, or if it matches the current document type,
%     interpret the content rather than treating it as character
%     data, because it may contain embedded markup like
%     \texttt{<olink>}\index{olink=\texttt{\char'074 olink\char'076 } (element)}\index{elements:!olink=\texttt{\char'074 olink\char'076 }}.\par
%    \begin{macrocode}
  <xsl:template match="db:programlisting" mode="readme">
    <xsl:variable name="curdoctype">
      <xsl:value-of select="$maindoc/db:book/@arch"/>
    </xsl:variable>
    <xsl:if test="@condition=$curdoctype
                  or
                  not(@condition)">
      <xsl:variable name="content">
        <xsl:apply-templates select="node()"
          mode="inline"/>
      </xsl:variable>
      <xsl:call-template name="markup"/>
      <xsl:text>&#xa;</xsl:text>
      <!-- now github method -->
      <xsl:text>```</xsl:text>
      <xsl:if test="@language">
        <xsl:value-of select="@language"/>
      </xsl:if>
      <!-- was four leading spaces for MarkDown verbatim.
           do NOT expect to find escaped TeX in $content
      <xsl:for-each select="tokenize($content,'&#xa;')">
        <xsl:text>    </xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>&#xa;</xsl:text>
      </xsl:for-each>
      -->
      <xsl:value-of select="replace($content,
                            '[ &#xa;&#x9;][ &#xa;&#x9;]*$',
                            '&#xa;')"/>
      <xsl:if
        test="not(matches(substring($content,
              string-length($content)),
              '[ \n\t]'))">
        <xsl:text>&#xa;</xsl:text>
      </xsl:if>
      <xsl:text>```&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:exceptionname}\label{template-db2md-exceptionname2}
% Marker for RFC2119 required vocabulary.\par
%    \begin{macrocode}
  <xsl:template match="db:exceptionname" mode="inline">
    <xsl:value-of select="upper-case(.)"/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:variablelist}\label{template-db2md-variablelist2}
% Discussion lists (\texttt{<variablelist>}\index{variablelist=\texttt{\char'074 variablelist\char'076 } (element)}\index{elements:!variablelist=\texttt{\char'074 variablelist\char'076 }}\kern1pt{}s) are done with the
%     \textsc{html}\index{HTML} \texttt{<dl>}\index{dl=\texttt{\char'074 dl\char'076 } (element)}\index{elements:!dl=\texttt{\char'074 dl\char'076 }} element.\par
%    \begin{macrocode}
  <xsl:template match="db:variablelist" mode="readme">
    <xsl:call-template name="markup">
      <xsl:with-param name="flag"
        select="'&#xa;&lt;dl>'"/>
    </xsl:call-template>
    <xsl:apply-templates mode="readme"/>
    <xsl:call-template name="markup">
      <xsl:with-param name="flag"
        select="'&#xa;&lt;/dl>&#xa;'"/>
    </xsl:call-template>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:term}\label{template-db2md-term2}
% The \texttt{<term>}\index{term=\texttt{\char'074 term\char'076 } (element)}\index{elements:!term=\texttt{\char'074 term\char'076 }} element in a
%     \texttt{<variablelist>}\index{variablelist=\texttt{\char'074 variablelist\char'076 } (element)}\index{elements:!variablelist=\texttt{\char'074 variablelist\char'076 }} becomes the \texttt{<dt>}\index{dt=\texttt{\char'074 dt\char'076 } (element)}\index{elements:!dt=\texttt{\char'074 dt\char'076 }}.\par
%    \begin{macrocode}
  <xsl:template match="db:term" mode="readme">
    <xsl:variable name="content">
      <xsl:apply-templates select="node()" mode="inline"/>
    </xsl:variable>
    <xsl:call-template name="markup">
      <xsl:with-param name="flag"
        select="'&#xa;  &lt;dt>'"/>
    </xsl:call-template>
    <xsl:call-template name="normtext">
      <xsl:with-param name="content"
        select="normalize-space($content)"/>
      <xsl:with-param name="indent">
        <xsl:if
          test="ancestor::db:part[@xml:id='code'] or
                ancestor::db:procedure[@xml:id='prepackage']">
          <xsl:value-of select="$sentinel"/>
        </xsl:if>
      </xsl:with-param>
    </xsl:call-template>
    <xsl:choose>
      <!-- only add extra flag when outputting MD -->
      <xsl:when test="ancestor::db:book/@arch='script'">
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="markup">
          <xsl:with-param name="flag" select="'&lt;/dt>'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:para}\label{template-db2md-para2}
% \begingroup\raggedright[\url{db:para } with \url{[parent::db:listitem [parent::db:orderedlist or parent::db:itemizedlist]]} 
% ]\par\endgroup
% A paragraph in an itemized list or ordered list gets
%   an asterisk for unnumbered or a digit for numbered.\par
%    \begin{macrocode}
  <!-- inline list paragraph -->
  <xsl:template
    match="db:para
           [parent::db:listitem
             [parent::db:orderedlist
              or
              parent::db:itemizedlist]]"  mode="readme">
    <xsl:variable name="content">
      <xsl:apply-templates select="node()" mode="inline"/>
    </xsl:variable>
    <xsl:text>&#xa;</xsl:text>
    <xsl:call-template name="markup"/>
    <xsl:choose>
      <xsl:when test="ancestor::db:itemizedlist">
        <xsl:text>  *  </xsl:text>
      </xsl:when>
      <xsl:when test="ancestor::db:orderedlist">
        <xsl:text> </xsl:text>
        <xsl:if
          test="count(parent::db:listitem/
                      preceding-sibling::db:listitem)&lt;9">
          <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:value-of 
          select="count(parent::db:listitem/
                        preceding-sibling::db:listitem)+1"/>
        <xsl:text>. </xsl:text>
      </xsl:when>
    </xsl:choose>
    <xsl:call-template name="normtext">
      <xsl:with-param name="content"
        select="normalize-space($content)"/>
      <xsl:with-param name="indent">
        <xsl:if
          test="ancestor::db:part[@xml:id='code'] or
                ancestor::db:procedure[@xml:id='prepackage']">
          <xsl:value-of select="$sentinel"/>
        </xsl:if>
      </xsl:with-param>
    </xsl:call-template>
    <xsl:call-template name="markup"/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:para}\label{template-db2md-para3}
% \begingroup\raggedright[\url{db:para} with \url{[ancestor::db:variablelist]} 
% ]\par\endgroup
% A paragraph in a \texttt{<variablelist>}\index{variablelist=\texttt{\char'074 variablelist\char'076 } (element)}\index{elements:!variablelist=\texttt{\char'074 variablelist\char'076 }} item becomes
%     a \texttt{<dd>}\index{dd=\texttt{\char'074 dd\char'076 } (element)}\index{elements:!dd=\texttt{\char'074 dd\char'076 }}.\par
%    \begin{macrocode}
  <xsl:template match="db:para[ancestor::db:variablelist]
                       [not(parent::db:warning)]"
    mode="readme">
    <xsl:variable name="content">
      <xsl:apply-templates select="node()" mode="inline"/>
    </xsl:variable>
    <xsl:call-template name="markup">
      <xsl:with-param name="flag" select="'&#xa;  &lt;dd>'"/>
    </xsl:call-template>
    <xsl:call-template name="normtext">
      <xsl:with-param name="content"
        select="normalize-space($content)"/>
      <xsl:with-param name="indent">
        <xsl:if
          test="ancestor::db:part[@xml:id='code'] or
                ancestor::db:procedure[@xml:id='prepackage']">
          <xsl:value-of select="$sentinel"/>
        </xsl:if>
      </xsl:with-param>
    </xsl:call-template>
    <xsl:choose>
      <!-- only add extra flag when outputting MD -->
      <xsl:when test="ancestor::db:book/@arch='script'">
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="markup">
          <xsl:with-param name="flag" select="'&lt;/dd>'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:sect1}\label{template-db2md-sect12}
% Special treatment for a \texttt{<sect1>}\index{sect1=\texttt{\char'074 sect1\char'076 } (element)}\index{elements:!sect1=\texttt{\char'074 sect1\char'076 }} with the
%     \texttt{<ID>}\index{ID=\texttt{\char'074 ID\char'076 } (element)}\index{elements:!ID=\texttt{\char'074 ID\char'076 }} of \texttt{"bugs"}\index{bugs=\texttt{"bugs"} (attribute value)}\index{attribute values:!bugs=\texttt{"bugs"}}.\par
%    \begin{macrocode}
  <xsl:template match="db:sect1" mode="readme">
    <xsl:choose>
      <xsl:when 
        test="@xml:id='bugs' and 
              $maindoc//db:revhistory/db:revision[1]/
              db:revdescription/db:orderedlist">
        <xsl:apply-templates mode="readme" select="db:title"/>
        <xsl:text>The following need attention:&#xa;&#xa;</xsl:text>
        <xsl:apply-templates  mode="readme"
          select="$maindoc//db:revhistory/db:revision[1]/
                  db:revdescription/db:orderedlist"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates mode="readme"/>        
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:anchor}\label{template-db2md-anchor}
% The \texttt{<anchor>}\index{anchor=\texttt{\char'074 anchor\char'076 } (element)}\index{elements:!anchor=\texttt{\char'074 anchor\char'076 }} element is used to fetch the
%     content of an element type whose name is
%     \emph{not} the one in {\ttfamily{}\$omit} and whose ancestor
%     \emph{is} one named in the {\ttfamily{}\$loc} parameter.  It also gets
%     used to retrieve the whole of the copyright
%     statement.\par
% \par\smallskip\leavevmode
% \CPKrunningecho{db:anchor}%
% \leavevmode\kern-12pt\colorbox{Black}{\vbox{\advance\hsize by-2em
%   \color{White}\sffamily\raggedright TODO: The pos seems to be redundant now}}\par\smallskip
%    \begin{macrocode}
  <xsl:template match="db:anchor" mode="readme">
    <xsl:variable name="loc" select="@targetptr"/>
    <xsl:variable name="pos" select="@type"/>
    <xsl:variable name="omit" select="@remap"/>
    <xsl:choose>
      <!-- special usage referencing a macro -->
      <xsl:when
        test="@targetptr='copyright' and @type='*'">
        <xsl:variable name="content">
          <xsl:for-each select="$maindoc">
            <xsl:call-template name="copyright-statement">
              <xsl:with-param name="ftype"
                select="/db:book/@userlevel"/>
            </xsl:call-template>
          </xsl:for-each>
        </xsl:variable>
        <xsl:text>&#xa;</xsl:text>
        <xsl:for-each select="tokenize($content,'&#xa;')">
          <xsl:text>    </xsl:text>
          <xsl:value-of select="replace(.,'^%','')"/>
          <xsl:text>&#xa;</xsl:text>
        </xsl:for-each>
      </xsl:when>
      <!-- normal operation, eg abstract -->
      <xsl:otherwise>
        <xsl:apply-templates mode="readme"
          select="$maindoc/
                  descendant::*[local-name()=$loc][1]
                  /*[local-name()!=$omit]"/>
        <!-- image -->
        <xsl:if
          test="$maindoc/
                descendant::*[local-name()=$loc][1]
                /@xlink:href">
          <xsl:for-each
            select="$maindoc/
                    descendant::*[local-name()=$loc][1]">
            <xsl:text>&#xa;![</xsl:text>
            <xsl:value-of select="normalize-space(@xlink:title)"/>
            <xsl:text>](</xsl:text>
            <xsl:if test="@vendor">
              <xsl:value-of select="@vendor"/>
            </xsl:if>
            <xsl:value-of select="@xlink:href"/>
            <xsl:text>)&#xa;</xsl:text>
          </xsl:for-each>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:olink}\label{template-db2md-olink}
% This template retrieves values from the main document
%     via the named template \DescribeTemplate{metadata}{\ttfamily{}metadata}.\par
%    \begin{macrocode}
  <xsl:template match="db:olink" mode="inline">
    <xsl:call-template name="metadata"/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:literallayout}\label{template-db2md-literallayout2}
% This is intended only for \TeX{} or \LaTeX{} source
%   code, outputting lines prefixed with four spaces.\par
%    \begin{macrocode}
  <xsl:template match="db:literallayout" mode="inline">
    <xsl:choose>
      <xsl:when
        test="@language!='LaTeX' and @language!='TeX'">
        <!-- so this handles bash OK -->
        <xsl:variable name="content" select="."/>
        <xsl:call-template name="normtext">
          <xsl:with-param name="content"
            select="normalize-space($content)"/>
          <xsl:with-param name="indent">
            <xsl:if
              test="ancestor::db:part[@xml:id='code'] or
                    ancestor::db:procedure[@xml:id='prepackage']">
              <xsl:value-of select="$sentinel"/>
              <xsl:text>    </xsl:text>
            </xsl:if>
          </xsl:with-param>
        </xsl:call-template>
        <xsl:if test="ancestor::db:part[@xml:id!='code']">
          <xsl:text>&#xa;</xsl:text>
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>[Raw </xsl:text>
        <xsl:value-of select="@language"/>
        <xsl:text> code omitted here: see PDF doc]</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsection{Flow}
% \begin{CPKtemplate}{db:acronym}\label{template-db2md-acronym2}
% Acronyms with an \texttt{<ID>}\index{ID=\texttt{\char'074 ID\char'076 } (element)}\index{elements:!ID=\texttt{\char'074 ID\char'076 }} are assumed to be
%   defining instances with the expansion as content.\par
%    \begin{macrocode}
  <xsl:template match="db:acronym" mode="inline">
    <xsl:call-template name="compensate-space"/>
    <xsl:choose>
      <xsl:when test="@xml:id">
        <xsl:apply-templates mode="inline"/>
        <xsl:text> (</xsl:text>
        <xsl:value-of select="@xml:id"/>
        <xsl:text>)</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates mode="inline"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{monospace}\label{template-db2md-monospace}
% \begingroup\raggedright[\url{db:filename} 
% and \url{db:guilabel} 
% and \url{db:guibutton} 
% ]\par\endgroup
% Filenames and \textsc{gui} elements are
%            rendered as monospace.\par
%    \begin{macrocode}
  <xsl:template match="db:filename |
                       db:guilabel |
                       db:guibutton" mode="inline">
    <xsl:text>`</xsl:text>
    <xsl:apply-templates mode="inline"/>
    <xsl:text>`</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{italics}\label{template-db2md-italics}
% \begingroup\raggedright[\url{db:classname} 
% and \url{db:package} 
% ]\par\endgroup
% Class and package names both go in italics; this
%     breaks the \LaTeX{} convention of sans-serif, but the font
%     is not normally controllable in Markdown.\par
%    \begin{macrocode}
  <xsl:template match="db:classname |
                       db:package" mode="inline">
    <xsl:text>_</xsl:text>
    <xsl:apply-templates mode="inline"/>
    <xsl:text>_</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:uri}\label{template-db2md-uri2}
% \textsc{uri}s are rendered as-is.\par
%    \begin{macrocode}
  <xsl:template match="db:uri" mode="inline">
    <xsl:apply-templates mode="inline"/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{quoted}\label{template-db2md-quoted}
% \begingroup\raggedright[\url{db:phrase} 
% and \url{db:wordasword} 
% and \url{db:quote} 
% ]\par\endgroup
% Words and phrases go in double quotes.\par
%    \begin{macrocode}
  <xsl:template match="db:phrase |
                       db:wordasword |
                       db:quote" mode="inline">
    <xsl:text>“</xsl:text>
    <xsl:apply-templates mode="inline"/>
    <xsl:text>”</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:footnote}\label{template-db2md-footnote2}
% Footnotes are superscripted digits.\par
%    \begin{macrocode}
  <xsl:template match="db:footnote" mode="inline">
    <xsl:text>&lt;sup></xsl:text>
    <xsl:number format="1" count="db:footnote" level="any"/>
    <xsl:text>&lt;/sup></xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:xref}\label{template-db2md-xref2}
% Create textual pointers for cross-references, as there
%     are no links as such in plain text.\par
%    \begin{macrocode}
  <xsl:template match="db:xref" mode="inline">
    <xsl:variable name="target"
      select="$maindoc//*[@xml:id=current()/@linkend]"/>
    <xsl:variable name="targetname"
      select="local-name($target)"/>
    <xsl:choose>
      <!-- handle informaltable, informalequation -->
      <xsl:when test="starts-with($targetname,'informal')">
        <xsl:text> the informal </xsl:text>
        <xsl:value-of
          select="substring-after($targetname,'informal')"/>
        <xsl:text> labelled ‘</xsl:text>
        <xsl:value-of select="@linkend"/>
        <xsl:text>’ in §</xsl:text>
        <xsl:variable name="ref">
          <xsl:for-each
            select="$target/ancestor::*
                    [not(name()='part' or name()='book')]">
            <ref n="{count(preceding-sibling::*
                     [name()=current()/name()]) + 1}">
              <xsl:value-of select="local-name()"/>
            </ref>
          </xsl:for-each>
        </xsl:variable>
        <xsl:for-each select="$ref/ref[@n>0]">
          <xsl:sort select="position()"
            order="descending"/>
          <xsl:value-of select="@n"/>
          <xsl:if test="position()!=last()">
            <xsl:text>.</xsl:text>
          </xsl:if>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>the </xsl:text>
        <xsl:value-of select="$targetname"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{link}\label{template-db2md-link}
% Create an inline link for a \textsc{uri}.\par
%    \begin{macrocode}
  <xsl:template match="db:link[@xlink:href]" mode="inline">
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Tracing </xsl:text>
        <xsl:value-of select="name(parent::*[1])"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="name()"/>
      </xsl:message>
    </xsl:if>
    <xsl:call-template name="compensate-space"/>
    <xsl:text>[</xsl:text>
    <xsl:choose>
      <xsl:when test="*">
        <xsl:apply-templates mode="inline"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="."/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>](</xsl:text>
    <xsl:value-of select="replace(@xlink:href,'PACKAGE',$docname)"/>
    <xsl:text>)</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:command}\label{template-db2md-command2}
% Prefix commands with a backslash where appropriate.\par
%    \begin{macrocode}
  <xsl:template match="db:command" mode="inline">
    <xsl:text>`</xsl:text>
    <xsl:if test="@xml:lang='TeX' or
                  @xml:lang='LaTeX' or
                  not(@xml:lang)">
      <xsl:text>\</xsl:text>
    </xsl:if>
    <xsl:apply-templates mode="inline"/>
    <xsl:text>`</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:tag}\label{template-db2md-tag2}
% Add prefixes and suffixes to specifics of XML markup
%     names.\par
%    \begin{macrocode}
  <xsl:template match="db:tag" mode="inline">
    <xsl:text>`</xsl:text>
    <xsl:choose>
      <xsl:when test="@class='starttag'">
        <xsl:text>&lt;</xsl:text>
      </xsl:when>
      <xsl:when test="@class='attvalue'">
        <xsl:text>"</xsl:text>
      </xsl:when>
      <xsl:when test="@class='attribute' and
                      @conformance!='noat'">
        <xsl:text>@</xsl:text>
      </xsl:when>
      <xsl:when test="@class='genentity'">
        <xsl:text>&amp;</xsl:text>
      </xsl:when>
      <xsl:when test="@class='numcharref'">
        <xsl:text>&amp;\#x</xsl:text>
      </xsl:when>
    </xsl:choose>
    <!-- do NOT expect to find escaped TeX here -->
    <xsl:value-of select="."/>
    <xsl:choose>
      <xsl:when test="@class='starttag'">
        <xsl:text>&gt;</xsl:text>
      </xsl:when>
      <xsl:when test="@class='attvalue'">
        <xsl:text>"</xsl:text>
      </xsl:when>
      <xsl:when test="@class='genentity' or
                      @class='numcharref'">
        <xsl:text>;</xsl:text>
      </xsl:when>
    </xsl:choose>
    <xsl:text>`</xsl:text>
    <!-- separate plural "s" with space, 
         otherwise rendering engines might hide it -->
    <xsl:if
      test="name(following-sibling::node()[1])='' and
                 starts-with(following-sibling::node()[1],'s')">
      <xsl:text> </xsl:text>
    </xsl:if>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{text}\label{template-db2md-text2}
% Surround with MD markup according to the nature of
%   the enclosure.\par
%    \begin{macrocode}
  <xsl:template match="text()" mode="inline">
    <xsl:choose>
      <xsl:when
        test="parent::db:emphasis[@role='strong']">
        <xsl:text>**</xsl:text>
        <!-- do NOT expect to find escaped TeX here -->
        <xsl:value-of select="."/>
        <xsl:text>**</xsl:text>
      </xsl:when>
      <xsl:when test="parent::db:firstterm">
        <xsl:text>**_</xsl:text>
        <!-- do NOT expect to find escaped TeX here -->
        <xsl:value-of select="."/>
        <xsl:text>_**</xsl:text>
      </xsl:when>
      <xsl:when test="parent::db:emphasis or
                      parent::db:productname or
                      parent::db:citetitle">
        <xsl:text>_</xsl:text>
        <xsl:call-template name="dologo"/>
        <xsl:text>_</xsl:text>
      </xsl:when>
      <xsl:when test="parent::db:option">
        <xsl:text>**`</xsl:text>
        <xsl:if
          test="parent::db:option/@language='bash'">
          <xsl:text>-</xsl:text>
        </xsl:if>
        <!-- do NOT expect to find escaped TeX here -->
        <xsl:value-of select="."/>
        <xsl:if
          test="parent::db:option/@language='bash'
                and
                not(parent::db:option/@conformance='nocolon')">
          <xsl:text>:</xsl:text>
        </xsl:if>
        <xsl:text>`**</xsl:text>
      </xsl:when>
      <xsl:when test="parent::db:varname">
        <xsl:text>`</xsl:text>
        <xsl:choose>
          <xsl:when
            test="parent::db:varname/@language='bash'">
            <xsl:text>$</xsl:text>
          </xsl:when>
          <xsl:when
            test="parent::db:varname/@language='LaTeX'">
            <xsl:text>\</xsl:text>
          </xsl:when>
        </xsl:choose>
        <!-- do NOT expect to find escaped TeX here -->
        <xsl:value-of select="."/>
        <xsl:text>`</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="dologo"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{db:biblioref}\label{template-db2md-biblioref2}
% Create a bibliographic reference without the aid of
%     \textsf{biblatex} or \BibTeX{}.\par
%    \begin{macrocode}
  <xsl:template match="db:biblioref" mode="inline">
    <xsl:text>(</xsl:text>
    <xsl:variable name="bibref" select="@linkend"/>
    <!-- change context to the entry -->
    <xsl:for-each
      select="$maindoc/descendant::db:biblioentry
              [@xml:id=$bibref]">
      <xsl:variable name="authors"
        select="count(descendant::db:author)"/>
      <!-- only name up to the first two -->
      <xsl:for-each
        select="descendant::db:author
                [count(preceding-sibling::db:author)&lt;2]">
        <xsl:if test="$authors>2
                      and
                      count(preceding-sibling::db:author)=1">
          <xsl:text>, </xsl:text>
        </xsl:if>
        <xsl:if
          test="count(preceding-sibling::db:author)=2">
          <xsl:text> &amp; </xsl:text>
        </xsl:if>
        <xsl:value-of select="db:personname/db:surname"/>
      </xsl:for-each>
      <xsl:if test="$authors>3">
        <xsl:text> et al</xsl:text>
      </xsl:if>
      <xsl:text>, </xsl:text>
      <xsl:choose>
        <xsl:when test="descendant::db:date">
          <xsl:value-of
            select="format-date
                    ((descendant::db:date)[1]/
                    @YYYY-MM-DD,'[Y]')"/>
        </xsl:when>
        <xsl:when test="descendant::db:confdates">
          <xsl:value-of
            select="format-date
                    ((descendant::db:confdates)[1]/
                    @YYYY-MM-DD-from,'[Y]')"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>n.d.</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
    <xsl:text>)</xsl:text>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{metadata}\label{template-db2md-metadata}
% This template handles the extraction of metadata from
%     the master file: {\ttfamily{}\$loc} is the name of the
%     element; {\ttfamily{}\$ctl} is the
%     [optional] name of an attribute to test; {\ttfamily{}\$val} is the [optional] value
%     to test {\ttfamily{}\$ctl} for;
%     {\ttfamily{}\$pos} is the name of
%     the attribute to return.\par
%    \begin{macrocode}
  <xsl:template name="metadata">
    <xsl:variable name="loc" select="@targetptr"/>
    <xsl:variable name="ctl" select="@condition"/>
    <xsl:variable name="val" select="@arch"/>
    <xsl:variable name="pos" select="@type"/>
    <xsl:choose>
      <!-- test an attribute -->
      <xsl:when test="$ctl!=''">
        <xsl:choose>
          <!-- if a value is given -->
          <xsl:when test="$val!=''">
            <xsl:value-of select="$maindoc/
             descendant::*[local-name()=$loc]
             [@*[name()=$ctl]=$val][1]/@*[name()=$pos]"/>
          </xsl:when>
          <!-- if not, test for existence of $ctl attrib only -->
          <xsl:otherwise>
            <xsl:value-of select="$maindoc/
             descendant::*[local-name()=$loc]
             [@*[name()=$ctl]][1]/@*[name()=$pos]"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- no test, just get a value -->
      <xsl:otherwise>
        <xsl:value-of select="$maindoc/
         descendant::*[local-name()=$loc][1]/@*[name()=$pos]"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{passthru}\label{template-db2md-passthru}
% \begingroup\raggedright[\url{db:itemizedlist} 
% and \url{db:listitem} 
% and \url{db:sect2} 
% ]\par\endgroup
% Don’t issue warning for unmatched elements.\par
%    \begin{macrocode}
  <xsl:template match="db:itemizedlist |
                       db:listitem |
                       db:sect2" mode="readme">
    <xsl:apply-templates mode="readme"/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{default}\label{template-db2md-default2}
% \begingroup\raggedright[\url{*} 
% ]\par\endgroup
% Warn about unhandled elements.\par
%    \begin{macrocode}
  <xsl:template match="*" mode="readme">
    <xsl:message>
      <xsl:text>Unhandled readme '</xsl:text>
      <xsl:value-of select="name()"/>
      <xsl:text>'</xsl:text>
    </xsl:message>
    <xsl:apply-templates mode="readme"/>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{markup}\label{template-db2md-markup}
% Named template to output MD prefix markup context if
%     an element is being processed. Catch the package and class
%     containers (ie don’t throw an error).\par
%    \begin{macrocode}
  <xsl:template name="markup">
    <xsl:param name="flag"/>
    <xsl:choose>
      <xsl:when
        test="ancestor::db:book/@arch='package' or
              ancestor::db:book/@arch='class'">
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:when test="$flag!=''">
        <xsl:text>&#xa;</xsl:text>
        <xsl:value-of select="$flag"/>
        <xsl:text> </xsl:text>
      </xsl:when>
      <xsl:when
        test="ancestor::db:book/@arch='script'">
        <!-- this gets done by the recursion anyway -->
        <xsl:text></xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text></xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \subsection{Typesetting plain text}
% \begin{CPKtemplate}{normtext}\label{template-db2md-normtext}
% This starts the simulation the
%     `typesetting' of non-code material
%     in plain text: this is a stub to call the setting
%     mechanism, so we need to do any preliminary replacements
%     of \LaTeX{} constructs that map to plain text
%     now. {\ttfamily{}\$content} is a
%     node-set of the content to be processed; {\ttfamily{}\$indent} is the {\ttfamily{}\$sentinel} plus any extra
%     space, eg for lists; {\ttfamily{}\$prefix} is the right-hand
%     symbol for indented material.\par
%    \begin{macrocode}
  <xsl:template name="normtext">
    <xsl:param name="content"/>
    <xsl:param name="indent">
      <xsl:text></xsl:text>
    </xsl:param>
    <xsl:param name="prefix">
      <xsl:text></xsl:text>
    </xsl:param>
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Starting normtext on ‘</xsl:text>
        <xsl:value-of select="$content"/>
        <xsl:text> (indent="</xsl:text>
        <xsl:value-of select="$indent"/>
        <xsl:text>", prefix="</xsl:text>
        <xsl:value-of select="$prefix"/>
        <xsl:text>")</xsl:text>
      </xsl:message>
    </xsl:if>
    <xsl:call-template name="set">
      <xsl:with-param name="text" 
        select="replace(
                 replace(
                  replace(
                   replace(concat($prefix,$content),
                           '\\TeX\{\}','TeX'),
                          '\\LaTeX\{\}','LaTeX'),
                         '\\thinspace\{\}',' '),
                        '\\nicefrac(.)(.)','$1/$2')"/>
      <xsl:with-param name="indent" select="$indent"/>
    </xsl:call-template>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{typeset}\label{template-db2md-typeset}
% This is where the first-stage recursive work gets
%     done. If there’s less than a line left to set, output the
%     indent, the line, and we’re done; otherwise, grab enough
%     words to fill a line, output it, and try again.\par
%    \begin{macrocode}
  <xsl:template name="set">
    <xsl:param name="text"/>
    <xsl:param name="indent">
      <xsl:text></xsl:text>
    </xsl:param>
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Starting set on ‘</xsl:text>
        <xsl:value-of select="$text"/>
        <xsl:text>’ in width=</xsl:text>
        <xsl:value-of select="$width"/>
      </xsl:message>
    </xsl:if>
    <xsl:choose>
      <!-- if the string fits the width
           or it contains something longer than a line
              (eg a long URI in a link)
           or if it's unbreakable, that's it -->
      <xsl:when test="string-length($text) &lt; $width
                      or
                      $width &lt; tokenize($text,' ')
                      or
                      not(contains($text,' '))">
        <xsl:value-of select="$indent"/>
        <xsl:value-of select="$text"/>
        <xsl:text>&#xa;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:variable name="line">
          <xsl:call-template name="token">
            <xsl:with-param name="text"
              select="$text"/>
            <xsl:with-param name="indent"
              select="$indent"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:value-of select="$line"/>
        <xsl:text>&#xa;</xsl:text>
        <xsl:call-template name="set">
          <xsl:with-param name="text"
            select="normalize-space(substring-after(
                    concat($indent,$text),$line))"/>
          <xsl:with-param name="indent"
            select="$indent"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{token}\label{template-db2md-token}
% See what fits, a token at a time.\par
%    \begin{macrocode}
  <xsl:template name="token">
    <xsl:param name="text"/>
    <xsl:param name="line">
      <xsl:text></xsl:text>
    </xsl:param>
    <xsl:param name="length">
      <xsl:text>0</xsl:text>
    </xsl:param>
    <xsl:param name="indent"/>
    <xsl:param name="cycle">
      <xsl:value-of select="number('0')"/>
    </xsl:param>
    <xsl:param name="context"/>
    <xsl:variable name="word">
      <xsl:choose>
        <xsl:when test="contains($text,' ')">
          <xsl:value-of
            select="substring-before($text,' ')"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$text"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="size" select="string-length($word)"/>
    <xsl:if test="$trace">
      <xsl:message>
        <xsl:text>Starting token on ‘</xsl:text>
        <xsl:value-of select="$text"/>
        <xsl:text>’ in width=</xsl:text>
        <xsl:value-of select="$width"/>
      </xsl:message>
    </xsl:if>
    <xsl:choose>
      <!-- too much for line -->
      <xsl:when test="$length + 1 + $size > $width">
        <xsl:value-of select="$line"/>
      </xsl:when>
      <!-- another word will fit -->
      <xsl:otherwise>
        <xsl:call-template name="token">
          <xsl:with-param name="line">
            <xsl:choose>
              <xsl:when test="$length=0">
                <!-- omit indent for lists on first cycle -->
                <xsl:choose>
                  <xsl:when
                    test="($context='itemizedlist' or
                          $context='orderedlist')
                          and $cycle = 0">
                    <xsl:text></xsl:text>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="$indent"/>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:value-of select="$word"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of
                  select="concat($line,' ',$word)"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:with-param>
          <xsl:with-param name="length">
            <xsl:choose>
              <xsl:when test="$length=0">
                <xsl:value-of
                  select="string-length($indent) + $size"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of
                  select="string-length($line) + 1 + $size"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:with-param>
          <xsl:with-param name="text"
            select="substring-after($text,' ')"/>
          <xsl:with-param name="cycle"
            select="$cycle + 1"/>
          <xsl:with-param name="context"
            select="$context"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{dologo}\label{template-db2md-dologo}
% Call this template when processing \texttt{<text()>}\index{text()=\texttt{\char'074 text()\char'076 } (element)}\index{elements:!text()=\texttt{\char'074 text()\char'076 }}
%     which may not be atomic, instead of doing an
%     \texttt{<apply-templates>}\index{apply-templates=\texttt{\char'074 apply-templates\char'076 } (element)}\index{elements:!apply-templates=\texttt{\char'074 apply-templates\char'076 }}. Note that these matches are
%     for the names defined in
%     {\ttfamily{}doctexbook.dtd}\thinspace.\par
%    \begin{macrocode}
  <xsl:template name="dologo">
    <xsl:choose>
      <xsl:when
        test="contains(.,'\BibTeX{}') or
              contains(.,'\Con\TeX t{}') or
              contains(.,'\LaTeX{}') or
              contains(.,'\LaTeXe{}') or
              contains(.,'\XeTeX{}') or
              contains(.,'\XeLaTeX{}') or
              contains(.,'\LyX{}') or
              contains(.,'\MF{}') or
              contains(.,'\MP{}') or
              contains(.,'\TeX{}')">
        <xsl:call-template name="detex">
          <xsl:with-param name="string" select="."/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="."/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{detex}\label{template-db2md-detex}
% Perform the actual replacements of logos identified in
%     \DescribeTemplate{dologo}{\ttfamily{}dologo}.\par
%    \begin{macrocode}
  <xsl:template name="detex">
    <xsl:param name="string"/>
    <xsl:choose>
      <xsl:when test="contains($string,'\BibTeX{}')">
        <xsl:call-template name="detex">
          <xsl:with-param name="string"
            select="replace($string,'\\BibTeX\{\}','BiBTeX')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($string,'\Con\TeX t{}')">
        <xsl:call-template name="detex">
          <xsl:with-param name="string"
            select="replace($string,'\\Con\\TeX t\{\}','ConTeXt')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($string,'\LaTeX{}')">
        <xsl:call-template name="detex">
          <xsl:with-param name="string"
            select="replace($string,'\\LaTeX\{\}','LaTeX')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($string,'\LaTeXe{}')">
        <xsl:call-template name="detex">
          <xsl:with-param name="string"
            select="replace($string,'\\LaTeXe\{\}','LaTeX2ε')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($string,'\XeTeX{}')">
        <xsl:call-template name="detex">
          <xsl:with-param name="string"
            select="replace($string,'\\XeTeX\{\}','XeTeX')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($string,'\XeLaTeX{}')">
        <xsl:call-template name="detex">
          <xsl:with-param name="string"
            select="replace($string,'\\XeLaTeX\{\}','XeLaTeX')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($string,'\LyX{}')">
        <xsl:call-template name="detex">
          <xsl:with-param name="string"
            select="replace($string,'\\LyX\{\}','LyX')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($string,'\MF{}')">
        <xsl:call-template name="detex">
          <xsl:with-param name="string"
            select="replace($string,'\\MF\{\}','METAFONT')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($string,'\MP{}')">
        <xsl:call-template name="detex">
          <xsl:with-param name="string"
            select="replace($string,'\\MP\{\}','METAPOST')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($string,'\TeX{}')">
        <xsl:call-template name="detex">
          <xsl:with-param name="string"
            select="replace($string,'\\TeX\{\}','TeX')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$string"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
%    \end{macrocode}
% \end{CPKtemplate}
% \begin{CPKtemplate}{end}\label{template-db2md-end2}
% That’s all, folks!\par
%    \begin{macrocode}
</xsl:stylesheet>
%    \end{macrocode}
% \end{CPKtemplate}
% \iffalse
%</db2mdscript>
% \fi
% \iffalse
%<*usemakefile>
% \fi
% \clearpage
% \section{The Makefile}\label{usemakefile}
% A standard \textsc{gnu} {\ttfamily{}Makefile} is supplied to handle most
% aspects of the production, including the packaging of the
% files and the zipping up for distribution to
% \textsc{ctan}\index{CTAN}. This replaces the generated
% {\ttfamily{}build} file of earlier versions. The
% {\ttfamily{}Makefile} is fully parameterised, so the
% one file can be used for any package simply by soft-linking it
% (creating an alias) from where you installed it into the
% working directory you create for any class or package.\par
% \begin{Sbox}\begin{minipage}{.85\columnwidth}\raggedright\sffamily
% The file is extracted during installation of
%   \emph{ClassPack} with the name
%   {\ttfamily{}classpack.make} to avoid any conflict with
%   a user's existing {\ttfamily{}Makefile}\thinspace. The file
%   {\sffamily \textsc{should}} be renamed after
%   installation.\par
% \end{minipage}\end{Sbox}{\fboxsep1em\centering\fbox{\TheSbox}\par\smallskip}
% \begin{CPKcomment}{usemakefile-comment}\label{comment-usemakefile}
% Identify the file origin,
% date, time, etc.\par
%    \begin{macrocode}
## The Makefile (from the classpack package v.1.28, 2024-02-21) 
## Generated by ClassPack v.1.28 (2024-02-21) on 24-03-04T22:35:19 
%    \end{macrocode}
% These lines are automatically prepended to the file
% and may be removed if necessary,
% using a suitable editor.
% \end{CPKcomment}
% \subsection{Auto-initialisation}\label{usemakefile:autoinit}
% This section is added automatically by \textit{ClassPack} 
% as a preamble to all classes and style packages.
% For details see the \textsf{ltxdoc} package documentation.
% \par\smallskip
% 
% \setcounter{CodelineNo}{0}
% \begingroup\color{DarkRed}\footnotesize
% \leavevmode\enspace{\scriptsize1}\quad{\ttfamily\textbackslash NeedsTeXFormat\{LaTeX2e\}[2015/01/01]}\\
% \leavevmode\enspace{\scriptsize2}\quad{\ttfamily\textbackslash ProvidesFile\{classpack\}[2024/02/21 v1.28}\\
% \leavevmode\enspace{\scriptsize3}\qquad{\ttfamily Package code for supporting ClassPack documentation]}\\\endgroup
% \setcounter{CodelineNo}{3}
% \subsection{Shortcut settings}\label{makesettings}
% \begin{CPKsetting}{shortcuts}\label{setting-Makefile-shortcuts1}
% As the actual filenames will be different depending on
%     your package or class, the following shortcuts
%     (`phony' targets in Makefile-speak)
%     are declared:\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=preamble-dependencies,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-1,firstnumber=1]{Makefile.make}
% They are defined below in \vref{shortcuts}.\par
% \end{CPKsetting}
% \subsection{Document and program dependencies}\label{makedeps1}
% \begin{CPKvariable}{variables}\label{variable-Makefile-variables}
% The current document name {\ttfamily{}\$(DOC)} is
%     found from the name of the most recently-saved
%     \textsc{xml} document in the current directory,
%     omitting the known names of
%     \emph{ClassPack} support files — the
%     result is assumed to be your class or package document.
%     The dependencies are:\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=dependencies-classpack,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-2,firstnumber=last,breaklines=true,basicstyle=\fontsize{9}{10}\selectfont\color{Black}\ttfamily,]{Makefile.make}
% \end{CPKvariable}
% \begin{description}[style=unboxed]
% \item[Java:]The Sun (now Oracle) and IBM Javas as well as the
% generic Java supplied with GNU/Linux distributions all
% seem to work well;
% \item[Saxon:]The HE (Home Edition) is available free of charge
% from \url{http://saxon.sourceforge.net} for
% domestic, hobby, academic, and pro bono use.\par
% You are {\sffamily \textsc{required}} to
% purchase an EE (Enterprise Edition) license for
% commercial work.\par
% \item[lxprintf:]is part of the LTxml suite of
% \textsc{xml} utilities from the Language
% Technology Group at Edinburgh University: see
% \url{https://www.ltg.ed.ac.uk/software/ltxml2/};
% \item[latexmk:]is a script distributed with \TeX{} Live for
% managing the build of complex \LaTeX{} documents. It
% automatically handles bibliographic and index
% processing and is configurable for \XeLaTeX{} as well
% as \emph{biber}.
% \end{description}
% \subsection{Script dependencies}\label{makedeps2}
% \begin{CPKsetting}{dependencies}\label{setting-Makefile-dependencies}
% The \emph{ClassPack}-specific
%     locations are the files, scripts, and programs needed by
%     the {\ttfamily{}Makefile}\thinspace, and are assumed to be
%     in one directory (here, {\ttfamily{}dev} within
%     the user’s Personal \TeX{} Directory as defined in the
%     current \TeX{} installation’s configuration
%     ({\ttfamily{}texmf.cnf}), conventionally
%     \url{~/texmf}).\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=classpack-metadata,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-3,firstnumber=last]{Makefile.make}
% \end{CPKsetting}
% \begin{description}[style=unboxed]
% \item[db2dtx.xsl:]is the main \textsc{xslt} script;
% \item[db2bibtex.xml:]is \texttt{xsl:include}d to handle the
% creation of a \BibTeX{} file;
% \item[db2md.xsl:]creates the {\ttfamily{}README.md}
% file;
% \item[decommentbbl.awk:]is an \emph{awk}\thinspace(1)
% script to handle malformed \BibTeX{} output when using
% the \emph{bibtex} processor
% instead of \emph{biber};
% \item[prepost.xml:]is the lookup file of packages for
% auto-loading;
% \item[readme.xml:]is the \textsc{xml} source from which
% the {\ttfamily{}README.md} file is
% created;
% \item[lppl.xml:]is the \LaTeX{} Project Public License text, used
% for the license of publicly-available packages and
% classes.
% \end{description}
% \subsection{Values extracted from the document}\label{makevalues}
% \begin{CPKsetting}{values}\label{setting-Makefile-values}
% The \emph{lxprintf} utility is
%     used to extract some key values from the
%     \textsc{xml} document ahead of
%     processing:\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=metadata-shortcuts,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-4,firstnumber=last,breaklines=true,basicstyle=\fontsize{9}{11}\selectfont\color{Black}\ttfamily,]{Makefile.make}
% \end{CPKsetting}
% \begin{description}[style=unboxed]
% \item[TYPE:] the filetype ({\ttfamily{}sty} or
% {\ttfamily{}cls}) of the package or class
% being produced;
% \item[LPROC:]the name of the \LaTeX{} processor
% (\emph{pdflatex} or
% \emph{xelatex});
% \item[BPROC:]the name of the \BibTeX{} processor
% (\emph{bibtex} or
% \emph{biber});
% \item[BIBREF:]The number of bibliographic citations, used to
% decide if we need to run the BPROC processor;
% \item[RFC:](used as a flag) the number of times the
% \texttt{<exceptionname>}\index{exceptionname=\texttt{\char'074 exceptionname\char'076 } (element)}\index{elements:!exceptionname=\texttt{\char'074 exceptionname\char'076 }} element type is used in the
% \textsc{xml} document;
% \item[RFCGOT:](used as a flag) the number of times the RFC2119
% bibliographic reference is actually specified in the
% \textsc{xml} document;
% \item[VER:]the version number of the current
% \textsc{xml} document;
% \item[CONFIG:]The name of any configuration file generated from
% the source;
% \item[APROC:]Command needed to process an ancillary file such
% as a test or demo;
% \item[ADOC:]The filename (without extension) of any such
% ancillary file;
% \item[AEXT:]The filetype (extension) of any such ancillary
% file;
% \item[ADDSTY:]The name of an additional package
% ({\ttfamily{}.sty}) file being shipped as-is
% with this class or package, specified in the
% Manifest.
% \end{description}
% \subsection{Target shortcuts}\label{shortcuts}
% \begin{CPKsetting}{shortcuts}\label{setting-Makefile-shortcuts2}
% The target shortcuts allow quicker typing of the
%     {\ttfamily{}make} command. In
%     particular these can be used in editors and
%     \textsc{api}s that understand \emph{make}\thinspace(1) (eg in
%     \emph{Emacs}, pressing
%     \keys{F10} and typing the shortcut will run the
%     specified recipe).\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=shortcuts-dtx,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-5,firstnumber=last]{Makefile.make}
% \end{CPKsetting}
% Note that the \textbf{\texttt{install}} target is
%   \emph{not} included in
%   \textbf{\texttt{all}}.\par
% \subsection{Transformation to {\ttfamily{}.dtx} and
%   creation of the package or class}\label{makerecipes}
% \begin{CPKfile}{dtx}\label{file-Makefile-dtx}
% The \emph{db2dtx.xsl} script
%     generates a number of output files in addition to the
%     {\ttfamily{}.dtx} file:\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=dtx-pdf,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-6,firstnumber=last]{Makefile.make}
% \end{CPKfile}
% \begin{description}[style=unboxed]
% \item[{\ttfamily{}.dtx} /
%       {\ttfamily{}.ins}\thinspace:]the Doc\TeX{} and Installer files which are the
% distributable containers for the class or
% package;
% \item[{\ttfamily{}.bib}\thinspace:]the {\ttfamily{}.bib} file for the
% documentation bibliography, if there was one
% given;
% \item[{\ttfamily{}MANIFEST}\thinspace:]a {\ttfamily{}MANIFEST} file, used for
% zipping everything up for distribution;
% \item[{\ttfamily{}README.md}\thinspace:]a \emph{Markdown} file format
% for \textsc{ctan}\index{CTAN} to use (replacing the
% previous plaintext {\ttfamily{}README});
% \item[Others:]Any ancillary files are also created.
% \end{description}
% The \verb|$(DOC).$(TYPE)| target
%   (abbreviated as \textbf{\texttt{cls}} or
%   \textbf{\texttt{sty}}) runs
%   \emph{pdflatex} on the
%   {\ttfamily{}.ins} file to extract the class or
%   package file and any ancillary files. The {\ttfamily{}yes} prefix forces them to
%   overwrite any previous copy.\par
% \subsection{Creating the documentation}\label{makedoc}
% \begin{CPKsetting}{pdf}\label{setting-Makefile-pdf}
% The \textbf{\texttt{pdf}} target first checks to see if
%     the documentation has used any of the keywords from
%     RFC2119, and if so, adds the entry for the RFC to the
%     {\ttfamily{}.bib} file.\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=pdf-ctan,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-7,firstnumber=last]{Makefile.make}
% \end{CPKsetting}
% It then executes either
%   \emph{pdflatex} or \XeLaTeX{} to create
%   the documentation. The \emph{latexmk}
%   script is not currently used, because of recurrent problems
%   it has in detecting a good build. In this version of
%   \emph{ClassPack}, using \XeLaTeX{}
%   assumes the use of \emph{biber}, and the
%   use of \emph{pdflatex} assumes the use
%   of \emph{bibtex}.\par
% The use of the {\ttfamily{}decommentbbl.awk}
%   script on the output from \emph{bibtex}
%   is to defeat the use of terminal percent comment characters
%   in some \BibTeX{} styles, which upset the
%   \textsf{ltxdoc} package because of the special use
%   of that character there.\par
% The \emph{sed}\thinspace(1) utility
%   is used to remove the two intrusive spaces in index entry
%   formatting caused by premature ingestion of the index
%   argument in restricted mode in \LaTeX{} which would otherwise
%   cause multiple entries for the same index term.\par
% \subsection{Package the files for CTAN}\label{makectan}
% \begin{CPKfile}{ctan}\label{file-Makefile-ctan}
% The plain (\textsc{ctan}\index{CTAN}) Zip file just
%     copies the files listed in the
%     {\ttfamily{}MANIFEST} into a directory named after
%     the class or package, removes any generated files (those
%     from chapters in the \texttt{<files>}\index{files=\texttt{\char'074 files\char'076 } (element)}\index{elements:!files=\texttt{\char'074 files\char'076 }} Part which will get
%     recreated), and zips the rest up flat.\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=ctan-tds,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-8,firstnumber=last,breaklines=true,basicstyle=\fontsize{8}{10}\selectfont\color{Black}\ttfamily,]{Makefile.make}
% \end{CPKfile}
% As recommended by \textsc{ctan}\index{CTAN}, if the zipped
%   file or its results are likely to contain ancillary files,
%   images, or other files as well as the standard Doc\TeX{}
%   files, a standalone {\ttfamily{}VERSION} file should
%   give the timestamp of the most recently-updated file in the
%   bundle. This is not currently implemented for the
%   \textsc{tds} zip file, only for the
%   \textsc{ctan}\index{CTAN} one.\par
% \subsection{Package the files as TDS}\label{maketds}
% \begin{CPKfile}{tds}\label{file-Makefile-tds}
% The final stage is to create the Zip files of the
%     class or package. The \textsc{tds} version is
%     created by extracting from the Manifest the filenames by
%     type of file which need to be copied into the relevant
%     three subdirectories named after the package or class in
%     {\ttfamily{}doc/latex}\thinspace,
%     {\ttfamily{}source/latex}\thinspace, and
%     {\ttfamily{}tex/latex}\thinspace, and zipping them up
%     recursively to preserve the tree.\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=tds-fragcheck,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-9,firstnumber=last,breaklines=true,basicstyle=\fontsize{8}{10}\selectfont\color{Black}\ttfamily,]{Makefile.make}
% \end{CPKfile}
% Because there could be both {\ttfamily{}.cls}
%   and {\ttfamily{}.sty} files in one package, and
%   because \emph{make} would pick up on an
%   error of one type not existing in a wildcard copy operation.
%   each one has to be set inside a condition that tests for
%   that type of file.\par
% \subsection{Chunking and fragmenting}\label{makechunks}
% Long \textsc{xml} or \textsc{xslt}
%   files reproduced with the \textsf{listings}
%   package using the starting and ending line number options
%   for chunking cause an unusable slow-down in processing, as
%   the entire file has to be re-read from the start each time,
%   and \textsf{listings} currently has a reported bug
%   which introduces bogus characters before each
%   listing.\par
% The temporary solution is to insert flagged string
%   values in the form of comments to delimit the chunks as
%   listed in the table \vpageref{boundaries}, and use the strings
%   as start and end delimiters as described in the
%   \textsf{listings} package documentation. This
%   means the large files have to be preprocessed to split them
%   into the delimited chunks with a recognisable filename
%   pattern. It is also important to ensure that the number of
%   chunks matches the number of \texttt{programlisting}\index{programlisting=\texttt{\char'074 programlisting\char'076 } (element)}\index{elements:!programlisting=\texttt{\char'074 programlisting\char'076 }} elements needed to
%   list those fragments included in your documentation.\par
% The \emph{chunk}\thinspace(1) shell
%   script and its associated {\ttfamily{}chunk.awk}
%   script do the splitting, and also create the
%   \emph{DocBook} code for each
%   fragment.\par
% \begin{CPKsetting}{fragments}\label{setting-Makefile-fragments}
% We can check that the list of files denoted as
%     fragments in the author's
%     \emph{ClassPack} document code matches
%     the list of fragment files generated by the
%     \emph{chunk}\thinspace(1) script.\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=fragcheck-install,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-10,firstnumber=last]{Makefile.make}
% \end{CPKsetting}
% \subsection{Installations}\label{makeinstall}
% There are two installations done here.\par
% \subsubsection{System installation}
% The system installation is for normal use of the
%     package or class in the user's \LaTeX{} work.\par
% \begin{CPKfile}{install}\label{file-Makefile-install}
% This performs a local \textbf{\texttt{install}} on
%       the user’s system by unzipping the
%       \textsc{tds} Zip file into the user’s Personal
%       \TeX{} Directory.\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=install-website,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-11,firstnumber=last]{Makefile.make}
% \end{CPKfile}
% \subsubsection{Web installation}
% The web installation is principally for the user's own
%     web site, replicated on the local disk.\par
% \begin{CPKfile}{web}\label{file-Makefile-web}
% This installs the package in a directory which is
%       part of a local \emph{Apache} or
%       other web server product.\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=website-recover,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-12,firstnumber=last]{Makefile.make}
% \end{CPKfile}
% \subsection{Recovery and utilities}
% \begin{CPKfile}{recover}\label{file-Makefile-recover}
% The \textbf{\texttt{recover}} target can be used when
%     \LaTeX{} has got itself wedged over an unexpected error
%     type: it performs a full run plus a run of the
%     bibliography.\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=recover-clean,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-13,firstnumber=last]{Makefile.make}
% The additional targets recreate the glossaries,
%     indexes, and bibliography; and reprocess the
%     {\ttfamily{}.dtx} file.\par
% \end{CPKfile}
% \begin{CPKfile}{clean}\label{file-Makefile-clean}
% The \textbf{\texttt{clean}} target deletes all created
%     files for the current version
%     \emph{excluding} (obviously) the
%     \textsc{xml} master file itself and earlier zip
%     files.\par
% \lstinputlisting[language=Makefile,rangeprefix=\#\#\ ,rangesuffix=\ \#\#,linerange=eof-ancillary,includerangemarker=false,showlines=false,numbers=left,numberstyle=\ttfamily\scriptsize\color{Blue},name=usemakefile-14,firstnumber=last]{Makefile.make}
% \end{CPKfile}
% \iffalse
%</usemakefile>
% \fi
% \iffalse
%<*decommentscript>
% \fi
% \clearpage
% \section{The {\ttfamily{}decommentbbl.awk} script}\label{decommentscript}
% \setcounter{CodelineNo}{0}
% \begin{CPKcomment}{decommentscript-comment}\label{comment-decommentscript}
% Identify the file origin,
% date, time, etc.\par
%    \begin{macrocode}
## The decommentbbl.awk script (from the classpack package v.1.28, 2024-02-21) 
## Generated by ClassPack v.1.28 (2024-02-21) on 24-03-04T22:35:19 
%    \end{macrocode}
% These lines are automatically prepended to the file
% and may be removed if necessary,
% using a suitable editor.
% \end{CPKcomment}
% The {\ttfamily{}decommentbbl.awk} script is used
% by the Makefile on the output from
% \emph{bibtex} (only, not
% \emph{biblatex}) to defeat the use of
% terminal percent comment characters in some \BibTeX{} styles,
% which upsets the \textsf{ltxdoc} package because of
% the special use of that character there.\par
% This is an \emph{awk}\thinspace(1)
% script to catenate consecutive lines of a \BibTeX{}-produced
% {\ttfamily{}.bbl} file which end in a comment
% character (removing the comment character in the process)
% because the default \% comment character gets
% misinterpreted by the \textsf{ltxdoc} package when
% building class or package files.\par
% \begin{CPKfunction}{decommentbbl}\label{function--decommentbbl}
% Read the whole file as lines, then catenate any line
% ending in a percent sign to the previous one.\par
%    \begin{macrocode}
#
############################################################
#
# Read every line of the file into an array

{
    line[NR]=$0;
} 

############################################################
#
# At the end, go through the array; if a line ends with
# a % sign, catenate it to the buffer, omitting the percent
# sign itself; otherwise, output the buffer and zero it for
# further use.

END {
    for(i=1;i<=NR;++i) {
	if(substr(line[i],length(line[i]))=="%") {
	    buffer=buffer substr(line[i],1,length(line[i])-1);
	} else {
	    print buffer line[i];buffer="";
	}
    }
}
%    \end{macrocode}
% Otherwise, output any accumulated line, lather, rinse,
%   repeat.\par
% \end{CPKfunction}
% \iffalse
%</decommentscript>
% \fi
% \iffalse
%<*chunkscript>
% \fi
% \clearpage
% \section{The {\ttfamily{}chunk.sh} shell script}\label{chunkscript}
% \setcounter{CodelineNo}{0}
% This shell script extracts all the named Processing
% Instructions in an \textsc{xml} document (including
% \textsc{xslt}) and creates a set of
% \texttt{<annotation>}\index{annotation=\texttt{\char'074 annotation\char'076 } (element)}\index{elements:!annotation=\texttt{\char'074 annotation\char'076 }} templates for documentation.\par
% \subsection{Script code}
% \begin{CPKfunction}{chunk}\label{function--chunk}
% There is one {\sffamily \textsc{mandatory}}
%     switch, \textbf{\texttt{-p}}, which takes an
%     argument of the Processing
%       Instruction\phantomsection\label{PI} ({\small\raisebox{-.5ex}{\textcolor{Red}{\HandRight}}}\textsc{pi})\index{Processing Instruction|see{PI}}\index{PI|textbf} name; in
%     \emph{ClassPack} this is
%     {\ttfamily{}cpdoc}\thinspace.\par
% This {\sffamily \textsc{must}} be followed by the
%     name of the document to process.\par
% Extraction and formatting is
%     done in the \emph{awk}\thinspace(1)
%     script {\ttfamily{}chunk.awk} (see \vref{chunkawkscript}).\par
%    \begin{macrocode}
#! /bin/bash
%    \end{macrocode}
% \label{}
% \begin{CPKcomment}{chunkscript-comment}\label{comment-chunkscript}
% Identify the file origin,
% date, time, etc.\par
%    \begin{macrocode}
## The chunk.sh shell script (from the classpack package v.1.28, 2024-02-21) 
## Generated by ClassPack v.1.28 (2024-02-21) on 24-03-04T22:35:19 
%    \end{macrocode}
% These lines are automatically prepended to the file
% and may be removed if necessary,
% using a suitable editor.
% \end{CPKcomment}
%    \begin{macrocode}
# Bourne shell script to create chunks of a long document
# splitting on named boundaries in [doubled] comment characters
# or (XML) Processing Instructions. See §6.3.4 of Classpack PDF

# 1.3 added dbincludes to assist post-editing

VERSION=1.3
VDATE="2024-02-19"
DEV=~/texmf/dev
DIR=`pwd`
APP=`basename $DIR`/`basename $DIR`.xml
SCRIPT=~/bin/chunk.awk

if [ -z "$1" ]; then
    cat <<EOF
Synopsis

$ chunk -p name file

  -p  specifies a PI name to use for splitting XML (no default)

  file  name of the XML document from dev to process

Output files are named after the values of the chunk boundaries
eg filename-xxxxxx.ext
EOF
    exit 0
else
    while [[ $# -gt 0 ]]; do
	key="$1"
	case $key in
	    -p)
		BOUNDARY="$2"
		shift
		shift
		;;
	    *)
		if [ ! -s "$DEV/$key" ]; then
		    echo No such file as "$DEV/$key"
		    exit 1
		else
		    INPUT="$DEV/$key"
		    EXT=`echo $INPUT | awk -F. '{print $NF}'`
		    FNAME=`basename $INPUT .$EXT`
		    if [ -z "$BOUNDARY" ]; then
			if [ "$EXT" = "tex" ]; then
			    CHUNKS=`grep '^%% [A-Za-z][A-Za-z\-]* %%' $INPUT |\
				wc -l`
			    BOUNDARY="%%"
			elif [ "$EXT" = "css" ]; then
			    CHUNKS=`grep '^/* [A-Za-z][A-Za-z\-]* */' $INPUT |\
				wc -l`
			    BOUNDARY="/* */"
			elif [ "$EXT" = "awk" -o "$EXT" = "make" ]; then
			    CHUNKS=`grep '^## [A-Za-z][A-Za-z\-]* ##' $INPUT |\
				wc -l`
			    BOUNDARY="##"
			else # scripts with no filetype
			    CHUNKS=`grep '^## [A-Za-z][A-Za-z\-]* ##' $INPUT |\
				wc -l`
			    BOUNDARY="##"
			fi
		    else
			if [ "$EXT" = "xml" -o "$EXT" = "xsl" -o "$EXT" = "dtd" ]; then
			    CHUNKS=`grep "^<?$BOUNDARY [A-Za-z][A-Za-z\-]*[ ]*?>" $INPUT|wc -l`
			else
			    echo The -p PI boundary cannot be used with non-XML/XSLT files
			    exit 3
			fi
		    fi
		    if [ "$CHUNKS" -eq 0 ]; then
			echo No $BOUNDARY fragments found in $INPUT
			echo Nothing to do
			exit 4
		    else
			echo $CHUNKS $BOUNDARY fragments found in $INPUT
		    fi
		fi
		shift
		;;
	esac
    done
fi

cat <<EOF
This is fragment chunk, v.$VERSION ($VDATE) by Silmaril for ClassPack
Read from $INPUT, chunking on $CHUNKS $BOUNDARY boundaries
EOF

cat <<EOF >$FNAME.chunks
<chunks source="$INPUT" date="`date --iso-8601=seconds`"
        boundary="$BOUNDARY" xmlns:xlink="http://www.w3.org/1999/xlink">
EOF

cat $INPUT | awk -v boundary="$BOUNDARY" \
		 -v fname="$FNAME" \
		 -v ext="$EXT" \
		 -f $SCRIPT

LINES=`grep -v $BOUNDARY $INPUT | wc -l`
echo $LINES "lines of code and comment"

cat <<EOF >>$FNAME.chunks
</chunks>
EOF

# Summaries

lxprintf -e programlisting[@xlink:href=\"$3\"][@conformance=\"frag\"] \
	 "%s\n" @startinglinenumber $DEV/$APP >$FNAME.doclist

lxprintf -e programlisting[@xlink:href=\"$3\"][@conformance=\"frag\"] \
	 "%s\n" @startinglinenumber $FNAME.chunks >$FNAME.actual

COMP=`diff $FNAME.doclist $FNAME.actual`

cat <<EOF >$FNAME-dbincludes.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect1
  PUBLIC "+//DTD Silmaril//DocBook 5 adapted for ClassPack//EN"
         "../doctexbook-master.dtd">
      <sect1>
        <title></title>
EOF
cat $FNAME.actual | while read CHUNKNAME; do

    cat <<EOF >>$FNAME-dbincludes.xml
        <annotation role="" xreflabel="$FNAME">
          <para></para>
          <programlisting xlink:href="$3"
            language="XML" conformance="frag"
            startinglinenumber="$CHUNKNAME"/>
        </annotation>
EOF

done
cat <<EOF >>$FNAME-dbincludes.xml
      </sect1>
EOF

if [ -n "$COMP" ]; then
    echo $DEV/$APP and $FNAME.xml have different chunk references
    exit 5
fi

exit
%    \end{macrocode}
% Output is created in a file with the same name as the
%     input file but with the filetype {\ttfamily{}.chunks}\thinspace,
%     so for the command \verb|$ ./chunk -p cpdoc db2bibtex.xsl| the following output is created:\par
% \iffalse
%<*ignore>
% \fi
% \begingroup\advance\hsize by-1em
% \begin{Verbatim}[frame=single,framesep=1em,
%  fontsize=\small]
<chunks source="db2bibtex.xsl" date="2019-12-17T22:41:48+00:00">
  <annotation role="template" arch="paragraph" xreflabel="init">
    <para></para>
    <programlisting xlink:href="db2bibtex.xsl"
 	    language="XSLT" conformance="frag"
	    startinglinenumber="init"/>
  </annotation>
  ...
</chunks>
% \end{Verbatim}
% \endgroup
% \iffalse
%</ignore>
% \fi
% \end{CPKfunction}
% \iffalse
%</chunkscript>
% \fi
% \iffalse
%<*chunkawkscript>
% \fi
% \clearpage
% \section{The {\ttfamily{}chunk.awk} script}\label{chunkawkscript}
% \setcounter{CodelineNo}{0}
% \begin{CPKcomment}{chunkawkscript-comment}\label{comment-chunkawkscript}
% Identify the file origin,
% date, time, etc.\par
%    \begin{macrocode}
## The chunk.awk script (from the classpack package v.1.28, 2024-02-21) 
## Generated by ClassPack v.1.28 (2024-02-21) on 24-03-04T22:35:19 
%    \end{macrocode}
% These lines are automatically prepended to the file
% and may be removed if necessary,
% using a suitable editor.
% \end{CPKcomment}
% \begin{CPKfunction}{chunkawk}\label{function--chunkawk}
% This script processes an \textsc{xml} or
%   \textsc{xslt} file and finds all the Processing
%   Instructions. They must occur in start/finish pairs,
%   delimiting the code to which they refer, so the script
%   assumes that the even-numbered ones are the ends of chunks.
%   For each completed chunk, the code gets output to a file
%   named after the main file, with the name of the
%   \textsc{pi}\index{PI} appended.\par
%    \begin{macrocode}
BEGIN {
    fn="";
    chunks=0;
    lines=0;
    totlines=0;
}

# Match a boundary starting a line (optional leading TABs or spaces)

/^[ \t]*<\?[^>]*\?>/ {
    n=split($0,t,"?");
    m=split(t[2],p," ");
    if (p[1]==boundary) {
        ++pi;
        if (pi/2==int(pi/2)) {
            print fn,lines,"lines";
	    totlines=totlines+lines;
            lines=0;
            fn="";
        } else {
            fn=fname "-" p[2] ".frag";
            just=0;
            ++chunks;
            if (p[2] in cname) {
                print "Chunk name",p[2],"already used"
                exit 1
            } else {
                cname[p[2]]=chunks;
            }
            file=fname ".chunks";
            print "  <annotation" >>file;
            print "    role=\"template\"" >>file;
            print "    arch=\"paragraph\"" >>file;
            print "    xreflabel=\"" p[2] "\">" >>file;
            print "    <para></para>" >>file;
            print "    <programlisting" >>file;
            print "      xlink:href=\"" fname "." ext "\"" >>file;
            print "      language=\"XSLT\"" >>file;
            print "      conformance=\"frag\"" >>file;
            print "      startinglinenumber=\"" p[2] "\"/>" >>file;
            print "  </annotation>" >>file;
        }
    }
}

{
    if (fn!=""&&just>0) {
        ++lines;
	print $0 >fn;
    }
}

{
    just=NR;
}

END {
    print chunks,"chunks in",totlines,"lines";
}
%    \end{macrocode}
% \end{CPKfunction}
% \iffalse
%</chunkawkscript>
% \fi
% \section{The \LaTeX{} Project Public License (v\thinspace{}1.3c)}\label{LPPL}
% \begin{quotation}\small\sffamily\parindent0pt
%   \parskip.5\baselineskip
%   \color{DarkBlue}\noindent
% Everyone is allowed to distribute verbatim copies of this
%       license document, but modification of it is not allowed.\par
% \end{quotation}
% \subsection{Preamble}\label{Preamble}
% The \LaTeX{} Project Public License (\textsc{lppl})
%       is the primary license under which the \LaTeX{} kernel and the
%       base \LaTeX{} packages are distributed.\par
% You may use this license for any work of which you hold the
%       copyright and which you wish to distribute.  This license may be
%       particularly suitable if your work is \TeX{}-related (such as a
%       \LaTeX{} package), but it is written in such a way that you can
%       use it even if your work is unrelated to \TeX{}.\par
% The section “Whether and How to Distribute Works under This
%       License”, below, gives instructions, examples, and
%       recommendations for authors who are considering distributing
%       their works under this license.\par
% This license gives conditions under which a work may be
%       distributed and modified, as well as conditions under which
%       modified versions of that work may be distributed.\par
% We, the \LaTeX{3} Project, believe that the conditions below
%       give you the freedom to make and distribute modified versions of
%       your work that conform with whatever technical specifications
%       you wish while maintaining the availability, integrity, and
%       reliability of that work.  If you do not see how to achieve your
%       goal while meeting these conditions, then read the document
%       {\ttfamily{}cfgguide.tex} and {\ttfamily{}modguide.tex} in the base \LaTeX{}
%       distribution for suggestions.\par
% \subsection{Definitions}\label{Definitions}
% In this license document the following terms are used:\par
% \begin{description}[style=unboxed]
% \item[Work:]Any work being distributed under this License.\par
% \item[Derived Work:]Any work that under any applicable law is derived from
%     the Work.\par
% \item[Modification:]Any procedure that produces a Derived Work under any
%     applicable law~--- for example, the production of a file
%     containing an original file associated with the Work or a
%     significant portion of such a file, either verbatim or
%     with modifications and/or translated into another
%     language.\par
% \item[Modify:]To apply any procedure that produces a Derived Work
%     under any applicable law.\par
% \item[Distribution:]Making copies of the Work available from one person to
%     another, in whole or in part.  Distribution includes (but
%     is not limited to) making any electronic components of the
%     Work accessible by file transfer protocols such as
%     \textsc{ftp} or \textsc{http} or by
%     shared file systems such as Sun's Network File System
%     (\textsc{nfs}).\par
% \item[Compiled Work:]A version of the Work that has been processed into a
%     form where it is directly usable on a computer system.
%     This processing may include using installation facilities
%     provided by the Work, transformations of the Work, copying
%     of components of the Work, or other activities.  Note that
%     modification of any installation facilities provided by
%     the Work constitutes modification of the Work.\par
% \item[Current Maintainer:]A person or persons nominated as such within the Work.
%     If there is no such explicit nomination then it is the
%     `Copyright Holder' under any applicable
%     law.\par
% \item[Base Interpreter:]A program or process that is normally needed for
%     running or interpreting a part or the whole of the
%     Work.\par
% A Base Interpreter may depend on external components
%     but these are not considered part of the Base Interpreter
%     provided that each external component clearly identifies
%     itself whenever it is used interactively.  Unless
%     explicitly specified when applying the license to the
%     Work, the only applicable Base Interpreter is a
%     `\LaTeX{}-Format' or in the case of files
%     belonging to the `\LaTeX{}-format' a program
%     implementing the `\TeX{} language'.\par
% \end{description}
% \subsection{Conditions on Distribution and Modification}\label{Conditions}
% \begin{enumerate}
% \item Activities other than distribution and/or modification
%   of the Work are not covered by this license; they are
%   outside its scope. In particular, the act of running the
%   Work is not restricted and no requirements are made
%   concerning any offers of support for the Work.\par
% \item \label{item-distribute}You may distribute a complete, unmodified copy of the
%   Work as you received it.  Distribution of only part of the
%   Work is considered modification of the Work, and no right to
%   distribute such a Derived Work may be assumed under the
%   terms of this clause.\par
% \item You may distribute a Compiled Work that has been
%   generated from a complete, unmodified copy of the Work as
%   distributed under Clause~\vref{item-distribute} above, as
%   long as that Compiled Work is distributed in such a way that
%   the recipients may install the Compiled Work on their system
%   exactly as it would have been installed if they generated a
%   Compiled Work directly from the Work.\par
% \item \label{item-currmaint}If you are the Current Maintainer of the Work, you may,
%   without restriction, modify the Work, thus creating a
%   Derived Work.  You may also distribute the Derived Work
%   without restriction, including Compiled Works generated from
%   the Derived Work.  Derived Works distributed in this manner
%   by the Current Maintainer are considered to be updated
%   versions of the Work.\par
% \item If you are not the Current Maintainer of the Work, you
%   may modify your copy of the Work, thus creating a Derived
%   Work based on the Work, and compile this Derived Work, thus
%   creating a Compiled Work based on the Derived Work.\par
% \item \label{item-conditions}If you are not the Current Maintainer of the Work, you
%   may distribute a Derived Work provided the following
%   conditions are met for every component of the Work unless
%   that component clearly states in the copyright notice that
%   it is exempt from that condition.  Only the Current
%   Maintainer is allowed to add such statements of exemption to
%   a component of the Work.\par
% \begin{enumerate}
% \item If a component of this Derived Work can be a direct
%       replacement for a component of the Work when that
%       component is used with the Base Interpreter, then,
%       wherever this component of the Work identifies itself to
%       the user when used interactively with that Base
%       Interpreter, the replacement component of this Derived
%       Work clearly and unambiguously identifies itself as a
%       modified version of this component to the user when used
%       interactively with that Base Interpreter.\par
% \item Every component of the Derived Work contains
%       prominent notices detailing the nature of the changes to
%       that component, or a prominent reference to another file
%       that is distributed as part of the Derived Work and that
%       contains a complete and accurate log of the
%       changes.\par
% \item No information in the Derived Work implies that any
%       persons, including (but not limited to) the authors of
%       the original version of the Work, provide any support,
%       including (but not limited to) the reporting and
%       handling of errors, to recipients of the Derived Work
%       unless those persons have stated explicitly that they do
%       provide such support for the Derived Work.\par
% \item You distribute at least one of the following with
%       the Derived Work:\par
% \begin{enumerate}
% \item A complete, unmodified copy of the Work; if your
%   distribution of a modified component is made by
%   offering access to copy the modified component from
%   a designated place, then offering equivalent access
%   to copy the Work from the same or some similar place
%   meets this condition, even though third parties are
%   not compelled to copy the Work along with the
%   modified component;\par
% \item Information that is sufficient to obtain a
%   complete, unmodified copy of the Work.\par
% \end{enumerate}
% \end{enumerate}
% \item If you are not the Current Maintainer of the Work, you
%   may distribute a Compiled Work generated from a Derived
%   Work, as long as the Derived Work is distributed to all
%   recipients of the Compiled Work, and as long as the
%   conditions of Clause~\vref{item-conditions}, above, are met
%   with regard to the Derived Work.\par
% \item The conditions above are not intended to prohibit, and
%   hence do not apply to, the modification, by any method, of
%   any component so that it becomes identical to an updated
%   version of that component of the Work as it is distributed
%   by the Current Maintainer under Clause~\vref{item-currmaint}, above.\par
% \item Distribution of the Work or any Derived Work in an
%   alternative format, where the Work or that Derived Work (in
%   whole or in part) is then produced by applying some process
%   to that format, does not relax or nullify any sections of
%   this license as they pertain to the results of applying that
%   process.\par
% \item % \begin{enumerate}
% \item A Derived Work may be distributed under a different
%       license provided that license itself honors the
%       conditions listed in Clause~\vref{item-conditions} above, in
%       regard to the Work, though it does not have to honor the
%       rest of the conditions in this license.\par
% \item If a Derived Work is distributed under a different
%       license, that Derived Work must provide sufficient
%       documentation as part of itself to allow each recipient
%       of that Derived Work to honor the restrictions in
%       Clause~\vref{item-conditions} above, concerning
%       changes from the Work.\par
% \end{enumerate}
% \item This license places no restrictions on works that are
%   unrelated to the Work, nor does this license place any
%   restrictions on aggregating such works with the Work by any
%   means.\par
% \item Nothing in this license is intended to, or may be used
%   to, prevent complete compliance by all parties with all
%   applicable laws.\par
% \end{enumerate}
% \subsection{No Warranty}\label{Warranty}
% There is no warranty for the Work.  Except when otherwise
%       stated in writing, the Copyright Holder provides the Work
%       `as is', without warranty of any kind, either
%       expressed or implied, including, but not limited to, the implied
%       warranties of merchantability and fitness for a particular
%       purpose.  The entire risk as to the quality and performance of
%       the Work is with you.  Should the Work prove defective, you
%       assume the cost of all necessary servicing, repair, or
%       correction.\par
% In no event unless required by applicable law or agreed to
%       in writing will The Copyright Holder, or any author named in the
%       components of the Work, or any other party who may distribute
%       and/or modify the Work as permitted above, be liable to you for
%       damages, including any general, special, incidental or
%       consequential damages arising out of any use of the Work or out
%       of inability to use the Work (including, but not limited to,
%       loss of data, data being rendered inaccurate, or losses
%       sustained by anyone as a result of any failure of the Work to
%       operate with any other programs), even if the Copyright Holder
%       or said author or said other party has been advised of the
%       possibility of such damages.\par
% \subsection{Maintenance of The Work}\label{Maintenance}
% The Work has the status `author-maintained'
%       if the Copyright Holder explicitly and prominently states near
%       the primary copyright notice in the Work that the Work can only
%       be maintained by the Copyright Holder or simply that it is
%       `author-maintained'.\par
% The Work has the status `maintained' if there
%       is a Current Maintainer who has indicated in the Work that they
%       are willing to receive error reports for the Work (for example,
%       by supplying a valid e-mail address). It is not required for the
%       Current Maintainer to acknowledge or act upon these error
%       reports.\par
% The Work changes from status `maintained' to
%       `unmaintained' if there is no Current Maintainer,
%       or the person stated to be Current Maintainer of the work cannot
%       be reached through the indicated means of communication for a
%       period of six months, and there are no other significant signs
%       of active maintenance.\par
% You can become the Current Maintainer of the Work by
%       agreement with any existing Current Maintainer to take over this
%       role.\par
% If the Work is unmaintained, you can become the Current
%       Maintainer of the Work through the following steps:\par
% \begin{enumerate}
% \item Make a reasonable attempt to trace the Current
%   Maintainer (and the Copyright Holder, if the two differ)
%   through the means of an Internet or similar search.\par
% \item If this search is successful, then enquire whether the
%   Work is still maintained.\par
% \begin{enumerate}
% \item If it is being maintained, then ask the Current
%       Maintainer to update their communication data within one
%       month.\par
% \item \label{item-intention}If the search is unsuccessful or no action to resume
%       active maintenance is taken by the Current Maintainer,
%       then announce within the pertinent community your
%       intention to take over maintenance.  (If the Work is a
%       \LaTeX{} work, this could be done, for example, by
%       posting to \url{news:comp.text.tex}.).
% \end{enumerate}
% \item % \begin{enumerate}
% \item If the Current Maintainer is reachable and agrees to
%       pass maintenance of the Work to you, then this takes
%       effect immediately upon announcement.\par
% \item \label{item-announce}If the Current Maintainer is not reachable and the
%       Copyright Holder agrees that maintenance of the Work be
%       passed to you, then this takes effect immediately upon
%       announcement.\par
% \end{enumerate}
% \item \label{item-change}If you make an `intention announcement'
%   as described in~\vref{item-intention} above and after three
%   months your intention is challenged neither by the Current
%   Maintainer nor by the Copyright Holder nor by other people,
%   then you may arrange for the Work to be changed so as to
%   name you as the (new) Current Maintainer.\par
% \item If the previously unreachable Current Maintainer becomes
%   reachable once more within three months of a change
%   completed under the terms of~\vref{item-announce}
%   or~\vref{item-change}, then that
%   Current
%   Maintainer must become or remain the Current Maintainer upon
%   request provided they then update their communication data
%   within one month.\par
% \end{enumerate}
% A change in the Current Maintainer does not, of itself,
%       alter the fact that the Work is distributed under the
%       \textsc{lppl} license.\par
% If you become the Current Maintainer of the Work, you should
%       immediately provide, within the Work, a prominent and
%       unambiguous statement of your status as Current Maintainer.  You
%       should also announce your new status to the same pertinent
%       community as in~\vref{item-intention}
%       above.\par
% \subsection{Whether and How to Distribute Works under This
%       License}\label{Distribute}
% This section contains important instructions, examples, and
%       recommendations for authors who are considering distributing
%       their works under this license.  These authors are addressed as
%       `you' in this section.\par
% \subsubsection{Choosing This License or Another License}\label{Choosing}
% If for any part of your work you want or need to use
% \emph{distribution} conditions that differ
% significantly from those in this license, then do not refer to
% this license anywhere in your work but, instead, distribute
% your work under a different license. You may use the text of
% this license as a model for your own license, but your license
% should not refer to the \textsc{lppl} or otherwise
% give the impression that your work is distributed under the
% \textsc{lppl}.\par
% The document {\ttfamily{}modguide.tex} in the base \LaTeX{}
% distribution explains the motivation behind the conditions of
% this license.  It explains, for example, why distributing
% \LaTeX{} under the \textsc{gnu} General Public
% License (\textsc{gpl}) was considered inappropriate.
% Even if your work is unrelated to \LaTeX{}, the discussion in
% {\ttfamily{}modguide.tex} may still be
% relevant, and authors intending to distribute their works
% under any license are encouraged to read it.\par
% \subsubsection{A Recommendation on Modification Without
% Distribution}\label{WithoutDistribution}
% It is wise never to modify a component of the Work, even
% for your own personal use, without also meeting the above
% conditions for distributing the modified component.  While you
% might intend that such modifications will never be
% distributed, often this will happen by accident~--- you may
% forget that you have modified that component; or it may not
% occur to you when allowing others to access the modified
% version that you are thus distributing it and violating the
% conditions of this license in ways that could have legal
% implications and, worse, cause problems for the community. It
% is therefore usually in your best interest to keep your copy
% of the Work identical with the public one.  Many works provide
% ways to control the behavior of that work without altering any
% of its licensed components.\par
% \subsubsection{How to Use This License}\label{HowTo}
% To use this license, place in each of the components of
% your work both an explicit copyright notice including your
% name and the year the work was authored and/or last
% substantially modified.  Include also a statement that the
% distribution and/or modification of that component is
% constrained by the conditions in this license.\par
% Here is an example of such a notice and statement:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX}]
%%% pig.dtx
%%% Copyright 2005 M. Y. Name
%%
%% 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 has the LPPL maintenance status `maintained'.
%% 
%% The Current Maintainer of this work is M. Y. Name.
%%
%% This work consists of the files pig.dtx and pig.ins
%% and the derived file pig.sty.
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% Given such a notice and statement in a file, the
% conditions given in this license document would apply, with
% the `Work' referring to the three files
% {\ttfamily{}pig.dtx}\thinspace, {\ttfamily{}pig.ins}\thinspace, and {\ttfamily{}pig.sty} (the last being generated
% from {\ttfamily{}pig.dtx} using {\ttfamily{}pig.ins}), the `Base
%   Interpreter' referring to any
% `\LaTeX{}-Format', and both `Copyright
%   Holder' and `Current Maintainer'
% referring to the person
% M.~Y.~Name\index{!}.\par
% If you do not want the Maintenance section of
% \textsc{lppl} to apply to your Work, change
% `maintained' above into
% `author-maintained'. However, we recommend that
% you use `maintained' as the Maintenance
% section was added in order to ensure that your Work remains
% useful to the community even when you can no longer maintain
% and support it yourself.\par
% \subsubsection{Derived Works That Are Not Replacements}\label{NotReplacements}
% Several clauses of the \textsc{lppl} specify
% means to provide reliability and stability for the user
% community. They therefore concern themselves with the case
% that a Derived Work is intended to be used as a (compatible or
% incompatible) replacement of the original Work. If this is not
% the case (e.g., if a few lines of code are reused for a
% completely different task), then clauses 6b and 6d shall not
% apply.\par
% \subsubsection{Important Recommendations}\label{Recommendations}
% \paragraph[Defining What Constitutes the Work]{Defining What Constitutes the Work :}
% The \textsc{lppl} requires that distributions
%   of the Work contain all the files of the Work.  It is
%   therefore important that you provide a way for the licensee
%   to determine which files constitute the Work.  This could,
%   for example, be achieved by explicitly listing all the files
%   of the Work near the copyright notice of each file or by
%   using a line such as:\par
% \iffalse
%<*ignore>
% \fi
\begin{lstlisting}[language={[LaTeX]TeX}]
%% This work consists of all files listed in manifest.txt.
\end{lstlisting}
% \iffalse
%</ignore>
% \fi
% in that place.  In the absence of an unequivocal list it
%   might be impossible for the licensee to determine what is
%   considered by you to comprise the Work and, in such a case,
%   the licensee would be entitled to make reasonable
%   conjectures as to which files comprise the Work.\par
% \section{Files distributed without annotations}\label{files}
% \subsection{The {\ttfamily{}prepost.xml} lookup file}\label{prepostdoc}
% This is an example file for customisation to your own
% style of working. For documentation, see \vref{prepost-setup}.
% \iffalse
%<*prepostdoc>
<!DOCTYPE refsection 
  PUBLIC "+//Silmaril//DTD DocBook 5.0 for DocTeX//EN" "doctexbook.dtd">
<!-- This is the lookup table prepost.xml used by the db2dtx.xsl
  script, part of the ClassPack package for maintaining LaTeX
  packages and document classes in XML. It is documented in the
  manual for ClassPack in the section on AutoPackage

  To sort the contents of this file by package name, use the command
     lxsort refsection/procedure step @remap prepost.xml >

  To list the packages specified, use the command
     lxprintf -e step "%s %s\n" ancestor::procedure/@xml:id @remap prepost.xml

  To list the packages signalled as defaults for your documentation, use
     the command
     lxprintf -e 'step[constructorsynopsis[@condition=""]]' \
        "%s %s\n" ancestor::procedure/@xml:id @remap prepost.xml

  The LTxml2 utilities are available from the Language Technology Group
     at the University of Edinburgh https://www.ltg.ed.ac.uk/software/ltxml2/
-->
<refsection>
  <title>LaTeX package selection criteria</title>
  <subtitle>and useful setup commands for before and after package
    invocation</subtitle>
  <!-- WARNING: IN THIS FILE ORDER IS SIGNIFICANT AS IT DETERMINES THE
       ORDER IN WHICH PACKAGES SHOULD BE LOADED FOR MINIMAL INTERFERENCE -->
  <procedure xml:id="prepackage">
    <title>Package selection criteria and commands before invocation</title>
    <!-- TOP PRIORITY -->
    <step condition="doc" remap="dox">
      <!-- doc.sty must come first because it invokes etexcmds
           which needs \expanded, and some other packages try
           to redefine this -->
      <para>Provides extra documentation commands to
	    distinguish types of macro being defined.</para>
      <constructorsynopsis condition=""/>
    </step>
    <!-- FONT SETUP -->
    <step remap="fix-cm" condition="doc cls sty">
      <para>Allow infinitely-variable font scaling. This may be
	replaced at some future stage by the
	<package>anyfontsize</package> package.</para>
    </step>
    <step condition="doc cls" remap="fontspec">
      <para>Font specification setup for use with &XeLaTeX; and
	&LuaLaTeX;. This automatically supersedes
	<package>fontenc</package> and <package>inputenc</package>
	which are not used with TrueType and OpenType fonts.</para>
      <constructorsynopsis remap="inputenc fontenc" condition="part">
	<methodparam>
	  <parameter>conformance</parameter>
	  <modifier>xelatex</modifier>
	</methodparam>
	<methodparam>
	  <parameter>conformance</parameter>
	  <modifier>lualatex</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
    <!-- switched the order of fontenc and inputenc on the advice of
         https://tex.stackexchange.com/questions/272338/pdfx-option-clash-inputenc-fontenc-hyperref -->
    <step condition="cls sty" remap="fontenc" role="T1">
      <para>Extended font encoding to handle UTF-8.</para>
    </step>
    <step condition="doc" remap="fontenc" role="T1">
      <para>Extended font encoding to handle UTF-8.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="doc" remap="inputenc" role="utf8"
      revision="2008-03-30">
      <para>This package allows a limited range of Unicode characters
	(eg accented letters) to be used without escapes. The
	supercession of the default <package>utf8x</package> is needed
	because <package>biblatex</package> in
	non-&XeLaTeX;/&LuaLaTeX; documents does not support
	<package>utf8x</package>.</para>
      <constructorsynopsis condition="bibliography">
	<methodparam>
	  <parameter>arch</parameter>
	  <modifier>biblatex</modifier>
	</methodparam>
      </constructorsynopsis>
      <constraintdef>
	<cmdsynopsis>
	  <command>\let\SavedShow\show</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step role="utf8x" remap="inputenc" condition="cls sty"
      revision="2008-03-30">
      <para>This package allows a limited range of Unicode characters
	(eg accented letters) to be used without escapes. 
	This hack allows utf8x in .dtx files (due to Heiko Oberdiek in
	Message-ID: j24bat&dollar;f5u&dollar;1@dont-email.me, see
	“Character table corrupted in .dtx” in comp.text.tex of
	2011-08-13 [continued in post].</para> 
    </step>
    <step condition="doc" remap="inputenc" role="utf8x"
      revision="2008-03-30">
      <para>This package allows a limited range of Unicode characters
	(eg accented letters) to be used without escapes. 
	This hack allows utf8x in .dtx files (due to Heiko Oberdiek in
	Message-ID: j24bat&dollar;f5u&dollar;1@dont-email.me, see
	“Character table corrupted in .dtx” in comp.text.tex of
	2011-08-13 [continued in post].</para>
      <constructorsynopsis condition=""/>
      <constraintdef>
	<cmdsynopsis>
	  <command>\let\SavedShow\show</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <!-- FONTS: note sans and monospace packages should come after
                serif so that any scale adjustments relative to the
                (main) serif font can be made correctly -->
    <!-- SERIF FONTS and selections containing serif as a default -->
    <step remap="ibarra" arch="serif" condition="cls doc sty">
      <para>&LaTeX; support for the Ibarra Real Nova family of fonts,
	a revival of a typeface designed by Geronimo Gil for the
	publication of Don Quixote for the Real Academia de la Lengua
	in 1780. Joaquín Ibarra was the printer.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step remap="charter" arch="serif" condition="cls sty">
      <para>Bitstream Charter as the default typeface</para>
    </step>
    <step remap="DejaVuSerif" arch="serif" condition="cls sty doc"
      conformance="nosc"> 
      <para>Sets the DejaVu typeface as the default serif
	typeface.</para> 
    </step>
    <step remap="dejavu" arch="serif" condition="cls sty doc"
      conformance="nosc"> 
      <para>Sets the DejaVu typeface as the default. Note that small
	caps are absent from this font, so they are faked with a
	smaller size of caps.</para>
      <constraintdef>
	<cmdsynopsis>
	  <command>\renewcommand{\textsc}[1]{{\small\MakeTextUppercase{#1}}}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step remap="libertine" arch="serif" condition="doc cls sty">
      <para>Linux Libertine and Biolinum fonts</para> 
    </step>
   <step remap="lmodern" arch="serif" condition="cls sty">
      <para>The updated Computer Modern typeface.</para>
    </step>
    <step remap="mathptmx" arch="serif" condition="cls sty">
      <para>Adobe Times New Roman with extended (non-Adobe) Times
	math.</para>
    </step>
    <step remap="noto" arch="serif" condition="cls sty doc"
      conformance="nosc"> 
      <para>Sets the Google NoTo typeface as the default.</para>
      <constraintdef>
	<cmdsynopsis>
	  <command>\renewcommand{\textsc}[1]{{\small\MakeTextUppercase{#1}}}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step remap="plex-serif" arch="serif" condition="cls sty doc"
      conformance="nosc"> 
      <para>Sets the IBM Plex typeface as the default serif
	typeface.</para> 
    </step>
    <!-- SANS -->
    <step remap="raleway" arch="sans" condition="doc"
      role="scale=MatchLowercase">
      <para>The current Raleway family is an extension of the original
	Raleway Thin by Matt McInerney. The family has been extended
	by Impallari, for more information see the impallari website
	<uri>http://www.impallari.com/projects/overview/matt-mcinerneys-raleway-family</uri>.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step remap="raleway" arch="sans" condition="cls sty">
      <para>The current Raleway family is an extension of the original
	Raleway Thin by Matt McInerney. The family has been extended
	by Impallari, for more information see the impallari website
	<uri>http://www.impallari.com/projects/overview/matt-mcinerneys-raleway-family</uri>.</para>
    </step>
    <step remap="avant" arch="sans" condition="cls sty">
      <para>Adobe Avant Garde as the default sans-serif
	typeface.</para> 
    </step>
    <step remap="DejaVuSans" arch="sans" condition="cls sty doc"
      conformance="nosc"> 
      <para>Sets the DejaVu typeface as the default sans-serif
	typeface.</para>
    </step>
    <step remap="emerald" arch="hand" condition="cls doc sty">
      <para>Collection of handwriting typefaces.</para>
    </step>
    <step role="scaled=0.8667" remap="helvet" arch="sans"
      condition="cls sty"> 
      <para>Adobe Helvetica as the default sans-serif typeface.</para>
    </step>
    <step remap="opensans" arch="sans" condition="doc cls sty" vendor="0">
      <para>Open Sans is a humanist sans serif typeface designed by
	Steve Matteson.</para>
    </step>
    <step remap="plex-sans" arch="sans" condition="cls sty doc"
      conformance="nosc">
      <para>Sets the IBM Plex typeface as the default sans
	typeface.</para>
    </step>
    <!-- MONO -->
    <step remap="courier" arch="mono" condition="cls sty">
      <para>Adobe Courier as the default monospace (typewriter)
	typeface.</para>
    </step>
    <step remap="luximono" arch="mono" condition="cls doc sty">
      <para>A serif monospace for documentation as its
      set width is slightly smaller than most monospace fonts.</para>
    </step>
    <step remap="plex-mono" arch="mono" condition="cls sty doc"
      conformance="nosc"> 
      <para>Sets the IBM Plex typeface as the default monospace
	typeface.</para>
    </step>
    <!-- MATH -->
    <step remap="amssymb" arch="math" condition="cls sty">
      <para>Provide for the American Mathematical Society's symbols
	(see their documentation for details).</para>
    </step>
    <step remap="eucal" arch="math" condition="cls sty">
      <para>Add the AMS Euler calligraphic math letters.</para>
    </step>
    <step remap="mathdesign" arch="math" condition="cls sty">
      <para>Use the alternate MathDesign fonts for mathematics.</para>
    </step>
    <!-- HANDWRITING and SYMBOLS -->
    <step remap="bbding" arch="symbol" condition="doc cls sty">
      <para>Karel Horak's dingbats symbols.</para>
    </step>
    <step remap="manfnt" arch="symbol" condition="cls sty">
      <para>Knuth's <wordasword>manual</wordasword> font (as in
	<citetitle>The &TeX;book</citetitle>), used for symbols.</para>
    </step>
    <step remap="marvosym" arch="symbol" condition="cls sty">
      <para>Selection of symbols by Martin Vogel, including the Euro
      sign.</para> 
    </step>
    <step remap="mflogo" arch="symbol" condition="doc cls">
      <para>Provides the &METAFONT; and &METAPOST; logos.</para>
      <constructorsynopsis condition=""/>
    </step>
    <!-- BIBLIOGRAPHIES -->
    <step condition="doc" remap="apacite">
      <para>Bibliographic commands and formatting for the American
      Psychological Association journals.</para>
      <constructorsynopsis condition="bibliography">
	<methodparam>
	  <parameter>xreflabel</parameter>
	  <modifier>apacite</modifier>
	</methodparam>
      </constructorsynopsis>
      <constraintdef>
	<cmdsynopsis>
	  <command>\AtBeginDocument{\edef\ApaciteRestoreAtCode{\catcode`@=\the\catcode`@\relax}}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="cls sty" remap="babel" role="british">
      <para>Add linguistic, cultural change, and H&ampers;J support for
	many languages.</para> 
    </step>
    <step condition="doc" remap="babel" role="british">
      <para>Add linguistic, cultural change, and H&ampers;J support for many
	languages.</para> 
      <constructorsynopsis condition=""/>
    </step>
    <step condition="doc" remap="biblatex"
      role="backend=biber,doi=true,isbn=true,url=true,
            uniquename=false,style=apa">
      <para>Use <package>biblatex</package> instead of &BIBTeX;</para>
      <constructorsynopsis remap="apacite" condition="bibliography">
	<methodparam>
	  <parameter>arch</parameter>
	  <modifier>biblatex</modifier>
	</methodparam>
      </constructorsynopsis>
      <constructorsynopsis condition="exceptionname"/>
    </step>
    <step condition="cls sty" remap="biblatex"
      role="backend=biber,doi=true,isbn=true,url=true,
            uniquename=false">
      <para>Use <package>biblatex</package> instead of &BIBTeX;</para>
    </step>
    <step condition="cls sty doc" remap="csquotes">
      <para>Adds correct curly quotes for cited titles when using
	<package>biblatex</package></para>
      <constructorsynopsis condition="bibliography">
	<methodparam>
	  <parameter>arch</parameter>
	  <modifier>biblatex</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step condition="cls sty" remap="natbib">
      <para>Bibliography extensions for the Natural Sciences to allow
      author-year citation and provide additional fields (eg DOI).</para>
    </step>
    <step condition="cls sty" remap="bibunits">
      <para>Provision for per-chapter bibliographies.</para>
    </step>
    <!-- UTILS -->
    <step condition="doc cls sty" remap="lettrine">
      <para>Implements dropped initial capitals on paragraphs.</para>
    </step>
    <step remap="array" condition="doc cls sty">
      <para>Additional column formatting types for tables.</para>
      <constructorsynopsis condition="tgroup"/>
      <constructorsynopsis condition="colspec">
	<methodparam>
	  <parameter>condition</parameter>
	</methodparam>
	<methodparam>
	  <parameter>colwidth</parameter>
	</methodparam>
	<methodparam>
	  <parameter>char</parameter>
	  <modifier>m</modifier>
	</methodparam>
	<methodparam>
	  <parameter>char</parameter>
	  <modifier>b</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step remap="datetime2" condition="doc cls sty" role="en-IE">
      <para>Culturally representative date and time formats</para>
    </step>
    <step remap="dcolumn" condition="doc">
      <para>Column formatting for decimal-aligned values</para>
      <constructorsynopsis condition="colspec">
	<methodparam>
	  <parameter>align</parameter>
	  <modifier>char</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step condition="doc cls sty" remap="calc">
      <para>Required for calculations involving lengths or counters,
	such as changes to widths for margin adjustment.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="doc cls sty" remap="fp">
      <para>Used for fixed-point calculations</para>
    </step>
    <step condition="cls" remap="ccaption">
      <para>Allows modifications to the layout of table and figure
	captions.</para>
    </step>
    <step condition="doc" remap="ccaption">
      <para>Allows modifications to the layout of table and figure
	captions.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="cls sty doc" remap="changebar">
      <para>Provides marginal change bars for edited text
	locations.</para>
    </step>
    <step remap="etoolbox" condition="doc cls sty">
      <para>An e-&TeX; toolbox for class and package authors</para>
    </step>
    <step condition="cls sty doc" remap="draftwatermark">
      <para>Allow the use of a background watermark saying
      <wordasword>DRAFT</wordasword>.</para>
    </step>
    <step condition="cls doc sty" remap="enumitem" role="inline">
      <para>List variants: inline and compact.
	Note that this replaces	the earlier defaults of
	<package>paralist</package> and 
	<package>mdwlist</package>.</para>
      <constructorsynopsis condition="orderedlist">
	<methodparam>
	  <parameter>spacing</parameter>
	  <modifier>compact</modifier>
	</methodparam>
      </constructorsynopsis>
      <constructorsynopsis condition="itemizedlist">
	<methodparam>
	  <parameter>spacing</parameter>
	  <modifier>compact</modifier>
	</methodparam>
      </constructorsynopsis>
      <constructorsynopsis condition="variablelist"/>
    </step>
    <step condition="doc cls sty" remap="fancybox">
      <para>This provides round-cornered and drop-shadow boxes.</para>
      <constructorsynopsis condition="note"/>
      <constructorsynopsis condition="sidebar"/>
    </step>
    <step condition="cls sty doc" remap="fancyhdr">
      <para>Do running headers and footers.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="cls sty" remap="fancyvrb">
      <para>Add more robust verbatim facilities.</para>
      <constructorsynopsis condition="programlisting"/>
    </step>
    <step condition="doc" remap="fancyvrb">
      <para>Add more robust verbatim facilities.</para>
      <constructorsynopsis condition="bibliography"/>
      <constructorsynopsis condition="programlisting">
	<methodparam>
	  <parameter>condition</parameter>
	  <modifier>ignore</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step remap="footmisc" condition="doc cls sty">
      <para>A collection of ways to change the typesetting of
	footnotes.</para>
    </step>
    <step condition="cls sty" remap="glossaries">
      <para>Replacement for the old <package>glossary</package>, with
      hugely enhanced features.</para>
      <constructorsynopsis condition="glossary"/>
      <constructorsynopsis condition="glossterm"/>
    </step>
    <step condition="cls sty" remap="glossary-longragged">
      <para>Add-on for the <package>glossaries</package> to handle
	<envar>longtable</envar> environments with
	<command>raggedright</command> columns.</para>
    </step>
    <step condition="cls sty" remap="reledmac">
      <para>Typesetting scholarly editions</para>
    </step>
    <step condition="doc cls sty" remap="relsize">
      <para>Provides size-relative font size changes (smaller, larger,
	etc).</para>
      <constructorsynopsis condition="acronym"/>
    </step>
    <step condition="doc cls sty" remap="flexlogo">
      <para>Allows user-programmable changes to the positioning of
      letters in the &TeX;-related logos on a per-font basis.</para>
    </step>
    <step condition="cls sty" remap="textcase">
      <para>Provides a more sophisticated casing function than the
      default.</para>
    </step>
    <step condition="doc" remap="textcase">
      <para>Provides a more sophisticated casing function than the
      default.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="cls sty" remap="float">
      <para>Allows redesigning of floats and creation of new float
      types.</para> 
    </step>
    <step condition="doc" remap="float">
      <para>Allows redesigning of floats and creation of new float
	types, but used here to change the float parameters as
	suggested by Donald Arsenau in fewerfloatpages.sty (see c.t.t
	&lt;yfitv3egipb.fsf@triumf.ca> of 2020-02-25.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="doc cls sty" remap="fmtcount" role="level">
      <para>Allows for the automated formatting of ordinal
	representations of numbers and counters as strings (eg first,
	second, third, etc).</para>
      <constructorsynopsis condition="xref">
	<methodparam>
	  <funcparams>linkend</funcparams>
	  <modifier>varlistentry</modifier>
	</methodparam>
	<methodparam>
	  <funcparams>linkend</funcparams>
	  <modifier>listitem</modifier>
	</methodparam>
	<methodparam>
	  <funcparams>linkend</funcparams>
	  <modifier>coref</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
<!-- defaults for Letter
* driver: pdftex
* paper: letterpaper
* layout: <same size as paper>
* layoutoffset:(h,v)=(0.0pt,0.0pt)
* modes: 
* h-part:(L,W,R)=(72.26999pt, 469.75502pt, 72.26999pt)
* v-part:(T,H,B)=(72.26999pt, 650.43001pt, 72.26999pt)
* \paperwidth=614.295pt
* \paperheight=794.96999pt
* \textwidth=469.75502pt
* \textheight=650.43001pt
* \oddsidemargin=0.0pt
* \evensidemargin=0.0pt
* \topmargin=-37.0pt
* \headheight=12.0pt
* \headsep=25.0pt
* \topskip=10.0pt
* \footskip=30.0pt
* \marginparwidth=65.0pt
* \marginparsep=11.0pt
* \columnsep=10.0pt
* \skip\footins=9.0pt plus 4.0pt minus 2.0pt
* \hoffset=0.0pt
* \voffset=0.0pt
* \mag=1000
* \@twocolumnfalse
* \@twosidefalse
* \@mparswitchfalse
* \@reversemarginfalse
* (1in=72.27pt=25.4mm, 1cm=28.453pt)
-->
<!-- defaults for A4
* driver: pdftex
* paper: a4paper
* layout: <same size as paper>
* layoutoffset:(h,v)=(0.0pt,0.0pt)
* modes: 
* h-part:(L,W,R)=(71.13188pt, 455.24411pt, 71.13188pt)
* v-part:(T,H,B)=(71.13188pt, 702.78308pt, 71.13188pt)
* \paperwidth=597.50787pt
* \paperheight=845.04684pt
* \textwidth=455.24411pt
* \textheight=702.78308pt
* \oddsidemargin=-1.1381pt
* \evensidemargin=-1.1381pt
* \topmargin=-38.1381pt
* \headheight=12.0pt
* \headsep=25.0pt
* \topskip=10.0pt
* \footskip=30.0pt
* \marginparwidth=57.0pt
* \marginparsep=11.0pt
* \columnsep=10.0pt
* \skip\footins=9.0pt plus 4.0pt minus 2.0pt
* \hoffset=0.0pt
* \voffset=0.0pt
* \mag=1000
* \@twocolumnfalse
* \@twosidefalse
* \@mparswitchfalse
* \@reversemarginfalse
* (1in=72.27pt=25.4mm, 1cm=28.453pt)
-->
    <step condition="doc" remap="geometry"
      role="a4paper,left=30mm,top=25mm,
            textwidth=150mm,textheight=225mm,headheight=15pt">  
      <!-- width for A4, height for Letter, assuming 25mm/1in margins  -->
      <para>Needed to allow resettable left margin to take account of
	whatever the widest macro name is; and to adjust margins on
	default base article package so that the document fits
	acceptably on both A4 and Letter paper. Assuming a 25mm (1in)
	margin, this means a text area of
	\[\min\big\{8½″-2″\,\big\|\,210\mbox{mm}-50\mbox{mm}\big\}×
	\min\big\{11″-2″\,\big\|\,297\mbox{mm}-50\mbox{mm}\big\}\] 
        which I calculate as 6¼″×9″ or 159mm\,×\,229mm.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="cls sty" remap="geometry">
      <para>Package for establishing margins and text area.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="doc cls sty" remap="printlen">
      <para>Change the units with which lengths are typeset</para>
    </step>
    <step condition="doc cls sty" remap="eso-pic">
      <para>Add picture commands (or backgrounds) to every page.</para>
    </step>
    <step condition="cls sty" remap="graphicx">
      <para>Provide for graphics (PNG, JPG, or PDF format (only) for
	pdflatex; EPS format (only) for standard &LaTeX;).</para>
      <constructorsynopsis condition="imagedata">
	<methodparam>
	  <parameter>fileref</parameter>
	</methodparam>
      </constructorsynopsis>
      <constructorsynopsis condition="abstract">
	<methodparam>
	  <parameter>xlink:href</parameter>
	</methodparam>
      </constructorsynopsis>
      <constructorsynopsis condition="guiicon">
	<methodparam>
	  <parameter>xlink:href</parameter>
	</methodparam>
      </constructorsynopsis>
      <!-- why would this require graphicx?
      <constructorsynopsis condition="part">
	<methodparam>
	  <parameter>conformance</parameter>
	  <modifier>xelatex</modifier>
	</methodparam>
    </constructorsynopsis>
      -->
    </step>
    <step condition="doc" remap="graphicx">
      <para>Provide for graphics (PNG, JPG, or PDF format (only) for
	pdflatex; EPS format (only) for standard &LaTeX;).</para>
      <constructorsynopsis condition="imagedata">
	<methodparam>
	  <parameter>fileref</parameter>
	</methodparam>
      </constructorsynopsis>
      <constructorsynopsis condition="guiicon">
	<methodparam>
	  <parameter>xlink:href</parameter>
	</methodparam>
      </constructorsynopsis>
      <constructorsynopsis condition="part">
	<methodparam>
	  <parameter>conformance</parameter>
	  <modifier>xelatex</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step condition="doc" remap="hypdoc">
      <para>Provides facilities of
      <package>hyperref</package> for Doc&TeX; files.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="doc cls sty" remap="hyperref">
      <para>Provides complex settings for making hypertext (clickable)
      links in PDF and PS output for URIs, cross-references, and
      bibliographic citations.</para>
    </step>
    <step remap="hanging" condition="doc cls sty">
      <para>Enables hanging indentation.</para>
    </step>
    <step condition="cls sty" remap="ifpdf">
      <para>Allow detection of PDF or DVI mode.</para>
    </step>
    <step condition="cls sty" remap="ifsym" role="geometry">
      <para>Geometric symbols from the <filename>if</filename>
      fonts.</para> 
    </step>
    <step condition="cls sty" remap="ifthen">
      <para>Package to enable if--then--else conditional
      processing.</para>
    </step>
    <step condition="cls sty" remap="lipsum">
      <para>Package to generate <wordasword>Greeked</wordasword> text
      (actually cod-Latin) as a placeholder.</para>
    </step>
    <step condition="doc" remap="listings">
      <para>Provides syntactic fontification or formatting
	(<phrase>pretty-printing</phrase>) of verbatim text
	according to the computer language used.</para>
      <constructorsynopsis condition="programlisting"/>
      <constructorsynopsis condition="literallayout">
	<methodparam>
	  <parameter>language</parameter>
	  <modifier>bash</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step condition="cls sty" remap="listings">
      <para>Provides syntactic fontification or formatting
      (<phrase>pretty-printing</phrase>) of verbatim text according to
      the computer language used.</para>
      <constructorsynopsis condition="programlisting">
	<methodparam>
	  <parameter>language</parameter>
	</methodparam>
      </constructorsynopsis>
      <constructorsynopsis condition="literallayout">
	<methodparam>
	  <parameter>language</parameter>
	  <modifier>bash</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step remap="ltxcmds" condition="doc">
      <para>Some &LaTeX; kernel commands for general use, especially
	<command>ltx@ifpackageloaded</command>.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="doc cls sty" remap="makeidx">
      <para>Package for creating indexes.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="doc sty cls" remap="marginnote">
      <para>Adds more flexibility to marginal notes.</para>
    </step>
    <step condition="cls sty" remap="mdwlist">
      <para>DEPRECATED: USE ENUMITEM. Mark Wooding's package for
	compact lists.</para>
    </step>
    <step condition="cls sty" remap="minitoc">
      <para>Provides a <wordasword>mini</wordasword> (per-chapter or
      per-section) Table of Contents.</para>
    </step>
    <step condition="cls sty" remap="multicol">
      <para>Provides multi-column typesetting.</para>
      <constructorsynopsis condition="simplelist">
	<methodparam>
	  <parameter>role</parameter>
	  <modifier>twocol</modifier>
	</methodparam>
      </constructorsynopsis>
      <constructorsynopsis condition="orderedlist">
	<methodparam>
	  <parameter>role</parameter>
	  <modifier>twocol</modifier>
	</methodparam>
      </constructorsynopsis>
      <constructorsynopsis condition="procedure">
	<methodparam>
	  <parameter>role</parameter>
	  <modifier>twocol</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step condition="cls sty doc" remap="multirow">
      <para>Provides multi-row typesetting.</para>
      <constructorsynopsis condition="entry">
	<methodparam>
	  <parameter>morerows</parameter>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step condition="doc cls sty" remap="bigdelim">
      <para>Provide extended parentheses and braces.</para>
    </step>
    <step condition="doc cls sty" remap="nicefrac">
      <para>Slanted fractions, even in math mode.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="doc cls sty" remap="paralist">
      <para>DEPRECATED: USE ENUMITEM. Provides for in-line lists.</para>
    </step>
    <step condition="doc cls sty" remap="parskip">
      <para>Creates paragraphs separated by white-space with no
	indentation.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="doc cls sty" remap="pdfpages">
      <para>Allow embedding of individual pages from another PDF
	document.</para>
      <constructorsynopsis condition="imagedata">
	<methodparam>
	  <parameter>format</parameter>
	  <modifier>pdf</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step condition="doc cls sty" remap="ragged2e">
      <para>Allow hyphenation in ragged setting.</para>
      <constructorsynopsis condition="bibliography">
	<methodparam>
	  <parameter>remap</parameter>
	  <modifier>shortbib</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step condition="doc" remap="sectsty">
      <para>Allows the section headings to be re-styled.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="cls sty" remap="sectsty">
      <para>Allows the section headings to be re-styled.</para>
    </step>
    <step condition="cls sty" remap="titlesec">
      <para>Allows the section headings to be re-styled.</para>
    </step>
    <step condition="cls sty" remap="setspace">
      <para>Provide 1½ or double line spacing.</para>
    </step>
    <step condition="cls sty" remap="soul">
      <para>Provides letter-spacing, strikeout, and underlining.</para>
    </step>
    <step condition="cls sty" remap="textcomp">
      <para>Additional commands for common symbols and punctuation.</para>
    </step>
    <step condition="doc cls sty" remap="ucccrest">
      <para>University College Cork crest (restricted).</para>
    </step>
    <step condition="doc cls sty" remap="ulem" role="normalem">
      <para>Underlining as an option (<emphasis>not</emphasis>
	automatically replacing italics).</para>
      <constructorsynopsis condition="link"/>
    </step>
    <step condition="doc cls sty" remap="url">
      <para>Handling of URI formatting.</para>
      <constructorsynopsis condition="ulink"/>
      <constructorsynopsis condition="uri"/>
      <constructorsynopsis condition="email"/>
      <constructorsynopsis condition="">
	<methodparam>
	  <parameter>methodsynopsis</parameter>
	  <modifier>href</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step condition="doc" remap="chicago">
      <para>University of Chicago reference and citation style.</para>
      <constructorsynopsis condition="bibliography">
	<methodparam>
	  <parameter>xreflabel</parameter>
	  <modifier>chicago</modifier>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step condition="doc cls sty" remap="uccbranding">
      <para>Provides the designers' standard colours for use in UCC
	documents</para>
    </step>
    <step condition="doc cls sty" remap="varioref">
      <para>Provides extended formatting of cross-references.</para>
      <constructorsynopsis condition="xref"/>
    </step>
    <step condition="cls sty" remap="siunitx">
      <para>Provides correct rendering of SI units.</para>
    </step>
    <step condition="cls sty" remap="csvsimple">
      <para>Allows import of CSV data for use in structured lists or
	tables.</para>
    </step>
    <step condition="cls sty" remap="lastpage">
      <para>Provides for <phrase>page <emphasis>n</emphasis> of
	  <emphasis>m</emphasis></phrase> numbering.</para>
    </step>
    <step condition="cls sty" remap="environ">
      <para>Allows the creation of environments in which the content
      can be captured for later [re-]use.</para>
    </step>
    <step condition="cls sty" remap="collcell">
      <para>Allows the data content of a cell in a
      <envar>tabular</envar> environment to be captured into a macro.</para>
    </step>
    <step condition="cls sty" remap="background">
      <para>Provides background images and mechanical tints (using
      TikZ) without affecting the placement of text.</para>
    </step>
    <step condition="cls sty" remap="xargs">
      <para>Allow for multiple optional arguments.</para>
    </step>
    <step condition="doc" remap="xcolor" role="svgnames">
      <para>Provide color.</para>
      <constructorsynopsis condition=""/>
    </step>
    <step condition="cls sty" remap="xcolor" role="svgnames">
      <para>Provide color.</para>
      <constructorsynopsis condition="type">
	<methodparam>
	  <parameter>fontcolor</parameter>
	</methodparam>
	<methodparam>
	  <parameter>fontcolormodel</parameter>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step condition="doc cls sty" remap="fontawesome">
      <para>Use the FontAwesome icons</para>
      <constructorsynopsis condition="guiicon">
	<methodparam>
	  <parameter>remap</parameter>
	</methodparam>
      </constructorsynopsis>
    </step>
    <step condition="doc cls sty" remap="menukeys">
      <para>Graphical representations of menus, directories, and
	keys.</para> 
      <constructorsynopsis condition="guimenu"/>
      <constructorsynopsis condition="guimenuitem"/>
      <constructorsynopsis condition="guisubmenu"/>
      <constructorsynopsis condition="guilabel"/>
      <constructorsynopsis condition="guibutton"/>
    </step>
    <step remap="tikz" condition="doc cls sty">
      <para>Graphics utility for diagramming.</para>
    </step>
    <step remap="classpack" condition="doc">
      <para>Utilities for <productname>ClassPack</productname>-styled
      documentation.</para>
      <constructorsynopsis condition=""/>
    </step>
  </procedure>
  <!-- commands to use after a package has been loaded -->
  <procedure xml:id="postpackage">
    <step condition="doc" remap="dox">
      <!-- must come first because is invokes etexcmds which needs
      \expanded, and some other packages redefine this -->
      <para>Provides extra documentation commands to
	    distinguish types of macro being defined.</para>
      <constructorsynopsis condition=""/>
      <constraintdef>
	<cmdsynopsis>
	  <!-- define the names of new objects 
	  as per the @role attribute on the <annotation> element 
	  defined in doctexbook.dtd (excl macro and environment)-->
	  <command>\doxitem[idxtype=attribute]{Attribute}{CPKattribute}{attributes}</command>
	  <command>\doxitem[idxtype=attvalue]{AttValue}{CPKattributevalue}{attribute values}</command>
	  <command>\doxitem[macrolike,idxtype=box]{Box}{CPKbox}{boxes}</command>
	  <command>\doxitem[idxtype=class]{Class}{CPKclass}{classes}</command>
	  <command>\doxitem[idxtype=colour]{Colour}{CPKcolour}{colours}</command>
	  <command>\doxitem[idxtype=comment]{Comment}{CPKcomment}{comments}</command>
	  <command>\doxitem[idxtype=counter]{Counter}{CPKcounter}{counters}</command>
	  <command>\doxitem[idxtype=DTD]{DTD}{CPKdtd}{DTDs/Schemas}</command>
	  <command>\doxitem[idxtype=element]{Element}{CPKelement}{element types}</command>
	  <command>\doxitem[idxtype=entity]{Entity}{CPKentity}{entities}</command>
	  <command>\doxitem[idxtype=error]{Error}{CPKerror}{errors}</command>
	  <command>\doxitem[idxtype=field]{Field}{CPKfield}{fields}</command>
	  <command>\doxitem[idxtype=file]{File}{CPKfile}{files}</command>
	  <command>\doxitem[idxtype=font]{Font}{CPKfont}{fonts}</command>
	  <command>\doxitem[idxtype=function]{Function}{CPKfunction}{functions}</command>
	  <command>\doxitem[idxtype=language]{Language}{CPKlanguage}{languages}</command>
	  <command>\doxitem[idxtype=length]{Length}{CPKlength}{lengths}</command>
	  <command>\doxitem[idxtype=mode]{Mode}{CPKmode}{modes}</command>
	  <command>\doxitem[idxtype=option]{Option}{CPKoption}{options}</command>
	  <command>\doxitem[idxtype=package]{Package}{CPKpackage}{packages}</command>
	  <command>\doxitem[idxtype=parameter]{Parameter}{CPKparameter}{parameters}</command>
	  <command>\doxitem[idxtype=rubric]{Rubric}{CPKrubric}{rubrics}</command>
	  <command>\doxitem[idxtype=setting]{Setting}{CPKsetting}{settings}</command>
	  <command>\doxitem[macrolike,idxtype=switch]{Switch}{CPKswitch}{switches}</command>
	  <command>\doxitem[idxtype=template]{Template}{CPKtemplate}{templates}</command>
	  <command>\doxitem[idxtype=typeface]{Typeface}{CPKtypeface}{typefaces}</command>
	  <command>\doxitem[idxtype=variable]{Variable}{CPKvariable}{variables}</command>
	  <!-- specify a narrow font to display the tags in the userdoc -->
	  <command>\newcommand{\LabelFont}[2][\relax]{\strut
    {\fontencoding\encodingdefault
	    \fontfamily{lmtt}\fontseries{lc}#1\selectfont#2}\space}</command>
	  <!-- define the environments to implement the objects -->
	  <command>\let\CPKmacro\macro\let\CPKendmacro\endmacro</command>
	  <command>\let\CPKenvironment\environment\let\CPKendenvironment\endenvironment</command>
	  <!-- how to print them in the margin -->
	  <command>\def\PrintAttributeName#1{\LabelFont{@#1}}</command> 
	  <command>\def\PrintAttributeValueName#1{\LabelFont{"#1"}}</command>
	  <command>\def\PrintClassName#1{\LabelFont[\fontfamily{lmss}]{#1}}</command> 
	  <command>\def\PrintColourName#1{\LabelFont[\color{#1}]{#1}}</command>
	  <command>\def\PrintCommentName#1{\LabelFont[\color{LightGrey}]{#1}}</command>
	  <command>\def\PrintCounterName#1{\LabelFont{#1}}</command>
	  <command>\def\PrintDTDName#1{\LabelFont{#1}}</command>
	  <command>\def\PrintElementName#1{\LabelFont{&lt;#1&gt;}}</command> 
	  <command>\def\PrintEntityName#1{\LabelFont{\&amp;#1;}}</command>
	  <command>\def\PrintEnvironmentName#1{\LabelFont[\fontfamily{lmss}]{#1}}</command>
	  <command>\def\PrintErrorName#1{\LabelFont[\color{Red}!]{#1}}</command>
	  <command>\def\PrintFunctionName#1{\LabelFont[\bfseries\itshape]{#1}}</command>
	  <command>\def\PrintLanguageName#1{\LabelFont{#1}}</command>
	  <command>\def\PrintLengthName#1{\LabelFont{#1}}</command>
	  <command>\def\PrintMacroName#1{\LabelFont{#1}}</command>
	  <command>\def\PrintModeName#1{\LabelFont[\sffamily]{\textlangle#1\textrangle}}</command>
	  <command>\def\PrintOptionName#1{\LabelFont[\bfseries]{#1}}</command>
	  <command>\def\PrintPackageName#1{\LabelFont[\fontfamily{lmss}]{#1}}</command> 
	  <command>\def\PrintSwitchName#1{\LabelFont{#1}}</command> 
	  <command>\def\PrintTemplateName#1{\LabelFont[\bfseries]{#1}}</command>
	  <command>\def\PrintVariableName#1{\LabelFont[\ttfamily]{#1}}</command>
	  <command>\def\PrintParameterName#1{\LabelFont[\ttfamily]{#1}}</command>
	  <command>\def\PrintFieldName#1{\LabelFont[\ttfamily]{#1}}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc" remap="calc">
      <constraintdef>
	<cmdsynopsis>
	  <command>{\scriptsize
	    \global\advance\@totalleftmargin by1em
	    \global\advance\MacroIndent by.5em}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="cls" remap="glossaries">
      <constraintdef>
	<cmdsynopsis>
	  <command>\makeglossaries</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc" remap="biblatex">
      <constraintdef>
	<cmdsynopsis>
	  <command>\AtBeginDocument{%
	    \setlength{\bibitemsep}{1ex}%
	    \setlength{\bibnamesep}{1.5\itemsep}%
	    \defbibheading{shortbib}[References]%
	      {\section{#1}\parindent0pt}}
	  \@ifpackagewith{babel}{british}{%
	    \DeclareLanguageMapping{british}%
	      {british-apa}}{\relax}</command>
	  <!-- added from
	    https://tex.stackexchange.com/questions/200409/biblatex-chicago-etoolbox-error-invalid-boolean-expression -->
	  <command>\providetoggle{blx@skipbiblist}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="cls sty" remap="biblatex">
      <constraintdef>
	<cmdsynopsis>
	  <command>\AtBeginDocument{%
	    \setlength{\bibitemsep}{1ex}%
	    \setlength{\bibnamesep}{1.5\itemsep}%
	    \defbibheading{shortbib}[References]%
	      {\section{#1}}}
	  \@ifpackagewith{babel}{british}{%
	    \DeclareLanguageMapping{british}%
	      {british-apa}}{\relax}</command>
	  <!-- added from
	    https://tex.stackexchange.com/questions/200409/biblatex-chicago-etoolbox-error-invalid-boolean-expression -->
	  <command>\providetoggle{blx@skipbiblist}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc" remap="apacite">
      <constraintdef>
	<cmdsynopsis>
	  <command>\AtBeginDocument{\ApaciteRestoreAtCode\setlength\bibitemsep{0.5\baselineskip}}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc" remap="raleway">
      <para>The Raleway typeface</para>
      <constraintdef>
	<cmdsynopsis>
	  <!--
	  <command>\renewcommand{\textsc}[1]{{\smaller\MakeTextUppercase{#1}}}</command>
	  -->
	  <command>\edef\CPKsfdef{\sfdefault}</command>
	</cmdsynopsis>
	<cmdsynopsis>
	  <command>\newcommand\bsans[1]{{\ifx\f@family\CPKsfdef\bfseries\else\sffamily\fi#1}}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc" remap="caladea">
      <para>The Caladea typeface</para>
      <constraintdef>
	<cmdsynopsis>
	  <command>\renewcommand{\textsc}[1]{{\small\MakeTextUppercase{#1}}}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="cls sty doc" remap="draftwatermark">
      <para>Disable by default.</para>
      <constraintdef>
	<cmdsynopsis>
	  <command>\SetWatermarkText{}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc" remap="ccaption">
      <para>Change captions to bold raggedright.</para>
      <constraintdef>
	<cmdsynopsis>
	  <command>\captionnamefont{\bfseries}</command>
	  <command>\captionstyle{\raggedright}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="cls sty" remap="ccaption">
      <para>Add space under captions</para>
      <constraintdef>
	<cmdsynopsis>
	  <command>\postcaption{\vspace*{.5\baselineskip}}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc cls sty" remap="enumitem" role="inline">
      <constraintdef>
	<cmdsynopsis>
	  <command>\setlist[description]{style=unboxed,font=\sffamily\bfseries}</command>
	</cmdsynopsis>
	<cmdsynopsis>
	  <command>\setlist[itemize]{leftmargin=2em}</command>
	</cmdsynopsis>
	<cmdsynopsis>
	  <command>\setlist[enumerate]{leftmargin=2em}</command>
	</cmdsynopsis>
<!--
	<cmdsynopsis>
	  <command>\setlist[enumerate*,1]{label=\emph{\alph*}),
	    itemjoin={{; }},itemjoin*={{; and }}}</command>
	</cmdsynopsis>
-->
      </constraintdef>
    </step>
    <step condition="doc" remap="fancyhdr">
      <constraintdef>
	<cmdsynopsis>
	  <command>\renewcommand{\MakeUppercase}{\relax}
	    \pagestyle{fancy}
	    \lhead{\leavevmode\kern-\CPKrevmarg\footnotesize\rightmark}
	    \rhead{\footnotesize\thepage}
	    \cfoot{}
            \lfoot{\leavevmode\kern-\CPKrevmarg\footnotesize\leftmark}
	    \rfoot{\footnotesize The \LaTeX\
	      \textsf{\CPKdocname} \CPKdoctype}
	    \renewcommand{\headrulewidth}{0pt}
	    \renewcommand{\footrulewidth}{0pt}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc cls sty" remap="printlen">
      <constraintdef>
	<cmdsynopsis>
	  <command>\uselengthunit{mm}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc cls sty" remap="datetime2">
      <cmdsynopsis>
	<command>\DTMlangsetup[en-IE]{showyear=true}</command>
	<command>\DTMlangsetup{ord=omit}</command>
	<command>\DTMsetdatestyle{iso}</command>
      </cmdsynopsis>
    </step>
    <step condition="doc" remap="hypdoc">
      <constraintdef>
	<cmdsynopsis>
	  <command>\hypersetup{linkcolor=DarkGreen,citecolor=DarkRed,urlcolor=Blue,colorlinks=true}</command>
	  <command>\@ifpackageloaded{biblatex}{%</command>
	  <command>\ExecuteBibliographyOptions{maxcitenames=1}</command>
	  <command>\DeclareFieldFormat{citehyperref}{%
	    \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
	    \bibhyperref{#1}}</command>
	  <command>\DeclareFieldFormat{textcitehyperref}{%
	    \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
	    \bibhyperref{%
	    #1%
	    \ifbool{cbx:parens}
	    {\bibcloseparen\global\boolfalse{cbx:parens}}
	    {}}}</command>
	  <command>\savebibmacro{cite}</command>
	  <command>\savebibmacro{textcite}</command>
	  <command>\renewbibmacro*{cite}{%
	    \printtext[citehyperref]{%
	    \restorebibmacro{cite}%
	    \usebibmacro{cite}}}</command>
	  <command>\renewbibmacro*{textcite}{%
	    \ifboolexpr{
	    ( not test {\iffieldundef{prenote}} and
	    test {\ifnumequal{\value{citecount}}{1}} )
	    or
	    ( not test {\iffieldundef{postnote}} and
	    test {\ifnumequal{\value{citecount}}{\value{citetotal}}} )
	    }
	    {\DeclareFieldAlias{textcitehyperref}{noformat}}
	    {}%
	    \printtext[textcitehyperref]{%
	    \restorebibmacro{textcite}%
	    \usebibmacro{textcite}}}</command>
	  <command>}{\relax}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc cls sty" remap="hyperref">
      <constraintdef>
	<cmdsynopsis>
	  <command>\hypersetup{linkcolor=DarkGreen,citecolor=DarkRed,urlcolor=Blue,colorlinks=true}</command>
	  <command>\AtBeginDocument{\renewcommand{\UrlFont}{\ttfamily}}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc" remap="inputenc" role="utf8">
      <constraintdef>
	<!-- see comment in pre about why this is here -->
	<cmdsynopsis>
	  <command>\AtBeginDocument{\let\show\SavedShow}</command>
	  <command>\DeclareUnicodeCharacter{9251}{\textvisiblespace}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc" remap="inputenc" role="utf8x">
      <constraintdef>
	<!-- see comment in pre about why this is here -->
	<cmdsynopsis>
	  <command>\AtBeginDocument{\let\show\SavedShow}</command>
	  <command>\DeclareUnicodeCharacter{9251}{\textvisiblespace}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="cls sty" remap="inputenc" role="utf8x">
      <constraintdef>
	<cmdsynopsis>
	  <command>\PrerenderUnicode{–}</command>
	  <command>\PrerenderUnicode{š}</command>
	  <command>\PrerenderUnicode{ć}</command>
	  <command>\PrerenderUnicode{Å}</command>
	  <command>\PrerenderUnicode{ı}</command>
	  <command>\PrerenderUnicode{É}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc" remap="float">
      <constraintdef>
	<cmdsynopsis>
	  <command>\renewcommand{\topfraction}{.85}</command>
	  <command>\renewcommand{\bottomfraction}{.7}</command>
	  <command>\renewcommand{\textfraction}{.15}</command>
	  <command>\renewcommand{\floatpagefraction}{.66}</command>
	  <command>\renewcommand{\dbltopfraction}{.66}</command>
	  <command>\renewcommand{\dblfloatpagefraction}{.66}</command>
	  <command>\setcounter{topnumber}{9}</command>
	  <command>\setcounter{bottomnumber}{9}</command>
	  <command>\setcounter{totalnumber}{20}</command>
	  <command>\setcounter{dbltopnumber}{9}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
<!-- big change to add sty here, if it buggers up the sty files, -->
<!-- remove it -->
    <step condition="doc sty cls" remap="listings">
      <para>Provides better formatting of listings, with syntactic
	highlighting for &LaTeX; and other languages.</para>
      <constraintdef>
	<cmdsynopsis>
	  <command>\lstdefinelanguage{dummy}
	    {morekeywords={dummy}}</command>
	  <command xml:id="METAFONT">\lstdefinelanguage{METAFONT}
	    {morekeywords={draw}}</command>
	  <command xml:id="Makefile">\lstdefinelanguage{Makefile}
	  {otherkeywords={.PHONY,.DEFAULT},%
	    morekeywords={PHONY,DEFAULT,shell,ifeq,else,endif},%
	    keywordsprefix={.},%
	    moredelim=[l][\color{Green}]{:},%
	    morecomment=[l]{\#},%
	    moredelim=[s][\color{Blue}]{\$(}{)}%
	  }</command>
	  <command xml:id="DocBook">\lstdefinelanguage{DocBook}[]{XML}
	    {morekeywords={abstract,address,affiliation,annotation,arg,
	    author,book,chapter,classname,cmdsynopsis,command,
	    constraintdef,contrib,copyright,cover,date,email,emphasis,
	    envar,filename,firstname,footnote,guibutton,guilabel,
	    guimenu,guimenuitem,guisubmenu,holder,info,itemizedlist,
	    listitem,literal,member,option,orderedlist,orgdiv,orgname,
	    package,para,parameter,part,personname,phrase,procedure,
	    productname,programlisting,quote,refsection,remark,
	    constructorsynopsis,methodparan,modifier,funcparams,olink,
	    bibliography,biblioentry,biblioset,subtitle,artpagenums,
	    volumenum,issuenum,DOCTYPE,SYSTEM,xml:id,releaseinfo,
	    replaceable,revdescription,revhistory,revision,sect1,sect2,
	    sect3,sect4,seg,seglistitem,segmentedlist,segtitle,
	    simplelist,step,surname,systemitem,tag,term,title,uri,
	    userinput,variablelist,varlistentry,wordasword,xref,year,
	    xlink:href}}
	  </command>
	  <command xml:id="BiBTeX">\lstdefinelanguage{BiBTeX}
	    {morestring=[s]{\{\}},morekeywords={Article,Book,
	    BookInBook,Booklet,Collection,InBook,InCollection,
	    InProceedings,InReference,MVBook,MVCollection,
	    MVProceedings,MVReference,Manual,Misc,Online,Patent,
	    Periodical,Proceedings,Reference,Report,SuppBook,
	    SuppCollection,SuppPeriodical,Thesis,Unpublished,
	    address,annote,author,booktitle,chapter,crossref,
	    edition,editor,howpublished,institution,journal,
	    key,month,note,number,organization,pages,publisher,
	    location,
	    school,institution,series,title,type,volume,year,date}}
	  </command>
	  <command xml:id="bash">\lstdefinelanguage{bash}
	    {morestring=[s]{[]},morekeywords={exit,logout,yes,no,@,
	    password,ssh,URL,cd,dvips,latex,ls,makeindex,man,mkdir,
	    pdflatex,sudo,texconfig,texdoc,updmap,xelatex,biber,
	    latexmk,bibtex}} 
	  </command>
	  <command xml:id="APA">\lstdefinelanguage{APA}[]{XML}
	    {morekeywords={TTL}}
	  </command>
	  <command xml:id="OOXML">\lstdefinelanguage{OOXML}[]{XML}
	    {morekeywords={w:p,w:pPr,w:pStyle,w:rPr,w:rFonts,
	    w:r,w:t,w:lang}}
	  </command>
	  <command xml:id="SGML">\lstdefinelanguage{SGML}[]{XML}
	    {morekeywords={sec,ttl}}
	  </command>
	  <command xml:id="DTD">\lstdefinelanguage{DTD}[]{XML}
	    {morekeywords={ELEMENT,ENTITY,ATTLIST,CDATA,ID,REQUIRED,
	    IMPLIED,PCDATA}}
	  </command>
	  <command xml:id="Runoff">\lstdefinelanguage{Runoff}
	    {morekeywords={h1}}
	  </command>
	  <command xml:id="GML">\lstdefinelanguage{GML}
	    {morekeywords={h1}}
	  </command>
	  <command xml:id="Scribe">\lstdefinelanguage{Scribe}
	    {morekeywords={Heading},morestring=[s]{[]}}
	  </command>
	  <command xml:id="RTF">\lstdefinelanguage{RTF}[]{TeX}
	    {moretexcs={rtf,ansi,deff,adeflang,fonttbl,f,froman,fprq,
	    fcharset,f1,fswiss,falt,fnil,colortbl,red,green,blue,
	    stylesheet,s,snext,nowidctlpar,hyphen,hyphlead,hyphtrail,
	    hyphmax,cf,kerning,dbch,af,langfe,afs,alang,loch,fs,
	    pgndec,pard,plain,qc,sb,sa,keepn,b,ab,rtlch,ltrch,par}}
	  </command>
	  <command xml:id="TEI">\lstdefinelanguage{TEI}[]{XML}
	    {morekeywords={TEI,TEI.2,teiHeader,fileDesc,sourceDesc,
	    titleStmt,title,author,editor,respStmt,resp,name,
	    editionStmt,edition,text,body,publicationStmt,publisher,
	    div,div1,placeName,lg,l,s,cl,phr,w,list,distinct,p,pb,
	    mls,div2,head,num,val,app,lem,rdg,q,sup,uncl,note,
	    DOCTYPE,SYSTEM,xml:id}}[keywords,comments,strings]
	  </command>
	  <command xml:id="XSLT3">\lstdefinelanguage{XSLT3}[]{XML}
	    {morekeywords={xsl:stylesheet,xsl:transform,
	    xsl:apply-imports,xsl:attribute-set,xsl:decimal-format,
	    xsl:import,xsl:include,xsl:key,xsl:namespace-alias,
	    xsl:output,xsl:param,
	    xsl:preserve-space,xsl:strip-space,xsl:template,
	    xsl:variable,xsl:character-map,xsl:function,
	    xsl:import-schema,xsl:param,xsl:variable,
	    xsl:apply-imports,xsl:apply-templates,xsl:attribute,
	    xsl:call-template,xsl:choose,xsl:comment,xsl:copy,
	    xsl:copy-of,xsl:element,xsl:fallback,xsl:for-each,
	    xsl:if,xsl:message,xsl:number,xsl:otherwise,
	    xsl:processing-instruction,xsl:text,xsl:value-of,
	    xsl:variable,xsl:when,xsl:with-param,xsl:sort,
	    xsl:for-each-group,xsl:next-match,xsl:analyze-string,
	    xsl:namespace,xsl:result-document,xsl:copy,
	    xsl:fallback,xsl:document,xsl:sequence,
	    xsl:matching-substring,xsl:non-matching-substring,
	    xsl:perform-sort,xsl:output-character},
	    alsodigit={-}}
	  </command>
	  <command xml:id="LaTeXe">\lstdefinelanguage{LaTeXe}[LaTeX]{TeX}
	    {morekeywords = {selectlanguage,foreignlanguage,
	    textbrokenbar,textlangle,textrangle,subsection,url,
	    chapter,tableofcontents,part,subsubsection,paragraph,
	    subparagraph,maketitle,setlength,listoffigures,
	    listoftables,color,arraybackslash,includegraphics,
	    textcite,parencite,graphicspath,lstinline,
	    DeclareLanguageMapping,textcolor,definecolor,colorbox,
	    fcolorbox,RequirePackage,PassOptionsToPackage}}
	  </command>
	  <command xml:id="BIBTeX">\lstdefinelanguage{BIBTeX}{
	    morekeywords = {title,author,edition,publisher,year,
	    address},
	    morestring=[b]",
	    }
	  </command>
	  <command xml:id="Email">\lstdefinelanguage{Email}{
	    morekeywords={From,Subject,To,Date},
	    }
	  </command>
	  <command>\lstset{defaultdialect=LaTeXe,frame=single,
	    framesep=.5em,backgroundcolor=\color{AliceBlue},
	    rulecolor=\color{LightSteelBlue},framerule=1pt}
	  </command>
	  <command xml:id="XMLFRAG">\lstdefinelanguage{XMLFRAG}{tag=**[s]&lt;>}[html]</command>
	  <command>\lstnewenvironment{listingsdoc}
	    {\lstset{language={[LaTeX]TeX}}}
	    {}</command>
	  <command>\newcommand\basicdefault[1]{\footnotesize
	    \color{Black}\ttfamily#1}
	  </command>
	  <command>\lstset{basicstyle=\basicdefault{\spaceskip.5em}}</command>
	  <command>\lstset{literate=
	    {§}{{\S}}1
	    {©}{{\raisebox{.125ex}{\copyright}\enspace}}1
	    {«}{{\guillemotleft}}1
	    {»}{{\guillemotright}}1
	    {Á}{{\'A}}1
	    {Ä}{{\"A}}1
	    {É}{{\'E}}1
	    {Í}{{\'I}}1
	    {Ó}{{\'O}}1
	    {Ö}{{\"O}}1
	    {Ú}{{\'U}}1
	    {Ü}{{\"U}}1
	    {ß}{{\ss}}2
	    {à}{{\`a}}1
	    {á}{{\'a}}1
	    {ä}{{\"a}}1
	    {é}{{\'e}}1
	    {í}{{\'i}}1
	    {ó}{{\'o}}1
	    {ö}{{\"o}}1
	    {ú}{{\'u}}1
	    {ü}{{\"u}}1
	    {¹}{{\textsuperscript1}}1
            {²}{{\textsuperscript2}}1
            {³}{{\textsuperscript3}}1
	    {ı}{{\i}}1
	    {—}{{---}}1
	    {’}{{'}}1
	    {…}{{\dots}}1
	    {➝}{{$leftarrow$}}1
            {⮠}{{$\hookleftarrow$}}1
	    {␣}{{\textvisiblespace}}1,
	    keywordstyle=\color{DarkCyan}\bfseries,
	    identifierstyle=\color{DarkRed},
	    commentstyle=\color{Gray}\upshape,
	    stringstyle=\color{DarkBlue}\upshape,
	    emphstyle=\color{DarkGreen}\upshape,
	    showstringspaces=false,
	    columns=fullflexible,
	    keepspaces=true}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc cls sty" remap="makeidx">
      <constraintdef>
	<cmdsynopsis>
	  <command>\makeindex</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc cls sty" remap="menukeys">
      <para>Graphical representations of menus, directories, and keys.</para>
      <constraintdef>
	<cmdsynopsis>
	  <command>\renewmenumacro{\menu}[>]{roundedmenus}</command>
	  <command>\renewmenumacro{\directory}[/]{pathswithblackfolder}</command>
	  <command>\renewmenumacro{\keys}{shadowedroundedkeys}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc" remap="nicefrac">
      <constraintdef>
	<cmdsynopsis>
	  <command>\def\textonehalf{\ensuremath{\nicefrac12}}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc cls sty" remap="sectsty">
      <constraintdef>
	<cmdsynopsis>
	  <command>\allsectionsfont{\sffamily\raggedright}</command>
	  <command>\renewcommand*{\descriptionlabel}[1]{\hspace\labelsep
	    \sffamily\bfseries #1}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step remap="tikz" condition="doc cls sty">
      <para>The calc library is useful.</para>
      <constraintdef>
	<cmdsynopsis>
	  <command>\usetikzlibrary{calc}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc sty cls" remap="varioref">
      <constraintdef>
	<cmdsynopsis>
	  <command>\vrefwarning</command>
	  <command>\labelformat{appendix}{Appendix~#1}</command>
	  <command>\labelformat{chapter}{\@chapapp~#1}</command>
	  <command>\labelformat{section}{section~#1}</command>
	  <command>\labelformat{subsection}{section~#1}</command>
	  <command>\labelformat{subsubsection}{section~#1}</command>
	  <command>\labelformat{paragraph}{section~#1}</command>
	  <command>\labelformat{figure}{Figure~#1}</command>
	  <command>\labelformat{table}{Table~#1}</command>
	  <command>\labelformat{item}{item~#1}</command>
	  <command>\renewcommand{\reftextcurrent}{elsewhere on this
	    page}</command> 
	  <command>\def\reftextafter{on the
	    \reftextvario{next}{following} page}</command> 
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc" remap="fontspec">
      <!-- https://tex.stackexchange.com/questions/303532/xelatex-fontspec-and-printing-the-name-of-the-current-font by egreg -->
      <para>Command <command>printinternalcurrentfont</command> added.</para>
      <constraintdef>
	<cmdsynopsis>
	  <command>\newcommand{\printexternalcurrentfont}{%
  \expandafter\format@externalcurrentfont\fontname\font:\@nil}%
  \def\format@externalcurrentfont[#1]:#2\@nil{%
  \texttt{\@ifnextchar"{\@gobble}{}#1}%
}	  </command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="cls sty doc" remap="xcolor">
      <para>There seems to be a bug in the T1 encoding of some package
	(unidentified, but possibly <package>xcolor</package>) which
	uses the command <command>T1</command>, which is an
	impossibility (no digits allowed in command names). So we fake
	it here to stop &LaTeX; complaining, by dropping the first
	argument on the floor.</para>
      <constraintdef>
	<cmdsynopsis>
	  <command>\@ifundefined{T}{%
	    \newcommand{\T}[2]{{\fontencoding{T1}%
	      \selectfont#2}}}{}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
    <step condition="doc" remap="url">
      <para>Adding a direct call to <command>urlstyle</command>
	because APA <productname>biblatex</productname> format
	doesn’t.</para>
      <constraintdef>
	<cmdsynopsis>
	  <command>\AtBeginDocument{\urlstyle{tt}}</command>
	</cmdsynopsis>
      </constraintdef>
    </step>
  </procedure>
</refsection>
%</prepostdoc>
% \fi
% \subsection{The {\ttfamily{}representation.xml} file}\label{rep}
% This file is used to reproduce the list of typographic
% representations and the typeface[s] in use. The \texttt{<row>}\index{row=\texttt{\char'074 row\char'076 } (element)}\index{elements:!row=\texttt{\char'074 row\char'076 }}
% element is tested in {\ttfamily{}figtab2latex.xsl} to
% compare each named element in the first cell with your
% \emph{ClassPack} document and the row gets
% included if there is at least one instance of it in the
% document (see the \ordinalstringnum{4} item in the list in \vref{testinc}).
% \iffalse
%<*rep>
<?xml version="1.0"?>
<!DOCTYPE section PUBLIC 
  "+//Silmaril//DTD DocBook 5.0 for DocTeX//EN" "doctexbook-master.dtd" [
<!ENTITY % OUTPUT "LaTeX">
]>
<section xml:id="typorep">
  <title>Typographic representation</title>
  <para>In this document, the following information items are shown in
  this way:</para>
  <informaltable role="\rmfamily">
    <tgroup cols="2">
      <colspec align="left"/>
      <colspec colwidth="12cm" align="left"/>
      <thead>
	<row>
	  <entry>Item</entry>
	  <entry>Description</entry>
	</row>
      </thead>
      <tbody>
	<row condition="test">
	  <entry><classname>class</classname></entry>
	  <entry>name of a &LaTeX; document class</entry>
	</row>
	<row condition="test">
	  <entry><code>code</code></entry>
	  <entry>word or phrase in a programming language</entry>
	</row>
	<row condition="test">
	  <entry><command>command</command></entry>
	  <entry>name of a &LaTeX; <wordasword>command</wordasword>
	    (&TeX; macro or control sequence)</entry>
	</row>
	<row condition="test">
	  <entry><envar>environment</envar></entry>
	  <entry>name of a &LaTeX; environment</entry>
	</row>
	<row condition="test">
	  <entry><filename>filename</filename></entry>
	  <entry>name of a file</entry>
	</row>
	<row condition="test">
	  <entry><firstterm>firstterm</firstterm></entry>
	  <entry>first significant use of a technical term</entry>
	</row>
	<row condition="test">
	  <entry><function>function</function></entry>
	  <entry>name of a function in a programming language</entry>
	</row>
	<row condition="test">
	  <entry><guibutton>button</guibutton></entry>
	  <entry>a button in a <acronym>GUI</acronym></entry>
	</row>
	<row condition="test">
	  <entry><guilabel>label</guilabel></entry>
	  <entry>a label in a <acronym>GUI</acronym></entry>
	</row>
	<row condition="test">
	  <entry><guimenu>menu</guimenu></entry>
	  <entry>a top-level menu entry in a <acronym>GUI</acronym></entry>
	</row>
	<row condition="test">
	  <entry><keycap>keycap</keycap></entry>
	  <entry>a keycap (single key)</entry>
	</row>
	<row condition="test">
	  <entry><methodname>template</methodname></entry>
	  <entry>name of a template in an <acronym>XSLT</acronym> script</entry>
	</row>
	<row condition="test">
	  <entry><option>option</option></entry>
	  <entry>name of an option to a &LaTeX; command, environment,
	    class, or package</entry>
	</row>
	<row condition="test">
	  <entry><package>package</package></entry>
	  <entry>name of a &LaTeX; package</entry>
	</row>
	<row condition="test">
	  <entry><parameter>parameter</parameter></entry>
	  <entry>name of a parameter to a &LaTeX; command or environment, or
	    to an <acronym>XSLT</acronym> script</entry>
	</row>
	<row condition="test">
	  <entry><productname>productname</productname></entry>
	  <entry>a product name</entry>
	</row>
	<row condition="test">
	  <entry><replaceable>replaceable</replaceable></entry>
	  <entry>a mnemonic for a user-replaceable string in a
	  paradigm of a command or procedure</entry>
	</row>
	<row condition="test">
	  <entry><systemitem>systemitem</systemitem></entry>
	  <entry>a computer system item (eg hostname or data value)</entry>
	</row>
	<row condition="test">
	  <entry><tag class="emptytag">tag</tag></entry>
	  <entry>a tag name in a markup language (eg <acronym>XML</acronym>)</entry>
	</row>
	<row condition="test">
	  <entry><varname>varname</varname></entry>
	  <entry>a variable name in a supported language</entry>
	</row>
      </tbody>
    </tgroup>
  </informaltable>
  <para>
  </para>
  <!--
  <para>This document is typeset in <type fontfamily="roman"/>, with
    <type fontfamily="sans"/> as the sans-serif face, and <type
      fontfamily="monospace"/> for the monospace.</para>
-->
</section>
%</rep>
% \fi
% \subsection{The {\ttfamily{}languages.xml} lookup file}\label{langsfile}
% This file will be used to look up language details for the
% \textsf{babel} and \textsf{polyglossia}
% packages.
% \par\begingroup
%   \fboxsep1em\centering
%   \fbox{\begin{minipage}{0.8\columnwidth}\sffamily
%  \raggedright\parindent0pt
%  \parskip=.5\baselineskip
% Order is significant in this file. When there are
%   multiple entries for a single \texttt{@Lang}\index{Lang=\texttt{\char'100 Lang} (attribute)}\index{attributes:!Lang=\texttt{\char'100 Lang}} attribute, the
%   \emph{last} one is used by
%   \emph{ClassPack}.\par
% \end{minipage}}\par\endgroup
% \iffalse
%<*langsfile>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE languages [
<!ELEMENT languages (language)+>
<!ELEMENT language EMPTY>
<!ATTLIST language
AsBabelOptions CDATA #IMPLIED
BabelName CDATA #IMPLIED
Country CDATA #IMPLIED
Encoding CDATA #IMPLIED
FontEncoding CDATA #IMPLIED
GuiName CDATA #IMPLIED
HasGuiSupport CDATA #IMPLIED
InternalEncoding CDATA #IMPLIED
Lang CDATA #IMPLIED
Language CDATA #IMPLIED
LangVariety CDATA #IMPLIED
name CDATA #REQUIRED
PolyglossiaName CDATA #IMPLIED
PolyglossiaOpts CDATA #IMPLIED
PostBabel CDATA #IMPLIED
QuoteStyle CDATA #IMPLIED
Requires CDATA #IMPLIED
RTL CDATA #IMPLIED>
]>
<languages>
   <language name="afrikaans"
             Language="afrikaans"
             GuiName="Afrikaans"
             BabelName="afrikaans"
             QuoteStyle="polish"
             Encoding="iso8859-15"
             Lang="af"
             Country="ZA"/>
   <language name="arabic_arabtex"
             Language="arabic_arabtex"
             GuiName="Arabic"
             HasGuiSupport="true"
             BabelName="arabtex"
             QuoteStyle="french"
             Encoding="cp1256"
             RTL="true"
             Lang="ar"
             Country="SA"/>
   <language name="arabic_arabi"
             Language="arabic_arabi"
             GuiName="Arabic"
             BabelName="arabic"
             PolyglossiaName="arabic"
             QuoteStyle="french"
             Encoding="cp1256"
             FontEncoding="LFE,LAE"
             RTL="true"
             AsBabelOptions="true"
             Lang="ar"
             Country="SA"/>
   <language name="belarusian"
             Language="belarusian"
             GuiName="Belarusian"
             BabelName="belarusian"
             QuoteStyle="french"
             Encoding="cp1251"
             AsBabelOptions="true"
             Lang="be"
             Country="BY"/>
   <language name="bulgarian"
             Language="bulgarian"
             GuiName="Bulgarian"
             BabelName="bulgarian"
             PolyglossiaName="bulgarian"
             QuoteStyle="german"
             Encoding="cp1251"
             FontEncoding="T2A"
             Lang="bg"
             Country="BG"/>
   <language name="tibetan"
             Language="tibetan"
             GuiName="Tibetan"
             PolyglossiaName="tibetan"
             Encoding="utf8"
             Lang="bo"
             Country="CN"/>
   <language name="breton"
             Language="breton"
             GuiName="Breton"
             BabelName="breton"
             PolyglossiaName="breton"
             QuoteStyle="french"
             Encoding="iso8859-15"
             Lang="br"
             Country="FR"/>
   <language name="catalan"
             Language="catalan"
             GuiName="Catalan"
             HasGuiSupport="true"
             BabelName="catalan"
             PolyglossiaName="catalan"
             PolyglossiaOpts="babelshorthands=true"
             QuoteStyle="french"
             Encoding="iso8859-15"
             Lang="ca"
             Country="ES"/>
   <language name="coptic"
             Language="coptic"
             GuiName="Coptic"
             PolyglossiaName="coptic"
             Encoding="utf8"
             Lang="cop"
             Country="EG"/>
   <language name="czech"
             Language="czech"
             GuiName="Czech"
             HasGuiSupport="true"
             BabelName="czech"
             PolyglossiaName="czech"
             QuoteStyle="german"
             Encoding="iso8859-2"
             Lang="cs"
             Country="CZ"/>
   <language name="welsh"
             Language="welsh"
             GuiName="Welsh"
             BabelName="welsh"
             PolyglossiaName="welsh"
             QuoteStyle="english"
             Encoding="iso8859-15"
             Lang="cy"
             Country="GB"/>
   <language name="danish"
             Language="danish"
             GuiName="Danish"
             HasGuiSupport="true"
             BabelName="danish"
             PolyglossiaName="danish"
             QuoteStyle="danish"
             Encoding="iso8859-15"
             Lang="da"
             Country="DK"/>
   <language name="german"
             Language="german"
             GuiName="German"
             BabelName="german"
             PolyglossiaName="german"
             PolyglossiaOpts="variant=german,spelling=old,babelshorthands=true"
             QuoteStyle="german"
             Encoding="iso8859-15"
             LangVariety="alt"
             Lang=""
             Country=""/>
   <language name="austrian"
             Language="austrian"
             GuiName="German"
             BabelName="austrian"
             PolyglossiaName="german"
             PolyglossiaOpts="variant=austrian,spelling=old,babelshorthands=true"
             QuoteStyle="german"
             Encoding="iso8859-15"
             Lang="de"
             Country="AT"/>
   <language name="naustrian"
             Language="naustrian"
             GuiName="German"
             BabelName="naustrian"
             PolyglossiaName="german"
             PolyglossiaOpts="variant=austrian,spelling=new,babelshorthands=true"
             QuoteStyle="german"
             Encoding="iso8859-15"
             Lang="de"
             Country="AT"/>
   <language name="german-ch"
             Language="german-ch"
             GuiName="German"
             BabelName="nswissgerman"
             PolyglossiaName="german"
             PolyglossiaOpts="babelshorthands=true"
             QuoteStyle="danish"
             Encoding="iso8859-15"
             Lang="de"
             Country="CH"/>
   <language name="german-ch-old"
             Language="german-ch-old"
             GuiName="German"
             BabelName="swissgerman"
             PolyglossiaName="german"
             PolyglossiaOpts="spelling=old,babelshorthands=true"
             QuoteStyle="danish"
             Encoding="iso8859-15"
             Lang="de"
             Country="CH"/>
   <language name="ngerman"
             Language="ngerman"
             GuiName="German"
             HasGuiSupport="true"
             BabelName="ngerman"
             PolyglossiaName="german"
             PolyglossiaOpts="variant=german,spelling=new,babelshorthands=true"
             QuoteStyle="german"
             Encoding="iso8859-15"
             Lang="de"
             Country="DE"/>
   <language name="lowersorbian"
             Language="lowersorbian"
             GuiName="Lower"
             BabelName="lowersorbian"
             PolyglossiaName="lsorbian"
             QuoteStyle="german"
             Encoding="iso8859-2"
             Lang="dsb"
             Country="DE"/>
   <language name="divehi"
             Language="divehi"
             GuiName="Divehi"
             PolyglossiaName="divehi"
             Encoding="utf8"
             Lang="dv"
             Country="MV"/>
   <language name="greek"
             Language="greek"
             GuiName="Greek"
             HasGuiSupport="true"
             BabelName="greek"
             PolyglossiaName="greek"
             PolyglossiaOpts="variant=monotonic"
             QuoteStyle="french"
             Encoding="iso8859-7"
             InternalEncoding="true"
             FontEncoding="LGR"
             Lang="el"
             Country="GR"/>
   <language name="polutonikogreek"
             Language="polutonikogreek"
             GuiName="Greek"
             BabelName="polutonikogreek"
             PolyglossiaName="greek"
             PolyglossiaOpts="variant=polytonic"
             QuoteStyle="french"
             Encoding="iso8859-7"
             InternalEncoding="true"
             FontEncoding="LGR"
             Lang="el"
             Country="GR"/>
   <language name="australian"
             Language="australian"
             GuiName="English"
             BabelName="australian"
             PolyglossiaName="english"
             PolyglossiaOpts="variant=australian"
             Encoding="iso8859-15"
             QuoteStyle="english"
             Lang="en"
             Country="AU"/>
   <language name="canadian"
             Language="canadian"
             GuiName="English"
             BabelName="canadian"
             QuoteStyle="english"
             Encoding="iso8859-15"
             Lang="en"
             Country="CA"/>
   <language name="british"
             Language="british"
             GuiName="English"
             BabelName="british"
             PolyglossiaName="english"
             PolyglossiaOpts="variant=british"
             QuoteStyle="english"
             Encoding="iso8859-15"
             Lang="en"
             Country="GB"/>
   <language name="newzealand"
             Language="newzealand"
             GuiName="English"
             BabelName="newzealand"
             PolyglossiaName="english"
             PolyglossiaOpts="variant=newzealand"
             QuoteStyle="english"
             Encoding="iso8859-15"
             Lang="en"
             Country="NZ"/>
   <language name="american"
             Language="american"
             GuiName="English"
             BabelName="american"
             PolyglossiaName="english"
             PolyglossiaOpts="variant=american"
             QuoteStyle="english"
             Encoding="iso8859-15"
             Lang="en"
             Country="US"/>
   <language name="english"
             Language="english"
             GuiName="English"
             HasGuiSupport="true"
             BabelName="english"
             PolyglossiaName="english"
             PolyglossiaOpts="variant=american"
             QuoteStyle="english"
             Encoding="iso8859-15"
             Lang="en"
             Country="US"/>
   <language name="esperanto"
             Language="esperanto"
             GuiName="Esperanto"
             BabelName="esperanto"
             PolyglossiaName="esperanto"
             QuoteStyle="english"
             Encoding="iso8859-3"
             Lang="eo"
             Country="EO"/>
   <language name="spanish-mexico"
             Language="spanish-mexico"
             GuiName="Spanish"
             BabelName="spanish"
             PolyglossiaName="spanish"
             QuoteStyle="french"
             Encoding="iso8859-15"
             PostBabel="\addto\shorthandsspanish{\spanishdeactivate{~&lt;&gt;.}}"
             Lang="es"
             Country="MX"/>
   <language name="spanish"
             Language="spanish"
             GuiName="Spanish"
             HasGuiSupport="true"
             BabelName="spanish"
             PolyglossiaName="spanish"
             QuoteStyle="french"
             Encoding="iso8859-15"
             PostBabel="\addto\shorthandsspanish{\spanishdeactivate{~&lt;&gt;}}"
             Lang="es"
             Country="ES"/>
   <language name="estonian"
             Language="estonian"
             GuiName="Estonian"
             BabelName="estonian"
             PolyglossiaName="estonian"
             QuoteStyle="polish"
             Encoding="iso8859-15"
             PostBabel="\addto\extrasestonian{\bbl@deactivate{~}}"
             Lang="et"
             Country="EE"/>
   <language name="basque"
             Language="basque"
             GuiName="Basque"
             HasGuiSupport="true"
             BabelName="basque"
             PolyglossiaName="basque"
             QuoteStyle="french"
             Encoding="iso8859-15"
             PostBabel="\addto\extrasbasque{\bbl@deactivate{~}}"
             Lang="eu"
             Country="ES"/>
   <language name="farsi"
             Language="farsi"
             GuiName="Farsi"
             BabelName="farsi"
             PolyglossiaName="farsi"
             Encoding="utf8"
             FontEncoding="LFE,LAE"
             RTL="true"
             PostBabel="\DeclareTextSymbol{\guillemotright}{LFE}{62}\DeclareTextSymbol{\guillemotleft}{LFE}{60}"
             Lang="fa"
             Country="IR"/>
   <language name="finnish"
             Language="finnish"
             GuiName="Finnish"
             HasGuiSupport="true"
             BabelName="finnish"
             PolyglossiaName="finnish"
             QuoteStyle="swedish"
             Encoding="iso8859-15"
             Lang="fi"
             Country="FI"/>
   <language name="canadien"
             Language="canadien"
             GuiName="French"
             BabelName="canadien"
             QuoteStyle="french"
             Encoding="iso8859-15"
             Lang="fr"
             Country="CA"/>
   <language name="french"
             Language="french"
             GuiName="French"
             HasGuiSupport="true"
             BabelName="french"
             PolyglossiaName="french"
             QuoteStyle="french"
             Encoding="iso8859-15"
             PostBabel="\addto\extrasfrench{%\providecommand{\og}{\leavevmode\flqq~}%\providecommand{\fg}{\ifdim\lastskip&gt;\z@\unskip\fi~\frqq}%}"
             Lang="fr"
             Country="FR"/>
   <language name="irish"
             Language="irish"
             GuiName="Irish"
             BabelName="irish"
             PolyglossiaName="irish"
             QuoteStyle="english"
             Encoding="iso8859-15"
             Lang="ga"
             Country="IE"/>
   <language name="english"
             Language="english"
             GuiName="Hiberno-English"
             BabelName="british"
             PolyglossiaName="variant=british"
             QuoteStyle="english"
             Encoding="iso8859-15"
             Lang="en"
             Country="IE"/>
   <language name="scottish"
             Language="scottish"
             GuiName="Scottish"
             BabelName="scottish"
             PolyglossiaName="scottish"
             QuoteStyle="english"
             Encoding="iso8859-15"
             Lang="gd"
             Country="GB"/>
   <language name="galician"
             Language="galician"
             GuiName="Galician"
             HasGuiSupport="true"
             BabelName="galician"
             PolyglossiaName="galician"
             QuoteStyle="french"
             Encoding="iso8859-15"
             PostBabel="\addto\shorthandsgalician{\galiciandeactivate{~}}"
             Lang="gl"
             Country="ES"/>
   <language name="ancientgreek"
             Language="ancientgreek"
             GuiName="Greek"
             BabelName="greek"
             PostBabel="\languageattribute{greek}{ancient}"
             PolyglossiaName="greek"
             PolyglossiaOpts="variant=ancient"
             QuoteStyle="french"
             Encoding="iso8859-7"
             InternalEncoding="true"
             FontEncoding="LGR"
             Lang="grc"
             Country="GR"/>
   <language name="hebrew"
             Language="hebrew"
             GuiName="Hebrew"
             HasGuiSupport="true"
             BabelName="hebrew"
             PolyglossiaName="hebrew"
             Encoding="cp1255"
             QuoteStyle="english"
             InternalEncoding="true"
             RTL="true"
             Lang="he"
             Country="IL"/>
   <language name="hindi"
             Language="hindi"
             GuiName="Hindi"
             PolyglossiaName="hindi"
             Encoding="utf8"
             Lang="hi"
             Country="IN"/>
   <language name="croatian"
             Language="croatian"
             GuiName="Croatian"
             BabelName="croatian"
             PolyglossiaName="croatian"
             QuoteStyle="polish"
             Encoding="iso8859-2"
             Lang="hr"
             Country="HR"/>
   <language name="uppersorbian"
             Language="uppersorbian"
             GuiName="Upper"
             BabelName="uppersorbian"
             PolyglossiaName="usorbian"
             QuoteStyle="german"
             Encoding="iso8859-2"
             Lang="hsb"
             Country="DE"/>
   <language name="magyar"
             Language="magyar"
             GuiName="Hungarian"
             HasGuiSupport="true"
             BabelName="magyar"
             PolyglossiaName="magyar"
             QuoteStyle="polish"
             Encoding="iso8859-2"
             Lang="hu"
             Country="HU"/>
   <language name="armenian"
             Language="armenian"
             GuiName="Armenian"
             PolyglossiaName="armenian"
             QuoteStyle="french"
             Encoding="utf8"
             Lang="hy"
             Country="AM"/>
   <language name="interlingua"
             Language="interlingua"
             GuiName="Interlingua"
             HasGuiSupport="true"
             BabelName="interlingua"
             PolyglossiaName="interlingua"
             Encoding="iso8859-15"
             Lang="ia"
             Country="IA"/>
   <language name="bahasa"
             Language="bahasa"
             GuiName="Indonesian"
             HasGuiSupport="true"
             BabelName="bahasa"
             PolyglossiaName="bahasai"
             QuoteStyle="english"
             Encoding="iso8859-15"
             Lang="id"
             Country="ID"/>
   <language name="ignore"
             Language="ignore"
             GuiName="Ignore"
             BabelName="ignore"
             PolyglossiaName="ignore"
             Encoding="iso8859-1"
             Lang=""
             Country=""/>
   <language name="icelandic"
             Language="icelandic"
             GuiName="Icelandic"
             BabelName="icelandic"
             PolyglossiaName="icelandic"
             QuoteStyle="german"
             Encoding="iso8859-15"
             Lang="is"
             Country="IS"/>
   <language name="italian"
             Language="italian"
             GuiName="Italian"
             HasGuiSupport="true"
             BabelName="italian"
             PolyglossiaName="italian"
             QuoteStyle="french"
             Encoding="iso8859-15"
             Lang="it"
             Country="IT"/>
   <language name="japanese"
             Language="japanese"
             GuiName="Japanese"
             HasGuiSupport="true"
             BabelName="japanese"
             Encoding="jis-platex"
             AsBabelOptions="true"
             Requires="japanese"
             InternalEncoding="true"
             FontEncoding="None"
             Lang="ja"
             Country="JP"/>
   <language name="japanese-cjk"
             Language="japanese-cjk"
             GuiName="Japanese"
             Encoding="euc-jp"
             Requires="CJK"
             Lang="ja"
             Country="JP"/>
   <language name="georgian"
             Language="georgian"
             GuiName="Georgian"
             BabelName="georgian"
             QuoteStyle="german"
             Encoding="utf8"
             FontEncoding="T8M"
             Lang="ka"
             Country="GE"/>
   <language name="kazakh"
             Language="kazakh"
             GuiName="Kazakh"
             Encoding="ascii"
             PostBabel="\input{t2aenc.def}\AtBeginDocument{\fontencoding{T2A}\selectfont}"
             Lang="kk"
             Country="KZ"/>
   <language name="kurmanji"
             Language="kurmanji"
             GuiName="Kurmanji"
             BabelName="kurmanji"
             Encoding="utf8"
             AsBabelOptions="true"
             Lang=""
             Country=""/>
   <language name="korean"
             Language="korean"
             GuiName="Korean"
             Encoding="euc-kr"
             QuoteStyle="english"
             Requires="CJK"
             Lang="ko"
             Country="KR"/>
   <language name="latin"
             Language="latin"
             GuiName="Latin"
             BabelName="latin"
             PolyglossiaName="latin"
             Encoding="iso8859-15"
             Lang="la"
             Country="LA"/>
   <language name="latex"
             Language="latex"
             GuiName="LaTeX"
             Encoding="iso8859-1"
             Lang=""
             Country=""/>
   <language name="lao"
             Language="lao"
             GuiName="Lao"
             PolyglossiaName="lao"
             Encoding="utf8"
             Lang="lo"
             Country="LA"/>
   <language name="lithuanian"
             Language="lithuanian"
             GuiName="Lithuanian"
             BabelName="lithuanian"
             PolyglossiaName="lithuanian"
             QuoteStyle="german"
             Encoding="iso8859-13"
             FontEncoding="L7x"
             AsBabelOptions="true"
             Lang="lt"
             Country="LT"/>
   <language name="latvian"
             Language="latvian"
             GuiName="Latvian"
             BabelName="latvian"
             PolyglossiaName="latvian"
             QuoteStyle="danish"
             Encoding="iso8859-4"
             AsBabelOptions="true"
             Lang="lv"
             Country="LV"/>
   <language name="mongolian"
             Language="mongolian"
             GuiName="Mongolian"
             BabelName="mongolian"
             Encoding="utf8"
             FontEncoding="T2A"
             AsBabelOptions="true"
             Lang="mn"
             Country="MN"/>
   <language name="marathi"
             Language="marathi"
             GuiName="Marathi"
             PolyglossiaName="marathi"
             Encoding="utf8"
             Lang="mr"
             Country="IN"/>
   <language name="bahasam"
             Language="bahasam"
             GuiName="Malay"
             BabelName="bahasam"
             PolyglossiaName="bahasam"
             QuoteStyle="english"
             Encoding="iso8859-15"
             Lang="ms"
             Country="MY"/>
   <language name="norsk"
             Language="norsk"
             GuiName="Norwegian"
             HasGuiSupport="true"
             BabelName="norsk"
             PolyglossiaName="norsk"
             QuoteStyle="french"
             Encoding="iso8859-15"
             Lang="nb"
             Country="NO"/>
   <language name="dutch"
             Language="dutch"
             GuiName="Dutch"
             HasGuiSupport="true"
             BabelName="dutch"
             PolyglossiaName="dutch"
             PolyglossiaOpts="babelshorthands=true"
             QuoteStyle="polish"
             Encoding="iso8859-15"
             Lang="nl"
             Country="NL"/>
   <language name="nynorsk"
             Language="nynorsk"
             GuiName="Norwegian"
             HasGuiSupport="true"
             BabelName="nynorsk"
             PolyglossiaName="nynorsk"
             QuoteStyle="french"
             Encoding="iso8859-15"
             Lang="nn"
             Country="NO"/>
   <language name="occitan"
             Language="occitan"
             GuiName="Occitan"
             PolyglossiaName="occitan"
             QuoteStyle="french"
             Encoding="utf8"
             Lang="oc"
             Country="FR"/>
   <language name="polish"
             Language="polish"
             GuiName="Polish"
             HasGuiSupport="true"
             BabelName="polish"
             PolyglossiaName="polish"
             QuoteStyle="polish"
             Encoding="iso8859-2"
             Lang="pl"
             Country="PL"/>
   <language name="brazilian"
             Language="brazilian"
             GuiName="Portuguese"
             HasGuiSupport="true"
             BabelName="brazil"
             PolyglossiaName="brazil"
             QuoteStyle="english"
             Encoding="iso8859-15"
             Lang="pt"
             Country="BR"/>
   <language name="portuguese"
             Language="portuguese"
             GuiName="Portuguese"
             HasGuiSupport="true"
             BabelName="portuges"
             PolyglossiaName="portuges"
             QuoteStyle="english"
             Encoding="iso8859-15"
             Lang="pt"
             Country="PT"/>
   <language name="romanian"
             Language="romanian"
             GuiName="Romanian"
             HasGuiSupport="true"
             BabelName="romanian"
             PolyglossiaName="romanian"
             QuoteStyle="polish"
             Encoding="iso8859-16"
             Lang="ro"
             Country="RO"/>
   <language name="russian"
             Language="russian"
             GuiName="Russian"
             HasGuiSupport="true"
             BabelName="russian"
             PolyglossiaName="russian"
             QuoteStyle="french"
             Encoding="koi8-r"
             FontEncoding="T2A"
             Lang="ru"
             Country="RU"/>
   <language name="sanskrit"
             Language="sanskrit"
             GuiName="Sanskrit"
             PolyglossiaName="sanskrit"
             Encoding="utf8"
             Lang="sa"
             Country="IN"/>
   <language name="samin"
             Language="samin"
             GuiName="North"
             BabelName="samin"
             PolyglossiaName="samin"
             Encoding="iso8859-15"
             Lang="se"
             Country="NO"/>
   <language name="slovak"
             Language="slovak"
             GuiName="Slovak"
             HasGuiSupport="true"
             BabelName="slovak"
             PolyglossiaName="slovak"
             QuoteStyle="german"
             Encoding="iso8859-2"
             Lang="sk"
             Country="SK"/>
   <language name="slovene"
             Language="slovene"
             GuiName="Slovene"
             BabelName="slovene"
             PolyglossiaName="slovenian"
             QuoteStyle="german"
             Encoding="iso8859-2"
             Lang="sl"
             Country="SI"/>
   <language name="albanian"
             Language="albanian"
             GuiName="Albanian"
             BabelName="albanian"
             PolyglossiaName="albanian"
             QuoteStyle="french"
             Encoding="iso8859-2"
             Lang="sq"
             Country="AL"/>
   <language name="serbian"
             Language="serbian"
             GuiName="Serbian"
             HasGuiSupport="true"
             BabelName="serbianc"
             PolyglossiaName="serbian"
             PolyglossiaOpts="script=Cyrillic"
             QuoteStyle="german"
             Encoding="utf8"
             FontEncoding="T2A"
             AsBabelOptions="true"
             Lang="sr"
             Country="RS"/>
   <language name="serbian-latin"
             Language="serbian-latin"
             GuiName="Serbian"
             BabelName="serbian"
             PolyglossiaName="serbian"
             PolyglossiaOpts="script=Latin"
             QuoteStyle="german"
             Encoding="iso8859-2"
             Lang="sr"
             Country="RS-Latin"/>
   <language name="swedish"
             Language="swedish"
             GuiName="Swedish"
             HasGuiSupport="true"
             BabelName="swedish"
             PolyglossiaName="swedish"
             QuoteStyle="swedish"
             Encoding="iso8859-15"
             Lang="sv"
             Country="SE"/>
   <language name="tamil"
             Language="tamil"
             GuiName="Tamil"
             PolyglossiaName="tamil"
             Encoding="utf8"
             Lang="ta"
             Country="IN"/>
   <language name="telugu"
             Language="telugu"
             GuiName="Telugu"
             PolyglossiaName="telugu"
             Encoding="utf8"
             Lang="te"
             Country="IN"/>
   <language name="thai"
             Language="thai"
             GuiName="Thai"
             BabelName="thai"
             PolyglossiaName="thai"
             QuoteStyle="english"
             Encoding="tis620-0"
             PostBabel="\usepackage{thswitch}"
             Lang="th"
             Country="TH"/>
   <language name="turkmen"
             Language="turkmen"
             GuiName="Turkmen"
             BabelName="turkmen"
             PolyglossiaName="turkmen"
             QuoteStyle="french"
             Encoding="utf8"
             AsBabelOptions="true"
             Lang="tk"
             Country="TM"/>
   <language name="turkish"
             Language="turkish"
             GuiName="Turkish"
             HasGuiSupport="true"
             BabelName="turkish"
             PolyglossiaName="turkish"
             QuoteStyle="french"
             Encoding="iso8859-9"
             PostBabel="\usepackage{xkeyval}"
             Lang="tr"
             Country="TR"/>
   <language name="ukrainian"
             Language="ukrainian"
             GuiName="Ukrainian"
             HasGuiSupport="true"
             BabelName="ukrainian"
             PolyglossiaName="ukrainian"
             QuoteStyle="french"
             Encoding="koi8-u"
             FontEncoding="T2A"
             Lang="uk"
             Country="UA"/>
   <language name="vietnamese"
             Language="vietnamese"
             GuiName="Vietnamese"
             BabelName="vietnamese"
             PolyglossiaName="vietnamese"
             QuoteStyle="french"
             Encoding="utf8"
             Requires="vietnamese"
             Lang="vi"
             Country="VN"/>
   <language name="chinese-simplified"
             Language="chinese-simplified"
             GuiName="Chinese"
             HasGuiSupport="true"
             Encoding="euc-cn"
             QuoteStyle="english"
             Requires="CJK"
             Lang="zh"
             Country="CN"/>
   <language name="chinese-traditional"
             Language="chinese-traditional"
             GuiName="Chinese"
             HasGuiSupport="true"
             QuoteStyle="english"
             Encoding="utf8-cjk"
             Requires="CJK"
             Lang="zh"
             Country="TW"/>
</languages>
%</langsfile>
% \fi
% \subsection{The {\ttfamily{}readme.xml} template file}\label{readmefile}
% This is the boilerplate used to generate the
% {\ttfamily{}README.md} file described in \vref{makereadme}.
% \iffalse
%<*readmefile>
<?xml version="1.0"?>
<!DOCTYPE chapter PUBLIC "+//Silmaril//DTD DocBook 5.0//EN"
  "/dtds/docbook/docbook-5.0/dtd/docbook.dtd" [
<!ENTITY TeX "TeX">
<!ENTITY LaTeX "LaTeX">
<!ENTITY XeLaTeX "XeLaTeX">
<!ENTITY BiBTeX "BibTeX">
<!ENTITY LaTeX3 "LaTeX3">
<!ATTLIST sect1 targetptr CDATA #IMPLIED type CDATA #IMPLIED>
<!ATTLIST anchor targetptr CDATA #IMPLIED type CDATA #IMPLIED>
]>
<chapter xml:id="readme" version="0.04" xml:lang="en:IE"
  revision="2023-05-29" annotations="Copyright © 2012 &LaTeX3; Project">
  <!-- 2016-08-12 title and identity moved to db2dtx -->
  <!-- 2023-05-29 updated wording and PTD -->
  <sect1 targetptr="abstract" type="content">
    <title>Summary</title>
    <anchor targetptr="abstract" type="*" remap="title"/>
  </sect1>
  <sect1>
    <title>Automated installation</title>
    <para>If this <olink targetptr="book" type="arch"/> is distributed
      from <link
	xlink:href="https://ctan.org/pkg/PACKAGE"><acronym>CTAN</acronym></link>, 
      it should be in a zip file which allows it to be installed
      automatically by the &TeX; Live Manager
      (<productname>tlmgr</productname>) and similar automated
      installers. If you are using automated &LaTeX; package
      installation, no further action is required.</para>
    <para>If you are using the &TeX; Live Manager program manually,
      you can install this package with the command:</para>
    <programlisting language="bash" condition="package">
$ tlmgr install <olink targetptr="book" type="xml:id"/>
    </programlisting>
  </sect1>
  <sect1>
    <title>TDS installation</title>
    <para>This <olink targetptr="book" type="arch"/> is also available
      as a <acronym xml:id="TDS">&TeX; Directory System</acronym> zip
      file (<filename>.tds.zip</filename>) from <link
	xlink:href="http://latex.silmaril.ie/packages/PACKAGE">the
	author’s package site</link>. This is the standard directory
      layout for a modern &TeX; installation which enables the <olink
	targetptr="book" type="arch"/> to be unzipped directly into
      your Personal &TeX; Directory without the need to use
      <productname>tlmgr</productname>.</para>
    <para>If you haven’t yet created a Personal &TeX; Directory, see
      <link
	xlink:href="http://latex.silmaril.ie/formattinginformation/">Formatting 
	Information</link> for details of what one is, and how to
      create it.</para>
    <itemizedlist>
      <listitem>
	<para>You can install this <olink targetptr="book"
	    type="arch"/> on any <acronym>TDS</acronym>-compliant
	  personal system (laptop, desktop, workstation, table,
	  smartphone, PDA, etc) by unzipping it straight into your
	  Personal &TeX; Directory. This will put all the files into
	  the right places, so you can start using them
	  immediately.</para>
      </listitem>
      <listitem>
	<para>On a shared (multiuser) system like a server, the
	  administrator can unzip it into the
	  <varname>$TEXMFLOCAL</varname> directory instead, and run
	  your &TeX; directory-indexing program (eg
	  <productname>texhash</productname>,
	  <productname>mktexlsr</productname>, etc) so that everyone
	  can use it.</para>
      </listitem>
      <listitem>
	<para>If you are using an old
	  non-<acronym>TDS</acronym>-compliant system, or an online
	  system with no <acronym>TDS</acronym> access, unzip the
	  files <emphasis>without their directory structure</emphasis>
	  (eg the <option>-j</option> option on
	  the <productname>zip</productname> command)
	  and put them all in your document directory.</para>
      </listitem>
    </itemizedlist>
  </sect1>
  <sect1>
    <title>Usage</title>
    <para>Include the line shown below in the Preamble of your &LaTeX;
      document; a <command>documentclass</command> line should be at
      the top; a <command>usepackage</command> command normally goes
      anywhere in your Preamble:</para>
    <programlisting condition="class" language="LaTeX">
\documentclass[options]{<olink targetptr="book" type="xml:id"/>}
    </programlisting>
    <programlisting condition="package" language="LaTeX">
\usepackage[options]{<olink targetptr="book" type="xml:id"/>}
    </programlisting>
    <para>(similarly for other classes or packages). Read the
      documentation for the options available, if any. The
      documentation is distributed as a <acronym>PDF</acronym>
      document in the zip file. You can also regenerate it by
      typesetting the <filename><olink targetptr="book"
	  type="xml:id"/>.dtx</filename> file with <productname><olink
	  arch="doc" condition="xml:id" targetptr="part"
	  type="conformance"/></productname> (and <productname><olink
	  targetptr="bibliography" type="condition"/></productname> and
      <productname>makeindex</productname>) in the normal way.</para>
  </sect1>
  <sect1 xml:id="bugs">
    <title>Bugs and TODO</title>
    <para>No outstanding reported bugs at the time of this version.</para>
    <para>For TODO items, see the PDF documentation.</para>
  </sect1>
  <sect1 targetptr="copright" type="content">
    <title>Copyright</title>
    <para>The following statement is included in the source code:</para>
    <anchor targetptr="copyright" type="*"/>
  </sect1>
</chapter>
%</readmefile>
% \fi
% \Finale

