summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Master/texmf-dist/doc/latex/l3packages/README98
-rw-r--r--Master/texmf-dist/doc/latex/l3packages/l3keys2e/l3keys2e.pdfbin0 -> 462121 bytes
-rw-r--r--Master/texmf-dist/doc/latex/l3packages/xfrac/xfrac.pdfbin0 -> 612412 bytes
-rw-r--r--Master/texmf-dist/doc/latex/l3packages/xparse/xparse.pdfbin0 -> 395269 bytes
-rw-r--r--Master/texmf-dist/doc/latex/l3packages/xtemplate/xtemplate.pdfbin0 -> 392288 bytes
-rw-r--r--Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e.dtx334
-rw-r--r--Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e.ins40
-rw-r--r--Master/texmf-dist/source/latex/l3packages/xfrac/xfrac.dtx1134
-rw-r--r--Master/texmf-dist/source/latex/l3packages/xfrac/xfrac.ins41
-rw-r--r--Master/texmf-dist/source/latex/l3packages/xparse/xparse.dtx2650
-rw-r--r--Master/texmf-dist/source/latex/l3packages/xparse/xparse.ins40
-rw-r--r--Master/texmf-dist/source/latex/l3packages/xtemplate/xtemplate.dtx2848
-rw-r--r--Master/texmf-dist/source/latex/l3packages/xtemplate/xtemplate.ins40
-rw-r--r--Master/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty156
-rw-r--r--Master/texmf-dist/tex/latex/l3packages/xfrac/xfrac.sty438
-rw-r--r--Master/texmf-dist/tex/latex/l3packages/xparse/xparse.sty1270
-rw-r--r--Master/texmf-dist/tex/latex/l3packages/xtemplate/xtemplate.sty1373
-rwxr-xr-xMaster/tlpkg/bin/tlpkg-ctan-check2
-rw-r--r--Master/tlpkg/tlpsrc/collection-latexrecommended.tlpsrc1
-rw-r--r--Master/tlpkg/tlpsrc/l3packages.tlpsrc0
20 files changed, 10464 insertions, 1 deletions
diff --git a/Master/texmf-dist/doc/latex/l3packages/README b/Master/texmf-dist/doc/latex/l3packages/README
new file mode 100644
index 00000000000..f926499e5d1
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/l3packages/README
@@ -0,0 +1,98 @@
+
+ LaTeX3 High-Level Concepts
+ ==========================
+
+ 2011/06/30
+
+
+WHERE TO GET IT
+---------------
+
+The files in this distribution represent a snapshot of selected files
+from the Subversion (SVN) repository of the LaTeX3 Project.
+
+To obtain current versions of the files, visit
+<http://www.latex-project.org/code.html> which contains further
+instructions.
+
+OVERVIEW
+--------
+
+The l3packages collection is contains implementations for aspects of the
+LaTeX3 kernel, dealing with higher-level ideas such as the Designer
+Interface. The packages here are considered broadly stable (The LaTeX3
+Project does not expect the interfaces to alter radically). These
+packages are build on LaTeX2e conventions at the interface level, and
+so may not migrate in the current form to a stand-alone LaTeX3 format.
+
+All of the material in the collection requires the LaTeX3 base layer
+package [l3kernel](http://ctan.org/pkg/l3kernel). The two packages must
+be installed in matching versions: if you update l3packages, make sure
+that l3kernel is updated at the same time.
+
+Currently included in the CTAN release of l3packages are the following
+bundles:
+ * l3keys2e
+ * xfrac
+ * xparse
+ * xtemplate
+
+l3keys2e
+--------
+
+The l3keys2e package allows keys defined using l3keys to be used
+as package and class options with LaTeX2e. This is tied to the
+method the existing kernel uses for processing options, and so it
+is likely that a stand-alone LaTeX3 kernel will use a very different
+approach.
+
+xfrac
+-----
+
+The xfrac package uses the interface defined by xtemplate to provide
+flexible split-level fractions _via_ the `\sfrac` macro. This is both a
+demonstration of the power of the template concept and also a useful
+addition to the available functionality in LaTeX2e.
+
+xparse
+-----
+
+The xparse package provides a high-level interface for declaring
+document commands, e.g., a uniform way to define commands taking
+optional arguments, optional stars (and others), mandatory arguments
+and more.
+
+xtemplate
+-----
+
+The xtemplate package provides an interface for defining generic
+functions using a key=val syntax. This is designed to be
+"self-documenting", with the key definitions providing information
+on how they are to be used.
+
+DISCUSSION
+----------
+
+Discussion concerning the approach, suggestions for improvements,
+changes, additions, etc. should be addressed to the list LaTeX-L.
+
+You can subscribe to this list by sending mail to
+
+ listserv@urz.uni-heidelberg.de
+
+with the body containing
+
+ subscribe LATEX-L <Your-First-Name> <Your-Second-Name>
+
+BUGS
+----
+
+The issue tracker for LaTeX3 bugs is currently located at
+
+ https://github.com/latex3/svn-mirror/issues
+
+Please report specific issues with LaTeX3 code there. More general
+discussion should be directed to the LaTeX-L lists.
+
+--- Copyright 1998 -- 2011
+ The LaTeX3 Project. All rights reserved ---
diff --git a/Master/texmf-dist/doc/latex/l3packages/l3keys2e/l3keys2e.pdf b/Master/texmf-dist/doc/latex/l3packages/l3keys2e/l3keys2e.pdf
new file mode 100644
index 00000000000..e9aab325c68
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/l3packages/l3keys2e/l3keys2e.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/l3packages/xfrac/xfrac.pdf b/Master/texmf-dist/doc/latex/l3packages/xfrac/xfrac.pdf
new file mode 100644
index 00000000000..433d5bff3e3
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/l3packages/xfrac/xfrac.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/l3packages/xparse/xparse.pdf b/Master/texmf-dist/doc/latex/l3packages/xparse/xparse.pdf
new file mode 100644
index 00000000000..e337ec061a8
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/l3packages/xparse/xparse.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/l3packages/xtemplate/xtemplate.pdf b/Master/texmf-dist/doc/latex/l3packages/xtemplate/xtemplate.pdf
new file mode 100644
index 00000000000..39a772965c1
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/l3packages/xtemplate/xtemplate.pdf
Binary files differ
diff --git a/Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e.dtx b/Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e.dtx
new file mode 100644
index 00000000000..4d1930a05e7
--- /dev/null
+++ b/Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e.dtx
@@ -0,0 +1,334 @@
+% \iffalse meta-comment
+%
+%% File: l3keys2e.dtx (C) Copyright 2009,2011 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3packages bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+%
+%<*driver|package>
+\RequirePackage{xparse}
+\GetIdInfo$Id: l3keys2e.dtx 2492 2011-07-02 13:40:38Z joseph $
+ {LaTeX2e option processing using LaTeX3 keys}
+%</driver|package>
+%<*driver>
+\documentclass[full]{l3doc}
+\usepackage{amstext}
+\begin{document}
+ \DocInput{\jobname.dtx}
+\end{document}
+%</driver>
+% \fi
+%
+% \title{^^A
+% The \textsf{l3keys2e} package\\
+% \LaTeXe{} option processing using \LaTeX3 keys^^A
+% \thanks{This file describes v\ExplFileVersion,
+% last revised \ExplFileDate.}^^A
+% }
+%
+% \author{^^A
+% The \LaTeX3 Project\thanks
+% {^^A
+% E-mail:
+% \href{mailto:latex-team@latex-project.org}
+% {latex-team@latex-project.org}^^A
+% }^^A
+% }
+%
+% \date{Released \ExplFileDate}
+%
+% \maketitle
+%
+% \begin{documentation}
+%
+% The key--value method for optional arguments is very popular, as it
+% allows the class or package author to define a large number of
+% options with a simple interface. The \pkg{expl3} bundle of \LaTeX3
+% base code includes the module \pkg{l3keys} for defining keys, but
+% to use these when loading \LaTeXe\ packages and classes requires
+% extra support. That support is provided by this small package, which
+% is intended to enable \LaTeXe\ packages to benefit from the power of
+% the \LaTeX3 key--value system.
+%
+% \subsection{Creating and using keyval options}
+%
+% As with any key--value input, using key--value pairs as package or
+% class options has two parts. The first stage is to define one or
+% more keys, using the \cs{keys_define:nn} function. For example, an
+% option which simply stores a value would be created using:
+% \begin{verbatim}
+% \keys_define:nn { module }
+% { option .set:N = \l_module_variable_tl }
+% \end{verbatim}
+% On its own, this will not make the key an option for the package or
+% class containing the definition. The second stage is therefore to
+% process the current options, searching for applicable keys.
+%
+% \begin{function}{\ProcessKeysOptions}
+% \begin{syntax}
+% \cs{ProcessKeysOptions} \Arg{module}
+% \end{syntax}
+% The \cs{ProcessKeysOptions} function is used to check the current
+% option list against the keys defined for \Arg{module}. Global (class)
+% options and local (package) options are checked when this function
+% is called in a package. Each option which does match a key name is
+% then used to attempt to set the appropriate key using
+% \cs{keys_set:nn}. For example, the option defined earlier would be
+% processed by the line
+% \begin{verbatim}
+% \ProcessKeysOptions { module }
+% \end{verbatim}
+% \end{function}
+%
+% \begin{function}{\ProcessKeysPackageOptions}
+% \begin{syntax}
+% \cs{ProcessKeysPackageOptions} \Arg{module}
+% \end{syntax}
+% This function works in a similar manner to \cs{ProcessKeysOptions}.
+% When used in a \LaTeXe{} package, \cs{ProcessKeysPackageOptions}
+% will not examine any class options available. In contrast,
+% \cs{ProcessKeysOptions} does parse class options (in common with the
+% \LaTeXe{} kernel function \cs{ProcessOptions}).
+% \end{function}
+%
+%\end{documentation}
+%
+%\begin{implementation}
+%
+%\subsection{\pkg{l3keys2e} Implementation}
+%
+% \begin{macrocode}
+%<*package>
+% \end{macrocode}
+%
+% \begin{macrocode}
+\ProvidesExplPackage
+ {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+% \end{macrocode}
+%
+% A check to make sure that \pkg{expl3} is not too old
+% \begin{macrocode}
+\@ifpackagelater { l3token } { 2011/07/02 }
+ { }
+ {
+ \PackageError { l3keys2e } { Support~package~l3kernel~too~old. }
+ {
+ Please~install~an~up~to~date~version~of~l3kernel~
+ using~your~TeX~package~manager~or~from~CTAN.\\ \\
+ Loading~l3keys2e~will~abort!
+ }
+ \tex_endinput:D
+ }
+% \end{macrocode}
+%
+% \begin{macro}{\keys_latexe_options_clist}
+% A single list is used for all options, into which they are collected
+% before processing.
+% \begin{macrocode}
+\clist_new:N \keys_latexe_options_clist
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\_l_keys_process_class_bool}
+% A flag to indicate that class options should be processed for
+% packages.
+% \begin{macrocode}
+\bool_new:N \_l_keys_process_class_bool
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\keys_latexe_options:n}
+% The main function calls functions to collect up the global and local
+% options into \cs{keys_latexe_options_clist} before calling the
+% underlying functions to actually do the processing. So that a suitable
+% message is produced if the option is unknown, the special
+% \texttt{unknown} key is set if it does not already exist for the
+% current module.
+% \begin{macrocode}
+\cs_new_protected:Npn \keys_latexe_options:n #1
+ {
+ \clist_clear:N \keys_latexe_options_clist
+ \keys_latexe_options_global:n {#1}
+ \keys_latexe_options_local:
+ \keys_if_exist:nnF {#1} { unknown }
+ {
+ \keys_define:nn {#1}
+ {
+ unknown .code:n =
+ {
+ \msg_error:nnxx { keyvalue } { option-unknown }
+ { \l_keys_key_tl } { \@currname }
+ }
+ }
+ }
+ \keys_set:nV {#1} \keys_latexe_options_clist
+ \AtEndOfPackage { \cs_set_eq:NN \@unprocessedoptions \scan_stop: }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\keys_latexe_options_global:n}
+% Global (class) options are handled differently for \LaTeXe{} packages
+% and classes. Hence this function is essentially a check on the current
+% file type. The initial test is needed as \LaTeXe{} allows variables to
+% be equal to \cs{scan_stop:}, which is forbidden in \LaTeX3 code.
+% \begin{macrocode}
+\cs_new_protected:Npn \keys_latexe_options_global:n #1
+ {
+ \cs_if_eq:NNF \@classoptionslist \scan_stop:
+ {
+ \cs_if_eq:NNTF \@currext \@clsextension
+ { \keys_latexe_options_class:n {#1} }
+ {
+ \bool_if:NT \_l_keys_process_class_bool
+ { \keys_latexe_options_package:n {#1} }
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\keys_latexe_options_class:n}
+% For classes, each option (stripped of any content after |=|)
+% is checked for existence as a key. If found, the option is added to
+% the combined list for processing. On the other hand, unused options
+% are stored up in \cs{@unusedoptionlist}. Before any of that, though,
+% there is a simple check to see if there is an |unknown| key. If there
+% is, then \emph{everything} will match and the mapping can be skipped.
+% \begin{macrocode}
+\cs_new_protected:Npn \keys_latexe_options_class:n #1
+ {
+ \keys_if_exist:nnTF {#1} { unknown }
+ { \clist_put_right:No \keys_latexe_options_clist \@classoptionslist }
+ {
+ \clist_map_inline:Nn \@classoptionslist
+ {
+ \keys_if_exist:nnTF {#1} { \keys_latexe_remove_equals:n {##1} }
+ { \clist_put_right:Nn \keys_latexe_options_clist {##1} }
+ { \clist_put_right:Nn \@unusedoptionlist {##1} }
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\keys_latexe_options_package:n}
+% For global options when processing a package, the tasks are slightly
+% different from those for a class. The check is the same, but here
+% there is nothing to do if the option is not applicable. Each valid
+% option also needs to be removed from \cs{@unusedoptionlist}.
+% \begin{macrocode}
+\cs_new_protected:Npn \keys_latexe_options_package:n #1
+ {
+ \clist_map_inline:Nn \@classoptionslist
+ {
+ \keys_if_exist:nnT {#1} { \keys_latexe_remove_equals:n {##1} }
+ {
+ \clist_put_right:Nn \keys_latexe_options_clist {##1}
+ \clist_remove_element:Nn \@unusedoptionlist {##1}
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\keys_latexe_options_local:}
+% If local options are found, the are added to the processing list.
+% \LaTeXe{} stores options for each file in a macro which may or may not
+% exist, hence the need to use \cs{cs_if_exist:c}.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \keys_latexe_options_local:
+ {
+ \cs_if_eq:NNF \@currext \@clsextension
+ {
+ \cs_if_exist:cT { opt@ \@currname . \@currext }
+ {
+ \exp_args:NNc \clist_put_right:NV \keys_latexe_options_clist
+ { opt@ \@currname . \@currext }
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\keys_latexe_remove_equals:n}
+% \begin{macro}{\keys_latexe_remove_equals:w}
+% As the name suggests, this is a simple function to remove an equals
+% sign from the input. This is all wrapped up in an \texttt{n} function
+% so that there will always be a sign available.
+% \begin{macrocode}
+\cs_new:Npn \keys_latexe_remove_equals:n #1
+ { \keys_latexe_remove_equals:w #1 = \q_stop }
+\cs_new:Npn \keys_latexe_remove_equals:w #1 = #2 \q_stop {#1}
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\ProcessKeysOptions}
+% \begin{macro}{\ProcessKeysOptions}
+% The user macro are simply wrappers around the internal process. In
+% contrast to other similar packages, the module name is always required
+% here.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \ProcessKeysOptions #1
+ {
+ \bool_set_true:N \_l_keys_process_class_bool
+ \keys_latexe_options:n {#1}
+ }
+\cs_new_protected_nopar:Npn \ProcessKeysPackageOptions #1
+ {
+ \bool_set_false:N \_l_keys_process_class_bool
+ \keys_latexe_options:n {#1}
+ }
+\@onlypreamble \ProcessKeysOptions
+\@onlypreamble \ProcessKeysPackageOptions
+% \end{macrocode}
+%\end{macro}
+%\end{macro}
+%
+% One message to give.
+% \begin{macrocode}
+\msg_new:nnnn { keyvalue } { option-unknown }
+ { Unknown~option~'#1'~for~package~#2. }
+ {
+ LaTeX~has~been~asked~to~set~an~option~called~'#1'~
+ but~the~#2~package~has~not~created~an~option~with~this~name.
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+%</package>
+% \end{macrocode}
+%
+% \end{implementation}
+%
+% \PrintIndex
diff --git a/Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e.ins b/Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e.ins
new file mode 100644
index 00000000000..fa9b799b037
--- /dev/null
+++ b/Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e.ins
@@ -0,0 +1,40 @@
+\iffalse meta-comment
+
+File xparse.ins Copyright (C) 2009,2011 The LaTeX3 Project
+
+It may be distributed and/or modified under the conditions of the
+LaTeX Project Public License (LPPL), either version 1.3c of this
+license or (at your option) any later version. The latest version
+of this license is in the file
+
+ http://www.latex-project.org/lppl.txt
+
+This file is part of the "xpackage bundle" (The Work in LPPL)
+and all files in that bundle must be distributed together.
+
+The released version of this bundle is available from CTAN.
+
+\fi
+
+\input docstrip.tex
+\askforoverwritefalse
+
+\preamble
+
+EXPERIMENTAL CODE
+
+Do not distribute this file without also distributing the
+source files specified above.
+
+Do not distribute a modified version of this file.
+
+\endpreamble
+% stop docstrip adding \endinput
+\postamble
+\endpostamble
+
+\keepsilent
+
+\generate{\file{l3keys2e.sty} {\from{l3keys2e.dtx} {package}}}
+
+\endbatchfile
diff --git a/Master/texmf-dist/source/latex/l3packages/xfrac/xfrac.dtx b/Master/texmf-dist/source/latex/l3packages/xfrac/xfrac.dtx
new file mode 100644
index 00000000000..371372fce44
--- /dev/null
+++ b/Master/texmf-dist/source/latex/l3packages/xfrac/xfrac.dtx
@@ -0,0 +1,1134 @@
+% \iffalse meta-comment
+%
+%% File: xfrac.dtx Copyright (C) 2004, 2008-2010 Morten Hoegholm
+%% (C) 2011 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3packages bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+%
+%<*driver|package>
+\RequirePackage{amstext,graphicx,l3keys2e,textcomp,xparse,xtemplate}
+\GetIdInfo$Id: xfrac.dtx 2349 2011-05-11 18:44:37Z joseph $
+ {L3 Experimental split-level fractions}
+%</driver|package>
+%<*driver>
+\documentclass[full]{l3doc}
+\usepackage{nicefrac,xfrac} ^^A Need nicefrac for demo purposes
+\providecommand*\key[1]{\textbf{#1}}
+\newcommand*\switch[2]{{\fontfamily{#1}\selectfont #2}}
+\begin{document}
+ \DocInput{\jobname.dtx}
+\end{document}
+%</driver>
+% \fi
+%
+% \title{^^A
+% The \textsf{xfrac} package\\ Split-level fractions^^A
+% \thanks{This file describes v\ExplFileVersion,
+% last revised \ExplFileDate.}^^A
+% }
+%
+% \author{^^A
+% The \LaTeX3 Project\thanks
+% {^^A
+% E-mail:
+% \href{mailto:latex-team@latex-project.org}
+% {latex-team@latex-project.org}^^A
+% }^^A
+% }
+%
+% \date{Released \ExplFileDate}
+%
+% \maketitle
+%
+% \begin{documentation}
+%
+% The \pkg{xfrac} package defines a document command \cs{sfrac}
+% with the following syntax:
+% \begin{quote}
+% \cs{sfrac}\oarg{instance}\marg{num}\oarg{sep}\marg{denom}
+% \end{quote}
+% Let's show a few examples:
+% \begin{verbatim}
+% \sfrac{1}{2}, $\sfrac{1}{2}$,
+% $\mathbf{3\times\sfrac{1}{2}}$
+% \quad \fontfamily{ppl}\selectfont Palatino: \sfrac{1}{2}
+% \quad \fontfamily{ptm}\selectfont Times: \sfrac{1}{2}
+% \end{verbatim}
+% \begin{quote}
+% \sfrac{1}{2}, $\sfrac{1}{2}$, $\mathbf{3\times\sfrac{1}{2}}$
+% \quad \fontfamily{ppl}\selectfont Palatino: \sfrac{1}{2}
+% \quad \fontfamily{ptm}\selectfont Times: \sfrac{1}{2}
+% \end{quote}
+% You'll notice something interesting: not only does the \cs{sfrac}
+% command work as it should in math mode, it also gets the job done
+% for other fonts as well.
+%
+% \section{A Bit of History}
+%
+% \subsection{The Past}
+%
+% One of the first exercises in \emph{The \TeX{}Book} is to design a
+% macro for split level fractions. The solution presented is fairly
+% simple, using a \emph{virgule} (a slash) for separating the two
+% components. It looks okay because the text font and math font of
+% Computer Modern look almost identical.
+%
+% The proper symbol to use instead of the virgule is a \emph{solidus}
+% which does not exist in Computer Modern. It is however available in
+% the European Computer Modern fonts, but I'll get back to that.
+%
+% \subsection{The Present}
+%
+% The most common way to produce split level fractions within \LaTeXe{}
+% is by means of the \pkg{nicefrac} package. Part of the reason it
+% has found widespread use is due to the strange design of the
+% built-in text fractions of the EC fonts, which look like this:
+% \textonehalf{}. The package is very simple to use but there are a few
+% issues:
+% \begin{itemize}
+% \item It uses the virgule instead of the solidus.
+% \item Font size of numerator and denominator is bigger than in the
+% built-in symbol. Compare Palatino: \switch{ppl}{\nicefrac{1}{2}}
+% \emph{vs.}~\switch{ppl}{\textonehalf}.
+% \item It doesn't correct for fonts using text figures such as in the
+% \pkg{eco} package. Compare \switch{cmor}{\nicefrac{1}{2}} and
+% \switch{cmor}{\nicefrac{8}{9}}.
+% \item In math mode, it doesn't always pick up the correct math
+% alphabet.
+% \end{itemize}
+% In short: \pkg{nicefrac} doesn't attempt to be the answer to
+% everything and so this is not a criticism of the package. It works
+% quite well for Computer Modern which was pretty much what was widely
+% available at the time it was developed. Users these days, however,
+% have a choice of many fonts when they write their documents.
+%
+% \subsection{The Future}
+%
+% Fonts are wildly different; one macro that works fine for Computer
+% Modern obviously doesn't work well at all in Palatino. For one we
+% have to make the separator symbol configurable, and we need to
+% take care of several details as well: font scaling of the
+% numerator/denominator pair (ND), font selection of ND, \emph{etc.} If we
+% are to have a single package for this in the future we have to define a
+% totally generic interface for the fraction commands and then adjust
+% parameters depending on the current font. What you see in this
+% prototype implementation of \pkg{xfrac} is just that.
+%
+% \section{Advanced User Interface}
+%
+% \subsection{Text mode}
+%
+% The usual problem in text mode has a name: Computer Modern. The
+% solidi of all the Computer Modern fonts leave a lot to be desired,
+% although things are potentially looking better as the Latin Modern
+% fonts are becoming more stable and widespread. As long as the
+% default fonts are Computer Modern variants we must however work
+% around this. One idea that comes to mind is to see what happens
+% when you use a solidus from another font instead. Let's try with
+% Times:
+% \begin{quote}
+% \DeclareInstance{xfrac}{cmr2}{text}
+% {slash-symbol-font = ptm}
+% \enquote{You take \sfrac[cmr2]{1}{2} cup of sugar, \ldots}
+% \end{quote}
+% That looks quite good actually, so it was probably very difficult
+% to obtain that result. Nope, it was extremely easy---if you happen
+% to know about \emph{instances}:
+% \begin{verbatim}
+% \DeclareInstance{xfrac}{cmr}{text}
+% {slash-symbol-font = ptm}
+% \end{verbatim}
+% So we define an instance with the name |cmr| from the template
+% |text| which in turn is of object type |xfrac|. You'll notice
+% the |cmr| is also the name of the font family for Computer Modern
+% Roman and the reasoning behind is that every font family should
+% have it's own settings, and if a document command is to work well
+% in that scheme, letting it use the name of the current font family
+% seems like a good idea. Thus the \cs{sfrac} command checks to see
+% whether an instance with same name as the current font family
+% exists and uses it if the test is true; otherwise the default
+% setting is used. Here we defined the instance to be used for the
+% font family |cmr| and just told it to use the Times font for
+% typesetting the slash symbol which turns out to be a solidus by
+% default.
+%
+% The option \texttt{cm-recommended} which is loaded by default uses
+% the Times solidus for Computer Modern Roman and Computer Modern
+% Sans Serif and the Palatino solidus for Computer Modern Typewriter
+% Type. This looks quite good. Should you however not want this you
+% can use the option \texttt{cm-standard} which produces somewhat
+% acceptable results using Computer Modern exclusively.
+%
+% So what about old style figures? If you use the \pkg{eco}
+% package you might define an instance similar to this (`cmor' is
+% the name of the roman font activated by \pkg{eco}):
+% \DeclareInstance{xfrac}{cmor}{text}
+% {
+% slash-symbol-font = ptm,
+% numerator-font = cmr,
+% denominator-font = cmr
+% }
+% \begin{verbatim}
+% \DeclareInstance{xfrac}{cmor}{text}
+% {
+% slash-symbol-font = ptm,
+% numerator-font = cmr,
+% denominator-font = cmr
+% }
+% \end{verbatim}
+% We also use regular Computer Modern Roman for typesetting ND, so
+% we end up with \switch{cmor}{\sfrac{1}{2}} and
+% \switch{cmor}{\sfrac{8}{9}} instead of
+% \switch{cmor}{\nicefrac{1}{2}} and \switch{cmor}{\nicefrac{8}{9}}.
+% Much better.
+%
+% There are also situations where other tricks are useful. If you
+% don't have the inferior and superior figures available in a font,
+% or the font doesn't have a wider design for small font sizes, you
+% can cheat by manually scaling the ND-pair. I got nice results for
+% Adobe's Stempel Garamond (with small caps and old style figures)
+% with the following setup:
+% \begin{verbatim}
+% \DeclareInstance{xfrac}{pegj}{text}
+% {
+% numerator-font = pegx,
+% denominator-font = pegx,
+% scale-factor = 0.9,
+% h-scale = 1.1
+% }
+% \end{verbatim}
+% We use the font family |pegx| (Stempel Garamond with real small
+% caps) for typesetting the ND-pair. Additionally the key
+% \key{scale-factor} specifies that the font size used for the
+% ND-pair should be $0.9$ of the height of the solidus, and the key
+% \key{h-scale} specifies that the ND-pair should be scaled an extra
+% 10\,\% horizontally.
+%
+% Should you be so fortunate the have a font with inferior and
+% superior figures like in the Monotype Janson example from Philipp
+% Lehman's excellent \emph{The Font Installation Guide}. In that
+% example Philipp defines the font families |mjn0| for the inferior
+% figures and |mjn1| for the superior. Thus to get the \cs{sfrac}
+% command to use them on the fly for the font family |mjnj| (Janson,
+% old style figures) we would say
+% \begin{verbatim}
+% \DeclareInstance{xfrac}{mjnj}{text}
+% {
+% numerator-font = mjn1,
+% denominator-font = mjn0,
+% scaling = false,
+% numerator-bot-sep = 0 pt,
+% denominator-bot-sep = 0 pt
+% }
+% \end{verbatim}
+% I think this example is a very clean way to do it. An alternative
+% approach could be to use the keys \key{numerator-format} and
+% \key{denominator-format} to process the arguments and let them
+% determine what to do.
+%
+% \subsection{Math Mode}
+%
+% In math mode the choices are a lot fewer because first of all
+% \TeX{} comes with a built-in limitation of $16$ math families.
+% Additionally we will not need a solidus for typesetting split
+% fractions in math, as tradition is to use a virgule instead. We
+% define the basic |mathdefault| instance to simply use the math
+% family in use when the instance is run. So if we're in normal math
+% like |$\sfrac{7}{9}$| we simply get family~$-1$. If we're inside a
+% \cs{mathbf} we're in family~$4$ (in the standard setup at least),
+% and so the fraction is typeset with the same math family. Simple,
+% isn't?
+%
+% You can also declare instances for the math families, but I really
+% don't see why you would. If you do then name them according to the
+% scheme \texttt{mathfam\meta{N}}, where \meta{N} is the family number, and
+% only do it if you \emph{really} know how to set up math fonts.
+% That is, if \cs{DeclareMathAlphabet} is unbeknownst to you, then
+% just don't go there.
+%
+% Another example: If we want \cs{sfrac} to produce split fractions
+% without doing anything at all, we can choose the collection
+% |plainmath|, which is defined as
+% \begin{verbatim}
+% \DeclareCollectionInstance{plainmath}{xfrac}{mathdefault}{math}
+% {
+% denominator-bot-sep = 0 pt,
+% numerator-bot-sep = 0 pt,
+% numerator-top-sep = \c_max_dim,
+% scaling = false,
+% slash-right-mkern = 0 mu,
+% slash-left-mkern = 0 mu
+% }
+% \end{verbatim}
+% This creates an alternative version of the instance |mathdefault|
+% with settings as specified by the keys. In the default math setup
+% \key{numerator-top-sep} is set to 0~pt, and here we set
+% \key{numerator-bot-sep} to 0~pt as well, so in order to avoid
+% over-specification (and an error message) we must set
+% \key{numerator-top-sep} to \cs{c_max_dim}. We activate (obeying
+% normal scoping rules) it with:
+% \begin{verbatim}
+% \UseCollection{xfrac}{plainmath}
+% \end{verbatim}
+% Then |$\sfrac{8}{13}$| produces^^A
+% \begingroup
+% \UseCollection{xfrac}{plainmath}
+% $\sfrac{8}{13}$ and just typing |$8/13$| gives the same result:
+% $8/13$.
+% \endgroup
+%
+% \section{The Template Interface}
+%
+% \begin{TemplateInterfaceDescription}{xfrac}
+%
+% \TemplateArgument{1}{The numerator}
+%
+% \TemplateArgument{2}{The separator}
+%
+% \TemplateArgument{3}{The denominator}
+%
+% \TemplateSemantics
+%
+% Typesets arguments 1 and 3 separated by argument 2, which in text
+% mode by default is a \emph{solidus}. This is taken from
+% \pkg{textcomp} where it is denoted \cs{textfractionsolidus}.
+% This is the character used for the ready made split level
+% fractions such as \textonehalf{}---except in the (European) Computer
+% Modern fonts. In math mode a \emph{virgule} is used instead as
+% this is more appropriate and it is always available in the math
+% fonts. The solidus is a text symbol only.
+%
+% \end{TemplateInterfaceDescription}
+%
+% \begin{TemplateDescription}{xfrac}{text}
+%
+% \TemplateKey{numerator-font}{tokenlist}
+% {Font family specification to use for the numerator.}
+% {\cs{f@family}}
+%
+% \TemplateKey{numerator-format}{function 1 arg}
+% {Action to be taken on the numerator.}
+% {Process argument unchanged}
+%
+% \TemplateKey{slash-symbol}{tokenlist}
+% {The separator symbol. If not specified the default value will be
+% used instead.}
+% {Solidus (\cs{textfractionsolidus})}
+%
+% \TemplateKey{slash-symbol-font}{tokenlist}
+% {Font family specification to use for the separator symbol.}
+% {\cs{f@family}}
+%
+% \TemplateKey{slash-symbol-format}{function 1 arg}
+% {Action to be taken on the separator symbol.}
+% {Process argument unchanged}
+%
+% \TemplateKey{denominator-font}{tokenlist}
+% {Font family specification to use for the denominator.}
+% {\cs{f@family}}
+%
+% \TemplateKey{denominator-format}{function 1 arg}
+% {Action to be taken on the denominator.}
+% {Process argument unchanged}
+%
+% \TemplateKey{h-scale}{real}
+% {Factor by which the numerator and denominator should be
+% horizontally scaled. It should only be used if the real superior
+% and inferior fonts are not available. For instance Stempel
+% Garamond looks excellent if scaled 10\,\% extra horizontally, \emph{i.e.},
+% by a factor of 1.1.}
+% {1}
+%
+% \TemplateKey{v-scale}{real}
+% {Same as \key{h-scale} only vertically. Probably not of much use
+% but added for completeness.}
+% {1}
+%
+% \TemplateKey{scale-factor}{real}
+% {Fraction of the size of \key{slash-symbol}. Used for setting the
+% font size of numerator and denominator. Usually a value of app.\
+% \sfrac{5}{6} produces fine results. It should only be used if the
+% real superior and inferior fonts are not available. As an example
+% Stempel Garamond looks better if the factor is 0.9.}
+% {0.83333}
+%
+% \TemplateKey{scale-relative}{choice}
+% {If set to |true| the font size of the numerator and denominator
+% is scaled with respect to the height of the \key{slash-symbol}. If
+% set to |false| the font is scaled with respect to the total height
+% of the \key{slash-symbol}.}
+% {true}
+%
+% \TemplateKey{scaling}{choice}
+% {If set to |true| the fonts are allowed to scale. If set to
+% |false| they are not. See the `Janson' example for an application.}
+% {true}
+%
+% \TemplateKey{numerator-top-sep}{length}
+% {Dimension specifying the space between the top of the
+% \key{slash-symbol} and the top of the numerator. If not specified,
+% the depth of the solidus will be used, because this value will
+% make the fraction look even.}
+% {Unspecified}
+%
+% \TemplateKey{numerator-bot-sep}{length}
+% {Dimension specifying the lift of the numerator from the
+% baseline.}
+% {Unspecified}
+%
+% \TemplateKey{denominator-bot-sep}{length}
+% {Dimension specifying the lift of the denominator from the
+% baseline.}
+% {Unspecified}
+%
+% \TemplateKey{slash-right-kern}{length}
+% {Dimension specifying the kerning between the \key{slash-symbol}
+% and the numerator.}
+% {\texttt{0pt}}
+%
+% \TemplateKey{slash-left-kern}{length}
+% {Dimension specifying the kerning between the \key{slash-symbol}
+% and the denominator.}
+% {\texttt{0pt}}
+%
+% \TemplateKey{math-mode}{choice}
+% {Are we in math mode or not?}
+% {false}
+%
+% \TemplateKey{phantom}{tokenlist}
+% {A character that suits the common cases. As we would mostly want
+% to use numbers in text mode we choose a \enquote{tall} number, while in
+% math it is somewhat different.}
+% {8}
+%
+% \TemplateSemantics
+%
+% This template is also the foundation for the \enquote{math} template. The
+% keys \key{slash-right-mkern} and \key{slash-left-mkern} can only
+% be used in math mode and are not shown here.
+%
+% \end{TemplateDescription}
+%
+% \begin{TemplateDescription}{xfrac}{math}
+%
+% \TemplateKey{numerator-font}{tokenlist}
+% {Font family specification to use for the numerator.}
+% {\cs{number}\cs{fam}}
+%
+% \TemplateKey{slash-symbol}{tokenlist}
+% {The separator symbol. If not specified the default value will be
+% used instead.}
+% {Virgule ($/$)}
+%
+% \TemplateKey{slash-symbol-font}{tokenlist}
+% {Font family specification to use for the separator symbol.}
+% {\cs{number}\cs{fam}}
+%
+% \TemplateKey{denominator-font}{tokenlist}
+% {Font family specification to use for the denominator.}
+% {\cs{number}\cs{fam}}
+%
+% \TemplateKey{scale-factor}{real}
+% {Fraction of the size of \key{slash-symbol}. In math mode we
+% cannot rely on the fonts to be able to scale, but giving a default
+% scale of 0.7 fits into the regular size changing scheme---the
+% default scheme has values $(D,T,S,SS)=(1,1,0.7,0.5)$ whereas we
+% with a default \key{scale-factor} of 0.7 get $(1,1,0.7,0.49)$.
+% That's close enough.}
+% {0.7}
+%
+% \TemplateKey{scale-relative}{choice}
+% {If set to |true| the font size of the numerator and denominator
+% is scaled with respect to the height of the \key{slash-symbol}. If
+% set to |false| the font is scaled with respect to the total height
+% of the \key{slash-symbol}.}
+% {false}
+%
+% \TemplateKey{scaling}{choice}
+% {If set to |true| the fonts are allowed to scale. If set to
+% |false| they are not. See the |plainmath| example for an application.}
+% {true}
+%
+% \TemplateKey{numerator-top-sep}{length}
+% {Dimension specifying the space between the top of the
+% \key{slash-symbol} and the top of the numerator. If not specified,
+% the depth of the virgule will be used, because this value will
+% make the fraction look even.}
+% {\texttt{0pt}}
+%
+% \TemplateKey{denominator-bot-sep}{length}
+% {Dimension specifying the lift of the denominator from the
+% baseline.}
+% {\texttt{0pt}}
+%
+% \TemplateKey{slash-right-mkern}{muskip}
+% {Same as \key{slash-right-kern} but for math mode only and should
+% be specified in \texttt{mu} units.}
+% {\texttt{-2mu}}
+%
+% \TemplateKey{slash-left-mkern}{muskip}
+% {Same as \key{slash-left-kern} but for math mode only and should
+% be specified in \texttt{mu} units.}
+% {\texttt{-1mu}}
+%
+% \TemplateKey{math-mode}{choice}
+% {Are we in math mode or not?}
+% {true}
+%
+% \TemplateKey{phantom}{tokenlist}
+% {A character that suits the common cases. In math we have a high
+% risk of using a parenthesis, so we choose that. Text mode is
+% another story.}
+% {(^^A)
+% }
+%
+% \TemplateSemantics
+%
+% This template is a restricted version of the |text| template. Only
+% the keys that are different from the |text| template are shown
+% here. Also bear in mind that the attributes \key{slash-left-kern}
+% and \key{slash-right-kern} have no meaning in this template.
+%
+% \end{TemplateDescription}
+%
+% \end{documentation}
+%
+% \begin{implementation}
+%
+% \section{\pkg{xfrac} Implementation}
+%
+% \begin{macrocode}
+%<*package>
+% \end{macrocode}
+%
+% \begin{macrocode}
+\ProvidesExplPackage
+ {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+% \end{macrocode}
+%
+% \begin{variable}{\l_xfrac_cm_std_bool}
+% There is one option to support.
+% \begin{macrocode}
+\keys_define:nn { xfrac }
+ {
+ cm-recommended .choice:,
+ cm-recommended /
+ false .code:n =
+ { \bool_set_true:N \l_xfrac_cm_std_bool },
+ cm-recommended /
+ true .code:n =
+ { \bool_set_false:N \l_xfrac_cm_std_bool },
+ cm-recommended .default:n = { true },
+ cm-standard .bool_set:N = \l_xfrac_cm_std_bool
+ }
+\ProcessKeysOptions { xfrac }
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xfrac_slash_box}
+% \begin{variable}{\l_xfrac_tmp_box}
+% In keeping with the \LaTeX3 philosophy, rather than use generic
+% scratch boxes and get confused, \pkg{xfrac} reserves its own named
+% working space.
+% \begin{macrocode}
+\box_new:N \l_xfrac_slash_box
+\box_new:N \l_xfrac_tmp_box
+% \end{macrocode}
+% \end{variable}
+% \end{variable}
+%
+% \begin{macro}[aux]{\xfrac_tmp:w}
+% Used for the raised boxes: weird as it does not take an argument
+% but the \cs{raisebox} does.
+% \begin{macrocode}
+\cs_new:Npn \xfrac_tmp:w { }
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \subsection{Initialisation of variables}
+%
+% Variables used in templates have to be set up: there is not
+% much to say about these, other than that they must exist.
+%
+% \begin{variable}{\l_xfrac_denominator_bot_sep_dim}
+% \begin{variable}{\l_xfrac_numerator_bot_sep_dim}
+% \begin{variable}{\l_xfrac_numerator_top_sep_dim}
+% \begin{variable}{\l_xfrac_slash_left_sep_dim}
+% \begin{variable}{\l_xfrac_slash_right_sep_dim}
+% Fixed lengths.
+% \begin{macrocode}
+\dim_new:N \l_xfrac_denominator_bot_sep_dim
+\dim_new:N \l_xfrac_numerator_bot_sep_dim
+\dim_new:N \l_xfrac_numerator_top_sep_dim
+\dim_new:N \l_xfrac_slash_left_sep_dim
+\dim_new:N \l_xfrac_slash_right_sep_dim
+% \end{macrocode}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+%
+% \begin{variable}{\l_xfrac_slash_left_muskip}
+% \begin{variable}{\l_xfrac_slash_right_muskip}
+% Math mode skips.
+% \begin{macrocode}
+\muskip_new:N \l_xfrac_slash_left_muskip
+\muskip_new:N \l_xfrac_slash_right_muskip
+% \end{macrocode}
+% \end{variable}
+% \end{variable}
+%
+% \begin{variable}{\l_xfrac_hscale_fp}
+% \begin{variable}{\l_xfrac_scale_factor_fp}
+% \begin{variable}{\l_xfrac_vscale_fp}
+% Floating point values.
+% \begin{macrocode}
+\fp_new:N \l_xfrac_hscale_fp
+\fp_new:N \l_xfrac_scale_factor_fp
+\fp_new:N \l_xfrac_vscale_fp
+% \end{macrocode}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+%
+% \begin{variable}{\l_xfrac_denominator_font_tl}
+% \begin{variable}{\l_xfrac_numerator_font_tl}
+% \begin{variable}{\l_xfrac_phantom_tl }
+% \begin{variable}{\l_xfrac_slash_symbol_tl}
+% \begin{variable}{\l_xfrac_slash_symbol_font_tl}
+% Token lists, which include floating-point numbers and math(s)
+% skips.
+% \begin{macrocode}
+\tl_new:N \l_xfrac_denominator_font_tl
+\tl_new:N \l_xfrac_numerator_font_tl
+\tl_new:N \l_xfrac_phantom_tl
+\tl_new:N \l_xfrac_slash_symbol_tl
+\tl_new:N \l_xfrac_slash_symbol_font_tl
+% \end{macrocode}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+%
+% \begin{macro}{\xfrac_fontscale:}
+% \begin{macro}{\xfrac_math:n}
+% \begin{macro}{\xfrac_denominator_font_change:}
+% \begin{macro}{\xfrac_denominator_format:n}
+% \begin{macro}{\xfrac_numerator_font_change:}
+% \begin{macro}{\xfrac_numerator_format:n}
+% \begin{macro}{\xfrac_relscale:}
+% \begin{macro}{\xfrac_slash_symbol_font_change:}
+% \begin{macro}{\xfrac_slash_symbol_format:n}
+% \begin{macro}{\xfrac_text_or_math:n}
+% Functions, either things which are calculated \enquote{on the fly}
+% (no argument required) or are functions taking one argument in the
+% code.
+% \begin{macrocode}
+\cs_new_nopar:Npn \xfrac_fontscale:
+\cs_new:Npn \xfrac_math:n #1 { }
+\cs_new_nopar:Npn \xfrac_denominator_font_change: { }
+\cs_new:Npn \xfrac_denominator_format:n #1 { }
+\cs_new_nopar:Npn \xfrac_numerator_font_change: { }
+\cs_new:Npn \xfrac_numerator_format:n #1 { }
+\cs_new_nopar:Npn \xfrac_relscale: { }
+\cs_new_nopar:Npn \xfrac_slash_symbol_font_change: { }
+\cs_new:Npn \xfrac_slash_symbol_format:n #1 { }
+\cs_new:Npn \xfrac_text_or_math:n #1 { }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \subsection{The template}
+%
+% There is only one object type in \pkg{xfrac}, rather unimaginatively
+% named \texttt{xfrac}.
+% \begin{macrocode}
+\DeclareObjectType { xfrac } { 3 }
+% \end{macrocode}
+%
+% A single template interface is used for both text and math(s), which
+% does make a few things a little complex later.
+% \begin{macrocode}
+\DeclareTemplateInterface { xfrac } { text } { 3 }
+ {
+ denominator-bot-sep : length = \c_max_dim ,
+ denominator-font : tokenlist = \f@family ,
+ denominator-format : function 1 = #1 ,
+ h-scale : real = 1 ,
+ math-mode : choice { false , true }
+ = false ,
+ numerator-font : tokenlist = \f@family ,
+ numerator-format : function 1 = #1 ,
+ numerator-bot-sep : length = \c_max_dim ,
+ numerator-top-sep : length = \c_max_dim ,
+ phantom : tokenlist = 8 ,
+ scale-factor : real = 0.83333 ,
+ scale-relative : choice { false , true }
+ = true ,
+ scaling : choice { false , true }
+ = true ,
+ slash-left-kern : length = 0 pt ,
+ slash-left-mkern : muskip = -2 mu ,
+ slash-right-kern : length = 0 pt ,
+ slash-right-mkern : muskip = -1 mu ,
+ slash-symbol : tokenlist = \textfractionsolidus ,
+ slash-symbol-font : tokenlist = \f@family ,
+ slash-symbol-format : function 1 = #1 ,
+ v-scale : real = 1 ,
+ }
+% \end{macrocode}
+% Most of the variable binding is quite simple: of course, the choices
+% are a little more complicated. That is particularly true where
+% these have to set up \enquote{on the fly} functions.
+% \begin{macrocode}
+\DeclareTemplateCode { xfrac } { text } { 3 }
+ {
+ denominator-bot-sep = \l_xfrac_denominator_bot_sep_dim ,
+ denominator-font = \l_xfrac_denominator_font_tl ,
+ denominator-format = \xfrac_denominator_format:n ,
+ h-scale = \l_xfrac_hscale_fp ,
+ math-mode =
+ {
+ false = \cs_set_eq:NN \xfrac_math:n \use:n,
+ true = \cs_set_eq:NN \xfrac_math:n \ensuremath
+ },
+ numerator-font = \l_xfrac_numerator_font_tl ,
+ numerator-format = \xfrac_numerator_format:n ,
+ numerator-bot-sep = \l_xfrac_numerator_bot_sep_dim ,
+ numerator-top-sep = \l_xfrac_numerator_top_sep_dim ,
+ phantom = \l_xfrac_phantom_tl ,
+ scale-factor = \l_xfrac_scale_factor_fp ,
+ scale-relative =
+ {
+ false =
+ \cs_set_nopar:Npn \xfrac_relscale:
+ {
+ \dim_eval:w
+ \box_ht:N \l_xfrac_tmp_box + \box_dp:N \l_xfrac_tmp_box
+ \dim_eval_end:
+ },
+ true =
+ \cs_set_nopar:Npn \xfrac_relscale:
+ { \box_ht:N \l_xfrac_slash_box }
+ },
+ scaling =
+ {
+ false = \cs_set_eq:NN \xfrac_fontscale: \prg_do_nothing:,
+ true =
+ \cs_set_nopar:Npn \xfrac_fontscale:
+ {
+ \fontsize
+ { \fp_use:N \l_xfrac_scale_factor_fp \xfrac_relscale: }
+ { \c_zero_dim }
+ \selectfont
+ }
+ },
+ slash-left-kern = \l_xfrac_slash_left_sep_dim ,
+ slash-left-mkern = \l_xfrac_slash_left_muskip ,
+ slash-right-kern = \l_xfrac_slash_right_sep_dim ,
+ slash-right-mkern = \l_xfrac_slash_right_muskip ,
+ slash-symbol = \l_xfrac_slash_symbol_tl ,
+ slash-symbol-font = \l_xfrac_slash_symbol_font_tl ,
+ slash-symbol-format = \xfrac_slash_symbol_format:n ,
+ v-scale = \l_xfrac_vscale_fp
+ }
+% \end{macrocode}
+% The implementation part starts with applying all of the settings
+% from above. The first part of the set up is then to determine
+% whether the surroundings are text or math(s), and react accordingly.
+% \begin{macrocode}
+ {
+ \AssignTemplateKeys
+ \mode_if_math:TF
+ {
+ \cs_set_eq:NN \xfrac_text_or_math:n \text
+ \cs_set_nopar:Npx \xfrac_denominator_font_change:
+ { \tex_fam:D \l_xfrac_denominator_font_tl }
+ \cs_set_nopar:Npx \xfrac_numerator_font_change:
+ { \tex_fam:D \l_xfrac_numerator_font_tl }
+ \cs_set_nopar:Npx \xfrac_slash_symbol_font_change:
+ { \tex_fam:D \l_xfrac_slash_symbol_font_tl }
+ }
+ {
+ \cs_set_eq:NN \xfrac_text_or_math:n \mbox
+ \cs_set_nopar:Npn \xfrac_denominator_font_change:
+ {
+ \fontfamily { \l_xfrac_denominator_font_tl }
+ \selectfont
+ }
+ \cs_set_nopar:Npn \xfrac_numerator_font_change:
+ {
+ \fontfamily { \l_xfrac_numerator_font_tl }
+ \selectfont
+ }
+ \cs_set_nopar:Npn \xfrac_slash_symbol_font_change:
+ {
+ \fontfamily { \l_xfrac_slash_symbol_font_tl }
+ \selectfont
+ }
+ }
+% \end{macrocode}
+% Everything is now either inside \cs{text} or an \cs{mbox}, depending
+% upon the surroundings. First, there are some boxes to set up.
+% \begin{macrocode}
+ \xfrac_text_or_math:n
+ {
+ \m@th
+ \hbox_set:Nn \l_xfrac_tmp_box
+ { \xfrac_math:n { \vphantom { ( ) } } }
+ \hbox_set:Nn \l_xfrac_slash_box
+ {
+ \xfrac_math:n
+ {
+ \xfrac_slash_symbol_format:n
+ {
+ \xfrac_math:n
+ {
+ \xfrac_slash_symbol_font_change:
+ \IfNoValueTF {#2}
+ { \l_xfrac_slash_symbol_tl } {#2}
+ }
+ }
+ }
+ }
+% \end{macrocode}
+% Check on the numerator separator dimensions. The code starts with the
+% assumption that neither has been given, as this can then be used to
+% set up a default, which is also used when both values are set
+% erroneously.
+% \begin{macrocode}
+ \cs_set_nopar:Npn \xfrac_tmp:w
+ {
+ \raisebox
+ {
+ \box_ht:N \l_xfrac_slash_box
+ - \box_dp:N \l_xfrac_slash_box
+ - \height
+ }
+ }
+ \dim_compare:nNnTF
+ { \l_xfrac_numerator_top_sep_dim } = { \c_max_dim }
+ {
+ \dim_compare:nNnF
+ { \l_xfrac_numerator_bot_sep_dim } = { \c_max_dim }
+ {
+ \cs_set_nopar:Npn \xfrac_tmp:w
+ {
+ \raisebox
+ { \dim_use:N \l_xfrac_numerator_bot_sep_dim }
+ }
+ }
+ }
+ {
+ \dim_compare:nNnTF
+ { \l_xfrac_numerator_bot_sep_dim } = { \c_max_dim }
+ {
+ \cs_set_nopar:Npn \xfrac_tmp:w
+ {
+ \raisebox
+ {
+ \box_ht:N \l_xfrac_slash_box
+ - \dim_use:N \l_xfrac_numerator_top_sep_dim
+ - \height
+ }
+ }
+ }
+ {
+ \msg_error:nn { xfrac }
+ { over-specified-numerator-sep }
+ }
+ }
+% \end{macrocode}
+% Typeset the numerator.
+% \begin{macrocode}
+ \xfrac_tmp:w
+ {
+ \xfrac_fontscale:
+ \xfrac_numerator_format:n
+ {
+ \scalebox
+ { \fp_use:N \l_xfrac_hscale_fp }
+ [ \fp_use:N \l_xfrac_vscale_fp ]
+ {
+ \xfrac_math:n
+ {
+ \xfrac_numerator_font_change:
+ {
+ \vphantom { \l_xfrac_phantom_tl }
+ #1
+ }
+ }
+ }
+ }
+ }
+ \xfrac_math:n
+ { % THIS IS JUST WRONG!
+ \mode_if_math:TF
+ { \tex_mskip:D \l_xfrac_slash_right_muskip }
+ { \tex_hskip:D \l_xfrac_slash_right_sep_dim }
+ }
+% \end{macrocode}
+% Typeset the separator.
+% \begin{macrocode}
+ \box_use:N \l_xfrac_slash_box
+ \xfrac_math:n
+ {
+ \mode_if_math:TF
+ { \tex_mskip:D \l_xfrac_slash_left_muskip }
+ { \tex_hskip:D \l_xfrac_slash_left_sep_dim }
+ }
+% \end{macrocode}
+% Typeset the denominator.
+% \begin{macrocode}
+ \dim_compare:nNnTF
+ { \l_xfrac_denominator_bot_sep_dim } = { \c_max_dim }
+ {
+ \cs_set_nopar:Npn \xfrac_tmp:w
+ { \raisebox { - \box_dp:N \l_xfrac_slash_box } }
+ }
+ {
+ \cs_set_nopar:Npn \xfrac_tmp:w
+ {
+ \raisebox
+ { \dim_use:N \l_xfrac_denominator_bot_sep_dim }
+ }
+ }
+ \xfrac_tmp:w
+ {
+ \xfrac_fontscale:
+ \xfrac_denominator_format:n
+ {
+ \scalebox
+ { \fp_use:N \l_xfrac_hscale_fp }
+ [ \fp_use:N \l_xfrac_vscale_fp ]
+ {
+ \xfrac_math:n
+ {
+ \xfrac_denominator_font_change:
+ {
+ \vphantom { \l_xfrac_phantom_tl }
+ #3
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+% \end{macrocode}
+%
+% Since math(s) and text mode are wildly different entities we define a
+% separate template for each. You already saw the \enquote{text}
+% template, and here is the \enquote{math} template.
+% \begin{macrocode}
+\DeclareRestrictedTemplate { xfrac } { text } { math }
+ {
+ numerator-font = \number \fam ,
+ slash-symbol = / ,
+ slash-symbol-font = \number \fam ,
+ denominator-font = \number \fam ,
+ scale-factor = 0.7 ,
+ scale-relative = false ,
+ scaling = true ,
+ numerator-top-sep = 0 pt ,
+ denominator-bot-sep = 0 pt ,
+ math-mode = true ,
+ phantom = ( % )
+ }
+% \end{macrocode}
+%
+%\subsection{The standard instances}
+%
+% For the default instances we just use the relevant templates with
+% the default settings.
+%
+% The default \enquote{text} instance.
+% \begin{macrocode}
+\DeclareInstance { xfrac } { default } { text } { }
+% \end{macrocode}
+%
+% The default \enquote{math(s)} instance.
+% \begin{macrocode}
+\DeclareInstance { xfrac } { mathdefault } { math } { }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\DeclareCollectionInstance { plainmath } { xfrac } { mathdefault } { math }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-bot-sep = 0 pt ,
+ numerator-top-sep = \c_max_dim ,
+ scale-factor = 1 ,
+ scale-relative = false ,
+ scaling = true ,
+ slash-right-mkern = 0 mu ,
+ slash-left-mkern = 0 mu
+ }
+% \end{macrocode}
+%
+% Default Computer Modern setup. Far from optimal, but better than
+% nothing.
+% \begin{macrocode}
+\DeclareInstance { xfrac } { cmr } { text }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-top-sep = 0.2 ex ,
+ slash-left-kern = -0.1 em ,
+ slash-right-kern = -0.1 em
+ }
+\DeclareInstance { xfrac } { cmss } { text }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-top-sep = 0.2 ex ,
+ slash-left-kern = -0.1 em ,
+ slash-right-kern = -0.1 em
+ }
+\DeclareInstance { xfrac } { cmtt } { text }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-top-sep = 0.2 ex ,
+ slash-left-kern = -0.1 em ,
+ slash-right-kern = -0.1 em
+ }
+% \end{macrocode}
+%
+% We can do better for the Computer Modern fonts. For cmr and cmss
+% we choose Times, and for cmtt use Palatino.
+% \begin{macrocode}
+\bool_if:NF \l_xfrac_cm_std_bool
+ {
+ \DeclareInstance { xfrac } { cmr } { text }
+ { slash-symbol-font = ptm }
+ \DeclareInstance { xfrac } { cmss } { text }
+ { slash-symbol-font = ptm }
+ \DeclareInstance { xfrac } { cmtt } { text }
+ { slash-symbol-font = ppl }
+ }
+% \end{macrocode}
+%
+% Things works slightly better with Latin Modern.
+% \begin{macrocode}
+\DeclareInstance { xfrac } { lmr } { text }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-top-sep = 0.1 ex ,
+ slash-left-kern = -0.15 em ,
+ slash-right-kern = -0.15 em
+ }
+\DeclareInstance { xfrac } { lmss } { text }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-top-sep = 0 pt ,
+ slash-left-kern = -0.15 em ,
+ slash-right-kern = -0.15 em
+ }
+\DeclareInstance { xfrac } { lmtt } { text }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-top-sep = 0 pt ,
+ slash-left-kern = -0.15 em ,
+ slash-right-kern = -0.15 em
+ }
+% \end{macrocode}
+%
+% \subsection{The user command}
+%
+% \begin{macro}{\sfrac}
+% Currently there is just a single user command. \cs{sfrac} takes
+% two mandatory arguments: numerator and denominator. It can take an
+% optional argument between the mandatory specifying the separator
+% like this:
+% \begin{verbatim}
+% \sfrac{7}[/]{12}
+% \end{verbatim}
+% It also has an optional argument that comes before the first
+% mandatory argument. If used it will use that instance instead of
+% the auto-detected one, so a user who has defined the instance
+% \enquote{cmr2} may use
+% \begin{verbatim}
+% \sfrac[cmr2]{7}{12}
+% \end{verbatim}
+% and get the settings from \enquote{cmr2} instead of the settings of
+% the current font family.
+% \begin{macrocode}
+\NewDocumentCommand \sfrac { o m o m }
+ {
+ \mode_if_math:TF
+ {
+ \IfInstanceExistTF { xfrac } { mathfam \number \fam }
+ { \UseInstance { xfrac } { mathfam \number \fam } }
+ { \UseInstance { xfrac } { mathdefault } }
+ {#2} {#3} {#4}
+ }
+ {
+ \IfInstanceExistTF { xfrac } {#1}
+ { \UseInstance { xfrac } {#1} }
+ {
+ \IfInstanceExistTF { xfrac } { \f@family }
+ { \UseInstance { xfrac } { \f@family } }
+ { \UseInstance { xfrac } { default } }
+ }
+ {#2} {#3} {#4}
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{Messages}
+%
+% Just the one.
+% \begin{macrocode}
+\msg_new:nnnn { xfrac } { over-specified-numerator-sep }
+ { You have specified both numerator-top-sep and numerator-bot-sep}
+ {I will pretend that you didn't specify either of them}
+% \end{macrocode}
+
+%
+% \begin{macrocode}
+%</package>
+% \end{macrocode}
+%
+% \end{implementation}
+%
+% \PrintIndex \ No newline at end of file
diff --git a/Master/texmf-dist/source/latex/l3packages/xfrac/xfrac.ins b/Master/texmf-dist/source/latex/l3packages/xfrac/xfrac.ins
new file mode 100644
index 00000000000..c1ab6c55448
--- /dev/null
+++ b/Master/texmf-dist/source/latex/l3packages/xfrac/xfrac.ins
@@ -0,0 +1,41 @@
+\iffalse meta-comment
+
+File xfrac.ins Copyright (C) 2004, 2008-2010 Morten Hoegholm
+ (C) 2011 The LaTeX3 Project
+
+It may be distributed and/or modified under the conditions of the
+LaTeX Project Public License (LPPL), either version 1.3c of this
+license or (at your option) any later version. The latest version
+of this license is in the file
+
+ http://www.latex-project.org/lppl.txt
+
+This file is part of the "l3packages bundle" (The Work in LPPL)
+and all files in that bundle must be distributed together.
+
+The released version of this bundle is available from CTAN.
+
+\fi
+
+\input docstrip.tex
+\askforoverwritefalse
+
+\preamble
+
+EXPERIMENTAL CODE
+
+Do not distribute this file without also distributing the
+source files specified above.
+
+Do not distribute a modified version of this file.
+
+\endpreamble
+% stop docstrip adding \endinput
+\postamble
+\endpostamble
+
+\keepsilent
+
+\generate{\file{xfrac.sty} {\from{xfrac.dtx} {package}}}
+
+\endbatchfile
diff --git a/Master/texmf-dist/source/latex/l3packages/xparse/xparse.dtx b/Master/texmf-dist/source/latex/l3packages/xparse/xparse.dtx
new file mode 100644
index 00000000000..79a996d4fc8
--- /dev/null
+++ b/Master/texmf-dist/source/latex/l3packages/xparse/xparse.dtx
@@ -0,0 +1,2650 @@
+% \iffalse meta-comment
+%
+%% File: xparse.dtx (C) Copyright 1999 Frank Mittelbach, Chris Rowley,
+%% David Carlisle
+%% (C) Copyright 2004-2008 Frank Mittelbach,
+%% The LaTeX3 Project
+%% (C) Copyright 2009-2011 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3packages bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+%
+%<*driver|package>
+\RequirePackage{expl3}
+\GetIdInfo$Id: xparse.dtx 2492 2011-07-02 13:40:38Z joseph $
+ {L3 Experimental document command parser}
+%</driver|package>
+%<*driver>
+\documentclass[full]{l3doc}
+\usepackage{amstext}
+\begin{document}
+ \DocInput{\jobname.dtx}
+\end{document}
+%</driver>
+% \fi
+%
+% \providecommand\acro[1]{\textsc{\MakeLowercase{#1}}}
+% \newenvironment{arg-description}{%
+% \begin{itemize}\def\makelabel##1{\hss\llap{\bfseries##1}}}{\end{itemize}}
+%
+% \title{^^A
+% The \textsf{xparse} package\\ Document command parser^^A
+% \thanks{This file describes v\ExplFileVersion,
+% last revised \ExplFileDate.}^^A
+% }
+%
+% \author{^^A
+% The \LaTeX3 Project\thanks
+% {^^A
+% E-mail:
+% \href{mailto:latex-team@latex-project.org}
+% {latex-team@latex-project.org}^^A
+% }^^A
+% }
+%
+% \date{Released \ExplFileDate}
+%
+% \maketitle
+%
+% \begin{documentation}
+%
+% The \pkg{xparse} package provides a high-level interface for
+% producing document-level commands. In that way, it is intended as
+% a replacement for the \LaTeXe{} \cs{newcommand} macro. However,
+% \pkg{xparse} works so that the interface to a function (optional
+% arguments, stars and mandatory arguments, for example) is separate
+% from the internal implementation. \pkg{xparse} provides a normalised
+% input for the internal form of a function, independent of the
+% document-level argument arrangement.
+%
+% At present, the functions in \pkg{xparse} which are regarded as
+% \enquote{stable} are:
+% \begin{itemize}
+% \item \cs{DeclareDocumentCommand}
+% \item \cs{NewDocumentCommand}
+% \item \cs{RenewDocumentCommand}
+% \item \cs{ProvideDocumentCommand}
+% \item \cs{DeclareDocumentEnvironment}
+% \item \cs{NewDocumentEnvironment}
+% \item \cs{RenewDocumentEnvironment}
+% \item \cs{ProvideDocumentEnvironment}
+% \item \cs{IfNoValue(TF)} (the need for \cs{IfValue(TF)} is currently
+% an item of active discussion)
+% \item \cs{IfBoolean(TF)}
+% \end{itemize}
+% with the other functions currently regarded as \enquote{experimental}. Please
+% try all of the commands provided here, but be aware that the
+% experimental ones may change or disappear.
+%
+% \subsection{Specifying arguments}
+%
+% Before introducing the functions used to create document commands,
+% the method for specifying arguments with \pkg{xparse} will be
+% illustrated. In order to allow each argument to be defined
+% independently, \pkg{xparse} does not simply need to know the
+% number of arguments for a function, but also the nature of each
+% one. This is done by constructing an \emph{argument specification},
+% which defines the number of arguments, the type of each argument
+% and any additional information needed for \pkg{xparse} to read the
+% user input and properly pass it through to internal functions.
+%
+% The basic form of the argument specifier is a list of letters, where
+% each letter defines a type of argument. As will be described below,
+% some of the types need additional information, such as default values.
+% The argument types can be divided into two, those which define
+% arguments that are mandatory (potentially raising an error if not
+% found) and those which define optional arguments. The mandatory types
+% are:
+% \begin{itemize}[font=\ttfamily]
+% \item[m] A standard mandatory argument, which can either be a single
+% token alone or multiple tokens surrounded by curly braces.
+% Regardless of the input, the argument will be passed to the
+% internal code surrounded by a brace pair. This is the \pkg{xparse}
+% type specifier for a normal \TeX\ argument.
+% \item[l] An argument which reads everything up to the first
+% open group token: in standard \LaTeX\ this is a left brace.
+% \item[u] Reads an argument `until' \meta{tokens} are encountered,
+% where the desired \meta{tokens} are given as an argument to the
+% specifier: \texttt{u}\marg{tokens}.
+% \end{itemize}
+% The types which define optional arguments are:
+% \begin{itemize}[font=\ttfamily]
+% \item[o] A standard \LaTeX\ optional argument, surrounded with square
+% brackets, which will supply
+% the special \cs{NoValue} token if not given (as described later).
+% \item[d] An optional argument which is delimited by \meta{token1}
+% and \meta{token2}, which are given as arguments:
+% \texttt{d}\meta{token1}\meta{token2}. As with \texttt{o}, if no
+% value is given the special token \cs{NoValue} is returned.
+% \item[O] As for \texttt{o}, but returns \meta{default} if no
+% value is given. Should be given as \texttt{O}\marg{default}.
+% \item[D] As for \texttt{d}, but returns \meta{default} if no
+% value is given: \texttt{D}\meta{token1}\meta{token2}\marg{default}.
+% Internally, the \texttt{o}, \texttt{d} and \texttt{O} types are
+% short-cuts to an appropriated-constructed \texttt{D} type argument.
+% \item[s] An optional star, which will result in a value
+% \cs{BooleanTrue} if a star is present and \cs{BooleanFalse}
+% otherwise (as described later).
+% \item[t] An optional \meta{token}, which will result in a value
+% \cs{BooleanTrue} if \meta{token} is present and \cs{BooleanFalse}
+% otherwise. Given as \texttt{t}\meta{token}.
+% \item[g] An optional argument given inside a pair of \TeX\ group
+% tokens (in standard \LaTeX, |{| \ldots |}|), which returns
+% \cs{NoValue} if not present.
+% \item[G] As for \texttt{g} but returns \meta{default} if no value
+% is given: \texttt{G}\marg{default}.
+% \end{itemize}
+%
+% Using these specifiers, it is possible to create complex input syntax
+% very easily. For example, given the argument definition
+% `|s o o m O{default}|', the input `|*[Foo]{Bar}|' would be parsed as:
+% \begin{itemize}[nolistsep]
+% \item |#1| = |\BooleanTrue|
+% \item |#2| = |{Foo}|
+% \item |#3| = |\NoValue|
+% \item |#4| = |{Bar}|
+% \item |#5| = |{default}|
+% \end{itemize}
+% whereas `|[One][Two]{}[Three]|' would be parsed as:
+% \begin{itemize}[nolistsep]
+% \item |#1| = |\BooleanFalse|
+% \item |#2| = |{One}|
+% \item |#3| = |{Two}|
+% \item |#4| = |{}|
+% \item |#5| = |{Three}|
+% \end{itemize}
+% Note that after parsing the input there will be always exactly the
+% same number of \meta{balanced text} arguments as the number of letters
+% in the argument specifier. The \cs{BooleanTrue} and \cs{BooleanFalse}
+% tokens are passed without braces; all other arguments are passed as
+% brace groups.
+%
+% Two more tokens have a special meaning when creating an argument
+% specifier. First, \texttt{+} is used to make an argument long (to
+% accept paragraph tokens). In contrast to \LaTeXe's \cs{newcommand},
+% this applies on an argument-by-argument basis. So modifying the
+% example to `|s o o +m O{default}|' means that the mandatory argument
+% is now \cs{long}, whereas the optional arguments are not.
+%
+% Secondly, the token \texttt{>} is used to declare so-called
+% \enquote{argument processors}, which can be used to modify the contents of an
+% argument before it is passed to the macro definition. The use of
+% argument processors is a somewhat advanced topic, (or at least a less
+% commonly used feature) and is covered in Section~\ref{sec:processors}.
+%
+% \subsection{Spacing and optional arguments}
+%
+% \TeX{} will find the first argument after a function name irrespective
+% of any intervening spaces. This is true for both mandatory and
+% optional arguments. So |\foo[arg]| and \verb*|\foo [arg]| are
+% equivalent. Spaces are also ignored when collecting arguments up
+% to the last mandatory argument to be collected (as it must exist).
+% So after
+% \begin{verbatim}
+% \DeclareDocumentCommand \foo { m o m } { ... }
+% \end{verbatim}
+% the user input |\foo{arg1}[arg2]{arg3}| and
+% \verb*|\foo{arg1} [arg2] {arg3}| will both be parsed in the same
+% way. However, spaces are \emph{not} ignored when parsing optional
+% arguments after the last mandatory argument. Thus with
+% \begin{verbatim}
+% \DeclareDocumentCommand \foo { m o } { ... }
+% \end{verbatim}
+% |\foo{arg1}[arg2]| will find an optional argument but
+% \verb*|\foo{arg1} [arg2]| will not. This is so that trailing optional
+% arguments are not picked up \enquote{by accident} in input.
+%
+% \subsection{Declaring commands and environments}
+%
+% With the concept of an argument specifier defined, it is now
+% possible to describe the methods available for creating both
+% functions and environments using \pkg{xparse}.
+%
+% The interface-building commands are the preferred method for
+% creating document-level functions in \LaTeX3. All of the functions
+% generated in this way are naturally robust (using the \eTeX{}
+% \cs{protected} mechanism).
+%
+% \begin{function}
+% {
+% \DeclareDocumentCommand ,
+% \NewDocumentCommand ,
+% \RenewDocumentCommand ,
+% \ProvideDocumentCommand
+% }
+% \begin{syntax}
+% \cs{DeclareDocumentCommand} \meta{Function} \Arg{arg spec} \Arg{code}
+% \end{syntax}
+% This family of commands are used to create a document-level
+% \meta{function}. The argument specification for the function is
+% given by \meta{arg spec}, and expanding
+% to be replaced by the \meta{code}.
+%
+% As an example:
+% \begin{verbatim}
+% \DeclareDocumentCommand \chapter { s o m }
+% {
+% \IfBooleanTF {#1}
+% { \typesetnormalchapter {#2} {#3} }
+% { \typesetstarchapter {#3} }
+% }
+% \end{verbatim}
+% would be a way to define a \cs{chapter} command which would
+% essentially behave like the current \LaTeXe{} command (except that it
+% would accept an optional argument even when a \texttt{*} was parsed).
+% The \cs{typesetnormalchapter} could test its first argument for being
+% \cs{NoValue} to see if an optional argument was present.
+%
+% The difference between the \cs{Declare\ldots}, \cs{New\ldots}
+% \cs{Renew\ldots} and \cs{Provide\ldots} versions is the behaviour
+% if \meta{function} is already defined.
+% \begin{itemize}
+% \item \cs{DeclareDocumentCommand} will always create the new
+% definition, irrespective of any existing \meta{function} with the
+% same name.
+% \item \cs{NewDocumentCommand} will issue an error if \meta{function}
+% has already been defined.
+% \item \cs{RenewDocumentCommand} will issue an error if \meta{function}
+% has not previously been defined.
+% \item \cs{ProvideDocumentCommand} creates a new definition for
+% \meta{function} only if one has not already been given.
+% \end{itemize}
+%
+% \begin{texnote}
+% Unlike \LaTeXe{}'s \cs{newcommand} and relatives, the
+% \cs{DeclareDocumentCommand} function do not prevent creation of
+% functions with names starting \cs{end\ldots}.
+% \end{texnote}
+% \end{function}
+%
+% \begin{function}
+% {
+% \DeclareDocumentEnvironment ,
+% \NewDocumentEnvironment ,
+% \RenewDocumentEnvironment ,
+% \ProvideDocumentEnvironment
+% }
+% \begin{syntax}
+% \cs{DeclareDocumentEnvironment} \Arg{environment} \Arg{arg spec}
+% ~~\Arg{start code} \Arg{end code}
+% \end{syntax}
+% These commands work in the same way as \cs{DeclareDocumentCommand},
+% etc., but create environments (\cs{begin}|{|\meta{function}|}| \ldots
+% \cs{end}|{|\meta{function}|}|). Both the \meta{start code} and
+% \meta{end code}
+% may access the arguments as defined by \meta{arg spec}.
+% \end{function}
+%
+% \subsection{Testing special values}
+%
+% Optional arguments created using \pkg{xparse} make use of dedicated
+% variables to return information about the nature of the argument
+% received.
+%
+% \begin{variable}{\NoValue}
+% \cs{NoValue} is a special marker returned by \pkg{xparse} if no
+% value is given for an optional argument. If typeset (which should
+% not happen), it will print the value \texttt{-NoValue-}.
+% \end{variable}
+%
+% \begin{function}[EXP,TF]{\IfNoValue}
+% \begin{syntax}
+% \cs{IfNoValueTF} \Arg{argument} \Arg{true code} \Arg{false code}
+% \end{syntax}
+% The \cs{IfNoValue} tests are used to check if <argument> (|#1|,
+% |#2|, \emph{etc.}) is the special \cs{NoValue} token. For example
+% \begin{verbatim}
+% \DeclareDocumentCommand \foo { o m }
+% {
+% \IfNoValueTF {#1}
+% { \DoSomethingJustWithMandatoryArgument {#2} }
+% { \DoSomethingWithBothArguments {#1} {#2} }
+% }
+% \end{verbatim}
+% will use a different internal function if the optional argument
+% is given than if it is not present.
+%
+% As the \cs{IfNoValue(TF)} tests are expandable, it is possible to
+% test these values later, for example at the point of typesetting or
+% in an expansion context.
+% \end{function}
+%
+% \begin{function}[EXP,TF]{\IfValue}
+% \begin{syntax}
+% \cs{IfValueTF} \Arg{argument} \Arg{true code} \Arg{false code}
+% \end{syntax}
+% The reverse form of the \cs{IfNoValue(TF)} tests are also available
+% as \cs{IfValue(TF)}. The context will determine which logical
+% form makes the most sense for a given code scenario.
+% \end{function}
+%
+% \begin{variable}{\BooleanFalse, \BooleanTrue}
+% The \texttt{true} and \texttt{false} flags set when searching for
+% an optional token (using \texttt{s} or \texttt{t\meta{token}}) have
+% names which are accessible outside of code blocks.
+% \end{variable}
+%
+% \begin{function}[EXP,TF]{\IfBoolean}
+% \begin{syntax}
+% \cs{IfBooleanTF} \meta{argument} \Arg{true code} \Arg{false code}
+% \end{syntax}
+% Used to test if \meta{argument} (|#1|, |#2|, \emph{etc.}) is
+% \cs{BooleanTrue} or \cs{BooleanFalse}. For example
+% \begin{verbatim}
+% \DeclareDocumentCommand \foo { s m }
+% {
+% \IfBooleanTF #1
+% { \DoSomethingWithStar {#2} }
+% { \DoSomethingWithoutStar {#2} }
+% }
+% \end{verbatim}
+% checks for a star as the first argument, then chooses the action to
+% take based on this information.
+% \end{function}
+%
+% \subsection{Argument processors}
+% \label{sec:processors}
+%
+% \pkg{xparse} introduces the idea of an argument processor, which is
+% applied to an argument \emph{after} it has been grabbed by the
+% underlying system but before it is passed to \meta{code}. An argument
+% processor can therefore be used to regularise input at an early stage,
+% allowing the internal functions to be completely independent of input
+% form. Processors are applied to user input and to default values for
+% optional arguments, but \emph{not} to the special \cs{NoValue} marker.
+%
+% Each argument processor is specified by the syntax
+% \texttt{>}\marg{processor} in the argument specification. Processors
+% are applied from right to left, so that
+% \begin{verbatim}
+% >{\ProcessorB} >{\ProcessorA} m
+% \end{verbatim}
+% would apply \cs{ProcessorA}
+% followed by \cs{ProcessorB} to the tokens grabbed by the \texttt{m}
+% argument.
+%
+% \begin{variable}{\ProcessedArgument}
+% \pkg{xparse} defines a very small set of processor functions. In the
+% main, it is anticipated that code writers will want to create their
+% own processors. These need to accept one argument, which is the
+% tokens as grabbed (or as returned by a previous processor function).
+% Processor functions should return the processed argument as the
+% variable \cs{ProcessedArgument}.
+% \end{variable}
+%
+% \begin{function}{\ReverseBoolean}
+% \begin{syntax}
+% \cs{ReverseBoolean}
+% \end{syntax}
+% This processor reverses the logic of \cs{BooleanTrue} and
+% \cs{BooleanFalse}, so that the the example from earlier would become
+% \begin{verbatim}
+% \DeclareDocumentCommand \foo { > { \ReverseBoolean } s m }
+% {
+% \IfBooleanTF #1
+% { \DoSomethingWithoutStar {#2} }
+% { \DoSomethingWithStar {#2} }
+% }
+% \end{verbatim}
+% \end{function}
+%
+% \begin{function}{\SplitArgument}
+% \begin{syntax}
+% \cs{SplitArgument} \Arg{number} \Arg{token}
+% \end{syntax}
+% This processor splits the argument given at each occurrence of the
+% \meta{token} up to a maximum of \meta{number} tokens (thus
+% dividing the input into $\text{\meta{number}} + 1$ parts).
+% An error is given if too many \meta{tokens} are present in the
+% input. The processed input is places inside
+% $\text{\meta{number}} + 1$ sets of braces for further use.
+% If there are less than \Arg{number} of \Arg{tokens} in the argument
+% then empty brace groups are added at the end of the processed
+% argument.
+% \begin{verbatim}
+% \DeclareDocumentCommand \foo
+% { > { \SplitArgument { 2 } { ; } } m }
+% { \InternalFunctionOfThreeArguments #1 }
+% \end{verbatim}
+% Any category code $13$ (active) \meta{tokens} will be replaced
+% before the split takes place.
+% \end{function}
+%
+% \begin{function}{\SplitList}
+% \begin{syntax}
+% \cs{SplitList} \Arg{token}
+% \end{syntax}
+% This processor splits the argument given at each occurrence of the
+% \meta{token} where the number of items is not fixed. Each item is
+% then wrapped in braces within |#1|. The result is that the
+% processed argument can be further processed using a mapping function.
+% \begin{verbatim}
+% \DeclareDocumentCommand \foo
+% { > { \SplitList { ; } } m }
+% { \MappingFunction #1 }
+% \end{verbatim}
+% Any category code $13$ (active) \meta{tokens} will be replaced
+% before the split takes place.
+% \end{function}
+%
+% \subsection{Separating interface and implementation}
+%
+% One \emph{experimental} idea implemented in \pkg{xparse} is to
+% separate out document command interfaces (the argument specification)
+% from the implementation (code). This is carried out using a
+% pair of functions, \cs{DeclareDocumentCommandInterface} and
+% \cs{DeclareDocumentCommandImplementation}
+%
+% \begin{function}{\DeclareDocumentCommandInterface}
+% \begin{syntax}
+% \cs{DeclareDocumentCommandInterface} \meta{function}
+% ~~~~\Arg{implementation} \Arg{arg spec}
+% \end{syntax}
+% This declares a \meta{function}, which will take arguments as detailed
+% in the \meta{arg spec}. When executed, the \meta{function} will look for
+% code stored as an \meta{implementation}.
+% \end{function}
+%
+% \begin{function}{\DeclareDocumentCommandImplementation}
+% \begin{syntax}
+% \cs{DeclareDocumentCommandImplementation}
+% ~~~~\Arg{implementation} \meta{args} \Arg{code}
+% \end{syntax}
+% Declares the \meta{implementation} for a function to accept \meta{args}
+% arguments and expand to \meta{code}. An implementation must take the
+% same number of arguments as a linked interface, although this is not
+% enforced by the code.
+% \end{function}
+%
+% \subsection{Fully-expandable document commands}
+%
+% There are \emph{very rare} occasion when it may be useful to create
+% functions using a fully-expandable argument grabber. To support this,
+% \pkg{xparse} can create expandable functions as well as the usual
+% robust ones. This imposes a number of restrictions on the nature of
+% the arguments accepted by a function, and the code it implements.
+% This facility should only be used when \emph{absolutely necessary};
+% if you do not understand when this might be, \emph{do not use these
+% functions}!
+%
+% \begin{function}{\DeclareExpandableDocumentCommand}
+% \begin{syntax}
+% \cs{DeclareExpandableDocumentCommand}
+% ~~~~\meta{function} \Arg{arg spec} \Arg{code}
+% \end{syntax}
+% This command is used to create a document-level \meta{function},
+% which will grab its arguments in a fully-expandable manner. The
+% argument specification for the function is given by \meta{arg spec},
+% and the function will execute \meta{code}. In general, \meta{code} will
+% also be fully expandable, although it is possible that this will
+% not be the case (for example, a function for use in a table might
+% expand so that \cs{omit} is the first non-expandable token).
+%
+% Parsing arguments expandably imposes a number of restrictions on
+% both the type of arguments that can be read and the error checking
+% available:
+% \begin{itemize}
+% \item The last argument (if any are present) must be one of the
+% mandatory types: \texttt{l}, \texttt{m} or \texttt{u}.
+% \item All arguments are either short or long: it is not possible
+% to mix short and long argument types.
+% \item The `optional group' argument types \texttt{g} and
+% \texttt{G} are not available.
+% \item It is not possible to differentiate between, for example
+% |\foo[| and |\foo{[}|: in both cases the \texttt{[} will be
+% interpreted as the start of an optional argument. As a result
+% result, checking for optional arguments is less robust than
+% in the standard version.
+% \end{itemize}
+% \pkg{xparse} will issue an error if an argument specifier is given
+% which does not conform to the first three requirements. The last
+% item is an issue when the function is used, and so is beyond the
+% scope of \pkg{xparse} itself.
+% \end{function}
+%
+% \subsection{Access to the argument specification}
+%
+% The argument specifications for document commands and environments are
+% available for examination and use.
+%
+% \begin{function}{\GetDocumentCommandArgSpec, \GetDocumentEnvironmentArgSpec}
+% \begin{syntax}
+% \cs{GetDocumentCommandArgSpec} \meta{function}
+% \cs{GetDocumentEnvironmentArgSpec} \meta{environment}
+% \end{syntax}
+% These functions transfer the current argument specification for the
+% requested \meta{function} or \meta{environment} into the token list
+% variable \cs{ArgumentSpecification}. If the \meta{function} or
+% \meta{environment} has no known argument specification then an error
+% is issued. The assignment to \cs{ArgumentSpecification} is local to
+% the current \TeX{} group.
+% \end{function}
+%
+% \begin{function}
+% {\ShowDocumentCommandArgSpec, \ShowDocumentEnvironmentArgSpec}
+% \begin{syntax}
+% \cs{ShowDocumentCommandArgSpec} \meta{function}
+% \cs{ShowDocumentEnvironmentArgSpec} \meta{environment}
+% \end{syntax}
+% These functions show the current argument specification for the
+% requested \meta{function} or \meta{environment} at the terminal. If
+% the \meta{function} or \meta{environment} has no known argument
+% specification then an error is issued.
+% \end{function}
+%
+% \section{Load-time options}
+%
+% \DescribeOption{log-declarations}
+% The package recognises the load-time option \texttt{log-declarations},
+% which is a key--value option taking the value \texttt{true} and
+% \texttt{false}. By default, the option is set to \texttt{true}, meaning
+% that each command or environment declared is logged. By loading
+% \pkg{xparse} using
+% \begin{verbatim}
+% \usepackage[load-declarations=false]{xparse}
+% \end{verbatim}
+% this may be suppressed and no information messages are produced.
+%
+% \end{documentation}
+%
+% \begin{implementation}
+%
+% \section{\pkg{xparse} implementation}
+%
+% \begin{macrocode}
+%<*package>
+% \end{macrocode}
+%
+% \begin{macrocode}
+\ProvidesExplPackage
+ {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+\RequirePackage{expl3}
+% \end{macrocode}
+%
+% A check to make sure that \pkg{expl3} is not too old
+% \begin{macrocode}
+\@ifpackagelater { l3token } { 2011/07/02 }
+ { }
+ {
+ \PackageError { xparse } { Support~package~l3kernel~too~old. }
+ {
+ Please~install~an~up~to~date~version~of~l3kernel~
+ using~your~TeX~package~manager~or~from~CTAN.\\ \\
+ Loading~xparse~will~abort!
+ }
+ \tex_endinput:D
+ }
+% \end{macrocode}
+%
+% \subsection{Variables and constants}
+%
+% \begin{variable}{\c_xparse_shorthands_prop}
+% Shorthands are stored as a property list: this is set up here as it
+% is a constant.
+% \begin{macrocode}
+\prop_new:N \c_xparse_shorthands_prop
+\prop_put:Nnn \c_xparse_shorthands_prop { o } { d[] }
+\prop_put:Nnn \c_xparse_shorthands_prop { O } { D[] }
+\prop_put:Nnn \c_xparse_shorthands_prop { s } { t* }
+% \end{macrocode}
+ %\end{variable}
+%
+% \begin{variable}{\l_xparse_arg_tl}
+% Token list variable for single grabbed argument when post-processing.
+% \begin{macrocode}
+\tl_new:N \l_xparse_arg_tl
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xparse_args_tl}
+% Token list variable for grabbed arguments.
+% \begin{macrocode}
+\tl_new:N \l_xparse_args_tl
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xparse_environment_bool}
+% Generating environments uses the same mechanism as generating
+% functions. However, full processing of arguments is always needed
+% for environments, and so the function-generating code needs to
+% know this.
+% \begin{macrocode}
+\bool_new:N \l_xparse_environment_bool
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xparse_error_bool}
+% Used to signal an error when creating expandable functions.
+% \begin{macrocode}
+\bool_new:N \l_xparse_error_bool
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xparse_function_tl}
+% When creating expandable functions, the current function name needs
+% to be passed along.
+% \begin{macrocode}
+\tl_new:N \l_xparse_function_tl
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xparse_last_arg_tl}
+% Used when creating expandable arguments.
+% \begin{macrocode}
+\tl_new:N \l_xparse_last_arg_tl
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xparse_long_bool}
+% A flag for \cs{long} arguments.
+% \begin{macrocode}
+\bool_new:N \l_xparse_long_bool
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xparse_m_args_int}
+% The number of simple \texttt{m} arguments is tracked so they can be
+% dumped \emph{en masse}.
+% \begin{macrocode}
+\int_new:N \l_xparse_m_args_int
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xparse_m_only_bool}
+% A flag to indicate that only \texttt{m} arguments have been found.
+% \begin{macrocode}
+\bool_new:N \l_xparse_m_only_bool
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xparse_mandatory_args_int}
+% So that trailing optional arguments can be picked up, a count has to
+% be taken of all mandatory arguments. This is then decreased as
+% mandatory arguments are added to the signature, so will be zero
+% only if there are no more mandatory arguments to add.
+% \begin{macrocode}
+\int_new:N \l_xparse_mandatory_args_int
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xparse_processor_bool}
+% When reading through the argument specifier, a flag is needed to
+% show that a processor has been found for the current argument. This
+% is used when checking how to handle \texttt{m} arguments.
+% \begin{macrocode}
+\bool_new:N \l_xparse_processor_bool
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xparse_processor_int}
+% In the grabber routine, each processor is saved with a number
+% recording the order it was found in. The total is then used to work
+% back through the grabbers so they apply to the argument right to left.
+% \begin{macrocode}
+\int_new:N \l_xparse_processor_int
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xparse_signature_tl}
+% Token list variable for constructing signatures.
+% \begin{macrocode}
+\tl_new:N \l_xparse_signature_tl
+% \end{macrocode}
+%\end{variable}
+%
+% \begin{variable}{\l_xparse_tmp_tl}
+% A general purpose token list variable.
+% \begin{macrocode}
+\tl_new:N \l_xparse_tmp_tl
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xparse_total_args_int}
+% The total number of arguments is used to create the internal function
+% which has a fixed number of arguments.
+% \begin{macrocode}
+\int_new:N \l_xparse_total_args_int
+% \end{macrocode}
+% \end{variable}
+%
+% \subsection{Turning the argument specifier into grabbers}
+%
+% \begin{macro}{\xparse_add_grabber_mandatory:N}
+% \begin{macro}{\xparse_add_grabber_optional:N}
+% To keep the various checks needed in one place, adding the grabber to
+% the signature is done here. For mandatory arguments, the only question
+% is whether to add a long grabber. For optional arguments, there is
+% also a check to see if any mandatory arguments are still to be added.
+% This is used to determine whether to skip spaces or not where
+% searching for the argument.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xparse_add_grabber_mandatory:N #1
+ {
+ \tl_put_right:Nx \l_xparse_signature_tl
+ {
+ \exp_not:c
+ { xparse_grab_ #1 \bool_if:NT \l_xparse_long_bool { _long } :w }
+ }
+ \bool_set_false:N \l_xparse_long_bool
+ \int_decr:N \l_xparse_mandatory_args_int
+ }
+\cs_new_protected_nopar:Npn \xparse_add_grabber_optional:N #1
+ {
+ \tl_put_right:Nx \l_xparse_signature_tl
+ {
+ \exp_not:c
+ {
+ xparse_grab_ #1
+ \bool_if:NT \l_xparse_long_bool { _long }
+ \int_compare:nNnF \l_xparse_mandatory_args_int > \c_zero
+ { _trailing }
+ :w
+ }
+ }
+ \bool_set_false:N \l_xparse_long_bool
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% All of the argument-adding functions work in essentially the same
+% way, except the one for \texttt{m} arguments. Any collected \texttt{m}
+% arguments are added to the signature, then the appropriate grabber
+% is added to the signature. Some of the adding functions also pick up
+% one or more arguments, and are also added to the signature. All of the
+% functions then call the loop function \cs{xparse_prepare_signature:N}.
+%
+% \begin{macro}{\xparse_add_type_+:w}
+% Making the next argument \cs{long} means setting the flag and
+% knocking one back off the total argument count. The \texttt{m}
+% arguments are recorded here as this has to be done for every case
+% where there is then a \cs{long} argument.
+% \begin{macrocode}
+\cs_new_protected_nopar:cpn { xparse_add_type_+:w }
+ {
+ \xparse_flush_m_args:
+ \bool_set_true:N \l_xparse_long_bool
+ \bool_set_false:N \l_xparse_m_only_bool
+ \int_decr:N \l_xparse_total_args_int
+ \xparse_prepare_signature:N
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_add_type_>:w}
+% When a processor is found, the function \cs{xparse_process_arg:n}
+% is added to the signature along with the processor code itself. When
+% the signature is used, the code will be added to an execution list by
+% \cs{xparse_process_arg:n}. Here, the loop calls
+% \cs{xparse_prepare_signature_aux:N} rather than
+% \cs{xparse_prepare_signature:N} so that the flag is not reset.
+% \begin{macrocode}
+\cs_new_protected:cpn { xparse_add_type_>:w } #1
+ {
+ \bool_set_true:N \l_xparse_processor_bool
+ \xparse_flush_m_args:
+ \int_decr:N \l_xparse_total_args_int
+ \tl_put_right:Nn \l_xparse_signature_tl { \xparse_process_arg:n {#1} }
+ \xparse_prepare_signature_aux:N
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_add_type_d:w}
+% To save on repeated code, \texttt{d} is actually turned into
+% the same grabber as is used by \texttt{D}, by putting the
+% \cs{NoValue} default in the correct place. So there is some
+% simple argument re-arrangement to do. Remember that |#1| and |#2|
+% should be single tokens.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_add_type_d:w #1#2
+ { \xparse_add_type_D:w #1 #2 { \NoValue } }
+% \end{macrocode}
+%\end{macro}
+%
+% \begin{macro}{\xparse_add_type_D:w}
+% All of the optional delimited arguments are handled internally by
+% the \texttt{D} type. At this stage, the two delimiters are stored
+% along with the default value.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_add_type_D:w #1#2#3
+ {
+ \xparse_flush_m_args:
+ \xparse_add_grabber_optional:N D
+ \tl_put_right:Nn \l_xparse_signature_tl { #1 #2 {#3} }
+ \xparse_prepare_signature:N
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_add_type_g:w}
+% The \texttt{g} type is simply an alias for \texttt{G} with the
+% correct default built-in.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xparse_add_type_g:w
+ { \xparse_add_type_G:w { \NoValue } }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_add_type_G:w}
+% For the \texttt{G} type, the grabber and the default are added to
+% the signature.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_add_type_G:w #1
+ {
+ \xparse_flush_m_args:
+ \xparse_add_grabber_optional:N G
+ \tl_put_right:Nn \l_xparse_signature_tl { {#1} }
+ \xparse_prepare_signature:N
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_add_type_l:w}
+% Finding \texttt{l} arguments is very simple: there is nothing to do
+% other than add the grabber.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xparse_add_type_l:w
+ {
+ \xparse_flush_m_args:
+ \xparse_add_grabber_mandatory:N l
+ \xparse_prepare_signature:N
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_add_type_m:w}
+% The \texttt{m} type is special as short arguments which are not
+% post-processed are simply counted at this stage. Thus there is a check
+% to see if either of these cases apply. If so, a one-argument grabber
+% is added to the signature. On the other hand, if a standard short
+% argument is required it is simply counted at this stage, to be
+% added later using \cs{xparse_flush_m_args:}.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xparse_add_type_m:w
+ {
+ \bool_if:nTF { \l_xparse_long_bool || \l_xparse_processor_bool }
+ {
+ \xparse_flush_m_args:
+ \xparse_add_grabber_mandatory:N m
+ }
+ { \int_incr:N \l_xparse_m_args_int }
+ \xparse_prepare_signature:N
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_add_type_t:w}
+% Setting up a \texttt{t} argument means collecting one token for the
+% test, and adding it along with the grabber to the signature.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_add_type_t:w #1
+ {
+ \xparse_flush_m_args:
+ \xparse_add_grabber_optional:N t
+ \tl_put_right:Nn \l_xparse_signature_tl { #1 }
+ \xparse_prepare_signature:N
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_add_type_u:w}
+% At the set up stage, the \texttt{u} type argument is identical to the
+% \texttt{G} type except for the name of the grabber function.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_add_type_u:w #1
+ {
+ \xparse_flush_m_args:
+ \xparse_add_grabber_mandatory:N u
+ \tl_put_right:Nn \l_xparse_signature_tl { {#1} }
+ \xparse_prepare_signature:N
+ }
+% \end{macrocode}
+%\end{macro}
+%
+% \begin{macro}{\xparse_check_and_add:N}
+% This function checks if the argument type actually exists and gives
+% an error if it doesn't.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xparse_check_and_add:N #1
+ {
+ \cs_if_free:cTF { xparse_add_type_ #1 :w }
+ {
+ \msg_error:nnx { xparse } { unknown-argument-type }
+ { \tl_to_str:n {#1} }
+ \xparse_add_type_m:w
+ }
+ { \use:c { xparse_add_type_ #1 :w } }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_count_mandatory:n}
+% \begin{macro}{\xparse_count_mandatory:N}
+% \begin{macro}[aux]{\xparse_count_mandatory_aux:N}
+% To count up mandatory arguments before the main parsing run, the
+% same approach is used. First, check if the current token is a
+% short-cut for another argument type. If it is, expand it and loop
+% again. If not, then look for a `counting' function to check the
+% argument type. No error is raised here if one is not found as one
+% will be raised by later code.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_count_mandatory:n #1
+ {
+ \int_zero:N \l_xparse_mandatory_args_int
+ \xparse_count_mandatory:N #1 \q_nil
+ }
+\cs_new_protected:Npn \xparse_count_mandatory:N #1
+ {
+ \quark_if_nil:NF #1
+ {
+ \prop_if_in:NnTF \c_xparse_shorthands_prop {#1}
+ {
+ \prop_get:NnN \c_xparse_shorthands_prop {#1} \l_xparse_tmp_tl
+ \exp_last_unbraced:NV \xparse_count_mandatory:N \l_xparse_tmp_tl
+ }
+ { \xparse_count_mandatory_aux:N #1 }
+ }
+ }
+\cs_new_protected:Npn \xparse_count_mandatory_aux:N #1
+ {
+ \cs_if_free:cTF { xparse_count_type_ #1 :w }
+ { \xparse_count_type_m:w }
+ { \use:c { xparse_count_type_ #1 :w } }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_count_type_>:w}
+% \begin{macro}{\xparse_count_type_+:w}
+% \begin{macro}{\xparse_count_type_d:w}
+% \begin{macro}{\xparse_count_type_D:w}
+% \begin{macro}{\xparse_count_type_g:w}
+% \begin{macro}{\xparse_count_type_G:w}
+% \begin{macro}{\xparse_count_type_l:w}
+% \begin{macro}{\xparse_count_type_m:w}
+% \begin{macro}{\xparse_count_type_t:w}
+% \begin{macro}{\xparse_count_type_u:w}
+% For counting the mandatory arguments, a function is provided for
+% each argument type that will mop any extra arguments and call the
+% loop function. Only the counting functions for mandatory arguments
+% actually do anything: the rest are simply there to ensure the loop
+% continues correctly.
+% \begin{macrocode}
+\cs_new_protected:cpn { xparse_count_type_>:w } #1
+ { \xparse_count_mandatory:N }
+\cs_new_protected_nopar:cpn { xparse_count_type_+:w }
+ { \xparse_count_mandatory:N }
+\cs_new_protected:Npn \xparse_count_type_d:w #1#2
+ { \xparse_count_mandatory:N }
+\cs_new_protected:Npn \xparse_count_type_D:w #1#2#3
+ { \xparse_count_mandatory:N }
+\cs_new_protected_nopar:Npn \xparse_count_type_g:w
+ { \xparse_count_mandatory:N }
+\cs_new_protected:Npn \xparse_count_type_G:w #1
+ { \xparse_count_mandatory:N }
+\cs_new_protected_nopar:Npn \xparse_count_type_l:w
+ {
+ \int_incr:N \l_xparse_mandatory_args_int
+ \xparse_count_mandatory:N
+ }
+\cs_new_protected_nopar:Npn \xparse_count_type_m:w
+ {
+ \int_incr:N \l_xparse_mandatory_args_int
+ \xparse_count_mandatory:N
+ }
+\cs_new_protected:Npn \xparse_count_type_t:w #1
+ { \xparse_count_mandatory:N }
+\cs_new_protected:Npn \xparse_count_type_u:w #1
+ {
+ \int_incr:N \l_xparse_mandatory_args_int
+ \xparse_count_mandatory:N
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_declare_cmd:Nnn}
+% \begin{macro}[aux]{\xparse_declare_cmd_aux:Nnn}
+% \begin{macro}[aux]{\xparse_declare_cmd_aux:cnn}
+% \begin{macro}[aux]{\xparse_declare_cmd_all_m:Nn}
+% \begin{macro}[aux]{\xparse_declare_cmd_mixed:Nn}
+% First, the signature is set up from the argument specification. There
+% is then a check: if only \texttt{m} arguments are needed (which
+% includes functions with no arguments at all) then the definition is
+% simple. On the other hand, if the signature is more complex then an
+% internal function actually contains the code with the user function
+% as a simple wrapper.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_declare_cmd:Nnn #1#2
+ {
+ \cs_if_exist:NTF #1
+ {
+ \msg_warning:nnxx { xparse } { redefine-command }
+ { \token_to_str:N #1 } { \tl_to_str:n {#2} }
+ }
+ {
+ \msg_info:nnxx { xparse } { define-command }
+ { \token_to_str:N #1 } { \tl_to_str:n {#2} }
+ }
+ \xparse_declare_cmd_aux:Nnn #1 {#2}
+ }
+\cs_new_protected:Npn \xparse_declare_cmd_aux:Nnn #1#2#3
+ {
+ \tl_clear_new:c { l_xparse_ \token_to_str:N #1 _arg_spec_tl }
+ \tl_set:cn { l_xparse_ \token_to_str:N #1 _arg_spec_tl } {#2}
+ \xparse_count_mandatory:n {#2}
+ \xparse_prepare_signature:n {#2}
+ \bool_if:NTF \l_xparse_m_only_bool
+ { \xparse_declare_cmd_all_m:Nn #1 {#3} }
+ { \xparse_declare_cmd_mixed:Nn #1 {#3} }
+ }
+\cs_generate_variant:Nn \xparse_declare_cmd_aux:Nnn { cnn }
+\cs_new_protected:Npn \xparse_declare_cmd_all_m:Nn #1#2
+ {
+ \cs_generate_from_arg_count:NNnn
+ #1 \cs_set_protected_nopar:Npn \l_xparse_total_args_int {#2}
+ }
+\cs_new_protected:Npn \xparse_declare_cmd_mixed:Nn #1#2
+ {
+ \group_begin:
+ \tex_escapechar:D 92 \scan_stop:
+ \tl_set:Nx \l_xparse_function_tl { \token_to_str:N #1 }
+ \exp_args:NNNo \group_end:
+ \tl_set:Nn \l_xparse_function_tl { \l_xparse_function_tl }
+ \cs_set_protected_nopar:Npx #1
+ {
+ \exp_not:n
+ {
+ \int_zero:N \l_xparse_processor_int
+ \tl_set:Nn \l_xparse_args_tl
+ }
+ { \exp_not:c { \l_xparse_function_tl } }
+ \exp_not:o \l_xparse_signature_tl
+ \exp_not:N \l_xparse_args_tl
+ }
+ \cs_generate_from_arg_count:cNnn
+ { \token_to_str:N #1 } \cs_set:Npn \l_xparse_total_args_int {#2}
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%
+% \begin{macro}{\xparse_declare_cmd_implementation:nNn}
+% Creating a stand-alone implementation using the \enquote{two-part}
+% mechanism is quite easy as this is just a wrapper for
+% \cs{cs_generate_from_arg_count:cNnn}.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_declare_cmd_implementation:nNn #1#2#3
+ {
+ \cs_generate_from_arg_count:cNnn { implementation_ #1 :w }
+ \cs_set:Npn {#2} {#3}
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_declare_cmd_interface:Nnn}
+% \begin{macro}[aux]{\xparse_declare_cmd_interface_all_m:Nn}
+% \begin{macro}[aux]{\xparse_declare_cmd_interface_mixed:Nn}
+% As with the basic function \cs{xparse_declare_cmd:Nnn}, there are
+% three things to do here. First, generate a signature from the
+% argument specification. Then use that to create a function which
+% will call the implementation part. Finally, a holder implementation
+% is created. As before, there is a short-cut for functions which only
+% have \texttt{m} type arguments.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_declare_cmd_interface:Nnn #1#2#3
+ {
+ \xparse_prepare_signature:n {#3}
+ \bool_if:NTF \l_xparse_m_only_bool
+ { \xparse_declare_cmd_interface_all_m:Nn #1 {#2} }
+ { \xparse_declare_cmd_interface_mixed:Nn #1 {#2} }
+ \cs_generate_from_arg_count:cNnn { implementation_ #2 :w }
+ \cs_set:Npn \l_xparse_total_args_int { '#2' }
+ }
+\cs_new_protected:Npn \xparse_declare_cmd_interface_all_m:Nn #1#2
+ {
+ \cs_generate_from_arg_count:NNnn
+ #1 \cs_set_protected_nopar:Npn \l_xparse_total_args_int
+ { \use:c { implementation_ #2 :w } }
+ }
+\cs_new_protected:Npn \xparse_declare_cmd_interface_mixed:Nn #1#2
+ {
+ \cs_set_protected_nopar:Npx #1
+ {
+ \exp_not:n
+ {
+ \int_zero:N \l_xparse_processor_int
+ \tl_set:Nn \l_xparse_args_tl
+ }
+ { \exp_not:c { \token_to_str:N #1 } }
+ \exp_not:o \l_xparse_signature_tl
+ \exp_not:N \l_xparse_args_tl
+ }
+ \cs_generate_from_arg_count:cNnn
+ { \token_to_str:N #1 } \cs_set:Npn \l_xparse_total_args_int
+ { \use:c { implementation_ #2 :w } }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_declare_env:nnnn}
+% The idea here is to make sure that the end of the environment has the
+% same arguments available as the beginning.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_declare_env:nnnn #1#2#3#4
+ {
+ \bool_set_true:N \l_xparse_environment_bool
+ \cs_if_exist:cTF {#1}
+ {
+ \msg_warning:nnxx { xparse } { redefine-environment }
+ { \tl_to_str:n {#1} } { \tl_to_str:n {#2} }
+ }
+ {
+ \msg_info:nnxx { xparse } { define-environment }
+ { \tl_to_str:n {#1} } { \tl_to_str:n {#2} }
+ }
+ \xparse_declare_cmd_aux:cnn { environment_begin_ #1 :w } {#2}
+ {
+ \group_begin:
+ \cs_set_protected_nopar:cpx { environment_end_ #1 :w }
+ {
+ \exp_not:c { environment_end_ #1 _aux:N }
+ \exp_not:o \l_xparse_args_tl
+ \group_end:
+ }
+ #3
+ }
+ \cs_set_protected_nopar:cpx { environment_end_ #1 : }
+ { \exp_not:c { environment_end_ #1 :w } }
+ \bool_set_false:N \l_xparse_environment_bool
+ \cs_set_nopar:cpx { environment_end_ #1 _aux:N } ##1
+ { \exp_not:c { environment_end_ #1 _aux :w } }
+ \cs_generate_from_arg_count:cNnn
+ { environment_end_ #1 _aux :w } \cs_set:Npn
+ \l_xparse_total_args_int {#4}
+ \cs_set_eq:cc {#1} { environment_begin_ #1 :w }
+ \cs_set_eq:cc { end #1 } { environment_end_ #1 : }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_flush_m_args:}
+% As \texttt{m} arguments are simply counted, there is a need to add
+% them to the token register in a block. As this function can only
+% be called if something other than \texttt{m} turns up, the flag can
+% be switched here. The total number of mandatory arguments added to
+% the signature is also decreased by the appropriate amount.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xparse_flush_m_args:
+ {
+ \cs_if_exist:cT { xparse_grab_m_ \int_use:N \l_xparse_m_args_int :w }
+ {
+ \tl_put_right:Nx \l_xparse_signature_tl
+ { \exp_not:c { xparse_grab_m_ \int_use:N \l_xparse_m_args_int :w } }
+ \int_set:Nn \l_xparse_mandatory_args_int
+ { \l_xparse_mandatory_args_int - \l_xparse_m_args_int }
+ }
+ \int_zero:N \l_xparse_m_args_int
+ \bool_set_false:N \l_xparse_m_only_bool
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[TF]{\xparse_if_no_value:n}
+% Tests for \cs{NoValue}.
+% \begin{macrocode}
+\prg_new_conditional:Npnn \xparse_if_no_value:n #1 { T , F , TF }
+ { \str_if_eq:nnTF {#1} { \NoValue } \prg_return_true: \prg_return_false: }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_prepare_signature:n}
+% Creating the signature is a case of working through the input and
+% turning into the output in \cs{l_xparse_signature_tl}. A track is
+% also kept of the total number of arguments. This function sets
+% everything up then hands off to the parser.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_prepare_signature:n #1
+ {
+ \bool_set_false:N \l_xparse_long_bool
+ \int_zero:N \l_xparse_m_args_int
+ \bool_if:NTF \l_xparse_environment_bool
+ { \bool_set_false:N \l_xparse_m_only_bool }
+ { \bool_set_true:N \l_xparse_m_only_bool }
+ \bool_set_false:N \l_xparse_processor_bool
+ \tl_clear:N \l_xparse_signature_tl
+ \int_zero:N \l_xparse_total_args_int
+ \xparse_prepare_signature:N #1 \q_nil
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_prepare_signature:N}
+% \begin{macro}[aux]{\xparse_prepare_signature_aux:N}
+% The main signature-preparation loop is in two parts, to keep the code
+% a little clearer. Most of the checks here is pretty clear, with a key
+% point to watch what is next on the stack so that the loop continues
+% correctly.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_prepare_signature:N #1
+ {
+ \bool_set_false:N \l_xparse_processor_bool
+ \xparse_prepare_signature_aux:N #1
+ }
+\cs_new_protected:Npn \xparse_prepare_signature_aux:N #1
+ {
+ \quark_if_nil:NTF #1
+ { \bool_if:NF \l_xparse_m_only_bool { \xparse_flush_m_args: } }
+ {
+ \prop_if_in:NnTF \c_xparse_shorthands_prop {#1}
+ {
+ \prop_get:NnN \c_xparse_shorthands_prop {#1} \l_xparse_tmp_tl
+ \exp_after:wN \xparse_prepare_signature:N \l_xparse_tmp_tl
+ }
+ {
+ \int_incr:N \l_xparse_total_args_int
+ \xparse_check_and_add:N #1
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_process_arg:n}
+% Processors are saved for use later during the grabbing process.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_process_arg:n #1
+ {
+ \int_incr:N \l_xparse_processor_int
+ \cs_set:cpn { xparse_processor_ \int_use:N \l_xparse_processor_int :n } ##1
+ { #1 {##1} }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{Grabbing arguments}
+%
+% \begin{macro}{\xparse_add_arg:n, \xparse_add_arg:V}
+% \begin{macro}[aux]{\xparse_add_arg_aux:n, \xparse_add_arg_aux:V}
+% The argument-storing system provides a single point for interfacing
+% with processors. They are done in a loop, counting downward. In this
+% way, the processor which was found last is executed first. The result
+% is that processors apply from right to left, as intended. Notice that
+% a set of braces are added back around the result of processing so that
+% the internal function will correctly pick up one argument for each
+% input argument.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_add_arg:n #1
+ {
+ \int_compare:nNnTF \l_xparse_processor_int = \c_zero
+ { \tl_put_right:Nn \l_xparse_args_tl { {#1} } }
+ {
+ \xparse_if_no_value:nTF {#1}
+ {
+ \int_zero:N \l_xparse_processor_int
+ \tl_put_right:Nn \l_xparse_args_tl { {#1} }
+ }
+ { \xparse_add_arg_aux:n {#1} }
+ }
+ }
+\cs_generate_variant:Nn \xparse_add_arg:n { V }
+\cs_new_protected:Npn \xparse_add_arg_aux:n #1
+ {
+ \tl_set_eq:NN \ProcessedArgument \l_xparse_arg_tl
+ \use:c { xparse_processor_ \int_use:N \l_xparse_processor_int :n } {#1}
+ \int_decr:N \l_xparse_processor_int
+ \int_compare:nNnTF \l_xparse_processor_int = \c_zero
+ {
+ \tl_put_right:Nx \l_xparse_args_tl
+ { { \exp_not:V \ProcessedArgument } }
+ }
+ { \xparse_add_arg_aux:V \ProcessedArgument }
+}
+\cs_generate_variant:Nn \xparse_add_arg_aux:n { V }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% All of the grabbers follow the same basic pattern. The initial
+% function sets up the appropriate information to define
+% \cs{parse_grab_arg:w} to grab the argument. This means determining
+% whether to use \cs{cs_set:Npn} or \cs{cs_set_nopar:Npn}, and for
+% optional arguments whether to skip spaces. In all cases,
+% \cs{xparse_grab_arg:w} is then called to actually do the grabbing.
+%
+% \begin{macro}{\xparse_grab_arg:w}
+% \begin{macro}[aux]{\xparse_grab_arg_aux_i:w}
+% \begin{macro}[aux]{\xparse_grab_arg_aux_ii:w}
+% Each time an argument is actually grabbed, \pkg{xparse} defines a
+% function to do it. In that way, long arguments from previous functions
+% can be included in the definition of the grabber function, so that
+% it does not raise an error if not long. The generic function used
+% for this is reserved here. A couple of auxiliary functions are also
+% needed in various places.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_grab_arg:w { }
+\cs_new_protected:Npn \xparse_grab_arg_aux_i:w { }
+\cs_new_protected:Npn \xparse_grab_arg_aux_ii:w { }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_grab_D:w}
+% \begin{macro}{\xparse_grab_D_long:w}
+% \begin{macro}{\xparse_grab_D_trailing:w}
+% \begin{macro}{\xparse_grab_D_long_trailing:w}
+% The generic delimited argument grabber. The auxiliary function does
+% a peek test before calling \cs{xparse_grab_arg:w}, so that the
+% optional nature of the argument works as expected.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_grab_D:w #1#2#3#4 \l_xparse_args_tl
+ {
+ \xparse_grab_D_aux:NNnnNn #1 #2 {#3} {#4} \cs_set_protected_nopar:Npn
+ { _ignore_spaces }
+ }
+\cs_new_protected:Npn \xparse_grab_D_long:w #1#2#3#4 \l_xparse_args_tl
+ {
+ \xparse_grab_D_aux:NNnnNn #1 #2 {#3} {#4} \cs_set_protected:Npn
+ { _ignore_spaces }
+ }
+\cs_new_protected:Npn \xparse_grab_D_trailing:w #1#2#3#4 \l_xparse_args_tl
+ { \xparse_grab_D_aux:NNnnNn #1 #2 {#3} {#4} \cs_set_protected_nopar:Npn { } }
+\cs_new_protected:Npn \xparse_grab_D_long_trailing:w #1#2#3#4 \l_xparse_args_tl
+ { \xparse_grab_D_aux:NNnnNn #1 #2 {#3} {#4} \cs_set_protected:Npn { } }
+% \end{macrocode}
+% \begin{macro}[aux]{\xparse_grab_D_aux:NNnnNn}
+% This is a bit complicated. The idea is that, in order to check for
+% nested optional argument tokens (\texttt{[[...]]} and so on) the
+% argument needs to be grabbed without removing any braces at all. If
+% this is not done, then cases like |[{[}]| fail. So after testing for
+% an optional argument, it is collected piece-wise. First, the opening
+% token is removed, then a check is made for a group. If it looks like
+% the entire argument is a group, then an extra set of braces are
+% added back in. The closing token is then used to collect everything
+% else. There is then a test to see if there is nesting, by looking
+% for a \enquote{spare} open-argument token. If that is found, things hand
+% off to a loop to deal with that.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_grab_D_aux:NNnnNn #1#2#3#4#5#6
+ {
+ #5 \xparse_grab_arg:w #1
+ {
+ \peek_meaning:NTF \c_group_begin_token
+ { \xparse_grab_arg_aux_i:w }
+ { \xparse_grab_arg_aux_ii:w }
+ }
+ #5 \xparse_grab_arg_aux_i:w ##1
+ {
+ \peek_charcode:NTF #2
+ { \xparse_grab_arg_aux_ii:w { {##1} } }
+ { \xparse_grab_arg_aux_ii:w {##1} }
+ }
+ #5 \xparse_grab_arg_aux_ii:w ##1 #2
+ {
+ \tl_if_in:nnTF {##1} {#1}
+ { \xparse_grab_D_nested:NNnnN #1 #2 {##1} {#4} #5 }
+ {
+ \xparse_add_arg:n {##1}
+ #4 \l_xparse_args_tl
+ }
+ }
+ \use:c { peek_charcode #6 :NTF } #1
+ { \xparse_grab_arg:w }
+ {
+ \xparse_add_arg:n {#3}
+ #4 \l_xparse_args_tl
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \begin{macro}[aux]{\xparse_grab_D_nested:NNnnN}
+% \begin{macro}{\l_xparse_nesting_a_tl}
+% \begin{macro}{\l_xparse_nesting_b_tl}
+% \begin{macro}{\q_xparse}
+% Catching nested optional arguments means more work. The aim here is
+% to collect up each pair of optional tokens without \TeX{} helping out,
+% and without counting anything. The code above will already have
+% removed the leading opening token and a closing token, but the
+% wrong one. The aim is then to work through the the material grabbed
+% so far and divide it up on each opening token, grabbing a closing
+% token to match (thus working in pairs). Once there are no opening
+% tokens, then there is a second check to see if there are any
+% opening tokens in the second part of the argument (for things
+% like |[][]|). Once everything has been found, the entire collected
+% material is added to the output as a single argument.
+% \begin{macrocode}
+\tl_new:N \l_xparse_nesting_a_tl
+\tl_new:N \l_xparse_nesting_b_tl
+\quark_new:N \q_xparse
+\cs_new_protected:Npn \xparse_grab_D_nested:NNnnN #1#2#3#4#5
+ {
+ \tl_clear:N \l_xparse_nesting_a_tl
+ \tl_clear:N \l_xparse_nesting_b_tl
+ #5 \xparse_grab_arg:w ##1 #1 ##2 \q_xparse ##3 #2
+ {
+ \tl_put_right:Nn \l_xparse_nesting_a_tl { ##1 #1 }
+ \tl_put_right:Nn \l_xparse_nesting_b_tl { #2 ##3 }
+ \tl_if_in:nnTF {##2} {#1}
+ { \xparse_grab_arg:w ##2 \q_xparse }
+ {
+ \tl_put_right:Nn \l_xparse_nesting_a_tl {##2}
+ \tl_if_in:NnTF \l_xparse_nesting_b_tl {#1}
+ {
+ \tl_set_eq:NN \l_xparse_tmp_tl \l_xparse_nesting_b_tl
+ \tl_clear:N \l_xparse_nesting_b_tl
+ \exp_after:wN \xparse_grab_arg:w \l_xparse_tmp_tl \q_xparse
+ }
+ {
+ \tl_put_right:No \l_xparse_nesting_a_tl
+ \l_xparse_nesting_b_tl
+ \xparse_add_arg:V \l_xparse_nesting_a_tl
+ #4 \l_xparse_args_tl
+ }
+ }
+ }
+ \xparse_grab_arg:w #3 \q_xparse
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_grab_G:w}
+% \begin{macro}{\xparse_grab_G_long:w}
+% \begin{macro}{\xparse_grab_G_trailing:w}
+% \begin{macro}{\xparse_grab_G_long_trailing:w}
+% \begin{macro}[aux]{\xparse_grab_G_aux:nnNn}
+% Optional groups are checked by meaning, so that the same code will
+% work with, for example, Con\TeX{}t-like input.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_grab_G:w #1#2 \l_xparse_args_tl
+ {
+ \xparse_grab_G_aux:nnNn {#1} {#2} \cs_set_protected_nopar:Npn
+ { _ignore_spaces }
+ }
+\cs_new_protected:Npn \xparse_grab_G_long:w #1#2 \l_xparse_args_tl
+ {
+ \xparse_grab_G_aux:nnNn {#1} {#2} \cs_set_protected:Npn { _ignore_spaces }
+ }
+\cs_new_protected:Npn \xparse_grab_G_trailing:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_G_aux:nnNn {#1} {#2} \cs_set_protected_nopar:Npn { } }
+\cs_new_protected:Npn \xparse_grab_G_long_trailing:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_G_aux:nnNn {#1} {#2} \cs_set_protected:Npn { } }
+\cs_new_protected:Npn \xparse_grab_G_aux:nnNn #1#2#3#4
+ {
+ #3 \xparse_grab_arg:w ##1
+ {
+ \xparse_add_arg:n {##1}
+ #2 \l_xparse_args_tl
+ }
+ \use:c { peek_meaning #4 :NTF } \c_group_begin_token
+ { \xparse_grab_arg:w }
+ {
+ \xparse_add_arg:n {#1}
+ #2 \l_xparse_args_tl
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_grab_l:w}
+% \begin{macro}{\xparse_grab_l_long:w}
+% \begin{macro}[aux]{\xparse_grab_l_aux:nN}
+% Argument grabbers for mandatory \TeX\ arguments are pretty simple.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_grab_l:w #1 \l_xparse_args_tl
+ { \xparse_grab_l_aux:nN {#1} \cs_set_protected_nopar:Npn }
+\cs_new_protected:Npn \xparse_grab_l_long:w #1 \l_xparse_args_tl
+ { \xparse_grab_l_aux:nN {#1} \cs_set_protected:Npn }
+\cs_new_protected:Npn \xparse_grab_l_aux:nN #1#2
+ {
+ #2 \xparse_grab_arg:w ##1##
+ {
+ \xparse_add_arg:n {##1}
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_grab_m:w}
+% \begin{macro}{\xparse_grab_m_long:w}
+% Collecting a single mandatory argument is quite easy.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_grab_m:w #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1
+ {
+ \xparse_add_arg:n {##1}
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:Npn \xparse_grab_m_long:w #1 \l_xparse_args_tl
+ {
+ \cs_set_protected:Npn \xparse_grab_arg:w ##1
+ {
+ \xparse_add_arg:n {##1}
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_grab_m_1:w}
+% \begin{macro}{\xparse_grab_m_2:w}
+% \begin{macro}{\xparse_grab_m_3:w}
+% \begin{macro}{\xparse_grab_m_4:w}
+% \begin{macro}{\xparse_grab_m_5:w}
+% \begin{macro}{\xparse_grab_m_6:w}
+% \begin{macro}{\xparse_grab_m_7:w}
+% \begin{macro}{\xparse_grab_m_8:w}
+% Grabbing 1--8 mandatory arguments. We don't need to worry about
+% nine arguments as this is only possible if everything is
+% mandatory. Each function has an auxiliary so that \cs{par} tokens
+% from other arguments still work.
+% \begin{macrocode}
+\cs_new_protected:cpn { xparse_grab_m_1:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1
+ {
+ \tl_put_right:Nn \l_xparse_args_tl { {##1} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_2:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2
+ {
+ \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_3:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3
+ {
+ \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} {##3} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_4:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4
+ {
+ \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} {##3} {##4} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_5:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4##5
+ {
+ \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} {##3} {##4} {##5} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_6:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4##5##6
+ {
+ \tl_put_right:Nn \l_xparse_args_tl
+ { {##1} {##2} {##3} {##4} {##5} {##6} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_7:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4##5##6##7
+ {
+ \tl_put_right:Nn \l_xparse_args_tl
+ { {##1} {##2} {##3} {##4} {##5} {##6} {##7} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_8:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4##5##6##7##8
+ {
+ \tl_put_right:Nn \l_xparse_args_tl
+ { {##1} {##2} {##3} {##4} {##5} {##6} {##7} {##8} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%\end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_grab_t:w}
+% \begin{macro}{\xparse_grab_t_long:w}
+% \begin{macro}{\xparse_grab_t_trailing:w}
+% \begin{macro}{\xparse_grab_t_long_trailing:w}
+% \begin{macro}[aux]{\xparse_grab_t_aux:NnNn}
+% Dealing with a token is quite easy. Check the match, remove the
+% token if needed and add a flag to the output.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_grab_t:w #1#2 \l_xparse_args_tl
+ {
+ \xparse_grab_t_aux:NnNn #1 {#2} \cs_set_protected_nopar:Npn
+ { _ignore_spaces }
+ }
+\cs_new_protected:Npn \xparse_grab_t_long:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_t_aux:NnNn #1 {#2} \cs_set_protected:Npn { _ignore_spaces } }
+\cs_new_protected:Npn \xparse_grab_t_trailing:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_t_aux:NnNn #1 {#2} \cs_set_protected_nopar:Npn { } }
+\cs_new_protected:Npn \xparse_grab_t_long_trailing:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_t_aux:NnNn #1 {#2} \cs_set_protected:Npn { } }
+\cs_new_protected:Npn \xparse_grab_t_aux:NnNn #1#2#3#4
+ {
+ #3 \xparse_grab_arg:w
+ {
+ \use:c { peek_charcode_remove #4 :NTF } #1
+ {
+ \xparse_add_arg:n { \BooleanTrue }
+ #2 \l_xparse_args_tl
+ }
+ {
+ \xparse_add_arg:n { \BooleanFalse }
+ #2 \l_xparse_args_tl
+ }
+ }
+ \xparse_grab_arg:w
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_grab_u:w}
+% \begin{macro}{\xparse_grab_u_long:w}
+% \begin{macro}[aux]{\xparse_grab_u_aux:NnN}
+% Grabbing up to a list of tokens is quite easy: define the grabber,
+% and then collect.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_grab_u:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_u_aux:NnN {#1} {#2} \cs_set_protected_nopar:Npn }
+\cs_new_protected:Npn \xparse_grab_u_long:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_u_aux:NnN {#1} {#2} \cs_set_protected:Npn }
+\cs_new_protected:Npn \xparse_grab_u_aux:NnN #1#2#3
+ {
+ #3 \xparse_grab_arg:w ##1 #1
+ {
+ \xparse_add_arg:n {##1}
+ #2 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \subsection{Argument processors}
+%
+% \begin{macro}{\xparse_process_to_str:n}
+% A basic argument processor: as much an example as anything else.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_process_to_str:n #1
+ { \tl_set:Nx \ProcessedArgument { \tl_to_str:n {#1} } }
+% \end{macrocode}
+%\end{macro}
+%
+% \begin{macro}{\xparse_bool_reverse:N}
+% A simple reversal.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_bool_reverse:N #1
+ {
+ \bool_if:NTF #1
+ { \tl_set:Nn \ProcessedArgument { \c_false_bool } }
+ { \tl_set:Nn \ProcessedArgument { \c_true_bool } }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\l_xparse_split_argument_tl}
+% \begin{macro}{\xparse_split_argument:nnn}
+% \begin{macro}[aux]{\xparse_split_argument_aux_i:w}
+% \begin{macro}[aux]{\xparse_split_argument_aux_ii:w}
+% \begin{macro}[aux]{\xparse_split_argument_aux_iii:w}
+% The idea of this function is to split the input $n + 1$ times using
+% a given token.
+% \begin{macrocode}
+\tl_new:N \l_xparse_split_argument_tl
+\group_begin:
+ \char_set_catcode_active:N \@
+ \cs_new_protected:Npn \xparse_split_argument:nnn #1#2#3
+ {
+ \tl_set:Nn \l_xparse_split_argument_tl {#3}
+ \group_begin:
+ \char_set_lccode:nn { `\@ } { `#2}
+ \tl_to_lowercase:n
+ {
+ \group_end:
+ \tl_replace_all_in:Nnn \l_xparse_split_argument_tl { @ } {#2}
+ }
+ \cs_set_protected:Npn \xparse_split_argument_aux_i:w
+ ##1 \q_mark ##2 #2 ##3 \q_stop
+ {
+ \tl_put_right:Nn \ProcessedArgument { {##2} }
+ ##1 \q_mark ##3 \q_stop
+ }
+ \cs_set_protected:Npn \xparse_split_argument_aux_iii:w
+ ##1 #2 ##2 \q_stop
+ {
+ \IfNoValueF {##1}
+ {
+ \msg_error:nnxxx { xparse } { split-excess-tokens }
+ { \tl_to_str:n {#2} } { \tl_to_str:n {#1} }
+ { \tl_to_str:n {#3} }
+ }
+ }
+ \tl_set:Nx \l_xparse_tmp_tl
+ {
+ \prg_replicate:nn { #1 + 1 }
+ { \xparse_split_argument_aux_i:w }
+ \xparse_split_argument_aux_ii:w
+ \exp_not:N \q_mark
+ \exp_not:o \l_xparse_split_argument_tl
+ \prg_replicate:nn {#1} { \exp_not:n {#2} \NoValue }
+ \exp_not:n { #2 \q_stop }
+ }
+ \l_xparse_tmp_tl
+ }
+\group_end:
+\cs_new_protected:Npn \xparse_split_argument_aux_i:w { }
+\cs_new_protected:Npn \xparse_split_argument_aux_ii:w
+ #1 \q_mark #2 \q_stop
+ {
+ \tl_if_empty:nF {#2}
+ { \xparse_split_argument_aux_iii:w #2 \q_stop }
+ }
+\cs_new_protected:Npn \xparse_split_argument_aux_iii:w { }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+%\begin{macro}{\l_xparse_split_list_tl}
+%\begin{macro}{\xparse_split_list:nn}
+%\begin{macro}{\xparse_split_list_aux:w}
+% Splitting a list is done again by first dealing with active
+% characters, then looping over the list using the same method as the
+% \cs{clist_map_\ldots} functions.
+% \begin{macrocode}
+\tl_new:N \l_xparse_split_list_tl
+\group_begin:
+ \char_set_catcode_active:N \@
+ \cs_new_protected:Npn \xparse_split_list:nn #1#2
+ {
+ \tl_set:Nn \l_xparse_split_list_tl {#2}
+ \group_begin:
+ \char_set_lccode:nn { `\@ } { `#1 }
+ \tl_to_lowercase:n
+ {
+ \group_end:
+ \tl_replace_all_in:Nnn \l_xparse_split_list_tl { @ } {#1}
+ }
+ \cs_set:Npn \xparse_split_list_aux:w ##1 #1
+ {
+ \quark_if_recursion_tail_stop:n {##1}
+ \tl_put_right:Nn \ProcessedArgument { {##1} }
+ \xparse_split_list_aux:w
+ }
+ \tl_if_empty:NTF \l_xparse_split_list_tl
+ { \tl_set:Nn \ProcessedArgument { { } } }
+ {
+ \tl_clear:N \ProcessedArgument
+ \exp_after:wN \xparse_split_list_aux:w
+ \l_xparse_split_list_tl #1
+ \q_recursion_tail #1 \q_recursion_stop
+ }
+ }
+\group_end:
+\cs_new_protected:Npn \xparse_split_list_aux:w { }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \subsection{Creating expandable functions}
+%
+% The trick here is to pass each grabbed argument along a chain of
+% auxiliary functions. Each one ultimately calls the next in the chain,
+% so that all of the arguments are passed along delimited using
+% \cs{q_xparse}. At the end of the chain, the marker is removed
+% so that the user-supplied code can be passed the correct number
+% of arguments. All of this is done by expansion!
+%
+% \begin{macro}{\xparse_exp_add_type_d:w}
+% As in the standard case, the trick here is to slot in the default
+% and treat as type \texttt{D}.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_exp_add_type_d:w #1#2
+ { \xparse_exp_add_type_D:w #1 #2 { \NoValue } }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_exp_add_type_D:w}
+% The most complex argument to grab in an expandable manner is the
+% general delimited one. First, a short-cut is set up in
+% \cs{l_xparse_tmp_tl} for the name of the current grabber function.
+% This is then created to grab one argument and test if it is equal
+% to the opening delimiter. If the test fails, the code adds the default
+% value and closing delimiter before `recycling' the argument. In either
+% case, the second auxiliary function is called. It finds the closing
+% delimiter and so the optional argument (if any). The function then
+% calls the next one in the chain, passing along the argument(s)
+% grabbed thus-far using \cs{q_xparse} as a marker.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_exp_add_type_D:w #1#2#3
+ {
+ \tl_set:Nx \l_xparse_tmp_tl
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_use:N \l_xparse_total_args_int
+ }
+ \xparse_exp_set:cpx { \l_xparse_tmp_tl } ##1 \q_xparse ##2
+ {
+ \exp_not:N \tl_if_head_eq_charcode:nNTF {##2} #1
+ {
+ \exp_not:c { \l_xparse_tmp_tl aux }
+ ##1 \exp_not:N \q_xparse
+ }
+ {
+ \exp_not:c { \l_xparse_tmp_tl aux }
+ ##1 \exp_not:N \q_xparse #3 #2 {##2}
+ }
+ }
+ \xparse_exp_set:cpx { \l_xparse_tmp_tl aux} ##1 \q_xparse ##2 #2
+ {
+ \exp_not:c
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_eval:n { \l_xparse_total_args_int + 1 }
+ }
+ ##1 {##2} \exp_not:N \q_xparse
+ }
+ \xparse_exp_prepare_function:N
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_exp_add_type_l:w}
+% \begin{macro}{\xparse_exp_add_type_m:w}
+% Gathering \texttt{l} and \texttt{m} arguments is almost the same.
+% The grabber for the current argument is created to simply get the
+% necessary argument and pass it along with any others through to the
+% next function in the chain.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xparse_exp_add_type_l:w
+ {
+ \xparse_exp_set:cpx
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_use:N \l_xparse_total_args_int
+ }
+ ##1 \q_xparse ##2##
+ {
+ \exp_not:c
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_eval:n { \l_xparse_total_args_int + 1 }
+ }
+ ##1 {##2} \exp_not:N \q_xparse
+ }
+ \xparse_exp_prepare_function:N
+ }
+\cs_new_protected_nopar:Npn \xparse_exp_add_type_m:w
+ {
+ \int_incr:N \l_xparse_m_args_int
+ \xparse_exp_set:cpx
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_use:N \l_xparse_total_args_int
+ }
+ ##1 \q_xparse ##2
+ {
+ \exp_not:c
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_eval:n { \l_xparse_total_args_int + 1 }
+ }
+ ##1 {##2} \exp_not:N \q_xparse
+ }
+ \xparse_exp_prepare_function:N
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_exp_add_type_t:w}
+% Looking for a single token is a simpler version of the \texttt{D}
+% code. The same idea of picking up one argument is used, but there is
+% no need for a second function as there is no closing token to find. So
+% either \cs{BooleanTrue} or \cs{BooleanFalse} are added to the list of
+% arguments. In the later case, the grabber argument must be `recycled'.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_exp_add_type_t:w #1
+ {
+ \tl_set:Nx \l_xparse_tmp_tl
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_eval:n { \l_xparse_total_args_int + 1 }
+ }
+ \xparse_exp_set:cpx
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_use:N \l_xparse_total_args_int
+ }
+ ##1 \q_xparse ##2
+ {
+ \exp_not:N \tl_if_head_eq_charcode:nNTF {##2} #1
+ {
+ \exp_not:c { \l_xparse_tmp_tl }
+ ##1 \exp_not:n { { \BooleanTrue } \q_xparse }
+ }
+ {
+ \exp_not:c { \l_xparse_tmp_tl }
+ ##1 \exp_not:n { { \BooleanFalse } \q_xparse {##2} }
+ }
+ }
+ \xparse_exp_prepare_function:N
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_exp_add_type_u:w}
+% Setting up for a \texttt{u} argument is a case of defining the
+% grabber for the current argument in a delimited fashion. The rest of
+% the process is as the other grabbers: add to the chain and call the
+% next function.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_exp_add_type_u:w #1
+ {
+ \xparse_exp_set:cpx
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_use:N \l_xparse_total_args_int
+ }
+ ##1 \q_xparse ##2 #1
+ {
+ \exp_not:c
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_eval:n { \l_xparse_total_args_int + 1 }
+ }
+ ##1 {##2} \exp_not:N \q_xparse
+ }
+ \xparse_exp_prepare_function:N
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_exp_check_and_add:N}
+% Virtually identical to the normal version, except calling the
+% expandable \texttt{add} functions rather than the standard versions.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xparse_exp_check_and_add:N #1
+ {
+ \cs_if_free:cTF { xparse_exp_add_type_ #1 :w }
+ {
+ \msg_error:nnx { xparse } { unknown-argument-type }
+ { \tl_to_str:n {#1} }
+ \tl_set:Nn \l_xparse_last_arg_tl { m }
+ \xparse_exp_add_type_m:w
+ }
+ {
+ \tl_set:Nn \l_xparse_last_arg_tl {#1}
+ \use:c { xparse_exp_add_type_ #1 :w }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xparse_exp_declare_cmd:Nnn}
+% \begin{macro}[aux]{\xparse_exp_declare_cmd_all_m:Nn}
+% \begin{macro}[aux]{\xparse_exp_declare_cmd_mixed:Nn}
+% \begin{macro}[aux]{\xparse_exp_declare_cmd_mixed_aux:Nn}
+% The overall scheme here is very different from the standard method.
+% For each argument, an internal function is created to grab an argument
+% and pass along previous ones. Each `daisy chains' to call the next
+% one in the sequence. Thus at the end of the chain, an extra `argument'
+% function is included to unwind the chain and pass data to the the
+% internal function containing the actual code. If all of the arguments
+% are type \texttt{m}, then the same tick is used as in the standard
+% version. The \texttt{x} in the lead-off and mop-up functions makes
+% sure that the braces around the first argument are not lost.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_exp_declare_cmd:Nnn #1#2#3
+ {
+ \cs_if_exist:NTF #1
+ {
+ \msg_warning:nnxx { xparse } { redefine-command }
+ { \token_to_str:N #1 } { \tl_to_str:n {#2} }
+ }
+ {
+ \msg_info:nnxx { xparse } { define-command }
+ { \token_to_str:N #1 } { \tl_to_str:n {#2} }
+ }
+ \group_begin:
+ \tex_escapechar:D 92 \scan_stop:
+ \tl_set:Nx \l_xparse_function_tl { \token_to_str:N #1}
+ \exp_args:NNNo \group_end:
+ \tl_set:Nn \l_xparse_function_tl { \l_xparse_function_tl }
+ \xparse_exp_prepare_function:n {#2}
+ \int_compare:nNnTF \l_xparse_total_args_int = \l_xparse_m_args_int
+ { \xparse_exp_declare_cmd_all_m:Nn #1 {#3} }
+ { \xparse_exp_declare_cmd_mixed:Nn #1 {#3} }
+ }
+\cs_new_protected:Npn \xparse_exp_declare_cmd_all_m:Nn #1#2
+ {
+ \bool_if:NTF \l_xparse_long_bool
+ {
+ \cs_generate_from_arg_count:NNnn
+ #1 \cs_set:Npn \l_xparse_total_args_int {#2}
+ }
+ {
+ \cs_generate_from_arg_count:NNnn
+ #1 \cs_set_nopar:Npn \l_xparse_total_args_int {#2}
+ }
+ }
+\cs_new_protected:Npn \xparse_exp_declare_cmd_mixed:Nn #1#2
+ {
+ \tl_if_in:noTF { l m u } \l_xparse_last_arg_tl
+ { \xparse_exp_declare_cmd_mixed_aux:Nn #1 {#2} }
+ { \msg_error:nn { xparse } { expandable-ending-optional } }
+ }
+\cs_new_protected:Npn \xparse_exp_declare_cmd_mixed_aux:Nn #1#2
+ {
+ \cs_set_nopar:Npx #1
+ { \exp_not:c { \token_to_str:N #1 1 } x \exp_not:N \q_xparse }
+ \cs_set_nopar:cpx
+ { \token_to_str:N #1 \int_eval:n { \l_xparse_total_args_int + 1 } }
+ x ##1 \q_xparse
+ { \exp_not:c { \token_to_str:N #1 } ##1 }
+ \cs_generate_from_arg_count:cNnn
+ { \token_to_str:N #1 } \cs_set:Npn \l_xparse_total_args_int {#2}
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_exp_prepare_function:n}
+% \begin{macro}[aux]{\xparse_exp_prepare_function_aux:n}
+% A couple of early validation tests. Processors are forbidden, as are
+% \texttt{g}, \texttt{l} and \texttt{u} arguments (the later more for
+% ease than any technical reason).
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_exp_prepare_function:n #1
+ {
+ \bool_set_false:N \l_xparse_error_bool
+ \tl_if_in:nnT {#1} { > }
+ {
+ \msg_error:nnx { xparse } { processor-in-expandable }
+ { \tl_to_str:n {#1} }
+ \bool_set_true:N \l_xparse_error_bool
+ }
+ \tl_if_in:nnT {#1} { g }
+ {
+ \msg_error:nnx { xparse } { grouped-in-expandable }
+ { g } { \tl_to_str:n {#1} }
+ \bool_set_true:N \l_xparse_error_bool
+ }
+ \tl_if_in:nnT {#1} { G }
+ {
+ \msg_error:nnx { xparse } { grouped-in-expandable }
+ { G } { \tl_to_str:n {#1} }
+ \bool_set_true:N \l_xparse_error_bool
+ }
+ \bool_if:NF \l_xparse_error_bool
+ { \xparse_exp_prepare_function_aux:n {#1} }
+ }
+\cs_new_protected:Npn \xparse_exp_prepare_function_aux:n #1
+ {
+ \cs_set_eq:NN \xparse_prepare_next:w \xparse_exp_prepare_function:N
+ \cs_set_eq:NN \xparse_exp_set:cpx \cs_set_nopar:cpx
+ \bool_set_false:N \l_xparse_long_bool
+ \int_zero:N \l_xparse_m_args_int
+ \int_zero:N \l_xparse_total_args_int
+ \tl_if_in:nnT {#1} { + }
+ {
+ \bool_set_true:N \l_xparse_long_bool
+ \cs_set_eq:NN \xparse_exp_set:cpx \cs_set:cpx
+ }
+ \xparse_exp_prepare_function:N #1 \q_nil
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_exp_prepare_function:N}
+% \begin{macro}[aux]{\xparse_exp_prepare_function_long:N}
+% \begin{macro}[aux]{\xparse_exp_prepare_function_short:N}
+% Preparing functions is a case of reading the signature, as in the
+% normal case. However, everything has to be either short or long, and
+% so there is an extra step to make sure that once one \texttt{+} has
+% been seen everything has one. That detour then takes us back to
+% a standard looping concept.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_exp_prepare_function:N #1
+ {
+ \bool_if:NTF \l_xparse_long_bool
+ { \xparse_exp_prepare_function_long:N #1 }
+ { \xparse_exp_prepare_function_short:N #1 }
+}
+\cs_new_protected:Npn \xparse_exp_prepare_function_long:N #1
+ {
+ \quark_if_nil:NF #1
+ {
+ \str_if_eq:nnTF {#1} { + }
+ { \xparse_exp_prepare_function_short:N }
+ {
+ \msg_error:nn { xparse } { inconsistent-long }
+ \xparse_exp_prepare_function_short:N #1
+ }
+ }
+ }
+\cs_new_protected:Npn \xparse_exp_prepare_function_short:N #1
+ {
+ \quark_if_nil:NF #1
+ {
+ \prop_if_in:NnTF \c_xparse_shorthands_prop {#1}
+ {
+ \prop_get:NnN \c_xparse_shorthands_prop {#1} \l_xparse_tmp_tl
+ \bool_if:NT \l_xparse_long_bool
+ { \tl_put_left:Nn \l_xparse_tmp_tl { + } }
+ \exp_after:wN \xparse_exp_prepare_function:N \l_xparse_tmp_tl
+ }
+ {
+ \int_incr:N \l_xparse_total_args_int
+ \xparse_exp_check_and_add:N #1
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_exp_set:cpx}
+% A short-cut to save constantly re-testing \cs{l_xparse_long_bool}.
+% \begin{macrocode}
+\cs_new_eq:NN \xparse_exp_set:cpx \cs_set_nopar:cpx
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{Access to the argument specification}
+%
+% \begin{macro}{\xparse_get_arg_spec:N}
+% \begin{macro}{\xparse_get_arg_spec:n}
+% \begin{macro}{\ArgumentSpecification}
+% Recovering the argument specification is also trivial, using the
+% \cs{tl_set_eq:cN} function.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_get_arg_spec:N #1
+ {
+ \cs_if_exist:cTF { l_xparse_ \token_to_str:N #1 _arg_spec_tl }
+ {
+ \tl_set_eq:Nc \ArgumentSpecification
+ { l_xparse_ \token_to_str:N #1 _arg_spec_tl }
+ }
+ {
+ \msg_error:nnx { xparse } { unknown-document-command }
+ { \token_to_str:N #1 }
+ }
+ }
+\cs_new_protected:Npn \xparse_get_arg_spec:n #1
+ {
+ \cs_if_exist:cTF { l_xparse_ #1 _arg_spec_tl }
+ { \tl_set_eq:Nc \ArgumentSpecification { l_xparse_ #1 _arg_spec_tl } }
+ {
+ \msg_error:nnx { xparse } { unknown-document-environment }
+ { \tl_to_str:n {#1} }
+ }
+ }
+\tl_new:N \ArgumentSpecification
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xparse_show_arg_spec:N}
+% \begin{macro}{\xparse_show_arg_spec:n}
+% Showing the argument specification simply means finding it and then
+% calling the \cs{tl_show:c} function.
+% \begin{macrocode}
+\cs_new_protected:Npn \xparse_show_arg_spec:N #1
+ {
+ \cs_if_exist:cTF { l_xparse_ \token_to_str:N #1 _arg_spec_tl }
+ {
+ \tl_set_eq:Nc \ArgumentSpecification
+ { l_xparse_ \token_to_str:N #1 _arg_spec_tl }
+ \tl_show:N \ArgumentSpecification
+ }
+ {
+ \msg_error:nnx { xparse } { unknown-document-command }
+ { \token_to_str:N #1 }
+ }
+ }
+\cs_new_protected:Npn \xparse_show_arg_spec:n #1
+ {
+ \cs_if_exist:cTF { l_xparse_ #1 _arg_spec_tl }
+ {
+ \tl_set_eq:Nc \ArgumentSpecification { l_xparse_ #1 _arg_spec_tl }
+ \tl_show:N \ArgumentSpecification
+ }
+ {
+ \msg_error:nnx { xparse } { unknown-document-environment }
+ { \tl_to_str:n {#1} }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+%\subsection{Messages}
+%
+% Some messages intended as errors.
+% \begin{macrocode}
+\msg_new:nnnn { xparse } { command-already-defined }
+ { Command~'#1'~already~defined! }
+ {
+ You~have~used~\NewDocumentCommand
+ with~a~command~that~already~has~a~definition. \\
+ The~existing~definition~of~'#1'~will~be~overwritten.
+ }
+\msg_new:nnnn { xparse } { command-not-yet-defined }
+ { Command ~'#1'~not~yet~defined! }
+ {
+ You~have~used~\RenewDocumentCommand
+ with~a~command~that~was~never~defined.\\
+ A~new~command~'#1'~will~be~created.
+ }
+\msg_new:nnnn { xparse } { environment-already-defined }
+ { Environment~'#1'~already~defined! }
+ {
+ You~have~used~\NewDocumentEnvironment
+ with~an~environment~that~already~has~a~definition.\\
+ The~existing~definition~of~'#1'~will~be~overwritten.
+ }
+\msg_new:nnnn { xparse } { environment-mismatch }
+ { Mismatch~between~start~and~end~of~environment. }
+ {
+ The~current~environment~is~called~'#1',~but~you~have~tried~to~
+ end~one~called~'#2'.~Environments~have~to~be~properly~nested.
+ }
+\msg_new:nnnn { xparse } { environment-not-yet-defined }
+ { Environment~'#1'~not~yet~defined! }
+ {
+ You~have~used~\RenewDocumentEnvironment
+ with~an~environment~that~was~never~defined.\\
+ A~new~environment~'#1'~will~be~created.
+ }
+\msg_new:nnnn { xparse } { environment-unknown }
+ { Environment~'#1'~undefined. }
+ {
+ You~have~tried~to~start~an~environment~called~'#1',~
+ but~this~has~never~been~defined.\\
+ The~command~will~be~ignored.
+ }
+\msg_new:nnnn { xparse } { expandable-ending-optional }
+ { Signature~for~expandable~command~ends~with~optional~argument. }
+ {
+ \c_msg_coding_error_text_tl
+ Expandable~commands~must~have~a~final~mandatory~argument~
+ (or~no~arguments~at~all).~You~cannot~have~a~terminal~optional~
+ argument~with~expandable~commands.
+ }
+\msg_new:nnnn { xparse } { grouped-in-expandable }
+ { Argument~specifier~'#1'~forbidden~in~expandable~commands. }
+ {
+ \c_msg_coding_error_text_tl
+ Argument~specification~'#2'~contains~the~optional~grouped~
+ argument~'#1':~
+ this~is only~supported~for~standard~robust~functions.
+ }
+\msg_new:nnnn { xparse } { inconsistent-long }
+ { Inconsistent~long~arguments~for~expandable~command. }
+ {
+ \c_msg_coding_error_text_tl
+ The~arguments~for~an~expandable~command~must~either~all~be~
+ short~or~all~be~long.~You~have~tried~to~mix~the~two~types.
+ }
+\msg_new:nnnn { xparse } { processor-in-expandable }
+ { Argument~processors~cannot~be~used~with~expandable~functions. }
+ {
+ \c_msg_coding_error_text_tl
+ Argument~specification~'#1'~contains~a~processor~function:~
+ this~is~only~supported~for~standard~robust~functions.
+ }
+\msg_new:nnnn { xparse } { split-excess-tokens }
+ { Too~many~'#1'~tokens~when~trying~to~split~argument. }
+ {
+ LaTeX~was~asked~to~split~the~input~'#3'~
+ at~each~occurrence~of~the~token~'#1',~up~to~a~maximum~of~#2~parts.~
+ There~were~too~many~'#1'~tokens.
+ }
+\msg_new:nnnn { xparse } { unknown-argument-type }
+ { Unknown~argument~type~'#1'~replaced~by~'m'. }
+ {
+ \c_msg_coding_error_text_tl
+ The~letter~'#1'~does~not~specify~a~known~argument~type.~
+ LaTeX~will~assume~you~want~a~standard~mandatory~argument~(type~'m').
+ }
+\msg_new:nnnn { xparse } { unknown-document-command }
+ { Unknown~document~command~'#1'. }
+ {
+ You~have~asked~for~the~argument~specification~for~a~command~'#1',~
+ but~this~is~not~a~document~command.
+ }
+\msg_new:nnnn { xparse } { unknown-document-environment }
+ { Unknown~document~environment~'#1'. }
+ {
+ You~have~asked~for~the~argument~specification~for~a~command~'#1',~
+ but~this~is~not~a~document~environment.
+ }
+% \end{macrocode}
+%
+% Intended more for information.
+% \begin{macrocode}
+\msg_new:nnn { xparse } { define-command }
+ {
+ Defining~document~command~#1~
+ with~arg.~spec.~'#2'~\msg_line_context:.
+ }
+\msg_new:nnn { xparse } { define-environment }
+ {
+ Defining~document~environment~'#1'~
+ with~arg.~spec.~'#2'~\msg_line_context:.
+ }
+\msg_new:nnn { xparse } { redefine-command }
+ {
+ Redefining~document~command~#1~
+ with~arg.~spec.~'#2'~\msg_line_context:.
+ }
+\msg_new:nnn { xparse } { redefine-environment }
+ {
+ Redefining~document~environment~'#1'~
+ with~arg.~spec.~'#2'~\msg_line_context:.
+ }
+% \end{macrocode}
+%
+% \subsection{User functions}
+%
+% The user functions are more or less just the internal functions
+% renamed.
+%
+% \begin{macro}{\BooleanFalse}
+% \begin{macro}{\BooleanTrue}
+% Design-space names for the Boolean values.
+% \begin{macrocode}
+\cs_new_eq:NN \BooleanFalse \c_false_bool
+\cs_new_eq:NN \BooleanTrue \c_true_bool
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\DeclareDocumentCommand}
+% \begin{macro}{\NewDocumentCommand}
+% \begin{macro}{\RenewDocumentCommand}
+% \begin{macro}{\ProvideDocumentCommand}
+% The user macros are pretty simple wrappers around the internal ones.
+% \begin{macrocode}
+\cs_new_protected:Npn \DeclareDocumentCommand #1#2#3
+ { \xparse_declare_cmd:Nnn #1 {#2} {#3} }
+\cs_new_protected:Npn \NewDocumentCommand #1#2#3
+ {
+ \cs_if_exist:NTF #1
+ {
+ \msg_error:nnx { xparse } { command-already-defined }
+ { \token_to_str:N #1 }
+ }
+ { \xparse_declare_cmd:Nnn #1 {#2} {#3} }
+ }
+\cs_new_protected:Npn \RenewDocumentCommand #1#2#3
+ {
+ \cs_if_exist:NTF #1
+ { \xparse_declare_cmd_aux:Nnn #1 {#2} {#3} }
+ {
+ \msg_error:nnx { xparse } { command-not-yet-defined }
+ { \token_to_str:N #1 }
+ }
+ }
+\cs_new_protected:Npn \ProvideDocumentCommand #1#2#3
+ { \cs_if_exist:NF #1 { \xparse_declare_cmd:Nnn #1 {#2} {#3} } }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\DeclareDocumentCommandImplementation}
+% \begin{macro}{\DeclareDocumentCommandInterface}
+% The separate implementation/interface system is again pretty simple
+% to create at the outer layer.
+% \begin{macrocode}
+\cs_new_protected:Npn \DeclareDocumentCommandImplementation #1#2#3
+ { \xparse_declare_cmd_implementation:nNn {#1} #2 {#3} }
+\cs_new_protected:Npn \DeclareDocumentCommandInterface #1#2#3
+ { \xparse_declare_cmd_interface:Nnn #1 {#2} {#3} }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\DeclareDocumentEnvironment}
+% \begin{macro}{\NewDocumentEnvironment}
+% \begin{macro}{\RenewDocumentEnvironment}
+% \begin{macro}{\ProvideDocumentEnvironment}
+% Very similar for environments.
+% \begin{macrocode}
+\cs_new_protected:Npn \DeclareDocumentEnvironment #1#2#3#4
+ { \xparse_declare_env:nnnn {#1} {#2} {#3} {#4} }
+\cs_new_protected:Npn \NewDocumentEnvironment #1#2#3#4
+ {
+ \cs_if_exist:cTF {#1}
+ { \msg_error:nnx { xparse } { environment-already-defined } {#1} }
+ { \xparse_declare_env:nnnn {#1} {#2} {#3} {#4} }
+}
+\cs_new_protected:Npn \RenewDocumentEnvironment #1#2#3#4
+ {
+ \cs_if_exist:cTF {#1}
+ { \xparse_declare_env:nnnn {#1} {#2} {#3} {#4} }
+ { \msg_error:nnx { xparse } { environment-not-yet-defined } {#1} }
+ }
+\cs_new_protected:Npn \ProvideDocumentEnvironment #1#2#3#4
+ { \cs_if_exist:cF { #1 } { \xparse_declare_env:nnnn {#1} {#2} {#3} {#4} } }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\DeclareExpandableDocumentCommand}
+% The expandable version of the basic function is essentially the same.
+% \begin{macrocode}
+\cs_new_protected:Npn \DeclareExpandableDocumentCommand #1#2#3
+ { \xparse_exp_declare_cmd:Nnn #1 {#2} {#3} }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[TF]{\IfBoolean}
+% The logical \meta{true} and \meta{false} statements are just the
+% normal \cs{c_true_bool} and \cs{c_false_bool}, so testing for them is
+% done with the \cs{bool_if:NTF} functions from \textsf{l3prg}.
+% \begin{macrocode}
+\cs_new_eq:NN \IfBooleanTF \bool_if:NTF
+\cs_new_eq:NN \IfBooleanT \bool_if:NT
+\cs_new_eq:NN \IfBooleanF \bool_if:NF
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[TF]{\IfNoValue}
+% Simple re-naming.
+% \begin{macrocode}
+\cs_new_eq:NN \IfNoValueF \xparse_if_no_value:nF
+\cs_new_eq:NN \IfNoValueT \xparse_if_no_value:nT
+\cs_new_eq:NN \IfNoValueTF \xparse_if_no_value:nTF
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}[TF]{\IfValue}
+% Inverted logic.
+% \begin{macrocode}
+\cs_set:Npn \IfValueF { \xparse_if_no_value:nT }
+\cs_set:Npn \IfValueT { \xparse_if_no_value:nF }
+\cs_set:Npn \IfValueTF #1#2#3 { \xparse_if_no_value:nTF {#1} {#3} {#2} }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{variable}{\NoValue}
+% The marker for no value being give: this can be typeset safely.
+% This is coded by hand as making it \cs{protected} ensures that it
+% will not turn into anything else by accident.
+% \begin{macrocode}
+\cs_new_protected:Npn \NoValue { -NoValue- }
+% \end{macrocode}
+%\end{variable}
+%
+% \begin{macro}{\ProcessedArgument}
+% Processed arguments are returned using this name, which is reserved
+% here although the definition will change.
+% \begin{macrocode}
+\tl_new:N \ProcessedArgument
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\ReverseBoolean}
+% A processor to reverse the logic for token detection.
+% \begin{macrocode}
+\cs_new_eq:NN \ReverseBoolean \xparse_bool_reverse:N
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\SplitArgument}
+% \begin{macro}{\SplitList}
+% Another simple copy.
+% \begin{macrocode}
+\cs_new_eq:NN \SplitArgument \xparse_split_argument:nnn
+\cs_new_eq:NN \SplitList \xparse_split_list:nn
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\GetDocumentCommandArgSpec}
+% \begin{macro}{\GetDocumentEnvironmentArgSpec}
+% \begin{macro}{\ShowDocumentCommandArgSpec}
+% \begin{macro}{\ShowDocumentEnvironmentArgSpec}
+% More simple mappings.
+% \begin{macrocode}
+\cs_new_eq:NN \GetDocumentCommandArgSpec \xparse_get_arg_spec:N
+\cs_new_eq:NN \GetDocumentEnvironmmentArgSpec \xparse_get_arg_spec:n
+\cs_new_eq:NN \ShowDocumentCommandArgSpec \xparse_show_arg_spec:N
+\cs_new_eq:NN \ShowDocumentEnvironmentArgSpec \xparse_show_arg_spec:n
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \subsection{Package options}
+%
+% A faked key--value option to keep the log clean. Not yet perfect, but
+% better than nothing.
+% \begin{macrocode}
+\DeclareOption { log-declarations = true } { }
+\DeclareOption { log-declarations = false }
+ {
+ \msg_redirect_module:nnn { xparse } { info } { none }
+ \msg_redirect_module:nnn { xparse } { warning } { none }
+ }
+\DeclareOption { log-declarations } { }
+\ProcessOptions \scan_stop:
+% \end{macrocode}
+%
+% \begin{macrocode}
+%</package>
+% \end{macrocode}
+%
+% \end{implementation}
+%
+% \PrintIndex
diff --git a/Master/texmf-dist/source/latex/l3packages/xparse/xparse.ins b/Master/texmf-dist/source/latex/l3packages/xparse/xparse.ins
new file mode 100644
index 00000000000..995ddbb8ff0
--- /dev/null
+++ b/Master/texmf-dist/source/latex/l3packages/xparse/xparse.ins
@@ -0,0 +1,40 @@
+\iffalse meta-comment
+
+File xparse.ins Copyright (C) 2000-2011 The LaTeX3 Project
+
+It may be distributed and/or modified under the conditions of the
+LaTeX Project Public License (LPPL), either version 1.3c of this
+license or (at your option) any later version. The latest version
+of this license is in the file
+
+ http://www.latex-project.org/lppl.txt
+
+This file is part of the "l3packages bundle" (The Work in LPPL)
+and all files in that bundle must be distributed together.
+
+The released version of this bundle is available from CTAN.
+
+\fi
+
+\input docstrip.tex
+\askforoverwritefalse
+
+\preamble
+
+EXPERIMENTAL CODE
+
+Do not distribute this file without also distributing the
+source files specified above.
+
+Do not distribute a modified version of this file.
+
+\endpreamble
+% stop docstrip adding \endinput
+\postamble
+\endpostamble
+
+\keepsilent
+
+\generate{\file{xparse.sty} {\from{xparse.dtx} {package}}}
+
+\endbatchfile
diff --git a/Master/texmf-dist/source/latex/l3packages/xtemplate/xtemplate.dtx b/Master/texmf-dist/source/latex/l3packages/xtemplate/xtemplate.dtx
new file mode 100644
index 00000000000..bdca9d69f82
--- /dev/null
+++ b/Master/texmf-dist/source/latex/l3packages/xtemplate/xtemplate.dtx
@@ -0,0 +1,2848 @@
+% \iffalse meta-comment
+%
+%% File: xtemplate.dtx (C) Copyright 1999 Frank Mittelbach, Chris Rowley,
+%% David Carlisle
+%% (C) Copyright 2004-2010 Frank Mittelbach,
+%% The LaTeX3 Project
+%% (C) Copyright 2011 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3packages bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+%
+%<*driver|package>
+\RequirePackage{expl3}
+\GetIdInfo$Id: xtemplate.dtx 2492 2011-07-02 13:40:38Z joseph $
+ {L3 Experimental prototype document functions}
+%</driver|package>
+%<*driver>
+\documentclass[full]{l3doc}
+\usepackage{amstext}
+\begin{document}
+ \DocInput{\jobname.dtx}
+\end{document}
+%</driver>
+% \fi
+%
+% \title{^^A
+% The \textsf{xtemplate} package\\ Prototype document functions^^A
+% \thanks{This file describes v\ExplFileVersion,
+% last revised \ExplFileDate.}^^A
+% }
+%
+% \author{^^A
+% The \LaTeX3 Project\thanks
+% {^^A
+% E-mail:
+% \href{mailto:latex-team@latex-project.org}
+% {latex-team@latex-project.org}^^A
+% }^^A
+% }
+%
+% \date{Released \ExplFileDate}
+%
+% \maketitle
+%
+% \begin{documentation}
+%
+% There are three broad \enquote{layers} between putting down ideas into
+% a source file and ending up with a typeset document. These layers of
+% document writing are
+% \begin{enumerate}
+% \item authoring of the text with mark-up;
+% \item document layout design;
+% \item implementation (with \TeX{} programming) of the design.
+% \end{enumerate}
+% We write the text as an author, and we see the visual output of the design
+% after the document is generated; the \TeX{} implementation in the middle is
+% the glue between the two.
+%
+% \LaTeX{}'s greatest success has been to standardise a system of mark-up that
+% balances the trade-off between ease of reading and ease of writing to suit
+% almost all forms of technical writing. It's
+% other original strength was a good background in typographical design; while
+% the standard \LaTeXe{} classes look somewhat dated now in terms of their
+% visual design, their typography is generally sound. (Barring the occasional
+% minor faults.)
+%
+% However, \LaTeXe{} has always lacked a standard approach to customising
+% the visual design of a document. Changing the looks of the standard classes
+% involved either:
+% \begin{itemize}
+% \item Creating a new version of the implementation code of the class and
+% editing it.
+% \item Loading one of the many packages to customise certain elements of
+% the standard classes.
+% \item Loading a completely different document class, such as
+% \textsf{KOMA-Script} or \textsf{memoir}, that allows easy customisation.
+% \end{itemize}
+% All three of these approaches have their drawbacks and learning curves.
+%
+% The idea behind \pkg{xtemplate} is to cleanly separate the three layers
+% introduced at the beginning of this section, so that document authors who
+% are not programmers can easily change the design of their documents.
+% \pkg{xtemplate} also makes it easier for \LaTeX{} programmers to provide
+% their own customisations on top of a pre-existing class.
+%
+% The idea behind the template module is to cleanly separate the three
+% layers, so that document authors who are not programmers can easily
+% change the design of their documents. Templates also make it easier
+% for \LaTeX{} programmers to provide their own customisations on top of
+% a pre-existing class.
+%
+% \section{What is a document?}
+%
+% Besides the textual content of the words themselves, the source file
+% of a document contains mark-up elements that add structure to the
+% document. These elements include sectional divisions, figure/table
+% captions, lists of various sorts, theorems/proofs, and so on.
+% The list will be different for every document that can be written.
+%
+% Each element can be represented logically without worrying about the
+% formatting, with mark-up such as \cs{section}, \cs{caption},
+% |\begin{enumerate}| and so on. The output of each one of these
+% document elements will be a typeset representation of the information
+% marked up, and the visual arrangement and design of these elements
+% can vary widely in producing a variety of desired outcomes.
+%
+% For each type of document element, there may be design variations that
+% contain the same sort of information but present it in slightly
+% different ways. For example, the difference between a numbered and an
+% unnumbered section, \cs{section} and |\section*|, or the difference
+% between an itemised list or an enumerated list.
+%
+% There are three distinct layers in the definition of
+% \enquote{a document} at this level
+% \begin{enumerate}
+% \item semantic elements such as the ideas of sections and lists;
+% \item a set of design solutions for representing these elements
+% visually;
+% \item specific variations for these designs that represent the
+% elements in the document.
+% \end{enumerate}
+% In the parlance of the template system, these are called object types,
+% templates, and instances, and they are discussed below in sections
+% \ref{sec:objects}, \ref{sec:templates}, and~\ref{sec:instances},
+% respectively.
+%
+% \section {Objects, templates, and instances}
+%
+% By formally declaring documents to be composed of mark-up elements
+% grouped into objects, which are interpreted and typeset with a set of
+% templates, each of which has one or more instances with which to
+% compose each and every semantic unit of the text, there can be clean
+% separate the components of document construction.
+%
+% All of the structures provided by the template system are global,
+% and do not respect \TeX{} grouping.
+%
+% \section{Object types}
+% \label{sec:objects}
+%
+% An \emph{object type} (sometimes just \enquote{object}) is an
+% abstract idea of a document element that takes a fixed number of
+% arguments corresponding to the information from the document author
+% that it is representing. A sectioning object, for example, might take
+% three inputs: \enquote{title}, \enquote{short title}, and
+% \enquote{label}.
+%
+% Any given document class will define which object types are to be
+% used in the document, and any template of a given object type can be
+% used to generate an instance for the object. (Of course, different
+% templates will produce different typeset representations, but the
+% underlying content will be the same.)
+%
+% \begin{function}{\DeclareObjectType}
+% \begin{syntax}
+% \cs{DeclareObjectType} \Arg{object type} \Arg{no. of args}
+% \end{syntax}
+% This function defines an \meta{object type} taking
+% \meta{number of arguments}, where the \meta{object type} is an
+% abstraction as discussed above. For example,
+% \begin{verbatim}
+% \DeclareObjectType{sectioning}{3}
+% \end{verbatim}
+% creates an object type \enquote{sectioning}, where each use of that
+% object type will need three arguments.
+% \end{function}
+%
+% \section{Templates}
+% \label{sec:templates}
+%
+% A \emph{template} is a generalised design solution for representing
+% the information of a specified object type. Templates that do the same
+% thing, but in different ways, are grouped together by their object type
+% and given separate names. There are two important parts to a template:
+% \begin{itemize}
+% \item the parameters it takes to vary the design it is producing;
+% \item the implementation of the design.
+% \end{itemize}
+% As a document author or designer does not care about the
+% implementation but rather only the interface to the template, these two
+% aspects of the template definition are split into two independent
+% declarations, \cs{DeclareTemplateInterface} and
+% \cs{DeclareTemplateCode}.
+%
+% \begin{function}{\DeclareTemplateInterface}
+% \begin{syntax}
+% \cs{DeclareTemplateInterface}
+% ~~\Arg{object type} \Arg{template} \Arg{no.~of args}
+% ~~\Arg{key list}
+% \end{syntax}
+% A \meta{template} interface is declared for a particular
+% \meta{object type}, where the \meta{number of arguments} must
+% agree with the object type declaration. The interface itself is
+% defined by the \meta{key list}, which is itself a key--value list
+% taking a specialized format:
+%
+% \begin{syntax}
+% \meta{key1}~":"~\meta{key type1}~","
+% \meta{key2}~":"~\meta{key type2}~","
+% \meta{key3}~":"~\meta{key type3}~"="~\meta{default3}~","
+% \meta{key4}~":"~\meta{key type4}~"="~\meta{default4}~","
+% \ldots
+% \end{syntax}
+% Each \meta{key} name should consist of \textsc{ascii} characters,
+% with the exception of |,|, |=| and \verb*| |. The recommended form
+% for key names is to use lower case letters, with dashes to separate
+% out different parts. Spaces are ignored in key names, so they can be
+% included are missed out at will. Each \meta{key} must have a
+% \meta{key type}, which defined the type of input that the \meta{key}
+% requires. A full list of key types is given in
+% Table~\ref{tab:key-types}. Each key may have a \meta{default}
+% value, which will be used in by the template if the \meta{key} is
+% not set explicitly. The \meta{default} should be of the correct
+% form to be accepted by the \meta{key type} of the \meta{key}: this
+% is not checked by the code.
+% \begin{table}
+% \centering
+% \begin{tabular}{>{\ttfamily}ll}
+% \toprule
+% \multicolumn{1}{l}{Key-type} & Description of input \\
+% \midrule
+% boolean & \texttt{true} or \texttt{false} \\
+% choice\Arg{choices}
+% & A list of pre-defined \meta{choices} \\
+% code
+% & Generalised key type: use |#1| as the input to the key \\
+% commalist & A comma-separated \\
+% function\Arg{$N$}
+% & A function definition with $N$ arguments
+% ($N$ from $0$ to $9$) \\
+% instance\Arg{name}
+% & An instance of type \meta{name} \\
+% integer & An integer or integer expression \\
+% length & A fixed length \\
+% muskip & A math length with shrink and stretch components \\
+% real & A real (floating point) value \\
+% skip & A length with shrink and stretch components \\
+% tokenlist & A token list: any text or commands \\
+% \bottomrule
+% \end{tabular}
+% \caption{Key-types for defining template interfaces with
+% \cs{DeclareTemplateInterface}.}
+% \label{tab:key-types}
+% \end{table}
+% \end{function}
+%
+% \begin{function}{\KeyValue}
+% \begin{syntax}
+% \cs{KeyValue} \Arg{key name}
+% \end{syntax}
+% There are occasions where the default (or value) for one key
+% should be taken from another. The \cs{KeyValue} function can be
+% used to transfer this information without needing to know the
+% internal implementation of the key:
+% \begin{verbatim}
+% \DeclareTemplateInterface { object } { template } { no. of args }
+% {
+% key-name-1 : key-type = value ,
+% key-name-2 : key-type = \KeyValue { key-name-1 },
+% ...
+% }
+% \end{verbatim}
+% \end{function}
+%
+% \begin{function}{\DeclareTemplateCode}
+% \begin{syntax}
+% \cs{DeclareTemplateCode}
+% ~~\Arg{object type} \Arg{template} \Arg{no.~of args}
+% ~~\Arg{key bindings} \Arg{code}
+% \end{syntax}
+% The relationship between a templates keys and the internal
+% implementation is created using the \cs{DeclareTemplateCode}
+% function. As with \cs{DeclareTemplateInterface}, the
+% \meta{template} name is given along with the \meta{object type}
+% and \meta{number of arguments} required. The \meta{key bindings}
+% argument is a key--value list which specifies the relationship
+% between each \meta{key} of the template interface with an
+% underlying\meta{variable}.
+%
+% \begin{syntax}
+% \meta{key1}~"="~\meta{variable1},
+% \meta{key2}~"="~\meta{variable2},
+% \meta{key3}~"="~global~\meta{variable3},
+% \meta{key4}~"="~global~\meta{variable4},
+% \ldots
+% \end{syntax}
+% With the exception of the choice, code and function key types,
+% the \meta{variable} here should be the name of an existing
+% \LaTeX3 register. As illustrated, the key word \enquote{global}
+% may be included in the listing to indicate that the \meta{variable}
+% should be assigned globally. A full list of variable bindings is
+% given in Table~\ref{tab:key-vars}.
+% \begin{table}
+% \centering
+% \begin{tabular}{>{\ttfamily}ll}
+% \toprule
+% \multicolumn{1}{l}{Key-type} & Description of binding \\
+% \midrule
+% boolean & Boolean variable, \emph{e.g}.~\cs{l_tmpa_bool} \\
+% choice
+% & List of choice implementations
+% (see Section~\ref{sec:choices-key}) \\
+% code
+% & \meta{code} using |#1| as input to the key \\
+% commalist & Comma list, \emph{e.g}.~\cs{l_tmpa_clist} \\
+% function
+% & Function taking $N$ arguments, \emph{e.g}.~\cs{use_i:nn} \\
+% instance \\
+% integer & Integer variable, \emph{e.g}.~\cs{l_tmpa_int} \\
+% length & Dimension variable, \emph{e.g}.~\cs{l_tmpa_dim} \\
+% muskip & Muskip variable, \emph{e.g}.~\cs{l_tmpa_muskip} \\
+% real & Floating-point variable, \emph{e.g}.~\cs{l_tmpa_fp} \\
+% skip & Skip variable, \emph{e.g}.~\cs{l_tmpa_skip} \\
+% tokenlist & Token list variable, \emph{e.g}.~\cs{l_tmpa_tl} \\
+% \bottomrule
+% \end{tabular}
+% \caption{Bindings required for different key types when defining
+% template implementations with \cs{DeclareTemplateCode}. Apart
+% from \texttt{code}, \texttt{choice} and \texttt{function}
+% all of these accept the key word \texttt{global} to carry
+% out a global assignment.}
+% \label{tab:key-vars}
+% \end{table}
+% The \meta{code} argument of \cs{DeclareTemplateCode} is used
+% as the replacement text for the template when it is used, either
+% directly or as an instance. This may therefore accept arguments
+% |#1|, |#2|, \emph{etc}.~as detailed by the \meta{number of arguments}
+% taken by the object type.
+% \end{function}
+%
+% \begin{function}{\AssignTemplateKeys}
+% \begin{syntax}
+% \cs{AssignTemplateKeys}
+% \end{syntax}
+% In the final argument of \cs{DeclareTemplateCode} the assignment of
+% keys defined by the template is carried out by using the function
+% \cs{AssignTemplateKeys}. Thus no keys are assigned if this is missing
+% from the \meta{code} used.
+% \end{function}
+%
+% \begin{function}{\EvaluateNow}
+% \begin{syntax}
+% \cs{EvaluteNow} \Arg{expression}
+% \end{syntax}
+% The standard method when creating an instance from a template is to
+% evaluate the \meta{expression} when the instance is used. However, it may
+% be desirable to calculate the value when declared, which can be
+% forced using \cs{EvaluateNow}. Currently, this functionality is
+% regarded as experimental: the team have not found an example where it
+% is actually needed, and so it may be dropped \emph{if} no good
+% examples are suggested!
+% \end{function}
+%
+% \section{Multiple choices}
+% \label{sec:choices-key}
+%
+% The \texttt{choice} key type implements multiple choice input. At the
+% interface level, only the list of valid choices is needed:
+% \begin{verbatim}
+% \DeclareTemplateInterface { foo } { bar } { 0 }
+% { key-name : choice { A, B, C } }
+% \end{verbatim}
+% where the choices are given as a comma-list (which must therefore
+% be wrapped in braces). A default value can also be given:
+% \begin{verbatim}
+% \DeclareTemplateInterface { foo } { bar } { 0 }
+% { key-name : choice { A, B, C } = A }
+% \end{verbatim}
+%
+% At the implementation level, each choice is associated with code,
+% using a nested key--value list.
+% \begin{verbatim}
+% \DeclareTemplateCode { foo } { bar } { 0 }
+% {
+% key-name =
+% {
+% A = Code-A ,
+% B = Code-B ,
+% C = Code-C
+% }
+% }
+% { ... }
+% \end{verbatim}
+% The two choice lists should match, but in the implementation a
+% special \texttt{unknown} choice is also available. This can be used
+% to ignore values and implement an \enquote{else} branch:
+% \begin{verbatim}
+% \DeclareTemplateCode { foo } { bar } { 0 }
+% {
+% key-name =
+% {
+% A = Code-A ,
+% B = Code-B ,
+% C = Code-C ,
+% unknown = Else-code
+% }
+% }
+% { ... }
+% \end{verbatim}
+% The \texttt{unknown} entry must be the last one given, and should
+% \emph{not} be listed in the interface part of the template.
+%
+% For keys which accept the values \texttt{true} and \texttt{false}
+% both the boolean and choice key types can be used. As template
+% interfaces are intended to prompt clarity at the design level, the
+% boolean key type should be favoured, with the choice type reserved
+% for keys which take arbitrary values.
+%
+% \section{Instances}
+% \label{sec:instances}
+%
+% After a template is defined it still needs to be put to use. The
+% parameters that it expects need to be defined before it can be used in
+% a document. Every time a template has parameters given to it, an
+% \emph{instance} is created, and this is the code that ends up in the
+% document to perform the typesetting of whatever pieces of information
+% are input into it.
+%
+% For example, a template might say \enquote{here is a section with or
+% without a number that might be centred or left aligned and print its
+% contents in a certain font of a certain size, with a bit of a gap
+% before and after it} whereas an instance declares \enquote{this is a
+% section with a number, which is centred and set in $12\,\text{pt}$
+% italic with a $10\,\text{pt}$ skip before and a
+% $12\,\text{pt}$ skip after it}. Therefore, an instance is just a
+% frozen version of a template with specific settings as chosen by the
+% designer.
+%
+% \begin{function}{\DeclareInstance}
+% \begin{syntax}
+% \cs{DeclareInstance}
+% ~~\Arg{object type} \Arg{instance} \Arg{template} \Arg{parameters}
+% \end{syntax}
+% This function uses a \meta{template} for an \meta{object type}
+% to create an \meta{instance}. The \meta{instance} will be set
+% up using the \meta{parameters}, which will set some of the
+% \meta{keys} in the \meta{template}.
+%
+% As a practical example, consider an object type for document sections
+% (which might include chapters, parts, sections, \emph{etc}.), which
+% is called \texttt{sectioning}. One possible template for this
+% object type might be called \texttt{basic}, and one instance of this
+% template would be a numbered section. The instance declaration might
+% read:
+% \begin{verbatim}
+% \DeclareInstance { sectioning } { section-num } { basic }
+% {
+% numbered = true ,
+% justification = center ,
+% font =\normalsize\itshape ,
+% before-skip = 10pt ,
+% after-skip = 12pt ,
+% }
+% \end{verbatim}
+% Of course, the key names here are entirely imaginary, but illustrate
+% the general idea of fixing some settings.
+% \end{function}
+%
+% \section{Document interface}
+%
+% After the instances have been chosen, document commands must be
+% declared to use those instances in the document. \cs{UseInstance}
+% calls instances directly, and this command should be used internally
+% in document-level mark-up.
+%
+% \begin{function}{\UseInstance}
+% \begin{syntax}
+% \cs{UseInstance}
+% ~~\Arg{object type} \Arg{instance} \meta{arguments}
+% \end{syntax}
+% Uses an \meta{instance} of the \meta{object type}, which will require
+% \meta{arguments} as determined by the number specified for the
+% \meta{object type}. The \meta{instance} must have been declared
+% before it can be used, otherwise an error is raised.
+% \end{function}
+%
+% \begin{function}{\UseTemplate}
+% \begin{syntax}
+% \cs{UseTemplate} \Arg{object type} \Arg{template}
+% ~~\Arg{settings} \meta{arguments}
+% \end{syntax}
+% Uses the \meta{template} of the specified \meta{object type},
+% applying the \meta{settings} and absorbing \meta{arguments} as
+% detailed by the \meta{object type} declaration. This in effect
+% is the same as creating an instance using \cs{DeclareInstance}
+% and immediately using it with \cs{UseInstance}, but without the
+% instance having any further existence. It is therefore useful where
+% a template needs to be used once.
+%
+% This function can also be used as the argument to \texttt{instance}
+% key types:
+% \begin{verbatim}
+% \DeclareInstance { object } { template } { instance }
+% {
+% instance-key =
+% \UseTemplate { object2 } { template2 } { <settings> }
+% }
+% \end{verbatim}
+% \end{function}
+%
+% \section{Changing existing definitions}
+%
+% Template parameters may be assigned specific defaults for instances
+% to use if the instance declaration doesn't explicit set those
+% parameters. In some cases, the document designer will wish to edit
+% these defaults to allow them to \enquote{cascade} to the instances.
+% The alternative would be to set each parameter identically for each
+% instance declaration, a tedious and error-prone process.
+%
+% \begin{function}{\EditTemplateDefaults}
+% \begin{syntax}
+% \cs{EditTemplateDefaults}
+% ~~\Arg{object type} \Arg{template} \Arg{new defaults}
+% \end{syntax}
+% Edits the \meta{defaults} for a \meta{template} for an
+% \meta{object type}. The \meta{new defaults}, given as a key--value
+% list, replace the existing defaults for the \meta{template}. This
+% means that the change will apply to instances declared after the
+% editing, but that instances which have already been created are
+% unaffected.
+% \end{function}
+%
+% \begin{function}{\EditInstance}
+% \begin{syntax}
+% \cs{EditInstance}
+% ~~\Arg{object type} \Arg{instance} \Arg{new values}
+% \end{syntax}
+% Edits the \meta{values} for an \meta{instance} for an
+% \meta{object type}. The \meta{new values}, given as a key--value
+% list, replace the existing values for the \meta{instance}. This
+% function is complementary to \cs{EditTemplateDefaults}:
+% \cs{EditInstance} changes a single instance while leaving the
+% template untouched.
+% \end{function}
+%
+% \section{When template parameters should be frozen}
+%
+% A class designer may be inheriting templates declared by someone else,
+% either third-party code or the \LaTeX{} kernel itself. Sometimes these
+% templates will be overly general for the purposes of the document.
+% The user should be able to customise parts of the template instances,
+% but otherwise be restricted to only those parameters allowed by the
+% designer.
+%
+% \begin{function}{\DeclareRestrictedTemplate}
+% \begin{syntax}
+% \cs{DeclareRestrictedTemplate}
+% ~~\Arg{object type} \Arg{parent template} \Arg{new template}
+% ~~\Arg{parameters}
+% \end{syntax}
+% Creates a copy of the \meta{parent template} for the
+% \meta{object type} called \meta{new template}. The key--value list
+% of \meta{parameters} applies in the \meta{new template} and cannot
+% be changed when creating an instance.
+% \end{function}
+%
+% \section{Getting information about templates and instances}
+%
+% \begin{function}{\ShowInstanceValues}
+% \begin{syntax}
+% \cs{ShowInstanceValues} \Arg{object type} \Arg{instance}
+% \end{syntax}
+% Shows the \meta{values} for an \meta{instance} of the given
+% \meta{object type} at the terminal.
+% \end{function}
+%
+% \begin{function}{\ShowCollectionInstanceValues}
+% \begin{syntax}
+% \cs{ShowInstanceValues} \Arg{collection} \Arg{object type} \Arg{instance}
+% \end{syntax}
+% Shows the \meta{values} for an \meta{instance} within
+% a \meta{collection} of the given \meta{object type} at the terminal.
+% \end{function}
+%
+% \begin{function}{\ShowTemplateCode}
+% \begin{syntax}
+% \cs{ShowTemplateCode} \Arg{object type} \Arg{template}
+% \end{syntax}
+% Shows the \meta{code} of a \meta{template} for an \meta{object type}
+% in the terminal.
+% \end{function}
+%
+% \begin{function}{\ShowTemplateDefaults}
+% \begin{syntax}
+% \cs{ShowTemplateDefaults} \Arg{object type} \Arg{template}
+% \end{syntax}
+% Shows the \meta{default} values of a \meta{template} for an
+% \meta{object type} in the terminal.
+% \end{function}
+%
+% \begin{function}{\ShowTemplateInterface}
+% \begin{syntax}
+% \cs{ShowTemplateInterface} \Arg{object type} \Arg{template}
+% \end{syntax}
+% Shows the \meta{keys} and associated \meta{key types} of a
+% \meta{template} for an \meta{object type} in the terminal.
+% \end{function}
+%
+% \begin{function}{\ShowTemplateVariables}
+% \begin{syntax}
+% \cs{ShowTemplateVariables} \Arg{object type} \Arg{template}
+% \end{syntax}
+% Shows the \meta{variables} and associated \meta{keys} of a
+% \meta{template} for an \meta{object type} in the terminal. Note that
+% \texttt{code} and \texttt{choice} keys do not map directly to variables
+% but to arbitrary code. For \texttt{choice} keys, each valid choice
+% is shown as a separate entry in the list, with the key name and choice
+% separated by a space, for example
+% \begin{verbatim}
+% Template 'example' of object type 'example' has variable mapping:
+% > demo unknown => \def \demo {?}
+% > demo c => \def \demo {c}
+% > demo b => \def \demo {b}
+% > demo a => \def \demo {a}.
+% \end{verbatim}
+% would be shown for a choice key \texttt{demo} with valid choices
+% \texttt{a}, \texttt{b} and \texttt{c}, plus code for an \texttt{unknown}
+% branch.
+% \end{function}
+%
+% \end{documentation}
+%
+% \begin{implementation}
+%
+% \section{\pkg{xtemplate} Implementation}
+%
+% \begin{macrocode}
+%<*package>
+% \end{macrocode}
+%
+% \begin{macrocode}
+\ProvidesExplPackage
+ {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+% \end{macrocode}
+%
+% A check to make sure that \pkg{expl3} is not too old
+% \begin{macrocode}
+\@ifpackagelater { l3token } { 2011/07/02 }
+ { }
+ {
+ \PackageError { xtemplate } { Support~package~l3kernel~too~old. }
+ {
+ Please~install~an~up~to~date~version~of~l3kernel~
+ using~your~TeX~package~manager~or~from~CTAN.\\ \\
+ Loading~xtemplate~will~abort!
+ }
+ \tex_endinput:D
+ }
+% \end{macrocode}
+%
+% \subsection{Variables and constants}
+%
+% \begin{variable}{\c_xtemplate_code_root_tl}
+% \begin{variable}{\c_xtemplate_defaults_root_tl}
+% \begin{variable}{\c_xtemplate_instances_root_tl}
+% \begin{variable}{\c_xtemplate_keytypes_root_tl}
+% \begin{variable}{\c_xtemplate_key_order_root_tl}
+% \begin{variable}{\c_xtemplate_restrict_root_tl}
+% \begin{variable}{\c_xtemplate_values_root_tl}
+% \begin{variable}{\c_xtemplate_vars_root_tl}
+% So that literal values are kept to a minimum.
+% \begin{macrocode}
+\tl_const:Nn \c_xtemplate_code_root_tl { template~code~>~ }
+\tl_const:Nn \c_xtemplate_defaults_root_tl { template~defaults~>~ }
+\tl_const:Nn \c_xtemplate_instances_root_tl { template~instance~>~ }
+\tl_const:Nn \c_xtemplate_keytypes_root_tl { template~key~types~>~ }
+\tl_const:Nn \c_xtemplate_key_order_root_tl { template~key~order~>~ }
+\tl_const:Nn \c_xtemplate_restrict_root_tl { template~restrictions~>~ }
+\tl_const:Nn \c_xtemplate_values_root_tl { template~values~>~ }
+\tl_const:Nn \c_xtemplate_vars_root_tl { template~vars~>~ }
+% \end{macrocode}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+%
+% \begin{variable}{\c_xtemplate_keytypes_arg_seq}
+% A list of keytypes which also need additional data (an argument), used
+% to parse the keytype correctly.
+% \begin{macrocode}
+\seq_new:N \c_xtemplate_keytypes_arg_seq
+\seq_put_right:Nn \c_xtemplate_keytypes_arg_seq { choice }
+\seq_put_right:Nn \c_xtemplate_keytypes_arg_seq { function }
+\seq_put_right:Nn \c_xtemplate_keytypes_arg_seq { instance }
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\g_xtemplate_object_type_prop}
+% For storing types and the associated number of arguments.
+% \begin{macrocode}
+\prop_new:N \g_xtemplate_object_type_prop
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xtemplate_assignments_tl}
+% When creating an instance, the assigned values are collected here.
+% \begin{macrocode}
+\tl_new:N \l_xtemplate_assignments_tl
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xtemplate_collection_tl}
+% The current instance collection name is stored here.
+% \begin{macrocode}
+\tl_new:N \l_xtemplate_collection_tl
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xtemplate_collections_prop}
+% Lists current collection in force, indexed by object type.
+% \begin{macrocode}
+\prop_new:N \l_xtemplate_collections_prop
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}{\l_xtemplate_default_tl}
+% The default value for a key is recovered here from the property list
+% in which it is stored. The internal implementation of property lists
+% means that this is safe even with un-escaped |#| tokens.
+% \begin{macrocode}
+\tl_new:N \l_xtemplate_default_tl
+% \end{macrocode}
+%\ end{macro}
+%
+% \begin{variable}{\l_xtemplate_error_bool}
+% A flag for errors to be carried forward.
+% \begin{macrocode}
+\bool_new:N \l_xtemplate_error_bool
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xtemplate_global_bool}
+% Used to indicate that assignments should be global.
+% \begin{macrocode}
+\bool_new:N \l_xtemplate_global_bool
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xtemplate_restrict_bool}
+% A flag to indicate that a template is being restricted.
+% \begin{macrocode}
+\bool_new:N \l_xtemplate_restrict_bool
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xtemplate_restrict_clist}
+% A scratch list for restricting templates.
+% \begin{macrocode}
+\clist_new:N \l_xtemplate_restrict_clist
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_xtemplate_key_name_tl}
+% \begin{variable}{\l_xtemplate_keytype_tl}
+% \begin{variable}{\l_xtemplate_keytype_arg_tl}
+% \begin{variable}{\l_xtemplate_value_tl}
+% \begin{variable}{\l_xtemplate_var_tl}
+% When defining each key in a template, the name and type of the key
+% need to be separated and stored. Any argument needed by the
+% keytype is also stored separately.
+% \begin{macrocode}
+\tl_new:N \l_xtemplate_key_name_tl
+\tl_new:N \l_xtemplate_keytype_tl
+\tl_new:N \l_xtemplate_keytype_arg_tl
+\tl_new:N \l_xtemplate_value_tl
+\tl_new:N \l_xtemplate_var_tl
+% \end{macrocode}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+%
+% \begin{variable}{\l_xtemplate_keytypes_prop}
+% \begin{variable}{\l_xtemplate_key_order_seq}
+% \begin{variable}{\l_xtemplate_values_prop}
+% \begin{variable}{\l_xtemplate_vars_prop}
+% To avoid needing too many difficult-to-follow csname assignments,
+% various scratch token registers are used to build up data, which is
+% then transferred
+% \begin{macrocode}
+\prop_new:N \l_xtemplate_keytypes_prop
+\seq_new:N \l_xtemplate_key_order_seq
+\prop_new:N \l_xtemplate_values_prop
+\prop_new:N \l_xtemplate_vars_prop
+% \end{macrocode}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+%
+% \begin{variable}{\l_xtemplate_tmp_clist}
+% \begin{variable}{\l_xtemplate_tmp_dim}
+% \begin{variable}{\l_xtemplate_tmp_int}
+% \begin{variable}{\l_xtemplate_tmp_muskip}
+% \begin{variable}{\l_xtemplate_tmp_skip}
+% For pre-processing the data stored by \pkg{xtemplate}, a number of
+% scratch variables are needed. The assignments are made to these in the
+% first instance, unless evaluation is delayed.
+% \begin{macrocode}
+\clist_new:N \l_xtemplate_tmp_clist
+\dim_new:N \l_xtemplate_tmp_dim
+\int_new:N \l_xtemplate_tmp_int
+\muskip_new:N \l_xtemplate_tmp_muskip
+\skip_new:N \l_xtemplate_tmp_skip
+% \end{macrocode}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+% \end{variable}
+%
+% \begin{variable}{\l_xtemplate_tmp_tl}
+% A scratch variable for comparisons and so on.
+% \begin{macrocode}
+\tl_new:N \l_xtemplate_tmp_tl
+% \end{macrocode}
+% \end{variable}
+%
+% \subsection{Testing existence and validity}
+%
+% There are a number of checks needed for either the existence of
+% a object type, template or instance. There are also some for the
+% validity of a particular call. All of these are collected up here.
+%
+% \begin{macro}{\xtemplate_execute_if_arg_agree:nnT}
+% A test agreement between the number of arguments for the template
+% type and that specified when creating a template. This is not done as a
+% separate conditional for efficiency and better error message
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_execute_if_arg_agree:nnT #1#2#3
+ {
+ \prop_get:NnN \g_xtemplate_object_type_prop {#1} \l_xtemplate_tmp_tl
+ \int_compare:nNnTF {#2} = \l_xtemplate_tmp_tl
+ {#3}
+ {
+ \msg_error:nnxxx { xtemplate }
+ { argument-number-mismatch } {#1} { \l_xtemplate_tmp_tl } {#2}
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_execute_if_code_exist:nnT}
+% A template is only fully declared if the code has been set up,
+% which can be checked by looking for the template function itself.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_execute_if_code_exist:nnT #1#2#3
+ {
+ \cs_if_exist:cTF { \c_xtemplate_code_root_tl #1 / #2 }
+ {#3}
+ {
+ \msg_error:nnxx { xtemplate } { no-template-code }
+ {#1} {#2}
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_execute_if_keytype_exist:nT}
+% \begin{macro}{\xtemplate_execute_if_keytype_exist:oF}
+% The test for valid keytypes looks for a function to set up the key,
+% which is part of the \enquote{code} side of the template definition.
+% This avoids having different lists for the two parts of the process.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_execute_if_keytype_exist:nT #1#2
+ {
+ \cs_if_exist:cTF { xtemplate_store_value_ #1 :n }
+ {#2}
+ { \msg_error:nnx { xtemplate } { unknown-keytype } {#1} }
+ }
+\cs_generate_variant:Nn \xtemplate_execute_if_keytype_exist:nT { o }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_execute_if_type_exist:nT}
+% To check that a particular object type is valid.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_execute_if_type_exist:nT #1#2
+ {
+ \prop_if_in:NnTF \g_xtemplate_object_type_prop {#1}
+ {#2}
+ { \msg_error:nnx { xtemplate } { unknown-object-type } {#1} }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_execute_if_keys_exist:nnT}
+% To check that the keys for a template have been set up before trying
+% to create any code, a simple check for the correctly-named keytype
+% property list.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_if_keys_exist:nnT #1#2#3
+ {
+ \cs_if_exist:cTF { \c_xtemplate_keytypes_root_tl #1 / #2 }
+ {#3}
+ {
+ \msg_error:nnxx { xtemplate } { unknown-template }
+ {#1} {#2}
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_if_key_value:nT, \xtemplate_if_key_value:oT}
+% Tests for the first token in a string being \cs{KeyValue}, where
+% \cs{EvaluateNow} is not important.
+% \begin{macrocode}
+\prg_new_conditional:Npnn \xtemplate_if_key_value:n #1 { T }
+ {
+ \str_if_eq:noTF { \KeyValue } { \tl_head:w #1 \q_stop }
+ {\prg_return_true: }
+ { \prg_return_false: }
+ }
+\cs_generate_variant:Nn \xtemplate_if_key_value:nT { o }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_if_eval_now:nTF}
+% Tests for the first token in a string being \cs{EvaluateNow}.
+% \begin{macrocode}
+\prg_new_conditional:Npnn \xtemplate_if_eval_now:n #1 { TF }
+ {
+ \str_if_eq:noTF { \EvaluateNow } { \tl_head:w #1 \q_stop }
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[TF]{\xtemplate_if_instance_exist:nnn}
+% Testing for an instance is collection dependent.
+% \begin{macrocode}
+\prg_new_conditional:Npnn \xtemplate_if_instance_exist:nnn #1#2#3
+ { T, F, TF }
+ {
+ \cs_if_exist:cTF { \c_xtemplate_instances_root_tl #1 / #2 / #3 }
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_if_use_template:nTF}
+% Tests for the first token in a string being \cs{UseTemplate}.
+% \begin{macrocode}
+\prg_new_conditional:Npnn \xtemplate_if_use_template:n #1 { TF }
+ {
+ \str_if_eq:noTF { \UseTemplate } { \tl_head:w #1 \q_stop }
+ { \prg_return_true: }
+ { \prg_return_false: }
+}
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{Saving and recovering property lists}
+%
+% The various property lists for templates have to be shuffled in
+% and out of storage.
+%
+% \begin{macro}{\xtemplate_store_defaults:n}
+% \begin{macro}{\xtemplate_store_keytypes:n}
+% \begin{macro}{\xtemplate_store_restrictions:n}
+% \begin{macro}{\xtemplate_store_values:n}
+% \begin{macro}{\xtemplate_store_vars:n}
+% The defaults and keytypes are transferred from the scratch property
+% lists to the \enquote{proper} lists for the template being created.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_store_defaults:n #1
+ {
+ \prop_gclear_new:c { \c_xtemplate_defaults_root_tl #1 }
+ \prop_gset_eq:cN { \c_xtemplate_defaults_root_tl #1 }
+ \l_xtemplate_values_prop
+ }
+\cs_new_protected:Npn \xtemplate_store_keytypes:n #1
+ {
+ \prop_gclear_new:c { \c_xtemplate_keytypes_root_tl #1 }
+ \prop_gset_eq:cN { \c_xtemplate_keytypes_root_tl #1 }
+ \l_xtemplate_keytypes_prop
+ \seq_gclear_new:c { \c_xtemplate_key_order_root_tl #1 }
+ \seq_gset_eq:cN { \c_xtemplate_key_order_root_tl #1 }
+ \l_xtemplate_key_order_seq
+ }
+\cs_new_protected:Npn \xtemplate_store_values:n #1
+ {
+ \prop_clear_new:c { \c_xtemplate_values_root_tl #1 }
+ \prop_set_eq:cN { \c_xtemplate_values_root_tl #1 }
+ \l_xtemplate_values_prop
+ }
+\cs_new_protected:Npn \xtemplate_store_restrictions:n #1
+ {
+ \clist_gclear_new:c { \c_xtemplate_restrict_root_tl #1 }
+ \clist_gset_eq:cN { \c_xtemplate_restrict_root_tl #1 }
+ \l_xtemplate_restrict_clist
+ }
+\cs_new_protected:Npn \xtemplate_store_vars:n #1
+ {
+ \prop_gclear_new:c { \c_xtemplate_vars_root_tl #1 }
+ \prop_gset_eq:cN { \c_xtemplate_vars_root_tl #1 }
+ \l_xtemplate_vars_prop
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_recover_defaults:n}
+% \begin{macro}{\xtemplate_recover_keytypes:n}
+% \begin{macro}{\xtemplate_recover_restrictions:n}
+% \begin{macro}{\xtemplate_recover_values:n}
+% \begin{macro}{\xtemplate_recover_vars:n}
+% Recovering the stored data for a template is rather less complex
+% than storing it. All that happens is the data is transferred from
+% the permanent to the scratch storage.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_recover_defaults:n #1
+ {
+ \prop_set_eq:Nc \l_xtemplate_values_prop
+ { \c_xtemplate_defaults_root_tl #1 }
+ }
+\cs_new_protected:Npn \xtemplate_recover_keytypes:n #1
+ {
+ \prop_set_eq:Nc \l_xtemplate_keytypes_prop
+ { \c_xtemplate_keytypes_root_tl #1 }
+ \seq_set_eq:Nc \l_xtemplate_key_order_seq
+ { \c_xtemplate_key_order_root_tl #1 }
+ }
+\cs_new_protected:Npn \xtemplate_recover_restrictions:n #1
+ {
+ \clist_set_eq:Nc \l_xtemplate_restrict_clist
+ { \c_xtemplate_restrict_root_tl #1 }
+ }
+\cs_new_protected:Npn \xtemplate_recover_values:n #1
+ {
+ \prop_set_eq:Nc \l_xtemplate_values_prop
+ { \c_xtemplate_values_root_tl #1 }
+ }
+\cs_new_protected:Npn \xtemplate_recover_vars:n #1
+ {
+ \prop_set_eq:Nc \l_xtemplate_vars_prop
+ { \c_xtemplate_vars_root_tl #1 }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \subsection{Creating new object types}
+%
+% \begin{macro}{\xtemplate_declare_object_type:nn}
+% Although the object type is the \enquote{top level} of the template
+% system, it is actually very easy to implement. All that happens is that
+% the number of arguments required is recorded, indexed by the name of the
+% object type.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_declare_object_type:nn #1#2
+ {
+ \int_set:Nn \l_xtemplate_tmp_int {#2}
+ \bool_if:nTF
+ {
+ \int_compare_p:nNn {#2} > \c_nine ||
+ \int_compare_p:nNn {#2} < \c_zero
+ }
+ {
+ \msg_error:nnxx { xtemplate } { bad-number-of-arguments }
+ {#1} { \exp_not:V \l_xtemplate_tmp_int }
+ }
+ {
+ \msg_info:nnxx { xtemplate } { declare-object-type }
+ {#1} {#2}
+ \prop_gput:NnV \g_xtemplate_object_type_prop {#1}
+ \l_xtemplate_tmp_int
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{Design part of template declaration}
+%
+% The \enquote{design} part of a template declaration defines the general
+% behaviour of each key, and possibly a default value. However, it does
+% not include the implementation. This means that what happens here is
+% the two properties are saved to appropriate lists, which can then
+% be used later to recover the information when implementing the keys.
+%
+% \begin{macro}{\xtemplate_declare_template_keys:nnnn}
+% The main function for the \enquote{design} part of creating a template
+% starts by checking that the object type exists and that the number of
+% arguments required agree. If that is all fine, then the two storage
+% areas for defaults and keytypes are initialised. The mechanism is then
+% set up for the \pkg{l3keyval} module to actually parse the keys.
+% Finally, the code hands of to the storage routine to save the parsed
+% information properly.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_declare_template_keys:nnnn #1#2#3#4
+ {
+ \xtemplate_execute_if_type_exist:nT {#1}
+ {
+ \xtemplate_execute_if_arg_agree:nnT {#1} {#3}
+ {
+ \prop_clear:N \l_xtemplate_values_prop
+ \prop_clear:N \l_xtemplate_keytypes_prop
+ \seq_clear:N \l_xtemplate_key_order_seq
+ \keyval_parse:NNn
+ \xtemplate_parse_keys_elt:n \xtemplate_parse_keys_elt:nn {#4}
+ \xtemplate_store_defaults:n { #1 / #2 }
+ \xtemplate_store_keytypes:n { #1 / #2 }
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_parse_keys_elt:n}
+% \begin{macro}[aux]{\xtemplate_parse_keys_elt_aux:n}
+% \begin{macro}[aux]{\xtemplate_parse_keys_elt_aux:}
+% Processing the key part of the key--value pair is always carried out
+% using this function, even if a value was found. First, the key name
+% is separated from the keytype, and if necessary the keytype is
+% separated into two parts. This information is then used to check that
+% the keytype is valid, before storing the keytype (plus argument if
+% necessary) as a property of the key name. The key name is also stored
+% (in braces) in the token list to record the order the keys are defined
+% in.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_parse_keys_elt:n #1
+ {
+ \xtemplate_split_keytype:n {#1}
+ \bool_if:NF \l_xtemplate_error_bool
+ {
+ \xtemplate_execute_if_keytype_exist:oT \l_xtemplate_keytype_tl
+ {
+ \seq_map_function:NN \c_xtemplate_keytypes_arg_seq
+ \xtemplate_parse_keys_elt_aux:n
+ \bool_if:NF \l_xtemplate_error_bool
+ {
+ \seq_if_in:NoTF \l_xtemplate_key_order_seq
+ \l_xtemplate_key_name_tl
+ {
+ \msg_error:nnx { xtemplate }
+ { duplicate-key-interface }
+ { \l_xtemplate_key_name_tl }
+ }
+ { \xtemplate_parse_keys_elt_aux: }
+ }
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_parse_keys_elt_aux:n #1
+ {
+ \str_if_eq:onT \l_xtemplate_keytype_tl {#1}
+ {
+ \tl_if_empty:NT \l_xtemplate_keytype_arg_tl
+ {
+ \msg_error:nnx { xtemplate }
+ { keytype-requires-argument } {#1}
+ \bool_set_true:N \l_xtemplate_error_bool
+ \seq_map_break:
+ }
+ }
+ }
+\cs_new_nopar:Npn \xtemplate_parse_keys_elt_aux:
+ {
+ \tl_set:Nx \l_xtemplate_tmp_tl
+ {
+ \l_xtemplate_keytype_tl
+ \tl_if_empty:NF \l_xtemplate_keytype_arg_tl
+ { { \l_xtemplate_keytype_arg_tl } }
+ }
+ \prop_put:Noo \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \seq_put_right:No \l_xtemplate_key_order_seq \l_xtemplate_key_name_tl
+ \str_if_eq:onT \l_xtemplate_keytype_tl { choice }
+ {
+ \clist_if_in:NnT \l_xtemplate_keytype_arg_tl { unknown }
+ { \msg_error:nn { xtemplate } { choice-unknown-reserved } }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_parse_keys_elt:nn}
+% For keys which have a default, the keytype and key name are first
+% separated out by the \cs{xtemplate_parse_keys_elt:n}
+% routine, before storing the default value in the scratch property list.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_parse_keys_elt:nn #1#2
+ {
+ \xtemplate_parse_keys_elt:n {#1}
+ \use:c { xtemplate_store_value_ \l_xtemplate_keytype_tl :n } {#2}
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_split_keytype:n}
+% \begin{macro}[aux]{\xtemplate_split_keytype_aux:w}
+% The keytype and key name should be separated by |:|. As the
+% definition might be given inside or outside of a code block, spaces
+% are removed and the category code of colons is standardised. After
+% that, the standard delimited argument method is used to separate the
+% two parts.
+% \begin{macrocode}
+\group_begin:
+\char_set_lccode:nn { `\@ } { `\: }
+\char_set_catcode_other:N \@
+\tl_to_lowercase:n
+ {
+ \group_end:
+ \cs_new_protected:Npn \xtemplate_split_keytype:n #1
+ {
+ \bool_set_false:N \l_xtemplate_error_bool
+ \tl_set:Nn \l_xtemplate_tmp_tl {#1}
+ \tl_remove_all:Nn \l_xtemplate_tmp_tl { ~ }
+ \tl_replace_all:Nnn \l_xtemplate_tmp_tl { : } { @ }
+ \tl_if_in:onTF \l_xtemplate_tmp_tl { @ }
+ {
+ \tl_clear:N \l_xtemplate_key_name_tl
+ \exp_after:wN \xtemplate_split_keytype_aux:w
+ \l_xtemplate_tmp_tl \q_stop
+ }
+ {
+ \bool_set_true:N \l_xtemplate_error_bool
+ \msg_error:nnx { xtemplate } { missing-keytype } {#1}
+ }
+ }
+ \cs_new_protected:Npn \xtemplate_split_keytype_aux:w #1 @ #2 \q_stop
+ {
+ \tl_put_right:Nx \l_xtemplate_key_name_tl { \tl_to_str:n {#1} }
+ \tl_if_in:nnTF {#2} { @ }
+ {
+ \tl_put_right:Nn \l_xtemplate_key_name_tl { @ }
+ \xtemplate_split_keytype_aux:w #2 \q_stop
+ }
+ {
+ \tl_if_empty:NTF \l_xtemplate_key_name_tl
+ { \msg_error:nnx { xtemplate } { empty-key-name } { @ #2 } }
+ { \xtemplate_split_keytype_arg:n {#2} }
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_split_keytype_arg:n, \xtemplate_split_keytype_arg:o}
+% \begin{macro}[aux]{\xtemplate_split_keytype_arg_aux:n}
+% \begin{macro}[aux]{\xtemplate_split_keytype_arg_aux:w}
+% The second stage of sorting out the keytype is to check for an
+% argument. As there is no convenient delimiting token to look for,
+% a check is made instead for each possible text value for the keytype.
+% To keep things faster, this only involves the keytypes that need an
+% argument. If a match is made, then a check is also needed to see that
+% it is at the start of the keytype information. All being well, the
+% split can then be applied. Any non-matching keytypes are assumed to
+% be \enquote{correct} as given, and are left alone (this is checked by
+% other code).
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_split_keytype_arg:n #1
+ {
+ \tl_set:Nn \l_xtemplate_keytype_tl {#1}
+ \tl_clear:N \l_xtemplate_keytype_arg_tl
+ \cs_set_protected_nopar:Npn \xtemplate_split_keytype_arg_aux:n ##1
+ {
+ \tl_if_in:nnT {#1} {##1}
+ {
+ \cs_set:Npn \xtemplate_split_keytype_arg_aux:w
+ ####1 ##1 ####2 \q_stop
+ {
+ \tl_if_empty:nT {####1}
+ {
+ \tl_set:Nn \l_xtemplate_keytype_tl {##1}
+ \tl_set:Nn \l_xtemplate_keytype_arg_tl {####2}
+ \seq_map_break:
+ }
+ }
+ \xtemplate_split_keytype_arg_aux:w #1 \q_stop
+ }
+ }
+ \seq_map_function:NN \c_xtemplate_keytypes_arg_seq
+ \xtemplate_split_keytype_arg_aux:n
+ }
+\cs_generate_variant:Nn \xtemplate_split_keytype_arg:n { o }
+\cs_new_nopar:Npn \xtemplate_split_keytype_arg_aux:n #1 { }
+\cs_new_nopar:Npn \xtemplate_split_keytype_arg_aux:w #1 \q_stop { }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \subsubsection{Storing values}
+%
+% As \pkg{xtemplate} pre-processes key values for efficiency reasons,
+% there is a need to convert the values given as defaults into
+% \enquote{ready to use} data. The same general idea is true when an instance
+% is declared. However, assignments are not made until an instance is
+% used, and so there has to be some intermediate storage. Furthermore,
+% the ability to delay evaluation of results is needed. To achieve these
+% aims, a series of \enquote{process and store} functions are defined here.
+%
+% All of the information about the key (the key name and the keytype)
+% is already stored as variables. The same property list is always used
+% to store the data, meaning that the only argument required is the
+% value to be processed and potentially stored.
+%
+% \begin{macro}{\xtemplate_store_value_boolean:n}
+% Storing Boolean values requires a test for delayed evaluation, but
+% is different to the various numerical variable types as there are
+% only two possible values to store. So the code here tests the default
+% switch and then records the meaning (either \texttt{true} or
+% \texttt{false}).
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_store_value_boolean:n #1
+ {
+ \xtemplate_if_eval_now:nTF {#1}
+ {
+ \bool_if:cTF { c_ #1 _bool }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ { true }
+ }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ { false }
+ }
+ }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl {#1}
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_store_value_code:n}
+% \begin{macro}{\xtemplate_store_value_choice:n}
+% \begin{macro}{\xtemplate_store_value_commalist:n}
+% \begin{macro}{\xtemplate_store_value_function:n}
+% \begin{macro}{\xtemplate_store_value_instance:n}
+% \begin{macro}{\xtemplate_store_value_real:n}
+% \begin{macro}{\xtemplate_store_value_tokenlist:n}
+% With no need to worry about delayed evaluation, these keytypes all
+% just store the input directly.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_store_value_code:n #1
+ { \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl {#1} }
+\cs_new_eq:NN \xtemplate_store_value_choice:n \xtemplate_store_value_code:n
+\cs_new_eq:NN \xtemplate_store_value_commalist:n \xtemplate_store_value_code:n
+\cs_new_eq:NN \xtemplate_store_value_function:n \xtemplate_store_value_code:n
+\cs_new_eq:NN \xtemplate_store_value_instance:n \xtemplate_store_value_code:n
+\cs_new_eq:NN \xtemplate_store_value_real:n \xtemplate_store_value_code:n
+\cs_new_eq:NN \xtemplate_store_value_tokenlist:n \xtemplate_store_value_code:n
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_store_value_integer:n}
+% \begin{macro}{\xtemplate_store_value_length:n}
+% \begin{macro}{\xtemplate_store_value_muskip:n}
+% \begin{macro}{\xtemplate_store_value_skip:n}
+% Storing the value of a number is in all cases more or less the same.
+% If evaluation is taking place now, assignment is made to a scratch
+% variable, and this result is then stored. On the other hand, if
+% evaluation is delayed the current data is simply stored \enquote{as is}.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_store_value_integer:n #1
+ {
+ \xtemplate_if_eval_now:nTF {#1}
+ {
+ \int_set:Nn \l_xtemplate_tmp_int {#1}
+ \prop_put:NVV \l_xtemplate_values_prop \l_xtemplate_key_name_int
+ \l_xtemplate_tmp_int
+ }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl {#1}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_store_value_length:n #1
+ {
+ \xtemplate_if_eval_now:nTF {#1}
+ {
+ \dim_set:Nn \l_xtemplate_tmp_dim {#1}
+ \prop_put:NVV \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_dim
+ }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl {#1}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_store_value_muskip:n #1
+ {
+ \xtemplate_if_eval_now:nTF {#1}
+ {
+ \muskip_set:Nn \l_xtemplate_tmp_muskip {#1}
+ \prop_put:NVV \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_muskip
+ }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl {#1}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_store_value_skip:n #1
+ {
+ \xtemplate_if_eval_now:nTF {#1}
+ {
+ \skip_set:Nn \l_xtemplate_tmp_skip {#1}
+ \prop_put:NVV \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_skip
+ }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl {#1}
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \subsection{Implementation part of template declaration}
+%
+% \begin{macro}{\xtemplate_declare_template_code:nnnnn}
+% The main function for implementing a template starts with a couple of
+% simple checks to make sure that there are no obvious mistakes: the
+% number of arguments must agree and the template keys must have been
+% declared.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_declare_template_code:nnnnn #1#2#3#4#5
+ {
+ \xtemplate_execute_if_type_exist:nT {#1}
+ {
+ \xtemplate_execute_if_arg_agree:nnT {#1}{#3}
+ {
+ \xtemplate_if_keys_exist:nnT {#1} {#2}
+ {
+ \xtemplate_store_key_implementation:nnn {#1} {#2} {#4}
+ \cs_generate_from_arg_count:cNnn
+ { \c_xtemplate_code_root_tl #1 / #2 }
+ \cs_gset_protected:Npn {#3} {#5}
+ }
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_store_key_implementation:nnn}
+% Actually storing the implementation part of a template is quite easy
+% as it only requires the list of keys given to be turned into a
+% property list. There is also some error-checking to do, hence the need
+% to have the list of defined keytypes available. In certain cases
+% (when choices are involved) parsing the key results in changes to the
+% default values. That is why they are loaded and then saved again.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_store_key_implementation:nnn #1#2#3
+ {
+ \xtemplate_recover_defaults:n { #1 / #2 }
+ \xtemplate_recover_keytypes:n { #1 / #2 }
+ \prop_clear:N \l_xtemplate_vars_prop
+ \keyval_parse:NNn
+ \xtemplate_parse_vars_elt:n \xtemplate_parse_vars_elt:nn {#3}
+ \xtemplate_store_vars:n { #1 / #2 }
+ \clist_clear:N \l_xtemplate_restrict_clist
+ \xtemplate_store_restrictions:n { #1 / #2 }
+ \prop_if_empty:NF \l_xtemplate_keytypes_prop
+ {
+ \prop_map_inline:Nn \l_xtemplate_keytypes_prop
+ {
+ \msg_error:nnxxx { xtemplate } { key-not-implemented }
+ {##1} {#2} {#1}
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_parse_vars_elt:n}
+% At the implementation stage, every key must have a value given. So
+% this is an error function.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_parse_vars_elt:n #1
+ { \msg_error:nnx { xtemplate } { key-no-variable } {#1} }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_parse_vars_elt:nn}
+% The actual storage part here is very simple: the storage bin name
+% is placed into the property list. At the same time, a comparison is
+% made with the keytypes defined earlier: if there is a mismatch then
+% an error is raised.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_parse_vars_elt:nn #1#2
+ {
+ \tl_set:Nx \l_xtemplate_key_name_tl { \tl_to_str:n {#1} }
+ \tl_remove_all:Nn \l_xtemplate_key_name_tl { ~ }
+ \prop_if_in:NoTF \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ {
+ \prop_get:NoN \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_keytype_tl
+ \xtemplate_split_keytype_arg:o \l_xtemplate_keytype_tl
+ \xtemplate_parse_vars_elt_aux:n {#2}
+ \prop_del:NV \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ }
+ { \msg_error:nnx { xtemplate } { unknown-key } {#1} }
+ }
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}[aux]{\xtemplate_parse_vars_elt_aux:n}
+% \begin{macro}[aux]{\xtemplate_parse_vars_elt_aux:w}
+% There now needs to be some sanity checking on the variable name
+% given. This does not apply for \texttt{choice} or
+% \texttt{code} \enquote{variables}, but in all other cases the variable
+% needs to exist. Also, the only prefix acceptable is \texttt{global}. So
+% there are a few related checks to make.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_parse_vars_elt_aux:n #1
+ {
+ \str_if_eq:onTF \l_xtemplate_keytype_tl { choice }
+ { \xtemplate_implement_choices:n {#1} }
+ {
+ \str_if_eq:onTF \l_xtemplate_keytype_tl { code }
+ {
+ \prop_put:Non \l_xtemplate_vars_prop
+ \l_xtemplate_key_name_tl {#1}
+ }
+ {
+ \str_if_eq:noTF {#1} { \tl_head:w #1 \q_stop }
+ {
+ \cs_if_exist:NTF #1
+ {
+ \prop_put:Non \l_xtemplate_vars_prop
+ \l_xtemplate_key_name_tl {#1}
+ }
+ {
+ \msg_error:nnx { xtemplate }
+ { variable-not-declared }
+ { \token_to_str:N #1 }
+ }
+ }
+ {
+ \tl_if_in:nnTF {#1} { global }
+ { \xtemplate_parse_vars_elt_aux:w #1 \q_stop }
+ {
+ \msg_error:nnx { xtemplate } { bad-variable }
+ { \tl_to_str:n {#1} }
+ }
+ }
+ }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_parse_vars_elt_aux:w #1 global #2 \q_stop
+ {
+ \tl_if_empty:nTF {#1}
+ {
+ \str_if_eq:noTF {#2} { \tl_head:w #2 \q_stop }
+ {
+ \cs_if_exist:NTF #2
+ {
+ \prop_put:Non \l_xtemplate_vars_prop
+ \l_xtemplate_key_name_tl { #1 global #2 }
+ }
+ {
+ \msg_error:nnx { xtemplate }
+ { variable-not-declared } { \token_to_str:N #2 }
+ }
+ }
+ {
+ \msg_error:nnx { xtemplate } { bad-variable }
+ { \tl_to_str:n { #1 global #2 } }
+ }
+ }
+ {
+ \msg_error:nnx { xtemplate } { bad-variable }
+ { \tl_to_str:n { #1 global #2 } }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_implement_choices:n}
+% \begin{macro}[aux]{\xtemplate_implement_choices_default:}
+% Implementing choices requires a second key--value loop. So after a
+% little set-up, the standard parser is called.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_implement_choices:n #1
+ {
+ \clist_set_eq:NN \l_xtemplate_tmp_clist \l_xtemplate_keytype_arg_tl
+ \prop_put:Non \l_xtemplate_vars_prop \l_xtemplate_key_name_tl { }
+ \keyval_parse:NNn
+ \xtemplate_implement_choice_elt:n \xtemplate_implement_choice_elt:nn
+ {#1}
+ \prop_if_in:NoT \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ { \xtemplate_implement_choices_default: }
+ \clist_if_empty:NF \l_xtemplate_tmp_clist
+ {
+ \clist_map_inline:Nn \l_xtemplate_tmp_clist
+ {
+ \msg_error:nnx { xtemplate } { choice-not-implemented }
+ {##1}
+ }
+ }
+ }
+% \end{macrocode}
+% A sanity check for the default value, so that an error is raised
+% now and not when converting to assignments.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_implement_choices_default:
+ {
+ \prop_get:NoN \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \tl_set:Nx \l_xtemplate_tmp_tl
+ { \l_xtemplate_key_name_tl \c_space_tl \l_xtemplate_tmp_tl }
+ \prop_if_in:NoF \l_xtemplate_vars_prop \l_xtemplate_tmp_tl
+ {
+ \tl_set:Nx \l_xtemplate_tmp_tl
+ { \l_xtemplate_key_name_tl \c_space_tl \l_xtemplate_tmp_tl }
+ \prop_if_in:NoF \l_xtemplate_vars_prop \l_xtemplate_tmp_tl
+ {
+ \prop_get:NoN \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \xtemplate_split_keytype_arg:o \l_xtemplate_tmp_tl
+ \prop_get:NoN \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \msg_error:nnxxx { xtemplate } { unknown-default-choice }
+ { \l_xtemplate_key_name_tl } { \l_xtemplate_key_name_tl }
+ { \l_xtemplate_keytype_arg_tl }
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_implement_choice_elt:n}
+% \begin{macro}{\xtemplate_implement_choice_elt:nn}
+% The actual storage of the implementation of a choice is mainly about
+% error checking. The code here ensures that all choices have to have
+% been declared, apart from the special \texttt{unknown} choice, which
+% must come last. The code for each choice is stored along with the
+% key name in the variables property list.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_implement_choice_elt:n #1
+ {
+ \clist_if_empty:NTF \l_xtemplate_tmp_clist
+ {
+ \str_if_eq:nnF {#1} { unknown }
+ {
+ \prop_get:NoN \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \xtemplate_split_keytype_arg:o \l_xtemplate_tmp_tl
+ \msg_error:nnxxx { xtemplate } { unknown-choice }
+ { \l_xtemplate_key_name_tl } {#1}
+ { \l_xtemplate_keytype_arg_tl }
+ }
+ }
+ {
+ \clist_if_in:NnTF \l_xtemplate_tmp_clist {#1}
+ { \clist_remove_element:Nn \l_xtemplate_tmp_clist {#1} }
+ {
+ \prop_get:NoN \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \xtemplate_split_keytype_arg:o \l_xtemplate_tmp_tl
+ \msg_error:nnxxx { xtemplate } { unknown-choice }
+ { \l_xtemplate_key_name_tl } {#1}
+ { \l_xtemplate_keytype_arg_tl }
+ }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_implement_choice_elt:nn #1#2
+ {
+ \xtemplate_implement_choice_elt:n {#1}
+ \tl_set:Nx \l_xtemplate_tmp_tl
+ { \l_xtemplate_key_name_tl \c_space_tl #1 }
+ \prop_put:Non \l_xtemplate_vars_prop \l_xtemplate_tmp_tl {#2}
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \subsection{Editing template defaults}
+%
+% Template defaults can be edited either with no other changes or
+% to prevent further editing, forming a \enquote{restricted template}.
+% In the later case, a new template results, whereas simple editing
+% does not produce a new template name.
+%
+% \begin{macro}{\xtemplate_declare_restricted:nnnn}
+% Creating a restricted template means copying the old template to the
+% new one first.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_declare_restricted:nnnn #1#2#3#4
+ {
+ \xtemplate_if_keys_exist:nnT {#1} {#2}
+ {
+ \xtemplate_set_template_eq:nn { #1 / #3 } { #1 / #2 }
+ \bool_set_true:N \l_xtemplate_restrict_bool
+ \xtemplate_edit_defaults_aux:nnn {#1} {#3} {#4}
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_edit_defaults:nnn}
+% \begin{macro}[aux]{\xtemplate_edit_defaults_aux:nnn}
+% Editing the template defaults means getting the values back out
+% of the store, then parsing the list of new values before putting
+% the updated list back into storage. The auxiliary function is used
+% to allow code-sharing with the template-restriction system.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_edit_defaults:nnn
+ {
+ \bool_set_false:N \l_xtemplate_restrict_bool
+ \xtemplate_edit_defaults_aux:nnn
+ }
+\cs_new_protected:Npn \xtemplate_edit_defaults_aux:nnn #1#2#3
+ {
+ \xtemplate_if_keys_exist:nnT {#1} {#2}
+ {
+ \xtemplate_recover_defaults:n { #1 / #2 }
+ \xtemplate_recover_restrictions:n { #1 / #2 }
+ \xtemplate_parse_values:nn { #1 / #2 } {#3}
+ \xtemplate_store_defaults:n { #1 / #2 }
+ \xtemplate_store_restrictions:n { #1 / #2 }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_parse_values:nn}
+% The routine to parse values is the same for both editing a
+% template and setting up an instance. So the code here does only the
+% minimum necessary for reading the values.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_parse_values:nn #1#2
+ {
+ \xtemplate_recover_keytypes:n {#1}
+ \clist_clear:N \l_xtemplate_restrict_clist
+ \keyval_parse:NNn
+ \xtemplate_parse_values_elt:n \xtemplate_parse_values_elt:nn {#2}
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_parse_values_elt:n}
+% Every key needs a value, so this is just an error routine.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_parse_values_elt:n #1
+ {
+ \bool_set_true:N \l_xtemplate_error_bool
+ \msg_error:nnx { xtemplate } { key-no-value } {#1}
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_parse_values_elt:nn}
+% \begin{macro}[aux]{\xtemplate_parse_values_elt_aux:nn}
+% \begin{macro}[aux]{\xtemplate_parse_values_elt_aux:on}
+% To store the value, find the keytype then call the saving function.
+% These need the current key name saved as \cs{l_xtemplate_key_name_tl}.
+% When a template is being restricted, the setting code will be
+% skipped for restricted keys.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_parse_values_elt:nn #1#2
+ {
+ \tl_set:Nx \l_xtemplate_key_name_tl { \tl_to_str:n {#1} }
+ \tl_remove_all:Nn \l_xtemplate_key_name_tl { ~ }
+ \prop_if_in:NoTF \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ {
+ \bool_if:NTF \l_xtemplate_restrict_bool
+ {
+ \clist_if_in:NoF \l_xtemplate_restrict_clist
+ \l_xtemplate_key_name_tl
+ {
+ \xtemplate_parse_values_elt_aux:on
+ \l_xtemplate_key_name_tl {#2}
+ }
+ }
+ { \xtemplate_parse_values_elt_aux:on \l_xtemplate_key_name_tl {#2} }
+ }
+ {
+ \msg_error:nnx { xtemplate } { unknown-key }
+ { \l_xtemplate_key_name_tl }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_parse_values_elt_aux:nn #1#2
+ {
+ \clist_put_right:Nn \l_xtemplate_restrict_clist {#1}
+ \prop_get:NnN \l_xtemplate_keytypes_prop {#1} \l_xtemplate_tmp_tl
+ \xtemplate_split_keytype_arg:o \l_xtemplate_tmp_tl
+ \use:c { xtemplate_store_value_ \l_xtemplate_keytype_tl :n } {#2}
+ }
+\cs_generate_variant:Nn \xtemplate_parse_values_elt_aux:nn { o }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_set_template_eq:nn}
+% To copy a template, each of the lists plus the code has to be copied
+% across. To keep this independent of the list storage system, it is
+% all done with two-part shuffles.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_set_template_eq:nn #1#2
+ {
+ \xtemplate_recover_defaults:n {#2}
+ \xtemplate_store_defaults:n {#1}
+ \xtemplate_recover_keytypes:n {#2}
+ \xtemplate_store_keytypes:n {#1}
+ \xtemplate_recover_vars:n {#2}
+ \xtemplate_store_vars:n {#1}
+ \cs_gset_eq:cc { \c_xtemplate_code_root_tl #1 }
+ { \c_xtemplate_code_root_tl #2 }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+%\subsection{Creating instances of templates}
+%
+% \begin{macro}{\xtemplate_declare_instance:nnnnn}
+% \begin{macro}[aux]{\xtemplate_declare_instance_aux:nnnnn}
+% Making an instance has two distinct parts. First, the keys given are
+% parsed to transfer the values into the structured data format used
+% internally. This allows the default and given values to be combined
+% with no repetition. In the second step, the structured data is
+% converted to pre-defined variable assignments, and these are stored
+% in the function for the instance. A final check is also made so that
+% there is always an instance \enquote{outside} of any collection.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_declare_instance:nnnnn #1#2#3#4#5
+ {
+ \xtemplate_execute_if_code_exist:nnT {#1} {#2}
+ {
+ \xtemplate_recover_defaults:n { #1 / #2 }
+ \xtemplate_recover_vars:n { #1 / #2 }
+ \xtemplate_declare_instance_aux:nnnnn {#1} {#2} {#3} {#4} {#5}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_declare_instance_aux:nnnnn #1#2#3#4#5
+ {
+ \bool_set_false:N \l_xtemplate_error_bool
+ \xtemplate_parse_values:nn { #1 / #2 } {#5}
+ \bool_if:NF \l_xtemplate_error_bool
+ {
+ \prop_put:Nnn \l_xtemplate_values_prop { from~template } {#2}
+ \xtemplate_store_values:n { #1 / #3 / #4 }
+ \xtemplate_convert_to_assignments:
+ \cs_set_protected:cpx { \c_xtemplate_instances_root_tl #1 / #3 / #4 }
+ {
+ \exp_not:N \xtemplate_assignments_push:n
+ { \exp_not:o \l_xtemplate_assignments_tl }
+ \exp_not:c { \c_xtemplate_code_root_tl #1 / #2 }
+ }
+ \xtemplate_if_instance_exist:nnnF {#1} { } {#4}
+ {
+ \cs_set_eq:cc
+ { \c_xtemplate_instances_root_tl #1 / / #4 }
+ { \c_xtemplate_instances_root_tl #1 / #3 / #4 }
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_edit_instance:nnnn}
+% \begin{macro}[aux]{\xtemplate_edit_instance_aux:nnnnn}
+% \begin{macro}[aux]{\xtemplate_edit_instance_aux:nonnn}
+% Editing an instance is almost identical to declaring one. The only
+% variation is the source of the values to use. When editing, they are
+% recovered from the previous instance run.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_edit_instance:nnnn #1#2#3
+ {
+ \xtemplate_if_instance_exist:nnnTF {#1} {#2} {#3}
+ {
+ \xtemplate_recover_values:n { #1 / #2 / #3 }
+ \prop_get:NnN \l_xtemplate_values_prop { from~template }
+ \l_xtemplate_tmp_tl
+ \xtemplate_edit_instance_aux:nonnn {#1} \l_xtemplate_tmp_tl
+ {#2} {#3}
+ }
+ {
+ \msg_error:nnxx { xtemplate } { unknown-instance }
+ {#1} {#3}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_edit_instance_aux:nnnnn #1#2
+ {
+ \xtemplate_recover_vars:n { #1 / #2 }
+ \xtemplate_declare_instance_aux:nnnnn {#1} {#2}
+ }
+\cs_generate_variant:Nn \xtemplate_edit_instance_aux:nnnnn { no }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_convert_to_assignments:}
+% \begin{macro}[aux]{\xtemplate_convert_to_assignments_aux:n}
+% \begin{macro}[aux]{\xtemplate_convert_to_assignments_aux:nn}
+% \begin{macro}[aux]{\xtemplate_convert_to_assignments_aux:no}
+% The idea on converting to a set of assignments is to loop over each
+% key, so that the loop order follows the declaration order of the keys.
+% This is done using a sequence as property lists are not
+% \enquote{ordered}.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_convert_to_assignments:
+ {
+ \tl_clear:N \l_xtemplate_assignments_tl
+ \seq_map_function:NN \l_xtemplate_key_order_seq
+ \xtemplate_convert_to_assignments_aux:n
+ }
+\cs_new_protected:Npn \xtemplate_convert_to_assignments_aux:n #1
+ {
+ \prop_get:NnN \l_xtemplate_keytypes_prop {#1} \l_xtemplate_tmp_tl
+ \xtemplate_convert_to_assignments_aux:no {#1} \l_xtemplate_tmp_tl
+ }
+% \end{macrocode}
+% The second auxiliary function actually does the work. The
+% arguments here are the key name (|#1|) and the keytype (|#2|).
+% From those, the value to assign and the name of the appropriate
+% variable are recovered. A bit of work is then needed to sort out
+% keytypes with arguments (for example instances), and to look for
+% global assignments. Once that is done, a hand-off can be made to the
+% handler for the relevant keytype.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_convert_to_assignments_aux:nn #1#2
+ {
+ \prop_if_in:NnT \l_xtemplate_values_prop {#1}
+ {
+ \prop_if_in:NnTF \l_xtemplate_vars_prop {#1}
+ {
+ \prop_get:NnN \l_xtemplate_values_prop {#1} \l_xtemplate_value_tl
+ \prop_get:NnN \l_xtemplate_vars_prop {#1} \l_xtemplate_var_tl
+ \xtemplate_split_keytype_arg:n {#2}
+ \str_if_eq:onF \l_xtemplate_keytype_tl { choice }
+ {
+ \str_if_eq:onF \l_xtemplate_keytype_tl { code }
+ { \xtemplate_find_global: }
+ }
+ \tl_set:Nn \l_xtemplate_key_name_tl {#1}
+ \use:c { xtemplate_assign_ \l_xtemplate_keytype_tl : }
+ }
+ { \msg_error:nnx { xtemplate } { unknown-attribute } {#1} }
+ }
+ }
+\cs_generate_variant:Nn \xtemplate_convert_to_assignments_aux:nn { no }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_find_global:}
+% \begin{macro}[aux]{\xtemplate_find_global_aux:w}
+% Global assignments should have the phrase |global| at the front.
+% This is pretty easy to find: no other error checking, though.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_find_global:
+ {
+ \bool_set_false:N \l_xtemplate_global_bool
+ \tl_if_in:onT \l_xtemplate_var_tl { global }
+ {
+ \exp_after:wN \xtemplate_find_global_aux:w \l_xtemplate_var_tl \q_stop
+ }
+ }
+\cs_new_protected:Npn \xtemplate_find_global_aux:w #1 global #2 \q_stop
+ {
+ \tl_set:Nn \l_xtemplate_var_tl {#2}
+ \bool_set_true:N \l_xtemplate_global_bool
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \subsection{Using templates directly}
+%
+% \begin{macro}{\xtemplate_use_template:nnn}
+% Directly use a template with a particular parameter setting.
+% This is also picked up if used in a nested fashion inside a parameter
+% list. The idea is essentially the same as creating an instance,
+% just with no saving of the result.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_use_template:nnn #1#2#3
+ {
+ \xtemplate_execute_if_code_exist:nnT {#1} {#2}
+ {
+ \xtemplate_recover_defaults:n { #1 / #2 }
+ \xtemplate_recover_vars:n { #1 / #2 }
+ \xtemplate_parse_values:nn { #1 / #2 } {#3}
+ \xtemplate_convert_to_assignments:
+ \use:c { \c_xtemplate_code_root_tl #1 / #2 }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{Assigning values to variables}
+%
+% \begin{macro}{\xtemplate_assign_boolean:}
+% \begin{macro}[aux]{\xtemplate_assign_boolean_aux:n}
+% Setting a Boolean value is slightly different to everything else
+% as the value can be used to work out which \texttt{set} function to
+% call. As long as there is no need to recover things from another
+% variable, everything is pretty easy.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_assign_boolean:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_boolean_aux:n { bool_gset } }
+ { \xtemplate_assign_boolean_aux:n { bool_set } }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_boolean_aux:n #1
+ {
+ \xtemplate_if_key_value:oT \l_xtemplate_value_tl
+ { \xtemplate_key_to_value: }
+ \tl_put_left:Nx \l_xtemplate_assignments_tl
+ {
+ \exp_not:c { #1 _ \l_xtemplate_value_tl :N }
+ \exp_not:o \l_xtemplate_var_tl
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_assign_choice:}
+% \begin{macro}[aux]
+% {\xtemplate_assign_choice_aux:n, \xtemplate_assign_choice_aux:o}
+% The idea here is to find either the choice as-given or else the
+% special |unknown| choice, and to copy the appropriate code across.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_assign_choice:
+ {
+ \tl_set:Nx \l_xtemplate_tmp_tl
+ { \l_xtemplate_key_name_tl \c_space_tl \l_xtemplate_value_tl }
+ \prop_if_in:NoTF \l_xtemplate_vars_prop \l_xtemplate_tmp_tl
+ { \xtemplate_assign_choice_aux:o \l_xtemplate_tmp_tl }
+ {
+ \tl_set:Nx \l_xtemplate_tmp_tl
+ { \l_xtemplate_key_name_tl \c_space_tl unknown }
+ \prop_if_in:NoTF \l_xtemplate_vars_prop \l_xtemplate_tmp_tl
+ { \xtemplate_assign_choice_aux:o \l_xtemplate_tmp_tl }
+ {
+ \prop_get:NoN \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \xtemplate_split_keytype_arg:o \l_xtemplate_tmp_tl
+ \msg_error:nnxxx { xtemplate } { unknown-choice }
+ { \l_xtemplate_key_name_tl } { \l_xtemplate_value_tl }
+ { \l_xtemplate_keytype_arg_tl }
+ }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_assign_choice_aux:n #1
+ {
+ \prop_get:NnN \l_xtemplate_vars_prop {#1} \l_xtemplate_tmp_tl
+ \tl_put_right:No \l_xtemplate_assignments_tl \l_xtemplate_tmp_tl
+ }
+\cs_generate_variant:Nn \xtemplate_assign_choice_aux:n { o }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_assign_code:}
+% \begin{macro}{\xtemplate_assign_code:n}
+% Assigning general code to a key needs a scratch function to be created
+% and run when \cs{AssignTemplateKeys} is called. So the appropriate
+% definition then use is created in the token list variable.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_assign_code:
+ {
+ \tl_put_left:Nx \l_xtemplate_assignments_tl
+ {
+ \cs_set_protected:Npn \xtemplate_assign_code:n \exp_not:n {##1}
+ { \exp_not:o \l_xtemplate_var_tl }
+ \xtemplate_assign_code:n { \exp_not:o \l_xtemplate_value_tl }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_assign_code:n #1 { }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_assign_function:}
+% \begin{macro}[aux]{\xtemplate_assign_function_aux:N}
+% This looks a bit messy but is only actually one function.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_assign_function:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_function_aux:N \cs_gset:Npn }
+ { \xtemplate_assign_function_aux:N \cs_set:Npn }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_function_aux:N #1
+ {
+ \tl_put_left:Nx \l_xtemplate_assignments_tl
+ {
+ \cs_generate_from_arg_count:NNnn
+ \exp_not:o \l_xtemplate_var_tl
+ \exp_not:N #1
+ { \exp_not:o \l_xtemplate_keytype_arg_tl }
+ { \exp_not:o \l_xtemplate_value_tl }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_assign_instance:}
+% \begin{macro}[aux]{\xtemplate_assign_instance_aux:N}
+% Using an instance means adding the appropriate function creation to
+% the tl. No checks are made at this stage, so if the instance is
+% not valid then errors will arise later.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_assign_instance:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_instance_aux:N \cs_gset_protected:Npn }
+ { \xtemplate_assign_instance_aux:N \cs_set_protected:Npn }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_instance_aux:N #1
+ {
+ \tl_put_left:Nx \l_xtemplate_assignments_tl
+ {
+ \exp_not:N #1 \exp_not:o \l_xtemplate_var_tl
+ {
+ \xtemplate_use_instance:nn
+ { \exp_not:o \l_xtemplate_keytype_arg_tl }
+ { \exp_not:o \l_xtemplate_value_tl }
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_assign_integer:}
+% \begin{macro}{\xtemplate_assign_length:}
+% \begin{macro}{\xtemplate_assign_muskip:}
+% \begin{macro}{\xtemplate_assign_real:}
+% \begin{macro}{\xtemplate_assign_skip:}
+% All of the calculated assignments use the same underlying code, with
+% only the low-level assignment function changing.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_assign_integer:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_variable:N \int_gset:Nn }
+ { \xtemplate_assign_variable:N \int_set:Nn }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_length:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_variable:N \dim_gset:Nn }
+ { \xtemplate_assign_variable:N \dim_set:Nn }
+}
+\cs_new_protected_nopar:Npn \xtemplate_assign_muskip:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_variable:N \muskip_gset:Nn }
+ { \xtemplate_assign_variable:N \muskip_set:Nn }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_real:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_variable:N \fp_gset:Nn }
+ { \xtemplate_assign_variable:N \fp_set:Nn }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_skip:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_variable:N \skip_gset:Nn }
+ { \xtemplate_assign_variable:N \skip_set:Nn }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_assign_tokenlist:}
+% \begin{macro}{\xtemplate_assign_commalist:}
+% \begin{macro}[aux]{\xtemplate_assign_tokenlist_aux:N}
+% Storing lists of tokens is easy: no complex calculations and no
+% need to worry about numbers of arguments. The comma list version
+% takes advantage of the low-level implementation of the variable type
+% to keep down code duplication.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_assign_tokenlist:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_tokenlist_aux:N \tl_gset:Nn }
+ { \xtemplate_assign_tokenlist_aux:N \tl_set:Nn }
+ }
+\cs_new_eq:NN \xtemplate_assign_commalist: \xtemplate_assign_tokenlist:
+\cs_new_protected_nopar:Npn \xtemplate_assign_tokenlist_aux:N #1
+ {
+ \xtemplate_if_key_value:oT \l_xtemplate_value_tl
+ { \xtemplate_key_to_value: }
+ \tl_put_left:Nx \l_xtemplate_assignments_tl
+ {
+ #1 \exp_not:o \l_xtemplate_var_tl
+ { \exp_not:o \l_xtemplate_value_tl }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_assign_variable:N}
+% A general-purpose function for all of the numerical assignments.
+% As long as the value is not coming from another variable, the stored
+% value is simply transferred for output.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_assign_variable:N #1
+ {
+ \xtemplate_if_key_value:oT \l_xtemplate_value_tl
+ { \xtemplate_key_to_value: }
+ \tl_put_left:Nx \l_xtemplate_assignments_tl
+ {
+ #1 \exp_not:o \l_xtemplate_var_tl
+ { \exp_not:o \l_xtemplate_value_tl }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_key_to_value:}
+% \begin{macro}[aux]{\xtemplate_key_to_value_aux:w}
+% The idea here is to recover the attribute value of another key. To
+% do that, the marker is removed and a look up takes place. If this
+% is successful, then the name of the variable of the attribute is
+% returned. This assumes that the value will be used in context where
+% it will be converted to a value, for example when setting a number.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_key_to_value:
+ { \exp_after:wN \xtemplate_key_to_value_aux:w \l_xtemplate_value_tl }
+\cs_new_protected:Npn \xtemplate_key_to_value_aux:w \KeyValue #1
+ {
+ \tl_set:Nx \l_xtemplate_tmp_tl { \tl_to_str:n {#1} }
+ \tl_remove_all:Nn \l_xtemplate_key_name_tl { ~ }
+ \prop_if_in:NoTF \l_xtemplate_vars_prop \l_xtemplate_tmp_tl
+ {
+ \prop_get:NoN \l_xtemplate_vars_prop \l_xtemplate_tmp_tl
+ \l_xtemplate_value_tl
+ }
+ {
+ \msg_error:nnx { xtemplate } { unknown-attribute }
+ { \l_xtemplate_tmp_tl }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \subsection{Using instances}
+%
+% \begin{macro}{\xtemplate_use_instance:nn}
+% \begin{macro}[aux]{\xtemplate_use_instance_aux:nNnnn}
+% \begin{macro}[aux]{\xtemplate_use_instance_aux:nn}
+% Using an instance is just a question of finding the appropriate
+% function. There is the possibility that a collection instance exists,
+% so this is checked before trying the general instance. If nothing is
+% found, an error is raised. One additional complication is that
+% if the first token of argument |#2| is \cs{UseTemplate} then that
+% is also valid. There is an error-test to make sure that the
+% types agree, and if so the template is used directly.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_use_instance:nn #1#2
+ {
+ \xtemplate_if_use_template:nTF {#2}
+ { \xtemplate_use_instance_aux:nNnnn {#1} #2 }
+ { \xtemplate_use_instance_aux:nn {#1} {#2} }
+ }
+\cs_new_protected:Npn \xtemplate_use_instance_aux:nNnnn #1#2#3#4#5
+ {
+ \str_if_eq:nnTF {#1} {#3}
+ { \xtemplate_use_template:nnn {#3} {#4} {#5} }
+ { \msg_error:nnxx { xtemplate } { type-mismatch } {#1} {#3} }
+}
+\cs_new_protected:Npn \xtemplate_use_instance_aux:nn #1#2
+ {
+ \xtemplate_get_collection:n {#1}
+ \xtemplate_if_instance_exist:nnnTF
+ {#1} { \l_xtemplate_collection_tl } {#2}
+ {
+ \use:c
+ {
+ \c_xtemplate_instances_root_tl #1 /
+ \l_xtemplate_collection_tl / #2
+ }
+ }
+ {
+ \xtemplate_if_instance_exist:nnnTF {#1} { } {#2}
+ { \use:c { \c_xtemplate_instances_root_tl #1 / / #2 } }
+ {
+ \msg_error:nnxx { xtemplate } { unknown-instance }
+ {#1} {#2}
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_use_collection:nn}
+% Switching to an instance collection is just a question of setting the
+% appropriate list.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_use_collection:nn #1#2
+ { \prop_put:Nnn \l_xtemplate_collections_prop {#1} {#2} }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_get_collection:n}
+% Recovering the collection for a given type is pretty easy: just a read
+% from the list.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_get_collection:n #1
+ {
+ \prop_if_in:NnTF \l_xtemplate_collections_prop {#1}
+ {
+ \prop_get:NnN \l_xtemplate_collections_prop {#1}
+ \l_xtemplate_collection_tl
+ }
+ { \tl_clear:N \l_xtemplate_collection_tl }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+%\subsection{Assignment manipulation}
+%
+% A few functions to transfer assignments about, as this is needed by
+% \cs{AssignTemplateKeys}.
+%
+% \begin{macro}{\xtemplate_assignments_pop:}
+% To actually use the assignments.
+% \begin{macrocode}
+\cs_new_nopar:Npn \xtemplate_assignments_pop: { \l_xtemplate_assignments_tl }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\xtemplate_assignments_push:n}
+% Here, the assignments are stored for later use.
+% \begin{macrocode}
+\cs_new_protected:Npn \xtemplate_assignments_push:n #1
+ { \tl_set:Nn \l_xtemplate_assignments_tl {#1} }
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{Showing templates and instances}
+%
+% \begin{macro}{\xtemplate_show_code:nn}
+% Showing the code for a template is just a translation of
+% \cs{cs_show:c}.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_show_code:nn #1#2
+ { \cs_show:c { \c_xtemplate_code_root_tl #1 / #2 } }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}
+% {
+% \xtemplate_show_defaults:nn, \xtemplate_show_keytypes:nn,
+% \xtemplate_show_vars:nn
+% }
+% \begin{macro}[int]{\xtemplate_show:Nnnn}
+% \begin{macro}[aux]{\xtemplate_show_aux:nn}
+% A modified version of the property-list printing code, such that
+% the output refers to templates and instances rather than to the
+% underlying structures.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_show_defaults:nn #1#2
+ {
+ \xtemplate_if_keys_exist:nnT {#1} {#2}
+ {
+ \xtemplate_recover_defaults:n { #1 / #2 }
+ \xtemplate_show:Nnnn \l_xtemplate_values_prop
+ {#1} {#2} { default~values }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_show_keytypes:nn #1#2
+ {
+ \xtemplate_if_keys_exist:nnT {#1} {#2}
+ {
+ \xtemplate_recover_keytypes:n { #1 / #2 }
+ \xtemplate_show:Nnnn \l_xtemplate_keytypes_prop
+ {#1} {#2} { interface }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_show_vars:nn #1#2
+ {
+ \xtemplate_execute_if_code_exist:nnT {#1} {#2}
+ {
+ \xtemplate_recover_vars:n { #1 / #2 }
+ \xtemplate_show:Nnnn \l_xtemplate_vars_prop
+ {#1} {#2} { variable~mapping }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_show:Nnnn #1#2#3#4
+ {
+ \prop_if_empty:NTF #1
+ {
+ \iow_term:x { Template~'#3'~of~object~type~'#2'~has~no~#4 . }
+ \tl_show:n { }
+ }
+ {
+ \iow_term:x { Template~'#3'~of~object~type~'#2'~has~ #4 : }
+ \tl_set:Nx \l_prop_show_tl
+ { \prop_map_function:NN #1 \xtemplate_show_aux:nn }
+ \etex_showtokens:D \exp_after:wN \exp_after:wN \exp_after:wN
+ { \exp_after:wN \prop_show_aux:w \l_prop_show_tl }
+ }
+}
+\cs_new:Npn \xtemplate_show_aux:nn #1#2
+ {
+ \iow_newline: > \c_space_tl \c_space_tl
+ #1
+ \c_space_tl \c_space_tl => \c_space_tl \c_space_tl
+ \exp_not:n {#2}
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\template_show_values:nnn}
+% Instance values are a little more complex, as there are the collection
+% and template to consider.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \xtemplate_show_values:nnn #1#2#3
+ {
+ \xtemplate_if_instance_exist:nnnT {#1} {#2} {#3}
+ {
+ \xtemplate_recover_values:n { #1 / #2 / #3 }
+ \prop_if_empty:NTF \l_xtemplate_values_prop
+ {
+ \iow_term:x
+ {
+ \tl_if_empty:nTF {#2}
+ { Instance~'#3'~ }
+ { Collection instance~'#3'~(from~collection~'#2')~ }
+ of~object~type~'#1'~has~no~values.
+ }
+ \tl_show:n { }
+ }
+ {
+ \prop_pop:NnN \l_xtemplate_values_prop { from~template }
+ \l_xtemplate_tmp_tl
+ \iow_term:x
+ {
+ \tl_if_empty:nTF {#2}
+ { Instance~'#3'~ }
+ { Collection instance~'#3'~(from~collection~'#2')~ }
+ of~object~type~'#1'
+ \quark_if_no_value:NF \l_xtemplate_tmp_tl
+ { ~(from~template~' \l_xtemplate_tmp_tl ')~ }
+ has~values:
+ }
+ \tl_set:Nx \l_prop_show_tl
+ {
+ \prop_map_function:NN \l_xtemplate_values_prop
+ \xtemplate_show_aux:nn
+ }
+ \etex_showtokens:D \exp_after:wN \exp_after:wN \exp_after:wN
+ { \exp_after:wN \prop_show_aux:w \l_prop_show_tl }
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{Messages}
+%
+% The text for error messages: short and long text for all of them.
+% \begin{macrocode}
+\msg_new:nnnn { xtemplate } { argument-number-mismatch }
+ { Object~type~'#1'~takes~#2~argument(s). }
+ {
+ \c_msg_coding_error_text_tl
+ Objects~of~type~'#1'~require~#2~argument(s).\\
+ You~have~tried~to~make~a~template~for~'#1'~
+ with~#3~argument(s),~which~is~not~possible:~
+ the~number~of~arguments~must~agree.
+ }
+\msg_new:nnnn { xtemplate } { bad-number-of-arguments }
+ { Bad~number~of~arguments~for~object~type~'#1'. }
+ {
+ \c_msg_coding_error_text_tl
+ An~object~may~accept~between~0~and~9~arguments.\\
+ You~asked~to~use~#2~arguments:~this~is~not~supported.
+ }
+\msg_new:nnnn { xtemplate } { bad-variable }
+ { Incorrect~variable~description. }
+ {
+ The~argument~'#1'~is~not~of~the~form \\
+ ~~'<variable>'\\
+ ~or~\\
+ ~~'global~<variable>'.\\
+ It~must~be~given~in~one~of~these~formats~to~be~used~in~a~template.
+ }
+\msg_new:nnnn { xtemplate } { choice-not-implemented }
+ { The~choice~'#1'~has~no~implementation. }
+ {
+ Each~choice~listed~in~the~interface~for~a~template~must~
+ have~an~implementation.
+ }
+\msg_new:nnnn { xtemplate } { choice-no-code }
+ { The~choice~'#1'~requires~implementation~details. }
+ {
+ \c_msg_coding_error_text_tl
+ When~creating~template~code~using~\DeclareTemplateCode,~
+ each~choice~name~must~have~an~associated~implementation.\\
+ This~should~be~given~after~a~'='~sign:~LaTeX~did~not~find~one.
+ }
+\msg_new:nnnn { xtemplate } { duplicate-key-interface }
+ { Key~'#1'~appears~twice~in~interface~definition~\msg_line_context:. }
+ {
+ \c_msg_coding_error_text_tl
+ Each~key~can~only~have~one~interface~declared~in~a~template.\\
+ LaTeX~found~two~interfaces~for~'#1'.
+ }
+\msg_new:nnnn { xtemplate } { keytype-requires-argument }
+ { The~key~type~'#1'~requires~an~argument~\msg_line_context:. }
+ {
+ You~should~have~put:\\
+ \ \ <key-name>~:~#1~{~<argument>~} \\
+ but~LaTeX~did~not~find~an~<argument>.
+ }
+\msg_new:nnnn { xtemplate } { invalid-keytype }
+ { The~key~'#1'~is~missing~a~key-type~\msg_line_context:. }
+ {
+ \c_msg_coding_error_text_tl
+ Each~key~in~a~template~requires~a~key-type,~given~in~the~form:\\
+ \ \ <key>~:~<key-type>\\
+ LaTeX~could~not~find~a~<key-type>~in~your~input.
+ }
+\msg_new:nnnn { xtemplate } { key-no-value }
+ { The~key~'#1'~has~no~value~\msg_line_context:. }
+ {
+ \c_msg_coding_error_text_tl
+ When~creating~an~instance~of~a~template~
+ every~key~listed~must~include~a~value:\\
+ \ \ <key>~=~<value>
+ }
+\msg_new:nnnn { xtemplate } { key-no-variable }
+ { The~key~'#1'~requires~implementation~details~\msg_line_context:. }
+ {
+ \c_msg_coding_error_text_tl
+ When~creating~template~code~using~\DeclareTemplateCode,~
+ each~key~name~must~have~an~associated~implementation.\\
+ This~should~be~given~after~a~'='~sign:~LaTeX~did~not~find~one.
+ }
+\msg_new:nnnn { xtemplate } { key-not-implemented }
+ { Key~'#1'~has~no~implementation~\msg_line_context:. }
+ {
+ \c_msg_coding_error_text_tl
+ The~definition~of~key~implementations~for~template~'#2'~
+ of~object~type~'#3'~does~not~include~any~details~for~key~'#1'.\\
+ The~key~was~declared~in~the~interface~definition,~
+ and~so~an~implementation~is~required.
+ }
+\msg_new:nnnn { xtemplate } { missing-keytype }
+ { The~key~'#1'~is missing~a~key-type~\msg_line_context:. }
+ {
+ \c_msg_coding_error_text_tl
+ Key~interface~definitions~should~be~of~the~form\\
+ \ \ #1~:~<key-type>\\
+ but~LaTeX~could~not~find~a~<key-type>.
+ }
+\msg_new:nnnn { xtemplate } { no-template-code }
+ {
+ The~template~'#2'~of~type~'#1'~is~unknown~
+ or~has~no~implementation.
+ }
+ {
+ \c_msg_coding_error_text_tl
+ There~is~no~code~available~for~the~template~name~given.\\
+ This~should~be~given~using~\DeclareTemplateCode.
+ }
+\msg_new:nnnn { xtemplate } { object-type-mismatch }
+ { Object~types~'#1'~and~'#2'~do~not~agree. }
+ {
+ You~are~trying~to~use~a~template~directly~with~\UseInstance
+ (or~a~similar~function),~but~the~object~types~do~not~match.
+ }
+\msg_new:nnnn { xtemplate } { unknown-attribute }
+ { The~template~attribute~'#1'~is~unknown. }
+ {
+ There~is~a~definition~in~the~current~template~reading\\
+ \ \ \token_to_str:N \KeyValue {~#1~} \\
+ but~there~is~no~key~called~'#1'.
+ }
+\msg_new:nnnn { xtemplate } { unknown-choice }
+ { The~choice~'#2'~was~not~declared~for~key~'#1'. }
+ {
+ The~key~'#1'~takes~a~fixed~list~of~choices~
+ and~this~list~does~not~include~'#2'.
+ }
+\msg_new:nnnn { xtemplate } { unknown-default-choice }
+ { The~default~choice~'#2'~was~not~declared~for~key~'#1'. }
+ {
+ The~key~'#1'~takes~a~fixed~list~of~choices~
+ and~this~list~does~not~include~'#2'.
+ }
+\msg_new:nnnn { xtemplate } { unknown-instance }
+ { The~instance~'#2'~of~type~'#1'~is~unknown. }
+ {
+ You~have~asked~to~use~an~instance~'#2',~
+ but~this~has~not~been~created.
+ }
+\msg_new:nnnn { xtemplate } { unknown-key }
+ { Unknown~template~key~'#1'. }
+ {
+ \c_msg_coding_error_text_tl
+ The~key~'#1'~was~not~declared~in~the~interface~
+ for~the~current~template.
+ }
+\msg_new:nnnn { xtemplate } { unknown-keytype }
+ { The~key-type~'#1'~is~unknown. }
+ {
+ \c_msg_coding_error_text_tl
+ Valid~key-types~are:\\
+ -~boolean;\\
+ -~choice;\\
+ -~code;\\
+ -~commalist;\\
+ -~function;\\
+ -~instance;\\
+ -~integer;\\
+ -~length;\\
+ -~muskip;\\
+ -~real;\\
+ -~skip;\\
+ -~tokenlist.
+ }
+\msg_new:nnnn { xtemplate } { unknown-object-type }
+ { The~object~type~'#1'~is~unknown. }
+ {
+ \c_msg_coding_error_text_tl
+ An~object~type~needs~to~be~declared~with~\DeclareObjectType
+ prior~to~using~it.
+ }
+\msg_new:nnnn { xtemplate } { unknown-template }
+ { The~template~'#2'~of~type~'#1'~is~unknown. }
+ {
+ No~interface~has~been~declared~for~a~template~
+ '#2'~of~object~type~'#1'.
+ }
+\msg_new:nnnn { xtemplate } { variable-not-declared }
+ { The~variable~'#1'~has~not~been~declared. }
+ {
+ Before~declaring~an~instance,~all~of~the~required~variables~
+ used~in~template~keys~must~be~created.
+ }
+% \end{macrocode}
+%
+% Information messages only have text: more text should not be needed.
+% \begin{macrocode}
+\msg_new:nnn { xtemplate } { declare-object-type }
+ { Declaring~object~type~'#1'~taking~#2~argument(s)~\msg_line_context:. }
+\msg_new:nnn { xtemplate } { declare-template-code }
+ { Declaring~code~for~template~'#2'~of~object~type'#1'~\msg_line_context:. }
+\msg_new:nnn { xtemplate } { declare-template-interface }
+ {
+ Declaring~interface~for~template~'#2'~of~object~type~'#1'~
+ \msg_line_context:.
+ }
+% \end{macrocode}
+%
+% \subsection{User functions}
+%
+% The user functions provided by \pkg{xtemplate} are pretty much direct
+% copies of internal ones. However, by sticking to the \pkg{xparse}
+% approach only the appropriate arguments are long.
+%
+% \begin{macro}{\DeclareObjectType}
+% \begin{macro}{\DeclareTemplateInterface}
+% \begin{macro}{\DeclareTemplateCode}
+% \begin{macro}{\DeclareRestrictedTemplate}
+% \begin{macro}{\EditTemplateDefaults}
+% \begin{macro}{\DeclareInstance}
+% \begin{macro}{\DeclareCollectionInstance}
+% \begin{macro}{\EditInstance}
+% \begin{macro}{\EditCollectionInstance}
+% \begin{macro}{\UseTemplate}
+% \begin{macro}{\UseInstance}
+% \begin{macro}{\UseCollection}
+% All simple translations, with the appropriate long/short argument
+% filtering.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \DeclareObjectType #1#2
+ { \xtemplate_declare_object_type:nn {#1} {#2} }
+\cs_new_protected:Npn \DeclareTemplateInterface #1#2#3#4
+ { \xtemplate_declare_template_keys:nnnn {#1} {#2} {#3} {#4} }
+\cs_new_protected:Npn \DeclareTemplateCode #1#2#3#4#5
+ { \xtemplate_declare_template_code:nnnnn {#1} {#2} {#3} {#4} {#5} }
+\cs_new_protected:Npn \DeclareRestrictedTemplate #1#2#3#4
+ { \xtemplate_declare_restricted:nnnn {#1} {#2} {#3} {#4} }
+\cs_new_protected:Npn \DeclareInstance #1#2#3#4
+ { \xtemplate_declare_instance:nnnnn {#1} {#3} { } {#2} {#4} }
+\cs_new_protected:Npn \DeclareCollectionInstance #1#2#3#4#5
+ { \xtemplate_declare_instance:nnnnn {#2} {#4} {#1} {#3} {#5} }
+\cs_new_protected:Npn \EditTemplateDefaults #1#2#3
+ { \xtemplate_edit_defaults:nnn {#1} {#2} {#3} }
+\cs_new_protected:Npn \EditInstance #1#2#3
+ { \xtemplate_edit_instance:nnnn {#1} { } {#2} {#3} }
+\cs_new_protected:Npn \EditCollectionInstance #1#2#3#4
+ { \xtemplate_edit_instance:nnnn {#2} {#1} {#3} {#4} }
+\cs_new_protected_nopar:Npn \UseTemplate #1#2#3
+ { \xtemplate_use_template:nnn {#1} {#2} {#3} }
+\cs_new_protected_nopar:Npn \UseInstance #1#2
+ { \xtemplate_use_instance:nn {#1} {#2} }
+\cs_new_protected_nopar:Npn \UseCollection #1#2
+ { \xtemplate_use_collection:nn {#1} {#2} }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\ShowTemplateCode}
+% \begin{macro}{\ShowTemplateDefaults}
+% \begin{macro}{\ShowTemplateInterface}
+% \begin{macro}{\ShowTemplateVariables}
+% \begin{macro}{\ShowInstanceValues}
+% \begin{macro}{\ShowCollectionInstanceValues}
+% The show functions are again just translation.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \ShowTemplateCode #1#2
+ { \xtemplate_show_code:nn {#1} {#2} }
+\cs_new_protected_nopar:Npn \ShowTemplateDefaults #1#2
+ { \xtemplate_show_defaults:nn {#1} {#2} }
+\cs_new_protected_nopar:Npn \ShowTemplateInterface #1#2
+ { \xtemplate_show_keytypes:nn {#1} {#2} }
+\cs_new_protected_nopar:Npn \ShowTemplateVariables #1#2
+ { \xtemplate_show_vars:nn {#1} {#2} }
+\cs_new_protected_nopar:Npn \ShowInstanceValues #1#2
+ { \xtemplate_show_values:nnn {#1} { } {#2} }
+\cs_new_protected_nopar:Npn \ShowCollectionInstanceValues #1#2#3
+ { \xtemplate_show_values:nnn {#1} {#2} {#3} }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}[TF]{\IfInstanceExist}
+% More direct translation: only the base instance is checked for.
+% \begin{macrocode}
+\cs_new_nopar:Npn \IfInstanceExistTF #1#2
+ { \xtemplate_if_instance_exist:nnnTF {#1} { } {#2} }
+\cs_new_nopar:Npn \IfInstanceExistT #1#2
+ { \xtemplate_if_instance_exist:nnnT {#1} { } {#2} }
+\cs_new_nopar:Npn \IfInstanceExistF #1#2
+ { \xtemplate_if_instance_exist:nnnF {#1} { } {#2} }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\EvaluateNow}
+% \begin{macro}{\KeyValue}
+% These are both do nothing functions. Both simply dump their arguments
+% when executed: this should not happen with \cs{KeyValue}.
+% \begin{macrocode}
+\cs_new_protected:Npn \EvaluateNow #1 {#1}
+\cs_new_protected:Npn \KeyValue #1 {#1}
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\AssignTemplateKeys}
+% A short call to use a token register by proxy.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \AssignTemplateKeys
+ { \xtemplate_assignments_pop: }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\cs_new_eq:NN \ShowTemplateKeytypes \ShowTemplateInterface
+% \end{macrocode}
+%
+% \begin{macrocode}
+%</package>
+% \end{macrocode}
+%
+%\end{implementation}
+%
+%\PrintIndex
diff --git a/Master/texmf-dist/source/latex/l3packages/xtemplate/xtemplate.ins b/Master/texmf-dist/source/latex/l3packages/xtemplate/xtemplate.ins
new file mode 100644
index 00000000000..71fa6cc29f6
--- /dev/null
+++ b/Master/texmf-dist/source/latex/l3packages/xtemplate/xtemplate.ins
@@ -0,0 +1,40 @@
+\iffalse meta-comment
+
+File xtemplate.ins Copyright (C) 2000-2011 The LaTeX3 Project
+
+It may be distributed and/or modified under the conditions of the
+LaTeX Project Public License (LPPL), either version 1.3c of this
+license or (at your option) any later version. The latest version
+of this license is in the file
+
+ http://www.latex-project.org/lppl.txt
+
+This file is part of the "l3packages bundle" (The Work in LPPL)
+and all files in that bundle must be distributed together.
+
+The released version of this bundle is available from CTAN.
+
+\fi
+
+\input docstrip.tex
+\askforoverwritefalse
+
+\preamble
+
+EXPERIMENTAL CODE
+
+Do not distribute this file without also distributing the
+source files specified above.
+
+Do not distribute a modified version of this file.
+
+\endpreamble
+% stop docstrip adding \endinput
+\postamble
+\endpostamble
+
+\keepsilent
+
+\generate{\file{xtemplate.sty} {\from{xtemplate.dtx} {package}}}
+
+\endbatchfile
diff --git a/Master/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty b/Master/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty
new file mode 100644
index 00000000000..3a84d0e1d4f
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty
@@ -0,0 +1,156 @@
+%%
+%% This is file `l3keys2e.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% l3keys2e.dtx (with options: `package')
+%%
+%% EXPERIMENTAL CODE
+%%
+%% Do not distribute this file without also distributing the
+%% source files specified above.
+%%
+%% Do not distribute a modified version of this file.
+%%
+%% File: l3keys2e.dtx (C) Copyright 2009,2011 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3packages bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\RequirePackage{xparse}
+\GetIdInfo$Id: l3keys2e.dtx 2492 2011-07-02 13:40:38Z joseph $
+ {LaTeX2e option processing using LaTeX3 keys}
+\ProvidesExplPackage
+ {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+\@ifpackagelater { l3token } { 2011/07/02 }
+ { }
+ {
+ \PackageError { l3keys2e } { Support~package~l3kernel~too~old. }
+ {
+ Please~install~an~up~to~date~version~of~l3kernel~
+ using~your~TeX~package~manager~or~from~CTAN.\\ \\
+ Loading~l3keys2e~will~abort!
+ }
+ \tex_endinput:D
+ }
+\clist_new:N \keys_latexe_options_clist
+\bool_new:N \_l_keys_process_class_bool
+\cs_new_protected:Npn \keys_latexe_options:n #1
+ {
+ \clist_clear:N \keys_latexe_options_clist
+ \keys_latexe_options_global:n {#1}
+ \keys_latexe_options_local:
+ \keys_if_exist:nnF {#1} { unknown }
+ {
+ \keys_define:nn {#1}
+ {
+ unknown .code:n =
+ {
+ \msg_error:nnxx { keyvalue } { option-unknown }
+ { \l_keys_key_tl } { \@currname }
+ }
+ }
+ }
+ \keys_set:nV {#1} \keys_latexe_options_clist
+ \AtEndOfPackage { \cs_set_eq:NN \@unprocessedoptions \scan_stop: }
+ }
+\cs_new_protected:Npn \keys_latexe_options_global:n #1
+ {
+ \cs_if_eq:NNF \@classoptionslist \scan_stop:
+ {
+ \cs_if_eq:NNTF \@currext \@clsextension
+ { \keys_latexe_options_class:n {#1} }
+ {
+ \bool_if:NT \_l_keys_process_class_bool
+ { \keys_latexe_options_package:n {#1} }
+ }
+ }
+ }
+\cs_new_protected:Npn \keys_latexe_options_class:n #1
+ {
+ \keys_if_exist:nnTF {#1} { unknown }
+ { \clist_put_right:No \keys_latexe_options_clist \@classoptionslist }
+ {
+ \clist_map_inline:Nn \@classoptionslist
+ {
+ \keys_if_exist:nnTF {#1} { \keys_latexe_remove_equals:n {##1} }
+ { \clist_put_right:Nn \keys_latexe_options_clist {##1} }
+ { \clist_put_right:Nn \@unusedoptionlist {##1} }
+ }
+ }
+ }
+\cs_new_protected:Npn \keys_latexe_options_package:n #1
+ {
+ \clist_map_inline:Nn \@classoptionslist
+ {
+ \keys_if_exist:nnT {#1} { \keys_latexe_remove_equals:n {##1} }
+ {
+ \clist_put_right:Nn \keys_latexe_options_clist {##1}
+ \clist_remove_element:Nn \@unusedoptionlist {##1}
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn \keys_latexe_options_local:
+ {
+ \cs_if_eq:NNF \@currext \@clsextension
+ {
+ \cs_if_exist:cT { opt@ \@currname . \@currext }
+ {
+ \exp_args:NNc \clist_put_right:NV \keys_latexe_options_clist
+ { opt@ \@currname . \@currext }
+ }
+ }
+ }
+\cs_new:Npn \keys_latexe_remove_equals:n #1
+ { \keys_latexe_remove_equals:w #1 = \q_stop }
+\cs_new:Npn \keys_latexe_remove_equals:w #1 = #2 \q_stop {#1}
+\cs_new_protected_nopar:Npn \ProcessKeysOptions #1
+ {
+ \bool_set_true:N \_l_keys_process_class_bool
+ \keys_latexe_options:n {#1}
+ }
+\cs_new_protected_nopar:Npn \ProcessKeysPackageOptions #1
+ {
+ \bool_set_false:N \_l_keys_process_class_bool
+ \keys_latexe_options:n {#1}
+ }
+\@onlypreamble \ProcessKeysOptions
+\@onlypreamble \ProcessKeysPackageOptions
+\msg_new:nnnn { keyvalue } { option-unknown }
+ { Unknown~option~'#1'~for~package~#2. }
+ {
+ LaTeX~has~been~asked~to~set~an~option~called~'#1'~
+ but~the~#2~package~has~not~created~an~option~with~this~name.
+ }
+%%
+%%
+%% End of file `l3keys2e.sty'.
diff --git a/Master/texmf-dist/tex/latex/l3packages/xfrac/xfrac.sty b/Master/texmf-dist/tex/latex/l3packages/xfrac/xfrac.sty
new file mode 100644
index 00000000000..d53d6d62bcb
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/l3packages/xfrac/xfrac.sty
@@ -0,0 +1,438 @@
+%%
+%% This is file `xfrac.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% xfrac.dtx (with options: `package')
+%%
+%% EXPERIMENTAL CODE
+%%
+%% Do not distribute this file without also distributing the
+%% source files specified above.
+%%
+%% Do not distribute a modified version of this file.
+%%
+%% File: xfrac.dtx Copyright (C) 2004, 2008-2010 Morten Hoegholm
+%% (C) 2011 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3packages bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\RequirePackage{amstext,graphicx,l3keys2e,textcomp,xparse,xtemplate}
+\GetIdInfo$Id: xfrac.dtx 2349 2011-05-11 18:44:37Z joseph $
+ {L3 Experimental split-level fractions}
+\ProvidesExplPackage
+ {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+\keys_define:nn { xfrac }
+ {
+ cm-recommended .choice:,
+ cm-recommended /
+ false .code:n =
+ { \bool_set_true:N \l_xfrac_cm_std_bool },
+ cm-recommended /
+ true .code:n =
+ { \bool_set_false:N \l_xfrac_cm_std_bool },
+ cm-recommended .default:n = { true },
+ cm-standard .bool_set:N = \l_xfrac_cm_std_bool
+ }
+\ProcessKeysOptions { xfrac }
+\box_new:N \l_xfrac_slash_box
+\box_new:N \l_xfrac_tmp_box
+\cs_new:Npn \xfrac_tmp:w { }
+\dim_new:N \l_xfrac_denominator_bot_sep_dim
+\dim_new:N \l_xfrac_numerator_bot_sep_dim
+\dim_new:N \l_xfrac_numerator_top_sep_dim
+\dim_new:N \l_xfrac_slash_left_sep_dim
+\dim_new:N \l_xfrac_slash_right_sep_dim
+\muskip_new:N \l_xfrac_slash_left_muskip
+\muskip_new:N \l_xfrac_slash_right_muskip
+\fp_new:N \l_xfrac_hscale_fp
+\fp_new:N \l_xfrac_scale_factor_fp
+\fp_new:N \l_xfrac_vscale_fp
+\tl_new:N \l_xfrac_denominator_font_tl
+\tl_new:N \l_xfrac_numerator_font_tl
+\tl_new:N \l_xfrac_phantom_tl
+\tl_new:N \l_xfrac_slash_symbol_tl
+\tl_new:N \l_xfrac_slash_symbol_font_tl
+\cs_new_nopar:Npn \xfrac_fontscale:
+\cs_new:Npn \xfrac_math:n #1 { }
+\cs_new_nopar:Npn \xfrac_denominator_font_change: { }
+\cs_new:Npn \xfrac_denominator_format:n #1 { }
+\cs_new_nopar:Npn \xfrac_numerator_font_change: { }
+\cs_new:Npn \xfrac_numerator_format:n #1 { }
+\cs_new_nopar:Npn \xfrac_relscale: { }
+\cs_new_nopar:Npn \xfrac_slash_symbol_font_change: { }
+\cs_new:Npn \xfrac_slash_symbol_format:n #1 { }
+\cs_new:Npn \xfrac_text_or_math:n #1 { }
+\DeclareObjectType { xfrac } { 3 }
+\DeclareTemplateInterface { xfrac } { text } { 3 }
+ {
+ denominator-bot-sep : length = \c_max_dim ,
+ denominator-font : tokenlist = \f@family ,
+ denominator-format : function 1 = #1 ,
+ h-scale : real = 1 ,
+ math-mode : choice { false , true }
+ = false ,
+ numerator-font : tokenlist = \f@family ,
+ numerator-format : function 1 = #1 ,
+ numerator-bot-sep : length = \c_max_dim ,
+ numerator-top-sep : length = \c_max_dim ,
+ phantom : tokenlist = 8 ,
+ scale-factor : real = 0.83333 ,
+ scale-relative : choice { false , true }
+ = true ,
+ scaling : choice { false , true }
+ = true ,
+ slash-left-kern : length = 0 pt ,
+ slash-left-mkern : muskip = -2 mu ,
+ slash-right-kern : length = 0 pt ,
+ slash-right-mkern : muskip = -1 mu ,
+ slash-symbol : tokenlist = \textfractionsolidus ,
+ slash-symbol-font : tokenlist = \f@family ,
+ slash-symbol-format : function 1 = #1 ,
+ v-scale : real = 1 ,
+ }
+\DeclareTemplateCode { xfrac } { text } { 3 }
+ {
+ denominator-bot-sep = \l_xfrac_denominator_bot_sep_dim ,
+ denominator-font = \l_xfrac_denominator_font_tl ,
+ denominator-format = \xfrac_denominator_format:n ,
+ h-scale = \l_xfrac_hscale_fp ,
+ math-mode =
+ {
+ false = \cs_set_eq:NN \xfrac_math:n \use:n,
+ true = \cs_set_eq:NN \xfrac_math:n \ensuremath
+ },
+ numerator-font = \l_xfrac_numerator_font_tl ,
+ numerator-format = \xfrac_numerator_format:n ,
+ numerator-bot-sep = \l_xfrac_numerator_bot_sep_dim ,
+ numerator-top-sep = \l_xfrac_numerator_top_sep_dim ,
+ phantom = \l_xfrac_phantom_tl ,
+ scale-factor = \l_xfrac_scale_factor_fp ,
+ scale-relative =
+ {
+ false =
+ \cs_set_nopar:Npn \xfrac_relscale:
+ {
+ \dim_eval:w
+ \box_ht:N \l_xfrac_tmp_box + \box_dp:N \l_xfrac_tmp_box
+ \dim_eval_end:
+ },
+ true =
+ \cs_set_nopar:Npn \xfrac_relscale:
+ { \box_ht:N \l_xfrac_slash_box }
+ },
+ scaling =
+ {
+ false = \cs_set_eq:NN \xfrac_fontscale: \prg_do_nothing:,
+ true =
+ \cs_set_nopar:Npn \xfrac_fontscale:
+ {
+ \fontsize
+ { \fp_use:N \l_xfrac_scale_factor_fp \xfrac_relscale: }
+ { \c_zero_dim }
+ \selectfont
+ }
+ },
+ slash-left-kern = \l_xfrac_slash_left_sep_dim ,
+ slash-left-mkern = \l_xfrac_slash_left_muskip ,
+ slash-right-kern = \l_xfrac_slash_right_sep_dim ,
+ slash-right-mkern = \l_xfrac_slash_right_muskip ,
+ slash-symbol = \l_xfrac_slash_symbol_tl ,
+ slash-symbol-font = \l_xfrac_slash_symbol_font_tl ,
+ slash-symbol-format = \xfrac_slash_symbol_format:n ,
+ v-scale = \l_xfrac_vscale_fp
+ }
+ {
+ \AssignTemplateKeys
+ \mode_if_math:TF
+ {
+ \cs_set_eq:NN \xfrac_text_or_math:n \text
+ \cs_set_nopar:Npx \xfrac_denominator_font_change:
+ { \tex_fam:D \l_xfrac_denominator_font_tl }
+ \cs_set_nopar:Npx \xfrac_numerator_font_change:
+ { \tex_fam:D \l_xfrac_numerator_font_tl }
+ \cs_set_nopar:Npx \xfrac_slash_symbol_font_change:
+ { \tex_fam:D \l_xfrac_slash_symbol_font_tl }
+ }
+ {
+ \cs_set_eq:NN \xfrac_text_or_math:n \mbox
+ \cs_set_nopar:Npn \xfrac_denominator_font_change:
+ {
+ \fontfamily { \l_xfrac_denominator_font_tl }
+ \selectfont
+ }
+ \cs_set_nopar:Npn \xfrac_numerator_font_change:
+ {
+ \fontfamily { \l_xfrac_numerator_font_tl }
+ \selectfont
+ }
+ \cs_set_nopar:Npn \xfrac_slash_symbol_font_change:
+ {
+ \fontfamily { \l_xfrac_slash_symbol_font_tl }
+ \selectfont
+ }
+ }
+ \xfrac_text_or_math:n
+ {
+ \m@th
+ \hbox_set:Nn \l_xfrac_tmp_box
+ { \xfrac_math:n { \vphantom { ( ) } } }
+ \hbox_set:Nn \l_xfrac_slash_box
+ {
+ \xfrac_math:n
+ {
+ \xfrac_slash_symbol_format:n
+ {
+ \xfrac_math:n
+ {
+ \xfrac_slash_symbol_font_change:
+ \IfNoValueTF {#2}
+ { \l_xfrac_slash_symbol_tl } {#2}
+ }
+ }
+ }
+ }
+ \cs_set_nopar:Npn \xfrac_tmp:w
+ {
+ \raisebox
+ {
+ \box_ht:N \l_xfrac_slash_box
+ - \box_dp:N \l_xfrac_slash_box
+ - \height
+ }
+ }
+ \dim_compare:nNnTF
+ { \l_xfrac_numerator_top_sep_dim } = { \c_max_dim }
+ {
+ \dim_compare:nNnF
+ { \l_xfrac_numerator_bot_sep_dim } = { \c_max_dim }
+ {
+ \cs_set_nopar:Npn \xfrac_tmp:w
+ {
+ \raisebox
+ { \dim_use:N \l_xfrac_numerator_bot_sep_dim }
+ }
+ }
+ }
+ {
+ \dim_compare:nNnTF
+ { \l_xfrac_numerator_bot_sep_dim } = { \c_max_dim }
+ {
+ \cs_set_nopar:Npn \xfrac_tmp:w
+ {
+ \raisebox
+ {
+ \box_ht:N \l_xfrac_slash_box
+ - \dim_use:N \l_xfrac_numerator_top_sep_dim
+ - \height
+ }
+ }
+ }
+ {
+ \msg_error:nn { xfrac }
+ { over-specified-numerator-sep }
+ }
+ }
+ \xfrac_tmp:w
+ {
+ \xfrac_fontscale:
+ \xfrac_numerator_format:n
+ {
+ \scalebox
+ { \fp_use:N \l_xfrac_hscale_fp }
+ [ \fp_use:N \l_xfrac_vscale_fp ]
+ {
+ \xfrac_math:n
+ {
+ \xfrac_numerator_font_change:
+ {
+ \vphantom { \l_xfrac_phantom_tl }
+ #1
+ }
+ }
+ }
+ }
+ }
+ \xfrac_math:n
+ { % THIS IS JUST WRONG!
+ \mode_if_math:TF
+ { \tex_mskip:D \l_xfrac_slash_right_muskip }
+ { \tex_hskip:D \l_xfrac_slash_right_sep_dim }
+ }
+ \box_use:N \l_xfrac_slash_box
+ \xfrac_math:n
+ {
+ \mode_if_math:TF
+ { \tex_mskip:D \l_xfrac_slash_left_muskip }
+ { \tex_hskip:D \l_xfrac_slash_left_sep_dim }
+ }
+ \dim_compare:nNnTF
+ { \l_xfrac_denominator_bot_sep_dim } = { \c_max_dim }
+ {
+ \cs_set_nopar:Npn \xfrac_tmp:w
+ { \raisebox { - \box_dp:N \l_xfrac_slash_box } }
+ }
+ {
+ \cs_set_nopar:Npn \xfrac_tmp:w
+ {
+ \raisebox
+ { \dim_use:N \l_xfrac_denominator_bot_sep_dim }
+ }
+ }
+ \xfrac_tmp:w
+ {
+ \xfrac_fontscale:
+ \xfrac_denominator_format:n
+ {
+ \scalebox
+ { \fp_use:N \l_xfrac_hscale_fp }
+ [ \fp_use:N \l_xfrac_vscale_fp ]
+ {
+ \xfrac_math:n
+ {
+ \xfrac_denominator_font_change:
+ {
+ \vphantom { \l_xfrac_phantom_tl }
+ #3
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+\DeclareRestrictedTemplate { xfrac } { text } { math }
+ {
+ numerator-font = \number \fam ,
+ slash-symbol = / ,
+ slash-symbol-font = \number \fam ,
+ denominator-font = \number \fam ,
+ scale-factor = 0.7 ,
+ scale-relative = false ,
+ scaling = true ,
+ numerator-top-sep = 0 pt ,
+ denominator-bot-sep = 0 pt ,
+ math-mode = true ,
+ phantom = ( % )
+ }
+\DeclareInstance { xfrac } { default } { text } { }
+\DeclareInstance { xfrac } { mathdefault } { math } { }
+\DeclareCollectionInstance { plainmath } { xfrac } { mathdefault } { math }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-bot-sep = 0 pt ,
+ numerator-top-sep = \c_max_dim ,
+ scale-factor = 1 ,
+ scale-relative = false ,
+ scaling = true ,
+ slash-right-mkern = 0 mu ,
+ slash-left-mkern = 0 mu
+ }
+\DeclareInstance { xfrac } { cmr } { text }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-top-sep = 0.2 ex ,
+ slash-left-kern = -0.1 em ,
+ slash-right-kern = -0.1 em
+ }
+\DeclareInstance { xfrac } { cmss } { text }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-top-sep = 0.2 ex ,
+ slash-left-kern = -0.1 em ,
+ slash-right-kern = -0.1 em
+ }
+\DeclareInstance { xfrac } { cmtt } { text }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-top-sep = 0.2 ex ,
+ slash-left-kern = -0.1 em ,
+ slash-right-kern = -0.1 em
+ }
+\bool_if:NF \l_xfrac_cm_std_bool
+ {
+ \DeclareInstance { xfrac } { cmr } { text }
+ { slash-symbol-font = ptm }
+ \DeclareInstance { xfrac } { cmss } { text }
+ { slash-symbol-font = ptm }
+ \DeclareInstance { xfrac } { cmtt } { text }
+ { slash-symbol-font = ppl }
+ }
+\DeclareInstance { xfrac } { lmr } { text }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-top-sep = 0.1 ex ,
+ slash-left-kern = -0.15 em ,
+ slash-right-kern = -0.15 em
+ }
+\DeclareInstance { xfrac } { lmss } { text }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-top-sep = 0 pt ,
+ slash-left-kern = -0.15 em ,
+ slash-right-kern = -0.15 em
+ }
+\DeclareInstance { xfrac } { lmtt } { text }
+ {
+ denominator-bot-sep = 0 pt ,
+ numerator-top-sep = 0 pt ,
+ slash-left-kern = -0.15 em ,
+ slash-right-kern = -0.15 em
+ }
+\NewDocumentCommand \sfrac { o m o m }
+ {
+ \mode_if_math:TF
+ {
+ \IfInstanceExistTF { xfrac } { mathfam \number \fam }
+ { \UseInstance { xfrac } { mathfam \number \fam } }
+ { \UseInstance { xfrac } { mathdefault } }
+ {#2} {#3} {#4}
+ }
+ {
+ \IfInstanceExistTF { xfrac } {#1}
+ { \UseInstance { xfrac } {#1} }
+ {
+ \IfInstanceExistTF { xfrac } { \f@family }
+ { \UseInstance { xfrac } { \f@family } }
+ { \UseInstance { xfrac } { default } }
+ }
+ {#2} {#3} {#4}
+ }
+ }
+\msg_new:nnnn { xfrac } { over-specified-numerator-sep }
+ { You have specified both numerator-top-sep and numerator-bot-sep}
+ {I will pretend that you didn't specify either of them}
+
+%%
+%%
+%% End of file `xfrac.sty'.
diff --git a/Master/texmf-dist/tex/latex/l3packages/xparse/xparse.sty b/Master/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
new file mode 100644
index 00000000000..be93d481af1
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
@@ -0,0 +1,1270 @@
+%%
+%% This is file `xparse.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% xparse.dtx (with options: `package')
+%%
+%% EXPERIMENTAL CODE
+%%
+%% Do not distribute this file without also distributing the
+%% source files specified above.
+%%
+%% Do not distribute a modified version of this file.
+%%
+%% File: xparse.dtx (C) Copyright 1999 Frank Mittelbach, Chris Rowley,
+%% David Carlisle
+%% (C) Copyright 2004-2008 Frank Mittelbach,
+%% The LaTeX3 Project
+%% (C) Copyright 2009-2011 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3packages bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\RequirePackage{expl3}
+\GetIdInfo$Id: xparse.dtx 2492 2011-07-02 13:40:38Z joseph $
+ {L3 Experimental document command parser}
+\ProvidesExplPackage
+ {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+\RequirePackage{expl3}
+\@ifpackagelater { l3token } { 2011/07/02 }
+ { }
+ {
+ \PackageError { xparse } { Support~package~l3kernel~too~old. }
+ {
+ Please~install~an~up~to~date~version~of~l3kernel~
+ using~your~TeX~package~manager~or~from~CTAN.\\ \\
+ Loading~xparse~will~abort!
+ }
+ \tex_endinput:D
+ }
+\prop_new:N \c_xparse_shorthands_prop
+\prop_put:Nnn \c_xparse_shorthands_prop { o } { d[] }
+\prop_put:Nnn \c_xparse_shorthands_prop { O } { D[] }
+\prop_put:Nnn \c_xparse_shorthands_prop { s } { t* }
+ %\end{variable}
+\tl_new:N \l_xparse_arg_tl
+\tl_new:N \l_xparse_args_tl
+\bool_new:N \l_xparse_environment_bool
+\bool_new:N \l_xparse_error_bool
+\tl_new:N \l_xparse_function_tl
+\tl_new:N \l_xparse_last_arg_tl
+\bool_new:N \l_xparse_long_bool
+\int_new:N \l_xparse_m_args_int
+\bool_new:N \l_xparse_m_only_bool
+\int_new:N \l_xparse_mandatory_args_int
+\bool_new:N \l_xparse_processor_bool
+\int_new:N \l_xparse_processor_int
+\tl_new:N \l_xparse_signature_tl
+\tl_new:N \l_xparse_tmp_tl
+\int_new:N \l_xparse_total_args_int
+\cs_new_protected_nopar:Npn \xparse_add_grabber_mandatory:N #1
+ {
+ \tl_put_right:Nx \l_xparse_signature_tl
+ {
+ \exp_not:c
+ { xparse_grab_ #1 \bool_if:NT \l_xparse_long_bool { _long } :w }
+ }
+ \bool_set_false:N \l_xparse_long_bool
+ \int_decr:N \l_xparse_mandatory_args_int
+ }
+\cs_new_protected_nopar:Npn \xparse_add_grabber_optional:N #1
+ {
+ \tl_put_right:Nx \l_xparse_signature_tl
+ {
+ \exp_not:c
+ {
+ xparse_grab_ #1
+ \bool_if:NT \l_xparse_long_bool { _long }
+ \int_compare:nNnF \l_xparse_mandatory_args_int > \c_zero
+ { _trailing }
+ :w
+ }
+ }
+ \bool_set_false:N \l_xparse_long_bool
+ }
+\cs_new_protected_nopar:cpn { xparse_add_type_+:w }
+ {
+ \xparse_flush_m_args:
+ \bool_set_true:N \l_xparse_long_bool
+ \bool_set_false:N \l_xparse_m_only_bool
+ \int_decr:N \l_xparse_total_args_int
+ \xparse_prepare_signature:N
+ }
+\cs_new_protected:cpn { xparse_add_type_>:w } #1
+ {
+ \bool_set_true:N \l_xparse_processor_bool
+ \xparse_flush_m_args:
+ \int_decr:N \l_xparse_total_args_int
+ \tl_put_right:Nn \l_xparse_signature_tl { \xparse_process_arg:n {#1} }
+ \xparse_prepare_signature_aux:N
+ }
+\cs_new_protected:Npn \xparse_add_type_d:w #1#2
+ { \xparse_add_type_D:w #1 #2 { \NoValue } }
+\cs_new_protected:Npn \xparse_add_type_D:w #1#2#3
+ {
+ \xparse_flush_m_args:
+ \xparse_add_grabber_optional:N D
+ \tl_put_right:Nn \l_xparse_signature_tl { #1 #2 {#3} }
+ \xparse_prepare_signature:N
+ }
+\cs_new_protected_nopar:Npn \xparse_add_type_g:w
+ { \xparse_add_type_G:w { \NoValue } }
+\cs_new_protected:Npn \xparse_add_type_G:w #1
+ {
+ \xparse_flush_m_args:
+ \xparse_add_grabber_optional:N G
+ \tl_put_right:Nn \l_xparse_signature_tl { {#1} }
+ \xparse_prepare_signature:N
+ }
+\cs_new_protected_nopar:Npn \xparse_add_type_l:w
+ {
+ \xparse_flush_m_args:
+ \xparse_add_grabber_mandatory:N l
+ \xparse_prepare_signature:N
+ }
+\cs_new_protected_nopar:Npn \xparse_add_type_m:w
+ {
+ \bool_if:nTF { \l_xparse_long_bool || \l_xparse_processor_bool }
+ {
+ \xparse_flush_m_args:
+ \xparse_add_grabber_mandatory:N m
+ }
+ { \int_incr:N \l_xparse_m_args_int }
+ \xparse_prepare_signature:N
+ }
+\cs_new_protected:Npn \xparse_add_type_t:w #1
+ {
+ \xparse_flush_m_args:
+ \xparse_add_grabber_optional:N t
+ \tl_put_right:Nn \l_xparse_signature_tl { #1 }
+ \xparse_prepare_signature:N
+ }
+\cs_new_protected:Npn \xparse_add_type_u:w #1
+ {
+ \xparse_flush_m_args:
+ \xparse_add_grabber_mandatory:N u
+ \tl_put_right:Nn \l_xparse_signature_tl { {#1} }
+ \xparse_prepare_signature:N
+ }
+\cs_new_protected_nopar:Npn \xparse_check_and_add:N #1
+ {
+ \cs_if_free:cTF { xparse_add_type_ #1 :w }
+ {
+ \msg_error:nnx { xparse } { unknown-argument-type }
+ { \tl_to_str:n {#1} }
+ \xparse_add_type_m:w
+ }
+ { \use:c { xparse_add_type_ #1 :w } }
+ }
+\cs_new_protected:Npn \xparse_count_mandatory:n #1
+ {
+ \int_zero:N \l_xparse_mandatory_args_int
+ \xparse_count_mandatory:N #1 \q_nil
+ }
+\cs_new_protected:Npn \xparse_count_mandatory:N #1
+ {
+ \quark_if_nil:NF #1
+ {
+ \prop_if_in:NnTF \c_xparse_shorthands_prop {#1}
+ {
+ \prop_get:NnN \c_xparse_shorthands_prop {#1} \l_xparse_tmp_tl
+ \exp_last_unbraced:NV \xparse_count_mandatory:N \l_xparse_tmp_tl
+ }
+ { \xparse_count_mandatory_aux:N #1 }
+ }
+ }
+\cs_new_protected:Npn \xparse_count_mandatory_aux:N #1
+ {
+ \cs_if_free:cTF { xparse_count_type_ #1 :w }
+ { \xparse_count_type_m:w }
+ { \use:c { xparse_count_type_ #1 :w } }
+ }
+\cs_new_protected:cpn { xparse_count_type_>:w } #1
+ { \xparse_count_mandatory:N }
+\cs_new_protected_nopar:cpn { xparse_count_type_+:w }
+ { \xparse_count_mandatory:N }
+\cs_new_protected:Npn \xparse_count_type_d:w #1#2
+ { \xparse_count_mandatory:N }
+\cs_new_protected:Npn \xparse_count_type_D:w #1#2#3
+ { \xparse_count_mandatory:N }
+\cs_new_protected_nopar:Npn \xparse_count_type_g:w
+ { \xparse_count_mandatory:N }
+\cs_new_protected:Npn \xparse_count_type_G:w #1
+ { \xparse_count_mandatory:N }
+\cs_new_protected_nopar:Npn \xparse_count_type_l:w
+ {
+ \int_incr:N \l_xparse_mandatory_args_int
+ \xparse_count_mandatory:N
+ }
+\cs_new_protected_nopar:Npn \xparse_count_type_m:w
+ {
+ \int_incr:N \l_xparse_mandatory_args_int
+ \xparse_count_mandatory:N
+ }
+\cs_new_protected:Npn \xparse_count_type_t:w #1
+ { \xparse_count_mandatory:N }
+\cs_new_protected:Npn \xparse_count_type_u:w #1
+ {
+ \int_incr:N \l_xparse_mandatory_args_int
+ \xparse_count_mandatory:N
+ }
+\cs_new_protected:Npn \xparse_declare_cmd:Nnn #1#2
+ {
+ \cs_if_exist:NTF #1
+ {
+ \msg_warning:nnxx { xparse } { redefine-command }
+ { \token_to_str:N #1 } { \tl_to_str:n {#2} }
+ }
+ {
+ \msg_info:nnxx { xparse } { define-command }
+ { \token_to_str:N #1 } { \tl_to_str:n {#2} }
+ }
+ \xparse_declare_cmd_aux:Nnn #1 {#2}
+ }
+\cs_new_protected:Npn \xparse_declare_cmd_aux:Nnn #1#2#3
+ {
+ \tl_clear_new:c { l_xparse_ \token_to_str:N #1 _arg_spec_tl }
+ \tl_set:cn { l_xparse_ \token_to_str:N #1 _arg_spec_tl } {#2}
+ \xparse_count_mandatory:n {#2}
+ \xparse_prepare_signature:n {#2}
+ \bool_if:NTF \l_xparse_m_only_bool
+ { \xparse_declare_cmd_all_m:Nn #1 {#3} }
+ { \xparse_declare_cmd_mixed:Nn #1 {#3} }
+ }
+\cs_generate_variant:Nn \xparse_declare_cmd_aux:Nnn { cnn }
+\cs_new_protected:Npn \xparse_declare_cmd_all_m:Nn #1#2
+ {
+ \cs_generate_from_arg_count:NNnn
+ #1 \cs_set_protected_nopar:Npn \l_xparse_total_args_int {#2}
+ }
+\cs_new_protected:Npn \xparse_declare_cmd_mixed:Nn #1#2
+ {
+ \group_begin:
+ \tex_escapechar:D 92 \scan_stop:
+ \tl_set:Nx \l_xparse_function_tl { \token_to_str:N #1 }
+ \exp_args:NNNo \group_end:
+ \tl_set:Nn \l_xparse_function_tl { \l_xparse_function_tl }
+ \cs_set_protected_nopar:Npx #1
+ {
+ \exp_not:n
+ {
+ \int_zero:N \l_xparse_processor_int
+ \tl_set:Nn \l_xparse_args_tl
+ }
+ { \exp_not:c { \l_xparse_function_tl } }
+ \exp_not:o \l_xparse_signature_tl
+ \exp_not:N \l_xparse_args_tl
+ }
+ \cs_generate_from_arg_count:cNnn
+ { \token_to_str:N #1 } \cs_set:Npn \l_xparse_total_args_int {#2}
+ }
+\cs_new_protected:Npn \xparse_declare_cmd_implementation:nNn #1#2#3
+ {
+ \cs_generate_from_arg_count:cNnn { implementation_ #1 :w }
+ \cs_set:Npn {#2} {#3}
+ }
+\cs_new_protected:Npn \xparse_declare_cmd_interface:Nnn #1#2#3
+ {
+ \xparse_prepare_signature:n {#3}
+ \bool_if:NTF \l_xparse_m_only_bool
+ { \xparse_declare_cmd_interface_all_m:Nn #1 {#2} }
+ { \xparse_declare_cmd_interface_mixed:Nn #1 {#2} }
+ \cs_generate_from_arg_count:cNnn { implementation_ #2 :w }
+ \cs_set:Npn \l_xparse_total_args_int { '#2' }
+ }
+\cs_new_protected:Npn \xparse_declare_cmd_interface_all_m:Nn #1#2
+ {
+ \cs_generate_from_arg_count:NNnn
+ #1 \cs_set_protected_nopar:Npn \l_xparse_total_args_int
+ { \use:c { implementation_ #2 :w } }
+ }
+\cs_new_protected:Npn \xparse_declare_cmd_interface_mixed:Nn #1#2
+ {
+ \cs_set_protected_nopar:Npx #1
+ {
+ \exp_not:n
+ {
+ \int_zero:N \l_xparse_processor_int
+ \tl_set:Nn \l_xparse_args_tl
+ }
+ { \exp_not:c { \token_to_str:N #1 } }
+ \exp_not:o \l_xparse_signature_tl
+ \exp_not:N \l_xparse_args_tl
+ }
+ \cs_generate_from_arg_count:cNnn
+ { \token_to_str:N #1 } \cs_set:Npn \l_xparse_total_args_int
+ { \use:c { implementation_ #2 :w } }
+ }
+\cs_new_protected:Npn \xparse_declare_env:nnnn #1#2#3#4
+ {
+ \bool_set_true:N \l_xparse_environment_bool
+ \cs_if_exist:cTF {#1}
+ {
+ \msg_warning:nnxx { xparse } { redefine-environment }
+ { \tl_to_str:n {#1} } { \tl_to_str:n {#2} }
+ }
+ {
+ \msg_info:nnxx { xparse } { define-environment }
+ { \tl_to_str:n {#1} } { \tl_to_str:n {#2} }
+ }
+ \xparse_declare_cmd_aux:cnn { environment_begin_ #1 :w } {#2}
+ {
+ \group_begin:
+ \cs_set_protected_nopar:cpx { environment_end_ #1 :w }
+ {
+ \exp_not:c { environment_end_ #1 _aux:N }
+ \exp_not:o \l_xparse_args_tl
+ \group_end:
+ }
+ #3
+ }
+ \cs_set_protected_nopar:cpx { environment_end_ #1 : }
+ { \exp_not:c { environment_end_ #1 :w } }
+ \bool_set_false:N \l_xparse_environment_bool
+ \cs_set_nopar:cpx { environment_end_ #1 _aux:N } ##1
+ { \exp_not:c { environment_end_ #1 _aux :w } }
+ \cs_generate_from_arg_count:cNnn
+ { environment_end_ #1 _aux :w } \cs_set:Npn
+ \l_xparse_total_args_int {#4}
+ \cs_set_eq:cc {#1} { environment_begin_ #1 :w }
+ \cs_set_eq:cc { end #1 } { environment_end_ #1 : }
+ }
+\cs_new_protected_nopar:Npn \xparse_flush_m_args:
+ {
+ \cs_if_exist:cT { xparse_grab_m_ \int_use:N \l_xparse_m_args_int :w }
+ {
+ \tl_put_right:Nx \l_xparse_signature_tl
+ { \exp_not:c { xparse_grab_m_ \int_use:N \l_xparse_m_args_int :w } }
+ \int_set:Nn \l_xparse_mandatory_args_int
+ { \l_xparse_mandatory_args_int - \l_xparse_m_args_int }
+ }
+ \int_zero:N \l_xparse_m_args_int
+ \bool_set_false:N \l_xparse_m_only_bool
+ }
+\prg_new_conditional:Npnn \xparse_if_no_value:n #1 { T , F , TF }
+ { \str_if_eq:nnTF {#1} { \NoValue } \prg_return_true: \prg_return_false: }
+\cs_new_protected:Npn \xparse_prepare_signature:n #1
+ {
+ \bool_set_false:N \l_xparse_long_bool
+ \int_zero:N \l_xparse_m_args_int
+ \bool_if:NTF \l_xparse_environment_bool
+ { \bool_set_false:N \l_xparse_m_only_bool }
+ { \bool_set_true:N \l_xparse_m_only_bool }
+ \bool_set_false:N \l_xparse_processor_bool
+ \tl_clear:N \l_xparse_signature_tl
+ \int_zero:N \l_xparse_total_args_int
+ \xparse_prepare_signature:N #1 \q_nil
+ }
+\cs_new_protected:Npn \xparse_prepare_signature:N #1
+ {
+ \bool_set_false:N \l_xparse_processor_bool
+ \xparse_prepare_signature_aux:N #1
+ }
+\cs_new_protected:Npn \xparse_prepare_signature_aux:N #1
+ {
+ \quark_if_nil:NTF #1
+ { \bool_if:NF \l_xparse_m_only_bool { \xparse_flush_m_args: } }
+ {
+ \prop_if_in:NnTF \c_xparse_shorthands_prop {#1}
+ {
+ \prop_get:NnN \c_xparse_shorthands_prop {#1} \l_xparse_tmp_tl
+ \exp_after:wN \xparse_prepare_signature:N \l_xparse_tmp_tl
+ }
+ {
+ \int_incr:N \l_xparse_total_args_int
+ \xparse_check_and_add:N #1
+ }
+ }
+ }
+\cs_new_protected:Npn \xparse_process_arg:n #1
+ {
+ \int_incr:N \l_xparse_processor_int
+ \cs_set:cpn { xparse_processor_ \int_use:N \l_xparse_processor_int :n } ##1
+ { #1 {##1} }
+ }
+\cs_new_protected:Npn \xparse_add_arg:n #1
+ {
+ \int_compare:nNnTF \l_xparse_processor_int = \c_zero
+ { \tl_put_right:Nn \l_xparse_args_tl { {#1} } }
+ {
+ \xparse_if_no_value:nTF {#1}
+ {
+ \int_zero:N \l_xparse_processor_int
+ \tl_put_right:Nn \l_xparse_args_tl { {#1} }
+ }
+ { \xparse_add_arg_aux:n {#1} }
+ }
+ }
+\cs_generate_variant:Nn \xparse_add_arg:n { V }
+\cs_new_protected:Npn \xparse_add_arg_aux:n #1
+ {
+ \tl_set_eq:NN \ProcessedArgument \l_xparse_arg_tl
+ \use:c { xparse_processor_ \int_use:N \l_xparse_processor_int :n } {#1}
+ \int_decr:N \l_xparse_processor_int
+ \int_compare:nNnTF \l_xparse_processor_int = \c_zero
+ {
+ \tl_put_right:Nx \l_xparse_args_tl
+ { { \exp_not:V \ProcessedArgument } }
+ }
+ { \xparse_add_arg_aux:V \ProcessedArgument }
+}
+\cs_generate_variant:Nn \xparse_add_arg_aux:n { V }
+\cs_new_protected:Npn \xparse_grab_arg:w { }
+\cs_new_protected:Npn \xparse_grab_arg_aux_i:w { }
+\cs_new_protected:Npn \xparse_grab_arg_aux_ii:w { }
+\cs_new_protected:Npn \xparse_grab_D:w #1#2#3#4 \l_xparse_args_tl
+ {
+ \xparse_grab_D_aux:NNnnNn #1 #2 {#3} {#4} \cs_set_protected_nopar:Npn
+ { _ignore_spaces }
+ }
+\cs_new_protected:Npn \xparse_grab_D_long:w #1#2#3#4 \l_xparse_args_tl
+ {
+ \xparse_grab_D_aux:NNnnNn #1 #2 {#3} {#4} \cs_set_protected:Npn
+ { _ignore_spaces }
+ }
+\cs_new_protected:Npn \xparse_grab_D_trailing:w #1#2#3#4 \l_xparse_args_tl
+ { \xparse_grab_D_aux:NNnnNn #1 #2 {#3} {#4} \cs_set_protected_nopar:Npn { } }
+\cs_new_protected:Npn \xparse_grab_D_long_trailing:w #1#2#3#4 \l_xparse_args_tl
+ { \xparse_grab_D_aux:NNnnNn #1 #2 {#3} {#4} \cs_set_protected:Npn { } }
+\cs_new_protected:Npn \xparse_grab_D_aux:NNnnNn #1#2#3#4#5#6
+ {
+ #5 \xparse_grab_arg:w #1
+ {
+ \peek_meaning:NTF \c_group_begin_token
+ { \xparse_grab_arg_aux_i:w }
+ { \xparse_grab_arg_aux_ii:w }
+ }
+ #5 \xparse_grab_arg_aux_i:w ##1
+ {
+ \peek_charcode:NTF #2
+ { \xparse_grab_arg_aux_ii:w { {##1} } }
+ { \xparse_grab_arg_aux_ii:w {##1} }
+ }
+ #5 \xparse_grab_arg_aux_ii:w ##1 #2
+ {
+ \tl_if_in:nnTF {##1} {#1}
+ { \xparse_grab_D_nested:NNnnN #1 #2 {##1} {#4} #5 }
+ {
+ \xparse_add_arg:n {##1}
+ #4 \l_xparse_args_tl
+ }
+ }
+ \use:c { peek_charcode #6 :NTF } #1
+ { \xparse_grab_arg:w }
+ {
+ \xparse_add_arg:n {#3}
+ #4 \l_xparse_args_tl
+ }
+ }
+\tl_new:N \l_xparse_nesting_a_tl
+\tl_new:N \l_xparse_nesting_b_tl
+\quark_new:N \q_xparse
+\cs_new_protected:Npn \xparse_grab_D_nested:NNnnN #1#2#3#4#5
+ {
+ \tl_clear:N \l_xparse_nesting_a_tl
+ \tl_clear:N \l_xparse_nesting_b_tl
+ #5 \xparse_grab_arg:w ##1 #1 ##2 \q_xparse ##3 #2
+ {
+ \tl_put_right:Nn \l_xparse_nesting_a_tl { ##1 #1 }
+ \tl_put_right:Nn \l_xparse_nesting_b_tl { #2 ##3 }
+ \tl_if_in:nnTF {##2} {#1}
+ { \xparse_grab_arg:w ##2 \q_xparse }
+ {
+ \tl_put_right:Nn \l_xparse_nesting_a_tl {##2}
+ \tl_if_in:NnTF \l_xparse_nesting_b_tl {#1}
+ {
+ \tl_set_eq:NN \l_xparse_tmp_tl \l_xparse_nesting_b_tl
+ \tl_clear:N \l_xparse_nesting_b_tl
+ \exp_after:wN \xparse_grab_arg:w \l_xparse_tmp_tl \q_xparse
+ }
+ {
+ \tl_put_right:No \l_xparse_nesting_a_tl
+ \l_xparse_nesting_b_tl
+ \xparse_add_arg:V \l_xparse_nesting_a_tl
+ #4 \l_xparse_args_tl
+ }
+ }
+ }
+ \xparse_grab_arg:w #3 \q_xparse
+ }
+\cs_new_protected:Npn \xparse_grab_G:w #1#2 \l_xparse_args_tl
+ {
+ \xparse_grab_G_aux:nnNn {#1} {#2} \cs_set_protected_nopar:Npn
+ { _ignore_spaces }
+ }
+\cs_new_protected:Npn \xparse_grab_G_long:w #1#2 \l_xparse_args_tl
+ {
+ \xparse_grab_G_aux:nnNn {#1} {#2} \cs_set_protected:Npn { _ignore_spaces }
+ }
+\cs_new_protected:Npn \xparse_grab_G_trailing:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_G_aux:nnNn {#1} {#2} \cs_set_protected_nopar:Npn { } }
+\cs_new_protected:Npn \xparse_grab_G_long_trailing:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_G_aux:nnNn {#1} {#2} \cs_set_protected:Npn { } }
+\cs_new_protected:Npn \xparse_grab_G_aux:nnNn #1#2#3#4
+ {
+ #3 \xparse_grab_arg:w ##1
+ {
+ \xparse_add_arg:n {##1}
+ #2 \l_xparse_args_tl
+ }
+ \use:c { peek_meaning #4 :NTF } \c_group_begin_token
+ { \xparse_grab_arg:w }
+ {
+ \xparse_add_arg:n {#1}
+ #2 \l_xparse_args_tl
+ }
+ }
+\cs_new_protected:Npn \xparse_grab_l:w #1 \l_xparse_args_tl
+ { \xparse_grab_l_aux:nN {#1} \cs_set_protected_nopar:Npn }
+\cs_new_protected:Npn \xparse_grab_l_long:w #1 \l_xparse_args_tl
+ { \xparse_grab_l_aux:nN {#1} \cs_set_protected:Npn }
+\cs_new_protected:Npn \xparse_grab_l_aux:nN #1#2
+ {
+ #2 \xparse_grab_arg:w ##1##
+ {
+ \xparse_add_arg:n {##1}
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:Npn \xparse_grab_m:w #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1
+ {
+ \xparse_add_arg:n {##1}
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:Npn \xparse_grab_m_long:w #1 \l_xparse_args_tl
+ {
+ \cs_set_protected:Npn \xparse_grab_arg:w ##1
+ {
+ \xparse_add_arg:n {##1}
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_1:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1
+ {
+ \tl_put_right:Nn \l_xparse_args_tl { {##1} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_2:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2
+ {
+ \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_3:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3
+ {
+ \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} {##3} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_4:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4
+ {
+ \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} {##3} {##4} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_5:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4##5
+ {
+ \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} {##3} {##4} {##5} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_6:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4##5##6
+ {
+ \tl_put_right:Nn \l_xparse_args_tl
+ { {##1} {##2} {##3} {##4} {##5} {##6} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_7:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4##5##6##7
+ {
+ \tl_put_right:Nn \l_xparse_args_tl
+ { {##1} {##2} {##3} {##4} {##5} {##6} {##7} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:cpn { xparse_grab_m_8:w } #1 \l_xparse_args_tl
+ {
+ \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4##5##6##7##8
+ {
+ \tl_put_right:Nn \l_xparse_args_tl
+ { {##1} {##2} {##3} {##4} {##5} {##6} {##7} {##8} }
+ #1 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:Npn \xparse_grab_t:w #1#2 \l_xparse_args_tl
+ {
+ \xparse_grab_t_aux:NnNn #1 {#2} \cs_set_protected_nopar:Npn
+ { _ignore_spaces }
+ }
+\cs_new_protected:Npn \xparse_grab_t_long:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_t_aux:NnNn #1 {#2} \cs_set_protected:Npn { _ignore_spaces } }
+\cs_new_protected:Npn \xparse_grab_t_trailing:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_t_aux:NnNn #1 {#2} \cs_set_protected_nopar:Npn { } }
+\cs_new_protected:Npn \xparse_grab_t_long_trailing:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_t_aux:NnNn #1 {#2} \cs_set_protected:Npn { } }
+\cs_new_protected:Npn \xparse_grab_t_aux:NnNn #1#2#3#4
+ {
+ #3 \xparse_grab_arg:w
+ {
+ \use:c { peek_charcode_remove #4 :NTF } #1
+ {
+ \xparse_add_arg:n { \BooleanTrue }
+ #2 \l_xparse_args_tl
+ }
+ {
+ \xparse_add_arg:n { \BooleanFalse }
+ #2 \l_xparse_args_tl
+ }
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:Npn \xparse_grab_u:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_u_aux:NnN {#1} {#2} \cs_set_protected_nopar:Npn }
+\cs_new_protected:Npn \xparse_grab_u_long:w #1#2 \l_xparse_args_tl
+ { \xparse_grab_u_aux:NnN {#1} {#2} \cs_set_protected:Npn }
+\cs_new_protected:Npn \xparse_grab_u_aux:NnN #1#2#3
+ {
+ #3 \xparse_grab_arg:w ##1 #1
+ {
+ \xparse_add_arg:n {##1}
+ #2 \l_xparse_args_tl
+ }
+ \xparse_grab_arg:w
+ }
+\cs_new_protected:Npn \xparse_process_to_str:n #1
+ { \tl_set:Nx \ProcessedArgument { \tl_to_str:n {#1} } }
+\cs_new_protected:Npn \xparse_bool_reverse:N #1
+ {
+ \bool_if:NTF #1
+ { \tl_set:Nn \ProcessedArgument { \c_false_bool } }
+ { \tl_set:Nn \ProcessedArgument { \c_true_bool } }
+ }
+\tl_new:N \l_xparse_split_argument_tl
+\group_begin:
+ \char_set_catcode_active:N \@
+ \cs_new_protected:Npn \xparse_split_argument:nnn #1#2#3
+ {
+ \tl_set:Nn \l_xparse_split_argument_tl {#3}
+ \group_begin:
+ \char_set_lccode:nn { `\@ } { `#2}
+ \tl_to_lowercase:n
+ {
+ \group_end:
+ \tl_replace_all_in:Nnn \l_xparse_split_argument_tl { @ } {#2}
+ }
+ \cs_set_protected:Npn \xparse_split_argument_aux_i:w
+ ##1 \q_mark ##2 #2 ##3 \q_stop
+ {
+ \tl_put_right:Nn \ProcessedArgument { {##2} }
+ ##1 \q_mark ##3 \q_stop
+ }
+ \cs_set_protected:Npn \xparse_split_argument_aux_iii:w
+ ##1 #2 ##2 \q_stop
+ {
+ \IfNoValueF {##1}
+ {
+ \msg_error:nnxxx { xparse } { split-excess-tokens }
+ { \tl_to_str:n {#2} } { \tl_to_str:n {#1} }
+ { \tl_to_str:n {#3} }
+ }
+ }
+ \tl_set:Nx \l_xparse_tmp_tl
+ {
+ \prg_replicate:nn { #1 + 1 }
+ { \xparse_split_argument_aux_i:w }
+ \xparse_split_argument_aux_ii:w
+ \exp_not:N \q_mark
+ \exp_not:o \l_xparse_split_argument_tl
+ \prg_replicate:nn {#1} { \exp_not:n {#2} \NoValue }
+ \exp_not:n { #2 \q_stop }
+ }
+ \l_xparse_tmp_tl
+ }
+\group_end:
+\cs_new_protected:Npn \xparse_split_argument_aux_i:w { }
+\cs_new_protected:Npn \xparse_split_argument_aux_ii:w
+ #1 \q_mark #2 \q_stop
+ {
+ \tl_if_empty:nF {#2}
+ { \xparse_split_argument_aux_iii:w #2 \q_stop }
+ }
+\cs_new_protected:Npn \xparse_split_argument_aux_iii:w { }
+\tl_new:N \l_xparse_split_list_tl
+\group_begin:
+ \char_set_catcode_active:N \@
+ \cs_new_protected:Npn \xparse_split_list:nn #1#2
+ {
+ \tl_set:Nn \l_xparse_split_list_tl {#2}
+ \group_begin:
+ \char_set_lccode:nn { `\@ } { `#1 }
+ \tl_to_lowercase:n
+ {
+ \group_end:
+ \tl_replace_all_in:Nnn \l_xparse_split_list_tl { @ } {#1}
+ }
+ \cs_set:Npn \xparse_split_list_aux:w ##1 #1
+ {
+ \quark_if_recursion_tail_stop:n {##1}
+ \tl_put_right:Nn \ProcessedArgument { {##1} }
+ \xparse_split_list_aux:w
+ }
+ \tl_if_empty:NTF \l_xparse_split_list_tl
+ { \tl_set:Nn \ProcessedArgument { { } } }
+ {
+ \tl_clear:N \ProcessedArgument
+ \exp_after:wN \xparse_split_list_aux:w
+ \l_xparse_split_list_tl #1
+ \q_recursion_tail #1 \q_recursion_stop
+ }
+ }
+\group_end:
+\cs_new_protected:Npn \xparse_split_list_aux:w { }
+\cs_new_protected:Npn \xparse_exp_add_type_d:w #1#2
+ { \xparse_exp_add_type_D:w #1 #2 { \NoValue } }
+\cs_new_protected:Npn \xparse_exp_add_type_D:w #1#2#3
+ {
+ \tl_set:Nx \l_xparse_tmp_tl
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_use:N \l_xparse_total_args_int
+ }
+ \xparse_exp_set:cpx { \l_xparse_tmp_tl } ##1 \q_xparse ##2
+ {
+ \exp_not:N \tl_if_head_eq_charcode:nNTF {##2} #1
+ {
+ \exp_not:c { \l_xparse_tmp_tl aux }
+ ##1 \exp_not:N \q_xparse
+ }
+ {
+ \exp_not:c { \l_xparse_tmp_tl aux }
+ ##1 \exp_not:N \q_xparse #3 #2 {##2}
+ }
+ }
+ \xparse_exp_set:cpx { \l_xparse_tmp_tl aux} ##1 \q_xparse ##2 #2
+ {
+ \exp_not:c
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_eval:n { \l_xparse_total_args_int + 1 }
+ }
+ ##1 {##2} \exp_not:N \q_xparse
+ }
+ \xparse_exp_prepare_function:N
+ }
+\cs_new_protected_nopar:Npn \xparse_exp_add_type_l:w
+ {
+ \xparse_exp_set:cpx
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_use:N \l_xparse_total_args_int
+ }
+ ##1 \q_xparse ##2##
+ {
+ \exp_not:c
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_eval:n { \l_xparse_total_args_int + 1 }
+ }
+ ##1 {##2} \exp_not:N \q_xparse
+ }
+ \xparse_exp_prepare_function:N
+ }
+\cs_new_protected_nopar:Npn \xparse_exp_add_type_m:w
+ {
+ \int_incr:N \l_xparse_m_args_int
+ \xparse_exp_set:cpx
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_use:N \l_xparse_total_args_int
+ }
+ ##1 \q_xparse ##2
+ {
+ \exp_not:c
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_eval:n { \l_xparse_total_args_int + 1 }
+ }
+ ##1 {##2} \exp_not:N \q_xparse
+ }
+ \xparse_exp_prepare_function:N
+ }
+\cs_new_protected:Npn \xparse_exp_add_type_t:w #1
+ {
+ \tl_set:Nx \l_xparse_tmp_tl
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_eval:n { \l_xparse_total_args_int + 1 }
+ }
+ \xparse_exp_set:cpx
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_use:N \l_xparse_total_args_int
+ }
+ ##1 \q_xparse ##2
+ {
+ \exp_not:N \tl_if_head_eq_charcode:nNTF {##2} #1
+ {
+ \exp_not:c { \l_xparse_tmp_tl }
+ ##1 \exp_not:n { { \BooleanTrue } \q_xparse }
+ }
+ {
+ \exp_not:c { \l_xparse_tmp_tl }
+ ##1 \exp_not:n { { \BooleanFalse } \q_xparse {##2} }
+ }
+ }
+ \xparse_exp_prepare_function:N
+ }
+\cs_new_protected:Npn \xparse_exp_add_type_u:w #1
+ {
+ \xparse_exp_set:cpx
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_use:N \l_xparse_total_args_int
+ }
+ ##1 \q_xparse ##2 #1
+ {
+ \exp_not:c
+ {
+ \exp_after:wN \token_to_str:N \l_xparse_function_tl
+ \int_eval:n { \l_xparse_total_args_int + 1 }
+ }
+ ##1 {##2} \exp_not:N \q_xparse
+ }
+ \xparse_exp_prepare_function:N
+ }
+\cs_new_protected_nopar:Npn \xparse_exp_check_and_add:N #1
+ {
+ \cs_if_free:cTF { xparse_exp_add_type_ #1 :w }
+ {
+ \msg_error:nnx { xparse } { unknown-argument-type }
+ { \tl_to_str:n {#1} }
+ \tl_set:Nn \l_xparse_last_arg_tl { m }
+ \xparse_exp_add_type_m:w
+ }
+ {
+ \tl_set:Nn \l_xparse_last_arg_tl {#1}
+ \use:c { xparse_exp_add_type_ #1 :w }
+ }
+ }
+\cs_new_protected:Npn \xparse_exp_declare_cmd:Nnn #1#2#3
+ {
+ \cs_if_exist:NTF #1
+ {
+ \msg_warning:nnxx { xparse } { redefine-command }
+ { \token_to_str:N #1 } { \tl_to_str:n {#2} }
+ }
+ {
+ \msg_info:nnxx { xparse } { define-command }
+ { \token_to_str:N #1 } { \tl_to_str:n {#2} }
+ }
+ \group_begin:
+ \tex_escapechar:D 92 \scan_stop:
+ \tl_set:Nx \l_xparse_function_tl { \token_to_str:N #1}
+ \exp_args:NNNo \group_end:
+ \tl_set:Nn \l_xparse_function_tl { \l_xparse_function_tl }
+ \xparse_exp_prepare_function:n {#2}
+ \int_compare:nNnTF \l_xparse_total_args_int = \l_xparse_m_args_int
+ { \xparse_exp_declare_cmd_all_m:Nn #1 {#3} }
+ { \xparse_exp_declare_cmd_mixed:Nn #1 {#3} }
+ }
+\cs_new_protected:Npn \xparse_exp_declare_cmd_all_m:Nn #1#2
+ {
+ \bool_if:NTF \l_xparse_long_bool
+ {
+ \cs_generate_from_arg_count:NNnn
+ #1 \cs_set:Npn \l_xparse_total_args_int {#2}
+ }
+ {
+ \cs_generate_from_arg_count:NNnn
+ #1 \cs_set_nopar:Npn \l_xparse_total_args_int {#2}
+ }
+ }
+\cs_new_protected:Npn \xparse_exp_declare_cmd_mixed:Nn #1#2
+ {
+ \tl_if_in:noTF { l m u } \l_xparse_last_arg_tl
+ { \xparse_exp_declare_cmd_mixed_aux:Nn #1 {#2} }
+ { \msg_error:nn { xparse } { expandable-ending-optional } }
+ }
+\cs_new_protected:Npn \xparse_exp_declare_cmd_mixed_aux:Nn #1#2
+ {
+ \cs_set_nopar:Npx #1
+ { \exp_not:c { \token_to_str:N #1 1 } x \exp_not:N \q_xparse }
+ \cs_set_nopar:cpx
+ { \token_to_str:N #1 \int_eval:n { \l_xparse_total_args_int + 1 } }
+ x ##1 \q_xparse
+ { \exp_not:c { \token_to_str:N #1 } ##1 }
+ \cs_generate_from_arg_count:cNnn
+ { \token_to_str:N #1 } \cs_set:Npn \l_xparse_total_args_int {#2}
+ }
+\cs_new_protected:Npn \xparse_exp_prepare_function:n #1
+ {
+ \bool_set_false:N \l_xparse_error_bool
+ \tl_if_in:nnT {#1} { > }
+ {
+ \msg_error:nnx { xparse } { processor-in-expandable }
+ { \tl_to_str:n {#1} }
+ \bool_set_true:N \l_xparse_error_bool
+ }
+ \tl_if_in:nnT {#1} { g }
+ {
+ \msg_error:nnx { xparse } { grouped-in-expandable }
+ { g } { \tl_to_str:n {#1} }
+ \bool_set_true:N \l_xparse_error_bool
+ }
+ \tl_if_in:nnT {#1} { G }
+ {
+ \msg_error:nnx { xparse } { grouped-in-expandable }
+ { G } { \tl_to_str:n {#1} }
+ \bool_set_true:N \l_xparse_error_bool
+ }
+ \bool_if:NF \l_xparse_error_bool
+ { \xparse_exp_prepare_function_aux:n {#1} }
+ }
+\cs_new_protected:Npn \xparse_exp_prepare_function_aux:n #1
+ {
+ \cs_set_eq:NN \xparse_prepare_next:w \xparse_exp_prepare_function:N
+ \cs_set_eq:NN \xparse_exp_set:cpx \cs_set_nopar:cpx
+ \bool_set_false:N \l_xparse_long_bool
+ \int_zero:N \l_xparse_m_args_int
+ \int_zero:N \l_xparse_total_args_int
+ \tl_if_in:nnT {#1} { + }
+ {
+ \bool_set_true:N \l_xparse_long_bool
+ \cs_set_eq:NN \xparse_exp_set:cpx \cs_set:cpx
+ }
+ \xparse_exp_prepare_function:N #1 \q_nil
+ }
+\cs_new_protected:Npn \xparse_exp_prepare_function:N #1
+ {
+ \bool_if:NTF \l_xparse_long_bool
+ { \xparse_exp_prepare_function_long:N #1 }
+ { \xparse_exp_prepare_function_short:N #1 }
+}
+\cs_new_protected:Npn \xparse_exp_prepare_function_long:N #1
+ {
+ \quark_if_nil:NF #1
+ {
+ \str_if_eq:nnTF {#1} { + }
+ { \xparse_exp_prepare_function_short:N }
+ {
+ \msg_error:nn { xparse } { inconsistent-long }
+ \xparse_exp_prepare_function_short:N #1
+ }
+ }
+ }
+\cs_new_protected:Npn \xparse_exp_prepare_function_short:N #1
+ {
+ \quark_if_nil:NF #1
+ {
+ \prop_if_in:NnTF \c_xparse_shorthands_prop {#1}
+ {
+ \prop_get:NnN \c_xparse_shorthands_prop {#1} \l_xparse_tmp_tl
+ \bool_if:NT \l_xparse_long_bool
+ { \tl_put_left:Nn \l_xparse_tmp_tl { + } }
+ \exp_after:wN \xparse_exp_prepare_function:N \l_xparse_tmp_tl
+ }
+ {
+ \int_incr:N \l_xparse_total_args_int
+ \xparse_exp_check_and_add:N #1
+ }
+ }
+ }
+\cs_new_eq:NN \xparse_exp_set:cpx \cs_set_nopar:cpx
+\cs_new_protected:Npn \xparse_get_arg_spec:N #1
+ {
+ \cs_if_exist:cTF { l_xparse_ \token_to_str:N #1 _arg_spec_tl }
+ {
+ \tl_set_eq:Nc \ArgumentSpecification
+ { l_xparse_ \token_to_str:N #1 _arg_spec_tl }
+ }
+ {
+ \msg_error:nnx { xparse } { unknown-document-command }
+ { \token_to_str:N #1 }
+ }
+ }
+\cs_new_protected:Npn \xparse_get_arg_spec:n #1
+ {
+ \cs_if_exist:cTF { l_xparse_ #1 _arg_spec_tl }
+ { \tl_set_eq:Nc \ArgumentSpecification { l_xparse_ #1 _arg_spec_tl } }
+ {
+ \msg_error:nnx { xparse } { unknown-document-environment }
+ { \tl_to_str:n {#1} }
+ }
+ }
+\tl_new:N \ArgumentSpecification
+\cs_new_protected:Npn \xparse_show_arg_spec:N #1
+ {
+ \cs_if_exist:cTF { l_xparse_ \token_to_str:N #1 _arg_spec_tl }
+ {
+ \tl_set_eq:Nc \ArgumentSpecification
+ { l_xparse_ \token_to_str:N #1 _arg_spec_tl }
+ \tl_show:N \ArgumentSpecification
+ }
+ {
+ \msg_error:nnx { xparse } { unknown-document-command }
+ { \token_to_str:N #1 }
+ }
+ }
+\cs_new_protected:Npn \xparse_show_arg_spec:n #1
+ {
+ \cs_if_exist:cTF { l_xparse_ #1 _arg_spec_tl }
+ {
+ \tl_set_eq:Nc \ArgumentSpecification { l_xparse_ #1 _arg_spec_tl }
+ \tl_show:N \ArgumentSpecification
+ }
+ {
+ \msg_error:nnx { xparse } { unknown-document-environment }
+ { \tl_to_str:n {#1} }
+ }
+ }
+\msg_new:nnnn { xparse } { command-already-defined }
+ { Command~'#1'~already~defined! }
+ {
+ You~have~used~\NewDocumentCommand
+ with~a~command~that~already~has~a~definition. \\
+ The~existing~definition~of~'#1'~will~be~overwritten.
+ }
+\msg_new:nnnn { xparse } { command-not-yet-defined }
+ { Command ~'#1'~not~yet~defined! }
+ {
+ You~have~used~\RenewDocumentCommand
+ with~a~command~that~was~never~defined.\\
+ A~new~command~'#1'~will~be~created.
+ }
+\msg_new:nnnn { xparse } { environment-already-defined }
+ { Environment~'#1'~already~defined! }
+ {
+ You~have~used~\NewDocumentEnvironment
+ with~an~environment~that~already~has~a~definition.\\
+ The~existing~definition~of~'#1'~will~be~overwritten.
+ }
+\msg_new:nnnn { xparse } { environment-mismatch }
+ { Mismatch~between~start~and~end~of~environment. }
+ {
+ The~current~environment~is~called~'#1',~but~you~have~tried~to~
+ end~one~called~'#2'.~Environments~have~to~be~properly~nested.
+ }
+\msg_new:nnnn { xparse } { environment-not-yet-defined }
+ { Environment~'#1'~not~yet~defined! }
+ {
+ You~have~used~\RenewDocumentEnvironment
+ with~an~environment~that~was~never~defined.\\
+ A~new~environment~'#1'~will~be~created.
+ }
+\msg_new:nnnn { xparse } { environment-unknown }
+ { Environment~'#1'~undefined. }
+ {
+ You~have~tried~to~start~an~environment~called~'#1',~
+ but~this~has~never~been~defined.\\
+ The~command~will~be~ignored.
+ }
+\msg_new:nnnn { xparse } { expandable-ending-optional }
+ { Signature~for~expandable~command~ends~with~optional~argument. }
+ {
+ \c_msg_coding_error_text_tl
+ Expandable~commands~must~have~a~final~mandatory~argument~
+ (or~no~arguments~at~all).~You~cannot~have~a~terminal~optional~
+ argument~with~expandable~commands.
+ }
+\msg_new:nnnn { xparse } { grouped-in-expandable }
+ { Argument~specifier~'#1'~forbidden~in~expandable~commands. }
+ {
+ \c_msg_coding_error_text_tl
+ Argument~specification~'#2'~contains~the~optional~grouped~
+ argument~'#1':~
+ this~is only~supported~for~standard~robust~functions.
+ }
+\msg_new:nnnn { xparse } { inconsistent-long }
+ { Inconsistent~long~arguments~for~expandable~command. }
+ {
+ \c_msg_coding_error_text_tl
+ The~arguments~for~an~expandable~command~must~either~all~be~
+ short~or~all~be~long.~You~have~tried~to~mix~the~two~types.
+ }
+\msg_new:nnnn { xparse } { processor-in-expandable }
+ { Argument~processors~cannot~be~used~with~expandable~functions. }
+ {
+ \c_msg_coding_error_text_tl
+ Argument~specification~'#1'~contains~a~processor~function:~
+ this~is~only~supported~for~standard~robust~functions.
+ }
+\msg_new:nnnn { xparse } { split-excess-tokens }
+ { Too~many~'#1'~tokens~when~trying~to~split~argument. }
+ {
+ LaTeX~was~asked~to~split~the~input~'#3'~
+ at~each~occurrence~of~the~token~'#1',~up~to~a~maximum~of~#2~parts.~
+ There~were~too~many~'#1'~tokens.
+ }
+\msg_new:nnnn { xparse } { unknown-argument-type }
+ { Unknown~argument~type~'#1'~replaced~by~'m'. }
+ {
+ \c_msg_coding_error_text_tl
+ The~letter~'#1'~does~not~specify~a~known~argument~type.~
+ LaTeX~will~assume~you~want~a~standard~mandatory~argument~(type~'m').
+ }
+\msg_new:nnnn { xparse } { unknown-document-command }
+ { Unknown~document~command~'#1'. }
+ {
+ You~have~asked~for~the~argument~specification~for~a~command~'#1',~
+ but~this~is~not~a~document~command.
+ }
+\msg_new:nnnn { xparse } { unknown-document-environment }
+ { Unknown~document~environment~'#1'. }
+ {
+ You~have~asked~for~the~argument~specification~for~a~command~'#1',~
+ but~this~is~not~a~document~environment.
+ }
+\msg_new:nnn { xparse } { define-command }
+ {
+ Defining~document~command~#1~
+ with~arg.~spec.~'#2'~\msg_line_context:.
+ }
+\msg_new:nnn { xparse } { define-environment }
+ {
+ Defining~document~environment~'#1'~
+ with~arg.~spec.~'#2'~\msg_line_context:.
+ }
+\msg_new:nnn { xparse } { redefine-command }
+ {
+ Redefining~document~command~#1~
+ with~arg.~spec.~'#2'~\msg_line_context:.
+ }
+\msg_new:nnn { xparse } { redefine-environment }
+ {
+ Redefining~document~environment~'#1'~
+ with~arg.~spec.~'#2'~\msg_line_context:.
+ }
+\cs_new_eq:NN \BooleanFalse \c_false_bool
+\cs_new_eq:NN \BooleanTrue \c_true_bool
+\cs_new_protected:Npn \DeclareDocumentCommand #1#2#3
+ { \xparse_declare_cmd:Nnn #1 {#2} {#3} }
+\cs_new_protected:Npn \NewDocumentCommand #1#2#3
+ {
+ \cs_if_exist:NTF #1
+ {
+ \msg_error:nnx { xparse } { command-already-defined }
+ { \token_to_str:N #1 }
+ }
+ { \xparse_declare_cmd:Nnn #1 {#2} {#3} }
+ }
+\cs_new_protected:Npn \RenewDocumentCommand #1#2#3
+ {
+ \cs_if_exist:NTF #1
+ { \xparse_declare_cmd_aux:Nnn #1 {#2} {#3} }
+ {
+ \msg_error:nnx { xparse } { command-not-yet-defined }
+ { \token_to_str:N #1 }
+ }
+ }
+\cs_new_protected:Npn \ProvideDocumentCommand #1#2#3
+ { \cs_if_exist:NF #1 { \xparse_declare_cmd:Nnn #1 {#2} {#3} } }
+\cs_new_protected:Npn \DeclareDocumentCommandImplementation #1#2#3
+ { \xparse_declare_cmd_implementation:nNn {#1} #2 {#3} }
+\cs_new_protected:Npn \DeclareDocumentCommandInterface #1#2#3
+ { \xparse_declare_cmd_interface:Nnn #1 {#2} {#3} }
+\cs_new_protected:Npn \DeclareDocumentEnvironment #1#2#3#4
+ { \xparse_declare_env:nnnn {#1} {#2} {#3} {#4} }
+\cs_new_protected:Npn \NewDocumentEnvironment #1#2#3#4
+ {
+ \cs_if_exist:cTF {#1}
+ { \msg_error:nnx { xparse } { environment-already-defined } {#1} }
+ { \xparse_declare_env:nnnn {#1} {#2} {#3} {#4} }
+}
+\cs_new_protected:Npn \RenewDocumentEnvironment #1#2#3#4
+ {
+ \cs_if_exist:cTF {#1}
+ { \xparse_declare_env:nnnn {#1} {#2} {#3} {#4} }
+ { \msg_error:nnx { xparse } { environment-not-yet-defined } {#1} }
+ }
+\cs_new_protected:Npn \ProvideDocumentEnvironment #1#2#3#4
+ { \cs_if_exist:cF { #1 } { \xparse_declare_env:nnnn {#1} {#2} {#3} {#4} } }
+\cs_new_protected:Npn \DeclareExpandableDocumentCommand #1#2#3
+ { \xparse_exp_declare_cmd:Nnn #1 {#2} {#3} }
+\cs_new_eq:NN \IfBooleanTF \bool_if:NTF
+\cs_new_eq:NN \IfBooleanT \bool_if:NT
+\cs_new_eq:NN \IfBooleanF \bool_if:NF
+\cs_new_eq:NN \IfNoValueF \xparse_if_no_value:nF
+\cs_new_eq:NN \IfNoValueT \xparse_if_no_value:nT
+\cs_new_eq:NN \IfNoValueTF \xparse_if_no_value:nTF
+\cs_set:Npn \IfValueF { \xparse_if_no_value:nT }
+\cs_set:Npn \IfValueT { \xparse_if_no_value:nF }
+\cs_set:Npn \IfValueTF #1#2#3 { \xparse_if_no_value:nTF {#1} {#3} {#2} }
+\cs_new_protected:Npn \NoValue { -NoValue- }
+\tl_new:N \ProcessedArgument
+\cs_new_eq:NN \ReverseBoolean \xparse_bool_reverse:N
+\cs_new_eq:NN \SplitArgument \xparse_split_argument:nnn
+\cs_new_eq:NN \SplitList \xparse_split_list:nn
+\cs_new_eq:NN \GetDocumentCommandArgSpec \xparse_get_arg_spec:N
+\cs_new_eq:NN \GetDocumentEnvironmmentArgSpec \xparse_get_arg_spec:n
+\cs_new_eq:NN \ShowDocumentCommandArgSpec \xparse_show_arg_spec:N
+\cs_new_eq:NN \ShowDocumentEnvironmentArgSpec \xparse_show_arg_spec:n
+\DeclareOption { log-declarations = true } { }
+\DeclareOption { log-declarations = false }
+ {
+ \msg_redirect_module:nnn { xparse } { info } { none }
+ \msg_redirect_module:nnn { xparse } { warning } { none }
+ }
+\DeclareOption { log-declarations } { }
+\ProcessOptions \scan_stop:
+%%
+%%
+%% End of file `xparse.sty'.
diff --git a/Master/texmf-dist/tex/latex/l3packages/xtemplate/xtemplate.sty b/Master/texmf-dist/tex/latex/l3packages/xtemplate/xtemplate.sty
new file mode 100644
index 00000000000..83be1411dad
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/l3packages/xtemplate/xtemplate.sty
@@ -0,0 +1,1373 @@
+%%
+%% This is file `xtemplate.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% xtemplate.dtx (with options: `package')
+%%
+%% EXPERIMENTAL CODE
+%%
+%% Do not distribute this file without also distributing the
+%% source files specified above.
+%%
+%% Do not distribute a modified version of this file.
+%%
+%% File: xtemplate.dtx (C) Copyright 1999 Frank Mittelbach, Chris Rowley,
+%% David Carlisle
+%% (C) Copyright 2004-2010 Frank Mittelbach,
+%% The LaTeX3 Project
+%% (C) Copyright 2011 The LaTeX3 Project
+%%
+%% It may be distributed and/or modified under the conditions of the
+%% LaTeX Project Public License (LPPL), either version 1.3c of this
+%% license or (at your option) any later version. The latest version
+%% of this license is in the file
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% This file is part of the "l3packages bundle" (The Work in LPPL)
+%% and all files in that bundle must be distributed together.
+%%
+%% The released version of this bundle is available from CTAN.
+%%
+%% -----------------------------------------------------------------------
+%%
+%% The development version of the bundle can be found at
+%%
+%% http://www.latex-project.org/svnroot/experimental/trunk/
+%%
+%% for those people who are interested.
+%%
+%%%%%%%%%%%
+%% NOTE: %%
+%%%%%%%%%%%
+%%
+%% Snapshots taken from the repository represent work in progress and may
+%% not work or may contain conflicting material! We therefore ask
+%% people _not_ to put them into distributions, archives, etc. without
+%% prior consultation with the LaTeX Project Team.
+%%
+%% -----------------------------------------------------------------------
+%%
+\RequirePackage{expl3}
+\GetIdInfo$Id: xtemplate.dtx 2492 2011-07-02 13:40:38Z joseph $
+ {L3 Experimental prototype document functions}
+\ProvidesExplPackage
+ {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+\@ifpackagelater { l3token } { 2011/07/02 }
+ { }
+ {
+ \PackageError { xtemplate } { Support~package~l3kernel~too~old. }
+ {
+ Please~install~an~up~to~date~version~of~l3kernel~
+ using~your~TeX~package~manager~or~from~CTAN.\\ \\
+ Loading~xtemplate~will~abort!
+ }
+ \tex_endinput:D
+ }
+\tl_const:Nn \c_xtemplate_code_root_tl { template~code~>~ }
+\tl_const:Nn \c_xtemplate_defaults_root_tl { template~defaults~>~ }
+\tl_const:Nn \c_xtemplate_instances_root_tl { template~instance~>~ }
+\tl_const:Nn \c_xtemplate_keytypes_root_tl { template~key~types~>~ }
+\tl_const:Nn \c_xtemplate_key_order_root_tl { template~key~order~>~ }
+\tl_const:Nn \c_xtemplate_restrict_root_tl { template~restrictions~>~ }
+\tl_const:Nn \c_xtemplate_values_root_tl { template~values~>~ }
+\tl_const:Nn \c_xtemplate_vars_root_tl { template~vars~>~ }
+\seq_new:N \c_xtemplate_keytypes_arg_seq
+\seq_put_right:Nn \c_xtemplate_keytypes_arg_seq { choice }
+\seq_put_right:Nn \c_xtemplate_keytypes_arg_seq { function }
+\seq_put_right:Nn \c_xtemplate_keytypes_arg_seq { instance }
+\prop_new:N \g_xtemplate_object_type_prop
+\tl_new:N \l_xtemplate_assignments_tl
+\tl_new:N \l_xtemplate_collection_tl
+\prop_new:N \l_xtemplate_collections_prop
+\tl_new:N \l_xtemplate_default_tl
+\bool_new:N \l_xtemplate_error_bool
+\bool_new:N \l_xtemplate_global_bool
+\bool_new:N \l_xtemplate_restrict_bool
+\clist_new:N \l_xtemplate_restrict_clist
+\tl_new:N \l_xtemplate_key_name_tl
+\tl_new:N \l_xtemplate_keytype_tl
+\tl_new:N \l_xtemplate_keytype_arg_tl
+\tl_new:N \l_xtemplate_value_tl
+\tl_new:N \l_xtemplate_var_tl
+\prop_new:N \l_xtemplate_keytypes_prop
+\seq_new:N \l_xtemplate_key_order_seq
+\prop_new:N \l_xtemplate_values_prop
+\prop_new:N \l_xtemplate_vars_prop
+\clist_new:N \l_xtemplate_tmp_clist
+\dim_new:N \l_xtemplate_tmp_dim
+\int_new:N \l_xtemplate_tmp_int
+\muskip_new:N \l_xtemplate_tmp_muskip
+\skip_new:N \l_xtemplate_tmp_skip
+\tl_new:N \l_xtemplate_tmp_tl
+\cs_new_protected:Npn \xtemplate_execute_if_arg_agree:nnT #1#2#3
+ {
+ \prop_get:NnN \g_xtemplate_object_type_prop {#1} \l_xtemplate_tmp_tl
+ \int_compare:nNnTF {#2} = \l_xtemplate_tmp_tl
+ {#3}
+ {
+ \msg_error:nnxxx { xtemplate }
+ { argument-number-mismatch } {#1} { \l_xtemplate_tmp_tl } {#2}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_execute_if_code_exist:nnT #1#2#3
+ {
+ \cs_if_exist:cTF { \c_xtemplate_code_root_tl #1 / #2 }
+ {#3}
+ {
+ \msg_error:nnxx { xtemplate } { no-template-code }
+ {#1} {#2}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_execute_if_keytype_exist:nT #1#2
+ {
+ \cs_if_exist:cTF { xtemplate_store_value_ #1 :n }
+ {#2}
+ { \msg_error:nnx { xtemplate } { unknown-keytype } {#1} }
+ }
+\cs_generate_variant:Nn \xtemplate_execute_if_keytype_exist:nT { o }
+\cs_new_protected:Npn \xtemplate_execute_if_type_exist:nT #1#2
+ {
+ \prop_if_in:NnTF \g_xtemplate_object_type_prop {#1}
+ {#2}
+ { \msg_error:nnx { xtemplate } { unknown-object-type } {#1} }
+ }
+\cs_new_protected:Npn \xtemplate_if_keys_exist:nnT #1#2#3
+ {
+ \cs_if_exist:cTF { \c_xtemplate_keytypes_root_tl #1 / #2 }
+ {#3}
+ {
+ \msg_error:nnxx { xtemplate } { unknown-template }
+ {#1} {#2}
+ }
+ }
+\prg_new_conditional:Npnn \xtemplate_if_key_value:n #1 { T }
+ {
+ \str_if_eq:noTF { \KeyValue } { \tl_head:w #1 \q_stop }
+ {\prg_return_true: }
+ { \prg_return_false: }
+ }
+\cs_generate_variant:Nn \xtemplate_if_key_value:nT { o }
+\prg_new_conditional:Npnn \xtemplate_if_eval_now:n #1 { TF }
+ {
+ \str_if_eq:noTF { \EvaluateNow } { \tl_head:w #1 \q_stop }
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+\prg_new_conditional:Npnn \xtemplate_if_instance_exist:nnn #1#2#3
+ { T, F, TF }
+ {
+ \cs_if_exist:cTF { \c_xtemplate_instances_root_tl #1 / #2 / #3 }
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+\prg_new_conditional:Npnn \xtemplate_if_use_template:n #1 { TF }
+ {
+ \str_if_eq:noTF { \UseTemplate } { \tl_head:w #1 \q_stop }
+ { \prg_return_true: }
+ { \prg_return_false: }
+}
+\cs_new_protected:Npn \xtemplate_store_defaults:n #1
+ {
+ \prop_gclear_new:c { \c_xtemplate_defaults_root_tl #1 }
+ \prop_gset_eq:cN { \c_xtemplate_defaults_root_tl #1 }
+ \l_xtemplate_values_prop
+ }
+\cs_new_protected:Npn \xtemplate_store_keytypes:n #1
+ {
+ \prop_gclear_new:c { \c_xtemplate_keytypes_root_tl #1 }
+ \prop_gset_eq:cN { \c_xtemplate_keytypes_root_tl #1 }
+ \l_xtemplate_keytypes_prop
+ \seq_gclear_new:c { \c_xtemplate_key_order_root_tl #1 }
+ \seq_gset_eq:cN { \c_xtemplate_key_order_root_tl #1 }
+ \l_xtemplate_key_order_seq
+ }
+\cs_new_protected:Npn \xtemplate_store_values:n #1
+ {
+ \prop_clear_new:c { \c_xtemplate_values_root_tl #1 }
+ \prop_set_eq:cN { \c_xtemplate_values_root_tl #1 }
+ \l_xtemplate_values_prop
+ }
+\cs_new_protected:Npn \xtemplate_store_restrictions:n #1
+ {
+ \clist_gclear_new:c { \c_xtemplate_restrict_root_tl #1 }
+ \clist_gset_eq:cN { \c_xtemplate_restrict_root_tl #1 }
+ \l_xtemplate_restrict_clist
+ }
+\cs_new_protected:Npn \xtemplate_store_vars:n #1
+ {
+ \prop_gclear_new:c { \c_xtemplate_vars_root_tl #1 }
+ \prop_gset_eq:cN { \c_xtemplate_vars_root_tl #1 }
+ \l_xtemplate_vars_prop
+ }
+\cs_new_protected:Npn \xtemplate_recover_defaults:n #1
+ {
+ \prop_set_eq:Nc \l_xtemplate_values_prop
+ { \c_xtemplate_defaults_root_tl #1 }
+ }
+\cs_new_protected:Npn \xtemplate_recover_keytypes:n #1
+ {
+ \prop_set_eq:Nc \l_xtemplate_keytypes_prop
+ { \c_xtemplate_keytypes_root_tl #1 }
+ \seq_set_eq:Nc \l_xtemplate_key_order_seq
+ { \c_xtemplate_key_order_root_tl #1 }
+ }
+\cs_new_protected:Npn \xtemplate_recover_restrictions:n #1
+ {
+ \clist_set_eq:Nc \l_xtemplate_restrict_clist
+ { \c_xtemplate_restrict_root_tl #1 }
+ }
+\cs_new_protected:Npn \xtemplate_recover_values:n #1
+ {
+ \prop_set_eq:Nc \l_xtemplate_values_prop
+ { \c_xtemplate_values_root_tl #1 }
+ }
+\cs_new_protected:Npn \xtemplate_recover_vars:n #1
+ {
+ \prop_set_eq:Nc \l_xtemplate_vars_prop
+ { \c_xtemplate_vars_root_tl #1 }
+ }
+\cs_new_protected:Npn \xtemplate_declare_object_type:nn #1#2
+ {
+ \int_set:Nn \l_xtemplate_tmp_int {#2}
+ \bool_if:nTF
+ {
+ \int_compare_p:nNn {#2} > \c_nine ||
+ \int_compare_p:nNn {#2} < \c_zero
+ }
+ {
+ \msg_error:nnxx { xtemplate } { bad-number-of-arguments }
+ {#1} { \exp_not:V \l_xtemplate_tmp_int }
+ }
+ {
+ \msg_info:nnxx { xtemplate } { declare-object-type }
+ {#1} {#2}
+ \prop_gput:NnV \g_xtemplate_object_type_prop {#1}
+ \l_xtemplate_tmp_int
+ }
+ }
+\cs_new_protected:Npn \xtemplate_declare_template_keys:nnnn #1#2#3#4
+ {
+ \xtemplate_execute_if_type_exist:nT {#1}
+ {
+ \xtemplate_execute_if_arg_agree:nnT {#1} {#3}
+ {
+ \prop_clear:N \l_xtemplate_values_prop
+ \prop_clear:N \l_xtemplate_keytypes_prop
+ \seq_clear:N \l_xtemplate_key_order_seq
+ \keyval_parse:NNn
+ \xtemplate_parse_keys_elt:n \xtemplate_parse_keys_elt:nn {#4}
+ \xtemplate_store_defaults:n { #1 / #2 }
+ \xtemplate_store_keytypes:n { #1 / #2 }
+ }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_parse_keys_elt:n #1
+ {
+ \xtemplate_split_keytype:n {#1}
+ \bool_if:NF \l_xtemplate_error_bool
+ {
+ \xtemplate_execute_if_keytype_exist:oT \l_xtemplate_keytype_tl
+ {
+ \seq_map_function:NN \c_xtemplate_keytypes_arg_seq
+ \xtemplate_parse_keys_elt_aux:n
+ \bool_if:NF \l_xtemplate_error_bool
+ {
+ \seq_if_in:NoTF \l_xtemplate_key_order_seq
+ \l_xtemplate_key_name_tl
+ {
+ \msg_error:nnx { xtemplate }
+ { duplicate-key-interface }
+ { \l_xtemplate_key_name_tl }
+ }
+ { \xtemplate_parse_keys_elt_aux: }
+ }
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_parse_keys_elt_aux:n #1
+ {
+ \str_if_eq:onT \l_xtemplate_keytype_tl {#1}
+ {
+ \tl_if_empty:NT \l_xtemplate_keytype_arg_tl
+ {
+ \msg_error:nnx { xtemplate }
+ { keytype-requires-argument } {#1}
+ \bool_set_true:N \l_xtemplate_error_bool
+ \seq_map_break:
+ }
+ }
+ }
+\cs_new_nopar:Npn \xtemplate_parse_keys_elt_aux:
+ {
+ \tl_set:Nx \l_xtemplate_tmp_tl
+ {
+ \l_xtemplate_keytype_tl
+ \tl_if_empty:NF \l_xtemplate_keytype_arg_tl
+ { { \l_xtemplate_keytype_arg_tl } }
+ }
+ \prop_put:Noo \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \seq_put_right:No \l_xtemplate_key_order_seq \l_xtemplate_key_name_tl
+ \str_if_eq:onT \l_xtemplate_keytype_tl { choice }
+ {
+ \clist_if_in:NnT \l_xtemplate_keytype_arg_tl { unknown }
+ { \msg_error:nn { xtemplate } { choice-unknown-reserved } }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_parse_keys_elt:nn #1#2
+ {
+ \xtemplate_parse_keys_elt:n {#1}
+ \use:c { xtemplate_store_value_ \l_xtemplate_keytype_tl :n } {#2}
+ }
+\group_begin:
+\char_set_lccode:nn { `\@ } { `\: }
+\char_set_catcode_other:N \@
+\tl_to_lowercase:n
+ {
+ \group_end:
+ \cs_new_protected:Npn \xtemplate_split_keytype:n #1
+ {
+ \bool_set_false:N \l_xtemplate_error_bool
+ \tl_set:Nn \l_xtemplate_tmp_tl {#1}
+ \tl_remove_all:Nn \l_xtemplate_tmp_tl { ~ }
+ \tl_replace_all:Nnn \l_xtemplate_tmp_tl { : } { @ }
+ \tl_if_in:onTF \l_xtemplate_tmp_tl { @ }
+ {
+ \tl_clear:N \l_xtemplate_key_name_tl
+ \exp_after:wN \xtemplate_split_keytype_aux:w
+ \l_xtemplate_tmp_tl \q_stop
+ }
+ {
+ \bool_set_true:N \l_xtemplate_error_bool
+ \msg_error:nnx { xtemplate } { missing-keytype } {#1}
+ }
+ }
+ \cs_new_protected:Npn \xtemplate_split_keytype_aux:w #1 @ #2 \q_stop
+ {
+ \tl_put_right:Nx \l_xtemplate_key_name_tl { \tl_to_str:n {#1} }
+ \tl_if_in:nnTF {#2} { @ }
+ {
+ \tl_put_right:Nn \l_xtemplate_key_name_tl { @ }
+ \xtemplate_split_keytype_aux:w #2 \q_stop
+ }
+ {
+ \tl_if_empty:NTF \l_xtemplate_key_name_tl
+ { \msg_error:nnx { xtemplate } { empty-key-name } { @ #2 } }
+ { \xtemplate_split_keytype_arg:n {#2} }
+ }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_split_keytype_arg:n #1
+ {
+ \tl_set:Nn \l_xtemplate_keytype_tl {#1}
+ \tl_clear:N \l_xtemplate_keytype_arg_tl
+ \cs_set_protected_nopar:Npn \xtemplate_split_keytype_arg_aux:n ##1
+ {
+ \tl_if_in:nnT {#1} {##1}
+ {
+ \cs_set:Npn \xtemplate_split_keytype_arg_aux:w
+ ####1 ##1 ####2 \q_stop
+ {
+ \tl_if_empty:nT {####1}
+ {
+ \tl_set:Nn \l_xtemplate_keytype_tl {##1}
+ \tl_set:Nn \l_xtemplate_keytype_arg_tl {####2}
+ \seq_map_break:
+ }
+ }
+ \xtemplate_split_keytype_arg_aux:w #1 \q_stop
+ }
+ }
+ \seq_map_function:NN \c_xtemplate_keytypes_arg_seq
+ \xtemplate_split_keytype_arg_aux:n
+ }
+\cs_generate_variant:Nn \xtemplate_split_keytype_arg:n { o }
+\cs_new_nopar:Npn \xtemplate_split_keytype_arg_aux:n #1 { }
+\cs_new_nopar:Npn \xtemplate_split_keytype_arg_aux:w #1 \q_stop { }
+\cs_new_protected:Npn \xtemplate_store_value_boolean:n #1
+ {
+ \xtemplate_if_eval_now:nTF {#1}
+ {
+ \bool_if:cTF { c_ #1 _bool }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ { true }
+ }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ { false }
+ }
+ }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl {#1}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_store_value_code:n #1
+ { \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl {#1} }
+\cs_new_eq:NN \xtemplate_store_value_choice:n \xtemplate_store_value_code:n
+\cs_new_eq:NN \xtemplate_store_value_commalist:n \xtemplate_store_value_code:n
+\cs_new_eq:NN \xtemplate_store_value_function:n \xtemplate_store_value_code:n
+\cs_new_eq:NN \xtemplate_store_value_instance:n \xtemplate_store_value_code:n
+\cs_new_eq:NN \xtemplate_store_value_real:n \xtemplate_store_value_code:n
+\cs_new_eq:NN \xtemplate_store_value_tokenlist:n \xtemplate_store_value_code:n
+\cs_new_protected:Npn \xtemplate_store_value_integer:n #1
+ {
+ \xtemplate_if_eval_now:nTF {#1}
+ {
+ \int_set:Nn \l_xtemplate_tmp_int {#1}
+ \prop_put:NVV \l_xtemplate_values_prop \l_xtemplate_key_name_int
+ \l_xtemplate_tmp_int
+ }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl {#1}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_store_value_length:n #1
+ {
+ \xtemplate_if_eval_now:nTF {#1}
+ {
+ \dim_set:Nn \l_xtemplate_tmp_dim {#1}
+ \prop_put:NVV \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_dim
+ }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl {#1}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_store_value_muskip:n #1
+ {
+ \xtemplate_if_eval_now:nTF {#1}
+ {
+ \muskip_set:Nn \l_xtemplate_tmp_muskip {#1}
+ \prop_put:NVV \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_muskip
+ }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl {#1}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_store_value_skip:n #1
+ {
+ \xtemplate_if_eval_now:nTF {#1}
+ {
+ \skip_set:Nn \l_xtemplate_tmp_skip {#1}
+ \prop_put:NVV \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_skip
+ }
+ {
+ \prop_put:Non \l_xtemplate_values_prop \l_xtemplate_key_name_tl {#1}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_declare_template_code:nnnnn #1#2#3#4#5
+ {
+ \xtemplate_execute_if_type_exist:nT {#1}
+ {
+ \xtemplate_execute_if_arg_agree:nnT {#1}{#3}
+ {
+ \xtemplate_if_keys_exist:nnT {#1} {#2}
+ {
+ \xtemplate_store_key_implementation:nnn {#1} {#2} {#4}
+ \cs_generate_from_arg_count:cNnn
+ { \c_xtemplate_code_root_tl #1 / #2 }
+ \cs_gset_protected:Npn {#3} {#5}
+ }
+ }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_store_key_implementation:nnn #1#2#3
+ {
+ \xtemplate_recover_defaults:n { #1 / #2 }
+ \xtemplate_recover_keytypes:n { #1 / #2 }
+ \prop_clear:N \l_xtemplate_vars_prop
+ \keyval_parse:NNn
+ \xtemplate_parse_vars_elt:n \xtemplate_parse_vars_elt:nn {#3}
+ \xtemplate_store_vars:n { #1 / #2 }
+ \clist_clear:N \l_xtemplate_restrict_clist
+ \xtemplate_store_restrictions:n { #1 / #2 }
+ \prop_if_empty:NF \l_xtemplate_keytypes_prop
+ {
+ \prop_map_inline:Nn \l_xtemplate_keytypes_prop
+ {
+ \msg_error:nnxxx { xtemplate } { key-not-implemented }
+ {##1} {#2} {#1}
+ }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_parse_vars_elt:n #1
+ { \msg_error:nnx { xtemplate } { key-no-variable } {#1} }
+\cs_new_protected:Npn \xtemplate_parse_vars_elt:nn #1#2
+ {
+ \tl_set:Nx \l_xtemplate_key_name_tl { \tl_to_str:n {#1} }
+ \tl_remove_all:Nn \l_xtemplate_key_name_tl { ~ }
+ \prop_if_in:NoTF \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ {
+ \prop_get:NoN \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_keytype_tl
+ \xtemplate_split_keytype_arg:o \l_xtemplate_keytype_tl
+ \xtemplate_parse_vars_elt_aux:n {#2}
+ \prop_del:NV \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ }
+ { \msg_error:nnx { xtemplate } { unknown-key } {#1} }
+ }
+\cs_new_protected:Npn \xtemplate_parse_vars_elt_aux:n #1
+ {
+ \str_if_eq:onTF \l_xtemplate_keytype_tl { choice }
+ { \xtemplate_implement_choices:n {#1} }
+ {
+ \str_if_eq:onTF \l_xtemplate_keytype_tl { code }
+ {
+ \prop_put:Non \l_xtemplate_vars_prop
+ \l_xtemplate_key_name_tl {#1}
+ }
+ {
+ \str_if_eq:noTF {#1} { \tl_head:w #1 \q_stop }
+ {
+ \cs_if_exist:NTF #1
+ {
+ \prop_put:Non \l_xtemplate_vars_prop
+ \l_xtemplate_key_name_tl {#1}
+ }
+ {
+ \msg_error:nnx { xtemplate }
+ { variable-not-declared }
+ { \token_to_str:N #1 }
+ }
+ }
+ {
+ \tl_if_in:nnTF {#1} { global }
+ { \xtemplate_parse_vars_elt_aux:w #1 \q_stop }
+ {
+ \msg_error:nnx { xtemplate } { bad-variable }
+ { \tl_to_str:n {#1} }
+ }
+ }
+ }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_parse_vars_elt_aux:w #1 global #2 \q_stop
+ {
+ \tl_if_empty:nTF {#1}
+ {
+ \str_if_eq:noTF {#2} { \tl_head:w #2 \q_stop }
+ {
+ \cs_if_exist:NTF #2
+ {
+ \prop_put:Non \l_xtemplate_vars_prop
+ \l_xtemplate_key_name_tl { #1 global #2 }
+ }
+ {
+ \msg_error:nnx { xtemplate }
+ { variable-not-declared } { \token_to_str:N #2 }
+ }
+ }
+ {
+ \msg_error:nnx { xtemplate } { bad-variable }
+ { \tl_to_str:n { #1 global #2 } }
+ }
+ }
+ {
+ \msg_error:nnx { xtemplate } { bad-variable }
+ { \tl_to_str:n { #1 global #2 } }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_implement_choices:n #1
+ {
+ \clist_set_eq:NN \l_xtemplate_tmp_clist \l_xtemplate_keytype_arg_tl
+ \prop_put:Non \l_xtemplate_vars_prop \l_xtemplate_key_name_tl { }
+ \keyval_parse:NNn
+ \xtemplate_implement_choice_elt:n \xtemplate_implement_choice_elt:nn
+ {#1}
+ \prop_if_in:NoT \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ { \xtemplate_implement_choices_default: }
+ \clist_if_empty:NF \l_xtemplate_tmp_clist
+ {
+ \clist_map_inline:Nn \l_xtemplate_tmp_clist
+ {
+ \msg_error:nnx { xtemplate } { choice-not-implemented }
+ {##1}
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_implement_choices_default:
+ {
+ \prop_get:NoN \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \tl_set:Nx \l_xtemplate_tmp_tl
+ { \l_xtemplate_key_name_tl \c_space_tl \l_xtemplate_tmp_tl }
+ \prop_if_in:NoF \l_xtemplate_vars_prop \l_xtemplate_tmp_tl
+ {
+ \tl_set:Nx \l_xtemplate_tmp_tl
+ { \l_xtemplate_key_name_tl \c_space_tl \l_xtemplate_tmp_tl }
+ \prop_if_in:NoF \l_xtemplate_vars_prop \l_xtemplate_tmp_tl
+ {
+ \prop_get:NoN \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \xtemplate_split_keytype_arg:o \l_xtemplate_tmp_tl
+ \prop_get:NoN \l_xtemplate_values_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \msg_error:nnxxx { xtemplate } { unknown-default-choice }
+ { \l_xtemplate_key_name_tl } { \l_xtemplate_key_name_tl }
+ { \l_xtemplate_keytype_arg_tl }
+ }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_implement_choice_elt:n #1
+ {
+ \clist_if_empty:NTF \l_xtemplate_tmp_clist
+ {
+ \str_if_eq:nnF {#1} { unknown }
+ {
+ \prop_get:NoN \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \xtemplate_split_keytype_arg:o \l_xtemplate_tmp_tl
+ \msg_error:nnxxx { xtemplate } { unknown-choice }
+ { \l_xtemplate_key_name_tl } {#1}
+ { \l_xtemplate_keytype_arg_tl }
+ }
+ }
+ {
+ \clist_if_in:NnTF \l_xtemplate_tmp_clist {#1}
+ { \clist_remove_element:Nn \l_xtemplate_tmp_clist {#1} }
+ {
+ \prop_get:NoN \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \xtemplate_split_keytype_arg:o \l_xtemplate_tmp_tl
+ \msg_error:nnxxx { xtemplate } { unknown-choice }
+ { \l_xtemplate_key_name_tl } {#1}
+ { \l_xtemplate_keytype_arg_tl }
+ }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_implement_choice_elt:nn #1#2
+ {
+ \xtemplate_implement_choice_elt:n {#1}
+ \tl_set:Nx \l_xtemplate_tmp_tl
+ { \l_xtemplate_key_name_tl \c_space_tl #1 }
+ \prop_put:Non \l_xtemplate_vars_prop \l_xtemplate_tmp_tl {#2}
+ }
+\cs_new_protected:Npn \xtemplate_declare_restricted:nnnn #1#2#3#4
+ {
+ \xtemplate_if_keys_exist:nnT {#1} {#2}
+ {
+ \xtemplate_set_template_eq:nn { #1 / #3 } { #1 / #2 }
+ \bool_set_true:N \l_xtemplate_restrict_bool
+ \xtemplate_edit_defaults_aux:nnn {#1} {#3} {#4}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_edit_defaults:nnn
+ {
+ \bool_set_false:N \l_xtemplate_restrict_bool
+ \xtemplate_edit_defaults_aux:nnn
+ }
+\cs_new_protected:Npn \xtemplate_edit_defaults_aux:nnn #1#2#3
+ {
+ \xtemplate_if_keys_exist:nnT {#1} {#2}
+ {
+ \xtemplate_recover_defaults:n { #1 / #2 }
+ \xtemplate_recover_restrictions:n { #1 / #2 }
+ \xtemplate_parse_values:nn { #1 / #2 } {#3}
+ \xtemplate_store_defaults:n { #1 / #2 }
+ \xtemplate_store_restrictions:n { #1 / #2 }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_parse_values:nn #1#2
+ {
+ \xtemplate_recover_keytypes:n {#1}
+ \clist_clear:N \l_xtemplate_restrict_clist
+ \keyval_parse:NNn
+ \xtemplate_parse_values_elt:n \xtemplate_parse_values_elt:nn {#2}
+ }
+\cs_new_protected:Npn \xtemplate_parse_values_elt:n #1
+ {
+ \bool_set_true:N \l_xtemplate_error_bool
+ \msg_error:nnx { xtemplate } { key-no-value } {#1}
+ }
+\cs_new_protected:Npn \xtemplate_parse_values_elt:nn #1#2
+ {
+ \tl_set:Nx \l_xtemplate_key_name_tl { \tl_to_str:n {#1} }
+ \tl_remove_all:Nn \l_xtemplate_key_name_tl { ~ }
+ \prop_if_in:NoTF \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ {
+ \bool_if:NTF \l_xtemplate_restrict_bool
+ {
+ \clist_if_in:NoF \l_xtemplate_restrict_clist
+ \l_xtemplate_key_name_tl
+ {
+ \xtemplate_parse_values_elt_aux:on
+ \l_xtemplate_key_name_tl {#2}
+ }
+ }
+ { \xtemplate_parse_values_elt_aux:on \l_xtemplate_key_name_tl {#2} }
+ }
+ {
+ \msg_error:nnx { xtemplate } { unknown-key }
+ { \l_xtemplate_key_name_tl }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_parse_values_elt_aux:nn #1#2
+ {
+ \clist_put_right:Nn \l_xtemplate_restrict_clist {#1}
+ \prop_get:NnN \l_xtemplate_keytypes_prop {#1} \l_xtemplate_tmp_tl
+ \xtemplate_split_keytype_arg:o \l_xtemplate_tmp_tl
+ \use:c { xtemplate_store_value_ \l_xtemplate_keytype_tl :n } {#2}
+ }
+\cs_generate_variant:Nn \xtemplate_parse_values_elt_aux:nn { o }
+\cs_new_protected:Npn \xtemplate_set_template_eq:nn #1#2
+ {
+ \xtemplate_recover_defaults:n {#2}
+ \xtemplate_store_defaults:n {#1}
+ \xtemplate_recover_keytypes:n {#2}
+ \xtemplate_store_keytypes:n {#1}
+ \xtemplate_recover_vars:n {#2}
+ \xtemplate_store_vars:n {#1}
+ \cs_gset_eq:cc { \c_xtemplate_code_root_tl #1 }
+ { \c_xtemplate_code_root_tl #2 }
+ }
+\cs_new_protected:Npn \xtemplate_declare_instance:nnnnn #1#2#3#4#5
+ {
+ \xtemplate_execute_if_code_exist:nnT {#1} {#2}
+ {
+ \xtemplate_recover_defaults:n { #1 / #2 }
+ \xtemplate_recover_vars:n { #1 / #2 }
+ \xtemplate_declare_instance_aux:nnnnn {#1} {#2} {#3} {#4} {#5}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_declare_instance_aux:nnnnn #1#2#3#4#5
+ {
+ \bool_set_false:N \l_xtemplate_error_bool
+ \xtemplate_parse_values:nn { #1 / #2 } {#5}
+ \bool_if:NF \l_xtemplate_error_bool
+ {
+ \prop_put:Nnn \l_xtemplate_values_prop { from~template } {#2}
+ \xtemplate_store_values:n { #1 / #3 / #4 }
+ \xtemplate_convert_to_assignments:
+ \cs_set_protected:cpx { \c_xtemplate_instances_root_tl #1 / #3 / #4 }
+ {
+ \exp_not:N \xtemplate_assignments_push:n
+ { \exp_not:o \l_xtemplate_assignments_tl }
+ \exp_not:c { \c_xtemplate_code_root_tl #1 / #2 }
+ }
+ \xtemplate_if_instance_exist:nnnF {#1} { } {#4}
+ {
+ \cs_set_eq:cc
+ { \c_xtemplate_instances_root_tl #1 / / #4 }
+ { \c_xtemplate_instances_root_tl #1 / #3 / #4 }
+ }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_edit_instance:nnnn #1#2#3
+ {
+ \xtemplate_if_instance_exist:nnnTF {#1} {#2} {#3}
+ {
+ \xtemplate_recover_values:n { #1 / #2 / #3 }
+ \prop_get:NnN \l_xtemplate_values_prop { from~template }
+ \l_xtemplate_tmp_tl
+ \xtemplate_edit_instance_aux:nonnn {#1} \l_xtemplate_tmp_tl
+ {#2} {#3}
+ }
+ {
+ \msg_error:nnxx { xtemplate } { unknown-instance }
+ {#1} {#3}
+ }
+ }
+\cs_new_protected:Npn \xtemplate_edit_instance_aux:nnnnn #1#2
+ {
+ \xtemplate_recover_vars:n { #1 / #2 }
+ \xtemplate_declare_instance_aux:nnnnn {#1} {#2}
+ }
+\cs_generate_variant:Nn \xtemplate_edit_instance_aux:nnnnn { no }
+\cs_new_protected_nopar:Npn \xtemplate_convert_to_assignments:
+ {
+ \tl_clear:N \l_xtemplate_assignments_tl
+ \seq_map_function:NN \l_xtemplate_key_order_seq
+ \xtemplate_convert_to_assignments_aux:n
+ }
+\cs_new_protected:Npn \xtemplate_convert_to_assignments_aux:n #1
+ {
+ \prop_get:NnN \l_xtemplate_keytypes_prop {#1} \l_xtemplate_tmp_tl
+ \xtemplate_convert_to_assignments_aux:no {#1} \l_xtemplate_tmp_tl
+ }
+\cs_new_protected:Npn \xtemplate_convert_to_assignments_aux:nn #1#2
+ {
+ \prop_if_in:NnT \l_xtemplate_values_prop {#1}
+ {
+ \prop_if_in:NnTF \l_xtemplate_vars_prop {#1}
+ {
+ \prop_get:NnN \l_xtemplate_values_prop {#1} \l_xtemplate_value_tl
+ \prop_get:NnN \l_xtemplate_vars_prop {#1} \l_xtemplate_var_tl
+ \xtemplate_split_keytype_arg:n {#2}
+ \str_if_eq:onF \l_xtemplate_keytype_tl { choice }
+ {
+ \str_if_eq:onF \l_xtemplate_keytype_tl { code }
+ { \xtemplate_find_global: }
+ }
+ \tl_set:Nn \l_xtemplate_key_name_tl {#1}
+ \use:c { xtemplate_assign_ \l_xtemplate_keytype_tl : }
+ }
+ { \msg_error:nnx { xtemplate } { unknown-attribute } {#1} }
+ }
+ }
+\cs_generate_variant:Nn \xtemplate_convert_to_assignments_aux:nn { no }
+\cs_new_protected_nopar:Npn \xtemplate_find_global:
+ {
+ \bool_set_false:N \l_xtemplate_global_bool
+ \tl_if_in:onT \l_xtemplate_var_tl { global }
+ {
+ \exp_after:wN \xtemplate_find_global_aux:w \l_xtemplate_var_tl \q_stop
+ }
+ }
+\cs_new_protected:Npn \xtemplate_find_global_aux:w #1 global #2 \q_stop
+ {
+ \tl_set:Nn \l_xtemplate_var_tl {#2}
+ \bool_set_true:N \l_xtemplate_global_bool
+ }
+\cs_new_protected:Npn \xtemplate_use_template:nnn #1#2#3
+ {
+ \xtemplate_execute_if_code_exist:nnT {#1} {#2}
+ {
+ \xtemplate_recover_defaults:n { #1 / #2 }
+ \xtemplate_recover_vars:n { #1 / #2 }
+ \xtemplate_parse_values:nn { #1 / #2 } {#3}
+ \xtemplate_convert_to_assignments:
+ \use:c { \c_xtemplate_code_root_tl #1 / #2 }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_boolean:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_boolean_aux:n { bool_gset } }
+ { \xtemplate_assign_boolean_aux:n { bool_set } }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_boolean_aux:n #1
+ {
+ \xtemplate_if_key_value:oT \l_xtemplate_value_tl
+ { \xtemplate_key_to_value: }
+ \tl_put_left:Nx \l_xtemplate_assignments_tl
+ {
+ \exp_not:c { #1 _ \l_xtemplate_value_tl :N }
+ \exp_not:o \l_xtemplate_var_tl
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_choice:
+ {
+ \tl_set:Nx \l_xtemplate_tmp_tl
+ { \l_xtemplate_key_name_tl \c_space_tl \l_xtemplate_value_tl }
+ \prop_if_in:NoTF \l_xtemplate_vars_prop \l_xtemplate_tmp_tl
+ { \xtemplate_assign_choice_aux:o \l_xtemplate_tmp_tl }
+ {
+ \tl_set:Nx \l_xtemplate_tmp_tl
+ { \l_xtemplate_key_name_tl \c_space_tl unknown }
+ \prop_if_in:NoTF \l_xtemplate_vars_prop \l_xtemplate_tmp_tl
+ { \xtemplate_assign_choice_aux:o \l_xtemplate_tmp_tl }
+ {
+ \prop_get:NoN \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl
+ \l_xtemplate_tmp_tl
+ \xtemplate_split_keytype_arg:o \l_xtemplate_tmp_tl
+ \msg_error:nnxxx { xtemplate } { unknown-choice }
+ { \l_xtemplate_key_name_tl } { \l_xtemplate_value_tl }
+ { \l_xtemplate_keytype_arg_tl }
+ }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_assign_choice_aux:n #1
+ {
+ \prop_get:NnN \l_xtemplate_vars_prop {#1} \l_xtemplate_tmp_tl
+ \tl_put_right:No \l_xtemplate_assignments_tl \l_xtemplate_tmp_tl
+ }
+\cs_generate_variant:Nn \xtemplate_assign_choice_aux:n { o }
+\cs_new_protected_nopar:Npn \xtemplate_assign_code:
+ {
+ \tl_put_left:Nx \l_xtemplate_assignments_tl
+ {
+ \cs_set_protected:Npn \xtemplate_assign_code:n \exp_not:n {##1}
+ { \exp_not:o \l_xtemplate_var_tl }
+ \xtemplate_assign_code:n { \exp_not:o \l_xtemplate_value_tl }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_assign_code:n #1 { }
+\cs_new_protected_nopar:Npn \xtemplate_assign_function:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_function_aux:N \cs_gset:Npn }
+ { \xtemplate_assign_function_aux:N \cs_set:Npn }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_function_aux:N #1
+ {
+ \tl_put_left:Nx \l_xtemplate_assignments_tl
+ {
+ \cs_generate_from_arg_count:NNnn
+ \exp_not:o \l_xtemplate_var_tl
+ \exp_not:N #1
+ { \exp_not:o \l_xtemplate_keytype_arg_tl }
+ { \exp_not:o \l_xtemplate_value_tl }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_instance:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_instance_aux:N \cs_gset_protected:Npn }
+ { \xtemplate_assign_instance_aux:N \cs_set_protected:Npn }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_instance_aux:N #1
+ {
+ \tl_put_left:Nx \l_xtemplate_assignments_tl
+ {
+ \exp_not:N #1 \exp_not:o \l_xtemplate_var_tl
+ {
+ \xtemplate_use_instance:nn
+ { \exp_not:o \l_xtemplate_keytype_arg_tl }
+ { \exp_not:o \l_xtemplate_value_tl }
+ }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_integer:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_variable:N \int_gset:Nn }
+ { \xtemplate_assign_variable:N \int_set:Nn }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_length:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_variable:N \dim_gset:Nn }
+ { \xtemplate_assign_variable:N \dim_set:Nn }
+}
+\cs_new_protected_nopar:Npn \xtemplate_assign_muskip:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_variable:N \muskip_gset:Nn }
+ { \xtemplate_assign_variable:N \muskip_set:Nn }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_real:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_variable:N \fp_gset:Nn }
+ { \xtemplate_assign_variable:N \fp_set:Nn }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_skip:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_variable:N \skip_gset:Nn }
+ { \xtemplate_assign_variable:N \skip_set:Nn }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_tokenlist:
+ {
+ \bool_if:NTF \l_xtemplate_global_bool
+ { \xtemplate_assign_tokenlist_aux:N \tl_gset:Nn }
+ { \xtemplate_assign_tokenlist_aux:N \tl_set:Nn }
+ }
+\cs_new_eq:NN \xtemplate_assign_commalist: \xtemplate_assign_tokenlist:
+\cs_new_protected_nopar:Npn \xtemplate_assign_tokenlist_aux:N #1
+ {
+ \xtemplate_if_key_value:oT \l_xtemplate_value_tl
+ { \xtemplate_key_to_value: }
+ \tl_put_left:Nx \l_xtemplate_assignments_tl
+ {
+ #1 \exp_not:o \l_xtemplate_var_tl
+ { \exp_not:o \l_xtemplate_value_tl }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_assign_variable:N #1
+ {
+ \xtemplate_if_key_value:oT \l_xtemplate_value_tl
+ { \xtemplate_key_to_value: }
+ \tl_put_left:Nx \l_xtemplate_assignments_tl
+ {
+ #1 \exp_not:o \l_xtemplate_var_tl
+ { \exp_not:o \l_xtemplate_value_tl }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_key_to_value:
+ { \exp_after:wN \xtemplate_key_to_value_aux:w \l_xtemplate_value_tl }
+\cs_new_protected:Npn \xtemplate_key_to_value_aux:w \KeyValue #1
+ {
+ \tl_set:Nx \l_xtemplate_tmp_tl { \tl_to_str:n {#1} }
+ \tl_remove_all:Nn \l_xtemplate_key_name_tl { ~ }
+ \prop_if_in:NoTF \l_xtemplate_vars_prop \l_xtemplate_tmp_tl
+ {
+ \prop_get:NoN \l_xtemplate_vars_prop \l_xtemplate_tmp_tl
+ \l_xtemplate_value_tl
+ }
+ {
+ \msg_error:nnx { xtemplate } { unknown-attribute }
+ { \l_xtemplate_tmp_tl }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_use_instance:nn #1#2
+ {
+ \xtemplate_if_use_template:nTF {#2}
+ { \xtemplate_use_instance_aux:nNnnn {#1} #2 }
+ { \xtemplate_use_instance_aux:nn {#1} {#2} }
+ }
+\cs_new_protected:Npn \xtemplate_use_instance_aux:nNnnn #1#2#3#4#5
+ {
+ \str_if_eq:nnTF {#1} {#3}
+ { \xtemplate_use_template:nnn {#3} {#4} {#5} }
+ { \msg_error:nnxx { xtemplate } { type-mismatch } {#1} {#3} }
+}
+\cs_new_protected:Npn \xtemplate_use_instance_aux:nn #1#2
+ {
+ \xtemplate_get_collection:n {#1}
+ \xtemplate_if_instance_exist:nnnTF
+ {#1} { \l_xtemplate_collection_tl } {#2}
+ {
+ \use:c
+ {
+ \c_xtemplate_instances_root_tl #1 /
+ \l_xtemplate_collection_tl / #2
+ }
+ }
+ {
+ \xtemplate_if_instance_exist:nnnTF {#1} { } {#2}
+ { \use:c { \c_xtemplate_instances_root_tl #1 / / #2 } }
+ {
+ \msg_error:nnxx { xtemplate } { unknown-instance }
+ {#1} {#2}
+ }
+ }
+ }
+\cs_new_protected:Npn \xtemplate_use_collection:nn #1#2
+ { \prop_put:Nnn \l_xtemplate_collections_prop {#1} {#2} }
+\cs_new_protected:Npn \xtemplate_get_collection:n #1
+ {
+ \prop_if_in:NnTF \l_xtemplate_collections_prop {#1}
+ {
+ \prop_get:NnN \l_xtemplate_collections_prop {#1}
+ \l_xtemplate_collection_tl
+ }
+ { \tl_clear:N \l_xtemplate_collection_tl }
+ }
+\cs_new_nopar:Npn \xtemplate_assignments_pop: { \l_xtemplate_assignments_tl }
+\cs_new_protected:Npn \xtemplate_assignments_push:n #1
+ { \tl_set:Nn \l_xtemplate_assignments_tl {#1} }
+\cs_new_protected_nopar:Npn \xtemplate_show_code:nn #1#2
+ { \cs_show:c { \c_xtemplate_code_root_tl #1 / #2 } }
+\cs_new_protected_nopar:Npn \xtemplate_show_defaults:nn #1#2
+ {
+ \xtemplate_if_keys_exist:nnT {#1} {#2}
+ {
+ \xtemplate_recover_defaults:n { #1 / #2 }
+ \xtemplate_show:Nnnn \l_xtemplate_values_prop
+ {#1} {#2} { default~values }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_show_keytypes:nn #1#2
+ {
+ \xtemplate_if_keys_exist:nnT {#1} {#2}
+ {
+ \xtemplate_recover_keytypes:n { #1 / #2 }
+ \xtemplate_show:Nnnn \l_xtemplate_keytypes_prop
+ {#1} {#2} { interface }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_show_vars:nn #1#2
+ {
+ \xtemplate_execute_if_code_exist:nnT {#1} {#2}
+ {
+ \xtemplate_recover_vars:n { #1 / #2 }
+ \xtemplate_show:Nnnn \l_xtemplate_vars_prop
+ {#1} {#2} { variable~mapping }
+ }
+ }
+\cs_new_protected_nopar:Npn \xtemplate_show:Nnnn #1#2#3#4
+ {
+ \prop_if_empty:NTF #1
+ {
+ \iow_term:x { Template~'#3'~of~object~type~'#2'~has~no~#4 . }
+ \tl_show:n { }
+ }
+ {
+ \iow_term:x { Template~'#3'~of~object~type~'#2'~has~ #4 : }
+ \tl_set:Nx \l_prop_show_tl
+ { \prop_map_function:NN #1 \xtemplate_show_aux:nn }
+ \etex_showtokens:D \exp_after:wN \exp_after:wN \exp_after:wN
+ { \exp_after:wN \prop_show_aux:w \l_prop_show_tl }
+ }
+}
+\cs_new:Npn \xtemplate_show_aux:nn #1#2
+ {
+ \iow_newline: > \c_space_tl \c_space_tl
+ #1
+ \c_space_tl \c_space_tl => \c_space_tl \c_space_tl
+ \exp_not:n {#2}
+ }
+\cs_new_protected_nopar:Npn \xtemplate_show_values:nnn #1#2#3
+ {
+ \xtemplate_if_instance_exist:nnnT {#1} {#2} {#3}
+ {
+ \xtemplate_recover_values:n { #1 / #2 / #3 }
+ \prop_if_empty:NTF \l_xtemplate_values_prop
+ {
+ \iow_term:x
+ {
+ \tl_if_empty:nTF {#2}
+ { Instance~'#3'~ }
+ { Collection instance~'#3'~(from~collection~'#2')~ }
+ of~object~type~'#1'~has~no~values.
+ }
+ \tl_show:n { }
+ }
+ {
+ \prop_pop:NnN \l_xtemplate_values_prop { from~template }
+ \l_xtemplate_tmp_tl
+ \iow_term:x
+ {
+ \tl_if_empty:nTF {#2}
+ { Instance~'#3'~ }
+ { Collection instance~'#3'~(from~collection~'#2')~ }
+ of~object~type~'#1'
+ \quark_if_no_value:NF \l_xtemplate_tmp_tl
+ { ~(from~template~' \l_xtemplate_tmp_tl ')~ }
+ has~values:
+ }
+ \tl_set:Nx \l_prop_show_tl
+ {
+ \prop_map_function:NN \l_xtemplate_values_prop
+ \xtemplate_show_aux:nn
+ }
+ \etex_showtokens:D \exp_after:wN \exp_after:wN \exp_after:wN
+ { \exp_after:wN \prop_show_aux:w \l_prop_show_tl }
+ }
+ }
+ }
+\msg_new:nnnn { xtemplate } { argument-number-mismatch }
+ { Object~type~'#1'~takes~#2~argument(s). }
+ {
+ \c_msg_coding_error_text_tl
+ Objects~of~type~'#1'~require~#2~argument(s).\\
+ You~have~tried~to~make~a~template~for~'#1'~
+ with~#3~argument(s),~which~is~not~possible:~
+ the~number~of~arguments~must~agree.
+ }
+\msg_new:nnnn { xtemplate } { bad-number-of-arguments }
+ { Bad~number~of~arguments~for~object~type~'#1'. }
+ {
+ \c_msg_coding_error_text_tl
+ An~object~may~accept~between~0~and~9~arguments.\\
+ You~asked~to~use~#2~arguments:~this~is~not~supported.
+ }
+\msg_new:nnnn { xtemplate } { bad-variable }
+ { Incorrect~variable~description. }
+ {
+ The~argument~'#1'~is~not~of~the~form \\
+ ~~'<variable>'\\
+ ~or~\\
+ ~~'global~<variable>'.\\
+ It~must~be~given~in~one~of~these~formats~to~be~used~in~a~template.
+ }
+\msg_new:nnnn { xtemplate } { choice-not-implemented }
+ { The~choice~'#1'~has~no~implementation. }
+ {
+ Each~choice~listed~in~the~interface~for~a~template~must~
+ have~an~implementation.
+ }
+\msg_new:nnnn { xtemplate } { choice-no-code }
+ { The~choice~'#1'~requires~implementation~details. }
+ {
+ \c_msg_coding_error_text_tl
+ When~creating~template~code~using~\DeclareTemplateCode,~
+ each~choice~name~must~have~an~associated~implementation.\\
+ This~should~be~given~after~a~'='~sign:~LaTeX~did~not~find~one.
+ }
+\msg_new:nnnn { xtemplate } { duplicate-key-interface }
+ { Key~'#1'~appears~twice~in~interface~definition~\msg_line_context:. }
+ {
+ \c_msg_coding_error_text_tl
+ Each~key~can~only~have~one~interface~declared~in~a~template.\\
+ LaTeX~found~two~interfaces~for~'#1'.
+ }
+\msg_new:nnnn { xtemplate } { keytype-requires-argument }
+ { The~key~type~'#1'~requires~an~argument~\msg_line_context:. }
+ {
+ You~should~have~put:\\
+ \ \ <key-name>~:~#1~{~<argument>~} \\
+ but~LaTeX~did~not~find~an~<argument>.
+ }
+\msg_new:nnnn { xtemplate } { invalid-keytype }
+ { The~key~'#1'~is~missing~a~key-type~\msg_line_context:. }
+ {
+ \c_msg_coding_error_text_tl
+ Each~key~in~a~template~requires~a~key-type,~given~in~the~form:\\
+ \ \ <key>~:~<key-type>\\
+ LaTeX~could~not~find~a~<key-type>~in~your~input.
+ }
+\msg_new:nnnn { xtemplate } { key-no-value }
+ { The~key~'#1'~has~no~value~\msg_line_context:. }
+ {
+ \c_msg_coding_error_text_tl
+ When~creating~an~instance~of~a~template~
+ every~key~listed~must~include~a~value:\\
+ \ \ <key>~=~<value>
+ }
+\msg_new:nnnn { xtemplate } { key-no-variable }
+ { The~key~'#1'~requires~implementation~details~\msg_line_context:. }
+ {
+ \c_msg_coding_error_text_tl
+ When~creating~template~code~using~\DeclareTemplateCode,~
+ each~key~name~must~have~an~associated~implementation.\\
+ This~should~be~given~after~a~'='~sign:~LaTeX~did~not~find~one.
+ }
+\msg_new:nnnn { xtemplate } { key-not-implemented }
+ { Key~'#1'~has~no~implementation~\msg_line_context:. }
+ {
+ \c_msg_coding_error_text_tl
+ The~definition~of~key~implementations~for~template~'#2'~
+ of~object~type~'#3'~does~not~include~any~details~for~key~'#1'.\\
+ The~key~was~declared~in~the~interface~definition,~
+ and~so~an~implementation~is~required.
+ }
+\msg_new:nnnn { xtemplate } { missing-keytype }
+ { The~key~'#1'~is missing~a~key-type~\msg_line_context:. }
+ {
+ \c_msg_coding_error_text_tl
+ Key~interface~definitions~should~be~of~the~form\\
+ \ \ #1~:~<key-type>\\
+ but~LaTeX~could~not~find~a~<key-type>.
+ }
+\msg_new:nnnn { xtemplate } { no-template-code }
+ {
+ The~template~'#2'~of~type~'#1'~is~unknown~
+ or~has~no~implementation.
+ }
+ {
+ \c_msg_coding_error_text_tl
+ There~is~no~code~available~for~the~template~name~given.\\
+ This~should~be~given~using~\DeclareTemplateCode.
+ }
+\msg_new:nnnn { xtemplate } { object-type-mismatch }
+ { Object~types~'#1'~and~'#2'~do~not~agree. }
+ {
+ You~are~trying~to~use~a~template~directly~with~\UseInstance
+ (or~a~similar~function),~but~the~object~types~do~not~match.
+ }
+\msg_new:nnnn { xtemplate } { unknown-attribute }
+ { The~template~attribute~'#1'~is~unknown. }
+ {
+ There~is~a~definition~in~the~current~template~reading\\
+ \ \ \token_to_str:N \KeyValue {~#1~} \\
+ but~there~is~no~key~called~'#1'.
+ }
+\msg_new:nnnn { xtemplate } { unknown-choice }
+ { The~choice~'#2'~was~not~declared~for~key~'#1'. }
+ {
+ The~key~'#1'~takes~a~fixed~list~of~choices~
+ and~this~list~does~not~include~'#2'.
+ }
+\msg_new:nnnn { xtemplate } { unknown-default-choice }
+ { The~default~choice~'#2'~was~not~declared~for~key~'#1'. }
+ {
+ The~key~'#1'~takes~a~fixed~list~of~choices~
+ and~this~list~does~not~include~'#2'.
+ }
+\msg_new:nnnn { xtemplate } { unknown-instance }
+ { The~instance~'#2'~of~type~'#1'~is~unknown. }
+ {
+ You~have~asked~to~use~an~instance~'#2',~
+ but~this~has~not~been~created.
+ }
+\msg_new:nnnn { xtemplate } { unknown-key }
+ { Unknown~template~key~'#1'. }
+ {
+ \c_msg_coding_error_text_tl
+ The~key~'#1'~was~not~declared~in~the~interface~
+ for~the~current~template.
+ }
+\msg_new:nnnn { xtemplate } { unknown-keytype }
+ { The~key-type~'#1'~is~unknown. }
+ {
+ \c_msg_coding_error_text_tl
+ Valid~key-types~are:\\
+ -~boolean;\\
+ -~choice;\\
+ -~code;\\
+ -~commalist;\\
+ -~function;\\
+ -~instance;\\
+ -~integer;\\
+ -~length;\\
+ -~muskip;\\
+ -~real;\\
+ -~skip;\\
+ -~tokenlist.
+ }
+\msg_new:nnnn { xtemplate } { unknown-object-type }
+ { The~object~type~'#1'~is~unknown. }
+ {
+ \c_msg_coding_error_text_tl
+ An~object~type~needs~to~be~declared~with~\DeclareObjectType
+ prior~to~using~it.
+ }
+\msg_new:nnnn { xtemplate } { unknown-template }
+ { The~template~'#2'~of~type~'#1'~is~unknown. }
+ {
+ No~interface~has~been~declared~for~a~template~
+ '#2'~of~object~type~'#1'.
+ }
+\msg_new:nnnn { xtemplate } { variable-not-declared }
+ { The~variable~'#1'~has~not~been~declared. }
+ {
+ Before~declaring~an~instance,~all~of~the~required~variables~
+ used~in~template~keys~must~be~created.
+ }
+\msg_new:nnn { xtemplate } { declare-object-type }
+ { Declaring~object~type~'#1'~taking~#2~argument(s)~\msg_line_context:. }
+\msg_new:nnn { xtemplate } { declare-template-code }
+ { Declaring~code~for~template~'#2'~of~object~type'#1'~\msg_line_context:. }
+\msg_new:nnn { xtemplate } { declare-template-interface }
+ {
+ Declaring~interface~for~template~'#2'~of~object~type~'#1'~
+ \msg_line_context:.
+ }
+\cs_new_protected_nopar:Npn \DeclareObjectType #1#2
+ { \xtemplate_declare_object_type:nn {#1} {#2} }
+\cs_new_protected:Npn \DeclareTemplateInterface #1#2#3#4
+ { \xtemplate_declare_template_keys:nnnn {#1} {#2} {#3} {#4} }
+\cs_new_protected:Npn \DeclareTemplateCode #1#2#3#4#5
+ { \xtemplate_declare_template_code:nnnnn {#1} {#2} {#3} {#4} {#5} }
+\cs_new_protected:Npn \DeclareRestrictedTemplate #1#2#3#4
+ { \xtemplate_declare_restricted:nnnn {#1} {#2} {#3} {#4} }
+\cs_new_protected:Npn \DeclareInstance #1#2#3#4
+ { \xtemplate_declare_instance:nnnnn {#1} {#3} { } {#2} {#4} }
+\cs_new_protected:Npn \DeclareCollectionInstance #1#2#3#4#5
+ { \xtemplate_declare_instance:nnnnn {#2} {#4} {#1} {#3} {#5} }
+\cs_new_protected:Npn \EditTemplateDefaults #1#2#3
+ { \xtemplate_edit_defaults:nnn {#1} {#2} {#3} }
+\cs_new_protected:Npn \EditInstance #1#2#3
+ { \xtemplate_edit_instance:nnnn {#1} { } {#2} {#3} }
+\cs_new_protected:Npn \EditCollectionInstance #1#2#3#4
+ { \xtemplate_edit_instance:nnnn {#2} {#1} {#3} {#4} }
+\cs_new_protected_nopar:Npn \UseTemplate #1#2#3
+ { \xtemplate_use_template:nnn {#1} {#2} {#3} }
+\cs_new_protected_nopar:Npn \UseInstance #1#2
+ { \xtemplate_use_instance:nn {#1} {#2} }
+\cs_new_protected_nopar:Npn \UseCollection #1#2
+ { \xtemplate_use_collection:nn {#1} {#2} }
+\cs_new_protected_nopar:Npn \ShowTemplateCode #1#2
+ { \xtemplate_show_code:nn {#1} {#2} }
+\cs_new_protected_nopar:Npn \ShowTemplateDefaults #1#2
+ { \xtemplate_show_defaults:nn {#1} {#2} }
+\cs_new_protected_nopar:Npn \ShowTemplateInterface #1#2
+ { \xtemplate_show_keytypes:nn {#1} {#2} }
+\cs_new_protected_nopar:Npn \ShowTemplateVariables #1#2
+ { \xtemplate_show_vars:nn {#1} {#2} }
+\cs_new_protected_nopar:Npn \ShowInstanceValues #1#2
+ { \xtemplate_show_values:nnn {#1} { } {#2} }
+\cs_new_protected_nopar:Npn \ShowCollectionInstanceValues #1#2#3
+ { \xtemplate_show_values:nnn {#1} {#2} {#3} }
+\cs_new_nopar:Npn \IfInstanceExistTF #1#2
+ { \xtemplate_if_instance_exist:nnnTF {#1} { } {#2} }
+\cs_new_nopar:Npn \IfInstanceExistT #1#2
+ { \xtemplate_if_instance_exist:nnnT {#1} { } {#2} }
+\cs_new_nopar:Npn \IfInstanceExistF #1#2
+ { \xtemplate_if_instance_exist:nnnF {#1} { } {#2} }
+\cs_new_protected:Npn \EvaluateNow #1 {#1}
+\cs_new_protected:Npn \KeyValue #1 {#1}
+\cs_new_protected_nopar:Npn \AssignTemplateKeys
+ { \xtemplate_assignments_pop: }
+\cs_new_eq:NN \ShowTemplateKeytypes \ShowTemplateInterface
+%%
+%%
+%% End of file `xtemplate.sty'.
diff --git a/Master/tlpkg/bin/tlpkg-ctan-check b/Master/tlpkg/bin/tlpkg-ctan-check
index 27c3fad9b79..3e0750a5e88 100755
--- a/Master/tlpkg/bin/tlpkg-ctan-check
+++ b/Master/tlpkg/bin/tlpkg-ctan-check
@@ -198,7 +198,7 @@ my @TLP_working = qw(
knitting knittingpattern knuth
koma-moderncvclassic koma-script kpfonts kurier
l2picfaq l2tabu l2tabu-english l2tabu-french l2tabu-it l2tabu-spanish
- l3kernel
+ l3kernel l3packages
labbook labelcas labels lastpage
latex latex-bib-ex latex-course latex-doc-ptr latex-notes-zh-cn
latex-referenz latex-tabellen
diff --git a/Master/tlpkg/tlpsrc/collection-latexrecommended.tlpsrc b/Master/tlpkg/tlpsrc/collection-latexrecommended.tlpsrc
index 8ad7bb8bdde..517208ba64d 100644
--- a/Master/tlpkg/tlpsrc/collection-latexrecommended.tlpsrc
+++ b/Master/tlpkg/tlpsrc/collection-latexrecommended.tlpsrc
@@ -26,6 +26,7 @@ depend index
depend jknapltx
depend koma-script
depend l3kernel
+depend l3packages
depend listings
depend mdwtools
depend memoir
diff --git a/Master/tlpkg/tlpsrc/l3packages.tlpsrc b/Master/tlpkg/tlpsrc/l3packages.tlpsrc
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/Master/tlpkg/tlpsrc/l3packages.tlpsrc