summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2017-07-28 21:42:49 +0000
committerKarl Berry <karl@freefriends.org>2017-07-28 21:42:49 +0000
commitbe3a88d7e7d41e6a88a01a9c320767140e93ecd0 (patch)
tree626c86772920ed08ab8023be97eba65b8244b0cc
parent81092d86348e2ce483ff79f789764cad14eb2aa7 (diff)
knowledge (28jul17)
git-svn-id: svn://tug.org/texlive/trunk@44904 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/latex/knowledge/README.txt22
-rw-r--r--Master/texmf-dist/doc/latex/knowledge/knowledge-example.tex65
-rw-r--r--Master/texmf-dist/doc/latex/knowledge/makefile73
-rw-r--r--Master/texmf-dist/source/latex/knowledge/all.ins55
-rw-r--r--Master/texmf-dist/source/latex/knowledge/knowledge-configuration.dtx252
-rw-r--r--Master/texmf-dist/source/latex/knowledge/knowledge-utils.dtx1185
-rw-r--r--Master/texmf-dist/source/latex/knowledge/knowledge.dtx5569
-rw-r--r--Master/texmf-dist/tex/latex/knowledge/knowledge.sty853
8 files changed, 7761 insertions, 313 deletions
diff --git a/Master/texmf-dist/doc/latex/knowledge/README.txt b/Master/texmf-dist/doc/latex/knowledge/README.txt
index 16cb728d87e..e6217ecdcd9 100644
--- a/Master/texmf-dist/doc/latex/knowledge/README.txt
+++ b/Master/texmf-dist/doc/latex/knowledge/README.txt
@@ -1,8 +1,8 @@
This directory contains the package
name: knowledge.sty
- version: 1.0
- date: 2017-06-09
+ version: 1.04
+ date: 2017-07-28
license: LaTeX Project Public License version 1.2 or above
author: Thomas Colcombet
@@ -18,9 +18,19 @@ references of a concept linked to its introduction. It also offers
simple notations.
-Content of the file knowledge.zip:
+Content of the file knowledge-sources.zip:
- README.txt: this file
- - knowledge.sty: the package file
- - knowledge.pdf: a documentation
- - knowledge-example.tex: a minimalist example
+ - knowledge.sty: the package file (generated)
+ - knowledge.pdf: the user documentation (generated)
+ - makefile: the makefile. Use 'make all'
+ to generate knowledge.sty and knowledge.pdf
+ - knowledge.dtx: the main file
+ (compiling it directly yields a developper version of the
+ documentation that contains the code. Use 'make all'
+ for the regular version)
+ - all.ins: file generating knowledge.sty when compiled (docstrip)
+ - knowledge-configuration.dtx
+ - knowledge-utils.dtx
+ - knowledge-example.tex: an example file
+
diff --git a/Master/texmf-dist/doc/latex/knowledge/knowledge-example.tex b/Master/texmf-dist/doc/latex/knowledge/knowledge-example.tex
index 878036ef03d..842d6fbd0e2 100644
--- a/Master/texmf-dist/doc/latex/knowledge/knowledge-example.tex
+++ b/Master/texmf-dist/doc/latex/knowledge/knowledge-example.tex
@@ -15,15 +15,18 @@
% The package 'knowledge' has now to be loaded.
% The options
% 'paper', 'electronic' or 'composition' (default)
-% can be used. These activates different rendering styles.
-% - paper produce a paper to be printed
-% - electronic highlights links using color
-% - composition (or default) highlights missing knowledges as
-% well as other information. It should always be used but when the paper is ready.
+% can be used. These activates different rendering styles:
+% - 'paper' produce a paper to be printed:
+% text in black and white
+% - 'electronic' highlights links using colors:
+% for being read on an electronic device
+% - 'composition' (or default) highlights missing knowledges as
+% well as agives other pieces of information. It should always
+% be used but when the paper is ready.
%
-\usepackage{knowledge} % default
-%\usepackage[electronic]{knowledge} % final version to be read electronically
-%\usepackage[paper]{knowledge} % final version in black and white for printing
+\usepackage[scope]{knowledge} % default
+%\usepackage[scope,electronic]{knowledge} % final version to be read electronically
+%\usepackage[scope,paper]{knowledge} % final version in black and white for printing
%
% The 'notion' configuration is commonly used for scientific papers.
@@ -34,10 +37,12 @@
-% The following
-% It is convenient now to provide a list of \knowledge in the preamble:
+% It is convenient now to provide a list of \knowledge in the preamble
+% (or in an external file) according to the following syntax:
+%
% \knowledge{knowledge text}[synonym 1|synonym 2|...]{directives}
-% Most common in a science paper are 'notion' knowledges that
+%
+% The most common directive in a science paper is 'notion': knowledges that
% are used in the body with \intro and \kl commands/""...""" and "..." notatation:
\knowledge{anchor point}[anchor points|Anchor points]{notion}
\knowledge{diagnose file}{notion}
@@ -53,7 +58,21 @@
% Some other configurations are possible, such as:
\knowledge{LaTeX}[latex|LATEX|Latex]{url={https://fr.wikipedia.org/wiki/LaTeX}, text=\LaTeX}
-\knowledge{pdflatex}{url={https://en.wikipedia.org/wiki/PdfTeX}, typewriter}
+
+% Configurations can also be made contextual. For instance, the
+% following knowledge is only accessible directly in the introduction.
+% It can nevertheless be used from elswhere using "pdflatex@@section:introduction",
+\knowledge{pdflatex}{scope={section:example},url={https://en.wikipedia.org/wiki/PdfTeX}, typewriter}
+% or \kl(section:introduction){pdflatex}. See 'scoping' in the documetation for more details.
+
+% Scoping can be used in the preamble. For instance:
+\begin{scope}\label{package}
+ \knowledge{knowledge}{link=knowledge package,link scope}
+\end{scope}
+
+
+
+
\title{Mini example for the \texttt{knowledge} package}
@@ -61,9 +80,23 @@
\begin{document}
\maketitle
\begin{abstract}
-\AP This document provides an elementary example of the ""knowledge package"" for "latex".
+\AP This document provides an elementary example of the "knowledge package" for "latex".
\end{abstract}
+\section{Introduction}
+\label{section:introduction}
+
+The package ""knowledge@@package"" is a package for "latex" that helps associating information to terms. This can be used for:
+\begin{itemize}
+\item managing external urls, for instance separating the file containing the addresses from their use,
+\item managing internal references's such as linking every use of a concept to the place of its introduction (in particular avoiding the use of labels),
+\item managing the index in a centralized way,
+\item replacing some macros for configuring the display.
+\end{itemize}
+Primarily, the goal of the "knowledge@@package" is for the production of scientific documents (the longer, the more interesting, such as a thesis or a book) in order to improve their readability on electronic devices. Ultimately, the goal is to produce documents that are more semantic-aware. Some capabilities (link handling the index) are not related to this purpose in particular.
+
+\section{Example running}
+\label{section:example}
Try compiling this document (two compilation phases to have proper links) using "pdflatex", and see how some notions are hyperlinked to their introduction point (some viewers make it more obvious than others by displaying a preview of the target of a link inside a document; since there is only one page in this example, this may be worth zooming in this case).
\AP When the "paper mode" is not active, links are clearly identified in blue. Try then compiling it in ""paper mode"" (an option of the "knowledge package"); it now looks like a regular paper (but the links are still there). In ""electronic mode"",
the links are still colored, but some other hints disappear like "anchor points".
@@ -89,8 +122,8 @@ The `@' symbol allows some flexibility by having a displayed text different from
\begin{quote}
\verb|\knowledge|\texttt{\{name\}[synonym1|synonym2|...]\{directives\}}
\end{quote}
-However, using undefined "knowledges" will not cause compile time errors, but be displayed as in the following `"unknown knowledge"' (i.e. in non-"paper mode" in brown, but in regular black in "paper mode" or "electronic mode"). \AP The ""diagnose file"" (that ends with a \texttt{.diagnose} extension) contains detailed information about these warnings, and should be read often when finalising the document.
+However, using undefined "knowledges" will not cause compile time errors, but be displayed as in the following `"unknown knowledge"' (i.e. in non-"paper mode" in brown, but in regular black in "paper mode" or "electronic mode"). \AP The ""diagnose file"" (that ends with a \texttt{.diagnose} extension) contains detailed information about these warnings, and should be read often when finalizing the document.
-\AP Small red corners are visible in the margin. These are called ""anchor points"", are introduced
-using the \texttt{\detokenize{\AP}}command usually at the beginning of each paragraph that introduce some concept, or even in the middle of the paragraph. The "anchor points" become invisible in "paper@paper mode" or "electronic mode".
+\AP Small red corners are visible in the margin. These are called ""anchor points"" and are introduced
+using the \texttt{\detokenize{\AP}}command, commonly at the beginning of each paragraph that introduce some concept, or even in the middle of the paragraph. The "anchor points" become invisible in "paper@paper mode" or "electronic mode".
\end{document} \ No newline at end of file
diff --git a/Master/texmf-dist/doc/latex/knowledge/makefile b/Master/texmf-dist/doc/latex/knowledge/makefile
new file mode 100644
index 00000000000..ddc1bfe8bcf
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/knowledge/makefile
@@ -0,0 +1,73 @@
+help:
+ echo "- help : this help"
+ echo "- all: produces knowledge.pdf and knowledge.sty"
+ echo "- ctan: creates the knowledge-ctan.zip file for CTAN"
+ echo "- clean"
+ echo "- knowledge.zip"
+ echo "- knowledge-sources.zip"
+ echo "- sources"
+
+all:
+knowledge.sty: knowledge.dtx knowledge-utils.dtx knowledge-configuration.dtx
+ latex all.ins
+
+
+clean:
+ make -CRegression clean
+ rm -f *.aux *.glo *.idx *.aux *.synctex.gz *.out *.toc *.kaux *.diagnose *.log
+ rm -f *.bbl *.out *.bbl *.ind *.ilg *.idx
+ rm -f knowledge.sty
+ rm -f knowledge.pdf knowledge-utils.pdf knowledge-configuration.pdf knowledge-example.pdf
+ rm -f knowledge-sources.zip knowledge-sources-complete.zip knowledge.zip
+ rm -f knowledge-ctan.zip
+
+
+ctan: knowledge-ctan.zip
+
+knowledge.pdf:knowledge.aux
+ pdflatex "\def\nocode{1} \input{knowledge.dtx}"
+ pdflatex "\def\nocode{1} \input{knowledge.dtx}"
+ pdflatex "\def\nocode{1} \input{knowledge.dtx}"
+
+
+knowledge.aux: knowledge.dtx knowledge.sty
+ pdflatex knowledge.dtx
+
+sources: clean knowledge-sources.zip knowledge-sources-complete.zip
+
+knowledge-sources-complete.zip: clean
+ \rm -f knowledge-sources-complete.zip
+ zip knowledge-sources-complete.zip *.* makefile Regression/*
+ cp knowledge-sources-complete.zip ../knowledge-sources-complete-`date +%y-%m-%d_%H:%M`.zip
+
+knowledge-ctan.zip: knowledge.pdf knowledge.sty all.ins README.txt makefile
+ rm -f knowledge-ctan.zip
+ rm -rf knowledge
+ mkdir knowledge
+ cp knowledge.pdf knowledge.sty knowledge/
+ cp knowledge.dtx knowledge-utils.dtx knowledge-configuration.dtx knowledge/
+ cp makefile all.ins knowledge-example.tex README.txt knowledge/
+ zip knowledge-ctan.zip knowledge/*
+ rm -rf knowledge
+
+
+knowledge-sources.zip: knowledge.dtx
+ rm -f knowledge-sources.zip
+ zip knowledge-sources.zip makefile knowledge.dtx knowledge-utils.dtx knowledge-configuration.dtx all.ins knowledge-example.tex README.txt
+ cp knowledge-sources.zip ../knowledge-sources-`date +%y-%m-%d_%H:%M`.zip
+
+knowledge.zip: knowledge.pdf knowledge.sty knowledge-example.tex README.txt
+ rm -f knowledge.zip
+ rm -rf knowledge
+ mkdir knowledge
+ cp knowledge.pdf knowledge.sty knowledge-example.tex README.txt knowledge/
+ zip knowledge.zip knowledge/*
+ rm -rf knowledge
+
+publish: knowledge.zip knowledge-sources.zip
+ cp knowledge.pdf ~/Travail/Web/public_html/Knowledge/
+ cp knowledge.zip ~/Travail/Web/public_html/Knowledge/knowledge--lastversion.zip
+ cp knowledge.zip ~/Travail/Web/public_html/Knowledge/knowledge-`date +%Y-%m-%d`.zip
+ cp knowledge-sources.zip ~/Travail/Web/public_html/Knowledge/knowledge-sources-`date +%Y-%m-%d`.zip
+
+
diff --git a/Master/texmf-dist/source/latex/knowledge/all.ins b/Master/texmf-dist/source/latex/knowledge/all.ins
new file mode 100644
index 00000000000..f88c9385e00
--- /dev/null
+++ b/Master/texmf-dist/source/latex/knowledge/all.ins
@@ -0,0 +1,55 @@
+%%
+%% Copyright (C) 2017 by Thomas Colcombet
+%%
+%% This file may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either
+%% version 1.2 of this license or (at your option) any later
+%% version. The latest version of this license is in:
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% and version 1.2 or later is part of all distributions of
+%% LaTeX version 1999/12/01 or later.
+%%
+\input docstrip.tex
+\keepsilent
+
+\preamble
+
+This is a generated file. Copyright (C) 2017 by Thomas Colcombet
+
+This file may be distributed and/or modified under the
+conditions of the LaTeX Project Public License, either
+version 1.2 of this license or (at your option) any later
+version. The latest version of this license is in:
+
+ http://www.latex-project.org/lppl.txt
+
+and version 1.2 or later is part of all distributions of
+LaTeX version 1999/12/01 or later.
+
+\endpreamble
+
+\askforoverwritefalse
+\generate{\file{knowledge.sty}{%
+ \from{knowledge.dtx}{head}%
+ \from{knowledge-utils.dtx}{package}%
+ \from{knowledge.dtx}{package}%
+ \from{knowledge-configuration.dtx}{package}%
+ \from{knowledge.dtx}{tail}%
+ }}%
+\obeyspaces
+\Msg{****************************************************}
+\Msg{*}
+\Msg{* To finish the installation you have to move the }
+\Msg{* following file into a directory searched by TeX:}
+\Msg{*}
+\Msg{* knowledge.sty}
+\Msg{*}
+\Msg{* To produce the documentation run the file *}
+\Msg{* knowledge.dtx through LaTeX.}
+\Msg{*}
+\Msg{****************************************************}
+
+\endbatchfile
+
diff --git a/Master/texmf-dist/source/latex/knowledge/knowledge-configuration.dtx b/Master/texmf-dist/source/latex/knowledge/knowledge-configuration.dtx
new file mode 100644
index 00000000000..da7ee25fb84
--- /dev/null
+++ b/Master/texmf-dist/source/latex/knowledge/knowledge-configuration.dtx
@@ -0,0 +1,252 @@
+% \iffalse meta-comment
+%
+% Copyright (C) 2016 by Thomas Colcombet
+% -----------------------------------
+%
+% This file may be distributed and/or modified under the
+% conditions of the LaTeX Project Public License, either version 1.2 % of this license or (at your option) any later version.
+% The latest version of this license is in:
+%
+% http://www.latex-project.org/lppl.txt
+%
+% and version 1.2 or later is part of all distributions of LaTeX
+% version 1999/12/01 or later.
+%
+% \fi
+%
+% \iffalse
+%
+%<*driver>
+\documentclass{ltxdoc}
+\usepackage[utf8]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{paralist}
+\EnableCrossrefs
+\CodelineIndex
+\RecordChanges
+
+\begin{document}
+\DocInput{knowledge-configuration.dtx}
+\end{document}
+%</driver>
+% \fi
+%
+% \CheckSum{0}
+%
+% \CharacterTable
+% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
+% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
+% Digits \0\1\2\3\4\5\6\7\8\9
+% Exclamation \! Double quote \" Hash (number) \#
+% Dollar \$ Percent \% Ampersand \&
+% Acute accent \' Left paren \( Right paren \)
+% Asterisk \* Plus \+ Comma \,
+% Minus \- Point \. Solidus \/
+% Colon \: Semicolon \; Less than \<
+% Equals \= Greater than \> Question mark \?
+% Commercial at \@ Left bracket \[ Backslash \\
+% Right bracket \] Circumflex \^ Underscore \_
+% Grave accent \` Left brace \{ Vertical bar \|
+% Right brace \} Tilde \~}
+%
+%
+% \changes{v2.0}{2016/02/26}{Initial version} %
+% \GetFileInfo{scopearticle.def} %
+% \DoNotIndex{}
+%
+%
+% \let\ifcode\iffalse
+%
+%
+% \title{The \textsf{knowledge-configuration} part of the \textsf{knowledge} package}
+% \author{Thomas Colcombet \\ \texttt{thomas.colcombet@irif.fr}}
+% \date{\today}
+% \maketitle
+%
+% \begin{abstract}
+% Some code for configuring the scope option of the package knowledge.
+% Essentially, it contains configurations for reconstructing the tree of the structure of the document. It is to be expanded when the use requires it.
+%
+% So far, it stands as a standalone file scopearticle.def. It should eventually be part of knowledge.sty, and be extra configurable (detect the style, and tries to automatically overload it).
+% \end{abstract}
+%
+% \section{Introduction}
+%
+% This package is in fact part of the code used by \texttt{knowledge} when the scope option is activated.
+% Its goal is to configure the hooks for the \texttt{article} class. It works also for similar classes.
+%
+% \StopEventually{\PrintIndex}
+%
+%
+%
+% This package patches the article class for making it compatible with
+% the scope package. Essentially, it modifies all the structure and the commands
+% that interact with the structure of an article, and weave into it the update of the
+% scope structure.
+%
+%
+% \section{Implementation}
+%
+% \subsection{Code preparation}
+% \begin{macrocode}
+\knowledge_begin_module_if:N\knowledge_option_scope_bool
+% \end{macrocode}
+%
+% \section{Main structure}
+%
+% Note that the scopes \texttt{base}, \texttt{document}, \texttt{body} and \texttt{scope} are already configured in knowledge.sty.
+%
+% \subsection{Standard sectioning command}
+%
+%
+% \begin{macrocode}
+\scope_area_set:nn
+ {part, section,subsection,subsubsection,
+ paragraph,subparagraph,subsubparagraph}
+ { category=structure,
+ autoclose = true,
+ occurrences = multiple,
+ knowledge=accepts
+ }
+\scope_area_set:nn
+ {base,document,section,subsection,subsubsection,
+ paragraph,subparagraph,subsubparagraph}
+ {knowledge=accepts}
+\scope_area_set:nn
+ {base,document}
+ {knowledge=attracts}
+\scope_area_set:nn
+ {body}
+ {knowledge=none}
+
+\scope_area_set:nn{part}{parents = {body}, forces = body }
+\scope_area_set:nn{section}{parents = {body,part}, forces = body }
+\scope_area_set:nn{subsection}{parents = section }
+\scope_area_set:nn{subsubsection}{parents = subsection }
+\scope_area_set:nn{paragraph}{parents = {document,section,subsection,subsubsection} }
+\scope_area_set:nn{subparagraph}{parents = {paragraph} }
+\scope_area_set:nn{subsubparagraph}{parents = {subparagraph} }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\scope_area_set:nn{abstract}
+ {autoclose=false,
+ occurrences=once,
+ parents={body,structure},
+ forces=body,
+ knowledge=none
+}
+% \end{macrocode}
+% \subsubsection{Overloading the commands}
+%
+% \begin{macrocode}
+\OverloadCommand\section{som}
+ {\scope_area_push:n{section}
+ \XparseArgs\SUPERsection{som}{#1}{#2}{#3}}
+\OverloadCommand\subsection{som}
+ {\scope_area_push:n{subsection}
+ \XparseArgs\SUPERsubsection{som}{#1}{#2}{#3}}
+\OverloadCommand\subsubsection{som}
+ {\scope_area_push:n{subsubsection}
+ \XparseArgs\SUPERsubsubsection{som}{#1}{#2}{#3}}
+\OverloadCommand\paragraph{som}
+ {\scope_area_push:n{paragraph}
+ \XparseArgs\SUPERparagraph{som}{#1}{#2}{#3}}
+\OverloadCommand\subparagraph{som}
+ {\scope_area_push:n{subparagraph}
+ \XparseArgs\SUPERsubparagraph{som}{#1}{#2}{#3}}
+\OverloadCommand\subsubparagraph{som}
+ {\scope_area_push:n{subsubparagraph}
+ \XparseArgs\SUPERsubsubparagraph{som}{#1}{#2}{#3}}
+% \end{macrocode}
+%
+% \subsection{Creation of new environments}
+%
+%
+%
+% \begin{macrocode}
+\KnowledgeConfigureEnvironment?
+ {theorem,lemma,proposition,fact,conjecture,problem}
+ {category=theorem-like,label=accepts}
+\KnowledgeConfigureEnvironment?
+ {remark,proof}
+ {label=accepts,knowledge=accepts}
+\KnowledgeConfigureEnvironment?
+ {center,flushleft,flushright,minipage,quotation,quote,verbatim,verse}
+ {knowledge=accepts,label=none}
+% \end{macrocode}
+%
+% Command overloading...
+% \begin{macrocode}
+\OverloadCommand\newtheorem{m}
+ {\KnowledgeConfigureEnvironment!{#1}{category=theorem-like,label=accepts}
+ \SUPERnewtheorem{#1}}
+\OverloadCommand\newenvironment{m}
+ {\KnowledgeConfigureEnvironment!{#1}{label=accepts}
+ \SUPERnewenvironment{#1}}
+\OverloadCommand\NewDocumentEnvironment{m}
+ {\KnowledgeConfigureEnvironment!{#1}{label=none}
+ \SUPERNewDocumentEnvironment{#1}}
+% \end{macrocode}
+%
+%
+% \subsection{Upgrading scope}
+%
+% \subsection{Itemizing}
+% The default code for \LaTeX{} is absolutely catastrophic.
+% In particular, trivlist is used implicitly, making impossible to
+% simply Overload the list environements.
+% Indeed, some of environments (like theorems) use trivlists and |\item|
+% for their internal display. However, one does not want this to be considered
+% as a list. Futhremore, normal lists make call to the code of trivlist too.
+% Thus we are in the situation in which trivlists have to be patched because otherwise
+% items could not guarantee the structure.
+% However, trivlist should not be treates as norm lists since these are fake lists used
+% for displaying purposes. The below code tries to patch this as cleanly as possible in order
+% to obtain a reasonable behaviour.
+% \begin{macrocode}
+\scope_area_set:nn
+ {itemize,enumerate,description}
+ {category=itemize-like}
+% {knowledge=none}
+
+\scope_area_set:nn{item}
+ {autoclose=true,
+ parents = itemize-like}
+
+
+\OverloadCommand\item{o}
+ {%\scope_categoryseq_pop_to:n{itemize-like}
+ %\scope_category_if_area_in:nnTF{trivlist}\scope_top_area_tl
+ % {}
+ % {\scope_area_push:n{item}}
+ \XparseArgs\SUPERitem{o}{#1}}
+
+%\OverloadCommand\trivlist{}
+% {\scope_area_push:n{trivlist}
+% \SUPERtrivlist}
+
+%\OverloadCommand\endtrivlist{}{
+% \SUPERendtrivlist
+% \scope_categoryseq_pop_to:n{itemize-like}
+% \exp_args:NV\tl_if_eq:nnTF\scope_top_area_tl{trivlist}
+% {\scope_area_pop:n{trivlist}}{}}
+% \end{macrocode}
+% \subsubsection{Micro areas}
+% \begin{macrocode}
+\scope_area_set:nn{emph,textit,texttt,textbf}{
+ autoclose = false,
+ occurrences = multiple,
+ forces = body
+ }
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
+\knowledge_end_module:
+% \end{macrocode}
+% \Finale
+
+
+
+
diff --git a/Master/texmf-dist/source/latex/knowledge/knowledge-utils.dtx b/Master/texmf-dist/source/latex/knowledge/knowledge-utils.dtx
new file mode 100644
index 00000000000..d0cb09aa137
--- /dev/null
+++ b/Master/texmf-dist/source/latex/knowledge/knowledge-utils.dtx
@@ -0,0 +1,1185 @@
+% \iffalse meta-comment
+%
+% Copyright (C) 2016 by Thomas Colcombet
+% -----------------------------------
+%
+% This file may be distributed and/or modified under the
+% conditions of the LaTeX Project Public License, either version 1.2 % of this license or (at your option) any later version.
+% The latest version of this license is in:
+%
+% http://www.latex-project.org/lppl.txt
+%
+% and version 1.2 or later is part of all distributions of LaTeX
+% version 1999/12/01 or later.
+%
+% \fi
+%
+% \iffalse
+%
+%<*driver>
+\documentclass{ltxdoc}
+\usepackage[utf8]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{paralist}
+\usepackage{hyperref}
+\usepackage{expl3}
+\EnableCrossrefs
+\CodelineIndex
+\RecordChanges
+
+
+\newcommand\kl[2][]{#2}
+
+\begin{document}
+\DocInput{knowledge-utils.dtx}
+\end{document}
+%</driver>
+% \fi
+%
+% \CheckSum{0}
+%
+% \CharacterTable
+% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
+% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
+% Digits \0\1\2\3\4\5\6\7\8\9
+% Exclamation \! Double quote \" Hash (number) \#
+% Dollar \$ Percent \% Ampersand \&
+% Acute accent \' Left paren \( Right paren \)
+% Asterisk \* Plus \+ Comma \,
+% Minus \- Point \. Solidus \/
+% Colon \: Semicolon \; Less than \<
+% Equals \= Greater than \> Question mark \?
+% Commercial at \@ Left bracket \[ Backslash \\
+% Right bracket \] Circumflex \^ Underscore \_
+% Grave accent \` Left brace \{ Vertical bar \|
+% Right brace \} Tilde \~}
+%
+%
+% \changes{v2.0}{2016/02/26}{Initial version} %
+% \GetFileInfo{knowledge-utils.sty} %
+% \DoNotIndex{}
+%
+% \title{The \textsf{knowledge-utils} package}
+% \author{Thomas Colcombet \\ \texttt{thomas.colcombet@irif.fr}}
+% \maketitle
+%
+% \begin{abstract}
+% This code is incorporated in the knowledge.sty file. It essentially contains a certain number of useful functions.
+%
+% This includes dealing with the kaux file (a single file which is output during the compilation, and then postprocessed for extracting information).
+% In contains some primitives for creating fields in tuples, macros for overloading other macros, and code for recreating an argument list (reversing par of the xparse syntax).
+%
+% This file needs to be cleaned and reorganize.
+% \end{abstract}
+%
+%\tableofcontents
+%
+%
+% \section{Introduction}
+%
+% The main file is knowledge.dtx.
+%
+%
+%
+%
+%
+% \section{Implementation}
+%
+% \def\cs{\ExplSyntaxOn\csARG}
+% \def\csARG#1{\ExplSyntaxOff\texttt{\detokenize{#1}}}
+%
+%\let\ifcode\iffalse
+%
+% \subsection{Code preparation}
+% \begin{macrocode}
+\usepackage{xparse}
+\usepackage{currfile}
+% \end{macrocode}
+% The interface of expl3 since Mars 2015 has changed and a small patch is required:
+% \begin{macrocode}
+\tl_if_exist:NTF
+ \c_sys_jobname_str
+ {}
+ {\tl_set_eq:Nc\c_sys_jobname_str{c_job_name_tl}}
+% \end{macrocode}
+% Some new \kl{latex3} commands:
+% \cs{cs_new_with_variants:Nnn},
+% \cs{if_mode_preamble:TF},
+% \cs{kl_hide_begin:} and \cs{kl_hide_begin:}
+% (that stand for \cs{@bsphack} and \cs{@esphack} of \kl{latex2e}).
+%
+% Creating new macros with their variants at the same time...
+% \begin{macrocode}
+\cs_new_protected:Nn\cs_new_protected_with_variants:Nnn
+ {\cs_new_protected:Nn#1{#3}
+ \cs_generate_variant:Nn#1{#2}}
+\cs_generate_variant:Nn\cs_new_protected_with_variants:Nnn{cnn}
+
+\cs_new_protected:Nn\cs_new_with_variants:Nnn
+ {\cs_new:Nn#1{#3}
+ \cs_generate_variant:Nn#1{#2}}
+\cs_generate_variant:Nn\cs_new_with_variants:Nnn{cnn}
+
+\cs_generate_variant:Nn\tl_show:n{x}
+% \end{macrocode}
+%
+% Now comes a command for simultaneously testing existence and non emptiness.
+% \begin{macrocode}
+\cs_new:Nn\tl_if_exist_ne:NTF
+ {\tl_if_exist:NTF#1{\tl_if_empty:NTF#1{#3}{#2}}{#3}}
+\cs_generate_variant:Nn\tl_if_empty:nTF{xTF}
+% \end{macrocode}
+%
+%
+% Immediate execution of code with parameters without explicit abstraction.
+%\begin{description}
+%\item \cs{kl_apply_inline:nnw} takes an argument specifier, a code with
+% arguments ($\sharp$1,\dots), and sufficiently many arguments, and executes
+% the code with arguments substituted (this is not expandable).
+%\item \cs{kl_apply_inline_variant:nnnw} does the same thing, and furthermore use a variant
+% of the code in which the arguments are executed as specified in the second argument.
+% For instance,
+%\begin{verbatim}
+%\kl_apply_inline_variant:nnnw{nn}{VV}
+% {\cs_new:Nn\wrap:n{#1##1#2}}
+% \leftdelimiter\rightdelimiter
+%\end{verbatim}
+%Define a new function \cs{wrap:n} that takes a parameter, and encloses it with the \textbf{content} of
+%\cs{leftdelimiter} and \cs{rightdelimiter}.
+%\end{description}
+%\ifcode
+% \begin{macrocode}
+\cs_new_protected:Npn\kl_apply_inline:nnw#1#2
+ {\group_begin:
+ \cs_set:cn{g_tmpa_cs:#1}
+ {\group_end:#2}
+ \use:c{g_tmpa_cs:#1}}
+
+\cs_new_protected:Npn\kl_apply_inline_variant:nnnw#1#2#3
+ {\group_begin:
+ \cs_set:cn{g_tmpa_cs:#1}
+ {\group_end:#3}
+ \exp_args:Nc
+ \cs_generate_variant:Nn{g_tmpa_cs:#1}{#2}
+ \use:c{g_tmpa_cs:#2}}
+% \end{macrocode}
+%\fi
+%
+% \begin{macrocode}
+\cs_new:Nn\mode_if_preamble:TF{#1}
+\AtBeginDocument
+ {\cs_gset:Nn\mode_if_preamble:TF{#2}}
+% \end{macrocode}
+% \begin{macrocode}
+\makeatletter
+\int_new:N\kl_sphack_int
+\cs_set_eq:NN\kl_stored_@bsphack\@bsphack
+\cs_set_eq:NN\kl_stored_@esphack\@esphack
+\cs_set:Nn\kl_hide_begin:
+ {\@bsphack
+ \cs_set_eq:NN\@bsphack\relax
+ \cs_set_eq:NN\@esphack\relax
+ \int_incr:N\kl_sphack_int}
+\cs_set:Nn\kl_hide_end:
+ {\int_decr:N\kl_sphack_int
+ \int_compare:nNnTF{\kl_sphack_int}=0
+ {\cs_set_eq:NN\@bsphack\kl_stored_@bsphack
+ \cs_set_eq:NN\@esphack\kl_stored_@esphack}{}
+ \@esphack}
+\makeatother
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\if_true:TF{#1}
+\cs_new:Nn\if_false:TF{#2}
+\cs_generate_variant:Nn\int_compare:nNnTF{cNnTF}
+\cs_generate_variant:Nn\use:nn{nx}
+% \end{macrocode}
+% The command |\cs_apply_inline:n<n's>| takes a first argument
+% with as many parameters as in |<n's>|, and apply it to them.
+% \ifcode
+% \begin{macrocode}
+\cs_new:Npn\cs_apply_inline:nn#1
+ {\cs_set:Npn\g_tmpa_cs:##1{#1}
+ \g_tmpa_cs:}
+\cs_new:Npn\cs_apply_inline:nnn#1
+ {\cs_set:Npn\g_tmpa_cs:##1##2{#1}
+ \g_tmpa_cs:}
+\cs_new:Npn\cs_apply_inline:nnnn#1
+ {\cs_set:Npn\g_tmpa_cs:##1##2##3{#1}
+ \g_tmpa_cs:}
+\cs_new:Npn\cs_apply_inline:nnnnn#1
+ {\cs_set:Npn\g_tmpa_cs:##1##2##3##4{#1}
+ \g_tmpa_cs:}
+\cs_new:Npn\cs_apply_inline:nnnnnn#1
+ {\cs_set:Npn\g_tmpa_cs:##1##2##3##4##5{#1}
+ \g_tmpa_cs:}
+\cs_new:Npn\cs_apply_inline:nnnnnnn#1
+ {\cs_set:Npn\g_tmpa_cs:##1##2##3##4##5##6{#1}
+ \g_tmpa_cs:}
+\cs_new:Npn\cs_apply_inline:nnnnnnnn#1
+ {\cs_set:Npn\g_tmpa_cs:##1##2##3##4##5##6##7{#1}
+ \g_tmpa_cs:}
+\cs_new:Npn\cs_apply_inline:nnnnnnnnn#1
+ {\cs_set:Npn\g_tmpa_cs:##1##2##3##4##5##6##7##8{#1}
+ \g_tmpa_cs:}
+\cs_new:Npn\cs_apply_inline:nnnnnnnnnn#1
+ {\cs_set:Npn\g_tmpa_cs:##1##2##3##4##5##6##7##8##9{#1}
+ \g_tmpa_cs:}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_generate_variant:Nn\cs_apply_inline:nn{nc}
+\cs_generate_variant:Nn\cs_apply_inline:nnn{ncc}
+\cs_generate_variant:Nn\cs_apply_inline:nnnn{nccc}
+\cs_generate_variant:Nn\cs_apply_inline:nnnnn{ncccc}
+\cs_generate_variant:Nn\cs_apply_inline:nnnnnn{nccccc}
+\cs_generate_variant:Nn\cs_apply_inline:nnnnnnn{ncccccc}
+\cs_generate_variant:Nn\cs_apply_inline:nnnnnnnn{nccccccc}
+\cs_generate_variant:Nn\cs_apply_inline:nnnnnnnnn{ncccccccc}
+\cs_generate_variant:Nn\cs_apply_inline:nnnnnnnnnn{nccccccccc}
+% \end{macrocode}
+%\fi
+%
+%
+% \subsection{KAux file}
+%
+% We introduce here the KAux file.
+% The principle of the KAux file is to play the role of an aux file, but at the same time it
+% has some facilities for using it with several subpackages.
+% Essentially, the code in the KAUX file is executed, and is supposed to use only functions defined by the
+% |\NewKAuxCommand| (using \texttt{xparse} syntax). Such functions do nothing by default,
+% unless explicitly activated when rereading the file.
+% At the beginning of the KAUX file, each command that may occur is declared,
+% the package that produced it is named, its arguments are provided, and its use
+% is succinctly described.
+%
+% By default, the location is stored in the KAux file, unless the writing command has a star.
+% When the KAux file is processed, the variables \cs{\kauxCurrentFile}
+% and \cs{\kauxCurrentLine} contain the filename and the line at the moment the information was processed.
+% The location can be explicitely written using \cs{\KAuwWriteLocation}.
+% Thus, by the user can decide when to write the line (at the begining of a command may be better when it has several lines).
+%
+% The file is open for writing when \cs{KAuxActivate} is called the
+% first time. So, commands may ensure that the file is activated using
+% \cs{KAuxActivate}, but this should be used after the configuration
+% is finished. So the rule is: when a package is loaded, one should never use
+% \cs{KAuxActivate}.
+% \begin{macrocode}
+\AtBeginDocument{\KAuxActivate}
+
+\NewDocumentCommand\KAuxActivate{}{
+ \cs_gset_eq:NN\KAuxActivate\relax
+ \KAuxOpen{}}
+% \end{macrocode}
+% \begin{macrocode}
+\AtEndDocument{\KAuxClose}
+% \end{macrocode}
+% \begin{macrocode}
+\iow_new:N\knowledge_kaux_iow
+
+\NewDocumentCommand\KAuxOpen{}
+ {\kaux_pretreatment_tl
+ \tl_gclear:N\kaux_pretreatment_tl
+ \iow_open:Nn
+ \knowledge_kaux_iow
+ {\c_sys_jobname_str.kaux}
+ \KAuxWrite*{}
+ \kaux_inittreatment_tl
+ \tl_gclear:N\kaux_inittreatment_tl
+ \KAuxWrite*{}}
+
+\NewDocumentCommand\KAuxClose{}
+ {\iow_close:N\knowledge_kaux_iow
+ \bool_gset_true:N\kaux_can_be_used_bool
+ \kaux_posttreatment_tl
+ }
+% \end{macrocode}
+%
+%
+%
+% Using the command |\KAuxBefore|, |\KAuxInit| and |\KAuxAfter|, one can add
+% code to be executed before the opening, at the beginning and after the writing of the KAUX file.
+% \begin{macrocode}
+\NewDocumentCommand\KAuxBefore{m}
+ {\tl_put_right:Nn\kaux_pretreatment_tl{#1}}
+\NewDocumentCommand\KAuxAfter{m}
+ {\tl_put_right:Nn\kaux_posttreatment_tl{#1}}
+\NewDocumentCommand\KAuxInit{m}
+ {\tl_put_right:Nn\kaux_inittreatment_tl{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\tl_gset:Nn\kaux_pretreatment_tl{}
+\tl_gset:Nn\kaux_posttreatment_tl{}
+\tl_gset:Nn\kaux_inittreatment_tl{}
+% \end{macrocode}
+%
+%
+% \subsubsection{KAux phases and commands}
+%
+% The idea is that the KAux file will be read several times. Once at the begining, before rewriting it,
+% and then more times afterward (maybe several times). Each time it is read corresponds to a `phase'.
+% By default, when a KAuxCommand is defined, then it does nothing (and absorbs its only parameter).
+% Then, when a phase is activated (and several phases can be activated simultaneously), each command
+% executes the corresponding code (declares using |\DeclareKAuxPhaseCommand|).
+%
+%
+% The list of KAux commands are kept in |\kaux_command_list_tl|.
+% \begin{macrocode}
+\tl_new:N\kaux_command_list_tl
+% \end{macrocode}
+%
+% When one wants to use some command in the KAux file, one has to first declare
+% it using |\NewKAuxCommand\commandname{arguments}{description}|
+% in which |\commandname| is the token of the command, |arguments|
+% is the description of arguments following the \texttt{xparse} package syntax,
+% and |description| is an informal description of what the command is intended to do.
+% Note that for efficiency reason, in the KAux file itself,
+% \emph{arguments have to be surrounded by curly brackets},
+% but when used, these will parsed using the argument description as defined by \texttt{xparse}.
+%
+% Technically, |\NewKAuxCommand| declares the command in the KAux file using |\KAuxCommand|,
+% then the arguments description is stored in |\kaux_commandname-args_tl|, and |\commandname|
+% itself is created, as a code that executes, followed by the arguments, all the tokens in |\kaux_commandname-active_tl|. Also, the command is appended to |\kaux_command_list_tl|.
+% \begin{macrocode}
+\NewDocumentCommand\NewKAuxCommand{ m m m }
+{ \ProvideDocumentCommand#1{#2}{}
+ \KAuxInit
+ {\KAuxWrite*{\KAuxCommand#1{#2}{#3}}}
+ \tl_gset:cn{kaux_\cs_to_str:N#1-args_tl}{#2}
+ \tl_gput_right:Nn\kaux_command_list_tl{#1}
+}
+\NewDocumentCommand\KAuxCommand{mmm}
+ {\ProvideDocumentCommand#1{#2}{}}
+% \end{macrocode}
+%
+% |\ActivateKAuxPhase{phase1,phase2,...}| sets the KAux commands to use
+% for all KAux commands the
+% code corresponding to |phase1|, |phase2|, \dots{} This is obtained by
+% defining for each command |\commandname| the tl variable |\kaux_commandname-active_tl|
+% accordingly.
+% \begin{macrocode}
+\NewDocumentCommand\ActivateKAuxPhase{m}{
+ \tl_map_inline:Nn\kaux_command_list_tl
+ {\kaux_activate_command_phase:Nn##1{#1}}
+ }
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\kaux_activate_command_phase:Nn
+{ \tl_gclear:c{kaux_\cs_to_str:N#1-active_tl}
+ %
+ \kaux_code_set:Nn\tmpa_code{}
+ \clist_map_inline:nn{#2}
+ {\cs_if_exist:cTF{kaux_\cs_to_str:N#1-##1:nnnnnnnnn}
+ {\exp_args:NNc
+ \kaux_code_put_right:NN
+ \tmpa_code{kaux_\cs_to_str:N#1-##1:nnnnnnnnn}}
+ {}}
+ \kaux_code_wrap:N\tmpa_code
+ \exp_args:NNx\kaux_code_put_left:Nn\tmpa_code
+ {\DeclareDocumentCommand\exp_not:N#1
+ {\exp_not:v{kaux_\cs_to_str:N#1-args_tl}}}
+ \kaux_code_exec:N\tmpa_code
+}
+% \end{macrocode}
+%
+% Here comes a bunch of commands for manipulating code.
+% The idea is to replicate some of the commands for the type tl (in a much less efficient way, it is true),
+% but make it compatible with arguments |#1|, |#2|. There may be much more efficient ways to do that,
+% but the expansion system makes it not obvious for me.
+% \begin{macrocode}
+\cs_new:Nn\kaux_code_set_eq:NN
+ {\cs_set_eq:NN#1#2}
+\cs_new:Nn\kaux_code_set:Nn
+ {\cs_set:Npn#1##1##2##3##4##5##6##7##8##9{#2}}
+\cs_new:Nn\kaux_code_put_right:NN
+ {\exp_args:NNo\kaux_code_put_right:Nn#1
+ {#2{##1}{##2}{##3}{##4}{##5}{##6}{##7}{##8}{##9}}}
+\cs_new:Nn\kaux_code_put_right:Nn
+ {\exp_args:NNo\cs_set:Nn
+ \tmp:nnnnnnnnn
+ {#1{##1}{##2}{##3}{##4}{##5}{##6}{##7}{##8}{##9}#2}
+ \cs_set_eq:NN#1\tmp:nnnnnnnnn}
+\cs_new:Nn\kaux_code_put_left:Nn
+ {\kaux_code_set:Nn\g_tmpc_code{#2}
+ \kaux_code_put_right:NN\g_tmpc_code#1
+ \kaux_code_set_eq:NN#1\g_tmpc_code}
+\cs_new:Nn\kaux_code_wrap:N
+ {\expandafter\cs_set:Nn
+ \expandafter\tmp:nnnnnnnnn
+ \expandafter{
+ \expandafter{#1{##1}{##2}{##3}{##4}{##5}{##6}{##7}{##8}{##9}}}
+ \cs_set_eq:NN#1\tmp:nnnnnnnnn}
+\cs_new:Nn\kaux_code_exec:N
+ {#1{##1}{##2}{##3}{##4}{##5}{##6}{##7}{##8}{##9}}
+% \end{macrocode}
+% Declaring a code for a KAuxCommand associated to a specific phase
+% is done using |\DeclareKAuxPhaseCommand\commandname{phase}{code}|.
+% The code is stored in a `cs' with nine parameters.
+% \begin{macrocode}
+\NewDocumentCommand\DeclareKAuxPhaseCommand{mmm}
+{ \tl_if_exist:cTF{kaux_\cs_to_str:N#1-args_tl}{}
+ {\ERROR_KAuxCommand_UNDEFINED}
+ \cs_gset:cn{kaux_\cs_to_str:N#1-#2:nnnnnnnnn}{#3}}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewDocumentCommand\KAuxWriteLocation{}
+ {\KAuxActivate
+ \group_begin:
+ \tl_set:Nx\l_tmpa_tl{{\currfilename}{\the\inputlineno}}
+ \tl_if_eq:NNTF\l_tmpa_tl\kaux_location_tl
+ {}
+ {\tl_gset_eq:NN\kaux_location_tl\l_tmpa_tl
+ \iow_now:Nx\knowledge_kaux_iow{}
+ \iow_now:Nx\knowledge_kaux_iow
+ {\KAuxFileAt\kaux_location_tl}}
+ \group_end:}
+
+\tl_new:N\kaux_location_tl
+
+\NewDocumentCommand\KAuxWriteX{sm}
+ {\KAuxActivate
+ \IfBooleanTF{#1}{}{\KAuxWriteLocation}
+ \exp_args:NNx\iow_now:Nn\knowledge_kaux_iow{#2}}
+
+\NewDocumentCommand\KAuxWrite{sm}
+ {\KAuxActivate
+ \IfBooleanTF{#1}{}{\KAuxWriteLocation}
+ \iow_now:Nn\knowledge_kaux_iow{#2}}
+
+\NewDocumentCommand\KAuxFileAt{mm}
+ {\tl_set:Nn\kauxCurrentFile{#1}
+ \tl_set:Nn\kauxCurrentLine{#2}}
+
+\tl_new:N\kauxCurrentFile
+\tl_new:N\kauxCurrentLine
+% \end{macrocode}
+%
+% The kaux file is allowed to be used at the beginning if it exists (of course),
+% and if the aux file also exists. This is for tools that delete the aux file for cleaning the directory
+% to virtually also delete the kaux file.
+% \begin{macrocode}
+\bool_new:N\kaux_can_be_used_bool
+\bool_gset_false:N\kaux_can_be_used_bool
+
+\file_if_exist:nT{\c_sys_jobname_str.aux}
+{\file_if_exist:nT{\c_sys_jobname_str.kaux}
+ {\bool_gset_true:N\kaux_can_be_used_bool}}
+
+\NewDocumentCommand\KAuxProcess{m}
+{ \bool_if:NT\kaux_can_be_used_bool
+ {\ActivateKAuxPhase{#1}
+ \input{\c_sys_jobname_str.kaux}}}
+% \end{macrocode}
+%
+%
+%
+%
+%
+%
+%
+%
+% \subsection{References}
+%
+% \begin{macrocode}
+\cs_new:Nn\cell_new_type:nnn
+ {
+ \cs_new:cn{#1_id:#2}{#3}
+ \cs_new:cn{#1_id_b:#2}{{#3}}
+ \cs_new:cpx{#1_at:N#2}##1
+ {\exp_not:n{\exp_after:wN\exp_args:Nc\exp_after:wN}
+ ##1 \exp_not:c{#1_id_b:#2}}
+ }
+
+\cs_new:Nn\cell_specialize:nnn
+ {\cs_new:cpx{#1_#2_id:#3}
+ {\exp_not:c{#1_id:n#3}{#2}}
+ \cs_new:cpx{#1_#2_at:N#3}##1
+ {\exp_not:c{#1_at:Nn#3}##1{#2}}
+ }
+
+\cs_new:Nn\cell_make_tl:nn
+ {\cs_set:Nn\l_tmpa_cs:nn
+ {\cs_new:cpx{#1_##1:#2##2}
+ {\exp_not:c{#1_at:N#2}\exp_not:c{tl_##1:N##2}}}
+ \l_tmpa_cs:nn{set}{n}
+ \l_tmpa_cs:nn{gset}{n}
+ \l_tmpa_cs:nn{set}{x}
+ \l_tmpa_cs:nn{gset}{x}
+ \l_tmpa_cs:nn{gput_right}{n}
+ \l_tmpa_cs:nn{gput_left}{n}
+ \l_tmpa_cs:nn{put_right}{n}
+ \l_tmpa_cs:nn{put_left}{n}
+ \l_tmpa_cs:nn{show}{}
+ \l_tmpa_cs:nn{use}{}
+ \l_tmpa_cs:nn{if_exist}{TF}
+ \l_tmpa_cs:nn{if_empty}{TF}
+ }
+
+\cs_new:Nn\cell_make_int:nn
+ {
+ \cs_set:Nn\l_tmpa_cs:nn
+ {\cs_new:cpx{#1_##1:#2##2}
+ {\exp_not:c{#1_at:N#2}\exp_not:c{int_##1:N##2}}}
+ \l_tmpa_cs:nn{new}{}
+ \l_tmpa_cs:nn{show}{}
+ \l_tmpa_cs:nn{set}{n}
+ \l_tmpa_cs:nn{gset}{n}
+ \l_tmpa_cs:nn{incr}{}
+ \l_tmpa_cs:nn{gincr}{}
+ \l_tmpa_cs:nn{decr}{}
+ \l_tmpa_cs:nn{gdecr}{}
+ \l_tmpa_cs:nn{use}{}
+ \l_tmpa_cs:nn{to_arabic}{}
+ }
+
+
+\cs_new:Nn\cell_make_bool:nn
+ {
+ \cs_set:Nn\l_tmpa_cs:nn
+ {\cs_new:cpx{#1_##1:#2##2}
+ {\exp_not:c{#1_at:N#2}\exp_not:c{bool_##1:N##2}}}
+ \l_tmpa_cs:nn{set_true}{}
+ \l_tmpa_cs:nn{set_false}{}
+ \l_tmpa_cs:nn{gset_true}{}
+ \l_tmpa_cs:nn{gset_false}{}
+ \l_tmpa_cs:nn{set}{n}
+ \l_tmpa_cs:nn{gset}{n}
+ \l_tmpa_cs:nn{if}{TF}
+ }
+
+\cs_new:Nn\seq_use:N
+ {\seq_use:Nn#1,}
+
+\cs_new:Nn\cell_make_seq:nn
+ {
+ \cs_set:Nn\l_tmpa_cs:nn
+ {\cs_new:cpx{#1_##1:#2##2}
+ {\exp_not:c{#1_at:N#2}\exp_not:c{seq_##1:N##2}}}
+ \l_tmpa_cs:nn{new}{}
+ \l_tmpa_cs:nn{set_from_clist}{n}
+ \l_tmpa_cs:nn{gset_from_clist}{n}
+ \l_tmpa_cs:nn{gpush}{n}
+ \l_tmpa_cs:nn{if_exist}{TF}
+ \l_tmpa_cs:nn{if_empty}{TF}
+ \l_tmpa_cs:nn{if_in}{nTF}
+ \l_tmpa_cs:nn{show}{}
+ \l_tmpa_cs:nn{use}{n}
+ \l_tmpa_cs:nn{use}{}
+ \l_tmpa_cs:nn{map_inline}{n}
+ }
+
+\cs_new:Nn\cell_make_tuple:nn
+ {
+ \cs_set:Nn\l_tmpa_cs:nn
+ {\cs_new:cpx{#1_##1:#2##2}
+ {\exp_not:c{#1_at:N#2}\exp_not:c{tuple_##1:N##2}}}
+ }
+
+\cs_new:Nn\cell_specialize_int:nnn
+ {
+ \cell_specialize:nnn{#1}{#2}{#3}
+ \cell_make_int:nn{#1_#2}{#3}
+ }
+
+\cs_new:Nn\cell_specialize_tl:nnn
+ {
+ \cell_specialize:nnn{#1}{#2}{#3}
+ \cell_make_tl:nn{#1_#2}{#3}
+ }
+
+\cs_new:Nn\cell_specialize_bool:nnn
+ {
+ \cell_specialize:nnn{#1}{#2}{#3}
+ \cell_make_bool:nn{#1_#2}{#3}
+ }
+
+\cs_new:Nn\cell_specialize_seq:nnn
+ {
+ \cell_specialize:nnn{#1}{#2}{#3}
+ \cell_make_seq:nn{#1_#2}{#3}
+ }
+% \end{macrocode}
+%
+% \subsection{Tuples}
+%
+% ensure
+% \cs{\tuple_empty_tl}, \cs{\tuple_new:N},
+% \cs{\tuple_gclear:N}, \cs{\tuple_if_exist:NTF},
+% \cs{\tuple_if_no_index:NNTF},
+% \cs{\tuple_gset:NNn}, \cs{\tuple_gset:NNN},
+% \cs{\tuple_gdel:NN}, \cs{\tuple_apply:NNNn},
+% \cs{\tuple_apply_inline:NNnn}, \cs{\tuple_get_default_tl:NNNn},
+% \cs{\tuple_get_int:NNN}, \cs{\tuple_incr:NN},
+% \cs{\tuple_decr:NN}, \cs{\tuple_gset_true:NN},
+% \cs{\bool_set_false:NN}
+%
+% \cs\tuple_new_expandable_index:Nnn takes a token acting as an index, a name,
+% and a default value, and creates a command |tuple_exp_|name|:N| which given
+% a tuple, retrieve in an expandable way the index, and if it does not exists outputs the default value.
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+% \begin{macrocode}
+\cs_new:Nn\tuple_new:n
+ {
+ \cs_new:cx{#1_new:N}
+ {\exp_not:N\tl_new:N##1
+ \exp_not:N\tl_gset:Nn##1{\exp_not:c{#1:}}}
+ \cs_new:cx{#1_gclear:N}
+ {\exp_not:N\tl_gset:Nn##1{\exp_not:c{#1:}}}
+ \cs_new:cx{#1_ensure:N}
+ {\exp_not:N\tl_if_exist:NTF##1{}
+ {\exp_not:N\tl_new:N##1
+ \exp_not:N\tl_gset:Nn##1{\exp_not:c{#1:}}}}
+ \cs_new:cn{#1:}{}
+ %
+ \cs_set:Nn\l_tmpa_cs:nn
+ { \cs_new:cpx{#1_##1:##2}
+ {\exp_not:c{tuple_##1:n##2}{\exp_not:n{#1}}}}
+ \l_tmpa_cs:nn{new_tl_index}{Nnn}
+ \l_tmpa_cs:nn{new_tl_index}{nn}
+ \l_tmpa_cs:nn{new_tl_index}{n}
+ \l_tmpa_cs:nn{new_int_index}{Nnn}
+ \l_tmpa_cs:nn{new_int_index}{nn}
+ \l_tmpa_cs:nn{new_int_index}{n}
+ \l_tmpa_cs:nn{new_bool_index}{Nn}
+ \l_tmpa_cs:nn{new_bool_index}{n}
+ \l_tmpa_cs:nn{show}{N}
+ \l_tmpa_cs:nn{if_exist}{NTF}
+ }
+\cs_new:Npn\tuple_if_exist:nNTF#1{\tl_if_exist:NTF}
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
+\cs_new:Nn\tuple_new_bool_index:nNNn
+ {
+ \cs_new:cn{#1_#4_expands_to:TF}{
+ \cs_set:Nn#2{##1}
+ \cs_set:Nn#3{##2}}
+ \cs_gset:Nn#2{}
+ \cs_gset:Nn#3{}
+ %
+ \cs_new:cx{#1_#4_if:NTF}
+ {\exp_not:N\expandafter
+ \exp_not:c{#1_#4_if~i:w}
+ ##1 \exp_not:n{#2 ab #2 c \tuple_end:}{##3}{##2}}
+ \cs_new:cpn{#1_#4_if~i:w}
+ ##1 #2 ##2 #2 ##3 \tuple_end:
+ {\tl_if_single:nTF{##3}}
+ %
+ \cs_new:cx{#1_#4_gset_false:N}
+ {\exp_not:N\expandafter
+ \exp_not:c{#1_#4_gset_false~i:w}
+ ##1 \exp_not:n{#2 ab #2 c \tuple_end:}##1}
+ \cs_new:cpn{#1_#4_gset_false~i:w}
+ ##1 #2 ##2 #2 ##3 \tuple_end:##4
+ {\tl_if_single:nTF{##3}
+ {\tl_gset:Nn##4{##1}}
+ {\tl_gset:Nn##4{##1##2}}}
+ %
+ \cs_new:cx{#1_#4_gset_true:N}
+ {\exp_not:N\expandafter
+ \exp_not:c{#1_#4_gset_true~:w}
+ ##1 \exp_not:n{#2 ab #2 c \tuple_end:}##1}
+ \cs_new:cpn{#1_#4_gset_true~:w}
+ ##1 #2 ##2 #2 ##3 \tuple_end: ##4
+ {\tl_if_single:nTF{##4}
+ {\tl_gset:Nn##4{##1 #2}}{}}
+}
+\cs_new:Nn\tuple_new_bool_index:nn
+ {\use:x{\exp_not:n{\tuple_new_bool_index:nNNn{#1}}
+ \exp_not:c{BOOL_#1_#2_true:}
+ \exp_not:c{BOOL_#1_#2_false:}
+ {#2}}}
+% \end{macrocode}
+%
+%
+%
+% \begin{macrocode}
+\cs_new:Nn\tuple_new_index:nNnn{
+ \cs_new:cn{#1_#3_expands_to:n}{\cs_set:Nn#2{##1}}
+ \cs_gset:Nn#2{}
+ %
+ \cs_new:cx{#1_#3_use:N}
+ {\exp_not:N\expandafter
+ \exp_not:c{#1_#3_use~i:w}
+ ##1 \exp_not:n{#2 {#4}\tuple_end:}}
+ \cs_new:cpx{#1_#3_use~i:w}
+ ##1 #2 ##2 ##3 \tuple_end:{##2}
+ %
+ \cs_new:cx{#1_#3_if_exist:NTF}
+ {\exp_not:N\expandafter
+ \exp_not:c{#1_#3_if_exist~i:w}
+ ##1 \exp_not:n{#2 ab #2 c \tuple_end:}{##3}{##2}}
+ \cs_new:cpn{#1_#3_if_exist~i:w}
+ ##1 #2 ##2 ##3 #2 ##4 \tuple_end:
+ {\tl_if_single:nTF{##4}}
+ %
+ \cs_new:cx{#1_#3_gdel:N}
+ {\exp_not:N\expandafter
+ \exp_not:c{#1_#3_gdel~i:w}
+ ##1 \exp_not:n{#2 ab #2 c \tuple_end:}##1}
+ \cs_new:cpn{#1_#3_gdel~i:w}
+ ##1 #2 ##2 ##3 #2 ##4 \tuple_end:##5
+ {\tl_if_single:nTF{##4}
+ {\tl_gset:Nn##5{##1}}
+ {\tl_gset:Nn##5{##1##3}}}
+ %
+ \cs_new:cx{#1_#3_gapply:NN}
+ {\exp_not:N\expandafter
+ \exp_not:c{#1_#3_gapply~i:w}
+ ##1 \exp_not:n{#2 ab #2 c \tuple_end:}##1##2}
+ \cs_new:cpn{#1_#3_gapply~i:w}
+ ##1 #2 ##2 ##3 #2 ##4 \tuple_end: ##5 ##6
+ {\tl_if_single:nTF{##4}
+ {\tl_gset:Nx##5{\exp_not:n{##1 #2}{##6{#4}}}}
+ {\tl_gset:Nx##5{\exp_not:n{##1 #2}{##6{##2}} \exp_not:n{##3}}}}
+}
+
+
+
+\cs_new:Nn\tuple_new_tl_index:nNnn
+ {\tuple_new_index:nNnn{#1}#2{#3}{#4}
+ %
+ \cs_new:cx{#1_#3_gset:Nn}
+ {\exp_not:N\expandafter
+ \exp_not:c{#1_#3_gset~:w}
+ ##1 \exp_not:n{#2 ab #2 c \tuple_end:}##1{##2}}
+ \cs_new:cpn{#1_#3_gset~:w}
+ ##1 #2 ##2 ##3 #2 ##4 \tuple_end: ##5 ##6
+ {\tl_if_single:nTF{##4}
+ {\tl_gset:Nn##5{##1 #2{##6}}}
+ {\tl_gset:Nn##5{##1 #2{##6} ##3}}}
+}
+\cs_new:Nn\tuple_new_tl_index:nnn
+ {\exp_args:Nnc\tuple_new_tl_index:nNnn{#1}{TL_#1_#2_:n}{#2}{#3}}
+\cs_new:Nn\tuple_new_tl_index:nn
+ {\tuple_new_tl_index:nnn{#1}{#2}{}}
+
+\cs_new:Nn\int_incr:n{\int_eval:n{#1+1}}
+\cs_new:Nn\int_decr:n{\int_eval:n{#1-1}}
+
+\cs_new:Nn\tuple_new_int_index:nNnn{
+ \tuple_new_index:nNnn{#1}#2{#3}{#4}
+ %
+ \cs_new:cx{#1_#3_get_int:NN}
+ {\exp_not:n{\int_set:Nn} ##2 {\exp_not:c{#1_#3_use:N} \exp_not:N##1}}
+ %
+ \cs_new:cx{#1_#3_gincr:N}
+ {\exp_not:c{#1_#3_gapply:NN}##1\exp_not:N\int_incr:n}
+ %
+ \cs_new:cx{#1_#3_gdecr:N}
+ {\exp_not:c{#1_#3_gapply:NN}##1\exp_not:N\int_decr:n}
+ %
+ \cs_new:cx{#1_#3_gset:Nn}
+ {\exp_not:N\expandafter
+ \exp_not:c{#1_#3_gset~:w}
+ ##1 \exp_not:n{#2 ab #2 c \tuple_end:}##1{##2}}
+ \cs_new:cpn{#1_#3_gset~:w}
+ ##1 #2 ##2 ##3 #2 ##4 \tuple_end: ##5 ##6
+ {\tl_if_single:nTF{##4}
+ {\tl_gset:Nx##5{##1 \exp_not:N#2 {\int_eval:n{##6}}}}
+ {\tl_gset:Nx##5{##1 \exp_not:N#2 {\int_eval:n{##6}} ##3}}}
+ %
+ \cs_new:cpx{#1_#3_case:NnTF}##1
+ {\exp_not:N\int_case:nnTF{\exp_not:c{#1_#3_eval:n}##1}}
+}
+\cs_new:Nn\tuple_new_int_index:nnn
+ {\exp_args:Nnc\tuple_new_int_index:nNnn{#1}{INT_#1_#2_:n}{#2}{#3}}
+\cs_new:Nn\tuple_new_int_index:nn
+ {\tuple_new_int_index:nnn{#1}{#2}{0}}
+% \end{macrocode}
+%
+% \begin{macrocode}
+%\cs_new:Nn\tuple_index_default_cs_set_eq:NN{
+% \cs_set:Npn#1{\cs_set_eq:NN#2}}
+%\cs_new:Nn\tuple_index_default_tl_set:NN{
+% \cs_set:Npn#1{\tl_set:Nn#2}}
+%\cs_new:Nn\tuple_index_default_tl_put_left:NN{
+% \cs_set:Npn#1{\tl_put_left:Nn#2}}
+%\cs_new:Nn\tuple_index_default_tl_put_right:NN{
+% \cs_set:Npn#1{\tl_put_right:Nn#2}}
+%\cs_new:Nn\tuple_index_default_int_set:NN{
+% \int_new:N#2
+% \cs_set:Npn#1{\int_set:Nn#2}}
+%\cs_new:Nn\tuple_index_default_bool_set:NN{
+% \bool_new:N#2
+% \cs_set:Npn#1##1{##1#2}}
+%\cs_new:Nn\tuple_index_default_ignore:N{
+% \cs_set:Npn#1##1{}}
+%\cs_new:Nn\tuple_index_default_show:N{
+% \cs_set_eq:NN#1\tl_show:n}
+% \end{macrocode}
+%
+%
+% \subsection{Variables encoding}
+%
+% We use an automatic generator of variables, of different types.
+% For global \texttt{tl} variables, the command is |\NewGTl|
+%\begin{verbatim}
+%\NewGTl{variable}[default value]{arguments}[identifier]
+%\end{verbatim}
+% The arguments satisfy the syntax of \texttt{xparse}, and the identifier uses these arguments for
+% creating a token list that can be used in a csname.
+% The result of this command is that new commands |\variableIfTF|, |\variableSet|,
+% |\variableSetX|, |\variableGet|, |\variableApply|, |\variableApplyInline| and |\variableIfEmpty|
+% are created.
+% For instance
+%\begin{verbatim}
+% \NewGTl{Test}{ m o }[test default]{\IfNoValue{#1}{#2}{#2-#1}}
+%\end{verbatim}
+% Gives right to |\TestSet{first}[1]{success}|
+% |\TestApplyInline{first}[1]{The test was a #1!}|.
+%
+%
+%
+% \begin{macrocode}
+\cs_new:Nn\int_get_default:N
+ {\int_if_exist:NTF#1{\int_use:N#1}{0}}
+\cs_generate_variant:Nn\int_get_default:N{c}
+\cs_new:Nn\int_force:N
+ {\int_if_exist:NTF#1{}{\int_new:N#1}}
+\cs_new:Npn\int_force_gset:Nn#1
+ {\int_force:N#1\int_gset:Nn#1}
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
+\NewDocumentCommand\NewGBool{ m m o }{
+ \IfNoValueTF{#3}{
+ \tl_gset:Nn\g_tmpa_tl{#2}
+ \tl_remove_all:Nn\g_tmpa_tl{~}
+ \int_case:nnTF{\tl_count:N\g_tmpa_tl}{
+ 0 {\NewGBoolComplete {#1}{#2}{#1:_bool}}
+ 1 {\NewGBoolComplete {#1}{#2}{#1:##1_bool}}
+ 2 {\NewGBoolComplete {#1}{#2}{#1:##1...##2_bool}}
+ 3 {\NewGBoolComplete {#1}{#2}{#1:##1...##2...##3_bool}}
+ 4 {\NewGBoolComplete {#1}{#2}{#1:##1...##2...##3...##4_bool}}
+ 5 {\NewGBoolComplete {#1}{#2}{#1:##1...##2...##3...##4...##5_bool}}
+ 6 {\NewGBoolComplete {#1}{#2}{#1:##1...##2...##3...##4...##5...##6_bool}}
+ 7 {\NewGBoolComplete {#1}{#2}{#1:##1...##2...##3...##4...##5...##6...##7_bool}}
+ 8 {\NewGBoolComplete {#1}{#2}{#1:##1...##2...##3...##4...##5...##6...##7...##8_bool}}
+ 9 {\NewGBoolComplete {#1}{#2}{#1:##1...##2...##3...##4...##5...##6...##7...##8...##9_bool}}
+ }{}{\ERROR}}{\NewGBoolComplete{#1}{#2}{#3}}}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewDocumentCommand\NewGBoolComplete{ m m m }{
+ \exp_args:Nc\NewDocumentCommand{#1SetTrue}{#2}
+ {\bool_gset_true:c{#3}}
+ \exp_args:Nc\NewDocumentCommand{#1SetFalse}{#2}
+ {\bool_gset_false:c{#3}}
+ \exp_args:Nc\NewDocumentCommand{#1Set}{#2}
+ {\exp_args:Nc\bool_gset_tl:Nn{#3}}
+ \exp_args:Nc\DeclareExpandableDocumentCommand{#1IfTF}{#2}
+ {\bool_if:cTF{#3}}
+}
+\cs_new:Nn\bool_gset_tl:Nn
+ {\use:c{bool_gset_#2:N}#1}
+% \end{macrocode}
+%
+%
+%
+% \begin{macrocode}
+\NewDocumentCommand\NewGCs{ m m o }{
+ \IfNoValueTF{#3}{
+ \tl_gset:Nn\g_tmpa_tl{#2}
+ \tl_remove_all:Nn\g_tmpa_tl{~}
+ \int_case:nnTF{\tl_count:N\g_tmpa_tl}{
+ 0 {\NewGCsComplete {#1}{#2}{#1_:}}
+ 1 {\NewGCsComplete {#1}{#2}{#1_##1_cs:w}}
+ 2 {\NewGCsComplete {#1}{#2}{#1_##1...##2_cs:w}}
+ 3 {\NewGCsComplete {#1}{#2}{#1_##1...##2...##3_cs:w}}
+ 4 {\NewGCsComplete {#1}{#2}{#1_##1...##2...##3...##4_cs:w}}
+ 5 {\NewGCsComplete {#1}{#2}{#1_##1...##2...##3...##4...##5_cs:w}}
+ 6 {\NewGCsComplete {#1}{#2}{#1_##1...##2...##3...##4...##5...##6_cs:w}}
+ 7 {\NewGCsComplete {#1}{#2}{#1_##1...##2...##3...##4...##5...##6...##7_cs:w}}
+ 8 {\NewGCsComplete {#1}{#2}{#1_##1...##2...##3...##4...##5...##6...##7...##8_cs:w}}
+ 9 {\NewGCsComplete {#1}{#2}{#1_##1...##2...##3...##4...##5...##6...##7...##8...##9_cs:w}}
+ }{}{\ERROR}}{\NewGCsComplete{#1}{#2}{#3}}}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewDocumentCommand\NewGCsComplete{ m m m }{}
+% \exp_args:Nc\NewDocumentCommand{#1New_internal}{ m m m }
+% {\NewDocumentCommand##1{ m ##2}{##3} }
+% \exp_args:Nc\NewDocumentCommand{#1New}{#2}
+% {\cs_new:cn{#2}{#2_internal{#2}}
+% \exp_args:Nc{#2_internal}}
+% \end{macrocode}
+%
+%
+%
+%
+%
+% \subsection{The \texttt{knowledge} file handling}
+%
+%
+% The knowledge package uses two macros for file handling:
+%\begin{itemize}
+%\item |\kl_copy_file:nn|(|nV|, |Vn|, |VV|) takes the name of two files
+% and copies the first one to the second (does nothing if the first file does not exist),
+%\item |kl_compare_files:Nnn|(|NnV|, |NVn|, |NVV|) takes a boolean and the name of two files,
+% and sets the boolean (locally) according to the result of their comparison for equality,
+%\item |\kl_tl_to_file:nn| takes the name of a file, and a token list, and creates the file with the tl as content.
+% This is a conveninent way to create empty files (since deleting files is not possible with \kl{TeX}...)
+%\end{itemize}
+%
+% \begin{macrocode}
+\cs_new_protected_with_variants:Nnn\kl_copy_file:nn{nV,Vn,VV}
+ {\file_if_exist:nT{#1}
+ {\group_begin:
+ \bool_set_false:N\l_tmpa_bool
+ \ior_open:Nn\g_tmpa_ior{#1}
+ \iow_open:Nn\g_tmpa_iow{#2}
+ \bool_do_until:Nn\l_tmpa_bool{
+ \ior_if_eof:NTF\g_tmpa_ior
+ {\bool_set_true:N\l_tmpa_bool}
+ {\ior_get_str:NN
+ \g_tmpa_ior
+ \l_tmpa_tl
+ \exp_args:NNV
+ \iow_now:Nn
+ \g_tmpa_iow
+ \l_tmpa_tl}
+ }
+ \ior_close:N\g_tmpa_ior
+ \iow_close:N\g_tmpa_iow
+ \group_end:}}
+
+\cs_new_protected_with_variants:Nnn\kl_compare_files:Nnn{NnV,NVn,NVV}
+ {\group_begin:
+ \bool_set_false:N\l_tmpa_bool% set when finished
+ \bool_set_true:N\l_tmpb_bool% result
+ \file_if_exist:nTF{#2}
+ {\file_if_exist:nF{#3}
+ {\bool_set_true:N\l_tmpa_bool
+ \bool_set_false:N\l_tmpb_bool}}
+ {\bool_set_true:N\l_tmpa_bool
+ \file_if_exist:nT{#3}
+ {\bool_set_false:N\l_tmpb_bool}}
+ \bool_if:NF\l_tmpa_bool{
+ \ior_open:Nn\g_tmpa_ior{#2}
+ \ior_open:Nn\g_tmpb_ior{#3}
+ %
+ \bool_do_until:Nn\l_tmpa_bool{
+ \ior_if_eof:NTF\g_tmpa_ior
+ {\bool_set_true:N\l_tmpa_bool
+ \ior_if_eof:NF\g_tmpb_ior
+ {\bool_set_false:N\l_tmp_bool}}
+ {\ior_if_eof:NTF\g_tmpb_ior
+ {\bool_set_true:N\l_tmpa_bool
+ \bool_set_false:N\l_tmp_bool}
+ {\ior_get_str:NN
+ \g_tmpa_ior
+ \l_tmpa_tl
+ \ior_get_str:NN
+ \g_tmpb_ior
+ \l_tmpb_tl
+ \tl_if_eq:NNF
+ \l_tmpa_tl\l_tmpb_tl
+ {\bool_set_true:N\l_tmpa_bool
+ \bool_set_false:N\l_tmpb_bool}
+ }}
+ }
+ \ior_close:N\g_tmpa_ior
+ \ior_close:N\g_tmpb_ior}
+ \bool_if:NTF\l_tmpb_bool
+ {\group_end:\bool_set_true:N#1}
+ {\group_end:\bool_set_false:N#1}
+ }
+
+\cs_new_protected:Nn\kl_tl_to_file:nn
+ {\iow_open:Nn\g_tmpa_iow{#1}
+ \iow_now:Nn\g_tmpa_iow{#2}
+ \iow_close:N\g_tmpa_iow}
+% \end{macrocode}
+%
+% These macros are used for testing the modification of knowledges.
+% At the begining, jobname.knowledge.aux is transferred to jobname.knowledge.tmp.
+% During the file reading, the file jobname.knowledge.aux is again written.
+% At the end, the two are compared.
+%
+% \begin{macrocode}
+\ior_new:N\g_tmpa_ior
+\ior_new:N\g_tmpb_ior
+\iow_new:N\g_tmpa_iow
+\iow_new:N\g_tmpb_iow
+% \end{macrocode}
+%
+%
+%
+%
+%
+% \subsection{Dealing with LaTeX commands}
+%
+%
+% We define now a certain number of commands that allows to
+% \begin{itemize}
+% \item Store known commands with a protected name.
+% \item Declare commands as obsolete when used in a document.
+% \item Create variants using \textsc{xsparse} that remove the hassle of optional parameters/stars, and so on.
+% \end{itemize}
+%
+%
+% \subsubsection{Overloading command}
+% Overloading a command is similar in syntax to |\NewDocumentCommand|
+% of the \texttt{xparse} package, but it further offer the macro |\SUPERcommand|
+% (where |\command| is the token under definition), which can be used for calling the original code.
+% It is often used in combination with |\XparseArgs| for recreating the arguments if necesssary.
+%
+%
+% \begin{macrocode}
+\cs_generate_variant:Nn\cs_gset_eq:NN{cN,cc}
+\NewDocumentCommand\OverloadCommand{mmm}
+ {\exp_args:Nc\cs_gset_eq:NN{SUPER\cs_to_str:N#1}#1
+ \exp_args:Nc\NewDocumentCommand{NEW\cs_to_str:N#1}{#2}{#3}
+ \cs_gset_eq:Nc#1{NEW\cs_to_str:N#1}}
+% \end{macrocode}
+%
+%
+%
+% \subsubsection{Xparse reversing}
+% The package \texttt{xparse} offers a convenient way for describing the profile of parameters
+% of new commands (optional star, optional parameters, and so on)
+% We provide converse commands, that recreates these arguments.
+% For instance, the command |\section| is supposed to have an optional star (numbering or not), followed by an optional argument (title in the toc), followed by a mandatory argument (the title of the section).
+% This would be defined with \texttt{xparse} as |\NewDocumentCommand\section{som}{...code...}|,
+% where \texttt{som} means star-optional-mandatory.
+% Imagine you want to overload this command. The command |\XParseArgs| is meant for that.
+% One first stores the old command |\section| as |\oldsection|:
+%\begin{verbatim}
+% \let\oldsection\section
+%\end{verbatim}
+% and then redefine it, calling in the code the old version:
+% \begin{verbatim}
+% \RenewDocumentCommand\section{som}{%
+% <pre-code>%
+% \XparseArgs\oldsection{som}{#1}{#2}{#3}
+% <post-code>}
+% \end{verbatim}
+% (please refer to \texttt{xparse} documentation for knowing how to use the arguments
+% in the pre- and post-code)
+%
+% The command |\ExpXparseArgs| is the expandable variant of it (I was unable to produce
+% a version that would work in both situations !).
+%
+% For parameter types treated so far are:
+% \begin{compactdesc}
+% \item[i]= ignore
+% \item[m]= mandatory
+% \item[o]= optional (under square brackets)
+% \item[s]= stars
+% \end{compactdesc}
+% \begin{macrocode}
+\NewDocumentCommand\XparseArgs{mm}
+ {\kutils_reverting_args:Nn#1{#2}}
+\DeclareExpandableDocumentCommand\ExpXparseArgs{mm}
+ {\kutils_exec_xreverting_args:Nn#1{#2}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\kutils_xrevert_arg_s:n
+ { \IfBooleanTF{#1}{*}{}}
+\cs_new:Nn\kutils_xrevert_arg_o:n
+ { \IfValueTF{#1}{[\exp_not:n{#1}]}{}}
+\cs_new:Nn\kutils_xrevert_arg_m:n
+ { {\exp_not:n{#1}} }
+\cs_new:Nn\kutils_xrevert_arg_i:n
+ { }
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\kutils_reverting_args:Nn{
+ \use:c{kutils_process_\tl_count:n{#2}:w}
+ #1{\kutils_exec_xreverting_args:n{#2}}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\kutils_exec_xreverting_args:n{
+ \tl_if_empty:nTF{#1}{}
+ {\kutils_exec_xreverting_args_internal:w#1\kutils_end:}}
+\cs_new:Nn\kutils_exec_xreverting_args:Nn{
+ \exp_not:N#1
+ \tl_if_empty:nTF{#2}{}
+ {\kutils_exec_xreverting_args_internal:w#2\kutils_end:}}
+\cs_new:Npn\kutils_exec_xreverting_args_internal:w#1#2\kutils_end:#3
+ { \use:c{kutils_xrevert_arg_#1:n}{#3}
+ \tl_if_empty:nTF{#2}{}
+ {\kutils_exec_xreverting_args_internal:w#2\kutils_end:}}
+% \end{macrocode}
+% The following internal commands |\cs_new:Nn\kutils_process_args:nn...| eat a token list `|\com|',
+% then an expandable command token list |\proc|, that is totally expanded with as arguments the following arguments (the number of which is fixed from the signature).
+% In the end, |\com| is prefixed.
+% Hence |\kutils_process_args:nnnn\com\proc a b|
+% completely expands |{\proc a b}| yielding some `result', and then executes |\com| followed by the `result'.
+% E.g. if |\swap#1#2| is |{#2}{#1}|, then |\kutils_process_args:nnnn\com\swap|
+% expands to the same as |\com| but with arguments reversed.
+% \begin{macrocode}
+\cs_new:Nn\kutils_process_args:nn
+ {#1}
+\cs_new:Nn\kutils_process_args:nnn
+ {\use:nx{#1}{#2{#3}}}
+\cs_new:Nn\kutils_process_args:nnnn
+ {\use:nx{#1}{#2{#3}{#4}}}
+\cs_new:Nn\kutils_process_args:nnnnn
+ {\use:nx{#1}{#2{#3}{#4}{#5}}}
+\cs_new:Nn\kutils_process_args:nnnnnn
+ {\use:nx{#1}{#2{#3}{#4}{#5}{#6}}}
+\cs_new:Nn\kutils_process_args:nnnnnnn
+ {\use:nx{#1}{#2{#3}{#4}{#5}{#6}{#7}}}
+\cs_new:Nn\kutils_process_args:nnnnnnnn
+ {\use:nx{#1}{#2{#3}{#4}{#5}{#6}{#7}{#8}}}
+\cs_new:Nn\kutils_process_args:nnnnnnnnn
+ {\use:nx{#1}{#2{#3}{#4}{#5}{#6}{#7}{#8}{#9}}}
+\exp_args:Nc\let{kutils_process_0:w}\kutils_process_args:nn
+\exp_args:Nc\let{kutils_process_1:w}\kutils_process_args:nnn
+\exp_args:Nc\let{kutils_process_2:w}\kutils_process_args:nnnn
+\exp_args:Nc\let{kutils_process_3:w}\kutils_process_args:nnnnn
+\exp_args:Nc\let{kutils_process_4:w}\kutils_process_args:nnnnnn
+\exp_args:Nc\let{kutils_process_5:w}\kutils_process_args:nnnnnnn
+\exp_args:Nc\let{kutils_process_6:w}\kutils_process_args:nnnnnnnn
+\exp_args:Nc\let{kutils_process_7:w}\kutils_process_args:nnnnnnnnn
+% \end{macrocode}
+%
+% \subsubsection{Obsolescence and vaulting}
+%
+% \begin{macrocode}
+\msg_new:nnn{scope}{LaTeX~obsolete}
+ {The~command~'#1'~is~deprecated.~
+ See~documentation~for~a~replacement.}
+
+\cs_new:Nn\kutils_secure_latex_command:N
+ {\cs_new_eq:cN{LaTeX\cs_to_str:N#1}#1}
+
+\cs_new:Nn\kutils_latex_to_vault:N
+ {\kutils_secure_latex_command:N#1
+ \cs_undefine:N#1}
+
+\cs_new:Nn\kutils_latex_to_obsolete:N
+ {\kutils_latex_to_vault:N#1
+ \cs_new:Npx#1{\exp_not:N\msg_error:nnn{scope}{LaTeX~obsolete}{\string #1}}}
+
+\cs_new:Nn\kutils_secure_latex_command:n
+ {\tl_map_function:nN{#1}\kutils_secure_latex_command:N}
+\cs_new:Nn\kutils_latex_to_vault:n
+ {\tl_map_function:nN{#1}\kutils_latex_to_vault:N}
+\cs_new:Nn\kutils_latex_to_obsolete:n
+ {\tl_map_function:nN{#1}\kutils_latex_to_obsolete:N}
+% \end{macrocode}
+%
+%
+%
+%
+% \Finale
+\endinput
+
+
+
+
diff --git a/Master/texmf-dist/source/latex/knowledge/knowledge.dtx b/Master/texmf-dist/source/latex/knowledge/knowledge.dtx
new file mode 100644
index 00000000000..069746c66f0
--- /dev/null
+++ b/Master/texmf-dist/source/latex/knowledge/knowledge.dtx
@@ -0,0 +1,5569 @@
+% \iffalse
+% !TEX encoding = UTF-8 Unicode
+% !TEX TS-program = pdflatex
+%
+%
+%
+% meta-comment
+%
+% Copyright (C) 2017 by Thomas Colcombet
+% -----------------------------------
+%
+% This file may be distributed and/or modified under the
+% conditions of the LaTeX Project Public License, either version 1.2
+% of this license or (at your option) any later version.
+% The latest version of this license is in:
+%
+% http://www.latex-project.org/lppl.txt
+%
+% and version 1.2 or later is part of all distributions of LaTeX
+% version 1999/12/01 or later.
+%
+% \fi
+%
+% \iffalse
+%<head>\usepackage{expl3}
+%<head>\ProvidesExplPackage{knowledge}{2017/07/28}{v1.04}{}
+%<*driver>
+\def\knowledgeversion{2017/07/28 v1.04}
+
+
+\documentclass{ltxdoc}
+\usepackage[utf8]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{paralist}
+\usepackage[svgnames]{xcolor}
+\usepackage[hyperref,quotation,scope]{knowledge}
+
+\knowledgeconfigure{visible anchor points=false}
+
+
+\ExplSyntaxOn
+\ifdefined\nocode\expandafter\use_i:nn\else\expandafter\use_ii:nn\fi
+ {\def\producecode{}
+ \cs_new_eq:cN{ifcodeTF}\use_ii:nn
+ }{\def\producecode{\newpage\DocInput{knowledge.dtx}}
+ \cs_new_eq:cN{ifcodeTF}\use_i:nn}
+\ExplSyntaxOff
+
+\EnableCrossrefs
+\CodelineIndex
+\RecordChanges
+
+\ifcodeTF{
+\NewDocumentCommand\textmenu{m}{#1}
+\usepackage{eso-pic}% http://ctan.org/pkg/eso-pic
+\AddToShipoutPictureFG{%
+ \AtPageUpperLeft{%
+ \put(\LenToUnit{0cm},\LenToUnit{-1em})
+ {%
+ \begin{tabular}[t]{p{21cm}}
+ \centering ---
+ \textmenu{\hyperref[paper:top]{top}} ---
+ \textmenu{\hyperref[section:status]{status version}} ---
+ \textmenu{\hyperref[section:toc]{toc}} ---
+ \ifcodeTF{\textmenu{\hyperref[section:todo]{todo list}} ---}
+ \textmenu{\hyperref[section:history]{history}} ---
+ \textmenu{\hyperref[section:quick start]{quick start}} ---
+ \textmenu{\hyperref[section:doc]{doc}} ---
+ \textmenu{\hyperref[section:faq]{FAQ}} ---
+ \textmenu{\hyperref[section:resources]{resources}} ---
+ \ifcodeTF{\textmenu{\hyperref[section:code]{code}} ---}{}
+ \end{tabular}%
+ }}}
+}
+
+
+% this is a hack. Introducing Hyphenation everywhere in a sequence of token.
+% Otherwise the macro names tend to always exceed lines.
+% It should be improved in order to always require at least--say--3 symbols before
+% and after the hyphenation.
+\ExplSyntaxOn
+\cs_new:Nn\tl_fragilize:n
+ {\__tl_fragilize:N#1\q_stop}
+\cs_new:Nn\__tl_fragilize:N
+ {\token_if_eq_meaning:NNTF#1\q_stop
+ {}{#1
+ \-\__tl_fragilize:N}}
+\cs_set_eq:NN\textfragilize\tl_fragilize:n
+\cs_new:Npn\Robustdisplay#1
+ {\exp_args:Nx\textfragilize{\robustdisplay{#1}}}
+\ExplSyntaxOff
+
+
+
+\let\subsubsubsection\paragraph
+
+
+\knowledge{not implemented}{link=to be done}
+\knowledge{to be done}{color=DarkRed}
+\knowledge{|}{text=\vbar}
+\knowledge{[...]}{italic,color=gray,md}
+
+% Macros defined by knowledge
+\knowledgestyle{kcommand}{typewriter,up,md,color=NavyBlue}
+\knowledgestyle{kcommand intro}{typewriter,up,md,color=blue}
+\knowledgedirective{kcommand}{autoref,style=kcommand,intro style=kcommand intro,wrap=\Robustdisplay}
+
+\knowledgedirective{kenvironment}{autoref,style=kcommand,intro style=kcommand intro}
+
+\knowledgestyle{kicommand}{wrap=\Robustdisplay,typewriter,up,md,color=NavyBlue}
+\knowledgestyle{kicommand intro}{wrap=\Robustdisplay,typewriter,up,md,color=blue}
+\knowledgedirective{kicommand}{autoref,style=kicommand,intro style=kicommand intro}
+
+% Internal variable of knowledge
+\knowledgestyle{kvariable}{wrap=\Robustdisplay,typewriter,up,md,color=NavyBlue}
+\knowledgestyle{kvariable intro}{wrap=\Robustdisplay,typewriter,up,md,color=blue}
+\knowledgedirective{kvariable}{autoref,style=kvariable,intro style=kvariable intro}
+
+% Macros from elsewhere that deserve a comment
+\knowledgestyle{icommand}{wrap=\Robustdisplay,typewriter,up,md,color=NavyBlue}
+\knowledgestyle{icommand intro}{wrap=\Robustdisplay,typewriter,up,md,color=blue}
+\knowledgedirective{icommand}{autoref,style=icommand,intro style=icommand intro}
+
+% directives
+\knowledgestyle{directive}{up,md,typewriter,color=NavyBlue}
+\knowledgestyle{directive intro}{up,md,typewriter,color=blue}
+\knowledgedirective{directive}{autoref,style=directive,intro style=directive intro}
+
+% options of the package
+\knowledgestyle{option}{up,md,typewriter,color=NavyBlue}
+\knowledgestyle{option intro}{up,md,typewriter,color=blue}
+\knowledgedirective{option}{autoref,style=option,intro style=option intro}
+
+
+
+\knowledgeconfigure{notion}
+
+\knowledgedirective{doc notion}
+ {autoref,style=doc notion,intro style=intro doc notion}
+\knowledgestyle{doc notion}{color=DarkBlue}
+\knowledgestyle{intro doc notion}{color={DarkBlue},emphasize}
+
+
+
+
+% Latex command. Just for boing typeset properly
+\knowledgedirective{lcommand}{wrap=\Robustdisplay, typewriter,up,md,color=NavyBlue}
+
+
+\knowledge{@token}{wrap=\Robustdisplay,up,md,typewriter,color=NavyBlue}
+
+
+
+\knowledge{_monoid}{style=unknown}
+\knowledge{_semigroup}{style=unknown}
+
+
+
+% style names
+\knowledgedirective{notion style}{autoref,style=style,intro style=intro style}
+\knowledgestyle{style}{typewriter,color=NavyBlue}
+\knowledgestyle{intro style}{typewriter,color=blue}
+
+\begin{scope}\label{style}
+ \knowledge{notion}{notion style}
+ \knowledge{intro notion}{notion style}
+
+ \knowledge{intro}{notion style}
+ \knowledge{unknown}{notion style}
+ \knowledge{intro unknown}{notion style}
+ \knowledge{autoref not introduced}{notion style}
+ \knowledge{autoref reintroduced}{notion style}
+\end{scope}
+
+
+
+
+\knowledge {\knowledgeexportscopename }{kcommand}
+\knowledge {\knowledgeexportbase }{kcommand}
+\knowledge \knowledgepackagemode{kcommand}
+
+\knowledge {experimental}{doc notion,color=gray}
+
+
+
+\knowledge\knowledge{kcommand}
+\knowledge\knowledgestyle{kcommand}
+\knowledge\knowledgedirective{kcommand}
+\knowledge\knowledgedefault{kcommand}
+\knowledge\knowledgeimport{kcommand}
+\knowledge\knowledgeconfigure{kcommand}
+\knowledge\knowledgeconfigureenvironment{kcommand}
+\knowledge\kl{kcommand}
+\knowledge\intro{kcommand}
+\knowledge\phantomintro{kcommand}
+\knowledge{\intro*}{kcommand,wrap=,text=\robustdisplay\intro*}
+\knowledge{\reintro*}{kcommand,wrap=,text=\robustdisplay\reintro*}
+\knowledge\reintro{kcommand}
+\knowledge\nointro{kcommand}
+
+\ExplSyntaxOn
+\NewDocumentCommand\robustdisplaycs{m}
+ {\expandafter\robustdisplay\csname#1\endcsname}
+
+\knowledge\IfKnowledgeCompositionModeTF
+ {kcommand}
+\knowledge\IfKnowledgeCompositionMode
+ {kcommand,wrap=,text=\robustdisplaycs{ifKnowledgeCompositionMode}}
+
+\knowledge\IfKnowledgeElectronicModeTF
+ {kcommand}
+\knowledge\IfKnowledgeElectronicMode
+ {kcommand,wrap=,text=\robustdisplaycs{ifKnowledgeElectronicMode}}
+
+\knowledge\IfKnowledgePaperModeTF
+ {kcommand}
+\knowledge\IfKnowledgePaperMode
+ {kcommand,wrap=,text=\robustdisplaycs{ifKnowledgePaperMode}}
+\ExplSyntaxOff
+
+\knowledge\robustdisplay{kcommand}
+\knowledge\knowledgeFixHyperrefTwocolumn{kcommand}
+
+\knowledge\KAuxCommand{kicommand}
+\knowledge\KAuxKnowledge{kicommand}
+\knowledge\NewKnowledgeParamCode{kicommand}
+\knowledge\NewKnowledgeParamBool{kicommand}
+\knowledge\NewKnowledgeParamTl{kicommand}
+\knowledge{\knowledge_kl_init:}{kicommand}
+\knowledge{\knowledge_defaultkl_init:}{kicommand}
+\knowledge{\KnowledgeConfigureNotion}{kicommand}
+\knowledge{\klTKS}{kicommand}
+
+
+\knowledge\phantomsection{lcommand}
+\knowledge\AP{kcommand}
+\knowledge\itemAP{kcommand}
+
+
+
+
+\knowledge\usepackage{lcommand}
+\knowledge\newcommand{lcommand}
+\knowledge\label{lcommand}
+\knowledge\NewDocumentCommand{lcommand}
+
+
+
+\ExplSyntaxOn
+\knowledge\ensuremath{lcommand}
+\knowledge\texttt{lcommand}
+\knowledge\ProcessKeysOptions{lcommand}
+\knowledge\newrobustcmd{lcommand}
+\knowledge\tableofcontents{lcommand}
+\knowledge\begin{lcommand}
+\knowledge\end{lcommand}
+\knowledge\section{lcommand}
+\knowledge\emph{lcommand}
+\knowledge\underline{lcommand}
+\knowledge\mathcal{lcommand}
+\knowledge\text{lcommand}
+\knowledge\sc{lcommand}
+\knowledge\md{lcommand}
+\knowledge\input{lcommand}
+\knowledge\csname{lcommand}
+\knowledge\item{lcommand}
+\knowledge\documentclass{lcommand}
+
+\knowledgeconfigure{quotation=false}
+\knowledge{quotation symbol}{kcommand,text=",wrap}
+\knowledge"{synonym}
+\knowledge{""}{kcommand,text=""}
+\knowledgeconfigure{quotation=true}
+
+\knowledge{CTAN}{color=blue,url=https://www.ctan.org/}
+
+
+\makeatletter
+\let\arobas @
+\makeatother
+
+\knowledge{"..."}{kcommand,text=\kl{"}$\cdots$\kl{"},wrap}
+\knowledge{""...""}{kcommand,text=\kl{""}$\cdots$\kl{""},wrap}
+\knowledge{"...@..."}{kcommand,text=\kl{"}$\cdots\arobas\cdots$\kl{"},wrap}
+\knowledge{""...@...""}{kcommand,text=\kl{""}$\cdots\arobas\cdots$\kl{""},wrap}
+\knowledge{"...@@..."}{kcommand,text=\kl{"}$\cdots\arobas\cdots\arobas\cdots$\kl{"},wrap}
+\knowledge{""...@@...""}{kcommand,text=\kl{""}$\cdots\arobas\cdots\arobas\cdots$\kl{""},wrap}
+\knowledge{"...@...@..."}{kcommand,text=\kl{"}$\cdots\arobas\cdots\arobas\cdots$\kl{"},wrap}
+\knowledge{""...@...@...""}{kcommand,text=\kl{""}$\cdots\arobas\cdots\arobas\cdots$\kl{""},wrap}
+\knowledge{@}{kcommand,text=\arobas,wrap}
+
+\knowledge\Else{lcommand,wrap=,text=\robustdisplaycs{else}}
+\knowledge\Fi{lcommand,wrap=,text=\robustdisplaycs{fi}}
+
+\knowledge\keys_define:nn{lcommand}
+\knowledge\keys_set:nn{lcommand}
+
+\knowledge\LaTeX{lcommand}
+\knowledge\TeX{lcommand}
+\knowledge{tex}{text=\TeX}
+\knowledge\detokenize{lcommand}
+\knowledge\index{lcommand}
+\knowledge\def{lcommand}
+\knowledge{AucTex}{lcommand}
+\knowledge{Emacs}{lcommand}
+\knowledge{XEmacs}{lcommand}
+
+\knowledge{\kl_underline_bool}{kvariable}
+\knowledge{\kl_emphasize_bool}{kvariable}
+\knowledge{\kl_boldface_bool}{kvariable}
+\knowledge{\kl_typewriter_bool}{kvariable}
+\knowledge{\kl_fbox_bool}{kvariable}
+\knowledge{\kl_ensuremath_bool}{kvariable}
+\knowledge{\kl_ensuretext_bool}{kvariable}
+\knowledge{\kl_italic_bool}{kvariable}
+\knowledge{\kl_lowercase_bool}{kvariable}
+\knowledge{\kl_uppercase_bool}{kvariable}
+\knowledge{\kl_forced_text_tl}{kvariable}
+\knowledge{\knowledge_kl_resource_tl}{kvariable}
+
+\knowledgedirective{people}{emphasize,color=DarkGray}
+\knowledge{stackexchange}{people}
+\knowledge{egreg}{people}
+
+\knowledge\KAuxWriteLocation{kicommand}
+\knowledge\KAuxScopeLabel{kicommand}
+
+\knowledge{\knowledge_configuration_pending_tl}{kicommand}
+\knowledge{\knowledge_xcolor_active_bool }{kicommand}
+\knowledge{\knowledge_xcolor_syntax_bool }{kicommand}
+\knowledge{\knowledge_hyperref_active_bool }{kicommand}
+\knowledge{\knowledge_hyperref_syntax_bool }{kicommand}
+\knowledge{\knowledge_makeidx_active_bool }{kicommand}
+\knowledge{\knowledge_makeidx_syntax_bool }{kicommand}
+\knowledge{\knowledge_namespace_tl }{kicommand}
+\knowledge{\knowledge_id:nnn }{kicommand}
+\knowledge{\scope_area_create:n }{kicommand}
+\knowledge{\scope_area_if_exist:nTF }{kicommand}
+\knowledge{\scope_area_if_in_scope:nTF }{kicommand}
+\knowledge{\scope_area_set:nn }{kicommand}
+\knowledge{\ScopeConfigure }{kicommand}
+\knowledge{\scope_category_if_exist:nTF }{kicommand}
+\knowledge{\scope_category_ensure:n }{kicommand}
+\knowledge{\scope_category_create:n }{kicommand}
+\knowledge{\scope_category_add_area:nn }{kicommand}
+\knowledge{\scope_category_use:n }{kicommand}
+\knowledge{\scope_category_show:n }{kicommand}
+\knowledge{\scope_instance_if_exist:nTF }{kicommand}
+\knowledge{\scopept_instance_if_exist:nTF }{kicommand}
+\knowledge{\scopept_label_if_exist:nTF }{kicommand}
+\knowledge{\scope_area_push:n }{kicommand}
+\knowledge{\scope_area_pop:n }{kicommand}
+\knowledge{\scope_popped_area_tl }{kicommand}
+\knowledge{\scope_pushed_area_tl }{kicommand}
+\knowledge{\scope_get_attractive_instance:N }{kicommand}
+\knowledge{\scope_get_labelizable_instance:N }{kicommand}
+\knowledge{\knowledge_kl_TKS:nnn}{kicommand}
+\knowledge{\knowledge_klTKS:nnn}{kicommand}
+\knowledge{\knowledge_kl_linkscope_tl}{kicommand}
+\knowledge{\knowledge_kl_find_in_scope:nnNTF}{kicommand}
+\knowledge{\knowledge_kl_display_code: }{kicommand}
+\knowledge{\knowledge_phantomintro_display_code: }{kicommand}
+\knowledge{\knowledge_kl_error_unknown: }{kicommand}
+\knowledge{\knowledge_kl_error_unknown_in_scope:}{kicommand}
+\knowledge{\knowledge_kl_update:N }{kicommand}
+\knowledge{\knowledge_kl_find: }{kicommand}
+\knowledge{\knowledge_kl_exec:N }{kicommand}
+\knowledge{\knowledge_II }{kicommand}
+\knowledge{\knowledge_scope_track_instance:Nn }{kicommand}
+\knowledge{\NewKnowledgeParamPackageError }{kicommand}
+\knowledge{\knowledge_knowledge_process:nn }{kicommand}
+\knowledge {\knowledge_kl_init: }{kicommand}
+\knowledge {\knowledge_defaultkl_init: }{kicommand}
+\knowledge {\knowledge_kl_used_style_tl }{kicommand}
+\knowledge {\knowledge_kl_display_code_preprocess: }{kicommand}
+\knowledge {\knowledge_intro_display_code_preprocess: }{kicommand}
+\knowledge{\klparse_absorb_modifiers:}{kicommand}
+\knowledge{\klparse_if_load_primes:TF}{kicommand}
+\knowledge{\klparse_if_load_supscript:TF}{kicommand}
+\knowledge{\klparse_if_load_subscript:TF}{kicommand}
+\knowledge{\klparse_absorb_modifiers_exec:}{kicommand}
+\knowledge{\klparse_primes_tl}{kicommand}
+\knowledge{\klparse_subscript_tl}{kicommand}
+\knowledge{\klparse_supscript_tl}{kicommand}
+\knowledge{\klparse_ifnextchar:NTF}{kicommand}
+\knowledge{\klparse_absorb_subscript:Nn}{kicommand}
+\knowledge{\klparse_absorb_supscript:Nn}{kicommand}
+\knowledge{\klparse_novalue_tl}{kicommand}
+
+\knowledge {\knowledge_kl_find }{kicommand}
+\knowledge {\knowledge_option_aci_define:n }{kicommand}
+
+\knowledge{\knowledge_kl_key_tl}{kvariable}
+\knowledge{\knowledge_kl_namespace_tl }{kvariable}
+\knowledge{\knowledge_kl_linkscope_tl }{kvariable}
+\knowledge{\knowledge_kl_command_tl }{kvariable}
+\knowledge{\knowledge_kl_base_key_tl }{kvariable}
+\knowledge{\knowledge_kl_text_tl }{kvariable}
+\knowledge{\knowledge_kl_link_tl }{kvariable}
+
+\knowledge{nesting_int}{kvariable}
+\knowledge{count_int}{kvariable}
+\knowledge{name_tl}{kvariable}
+\knowledge{pushcode_tl}{kvariable}
+\knowledge{popcode_tl}{kvariable}
+\knowledge{autoclose_bool}{kvariable}
+\knowledge{environment_bool}{kvariable}
+\knowledge{recursive_bool}{kvariable}
+\knowledge{multiple_bool}{kvariable}
+\knowledge{acceptsknowledge_bool}{kvariable}
+\knowledge{attractsknowledge_bool}{kvariable}
+\knowledge{labelizable_bool}{kvariable}
+\knowledge{scope_bool}{kvariable}
+\knowledge{mandatorybase_seq}{kvariable}
+\knowledge{instance.attractsknowledge_bool}{kvariable}
+
+
+\knowledge{\scope_instances_stack_seq }{kvariable}
+\knowledge{\scope_top_instance_tl }{kvariable}
+\knowledge{\scope_top_area_tl }{kvariable}
+\knowledge{\knowledge_sets_to:nnn }{kvariable}
+\knowledge{\knowledge_at:N }{kvariable}
+\knowledge{\token }{kvariable}
+\knowledge{\knowledge_visible_instances_seq }{kvariable}
+\knowledge{\knowledge_current_instance_tl }{kvariable}
+\knowledge{\knowledge_set_now:nnnn }{kicommand}
+\knowledge{\knowledge_knowledgestyle_bool }{kvariable}
+\knowledge{\kl_knowledgedefault_tl }{kvariable}
+\knowledge{\knowledge_kl_recursion_int }{kvariable}
+\knowledge{\knowledge_kl_max_recursion_int }{kvariable}
+
+\ExplSyntaxOff
+
+\begin{scope}\label{area}
+ \knowledge{nesting_int}{kvariable}
+ \knowledge{count_int}{kvariable}
+ \knowledge{name_tl}{kvariable}
+ \knowledge{pushcode_tl}{kvariable}
+ \knowledge{popcode_tl}{kvariable}
+ \knowledge{autoclose_bool}{kvariable}
+ \knowledge{environment_bool}{kvariable}
+ \knowledge{recursive_bool}{kvariable}
+ \knowledge{multiple_bool}{kvariable}
+ \knowledge{forces_tl}{kvariable}
+ \knowledge{acceptsknowledge_bool}{kvariable}
+ \knowledge{attractsknowledge_bool}{kvariable}
+ \knowledge{labelizable_bool}{kvariable}
+ \knowledge{scope_bool}{kvariable}
+ \knowledge{mandatorybase_seq}{kvariable}
+
+ \knowledge{autoclose=}{kvariable}
+ \knowledge{environment=}{kvariable}
+ \knowledge{parents=}{kvariable}
+ \knowledge{scope=}{kvariable}
+ \knowledge{label=}{kvariable}
+ \knowledge{push code=}{kvariable}
+ \knowledge{pop code=}{kvariable}
+ \knowledge{occurrences=}{kvariable}
+ \knowledge{forces=}{kvariable}
+\end{scope}
+
+\knowledge{instance.area}{kvariable}
+\knowledge{instance.parent}{kvariable}
+
+
+
+
+\knowledge{text=}{directive}
+\knowledge{link=}{directive}
+\knowledge{link scope=}{directive}
+\knowledge{style=}{directive}
+\knowledge{intro style=}{directive}
+\knowledge{wrap=}{directive}
+\knowledge{scope=}{directive}
+\knowledge{export=}[export]{directive}
+\knowledge{now}{directive}
+
+
+\knowledge{protect link}{directive}
+\knowledge{emphasize}{directive}
+\knowledge{underline}{directive}
+\knowledge{italic}{directive}
+\knowledge{up}{directive}
+\knowledge{md}{directive}
+\knowledge{boldface}{directive}
+\knowledge{fbox}{directive}
+\knowledge{typewriter}{directive}
+\knowledge{ensuretext}{directive}
+\knowledge{ensuremath}{directive}
+\knowledge{lowercase}{directive}
+\knowledge{uppercase}{directive}
+\knowledge{mathord}{directive}
+\knowledge{mathbin}{directive}
+\knowledge{mathop}{directive}
+\knowledge{mathrel}{directive}
+\knowledge{mathclose}{directive}
+\knowledge{mathopen}{directive}
+\knowledge{mathpunct}{directive}
+\knowledge{synonym}{directive}
+\knowledge{index=}{directive}
+\knowledge{index key=}{directive}
+\knowledge{index parent key=}{directive}
+\knowledge{index style=}{directive}
+\knowledge{color=}{directive}
+\knowledge{colorbox=}{directive}
+\knowledge{ref=}{directive}
+\knowledge{url=}{directive}
+\knowledge{autoref}{directive}
+\knowledge{autorefhere}{directive}
+\knowledge{namespace=}{directive}
+\knowledge{notion}{directive}
+
+
+\begin{scope}\label{option}
+ \knowledge{hyperref}{option}
+ \knowledge{xcolor}{option}
+ \knowledge{makeidx}{option}
+ \knowledge{scope}{option}
+ \knowledge{quotation}[quotation=]{option}
+ \knowledge{notion}{option}
+\end{scope}
+\knowledge{hyperref option}{link=hyperref,link scope=option}
+\knowledge{makeidx option}{link=makeidx,link scope=option}
+\knowledge{scope option}{link=scope,link scope=option}
+\knowledge{xcolor option}{link=xcolor,link scope=option}
+\knowledge{notion option}{link=notion,link scope=option}
+\knowledge{quotation option}{link=quotation,link scope=option}
+
+
+\knowledge{visible anchor points}[visible AP|visible AP=|visible anchor points=]{option}
+\knowledge{protect quotation}[protect quotation=]{option}
+\knowledge{protect link co}{option,text=protect link}
+\knowledge{unprotect link co}{option,text=unprotect link}
+\knowledge{hyperlinks=}{option}
+\knowledge{fix hyperref twocolumn}{option}
+\knowledge{diagnose line=}[diagnose line]{option}
+
+
+\knowledge{active}{option}
+\knowledge{inactive}{option}
+\knowledge{compatibility}{option}
+\knowledge{auto}{option}
+
+% options from external packages
+\knowledgedirective{eoption}{typewriter}
+\knowledge{svgnames}{eoption}
+\knowledge{hidelinks}{eoption}
+\knowledge{breaklinks}{eoption}
+
+\knowledgedirective{package}{typewriter,color=DarkBlue}
+\begin{scope}\label{package}
+ \knowledge{knowledge}{doc notion, package}
+ \knowledge{expl3}{package,url={https://www.ctan.org/pkg/expl3}}
+ \knowledge{hyperref}{package,url={https://www.ctan.org/pkg/hyperref}}
+ \knowledge{tikzcd}{package,url={https://www.ctan.org/pkg/tikz-cd}}
+ \knowledge{standalone}{package,url={https://www.ctan.org/pkg/standalone}}
+ \knowledge{xcolor}{package,url={https://www.ctan.org/pkg/xcolor}}
+ \knowledge{makeidx}{package,url={https://www.ctan.org/pkg/makeidx}}
+ \knowledge{etoolbox}{package,url={https://www.ctan.org/pkg/etoolbox}}
+ \knowledge{xparse}{package,url={https://www.ctan.org/pkg/xparse}}
+ \knowledge{amsmath}{package,url={https://www.ctan.org/pkg/amsmath}}
+ \knowledge{amssymb}{package,url={https://www.ctan.org/pkg/amssymb}}
+\end{scope}
+
+\knowledgedirective{environment}{typewriter}
+\begin{scope}\label{env}
+ \knowledge{scope}{kenvironment}
+ \knowledge{export}{kenvironment}
+ \knowledge{import}{kenvironment}
+ \knowledge{theorem}{environment}
+ \knowledge{tikzcd}{environment,ref=section:tikzcd}
+ \knowledge{document}{environment}
+\end{scope}
+
+\knowledge{align*}{typewriter}
+
+%\knowledgedefault{index}
+\knowledgedefault{}
+
+\knowledge{label}{}
+
+\knowledge{scoping}[Scoping]{doc notion}
+\knowledge{package option}[package options|Package options]{doc notion}
+\knowledge{configuration option}[configuration options|Configuration options]{link=package option}
+\knowledge{stack of visible scope instances}{notion}
+\knowledge{quotation notation}{doc notion}
+\knowledge{jobname.kaux}[kaux file]{doc notion}
+\knowledge{undefined knowledge}[undefined knowledges|Undefined knowledges]{doc notion}
+\knowledge{Non introduced autoref knowledge}{doc notion}
+\knowledge{Duplicated intros}{doc notion}
+\knowledge{instance}[instances|Instances]{doc notion}
+\knowledge{directive}[directives|Directives]{doc notion}
+\knowledge{area}[areas|Areas]{doc notion}
+\knowledge{knowledge}[knowledges|Knowledges]{doc notion}
+\knowledge{diagnose file}[diagnose|filename.diagnose]{doc notion}
+\knowledge{.diagnose}{link=diagnose file,typewriter}
+\knowledge{macro directive}[macro directives|Macro directives]{doc notion}
+\knowledge{default directive}[default directives|Default directives]{doc notion}
+\knowledge{knowledge style}[Knowledge styles|knowledge styles]{doc notion}
+\knowledge{style}[styles|Styles|display style|display styles]{link=knowledge style}
+\knowledge{category}[categories|Categories]{doc notion}
+\knowledge{scope}[scopes|Scopes]{doc notion} % separate the package
+\knowledge{namespace}[namespaces|Namespaces]{doc notion}
+\knowledge{vertical mode}{doc notion}
+\knowledge{debug mode}{doc notion}
+\knowledge{knowledge macro}[Knowledge macros|knowledge macros]{doc notion}
+\knowledge{anchor point}[anchor points|Anchor points]{doc notion}
+\knowledge{configuration directive}[Configuration directives|configuration directives]{doc notion}
+
+\knowledge {\knowledge namespace}{doc notion}
+\knowledge {\knowledge knowledge name}{doc notion}
+\knowledge {\knowledge synonyms}[\knowledge optional argument]{doc notion}
+\knowledge {\knowledge directives}[knowledge directive]{doc notion}
+
+\knowledge {composition mode}[composition]{option}
+\knowledge {paper mode}[paper]{option}
+\knowledge {electronic mode}[electronic]{option}
+
+\knowledge {targeting directive}[targeting directives]{doc notion}
+\knowledge {display directive}[display directives]{doc notion}
+\knowledge {scope directive}[scope directives]{doc notion}
+
+\knowledge {index key}{doc notion}
+\knowledge {index entry}{doc notion}
+\knowledge {main index entry}{doc notion}
+\knowledge {table of contents}[toc]{doc notion}
+\knowledge {knowledge name}{doc notion}
+\knowledge {klab}{doc notion}
+\knowledge {knowledge names}{synonym}
+\knowledge {export file}{doc notion}
+\knowledge {index}{doc notion}
+\knowledge {warning styles}{doc notion}
+\knowledge {default styles}{doc notion}
+\knowledge {`Undefined knowledges' section}{link=undefined knowledge}
+\knowledge {Autoref not introduced}{doc notion}
+\knowledge {Autoref introduced twice}{doc notion}
+\knowledge {scopept instances}{doc notion}
+\knowledge {token list variable}{doc notion}
+\knowledge {knowledgenow directives}{doc notion}
+\knowledge {writing mode}[Writing modes|writing modes]{doc notion}
+
+\knowledge {scope.sty}{link=scope option}
+
+\knowledgedefault{}
+
+
+
+
+ \newtheorem{problem}{\textcolor{red}{\texttt{The problem}}}
+
+ \newenvironment{warning}{\medskip\par\noindent\textcolor{red}{\texttt{Warning!}}}{\medskip\par}
+
+\newtheorem{remark}{Remark}
+
+\newenvironment{hint}{\medskip\par\noindent\textbf{Hint.}}{\medskip\par}
+\NewDocumentEnvironment{variation}{o}
+ {\medskip\par\noindent\textcolor{blue}{\texttt{Variation%
+ \IfNoValueF{#1}{ (\textcolor{DarkBlue}{#1})}%
+ .}}}{\medskip\par}
+
+
+\newsavebox{\fminipagebox}
+
+\NewDocumentEnvironment{cminipage}{m O{\fboxsep}}
+ {\par\kern#2\noindent\begin{lrbox}{\fminipagebox}
+ \begin{minipage}{#1}\ignorespaces}
+ {\end{minipage}\end{lrbox}%
+ \makebox[#1]{%
+ \kern\dimexpr-\fboxsep-\fboxrule\relax
+ \colorbox{Honeydew}{\usebox{\fminipagebox}}%
+ \kern\dimexpr-\fboxsep-\fboxrule\relax}\par\kern#2}
+
+\NewDocumentEnvironment{fminipage}{m O{\fboxsep}}
+ {\par\kern#2\noindent\begin{lrbox}{\fminipagebox}
+ \begin{minipage}{#1}\ignorespaces}
+ {\end{minipage}\end{lrbox}%
+ \makebox[#1]{%
+ \kern\dimexpr-\fboxsep-\fboxrule\relax
+ \fbox{\usebox{\fminipagebox}}%
+ \kern\dimexpr-\fboxsep-\fboxrule\relax}\par\kern#2\relax}
+
+ \newenvironment{code}[1][12.4cm]
+ {\par
+ \noindent
+ \cminipage{#1}%
+ \tt
+ }{%
+ \endcminipage%
+ \par
+ }
+
+ \newenvironment{PDFoutput}[1][8.5cm]
+ {\begin{flushright}\begin{fminipage}{#1}}
+ {\end{fminipage}\end{flushright}\par}
+
+ \newcommand\smallcode[1]{\colorbox{Honeydew}{\texttt{#1}}}
+
+\newcommand\MakeUnderscoreLetter{%
+ \catcode`_ = 11%
+ \catcode`: = 11%
+}
+\MakeUnderscoreLetter
+
+
+\ExplSyntaxOn
+\group_begin:
+ \catcode`| = 11%
+ \global\def\vbar{|}
+\group_end:
+\ExplSyntaxOff
+
+
+\knowledge{command}{typewriter,wrap=\robustdisplay}
+
+
+
+
+
+
+
+
+
+\begin{document}
+\label{paper:top}
+\title{The \texttt{knowledge} package\\\small[\knowledgeversion]}
+\author{Thomas Colcombet \\ \texttt{thomas.colcombet@irif.fr}}
+\maketitle
+
+\begin{abstract}""@knowledge@package""
+The "knowledge@@package" package offers automatic tools and commands
+for helping the writer of a (scientific) document to have all notions (hyper)linked
+to places where these are defined. Using the standard tools of \LaTeX{} for doing
+that would be extremely tedious.
+Eventually, it is intended to use the package for producing scientific semantic aware documents.
+\end{abstract}
+
+
+\section*{Status of this version}
+\label{section:status}
+\begin{quote}
+\begin{tabular}{ll}
+\texttt{contact:}&\texttt{thomas.colcombet@irif.fr}\\
+\texttt{version:}&\texttt{\knowledgeversion} (produced \today)\\
+\texttt{license:}&\texttt{LaTeX Project Public License 1.2}\\
+\texttt{web:}&\url{https://www.irif.fr/~colcombe/knowledge_en.html}\\
+\texttt{CTAN:}&\url{https://www.ctan.org/pkg/knowledge}
+\end{tabular}
+\end{quote}
+This is still in beta version but close to a first definitive release. A lot of functionalities are perfectly operational, and the syntax is close to stable. At any rate, if changes happen, these will only affect a few lines in the configuration of the document. Nevertheless, it is still advised to put the package directly in the document's directory rather than in the search tree of \LaTeX.
+\newpage
+\knowledgeconfigure{protect links}
+\tableofcontents
+\label{section:toc}
+\knowledgeconfigure{unprotect links}
+
+
+\newpage
+\ifcodeTF{%
+\section{Todo list}
+\label{section:todo}
+This is essentially a list for personal referencing of what has to be done.
+\begin{asparaitem}
+\item add the scope information in the diagnose file,
+\item allow to protect quotation in commands, and not only environments (for instance xymatrix)
+\item remove the warnings about redefining commands
+\item give detail on where appear the multiple introduction of the same knowledge
+\item proper mathematics handling. Write a new \intro{\NewDocumentCommand}-like macro
+\item detect using some trick that the previous compilation failed, and deactivate the Kaux file in this case
+ (for the moment, removing the aux file deactivates the kaux file. This is convenient but not sufficient.)
+\item proper code for \kl{\nointro}.
+\item Solve the problem of \kl{\kl} (and similar commands) being unknown when creating the pdf index.
+\item improve the diagnose file
+ \begin{asparaenum}
+ \item more information on the origin of errors (file/line)
+ \item help possible in it
+ \item short or long version of diagnose upon request
+ \end{asparaenum}
+\item improving the \kl{\AP} and \kl{\itemAP} commands. For the moment \kl{\AP} silently fails inside the
+ optional argument of \kl{\item}, and probably elsewhere too. See how this can be improved.
+\item solve the \kl(package){amsmath} problem that \kl{\label} is deactivated in unnumbered environment, while knowledge would nevertheless like to point to the place...
+\item Code export and import features.
+\item Pointing inside an external pdf document.
+\end{asparaitem}%
+}
+
+\newpage
+%\newgeometry{left=3cm,bottom=0.1cm}
+\section{History}
+\label{section:history}
+\small
+\begin{compactdesc}
+\item[2016-06-07] \verb|\knowledgemacro| is now renamed to \kl{\knowledgedirective}.
+\item[2017-01-13] \kl{\AP} has been recoded, and is now more properly aligned in the margin. The \kl{visible anchor points} option has also been made usable without the \kl(package){xcolor} package.
+\item[2017-01-13] The package \kl{scope option} can now be omitted. This in particular avoid clashes with the over-restriction on the structure of the document it entails. It should be improved to stop overloading the \kl{\begin} command.
+\item[2017-01-14] The overloading of \kl{\begin} and \kl{\end} was done as protected commands, which should not be the case to be consistent with the behaviour of LaTeX (for instance, this was giving an extra line in the title in the conference mode of the class IEEEtran). Corrected: these commands are not protected anymore.
+\item[2017-01-15] A workaround for an incompatibility between the "hyperref@@package" and the two-column mode as been added in the macro
+\kl{\knowledgeFixHyperrefTwocolumn} (thanks to Daniela Petrisan).
+\item[2017-01-15] Added the \kl[\knowledge directives]{directive} \kl{synonym}.
+\item[2017-01-15] Added the \texttt{noknowledge package} for minimizing the effects of not having "knowledge@@package" activated.
+\item[2017-01-17] Changed the way options are handled, decoupling the package options (options of \kl{\usepackage}) from the configuration options (see \kl{\knowledgeconfigure}).
+\item[2017-01-17] Proper treatment of `final` option and \kl[composition mode]{composition} options.
+\item[2017-01-17] Added \robustdisplaycs{IfKnowledgeFinalMode}\texttt{[TF]} commands for the user.
+\item[2017-01-17] Added the option \kl{fix hyperref twocolumn} as a shorthand for calling \kl{\knowledgeFixHyperrefTwocolumn} (thanks to Daniela Petrisan and Luca Reggio).
+\item[2017-01-18] Added the configuration option \kl(option){notion} that offers a basic configuration compatible with \kl(package){xcolor} or not, and \texttt{final} and \kl{composition} modes.
+\item[2017-01-19] Added \kl{\phantomintro} and an explanation on how to deal with \kl{align*}.
+\item[2017-02-20] Removed the warnings of latex for unknown labels in \kl{autoref}.
+\item[2017-02-20] Removed nasty error making \kl{\AP} not operative when anchor points were not visible.
+\item[2017-02-21] Added the \kl{protect link} directive.
+\item[2017-02-21] Added the \kl{hyperlinks=} configuration.
+\item[2017-02-27] \kl{visible anchor points} is active by default now.
+\item[2017-02-27] A simple example is now included.
+\item[2017-02-28] Minor changes on the documentation.
+\item[2017-02-28] Added the \kl(env){scope} environment.
+\item[2017-02-28] Added the \kl{protect link co} and \kl{unprotect link co} \kl{configuration directives}.
+\item[2017-02-28] Added the \kl{\knowledgeconfigureenvironment} command.
+\item[2017-03-03] Added the \kl{breaklinks} faq (thanks to Luca Reggio for the request).
+\item[2017-03-10] Added the \kl{"..."} and \kl{""...""} notations and the \kl(option){quotation} mode (requested by Gabriele Puppis and Andreas Krebs).
+\item[2017-03-11] Added the \kl{"...@..."} and \kl{""...@...""} notations.
+\item[2017-03-13] Corrected for being compatible with version of expl3 posterior to Mars 2015 (\verb|\c_sys_jobname_str| does not exist anymore). (Thanks to Jean-Éric Pin).
+\item[2017-03-14] Corrected that the \verb|@| letter was left a letter after \kl{\knowledgeFixHyperrefTwocolumn}.
+\item[2017-04-09] Internal change of code, for "scope" handling and for the "quotation notation": slowly going toward an extended "quotation notation" that can make the "scope" of search explicit.
+\item[2017-04-09] Added the \kl{protect quotation} configure option, that is given a list of environments, and deactivates automatically the "quotation notation" when in there environments. This is a simple code for the moment. Typically, one can use \smallcode{\kl\knowledgeconfigure\{\kl{protect quotation}=tikzcd\}}. For the moment, it is not explained in the document.
+\item[2017-04-19] Changed the display code such hat nested knowledges behave properly: before, the introduction would be performed for the object and the subobjects.
+\item[2017-04-20] The "electronic mode" has been added, and the `final mode` is now renamed into "paper mode". The \kl{\knowledgepackagemode} configuration variable is also available for easier scripting.
+\item[2017-06-06] FAQ on deactivating the quote in "Emacs" (thanks to Sylvain Perifel).
+\item[2017-06-08] Removed the \texttt{noknowledge} package and all references to it.
+\item[2017-06-08] Removed the \texttt{knowledgeutils.sty} and \texttt{scopearticle.sty} which are now integrated in the main file.
+\item[2017-06-08] The file \texttt{knowledge-example.sty} as been improved.
+\item[2017-06-09] First release of version 1.0 on "CTAN".
+\item[2017-06-10] Corrected the "quotation notation" to make it expandable for avoiding problems in table of contents (the @ was not working).
+\item[2017-06-11] Corrected a bug linked to changes of expl3 on recent distributions (pointed by Murray Eisenberg)
+\item[2017-06-11] Release of v1.01
+\item[2017-06-27] Overloaded labels now perform an expansion of the argument (this was causing problems with biblatex).
+\item[2017-06-28] Options \texttt{log-declarations} of "xparse@@package" package removed (causing clash wit other packages, as pointed by Juliusz Chroboczek).
+\item[2017-06-28] Release of v1.02.
+\item[2017-06-30] added the field \texttt{\robustdisplay{labelizable_bool}} to areas. Coded missing features of scoping. Now the "scope=" directive works with as parameter an enclosing "area", or a label.
+\item [2017-06-30] Added in the source a Regression subdirectory containing files to be tested (so far only one: regression-scope.tex)
+\item [2017-07-01] Corrected a conflict between the "scope@@option" and "makeidx@@option" option.
+\item [2017-07-03] Scoping becomes operational.
+\item [2017-07-04] The documentation for "notion@@style" and "intro notion@@style" are added (thanks to Fabian Reiter).
+\item [2017-07-09] The boolean "environment_bool@@area" has been added to "areas" in order to not always trigger the scope from an environment. Now the environment "document@@env" has this Boolean set to false, and it resolves a bug with the package "standalone@@package" noticed by Fabian Reiter.
+\item [2017-07-20] "Scoping" becomes fully operational, with the parenthesis notation of \kl{\kl} and \kl{\intro}. The use of scope has been recoded. Now scope links reuse implicitly the key as a link. Documentation updated.
+\item[2017-07-26] File and line numbers added in the "kaux file". Added the option "diagnose line=" to deactivate it.
+\item[2017-07-26] Corrections to the documentation.
+\item[2017-07-27] Version 1.03.
+\item[2017-07-28] Corrected a bug of scoping in the context of synonyms. Added ctan for producing the ctan zip file.
+\item[2017-07-28] Version 1.04.
+\end{compactdesc}
+\normalsize
+%\restoregeometry
+
+
+
+\newcommand{\filluptopage}[1]{%
+ \clearpage
+ \loop\ifnum\value{page}<#1\relax
+ \null\clearpage
+ \repeat
+}
+\filluptopage{4}
+
+
+\section{Quick start}
+\label{section:quick start}
+
+\leavevmode
+\AP
+The "knowledge@@package" package offers several capabilities for handling colors, changing the display style, defining internal and external hyperlinks, producing an index, etc...
+All these possibilities arise from defining explicitly or implicitly \kl{knowledges} associated to terms in plain english (or other languages).
+
+We start by describing a certain number of problems/scenarii that a user is confronted to, and show how to solve them. The hyperlinks in this document have been generated using the "knowledge@@package" package.
+In the subsequent questions, a more detailed account of how the "package@knowledge@package" works and can be parameterized is given.
+
+There is also a file \texttt{knowledge-example.tex} that can be used as a starting point.
+
+\subsection{Linking to outer documents/urls, and to labels}
+
+\medskip
+\begin{problem}
+I have a lot of external url's that I would like to [[very] often] have a link to, but I do not want to
+always type the full url. I do not want to remember weird labels/internal references/macro names either.
+\end{problem}
+\medskip
+
+A solution is as follows. One first loads the "knowledge@@package" package with option
+\kl(option){hyperref}
+using either:
+\marginpar{\begin{hint}
+You may use other options like \kl(option){xcolor} for allowing debugging with colors (for undefined knowledges).
+\end{hint}}
+\begin{code}[8cm]
+\kl{\usepackage}["hyperref@@package",\kl(option){quotation}]\{"knowledge@@package"\}
+\end{code}
+\noindent or:
+\begin{code}[8cm]
+\kl\usepackage[hidelinks\footnote{The option \kl{hidelinks} is advised, but not necessary.}]\{\kl(package){hyperref}\}\\
+\kl\usepackage[\kl(option){quotation}\footnote{If you want to use the \kl"$\cdots$\kl" notation.}]\{"knowledge@@package"\}
+\end{code}
+
+Then, in the preamble (or in an external file), one uses commands of the form:
+
+\begin{code}
+\kl\knowledge\{latex\}\{\kl{url=}\{https://en.wikipedia.org/wiki/LaTeX\}\}
+\end{code}
+This configures the text `\texttt{latex}' to be associated with the sole directive \kl{url=},
+which means an hyperreference to this address.
+
+Finally in the body of the paper, the sole extra command \kl{\kl} (or the \kl"-symbol if the \kl(option){quotation} option is activated) is used,
+with as parameter a text. This text is searched for, and the directives attached to it (here the url),
+are used for formatting its printing\footnote{This resembles a lot a macro so far. It nevertheless differs in that: (a) if not defined, it does not make the compilation fail as a macro would, and thus does not interfere with the writing process, (b) any text can be used and not only alphabetic letters as in \TeX, (c) you do not have to care about the space after, and (d)
+in fact the machinery for resolving the meaning of a knowledge is much more powerful than simple macro execution.}.
+Hence:
+ \marginpar{\begin{hint}
+ If the knowledge is not defined, this does not make the compilation fail.
+ In fact, it is good practice to use many \kl{\kl} commands or \kl{"..."} notations while writing a text,
+ and only resolve these questions at the end (see also the \kl{diagnose file}).
+ \end{hint}}
+\begin{code}[10cm]
+This package has been written for use in \kl\kl\{latex\}.
+\end{code}\noindent
+or, if the \kl(option){quotation} option is activated,
+\begin{code}[10cm]
+This package has been written for use in \kl{"}latex\kl{"}.
+\end{code}\noindent
+yields
+\knowledge{urllatex}{url=https://en.wikipedia.org/wiki/LaTeX}
+\begin{PDFoutput}
+This package has been written for use in \kl[urllatex]{latex}.
+\end{PDFoutput}
+
+\begin{variation}
+But in fact, I would like `\texttt{latex}' to also be properly typeset \LaTeX{}, and in \textcolor{gray}{gray}.
+This requires to load the package with the \kl(option){xcolor} option (for being able to use colors, obviously), or by loading the package "xcolor@@package" before, and then modify the \kl{\knowledge} command using
+extra "directives":
+\begin{code}[10.9cm]
+\kl\knowledge\{latex\}\{\kl{url=}https://en.wikipedia.org/wiki/LaTeX,\\
+\qquad\kl{text=}\kl\LaTeX,~\kl{color=}gray\}
+\end{code}\noindent
+yields with the same text
+\knowledge{urllatexgray}{url=https://en.wikipedia.org/wiki/LaTeX, color=gray, text=\LaTeX}
+\begin{PDFoutput}
+This package has been written for use in \kl[urllatexgray]{LaTeX}.
+\end{PDFoutput}
+
+The \kl[\knowledge directives]{directives} \kl{text=} and \kl{color=} have quite obvious meaning.
+\kl{Directives} can also control the style using \kl{emphasize}, \kl{boldface}, \kl{italic},
+\kl{typewriter} and so on. See Section~\ref{subsection:directive list} for a complete list of "directives@knowledge directive".
+\end{variation}
+\begin{variation}[synonyms]
+It happens very often that there are several ways to name a notion, because of capitalized letters, conjugacy, grammar, or simply because at this place in the document in it is not explicitly named. There are two ways to resolve this issue. The first is to use the syntax
+\begin{center}
+\smallcode{\kl\kl[\textit{knowledge}]\{\textit{text}\}}\qquad or\qquad\smallcode{\kl"\textit{text}\kl @\textit{knowledge}\kl"}
+\end{center}
+the result is that the text `\textit{text}' is displayed, but urls, colors, etc from `\textit{knowledge}' are used.
+
+Another more systematic way to do it is to declare synonyms.
+This can be achieved using a `\vbar' separated list of texts in the \kl[\knowledge synonyms]{optional parameter} of the\kl{\knowledge} command, it is possible to add a list of `synonyms', such as in:
+%
+\marginpar{\begin{hint}
+This is a shorthand for a \kl{synonym} (or \kl{link=}) directive.\\For instance, with the code
+ \begin{code}[4.3cm]
+ \kl{\knowledge}\{D. Knuth\}\\~~~~\{\kl{link=}Knuth\}
+ \end{code}\noindent then \smallcode{\kl\kl\{D. Knuth\}}
+ would also point to the same url.
+ \begin{code}[4.3cm]
+ \kl{\knowledge}\{D. Knuth\}\\~~~~\{\kl{synonym}\}
+ \end{code}\noindent would also work if used just after the definition
+ of \texttt{Knuth}.\\
+ \end{hint}}
+%
+\begin{code}
+\kl{\knowledge}\{latex\}[LaTeX\vbar Latex\vbar LATEX]\\
+ \{\kl{url=}http://en.wikipedia.org/wiki/LaTeX,~\kl{text=}\kl{\LaTeX}, \kl{color=}gray\}
+\end{code}
+This is interesting for people's name that can be displayed in various ways depending on the context. Hence
+%
+ \begin{code}[9.8cm]
+ \kl\knowledge\{Donald Ervin Knuth\}[Donald Knuth\vbar Knuth]
+ \{\kl{url=}https://fr.wikipedia.org/wiki/Donald_Knuth\}
+ \end{code}
+\noindent would allow
+\begin{center}
+\smallcode{\kl\kl\{Knuth\}}~~~as well as~~~\smallcode{\kl\kl\{Donald Knuth\}},\\
+or simply \smallcode{\kl"Knuth\kl"}~~~as well as~~~\smallcode{\kl"Donald Knuth\kl"} and so on
+\end{center} to all point to the same web address.
+It is even more convenient to use it for nouns that are sometimes in plural form or at the beginning of a sentence. Hence:
+%\marginpar{%
+% \begin{hint}
+% Sometimes one wants to use a \kl{knowledge} by explicitly mentioning it:
+% \begin{code}[4.3cm]
+% \kl\kl[group]\{This object\}
+% \\ is very important.
+% \end{code}
+% or
+% \begin{code}[4.3cm]
+% \kl"This object\kl{@}group\kl"
+% \\ is very important.
+% \end{code}
+% \end{hint}}
+\begin{code}[10.6cm]
+\kl\knowledge\{group\}[groups\vbar Groups\vbar group morphism\vbar group morphisms\vbar Group morphisms]\\
+ \{\kl{url=}https://en.wikipedia.org/wiki/Group_(mathematics)\}
+\end{code}
+\end{variation}\noindent
+makes it possible to use the notions in many contexts:
+\begin{code}
+\kl"Groups\kl" form a category when equipped with \kl"group morphisms\kl".
+\end{code}
+
+
+
+
+\subsection{Linking inside a document}
+
+
+\begin{problem}
+I am writing a long scientific document with many notions tied together
+(typically, I have made all my best for clarifying but nevertheless
+it remains obscure,
+or it is a long survey involving many subfields, or a book, or a PhD thesis\footnote{Reviewers should appreciate...}).
+I would like all the notions be linked inside the document for being able
+in one click, whenever something is used, to jump to its definition.
+However, I do not want it to be a hassle when writing.
+\end{problem}
+\medskip
+
+
+A solution is as follows. First load the "knowledge@@package" package in the preamble:
+\begin{code}[11cm]
+\kl\usepackage[\kl(option){xcolor},\kl(option){hyperref},\kl(option){notion},\kl(option){quotation}]\{"knowledge@@package"\}
+\end{code}
+\noindent with suitable options: \kl(option){hyperref} for links,
+\kl(option){xcolor} for colors (if required, but always advised), "quotation@@option" for using the "quotation notation" and \kl(option){notion} for automatic configuration of the "notion" "directive".
+
+%
+%
+Then write the document using \kl{\intro} (or \kl{""}$\cdots$\kl{""} if \kl(option){quotation} is activated) when a notion is defined/introduced, and
+\marginpar{\begin{hint} Using an \kl{\AP} command is strongly advised,
+ and allows to control more precisely where the target of hyperreferences is:
+ at the beginning of a paragraph is better than the beginning of the section several pages before...
+ \end{hint}}
+\kl{\kl} (or \kl{"}$\cdots$\kl{"} if \kl(option){quotation} is activated)when it is used. For instance:
+\begin{code}[12cm]
+\kl\AP{}
+A \kl\intro\{semigroup\} is an ordered pair \verb|$(S,\cdot)$| where \verb|$\cdot$| is an
+associative binary operator over~\verb|$S$|.\\
+\kl{[...]}\\
+\kl{\AP}
+A \kl\intro\{monoid\} \verb|$(M,\cdot,1)$| is a \kl\kl\{semigroup\} \verb|$(M,\cdot)$| together
+with a neutral element \verb|$1$|.
+\end{code}
+\noindent or when the "quotation notation" is activated:
+\begin{code}[12cm]
+\kl\AP{}
+A \kl{""}semigroup\kl{""} is an ordered pair \verb|$(S,\cdot)$| where \verb|$\cdot$| is an
+associative binary operator over~\verb|$S$|.\\
+\kl{[...]}\\
+\kl\AP{}
+A \kl{""}monoid\kl{""} \verb|$(M,\cdot,1)$| is a \kl"semigroup\kl" \verb|$(M,\cdot)$| together
+with a neutral element \verb|$1$|.
+\end{code}
+
+This yields
+\knowledgeconfigure{visible anchor points=true}%
+\marginpar{Note that the \kl{\AP} command is made visible thanks to a red corner.}
+\begin{PDFoutput}[10cm]
+\AP A \kl[_semigroup]{semigroup} is an ordered pair $(S,\cdot)$ where $\cdot$ is an
+associative binary operator over~$S$.\\
+\kl{[...]}\\
+A \kl[_monoid]{monoid}
+$(M,\cdot,1)$ is a \kl[_semigroup]{semigroup} $(M,\cdot)$ together
+with a neutral element~$1$.
+\end{PDFoutput}
+\knowledgeconfigure{visible anchor points=false}%
+\kl{Undefined knowledges} are in brown (it is an important feature that the compilation does not fail: undefined knowledges should not interfere with the writing of the document, which is the purpose of all this).
+One can now see the list of such problems in the file `\kl{filename.diagnose}'.
+One can in particular find in the "`Undefined knowledges' section":
+\begin{verbatim}
+\knowledge{semigroup}{}
+\knowledge{monoid}{}\end{verbatim}
+Which means that both `monoid' and `semigroup' are unknown \kl{knowledges}.
+
+\AP
+To solve this, let us copy these two (or more) lines in the paper\footnote{it is good practive to use a separate file, something like `paper-knowledge.tex'.}, adding the \kl{notion} directive (which is a configured version of the \kl{autoref} directive, meaning essentially that you want to use the features of the \kl{\intro} command), i.e., in the preamble:
+\begin{code}[6.7cm]
+\kl\knowledge\{semigroup\}\{\kl{notion}\}\\
+\kl\knowledge\{monoid\}\{\kl{notion}\}
+\end{code}
+The result is then (after two compilations):
+%
+\knowledgeconfigure{visible anchor points=true}%
+\begin{PDFoutput}[10cm]
+\knowledge{semigroup}{scope=document,notion}%
+\knowledge{monoid}{scope=document,notion}%
+\AP A \intro{semigroup} is an ordered pair $(S,\cdot)$ where $\cdot$ is an
+associative binary operator over~$S$.
+\kl{[...]}
+A \intro{monoid} $(M,\cdot,1)$ is a \kl{semigroup} $(M,\cdot)$ together
+with a neutral element~$1$.
+\end{PDFoutput}
+\knowledgeconfigure{visible anchor points=false}%
+%
+Clicking on `semigroup' now jumps to the place it was introduced, and very precisely at the
+location of the red corner depicting the presence of the \kl{\AP}-command.
+If now one adds the option \texttt{"paper"} while loading the package, then the colors and the red corner disappear:
+\begin{PDFoutput}[10cm]
+\knowledge{semigroup2}{scope=document,autoref}%
+\knowledge{monoid2}{scope=document,autoref}%
+\AP A \intro[semigroup2]{semigroup} is an ordered pair $(S,\cdot)$ where $\cdot$ is an
+associative binary operator over~$S$.
+\kl{[...]}
+A \intro[monoid2]{monoid} $(M,\cdot,1)$ is a \kl[semigroup2]{semigroup} $(M,\cdot)$ together
+with a neutral element~$1$.
+\end{PDFoutput}
+
+\AP
+It is very often the case that for plain english (or other languages) some terms can be used in several forms; verbs can be conjugated; nouns can be plural, and so on.
+\marginpar{\hint{ The \kl[\knowledge directives]{directives} \kl{synonym} and "link=" can be also convenient.}}%
+So usually the lines added to the file look more like:
+\begin{code}[10.7cm]
+\kl\knowledge\{semigroup\}[semigroups\vbar Semigroups]\{\kl{notion}\}\\
+\kl\knowledge\{monoid\}[monoid\vbar Monoids]\{\kl{notion}\}
+\end{code}
+\noindent
+Now, using code like
+\begin{code}[11cm]
+\kl"Monoids\kl" and \kl{"}semigroups\kl{"} play the same role from now.
+\end{code}
+\noindent will properly be linked to the definition of a semigroup and a monoid.
+
+
+
+\subsection{Mathematics}
+\label{subsection:mathematics scenario}
+
+The examples above show various techniques for using \kl{knowledges} for enhancing the information associated to terms. In fact, these techniques are not incompatible with mathematics. Imagine, for instance that you would like each time a macro \kl[@token]{\monoid} is met, to display $\mathcal M$, you would do for instance:
+\marginpar{\begin{hint} Defining new macros is best done using \kl{\newrobustcmd} (of the \texttt{etoolbox} package), rather than the usual \kl{\newcommand} of \LaTeX. This remark is general in \LaTeX{}, unless you have very specific reason to have your macro expandable. This is even more true when using "knowledge@@package"\end{hint}.}
+\begin{code}[7cm]
+\kl\newrobustcmd\kl[@token]\monoid\{\kl\mathcal\ M\}
+\end{code}\noindent
+Imagine that furthermore, you would like to hyperlink to the definition of a monoid. A standard \kl{\kl} command does the job\footnote{It is highly advised to not use the "quotation notation" is math mode or macros.}:
+\begin{code}[9cm]
+\kl\newrobustcmd\kl[@token]\monoid\{\kl\kl[monoid]\{\kl\mathcal\ M\}\}\\~
+What is \$\kl[@token]\monoid\$ ?
+\end{code}\noindent
+\noindent
+would yield:
+\begin{PDFoutput}[4cm]
+\newcommand \monoid{\kl[monoid]{\mathcal M}}
+What is $\monoid$ ?
+\end{PDFoutput}
+\begin{problem}
+But I want more. I want to be able to introduce variables.
+Even better, I would like to be able to have variables hyperlinking to the place of their introduction, knowing that the same variable name may mean different things depending on the lemma or proof we are in. Hence, I want to properly control the scope of knowledges.
+\end{problem}
+
+\AP To be done, this requires to use \kl{scoping}. The principle of \kl{scoping} is that a knowledge can be
+attached to a particular context. This is particularly true when typesetting mathematics: a variable is meaningful inside a statement, and inside the proof of the statement. Furthermore, the same variable name may reappear elsewhere with a different meaning.
+
+The following code gives an idea of what is possible using \kl{scoping}:
+\begin{code}
+\kl\knowledgeconfigureenvironment\{theorem,lemma,proof\}\{\}\par\noindent
+\kl{[...]}\par\noindent
+\kl\begin\{lemma\}\kl\label\{theorem:main\}\par\noindent
+~~~~\kl\knowledge\{n\}\{\kl{notion}\}\par\noindent
+~~~~For all number~\$\kl\intro\ n\$, \kl{[...]}\par\noindent
+\kl\end\{lemma\}\par\noindent
+\kl{[...]}\par\noindent
+Here \$\kl\kl\ n\$ is an undefined knowledge.\par\noindent
+\kl{[...]}\par\noindent
+\kl\begin\{proof\}[Proof of theorem\~\space\{theorem:main\}]\par\noindent
+~~~~\kl\knowledgeimport\{theorem:main\}\par\noindent
+~~~~Inside the proof, \$\kl\kl\ n\$ is hyperlinked to the theorem...\par\noindent
+\kl\end\{proof\}
+\end{code}
+More on \kl{scoping} can be found in Section~\ref{subsection:scoping}.
+
+
+\newpage
+
+\section{Usage of the "knowledge@@package" package}
+\label{section:doc}
+
+\iffalse
+We shall now give a more complete description of the functionalities of the "knwoeldge@@package".
+\ref{subsection:loading packages}
+\ref{subsection:knowledge command}
+\ref{subsection:kl command}
+\ref{subsection:diagnose file}
+\ref{subsection:hyperref package}
+\ref{subsection:xcolor package}
+\ref{subsection:makeidx package}
+\fi
+
+\subsection{Options and configuration}
+\label{subsection:loading packages}
+
+Options are used to activate some capabilities.
+Some options have to be used when loading the "knowledge@@package" package, while some others
+can also be used inside the document thanks to the use of \kl{\knowledgeconfigure}.
+In this section, we review these ""package options"".
+
+\subsubsection{Options at package loading}
+
+The options that can be used in the optional parameter of \kl{\usepackage} when loading the "knowledge@@package" package belong to the following classes:
+\begin{compactdesc}
+\itemAP[Writing mode] The "paper", "electronic" or "composition" modes are possible ("composition" is by default) (see Section~\ref{subsubsection:writing modes} for more details).
+These modes change several default rendering settings.
+\itemAP[Other packages] some of the options concern the loading and the use of other packages (\kl(package){hyperref}, \kl(package){xcolor}, \dots). This is explained in Section~\ref{subsubsection:packages-loading}.
+\itemAP[Configuration options] as used by the command \kl{\knowledgeconfigure} can be used when loading the package.
+\itemAP[Scoping] The \kl[scope option]{scope} "option@package option" makes the package aware at a fine level of the structure of the document (see Section~\ref{subsection:scoping} for explanations). This provides, for instance, the possibility to define pieces of "knowledge" that it attached to a section of the documents.
+\end{compactdesc}
+
+\subsubsection{Writing stages}
+\label{subsubsection:writing modes}
+Other "package options" of "knowledge@@package" concern the ""writing modes"". There are three of them:
+\begin{itemize}
+\itemAP In ""paper"" mode, the paper is rendered as for printing: in particular, no informative colors are visible. Hyperlinks are nevertheless present.
+\itemAP In ""electronic"" mode, the document has some colors witnessing the existence of the links for the reader to know that clicking is available.
+\itemAP In ""composition"" mode, the document has colors helping the writing: "undefined knowledges" appear explicitly, "anchor points" are displayed, and so on.
+\end{itemize}
+Activating the modes is obtained either at load time using one of:\\
+\begin{tabular}[t]{ll}
+ &\smallcode{\kl\usepackage[\kl{paper}]\{"knowledge@@package"\}}\\[2mm]
+or\quad&\smallcode{\kl\usepackage[\kl{electronic}]\{"knowledge@@package"\}}\\[2mm]
+or &\smallcode{\kl\usepackage[\kl{composition}]\{"knowledge@@package"\}}
+\end{tabular}\\
+\AP or by setting before loading the variable \intro{\knowledgepackagemode} as in:\\
+\begin{tabular}[t]{ll}
+ &\smallcode{\kl\def\kl\knowledgepackagemode\texttt\{\kl{paper}\texttt\}}
+\end{tabular}\\
+The idea is that this can be used in automatic compilation scripts. For instance, launching in a terminal:\\
+\begin{code}[12cm]
+\smallcode{\texttt{pdflatex} \quotationmark\kl\def\kl\knowledgepackagemode%
+ \texttt\{\kl{electronic}\texttt\}\kl\input\texttt\{file.tex\texttt\}\quotationmark}
+\end{code}
+would result in compiling `\texttt{file.tex}' using "knowledge@@package" in
+"electronic mode".
+
+The following primitives are available in order to be mode-dependent:\\
+\begin{code}[11.2cm]
+\AP
+\intro\IfKnowledgePaperModeTF\texttt\{true code\texttt\}\texttt\{false code\texttt\}\\
+\AP
+\intro{\IfKnowledgePaperMode} true code [\kl{\Else} false code] \kl{\Fi}\\
+\AP
+\intro{\IfKnowledgeElectronicModeTF}\texttt\{true code\texttt\}\texttt\{false code\texttt\}\\
+\AP
+\intro{\IfKnowledgeElectronicMode} true code [\kl{\Else} false code] \kl{\Fi}\\
+\AP
+\intro{\IfKnowledgeCompositionModeTF}\texttt\{true code\texttt\}\texttt\{false code\texttt\}\\
+\AP
+\intro{\IfKnowledgeCompositionMode} true code [\kl{\Else} false code] \kl{\Fi}
+\end{code}
+
+
+\subsubsection{Automatic loading of other packages}
+\label{subsubsection:packages-loading}
+A certain number of "package options" coincide with the loading of other packages.
+For the moment, the packages that are concerned are \kl(option){hyperref},
+\kl(option){xcolor}, and \kl(option){makeidx}.
+
+For activating these functionalities, it is sufficient, either to load the package \emph{before} the "knowledge@@package" package, or to name it explicitly as an "option@package option" for "knowledge@@package".
+Loading separately the package is convenient for setting options for it. For instance,
+a typical preamble may look like:
+\begin{code}[7cm]
+\kl\documentclass\{article\}\\
+%\kl\usepackage[utf8]\{inputenc\}\\
+%\kl\usepackage[T1]\{fontenc\}\\
+\kl\usepackage[svgnames]\{\kl(package){xcolor}\}\\
+\kl\usepackage[\texttt{draft}]\{\kl(package){hyperref}\}\\
+\kl\usepackage[\kl(package){makeidx}]\{"knowledge@@package"\}
+\end{code}\noindent
+Such a sequence will activate the "knowledge@@package" package using the features related to \kl(package){xcolor} configured with \texttt{svgnames} option, to \kl(package){hyperref} configured with \texttt{draft} option, and to \kl(package){makeidx} with its standard configuration.
+
+
+
+In fact, the syntax when a package is loaded as an option of "knowledge@@package" is of the form
+`package=choice' in which choice can take the following values:
+\begin{description}
+\itemAP[\intro{active}] The package will be loaded, and all the capabilities that it triggers are activated.
+This is the implicit meaning when nothing more is specified.
+\item[\intro{inactive}] The package is not loaded, and no capabilities are activated (even if it had been loaded previously by another |\usepackage| command).
+\item[\intro{compatibility}] The package is not loaded. The directives it used do not cause any error, but have no effect.
+\item[\intro{auto}] If the package was loaded before, then the associated capabilities are activated. This is the default behavior when the package is not named while loading.
+\end{description}
+Currently, the packages that can be loaded are:
+\begin{description}
+\itemAP[\kl(package){hyperref}] which activates all the (auto)referencing capabilities.
+\item[\kl(package){xcolor}] which activates coloring commands.
+\item[\kl(package){makeidx}] for handling the index automatically.
+\end{description}
+
+\subsubsection{Configuring and \kl{\knowledgeconfigure}}
+
+Some part of the configuration can be done outside of the \kl{\usepackage} command that loads the "knowledge@@package" package. \AP This is done using the
+\kl{\knowledgeconfigure} command:
+\begin{center}
+\smallcode{\intro\knowledgeconfigure\{\kl{configuration directives}\}}
+\end{center}
+Note that by default, the \kl{configuration directives} used by \kl{\knowledgeconfigure} can
+be used in the optional parameter of \kl{\usepackage} when loading the "knowledge@@package" package, but the converse is not true.
+""Configuration directives"" consists of a comma separated list of elements that can take the following values:
+
+\begin{description}
+\itemAP[""diagnose line=""] can be set to true or false. It activates or deactivates the line numbering in the "diagnose file".
+\itemAP[\kl{fix hyperref twocolumn}] triggers a hack that solves a known problem that may occur when "hyperref@@package" is used in two-columns mode.
+\itemAP["notion@@option"] configures the "notion" "directive" which is a refined version of "autoref".
+\itemAP["protect quotation="] is followed by a comma separated list of environments in which the "quotation notation" will be automatically deactivated (surrounded by braces if more than one item in the list).
+\itemAP[\intro{protect link co} and \intro{unprotect link co}] starts and ends respectively a zone in which the "knowledge@@package" package do not create hyperlinks. These can be nested.
+This is typically useful around, e.g. the table of contents.
+\itemAP[\kl(option){quotation}] activates the "quotation notation", which allows to use \kl{"..."}, \kl{"...@..."} and \kl{"...@...@..."}
+ instead of \kl{\kl} commands and \kl{""...""}, \kl{""...@...""} and \kl{""...@...@...""} instead of the \kl{\intro} command.
+\itemAP[\kl{visible anchor points}] is an option that makes visible or invisible the \kl{anchor points} of the \kl{\AP} and \kl{\itemAP} commands.
+\end{description}
+
+
+%\subsubsection{Other configuration}
+
+%Another option at loading is "scope@scope option": it is used for activating some macros for keeping track of the structure of the document. This is in particular helpful for making "knowledges" attached to specific parts of the document, or helping in the resolution of ambiguities. See Section~\ref{subsection:scoping} for more information on its use.
+
+\subsection{What is a \kl{knowledge}?}
+
+A \intro{knowledge} is often informally used in this document. Essentially, it captures what is an elementary concept in the document.
+Internally, a \kl{knowledge} is identified by three components:
+\begin{compactdesc}
+\itemAP[The \intro{knowledge name}] is a \kl{tex} string that has almost no limitation (but being well balanced, and containing no $\sharp$). It is the text entered by the user for defining and using the \kl{knowledge}.
+\itemAP[The \intro{scope}] which is a simple string identifying where the \kl{knowledge} is usable. The scopes are generated by the system.
+ For instance, internally, each section will be uniquely named `\texttt{section-1}', `\texttt{section-2}', and so on (this is invisible for the user). Each \kl{knowledge} is primarily valid in
+ exactly one such \kl{scope}. \kl{Knowledges} defined in the preamble are given the \kl{scope} `\texttt{document}'.
+ Usually, the user refers to scope using, for instance, labels.
+\itemAP[The \intro{namespace}] is a simple string that is used for avoiding clashes. It is most of the time simply `\texttt{default}'. It is `\texttt{style}' for \kl{styles} (that are internally as knowledges).
+ It is a possibility available to a developer to, when developing a new set of functionalities, use a different \kl{namespace} for avoiding clashes of names (for instance if one wants a french and an english set of knowledges that should not conflict, and would use separate sets of macros).
+ Usually, a normal user does not see \kl{namespaces}.
+\end{compactdesc}
+
+
+
+\subsection{The \kl{\knowledge} command and variations}
+\label{subsection:knowledge command}
+
+In this section, we describe the main commands that create \kl{knowledges}.
+The main one is \kl{\knowledge}. It can also be used in combination with \kl{\knowledgedirective}, \kl{\knowledgestyle} and \kl{\knowledgedefault}.
+
+\subsubsection{General description of the \kl{\knowledge} command}
+
+The key command for introducing knowledges is \kl{\knowledge}.
+The syntax is:
+\begin{center}
+\smallcode{\intro\knowledge\{\kl[\knowledge knowledge name]{knowledge name}\}%
+ [\kl[\knowledge synonyms]{synonyms}]\{\kl[\knowledge directives]{directives}\}}
+\end{center}
+
+\AP
+The \intro[\knowledge knowledge name]{knowledge name} is a string describing the knowledge. It may use any combination of symbols (well balanced with respect to brackets).
+This string will be used to fetch the \kl{knowledge}. Note (and this is a standard \kl{tex} behavior) that several consecutive spaces is the same as one or a line feed.
+\AP The \intro[\knowledge synonyms]{synonyms} are \kl[\knowledge knowledge name]{knowledge names} given in a `\vbar' separated list. This is a
+shorthand for writing `\kl{link=}' \kl[\knowledge directives]{directives}. (Note that there is another way to define synonyms using the \kl{synonym} directive).
+\AP
+The \intro[\knowledge directives]{directives} consists of `key=value' statements in a comma separated list.
+There are many \kl[\knowledge directives]{directives}. A list can be found in Section~\ref{subsection:directive list}. New ones can be defined using the \kl{\knowledgedirective} command.
+
+\AP
+The principle of the \kl{\knowledge} command is to introduce a new \kl{knowledge}, ready for being used.
+However, what it does exactly depends a lot on the situations.
+First, the \kl[\knowledge directives]{directives} (a comma separated list of `key=value' commands) are parsed, and from it, the namespace and scope of the knowledge are determined, and it is decided if it will be executed immediately or postponed to the next compilation phase.
+Only then, either the \kl{knowledge} is written in the \kl{kaux file} for execution during the next compilation phase, or it is executed immediately.
+Finally, \kl[\knowledge synonyms]{synonyms} are parsed and linked to the \kl{knowledge}.
+
+\subsubsection{Targeting and the corresponding directives}
+
+The \kl{\knowledge} has to decide what to do when defining something. The basic behaviour is as follows.
+\begin{itemize}
+\item If the \kl{\knowledge} command is used in the preamble, then the \kl{knowledge} given as argument is defined immediately (the same effect can be obtained using the \kl{now} "directive"), and is accessible in the first compilation phase everywhere in the document (one extra phase is nevertheless required if \kl{autoref} or \kl{ref=} directives are used, for the "hyperref@@package" to do its job, or if "scope=" is used). This is the simplest way to use \kl\knowledge.
+\item Import/Export (\kl{not implemented}) writes a document containing a list of \kl{\knowledge} commands giving access to its content. This is to be imported by another document.
+\item Otherwise, the \kl{knowledge} is written in an external file (the \kl{jobname.kaux} file), and the \kl{knowledge} will be really usable in the next compilation phase. This is particularly useful in conjunction with the \kl{scope option}: the \kl{knowledge} will have a scope depending on where it is introduced (for instance the document, or a theorem, or a lemma). The same \kl{knowledge name} can then point to different \kl{knowledges} depending on where it is used.
+\end{itemize}
+
+The \intro{targeting directives} refine the above defined behaviour:
+\begin{description}
+\itemAP[\intro{scope=}] When using a \kl[\knowledge directives]{directive} `\kl{scope=}name', the scope of the definition can be modified.
+ \kl{\knowledge} will first check if there is an outer \kl{area} of this name, that accepts knowledge (only
+ "scope@@env" environments are subject to this unless \kl{\knowledgeconfigureenvironment} is used, or
+ the "scope@@option" "package option" is used when loading the package).
+If this is the case, the knowledge will be associated to the corresponding \kl{instance}. For instance, inside a theorem, by default, the scope is the theorem, but adding the directive `\kl{scope=}section', the \kl{knowledge} becomes available in the whole section.
+
+If no scope is found using the above search, a label of the given name is searched for, and if it exists, the corresponding scope is chosen.
+\itemAP[\intro{export=}] (\kl{not implemented}) When using this directive, the knowledge will be (furthermore) written in another file, ready for being used in another document. In particular, the knowledge (in the other document) will point to the present one. The details on how this is supposed to work is to be specified.
+\itemAP[\intro{namespace=}] Allows to change the \kl{namespace}. In itself, this is useless. It has to be used in conjunction with new forms of \kl\kl-like commands.
+\itemAP[\intro{now}] requires the \kl{knowledge} to be defined immediately. This may save one compilation phase. The drawback is that the \kl{knowledge} cannot be accessed before the \kl{\knowledge} command that has been introduced. It may help for modularity considerations. (for instance a \kl{knowledge}
+is used inside a proof, it has no sense to make it available elsewhere, and it is better style to locally define it).
+\end{description}
+
+
+\subsubsection{General directives}
+
+We give here the list of \intro{display directives} that are available without loading any sub packages.
+A certain number of Boolean directives are available without any options. These most of the time are used for typesetting the output. Each of these can be used as
+`\texttt{bool=true}' (or shortly just `\texttt{bool}'), `\texttt{bool=false}' or `\texttt{bool=default}'
+(that leaves it in the default state, or the one determined by surrounding knowledges).
+The general boolean \kl[\knowledge directives]{directives} are the following:
+\begin{description}
+\itemAP[\intro{emphasize}] forces the text to be emphasized using `\kl{\emph}',
+\itemAP[\intro{italic}/\intro{up}] forces/unforces italic (be it in math or text mode),
+\itemAP[\intro{boldface}/\intro{md}] forces/unforces boldface (be it in math or text mode),
+\itemAP[\intro{underline}] forces the text to be emphasized using `\kl{\underline}',
+\itemAP[\intro{fbox}] puts a box around the text,
+\itemAP[\intro{typewriter}] puts in typewriter font (be it in math or text mode),
+\itemAP[\intro{ensuretext}] guarantees that text mode is used (using the `\kl{\text}' macro, thus in a
+way consistent with the surrounding style),
+\itemAP[\intro{ensuremath}] guarantees that math mode is used,
+\itemAP[\reintro{mathord}, \reintro{mathop}, \reintro{mathbin}, \reintro{mathrel}, \reintro{mathopen}, \reintro{mathclose}, \reintro{mathpunct}]
+yield the corresponding standard \TeX{} spacing features in math mode,
+ \begin{description}
+ \item[\intro{mathord}] for an ordinary mathematical object,
+ \item[\intro{mathop}] for a large operator (such as $\sum$, $\prod$, \dots),
+ \item[\intro{mathbin}] for a binary operation (such as $+$, $-$, or $\otimes$, \dots),
+ \item[\intro{mathrel}] for a binary relation (such as $=$, $<$, $\leq$, \dots),
+ \item[\intro{mathopen}] for an opening bracket, parenthesis, \dots
+ \item[\intro{mathclose}] for an closing bracket, parenthesis, \dots
+ \item[\intro{mathpunct}] for a punctuation symbol.
+ \end{description}
+\itemAP[\intro{lowercase}] puts the content in lowercase,
+\itemAP[\intro{uppercase}] puts the content in uppercase.
+\end{description}
+
+
+\AP The non-boolean general \kl[\knowledge directives]{directives} are the following:
+\begin{compactdesc}
+\itemAP[\intro{text=}\textmd{\{text\}}] will execute the \LaTeX{} code `text' instead of the key used for calling \kl\kl. For instance,
+ \smallcode{\kl\knowledge \{latex\}\{\kl{text=}\kl{\LaTeX}\}} will typeset `\LaTeX{}' properly when used. Surrounding braces can be omitted if there are no commas. Be careful when linking to such knowledges, since the substitution of meaning will happen for all the knowledges linking to it.
+\itemAP[\intro{link=}\textmd{\{knowledge\}}] will continue searching the for linked \kl{knowledge}. Surrounding braces can be omitted if there are no commas.
+ This directive is often bypassed by the use of the \kl[\knowledge optional argument]{optional argument} of \kl{\knowledge} defining synonyms or the \kl{synonym} directive.
+\itemAP[\intro{link scope=}\textmd{\{label\}}] will continue searching in the "scope" identified by the label. Surrounding braces can be omitted if there are no commas. If no "directive" "link=" is given, then the same key is searched for.
+
+ This directive is often bypassed by the use of the \kl[\knowledge optional argument]{optional argument} of \kl{\knowledge} defining synonyms or the \kl{synonym} directive.
+\itemAP[\intro{synonym}] defines the knowledge as a link to the previously defined knowledge (in fact, the most recently defined that was not using \kl{synonym}). For instance
+\begin{code}[11cm]
+\kl\knowledge\{Leslie Lamport\}\par
+~~~~~\{\kl{ref=}\{https://fr.wikipedia.org/wiki/Leslie_Lamport\}\}\\
+\kl\knowledge\{L. Lamport\}\{\kl{synonym}\}\\
+\kl\knowledge\{Lamport\}\{\kl{synonym}\}
+\end{code}\noindent
+results in the two subsequent \kl{knowledge names} to point to the first one.
+\itemAP[\intro{style=}\textmd{\{knowledge style\}}] will adopt the styling option of the \kl{knowledge style}. Surrounding braces can be omitted if there are no commas.
+\itemAP[\intro{wrap=}\textmd{\robustdisplay\token}] will execute the macro `\textmd{\robustdisplay\token}' with as argument the knowledge text before displaying it. For instance,
+\kl{wrap=}\kl\robustdisplay,
+(where \intro{\robustdisplay} is a variant of \kl{\detokenize} removing the trailing space) is used in this document for typesetting the commands.
+\end{compactdesc}
+
+
+\subsubsection{\kl{Knowledge styles} and the \kl{\knowledgestyle} command}
+\label{subsubsection:knowledge styles}
+
+\intro{Styles} are formatting pieces of information, as for \kl{knowledges}, but that can be used by other \kl{knowledges}. In some respect, this is very similar to \kl{macro directives} (see below), but the difference lies in that \kl{styles} are dynamically resolved, while \kl{macro directives} are statically resolved. \kl{Styles} in particular offer the access to some configuration features of the system.
+For instance, changing the \kl(style){intro} \kl{style} changes the way the \kl{\intro} command is displayed.
+See below for some instances.
+
+\AP
+The central command is \kl{\knowledgestyle}, that has the following syntax:
+\begin{center}
+\smallcode{\intro\knowledgestyle*\{style name\}\{\kl[\knowledge directives]{directives}\}}
+\end{center}
+The optional star permits to overload an existing style (otherwise, this results in an error). The \kl[\knowledge directives]{directives} follow the same structure as for a normal \kl{\knowledge}
+command. When defined, a \kl{style} can be used in a \kl{\knowledge}
+command using the \kl[\knowledge directives]{directives} `\kl{style=}style name' (it will be used when a \kl{\kl} command calls for the \kl{knowledge}) or `\kl{intro style=}style name' (that will be used by \kl{\intro} commands).
+
+\AP
+A certain number of \intro{default styles} are also offered, that in particular includes \intro{warning styles}. The list is as follows:
+\begin{compactdesc}
+\itemAP[""intro@@style""] is the default style for macros using \kl{\intro}.
+ It can be changed using the `\kl{intro style=}' \kl[\knowledge directives]{directive} (after \kl{autoref}).
+\itemAP[""unknown@@style""] is the default \kl{style} used for the first time an undefined \kl{knowledge} is met.
+\itemAP[""intro unknown@@style""] is the default \kl{style} used when an undefined \kl{knowledge} is met.
+%\itemAP[""autoref not introduced@@style""] is the \kl{style} used the first time a \kl{knowledge} has been used using the \kl{autoref} directive, but there is no corresponding \kl{\intro} (\kl{not implemented}).
+%\itemAP[""autoref reintroduced@@style""] is the \kl{style} used when a \kl{knowledge} defined with the \kl[\knowledge directives]{directive} \kl{autoref} has be found twice in an \kl{\intro} command (\kl{not implemented})
+\end{compactdesc}
+
+\subsubsection{New directives: the \kl{\knowledgedirective} command}
+\label{subsubsection:macro directives}
+
+When defining \kl{knowledges}, it is often the case that the same
+sequence of directives are used. \intro{Macro directives} are here for simplifying this situation (see also \kl{\knowledgedefault} and \kl{\knowledgestyle}). This is achieved using the \kl{\knowledgedirective} directive:
+\marginpar{\begin{hint} This should not be confused with \kl{styles} which offer another way to control the display.\end{hint}}
+\begin{center}
+ \smallcode{\intro{\knowledgedirective}\{name\}[optional parameter]\{directives\}}
+\end{center}
+After such a command has been issued, `name' becomes a \kl[\knowledge directives]{directive}
+usable in \kl{\knowledge} commands, that amounts to execute the comma separated list `directives'. The newly created \kl[\knowledge directives]{directive} may receive a value, that is accessible as \texttt{\#1} in `directives'. The `optional parameter' gives
+a default value. For instance:
+\begin{code}
+\kl\knowledgedirective\{highlight\}[brown]\{\kl{color=}\{\#1\},\kl{emphasize},\kl{md}\}\\{}
+\kl{[...]}\\{}
+\kl\knowledge\{notion A\}\{highlight\}\\
+\kl\knowledge\{notion B\}\{highlight\}\\
+\kl\knowledge\{notion C\}\{highlight\}\\
+\kl\knowledge\{important notion D\}\{highlight=red\}\\{}
+\kl{[...]}\\
+We shall now see \kl\kl\{notion A\}, \kl\kl\{notion B\}, \kl\kl\{notion C\}, as well as the \kl\kl\{important notion D\}.
+\end{code}
+\noindent
+yields
+\begin{PDFoutput}
+\knowledgedirective{highlight}[brown]{color={#1},emphasize,md}
+\knowledge{notion A}{highlight}
+\knowledge{notion B}{highlight}
+\knowledge{notion C}{highlight}
+\knowledge{important notion D}{highlight=red}
+We shall now see \kl{notion A}, \kl{notion B}, \kl{notion C}, as well as the \kl{important notion D}.
+\end{PDFoutput}
+
+\subsubsection{\kl{\knowledgestyle} versus \kl{\knowledgedirective}}
+\label{subsubsection:style versus macro}
+
+The two commands \kl{\knowledgestyle} and \kl{\knowledgedirective}
+offer ways to systematize the writing of knowledges. These can seem redundant.
+This is not the case, and for understanding it, it is necessary to understand a bit the way the \kl{\knowledge} command works.
+
+In general when a \kl{\knowledge} (or \kl{\knowledgestyle}) command is found, the \kl[\knowledge directives]{directives} are parsed and a new internal form of the \kl{\knowledge} command is written in the \kl{kaux file}, that will be executed during the next compilation of the document.
+In this phase, some first operations are performed. For instance, in an \kl{autoref} \kl[\knowledge directives]{directive}, an internal label name is constructed. Executing a \kl{knowledge macro} is done at this moment.
+
+The postponed command is then executed during the next compilation phase (or immediately if we are in the preamble, or if the \kl{now} directive is used). The execution effectively stores the \kl{knowledge} in the system. This is only at that moment that the \kl{knowledge} becomes available to be used by \kl{\kl} and similar commands.
+
+When a \kl{\kl} command (or similar) is met, it is `executed', and display informations are considered, and in particular \kl{styles} are called.
+
+Somes consequences of this kind of this are as follows:
+\begin{itemize}
+\item \kl{autoref} directives should not be used in the definition of a \kl{style}, since this would mean that
+ there would be one anchor point for all the \kl{knowledges} that use this \kl{style}. This is usually not the kind of behavior that we expect.
+\item configuring the default displays of the system (such as the \kl{intro style=} in particular) has to be done through the \kl{style} mechanism.
+\item \kl{styles} use less memory than macros.
+\end{itemize}
+
+\subsubsection{\kl{Default directives}: the \kl{\knowledgedefault} command}
+\label{subsubsection:default directives}
+
+It may happen that a sequence of consecutive \kl{\knowledge} commands have to share the same list of \kl[\knowledge directives]{directives}. The \kl{macro directives} can help solving this issue. The \intro{default directives} also go in this direction, using the \kl{\knowledgedefault} command:
+\begin{center}
+\smallcode{\intro\knowledgedefault*\{\kl[\knowledge directives]{directives}\}}
+\end{center}
+When such a command is applied, then from that point, all \kl{\knowledge} commands
+will use the given \kl[\knowledge directives]{directives} as default. This will stop when another \kl{\knowledgedefault} command is met or the current group is closed.
+The optional star does not reset the \kl{default directives} but simply add new ones.
+
+
+
+
+\subsection{The \kl{\kl} command}
+\label{subsection:kl command}
+
+\subsubsection{The standard syntax}
+
+\marginpar{\begin{hint} Note that the \kl{\kl} command can often be replaced by the
+\kl{"..."}{} notation, activated by the "quotation@@option" option.\end{hint}}
+
+
+The \kl{\kl} command has one of the following syntaxes:
+\begin{center}
+\begin{tabular}{cc}
+&\smallcode{\intro{\kl}(\kl[klab]{optional label})[\kl[knowledge name]{optional knowledge name}]\{text\}}\\
+or\quad&
+\smallcode{\reintro{\kl}[\kl[knowledge name]{optional knowledge name}](\kl[klab]{optional label})\{text\}}
+\end{tabular}
+\end{center}
+its semantic is to search for the `optional knowledge name' if present, or for `text' otherwise. How this is exactly performed depends on the presence of the \kl[klab]{optional label}.
+The search process is as follows:
+\begin{asparaitem}
+\itemAP if an \intro[klab]{optional label} is given, the \kl{knowledge} is searched in the corresponding scope.
+\itemAP otherwise, the \kl{stack of visible scope instances} is processed through (starting from the inner most)
+ until a \kl{knowledge} of name `\kl{knowledge name}' or `text', of \kl{namespace} `default' and this \kl{scope}
+ is found.
+
+ If the `knowledge name/text' has not been found, the \kl{style} `"unknown@@style"' is used, and the
+ text displayed.
+\item Otherwise, the \kl{knowledge} is executed. If it is a \kl{link=} or \kl{synonym} defined \kl{knowledge}, the link is followed, and the process continues.
+\item Finally, all the definitions involved in the \kl{knowledge} are processed, following a \kl{style=} if defined, the \kl{knowledge} is updated (essentially incrementing the counter of use), and the \kl{knowledge} is displayed.
+\end{asparaitem}
+This general mechanism is used also by other commands that are variations around \kl{\kl} such as in particular \kl{\intro}.
+
+
+
+
+\subsubsection{The "quotation notation"}
+
+\phantomintro{"}\phantomintro{@}\phantomintro{quotation notation}%
+When activated, the ""quotation@@option"" mode activates shorthand
+notations for the \kl{\kl} and \kl{\intro} macros. Possible syntaxes are as follows:
+\begin{description}
+\itemAP[\smallcode{\kl"text\kl"}]\phantomintro{"..."}%
+ uses the "knowledge" pointed to by `text'. Equivalent to~\texttt{\kl\kl\{text\}}.
+\itemAP[\smallcode{\kl"text@knowledge\kl"}]\phantomintro{"...@..."}%
+ uses the "knowledge" pointed to by `knowledge to display `text'. Equivalent to~\texttt{\kl\kl[knowledge]\{text\}}.
+\itemAP[\smallcode{\kl"text@@label\kl"}]\phantomintro{"...@@..."}%
+ uses the "knowledge" pointed to by `text' in "scope" `scope' to display `text'. Equivalent to~\texttt{\kl\kl(label)\{text\}}.
+\itemAP[\smallcode{\kl"text@knowledge@label\kl"}]\phantomintro{"...@...@..."}%
+ uses the "knowledge" pointed to by `knowledge in "scope" `scope' to display `text'. Equivalent to~\texttt{\kl\kl[knowledge](label)\{text\}}.
+\itemAP[\smallcode{\kl{""}text\kl{""}}]\phantomintro{""...""}%
+ introduces the "knowledge" pointed to by `text'. Equivalent to~\texttt{\kl\intro\{text\}}.
+\itemAP[\smallcode{\kl{""}text@knowledge\kl{""}}]\phantomintro{""...@...""}%
+ introduces the "knowledge" pointed to by `knowledge while displaying `text'. Equivalent to~\texttt{\kl\intro[knowledge]\{text\}}.
+\itemAP[\smallcode{\kl{""}text@@label\kl{""}}]\phantomintro{""...@@...""}%
+ introduces the "knowledge" pointed by `text' in "scope" `scope'. Equivalent to~\texttt{\kl\intro(label)\{text\}}.
+\itemAP[\smallcode{\kl{""}text@knowledge@label\kl{""}}]\phantomintro{""...@...@...""}%
+ introduces the "knowledge" pointed to by `knowledge in "scope" `scope' while displaying `text'. Equivalent to~\texttt{\kl\intro[knowledge](label)\{text\}}.
+\end{description}
+
+\noindent\AP Activating and deactivating the "quotation notation" is obtained using:
+\begin{center}
+\smallcode{"\knowledgeconfigure"\{"quotation@@option"\}}\ ,
+\end{center}
+and deactivating it is obtained using:
+\begin{center}
+\smallcode{"\knowledgeconfigure"\{"quotation@@option"=false\}}.
+\end{center}
+It can also be activated while loading the package.
+
+\AP It is sometimes the case that some packages do use the quote symbol, usually in some environment
+(this is the case of the "tikzcd@@env" environment). The "knowledge@@package" package can be configured to deactivate always the "quotation notation" when entering the environment. This is obtained using the "configuration option" ""protect quotation="" followed by a list of environments to be protected:
+\begin{code}[12cm]
+\kl\knowledgeconfigure\{"protect quotation="\{env1,env2,\dots\}\}
+\end{code}
+Note that the braces surrounding the list of environments can be omitted if the list contains only one item.
+
+There are nevertheless some situations in which one would prefer to use the original \kl{\kl} notation:
+\begin{itemize}
+\item When nesting of "knowledges" is involved, or the "knowledge" includes the symbol \kl",
+\item when "quotation@@option" is deactivated (or not activated) because of a conflict
+\item in particular, this should be avoided in macros, in particular for the math mode, since these may be used one day or another in a "tikzcd@@env" or similar environment for instance.
+\end{itemize}
+
+\subsection{Scoping}
+\label{section:scopes}\label{subsection:scoping}
+\phantomintro{scoping}
+
+Rapidly, when long documents are in construction, one wants \kl{knowledges} to be isolated in some subparts. For instance, one may want that a temporary definition in a proof to not leak elsewhere in the document where the same term could be used with a different meaning. Some definitions may be only meaningful in, say, the current section/part. This is in particular true when one aims to track single variables: Clearly, a variable named $x$ can occur in several lemmas, but each of them correspond to a distinct `introduction' location. For handling this situation, the "knowledge@@package" package possesses some scoping features.
+
+\subsubsection{What is the structure of \kl{scopes} in a document}
+
+To start with, one needs to understand what are the possible \kl{scopes}.
+\begin{itemize}
+\itemAP By default, all the body of the document belongs to a \kl{scope} called `\texttt{document}'.
+ The user can open new scopes using the \intro(env){scope} environment:
+ \begin{code}[10cm]
+ \kl\begin\{\kl(env){scope}\}\par
+ ~~\kl\knowledge\{local notion\}\{\kl{color=}green\}\par
+ ~~Here is a \kl\kl\{local notion\} that appears in green.\par
+ \kl\end\{\kl(env){scope}\}\\
+ But this \kl\kl\{local notion\} is undefined.
+ \end{code}
+ Note that scoping is independent from the grouping mechanism of \LaTeX.
+
+ \AP The user can also declare an environment (existing or to exist)
+ to behave like \kl(env){scope} using the
+ command \kl{\knowledgeconfigureenvironment}.
+ \itemAP The use of the ""scope@scope option"" \kl{configuration option} reconstructs the structure of the document, and \kl{scopes} will be created for sections, subsections, itemize, items, and so on. But be cautious, this feature, though working, remains experimental in this version of the package.
+\end{itemize}
+
+\subsubsection{How is chosen the \kl{scope} of a \kl{knowledge}}
+
+In general, when a \kl{\knowledge} command is used, the system tries to figure out what should be its "scope":
+\begin{itemize}
+\item If the command occurs in the preamble, then the default \kl{scope} will be `document'.
+\item \AP Otherwise, the information is searched for in the ""stack of visible scope instances"" which means that the \kl{knowledge} will be defined at the level of the innermost surrounding scope that `attracts knowledges'. If the \kl{scope option} is not activated (and the user dod not perform its own configuration), this is the inner most \kl(env){scope} environment (or similar environment if \kl{\knowledgeconfigureenvironment} has been used), or `document' if the declaration is not in the scope. If the \kl{scope option} is used, this will be the innermost lemma, proof, or theorem in the context.
+\item This default behavior can be modified using the \kl{scope=} directive. The \kl{scope=} directive can be followed with a scope level, such as `section', `subsection', 'chapter' or `itemize' (in particular in combination with the \kl{scope option}), that will be looked for in the current context and will receive the \kl{knowledge}. The \kl[\knowledge directives]{directive} can also be followed by a label name, and the active scope at the moment of this label will be used.
+
+The following code (that requires the "scope option" for being functional) should be self explanatory:
+ \begin{code}[11.5cm]
+ \kl\section\{First section\}\par\noindent
+ \kl\label\{section:first\}\par\noindent
+ \kl\knowledge\{one\}\{\kl{scope=}section,\kl{color=}green\}\par\noindent
+ \kl\knowledge\{two\}\{\kl{scope=}some label,\kl{color=}green\}\par\noindent
+ ~\par\noindent
+ \kl\begin\{\kl(env){scope}\}\kl\label\{some label\}\par\noindent
+ ~~Here \kl\kl\{one\} and \kl\kl\{two\} are defined.\par\noindent
+ \kl\end\{\kl(env){scope}\}\par\noindent
+ Here \kl\kl\{one\} is defined but \kl\kl\{two\} isn't.\par\noindent
+ ~\par\noindent
+ \kl\section\{Second section\}\par\noindent
+ Here neither \kl\kl\{one\} nor \kl\kl\{two\} is defined.
+ However, I can still use them using \kl\kl(section:first)\{one\} and \kl\kl(some label)\{two\}
+ (or \kl"one@@section:first\kl" and \kl"two@@some label\kl").
+ \end{code}
+\end{itemize}
+
+\subsubsection{Accessing other scopes, the \kl{\knowledgeimport} command}
+
+Something important is missing so far: one rapidly wants to access to \kl{knowledges} that do not exist in the current \kl{scope}. For instance, a notion is used in a section of a document, and one would like to refer to it in the introduction. Another case is that of a notion or a mathematic variable that is introduced in the statement of a theorem, and should be accessible inside the proof. There are essentially two ways to access such distance \kl{knowledges}: either use the \smallcode{\kl\kl(label)\{text\}} command (or the equivalent \smallcode{\kl{"...@...@..."}} notation), or use the \kl{\knowledgeimport} command. We describe the second possibility now. The syntax is:
+\begin{center}
+\smallcode{\intro\knowledgeimport\{label\}}
+\end{center}
+The result is that the \kl{knowledges} in the \kl{scope} identified by the label are now
+accessible until the closure of the current \kl{scope}.
+
+For instance:
+\begin{code}[9cm]
+\kl\knowledgeconfigureenvironment\{theorem,proof\}\{\}\par\indent
+{[...]}\par\indent
+\kl\begin\{theorem\}\kl\label\{theorem:1\}\par\noindent
+~~\kl\knowledge\verb|\alpha|\{\kl{autoref},\kl{color=}red\}\par\noindent
+~~Let \$\kl\intro\verb|\alpha|\$ be an integer [...]\par\noindent
+\kl\end\{theorem\}\par\noindent
+{[...]}\par\indent
+Here \$\kl\kl\verb|\alpha|\$ is unknown.\par\noindent
+{[...]}\par\indent
+\kl\begin\{proof\}\par\noindent
+~~\kl\knowledgeimport\{theorem:1\}\par\noindent
+~~But now \$\kl\kl\verb|\alpha|\$ points to its definition.\par\noindent
+\kl\end\{proof\}
+\end{code}
+
+
+\subsubsection{Managing scoping environments}
+
+ \AP The user can also declare an environment
+ to behave like \kl(env){scope} using the
+ command \kl{\knowledgeconfigureenvironment}, as well as adapt some of its characteristics using
+"scope directives".
+\begin{center}
+ \smallcode{\intro\knowledgeconfigureenvironment\{environments\}\{scope directives\}}
+\end{center}
+For instance:
+\begin{code}[12cm]
+ \kl\knowledgeconfigureenvironment \{lemma,theorem,fact,proof\} \{knowledge=attracts\}
+\end{code}
+ \noindent
+ will induce the corresponding environments to have internal knowledges.
+
+Most of the times, it is not necessary to use "scope directives".
+
+\begin{remark}
+Note that (in the current implementation) it is necessary to use the
+commands \kl{\begin} and \kl{\end}. Hence \verb|\proof|\dots\verb|\endproof| would
+ not trigger a scoping environment while \kl{\begin}\texttt{\{proof\}}\dots\kl{\end}\texttt{\{proof\}}
+ would.
+\end{remark}
+
+\AP The ""scope directives"" are advanced features, that should not be used in general. These are the following:
+\begin{compactdesc}
+\itemAP[\intro(area){scope=}\texttt{true/false}] tells whether an environment should induce a scope. For the moment, this is not used (as soon as configured, it always behave like a scope).
+ \itemAP[\intro(area){label=}\texttt{none/accepts}] tells whether a \kl{\label} command can refer to an "instance" of this "area",
+ \itemAP[\intro(area){environment=}\texttt{true/false}] should be set to true if the scope has to be opened whenever an environment of same name is opened
+ \itemAP[\intro(area){autoclose=}\texttt{true/false}] means that the closure is triggered by another event (closure of another enclosing instance, or pushing of an area that requires its closure).
+ \itemAP[\intro(area){parents=}\{"area1@area","area2@area",\dots\}] takes a comma separated list of areas that are allowed as parent. For opening the area, some enclosing instances maybe closed for reaching such a parent.
+ \itemAP[\intro(area){push code=}\texttt{\{code\}}] defines the code to be executed when the area is pushed (each time, these are added)
+ \itemAP[\intro(area){pop code=}\texttt{\{code\}}] defines the code to be exected when the are is popped (added too)
+ \itemAP[\intro(area){occurrences=}\texttt{once/multiple/recursive}] can be one of `\texttt{once}' if the area can only have one instance in the document, `\texttt{multiple}' if there can be several instances, but not nested, and `\texttt{recursive}', if there is no restriction.
+ \itemAP[\intro(area){forces=}"area"] requires a specific area as an ancestor of this area. This ancestor is implicitly pushed if necessary.
+ \end{compactdesc}
+
+
+\subsection{Error handling}
+\label{section:error handling}
+
+By default, the "knowledge@@package" package tries to not stop the compilation unless a serious problem has been found. In particular, it is possible to write an entire document using \kl{\intro} and \kl{\kl} commands or the "quotation notation" without ever introducing a \kl{knowledge}, and only in the end provide this information. This is a feature: as opposed to normal macros, not defining a knowledge should not stop the real work, which is the writing of the document.
+
+\AP
+It happens very often that a \kl[undefined knowledge]{knowledge is not defined}.
+Such \kl{knowledges} are displayed using the "unknown@@style" \kl{style}.
+The detail of the problems are then gathered in the \kl{diagnose file}.
+
+
+\subsection{The \kl{diagnose file}}
+\label{subsection:diagnose file}
+
+The \intro{diagnose file} is a file that is created when the "knowledge@@package" package is used. It enormously eases the use of the package, and it is a good habit to very often peek in it. It gathers a certain number of informations, that can be warning, code to be used, or simply information. This file has the name of the tex document with the extension \kl{.diagnose}. Its content is divided into clearly identified parts. Depending on the used options, some of these parts may appear or disappear.
+\begin{description}
+\itemAP[\intro{Undefined knowledges}] in this section are listed all the knowledges that have been unsuccessfully searched for. These are given in a line of code of the form \kl{\knowledge}\{undefined knowledge\}\{\}. One result of this way of describing is that copying the content of this section to the document itself will solve all problems of \kl{undefined knowledges}. It is an efficient way,
+when one has written a document without caring so much about knowledges to copy the content of this section, and then modify it/reorganize it, in order to suit ones purposes.
+\itemAP[\intro{Autoref not introduced}] In this section, all \kl{knowledges} that were declared using the \kl{autoref} \kl[\knowledge directives]{directive} (this can be the case indirectly using "notion"), but have not been introduced in the document are listed. When a document reaches its final states, this section should be empty.
+Usually, one should add the corresponding \kl{\intro} or \kl{\phantomintro} command somewhere in the text.
+\itemAP[\intro{Autoref introduced twice}] In this section, all \kl{knowledges} that were declared using the \kl{autoref} \kl[\knowledge directives]{directive} and introduced using \kl{\intro} or \kl{\nointro}
+more than once are listed. When a document reaches its final states, this section should be empty. Consider using \kl{\kl} or \kl{\reintro} for solving the problem.
+Note that this may be caused by an \kl{\intro} used in some title (and repeated in the table of contents).
+\end{description}
+
+
+\iffalse
+
+\subsection{Importing and exporting (\kl{not implemented})}
+\label{subsection:import-export}
+
+
+Exporting is not coded yet, and it is not even clear how it should be done.
+
+
+Exporting means outputting in the \kl{export file} some code that it is sufficient to include in another document for being able to refer to some knowledges.
+
+
+When this file is used, using for instance an \kl{\input} command, or simply copied and paste in another document, then the knowledge `Pythagorean theorem'
+becomes available, and points to the proper file.
+Hence in another document, we can use:
+\begin{code}
+\kl\knowledgeimport\{lesson1\}
+\end{code}
+that would make immediately available all the knowledge attached to \kl{scope} `lesson1'. Another possibility if this should be linked only once is to use it directly in the text:
+\begin{code}
+
+\end{code}
+
+It is useful to be able to 1) export some of the knowledges defined in a document, and 2) import them in another document. For the moment this feature is not coded.
+\kl{to be done}
+
+\begin{itemize}
+\item \intro\knowledgeexportscopename
+\item \intro\knowledgeexportbase
+\item \intro\knowledgeimport
+\end{itemize}
+\fi
+
+
+
+\subsection{Other packages}
+
+\subsubsection{The \kl{xcolor option}}
+\label{subsection:xcolor package}
+
+The \intro{xcolor option} is used if one wants to change colors. It is good to always load it since it also triggers coloring for debugging. It triggers colors in the \kl{warning styles} that can be useful in debugging.
+It also offers two new directives:
+\begin{description}
+\itemAP[\intro{color=}] where in `\kl{color=}name', name is a color description following the syntax of the "xcolor@@package" package.
+\itemAP[\intro{colorbox=}] surrounds the text with a colorbox of given color (following the syntax of the "xcolor@@package" package).
+\end{description}
+Loading the package before is necessary for changing the options of the "xcolor@@package" package (for instance for using \kl{svgnames}).
+
+\subsubsection{The \kl{hyperref option}}
+ \label{subsection:hyperref option}
+
+\subsubsubsection{Activating the \kl{hyperref option}}
+
+The \intro{hyperref option} loads the \intro(package){hyperref} and triggers a certain number of link-related features. This is done either by the command:
+\marginpar{\begin{hint}
+ The "hyperref@@package" tends to surround links by boxes that do not help.
+ A solution is to use the \kl{hidelinks} option, i.e., load it with:
+ \begin{code}[4cm]
+ \kl\usepackage\\{}
+ [\kl{hidelinks}]\{\kl(package){hyperref}\}
+ \end{code}
+ \end{hint}
+This is done by default when it is loaded by the
+"knowledge@@package" package.}
+\begin{center}
+\smallcode{%
+\kl{\usepackage}[\kl(option){hyperref}]\{\kl(package){knowledge}\}}
+\end{center}\noindent
+or by loading the "hyperref@@package" before the "knowledge@@package" package (suggestion: with the \kl{hidelinks} and "breaklinks" option).
+
+The \kl[\knowledge directives]{directives} activated by the package are:
+\begin{compactdesc}
+\itemAP[\kl{url=}] for hyperlinking to an external document
+\item[\kl{ref=}] for hyperlinking inside document
+\item[\kl{protect link}] it a boolean for protecting from the creation of nested hyperlinks,
+\item[\kl{autoref}] for relating objects with their definition
+\item[\kl{autorefhere}] similar, and used implicitely for math
+\end{compactdesc}
+
+\AP
+The package comes also with the "configuration directive" \intro{hyperlinks=} which is a boolean
+deactivates or reactivates the links.
+
+
+
+\subsubsubsection{Functionnalities triggered by the \kl{hyperref option}}
+
+\begin{description}
+\itemAP[\intro{ref=}]\texttt{\{label\}} puts an hyperlink pointing toward a label inside the document (the braces can be omitted when there is no comma).
+\item[\intro{protect link}] disables the inside hyperlinks,
+\item[\intro{url=}]\texttt{\{url address\}} puts an hyperlink to an (external) url
+(the braces can be omitted when there is no comma).
+ \marginpar{\begin{hint} You may have to use \texttt{$\backslash$\~} instead of \texttt{\~} in url's addresses.\end{hint}}
+\item[\kl{autoref}] activates the ability to introduce once, use several times an instance. This is very convenient when writing scientific documents with many notions. This is the basic directive activating
+the features of the \kl{\intro} command.
+\item[\kl{autorefhere}] puts immediately a label at the location of the definition, and makes all \kl{\kl} occurrences of this \kl{knowledge}
+hyperlink to this location.
+\end{description}
+
+\subsubsubsection{The \kl{autoref} directive}
+\marginpar
+ {\begin{hint} It is usually easier to use the `\kl{notion}' directive
+ than simply the \kl{autoref} directive. Its use it already configured. \end{hint}}
+\phantomintro{""}
+The \intro{autoref} \kl[\knowledge directives]{directive} is among the most useful offered by the "knowledge@@package" package.
+When set, the \kl{knowledge} should be used with both \intro\intro{} (exactly once) --
+or the \kl{""...""} and \kl{""...@...""} notations (and variants) if \kl(option){quotation} is active -- and \kl{\kl} (possibly several times) -- or the \kl{"..."} notation if \kl(option){quotation} is active. The use of \kl{\kl}
+will hyperlink to the location of the \kl{\intro}. The syntax of \kl{\intro} is the same as
+for \kl{\kl}:
+\begin{center}
+\smallcode{\kl{\intro}[optional knowledge name]\{knowledge name\}}
+\end{center}
+
+\emph{See \kl{\AP} below for improving the result.}
+
+A typical use looks as follows:
+\marginpar{\begin{hint}
+ Though the \kl{\intro} command can be used
+ in the title of, e.g. sections, without any errors, this may cause
+ a warning when a \kl{table of contents} is used: the command is
+ executed twice, once in the \kl{table of contents}, and once in the
+ document itself.
+ \end{hint}}
+\begin{code}
+\kl\knowledge\{house\}[Houses\vbar houses]\{\kl{autoref}\}\\~
+\kl{[...]}\\
+\kl\begin\{document\}\\~
+\kl{[...]}\\
+In this document, we will see the very important notion of \kl{"}houses\kl{"}.\\~
+\kl{[...]}\\
+\kl\AP\\
+Let us define a \kl{""}house\kl{""} to be a building that functions as a home.\\~
+\kl{[...]}\\
+\kl\end\{document\}
+\end{code}\noindent
+yields
+\begin{PDFoutput}
+\knowledge{house}[Houses| houses]{autoref}%
+\kl{[...]}\\
+In this document, we will see the very important notion of \kl{houses}.\\~
+\kl{[...]}\\
+\AP
+Let us define a \intro{house} to be a building that functions as a home.
+\\~
+\kl{[...]}
+\end{PDFoutput}
+
+\AP
+The variant \intro{\intro*} makes the next \kl{\kl} command behave like \kl{\intro}. This is useful in particular in math mode:
+\begin{code}
+\kl\newcommand\kl[@token]\monoid\{\kl\kl[\kl[@token]\monoid]\{\kl\mathcal M\}\}\\
+\kl\knowledge\kl[@token]\monoid\{autoref\}\\~
+\kl{[...]}\\
+\kl\AP\\~
+Let now \$\kl{\intro*}\kl[@token]\monoid\$ be a monoid.\\~
+\kl{[...]}\\
+Remember now who is \$\kl[@token]\monoid\$.
+\end{code}
+%
+\marginpar{\begin{hint} This does not work in \kl{align*} and similar environments.
+Section~\ref{section:amsmath questions} gives some solutions. \end{hint}}
+\begin{PDFoutput}
+\newcommand\moonoid{\kl[\moonoid]{\mathcal M}}
+\knowledge\moonoid{autoref}
+\AP
+Let now $\intro*\moonoid$ be a monoid.\\~
+\kl{[...]}\\
+Remember now who is $\moonoid$.
+\end{PDFoutput}
+
+\AP The \intro{\phantomintro} version:
+\begin{center}
+\smallcode{\kl{\phantomintro}\{knowledge\}}
+\end{center}
+ takes a \kl{knowledge}, and introduces it at the current location, without displaying anything. This is behaves like an invisible intro, i.e., essentially an abbreviation for \smallcode{\kl\intro[knowledge]\{\}}.
+This can be used as a workaround in environment like \kl{align*} that do not allow the use of labels (see Section~\ref{section:amsmath questions}).
+
+
+\AP
+The \intro{\nointro} command:
+\begin{center}
+\smallcode{\kl{\nointro}\{knowledge\}}
+\end{center}
+does not display anything and silently prevents the knowledge from issuing warnings
+because it is not introduced.
+
+\AP
+The \intro{\reintro} command:
+\begin{center}
+\smallcode{\kl{\reintro}[optional knowledge]\{knowledge\}}
+\end{center}
+is displayed as for \kl{\intro}, but without being an anchor for hyperlinks, and without counting as a real \kl\intro. It is used if there are for some reason several places that should look like an introduction (typically in the same paragraph), but count as a single target. There is a variant \intro{\reintro*} that makes the next \kl{\kl} command behave like a \kl{\reintro} (similar to \kl{\intro*} with respect to \kl{\intro}).
+
+\AP
+\kl{Knowledges} that use this directive can be parameterized by modifying the style "intro@@style".
+
+\AP
+For modifying the display of \kl{knowledges} introduced by \kl{\intro},
+there is a new directive:
+\begin{description}
+\itemAP[\intro{intro style=}] that takes the name of a \kl{style} as argument.
+ This \kl{style} will be used when the \kl{knowledge} is used in a \kl{\intro} or \kl{\reintro} command.
+\end{description}
+
+%Hence:
+%\begin{code}
+%%test
+%\end{code}
+
+\subsubsubsection{The \kl{autorefhere} \kl[\knowledge directives]{directive}}
+
+The \intro{autorefhere} directive silently introduces an \kl{anchor point} at the location of the \kl{\knowledge} command invoking it.
+Uses of \kl{\kl} commands will be hyperlinked to this location.
+
+\AP
+In some sense, an \kl{autorefhere} directive can be understood as the sequence of
+a \kl{autoref} directive that would be immediately followed by the corresponding \kl{\intro} command. This is a bit better since using \kl{autoref} is the body of the document requires three phases of compilation (two only if in the preamble).
+However, the \kl{autorefhere} \kl[\knowledge directives]{directive} does only require two (as for normal labels).
+
+\AP
+In fact, this \kl{autorefhere} directive is what is used underneath when introducing mathematical variables, and should be used for implementing similar behaviors.
+
+
+% phantomsection behaves badly in sections
+\let\oldphantomsection\phantomsection
+\RenewDocumentCommand\phantomsection{}{\oldphantomsection}
+
+\subsubsubsection{Using \kl{anchor points}}
+
+
+The directives \kl{autoref} and \kl{autorefhere} use underneath the "hyperref@@package". This means that it puts à label at the place of the \kl{\intro} command, and then points to it. However, the semantics in this case, is to jump to the beginning of the surrounding `region'.
+If the \kl{\intro} happens in a `section' (but not inside a theorem-like envionment) then the \kl{\kl} command will point at the beginning of the section, possibly 10 pages above the definition itself.
+
+\AP
+The standard solution in the \kl(package){hyperref} package
+is to use the \intro{\phantomsection}. This means defining \intro{anchor points} in the document that will be the target of hyperlinks.
+
+We offer here new commands for helping using this feature:
+\smallskip
+\begin{compactdesc}
+\itemAP[\intro{\AP}] declares an \kl{anchor point} at the left of the current column, at the height of the current line. If the \kl{configuration option} \kl{visible anchor points} is set (and this is the case by default), a mark will show the precise location of the target. Be careful: it does not work in some situations, like for instance inside the optional argument of an \kl{\item} command (but this is ok elsewhere in an itemize environment), or inside a some macros in mathmode (e.g. fractions). In the particular case of \kl{\item}, one should use instead:
+\itemAP[\intro{\itemAP}] Similar to \kl\AP, but to be used instead of an \kl\item.
+\end{compactdesc}
+\smallskip
+
+Usually putting an \kl{\AP} (a standard command of the "hyperref@@package") at the beginning of every paragraph, and replacing \kl{\item} by \kl{\itemAP} in itemize-like environments is most of the time good and safe option.
+
+For instance:
+\begin{code}[12.5cm]
+\kl\AP\\
+ In order to describe what is a \kl\kl\{monoid\}, let us us first define
+a \kl\intro\{product\} to be an associative binary operator,
+and a \kl\intro\{unit\} to be \kl{[...]}
+\bigskip
+
+\kl\begin\{description\}\\
+\kl\itemAP[A \kl\intro\{semigroup\}] is a set equipped with a \kl\kl\{product\}.\\
+\kl\itemAP[A \kl\intro\{monoid\}] is a \kl\kl\{semigroup\} that has a \kl\kl\{unit\}.\\
+\kl\end\{description\}
+\end{code}
+\noindent
+yields
+\begin{PDFoutput}[10cm]
+\knowledgeconfigure{visible AP=true}
+\knowledge{semigroup2}{text=semigroup,autoref}
+\knowledge{monoid2}{text=monoid,autoref}
+\knowledge{product2}{text=product,autoref}
+\knowledge{unit2}{text=unit,autoref}
+~~~~~~~
+\begin{minipage}{8.8cm}
+\smallskip
+\AP In order to describe what is a \kl{monoid2}, let us us first define
+ a \intro{product2} to be an associative binary operator,
+and a \intro{unit2} to be
+\kl{[...]}\par
+\begin{description}
+\itemAP[A \intro{semigroup2}] is a set equipped with a \kl{product2}.
+\itemAP[A \intro{monoid2}] is a \kl{semigroup2} that has a \kl{unit2}.
+\smallskip
+\end{description}
+\end{minipage}
+\end{PDFoutput}
+\AP
+One can check that the different knowledges are properly hyperlinked, and that precise targets are the one described by \kl{\AP} and \kl{\itemAP}. For helping debugging the \kl{anchor points}, these are by default made visible as (red)
+corners on output. When the "knowledge@@package" package is loaded with the \kl{paper} option
+these graphical helps disappear.
+This can also be desactivated using:\phantomintro{visible anchor points}
+ \begin{code}[9cm]
+ \kl\knowledgeconfigure\{\kl{visible anchor points=}false\}
+ \end{code}
+
+
+\subsubsection{The \kl{makeidx option}}
+ \label{subsection:makeidx option}
+
+\subsubsubsection{Activating the \kl{makeidx option}}
+
+The \intro{makeidx option} loads the \intro(package){makeidx} package and triggers a certain number of link-related features. This is done either by the command:
+\begin{center}
+\smallcode{\kl{\usepackage}[\kl(option){makeidx}]\{\kl(package){knowledge}\}}
+\end{center}\noindent
+or by loading the \kl(package){makeidx} before the "knowledge@@package" package.
+
+\subsubsubsection{Features}
+
+When activated, it becomes possible to trigger the \kl{\index} command when a \kl{\kl} command is used.
+The following \kl[\knowledge directives]{directives} are use:
+\begin{description}
+\itemAP[\intro{index=}] is the version that uses the standard syntax of the \kl{\index} parameter.
+\itemAP[\intro{index key=}] takes as argument the \kl{index key}: a text that is used for identifying the \kl{index entry} (usually an accent free version of it).
+\itemAP[\intro{index parent key=}] makes the \kl{index entry} be a subentry of the given \kl{main index entry}.
+\itemAP[\intro{index style=}] makes the \kl{index entry} be a subentry of the given \kl{main index entry}.
+\end{description}
+
+
+\subsection{Dealing with math}
+\label{subsection:math}
+
+This part is under development.
+
+\iffalse
+The "knowledge@@package" package offers several tools for dealing with mathematics. It is mostly still experimental.
+The essential goal is to be able to track the identity variables and to point each of them to its introduction.
+For obtaining this, this requires:
+\begin{itemize}
+\item to use the \kl{scoping} since in mathematical proofs the same name can be used to represent many things depending on the context, and
+\item offer ways to easily define macros. One key issue that make this different than standard macro definition is that one is accustomed to use subscripts, supscripts, or primes, to separate different objects. However, it would be very inconvenient to separately define macros for each variant. Hence, is is ok to say that \verb|\rx,\ry,\rz| are variables denoting real numbers (typeset $x,y,z$), but is not ok to separately have to make precise that $x_1$, $x_{i+2}$ and so on in fact represent the same object. It is aso normal that $x$ and $x'$ are different objects, but it is not the case for $f$ and $f'$ if one uses the convention that second is the derivative of the first.
+\end{itemize}
+\fi
+
+\subsection{Fixes}
+\label{subsection:fixes}
+
+In this section, we present some fixes that have been added to help the user solve problems.
+
+\paragraph{Hyperref and twocolumn} It happens that the "hyperref@@package" and two-column mode yields a fatal error. This happens when a link spans across the boundary between two pages. This is an issue which is not related to the "knowledge@@package" package, but becomes severely more annoying when more links have to be used.
+A \emph{workaround} can be tried by calling the
+command \intro{\knowledgeFixHyperrefTwocolumn} in the preamble.
+I do not know to which extend it is compatible with various classes...
+
+\subsection{Predefined configuration}
+
+\subsubsection{The "notion" directive}
+
+The configuration option~\kl{notion} is activated using:
+\begin{center}
+\smallcode{\kl\knowledgeconfigure\{\intro[notion option]{notion}\}}
+\end{center}\noindent
+It automatically configures a \kl[\knowledge directives]{directive} \intro{notion}
+which is an \kl{autoref} displayed properly:
+\begin{itemize}
+\item In \kl{paper mode}, the \kl{\intro} commands (not in math mode) are emphasized, while the \kl{\kl} commands are displayed as normal. It has the aspect of a normal paper.
+\item In "electronic mode" and \kl{composition mode} (with the "xcolor@@package" package), notions are furthermore typeset in blue when introduced, and in dark blue when used. Without the \kl(package){xcolor} package, underlining draw the attention to the knowledges (not in math mode).
+\end{itemize}
+The behavior of the "notion" directive is to activate "autoref", and to configure the following two "styles":
+\begin{itemize}
+\itemAP the "style" ""notion@@style"" is used for normal use,
+\itemAP the "style" ""intro notion@@style"" is used for introduction.
+\end{itemize}
+
+A typical document using notion could start by the following commands:
+\begin{code}
+\kl\documentclass\{article\}\\
+\kl\usepackage\{\kl(package){xcolor}\}\\
+\kl\usepackage[\kl{hidelinks}]\{\kl(package){hyperref}\}\\
+\kl\usepackage[\kl{paper}]\{"knowledge@@package"\}\\
+\kl\knowledgeconfigure\{"notion@@option"\}\\
+{[...]}\\
+\kl\knowledge\{some text\}\{notion\}
+\end{code}\noindent
+Then the paper is displayer in a colorful way. As soon as the \texttt{false} is replaced by \texttt{true}, the paper becomes black and seriously looking as it should.
+
+\newpage
+
+\section{Some questions and some answers}
+\label{section:faq}
+
+\subsection{How to compile?}
+
+As usual with \LaTeX, a certain number of compilation phases are necessary for reaching a document in final form. The problematic point is of course the use of labels, and in particular the \kl{\intro} command. When it is used, and all the \kl{\knowledge} commands are in the preamble, then two phases are necessary. When \kl{\knowledge} commands are used in the body of the documents, then one extra phase is required, meaning three with \kl{autoref} definitions. This is also the case when "scoping" is used.
+
+\subsection{Problem with \kl{\item} parameters}
+
+\paragraph{The use of~\kl{\AP} inside \kl{\item} does not work.} Do not use \kl{\AP} inside the optional argument of \kl{\item}, and rather use the command \kl{\itemAP}.
+
+\paragraph{Argument of \kl{\kl} has an extra `\texttt\}'.} This is a problem of using optional parameters inside optional parameters such as in \smallcode{\kl\item[\kl\kl[test]\{Test\}]}. You can surround the content of the optional parameter by two level of curly braces as in \smallcode{\kl\item[\{\{\kl\kl[test]\{Test\}\}\}]}.
+The notation \kl{"..."} does not have this issue.
+
+
+
+
+
+\subsection{Knowledges and moving arguments (table of contents, \dots).}
+
+
+
+\paragraph{The use of \kl{\kl} does not work in (e.g.) the table of content.} When the \kl{knowledge name} contains expandable macros, or accentuated letters, then these are not copied in the table of content as the exact same text, but are expanded/translated. Thus, when the table of content is displayed, the \kl{\kl} command complains of not knowing the \kl{knowledge}. For instance\footnote{with \texttt{\kl\usepackage[utf8]\{inputenc\}} and, for instance \texttt{\kl\usepackage[T1]\{fontenc\}} for the accents.}:
+\begin{center}
+\begin{code}[11cm]
+\kl\newcommand\robustdisplay\Ltwo\{\kl\ensuremath\{L\^{}2\}\}\\
+\kl\knowledge\{\robustdisplay\Ltwo-space\}[\robustdisplay\Ltwo-spaces]\{autoref\}\\
+\kl\knowledge\{\'etale topology\}[\'Etale topology]\par
+~~~~~~~\{\kl{url=}\{https://en.wikipedia.org/wiki/\'Etale_topology\}\}\\
+{[...]}\\
+\kl\begin\{document\}\\
+\kl\tableofcontents\\
+\kl\section\{On \kl\kl\{\robustdisplay\Ltwo-spaces\}\\
+{[...]}\\
+\kl\section\{On the \kl\kl\{\'etale topology\}\}\\
+{[...]}\\
+\kl\end\{document\}
+\end{code}\end{center}\noindent
+will result in that both \kl{knowledges} are considered unknown in the table of contents.
+For the first one, this is due to the expansion of~$\texttt{\robustdisplay\Ltwo}$. For the second, this is due to an implicit translation of the accentuated letter into an internal sequence of commands (for instance `\'e' is translated into the internal sequence `\verb|\IeC {\'e}|'). Some solutions are as follows:
+\begin{itemize}
+\item Make the macros non-expandable, for instance using \kl{\newrobustcmd} (of the \kl(package){etoolbox}) or \kl{\NewDocumentCommand} (of the \kl(package){xparse} package, with a different handling of arguments) instead of \kl{\newcommand}. Hence:
+\begin{code}
+\kl\newrobustcmd\robustdisplay\Ltwo\{\kl\ensuremath\{L\^{}2\}\}
+\end{code}\noindent
+solves the first problem.
+\item Using an equivalent text that does not have the problem:
+ \begin{code}
+ \kl\knowledge\{$\backslash$'etale topology\}\{\kl{link=}\'etale topology\}\\
+ {[...]}\\
+ \kl\section\{On the \kl\kl\{$\backslash$'etale topology\}\}
+ \end{code}
+\item Both problems can be solved using synonyms/links that have no problem. For instance:
+ \begin{code}
+ \kl\knowledge\{Ltwo-space\}\{\kl{link=}\robustdisplay\Ltwo-space\}\\
+ \kl\knowledge\{etale topology\}\{\kl{link=}\'etale topology\}\\
+ {[...]}\\
+ \kl\section\{On \kl\kl[Ltwo-space]\{\robustdisplay\Ltwo-spaces\}\}\\
+ \kl\section\{On the \kl\kl[etale topology]\{étale topology\}\}
+ \end{code}
+\item Other solutions? None so far. I am trying to systematize the treatment of these problems.
+\end{itemize}
+
+
+\paragraph{Using \kl{\intro} in a section title causes introducing the knowledge twice.}
+Do not use \kl{\intro} in titles, but rather \kl{\reintro}. If you want the section to be the target of the \kl{knowledge}, then put after the section a \kl{\nointro} command.
+\begin{center}
+\begin{tabular}{ccc}
+%\hline
+\begin{code}[5.5cm]
+\kl\section\{On \kl\intro\{topology\}\}\\
+\end{code}&&
+\begin{code}[5.9cm]
+\kl\section\{On \kl{\reintro}\{topology\}\}\\
+\kl{\phantomintro}\{topology\}
+\end{code}\\
+\textit{Problematic code}&&
+\textit{A solution}
+\end{tabular}
+\end{center}
+
+\subsection{Problems with "tikzcd@@package" and other issues with the "quotation notation"}
+\label{section:tikzcd}
+
+The package "tikzcd@@package" uses (heavily) the quotes. Thus, it conflicts with the "quotation notation".
+Some other packages may do the same. For solving this issue, the only thing to do is to temporarily deactivate the "quotation notation".
+
+To avoid this problem, it is sufficient to use before each figure:
+\begin{code}[8.5cm]
+"\knowledgeconfigure"\{"quotation@@option"=false\}
+\end{code}
+and after the figure:
+\begin{code}[7cm]
+"\knowledgeconfigure"\{"quotation@@option"\}
+\end{code}
+Another possibility is to force some environment to deactivate systematically the "quotation notation" when used. For instance
+\begin{code}[10cm]
+"\knowledgeconfigure"\{"protect quotation="\{"tikzcd@@env"\}\}
+\end{code}\noindent
+will deactivate the "quotation notation" in all the "tikzcd@@env" environments.
+
+
+\subsection{Problems with \kl(package){amsmath}}
+\label{section:amsmath questions}
+
+\paragraph{The \kl{\intro} command does not work in \kl{align*} or similar environments}
+It happens that in starred environment (i.e., unnumbered), the package \kl(package){amsmath}
+deactivates the labels. As a consequence the command \kl{\intro}, which internally uses {\kl\label} (at least so far), does not work. For the moment, there is no real solution, but a workaround which consists in introducing the \kl{knowledge} before
+the incriminated environment using \kl\phantomsection, and then use \kl{\reintro} inside the environment. Imagine for instance a command
+\texttt{\robustdisplay\SomeCommand}, that inside uses \texttt{\kl\kl[\robustdisplay{\Somecommand}]}, then:
+\begin{center}
+ \begin{tabular}{ccc}
+ does not work&&works\\
+ \begin{code}[5cm]
+ \kl\begin\{\kl{align*}\}\\
+ \kl\intro*\texttt{\robustdisplay{\SomeCommand}}\\
+ \kl\end\{\kl{align*}\}\\
+ \end{code}
+ &&
+ \begin{code}[5cm]
+ \kl\phantomintro\texttt{\robustdisplay{\SomeCommand}}\\
+ \kl\begin\{\kl{align*}\}\\
+ \kl\reintro*\texttt{\robustdisplay{\SomeCommand}}\\
+ \kl\end\{\kl{align*}\}
+ \end{code}
+ \end{tabular}
+\end{center}
+
+\subsection{Hyperref complains}
+\paragraph{A fatal error occurs in twocolumn mode.} A workaround is to use
+\smallcode{\kl\knowledgeconfigure\{\kl{fix hyperref twocolumn}\}}.
+
+\subsection{Incorrect display}
+
+
+\paragraph{Incorrect breaking at the end of lines (in Arxiv for instance)}
+It may happen that some hyperlinks generated by "knowledge@@package" are not broken properly
+at the end of lines. This is an issue with the \kl(package){hyperref} package. This in particularly happened for files compiled by the Arxiv system while the file on the local computer was not having any problem.
+
+A workaround is to use the \texttt{breaklinks} option of \kl(package){hyperref}. The preamble thus looks like:
+\begin{code}[9cm]
+\kl{[...]}\par\noindent
+\kl\usepackage[\kl{breaklinks},\kl{hidelinks}]\{\kl(package){hyperref}\}\par\noindent
+\kl{[...]}\par\noindent
+\kl\usepackage\{\kl{knowledge}\}\par\noindent
+\kl{[...]}\par\noindent
+\end{code}
+
+\subsection{Editor}
+
+\newenvironment{pquote}{\begin{quote}}{\end{quote}}
+\knowledgeconfigure{protect quotation=pquote}
+
+\subsubsection{"Emacs" editor and \kl[quotation notation]{quotes}}
+The "AucTex" mode in "Emacs" binds the quote symbol to other characters. This is not convenient when using the "knowledge@@package" package.
+
+This behavior can be deactivated temporarily using:
+\begin{pquote}
+\texttt{M-x local-unset-key $\backslash$\quotationmark.}
+\end{pquote}\noindent
+or definitively using:
+\begin{pquote}
+\texttt{(defun my-hook () (local-unset-key \quotationmark$\backslash$\quotationmark\quotationmark))\\
+(add-hook 'LaTeX-mode-hook 'my-hook)}
+\end{pquote}
+% source: Sylvain Perifel, and:
+%(source : https://stackoverflow.com/questions/24835536/insert-regular-double-quotes-in-latex-mode-with-auctex)
+
+\subsection{Others}
+If other kind of problems occur, report them to \texttt{thomas.colcombet@irif.fr}.
+
+\newpage
+
+\section{Resources}
+\label{section:resources}
+
+\subsection{List of commands}
+\begin{compactdesc}
+\item[\kl\AP] introduces an "anchor point".
+\item[\kl\intro] searches for a \kl{knowledge} and put an anchor to it (to be used with the \kl{autoref} directive).
+\item[\kl\kl] searches for a \kl{knowledge} and displays it accordingly.
+\item[\kl\knowledge] defines new \kl{knowledges}.
+\item[\kl\knowledgeconfigure] configures the package.
+\item[\kl\knowledgedefault] declares the default \kl[\knowledge directives]{directives} to be automatically used in \kl{\knowledge} commands.
+\item[\kl\knowledgeimport] gives access to \kl{knowledges} existing in other scopes.
+\item[\kl\knowledgedirective] defines a new \kl[\knowledge directives]{directive}.
+\item[\kl\knowledgestyle] defines a new \kl{style}.
+\item[\kl\nointro] declares that the knowledge will never be introduced (does not work properly yet).
+\item[\kl\phantomintro] performs an invisible \kl\intro.
+\item[\kl\reintro] uses the \kl{display style} of \kl{\intro} without introducing an anchor.
+\end{compactdesc}
+
+\subsection{List of environments}
+\begin{compactdesc}
+\item[\kl(env){export}] (\kl{not implemented}) requires exportation of the content
+\item[\kl(env){import}] (\kl{not implemented}) declares external resources
+\item[\kl(env){scope}] Defines a \kl{scope} in which \kl{knowledges} are internal.
+\end{compactdesc}
+
+\subsection{List of directives}
+\label{subsection:directive list}
+
+
+\begin{compactdesc}
+\item["autoref"] Activates the \kl{\intro} feature (requires the "hyperref@@package").
+\item[\kl{autorefhere}] creates an \kl{anchor point} that points to the \kl{\knowledge} command (Requires the \kl{hyperref option}).
+\item[\kl{boldface}] Displays the knowledge in boldface.
+\item[\kl{color=}] Displays the \kl{knowledge} is the given color (resquires \kl(option){xcolor}).
+\item[\kl{colorbox=}] Displays the \kl{knowledge} in a box of the given color (requires \kl(option){xcolor}).
+\item[\kl{emphasize}] Emphasizes the displayed output.
+\item[\kl{ensuretext}] Guarantees that the output will be displayed in text mode.
+\item[\kl{ensuremath}] Guarantees that the output will be displayed in math mode.
+\item[\kl{export=}] (\kl{not implemented})
+\item[\kl{fbox}] Surround the text with a box.
+\item[\kl{md}] Removes boldface typesetting.
+\item[\kl{notion}]
+%\item[\kl{import=}] (\kl{not implemented})
+\item[\kl{index=}] Chooses the text to be displayed in the \kl{index=}.
+\item[\kl{index key=}] the key used to choose the place in the \kl{index}.
+\item[\kl{index style=}] the \kl{style} to be used to display in the \kl{index}.
+\item[\kl{index parent key=}] the parent key in the \kl{index}.
+\item[\kl{intro style=}] Chooses the typesetting in case of an intro.
+\item[\kl{italic}] Typesets the output in italic.
+\item[\kl{link=}] Follow with the search the linked knowledge.
+\item[\kl{link scope=}] Follow the search in the corresponding scope, using the same key, or the one provided by \kl{link=}
+ if present.
+\item[\kl{lowercase}] Put all letters of the output in lowercase.
+\item[\kl{mathord}, \kl{mathop}, \kl{mathbin}, \kl{mathrel}, \kl{mathopen}, \kl{mathclose}, \kl{mathpunct}] Selects a spacing behaviour in math mode.
+\item[\kl{protect link}] Disables the hyperlinks inside the link.
+\item[\kl{ref=}] Links to a label inside the document.
+\item[\kl{scope=}] Choose the \kl{scope} of the definition.
+\item[\kl{style=}] Links to a style.
+\item[\kl{synonym}] Is a synonym of the lastly defined \kl{knowledge}.
+\item[\kl{text=}] Changes the output text.
+\item[\kl{typewriter}] Typeset in as with \kl{\texttt}.
+\item[\kl{underline}] Underlines the text.
+\item[\kl{up}] Removes italic typesetting.
+\item[\kl{uppercase}] Put all letters of the output in uppercase.
+\item[\kl{url=}] An url to point to (uses the "hyperref@@package").
+\item[\kl{wrap=}] A macro used to process the displayed text.
+\end{compactdesc}
+
+\subsection{List of \kl{configuration directives} (to use with \kl{\knowledgeconfigure})}
+\label{subsection:configuration directive list}
+\begin{compactdesc}
+\item["composition"] switches to "composition mode",
+\item["diagnose line="\textmd{\{true,false\}}] activates or deactivates the line numbering in the "diagnose file".
+\item["electronic"] switches to "electronic mode",
+\item[\kl{fix hyperref twocolumn}] fixes a known problem between "hyperref@@package"
+ and the two column mode.
+\item[\kl{hyperlinks=}\textmd{\{true,false\}}] activates or deactivates the hyperlinks.
+\item[{{\kl(option){notion}}}] activates the "notion" directive
+\item[\kl(option){quotation=}\textmd{\{true,false\}}] activates or deactivates the "quotation notation".
+\item["paper"] switches to "paper mode",
+\item[\kl{protect link co} and \kl{unprotect link co}] starts and ends respectively a zone in which the "knowledge@@package" package does not create hyperlinks.
+\item[\kl{protect quotation=}\textmd{\{environment list\}}] declares a list of environment in which the "quotation notation" should be deactivated
+\item[\kl{visible anchor points=}\textmd{\{true,false\}}] makes the \kl{anchor points} either visible or invisible
+\end{compactdesc}
+\newpage
+
+
+
+
+
+
+\subsection*{List of default \kl{styles}}
+\begin{compactdesc}
+\itemAP[\kl(style){intro}]
+\itemAP[\kl(style){unknown}]
+\itemAP[\kl(style){intro unknown}]
+\itemAP[\kl(style){notion}] (if "notion" is activated)
+\itemAP[\kl(style){intro notion}] (if "notion" is activated)
+\end{compactdesc}
+
+
+
+
+
+
+
+
+
+
+
+\knowledgeconfigure{quotation=false}
+\producecode
+
+\end{document}
+%</driver>
+% \fi
+%
+% \CheckSum{0}
+%
+%
+% \changes{v1.01}{2017/06/11}{Initial version} %
+% \changes{v1.02}{2017/06/28}{bug fixes} %
+% \changes{v1.03}{2017/07/27}{scoping,bug fixes} %
+% \changes{v1.04}{2017/07/28}{minor changes,bug fixes} %
+% \GetFileInfo{knowledge.sty} %
+% \DoNotIndex{}
+%
+%
+%\let\ifcode\iffalse
+%
+%%%%%%%%%%
+%
+% \section{Implementation}
+% \label{section:code}
+% \subsection{Code preparation}
+%<*head>
+% \begin{macrocode}
+\RequirePackage{l3keys2e}
+\RequirePackage{etoolbox}
+\RequirePackage{xparse}
+\bool_if_exist:NTF\knowledge_package_loaded_bool
+ {\endinput}
+ {\bool_set_true:N\knowledge_package_loaded_bool}
+% \end{macrocode}
+%</head>
+%<*package>
+% \begin{macrocode}
+\cs_new:Npn\knowledge_skip_module:#1\knowledge_end_module:
+ {}
+\cs_new:Nn\knowledge_begin_module_if:N
+ {\bool_if:NF#1\knowledge_skip_module:}
+\cs_new:Nn\knowledge_end_module:
+ {}
+% \end{macrocode}
+%
+% One defines the code of \intro{\klparse_ifnextchar:NTF}
+% which is a link to \verb|\@ifnextchar|,
+% as well as the constant \intro{\klparse_novalue_tl} which contains
+% the token list corresponding to a non-given optional argument
+% as used in the \kl(package){xparse} package.
+%
+% \begin{macrocode}
+\cs_set_eq:Nc\klparse_ifnextchar:NTF{@ifnextchar}
+
+\NewDocumentCommand\klparse_setnovalue{o}
+ {\tl_set:Nn\klparse_novalue_tl{#1}}
+\klparse_setnovalue\relax
+
+\cs_new:Npn\klparse_if_novalue:NTF
+ {\tl_if_eq:NNTF\klparse_novalue_tl}
+% \end{macrocode}
+%
+% \subsection{Messages of the package}
+%
+% \begin{macrocode}
+\cs_new:Nn\knowledge_info:n{\msg_info:nnn{knowledge}{knowledge~info}{#1}}
+\cs_new:Nn\knowledge_warning:n{\msg_warning:nnn{knowledge}{knowledge~warning}{#1}}
+\cs_new:Nn\knowledge_error:n{\msg_error:nnn{knowledge}{knowledge~error}{#1}}
+
+\msg_new:nnnn{knowledge}{knowledge~info}{#1}{#2}
+\msg_new:nnnn{knowledge}{knowledge~warning}{#1}{#2}
+\msg_new:nnnn{knowledge}{knowledge~error}{#1}{#2}
+
+\cs_generate_variant:Nn\knowledge_info:n{x}
+\cs_generate_variant:Nn\knowledge_warning:n{x}
+\cs_generate_variant:Nn\knowledge_error:n{x}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\msg_new:nnn{ knowledge }{ knowledge~recursion }
+ { The~knowledges~are~probably~cyclic,~starting~from~'#1'~(namespace~'#2'),~
+ currently~at~'#3'.}
+\msg_new:nnn{ knowledge }{ knowledge~unknown }
+ {The~knowledge~'#1'~could~not~be~found~in~scopes~<~#3~>~(namespace~'#2').}
+\msg_new:nnn{ knowledge }{ knowledge~unknown~in~scope }
+ {The~knowledge~'#1'~could~not~be~found~in~scope~'#3'~(namespace~'#2').}
+\msg_new:nnn{ knowledge }{ knowledge~unknown~label }
+ {The~label~'#2'~could~not~be~found~while~searching~for~'#1'.~Possibly~rerun~latex.}
+
+\msg_new:nnn{ knowledge }{ package~required }
+ {In~order~to~use~directive~'#1',~please~load~package~or~use~option~'#2'.}
+\msg_new:nnn{ knowledge }{ knowledge~exists }
+ { The~knowledge~'#1'~in~scope~'#2'~(namespace~'#3')~already~exists. }
+
+
+\msg_new:nnn{scope}{area~exists}{Area~'#1'~already~exists.}
+\msg_new:nnn{scope}{area~not~exist}{Area~'#1'~does~not~exist.}
+\msg_new:nnn{scope}{empty~pop}{Attempt~to~pop~an~empty~area~stack.}
+\msg_new:nnn{scope}{no~pushing~here}
+ {Not~allowed~to~open~'\scope_pushed_area_tl'~here.~
+ Current~stack~is~<\seq_use:Nn\scope_instances_stack_seq{::}>.}
+\msg_new:nnn{scope}{no~popping}{Not~allowed~to~close~'\scope_popped_area_tl'.}
+\msg_new:nnn{scope}{no~popping~here}
+ {Not~allowed~to~close~'\scope_popped_area_tl'~here~(at~'\scope_top_area_tl').}
+\msg_new:nnn{scope}{unknown~label}
+ {\tl_if_empty:nTF{#2}{}{\exp_not:n{#2}}:
+ ~Unknown~label~`#1'.~Possibly~rerun~latex.}
+\msg_new:nnn{scope}{area~not~in~context}
+ {\tl_if_empty:nTF{#2}{}{\exp_not:n{#2}}:
+ ~The~area~`#1'~can't~be~found~in~context.~Possibly~rerun~latex.}
+% \end{macrocode}
+% Other Warning and error commands.
+% \begin{macrocode}
+\NewKAuxCommand\KAuxErrorKnowledgeRecursive{mmmm}
+ {Package~'knowledge:~A~knowledge~has~recursive~definition.~
+ {namespace}{scope}{undefined~knowledge}{base~knowledge}}
+ {}
+\cs_new:Nn\knowledge_kl_error_recursion: {
+ \msg_error:nnxxx{ knowledge }{ knowledge~recursion }
+ {\exp_not:V\knowledge_kl_base_key_tl}
+ {\exp_not:V\knowledge_kl_namespace_tl}
+ {\exp_not:V\knowledge_kl_key_tl}
+ \knowledge_kl_error_display:n{recursive~knowledge}
+}
+% \end{macrocode}
+%
+% \subsection{Option and packages}
+%
+%
+% \subsubsection{Configuration option}
+%
+% The options exist in two forms, the one that usable during the loading of the package,
+% and the one that can be used in \kl{\knowledgeconfigure}, i.e., at some other locations in the document.
+% The configuration options can be used when loading the package, however, these are first
+% appended to the tl variable \kl{\knowledge_configuration_pending_tl}, and executed at the end of the loading.
+% This is important, since automatic configuration needs, for instance, to know if the \kl{composition mode}, or the \kl{paper mode} is used right now, but one cannot expect the user to declare the options in this particular order.
+%
+% I do not know why, but \kl{\ProcessKeysOptions} removes the spaces in the parameters.
+% So we have to do the same if we want to load options this way.
+%
+% We first provide a token list that stores the configurations (which are different from the options).
+% \begin{macrocode}
+\tl_new:N\knowledge_configuration_pending_tl
+\tl_set:Nn\knowledge_configuration_pending_tl{}
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
+\NewDocumentCommand\KnowledgePackageTrigger{mm}
+ { \keys_define:nn{ knowledge~package~options }{ #1 .code:n = {#2} } }
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
+\NewDocumentCommand\KnowledgeConfigureBooleanOption{om}{
+ \tl_set:Nn\l_tmpa_tl{#2}
+ \tl_remove_all:Nn\l_tmpa_tl{~}
+ \IfNoValueTF{#1}
+ {\bool_new:c{knowledge_configuration_#2_bool}
+ \exp_args:NcnV\knowledge_KnowledgeConfigureBooleanOption:Nnnnn
+ {knowledge_configuration_#2_bool}{#2}\l_tmpa_tl{}{}}
+ {\exp_args:NNnV\knowledge_KnowledgeConfigureBooleanOption:Nnnnn
+ #1{#2}\l_tmpa_tl{}{}}
+ }
+\NewDocumentCommand\KnowledgeConfigureBooleanOptionTF{ommm}{
+ \tl_set:Nn\l_tmpa_tl{#2}
+ \tl_remove_all:Nn\l_tmpa_tl{~}
+ \IfNoValueTF{#1}
+ {\bool_new:c{knowledge_configuration_#2_bool}
+ \exp_args:NcnV\knowledge_KnowledgeConfigureBooleanOption:Nnnnn
+ {knowledge_configuration_#2_bool}{#2}\l_tmpa_tl{#3}{#4}}
+ {\exp_args:NNnV\knowledge_KnowledgeConfigureBooleanOption:Nnnnn
+ #1{#2}\l_tmpa_tl{#3}{#4}}
+ }
+
+\cs_new:Nn\knowledge_KnowledgeConfigureBooleanOption:Nnnnn{
+ \keys_define:nn{ knowledge~package~options }{
+ #3 .choice:,
+ #3 / true .code:n = {\tl_put_right:Nn\knowledge_configuration_pending_tl{,#2=true}},
+ #3 / false .code:n = {\tl_put_right:Nn\knowledge_configuration_pending_tl{,#2=false}},
+ #3 .default:n = {true}
+ }
+ \keys_define:nn{ knowledge~configuration~options }{
+ #2 .choice:,
+ #2 / true .code:n = {\bool_if:NF#1{\bool_set_true:N#1#4}},
+ #2 / false .code:n = {\bool_if:NT#1{\bool_set_false:N#1#5}},
+ #2 .default:n = {true}
+ }}
+
+\NewDocumentCommand\KnowledgePackageBooleanOption{om}{
+ \tl_set:Nn\l_tmpa_tl{#2}
+ \tl_remove_all:Nn\l_tmpa_tl{~}
+ \IfNoValueTF{#1}
+ {\bool_new:c{knowledge_configuration_#2_bool}
+ \exp_args:NcnV\knowledge_KnowledgePackageBooleanOption:Nnn
+ {knowledge_configuration_#2_bool}{#2}\l_tmpa_tl}
+ {\exp_args:NNnV\knowledge_KnowledgePackageBooleanOption:Nnn
+ #1{#2}\l_tmpa_tl}
+ }
+\cs_new:Nn\knowledge_KnowledgePackageBooleanOption:Nnn{
+ \keys_define:nn{ knowledge~package~options }{
+ #3 .choice:,
+ #3 / true .code:n = {\bool_set_true:N#1},
+ #3 / false .code:n = {\bool_set_false:N#1},
+ #3 .default:n = {true}
+ }
+ \keys_define:nn{ knowledge~configuration~options }{
+ #2 .code:n = {\OPTION_CANNOT_BE_USED_IN_knowledgeconfigure}
+ }}
+\NewDocumentCommand\KnowledgeConfigureTrigger{omm}{
+ \IfNoValueTF{#1}
+ {\tl_set:Nn\l_tmpa_tl{#2}
+ \tl_remove_all:Nn\l_tmpa_tl{~}
+ \exp_args:NNV\KnowledgeConfigureTrigger[\l_tmpa_tl]{#2}{#3}}
+ {\keys_define:nn { knowledge~configuration~options }
+ { #2 .code:n = {#3}, #2 .default:V = \klparse_novalue_tl }
+ \keys_define:nn { knowledge~package~options }
+ { #1 .code:n = {\tl_put_right:Nn\knowledge_configuration_pending_tl{,#2={##1}} }}
+ }
+}
+\NewDocumentCommand\KnowledgeConfigureOption{mm}{
+ \keys_define:nn { knowledge~configuration~options }
+ { #1 .code:n = {#2} }
+}
+\NewDocumentCommand\knowledgeconfigure{m}{
+ \keys_set:nn{ knowledge~configuration~options }{#1}
+}
+% \end{macrocode}
+%
+%
+% \subsubsection{List of options that have to be prepared}
+%
+% \begin{macrocode}
+\bool_new:N\knowledge_configuration_quotation_bool
+\KnowledgeConfigureBooleanOptionTF[\knowledge_configuration_quotation_bool]{quotation}{\klactivatequotation}{\kldeactivatequotation}
+\KnowledgeConfigureOption{protect~quotation}{\kl_protect_environment_quotation:n{#1}}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\bool_new:N\knowledge_configuration_diagnoseline_bool
+\bool_gset_true:N\knowledge_configuration_diagnoseline_bool
+\KnowledgeConfigureBooleanOption[\knowledge_configuration_diagnoseline_bool]{diagnose~line}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\bool_new:N\knowledge_configuration_visibleAP_bool
+\KnowledgeConfigureBooleanOption[\knowledge_configuration_visibleAP_bool]{visible~anchor~points}\KnowledgeConfigureBooleanOption[\knowledge_configuration_visibleAP_bool]{visible~AP}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\bool_new:N\knowledge_hyperlinks_active_bool
+\bool_set_true:N\knowledge_hyperlinks_active_bool
+% \end{macrocode}
+%
+% Modes.
+
+% \begin{macrocode}
+\tl_set:Nn\knowledge_option_mode_tl{}
+\KnowledgePackageTrigger{ paper }{\tl_set:Nn\knowledge_option_mode_tl{paper}}
+\KnowledgePackageTrigger{ electronic }{\tl_set:Nn\knowledge_option_mode_tl{electronic}}
+\KnowledgePackageTrigger{ composition }{\tl_set:Nn\knowledge_option_mode_tl{composition}}
+% this one is for compatibility
+\KnowledgePackageTrigger{ final }{\tl_set:Nn\knowledge_option_mode_tl{final}}
+%
+% \end{macrocode}
+%
+% \begin{macrocode}
+\KnowledgeConfigureTrigger{ fix~hyperref~twocolumn }
+ {\knowledgeFixHyperrefTwocolumn}
+\KnowledgeConfigureTrigger{ notion }
+ {\KnowledgeConfigureNotion{notion}}
+\KnowledgeConfigureTrigger{ protect~links }
+ {\kl_kl_nesting_incr:}
+\KnowledgeConfigureTrigger{ unprotect~links }
+ {\kl_kl_nesting_decr:}
+% \end{macrocode}
+%
+% \subsubsection{External package options}
+%
+%\intro{\knowledge_xcolor_active_bool}, \intro{\knowledge_xcolor_syntax_bool},
+%\intro{\knowledge_hyperref_active_bool}, \intro{\knowledge_hyperref_syntax_bool},
+%\intro{\knowledge_makeidx_active_bool}, \intro{\knowledge_makeidx_syntax_bool}
+%
+% First, one tests the package available.
+% \begin{macrocode}
+\cs_new_eq:Nc\package_if_loaded:nTF{@ifpackageloaded}
+\cs_new:Nn\knowledge_option_aci_test_loaded:n{
+ \bool_new:c{knowledge_#1_active_bool}
+ \bool_new:c{knowledge_#1_syntax_bool}
+ \package_if_loaded:nTF{#1}
+ {\bool_set_true:c{knowledge_#1_active_bool}
+ \bool_set_true:c{knowledge_#1_syntax_bool}}
+ {\bool_set_false:c{knowledge_#1_active_bool}
+ \bool_set_false:c{knowledge_#1_syntax_bool}}
+}
+\knowledge_option_aci_test_loaded:n{hyperref}
+\knowledge_option_aci_test_loaded:n{xcolor}
+\knowledge_option_aci_test_loaded:n{makeidx}
+% \end{macrocode}
+%
+%\intro{\knowledge_option_aci_define:n}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_option_aci_define:n{
+ \keys_define:nn{ knowledge~package~options } {
+ #1 .choice: ,
+ #1 / active .code:n = {
+ \bool_set_true:c{knowledge_#1_active_bool}
+ \bool_set_true:c{knowledge_#1_syntax_bool}},
+ #1 / compatibility .code:n = {
+ \bool_set_false:c{knowledge_#1_active_bool}
+ \bool_set_true:c{knowledge_#1_syntax_bool}},
+ #1 / inactive .code:n = {
+ \bool_set_false:c{knowledge_#1_active_bool}
+ \bool_set_false:c{knowledge_#1_syntax_bool}},
+ #1 .default:n = {active}
+ }}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new:Nn\knowledge_option_bool_new:nN{
+ \keys_define:nn{ knowledge~package~options } {
+ #1 .choice: ,
+ #1 / true .code:n = { \bool_gset_true:N#2 },
+ #1 / false .code:n = { \bool_gset_false:N#2 },
+ #1 .default:n = {true}
+ }
+}
+\cs_new:Nn\knowledge_option_bool_new:n
+ {\bool_new:c{knowledge_option_#1_bool}
+ \exp_args:Nnc\knowledge_option_bool_new:nN{#1}{knowledge_option_#1_bool}}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new:Nn\knowledge_option_aci_autoload:nn{
+ \bool_if:cTF{knowledge_#1_active_bool}
+ {\package_if_loaded:nTF{#1}{}
+ {\RequirePackage[#2]{#1}}}{}
+}
+% \end{macrocode}
+%
+%\subsubsection{Executing the options}
+%
+% \begin{macrocode}
+\knowledge_option_bool_new:n{scope}
+\knowledge_option_aci_define:n{hyperref}
+\knowledge_option_aci_define:n{xcolor}
+\knowledge_option_aci_define:n{makeidx}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\ProcessKeysOptions{knowledge~package~options}
+% \end{macrocode}
+%
+% Selection of the mode.
+% \begin{macrocode}
+\tl_if_exist:NTF\knowledgepackagemode
+ {}{\tl_set:Nn\knowledgepackagemode{}}
+
+\tl_if_empty:NTF\knowledgepackagemode
+ {\tl_if_empty:NTF\knowledge_option_mode_tl
+ {\tl_set:Nn\knowledge_option_mode_tl{composition}}
+ {}}
+ {\tl_if_empty:NTF\knowledge_option_mode_tl
+ {\tl_set_eq:NN\knowledge_option_mode_tl\knowledgepackagemode}
+ {\knowledge_info:n{Knowledge~mode~overriden~by~user.}
+ \tl_set_eq:NN\knowledge_option_mode_tl\knowledgepackagemode
+ }}
+
+\bool_new:N\knowledge_option_composition_bool
+\bool_set_false:N\knowledge_option_composition_bool
+\bool_new:N\knowledge_option_electronic_bool
+\bool_set_false:N\knowledge_option_electronic_bool
+\bool_new:N\knowledge_option_paper_bool
+\bool_set_false:N\knowledge_option_paper_bool
+
+\keys_define:nn{ knowledge~package~modes }{
+ paper .code:n = {
+ \bool_set_true:N\knowledge_option_paper_bool
+ \bool_set_false:N\knowledge_configuration_visibleAP_bool
+ },
+ electronic .code:n = {
+ \bool_set_true:N\knowledge_option_electronic_bool
+ \bool_set_false:N\knowledge_configuration_visibleAP_bool
+ },
+ composition .code:n = {
+ \bool_set_true:N\knowledge_option_composition_bool
+ \bool_set_true:N\knowledge_configuration_visibleAP_bool
+ },
+ final .code:n = { \knowledge_warning:x{Mode~`final`~is~deprecated,~
+ and~should~be~replaced~by~mode~`paper`.}
+ \tl_set:Nn\knowledge_option_mode_tl{paper}
+ \keys_set:nn{knowledge~package~modes}{paper}},
+ unknown .code:n =
+ {\knowledge_warning:x{Unknown~mode~`\l_keys_key_tl`.}
+ \tl_set:Nn\knowledge_option_mode_tl{ composition }
+ \keys_set:nV{ knowledge~package~modes }{ composition }}
+}
+\keys_set:nV{ knowledge~package~modes }\knowledge_option_mode_tl
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
+\knowledge_option_aci_autoload:nn{ hyperref }{hidelinks}
+\knowledge_option_aci_autoload:nn{ xcolor }{}
+\knowledge_option_aci_autoload:nn{ makeidx }{}
+% \end{macrocode}
+%
+%
+%
+%
+% \subsection{Scope implementation}
+%
+% The two strings that are used as (hopefully) unique prefixes in the namespace.
+% \begin{macrocode}
+\tl_gset:Nn\scope_tl{SC@PE:}
+\tl_gset:Nn\scopept_tl{K@UX:}
+% \end{macrocode}
+% \intro{\scope_instances_stack_seq} contains the stack of instances of areas.
+% \intro{\scope_top_instance_tl} contains always the topmost instance of the stack.
+% \intro{\scope_top_area_tl} contains the corresponding \kl{area}.
+% \begin{macrocode}
+\seq_new:N\scope_instances_stack_seq
+\tl_new:N\scope_top_instance_tl
+\tl_new:N\scope_top_area_tl
+% \end{macrocode}
+%
+%
+% \subsubsection{Data structures}
+%
+% Several `data structures' are used internally by the package.
+% \begin{description}
+% \item[\kl{areas}] are zones structuring valid documents. These are typically
+% `\texttt{document}', `\texttt{scope}', `\texttt{section}', `\texttt{subsection}', `\texttt{theorem}', `\texttt{itemize}', `\texttt{item}' and so on.
+% \item[\kl{categories}] are collections of \kl{areas} that share some common behaviours, for instance, the \kl{category} `\texttt{itemize-like}' will aggregate
+% `\texttt{itemize}', `\texttt{enumerate}' \kl{areas}. In particular an `\texttt{item}'
+% \kl{area} is required to have a parent that belongs to the \kl{category} `\texttt{itemize-like}'.
+% \item[\kl{instances}] are the realization of \kl{areas} in a document. Hence `section' is an \kl{area},
+% but each section of a document is an \kl{instance}.
+% \item[\kl{scopept instances}] stands for `phase two'. These are functions that are activated during
+% the second compilation. (and also, under implementation, in the preamble)
+% \item[\kl{knowledges}] are the central notion
+% \end{description}
+%
+% \paragraph{Areas}
+%
+% An \intro{area} is an environment unit such as `\texttt{theorem}', `\texttt{section}', and so on\dots{}
+% Special realization of these \kl{areas} are called `\kl{instances}'.
+% Hence, there is an \kl{area} named `\texttt{section}', and there are potentially
+% many \kl{instances} of this area in the document.
+% Part of the machinery is used for the allocation of \kl{instances}.
+% In some sense, this is a weak form of grammar describing how these can be used.
+% For instance, a subsection has to occur below a section, and opening a section immediately
+% closes the current subsection if it exists.
+%
+% To help the definition, the areas can be grouped into categories in order to share part of the code/definitions.
+% Each time an \kl{area} is defined, a corresponding \kl{category} with same name is also defined.
+%
+% An \kl{area} has some fields. The field X of \kl{area} A
+% can be found in the token of name |\scope_tl.area[A].X|.
+% \begin{compactdesc}
+% \item[\intro(area){nesting_int}] is an int counting the nesting level of the area at the current moment.
+% \item[\intro(area){count_int}] is an int counting the instances of the area opened so far. It is used (for the moment)
+% in order to uniquely name the instances. It is also used in some tests. It is incremented each time
+% a new \kl{instance} of this area is created.
+% \item[\intro(area){name_tl}] is the text name of the \kl{area}.
+% \item[\intro(area){pushcode_tl}] is code to be executed when an \kl{instance} of the \kl{area} is created.
+% \item[\intro(area){popcode_tl}] is code to be executed just before an \kl{instance} of the \kl{area} is closed.
+% \item[\intro(area){autoclose_bool}] is a boolean which, when set to true,
+% means that \kl{instances} of this area may be implicitly closed. This is the case for instance
+% for a `subsection', which can be implicitly closed when another `subsection' is started, or when
+% a `section' is started, or when the document finishes.
+% \item[\intro(area){recursive_bool}] is a boolean describing whether such an environment can be opened inside itself.
+% This is more for making the error messages explicit.
+% \item[\intro(area){multiple_bool}] is a boolean that tells whether several instances of this area can be defined
+% in the document. This is also mainly for making more explicit the error messages.
+% \item[\intro(area){forces_tl}] is the name of an area that has to be opened if one wants to use this area.
+% It is opened if necessary.
+% \item[\intro(area){acceptsknowledge_bool}] is a boolean telling whether a knowledge can be associated to an instance of this area.
+% \item[\intro(area){labelizable_bool}] tells whether a label can point to such an environment.
+% \item[\intro(area){attractsknowledge_bool}] is a boolean that tells whether this area
+% spontaneously catpures the \kl{knowledges} defined in its scope.
+% Hence, a section does not attract knowledges: the document does.
+% However, the user can force a knowledge to only be valid in a section since `section's accept knowledges.
+% \item[\intro(area){mandatorybase_seq}] is a \texttt{seq} containing the list of categories that are allowed to
+% be the parent of this area. For instance, \kl{\item}
+% would have \texttt{itemize}, \texttt{compactdesc} and \texttt{enumerate}.
+% \end{compactdesc}
+%
+%
+% \begin{macrocode}
+\cs_new:Nn\scope_area_show:n{
+ \group_begin:
+ \scope_area_if_exist:nTF{#1}
+ { \tl_set:Nx\self{\scope_tl.area[#1]}
+ \tl_show:x
+ {Area~name:~\use:c{\self.name_tl},~
+ autoclose=\bool_if:cTF{\self.autoclose_bool}TF,~
+ recursive=\bool_if:cTF{\self.recursive_bool}TF,~
+ multiple=\bool_if:cTF{\self.multiple_bool}TF,~
+ scope=\bool_if:cTF{\self.scope_bool}TF,~
+ environment=\bool_if:cTF{\self.environment_bool}TF,~
+ forces={\use:c{\self.forces_tl}},~
+ accepts~knowledge=\bool_if:cTF{\self.accepts_knowledge_bool}TF,~
+ attracts~knowledge=\bool_if:cTF{\self.attracts_knowledge_bool}TF,~
+ accepts~labels=\bool_if:cTF{\self.labelizable_bool}TF.
+ }
+ }
+ {\knowledge_error:n{Unknown~area~`#1'~in~`\noexpand\scope_area_show:n'.}}
+ \group_end:
+}
+% \end{macrocode}
+%
+%
+%
+% Areas are created empty by \kl\scope_area_create:n.
+% \begin{macrocode}
+\cs_new:Nn\scope_area_create:n
+ {\group_begin:
+ \tl_set:Nx\self{\scope_tl.area[#1]}
+ %
+ \scope_category_add_area:nn{all}{#1}
+ %
+ \tl_gset:cn{\self.name_tl}{#1}
+ \seq_new:c{\self.category_seq}
+ \seq_gpush:cn{\self.category_seq}{all}
+ \seq_gpush:cn{\self.category_seq}{#1}
+ \bool_gset_false:c{\self.autoclose_bool}
+ \bool_gset_true:c{\self.environment_bool}
+ \bool_gset_true:c{\self.multiple_bool}
+ \bool_gset_true:c{\self.attractsknowledge_bool}
+ \bool_gset_true:c{\self.labelizable_bool}
+ \bool_gset_false:c{\self.scope_bool}
+ \bool_gset_true:c{\self.acceptsknowledge_bool}
+ \tl_gset:cn{\self.pushcode_tl}{}
+ \tl_gset:cn{\self.popcode_tl}{}
+ \tl_gset:cn{\self.forces_tl}{}
+ \seq_new:c{\self.mandatorybase_seq}
+ \int_new:c{\self.count_int}
+ \int_gset:cn{\self.count_int}{0}
+ \int_new:c{\self.nesting_int}
+ \int_gset:cn{\self.nesting_int}{0}
+ %
+ \scope_category_if_exist:nTF{#1}
+ {}{\scope_category_create:n{#1}
+ \seq_gpush:cn{\scope_tl.category[#1].areas_seq}{#1}}
+ \group_end:
+}
+% \end{macrocode}
+%
+%
+% \kl\scope_area_if_exist:nTF, \kl\scope_area_if_in_scope:nTF.
+% \begin{macrocode}
+\cs_new:Npn\scope_area_if_exist:nTF#1
+ {\tl_if_exist:cTF{\scope_tl.area[#1].name_tl}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Npn\scope_if_triggers_area:nTF#1{
+ \scope_area_if_exist:nTF{#1}
+ {\bool_if:cTF{\scope_tl.area[#1].environment_bool}
+ \use_i:nn
+ \use_ii:nn}
+ \use_ii:nn
+}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Npn\scope_area_if_in_scope:nTF#1
+ {\int_compare:nNnTF
+ {\use:c{\scope_tl.area[#1].nesting_int}}>0}
+% \end{macrocode}
+%
+% \AP The commands \kl{\scope_area_set:nn}
+% introduces (if necessary) and changes the parameters of areas.
+% The first argument is a comma separated list of area names, and the second
+% argument is a comma separated list of key=val commands. The keys available by default are the following:
+%
+% \AP The base command for configuring a scope is \intro\ScopeConfigure\{area~list\}\{directives\}.
+% \begin{macrocode}
+\NewDocumentCommand\ScopeConfigure{mm}
+ {\scope_area_set:nn{#1}{#2}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_area_set:nn
+ {\clist_map_inline:nn{#1}
+ {\scope_area_set_i:nn{##1}{#2}}}
+\cs_new:Nn\scope_area_set_i:nn {
+ \scope_area_if_exist:nTF{#1}
+ {}{\scope_area_create:n{#1}}
+ \group_begin:
+ \tl_set:Nx\scope_area_tl{#1}
+ \tl_set:Nx\self{\scope_tl.area[\scope_area_tl]}
+ \keys_set:nn{ scope~area~set }{#2}
+ \group_end:}
+% \end{macrocode}
+% \begin{macrocode}
+% \scope_area_tl contains the name of the area under definition
+\keys_define:nn{ scope~area~set } {
+ category .code:n =
+ {\clist_map_inline:nn{#1}
+ {\scope_category_ensure:n{##1}
+ \seq_gpush:cV
+ {\scope_tl.category[##1].areas_seq}\scope_area_tl
+ }},
+ autoclose .choice:,
+ autoclose / false .code:n =
+ {\bool_gset_false:c{\self.autoclose_bool}},
+ autoclose / true .code:n =
+ {\bool_gset_true:c{\self.autoclose_bool}},
+ parents .code:n =
+ {\seq_gset_from_clist:cn{\self.mandatorybase_seq}{#1}},
+ push~code .code:n =
+ {\tl_gput_right:cn{\self.pushcode_tl}{#1}},
+ pop~code .code:n =
+ {\tl_gput_right:cn{\self.popcode_tl}{#1}},
+ occurrences .choice:,
+ occurrences / once .code:n =
+ {\bool_gset_false:c{\self.multiple_bool}
+ \bool_gset_false:c{\self.recursive_bool}},
+ occurrences / multiple .code:n = {
+ \bool_gset_true:c{\self.multiple_bool}
+ \bool_gset_false:c{\self.recursive_bool}},
+ occurrences / recursive .code:n = {
+ \bool_gset_true:c{\self.multiple_bool}
+ \bool_gset_true:c{\self.recursive_bool}},
+ scope .choice:,
+ scope / true .code:n = {
+ \bool_gset_true:c{\self.scope_bool}},
+ scope / false .code:n = {
+ \bool_gset_false:c{\self.scope_bool}},
+ environment .choice:,
+ environment / true .code:n = {
+ \bool_gset_true:c{\self.environment_bool}},
+ environment / false .code:n = {
+ \bool_gset_false:c{\self.environment_bool}},
+ environment .default:n = {true},
+ label .choice:,
+ label / none .code:n = {
+ \bool_gset_false:c{\self.labelizable_bool}},
+ label / accepts .code:n = {
+ \bool_gset_true:c{\self.labelizable_bool}},
+ knowledge .choice:,
+ knowledge / none .code:n = {
+ \bool_gset_false:c{\self.acceptsknowledge_bool}
+ \bool_gset_false:c{\self.attractsknowledge_bool}},
+ knowledge / accepts .code:n = {
+ \bool_gset_true:c{\self.acceptsknowledge_bool}
+ \bool_gset_false:c{\self.attractsknowledge_bool}},
+ knowledge / attracts .code:n = {
+ \bool_gset_true:c{\self.acceptsknowledge_bool}
+ \bool_gset_true:c{\self.attractsknowledge_bool}},
+ forces .code:n =
+ {\tl_gset:cn{\self.forces_tl}{#1}}
+}
+% \end{macrocode}
+%
+% \paragraph{Categories}
+%
+%\begin{compactdesc}
+% \item[\intro{\scope_category_if_exist:nTF}] tests if a \kl{category} does exist.
+% \item[\intro{\scope_category_ensure:n}] guarantees that a \kl{category} exists, possibly creating it if necessary.
+% \item[\intro{\scope_category_create:n}] creates a \kl{category}.
+% \item[\intro{\scope_category_add_area:nn}] adds an \kl{area} to a \kl{category}.
+% \item[\intro{\scope_category_use:n}] displays the \kl{category} as a comma separated list of \kl{area} names (expandable).
+% \item[\intro{\scope_category_show:n}] shows the content of a \kl{category} on the console.
+% \end{compactdesc}
+% \iffalse
+% \begin{macrocode}
+\cs_new:Npn\scope_category_if_exist:nTF#1
+ {\tl_if_exist:cTF{\scope_tl.category[#1].name_tl}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_category_ensure:n
+ {\scope_category_if_exist:nTF
+ {#1}{}{\scope_category_create:n{#1}}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_category_create:n
+ {\tl_gset:cn{\scope_tl.category[#1].name_tl}{#1}
+ \seq_new:c{\scope_tl.category[#1].areas_seq}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_category_add_area:nn
+ {\scope_category_ensure:n{#1}
+ \seq_gpush:cn{\scope_tl.category[#1].areas_seq}{#2}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_category_use:n
+ {\seq_use:cn{\scope_tl.category[#1].areas_seq},}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_category_show:n
+ {\seq_show:c{\scope_tl.category[#1].areas_seq}}
+% \end{macrocode}
+%\fi
+%
+%\paragraph{Instances}
+%
+% We now turn to define the fields involved in an instance.
+% There are two series of objects. The ones defined in the first pass of compilation,
+% and used for maintaining the structure of the scopes, and the ones
+% that are used in the second pass, which gather information throughout the
+% whole file. The first one are prefixed by \texttt{scope},
+% the others by \texttt{kaux}.
+% \begin{compactdesc}
+% \item[\intro{instance.area}] is the name of the area it is an instance of.
+% \item[\intro{instance.parent}] is the name of the parent instance.
+% \end{compactdesc}
+% \begin{compactdesc}
+% \item[\intro{\scope_instance_if_exist:nTF}]
+% \item[\intro{\scopept_instance_if_exist:nTF}]
+% \item[\intro{\scopept_label_if_exist:nTF}]
+% \end{compactdesc}
+%\iffalse
+% \begin{macrocode}
+\cs_new:Npn\scope_instance_if_exist:nTF#1
+ {\tl_if_exist:cTF{\scope_tl.instance[#1].area_tl}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Npn\scopept_instance_if_exist:nTF#1
+ {\tl_if_exist:cTF{\scopept_tl.instance[#1].area_tl}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Npn\scopept_label_if_exist:nTF#1
+ {\tl_if_exist:cTF{\scopept_tl.label[#1].instance_tl}}
+% \end{macrocode}
+%\fi
+%
+% \subsubsection{Pushing and popping}
+%
+% Introduces the macros \intro{\scope_area_push:n} and \intro{\scope_area_pop:n}.
+%
+% The token lists \intro{\scope_popped_area_tl} and \intro{\scope_pushed_area_tl}
+% contain the area that triggered the push / the pop. These lists are only meaningful in these macros.
+% \begin{macrocode}
+\tl_new:N\scope_pushed_area_tl
+\tl_new:N\scope_popped_area_tl
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_area_pop:n {
+ \tl_gset:Nn\scope_popped_area_tl{#1}
+ \bool_if:cTF{\scope_tl.area[\scope_popped_area_tl].autoclose_bool}
+ {\msg_error:nn{scope}{no~popping}}
+ {\scope_area_pop_i:}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_area_pop_i: {
+ \tl_if_eq:NNTF\scope_top_area_tl\scope_popped_area_tl
+ {\scope_internal_pop:}
+ {\bool_if:cTF{\scope_tl.area[\scope_top_area_tl].autoclose_bool}
+ {\scope_internal_pop:
+ \scope_area_pop_i:}
+ {\msg_error:nn{scope}{no~popping~here}}}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_internal_pop: {
+ \use:c{\scope_tl.area[\scope_top_area_tl].popcode_tl}
+ \seq_gpop:NNTF\scope_instances_stack_seq\scope_top_instance_tl
+ {\int_gdecr:c{\scope_tl.area[\scope_top_area_tl].nesting_int}
+ \exp_args:NV\knowledge_pop_visible_instances_to:n\scope_top_instance_tl
+ \seq_get:NN\scope_instances_stack_seq\scope_top_instance_tl
+ \tl_gset_eq:NN\scope_top_instance_tl\scope_top_instance_tl
+ \tl_gset:Nx\scope_top_area_tl
+ {\tl_use:c{\scope_tl.instance[\scope_top_instance_tl].area_tl}}}
+ {\msg_error:nnn{scope}{empty~pop}{}}
+ }
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_area_push:n {
+ \tl_gset:Nn\scope_pushed_area_tl{#1}
+ \scope_area_push_i:n{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_area_push_i:n {
+ \tl_if_empty:cTF{\scope_tl.area[#1].forces_tl}
+ {}
+ {\exp_args:Nx\scope_area_if_in_scope:nTF
+ {\tl_use:c{\scope_tl.area[#1].forces_tl}}
+ {}
+ {\exp_args:Nx\scope_area_push_i:n
+ {\tl_use:c{\scope_tl.area[#1].forces_tl}}}}
+ \scope_area_push_ii:n{#1}
+}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Npn\scope_if_area_in_areaclist:nnTF#1
+ {\exp_args:NnV\clist_if_in:nnTF{#1}\scope_top_area_tl}
+
+\cs_new:Nn\scope_category_expand:n
+ {\clist_use:x{
+ \clist_map:nN{#1}{
+ \seq_use:c{\scope_tl.category[#1].areas_seq},}}}
+
+\cs_new:Nn\scope_categories_expand:n
+ {\clist_map_function:nN{#1}\scope_category_expand:n}
+
+\cs_new:Nn\scope_if_area_in_categoryclist:nnTF
+ {\group_begin:
+ \tl_set:Nx\l_tmpa_tl
+ {\clist_map_function:nN{#2}\scope_category_areas_use:n}
+ \bool_set_false:N\l_tmpa_bool
+ \clist_map_inline:nn{#2}
+ {\scope_category_areas_if_in:nnTF{##1}{#1}
+ {\bool_set_true:N\l_tmpa_bool\seq_map_break:}{}}
+ \bool_if:NTF\l_tmpa_bool
+ {\group_end:#3}
+ {\group_end:#4}
+ }
+
+
+\cs_new:Npn\scope_category_if_area_in:nnTF#1#2
+ {\exp_args:Nnx\seq_if_in:cnTF
+ {\scope_tl.category[#1].areas_seq}{#2}}
+
+\cs_new:Nn\scope_categoryseq_if_area_in:NnTF
+ { \seq_if_empty:NTF#1
+ {#3}
+ {\group_begin:
+ \bool_set_false:N\l_tmpa_bool
+ \seq_map_inline:Nn#1
+ {\seq_if_in:cnTF{\scope_tl.category[##1].areas_seq}{#2}
+ {\bool_set_true:N\l_tmpa_bool\seq_map_break:}{}}
+ \bool_if:NTF\l_tmpa_bool
+ {\group_end:#3}
+ {\group_end:#4}
+ }}
+
+\cs_new:Npn\scope_area_mandatorybase_if_area_in:nnTF#1
+ {\exp_args:Nc\scope_categoryseq_if_area_in:NnTF
+ {\scope_tl.area[#1].mandatorybase_seq}}
+
+\cs_new:Nn\scope_categoryseq_pop_to:N
+ {\exp_args:NNx\scope_categoryseq_if_area_in:NnTF#1{\scope_top_area_tl}
+ {}{\scope_auto_pop:\scope_categoryseq_pop_to:N#1}}
+
+\cs_new:Nn\scope_categoryseq_pop_to:n
+ {\group_begin:
+ \seq_set_from_clist:Nn\l_tmpa_seq{#1}
+ \scope_categoryseq_pop_to:N\l_tmpa_seq
+ \group_end:}
+
+\cs_new:Nn\scope_area_push_ii:n {
+ \seq_if_empty:cTF{\scope_tl.area[#1].mandatorybase_seq}
+ {\scope_internal_push:n{#1}}
+ {\exp_args:Nnx\use:n
+ {\scope_area_mandatorybase_if_area_in:nnTF{#1}}
+ {\scope_top_area_tl}
+ {\scope_internal_push:n{#1}}
+ {\scope_auto_pop:
+ \scope_area_push_ii:n{#1}}}
+ }
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_internal_push:n {
+ \tl_gset:Nn\scope_top_area_tl{#1}
+ \int_gincr:c{\scope_tl.area[\scope_top_area_tl].nesting_int}
+ \int_gincr:c{\scope_tl.area[\scope_top_area_tl].count_int}
+ % storing the previous top instance
+ \tl_set_eq:NN\l_tmpa_tl\scope_top_instance_tl
+ %naming the new instance
+ \bool_if:cTF{\scope_tl.area[\scope_top_area_tl].multiple_bool}
+ {\tl_gset:Nx\scope_top_instance_tl
+ {\scope_top_area_tl-\int_to_arabic:n{\int_use:c{\scope_tl.area[\scope_top_area_tl].count_int}}}}
+ {\tl_gset_eq:NN\scope_top_instance_tl\scope_top_area_tl}
+ %
+ \exp_args:Nx\knowledge_push_visible_instance:n{\scope_top_instance_tl}
+ \seq_push:Nx\scope_instances_stack_seq{\scope_top_instance_tl}
+ %
+ \tl_gset:cx
+ {\scope_tl.instance[\scope_top_instance_tl].area_tl}
+ {\scope_top_area_tl}
+ \tl_gset:cx
+ {\scope_tl.instance[\scope_top_instance_tl].parent_tl}
+ {\l_tmpa_tl}
+ %
+ \seq_if_exist:cTF{\scopept_tl.instance[\l_tmpa_tl].context_seq}
+ {\seq_set_eq:Nc\l_tmpa_seq{\scopept_tl.instance[\l_tmpa_tl].context_seq}}
+ {\seq_clear_new:N\l_tmpa_seq}
+ \exp_args:NNx\seq_gpush:Nn
+ \l_tmpa_seq{\scope_top_instance_tl}
+ \seq_gset_eq:cN
+ {\scopept_tl.instance[\scope_top_instance_tl].context_seq}
+ \l_tmpa_seq
+ %
+ \KAuxWriteX
+ {\KAuxScopeNewInstance{\scope_top_area_tl}{\scope_top_instance_tl}{\l_tmpa_tl}}
+ %
+ \tl_use:c{\scope_tl.area[\scope_top_area_tl].pushcode_tl}
+}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_auto_pop: {
+ \bool_if:cTF{\scope_tl.area[\scope_top_area_tl].autoclose_bool}
+ {\scope_internal_pop:}
+ {\msg_error:nn{scope}{no~pushing~here}}
+ }
+% \end{macrocode}
+%
+%
+% \subsubsection{Inspecting}
+%
+% \intro{\scope_get_attractive_instance:N} takes a \kl{token list variable},
+% and sets it to contain an
+% instance able to receive knowledges.
+% This is done by inspecting the scope stack until reaching an instance
+% that has \kl{instance.attractsknowledge_bool} set to true (by default, this is `base').
+%
+% Searching for instances.
+% \begin{macrocode}
+\cs_new:Nn\scope_get_attractive_instance:N
+{\tl_set:Nn#1{base}
+ \seq_map_inline:Nn\scope_instances_stack_seq
+ {\bool_if:cTF
+ {\scope_tl.area[\tl_use:c{\scope_tl.instance[##1].area_tl}].attractsknowledge_bool}
+ {\tl_set:Nn#1{##1}\seq_map_break:}{}}
+}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new:Nn\scope_get_labelizable_instance:N
+{\tl_set:Nn#1{base}
+ \seq_map_inline:Nn\scope_instances_stack_seq
+ {\bool_if:cTF
+ {\scope_tl.area[\tl_use:c{\scope_tl.instance[##1].area_tl}].labelizable_bool}
+ {\tl_set:Nn#1{##1}\seq_map_break:}{}}
+}
+% \end{macrocode}
+%
+% The command \kl{\knowledge_scope_track_instance:Nn} tries to find a given instance in the current context,
+% and if it fails, it tries to find a label of this name that provides an instance.
+% \begin{macrocode}
+\cs_new:Nn\knowledge_scope_track_instance:Nn{
+ \scope_area_if_exist:nTF{#2}
+ {\knowledge_scope_track_instance_from_area:Nn#1{#2}}
+ {\knowledge_scope_track_instance_from_label:Nn#1{#2}}
+}
+\cs_new:Nn\knowledge_scope_track_instance_from_area:Nn{
+ \tl_set:Nn#1{}
+ \seq_map_inline:Nn\scope_instances_stack_seq
+ {\exp_args:Nxx\tl_if_eq:nnTF
+ {\csname \scope_tl.instance[##1].area_tl\endcsname}
+ {#2}
+ {\tl_set:Nn#1{##1}\seq_map_break:}
+ {}}
+ \tl_if_empty:NTF#1
+ {\msg_error:nnxx{scope}{area~not~in~context}{#2}{scope=}}
+ {}
+}
+\cs_new:Nn\knowledge_scope_track_instance_from_label:Nn{
+ \tl_set:Nn#1{}
+ \scopept_label_instance_if_exist:nTF{#2}
+ {\tl_set:Nx#1{\scopept_label_instance_use:n{#2}}}
+ {\msg_warning:nnnn{scope}{unknown~label}{#2}{scope=}}
+}
+% \end{macrocode}
+% \begin{macrocode}
+\bool_new:N\scopept_map_break_bool
+\cs_new:Nn\scopept_map_break:
+ {\bool_set_true:N\scopept_map_break_bool}
+
+\cs_new:Nn\scopept_map_instance_ancestors:nN
+ {\bool_set_false:N\scopept_map_break_bool
+ \scope_map_instance_ancestors_i:nN{#1}#2
+ }
+\cs_new:Nn\scopept_map_instance_ancestors_i:nN
+{ \tl_if_empty:nTF{#1}
+ {}
+ {\scopept_instance_if_exist:nTF{#1}{
+ #2{#1}
+ \bool_if:NTF\scopept_map_break_bool
+ {}
+ {\exp_args:Nx\scopept_map_instance_ancestors_i:nN
+ {\scopept_instance_parent_at:Nn\tl_use:N{#1}}#2}}
+ {}}}
+\cs_new:Nn\scopept_map_instances_seq_ancestors:NN
+ {\seq_map_inline:Nn#1
+ {\scopept_map_instance_ancestors_i:nN{##1}#2
+ \bool_if:NTF\scopept_map_break_bool:{\seq_map_break:}{}}
+}
+% \end{macrocode}
+%
+%
+% \subsubsection{Label overloading}
+%
+% In order to identify scopes, the standard \kl{\label} command is used.
+% This requires to overload it for it to write on the \kl{kaux file}.
+% Thus, the new \kl{\label} command executes the original code,
+% and furthermore writes in the \kl{kaux file} a \kl{\KAuxScopeLabel} command.
+% \iffalse
+% Note that in order to accelerate compilation, the label is both written on the "kaux file",
+% and directly in the memory. This
+% \fi
+% \begin{macrocode}
+\NewDocumentCommand\scopeLabel{m}
+ { \kl_hide_begin:
+ \scope_get_labelizable_instance:N\l_tmpb_tl
+ \KAuxWriteX*{\exp_not:n{\KAuxScopeLabel}{#1}{\l_tmpb_tl}}
+ \tl_gset:cx{\scopept_tl.label[#1].instance_tl}{\l_tmpb_tl}
+ \kl_hide_end:
+ \cs_if_exist:NTF\LaTeXlabel\LaTeXlabel\use_none:n{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\let\label\scopeLabel
+% \end{macrocode}
+%
+%
+%\subsubsection{Processing the \kl{kaux file}}
+%
+% When reading the file, scope outputs commands that will be processed
+% at the next iteration. It shares the output files \kl{jobname.kaux} for that.
+% Commands that may be used in this process are defined here.
+% \begin{macrocode}
+\NewKAuxCommand\KAuxScopeNewInstance{mmm}
+ {Package~scope:~Declares~a~new~instance~of~a~scope.}
+\DeclareKAuxPhaseCommand\KAuxScopeNewInstance{init}
+ {\tl_gset:cn{\scopept_tl.instance[#2].area_tl}{#1}
+ \tl_gset:cn{\scopept_tl.instance[#2].parent_tl}{#3}}
+% \end{macrocode}
+% \begin{macrocode}
+\NewKAuxCommand\KAuxScopeLabel{mm}
+ {Package~scope:~Links~a~label~to~the~scope~of~its~definition.}
+\DeclareKAuxPhaseCommand\KAuxScopeLabel{init}
+ {\tl_gset:cn{\scopept_tl.label[#1].instance_tl}{#2}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Npn\scopept_label_instance_if_exist:nTF#1
+ {\tl_if_exist:cTF{\scopept_tl.label[#1].instance_tl}}
+\cs_new:Nn\scopept_label_instance_use:n
+ {\tl_use:c{\scopept_tl.label[#1].instance_tl}}
+% \end{macrocode}
+%
+% \subsubsection{Commands}
+%
+% The command \kl{\knowledgeconfigureenvironment} declares a
+% standard latex environment to behave like the \kl(env){scope} environment
+% (while keeping its standard display).
+% \begin{macrocode}
+\newcommand\knowledgeconfigureenvironment\KnowledgeConfigureEnvironment
+\NewDocumentCommand\KnowledgeConfigureEnvironment{t?t!mm}
+ {\clist_map_inline:nn{#3}{
+ \IfBooleanTF{#2}
+ {\scope_area_environment_new:nn{##1}{#4}}
+ {\cs_if_exist:cT{##1}
+ {\cs_if_exist:cT{end##1}
+ {\scope_area_environment_new:nn{##1}{#4}
+ \use_none:n}}
+ {\IfBooleanF{#1}
+ {\knowledge_error:n{Unknown~environment~`##1'~in~\KnowledgeConfigureEnvironment.}}}
+ }}}
+\newcommand\scope_activate_environment[2][environment]{
+ \scope_area_environment_new:nn
+ {#2}{category=#1}}
+\cs_new:Nn\scope_area_environment_new:nn
+ {\scope_area_set:nn{#1}{
+ parents = all,
+ autoclose = false,
+ environment = true,
+ occurrences = recursive,
+ knowledge = attracts,
+ category = environment,
+ #2
+ }}
+% \end{macrocode}
+%
+%
+% \subsubsection{Activation of the \kl{scope option}}
+%
+% \begin{macrocode}
+\NewDocumentCommand\ScopeHackEnvironments{}
+ { %\ScopeActivate
+ \scope_area_push:n{document}
+ \kutils_secure_latex_command:N\begin
+ \global\let\SUPERbegin\begin
+ \global\def\begin##1
+ {\scope_if_triggers_area:nTF{##1}
+ {\scope_area_push:n{##1}}{}
+ \SUPERbegin{##1}}
+ \kutils_secure_latex_command:N\end
+ \global\let\SUPERend\end
+ \global\def\end##1
+ {\SUPERend{##1}
+ \scope_if_triggers_area:nTF{##1}
+ {\scope_area_pop:n{##1}}
+ {}}
+ \kutils_secure_latex_command:N\label
+ \let\label\scopeLabel
+}
+% \end{macrocode}
+%
+% This command will activate the scope package.
+% The idea is that this package, if activated too early, then
+% it may not yet have all its features usable. However, it
+% must be loaded before being used, e.g., by commands
+% like knowledge.
+% \begin{macrocode}
+\NewDocumentCommand\ScopeActivate{}{
+ \scope_internal_push:n{base}
+ \cs_gset_eq:NN\ScopeActivate\relax
+}
+\AtBeginDocument{\ScopeActivate}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\AtBeginDocument{\ScopeHackEnvironments}
+%\AtEndDocument{\scope_area_pop:n{document}}
+% \end{macrocode}
+%
+% \begin{macrocode}
+ \scope_area_set:nn{document,base,body} {
+ environment=false
+ }
+ \scope_area_set:nn{base}
+ {occurrences = once,
+ autoclose = false}
+ \scope_area_set:nn{document}
+ {autoclose = false,
+ occurrences = once,
+ parents = base}
+ \scope_area_set:nn{body}
+ {autoclose = true,
+ occurrences = once,
+ parents = document}
+ \scope_area_set:nn
+ {base,document}{knowledge=accepts}
+ \scope_area_set:nn
+ {base,document}{knowledge=attracts}
+ \scope_area_set:nn
+ {body}{knowledge=none}
+ %
+ \newenvironment{scope}
+ {\mode_if_preamble:TF{\scope_area_push:n{scope}}{}}
+ {\mode_if_preamble:TF{\scope_area_pop:n{scope}}{}}
+ \knowledgeconfigureenvironment{scope}{}
+% \end{macrocode}
+%
+% \subsubsection{Importing and exporting scopes}
+% \begin{macrocode}
+\scope_area_set:nn{knowledge~context~internal}
+{
+ occurrences = recursive,
+ autoclose = false,
+ parents= {base,all},
+ knowledge=attracts
+}
+\scope_area_set:nn{knowledge~import~internal}
+{
+ occurrences = recursive,
+ autoclose = false,
+ parents= {base,all},
+ knowledge = accepts
+}
+\NewDocumentEnvironment{knowledge~import}{m}
+ {\ScopeActivate\scope_area_push:n{knowledge~import~internal}
+ \clist_map_inline:nn{#1}{\knowledgeimport{##1}}}
+ {\scope_area_pop:n{knowledge~import~internal}}
+\NewDocumentEnvironment{knowledge~context}{m}
+ {\ScopeActivate\scope_area_push:n{knowledge~context~internal}
+ \scopeLabel{#1}}
+ {\scope_area_pop:n{knowledge~context~internal}}
+% \end{macrocode}
+% \subsection{Files}
+%
+%
+% \subsubsection{KAux file}
+%
+% Code to be executed before, at initialization and after the writing of the \kl{kaux file}.
+% \begin{macrocode}
+\KAuxBefore{\KAuxProcess{init}}
+\KAuxInit{}
+\KAuxAfter{\KnowledgeDiagnoseOutput}
+% \end{macrocode}
+%
+% \subsubsection{Diagnose file}
+%
+% \begin{macrocode}
+\iow_new:N\knowledge_diagnosefile_iow
+\cs_new:Nn\knowledge_diagnose:n
+ {\iow_now:Nn\knowledge_diagnosefile_iow{#1}}
+\cs_generate_variant:Nn\knowledge_diagnose:n{x,V}
+
+\cs_new:Nn\knowledge_diagnose_reset_line:
+ {\tl_gset:Nn\knowledge_diagnose_lastline_tl{...}}
+\knowledge_diagnose_reset_line:
+
+\cs_new:Nn\knowledge_diagnose_line:
+ {\bool_if:NT\knowledge_configuration_diagnoseline_bool
+ {\tl_set:Nx\g_tmpa_tl
+ {\c_percent_str\space\kauxCurrentFile : \kauxCurrentLine}
+ \tl_if_eq:NNTF\g_tmpa_tl\knowledge_diagnose_lastline_tl
+ {}
+ {\tl_gset_eq:NN\knowledge_diagnose_lastline_tl\g_tmpa_tl
+ \knowledge_diagnose:V\g_tmpa_tl}}}
+
+\msg_new:nnn{knowledge}{unknown~knowledge}
+ {Some~knowledge~are~not~defined.~See~the~'.diagnose'~file~for~more~information.}
+\msg_new:nnn{knowledge}{autoref~introduced~twice}
+ {Some~knowledge~is~introduced~twice.~See~the~'.diagnose'~file~for~more~information.}
+\msg_new:nnn{knowledge}{autoref~not~introduced}
+ {Some~knowledge~is~used~but~not~introduced.~See~the~'.diagnose'~file~for~more~information.}
+\msg_new:nnn{knowledge}{scope~unknown}
+ {Some~label~is~used~but~not~defined.~See~the~'.diagnose'~file~for~more~information.}
+
+\NewDocumentCommand\KnowledgeDiagnoseOutput{}{
+ \iow_open:Nn\knowledge_diagnosefile_iow{\c_sys_jobname_str.diagnose}
+ % compute first the list of warnings and important information
+ %
+ \knowledge_diagnose_reset_line:
+ \KAuxProcess{diagnose-digest}
+ %
+ \knowledge_diagnose:n{***********}
+ \knowledge_diagnose:n{*~Summary~*}
+ \knowledge_diagnose:n{***********}
+ \knowledge_diagnose:n{}
+ \knowledge_diagnose:x{\int_use:N\kl_digest_unknownknowledge_int\space undefined~knowledge(s).}
+ %\knowledge_diagnose:x{\int_use:N\kl_digest_unknownlabel_int\space label(s)~are~used~as~scopes~but~not~introduced.}
+ \knowledge_diagnose:x{\int_use:N\kl_digest_autoreftwiceintro_int\space autoreference(s)~are~introduced~twice.}
+ \knowledge_diagnose:x{\int_use:N\kl_digest_autorefnointro_int\space autoreference(s)~are~used~but~not~introduced.}
+ \knowledge_diagnose:n{}
+ \knowledge_diagnose:x{\int_use:N\kl_digest_autorefused_int\space autoreference(s)~are~properly~used.}
+ \knowledge_diagnose:x{\int_use:N\kl_digest_autorefunused_int\space autoreference(s)~are~defined~but~not~used.}
+ \knowledge_diagnose:n{}
+ \knowledge_diagnose:n{}
+ %
+ \int_compare:nNnT\kl_digest_unknownknowledge_int>0{
+ \knowledge_diagnose:n{************************}
+ \knowledge_diagnose:n{*~Undefined~knowledges~*}
+ \knowledge_diagnose:n{************************}
+ \knowledge_diagnose:n{}
+ %
+ \knowledge_diagnose_reset_line:
+ \KAuxProcess{diagnose-unknown-suggest}
+ %
+ \knowledge_diagnose:n{}
+ \knowledge_diagnose:n{}
+ %
+ \msg_warning:nn{knowledge}{unknown~knowledge}
+ }
+ %
+ \int_compare:nNnT\kl_digest_autoreftwiceintro_int>0{
+ \knowledge_diagnose:n{****************************}
+ \knowledge_diagnose:n{*~autoref-introduced-twice~*}
+ \knowledge_diagnose:n{****************************}
+ \knowledge_diagnose:n{}
+ %
+ \knowledge_diagnose_reset_line:
+ \KAuxProcess{autoref-introduced-twice}
+ %
+ \knowledge_diagnose:n{}
+ \knowledge_diagnose:n{}
+ %
+ \msg_warning:nn{knowledge}{autoref~introduced~twice}
+ }
+ %
+ \int_compare:nNnT\kl_digest_autorefnointro_int>0{
+ \knowledge_diagnose:n{******************************}
+ \knowledge_diagnose:n{*~Autoref~used~without~intro~*}
+ \knowledge_diagnose:n{******************************}
+ \knowledge_diagnose:n{}
+ %
+ \knowledge_diagnose_reset_line:
+ \KAuxProcess{autoref-not-introduced}
+ %
+ \knowledge_diagnose:n{}
+ \knowledge_diagnose:n{}
+ %
+ \msg_warning:nn{knowledge}{autoref~not~introduced}
+ }
+ %
+ \iffalse
+ \knowledge_diagnose:n{***********************}
+ \knowledge_diagnose:n{*~Exported~knowledges~*}
+ \knowledge_diagnose:n{***********************}
+ \knowledge_diagnose:n{}
+ \KAuxProcess{diagnose-export}
+ \knowledge_diagnose:n{}
+ \fi%
+ \iow_close:N\knowledge_diagnosefile_iow
+}
+% \end{macrocode}
+%
+%
+%
+%
+% \subsection{Accessing knowledges}
+%
+% We define now the basic macros that are used for accessing knowledges.
+% Each knowledge is identified by three parameters:
+% \begin{itemize}
+% \item the namespace name (no arobas in it), each different use of the "knowledge@@package" package can use a different namespace. For the moment, this is always `default'.
+% \item the \kl{instance} name (defining the scope, i.e. the region in which it is defined; no arobas in it), it is generated and dealt with by the \texttt{scope} package,
+% \item the \kl{knowledge} text itself.
+% \end{itemize}
+%
+% The variable \kl{\knowledge_namespace_tl}
+% stores the current namespace, i.e. the ones that is used by default.
+% It is sometimes temporarily modified.
+% \begin{macrocode}
+\tl_set:Nn\knowledge_knowledge_default_namespace_tl {default}
+% \end{macrocode}
+% The macro \kl{\knowledge_id:nnn} takes these three arguments in
+% this order (namespace/instance/scope) and produces a unique string that can be used to access
+% (using \kl{\csname}, or \texttt{:c} in LaTeX3) the tuple.
+% \begin{macrocode}
+\makeatother
+\cell_new_type:nnn{knowledge}{nnnn}{KL@#2@#3@\detokenize{#4}_#1}
+\cell_new_type:nnn{knowledge}{nnn}{\knowledge_id:nnnn{}{#1}{#2}{#3}}
+\cs_generate_variant:Nn\knowledge_id:nnn{nnV,nVV,nVn,VVV}
+\cs_generate_variant:Nn\knowledge_at:Nnnn{NnnV}
+\cs_new:Npn\knowledge_at:c{\exp_args:Nc\knowledge_at:N}
+% \end{macrocode}
+% For convenience, when the same knowledge has to be accessed many times, one uses
+% \kl{\knowledge_sets_to:nnn} which is followed by the same three arguments.
+% It defines \kl{\knowledge_at:N}\kl{\token} to execute \kl{\token} with as
+% first parameter the token pointing to the knowledge.
+% \begin{macrocode}
+\cs_new:Nn\knowledge_sets_to:nnn
+ {\cs_set:Nx\knowledge_at:N
+ {##1\exp_not:c{\knowledge_id:nnn{#1}{#2}{#3}}}}
+% \end{macrocode}
+% Finally, one creates a new kind of tuples, called ktuples for storing the \kl{knowledges}.
+% \begin{macrocode}
+\tuple_new:n{ktuple}
+% \end{macrocode}
+% Some more code.
+% \begin{macrocode}
+\cs_new:Npn\knowledge_knowledge_if_exist:nnnTF#1#2#3{
+ \exp_args:Nc\ktuple_if_exist:NTF{\knowledge_id:nnn{#1}{#2}{#3}}
+}
+\cs_generate_variant:Nn
+ \knowledge_knowledge_if_exist:nnnTF{VVVTF}
+% \end{macrocode}
+%
+%
+% \subsection{Knowledge code}
+%
+%
+% \subsubsection{Defining directives}
+%
+%
+% The commands used for introducing new directives.
+% The command
+% \begin{code}
+% \intro\NewKnowledgeParamBool[*]\{name\}\kl{\token}
+% \end{code}\noindent
+% creates a new boolean directive of name `name'.
+% When the knowledge is executed, the value will be stored in the \kl{\token}.
+% By default, the directive is only usable in \kl{knowledgenow directives}.
+% If the optional star is used, then the \kl{directive} is usable in the \kl{\knowledge} command, and its value is propagated automatically. Hence, no-star means internal booleans used by the
+% system, and star means booleans accessible to the user.
+% \iffalse
+% \begin{macrocode}
+\NewDocumentCommand\NewKnowledgeParamBool{smm}{
+ \ktuple_new_bool_index:n{#2}
+ \use:c{ktuple_#2_expands_to:TF}
+ {\bool_set_true:N#3}{\bool_set_false:N#3}
+ %
+ \keys_define:nn { knowledgenow~directives }{
+ #2 .choice:,
+ #2 / false .code:n =
+ { \knowledge_at:c{ktuple_#2_gset_false:N}},
+ #2 / true .code:n =
+ { \knowledge_at:c{ktuple_#2_gset_true:N} },
+ #2 / default .code:n =
+ { \knowledge_at:c{ktuple_#2_gdel:N}},
+ #2 .default:n = {true}
+ }
+ \IfBooleanTF{#1}{\KnowledgeTransferBool{#2}}{}
+}
+\NewDocumentCommand\KnowledgeTransferBool{m}{
+ \clist_map_inline:nn{ #1 }{
+ \keys_define:nn { knowledge~directives }{
+ ##1 .choice:,
+ ##1 / false .code:n = { \knowledge_delay_directive:n{##1= false}},
+ ##1 / true .code:n = { \knowledge_delay_directive:n{##1= true}},
+ ##1 / default .code:n = { \knowledge_delay_directive:n{##1= default}},
+ ##1 .default:n = true
+ }}
+}
+% \end{macrocode}
+% \fi
+% The command \kl{\NewKnowledgeParamTl} is similar to \kl{\NewKnowledgeParamBool},
+% but creates a directive that stores text.
+% \begin{code}
+% \intro\NewKnowledgeParamTl[*]\{name\}\kl{\token}
+% \end{code}\noindent
+% \iffalse
+% \begin{macrocode}
+\NewDocumentCommand\NewKnowledgeParamTl{smm}{
+ \ktuple_new_tl_index:n{#2}
+ \use:c{ktuple_#2_expands_to:n}
+ {\tl_set:Nn#3{##1}}
+ %
+ \keys_define:nn { knowledgenow~directives }{
+ #2 .code:n =
+ { \knowledge_at:c{ktuple_#2_gset:Nn}{##1} },
+ #2~X .code:n =
+ { \knowledge_at:c{ktuple_#2_gset:Nx}{##1} },
+ no~#2 .code:n =
+ { \knowledge_at:c{ktuple_#2_gdel:N} }}
+ \IfBooleanTF{#1}{\KnowledgeTransferTl{#2}}{}
+}
+% \end{macrocode}
+% \begin{macrocode}
+\NewDocumentCommand\KnowledgeTransferTl{m}
+ {\keys_define:nn { knowledge~directives }
+ {#1 .code:n = {\knowledge_delay_directive:n{#1={##1}}}}}
+% \end{macrocode}
+% \fi
+% The command \kl{\NewKnowledgeParamCode} is similar to \kl{\NewKnowledgeParamBool},
+% but creates a directive that stores code. There is no optional star for code (never directly accessible to the user).
+% \begin{code}\AP
+% \intro\NewKnowledgeParamCode\{name\}\kl{\token}
+% \end{code}\noindent
+% \begin{macrocode}
+\NewDocumentCommand\NewKnowledgeParamCode{mm}{
+ \ktuple_new_tl_index:n{#1}
+ \use:c{ktuple_#1_expands_to:n}
+ {\tl_set:Nn#2{##1}}
+ %
+ \keys_define:nn { knowledgenow~directives }{
+ #1 .code:n =
+ { \knowledge_at:c
+ {ktuple_#1_gset:Nn}{##1} },
+ #1+ .code:n =
+ { \knowledge_at:c
+ {ktuple_#1_gput_right:Nn}{##1} },
+ +#1 .code:n =
+ { \knowledge_at:c
+ {ktuple_#1_gput_left:Nn}{##1} }
+}}
+% \end{macrocode}
+%
+%\par
+% \AP The command \kl{\NewKnowledgeParamPackageError} takes a comma separated
+% list of directives as first argument, and a package name as second argument.
+% After that, when one of these \kl{directives} is used, an error suggesting to load the
+% corresponding package is thrown.
+% \begin{code}
+% \intro\NewKnowledgeParamPackageError\{directive list\}\{package name\}
+% \end{code}\noindent
+% \begin{macrocode}
+\NewDocumentCommand\NewKnowledgeParamPackageError{mm}
+% \end{macrocode}
+% \ifcode
+% \begin{macrocode}
+{ \clist_map_inline:nn{#1}{
+ \keys_define:nn { knowledge~directives }{
+ ##1 .code:n = {
+ \msg_error:nnnn{ knowledge }{ package~required }{##1}{#2}}
+ }}}
+% \end{macrocode}
+%
+% \fi
+%
+%
+%
+% \subsubsection{Scopes}
+%
+%
+% \kl{Knowledges} are attached to \kl{instances}, which identify
+% the region in which these have been defined and also where they can be used.
+% For instance, if the user mentions `\kl{scope=}section' when defining a knowledge,
+% this means that the knowledge will only be visible in this
+% area\footnote{Though it can be imported and become visible elsewhere using appropriate commands.}.
+% Technically, instances are not directly handled by the user, nor by the "knowledge@@package" package.
+%
+% Note that \kl{\knowledge_visible_instances_seq} may only be correct after one compilation.
+%
+% For handling scopes, only three pieces of data are required:
+%
+% \begin{itemize}
+% \item
+% the token list \kl{\knowledge_current_instance_tl} contains the current
+% instance to be used.
+% \item
+% the sequence \kl{\knowledge_visible_instances_seq} contains the sequence
+% of instances that are visible right now. This are searched through when
+% a knowledge is used. The leftmost instance is the most important one.
+% \item
+% the command \kl{\knowledge_scope_track_instance:Nn}, given some requests, answers
+% an instance. Typically, if the request is `\texttt{subsection}', the answer will be `\texttt{subsection-3.1}',
+% identifying the subsection currently in scope.
+% \end{itemize}
+% \begin{macrocode}
+\tl_new:N\knowledge_current_instance_tl
+\tl_gset:Nn\knowledge_current_instance_tl{base}
+% \end{macrocode}
+% \begin{macrocode}
+\seq_new:N\knowledge_visible_instances_seq
+%
+\cs_new:Nn\knowledge_push_visible_instance:n
+ {\seq_gpush:Nn\knowledge_visible_instances_seq{#1}}
+%
+\cs_new:Nn\knowledge_lpush_visible_instance:n
+ {\seq_push:Nn\knowledge_visible_instances_seq{#1}}
+%
+\cs_new:Npn\knowledge_pop_visible_instance:
+ {\seq_gpop:NN\knowledge_visible_instances_seq\g_tmpa_tl}
+%
+\cs_new:Nn\knowledge_pop_visible_instances_to:n
+ {\seq_gpop:NNTF\knowledge_visible_instances_seq\g_tmpa_tl
+ {\exp_args:NV\tl_if_eq:nnTF\g_tmpa_tl{#1}
+ {}
+ {\knowledge_pop_visible_instances_to:n{#1}}}
+ {\INTERNAL_ERROR_EMPTY_POP_VISIBLE}}
+\cs_new:Nn\knowledge_show_visible_instances:
+ {\tl_show:x
+ {Visible~instances~<\seq_use:Nn\knowledge_visible_instances_seq{,}>}}
+%
+\cs_new:Nn\knowledge_import_instance:n
+ {\seq_if_in:NnTF\knowledge_visible_instances_seq{#1}
+ {}{\knowledge_push_visible_instance:n{#1}}}
+%
+\NewDocumentCommand\knowledgeimport{m}
+ {\kl_hide_begin:
+ \scopept_label_instance_if_exist:nTF{#1}
+ {\exp_args:Nx\knowledge_import_instance:n{\scopept_label_instance_use:n{#1}}}
+ {\msg_warning:nnnn{scope}{unknown~label}{#1}{\knowledgeimport}}
+ \kl_hide_end:
+}
+% \end{macrocode}
+%
+%
+% \subsubsection{The knowledge targeting}
+%
+% The \kl{\knowledge} command itself is dealt with in several steps.
+% In fact most of the interesting code is dealt in special subpackages.
+% Essentially, the \kl{\keys_define:nn}\verb|{ knowledgenow~directives }|(...)
+% commands used throughout the code are here to add new functionalities to it.
+%
+%
+% \begin{macrocode}
+\keys_define:nn { knowledge~directives } {
+ namespace .code:n = { \tl_set:Nn\knowledge_knowledge_namespace_tl{#1} },
+ force .choice:,
+ force / false .code:n = {\bool_set_false:N\knowledge_knowledge_force_bool},
+ force / true .code:n = {\bool_set_true:N\knowledge_knowledge_force_bool},
+ force .default:n = false,
+ clear .choice:,
+ clear / false .code:n = {\bool_set_false:N\knowledge_knowledge_clear_bool},
+ clear / true .code:n = {\bool_set_true:N\knowledge_knowledge_clear_bool},
+ clear .default:n = false,
+ export .choice:,
+ export / false .code:n = {\bool_set_false:N\knowledge_knowledge_export_bool},
+ export / true .code:n = {\bool_set_true:N\knowledge_knowledge_export_bool},
+ export .default:n = false,
+ instance .code:n =
+ { \tl_set:Nn\knowledge_knowledge_instance_tl{#1} },
+ scope .code:n =
+ { \knowledge_scope_track_instance:Nn\knowledge_knowledge_instance_tl{#1} },
+ synonym .code:n =
+ { \bool_set_true:N\knowledge_knowledge_is_synonym_bool
+ \exp_args:Nnx\keys_set:nn { knowledge~directives }
+ {link={\exp_not:o\knowledge_knowledge_synonym_tl},
+ link~instance={\exp_not:o\knowledge_knowledge_synonyminstance_tl},
+ instance={\exp_not:o\knowledge_knowledge_synonyminstance_tl}}}
+}
+% \end{macrocode}
+%
+%
+% The \intro{\KAuxKnowledge} command is added to the \kl{kaux file} when
+% \kl{\knowledge} delays its definition to the next phase of compilation.
+% \begin{macrocode}
+\NewKAuxCommand\KAuxKnowledge{mmmm}
+ {Package~knowledge:~Declares~a~knowledge.~
+ Takes~the~{namespace}{instance}{knowledge}{directives}.}
+% \end{macrocode}
+% \begin{macrocode}
+\DeclareKAuxPhaseCommand\KAuxKnowledge{init}
+ {\knowledge_set_now:nnnn{#1}{#2}{#3}{#4}}
+% \end{macrocode}
+% \begin{macrocode}
+\NewKAuxCommand\KAuxExport{mmmm}
+ {Package~knowledge:~undefined~so~far.}
+% \end{macrocode}
+%
+% \intro{\knowledge_set_now:nnnn} takes the three parameters defining a knowledge, checks that it was not existing before, and
+% then calls the \kl{\keys_set:nn}\{knowledgenow directives\} for defining it.
+% \begin{macrocode}
+\cs_new:Nn\knowledge_set_now:nnnn
+ {\knowledge_sets_to:nnn{#1}{#2}{#3}
+ \tl_set:Nn\knowledge_set_now_k_tl{{#1}{#2}{#3}}
+ \knowledge_at:N\ktuple_if_exist:NTF
+ {\bool_if:NTF\knowledge_knowledgestyle_bool
+ {\knowledge_at:N\ktuple_gclear:N}
+ {\knowledge_warning:n{knowledge~'#3'~(namespace=#1,~scope=#2)~is~redefined.}}}
+ {\knowledge_at:N\ktuple_new:N}
+ \keys_set:nn { knowledgenow~directives } { #4 }
+}
+\cs_generate_variant:Nn\knowledge_set_now:nnnn{nnVn}
+% \end{macrocode}
+%
+%
+% We can now define the \kl{\knowledge} command itself.
+% It starts by writing the line number in the \kl{kaux file}
+% using \kl{\KAuxWriteLocation}, and then proceeds with \kl{\knowledge_II}.
+% \begin{macrocode}
+\NewDocumentCommand\knowledge{}
+ {\KAuxWriteLocation\knowledge_II}
+% \end{macrocode}
+% The command \intro{\knowledge_II} is the center of the \kl{\knowledge}
+% command. It parses its arguments (in particular separating the synonyms using the "xparse@@package"), and executes \kl{\knowledge_knowledge_process:nn}
+% \begin{macrocode}
+\NewDocumentCommand\knowledge_II{m >{\SplitList{|}}o m }
+{ \kl_hide_begin:
+ \group_begin:
+ \tl_set_eq:NN\knowledge_namespace_tl
+ \knowledge_knowledge_default_namespace_tl
+ %
+ \bool_gset_false:N\knowledge_knowledge_is_synonym_bool
+ %
+ \use:x{
+ \exp_not:n{\knowledge_knowledge_process:nn{#1}}
+ {\exp_not:V\kl_knowledgedefault_tl,\exp_not:n{#3}}}
+ %
+ \bool_if:NF\knowledge_knowledge_is_synonym_bool
+ {\tl_gset:Nn\knowledge_knowledge_synonym_tl{#1}
+ \tl_gset_eq:NN\knowledge_knowledge_synonyminstance_tl
+ \knowledge_knowledge_instance_tl}
+ %
+ \IfNoValueTF{#2}{}{
+ \cs_set:Nn\l_tmpa_cs:n
+ {\exp_args:Nnx\knowledge_knowledge_process:nn{##1}{synonym}}
+ \ProcessList{#2}\l_tmpa_cs:n
+ }
+ %
+ \group_end:
+ \kl_hide_end:
+}
+\bool_new:N\knowledge_knowledge_now_bool
+\bool_new:N\knowledge_knowledge_is_synonym_bool
+\tl_new:N\knowledge_knowledge_synonym_tl
+\tl_new:N\knowledge_knowledge_synonyminstance_tl
+\tl_gset:Nn\knowledge_knowledge_synonyminstance_tl{}
+% \end{macrocode}
+%
+% The boolean \kl{\knowledge_knowledgestyle_bool}
+% is set to true in order \kl{\knowledge_knowledge_process:nn}
+% to know if it has been triggered by \kl{\knowledge}
+% or \kl{\knowledgestyle}.
+% \begin{macrocode}
+\bool_new:N\knowledge_knowledgestyle_bool
+% \end{macrocode}
+% \begin{macrocode}
+\NewDocumentCommand\knowledgestyle{ s m m }
+{ \kl_hide_begin:
+ \group_begin:
+ \tl_set:Nn\knowledge_namespace_tl{style}
+ %
+ \bool_set_true:N\knowledge_knowledgestyle_bool
+ \IfBooleanTF{#1}
+ {\bool_set_true:N\knowledge_knowledgestyle_override_bool}
+ {\bool_set_false:N\knowledge_knowledgestyle_override_bool}
+ %
+ \knowledge_knowledge_process:nn{#2}{#3}
+ \group_end:
+ \kl_hide_end:
+}
+% \end{macrocode}
+%
+%
+%
+%
+%
+% The \kl{\knowledge_knowledge_process:nn} command is the internal
+% version of \kl{\knowledge}. It takes two parameters:
+% the key, and the comma separated list of directives.
+% \begin{macrocode}
+\cs_new:Nn\knowledge_knowledge_process:nn
+{ \bool_set_false:N\knowledge_knowledge_now_bool
+ \bool_set_false:N\knowledge_knowledge_clear_bool
+ \bool_set_false:N\knowledge_knowledge_force_bool
+ \bool_set_false:N\knowledge_knowledge_export_bool
+ %
+ %
+ \tl_set:Nn\knowledge_key_tl{#1}
+ %
+ \tl_set_eq:NN\knowledge_knowledge_namespace_tl\knowledge_namespace_tl
+ \scope_get_attractive_instance:N\knowledge_knowledge_instance_tl
+ %
+ \tl_set:Nn\knowledge_directives_tl{}
+ %
+ \keys_set:nn { knowledge~directives } { #2 }
+ %
+ \mode_if_preamble:TF
+ {\bool_set_true:N\knowledge_knowledge_now_bool}
+ {}
+ %
+ \bool_if:NTF\knowledge_knowledge_now_bool
+ {\use:x{
+ \exp_not:N\knowledge_set_now:nnnn
+ {\knowledge_knowledge_namespace_tl}
+ {\knowledge_knowledge_instance_tl}
+ {\exp_not:V\knowledge_key_tl}
+ {\exp_not:V\knowledge_directives_tl}}
+ }{
+ \KAuxWriteX*{
+ \exp_not:N\KAuxKnowledge
+ {\knowledge_knowledge_namespace_tl}
+ {\knowledge_knowledge_instance_tl}
+ {\exp_not:V\knowledge_key_tl}
+ {\exp_not:V\knowledge_directives_tl}}
+ }
+ %
+ \bool_if:NT\knowledge_knowledge_export_bool
+ {\KAuxWriteX*{
+ \exp_not:N\KAuxExport
+ {\knowledge_knowledge_namespace_tl}
+ {\knowledge_knowledge_instance_tl}
+ {\exp_not:V\knowledge_key_tl}
+ {\exp_not:V\knowledge_directives_tl}}
+ }
+}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_delay_directive:n
+ {\tl_if_empty:NTF\knowledge_directives_tl
+ {\tl_set:Nn\knowledge_directives_tl{#1}}
+ {\tl_put_right:Nn\knowledge_directives_tl{,#1}}}
+\cs_generate_variant:Nn\knowledge_delay_directive:n{x}
+% \end{macrocode}
+%
+%
+%
+% \subsubsection{The \kl{\knowledgedirective} command}
+%
+% \begin{macrocode}
+\NewDocumentCommand\knowledgedirective{mom}{
+ \kl_hide_begin:
+ \cs_new:cn
+ {knowledgedirective_#1:n}
+ {\keys_set:nn{ knowledge~directives }{#3}}
+ \keys_define:nn{ knowledge~directives }
+ {#1 .code:n = {\use:c{knowledgedirective_#1:n}{##1}}}
+ \IfNoValueF{#2}
+ {\keys_define:nn{ knowledge~directives }{#1 .default:n = {#2}}}
+ \kl_hide_end:
+}
+% \end{macrocode}
+%
+% \subsubsection{The \kl{\knowledgedefault} command}
+%
+% It uses internally the variable \intro{\kl_knowledgedefault_tl}.
+% \begin{macrocode}
+\tl_new:N\kl_knowledgedefault_tl
+\NewDocumentCommand\knowledgedefault{sm}{
+ \kl_hide_begin:
+ \IfBooleanTF{#1}
+ {\tl_put_right:Nn\kl_knowledgedefault_tl{,#2}}
+ {\tl_set:Nn\kl_knowledgedefault_tl{#2}}
+ \kl_hide_end:
+}
+% \end{macrocode}
+%
+%
+% \subsubsection{Main \kl{\kl} code}
+%
+%
+% The \kl{\kl}, and its internal version \kl{\klTKS} are the central ones in the package. Indeed, all commands such as \kl{\intro}, \kl{\phantomintro}, \kl{\reintro} or the \kl{"...@...@..."} notation eventually end to a call to these functions.
+%
+% Essentially, \kl{\kl} parses its parameters, and then call its internal version \kl{\knowledge_klTKS:nnn}
+% with proper parameters: Text, Knowledge, Scope (the scope can be empty):
+% \begin{macrocode}
+\NewDocumentCommand\kl{d() o d() m}{
+ \IfNoValueTF{#1}
+ {\IfNoValueTF{#3}
+ {\IfNoValueTF{#2}
+ {\knowledge_klTKS:nnn{#4}{#4}{}}
+ {\knowledge_klTKS:nnn{#4}{#2}{}}}
+ {\IfNoValueTF{#2}
+ {\knowledge_klTKS:nnn{#4}{#4}{#3}}
+ {\knowledge_klTKS:nnn{#4}{#2}{#3}}}}
+ {\IfNoValueTF{#2}
+ {\knowledge_klTKS:nnn{#4}{#4}{#1}}
+ {\knowledge_klTKS:nnn{#4}{#2}{#1}}}
+}
+% \end{macrocode}
+%
+% The following macro, \kl{\knowledge_klTKS:nnn} is the internal version of \kl{\kl}. it takes explicitely the text to be displayed,
+% followed by the \kl{knowledge name} to be used, and a \kl{label} pointing to the \kl[instance]{instance of scope}
+% in which the \kl{knowledge name} has to searched. This \kl{label} can be empty, and in this case, this means that
+% the stack of instances that are visible in the context of the call of the command should be inspected for searching for
+% the knowledge. There exists a version \kl{\klTKS} which can be used, and does not require the \kl(package){expl3} syntax.
+% \begin{macrocode}
+\NewDocumentCommand\klTKS{}{\knowledge_klTKS:nnn}
+\cs_new:Nn\knowledge_klTKS:nnn{
+ \group_begin:
+ \knowledge_kl_init:
+ \cs_gset_eq:NN\knowledge_kl_init:\knowledge_defaultkl_init:
+ \tl_set:Nn\knowledge_kl_linkscope_tl{#3}
+ \tl_set:Nn\knowledge_kl_linkinstance_tl{}
+ \tl_set:Nn\knowledge_kl_text_tl{#1}
+ \tl_set:Nn\knowledge_kl_base_key_tl{#2}
+ \tl_set_eq:NN\knowledge_kl_key_tl\knowledge_kl_base_key_tl
+ \int_set_eq:NN\knowledge_kl_recursion_int\knowledge_kl_max_recursion_int
+ \knowledge_kl_find:
+ \group_end:
+ \knowledge_display_sequence:
+}
+% \end{macrocode}
+%
+% At this step, the code has launched \kl{\knowledge_kl_find:}
+% Internally, it counts using \kl{\knowledge_kl_recursion_int}
+% the number of indirections, and bounds
+% starting from the integer \kl{\knowledge_kl_max_recursion_int}
+% (40 by default).
+% \begin{macrocode}
+\int_const:Nn\knowledge_kl_max_recursion_int{40}
+\int_new:N\knowledge_kl_recursion_int
+% \end{macrocode}
+% \noindent
+% and then launches the search.
+%
+%
+% The core of the \kl{\kl} command is \intro{\knowledge_kl_find:}.
+% It uses the variables \kl{\knowledge_kl_recursion_int} for checking non-recursion.
+% It searches for the entry \kl{\knowledge_kl_key_tl}, either in searching in the \kl{stack of visible scope instances},
+% or following \kl{\knowledge_kl_linkscope_tl} if the label exist.
+% It first works on whether a scope label is given or not:
+% \begin{macrocode}
+\cs_set:Nn\knowledge_kl_find:{
+ \tl_if_empty:NTF\knowledge_kl_linkinstance_tl
+ {\tl_if_empty:NTF\knowledge_kl_linkscope_tl
+ \knowledge_kl_find_withoutscope:
+ \knowledge_kl_find_withscope:}
+ \knowledge_kl_find_withinstance:
+}
+% \end{macrocode}
+% In case a scope label is provided, then the label is tested for being known; if it is the case, it is followed, and the knowledge is looked for and executed.
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_find_withinstance:{
+ \knowledge_knowledge_if_exist:VVVTF
+ \knowledge_kl_namespace_tl
+ \knowledge_kl_linkinstance_tl
+ \knowledge_kl_key_tl
+ {\knowledge_kl_exec:nnV
+ \knowledge_kl_namespace_tl
+ \knowledge_kl_linkinstance_tl
+ \knowledge_kl_key_tl}
+ { \knowledge_kl_error_unknown_in_scope: }
+}
+\cs_new:Nn\knowledge_kl_find_withscope:{
+ \exp_args:NV
+ \scopept_label_instance_if_exist:nTF\knowledge_kl_linkscope_tl
+ { \tl_set:Nx\knowledge_kl_linkinstance_tl
+ {\scopept_label_instance_use:n{\knowledge_kl_linkscope_tl}}
+ \knowledge_kl_find_withinstance: }
+ { \knowledge_kl_error_label_unknown: }
+}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_find_withoutscope:{
+ \int_decr:N\knowledge_kl_recursion_int
+ \tl_clear:N\knowledge_kl_link_tl
+ \tl_clear:N\knowledge_kl_style_tl
+ \tl_clear:N\knowledge_kl_intro_style_tl
+ \int_compare:nNnTF\knowledge_kl_recursion_int=0
+ \knowledge_kl_error_recursion:
+ {\knowledge_kl_find_in_scope:VNTF
+ \knowledge_kl_key_tl\knowledge_kl_linkinstance_tl
+ {\knowledge_kl_exec:nnV
+ \knowledge_kl_namespace_tl
+ \knowledge_kl_linkinstance_tl
+ \knowledge_kl_key_tl}
+ {\knowledge_kl_error_unknown:}
+ }
+}
+% \end{macrocode}
+% We now code the macro \kl{\knowledge_kl_find_in_scope:nnNTF}, that
+% takes the \kl{namespace}, and the \kl{knowledge}, and answers the \kl{instance} (if it exists),
+% and sets the tl-token (third argument) to contain the scope in which it has been found.
+% \begin{macrocode}
+\cs_new:Npn\knowledge_kl_find_in_scope:nNTF{
+ \exp_args:NV\knowledge_kl_find_in_scope:nnNTF
+ \knowledge_kl_namespace_tl
+}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_find_in_scope:nnNTF{
+ \group_begin:
+ \tl_set:Nn\l_tmpa_tl{#1}
+ \tl_set:Nn\l_tmpb_tl{#2}
+ \bool_gset_false:N\g_tmpa_bool
+ \seq_map_function:NN
+ \knowledge_visible_instances_seq
+ \knowledge_kl_find_in_scope_test:n
+ \group_end:
+ \bool_if:NTF\g_tmpa_bool
+ {\tl_set_eq:NN#3\g_tmpa_tl #4}
+ {#5}
+}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_find_in_scope_test:n{
+ \exp_args:Nc\ktuple_if_exist:NTF
+ {\knowledge_id:nnV{\l_tmpa_tl}{#1}\l_tmpb_tl}
+ {\bool_gset_true:N\g_tmpa_bool
+ \tl_gset:Nn\g_tmpa_tl{#1}
+ \seq_map_break:}{}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_generate_variant:Nn\knowledge_kl_find_in_scope:nnNTF{nVNTF}
+\cs_generate_variant:Nn\knowledge_kl_find_in_scope:nNTF{VNTF}
+% \end{macrocode}
+% When the \kl{knowledge} is found, it is eventually executed using
+% \intro{\knowledge_kl_exec:N}. The argument is a control sequence pointing to the \kl{knowledge}. It is first executed
+% in order to set the variables.
+% Then, the token of the \kl{knowledge} is stored in the variable \kl{\knowledge_kl_resource_tl}.
+% Then, if a \kl{style} is given, it is executed. The next step is to update the \kl{knowledge}
+% which means essentially updating its internal counters of use.
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_exec:nnn{
+ \exp_args:NNc\tl_set:Nn\knowledge_kl_resource_tl
+ {\knowledge_id:nnn{#1}{#2}{#3}}
+ %
+ \tl_set:Nn\knowledge_kl_link_tl{}
+ \tl_set:Nn\knowledge_kl_linkscope_tl{}
+ \tl_set:Nn\knowledge_kl_linkinstance_tl{}
+ %
+ \knowledge_kl_resource_tl
+ %
+ \tl_if_empty:xTF\knowledge_kl_used_style_tl
+ {}
+ {\knowledge_kl_use_style:x
+ {\knowledge_kl_used_style_tl}}
+ %
+ \expandafter\knowledge_kl_update:N\knowledge_kl_resource_tl
+ %
+ %\knowledge_kl_exec_to_kaux:
+ %
+ \tl_if_exist_ne:NTF\knowledge_kl_linkscope_tl{
+ \tl_if_exist_ne:NTF\knowledge_kl_link_tl{}{
+ \tl_set_eq:NN\knowledge_kl_link_tl
+ \knowledge_kl_key_tl
+ }}{}
+ %
+ \tl_if_exist_ne:NTF\knowledge_kl_link_tl{
+ \tl_set_eq:NN
+ \knowledge_kl_key_tl
+ \knowledge_kl_link_tl
+ \knowledge_kl_find:
+ }{
+ \knowledge_kl_display_code:}
+}
+\cs_generate_variant:Nn\knowledge_kl_exec:nnn{nnV}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_use_style:n{
+ \knowledge_kl_find_in_scope:nnNTF
+ {style}
+ {#1}
+ \l_tmpa_tl
+ {\use:c{\knowledge_id:nVn{style}\l_tmpa_tl{#1}}}
+ {\knowledge_error:n{Unknown~style~`#1'}}
+}
+\cs_generate_variant:Nn\knowledge_kl_use_style:n {x}
+% \end{macrocode}
+%
+%
+%
+%
+%
+%
+%
+% \subsubsection{Error handling}
+%
+%
+%
+% \begin{macrocode}
+%\NewKAuxCommand\KAuxErrorLabelUnknown{mmm}
+% {Package~'knowledge:~A~label~is~not~defined.~
+% {label}}
+% {}
+\NewKAuxCommand\KAuxErrorKnowledgeUnknown{mmmm}
+ {Package~'knowledge:~A~knowledge~is~not~defined.~
+ {namespace}{scope/empty}{undefined~knowledge}{base~knowledge}}
+ {}
+\NewKAuxCommand\KAuxErrorLabelUnknown{m}
+ {Package~'knowledge:~A~label~is~not~defined.~
+ {label}}
+ {}
+% \end{macrocode}
+% \begin{macrocode}
+\DeclareKAuxPhaseCommand\KAuxErrorKnowledgeUnknown{diagnose-unknown-suggest}
+ {\knowledge_diagnose_line:
+ \tl_if_empty:nTF{#2}
+ {\knowledge_diagnose:n{\knowledge{#3}{}}}
+ {\knowledge_diagnose:n{\knowledge{#3}{scope={#2}}}}
+ }
+% \end{macrocode}
+% The code executed when an undefined knowledge is met. It
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_error_unknown:
+ {\KAuxWriteX{
+ \KAuxErrorKnowledgeUnknown
+ {\knowledge_kl_namespace_tl}
+ {}
+ {\exp_args:NV\detokenize\knowledge_kl_key_tl}
+ {\exp_args:NV\detokenize\knowledge_kl_base_key_tl}
+ }
+ \IfKnowledgePaperModeF{
+ \msg_warning:nnxxx{ knowledge }{ knowledge~unknown }
+ {\exp_not:V\knowledge_kl_key_tl}
+ {\exp_not:V\knowledge_kl_namespace_tl}
+ {\seq_use:Nn\knowledge_visible_instances_seq{~|~}}}
+ \knowledge_kl_use_style:n{unknown}
+ \knowledge_set_now:nnVn
+ {default}{base}
+ \knowledge_kl_key_tl
+ {style={unknown}}
+ \knowledge_kl_display_code:
+}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_error_unknown_in_scope:
+ {\KAuxWriteX{
+ \KAuxErrorKnowledgeUnknown
+ {\knowledge_kl_namespace_tl}
+ {\knowledge_kl_linkscope_tl}
+ {\exp_args:NV\detokenize\knowledge_kl_key_tl}
+ {\exp_args:NV\detokenize\knowledge_kl_base_key_tl}
+ }
+ \IfKnowledgePaperModeF{
+ \msg_warning:nnxxx{ knowledge }{ knowledge~unknown~in~scope }
+ {\exp_not:V\knowledge_kl_key_tl}
+ {\exp_not:V\knowledge_kl_namespace_tl}
+ {\knowledge_kl_linkscope_tl}}
+ \knowledge_kl_use_style:n{unknown}
+ \knowledge_set_now:nnVn
+ {default}{base}
+ \knowledge_kl_key_tl
+ {style={unknown}}
+ \knowledge_kl_display_code:
+}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_error_label_unknown:{
+ \KAuxWriteX{
+ \KAuxErrorKnowledgeUnknown
+ {\knowledge_kl_namespace_tl}
+ {\knowledge_kl_linkscope_tl}
+ {\exp_args:NV\detokenize\knowledge_kl_key_tl}
+ {\exp_args:NV\detokenize\knowledge_kl_base_key_tl}
+ }
+ \knowledge_kl_use_style:n{unknown}
+ \IfKnowledgePaperModeF{
+ \msg_warning:nnxx{ knowledge }{ knowledge~unknown~label }
+ {\exp_not:V\knowledge_kl_key_tl}
+ {\knowledge_kl_linkscope_tl}}
+ \knowledge_kl_display_code:
+}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_error_display:n
+ {\textcolor{orange}{\exp_args:NV\detokenize\knowledge_kl_text_tl}}
+% \end{macrocode}
+%
+%
+%
+% \subsubsection{Variants of the \kl{\kl} macro}
+%
+%
+%
+% When defining a new use of \texttt{knowledge}, many macros have to be taken into account.
+% Some have to be defined explicitly. Some other have default behaviours.
+% \begin{asparaitem}
+% \item \intro{\knowledge_kl_init:} is the code to be used at the initialization, that sets the other parameters. Once it is used, it is removed. By default it is \kl{\knowledge_defaultkl_init:}.
+% \item \intro{\knowledge_kl_namespace_tl} is the \kl{namespace} in which the \kl{knowledge} is to be searched. Not defined by default.
+% \item \intro{\knowledge_kl_linkscope_tl} is a label that points to an instance of a \kl{scope}. It can be empty, and in this case, this means that the search proceeds in the \kl{stack of visible scope instances}. By default it is empty.
+% \item \intro{\knowledge_kl_used_style_tl} is the style loaded by default.
+% \item \intro{\knowledge_kl_display_code:} is the code to be executed for displaying the \kl{knowledge}. This is not defined by default.
+% \item \intro{\knowledge_kl_max_recursion_int} is the maximum number of recursion allowed when searching for a \kl{knowledge}. It is by default 40.
+% \item \intro{\knowledge_kl_error_unknown:} The fallback code to execute when the \kl{knowledge} is unknown.
+% By default, it displays a warning and put the name in orange.
+% \item \intro{\knowledge_kl_display_code_preprocess:} is the code to be used first before displaying. It does nothing for \kl{\kl}, but is set to \kl{\knowledge_intro_display_code_preprocess:}.
+% \item \intro{\knowledge_kl_update:N} is a code to be executed to update the knowledge. By default, it increments the ktuple counter `countuse_int'.
+% \end{asparaitem}
+%
+% The codes can uses internally the following variables, that are accessible for the user when defining new \kl\kl-like commands:
+% \begin{asparaitem}
+% \item \intro{\knowledge_kl_command_tl} the command that has triggered the search
+% \item \intro{\knowledge_kl_base_key_tl} contains the name of the knowledge for which the search has started,
+% \item \intro{\knowledge_kl_text_tl} contains the text to be displayed,
+% \item \intro{\knowledge_kl_key_tl} contains the name of the knowledge searched at a particular moment,
+% \item \intro{\knowledge_kl_recursion_int} counts the number of indirection in the current, starting from \kl{\knowledge_kl_max_recursion_int}, and going down,
+% \item \intro{\knowledge_kl_link_tl} contains the link to be followed.
+% \end{asparaitem}
+%
+% \begin{macrocode}
+\NewDocumentCommand\intro{s}{
+ \kl_activate_intro:\IfBooleanF{#1}\kl}
+\NewDocumentCommand\reintro{s}{
+ \kl_activate_reintro:\IfBooleanF{#1}\kl}
+
+\cs_new:Nn\kl_activate_intro:
+ {\cs_gset_eq:NN\knowledge_kl_init:\knowledge_intro_init:}
+\cs_new:Nn\kl_activate_reintro:
+ {\cs_gset_eq:NN\knowledge_kl_init:\knowledge_reintro_init:}
+% poor man's implementation
+\NewDocumentCommand\phantomintro{m}{
+ \cs_gset_eq:NN\knowledge_kl_init:\knowledge_phantomintro_init:
+ \kl[{#1}]{}
+}
+% for the moment \nointro behaves like \phantomintro
+\let\nointro\phantomintro
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_intro_init:
+ {\tl_set:Nn
+ \knowledge_kl_command_tl{intro}
+ \cs_set_eq:NN
+ \knowledge_kl_update:N
+ \knowledge_intro_update:N
+ \cs_set_eq:NN
+ \knowledge_kl_display_code_preprocess:
+ \knowledge_intro_display_code_preprocess:
+ \tl_set:Nn
+ \knowledge_kl_used_style_tl
+ {\knowledge_kl_intro_style_tl}
+ }
+\cs_new:Nn\knowledge_phantomintro_init:
+ {\tl_set:Nn
+ \knowledge_kl_command_tl{phantomintro}
+ \cs_set_eq:NN
+ \knowledge_kl_update:N
+ \knowledge_intro_update:N
+ \cs_set_eq:NN
+ \knowledge_kl_display_code_preprocess:
+ \knowledge_intro_display_code_preprocess:
+ \tl_set:Nn
+ \knowledge_kl_used_style_tl
+ {\knowledge_kl_intro_style_tl}
+ \cs_set_eq:NN
+ \knowledge_kl_display_code:
+ \knowledge_phantomintro_display_code:
+ }
+\cs_new:Nn\knowledge_reintro_init:
+ {\tl_set:Nn
+ \knowledge_kl_command_tl
+ {reintro}
+ \tl_set:Nn
+ \knowledge_kl_used_style_tl
+ {\knowledge_kl_intro_style_tl}
+ }
+\cs_new:Nn\knowledge_intro_update:N
+ {\ktuple_countintro_gincr:N#1}
+
+\tl_set:Nn\knowledge_kl_intro_style_tl
+ {intro}
+% \end{macrocode}
+% When the \kl{\intro} is used more than once, new labels are introduced (appending b,c,d\dots),
+% in order to point to these targets easily.
+% \begin{macrocode}
+\cs_new:Npn\knowledge_intro_display_code_preprocess:
+ {\tl_if_exist_ne:NTF\knowledge_kl_resource_tl
+ {\expandafter\ktuple_countintro_get_int:NN
+ \knowledge_kl_resource_tl\l_tmpa_int
+ \tl_set:Nx\l_tmpa_tl
+ {\int_compare:nNnTF\l_tmpa_int=1{}{\int_to_alph:n\l_tmpa_int}}}
+ {\tl_set:Nn\l_tmpa_tl{}}
+ \tl_if_exist_ne:NTF\kl_autoref_tl
+ {\exp_args:Nx\label{\expandafter\noexpand\kl_autoref_tl\l_tmpa_tl}}
+ {}}
+% \end{macrocode}
+% \begin{macrocode}
+\tl_new:N\knowledge_kl_style_tl
+\tl_set:Nn\knowledge_kl_used_style_tl{\knowledge_kl_style_tl}
+\cs_new:Nn\knowledge_defaultkl_init:{}
+\cs_gset:Nn\knowledge_defaultkl_update:N
+ {\ktuple_countuse_gincr:N#1}
+\tl_set:Nn\knowledge_defaultkl_namespace_tl{default}
+% \end{macrocode}
+%
+%
+% \subsubsection{Code for mathematical variables (unstable)}
+%
+% The code does not work anymore.
+% Should now use \kl{\knowledge_klTKS:nnn}.
+% \begin{macrocode}
+\tl_set:Nn\knowledge_variablekl_namespace_tl{variable}
+% \end{macrocode}
+% \begin{macrocode}
+\bool_new:N\kl_already_met_bool
+\ktuple_new_bool_index:n{already_met_bool}
+\ktuple_already_met_bool_expands_to:TF
+ {\bool_gset_true:N\kl_already_met_bool}
+ {\bool_gset_false:N\kl_already_met_bool}
+
+\NewDocumentCommand\introvar{om}
+ {\IfNoValueTF{#1}
+ {\introvar:nn{#2}{#2}}
+ {\introvar:nn{#1}{#2}}}
+
+\cs_new:Nn\introvar:nn
+ {\group_begin:
+ \scope_get_attractive_instance:N
+ \knowledge_knowledge_instance_tl
+ \knowledge_sets_to:nnn
+ \knowledge_variablekl_namespace_tl
+ \knowledge_knowledge_instance_tl
+ {#1}
+ \knowledge_at:N\ktuple_ensure:N
+ \knowledge_at:N\ktuple_already_met_bool_if:NTF
+ {\WARNING_VARIABLE_INTRODUCED_TWICE_IN_SAME_SCOPE
+ \group_end:
+ \textcolor{orange}{#2}}
+ {\knowledge_at:N\ktuple_already_met_bool_gset_true:N
+ \knowledge[\knowledge_variablekl_namespace_tl]{#1}{autorefhere}
+ \group_end:
+ #2}
+}
+
+\NewDocumentCommand\klvar{om}
+ {\group_begin:
+ \tl_set:Nn\knowledge_kl_command_tl{\klvar}
+ \tl_set_eq:NN\knowledge_kl_namespace_tl\knowledge_variablekl_namespace_tl
+ \cs_set_eq:NN\knowledge_kl_display_code:\knowledge_variablekl_display_code:
+ \kl_base:nn{#1}{#2}
+ \group_end:
+}
+
+\cs_new:Nn\knowledge_variablekl_display_code:
+ {\bool_if:NTF\knowledge_hyperref_active_bool
+ {\tl_if_exist:NTF\kl_autoref_tl
+ {\kl_hyperref_silentlabel:nn\kl_autoref_tl\knowledge_kl_text_tl}
+ {\textcolor{purple}{\knowledge_kl_text_tl}}}
+ {\knowledge_kl_text_tl}}
+% \end{macrocode}
+%
+%
+%
+% \subsubsection{Display parameters}
+%
+%
+%\begin{compactdesc}
+%\item[\intro{\kl_emphasize_bool}]
+%\item[\intro{\kl_boldface_bool}]
+%\item[\intro{\kl_underline_bool}]
+%\item[\intro{\kl_typewriter_bool}]
+%\item[\intro{\kl_fbox_bool}]
+%\item[\intro{\kl_ensuremath_bool}]
+%\item[\intro{\kl_ensuretext_bool}]
+%\item[\intro{\kl_italic_bool}]
+%\item[\intro{\kl_lowercase_bool}]
+%\item[\intro{\kl_uppercase_bool}]
+%\item[\intro{\kl_forced_text_tl}]
+%\item[\reintro{\knowledge_kl_link_tl}]
+%\item[\reintro{\knowledge_kl_linkscope_tl}]
+%\item[\reintro{\knowledge_kl_display_code:}]
+%\item[\intro{\knowledge_phantomintro_display_code:}]
+%\end{compactdesc}
+%
+% \begin{macrocode}
+\NewKnowledgeParamBool*{protect~link}\kl_protect_link_bool
+\NewKnowledgeParamBool*{emphasize}\kl_emphasize_bool
+\NewKnowledgeParamBool*{underline}\kl_underline_bool
+\NewKnowledgeParamBool*{boldface}\kl_boldface_bool
+\NewKnowledgeParamBool*{md}\kl_md_bool
+\NewKnowledgeParamBool*{fbox}\kl_fbox_bool
+\NewKnowledgeParamBool*{typewriter}\kl_typewriter_bool
+\NewKnowledgeParamBool*{ensuremath}\kl_ensuremath_bool
+\NewKnowledgeParamBool*{mathord}\kl_mathord_bool
+\NewKnowledgeParamBool*{mathop}\kl_mathop_bool
+\NewKnowledgeParamBool*{mathbin}\kl_mathbin_bool
+\NewKnowledgeParamBool*{mathrel}\kl_mathrel_bool
+\NewKnowledgeParamBool*{mathopen}\kl_mathopen_bool
+\NewKnowledgeParamBool*{mathclose}\kl_mathclose_bool
+\NewKnowledgeParamBool*{mathpunct}\kl_mathpunct_bool
+\NewKnowledgeParamBool*{ensuretext}\kl_ensuretext_bool
+\NewKnowledgeParamBool*{italic}\kl_italic_bool
+\NewKnowledgeParamBool*{up}\kl_up_bool
+\NewKnowledgeParamBool*{lowercase}\kl_lowercase_bool
+\NewKnowledgeParamBool*{uppercase}\kl_uppercase_bool
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewKnowledgeParamTl*{text}\kowledge_kl_forced_text_tl
+\NewKnowledgeParamTl*{link}\knowledge_kl_link_tl
+\NewKnowledgeParamTl*{link~scope}\knowledge_kl_linkscope_tl
+\NewKnowledgeParamTl*{link~instance}\knowledge_kl_linkinstance_tl
+\NewKnowledgeParamTl*{wrap}\knowledge_kl_wrap_tl
+\NewKnowledgeParamTl*{style}\knowledge_kl_style_tl
+\NewKnowledgeParamTl*{intro~style}\knowledge_kl_intro_style_tl
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewKnowledgeParamCode{displaycode}\kl_display_code:
+% \end{macrocode}
+%
+% \begin{macrocode}
+\ktuple_new_int_index:n{countuse}
+\ktuple_countuse_expands_to:n{}
+\ktuple_new_int_index:n{countintro}
+\ktuple_countintro_expands_to:n{}
+% \end{macrocode}
+%
+% The "directive" "now"
+% \begin{macrocode}
+\keys_define:nn{ knowledge~directives }{
+ now .code:n = { \bool_set_true:N\knowledge_knowledge_now_bool }
+}
+% \end{macrocode}
+%
+% The special directive \kl{autorefhere} is used for variables, where for which it is not necessary
+% to explicitely use a \kl{\knowledge} command.
+% \begin{macrocode}
+\int_new:N\knowledge_autoref_count
+
+\keys_define:nn{ knowledge~directives }{
+ autoref .code:n = {
+ \keys_set:nn{ knowledge~directives }
+ { intro~style=intro }
+ \int_gincr:N\knowledge_autoref_count
+ \knowledge_delay_directive:x
+ {autoref = {autoref-\int_use:N\knowledge_autoref_count}}},
+ autorefhere .code:n = {
+ \int_gincr:N\knowledge_autoref_count
+ \exp_args:Nx\label{autoref-\int_use:N\knowledge_autoref_count}
+ \knowledge_delay_directive:x
+ {autoref = {autoref-\int_use:N\knowledge_autoref_count}}}}
+
+\ktuple_new_tl_index:n{autoref}
+\use:c{ktuple_autoref_expands_to:n}
+ {\tl_set:Nn\kl_autoref_tl{#1} }
+\keys_define:nn { knowledgenow~directives } {
+autoref .code:n =
+ { \knowledge_at:c{ktuple_autoref_gset:Nn}{#1}
+ \KAuxWriteX*
+ {\exp_not:N\KAuxAutoref\exp_not:V\knowledge_set_now_k_tl}}
+}
+% \end{macrocode}
+% \begin{macrocode}
+\int_new:N\kl_countuse_int
+\int_new:N\kl_countintro_int
+\NewKAuxCommand\KAuxAutoref{mmm}
+ {Package~knowledge:~Declares~an~autoref~knowledge.~
+ Arguments~{namespace}{instance}{knowledge}.}
+
+\int_new:N\kl_digest_autorefused_int
+\int_new:N\kl_digest_autorefnointro_int
+\int_new:N\kl_digest_autoreftwiceintro_int
+\int_new:N\kl_digest_autorefunused_int
+\int_new:N\kl_digest_unknownknowledge_int
+\int_new:N\kl_digest_unknownlabel_int
+
+\DeclareKAuxPhaseCommand\KAuxErrorKnowledgeUnknown{diagnose-digest}
+ {\int_gincr:N\kl_digest_unknownknowledge_int}
+%\DeclareKAuxPhaseCommand\KAuxErrorLabelUnknown{diagnose-digest}
+% {\int_gincr:N\kl_digest_unknownlabel_int}
+
+\DeclareKAuxPhaseCommand\KAuxAutoref{diagnose-digest}
+ {\group_begin:
+ \knowledge_sets_to:nnn{#1}{#2}{#3}
+ \knowledge_at:N\ktuple_countuse_get_int:NN\kl_countuse_int
+ \knowledge_at:N\ktuple_countintro_get_int:NN\kl_countintro_int
+ \int_compare:nNnT\kl_countintro_int=1
+ {\int_gincr:N\kl_digest_autorefused_int}
+ \int_compare:nNnT\kl_countintro_int=0
+ {\int_compare:nNnTF\kl_countuse_int=0
+ {\int_gincr:N\kl_digest_autorefunused_int}
+ {\int_gincr:N\kl_digest_autorefnointro_int}}
+ \int_compare:nNnT\kl_countintro_int>1
+ {\int_gincr:N\kl_digest_autoreftwiceintro_int}
+ \group_end:}
+
+\DeclareKAuxPhaseCommand\KAuxAutoref{autoref-not-introduced}
+ {\group_begin:
+ \knowledge_sets_to:nnn{#1}{#2}{#3}
+ \knowledge_at:N\ktuple_countuse_get_int:NN\kl_countuse_int
+ \knowledge_at:N\ktuple_countintro_get_int:NN\kl_countintro_int
+ \int_compare:nNnT\kl_countuse_int>0
+ {\int_compare:nNnT\kl_countintro_int=0
+ {\knowledge_diagnose_line:
+ \knowledge_diagnose:n{\nointro{#1}{#2}{#3}}}}
+ \group_end:}
+\DeclareKAuxPhaseCommand\KAuxAutoref{autoref-introduced-twice}
+ {\group_begin:
+ \knowledge_sets_to:nnn{#1}{#2}{#3}
+ \knowledge_at:N\ktuple_countuse_get_int:NN\kl_countuse_int
+ \knowledge_at:N\ktuple_countintro_get_int:NN\kl_countintro_int
+ \int_compare:nNnT\kl_countintro_int>1
+ {\knowledge_diagnose_line:
+ \knowledge_diagnose:n{{#1}{#2}{#3}}}
+ \group_end:}
+% \end{macrocode}
+% \begin{macrocode}
+\NewKAuxCommand\KAuxUseKnowledge{mmm}
+ {Package~knowledge:~Identifies~the~use~of~some~knowledge.~
+ Arguments~{namespace}{instance}{knowledge}.}
+% \end{macrocode}
+%
+%
+%\subsubsection{Display code}
+%
+%
+%
+%
+% \def\CS#1{\texttt{\detokenize{#1}}}
+% The macro \CS{\knowledge_kl_display_sequence:n} is expandable. It takes a sequence
+% of macros with one parameter, and nests them.
+% Hence \CS{\knowledge_kl_display_sequence:n}\{abcde\}
+% expands to a\{b\{c\{d\{e\}\}\}\}, in which each of the objects are expanded.
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_display_sequence:n
+ {\knowledge_kl_display_sequence:w#1\display_end:}
+\cs_new:Npn\knowledge_kl_display_sequence:w#1#2\display_end:
+ {\tl_if_empty:nTF{#2}{#1}
+ {#1{\knowledge_kl_display_sequence:w #2 \display_end:}}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_phantomintro_display_code:
+ {\knowledge_intro_display_code_preprocess:
+ \cs_gset:Npx\knowledge_display_sequence:{
+ \knowledge_kl_display_sequence:n{
+ \knowledge_kl_display_code_index:n
+ \knowledge_invisible_display_code_text:
+ }}}
+\cs_new:Nn\knowledge_invisible_display_code_text:{}
+% \end{macrocode}
+% The central display code executes in a nested way the following long sequence of subcodes.
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code:{
+ \knowledge_kl_display_code_preprocess:
+ \cs_gset:Npx\knowledge_display_sequence:{
+ \knowledge_kl_display_sequence:n{
+ \knowledge_kl_display_code_index:n
+ \knowledge_defaultkl_display_code_fbox:n
+ \knowledge_defaultkl_display_code_emphasize:n
+ \knowledge_defaultkl_display_code_ensuremath:n
+ \knowledge_defaultkl_display_code_ensuretext:n
+ \knowledge_defaultkl_display_code_mathord:n
+ \knowledge_defaultkl_display_code_mathop:n
+ \knowledge_defaultkl_display_code_typewriter:n
+ \knowledge_defaultkl_display_code_sc:n
+ \knowledge_defaultkl_display_code_italic:n
+ \knowledge_defaultkl_display_code_up:n
+ \knowledge_defaultkl_display_code_boldface:n
+ \knowledge_defaultkl_display_code_md:n
+ \knowledge_defaultkl_display_code_ref:n
+ \knowledge_defaultkl_display_code_url:n
+ \knowledge_defaultkl_display_code_color:n
+ \knowledge_defaultkl_display_code_colorbox:n
+ \knowledge_defaultkl_display_code_underline:n
+ \knowledge_defaultkl_code_nestingprotect:n
+ \knowledge_defaultkl_display_code_text:}}
+}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_display_code_index:n{#1}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_fbox:n
+ {\bool_if:NTF\kl_fbox_bool{\exp_not:N\fbox{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Npn\knowledge_kl_display_code_preprocess:
+ {}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_ensuremath:n
+ {\bool_if:NTF\kl_ensuremath_bool{\exp_not:N\ensuremath}\use:n{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_ensuretext:n
+ {\bool_if:NTF\kl_ensuretext_bool{\mode_if_math:TF{\exp_not:N\text}\use:n}\use:n{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_mathord:n{
+ \bool_if:NTF\kl_mathord_bool
+ {\mode_if_math:TF{\exp_not:N\mathord}\use:n{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_mathop:n{
+ \bool_if:NTF\kl_mathop_bool
+ {\mode_if_math:TF{\exp_not:N\mathop}\use:n{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_mathbin:n{
+ \bool_if:NTF\kl_mathbin_bool
+ {\mode_if_math:TF{\exp_not:N\mathbin}\use:n{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_mathrel:n{
+ \bool_if:NTF\kl_mathrel_bool
+ {\mode_if_math:TF{\exp_not:N\mathrel}\use:n{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_mathopen:n{
+ \bool_if:NTF\kl_mathopen_bool
+ {\mode_if_math:TF{\exp_not:N\mathopen}\use:n{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_mathclose:n{
+ \bool_if:NTF\kl_mathclose_bool
+ {\mode_if_math:TF{\exp_not:N\mathclose}\use:n{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_mathpunct:n{
+ \bool_if:NTF\kl_mathpunct_bool
+ {\mode_if_math:TF{\exp_not:N\mathpunct}\use:n{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_emphasize:n{
+ \bool_if:NTF\kl_emphasize_bool
+ {\mode_if_math:TF\use:n{\exp_not:N\emph}{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_underline:n{
+ \bool_if:NTF\kl_underline_bool
+ {\mode_if_math:TF{#1}
+ {\exp_not:N\underline{\exp_not:N\smash{#1}}}}
+ {#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_typewriter:n{
+ \bool_if:NTF\kl_typewriter_bool
+ {\mode_if_math:TF{\exp_not:N\mathtt}{\exp_not:N\texttt}{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_italic:n{
+ \bool_if:NTF\kl_italic_bool
+ {\mode_if_math:TF{\exp_not:N\mathit}{\exp_not:N\textit}{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_sc:n{
+ \bool_if:NTF\kl_cs_bool
+ {\mode_if_math:TF{\exp_not:N\mathsc}{\exp_not:N\textsc}{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_md:n{
+ \bool_if:NTF\kl_md_bool
+ {\mode_if_math:TF{\exp_not:N\mathmd}{\exp_not:N\textmd}{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_up:n{
+ \bool_if:NTF\kl_up_bool
+ {\mode_if_math:TF{\exp_not:N\mathup}{\exp_not:N\textup}{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_boldface:n{
+ \bool_if:NTF\kl_boldface_bool
+ {\mode_if_math:TF{\exp_not:N\mathbf}{\exp_not:N\textbf}{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_ref:n{
+ \bool_if:NTF\knowledge_hyperref_active_bool
+ {\tl_if_exist:NTF\kl_ref_tl
+ {\exp_not:N\kl_hyperlink_label:nn{\exp_not:V\kl_ref_tl}{#1}}
+ {\tl_if_exist:NTF\kl_autoref_tl
+ {\exp_not:N\kl_hyperlink_silentlabel:nn{\exp_not:V\kl_autoref_tl}{#1}}
+ {#1}}}
+ {#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_url:n{
+ \bool_if:NTF\knowledge_hyperref_active_bool
+ {\tl_if_exist:NTF\kl_url_tl{\exp_not:N\kl_hyperlink_url:nn{\exp_not:V\kl_url_tl}{#1}}{#1}}
+ {#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_color:n{
+ \bool_if:NTF\knowledge_xcolor_active_bool
+ {\tl_if_exist:NTF\kl_color_tl
+ {\exp_not:N\textcolor{\kl_color_tl}{#1}}{#1}}
+ {#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_colorbox:n{
+ \bool_if:NTF\knowledge_xcolor_active_bool
+ {\tl_if_exist:NTF\kl_colorbox_tl
+ {\exp_not:N\colorbox{\kl_colorbox_tl}{#1}}{#1}}
+ {#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_code_nestingprotect:n{
+ \bool_if:NTF\kl_protect_link_bool
+ {\exp_not:N\kl_kl_nesting_incr:#1\exp_not:N\kl_kl_nesting_decr:}{#1}
+ }
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_code_wrap:n{
+ \tl_if_exist:NTF\knowledge_kl_wrap_tl
+ {\exp_not:V\knowledge_kl_wrap_tl{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_defaultkl_display_code_text:{
+ \knowledge_defaultkl_code_wrap:n{
+ \tl_if_exist:NTF\kowledge_kl_forced_text_tl
+ {\exp_not:V\kowledge_kl_forced_text_tl}
+ {\exp_not:V\knowledge_kl_text_tl}
+ }
+}
+% \end{macrocode}
+%
+% \subsubsection{Other commands}
+%
+% \paragraph{\kl{\AP} and \kl{\itemAP}}
+% The code for the command \kl{\AP} is inspired from a
+% \href{http://tex.stackexchange.com/questions/123392/add-a-marker-to-the-left-of-the-text}{\underline{code}} of \kl{egreg} on \kl{stackexchange}.
+% \begin{macrocode}
+\NewDocumentCommand\AP{}
+ {\bool_if:NT\knowledge_hyperref_active_bool
+ {\strut\vadjust{\knowledge_AP_internal:}}}
+\NewDocumentCommand\itemAP{o}{
+ \IfNoValueTF{#1}
+ {\item\AP}
+ {\item[\knowledge_itemAP: #1]}}
+% \end{macrocode}
+% \begin{macrocode}
+\int_new:N\kl_hyperref_kl_nesting_count_int
+\bool_new:N\kl_hyperref_active_here_bool
+\bool_set_true:N\kl_hyperref_active_here_bool
+\cs_new:Npn\kl_if_hyperlinks_active_here:TF
+ {\bool_if:NTF\knowledge_hyperlinks_active_bool
+ {\bool_if:NTF\kl_hyperref_active_here_bool}
+ \use_ii:nn}
+\cs_new:Nn\kl_kl_nesting_incr:
+ {\int_gincr:N\kl_hyperref_kl_nesting_count_int
+ \bool_gset:Nn\kl_hyperref_active_here_bool
+ {\int_compare_p:nNn\kl_hyperref_kl_nesting_count_int=0}}
+\cs_new:Nn\kl_kl_nesting_decr:
+ {\int_gdecr:N\kl_hyperref_kl_nesting_count_int
+ \bool_gset:Nn\kl_hyperref_active_here_bool
+ {\int_compare_p:nNn\kl_hyperref_kl_nesting_count_int=0}}
+% \end{macrocode}
+% We make replicates of the commands of \kl(package){hyperref} that we want to sometimes deactivate.
+% \begin{macrocode}
+\cs_new:Npn\kl_hyperlink_label:nn#1
+ {\kl_if_hyperlinks_active_here:TF{\hyperref[{#1}]}{\use:n}}
+\cs_new:Npn\kl_hyperlink_url:nn
+ {\kl_if_hyperlinks_active_here:TF\href\use_ii:nn}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\kl_hyperlink_silentlabel:nn
+ {\kl_if_hyperref_exist:nTF{#1}
+ {\kl_hyperlink_label:nn{#1}{#2}}
+ {#2}}
+\cs_new:Npn\kl_if_hyperref_exist:nTF#1
+ {\expandafter\ifx\csname r@#1\endcsname\relax
+ \expandafter\use_ii:nn\else
+ \expandafter\use_i:nn\fi}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_AP_internal:{%
+ \vbox to 0pt{
+ \kern-\dp\strutbox
+ \smash{\llap{\knowledge_AP_mark:\kern0.5em}}
+ \vss}}
+\cs_new:Nn\knowledge_AP_mark:{%
+ \setlength\unitlength{1em}
+ \begin{picture}(0,0)
+ \put(0,1){
+ \bool_if:NT\knowledge_hyperref_active_bool
+ {\put(-0.05,-1.04){\phantomsection}}
+ \bool_if:NT\knowledge_configuration_visibleAP_bool
+ {\bool_if:NTF\knowledge_xcolor_active_bool
+ {\textcolor{red}}{\use:n}
+ {\line(0,-1){0.5}\line(1,0){0.5}}}}
+ \end{picture}{}}
+\cs_new:Nn\knowledge_itemAP:{
+ \hbox_overlap_left:n
+ {\knowledge_AP_mark:\hspace{1em}}
+ }
+% \end{macrocode}
+% \subsection{Activate and deactivate the \kl{quotation notation}}
+%
+% First, let us define an internal command that tales
+% knowledge,key,scope.
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_TKS:nnn{
+ \group_begin:
+ \knowledge_warning:n{#1/#2/#3}
+ \knowledge_kl_init:
+ \cs_gset_eq:NN\knowledge_kl_init:\knowledge_defaultkl_init:
+
+ \scopept_label_instance_if_exist:nTF{#3}
+ { \exp_args:Nx\knowledge_lpush_visible_instance:n
+ {\scopept_label_instance_use:n{#3}}
+ \kl_base:nn{#2}{#1}
+ }
+ { \tl_set:Nn\knowledge_kl_text_tl{#1}
+ \knowledge_kl_error_label_unknown:
+ \knowledge_warning:n
+ {Unknown~label~in~scope=`#3'.~Possibly~rerun~latex.}
+ }
+ \group_end:
+ \exp_args:No\knowledge_warning:n\knowledge_display_sequence:
+\knowledge_warning:n{before}
+ \knowledge_display_sequence:
+\knowledge_warning:n{after}
+ %\tl_show:n{\fskljkqlffk}
+}
+\NewDocumentCommand\klInnerTKSnnn{}\knowledge_kl_TKS:nnn
+% \end{macrocode}
+% \begin{macrocode}
+\ExplSyntaxOff
+\def\makequotationactive
+ {\catcode`"13\relax}
+\def\makequotationletter
+ {\catcode`"12\relax}
+
+\let\quotationmark"
+
+\ExplSyntaxOn
+\makequotationactive
+\edef\klactivequotationmark#1"{
+ \noexpand\tl_if_empty:nTF{#1}
+ {\noexpand\klactivedoublequotationmark}
+ {\noexpand\klquotation_parse_arobas_sep:Nw
+ \noexpand\klquotation_expand:nnn #1
+ @
+ @
+ @\noexpand\kl_end}
+}
+\edef\klactivedoublequotationmark#1""{
+ \noexpand\klquotation_parse_arobas_sep:Nw
+ \noexpand\kldoublequotation_expand:nnn #1
+ @
+ @
+ @\noexpand\kl_end
+}
+\cs_new:Npx\klquotation_parse_arobas_sep:Nw #1#2@#3@#4@#5\kl_end
+ {#1{#2}{#3}{#4}}
+
+\cs_set_eq:NN\tl_if_novalue:nTF\IfNoValueTF
+
+\cs_new:Npn\kldoublequotation_expand:nnn
+ {\kl_activate_intro:\klquotation_expand:nnn}
+
+\cs_new:Nn\klquotation_expand:nnn{
+ \tl_if_empty:nTF{#2}
+ {\klTKS{#1}{#1}{#3}}
+ {\klTKS{#1}{#2}{#3}}
+}
+
+
+\def\klactivatequotation
+ {\makequotationactive
+ \let"\klactivequotationmark}
+\def\kldeactivatequotation
+ {\makequotationletter}
+
+\kldeactivatequotation
+
+
+% \end{macrocode}
+%
+% We now provide the code that is used for easily activating and deactivating quotation.
+% \begin{macrocode}
+\cs_new:Nn\kl_protect_environment_quotation:n
+ {\clist_map_inline:nn{#1}
+ {\scope_area_set:nn{#1}
+ { push~code={\knowledgeconfigure{quotation=false}},
+ pop~code={\knowledgeconfigure{quotation=true}}}}
+ }
+% \end{macrocode}
+%
+% \subsection{Mathematics}
+%
+% \subsubsection{Capturing subscripts, superscripts and primes}
+% We know provide the core code for parsing subscripts, superscripts and primes.
+%
+% The central command is \intro{\klparse_absorb_modifiers:}.
+% This command parses all the subscripts and so on occurring after,
+% and then launches \intro{\klparse_absorb_modifiers_exec:}
+% (that is supposed to have been set with the proper code).
+% At the end, the token lists \intro{\klparse_primes_tl}, \intro{\klparse_subscript_tl}
+% and \intro{\klparse_supscript_tl}
+% contain the texts that have been collected during the parsing.
+% If a subscript or a superscript is not present, then the corresponding token list
+% is set equal to be \kl{\klparse_novalue_tl}. This is not the case for primes:
+% if there are no primes, then the token list \kl{\klparse_primes_tl} is simply empty.
+% Parsing subscripts, superscripts and primes can be deactivated or activated by setting appropriately the
+% macros \kl{\klparse_if_load_primes:TF}
+% \kl{\klparse_if_load_subscript:TF} and \kl{\klparse_if_load_supscript:TF}.
+% \begin{macrocode}
+\cs_new:Nn\klparse_absorb_modifiers:
+ {\tl_set_eq:NN\klparse_primes_tl\c_empty_tl
+ \bool_if:NTF\klparse_load_primes_bool
+ \klparse_absorb_modifiers_pses:
+ \klparse_absorb_modifiers_ses:
+ }
+
+\cs_new:Nn\klparse_absorb_modifiers_pses:
+ {\klparse_ifnextchar:NTF'
+ {\tl_put_right:Nn\klparse_primes_tl'
+ \use_i:nn\klparse_absorb_modifiers_pses:}
+ \klparse_absorb_modifiers_ses:
+ }
+
+\cs_new:Nn\klparse_absorb_modifiers_ses:
+ {\bool_if:NTF\klparse_load_subscript_bool
+ {\klparse_absorb_subscript:Nn\klparse_subscript_tl\klparse_absorb_modifiers_es:}
+ {\tl_set_eq:NN\klparse_subscript_tl\klparse_novalue_tl
+ \klparse_absorb_modifiers_es:}
+ }
+
+\cs_new:Nn\klparse_absorb_modifiers_es:
+ {\bool_if:NTF\klparse_load_supscript_bool
+ {\tl_if_empty:NTF\klparse_primes_tl
+ {\klparse_absorb_supscript:Nn\klparse_supscript_tl
+ \klparse_absorb_modifiers_ts:}
+ {\tl_set_eq:NN\klparse_supscript_tl\klparse_novalue_tl
+ \klparse_absorb_modifiers_exec:}}
+ {\tl_set_eq:NN\klparse_supscript_tl\klparse_novalue_tl
+ \klparse_absorb_modifiers_exec:}
+ }
+
+\cs_new:Nn\klparse_absorb_modifiers_ts:
+ {\bool_if:NTF\klparse_load_subscript_bool{
+ \klparse_if_novalue:NTF\klparse_subscript_tl
+ {\klparse_absorb_subscript:Nn\klparse_subscript_tl\klparse_absorb_modifiers_exec:}
+ \klparse_absorb_modifiers_exec:}
+ {\klparse_absorb_modifiers_exec:}
+ }
+% \end{macrocode}
+%
+% The macros \intro{\klparse_absorb_subscript:Nn} and \intro{\klparse_absorb_supscript:Nn}.
+% These are weirdly defined because the catcode of underscore is changed.
+% \begin{macrocode}
+\ExplSyntaxOff
+\def\absorbsupscriptNn{\absorbopt ^}
+\def\absorbsubscriptNn{\absorbopt _}
+\ExplSyntaxOn
+\cs_set_eq:NN\klparse_absorb_supscript:Nn\absorbsupscriptNn
+\cs_set_eq:NN\klparse_absorb_subscript:Nn\absorbsubscriptNn
+
+\cs_new:Npn\absorbopt#1#2#3
+ {\klparse_ifnextchar:NTF #1
+ {\klparse_absorbopt_ii:NnNn #2 {#3}}
+ {\tl_set_eq:NN #2 \klparse_novalue_tl #3}}
+
+\cs_new:Nn\klparse_absorbopt_ii:NnNn
+ {\tl_set:Nn #1 {#4} #2 }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_set_eq:NN\klparse_if_load_subscript:TF\use_i:nn
+\cs_set_eq:NN\klparse_if_load_supscript:TF\use_i:nn
+\cs_set_eq:NN\klparse_if_load_primes:TF\use_i:nn
+% \end{macrocode}
+%
+% \subsection{Subpackages}
+%
+% \subsubsection{Generalities}
+%
+% \begin{macrocode}
+\cs_new:Nn\knowledge_directives_require_aci_package:nn
+ {\bool_if:cTF{knowledge_#2_syntax_bool}{}{
+ \NewKnowledgeParamPackageError{#1}{#2}}}
+% \end{macrocode}
+%
+%
+% \subsubsection{The \texttt{xcolor option}}
+%
+% \begin{macrocode}
+\NewKnowledgeParamTl*{color}\kl_color_tl
+\NewKnowledgeParamTl*{colorbox}\kl_colorbox_tl
+
+\knowledge_directives_require_aci_package:nn
+ {color,colorbox}{xcolor}
+% \end{macrocode}
+%
+%
+% \subsubsection{The \kl{hyperref option}}
+%
+% \begin{macrocode}
+\NewKnowledgeParamTl*{url}\kl_url_tl
+\NewKnowledgeParamTl*{ref}\kl_ref_tl
+
+\knowledge_directives_require_aci_package:nn
+ {url,ref,autoref}{hyperref}
+% \end{macrocode}
+% The commands \kl{\intro}, \kl{\kl} and \kl{\reintro} are made silent when
+% creating the pdf names of sections (for avoiding warnings of the "hyperref@@package").
+% \begin{macrocode}
+\bool_if:NT\knowledge_hyperref_active_bool{
+ \DeclareExpandableDocumentCommand\knowledge_fake_kl{om}{#2}
+ \DeclareExpandableDocumentCommand\knowledge_fake_intro{som}{#3}
+ \DeclareExpandableDocumentCommand\knowledge_fake_reintro{som}{#3}
+
+ \pdfstringdefDisableCommands{%
+ \let\kl\knowledge_fake_kl
+ \let\intro\knowledge_fake_intro
+ \let\reintro\knowledge_fake_reintro
+ }
+}
+% \end{macrocode}
+%
+%
+% \subsubsection{The \kl{makeidx option}}
+%
+% \begin{macrocode}
+\bool_if:NT\knowledge_makeidx_active_bool{
+ \makeindex
+
+ \cs_gset:Npn\knowledge_kl_display_code_index:n
+ {\knowledge_defaultkl_display_code_index:n}
+
+ \cs_new:Npn\knowledge_defaultkl_display_code_index:n
+ {\tl_if_exist:NT\kl_index_tl
+ {\exp_not:N\index
+ {{\tl_if_exist_ne:NTF\kl_index_parent_key_tl
+ {\exp_not:V\kl_index_parent_key_tl!}{}
+ \tl_if_exist_ne:NTF\kl_index_key_tl
+ {\exp_not:V\kl_index_key_tl@}{}
+ \expandafter\detokenize\expandafter{\kl_index_tl}
+ }}}}
+}
+
+\NewKnowledgeParamTl{index}\kl_index_tl
+\keys_define:nn { knowledge~directives }
+{ index .code:n = {
+ \tl_if_empty:nTF{#1}
+ {\knowledge_delay_directive:x{index={\exp_not:V\knowledge_key_tl}}}
+ {\knowledge_delay_directive:n{index={#1}}}},
+ index .default:n = {}
+}
+
+\NewKnowledgeParamTl*{index~style}\kl_index_style_tl
+\NewKnowledgeParamTl*{index~parent~key}\kl_index_parent_tl
+\NewKnowledgeParamTl*{index~key}\kl_index_key_tl
+% \end{macrocode}
+%
+% \subsection{Fixes}
+%
+% \subsubsection{Hyperref in twocolumn}
+%
+% A bug occurs when hyperref is used in twocolumn mode and a link spreads on the boundary between two pages. This causes a fatal error. Here is defined a workaround found at:
+%\url{http://tex.stackexchange.com/questions/249579/pdfendlink-ended-up-in-different-nesting-level-than-pdfstartlink-error-with}
+% for avoiding problems with hyperref links being split it is suficient to call
+% the macro \kl{\knowledgeFixHyperrefTwocolumn}
+% or \kl\knowledgeconfigure\texttt\{\intro{fix hyperref twocolumn}\texttt\}
+% \begin{macrocode}
+\ExplSyntaxOff\makeatletter
+\newcommand\knowledgeFixHyperrefTwocolumn{
+ \RequirePackage{etoolbox}
+ \newcount\c@additionalboxlevel
+ \setcounter{additionalboxlevel}{0}
+ \newcount\c@maxboxlevel
+ \setcounter{maxboxlevel}{1}
+ \patchcmd\@combinedblfloats{\box\@outputbox}{%
+ \stepcounter{additionalboxlevel}%
+ \box\@outputbox
+ }{}{\errmessage{\noexpand\@combinedblfloats could not be patched}}
+ %
+ \AtBeginShipout{%
+ \ifnum\value{additionalboxlevel}>\value{maxboxlevel}%
+ \typeout{Warning: maxboxlevel might be too small, increase to %
+ \the\value{additionalboxlevel}%
+ }%
+ \fi
+ \@whilenum\value{additionalboxlevel}<\value{maxboxlevel}\do{%
+ \typeout{* Additional boxing of page `\thepage'}%
+ \setbox\AtBeginShipoutBox=\hbox{\copy\AtBeginShipoutBox}%
+ \stepcounter{additionalboxlevel}%
+ }%
+ \setcounter{additionalboxlevel}{0}%
+ }
+}
+\ExplSyntaxOn
+\makeatother
+% \end{macrocode}
+%
+%
+%
+% \subsection{configuration}
+%
+% \subsubsection{Accessing the \kl{writing mode}}
+%
+% The paper can be compiled either in \kl{composition mode}, in \kl{paper mode}, or in \kl{electronic mode}.
+% But not both or none. In case of none, this is by default \kl{paper mode}. In case both are activated, this is \kl{paper mode}.
+% \begin{macrocode}
+\bool_if:NF\knowledge_option_composition_bool
+ {\bool_if:NF\knowledge_option_paper_bool}
+ {\bool_gset_true:N\knowledge_option_composition_bool}
+\bool_if:NT\knowledge_option_composition_bool
+ {\bool_if:NT\knowledge_option_paper_bool}
+ {\bool_gset_false:N\knowledge_option_composition_bool}
+
+
+\DeclareExpandableDocumentCommand\IfKnowledgeCompositionModeTF{}
+ {\bool_if:NTF\knowledge_option_composition_bool}
+\newif\ifKnowledgeCompositionMode
+\IfKnowledgeCompositionModeTF
+ \KnowledgeCompositionModetrue
+ \KnowledgeCompositionModefalse
+
+\DeclareExpandableDocumentCommand\IfKnowledgeElectronicModeTF{}
+ {\bool_if:NTF\knowledge_option_electronic_bool}
+\newif\ifKnowledgeElectronicMode
+\IfKnowledgeElectronicModeTF
+ \KnowledgeElectronicModetrue
+ \KnowledgeElectronicModefalse
+
+\DeclareExpandableDocumentCommand\IfKnowledgePaperModeTF{}
+ {\bool_if:NTF\knowledge_option_paper_bool}
+\DeclareExpandableDocumentCommand\IfKnowledgePaperModeF{}
+ {\IfKnowledgePaperModeTF{}}
+\newif\ifKnowledgePaperMode
+\IfKnowledgePaperModeTF
+ \KnowledgePaperModetrue
+ \KnowledgePaperModefalse
+
+\DeclareExpandableDocumentCommand\IfXcolorTF{}
+ {\bool_if:NTF\knowledge_xcolor_active_bool}
+\newif\ifXcolor
+\IfXcolorTF
+ \Xcolortrue
+ \Xcolorfalse
+% \end{macrocode}
+%
+%
+% \subsubsection{Basic configuration}
+%
+% \begin{macrocode}
+\cs_gset_eq:NN\knowledge_kl_init:\knowledge_defaultkl_init:
+\tl_gset_eq:NN\knowledge_kl_namespace_tl\knowledge_defaultkl_namespace_tl
+\cs_gset_eq:NN\knowledge_kl_display_code:\knowledge_defaultkl_display_code:
+\cs_gset_eq:NN\knowledge_kl_update:N\knowledge_defaultkl_update:N
+\tl_gset:Nn\knowledge_kl_command_tl{\kl}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\newcommand\robustdisplay[1]
+ {\expandafter\tl_trim_spaces:n\expandafter{\detokenize{#1}}}
+\newcommand\robustdisplaybracket[1]
+ {[\robustdisplay{#1}]}
+
+% in paper mode, nothing is displayed
+\IfKnowledgePaperModeTF{
+ \knowledgestyle{intro}{emphasize}
+ \knowledgestyle{unknown}{}
+ \knowledgestyle{intro unknown}{emphasize}
+}{}
+
+\IfKnowledgeCompositionModeTF{
+ \IfXcolorTF{
+ \knowledgestyle{intro}{emphasize}
+ \knowledgestyle{unknown}{color=brown}
+ \knowledgestyle{intro unknown}{emphasize,color=red}
+ }{
+ \knowledgestyle{intro}{emphasize}
+ \knowledgestyle{unknown}{underline}
+ \knowledgestyle{intro unknown}{emphasize,underline}}
+}{}
+
+\IfKnowledgeElectronicModeTF{
+ \IfXcolorTF{
+ \knowledgestyle{intro}{emphasize}
+ \knowledgestyle{unknown}{color=brown}
+ \knowledgestyle{intro unknown}{emphasize,color=red}
+ }{
+ \knowledgestyle{intro}{emphasize}
+ \knowledgestyle{unknown}{underline}
+ \knowledgestyle{intro unknown}{emphasize,underline}}
+}{}
+% \end{macrocode}
+%
+
+%
+% \subsubsection{Science paper configuration}
+% \label{section:notion option}
+%
+%\paragraph{The configuration option `\kl{notion}'.}
+%
+%The macro \intro{\KnowledgeConfigureNotion}
+% takes an optional color name (default is blue), and a text.
+% it creates the equivalent of notion of this name, including, configuration of the colors, introducing of styles, and so on.
+%
+% \begin{macrocode}
+\ExplSyntaxOff
+\newrobustcmd\KnowledgeConfigureNotion[2][blue]{
+% \end{macrocode}
+% This code, which is called using \kl{\KnowledgeConfigureNotion} or
+% the configuration option \kl{notion} can serve as a basis for other configuration.
+%\begin{code}[10cm]
+% \begin{macrocode}
+ \knowledgedirective{#2}{autoref,style=#2,intro style=intro #2}
+ \ifKnowledgePaperMode
+ % paper mode
+ \knowledgestyle{#2}{}
+ \knowledgestyle{intro #2}{emphasize}
+ \fi
+ \ifKnowledgeCompositionMode
+ \ifXcolor
+ % composition mode with colors
+ \knowledgestyle{#2}{color={#1!70!black}}
+ \knowledgestyle{intro #2}{emphasize,color={#1}}
+ \else
+ % composition mode, no colors (use underline)
+ \knowledgestyle{#2}{underline}
+ \knowledgestyle{intro #2}{emphasize, underline}
+ \fi
+ \fi
+ \ifKnowledgeElectronicMode
+ \ifXcolor
+ % electronic mode
+ \knowledgestyle{#2}{color={#1!70!black}}
+ \knowledgestyle{intro #2}{emphasize,color={#1}}
+ \else
+ % electronic mode, no colors (use underline)
+ \knowledgestyle{#2}{underline}
+ \knowledgestyle{intro #2}{emphasize, underline}
+ \fi
+ \fi
+% \end{macrocode}
+%\end{code}
+% End of the interesting code.
+% \begin{macrocode}
+}
+\ExplSyntaxOn
+% \end{macrocode}
+%
+% \subsection{Finalizing}
+%
+% At the end, the pending configurations have to be executed (this has to be done with the proper
+% catcode when for instance the \kl(option){quotation} notation is activated).
+%</package>
+%<*tail>
+% \begin{macrocode}
+\ExplSyntaxOn
+\exp_args:NNV\ExplSyntaxOff\knowledgeconfigure\knowledge_configuration_pending_tl
+% \end{macrocode}
+% \begin{macrocode}
+\ScopeActivate
+% \end{macrocode}
+%</tail>
+%
+% \Finale
+%\endinput
+
+
+
+
diff --git a/Master/texmf-dist/tex/latex/knowledge/knowledge.sty b/Master/texmf-dist/tex/latex/knowledge/knowledge.sty
index b566866f7fa..eccc94e1443 100644
--- a/Master/texmf-dist/tex/latex/knowledge/knowledge.sty
+++ b/Master/texmf-dist/tex/latex/knowledge/knowledge.sty
@@ -5,11 +5,12 @@
%% The original source files were:
%%
%% knowledge.dtx (with options: `head')
-%% knowledgeutils.dtx (with options: `package')
+%% knowledge-utils.dtx (with options: `package')
%% knowledge.dtx (with options: `package')
-%% scopearticle.dtx (with options: `package')
+%% knowledge-configuration.dtx (with options: `package')
+%% knowledge.dtx (with options: `tail')
%%
-%% This is a generated file. Copyright (C) 2016 by Thomas Colcombet
+%% This is a generated file. Copyright (C) 2017 by Thomas Colcombet
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
@@ -21,23 +22,16 @@
%% and version 1.2 or later is part of all distributions of
%% LaTeX version 1999/12/01 or later.
%%
-%%%%%%%%%%
\usepackage{expl3}
-\ProvidesExplPackage{knowledge}{2017/06/11}{v1.01}{}
+\ProvidesExplPackage{knowledge}{2017/07/28}{v1.04}{}
+%%%%%%%%%%
\RequirePackage{l3keys2e}
\RequirePackage{etoolbox}
-\RequirePackage[log-declarations=false]{xparse}
+\RequirePackage{xparse}
\bool_if_exist:NTF\knowledge_package_loaded_bool
{\endinput}
{\bool_set_true:N\knowledge_package_loaded_bool}
-\cs_new:Npn\knowledge_skip_module:#1\knowledge_end_module:
- {}
-\cs_new:Nn\knowledge_begin_module_if:N
- {\bool_if:NF#1\knowledge_skip_module:}
-\cs_new:Nn\knowledge_end_module:
- {}
-
\usepackage{xparse}
\usepackage{currfile}
\tl_if_exist:NTF
@@ -251,7 +245,6 @@
\tl_new:N\kauxCurrentFile
\tl_new:N\kauxCurrentLine
-
\bool_new:N\kaux_can_be_used_bool
\bool_gset_false:N\kaux_can_be_used_bool
@@ -737,6 +730,12 @@
\cs_new:Nn\kutils_latex_to_obsolete:n
{\tl_map_function:nN{#1}\kutils_latex_to_obsolete:N}
%%%%%%%%%%
+\cs_new:Npn\knowledge_skip_module:#1\knowledge_end_module:
+ {}
+\cs_new:Nn\knowledge_begin_module_if:N
+ {\bool_if:NF#1\knowledge_skip_module:}
+\cs_new:Nn\knowledge_end_module:
+ {}
\cs_set_eq:Nc\klparse_ifnextchar:NTF{@ifnextchar}
\NewDocumentCommand\klparse_setnovalue{o}
@@ -747,12 +746,56 @@
{\tl_if_eq:NNTF\klparse_novalue_tl}
\cs_new:Nn\knowledge_info:n{\msg_info:nnn{knowledge}{knowledge~info}{#1}}
\cs_new:Nn\knowledge_warning:n{\msg_warning:nnn{knowledge}{knowledge~warning}{#1}}
+\cs_new:Nn\knowledge_error:n{\msg_error:nnn{knowledge}{knowledge~error}{#1}}
\msg_new:nnnn{knowledge}{knowledge~info}{#1}{#2}
\msg_new:nnnn{knowledge}{knowledge~warning}{#1}{#2}
+\msg_new:nnnn{knowledge}{knowledge~error}{#1}{#2}
\cs_generate_variant:Nn\knowledge_info:n{x}
\cs_generate_variant:Nn\knowledge_warning:n{x}
+\cs_generate_variant:Nn\knowledge_error:n{x}
+\msg_new:nnn{ knowledge }{ knowledge~recursion }
+ { The~knowledges~are~probably~cyclic,~starting~from~'#1'~(namespace~'#2'),~
+ currently~at~'#3'.}
+\msg_new:nnn{ knowledge }{ knowledge~unknown }
+ {The~knowledge~'#1'~could~not~be~found~in~scopes~<~#3~>~(namespace~'#2').}
+\msg_new:nnn{ knowledge }{ knowledge~unknown~in~scope }
+ {The~knowledge~'#1'~could~not~be~found~in~scope~'#3'~(namespace~'#2').}
+\msg_new:nnn{ knowledge }{ knowledge~unknown~label }
+ {The~label~'#2'~could~not~be~found~while~searching~for~'#1'.~Possibly~rerun~latex.}
+
+\msg_new:nnn{ knowledge }{ package~required }
+ {In~order~to~use~directive~'#1',~please~load~package~or~use~option~'#2'.}
+\msg_new:nnn{ knowledge }{ knowledge~exists }
+ { The~knowledge~'#1'~in~scope~'#2'~(namespace~'#3')~already~exists. }
+
+\msg_new:nnn{scope}{area~exists}{Area~'#1'~already~exists.}
+\msg_new:nnn{scope}{area~not~exist}{Area~'#1'~does~not~exist.}
+\msg_new:nnn{scope}{empty~pop}{Attempt~to~pop~an~empty~area~stack.}
+\msg_new:nnn{scope}{no~pushing~here}
+ {Not~allowed~to~open~'\scope_pushed_area_tl'~here.~
+ Current~stack~is~<\seq_use:Nn\scope_instances_stack_seq{::}>.}
+\msg_new:nnn{scope}{no~popping}{Not~allowed~to~close~'\scope_popped_area_tl'.}
+\msg_new:nnn{scope}{no~popping~here}
+ {Not~allowed~to~close~'\scope_popped_area_tl'~here~(at~'\scope_top_area_tl').}
+\msg_new:nnn{scope}{unknown~label}
+ {\tl_if_empty:nTF{#2}{}{\exp_not:n{#2}}:
+ ~Unknown~label~`#1'.~Possibly~rerun~latex.}
+\msg_new:nnn{scope}{area~not~in~context}
+ {\tl_if_empty:nTF{#2}{}{\exp_not:n{#2}}:
+ ~The~area~`#1'~can't~be~found~in~context.~Possibly~rerun~latex.}
+\NewKAuxCommand\KAuxErrorKnowledgeRecursive{mmmm}
+ {Package~'knowledge:~A~knowledge~has~recursive~definition.~
+ {namespace}{scope}{undefined~knowledge}{base~knowledge}}
+ {}
+\cs_new:Nn\knowledge_kl_error_recursion: {
+ \msg_error:nnxxx{ knowledge }{ knowledge~recursion }
+ {\exp_not:V\knowledge_kl_base_key_tl}
+ {\exp_not:V\knowledge_kl_namespace_tl}
+ {\exp_not:V\knowledge_kl_key_tl}
+ \knowledge_kl_error_display:n{recursive~knowledge}
+}
\tl_new:N\knowledge_configuration_pending_tl
\tl_set:Nn\knowledge_configuration_pending_tl{}
\NewDocumentCommand\KnowledgePackageTrigger{mm}
@@ -812,14 +855,13 @@
\keys_define:nn{ knowledge~configuration~options }{
#2 .code:n = {\OPTION_CANNOT_BE_USED_IN_knowledgeconfigure}
}}
-
\NewDocumentCommand\KnowledgeConfigureTrigger{omm}{
\IfNoValueTF{#1}
{\tl_set:Nn\l_tmpa_tl{#2}
\tl_remove_all:Nn\l_tmpa_tl{~}
\exp_args:NNV\KnowledgeConfigureTrigger[\l_tmpa_tl]{#2}{#3}}
{\keys_define:nn { knowledge~configuration~options }
- { #2 .code:n = {#3} }
+ { #2 .code:n = {#3}, #2 .default:V = \klparse_novalue_tl }
\keys_define:nn { knowledge~package~options }
{ #1 .code:n = {\tl_put_right:Nn\knowledge_configuration_pending_tl{,#2={##1}} }}
}
@@ -834,6 +876,9 @@
\bool_new:N\knowledge_configuration_quotation_bool
\KnowledgeConfigureBooleanOptionTF[\knowledge_configuration_quotation_bool]{quotation}{\klactivatequotation}{\kldeactivatequotation}
\KnowledgeConfigureOption{protect~quotation}{\kl_protect_environment_quotation:n{#1}}
+\bool_new:N\knowledge_configuration_diagnoseline_bool
+\bool_gset_true:N\knowledge_configuration_diagnoseline_bool
+\KnowledgeConfigureBooleanOption[\knowledge_configuration_diagnoseline_bool]{diagnose~line}
\bool_new:N\knowledge_configuration_visibleAP_bool
\KnowledgeConfigureBooleanOption[\knowledge_configuration_visibleAP_bool]{visible~anchor~points}\KnowledgeConfigureBooleanOption[\knowledge_configuration_visibleAP_bool]{visible~AP}
\bool_new:N\knowledge_hyperlinks_active_bool
@@ -847,7 +892,7 @@
\KnowledgeConfigureTrigger{ fix~hyperref~twocolumn }
{\knowledgeFixHyperrefTwocolumn}
\KnowledgeConfigureTrigger{ notion }
- {\KnowledgeConfigureNotion}
+ {\KnowledgeConfigureNotion{notion}}
\KnowledgeConfigureTrigger{ protect~links }
{\kl_kl_nesting_incr:}
\KnowledgeConfigureTrigger{ unprotect~links }
@@ -951,6 +996,26 @@
\seq_new:N\scope_instances_stack_seq
\tl_new:N\scope_top_instance_tl
\tl_new:N\scope_top_area_tl
+\cs_new:Nn\scope_area_show:n{
+ \group_begin:
+ \scope_area_if_exist:nTF{#1}
+ { \tl_set:Nx\self{\scope_tl.area[#1]}
+ \tl_show:x
+ {Area~name:~\use:c{\self.name_tl},~
+ autoclose=\bool_if:cTF{\self.autoclose_bool}TF,~
+ recursive=\bool_if:cTF{\self.recursive_bool}TF,~
+ multiple=\bool_if:cTF{\self.multiple_bool}TF,~
+ scope=\bool_if:cTF{\self.scope_bool}TF,~
+ environment=\bool_if:cTF{\self.environment_bool}TF,~
+ forces={\use:c{\self.forces_tl}},~
+ accepts~knowledge=\bool_if:cTF{\self.accepts_knowledge_bool}TF,~
+ attracts~knowledge=\bool_if:cTF{\self.attracts_knowledge_bool}TF,~
+ accepts~labels=\bool_if:cTF{\self.labelizable_bool}TF.
+ }
+ }
+ {\knowledge_error:n{Unknown~area~`#1'~in~`\noexpand\scope_area_show:n'.}}
+ \group_end:
+}
\cs_new:Nn\scope_area_create:n
{\group_begin:
\tl_set:Nx\self{\scope_tl.area[#1]}
@@ -962,8 +1027,11 @@
\seq_gpush:cn{\self.category_seq}{all}
\seq_gpush:cn{\self.category_seq}{#1}
\bool_gset_false:c{\self.autoclose_bool}
+ \bool_gset_true:c{\self.environment_bool}
\bool_gset_true:c{\self.multiple_bool}
\bool_gset_true:c{\self.attractsknowledge_bool}
+ \bool_gset_true:c{\self.labelizable_bool}
+ \bool_gset_false:c{\self.scope_bool}
\bool_gset_true:c{\self.acceptsknowledge_bool}
\tl_gset:cn{\self.pushcode_tl}{}
\tl_gset:cn{\self.popcode_tl}{}
@@ -981,11 +1049,16 @@
}
\cs_new:Npn\scope_area_if_exist:nTF#1
{\tl_if_exist:cTF{\scope_tl.area[#1].name_tl}}
+\cs_new:Npn\scope_if_triggers_area:nTF#1{
+ \scope_area_if_exist:nTF{#1}
+ {\bool_if:cTF{\scope_tl.area[#1].environment_bool}
+ \use_i:nn
+ \use_ii:nn}
+ \use_ii:nn
+}
\cs_new:Npn\scope_area_if_in_scope:nTF#1
{\int_compare:nNnTF
{\use:c{\scope_tl.area[#1].nesting_int}}>0}
-\msg_new:nnn{scope}{area~exists}{Area~already~exists~'#1'.}
-\msg_new:nnn{scope}{area~not~exist}{Area~does~not~exist~'#1'.}
\NewDocumentCommand\ScopeConfigure{mm}
{\scope_area_set:nn{#1}{#2}}
\cs_new:Nn\scope_area_set:nn
@@ -1027,6 +1100,22 @@
occurrences / recursive .code:n = {
\bool_gset_true:c{\self.multiple_bool}
\bool_gset_true:c{\self.recursive_bool}},
+ scope .choice:,
+ scope / true .code:n = {
+ \bool_gset_true:c{\self.scope_bool}},
+ scope / false .code:n = {
+ \bool_gset_false:c{\self.scope_bool}},
+ environment .choice:,
+ environment / true .code:n = {
+ \bool_gset_true:c{\self.environment_bool}},
+ environment / false .code:n = {
+ \bool_gset_false:c{\self.environment_bool}},
+ environment .default:n = {true},
+ label .choice:,
+ label / none .code:n = {
+ \bool_gset_false:c{\self.labelizable_bool}},
+ label / accepts .code:n = {
+ \bool_gset_true:c{\self.labelizable_bool}},
knowledge .choice:,
knowledge / none .code:n = {
\bool_gset_false:c{\self.acceptsknowledge_bool}
@@ -1063,15 +1152,6 @@
{\tl_if_exist:cTF{\scopept_tl.label[#1].instance_tl}}
\tl_new:N\scope_pushed_area_tl
\tl_new:N\scope_popped_area_tl
-\msg_new:nnn{scope}{empty~pop}
- {Attempt~to~pop~an~empty~area~stack.}
-\msg_new:nnn{scope}{no~pushing~here}
- {Not~allowed~to~open~'\scope_pushed_area_tl'~here.~
- Current~stack~is~<\seq_use:Nn\scope_instances_stack_seq{::}>.}
-\msg_new:nnn{scope}{no~popping}
- {Not~allowed~to~close~'\scope_popped_area_tl'.}
-\msg_new:nnn{scope}{no~popping~here}
- {Not~allowed~to~close~'\scope_popped_area_tl'~here~(at~'\scope_top_area_tl').}
\cs_new:Nn\scope_area_pop:n {
\tl_gset:Nn\scope_popped_area_tl{#1}
\bool_if:cTF{\scope_tl.area[\scope_popped_area_tl].autoclose_bool}
@@ -1221,6 +1301,36 @@
{\scope_tl.area[\tl_use:c{\scope_tl.instance[##1].area_tl}].attractsknowledge_bool}
{\tl_set:Nn#1{##1}\seq_map_break:}{}}
}
+\cs_new:Nn\scope_get_labelizable_instance:N
+{\tl_set:Nn#1{base}
+ \seq_map_inline:Nn\scope_instances_stack_seq
+ {\bool_if:cTF
+ {\scope_tl.area[\tl_use:c{\scope_tl.instance[##1].area_tl}].labelizable_bool}
+ {\tl_set:Nn#1{##1}\seq_map_break:}{}}
+}
+\cs_new:Nn\knowledge_scope_track_instance:Nn{
+ \scope_area_if_exist:nTF{#2}
+ {\knowledge_scope_track_instance_from_area:Nn#1{#2}}
+ {\knowledge_scope_track_instance_from_label:Nn#1{#2}}
+}
+\cs_new:Nn\knowledge_scope_track_instance_from_area:Nn{
+ \tl_set:Nn#1{}
+ \seq_map_inline:Nn\scope_instances_stack_seq
+ {\exp_args:Nxx\tl_if_eq:nnTF
+ {\csname \scope_tl.instance[##1].area_tl\endcsname}
+ {#2}
+ {\tl_set:Nn#1{##1}\seq_map_break:}
+ {}}
+ \tl_if_empty:NTF#1
+ {\msg_error:nnxx{scope}{area~not~in~context}{#2}{scope=}}
+ {}
+}
+\cs_new:Nn\knowledge_scope_track_instance_from_label:Nn{
+ \tl_set:Nn#1{}
+ \scopept_label_instance_if_exist:nTF{#2}
+ {\tl_set:Nx#1{\scopept_label_instance_use:n{#2}}}
+ {\msg_warning:nnnn{scope}{unknown~label}{#2}{scope=}}
+}
\bool_new:N\scopept_map_break_bool
\cs_new:Nn\scopept_map_break:
{\bool_set_true:N\scopept_map_break_bool}
@@ -1246,8 +1356,9 @@
}
\NewDocumentCommand\scopeLabel{m}
{ \kl_hide_begin:
- \scope_get_attractive_instance:N\l_tmpb_tl
- \KAuxWriteX*{\exp_not:n{\KAuxScopeLabel{#1}}{\l_tmpb_tl}}
+ \scope_get_labelizable_instance:N\l_tmpb_tl
+ \KAuxWriteX*{\exp_not:n{\KAuxScopeLabel}{#1}{\l_tmpb_tl}}
+ \tl_gset:cx{\scopept_tl.label[#1].instance_tl}{\l_tmpb_tl}
\kl_hide_end:
\cs_if_exist:NTF\LaTeXlabel\LaTeXlabel\use_none:n{#1}}
\let\label\scopeLabel
@@ -1264,20 +1375,45 @@
{\tl_if_exist:cTF{\scopept_tl.label[#1].instance_tl}}
\cs_new:Nn\scopept_label_instance_use:n
{\tl_use:c{\scopept_tl.label[#1].instance_tl}}
+\newcommand\knowledgeconfigureenvironment\KnowledgeConfigureEnvironment
+\NewDocumentCommand\KnowledgeConfigureEnvironment{t?t!mm}
+ {\clist_map_inline:nn{#3}{
+ \IfBooleanTF{#2}
+ {\scope_area_environment_new:nn{##1}{#4}}
+ {\cs_if_exist:cT{##1}
+ {\cs_if_exist:cT{end##1}
+ {\scope_area_environment_new:nn{##1}{#4}
+ \use_none:n}}
+ {\IfBooleanF{#1}
+ {\knowledge_error:n{Unknown~environment~`##1'~in~\KnowledgeConfigureEnvironment.}}}
+ }}}
+\newcommand\scope_activate_environment[2][environment]{
+ \scope_area_environment_new:nn
+ {#2}{category=#1}}
+\cs_new:Nn\scope_area_environment_new:nn
+ {\scope_area_set:nn{#1}{
+ parents = all,
+ autoclose = false,
+ environment = true,
+ occurrences = recursive,
+ knowledge = attracts,
+ category = environment,
+ #2
+ }}
\NewDocumentCommand\ScopeHackEnvironments{}
{ %\ScopeActivate
\scope_area_push:n{document}
\kutils_secure_latex_command:N\begin
\global\let\SUPERbegin\begin
\global\def\begin##1
- {\scope_area_if_exist:nTF{##1}
+ {\scope_if_triggers_area:nTF{##1}
{\scope_area_push:n{##1}}{}
\SUPERbegin{##1}}
\kutils_secure_latex_command:N\end
\global\let\SUPERend\end
\global\def\end##1
{\SUPERend{##1}
- \scope_area_if_exist:nTF{##1}
+ \scope_if_triggers_area:nTF{##1}
{\scope_area_pop:n{##1}}
{}}
\kutils_secure_latex_command:N\label
@@ -1288,40 +1424,10 @@
\cs_gset_eq:NN\ScopeActivate\relax
}
\AtBeginDocument{\ScopeActivate}
-\scope_area_set:nn{knowledge~context~internal}
-{
- occurrences = recursive,
- autoclose = false,
- parents= {base,all},
- knowledge=attracts
-}
-\scope_area_set:nn{knowledge~import~internal}
-{
- occurrences = recursive,
- autoclose = false,
- parents= {base,all},
- knowledge = accepts
-}
-\NewDocumentEnvironment{knowledge~import}{m}
- {\ScopeActivate\scope_area_push:n{knowledge~import~internal}
- \clist_map_inline:nn{#1}{\knowledgeimport{##1}}}
- {\scope_area_pop:n{knowledge~import~internal}}
-\NewDocumentEnvironment{knowledge~context}{m}
- {\ScopeActivate\scope_area_push:n{knowledge~context~internal}
- \scopeLabel{#1}}
- {\scope_area_pop:n{knowledge~context~internal}}
-\NewDocumentCommand\knowledgescopingenvironment{>{\SplitList{,}} m}
- { \cs_set:Nn\l_tmpa_cs:n
- {\scope_area_set:nn{##1}
- {autoclose=false,
- occurrences=recursive,
- knowledge=attracts,
- parents=all}}
- \ProcessList{#1}\l_tmpa_cs:n
-}
\AtBeginDocument{\ScopeHackEnvironments}
-\AtEndDocument{\scope_area_pop:n{document}}
-\cs_new:Nn\knowledge_scope_default:{
+ \scope_area_set:nn{document,base,body} {
+ environment=false
+ }
\scope_area_set:nn{base}
{occurrences = once,
autoclose = false}
@@ -1343,27 +1449,72 @@
\newenvironment{scope}
{\mode_if_preamble:TF{\scope_area_push:n{scope}}{}}
{\mode_if_preamble:TF{\scope_area_pop:n{scope}}{}}
- \knowledgescopingenvironment{scope}
+ \knowledgeconfigureenvironment{scope}{}
+\scope_area_set:nn{knowledge~context~internal}
+{
+ occurrences = recursive,
+ autoclose = false,
+ parents= {base,all},
+ knowledge=attracts
+}
+\scope_area_set:nn{knowledge~import~internal}
+{
+ occurrences = recursive,
+ autoclose = false,
+ parents= {base,all},
+ knowledge = accepts
}
-\knowledge_scope_default:
+\NewDocumentEnvironment{knowledge~import}{m}
+ {\ScopeActivate\scope_area_push:n{knowledge~import~internal}
+ \clist_map_inline:nn{#1}{\knowledgeimport{##1}}}
+ {\scope_area_pop:n{knowledge~import~internal}}
+\NewDocumentEnvironment{knowledge~context}{m}
+ {\ScopeActivate\scope_area_push:n{knowledge~context~internal}
+ \scopeLabel{#1}}
+ {\scope_area_pop:n{knowledge~context~internal}}
\KAuxBefore{\KAuxProcess{init}}
\KAuxInit{}
\KAuxAfter{\KnowledgeDiagnoseOutput}
\iow_new:N\knowledge_diagnosefile_iow
\cs_new:Nn\knowledge_diagnose:n
{\iow_now:Nn\knowledge_diagnosefile_iow{#1}}
-\cs_generate_variant:Nn\knowledge_diagnose:n{x}
+\cs_generate_variant:Nn\knowledge_diagnose:n{x,V}
+
+\cs_new:Nn\knowledge_diagnose_reset_line:
+ {\tl_gset:Nn\knowledge_diagnose_lastline_tl{...}}
+\knowledge_diagnose_reset_line:
+
+\cs_new:Nn\knowledge_diagnose_line:
+ {\bool_if:NT\knowledge_configuration_diagnoseline_bool
+ {\tl_set:Nx\g_tmpa_tl
+ {\c_percent_str\space\kauxCurrentFile : \kauxCurrentLine}
+ \tl_if_eq:NNTF\g_tmpa_tl\knowledge_diagnose_lastline_tl
+ {}
+ {\tl_gset_eq:NN\knowledge_diagnose_lastline_tl\g_tmpa_tl
+ \knowledge_diagnose:V\g_tmpa_tl}}}
+
+\msg_new:nnn{knowledge}{unknown~knowledge}
+ {Some~knowledge~are~not~defined.~See~the~'.diagnose'~file~for~more~information.}
+\msg_new:nnn{knowledge}{autoref~introduced~twice}
+ {Some~knowledge~is~introduced~twice.~See~the~'.diagnose'~file~for~more~information.}
+\msg_new:nnn{knowledge}{autoref~not~introduced}
+ {Some~knowledge~is~used~but~not~introduced.~See~the~'.diagnose'~file~for~more~information.}
+\msg_new:nnn{knowledge}{scope~unknown}
+ {Some~label~is~used~but~not~defined.~See~the~'.diagnose'~file~for~more~information.}
\NewDocumentCommand\KnowledgeDiagnoseOutput{}{
\iow_open:Nn\knowledge_diagnosefile_iow{\c_sys_jobname_str.diagnose}
% compute first the list of warnings and important information
- \KAuxProcess{diagnose~digest}
+ %
+ \knowledge_diagnose_reset_line:
+ \KAuxProcess{diagnose-digest}
%
\knowledge_diagnose:n{***********}
\knowledge_diagnose:n{*~Summary~*}
\knowledge_diagnose:n{***********}
\knowledge_diagnose:n{}
\knowledge_diagnose:x{\int_use:N\kl_digest_unknownknowledge_int\space undefined~knowledge(s).}
+ %\knowledge_diagnose:x{\int_use:N\kl_digest_unknownlabel_int\space label(s)~are~used~as~scopes~but~not~introduced.}
\knowledge_diagnose:x{\int_use:N\kl_digest_autoreftwiceintro_int\space autoreference(s)~are~introduced~twice.}
\knowledge_diagnose:x{\int_use:N\kl_digest_autorefnointro_int\space autoreference(s)~are~used~but~not~introduced.}
\knowledge_diagnose:n{}
@@ -1377,27 +1528,45 @@
\knowledge_diagnose:n{*~Undefined~knowledges~*}
\knowledge_diagnose:n{************************}
\knowledge_diagnose:n{}
+ %
+ \knowledge_diagnose_reset_line:
\KAuxProcess{diagnose-unknown-suggest}
+ %
+ \knowledge_diagnose:n{}
\knowledge_diagnose:n{}
- \knowledge_diagnose:n{}}
+ %
+ \msg_warning:nn{knowledge}{unknown~knowledge}
+ }
%
\int_compare:nNnT\kl_digest_autoreftwiceintro_int>0{
\knowledge_diagnose:n{****************************}
- \knowledge_diagnose:n{*~Autoref~introduced~twice~*}
+ \knowledge_diagnose:n{*~autoref-introduced-twice~*}
\knowledge_diagnose:n{****************************}
\knowledge_diagnose:n{}
- \KAuxProcess{autoref~introduced~twice}
+ %
+ \knowledge_diagnose_reset_line:
+ \KAuxProcess{autoref-introduced-twice}
+ %
+ \knowledge_diagnose:n{}
\knowledge_diagnose:n{}
- \knowledge_diagnose:n{}}
+ %
+ \msg_warning:nn{knowledge}{autoref~introduced~twice}
+ }
%
\int_compare:nNnT\kl_digest_autorefnointro_int>0{
\knowledge_diagnose:n{******************************}
\knowledge_diagnose:n{*~Autoref~used~without~intro~*}
\knowledge_diagnose:n{******************************}
\knowledge_diagnose:n{}
- \KAuxProcess{autoref~not~introduced}
+ %
+ \knowledge_diagnose_reset_line:
+ \KAuxProcess{autoref-not-introduced}
+ %
\knowledge_diagnose:n{}
- \knowledge_diagnose:n{}}
+ \knowledge_diagnose:n{}
+ %
+ \msg_warning:nn{knowledge}{autoref~not~introduced}
+ }
%
\iffalse
\knowledge_diagnose:n{***********************}
@@ -1413,13 +1582,18 @@
\makeatother
\cell_new_type:nnn{knowledge}{nnnn}{KL@#2@#3@\detokenize{#4}_#1}
\cell_new_type:nnn{knowledge}{nnn}{\knowledge_id:nnnn{}{#1}{#2}{#3}}
-\cs_generate_variant:Nn\knowledge_id:nnn{nnV,nVV,nVn}
+\cs_generate_variant:Nn\knowledge_id:nnn{nnV,nVV,nVn,VVV}
\cs_generate_variant:Nn\knowledge_at:Nnnn{NnnV}
\cs_new:Npn\knowledge_at:c{\exp_args:Nc\knowledge_at:N}
\cs_new:Nn\knowledge_sets_to:nnn
{\cs_set:Nx\knowledge_at:N
{##1\exp_not:c{\knowledge_id:nnn{#1}{#2}{#3}}}}
\tuple_new:n{ktuple}
+\cs_new:Npn\knowledge_knowledge_if_exist:nnnTF#1#2#3{
+ \exp_args:Nc\ktuple_if_exist:NTF{\knowledge_id:nnn{#1}{#2}{#3}}
+}
+\cs_generate_variant:Nn
+ \knowledge_knowledge_if_exist:nnnTF{VVVTF}
\NewDocumentCommand\NewKnowledgeParamBool{smm}{
\ktuple_new_bool_index:n{#2}
\use:c{ktuple_#2_expands_to:TF}
@@ -1486,13 +1660,13 @@
##1 .code:n = {
\msg_error:nnnn{ knowledge }{ package~required }{##1}{#2}}
}}}
-\msg_new:nnn{ knowledge }{ package~required }
- {In~order~to~use~directive~'#1',~please~load~package~or~use~option~'#2'.}
\tl_new:N\knowledge_current_instance_tl
\tl_gset:Nn\knowledge_current_instance_tl{base}
\seq_new:N\knowledge_visible_instances_seq
\cs_new:Nn\knowledge_push_visible_instance:n
{\seq_gpush:Nn\knowledge_visible_instances_seq{#1}}
+\cs_new:Nn\knowledge_lpush_visible_instance:n
+ {\seq_push:Nn\knowledge_visible_instances_seq{#1}}
\cs_new:Npn\knowledge_pop_visible_instance:
{\seq_gpop:NN\knowledge_visible_instances_seq\g_tmpa_tl}
\cs_new:Nn\knowledge_pop_visible_instances_to:n
@@ -1511,11 +1685,9 @@
{\kl_hide_begin:
\scopept_label_instance_if_exist:nTF{#1}
{\exp_args:Nx\knowledge_import_instance:n{\scopept_label_instance_use:n{#1}}}
- {}
+ {\msg_warning:nnnn{scope}{unknown~label}{#1}{\knowledgeimport}}
\kl_hide_end:
}
-\cs_if_exist:NTF\knowledge_track_instance:n{}
- {\cs_new:Nn\knowledge_track_instance:n{base}}
\keys_define:nn { knowledge~directives } {
namespace .code:n = { \tl_set:Nn\knowledge_knowledge_namespace_tl{#1} },
force .choice:,
@@ -1533,13 +1705,14 @@
instance .code:n =
{ \tl_set:Nn\knowledge_knowledge_instance_tl{#1} },
scope .code:n =
- { \tl_set:Nx\knowledge_knowledge_instance_tl{\knowledge_track_instance:n{#1}}},
+ { \knowledge_scope_track_instance:Nn\knowledge_knowledge_instance_tl{#1} },
synonym .code:n =
- { \exp_args:Nnx\keys_set:nn { knowledge~directives }
- {link={\exp_not:o\knowledge_knowledge_synonym_tl}}}
+ { \bool_set_true:N\knowledge_knowledge_is_synonym_bool
+ \exp_args:Nnx\keys_set:nn { knowledge~directives }
+ {link={\exp_not:o\knowledge_knowledge_synonym_tl},
+ link~instance={\exp_not:o\knowledge_knowledge_synonyminstance_tl},
+ instance={\exp_not:o\knowledge_knowledge_synonyminstance_tl}}}
}
-\msg_new:nnn{ knowledge }{ knowledge~exists }
- { The~knowledge~'#1'~in~scope~'#2'~(namespace~'#3')~already~exists. }
\NewKAuxCommand\KAuxKnowledge{mmmm}
{Package~knowledge:~Declares~a~knowledge.~
Takes~the~{namespace}{instance}{knowledge}{directives}.}
@@ -1553,7 +1726,7 @@
\knowledge_at:N\ktuple_if_exist:NTF
{\bool_if:NTF\knowledge_knowledgestyle_bool
{\knowledge_at:N\ktuple_gclear:N}
- {\tl_show:n{knowledge~'#3'~(namespace=#1,~scope=#2)~is~redefined.}}}
+ {\knowledge_warning:n{knowledge~'#3'~(namespace=#1,~scope=#2)~is~redefined.}}}
{\knowledge_at:N\ktuple_new:N}
\keys_set:nn { knowledgenow~directives } { #4 }
}
@@ -1572,20 +1745,25 @@
\exp_not:n{\knowledge_knowledge_process:nn{#1}}
{\exp_not:V\kl_knowledgedefault_tl,\exp_not:n{#3}}}
%
- % if synonym, then the synonym name is unchanged
\bool_if:NF\knowledge_knowledge_is_synonym_bool
- {\tl_gset:Nn\knowledge_knowledge_synonym_tl{#1}}
+ {\tl_gset:Nn\knowledge_knowledge_synonym_tl{#1}
+ \tl_gset_eq:NN\knowledge_knowledge_synonyminstance_tl
+ \knowledge_knowledge_instance_tl}
%
\IfNoValueTF{#2}{}{
\cs_set:Nn\l_tmpa_cs:n
- {\knowledge_knowledge_process:nn{##1}{link={#1}}}
+ {\exp_args:Nnx\knowledge_knowledge_process:nn{##1}{synonym}}
\ProcessList{#2}\l_tmpa_cs:n
}
+ %
\group_end:
\kl_hide_end:
}
+\bool_new:N\knowledge_knowledge_now_bool
\bool_new:N\knowledge_knowledge_is_synonym_bool
\tl_new:N\knowledge_knowledge_synonym_tl
+\tl_new:N\knowledge_knowledge_synonyminstance_tl
+\tl_gset:Nn\knowledge_knowledge_synonyminstance_tl{}
\bool_new:N\knowledge_knowledgestyle_bool
\NewDocumentCommand\knowledgestyle{ s m m }
{ \kl_hide_begin:
@@ -1593,6 +1771,9 @@
\tl_set:Nn\knowledge_namespace_tl{style}
%
\bool_set_true:N\knowledge_knowledgestyle_bool
+ \IfBooleanTF{#1}
+ {\bool_set_true:N\knowledge_knowledgestyle_override_bool}
+ {\bool_set_false:N\knowledge_knowledgestyle_override_bool}
%
\knowledge_knowledge_process:nn{#2}{#3}
\group_end:
@@ -1604,6 +1785,7 @@
\bool_set_false:N\knowledge_knowledge_force_bool
\bool_set_false:N\knowledge_knowledge_export_bool
%
+ %
\tl_set:Nn\knowledge_key_tl{#1}
%
\tl_set_eq:NN\knowledge_knowledge_namespace_tl\knowledge_namespace_tl
@@ -1616,6 +1798,7 @@
\mode_if_preamble:TF
{\bool_set_true:N\knowledge_knowledge_now_bool}
{}
+ %
\bool_if:NTF\knowledge_knowledge_now_bool
{\use:x{
\exp_not:N\knowledge_set_now:nnnn
@@ -1623,14 +1806,15 @@
{\knowledge_knowledge_instance_tl}
{\exp_not:V\knowledge_key_tl}
{\exp_not:V\knowledge_directives_tl}}
- } {
+ }{
\KAuxWriteX*{
\exp_not:N\KAuxKnowledge
{\knowledge_knowledge_namespace_tl}
{\knowledge_knowledge_instance_tl}
{\exp_not:V\knowledge_key_tl}
{\exp_not:V\knowledge_directives_tl}}
- }
+ }
+ %
\bool_if:NT\knowledge_knowledge_export_bool
{\KAuxWriteX*{
\exp_not:N\KAuxExport
@@ -1664,35 +1848,75 @@
{\tl_set:Nn\kl_knowledgedefault_tl{#2}}
\kl_hide_end:
}
-\int_const:Nn\knowledge_kl_max_recursion_int{40}
-\int_new:N\knowledge_kl_recursion_int
-\cs_new:Nn\kl_base:nn{
- \tl_set:Nn\knowledge_kl_text_tl{#2}
+\NewDocumentCommand\kl{d() o d() m}{
\IfNoValueTF{#1}
- {\tl_set:Nn\knowledge_kl_base_key_tl{#2}}
- {\tl_set:Nn\knowledge_kl_base_key_tl{#1}}
- %
- \tl_set_eq:NN\knowledge_kl_key_tl\knowledge_kl_base_key_tl
- %
- \int_set_eq:NN\knowledge_kl_recursion_int\knowledge_kl_max_recursion_int
- %
- \knowledge_kl_find:
+ {\IfNoValueTF{#3}
+ {\IfNoValueTF{#2}
+ {\knowledge_klTKS:nnn{#4}{#4}{}}
+ {\knowledge_klTKS:nnn{#4}{#2}{}}}
+ {\IfNoValueTF{#2}
+ {\knowledge_klTKS:nnn{#4}{#4}{#3}}
+ {\knowledge_klTKS:nnn{#4}{#2}{#3}}}}
+ {\IfNoValueTF{#2}
+ {\knowledge_klTKS:nnn{#4}{#4}{#1}}
+ {\knowledge_klTKS:nnn{#4}{#2}{#1}}}
+}
+\NewDocumentCommand\klTKS{}{\knowledge_klTKS:nnn}
+\cs_new:Nn\knowledge_klTKS:nnn{
+ \group_begin:
+ \knowledge_kl_init:
+ \cs_gset_eq:NN\knowledge_kl_init:\knowledge_defaultkl_init:
+ \tl_set:Nn\knowledge_kl_linkscope_tl{#3}
+ \tl_set:Nn\knowledge_kl_linkinstance_tl{}
+ \tl_set:Nn\knowledge_kl_text_tl{#1}
+ \tl_set:Nn\knowledge_kl_base_key_tl{#2}
+ \tl_set_eq:NN\knowledge_kl_key_tl\knowledge_kl_base_key_tl
+ \int_set_eq:NN\knowledge_kl_recursion_int\knowledge_kl_max_recursion_int
+ \knowledge_kl_find:
+ \group_end:
+ \knowledge_display_sequence:
}
-\cs_new:Nn\knowledge_kl_find:
-{
+\int_const:Nn\knowledge_kl_max_recursion_int{40}
+\int_new:N\knowledge_kl_recursion_int
+\cs_set:Nn\knowledge_kl_find:{
+ \tl_if_empty:NTF\knowledge_kl_linkinstance_tl
+ {\tl_if_empty:NTF\knowledge_kl_linkscope_tl
+ \knowledge_kl_find_withoutscope:
+ \knowledge_kl_find_withscope:}
+ \knowledge_kl_find_withinstance:
+}
+\cs_new:Nn\knowledge_kl_find_withinstance:{
+ \knowledge_knowledge_if_exist:VVVTF
+ \knowledge_kl_namespace_tl
+ \knowledge_kl_linkinstance_tl
+ \knowledge_kl_key_tl
+ {\knowledge_kl_exec:nnV
+ \knowledge_kl_namespace_tl
+ \knowledge_kl_linkinstance_tl
+ \knowledge_kl_key_tl}
+ { \knowledge_kl_error_unknown_in_scope: }
+}
+\cs_new:Nn\knowledge_kl_find_withscope:{
+ \exp_args:NV
+ \scopept_label_instance_if_exist:nTF\knowledge_kl_linkscope_tl
+ { \tl_set:Nx\knowledge_kl_linkinstance_tl
+ {\scopept_label_instance_use:n{\knowledge_kl_linkscope_tl}}
+ \knowledge_kl_find_withinstance: }
+ { \knowledge_kl_error_label_unknown: }
+}
+\cs_new:Nn\knowledge_kl_find_withoutscope:{
\int_decr:N\knowledge_kl_recursion_int
\tl_clear:N\knowledge_kl_link_tl
\tl_clear:N\knowledge_kl_style_tl
\tl_clear:N\knowledge_kl_intro_style_tl
\int_compare:nNnTF\knowledge_kl_recursion_int=0
- {\knowledge_kl_error_recursion:}
+ \knowledge_kl_error_recursion:
{\knowledge_kl_find_in_scope:VNTF
- \knowledge_kl_key_tl\knowledge_kl_instance_tl
- {\exp_args:Nc\knowledge_kl_exec:N
- {\knowledge_id:nnV
+ \knowledge_kl_key_tl\knowledge_kl_linkinstance_tl
+ {\knowledge_kl_exec:nnV
\knowledge_kl_namespace_tl
- \knowledge_kl_instance_tl
- \knowledge_kl_key_tl}}
+ \knowledge_kl_linkinstance_tl
+ \knowledge_kl_key_tl}
{\knowledge_kl_error_unknown:}
}
}
@@ -1721,43 +1945,63 @@
\seq_map_break:}{}}
\cs_generate_variant:Nn\knowledge_kl_find_in_scope:nnNTF{nVNTF}
\cs_generate_variant:Nn\knowledge_kl_find_in_scope:nNTF{VNTF}
+\cs_new:Nn\knowledge_kl_exec:nnn{
+ \exp_args:NNc\tl_set:Nn\knowledge_kl_resource_tl
+ {\knowledge_id:nnn{#1}{#2}{#3}}
+ %
+ \tl_set:Nn\knowledge_kl_link_tl{}
+ \tl_set:Nn\knowledge_kl_linkscope_tl{}
+ \tl_set:Nn\knowledge_kl_linkinstance_tl{}
+ %
+ \knowledge_kl_resource_tl
+ %
+ \tl_if_empty:xTF\knowledge_kl_used_style_tl
+ {}
+ {\knowledge_kl_use_style:x
+ {\knowledge_kl_used_style_tl}}
+ %
+ \expandafter\knowledge_kl_update:N\knowledge_kl_resource_tl
+ %
+ %\knowledge_kl_exec_to_kaux:
+ %
+ \tl_if_exist_ne:NTF\knowledge_kl_linkscope_tl{
+ \tl_if_exist_ne:NTF\knowledge_kl_link_tl{}{
+ \tl_set_eq:NN\knowledge_kl_link_tl
+ \knowledge_kl_key_tl
+ }}{}
+ %
+ \tl_if_exist_ne:NTF\knowledge_kl_link_tl{
+ \tl_set_eq:NN
+ \knowledge_kl_key_tl
+ \knowledge_kl_link_tl
+ \knowledge_kl_find:
+ }{
+ \knowledge_kl_display_code:}
+}
+\cs_generate_variant:Nn\knowledge_kl_exec:nnn{nnV}
\cs_new:Nn\knowledge_kl_use_style:n{
\knowledge_kl_find_in_scope:nnNTF
{style}
{#1}
\l_tmpa_tl
{\use:c{\knowledge_id:nVn{style}\l_tmpa_tl{#1}}}
- {\tl_show:n{ERROR-UNKNOWN-STYLE:~#1}}
+ {\knowledge_error:n{Unknown~style~`#1'}}
}
\cs_generate_variant:Nn\knowledge_kl_use_style:n {x}
-
-\cs_new:Nn\knowledge_kl_exec:N{
- #1
- \tl_set:Nn\knowledge_kl_resource_tl{#1}
- \tl_if_empty:xTF\knowledge_kl_used_style_tl
- {}
- {\knowledge_kl_use_style:x
- {\knowledge_kl_used_style_tl}}
- \tl_if_exist_ne:NTF\knowledge_kl_link_tl{
- \knowledge_kl_update:N#1
- \tl_set_eq:NN
- \knowledge_kl_key_tl
- \knowledge_kl_link_tl
- \tl_set:Nn\knowledge_kl_link_tl{}
- \knowledge_kl_find:
- }{
- \knowledge_kl_update:N#1
- \knowledge_kl_display_code:
-}}
\NewKAuxCommand\KAuxErrorKnowledgeUnknown{mmmm}
- {Package~'knowledge':~A~knowledge~is~not~defined.~
- {namespace}{scope}{undefined~knowledge}{base~knowledge}}
+ {Package~'knowledge:~A~knowledge~is~not~defined.~
+ {namespace}{scope/empty}{undefined~knowledge}{base~knowledge}}
+ {}
+\NewKAuxCommand\KAuxErrorLabelUnknown{m}
+ {Package~'knowledge:~A~label~is~not~defined.~
+ {label}}
{}
-
\DeclareKAuxPhaseCommand\KAuxErrorKnowledgeUnknown{diagnose-unknown-suggest}
- {\knowledge_diagnose:n
- {\knowledge{#3}{}}}
-
+ {\knowledge_diagnose_line:
+ \tl_if_empty:nTF{#2}
+ {\knowledge_diagnose:n{\knowledge{#3}{}}}
+ {\knowledge_diagnose:n{\knowledge{#3}{scope={#2}}}}
+ }
\cs_new:Nn\knowledge_kl_error_unknown:
{\KAuxWriteX{
\KAuxErrorKnowledgeUnknown
@@ -1766,47 +2010,64 @@
{\exp_args:NV\detokenize\knowledge_kl_key_tl}
{\exp_args:NV\detokenize\knowledge_kl_base_key_tl}
}
- \knowledge_kl_use_style:n{unknown}
- \knowledge_set_now:nnVn
- {default}{base}
- \knowledge_kl_key_tl
- {style={unknown~(cont)}}
- \msg_warning:nnxxx{ knowledge }{ knowledge~unknown }
+ \IfKnowledgePaperModeF{
+ \msg_warning:nnxxx{ knowledge }{ knowledge~unknown }
{\exp_not:V\knowledge_kl_key_tl}
{\exp_not:V\knowledge_kl_namespace_tl}
- {\seq_use:Nn\knowledge_visible_instances_seq{~|~}}
+ {\seq_use:Nn\knowledge_visible_instances_seq{~|~}}}
+ \knowledge_kl_use_style:n{unknown}
+ \knowledge_set_now:nnVn
+ {default}{base}
+ \knowledge_kl_key_tl
+ {style={unknown}}
\knowledge_kl_display_code:
}
-
-\msg_new:nnn{ knowledge }{ knowledge~unknown }
- {The~knowledge~'#1'~(namespace~'#2')~could~not~be~found~in~scopes~<~#3~>.}
-\NewKAuxCommand\KAuxErrorKnowledgeRecursive{mmmm}
- {Package~'knowledge':~A~knowledge~has~recursive~definition.~
- {namespace}{scope}{undefined~knowledge}{base~knowledge}}
- {}
-
-\msg_new:nnn{ knowledge }{ knowledge~recursion }
- { The~knowledges~are~probably~cyclic,~starting~from~'#1'~(namespace~'#2'),~
- currently~at~'#3'.}
-
-\cs_new:Nn\knowledge_kl_error_recursion: {
- \msg_error:nnxxx{ knowledge }{ knowledge~recursion }
- {\exp_not:V\knowledge_kl_base_key_tl}
- {\exp_not:V\knowledge_kl_namespace_tl}
- {\exp_not:V\knowledge_kl_key_tl}
- \knowledge_kl_error_display:n{recursive~knowledge}
+\cs_new:Nn\knowledge_kl_error_unknown_in_scope:
+ {\KAuxWriteX{
+ \KAuxErrorKnowledgeUnknown
+ {\knowledge_kl_namespace_tl}
+ {\knowledge_kl_linkscope_tl}
+ {\exp_args:NV\detokenize\knowledge_kl_key_tl}
+ {\exp_args:NV\detokenize\knowledge_kl_base_key_tl}
+ }
+ \IfKnowledgePaperModeF{
+ \msg_warning:nnxxx{ knowledge }{ knowledge~unknown~in~scope }
+ {\exp_not:V\knowledge_kl_key_tl}
+ {\exp_not:V\knowledge_kl_namespace_tl}
+ {\knowledge_kl_linkscope_tl}}
+ \knowledge_kl_use_style:n{unknown}
+ \knowledge_set_now:nnVn
+ {default}{base}
+ \knowledge_kl_key_tl
+ {style={unknown}}
+ \knowledge_kl_display_code:
+}
+\cs_new:Nn\knowledge_kl_error_label_unknown:{
+ \KAuxWriteX{
+ \KAuxErrorKnowledgeUnknown
+ {\knowledge_kl_namespace_tl}
+ {\knowledge_kl_linkscope_tl}
+ {\exp_args:NV\detokenize\knowledge_kl_key_tl}
+ {\exp_args:NV\detokenize\knowledge_kl_base_key_tl}
+ }
+ \knowledge_kl_use_style:n{unknown}
+ \IfKnowledgePaperModeF{
+ \msg_warning:nnxx{ knowledge }{ knowledge~unknown~label }
+ {\exp_not:V\knowledge_kl_key_tl}
+ {\knowledge_kl_linkscope_tl}}
+ \knowledge_kl_display_code:
}
-
\cs_new:Nn\knowledge_kl_error_display:n
{\textcolor{orange}{\exp_args:NV\detokenize\knowledge_kl_text_tl}}
\NewDocumentCommand\intro{s}{
- \cs_gset_eq:NN\knowledge_kl_init:\knowledge_intro_init:
- \IfBooleanF{#1}\kl
-}
+ \kl_activate_intro:\IfBooleanF{#1}\kl}
\NewDocumentCommand\reintro{s}{
- \cs_gset_eq:NN\knowledge_kl_init:\knowledge_reintro_init:
- \IfBooleanF{#1}\kl
-}
+ \kl_activate_reintro:\IfBooleanF{#1}\kl}
+
+\cs_new:Nn\kl_activate_intro:
+ {\cs_gset_eq:NN\knowledge_kl_init:\knowledge_intro_init:}
+\cs_new:Nn\kl_activate_reintro:
+ {\cs_gset_eq:NN\knowledge_kl_init:\knowledge_reintro_init:}
\NewDocumentCommand\phantomintro{m}{
\cs_gset_eq:NN\knowledge_kl_init:\knowledge_phantomintro_init:
\kl[{#1}]{}
@@ -1870,15 +2131,6 @@
\cs_gset:Nn\knowledge_defaultkl_update:N
{\ktuple_countuse_gincr:N#1}
\tl_set:Nn\knowledge_defaultkl_namespace_tl{default}
-\NewDocumentCommand\kl{om}{\kl_kl_inner:nn{#1}{#2}}
-\cs_new:Nn\kl_kl_inner:nn
-{\group_begin:
- \knowledge_kl_init:
- \cs_gset_eq:NN\knowledge_kl_init:\knowledge_defaultkl_init:
- \kl_base:nn{#1}{#2}
- \group_end:
- \knowledge_display_sequence:
-}
\tl_set:Nn\knowledge_variablekl_namespace_tl{variable}
\bool_new:N\kl_already_met_bool
\ktuple_new_bool_index:n{already_met_bool}
@@ -1947,6 +2199,8 @@
\NewKnowledgeParamBool*{uppercase}\kl_uppercase_bool
\NewKnowledgeParamTl*{text}\kowledge_kl_forced_text_tl
\NewKnowledgeParamTl*{link}\knowledge_kl_link_tl
+\NewKnowledgeParamTl*{link~scope}\knowledge_kl_linkscope_tl
+\NewKnowledgeParamTl*{link~instance}\knowledge_kl_linkinstance_tl
\NewKnowledgeParamTl*{wrap}\knowledge_kl_wrap_tl
\NewKnowledgeParamTl*{style}\knowledge_kl_style_tl
\NewKnowledgeParamTl*{intro~style}\knowledge_kl_intro_style_tl
@@ -1955,6 +2209,9 @@
\ktuple_countuse_expands_to:n{}
\ktuple_new_int_index:n{countintro}
\ktuple_countintro_expands_to:n{}
+\keys_define:nn{ knowledge~directives }{
+ now .code:n = { \bool_set_true:N\knowledge_knowledge_now_bool }
+}
\int_new:N\knowledge_autoref_count
\keys_define:nn{ knowledge~directives }{
@@ -1990,11 +2247,12 @@ autoref .code:n =
\int_new:N\kl_digest_autoreftwiceintro_int
\int_new:N\kl_digest_autorefunused_int
\int_new:N\kl_digest_unknownknowledge_int
+\int_new:N\kl_digest_unknownlabel_int
-\DeclareKAuxPhaseCommand\KAuxErrorKnowledgeUnknown{diagnose~digest}
+\DeclareKAuxPhaseCommand\KAuxErrorKnowledgeUnknown{diagnose-digest}
{\int_gincr:N\kl_digest_unknownknowledge_int}
-\DeclareKAuxPhaseCommand\KAuxAutoref{diagnose~digest}
+\DeclareKAuxPhaseCommand\KAuxAutoref{diagnose-digest}
{\group_begin:
\knowledge_sets_to:nnn{#1}{#2}{#3}
\knowledge_at:N\ktuple_countuse_get_int:NN\kl_countuse_int
@@ -2009,23 +2267,28 @@ autoref .code:n =
{\int_gincr:N\kl_digest_autoreftwiceintro_int}
\group_end:}
-\DeclareKAuxPhaseCommand\KAuxAutoref{autoref~not~introduced}
+\DeclareKAuxPhaseCommand\KAuxAutoref{autoref-not-introduced}
{\group_begin:
\knowledge_sets_to:nnn{#1}{#2}{#3}
\knowledge_at:N\ktuple_countuse_get_int:NN\kl_countuse_int
\knowledge_at:N\ktuple_countintro_get_int:NN\kl_countintro_int
\int_compare:nNnT\kl_countuse_int>0
{\int_compare:nNnT\kl_countintro_int=0
- {\knowledge_diagnose:n{\nointro{#1}{#2}{#3}}}}
+ {\knowledge_diagnose_line:
+ \knowledge_diagnose:n{\nointro{#1}{#2}{#3}}}}
\group_end:}
-\DeclareKAuxPhaseCommand\KAuxAutoref{autoref~introduced~twice}
+\DeclareKAuxPhaseCommand\KAuxAutoref{autoref-introduced-twice}
{\group_begin:
\knowledge_sets_to:nnn{#1}{#2}{#3}
\knowledge_at:N\ktuple_countuse_get_int:NN\kl_countuse_int
\knowledge_at:N\ktuple_countintro_get_int:NN\kl_countintro_int
\int_compare:nNnT\kl_countintro_int>1
- {\knowledge_diagnose:n{{#1}{#2}{#3}}}
+ {\knowledge_diagnose_line:
+ \knowledge_diagnose:n{{#1}{#2}{#3}}}
\group_end:}
+\NewKAuxCommand\KAuxUseKnowledge{mmm}
+ {Package~knowledge:~Identifies~the~use~of~some~knowledge.~
+ Arguments~{namespace}{instance}{knowledge}.}
\cs_new:Nn\knowledge_kl_display_sequence:n
{\knowledge_kl_display_sequence:w#1\display_end:}
\cs_new:Npn\knowledge_kl_display_sequence:w#1#2\display_end:
@@ -2065,13 +2328,10 @@ autoref .code:n =
\knowledge_defaultkl_display_code_text:}}
}
\cs_new:Nn\knowledge_kl_display_code_index:n{#1}
-
\cs_new:Nn\knowledge_defaultkl_display_code_fbox:n
{\bool_if:NTF\kl_fbox_bool{\exp_not:N\fbox{#1}}{#1}}
-
\cs_new:Npn\knowledge_kl_display_code_preprocess:
{}
-
\cs_new:Nn\knowledge_defaultkl_display_code_ensuremath:n
{\bool_if:NTF\kl_ensuremath_bool{\exp_not:N\ensuremath}\use:n{#1}}
\cs_new:Nn\knowledge_defaultkl_display_code_ensuretext:n
@@ -2152,7 +2412,6 @@ autoref .code:n =
\cs_new:Nn\knowledge_defaultkl_code_wrap:n{
\tl_if_exist:NTF\knowledge_kl_wrap_tl
{\exp_not:V\knowledge_kl_wrap_tl{#1}}{#1}}
-
\cs_new:Nn\knowledge_defaultkl_display_code_text:{
\knowledge_defaultkl_code_wrap:n{
\tl_if_exist:NTF\kowledge_kl_forced_text_tl
@@ -2214,6 +2473,30 @@ autoref .code:n =
\hbox_overlap_left:n
{\knowledge_AP_mark:\hspace{1em}}
}
+\cs_new:Nn\knowledge_kl_TKS:nnn{
+ \group_begin:
+ \knowledge_warning:n{#1/#2/#3}
+ \knowledge_kl_init:
+ \cs_gset_eq:NN\knowledge_kl_init:\knowledge_defaultkl_init:
+
+ \scopept_label_instance_if_exist:nTF{#3}
+ { \exp_args:Nx\knowledge_lpush_visible_instance:n
+ {\scopept_label_instance_use:n{#3}}
+ \kl_base:nn{#2}{#1}
+ }
+ { \tl_set:Nn\knowledge_kl_text_tl{#1}
+ \knowledge_kl_error_label_unknown:
+ \knowledge_warning:n
+ {Unknown~label~in~scope=`#3'.~Possibly~rerun~latex.}
+ }
+ \group_end:
+ \exp_args:No\knowledge_warning:n\knowledge_display_sequence:
+\knowledge_warning:n{before}
+ \knowledge_display_sequence:
+\knowledge_warning:n{after}
+ %\tl_show:n{\fskljkqlffk}
+}
+\NewDocumentCommand\klInnerTKSnnn{}\knowledge_kl_TKS:nnn
\ExplSyntaxOff
\def\makequotationactive
{\catcode`"13\relax}
@@ -2221,6 +2504,7 @@ autoref .code:n =
{\catcode`"12\relax}
\let\quotationmark"
+
\ExplSyntaxOn
\makequotationactive
\edef\klactivequotationmark#1"{
@@ -2228,15 +2512,15 @@ autoref .code:n =
{\noexpand\klactivedoublequotationmark}
{\noexpand\klquotation_parse_arobas_sep:Nw
\noexpand\klquotation_expand:nnn #1
- @\klparse_novalue_tl
- @\klparse_novalue_tl
+ @
+ @
@\noexpand\kl_end}
}
\edef\klactivedoublequotationmark#1""{
\noexpand\klquotation_parse_arobas_sep:Nw
\noexpand\kldoublequotation_expand:nnn #1
- @\klparse_novalue_tl
- @\klparse_novalue_tl
+ @
+ @
@\noexpand\kl_end
}
\cs_new:Npx\klquotation_parse_arobas_sep:Nw #1#2@#3@#4@#5\kl_end
@@ -2244,10 +2528,14 @@ autoref .code:n =
\cs_set_eq:NN\tl_if_novalue:nTF\IfNoValueTF
-\cs_new:Nn\kldoublequotation_expand:nnn
- {\tl_if_novalue:nTF{#2}{\intro{#1}}{\intro[{#2}]{#1}}}
-\cs_new:Nn\klquotation_expand:nnn
- {\tl_if_novalue:nTF{#2}{\kl{#1}}{\kl[{#2}]{#1}}}
+\cs_new:Npn\kldoublequotation_expand:nnn
+ {\kl_activate_intro:\klquotation_expand:nnn}
+
+\cs_new:Nn\klquotation_expand:nnn{
+ \tl_if_empty:nTF{#2}
+ {\klTKS{#1}{#1}{#3}}
+ {\klTKS{#1}{#2}{#3}}
+}
\def\klactivatequotation
{\makequotationactive
@@ -2256,6 +2544,7 @@ autoref .code:n =
{\makequotationletter}
\kldeactivatequotation
+
\cs_new:Nn\kl_protect_environment_quotation:n
{\clist_map_inline:nn{#1}
{\scope_area_set:nn{#1}
@@ -2371,34 +2660,6 @@ autoref .code:n =
\NewKnowledgeParamTl*{index~style}\kl_index_style_tl
\NewKnowledgeParamTl*{index~parent~key}\kl_index_parent_tl
\NewKnowledgeParamTl*{index~key}\kl_index_key_tl
-\cs_gset_eq:NN\knowledge_kl_init:\knowledge_defaultkl_init:
-\tl_gset_eq:NN \knowledge_kl_namespace_tl\knowledge_defaultkl_namespace_tl
-\cs_gset_eq:NN\knowledge_kl_display_code:\knowledge_defaultkl_display_code:
-\cs_gset_eq:NN\knowledge_kl_update:N\knowledge_defaultkl_update:N
-\tl_gset:Nn\knowledge_kl_command_tl{\kl}
-\newcommand\robustdisplay[1]
- {\expandafter\tl_trim_spaces:n\expandafter{\detokenize{#1}}}
-\newcommand\robustdisplaybracket[1]
- {[\robustdisplay{#1}]}
-\cs_set_eq:NN\knowledge_error_display:n\use:n
-
-\bool_if:NTF\knowledge_xcolor_active_bool{
- \knowledgestyle{intro}{emphasize}
- \knowledgestyle{unknown}{wrap=\knowledge_error_display:n,color=red}
- \knowledgestyle{unknown~(cont)}{wrap=\knowledge_error_display:n,color=gray}
- \knowledgestyle{autoref~not~introduced}{wrap=\knowledge_error_display,color=orange}
- \knowledgestyle{autoref~not~introduced~(cont)}{wrap=\knowledge_error_display:n,color=gray}
- \knowledgestyle{autoref~reintroduced}{wrap=\knowledge_error_display:n,color=red}
- \knowledgestyle{autoref~reintroduced~(cont)}{wrap=\knowledge_error_display:n,color=red}
-}{
- \knowledgestyle{intro}{emphasize}
- \knowledgestyle{unknown}{wrap=\knowledge_error_display:n}
- \knowledgestyle{unknown~(cont)}{wrap=\knowledge_error_display:n}
- \knowledgestyle{autoref~not~introduced}{wrap=\knowledge_error_display:n}
- \knowledgestyle{autoref~not~introduced~(cont)}{wrap=\knowledge_error_display:n}
- \knowledgestyle{autoref~reintroduced}{wrap=\knowledge_error_display:n}
- \knowledgestyle{autoref~reintroduced~(cont)}{wrap=\knowledge_error_display:n}
-}
\ExplSyntaxOff\makeatletter
\newcommand\knowledgeFixHyperrefTwocolumn{
\RequirePackage{etoolbox}
@@ -2450,6 +2711,8 @@ autoref .code:n =
\DeclareExpandableDocumentCommand\IfKnowledgePaperModeTF{}
{\bool_if:NTF\knowledge_option_paper_bool}
+\DeclareExpandableDocumentCommand\IfKnowledgePaperModeF{}
+ {\IfKnowledgePaperModeTF{}}
\newif\ifKnowledgePaperMode
\IfKnowledgePaperModeTF
\KnowledgePaperModetrue
@@ -2461,67 +2724,78 @@ autoref .code:n =
\IfXcolorTF
\Xcolortrue
\Xcolorfalse
+\cs_gset_eq:NN\knowledge_kl_init:\knowledge_defaultkl_init:
+\tl_gset_eq:NN\knowledge_kl_namespace_tl\knowledge_defaultkl_namespace_tl
+\cs_gset_eq:NN\knowledge_kl_display_code:\knowledge_defaultkl_display_code:
+\cs_gset_eq:NN\knowledge_kl_update:N\knowledge_defaultkl_update:N
+\tl_gset:Nn\knowledge_kl_command_tl{\kl}
+\newcommand\robustdisplay[1]
+ {\expandafter\tl_trim_spaces:n\expandafter{\detokenize{#1}}}
+\newcommand\robustdisplaybracket[1]
+ {[\robustdisplay{#1}]}
+
+\IfKnowledgePaperModeTF{
+ \knowledgestyle{intro}{emphasize}
+ \knowledgestyle{unknown}{}
+ \knowledgestyle{intro unknown}{emphasize}
+}{}
+
+\IfKnowledgeCompositionModeTF{
+ \IfXcolorTF{
+ \knowledgestyle{intro}{emphasize}
+ \knowledgestyle{unknown}{color=brown}
+ \knowledgestyle{intro unknown}{emphasize,color=red}
+ }{
+ \knowledgestyle{intro}{emphasize}
+ \knowledgestyle{unknown}{underline}
+ \knowledgestyle{intro unknown}{emphasize,underline}}
+}{}
+
+\IfKnowledgeElectronicModeTF{
+ \IfXcolorTF{
+ \knowledgestyle{intro}{emphasize}
+ \knowledgestyle{unknown}{color=brown}
+ \knowledgestyle{intro unknown}{emphasize,color=red}
+ }{
+ \knowledgestyle{intro}{emphasize}
+ \knowledgestyle{unknown}{underline}
+ \knowledgestyle{intro unknown}{emphasize,underline}}
+}{}
+
\ExplSyntaxOff
-\newrobustcmd\KnowledgeConfigureNotion[1][blue]{
- \knowledgedirective{notion}
- {autoref,style=notion,intro style=intro notion}
+\newrobustcmd\KnowledgeConfigureNotion[2][blue]{
+ \knowledgedirective{#2}{autoref,style=#2,intro style=intro #2}
\ifKnowledgePaperMode
- \knowledgestyle{notion}{}
- \knowledgestyle{intro notion}{emphasize}
- \knowledgestyle{unknown}{}
- \knowledgestyle{unknown (cont)}{}
+ % paper mode
+ \knowledgestyle{#2}{}
+ \knowledgestyle{intro #2}{emphasize}
\fi
\ifKnowledgeCompositionMode
\ifXcolor
- \knowledgestyle{notion}{color={#1!70!black}}
- \knowledgestyle{intro notion}{emphasize,color={#1}}
- \knowledgestyle{unknown}{color=brown}
- \knowledgestyle{unknown (cont)}{color=brown}
+ % composition mode with colors
+ \knowledgestyle{#2}{color={#1!70!black}}
+ \knowledgestyle{intro #2}{emphasize,color={#1}}
\else
- \knowledgestyle{notion}{underline}
- \knowledgestyle{intro notion}{emphasize, underline}
- \knowledgestyle{unknown}{}
- \knowledgestyle{unknown (cont)}{}
+ % composition mode, no colors (use underline)
+ \knowledgestyle{#2}{underline}
+ \knowledgestyle{intro #2}{emphasize, underline}
\fi
\fi
\ifKnowledgeElectronicMode
\ifXcolor
- \definecolor{klDarkBlue}{rgb}{0,0,0.7}
- \knowledgestyle{notion}{color={#1!70!black}}
- \knowledgestyle{intro notion}{emphasize,color={#1}}
- \knowledgestyle{unknown}{}
- \knowledgestyle{unknown (cont)}{}
+ % electronic mode
+ \knowledgestyle{#2}{color={#1!70!black}}
+ \knowledgestyle{intro #2}{emphasize,color={#1}}
\else
- \knowledgestyle{notion}{underline}
- \knowledgestyle{intro notion}{emphasize, underline}
- \knowledgestyle{unknown}{}
- \knowledgestyle{unknown (cont)}{}
- \fi
+ % electronic mode, no colors (use underline)
+ \knowledgestyle{#2}{underline}
+ \knowledgestyle{intro #2}{emphasize, underline}
+ \fi
\fi
}
\ExplSyntaxOn
-\exp_args:NNV\ExplSyntaxOff\knowledgeconfigure\knowledge_configuration_pending_tl
-\ScopeActivate
-\ExplSyntaxOn
\knowledge_begin_module_if:N\knowledge_option_scope_bool
-\scope_area_set:nn{base}
-{
- occurrences = once,
- autoclose = false
-}
-\scope_area_set:nn{document}
-{
- autoclose = false,
- occurrences = once,
- parents = base
-}
-\scope_area_set:nn{body}
-{
- autoclose = true,
- occurrences = once,
- parents = document,
- }
\scope_area_set:nn
{part, section,subsection,subsubsection,
paragraph,subparagraph,subsubparagraph}
@@ -2573,36 +2847,28 @@ autoref .code:n =
\OverloadCommand\subsubparagraph{som}
{\scope_area_push:n{subsubparagraph}
\XparseArgs\SUPERsubsubparagraph{som}{#1}{#2}{#3}}
-\cs_new:Nn\scope_area_environment_new:nn
- {\scope_area_set:nn{#1}{
- parents = all,
- autoclose = false,
- occurrences = multiple,
- knowledge = attracts,
- #2
- }}
-
+\KnowledgeConfigureEnvironment?
+ {theorem,lemma,proposition,fact,conjecture,problem}
+ {category=theorem-like,label=accepts}
+\KnowledgeConfigureEnvironment?
+ {remark,proof}
+ {label=accepts,knowledge=accepts}
+\KnowledgeConfigureEnvironment?
+ {center,flushleft,flushright,minipage,quotation,quote,verbatim,verse}
+ {knowledge=accepts,label=none}
\OverloadCommand\newtheorem{m}
- {\scope_area_environment_new:nn
- {#1}
- {category=theorem-like}
+ {\KnowledgeConfigureEnvironment!{#1}{category=theorem-like,label=accepts}
\SUPERnewtheorem{#1}}
-
\OverloadCommand\newenvironment{m}
- {\scope_area_environment_new:nn
- {#1}
- {category=environment}
+ {\KnowledgeConfigureEnvironment!{#1}{label=accepts}
\SUPERnewenvironment{#1}}
\OverloadCommand\NewDocumentEnvironment{m}
- {\scope_area_environment_new:nn
- {#1}
- {category=environment}
+ {\KnowledgeConfigureEnvironment!{#1}{label=none}
\SUPERNewDocumentEnvironment{#1}}
\scope_area_set:nn
{itemize,enumerate,description}
{category=itemize-like}
-
\scope_area_set:nn{item}
{autoclose=true,
parents = itemize-like}
@@ -2621,7 +2887,12 @@ autoref .code:n =
forces = body
}
\knowledge_end_module:
-\ExplSyntaxOff
+
+%%%%%%%%%%
+\ExplSyntaxOn
+\exp_args:NNV\ExplSyntaxOff\knowledgeconfigure\knowledge_configuration_pending_tl
+\ScopeActivate
+
\endinput
%%
%% End of file `knowledge.sty'.