texlive[45560] Master/texmf-dist: knowledge (19oct17)
commits+karl at tug.org
commits+karl at tug.org
Thu Oct 19 23:29:32 CEST 2017
Revision: 45560
http://tug.org/svn/texlive?view=revision&revision=45560
Author: karl
Date: 2017-10-19 23:29:32 +0200 (Thu, 19 Oct 2017)
Log Message:
-----------
knowledge (19oct17)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/latex/knowledge/knowledge.pdf
trunk/Master/texmf-dist/doc/latex/knowledge/makefile
trunk/Master/texmf-dist/tex/latex/knowledge/knowledge.sty
Added Paths:
-----------
trunk/Master/texmf-dist/doc/latex/knowledge/README.md
trunk/Master/texmf-dist/doc/latex/knowledge/knowledge.tex
trunk/Master/texmf-dist/source/latex/knowledge/knowledge-code.dtx
trunk/Master/texmf-dist/source/latex/knowledge/knowledge.ins
Removed Paths:
-------------
trunk/Master/texmf-dist/doc/latex/knowledge/README.txt
trunk/Master/texmf-dist/source/latex/knowledge/all.ins
trunk/Master/texmf-dist/source/latex/knowledge/knowledge.dtx
Added: trunk/Master/texmf-dist/doc/latex/knowledge/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/knowledge/README.md (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/knowledge/README.md 2017-10-19 21:29:32 UTC (rev 45560)
@@ -0,0 +1,47 @@
+%%%%%%%%
+This directory contains the package
+
+ name: knowledge
+ license: LaTeX Project Public License version 1.2 or above
+ version: v1.08
+ date: 2017/10/17
+ author: Thomas Colcombet
+ mail: thomas.colcombet at irif.fr
+ web: https://www.irif.fr/~colcombe/knowledge_en.html
+
+Purpose:
+ The knowledge package for LaTeX offers a systematic way to handle
+ notions/concepts/terms throughout a document. In combination with
+ hyperref, it is used for easily handling links inside a document (every
+ use of a concept is linked to its introduction), or outside the document
+ (for centralizing the url's in a separate part). It also helps building an
+ index, and deals with scoping of concepts as well as mathematics.
+ It is designed to--as much as possible--not interfere with the writing of
+ the document.
+
+Install:
+ It is sufficient to have the file knowledge.sty accessible by LaTeX.
+ It can be produced by `make knowledge.sty' if necessary.
+ The documentation is in the file knowledge.pdf.
+ A starting example can be found in knowledge-example.tex.
+
+Content of the file knowledge-sources.zip:
+ - README.md: this file generated while compiling knowledge.ins,
+ the content is in knowledge-code.dtx
+ - knowledge.sty: the package file (generated using knowledge.ins)
+ - knowledge.pdf: the user documentation (generated by compiling
+ knowledge.tex)
+ - knowledge.tex: the tex file producing the knowledge.pdf.
+ - makefile: the makefile. Use 'make all' to generate knowledge.sty
+ and knowledge.pdf. It can also: clean the directory, make zip
+ version of the sources, or ready for CTAN.
+ - knowledge.ins: is the file generating knowledge.sty and
+ README.md from knowledge-code.dtx (using docstrip).
+ - knowledge-code.dtx: most of the code. Can be compiled to
+ provided a longer documentation.
+ - knowledge-configuration.dtx: file containing part of the configuration.
+ - knowledge-utils.dtx: file containing several pieces of code not really
+ related specifically to knowledge
+ - knowledge-example.tex: an example file.
+
+
Property changes on: trunk/Master/texmf-dist/doc/latex/knowledge/README.md
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Deleted: trunk/Master/texmf-dist/doc/latex/knowledge/README.txt
===================================================================
--- trunk/Master/texmf-dist/doc/latex/knowledge/README.txt 2017-10-19 21:28:59 UTC (rev 45559)
+++ trunk/Master/texmf-dist/doc/latex/knowledge/README.txt 2017-10-19 21:29:32 UTC (rev 45560)
@@ -1,38 +0,0 @@
-This directory contains the package
-
- name: knowledge.sty
- version: v1.07
- date: 2017/10/13
- license: LaTeX Project Public License version 1.2 or above
-
- author: Thomas Colcombet
- mail: thomas.colcombet at irif.fr
- web: https://www.irif.fr/~colcombe/knowledge_en.html
-
-
- Purpose:
- The knowledge package for LaTeX offers a systematic way to handle
- notions/concepts/terms throughout a document. It helps building an
- index. In combination with hyperref it makes it easy to have every
- references of a concept linked to its introduction. It also offers
- simple notations.
-
-
-Content of the file knowledge-sources.zip:
- - README.txt: this file, generated while compiling knowledge.dtx
- - 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. It also produces README.txt)
- - all.ins: file generating knowledge.sty when compiled (docstrip)
- - knowledge-configuration.dtx: file containing part of the configuration
- - knowledge-utils.dtx: file containing several pieces of code not really
- related specifically to knowledge
- - knowledge-example.tex: an example file
-
- Note: this file is created when compiling knowledge.dtx
-
Modified: trunk/Master/texmf-dist/doc/latex/knowledge/knowledge.pdf
===================================================================
(Binary files differ)
Added: trunk/Master/texmf-dist/doc/latex/knowledge/knowledge.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/knowledge/knowledge.tex (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/knowledge/knowledge.tex 2017-10-19 21:29:32 UTC (rev 45560)
@@ -0,0 +1,2434 @@
+\documentclass{ltxdoc}
+\usepackage[utf8]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{paralist}
+\usepackage[svgnames]{xcolor}
+\usepackage{expl3}
+\usepackage[hyperref,quotation,scope]{knowledge}
+\knowledgeconfigure{visible anchor points=false}
+\knowledgeconfigure{notion,diagnose line=false}
+\GetFileInfo{knowledge.sty}
+\edef\knowledgeversiondate{\fileversion--\filedate}
+
+% Depending on whether the file is included from knowledge-code.dtx
+% or not, some configuration changes.
+% This involves mainly the presence of the code.
+% It also triggers the apparition of the todo list, and a top bar allowing
+% faster navigation in the document.
+\ExplSyntaxOn
+\ifdefined\knowledgecode\expandafter\use_i:nn\else\expandafter\use_ii:nn\fi
+ {\def\producecode{\newpage\DocInput{knowledge-code.dtx}}
+ \cs_new_eq:cN{ifcodeTF}\use_i:nn}
+ {\def\producecode{}
+ \cs_new_eq:cN{ifcodeTF}\use_ii:nn}
+\ExplSyntaxOff
+% End of the parametrization.
+
+
+\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
+
+
+\NewDocumentCommand\ToImprove{m}{\marginpar{\textcolor{red}{To improve:} #1}}
+
+
+\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
+\knowledgedirective{kenvironment}{autoref,style=cs,intro style=csintro}
+
+
+
+% 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}
+
+
+
+\knowledgedirective{doc notion}
+ {autoref,style=doc notion,intro style=intro doc notion}
+\knowledgestyle{doc notion}{color=DarkBlue}
+\knowledgestyle{intro doc notion}{color=blue,emphasize}
+
+\let\cs\undefined
+\knowledgenewvariant\cs
+ {namespace=cs,
+ default style={autoref link,cs},
+ unknown style=cs unknown,
+ unknown style cont=cs unknown,
+ unknown warning=f alse,
+ unknown diagnose=true,
+ suggestion=cs,
+ PDF string={\detokenize{#1}}}
+\knowledgestyle{cs}{wrap=\Robustdisplay,typewriter,up,md,color=NavyBlue}
+\knowledgestyle{cs unknown}{wrap=\Robustdisplay,typewriter,up,md,color=black}
+
+\knowledgenewvariant\csintro
+ {namespace=cs,
+ auto knowledge={autoref,scope=document,also now},
+ default style={autoref target,csintro},
+ unknown style=csintro unknown,
+ unknown style cont=csintro unknown,
+ unknown warning=false,
+ unknown diagnose=false,
+ PDF string = {\detokenize{#1}}}
+\knowledgestyle{csintro}{wrap=\Robustdisplay,typewriter,up,md,color=blue}
+\knowledgestyle{csintro unknown}{wrap=\Robustdisplay,typewriter,up,md,color=black}
+
+\knowledgenewvariant\csreintro
+ {namespace=cs,
+ default style=csintro,
+ unknown style=csintro unknown,
+ unknown style cont=csintro unknown,
+ PDF string = {\Robustdisplay{#1}}}
+
+
+
+\knowledge{@token}{wrap=\Robustdisplay,up,md,typewriter,color=NavyBlue}
+
+
+
+\knowledge{_monoid}{style=kl unknown}
+\knowledge{_semigroup}{style=kl unknown}
+
+
+
+% style names
+\knowledgedirective{notion style}{autoref,style=style,intro style=intro style}
+\knowledgestyle{style}{typewriter,up,md,color=NavyBlue}
+\knowledgestyle{intro style}{typewriter,up,md,color=blue}
+
+\begin{scope}\label{style}
+ \knowledge{notion}{notion style}
+ \knowledge{intro notion}{notion style}
+
+ \knowledge{kl}{notion style}
+ \knowledge{kl unknown}{notion style}
+ \knowledge{kl unknown cont}{notion style}
+
+ \knowledge{intro}{notion style}
+ \knowledge{intro unknown}{notion style}
+ \knowledge{intro unknown cont}{notion style}
+ \knowledge{autoref not introduced}{notion style}
+ \knowledge{autoref reintroduced}{notion style}
+\end{scope}
+
+
+\knowledgedirective{kvariable}{style=cs}
+\knowledge {experimental}{doc notion,color=gray}
+
+
+\ExplSyntaxOn
+\NewDocumentCommand\robustdisplaycs{m}
+ {\expandafter\robustdisplay\csname#1\endcsname}
+
+
+
+
+\knowledgeconfigure{quotation=false}
+\knowledge"{text=\quotesymbol}
+\knowledge{""}{text=\quotesymbol\quotesymbol}
+\knowledgeconfigure{quotation=true}
+
+\knowledge{AucTex}{typewriter}
+\knowledge{Emacs}[emacs|EMACS]{typewriter}
+
+\makeatletter
+\let\arobas @
+\makeatother
+
+\knowledgestyle{tt}{typewriter,up,md,color=NavyBlue}
+\knowledgestyle{tt intro}{typewriter,up,md,color=blue}
+\knowledgedirective{kcommand}{style=tt,intro style=tt intro,autoref}
+
+\knowledgedirective{kquotation}{style=tt,intro style=tt intro,autoref}
+\knowledge{"..."}{kquotation,text=\kl"$\cdots$\kl{"}}
+\knowledge{""...""}{kquotation,text=\kl{""}$\cdots$\kl{""}}
+\knowledge{"... at ..."}{kquotation,text=\kl{"}$\cdots\arobas\cdots$\kl{"}}
+\knowledge{""... at ...""}{kquotation,text=\kl{""}$\cdots\arobas\cdots$\kl{""}}
+\knowledge{"...@@..."}{kquotation,text=\kl{"}$\cdots\arobas\cdots\arobas\cdots$\kl{"}}
+\knowledge{""...@@...""}{kquotation,text=\kl{""}$\cdots\arobas\cdots\arobas\cdots$\kl{""}}
+\knowledge{"... at ...@..."}{kquotation,text=\kl{"}$\cdots\arobas\cdots\arobas\cdots$\kl{"}}
+\knowledge{""... at ...@...""}{kquotation,text=\kl{""}$\cdots\arobas\cdots\arobas\cdots$\kl{""}}
+\knowledge{@}{kcommand,text=\arobas}
+
+
+
+\knowledge{tex}{text=\TeX}
+
+\knowledgedirective{people}{emphasize,color=DarkGray}
+\knowledge{stackexchange}{people}
+\knowledge{egreg}{people}
+
+\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}
+
+
+\ExplSyntaxOff
+
+\begin{scope}\label{area}
+ \knowledge{nesting_int}{directive}
+ \knowledge{count_int}{directive}
+ \knowledge{name_tl}{directive}
+ \knowledge{pushcode_tl}{directive}
+ \knowledge{popcode_tl}{directive}
+ \knowledge{autoclose_bool}{directive}
+ \knowledge{environment_bool}{directive}
+ \knowledge{recursive_bool}{directive}
+ \knowledge{multiple_bool}{directive}
+ \knowledge{forces_tl}{directive}
+ \knowledge{acceptsknowledge_bool}{directive}
+ \knowledge{attractsknowledge_bool}{directive}
+ \knowledge{labelizable_bool}{directive}
+ \knowledge{scope_bool}{directive}
+ \knowledge{mandatorybase_seq}{directive}
+
+ \knowledge{autoclose=}{directive}
+ \knowledge{environment=}{directive}
+ \knowledge{parents=}{directive}
+ \knowledge{scope=}{directive}
+ \knowledge{label=}{directive}
+ \knowledge{push code=}{directive}
+ \knowledge{pop code=}{directive}
+ \knowledge{occurrences=}{directive}
+ \knowledge{forces=}{directive}
+\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{up}{directive}
+\knowledge{md}{directive}
+\knowledge{boldface}{directive}
+\knowledge{fbox}{directive}
+\knowledge{typewriter}{directive}
+\knowledge{ensuretext}{directive}
+\knowledge{ensuremath}{directive}
+\knowledge{italic}[italic=]{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{cyclic color}{directive}
+\knowledge{colorbox=}{directive}
+\knowledge{ref=}{directive}
+\knowledge{url=}{directive}
+\knowledge{autoref}{directive}
+\knowledge{autorefhere}{directive}
+\knowledge{namespace=}{directive}
+\knowledge{autoref link}{directive}
+\knowledge{autoref target}{directive}
+\knowledge{also now}{directive}
+\knowledge{notion}{directive}
+\knowledge{invisible=}[invisible]{directive}
+\knowledge{detokenize}{directive}
+\knowledge{remove space}{directive}
+
+\begin{scope}\label{option}
+ \knowledge{hyperref}{option}
+ \knowledge{xcolor}{option}
+ \knowledge{makeidx}{option}
+ \knowledge{scope}{option}
+ \knowledge{quotation}[quotation=]{option}
+ \knowledge{notion}{option}
+ \knowledge{cyclic colors=}{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}
+\knowledge{CTAN}{color=darkgray,url={https://www.ctan.org/}}
+\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{variant directives}[variant directive|Variant directives]{doc notion}
+\begin{scope}\label{variant}
+ \knowledge{directive}[directives|Directives]{link=variant directive}
+ \knowledge {namespace=}{directive}
+ \knowledge {default style=}{directive}
+ \knowledge {unknown style=}{directive}
+ \knowledge {unknown style cont=}{directive}
+ \knowledge {style directive=}{directive}
+ \knowledge {auto knowledge=}{directive}
+ \knowledge {unknown warning=}{directive}
+ \knowledge {unknown diagnose=}{directive}
+ \knowledge {suggestion=}{directive}
+ \knowledge {PDF string=}{directive}
+ \knowledge {starred sequence}{doc notion}
+ \knowledge {modifier}[modifiers|Modifiers]{doc notion}
+\end{scope}
+
+\knowledge{align*}{typewriter}
+
+%\knowledgedefault{index}
+\knowledgedefault{}
+
+\knowledge{label}{}
+
+\knowledge{variant of \cs{\kl}}[variants of \cs{\kl}|Variants of \cs{\kl}]{doc notion}
+\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}
+
+\knowledge{latex}{text=\LaTeX}
+\knowledge{tex}{}
+\knowledge{pdflatex}{}
+
+\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}}}
+
+
+\ExplSyntaxOn
+\group_begin:
+ \catcode`| = 11%
+ \global\def\vbar{|}
+\group_end:
+\ExplSyntaxOff
+
+
+
+
+
+
+
+
+
+
+\begin{document}
+\label{paper:top}
+\title{The \texttt{knowledge} package\\%
+ \small[\fileversion{} --- \filedate]}
+\author{Thomas Colcombet \\ \texttt{thomas.colcombet at irif.fr}}
+\maketitle
+
+\begin{abstract}\phantomintro(package){knowledge}%
+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}
+
+\ifcodeTF{\begin{quote}This version of the documentation includes a good part of the code. A casual user should \textit{a priori} not use this version of the documentation.\end{quote}}{}
+
+\section*{Status of this version}
+\label{section:status}
+\begin{quote}
+\begin{tabular}{ll}
+\texttt{contact:}&\texttt{thomas.colcombet at irif.fr}\\
+\texttt{version:}&\texttt{\fileversion}\\
+\texttt{date:}&\texttt{\filedate}
+(documentation 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.
+\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 make quoatation work properly in the titles of section...,
+\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 \csintro{\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 \cs{\nointro}.
+\item Solve the problem of \cs{\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 \cs{\AP} and \cs{\itemAP} commands. For the moment \cs{\AP} silently fails inside the
+ optional argument of \cs{\item}, and probably elsewhere too. See how this can be improved.
+\item solve the \kl(package){amsmath} problem that \cs{\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 \cs{\knowledgedirective}.
+\item[2017-01-13] \cs{\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 \cs{\begin} command.
+\item[2017-01-14] The overloading of \cs{\begin} and \cs{\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
+\cs{\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 \cs{\usepackage}) from the configuration options (see \cs{\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 \cs{\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 \cs{\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 \cs{\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 \cs{\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{"... at ..."} and \kl{""... at ...""} 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 \cs{\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{\cs\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 \cs{\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 \cs{environment_bool} 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 \cs{\kl} and \cs{\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-08-06] Now passes the compliance test \texttt{check-declarations} of "expl3@@package"
+ (thanks to Marc Zeitoun)
+\item[2017-09-12] The "hidelinks" option of "hyperref@@package" is now always activated.
+\item[2017-09-25] Ancient version of "xparse@@package" does not have \cs{\NewExpandableDocumentCommand}. Corrected.
+\item[2017-09-26] Version 1.05 on "CTAN".
+\item[2017-10-10] Bug in the implementation of \cs{\knowledgenewvariant} (that was invisible for older versions of "expl3@@package"). Found and corrected (thanks to Marc Zeitoun).
+\item[2017-10-10] Version 1.06 on "CTAN".
+\item[2017-10-15] Diagnose extended (suggested by Fabian Reiter). Minor corrections. Version 1.07 on "CTAN".
+\item[2017-10-17] Added "cyclic color" and "cyclic colors=@@option". Reorganization of the structure of the code for producing a better "CTAN" archive. Version 1.08 on "CTAN".
+\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 may be 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 at 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]
+\cs{\usepackage}["hyperref@@package",\kl(option){quotation}]\{"knowledge@@package"\}
+\end{code}
+\noindent or:
+\begin{code}[8cm]
+\cs\usepackage\{\kl(package){hyperref}\}\\
+\cs\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}
+\cs\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 \cs{\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 \cs{\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 \cs\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 \cs{\knowledge} command using
+extra "directives":
+\begin{code}[10.9cm]
+\cs\knowledge\{latex\}\{\kl{url=}https://en.wikipedia.org/wiki/LaTeX,\\
+\qquad\kl{text=}\cs\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 at 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 it is not explicitly named in the text. There are two ways to resolve this issue. The first is to use the syntax
+\begin{center}
+\smallcode{\cs\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\cs{\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]
+ \cs{\knowledge}\{D. Knuth\}\\~~~~\{\kl{link=}Knuth\}
+ \end{code}\noindent then \smallcode{\cs\kl\{D. Knuth\}}
+ would also point to the same url.
+ \begin{code}[4.3cm]
+ \cs{\knowledge}\{D. Knuth\}\\~~~~\{\kl{synonym}\}
+ \end{code}\noindent would also work if used just after the definition
+ of \texttt{Knuth}.\\
+ \end{hint}}
+%
+\begin{code}
+\cs{\knowledge}\{latex\}[LaTeX\vbar Latex\vbar LATEX]\\
+ \{\kl{url=}http://en.wikipedia.org/wiki/LaTeX,~\kl{text=}\cs{\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]
+ \cs\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{\cs\kl\{Knuth\}}~~~as well as~~~\smallcode{\cs\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]
+% \cs\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]
+\cs\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]
+\cs\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 \cs{\intro} (or \kl{""}$\cdots$\kl{""} if \kl(option){quotation} is activated) when a notion is defined/introduced, and
+\marginpar{\begin{hint} Using an \cs{\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}}
+\cs{\kl} (or \kl{"}$\cdots$\kl{"} if \kl(option){quotation} is activated) when it is used. For instance:
+\begin{code}[12cm]
+\cs\AP{}
+A \cs\intro\{semigroup\} is an ordered pair \verb|$(S,\cdot)$| where \verb|$\cdot$| is an
+associative binary operator over~\verb|$S$|.\\
+\kl{[...]}\\
+\cs{\AP}
+A \cs\intro\{monoid\} \verb|$(M,\cdot,1)$| is a \cs\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]
+\cs\AP{}
+A \kl{""}semigroup\kl{""} is an ordered pair \verb|$(S,\cdot)$| where \verb|$\cdot$| is an
+associative binary operator over~\verb|$S$|.\\
+\kl{[...]}\\
+\cs\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 \cs{\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{[...]}\\
+\AP 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 practice 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 \cs{\intro} command), i.e., in the preamble:
+\begin{code}[6.7cm]
+\cs\knowledge\{semigroup\}\{\kl{notion}\}\\
+\cs\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{[...]}\\
+\AP 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 \cs{\AP}-command.
+If now one adds the option \kl{electronic} while loading the package, then the colors and the red corner disappear. When using the option \kl{paper}, the links are still there, but all texts are in black.
+
+\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]
+\cs\knowledge\{semigroup\}[semigroups\vbar Semigroups]\{\kl{notion}\}\\
+\cs\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 \cs{\newrobustcmd} (of the \texttt{etoolbox} package), rather than the usual \cs{\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]
+\cs\newrobustcmd\kl[@token]\monoid\{\cs\mathcal\ M\}
+\end{code}\noindent
+Imagine that furthermore, you would like to hyperlink to the definition of a monoid. A standard \cs{\kl} command does the job\footnote{It is highly advised to not use the "quotation notation" in math mode or macros.}:
+\begin{code}[9cm]
+\cs\newrobustcmd\kl[@token]\monoid\{\cs\kl[monoid]\{\cs\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}
+\cs\knowledgeconfigureenvironment\{theorem,lemma,proof\}\{\}\par\noindent
+\kl{[...]}\par\noindent
+\cs\begin\{lemma\}\cs\label\{theorem:main\}\par\noindent
+~~~~\cs\knowledge\{n\}\{\kl{notion}\}\par\noindent
+~~~~For all number~\$\cs\intro\ n\$, \kl{[...]}\par\noindent
+\cs\end\{lemma\}\par\noindent
+\kl{[...]}\par\noindent
+Here \$\cs\kl\ n\$ is an undefined knowledge.\par\noindent
+\kl{[...]}\par\noindent
+\cs\begin\{proof\}[Proof of theorem\~\space\{theorem:main\}]\par\noindent
+~~~~\cs\knowledgeimport\{theorem:main\}\par\noindent
+~~~~Inside the proof, \$\cs\kl\ n\$ is hyperlinked to the theorem...\par\noindent
+\cs\end\{proof\}
+\end{code}
+More on \kl{scoping} can be found in Section~\ref{subsection:scoping}.
+
+The use of "variants of \cs{\kl}" is also useful for typesetting mathematics. It allows for instance, to implicitly execute the \cs{\knowledge} command at the same time of the introduction. See~\ref{subsubsection:variants} for more detail.
+
+\newpage
+
+\section{Usage of the \kl(package){knowledge} 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 \cs{\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 \cs{\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 \cs{\knowledgeconfigure} can be used when loading the package.
+\itemAP[Scoping] The \kl[scope option]{scope} "option at 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 are attached to a section of the documents.
+\end{compactdesc}
+
+\subsubsection{Writing mode}
+\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{\cs\usepackage[\kl{paper}]\{"knowledge@@package"\}}\\[2mm]
+or\quad&\smallcode{\cs\usepackage[\kl{electronic}]\{"knowledge@@package"\}}\\[2mm]
+or &\smallcode{\cs\usepackage[\kl{composition}]\{"knowledge@@package"\}}
+\end{tabular}\\
+\AP or by setting before loading the variable \csintro{\knowledgepackagemode} as in:\\
+\begin{tabular}[t]{ll}
+ &\smallcode{\cs\def\cs\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} \quotesymbol\cs\def\cs\knowledgepackagemode%
+ \texttt\{\kl{electronic}\texttt\}\cs\input\texttt\{file.tex\texttt\}\quotesymbol}
+\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.4cm]
+\AP
+\csintro\IfKnowledgePaperModeTF\texttt\{true code\texttt\}\texttt\{false code\texttt\}\\
+\AP
+\csintro{\ ifKnowledgePaperMode} true code [\cs{\ else} false code] \cs{\ fi}\\
+\AP
+\csintro{\IfKnowledgeElectronicModeTF}\texttt\{true code\texttt\}\texttt\{false code\texttt\}\\
+\AP
+\csintro{\ ifKnowledgeElectronicMode} true code [\cs{\ else} false code] \cs{\ fi}\\
+\AP
+\csintro{\IfKnowledgeCompositionModeTF}\texttt\{true code\texttt\}\texttt\{false code\texttt\}\\
+\AP
+\csintro{\ ifKnowledgeCompositionMode} true code [\cs{\ else} false code] \cs{\ 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 at 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]
+\cs\documentclass\{article\}\\
+%\cs\usepackage[utf8]\{inputenc\}\\
+%\cs\usepackage[T1]\{fontenc\}\\
+\cs\usepackage[svgnames]\{\kl(package){xcolor}\}\\
+\cs\usepackage[\texttt{draft}]\{\kl(package){hyperref}\}\\
+\cs\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 \cs{\knowledgeconfigure}}
+
+Some part of the configuration can be done outside of the \cs{\usepackage} command that loads the "knowledge@@package" package. \AP This is done using the
+\cs{\knowledgeconfigure} command:
+\begin{center}
+\smallcode{\csintro\knowledgeconfigure\{\kl{configuration directives}\}}
+\end{center}
+Note that by default, the \kl{configuration directives} used by \cs{\knowledgeconfigure} can
+be used in the optional parameter of \cs{\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". False is the default.
+\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{"... at ..."} and \kl{"... at ...@..."}
+ instead of \cs{\kl} commands and \kl{""...""}, \kl{""... at ...""} and \kl{""... at ...@...""} instead of the \cs{\intro} command.
+\itemAP[\kl{visible anchor points}] is an option that makes visible or invisible the \kl{anchor points} of the \cs{\AP} and \cs{\itemAP} commands.
+\end{description}
+
+
+%\subsubsection{Other configuration}
+
+%Another option at loading is "scope at 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 \cs{\knowledge} command and variations}
+\label{subsection:knowledge command}
+
+In this section, we describe the main commands that create \kl{knowledges}.
+The main one is \cs{\knowledge}. It can also be used in combination with \cs{\knowledgedirective}, \cs{\knowledgestyle} and \cs{\knowledgedefault}.
+
+\subsubsection{General description of the \cs{\knowledge} command}
+
+The key command for introducing knowledges is \cs{\knowledge}.
+The syntax is:
+\begin{center}
+\smallcode{\csintro\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 \cs{\knowledgedirective} command.
+
+\AP
+The principle of the \cs{\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 \cs{\knowledge} has to decide what to do when defining something. The basic behaviour is as follows.
+\begin{itemize}
+\item If the \cs{\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 \cs\knowledge.
+\item Import/Export (\kl{not implemented}) writes a document containing a list of \cs{\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.
+ \cs{\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 \cs{\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 \cs\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 \cs{\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).
+\itemAP[\intro{also now}] requires the \kl{knowledge} to be defined immediately as well as delayed to the next compilation phase. This is in particular how "autorefrences at autoref" should be handled. See the use of \cs{\knowledgenewvariant} for more examples.
+\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 `\cs{\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 `\cs{\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 `\cs{\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,
+\itemAP[""detokenize""] detokenizes the content, i.e., instead of executing it provides a string that displays it (this is useful for commands),
+\itemAP[""remove space""]
+\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 \cs\kl. For instance,
+ \smallcode{\cs\knowledge \{latex\}\{\kl{text=}\cs{\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 \cs{\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 \cs{\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]
+\cs\knowledge\{Leslie Lamport\}\par
+~~~~~\{\kl{ref=}\{https://fr.wikipedia.org/wiki/Leslie\_Lamport\}\}\\
+\cs\knowledge\{L. Lamport\}\{\kl{synonym}\}\\
+\cs\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=}\cs\robustdisplay,
+(where \csintro{\robustdisplay} is a variant of \cs{\tl_to_str:n} removing the trailing space) is used in this document for typesetting the commands.
+\end{compactdesc}
+
+
+\subsubsection{\kl{Knowledge styles} and the \cs{\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 \cs{\intro} command is displayed.
+See below for some instances.
+
+\AP
+The central command is \cs{\knowledgestyle}, that has the following syntax:
+\begin{center}
+\smallcode{\csintro{\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 \cs{\knowledge}
+command. When defined, a \kl{style} can be used in a \cs{\knowledge}
+command using the \kl[\knowledge directives]{directives} `\kl{style=}style name' (it will be used when a \cs{\kl} command calls for the \kl{knowledge}) or `\kl{intro style=}style name' (that will be used by \cs{\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[""kl@@style""] is the default style for macros using \cs{\kl}.
+ It can be modified dynamically using the `\kl{style=}' \kl[\knowledge directives]{directive}.
+\itemAP[""kl unknown@@style"" and ""kl unknown cont@@style""] are
+ the default \kl{styles} used when an undefined \kl{knowledge} is met.
+\itemAP[""intro@@style"" and ] is the default style for macros using \cs{\intro}.
+ It can be modified dynamically using the `\kl{intro style=}' \kl[\knowledge directives]{directive}.
+\itemAP[""intro unknown@@style"" and ""intro unknown cont@@style""]
+ are the default \kl{styles} used when an undefined \kl{knowledge} is met.
+\end{compactdesc}
+
+\subsubsection{New directives: the \cs{\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 \cs{\knowledgedefault} and \cs{\knowledgestyle}). This is achieved using the \cs{\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{\csintro{\knowledgedirective}\{name\}[optional parameter]\{directives\}}
+\end{center}
+After such a command has been issued, `name' becomes a \kl[\knowledge directives]{directive}
+usable in \cs{\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}
+\cs\knowledgedirective\{highlight\}[brown]\{\kl{color=}\{\#1\},\kl{emphasize},\kl{md}\}\\{}
+\kl{[...]}\\{}
+\cs\knowledge\{notion A\}\{highlight\}\\
+\cs\knowledge\{notion B\}\{highlight\}\\
+\cs\knowledge\{notion C\}\{highlight\}\\
+\cs\knowledge\{important notion D\}\{highlight=red\}\\{}
+\cs{[...]}\\
+We shall now see \cs\kl\{notion A\}, \cs\kl\{notion B\}, \cs\kl\{notion C\}, as well as the \cs\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{\cs{\knowledgestyle} versus \cs{\knowledgedirective}}
+\label{subsubsection:style versus macro}
+
+The two commands \cs{\knowledgestyle} and \cs{\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 \cs{\knowledge} command works.
+
+In general when a \cs{\knowledge} (or \cs{\knowledgestyle}) command is found, the \kl[\knowledge directives]{directives} are parsed and a new internal form of the \cs{\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 \cs{\kl} and similar commands.
+
+When a \cs{\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 \cs{\knowledgedefault} command}
+\label{subsubsection:default directives}
+
+It may happen that a sequence of consecutive \cs{\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 \cs{\knowledgedefault} command:
+\begin{center}
+\smallcode{\csintro\knowledgedefault*\{\kl[\knowledge directives]{directives}\}}
+\end{center}
+When such a command is applied, then from that point, all \cs{\knowledge} commands
+will use the given \kl[\knowledge directives]{directives} as default. This will stop when another \cs{\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 \cs{\kl} command}
+\label{subsection:kl command}
+
+\subsubsection{The standard syntax}
+
+\marginpar{\begin{hint} Note that the \cs{\kl} command can often be replaced by the
+\kl{"..."}{} notation, activated by the "quotation@@option" option.\end{hint}}
+
+
+The \cs{\kl} command has one of the following syntaxes:
+\begin{center}
+\begin{tabular}{cc}
+&\smallcode{\csintro{\kl}(\kl[klab]{optional label})[\kl[knowledge name]{optional knowledge name}]\{text\}}\\
+or\quad&
+\smallcode{\csreintro{\kl}[\kl[knowledge name]{optional knowledge name}](\kl[klab]{optional label})\{text\}}\ .
+\end{tabular}
+\end{center}
+Its meaning 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} `"kl unknown@@style"' (or similar "styles", as defined by the "unknown style=@@variant" or "unknown style cont=@@variant") 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 \cs{\kl} such as in particular \cs{\intro}.
+
+
+\subsubsection{The "quotation notation"}
+
+\phantomintro{"}\phantomintro{@}\phantomintro{quotation notation}%
+When activated, the ""quotation@@option"" mode activates shorthand
+notations for the \cs{\kl} and \cs{\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{\cs\kl\{text\}}.
+\itemAP[\smallcode{\kl"text at knowledge\kl"}]\phantomintro{"... at ..."}%
+ uses the "knowledge" pointed to by `knowledge to display `text'. Equivalent to~\texttt{\cs\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{\cs\kl(label)\{text\}}.
+\itemAP[\smallcode{\kl"text at knowledge@label\kl"}]\phantomintro{"... at ...@..."}%
+ uses the "knowledge" pointed to by `knowledge in "scope" `scope' to display `text'. Equivalent to~\texttt{\cs\kl[knowledge](label)\{text\}}.
+\itemAP[\smallcode{\kl{""}text\kl{""}}]\phantomintro{""...""}%
+ introduces the "knowledge" pointed to by `text'. Equivalent to~\texttt{\cs\intro\{text\}}.
+\itemAP[\smallcode{\kl{""}text at knowledge\kl{""}}]\phantomintro{""... at ...""}%
+ introduces the "knowledge" pointed to by `knowledge while displaying `text'. Equivalent to~\texttt{\cs\intro[knowledge]\{text\}}.
+\itemAP[\smallcode{\kl{""}text@@label\kl{""}}]\phantomintro{""...@@...""}%
+ introduces the "knowledge" pointed by `text' in "scope" `scope'. Equivalent to~\texttt{\cs\intro(label)\{text\}}.
+\itemAP[\smallcode{\kl{""}text at knowledge@label\kl{""}}]\phantomintro{""... at ...@...""}%
+ introduces the "knowledge" pointed to by `knowledge in "scope" `scope' while displaying `text'. Equivalent to~\texttt{\cs\intro[knowledge](label)\{text\}}.
+\end{description}
+
+\noindent\AP Activating and deactivating the "quotation notation" is obtained using:
+\begin{center}
+\smallcode{\cs\knowledgeconfigure\{"quotation@@option"\}}\ ,
+\end{center}
+and deactivating it is obtained using:
+\begin{center}
+\smallcode{\cs\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]
+\cs\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 \cs{\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}
+
+
+
+\subsubsection{\kl{Variants of \cs{\kl}}, \cs{\knowledgenewvariant}, \cs{\knowledgevariantmodifier} }
+\label{subsubsection:variants}
+\phantomintro{variant of \cs{\kl}}%
+It may happen for several reasons that we may want to define new variants of the \cs{\kl} macros, that essentially perform the same task, but are configured differently. Typical examples may be:
+\begin{itemize}
+\item several sets of "knowledges" may intersect but should use different "namespace",
+\item some "knowledges" involve macros and for this reason should be non-expanded even if the \cs{\knowledge}
+ command is not met,
+\item the \cs{\knowledge} command should be performed automatically,
+\item activate or desactivate the warnings or messages in the "diagnose file".
+\end{itemize}
+In fact, several macros in this document are instantiation of this mechanism. This is the case for for instance for \cs{\intro}, \cs{\phantomintro}, \cs{\reintro} or \cs{\mathkl} etc...
+
+
+\AP The macro for introducing a new \reintro{variant of \cs{\kl}} is:
+\begin{center}
+\smallcode{\csintro{\knowledgenewvariant}\cs\variant\{\kl{variant directives}\}}
+\end{center}
+and is similar to the one for modifying the behavior of a "variant of \cs{\kl}":
+\begin{center}
+\smallcode{\csintro{\knowledgesetvariant}\cs\variant\{\kl{variant directives}\}}\ .
+\end{center}
+These command define/modify a/the macro \cs{\variant} that uses the same syntax as \cs{\kl}. \AP The \intro{variant directives} consist of a comma separated list of "directives@@variant" as follows:
+\begin{compactdesc}
+\itemAP[""namespace=@@variant""namespace] declares in which "namespace" (a string) the knowledges are to be searched.
+ This means in particular that the \cs{\knowledge} concerned should be defined using the the proper "namespace=" directive.
+\itemAP[""default style=@@variant"", ""unknown style=@@variant"", ""unknown style cont=@@variant""\{list of "style" names\}]
+ declares the style name to be used (1) by default when the "knowledge" is found, (2) when it is not found for the first time, and (3) the subsequent times.
+\itemAP[""style directive=@@variant""\{directive names list\}] defines a list (comma separated) of directives that can
+ be used in a \cs{\knowledge} command to modify the aspect (for instance, the \cs{\intro} behavior is modified by the "intro style=" directive, while the \cs{\kl} command is configured using the "style=" directive). If the "directives" do not exist, these are created.
+\itemAP[""auto knowledge=@@variant""\{directives\}] declares that the use of \cs{\variant} should automatically execute a \cs{\knowledge} command, and what should be the directives it uses. See examples below.
+\itemAP[""unknown warning=@@variant""true/false] activates or deactivates the warnings when a "knowledge" is not found
+ (for instance, these are deactivated in "paper mode"). True by default.
+\itemAP[""unknown diagnose=@@variant""true/false] activates or deactivates the corresponding messages in the "diagnose file". True by default.
+\itemAP[""suggestion=@@variant""\{directives\}] configures the "directives" to be suggested in the "diagnose file"
+when the "knowledge" is unknown.
+\itemAP[""PDF string=@@variant""\{code\}] gives a substitute text for "hyperref@@package" to use for producing the bookmarks. This code has to be expandable. The code may use three parameters; $\sharp1$ is the main text of the command, $\sharp 2$ is the optional parameter, and $\sharp 3$ is the scope. The macro \cs{\IfNoValueTF} of the package "xparse@@package" can be used to test if the second and third arguments are present. By default, the code is \texttt{\{$\sharp1$\}}. Note that the star syntax cannot be used in this context. It the expected result cannot be achieved usinf this directive, the less convenient macro \cs{\texorpdfstring} of the "hyperref@@package" should be used.
+\end{compactdesc}
+\smallskip
+
+\AP The second feature is to use "modifiers@@variant". These correspond to the starred version of the command.
+For instance, one expects `\cs{\intro}*\cs{\kl}' to reduce to `\cs{\intro}'. For this, one has to declare explicitly the reduction using:
+\begin{center}
+\smallcode{\csintro{\knowledgevariantmodifier}\{"starred sequence@@variant"\}\cs\variant}\ ,
+\end{center}
+in which the "starred sequence@@variant" is of the form `\cs{variant1}*\cs{variant2}*\dots*\cs{variantk}'.
+This sequence is declared to reduce to \cs{\variant}.
+For instance, \smallcode{\cs{\knowledgevariantmodifier}\{\cs\intro*\cs\kl\}\cs\intro} declares `\cs{\intro}*\cs{\kl}' to reduce to `\cs{\intro}'.
+
+\subsubsection{Examples of \kl{variants of \cs{\kl}}}
+
+The best way for introducing new variants is to look at examples. We provide two of them now.
+the first one is the configuration of the \cs{\kl} and \cs{\intro} commands as defined in the "package at knowledge@package".
+The second one is the code used in this documentation for displaying macros, defining the macros \cs{\cs}
+and \cs{\csintro}.
+
+\paragraph{The configuration of \cs{\kl} and \cs{\intro}} It is also interesting to see this code since it gives more ideas on how to modify the standard behaviour of these commands correctly.
+\begin{code}
+\cs\knowledgestyle\{autoref link\}\{"autoref link"\}\par
+\cs\knowledgestyle\{autoref target\}\{"autoref target"\}\par
+\cs\knowledgestyle\{invisible\}\{"invisible"\}\par
+\cs\knowledgenewvariant\cs\kl\{\par
+~~~~"namespace=@@variant"default,\par
+~~~~"default style=@@variant"\{"kl@@style",autoref link\},\par
+~~~~"unknown style=@@variant" "kl unknown@@style",\par
+~~~~"unknown style cont=@@variant" "kl unknown cont@@style",\par
+~~~~"style directive=@@variant" "style at style="\par
+\}\par
+\cs\knowledgenewvariant\cs\intro\{\par
+~~~~"namespace=@@variant" default,\par
+~~~~"default style=@@variant" \{"intro@@style",autoref target\},\par
+~~~~"unknown style=@@variant" "intro unknown@@style",\par
+~~~~"unknown style cont=@@variant" "intro unknown cont@@style",\par
+~~~~"style directive=@@variant" "intro style at intro style="\par
+\}\par
+\cs\knowledgevariantmodifier\{\cs\intro*\cs\kl\}\cs\intro
+\end{code}
+Note that \cs{\reintro} and \cs{\phantomintro} are defined using similar code.
+
+\paragraph{Displaying control sequences}
+
+\AP The second code example is used in this document (the documentation of the package) and consists of two macros \csintro{\cs} and \csintro{\csintro} which have the
+following semantics:
+\begin{itemize}
+\item these have the same syntax as \cs{\kl} and \cs{\intro} respectively.
+\item these are used to display control sequences without executing it,
+\item if \cs{\csintro} is never used, it appears in black,
+\item is \cs{\csintro} is used, then it is in color blue, and the calls to \cs{\cs}
+ are in dark blue, and furthermore, the \cs{\cs} calls possess an hyperlink to
+ the call to \cs{\csintro}.
+\item no \cs{\knowledge} command is necessary, and no warnings are issued.
+\end{itemize}
+\begin{code}
+\cs\knowledgestyle\{cs\}\par
+~~~~\{"detokenize","remove space","typewriter","up","md","color="NavyBlue\}\par
+\cs\knowledgestyle\{cs unknown\}\par
+~~~~\{"detokenize","remove space","typewriter","up","md","color="black\}\par
+\cs\knowledgenewvariant\cs\cs\{\par
+~~~~"namespace=@@variant"cs,\par
+~~~~"default style=@@variant"\{autoref link,cs\},\par
+~~~~"unknown style=@@variant"cs unknown,\par
+~~~~"unknown style cont=@@variant"cs unknown,\par
+~~~~"unknown warning=@@variant"false,\par
+~~~~"unknown diagnose=@@variant"false,\par
+~~~~"suggestion=@@variant"cs\par
+\}\par
+\cs\knowledgestyle\{csintro\}\par
+~~~~\{"detokenize","remove space","typewriter","up","md","color="blue\}\par
+\cs\knowledgestyle\{csintro unknown\}\par
+~~~~\{"detokenize","remove space","typewriter","up","md","color="black\}\par
+\cs\knowledgenewvariant\cs\csintro\{\par
+~~~~"namespace=@@variant"cs,\par
+~~~~"auto knowledge=@@variant"\{"autoref","scope="document,"also now"\},\par
+~~~~"default style=@@variant"\{autoref target,csintro\},\par
+~~~~"unknown style=@@variant"csintro unknown,\par
+~~~~"unknown style cont=@@variant"csintro unknown,\par
+\}\par
+\cs\knowledgevariantmodifier\{\cs\intro*\cs\cs\}\cs\csintro\par
+\cs\knowledgevariantmodifier\{\cs\csintro*\cs\cs\}\cs\csintro\par
+\cs\knowledgevariantmodifier\{\cs\cs*\cs\kl\}\cs\cs\par
+\cs\knowledgevariantmodifier\{\cs\csintro*\cs\kl\}\cs\csintro
+\end{code}
+Several things can be noted about this code:
+\begin{asparaitem}
+\item the "directives" "detokenize" and "remove space" prevent the execution of the argument, and instead display its name, this is important since the argument is a control sequence,
+\item the "directives" "typewriter", "up" and "md" give a uniform aspect (no italic, no boldface) to the result in all contexts,
+\item the "namespace" is set to be different from the default one, avoiding possible clashes with \cs{\kl},
+\item when a \cs{\csintro} command is met, the corresponding \cs{\knowledge} command is automatically issued, in particular with `"scope="document' for guaranteeing the visibility of each command everywhere in the document,
+\item the "also now" directive is necessary for the compilation to (possibly) stabilize in
+ two iterations, since it uses the proper \cs{\label} already at the first iteration (without "also now", it would be performed on the second one only, and with just "now", it would be visible only by the uses after the introduction).
+\item warnings and diagnose information is explicitly eliminated.
+\end{asparaitem}
+
+
+
+\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.
+
+Note that the use of "scopes" may overconstrain the latex code, in particular if the "scope@@option" is used. The result is that a code that was compiling before activating the option, will not after doing it. This may happen for instance if one uses a \cs{\section} command inside a
+a \cs{theorem} environment. Of course, though this is not forbidden by "latex", this is not something that one usually wants to do. At any rate, the scope handling of the "knowledge@@package" package --- at least in its current form --- complains in such a situation. Indeed, it attempts to reconstruct a full hierarchically decomposed version of the document. In the above example, when the \cs{\section} command is met, the package attempts to close the outer section, but this would force the theorem also to be closed. However, closing a theorem requires an \cs{\end} command. Error...
+
+\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]
+ \cs\begin\{\kl(env){scope}\}\par
+ ~~\cs\knowledge\{local notion\}\{\kl{color=}green\}\par
+ ~~Here is a \cs\kl\{local notion\} that appears in green.\par
+ \cs\end\{\kl(env){scope}\}\\
+ But this \cs\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 \cs{\knowledgeconfigureenvironment}.
+ \itemAP The use of the ""scope at 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, may cause some compiling document to not compile anymore if some weird (and unnatural) nesting of scopes are used.
+\end{itemize}
+
+\subsubsection{How is chosen the \kl{scope} of a \kl{knowledge}?}
+
+In general, when a \cs{\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 did not perform its own configuration), this is the inner most \kl(env){scope} environment (or similar environment if \cs{\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]
+ \cs\section\{First section\}\par\noindent
+ \cs\label\{section:first\}\par\noindent
+ \cs\knowledge\{one\}\{\kl{scope=}section,\kl{color=}green\}\par\noindent
+ \cs\knowledge\{two\}\{\kl{scope=}some label,\kl{color=}green\}\par\noindent
+ ~\par\noindent
+ \cs\begin\{\kl(env){scope}\}\cs\label\{some label\}\par\noindent
+ ~~Here \cs\kl\{one\} and \cs\kl\{two\} are defined.\par\noindent
+ \cs\end\{\kl(env){scope}\}\par\noindent
+ Here \cs\kl\{one\} is defined but \cs\kl\{two\} isn't.\par\noindent
+ ~\par\noindent
+ \cs\section\{Second section\}\par\noindent
+ Here neither \cs\kl\{one\} nor \cs\kl\{two\} is defined.
+ However, I can still use them using \cs\kl(section:first)\{one\} and \cs\kl(some label)\{two\}
+ (or \kl"one@@section:first\kl" and \kl"two@@some label\kl", or using the \cs{\knowledgeimport}\{section:first\}).
+ \end{code}
+\end{itemize}
+
+\subsubsection{Accessing other scopes, the \cs{\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{\cs\kl(label)\{text\}} command (or the equivalent \smallcode{\kl{"... at ...@..."}} notation), or use the \cs{\knowledgeimport} command. We describe the second possibility now. The syntax is:
+\begin{center}
+\smallcode{\csintro\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]
+\cs\knowledgeconfigureenvironment\{theorem,proof\}\{\}\par\indent
+{[...]}\par\indent
+\cs\begin\{theorem\}\cs\label\{theorem:1\}\par\noindent
+~~\cs\knowledge\verb|\alpha|\{\kl{autoref},\kl{color=}red\}\par\noindent
+~~Let \$\cs\intro\verb|\alpha|\$ be an integer [...]\par\noindent
+\cs\end\{theorem\}\par\noindent
+{[...]}\par\indent
+Here \$\cs\kl\verb|\alpha|\$ is unknown.\par\noindent
+{[...]}\par\indent
+\cs\begin\{proof\}\par\noindent
+~~\cs\knowledgeimport\{theorem:1\}\par\noindent
+~~But now \$\cs\kl\verb|\alpha|\$ points to its definition.\par\noindent
+\cs\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 \cs{\knowledgeconfigureenvironment}, as well as adapt some of its characteristics using
+"scope directives".
+\begin{center}
+ \smallcode{\csintro\knowledgeconfigureenvironment\{environments\}\{"scope directives"\}}
+\end{center}
+For instance:
+\begin{code}[12cm]
+ \cs\knowledgeconfigureenvironment \{lemma,theorem,fact,proof\}\par
+ ~~~~~~~~\{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 \cs{\begin} and \cs{\end}. Hence \cs{\proof}\dots\cs{\endproof} would
+ not trigger a scoping environment while \cs{\begin{proof}}\dots\cs{\end{proof}}
+ would.
+\end{remark}
+
+\AP The ""scope directives"" are low level and advanced features. These should not be used in general. Their list is 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 \cs{\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 using the \cs{\begin} and \cs{\end} commands of "latex".
+ \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). It should be true for "latex" environments, and false when configuring, e.g, \cs{\section} to open an "scope" (since the end of the section is automatic: when another section is opened, or some higher level sectioning command).
+ \itemAP[\intro(area){parents=}\{"area1 at area","area2 at area",\dots\}] takes a comma separated list of areas that are allowed as parent. For opening the area, some enclosing instances may be automatically closed for reaching such a parent (if their "autoclose=@@area" "directive at scope directive" is set to true).
+ \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 \cs{\intro} and \cs{\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
+Very often there is some \kl[undefined knowledge]{undefined knowledge}.
+Such \kl{knowledges} are displayed using "kl unknown@@style" and "kl unknown cont@@style")
+\kl{styles} when issued by \cs{\kl}; using "intro unknown@@style" and "intro unknown cont@@style" when issued by \cs{\intro}.
+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 sometimes check 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 \texttt{\cs{\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. By default, no suggestion is offered (i.e., the \texttt{\{\}} braces are empty). Suggestion can be automatically configured using the "suggestion=@@variant" "directive@@variant" of the macros \cs{\knowledgenewvariant} and \cs{\knowledgesetvariant}.
+
+For instance, using:
+\begin{center}
+\smallcode{\cs\knowledgesetvariant\cs\kl\{"notion"\}}
+\end{center}
+the "directive" "notion" is suggested for more directly copying the content.
+\itemAP[\intro{Autoref not introduced}] This section lists all \kl{knowledges} that were declared using the \kl{autoref} \kl[\knowledge directives]{directive} (this can be the case indirectly using, e.g. "notion"), but have not been introduced in the document . When a document reaches its final states, this section should be empty.
+Usually, one should add the corresponding \cs{\intro} or \cs{\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 \cs{\intro} or \cs{\nointro}
+more than once are listed. When a document reaches its final states, this section should be empty. Consider using \cs{\kl} or \cs{\reintro} for solving the problem.
+Note that this may be caused by an \cs{\intro} used in some title (and repeated in the table of contents).
+\end{description}
+
+\AP By default, the "diagnose file" does not give the file and the line of the messages.
+This can be activated using the "diagnose line" boolean option:
+\begin{center}
+\smallcode{\cs\knowledgeconfigure\{""diagnose line=""true\}}
+\end{center}
+
+\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 \cs{\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}
+\cs\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 \csintro\knowledgeexportscopename
+\item \csintro\knowledgeexportbase
+\item \csintro\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{cyclic color}] similar to `"color="', but selects the color automatically in a a cyclic list of colors. This can be convenient for debugging.
+ The cyclic list of colors can be chosen using the "configuration directive" ""cyclic colors=@@option"":
+ \begin{center}
+ \smallcode{\cs\knowledgeconfigure\{"cyclic colors=@@option"\{color1,color2,\dots\}\}}
+ \end{center}
+ Note that no spaces are allowed between colors, and that at least two colors are required.
+
+ The default cyclic color list is:
+ \begin{center}
+ \texttt{\{red,green,blue,cyan,magenta,yellow,gray,brown,lime,\\olive,orange,pink,purple,teal,violet\}}
+ \end{center}
+\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 (this are visible in some viewers, and not in some others): this is deactivated by the "knowledge@@package" package using the "hidelinks" option of "hyperref@@package".\end{hint}}
+\begin{center}
+\smallcode{%
+\cs{\usepackage}[\kl(option){hyperref}]\{\kl(package){knowledge}\}}
+\end{center}\noindent
+or by loading the "hyperref@@package" before the "knowledge@@package" package.
+
+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 \cs{\intro} command.
+\item[\kl{autorefhere}] puts immediately a label at the location of the definition, and makes all \cs{\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 \csintro{\intro} (exactly once) --
+or the \kl{""...""} and \kl{""... at ...""} notations (and variants) if \kl(option){quotation} is active -- and \cs{\kl} (possibly several times) -- or the \kl{"..."} notation if \kl(option){quotation} is active. The use of \cs{\kl}
+will hyperlink to the location of the \cs{\intro}. The syntax of \cs{\intro} is the same as
+for \cs{\kl}:
+\begin{center}
+\smallcode{\cs{\intro}[optional knowledge name]\{knowledge name\}}
+\end{center}
+
+\emph{See \cs{\AP} below for improving the result.}
+
+A typical use looks as follows:
+\marginpar{\begin{hint}
+ Though the \cs{\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}
+\cs\knowledge\{house\}[Houses\vbar houses]\{\kl{autoref}\}\\~
+\kl{[...]}\\
+\cs\begin\{document\}\\~
+\kl{[...]}\\
+In this document, we will see the very important notion of \kl{"}houses\kl{"}.\\~
+\kl{[...]}\\
+\cs\AP\\
+Let us define a \kl{""}house\kl{""} to be a building that functions as a home.\\~
+\kl{[...]}\\
+\cs\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 \csintro{\intro*} makes the next \cs{\kl} command behave like \cs{\intro}. This is useful in particular in math mode:
+\begin{code}
+\cs\newcommand\kl[@token]\monoid\{\cs\kl[\kl[@token]\monoid]\{\cs\mathcal M\}\}\\
+\cs\knowledge\kl[@token]\monoid\{autoref\}\\~
+\kl{[...]}\\
+\cs\AP\\~
+Let now \$\cs{\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 \csintro{\phantomintro} version:
+\begin{center}
+\smallcode{\cs{\phantomintro}(optional label)\{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{\cs\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 \csintro{\nointro} command:
+\begin{center}
+\smallcode{\cs{\nointro}\{knowledge\}}
+\end{center}
+does not display anything and silently prevents the knowledge from issuing warnings
+because it is not introduced.
+
+\AP
+The \csintro{\reintro} command:
+\begin{center}
+\smallcode{\cs{\reintro}[optional knowledge]\{knowledge\}}
+\end{center}
+is displayed as for \cs{\intro}, but without being an anchor for hyperlinks, and without counting as a real \cs\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 \csintro{\reintro*} that makes the next \cs{\kl} command behave like a \cs{\reintro} (similar to \cs{\intro*} with respect to \cs{\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 \cs{\intro},
+there are new directives:
+\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 \cs{\intro} or \cs{\reintro} command.
+\itemAP[\intro{autoref target}] declares the knowledge to be the target of the autoref (this is implicit when using \cs{\intro}).
+\itemAP[\intro{autoref link}] requires a link to the target of the autoref to be produced (this is implicit when using \cs{\kl}).
+\end{description}
+See the use of \cs{\knowledgesetvariant} for examples of configuration.
+%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 \cs{\knowledge} command invoking it.
+Uses of \cs{\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 \cs{\intro} command. This is a bit better since using \kl{autoref} in 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" package. This means that it puts à label at the place of the \cs{\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 \cs{\intro} happens in a `section' (but not inside a theorem-like envionment) then the \cs{\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 \csintro{\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[\csintro{\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 \cs{\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 \cs{\item}, one should use instead:
+\itemAP[\csintro{\itemAP}] Similar to \cs\AP, but to be used instead of an \cs\item.
+\end{compactdesc}
+\smallskip
+
+Usually putting an \cs{\AP} (a standard command of the "hyperref@@package") at the beginning of every paragraph, and replacing \cs{\item} by \cs{\itemAP} in itemize-like environments is most of the time good and safe option.
+
+For instance:
+\begin{code}[12.5cm]
+\cs\AP\\
+ In order to describe what is a \cs\kl\{monoid\}, let us us first define
+a \cs\intro\{product\} to be an associative binary operator,
+and a \cs\intro\{unit\} to be \kl{[...]}
+\bigskip
+
+\cs\begin\{description\}\\
+\cs\itemAP[A \cs\intro\{semigroup\}] is a set equipped with a \cs\kl\{product\}.\\
+\cs\itemAP[A \cs\intro\{monoid\}] is a \cs\kl\{semigroup\} that has a \cs\kl\{unit\}.\\
+\cs\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 \cs{\AP} and \cs{\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
+this graphical help disappears.
+This can also be desactivated using:\phantomintro{visible anchor points}
+ \begin{code}[9cm]
+ \cs\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{\cs{\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 \cs{\index} command when a \cs{\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 \cs{\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 using using
+\begin{center}
+\smallcode{\cs\knowledgeconfigure\{""fix hyperref twocolumn""\}}.
+\end{center}
+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{\cs\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 \cs{\intro} commands (not in math mode) are emphasized, while the \cs{\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}
+\cs\documentclass\{article\}\\
+\cs\usepackage\{\kl(package){xcolor}\}\\
+\cs\usepackage\{\kl(package){hyperref}\}\\
+\cs\usepackage[\kl{paper}]\{"knowledge@@package"\}\\
+\cs\knowledgeconfigure\{"notion@@option"\}\\
+{[...]}\\
+\cs\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 \cs{\intro} command. When it is used, and all the \cs{\knowledge} commands are in the preamble, then two phases are necessary. When \cs{\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 \cs{\item} parameters}
+
+\paragraph{The use of~\cs{\AP} inside \cs{\item} does not work.} Do not use \cs{\AP} inside the optional argument of \cs{\item}, and rather use the command \cs{\itemAP}.
+
+\paragraph{Argument of \cs{\kl} has an extra `\texttt\}'.} This is a problem of using optional parameters inside optional parameters such as in \smallcode{\cs\item[\cs\kl[test]\{Test\}]}. You can surround the content of the optional parameter by two level of curly braces as in \smallcode{\cs\item[\{\{\cs\kl[test]\{Test\}\}\}]}.
+The notation \kl{"..."} does not have this issue.
+
+
+
+
+\subsection{Knowledges and moving arguments (table of contents, \dots).}
+
+
+
+\paragraph{The use of \cs{\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 \cs{\kl} command complains of not knowing the \kl{knowledge}. For instance\footnote{with \texttt{\cs\usepackage[utf8]\{inputenc\}} and, for instance \texttt{\cs\usepackage[T1]\{fontenc\}} for the accents.}:
+\begin{center}
+\begin{code}[11cm]
+\cs\newcommand\robustdisplay\Ltwo\{\cs\ensuremath\{L\^{}2\}\}\\
+\cs\knowledge\{\robustdisplay\Ltwo-space\}[\robustdisplay\Ltwo-spaces]\{autoref\}\\
+\cs\knowledge\{\'etale topology\}[\'Etale topology]\par
+~~~~~~~\{\kl{url=}\{https://en.wikipedia.org/wiki/\'Etale\_topology\}\}\\
+{[...]}\\
+\cs\begin\{document\}\\
+\cs\tableofcontents\\
+\cs\section\{On \cs\kl\{\robustdisplay\Ltwo-spaces\}\\
+{[...]}\\
+\cs\section\{On the \cs\kl\{\'etale topology\}\}\\
+{[...]}\\
+\cs\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 \cs{\newrobustcmd} (of the \kl(package){etoolbox} package) or \cs{\NewDocumentCommand} (of the \kl(package){xparse} package, with a different handling of arguments) instead of \cs{\newcommand}. Hence:
+\begin{code}
+\cs\newrobustcmd\robustdisplay\Ltwo\{\cs\ensuremath\{L\^{}2\}\}
+\end{code}\noindent
+solves the first problem.
+\item Using an equivalent text that does not have the problem:
+ \begin{code}
+ \cs\knowledge\{$\backslash$'etale topology\}\{\kl{link=}\'etale topology\}\\
+ {[...]}\\
+ \cs\section\{On the \cs\kl\{$\backslash$'etale topology\}\}
+ \end{code}
+\item Both problems can be solved using synonyms/links that have no problem. For instance:
+ \begin{code}
+ \cs\knowledge\{Ltwo-space\}\{\kl{link=}\robustdisplay\Ltwo-space\}\\
+ \cs\knowledge\{etale topology\}\{\kl{link=}\'etale topology\}\\
+ {[...]}\\
+ \cs\section\{On \cs\kl[Ltwo-space]\{\robustdisplay\Ltwo-spaces\}\}\\
+ \cs\section\{On the \cs\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 \cs{\intro} in a section title causes introducing the knowledge twice.}
+Do not use \cs{\intro} in titles, but rather \cs{\reintro}. If you want the section to be the target of the \kl{knowledge}, then put after the section a \cs{\pantomintro} command.
+\begin{center}
+\begin{tabular}{ccc}
+%\hline
+\begin{code}[5.5cm]
+\cs\section\{On \cs\intro\{topology\}\}\\
+\end{code}&&
+\begin{code}[5.9cm]
+\cs\section\{On \cs{\reintro}\{topology\}\}\\
+\cs{\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"
+
+This can be doe either explicitely using before each figure:
+\begin{code}[8.5cm]
+\cs\knowledgeconfigure\{"quotation@@option"=false\}
+\end{code}
+\noindent
+and after the figure:
+\begin{code}[7cm]
+\cs\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]
+\cs\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 \cs{\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 \cs{\intro}, which internally uses {\cs\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 \cs\phantomsection, and then use \cs{\reintro} inside the environment. Imagine for instance a command
+\texttt{\robustdisplay\SomeCommand}, that inside uses \texttt{\cs\kl[\robustdisplay{\Somecommand}]}, then:
+\begin{center}
+ \begin{tabular}{ccc}
+ does not work&&works\\
+ \begin{code}[5cm]
+ \cs\begin\{\kl{align*}\}\\
+ \cs\intro*\texttt{\robustdisplay{\SomeCommand}}\\
+ \cs\end\{\kl{align*}\}\\
+ \end{code}
+ &&
+ \begin{code}[5cm]
+ \cs\phantomintro\texttt{\robustdisplay{\SomeCommand}}\\
+ \cs\begin\{\kl{align*}\}\\
+ \cs\reintro*\texttt{\robustdisplay{\SomeCommand}}\\
+ \cs\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{\cs\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
+\cs\usepackage[\kl{breaklinks}]\{\kl(package){hyperref}\}\par\noindent
+\kl{[...]}\par\noindent
+\cs\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$\quotesymbol.}
+\end{pquote}\noindent
+or definitively using:
+\begin{pquote}
+\texttt{(defun my-hook () (local-unset-key \quotesymbol$\backslash$\quotesymbol\quotesymbol))\\
+(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 at irif.fr}.
+
+\newpage
+
+\section{Resources}
+\label{section:resources}
+
+\subsection{List of commands}
+\begin{compactdesc}
+\item[\cs\AP] introduces an "anchor point".
+\item[\cs\intro] searches for a \kl{knowledge} and put an anchor to it (to be used with the \kl{autoref} directive).
+\item[\cs\kl] searches for a \kl{knowledge} and displays it accordingly.
+\item[\cs\knowledge] defines new \kl{knowledges}.
+\item[\cs\knowledgeconfigure] configures the package.
+\item[\cs\knowledgedirective] defines a new \kl[\knowledge directives]{directive}.
+\item[\cs\knowledgedefault] declares the default \kl[\knowledge directives]{directives} to be automatically used in \cs{\knowledge} commands.
+\item[\cs\knowledgeimport] gives access to \kl{knowledges} existing in other scopes.
+\item[\cs\knowledgenewvariant] defines a new "variant of \cs{\kl}".
+\item[\cs\knowledgesetvariant] configures a "variant of \cs{\kl}".
+\item[\cs\knowledgestyle] defines a new \kl{style}.
+\item[\cs\knowledgevariantmodifier] declares a meaning of \cs{*} in "variants of \cs{\kl}".
+\item[\cs\nointro] declares that the knowledge will never be introduced (does not work properly yet).
+\item[\cs\phantomintro] performs an invisible \cs\intro.
+\item[\cs\reintro] uses the \kl{display style} of \cs{\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 \kl{directives} (to use with \cs{\knowledge})}
+\label{subsection:directive list}
+
+
+\begin{compactdesc}
+\item["autoref"] Activates the \cs{\intro} feature (requires the "hyperref@@package").
+\item["autoref link"] activates an hyperlink to the target.
+\item["autoref target"] puts a target for a hyperlink.
+\item[\kl{autorefhere}] creates an \kl{anchor point} that points to the \cs{\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{cyclic color}] Displays in a color among a cyclic list (requires \kl(option){xcolor}).
+\item[\kl{detokenize}] Avoids evaluation of the text.
+\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{invisible=}] no display
+\item[\kl{italic=}] displays in italic
+\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{remove space}] removes the spaces from the input
+\item[\kl{typewriter}] Typeset in as with \cs{\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 \cs{\knowledgeconfigure})}
+\label{subsection:configuration directive list}
+\begin{compactdesc}
+\item["composition"] switches to "composition mode",
+\item["cyclic colors=@@option"] fixes the cyclic list of colors used by the "directive" "cyclic color".
+\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){kl unknown}, \kl(style){kl unknown cont}]
+\itemAP[\kl(style){intro unknown}, \kl(style){intro unknown cont}]
+\itemAP[\kl(style){notion}] (if "notion" is activated)
+\itemAP[\kl(style){intro notion}] (if "notion" is activated)
+\end{compactdesc}
+
+
+
+
+\producecode
+\end{document}
Property changes on: trunk/Master/texmf-dist/doc/latex/knowledge/knowledge.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/doc/latex/knowledge/makefile
===================================================================
--- trunk/Master/texmf-dist/doc/latex/knowledge/makefile 2017-10-19 21:28:59 UTC (rev 45559)
+++ trunk/Master/texmf-dist/doc/latex/knowledge/makefile 2017-10-19 21:29:32 UTC (rev 45560)
@@ -1,50 +1,50 @@
help:
- @echo "- help : this help"
- @echo "- all: produces knowledge.pdf and knowledge.sty"
- @echo "- ctan: creates the knowledge-ctan.zip file for CTAN"
+ @echo "This is the makefile for the knowledge package"
+ @echo "- all: produces knowledge.pdf knowledge.sty knowledge-code.pdf README.md"
@echo "- clean"
- @echo "- long: produces knowledge-long.pdf (doc with most code)"
- @echo "- knowledge.zip"
- @echo "- knowledge-sources.zip"
- @echo "- sources"
+ @echo "- knowledge.zip: a minimalistic install"
+ @echo "- ctan: creates the knowledge-ctan.zip file tailored for CTAN"
+ @echo "- sources: creates knowledge-sources-complete.zip"
+ @echo "- publish: personal use"
-all: knowledge.sty knowledge.pdf
+all: knowledge.sty knowledge.pdf knowledge-code.pdf README.md
-knowledge.sty: knowledge.dtx knowledge-utils.dtx knowledge-configuration.dtx
- latex all.ins
+knowledge.sty: knowledge-code.dtx knowledge-utils.dtx knowledge-configuration.dtx knowledge.ins
+ latex knowledge.ins
+README.md: knowledge-code.dtx knowledge.ins
+ latex knowledge.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-code.pdf
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-sources-complete.zip knowledge.zip
rm -f knowledge-ctan.zip
+ rm -f README.md
+ make -CRegression clean
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.pdf: knowledge.tex knowledge.sty
+ pdflatex knowledge.tex
+ pdflatex knowledge.tex
+ pdflatex knowledge.tex
+knowledge-code.pdf: knowledge-code.dtx knowledge.tex knowledge.sty
+ pdflatex knowledge-code.dtx
+ pdflatex knowledge-code.dtx
+ pdflatex knowledge-code.dtx
-knowledge.aux: knowledge.dtx knowledge.sty
- pdflatex knowledge.dtx
-long: knowledge-long.pdf
-
-knowledge-long.pdf:
+knowledge.aux: knowledge.dtx knowledge.sty
pdflatex knowledge.dtx
- pdflatex knowledge.dtx
- pdflatex knowledge.dtx
- mv knowledge.pdf knowledge-long.pdf
-sources: clean knowledge-sources.zip knowledge-sources-complete.zip
+sources: clean knowledge-ctan.zip knowledge-sources-complete.zip
knowledge-sources-complete.zip: clean
\rm -f knowledge-sources-complete.zip
@@ -51,34 +51,26 @@
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
+knowledge-ctan.zip: knowledge.pdf knowledge.sty knowledge.ins README.md makefile
rm -f knowledge-ctan.zip
rm -rf knowledge
mkdir knowledge
cp knowledge.pdf knowledge/
- cp knowledge.dtx knowledge-utils.dtx knowledge-configuration.dtx knowledge/
- cp makefile all.ins knowledge-example.tex README.txt knowledge/
+ cp knowledge.tex knowledge/
+ cp knowledge-code.dtx knowledge-utils.dtx knowledge-configuration.dtx knowledge/
+ cp makefile knowledge.ins knowledge-example.tex README.md 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
+knowledge.zip: knowledge.pdf knowledge.sty knowledge-example.tex README.md
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
+ zip knowledge.zip knowledge.pdf knowledge.sty knowledge.example.tex
-publish: knowledge.zip knowledge-sources.zip
+publish: knowledge.zip knowledge-ctan.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
+ cp knowledge-ctan.zip ~/Travail/Web/public_html/Knowledge/knowledge-sources-`date +%Y-%m-%d`.zip
Deleted: trunk/Master/texmf-dist/source/latex/knowledge/all.ins
===================================================================
--- trunk/Master/texmf-dist/source/latex/knowledge/all.ins 2017-10-19 21:28:59 UTC (rev 45559)
+++ trunk/Master/texmf-dist/source/latex/knowledge/all.ins 2017-10-19 21:29:32 UTC (rev 45560)
@@ -1,55 +0,0 @@
-%%
-%% 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
-
Added: trunk/Master/texmf-dist/source/latex/knowledge/knowledge-code.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/knowledge/knowledge-code.dtx (rev 0)
+++ trunk/Master/texmf-dist/source/latex/knowledge/knowledge-code.dtx 2017-10-19 21:29:32 UTC (rev 45560)
@@ -0,0 +1,3615 @@
+% \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/10/18}{1.07}{}
+%<*driver>
+\def\knowledgecode{active}
+\input{knowledge.tex}
+%</driver>
+% \fi
+%
+% \CheckSum{0}
+%
+%
+% \changes{1.01}{2017/06/11}{Initial version} %
+% \changes{1.02}{2017/06/28}{bug fixes} %
+% \changes{1.03}{2017/07/27}{scoping,bug fixes} %
+% \changes{1.04}{2017/07/28}{minor changes,bug fixes} %
+% \changes{1.05}{2017/09/26}{minor changes,bug fixes} %
+% \changes{1.06}{2017/10/10}{bug correction} %
+% \changes{1.07}{2017/10/15}{minor improvements} %
+% \changes{1.08}{2017/10/17}{minor changes and reorganization of the files} %
+% \GetFileInfo{knowledge.sty} %
+% \DoNotIndex{}
+%
+%
+%\let\ifcode\iffalse
+%
+%%%%%%%%%%
+%
+% \section{Implementation}
+% \label{section:code}
+%
+% \subsection{README.md}
+%
+%<*readme>
+% \begin{macrocode}
+This directory contains the package
+
+ name: knowledge
+ license: LaTeX Project Public License version 1.2 or above
+ version: v1.08
+ date: 2017/10/17
+ author: Thomas Colcombet
+ mail: thomas.colcombet at irif.fr
+ web: https://www.irif.fr/~colcombe/knowledge_en.html
+
+Purpose:
+ The knowledge package for LaTeX offers a systematic way to handle
+ notions/concepts/terms throughout a document. In combination with
+ hyperref, it is used for easily handling links inside a document (every
+ use of a concept is linked to its introduction), or outside the document
+ (for centralizing the url's in a separate part). It also helps building an
+ index, and deals with scoping of concepts as well as mathematics.
+ It is designed to--as much as possible--not interfere with the writing of
+ the document.
+
+Install:
+ It is sufficient to have the file knowledge.sty accessible by LaTeX.
+ It can be produced by `make knowledge.sty' if necessary.
+ The documentation is in the file knowledge.pdf.
+ A starting example can be found in knowledge-example.tex.
+
+Content of the file knowledge-sources.zip:
+ - README.md: this file generated while compiling knowledge.ins,
+ the content is in knowledge-code.dtx
+ - knowledge.sty: the package file (generated using knowledge.ins)
+ - knowledge.pdf: the user documentation (generated by compiling
+ knowledge.tex)
+ - knowledge.tex: the tex file producing the knowledge.pdf.
+ - makefile: the makefile. Use 'make all' to generate knowledge.sty
+ and knowledge.pdf. It can also: clean the directory, make zip
+ version of the sources, or ready for CTAN.
+ - knowledge.ins: is the file generating knowledge.sty and
+ README.md from knowledge-code.dtx (using docstrip).
+ - knowledge-code.dtx: most of the code. Can be compiled to
+ provided a longer documentation.
+ - knowledge-configuration.dtx: file containing part of the configuration.
+ - knowledge-utils.dtx: file containing several pieces of code not really
+ related specifically to knowledge
+ - knowledge-example.tex: an example file.
+
+% \end{macrocode}
+%</readme>
+% \subsection{Code preparation}
+%<*head>
+% \begin{macrocode}
+\RequirePackage{l3keys2e}
+\RequirePackage{etoolbox}
+\RequirePackage{xparse}
+\RequirePackage{etoolbox}
+\bool_if_exist:NTF\knowledge_package_loaded_bool
+ {\endinput}
+ {\bool_new:N\knowledge_package_loaded_bool
+ \bool_set_true:N\knowledge_package_loaded_bool}
+% \end{macrocode}
+% \begin{macrocode}
+% \end{macrocode}
+%</head>
+%\begin{center}
+% The content of \texttt{knowledge-utils.sty} is inserted here.\\
+%\end{center}
+%<*package>\\
+% Macros to skip pieces of code depending on some bool. This can certainly be done differently.
+% \begin{macrocode}
+\cs_new:Nn\knowledge_begin_module_if:n
+ {\bool_if:NF#1\knowledge_skip_module:}
+\cs_new:Npn\knowledge_skip_module:#1\knowledge_end_module:
+ {}
+\cs_new:Nn\knowledge_end_module:
+ {}
+% \end{macrocode}
+%
+%\AP One defines the code of \csintro{\klparse_ifnextchar:NTF}
+% which is a link to \cs{\@ifnextchar},
+% as well as the constant \csintro{\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}
+% \end{macrocode}
+% \begin{macrocode}
+\tl_new:N\klparse_novalue_tl
+\NewDocumentCommand\klparse_setnovalue{o}
+ {\tl_set:Nn\klparse_novalue_tl{#1}}
+\klparse_setnovalue\relax
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Npn\klparse_if_novalue:NTF
+ {\tl_if_eq:NNTF\klparse_novalue_tl}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_generate_variant:Nn\tl_to_str:n{V}
+% \end{macrocode}
+%
+% \subsection{Messages of the package}
+%
+%\AP First, some generic messages that are produced using \csintro{\knowledge_info:n},
+% \csintro{\knowledge_warning:n} and \csintro{\knowledge_error:n}
+% as well as the argument expending versions.
+% These are mainly for development purposes.
+% \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}}
+% \end{macrocode}
+% \begin{macrocode}
+\msg_new:nnnn{knowledge}{knowledge~info}{#1}{#2}
+\msg_new:nnnn{knowledge}{knowledge~warning}{#1}{#2}
+\msg_new:nnnn{knowledge}{knowledge~error}{#1}{#2}
+% \end{macrocode}
+% \begin{macrocode}
+\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}
+%\AP We provide now the `official' messages \csintro{knowledge~recursion}, \csintro{knowledge~unknown},
+% \csintro{knowledge~unknown~in~scope}, \csintro{knowledge~unknown~label}, \csintro{package~required} and \csintro{knowledge~exists}.
+% \begin{macrocode}
+\msg_new:nnn{ knowledge }{ knowledge~recursion }
+ { The~knowledges~are~probably~cyclic,~starting~from~'#1'~(namespace~'#2'),~
+ currently~at~'#3'.}
+% \end{macrocode}
+% \begin{macrocode}
+\msg_new:nnn{ knowledge }{ knowledge~unknown }
+ {The~knowledge~'#1'~could~not~be~found~in~scopes~<~#3~>~(namespace~'#2').}
+% \end{macrocode}
+% \begin{macrocode}
+\msg_new:nnn{ knowledge }{ knowledge~unknown~in~scope }
+ {The~knowledge~'#1'~could~not~be~found~in~scope~'#3'~(namespace~'#2').}
+% \end{macrocode}
+% \begin{macrocode}
+\msg_new:nnn{ knowledge }{ knowledge~unknown~label }
+ {The~label~'#2'~could~not~be~found~while~searching~for~'#1'.~Possibly~rerun~latex.}
+% \end{macrocode}
+% \begin{macrocode}
+\msg_new:nnn{ knowledge }{ package~required }
+ {In~order~to~use~directive~'#1',~please~load~package~or~use~option~'#2'.}
+% \end{macrocode}
+% \begin{macrocode}
+\msg_new:nnn{ knowledge }{ knowledge~exists }
+ { The~knowledge~'#1'~in~scope~'#2'~(namespace~'#3')~already~exists. }
+% \end{macrocode}
+%
+%\AP The messages when there is a problem with scoping are \csintro{area~exists}, \csintro{area~not~exist},
+% \csintro{empty~pop}, \csintro{no~pushing~here}, \csintro{no~popping},
+% \csintro{no~popping~here}, \csintro{unknown~label} and \csintro{area~not~in~context}.
+% \begin{macrocode}
+\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}
+%\AP We define new the final messages, that are thrown at the end of the compilation as a recap that some problems occured. These are: \csintro{recap~unknown~knowledge}, \csintro{recap~autoref~introduced~twice} and \csintro{recap~autoref~not~introduced}.
+% \begin{macrocode}
+\msg_new:nnn{knowledge}{recap~unknown~knowledge}
+ {Some~knowledge~are~not~defined.~See~the~'.diagnose'~file~for~more~information.}
+\msg_new:nnn{knowledge}{recap~autoref~introduced~twice}
+ {Some~knowledge~is~introduced~twice.~See~the~'.diagnose'~file~for~more~information.}
+\msg_new:nnn{knowledge}{recap~autoref~not~introduced}
+ {Some~knowledge~is~used~but~not~introduced.~See~the~'.diagnose'~file~for~more~information.}
+% \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 \cs{\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 \csintro{\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.
+%
+% \ToImprove{I do not know why, but \cs{\ProcessKeysOptions} removes the spaces in the parameters.
+% So we have to do the same if we want to load options this way. This does not seem canonical.}
+%
+% We first provide a token list that stores the configurations (which are different from the options).
+% \begin{macrocode}
+\tl_clear_new:N\knowledge_configuration_pending_tl
+% \end{macrocode}
+%
+%
+% \paragraph{Configuration options}
+% We provide here the code that is used to create new options for \cs{\knowledgeconfigure}.
+% At the same time, it sets at package loading these options to be `posponed' (these will be executed)
+% when the package loading is completed.
+% \begin{macrocode}
+\newrobustcmd\knowledgeconfigure[1]{
+ \keys_set:nn{ knowledge~configuration~options }{#1}
+}
+% \end{macrocode}
+%
+% \begin{quote}
+% \csintro{\KnowledgeConfigureBooleanOption}[\cs{optional_bool}]\{option name\}\par
+% \csintro{\KnowledgeConfigureBooleanOptionTF}[\cs{optional_bool}]\{option name\}\par
+% ~~~~~~~~\{true code\}\{false code\}
+% \end{quote}
+% It takes an optional bool (of \kl(package){expl3}) and the name of the configuration option.
+% The option is defined both in \cs{knowledge~package~options},
+% and in \cs{knowledge~configuration~options}.
+% In the former case, the option is simply appended to \cs{\knowledge_configuration_pending_tl} for
+% being executed at the end of package loading.
+% \begin{macrocode}
+\NewDocumentCommand\KnowledgeConfigureBooleanOption{om}
+ {\KnowledgeConfigureBooleanOptionTF[#1]{#2}{}{}}
+\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}
+}}
+% \end{macrocode}
+%\begin{quote}\tt
+% \csintro{\KnowledgeConfigureTrigger}\{option name\}\{code\}
+%\end{quote}
+% triggers the code when the corresponding configuration option is required.
+% \begin{macrocode}
+\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}} }}
+ }
+}
+% \end{macrocode}
+%
+%
+%
+% \paragraph{Package loading options}
+%
+% \begin{quote}\tt
+% \csintro{\KnowledgePackageTrigger}\{package option\}\{code\}
+% \end{quote}
+% is similar to \cs{\KnowledgeConfigureTrigger} but only valid at package loading and not in \cs{\knowledgeconfigure}.
+% \begin{macrocode}
+\newrobustcmd\KnowledgePackageTrigger[2]
+ { \keys_define:nn{ knowledge~package~options }{ #1 .code:n = {#2} }
+ \keys_define:nn{ knowledge~configuration~options }{
+ #1 .code:n = {\knowledge_error:n
+ {The~configuration~directive~`#1'~can~only~be~used~at~package~loading.}}
+ }}
+% \end{macrocode}
+% \begin{quote}\tt
+% \csintro{\KnowledgePackageBooleanOption}[\cs{optional_bool}]\{optionname\}
+% \end{quote}
+% defines a Boolean package option, the value of which being stored in \cs{optional_bool}.
+% If no \cs{optional_bool} is given, then \cs{\knowledge_configuration_optioname_bool}
+% is chosen.
+% \begin{macrocode}
+\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 = {\knowledge_error:n
+ {The~configuration~directive~`#2'~can~only~be~used~at~package~loading.}}
+ }}
+% \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}
+%
+%
+% \subsubsection{List of options that have to be prepared}
+%
+% Code for a single feature. It takes the name of the trigger followed by the code.
+%
+% \begin{macrocode}
+\bool_new:N\knowledge_configuration_quotation_bool
+\KnowledgeConfigureBooleanOptionTF[\knowledge_configuration_quotation_bool]{quotation}{\klactivatequotation}{\kldeactivatequotation}
+\KnowledgeConfigureTrigger{protect~quotation}{\kl_protect_environment_quotation:n{#1}}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\bool_new:N\knowledge_configuration_diagnoseline_bool
+\bool_gset_false: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 are stored in \csintro{\knowledge_option_mode_tl}.
+% \begin{macrocode}
+\tl_clear_new:N\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}
+%
+%\csintro{\knowledge_xcolor_active_bool}, \csintro{\knowledge_xcolor_syntax_bool},
+%\csintro{\knowledge_hyperref_active_bool}, \csintro{\knowledge_hyperref_syntax_bool},
+%\csintro{\knowledge_makeidx_active_bool}, \csintro{\knowledge_makeidx_syntax_bool}
+%
+% First, one tests the package available.
+% \csintro{\package_if_loaded:nTF} tests if a package is loaded.
+% \csintro{\knowledge_option_aci_test_loaded:n} uses it for setting the default values of the booleans
+% \begin{compactitem}
+% \item \csintro{\knowledge_packagename_active_bool} that sets all the functionalities linked to the corresponding package to be active.
+% \item \csintro{\knowledge_packagename_syntax_bool} that states that the syntax is allowed.
+% \end{compactitem}
+% \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}
+%\begin{quote}\tt
+%\csintro{\knowledge_option_aci_define:n}\{package name\}
+%\end{quote}
+% defines the different possible ways to use the package.
+% \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{quote}\tt
+% \csintro{\knowledge_option_aci_autoload:nn}\{package name\}\{options for the package\}
+% \end{quote}
+% is called for each package after the options have been processed.
+% It loads the package if required, possibly with options.
+% \begin{macrocode}
+\cs_new:Nn\knowledge_option_aci_autoload:nnn{
+ \bool_if:cTF{knowledge_#1_active_bool}
+ {\package_if_loaded:nTF{#1}{}
+ {\RequirePackage[#2]{#1}{#3}}}
+ {}
+}
+\cs_new:Nn\knowledge_option_aci_autoload:nn
+ {\knowledge_option_aci_autoload:nnn{#1}{#2}{}}
+% \end{macrocode}
+%
+% \paragraph{The real 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}
+%
+% \subsubsection{Executing the package options}
+%
+% \begin{macrocode}
+\ProcessKeysOptions{knowledge~package~options}
+% \end{macrocode}
+%
+% \subsubsection{Options post treatment for the "writing mode"}
+%
+% \begin{macrocode}
+
+\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
+% \end{macrocode}
+% Testing if the "writing mode" has been chosen by setting \cs{\knowledgepackagemode}.
+% \begin{macrocode}
+\tl_if_exist:NTF\knowledgepackagemode
+ {}
+ {\tl_new:N\knowledgepackagemode
+ \tl_set:Nn\knowledgepackagemode{}}
+% \end{macrocode}
+% \begin{macrocode}
+\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
+ }}
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
+\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}
+%
+%
+% \subsubsection{Options post-treatment for the other packages}
+% \begin{macrocode}
+\knowledge_option_aci_autoload:nnn{ hyperref }{}{\hypersetup{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_const:Nn\scope_tl{SC at PE}
+\tl_const:Nn\scopept_tl{SC at PE2}
+% \end{macrocode}
+% \csintro{\scope_instances_stack_seq} contains the stack of instances of areas.
+% \csintro{\scope_top_instance_tl} contains always the topmost instance of the stack.
+% \csintro{\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[\csintro{nesting_int}] is an int counting the nesting level of the area at the current moment.
+% \item[\csintro{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[\csintro{name_tl}] is the text name of the \kl{area}.
+% \item[\csintro{pushcode_tl}] is code to be executed when an \kl{instance} of the \kl{area} is created.
+% \item[\csintro{popcode_tl}] is code to be executed just before an \kl{instance} of the \kl{area} is closed.
+% \item[\csintro{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[\csintro{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[\csintro{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[\csintro{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[\csintro{acceptsknowledge_bool}] is a boolean telling whether a knowledge can be associated to an instance of this area.
+% \item[\csintro{labelizable_bool}] tells whether a label can point to such an environment.
+% \item[\csintro{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[\csintro{mandatorybase_seq}] is a \texttt{seq} containing the list of categories that are allowed to
+% be the parent of this area. For instance, \cs{\item}
+% would have \texttt{itemize}, \texttt{compactdesc} and \texttt{enumerate}.
+% \end{compactdesc}
+%
+% \begin{macrocode}
+\tl_new:N\l_self_tl
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\scope_area_show:n{
+ \group_begin:
+ \scope_area_if_exist:nTF{#1}
+ { \tl_set:Nx\l_self_tl{\scope_tl.area[#1]}
+ \tl_show:x
+ {Area~name:~\use:c{\l_self_tl.name_tl},~
+ autoclose=\bool_if:cTF{\l_self_tl.autoclose_bool}TF,~
+ recursive=\bool_if:cTF{\l_self_tl.recursive_bool}TF,~
+ multiple=\bool_if:cTF{\l_self_tl.multiple_bool}TF,~
+ scope=\bool_if:cTF{\l_self_tl.scope_bool}TF,~
+ environment=\bool_if:cTF{\l_self_tl.environment_bool}TF,~
+ forces={\use:c{\l_self_tl.forces_tl}},~
+ accepts~knowledge=\bool_if:cTF{\l_self_tl.accepts_knowledge_bool}TF,~
+ attracts~knowledge=\bool_if:cTF{\l_self_tl.attracts_knowledge_bool}TF,~
+ accepts~labels=\bool_if:cTF{\l_self_tl.labelizable_bool}TF.
+ }
+ }
+ {\knowledge_error:n{Unknown~area~`#1'~in~`\noexpand\scope_area_show:n'.}}
+ \group_end:
+}
+% \end{macrocode}
+%
+%
+%
+% Areas are created empty by \cs{\scope_area_create:n}.
+% \begin{macrocode}
+\cs_new:Nn\scope_area_create:n
+ {\group_begin:
+ \tl_set:Nx\l_self_tl{\scope_tl.area[#1]}
+ %
+ \scope_category_add_area:nn{all}{#1}
+ %
+ \tl_new:c{\l_self_tl.name_tl}
+ \tl_gset:cn{\l_self_tl.name_tl}{#1}
+ \seq_new:c{\l_self_tl.category_seq}
+ \seq_gpush:cn{\l_self_tl.category_seq}{all}
+ \seq_gpush:cn{\l_self_tl.category_seq}{#1}
+ \bool_new:c{\l_self_tl.autoclose_bool}
+ \bool_gset_false:c{\l_self_tl.autoclose_bool}
+ \bool_new:c{\l_self_tl.environment_bool}
+ \bool_gset_true:c{\l_self_tl.environment_bool}
+ \bool_new:c{\l_self_tl.multiple_bool}
+ \bool_gset_true:c{\l_self_tl.multiple_bool}
+ \bool_new:c{\l_self_tl.attractsknowledge_bool}
+ \bool_gset_true:c{\l_self_tl.attractsknowledge_bool}
+ \bool_new:c{\l_self_tl.labelizable_bool}
+ \bool_gset_true:c{\l_self_tl.labelizable_bool}
+ \bool_new:c{\l_self_tl.scope_bool}
+ \bool_gset_false:c{\l_self_tl.scope_bool}
+ \bool_new:c{\l_self_tl.acceptsknowledge_bool}
+ \bool_gset_true:c{\l_self_tl.acceptsknowledge_bool}
+ \bool_new:c{\l_self_tl.recursive_bool}
+ \tl_gclear_new:c{\l_self_tl.pushcode_tl}
+ \tl_gclear_new:c{\l_self_tl.popcode_tl}
+ \tl_gclear_new:c{\l_self_tl.forces_tl}
+ \seq_new:c{\l_self_tl.mandatorybase_seq}
+ \int_new:c{\l_self_tl.count_int}
+ \int_gset:cn{\l_self_tl.count_int}{0}
+ \int_new:c{\l_self_tl.nesting_int}
+ \int_gset:cn{\l_self_tl.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}
+%
+%
+% \cs{\scope_area_if_exist:nTF}, \cs{\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 \cs{\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 \csintro{\ScopeConfigure}\{area~list\}\{directives\}.
+% \begin{macrocode}
+\newrobustcmd\ScopeConfigure[2]
+ {\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}}}
+% \end{macrocode}
+% \begin{macrocode}
+\tl_new:N\scope_area_tl
+\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\l_self_tl{\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{\l_self_tl.autoclose_bool}},
+ autoclose / true .code:n =
+ {\bool_gset_true:c{\l_self_tl.autoclose_bool}},
+ parents .code:n =
+ {\seq_gset_from_clist:cn{\l_self_tl.mandatorybase_seq}{#1}},
+ push~code .code:n =
+ {\tl_gput_right:cn{\l_self_tl.pushcode_tl}{#1}},
+ pop~code .code:n =
+ {\tl_gput_right:cn{\l_self_tl.popcode_tl}{#1}},
+ occurrences .choice:,
+ occurrences / once .code:n =
+ {\bool_gset_false:c{\l_self_tl.multiple_bool}
+ \bool_gset_false:c{\l_self_tl.recursive_bool}},
+ occurrences / multiple .code:n = {
+ \bool_gset_true:c{\l_self_tl.multiple_bool}
+ \bool_gset_false:c{\l_self_tl.recursive_bool}},
+ occurrences / recursive .code:n = {
+ \bool_gset_true:c{\l_self_tl.multiple_bool}
+ \bool_gset_true:c{\l_self_tl.recursive_bool}},
+ scope .choice:,
+ scope / true .code:n = {
+ \bool_gset_true:c{\l_self_tl.scope_bool}},
+ scope / false .code:n = {
+ \bool_gset_false:c{\l_self_tl.scope_bool}},
+ environment .choice:,
+ environment / true .code:n = {
+ \bool_gset_true:c{\l_self_tl.environment_bool}},
+ environment / false .code:n = {
+ \bool_gset_false:c{\l_self_tl.environment_bool}},
+ environment .default:n = {true},
+ label .choice:,
+ label / none .code:n = {
+ \bool_gset_false:c{\l_self_tl.labelizable_bool}},
+ label / accepts .code:n = {
+ \bool_gset_true:c{\l_self_tl.labelizable_bool}},
+ knowledge .choice:,
+ knowledge / none .code:n = {
+ \bool_gset_false:c{\l_self_tl.acceptsknowledge_bool}
+ \bool_gset_false:c{\l_self_tl.attractsknowledge_bool}},
+ knowledge / accepts .code:n = {
+ \bool_gset_true:c{\l_self_tl.acceptsknowledge_bool}
+ \bool_gset_false:c{\l_self_tl.attractsknowledge_bool}},
+ knowledge / attracts .code:n = {
+ \bool_gset_true:c{\l_self_tl.acceptsknowledge_bool}
+ \bool_gset_true:c{\l_self_tl.attractsknowledge_bool}},
+ forces .code:n =
+ {\tl_gset:cn{\l_self_tl.forces_tl}{#1}}
+}
+% \end{macrocode}
+%
+% \paragraph{Categories}
+%
+%\begin{compactdesc}
+% \item[\csintro{\scope_category_if_exist:nTF}] tests if a \kl{category} does exist.
+% \item[\csintro{\scope_category_ensure:n}] guarantees that a \kl{category} exists, possibly creating it if necessary.
+% \item[\csintro{\scope_category_create:n}] creates a \kl{category}.
+% \item[\csintro{\scope_category_add_area:nn}] adds an \kl{area} to a \kl{category}.
+% \item[\csintro{\scope_category_use:n}] displays the \kl{category} as a comma separated list of \kl{area} names (expandable).
+% \item[\csintro{\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_new:c{\scope_tl.category[#1].name_tl}
+ \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[\csintro{\scope_instance_if_exist:nTF}]
+% \item[\csintro{\scopept_instance_if_exist:nTF}]
+% \item[\csintro{\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 \csintro{\scope_area_push:n} and \csintro{\scope_area_pop:n}.
+%
+% The token lists \csintro{\scope_popped_area_tl} and \csintro{\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_new:c
+ {\scope_tl.instance[\scope_top_instance_tl].area_tl}
+ \tl_gset:cx
+ {\scope_tl.instance[\scope_top_instance_tl].area_tl}
+ {\scope_top_area_tl}
+ \tl_new:c
+ {\scope_tl.instance[\scope_top_instance_tl].parent_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_new:c
+ {\scopept_tl.instance[\scope_top_instance_tl].context_seq}
+ \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}
+%
+% \csintro{\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 \cs{\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 \cs{\label} command is used.
+% This requires to overload it for it to write on the \kl{kaux file}.
+% Thus, the new \cs{\label} command executes the original code,
+% and furthermore writes in the \kl{kaux file} a \cs{\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_new: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
+\cs_new:Npn\knowledge_latex_label:n{
+ \cs_if_exist:NTF\LaTeXlabel\LaTeXlabel\label
+}
+% \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_new:cn{\scopept_tl.instance[#2].area_tl}{#1}
+ \tl_new: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_if_exist:cTF{\scopept_tl.label[#1].instance_tl}{}
+ {\tl_new: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 \cs{\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{}
+ { \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}
+
+\tl_new:N\knowledge_diagnose_lastline_tl
+\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}}}
+
+\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}{recap~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}{recap~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}{recap~autoref~not~introduced}
+ }
+ \int_compare:nNnT\kl_digest_autorefunused_int>0{
+ \knowledge_diagnose:n{***********************************}
+ \knowledge_diagnose:n{*~Autoref~introduced~but~not~used~*}
+ \knowledge_diagnose:n{***********************************}
+ \knowledge_diagnose:n{}
+ %
+ \knowledge_diagnose_reset_line:
+ \KAuxProcess{autoref-introduced-not-used}
+ %
+ \knowledge_diagnose:n{}
+ \knowledge_diagnose:n{}
+ %
+ }
+ %
+ \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 \cs{\knowledge_namespace_tl}
+% stores the current namespace, i.e. the ones that is used by default.
+% It is sometimes temporarily modified.
+% \begin{macrocode}
+\tl_new:Nn\knowledge_default_namespace_tl {default}
+% \end{macrocode}
+% The macro
+% \begin{code}
+% \csintro{\knowledge_id:nnn}\{namespace\}\{instance\}\{knowledge key\}
+% \end{code}
+% takes these three arguments in
+% this order (namespace/instance/scope) and produces a unique string that can be used to access
+% (using \cs{\csname}, or \texttt{:c} in LaTeX3) the tuple.
+% \begin{macrocode}
+\makeatother
+\cell_new_type:nnn{knowledge}{nnnn}{KL@#2@#3@\tl_to_str:n{#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
+% \begin{code}
+% \csintro{\knowledge_sets_to:nnn}\{namespace\}\{knowledge key\}\{scope\}
+% \end{code}
+% which is followed by the same three arguments.
+% It defines
+% \begin{code}
+% \csintro{\knowledge_at:N}\cs{\token}
+% \end{code} that executes \cs{\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 \cs{ktuples}
+% for storing the \kl{knowledges}.
+% \begin{macrocode}
+\tuple_new:n{ktuple}
+% \end{macrocode}
+% Some more code for testing if a "knowledge" is defined:
+% \begin{code}
+% \csintro{\knowledge_knowledge_if_exist:nnnTF}\{namespace\}\{instance\}\{key\}\par
+% ~~~~~~~\{true code\}\{false code\}
+% \end{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{Generalities}
+%
+% The \cs{\knowledge} command is dealt in several steps.
+% \begin{asparaitem}
+% \item In a first phase, the "directives" are parsed using the keys \csintro{knowledge~directives}.
+% During this phase, all the information concerning the target is fixed, as well as other pieces of informations
+% such as the real reference of the "autoref" directive. The result is gathered in a second comma separated
+% list of directives
+% \item Then, depdnging on the targetting information, the
+% \end{asparaitem}
+% Essentially, the \cs{\keys_define:nn}\verb|{ knowledgenow~directives }|(...)
+% commands used throughout the code are here to add new functionalities to it.
+%
+%
+% \subsubsection{Defining directives}
+%
+%
+% The commands used for introducing new directives.
+% The command
+% \begin{code}
+% \csintro{\NewKnowledgeParamBool}[*]\{name\}\cs{\token}
+% \end{code}
+% creates a new boolean directive of name `name'.
+% When the knowledge is executed, the value will be stored in the \cs{\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 \cs{\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}
+ \bool_new:N#3
+ \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
+% \AP The command \cs{\NewKnowledgeParamTl} is similar to \cs{\NewKnowledgeParamBool},
+% but creates a directive that stores text.
+% \begin{code}
+% \csintro\NewKnowledgeParamTl*[\cs\token]\{name\}
+% \end{code}\noindent
+% \iffalse
+% \begin{macrocode}
+\NewDocumentCommand\NewKnowledgeParamTl{som}{
+ %\tl_show:n{#2}
+ \IfNoValueTF{#2}
+ { \tl_set:Nn\l_tmpa_tl{#3}
+ \tl_remove_all:Nn\l_tmpa_tl{~}
+ \use:x{
+ \exp_not:N\NewKnowledgeParamTl
+ \IfBooleanT{#1}{*}
+ [\exp_not:c{knowledge_kl_\l_tmpa_tl _tl}]
+ {#3}
+ }}
+ {\cs_if_exist:cTF{ktuple_#3_expands_to:n}
+ {}
+ {\ktuple_new_tl_index:n{#3}}
+ \tl_if_exist:NTF#2{}
+ {\tl_new:N#2}
+ \use:c{ktuple_#3_expands_to:n}
+ {\tl_set:Nn#2{##1}}
+ %
+ \keys_define:nn { knowledgenow~directives }{
+ #3 .code:n =
+ { \knowledge_at:c{ktuple_#3_gset:Nn}{##1} },
+ #3~X .code:n =
+ { \knowledge_at:c{ktuple_#3_gset:Nx}{##1} },
+ no~#3 .code:n =
+ { \knowledge_at:c{ktuple_#3_gdel:N} }}
+ \IfBooleanTF{#1}{\KnowledgeTransferTl{#3}}{}
+}}
+% \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 \cs{\NewKnowledgeParamCode} is similar to \cs{\NewKnowledgeParamBool},
+% but creates a directive that stores code. There is no optional star for code (never directly accessible to the user).
+% \begin{code}\AP
+% \csintro\NewKnowledgeParamCode\{name\}\cs{\token}
+% \end{code}\noindent
+% \begin{macrocode}
+\NewDocumentCommand\NewKnowledgeParamCode{mm}{
+ \ktuple_new_tl_index:n{#1}
+ \tl_new:N#2
+ \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 \cs{\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}
+% \csintro\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{Scope basics}
+%
+%
+% \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.
+%
+% In this part of the code, we provide a small number of commands for dealing with instances.
+% The real code that computes the current context of scope if later.
+%
+%
+% \begin{compactdesc}
+% \item[\csintro{\knowledge_current_instance_tl}] contains the current
+% instance to be used.
+% \item[\cs{\knowledge_visible_instances_seq}] contains the sequence
+% of instances that are visible right now.
+% \item[\csintro{\knowledge_scope_track_instance:Nn}\cs\tokenlist\{scope name\}]
+% sets \cs{\tokenlist} to the outermost instance of the scope name.
+% Typically, if the request is `\texttt{subsection}', the answer will be `\texttt{subsection-3.1}',
+% identifying the subsection currently in scope.
+% \end{compactdesc}
+% \begin{macrocode}
+\tl_new:N\knowledge_current_instance_tl
+\tl_gset:Nn\knowledge_current_instance_tl{base}
+% \end{macrocode}
+%
+% \AP The sequence \csintro{\knowledge_visible_instances_seq} contains the
+% "instances" that are visible right now. This are searched through when
+% a knowledge is used. The leftmost instance is the most important one (innermost scope).
+% Note that \cs{\knowledge_visible_instances_seq} may only be correct after one compilation.
+% \begin{compactdesc}
+% \item[\csintro{\knowledge_push_visible_instance:n}]
+% \item[\csintro{\knowledge_pop_visible_instance:}]
+% \item[\csintro{\knowledge_pop_visible_instances_to:n}]
+% \item[\csintro{\knowledge_show_visible_instances:}]
+% \end{compactdesc}
+%
+% \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: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{,}>}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_import_instance:n
+ {\seq_if_in:NnTF\knowledge_visible_instances_seq{#1}
+ {}{\knowledge_push_visible_instance:n{#1}}}
+% \end{macrocode}
+% \begin{macrocode}
+\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}
+%%
+% \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 \csintro{\KAuxKnowledge} command is added to the \kl{kaux file} when
+% \cs{\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}
+\newrobustcmd\KAuxExport[4]
+ {Package~knowledge:~undefined~so~far.}
+% \end{macrocode}
+%
+%\AP \csintro{\knowledge_set_now:nnnn}\cs{{}} takes the three parameters defining a knowledge and a list of \kl{knowledgenow directives}, checks that it was not existing before, and
+% then calls the \cs{\keys_set:nn}\{knowledgenow directives\} for defining it.
+% \begin{macrocode}
+\cs_new:Nn\knowledge_new_now:nnnn
+ {\knowledge_sets_to:nnn{#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_new:Nn\knowledge_set_now:nnnn
+ {\knowledge_sets_to:nnn{#1}{#2}{#3}
+ \knowledge_at:N\ktuple_if_exist:NTF
+ {\bool_if:NTF\knowledge_knowledgestyle_bool
+ {\knowledge_at:N\ktuple_gclear:N}
+ {}}
+ {\knowledge_at:N\ktuple_new:N}
+ \keys_set:nn { knowledgenow~directives } { #4 }
+}
+\cs_generate_variant:Nn\knowledge_new_now:nnnn{nnVn}
+\cs_generate_variant:Nn\knowledge_set_now:nnnn{nnVn}
+% \end{macrocode}
+%
+%
+%\AP We can now define the \cs{\knowledge} command itself.
+% It starts by writing the line number in the \kl{kaux file}
+% using \cs{\KAuxWriteLocation}, and then proceeds with \cs{\__knowledge_knowledge}.
+% \begin{macrocode}
+\NewDocumentCommand\knowledge{}
+ {\KAuxWriteLocation\__knowledge_knowledge}
+% \end{macrocode}
+% The command \csintro{\__knowledge_knowledge} is the center of the \cs{\knowledge}
+% command. It parses its arguments (in particular separating the synonyms using the "xparse@@package"), and executes \cs{\knowledge_knowledge_process:nn}
+% \begin{macrocode}
+\NewDocumentCommand\__knowledge_knowledge{m >{\SplitList{|}}o m }
+{ \kl_hide_begin:
+ \group_begin:
+ \tl_set_eq:NN\knowledge_namespace_tl
+ \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\knowledge_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:
+}
+% \end{macrocode}
+%
+%\AP The boolean \cs{\knowledge_knowledgestyle_bool}
+% is set to true in order \cs{\knowledge_knowledge_process:nn}
+% to know if it has been triggered by \cs{\knowledge}
+% or \cs{\knowledgestyle}.
+% \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}
+%
+%
+%
+%
+%
+%\AP The \cs{\knowledge_knowledge_process:nn} command is the internal
+% version of \cs{\knowledge}. It takes two parameters:
+% the key, and the comma separated list of directives.
+% \begin{macrocode}
+\bool_new:N\knowledge_knowledgestyle_bool
+\bool_new:N\knowledge_knowledgestyle_override_bool
+\bool_new:N\knowledge_knowledge_now_bool
+\bool_new:N\knowledge_knowledge_alsonow_bool
+\bool_new:N\knowledge_knowledge_is_synonym_bool
+\bool_new:N\knowledge_knowledge_autoref_bool
+\tl_clear_new:N\knowledge_knowledge_synonym_tl
+\tl_clear_new:N\knowledge_knowledge_synonyminstance_tl
+\tl_clear_new:N\knowledge_knowledge_clear_bool
+\tl_clear_new:N\knowledge_knowledge_force_bool
+\tl_clear_new:N\knowledge_knowledge_export_bool
+\tl_clear_new:N\knowledge_knowledge_key_tl
+\tl_clear_new:N\knowledge_knowledge_namespace_tl
+\tl_clear_new:N\knowledge_knowledge_instance_tl
+\tl_clear_new:N\knowledge_knowledge_directives_tl
+% \end{macrocode}
+% The macro \csintro{\knowledge_knowledge_process:nn}
+% is the heart of \cs{\knowledge} command.
+% \begin{macrocode}
+\cs_new:Nn\knowledge_knowledge_process:nn
+{ \bool_set_false:N\knowledge_knowledge_clear_bool
+ \bool_set_false:N\knowledge_knowledge_force_bool
+ \bool_set_false:N\knowledge_knowledge_export_bool
+ \bool_set_false:N\knowledge_knowledge_autoref_bool
+ \bool_set_false:N\knowledge_knowledge_now_bool
+ \bool_set_false:N\knowledge_knowledge_alsonow_bool
+ %
+ \tl_set:Nn\knowledge_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_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_new_now:nnnn
+ {\knowledge_knowledge_namespace_tl}
+ {\knowledge_knowledge_instance_tl}
+ {\exp_not:V\knowledge_knowledge_key_tl}
+ {\exp_not:V\knowledge_knowledge_directives_tl}}
+ }{}
+ \bool_if:nTF{\knowledge_knowledge_alsonow_bool}
+ {\use:x{
+ \exp_not:N\knowledge_set_now:nnnn
+ {\knowledge_knowledge_namespace_tl}
+ {\knowledge_knowledge_instance_tl}
+ {\exp_not:V\knowledge_knowledge_key_tl}
+ {\exp_not:V\knowledge_knowledge_directives_tl}}
+ }{}
+ \bool_if:NTF\knowledge_knowledge_now_bool
+ {}
+ { \KAuxWriteX*{
+ \exp_not:N\KAuxKnowledge
+ {\knowledge_knowledge_namespace_tl}
+ {\knowledge_knowledge_instance_tl}
+ {\exp_not:V\knowledge_knowledge_key_tl}
+ {\exp_not:V\knowledge_knowledge_directives_tl}}
+ }
+ \bool_if:NT\knowledge_knowledge_autoref_bool
+ {\KAuxWriteX*
+ {\exp_not:N\KAuxAutoref
+ {\knowledge_knowledge_namespace_tl}
+ {\knowledge_knowledge_instance_tl}
+ {\exp_not:V\knowledge_knowledge_key_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_knowledge_key_tl}
+ {\exp_not:V\knowledge_knowledge_directives_tl}}
+ }
+}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_delay_directive:n
+ {\tl_if_empty:NTF\knowledge_knowledge_directives_tl
+ {\tl_set:Nn\knowledge_knowledge_directives_tl{#1}}
+ {\tl_put_right:Nn\knowledge_knowledge_directives_tl{,#1}}}
+\cs_generate_variant:Nn\knowledge_delay_directive:n{x}
+% \end{macrocode}
+%
+%
+%
+% \subsubsection{The \cs{\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 \cs{\knowledgedefault} command}
+%
+% It uses internally the variable \csintro{\knowledge_knowledgedefault_tl}.
+% \begin{macrocode}
+\tl_new:N\knowledge_knowledgedefault_tl
+\NewDocumentCommand\knowledgedefault{sm}{
+ \kl_hide_begin:
+ \IfBooleanTF{#1}
+ {\tl_put_right:Nn\knowledge_knowledgedefault_tl{,#2}}
+ {\tl_set:Nn\knowledge_knowledgedefault_tl{#2}}
+ \kl_hide_end:
+}
+% \end{macrocode}
+%
+%
+% \subsubsection{Main \cs{\kl} code}
+%
+%
+% The \cs{\kl}, and its internal version \cs{\klTKS} are the central ones in the package. Indeed, all commands such as \cs{\intro}, \cs{\phantomintro}, \cs{\reintro} or the \kl{"... at ...@..."} notation eventually end to a call to these functions.
+%
+% Essentially, \cs{\kl} parses its parameters, and then call its internal version \cs{\knowledge_klTKS:nnn}
+% with proper parameters: Text, Knowledge, Scope (the scope can be empty):
+% \begin{macrocode}
+\NewDocumentCommand\__kl:w{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, \cs{\knowledge_klTKS:nnn} is the internal version of \cs{\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 \cs{\klTKS} which can be used, and does not require the \kl(package){expl3} syntax.
+% \begin{macrocode}
+\tl_clear_new:N\knowledge_kl_text_tl
+\tl_clear_new:N\knowledge_kl_base_key_tl
+\tl_clear_new:N\knowledge_kl_key_tl
+\tl_clear_new:N\knowledge_kl_autoref_tl
+\tl_clear_new:N\knowledge_kl_resourcetoken_tl
+\tl_clear_new:N\knowledge_kl_resourcearguments_tl
+\tl_clear_new:N\knowledge_kl_display_process_tl
+\tl_clear_new:N\knowledge_kl_display_sequence_tl
+\tl_new:N\knowledge_namespace_tl
+\tl_new:Nn\knowledge_display_code_tl{INTERNAL~ERROR~DISPLAY~CODE}
+% \end{macrocode}
+% \begin{macrocode}
+\NewDocumentCommand\klTKS{}{\knowledge_klTKS:nnn}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_klTKS:nnn{
+ \group_begin:
+ %
+ \tl_set:Nn\knowledge_kl_linkscope_tl{#3}
+ \tl_set:Nn\knowledge_kl_instance_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
+ %
+ \tl_if_exist:cTF
+ {knowledge_kl_\tl_to_str:V\knowledge_kl_modifiers_tl _init_tl}
+ {\use:c{knowledge_kl_\tl_to_str:V\knowledge_kl_modifiers_tl _init_tl}}
+ {\knowledge_error:x
+ {Unknown~variant~modifier~sequence~`\exp_not:V\knowledge_kl_modifiers_tl'.}}
+ %
+ \knowledge_kl_modifiers_reset:
+ %
+ \knowledge_kl_use_styles:x{\knowledge_kl_default_style_tl}
+ %
+ \knowledge_kl_find:
+ \group_end:
+ \knowledge_display_code_tl
+}
+% \end{macrocode}
+%
+% At this step, the code has launched \cs{\knowledge_kl_find:}
+% Internally, it counts using \cs{\knowledge_kl_recursion_int}
+% the number of indirections, and bounds
+% starting from the integer \cs{\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 \cs{\kl} command is \csintro{\knowledge_kl_find:}.
+% It uses the variables \cs{\knowledge_kl_recursion_int} for checking non-recursion.
+% It searches for the entry \cs{\knowledge_kl_key_tl}, either in searching in the \kl{stack of visible scope instances},
+% or following \cs{\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:{
+ \knowledge_kl_find_recursion_exceeded:TF
+ {\knowledge_kl_error_recursion:}
+ {\tl_if_empty:NTF\knowledge_kl_instance_tl
+ {\tl_if_empty:NTF\knowledge_kl_linkscope_tl
+ \knowledge_kl_find_withoutscope:
+ \knowledge_kl_find_withscope:}
+ \knowledge_kl_find_withinstance:}
+}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_set:Npn\knowledge_kl_find_recursion_exceeded:TF{
+ \int_decr:N\knowledge_kl_recursion_int
+ \int_compare:nNnTF\knowledge_kl_recursion_int=0
+}
+% \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_instance_tl
+ \knowledge_kl_key_tl
+ {\knowledge_kl_exec:nnV
+ \knowledge_kl_namespace_tl
+ \knowledge_kl_instance_tl
+ \knowledge_kl_key_tl}
+ { \knowledge_kl_error_unknown_in_scope_firsttime: }
+}
+\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_instance_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:{
+ \knowledge_kl_find_in_scope:VNTF
+ \knowledge_kl_key_tl
+ \knowledge_kl_instance_tl
+ {\knowledge_kl_exec:nnV
+ \knowledge_kl_namespace_tl
+ \knowledge_kl_instance_tl
+ \knowledge_kl_key_tl}
+ {\knowledge_kl_error_unknown_firsttime:}
+}
+% \end{macrocode}
+% We now code the macro \cs{\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}
+% \AP
+% When the \kl{knowledge} is found, it is eventually executed using
+% \begin{code}
+% \csintro{\knowledge_kl_exec:nnn}\{namespace\}\{instance\}\{key\}
+% \end{code} 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 \cs{\knowledge_kl_resourcetoken_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{
+ \tl_set:Nx\knowledge_kl_resourcearguments_tl
+ {{#1}{#2}{\exp_not:n{#3}}}
+ \exp_args:NNc\tl_set:Nn\knowledge_kl_resourcetoken_tl
+ {\knowledge_id:nnn{#1}{#2}{#3}}
+ \expandafter\ktuple_countuse_gincr:N\knowledge_kl_resourcetoken_tl
+ %
+ \tl_clear:N\knowledge_kl_link_tl
+ \tl_clear:N\knowledge_kl_linkscope_tl
+ \tl_clear:N\knowledge_kl_instance_tl
+ \tl_map_function:NN
+ \knowledge_kl_styledirectives_tl
+ \tl_clear:N
+ %
+ \knowledge_kl_resourcetoken_tl
+ %
+ \bool_if:NTF\kl_unknown_knowledge_bool
+ {\knowledge_kl_error_unknown:}
+ {\tl_map_function:NN
+ \knowledge_kl_styledirectives_tl
+ \knowledge_kl_use_styles:x
+ %
+ \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_compute_code:
+ }
+}
+\cs_generate_variant:Nn\knowledge_kl_exec:nnn{nnV}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_use_styles:n
+ {\clist_map_function:nN{#1}\knowledge_kl_use_style:n}
+\cs_generate_variant:Nn\knowledge_kl_use_styles:n {x}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_use_style:n{
+ \tl_if_empty:nTF{#1}{}
+ {\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'}}}
+}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new:Nn\knowledge_usestyle:nn{
+ \group_begin:
+ \tl_set:Nn\knowledge_kl_forcedtext_tl{#2}
+ \knowledge_kl_use_styles:x{#1}
+ \knowledge_kl_compute_code:
+ \group_end:
+ \knowledge_display_code_tl
+}
+\NewDocumentCommand\knowledgeusestyle{mm}{\knowledge_usestyle:nn{#1}{#2}}
+% \end{macrocode}
+%
+%
+%
+%
+%
+%
+% \subsubsection{Error handling}
+%
+%
+%
+% \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}
+% \begin{macrocode}
+\NewKAuxCommand\KAuxErrorKnowledgeUnknown{mmmmm}
+ {Package~'knowledge:~A~knowledge~is~not~defined.~
+ {namespace}{scope/empty}{undefined~knowledge}{base~knowledge}{command}}
+ {}
+\NewKAuxCommand\KAuxErrorLabelUnknown{m}
+ {Package~'knowledge:~A~label~is~not~defined.~
+ {label}}
+ {}
+% \end{macrocode}
+% \begin{macrocode}
+\DeclareKAuxPhaseCommand\KAuxErrorKnowledgeUnknown{diagnose-unknown-suggest}
+{ \knowledge_diagnose_line:
+ \tl_set_eq:Nc\l_tmpa_tl{knowledge_kl_\cs_to_str:N#5_suggestion_tl}
+ \tl_if_empty:nTF{#2}{}
+ {\tl_if_empty:NTF\l_tmpa_tl{}
+ {\tl_put_right:Nn\l_tmpa_tl{,}}
+ \tl_put_right:Nn\l_tmpa_tl{scope={#2}}}
+ \knowledge_diagnose:x
+ {\exp_not:n{\knowledge{#3}}{\exp_not:V\l_tmpa_tl}}
+}
+% \end{macrocode}
+% The code executed when an undefined knowledge is met. It
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_error_unknown_firsttime:
+ {\bool_if:cTF{\knowledge_variant_var:n{unknownwarning_bool}}
+ {\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{~|~}}}
+ }{}
+ \bool_if:cTF{\knowledge_variant_var:n{unknowndiagnose_bool}}
+ {\KAuxWriteX{
+ \KAuxErrorKnowledgeUnknown
+ {\knowledge_kl_namespace_tl}
+ {}
+ {\tl_to_str:V\knowledge_kl_key_tl}
+ {\tl_to_str:V\knowledge_kl_base_key_tl}
+ {\exp_not:V\knowledge_kl_command_tl}
+ }}{}
+ \use:x{\exp_not:N\knowledge_set_now:nnnn
+ {\knowledge_kl_namespace_tl}{base}
+ {\exp_not:V\knowledge_kl_key_tl}
+ {UnKnoWn~KNowLedGE}}
+ \tl_gset:Nx\knowledge_display_code_tl
+ {\exp_not:N\knowledge_usestyle:nn
+ {\use:c{\knowledge_variant_var:n{unknown_style_tl}}}
+ {\exp_not:V\knowledge_kl_text_tl}}
+}
+\cs_new:Nn\knowledge_kl_error_unknown:{
+ \tl_gset:Nx\knowledge_display_code_tl
+ {\exp_not:N\knowledge_usestyle:nn
+ {\use:c{\knowledge_variant_var:n{unknown_style_cont_tl}}}
+ {\exp_not:V\knowledge_kl_text_tl}}
+}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_error_unknown_in_scope_firsttime:
+ {\bool_if:cTF{\knowledge_variant_var:n{unknownwarning_bool}}
+ {\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}}}{}
+ \bool_if:cTF{\knowledge_variant_var:n{unknowndiagnose_bool}}
+ {\KAuxWriteX{
+ \KAuxErrorKnowledgeUnknown
+ {\knowledge_kl_namespace_tl}
+ {\knowledge_kl_linkscope_tl}
+ {\tl_to_str:V\knowledge_kl_key_tl}
+ {\tl_to_str:V\knowledge_kl_base_key_tl}
+ {\exp_not:V\knowledge_kl_command_tl}
+ }}{}
+ \use:x{\exp_not:N\knowledge_set_now:nnnn
+ {\knowledge_kl_namespace_tl}
+ {\knowledge_kl_linkscope_tl}
+ {\exp_not:V\knowledge_kl_key_tl}
+ {UnKnoWn~KNowLedGE}}
+ \tl_gset:Nx\knowledge_display_code_tl
+ {\exp_not:N\knowledge_usestyle:nn
+ {\use:c{\knowledge_variant_var:n{unknown_style_tl}}}
+ {\exp_not:V\knowledge_kl_text_tl}}
+}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_error_label_unknown:{
+ \KAuxWriteX{
+ \KAuxErrorKnowledgeUnknown
+ {\knowledge_kl_namespace_tl}
+ {\knowledge_kl_linkscope_tl}
+ {\tl_to_str:V\knowledge_kl_key_tl}
+ {\tl_to_str:V\knowledge_kl_base_key_tl}
+ {\exp_not:V\knowledge_kl_command_tl}
+ }
+ %
+ \IfKnowledgePaperModeF{
+ \msg_warning:nnxx{ knowledge }{ knowledge~unknown~label }
+ {\exp_not:V\knowledge_kl_key_tl}
+ {\knowledge_kl_linkscope_tl}}
+ %
+ \tl_gset:Nx\knowledge_display_code_tl
+ {\exp_not:N\knowledge_usestyle:nn
+ {\use:c{\knowledge_variant_var:n{unknown_style_tl}}}
+ {\exp_not:V\knowledge_kl_text_tl}}
+}
+% \end{macrocode}
+% This is the code use by default when an error is met and the result has nevertheless to be displayed.
+% \ToImprove{this code is dependent on xcolor and shouldn't.}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_error_display:n
+ {\textcolor{orange}{\tl_to_str:V\knowledge_kl_text_tl}}
+% \end{macrocode}
+%
+% \subsubsection{Variant modifiers and \cs{\knowledgevariantmodifier}}
+%
+% When a \cs\kl-like command is met, its name is added to
+% \csintro{\knowledge_kl_modifiers_tl}.
+% Each time a new command is added using \csintro{\knowledge_kl_modifiers_add:N},
+% it is appended to \cs{\knowledge_kl_modifiers_tl}, and a reduction is applied
+% using \cs{\knowledge_kl_modifiers_reduce:}:
+% \begin{macrocode}
+\tl_clear_new:N\knowledge_kl_modifiers_tl
+\cs_new:Nn\knowledge_kl_modifiers_reset:
+ {\tl_gclear:N\knowledge_kl_modifiers_tl}
+\cs_new:Nn\knowledge_kl_modifiers_add:N
+ {\tl_gput_right:Nn\knowledge_kl_modifiers_tl{#1*}
+ \knowledge_kl_modifiers_reduce:}
+% \end{macrocode}
+%\AP This reduction is performed by \csintro{\knowledge_kl_modifiers_reduce:},
+% and configured using \cs{\knowledgevariantmodifier}.
+% \begin{macrocode}
+\NewDocumentCommand\knowledgevariantmodifier{mm}
+ {\tl_new:cn
+ {KLSV_\tl_to_str:n{#1*} _tl}
+ {#2*}}
+\cs_new:Nn\knowledge_kl_modifiers_reduce:
+ {\tl_if_exist:cTF
+ {KLSV_\tl_to_str:V\knowledge_kl_modifiers_tl _tl}
+ {\tl_gset_eq:Nc\knowledge_kl_modifiers_tl
+ {KLSV_\tl_to_str:V\knowledge_kl_modifiers_tl _tl}}
+ {}}
+% \end{macrocode}
+%
+% \begin{macrocode}
+% \end{macrocode}
+%
+% \begin{macrocode}
+% \end{macrocode}
+%
+% \subsubsection{Implementation of \cs{\knowledgenewvariant}}
+%
+% \begin{macrocode}
+\cs_new:Nn\knowledge_variant_var:n
+ {knowledge_kl_\expandafter\cs_to_str:N\knowledge_kl_command_tl _#1}
+% \end{macrocode}
+% \begin{macrocode}
+\NewDocumentCommand\knowledgenewvariant{mm}{
+ \exp_args:Nc\tl_new:Nn
+ {knowledge_kl_\cs_to_str:N#1_command_tl}
+ {#1}
+ %
+ %
+ \NewDocumentCommand#1{s}
+ {\knowledge_kl_modifiers_add:N#1
+ \IfBooleanF{##1}{\__kl:w}}
+ %
+ \tl_new_eq:cN
+ {knowledge_kl_\cs_to_str:N#1_namespace_tl}
+ \knowledge_default_namespace_tl
+ \tl_new:cx{knowledge_kl_\cs_to_str:N#1_suggestion_tl}{}
+ \bool_new_true:c{knowledge_kl_\cs_to_str:N#1_unknownwarning_bool}
+ \bool_new_true:c{knowledge_kl_\cs_to_str:N#1_unknowndiagnose_bool}
+ \tl_new:cn{knowledge_kl_\cs_to_str:N#1_default_style_tl}{}
+ \tl_new:cn{knowledge_kl_\cs_to_str:N#1_unknown_style_tl}{}
+ \tl_new:cn{knowledge_kl_\cs_to_str:N#1_unknown_style_cont_tl}{}
+ \tl_new:cx{knowledge_kl_\cs_to_str:N#1_autoknowledge_tl}{}
+ \tl_new:cx{knowledge_kl_\cs_to_str:N#1_styledirectives_tl}{}
+ %
+ \bool_if:NT\knowledge_hyperref_active_bool
+ {\exp_args:Nx\pdfstringdefDisableCommands
+ {\exp_not:N\def\exp_not:N#1
+ {\exp_not:N\knowledge_variant_arg_absorber:Nw
+ \exp_not:c{\cs_to_str:N#1_PDFstring}}}}
+ \exp_args:Nc\newcommand{\cs_to_str:N#1_PDFstring}[3]{##1}
+ %
+ \tl_new:cx{knowledge_kl_\tl_to_str:n{#1*} _init_tl}
+ {
+ \exp_not:n{\tl_set_eq:NN\knowledge_kl_command_tl}
+ \exp_not:c{knowledge_kl_\cs_to_str:N#1_command_tl}
+ \exp_not:n{\tl_set_eq:NN\knowledge_kl_namespace_tl}
+ \exp_not:c{knowledge_kl_\cs_to_str:N#1_namespace_tl}
+ \exp_not:n{\tl_set_eq:NN\knowledge_kl_default_style_tl}
+ \exp_not:c{knowledge_kl_\cs_to_str:N#1_default_style_tl}
+ \exp_not:n{\tl_set_eq:NN\knowledge_kl_unknown_style_tl}
+ \exp_not:c{knowledge_kl_\cs_to_str:N#1_unknown_style_tl}
+ \exp_not:n{\tl_set_eq:NN\knowledge_kl_unknown_style_cont_tl}
+ \exp_not:c{knowledge_kl_\cs_to_str:N#1_unknown_style_cont_tl}
+ \exp_not:n{\tl_set_eq:NN\knowledge_kl_styledirectives_tl}
+ \exp_not:c{knowledge_kl_\cs_to_str:N#1 _styledirectives_tl}
+ \exp_not:c{knowledge_kl_\cs_to_str:N#1 _autoknowledge_tl}
+ }
+ %
+ %\bool_if:NT\knowledge_hyperref_active_bool
+ % {\pdfstringdefDisableCommands{\let#1\knowledge_fake_kl:n}}
+ %
+ \knowledgesetvariant#1{#2}
+}
+\DeclareExpandableDocumentCommand\knowledge_variant_arg_absorber:Nw
+ {m d() o d() m}
+ {\IfNoValueTF{#2}
+ {#1{#5}{#2}{#3}}
+ {#1{#5}{#2}{#1}}}
+
+\tl_new:N\knowledge_variant_command_tl
+\tl_new:N\knowledge_variant_key_tl
+\NewDocumentCommand\knowledgesetvariant{mm}{
+ \tl_set:Nn\knowledge_variant_command_tl{#1}
+ \tl_set:Nx\knowledge_variant_key_tl{\cs_to_str:N#1}
+ %
+ \keys_set:nn{ knowledge~configure~variant }{#2}
+}
+% \end{macrocode}
+% \begin{macrocode}
+\keys_define:nn{ knowledge~configure~variant }{
+ namespace .code:n =
+ {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _namespace_tl}{#1}},
+ %
+ unknown~warning .choices:nn = {true,false}
+ {\bool_set_text:cn{knowledge_kl_\knowledge_variant_key_tl _unknownwarning_bool}{#1}},
+ %
+ unknown~diagnose .choices:nn = {true,false}
+ {\bool_set_text:cn{knowledge_kl_\knowledge_variant_key_tl _unknowndiagnose_bool}{#1}},
+ %
+ default~style .code:n =
+ {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _default_style_tl}{#1}},
+ unknown~style .code:n =
+ {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _unknown_style_tl}{#1}},
+ unknown~style~cont .code:n =
+ {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _unknown_style_cont_tl}{#1}},
+ %
+ auto~knowledge .code:n =
+ { \tl_set:cx{knowledge_kl_\knowledge_variant_key_tl _autoknowledge_tl}
+ {\exp_not:N\exp_args:NV
+ \exp_not:N\knowledge
+ {\exp_not:N\knowledge_kl_key_tl}
+ {namespace=\exp_not:N\knowledge_kl_namespace_tl,\exp_not:n{#1}}}},
+ %
+ style~directive .code:n = {
+ \tl_clear:c{knowledge_kl_\knowledge_variant_key_tl _styledirectives_tl}
+ \clist_map_inline:nn{#1}
+ {\use:x{\NewKnowledgeParamTl*
+ [\exp_not:c{knowledge_kl_##1_tl}]}
+ {##1}
+ \tl_put_right:cx{knowledge_kl_\knowledge_variant_key_tl _styledirectives_tl}
+ {\exp_not:c{knowledge_kl_##1_tl}}}
+ },
+ %
+ suggestion .code:n =
+ {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _suggestion_tl}{#1}},
+ %
+ PDF~string .code:n =
+ {\exp_args:Nc\renewcommand{\knowledge_variant_key_tl _PDFstring}[3]{#1}}
+}
+% \end{macrocode}
+%
+%
+% \subsubsection{Variants of the \cs{\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 \csintro{\knowledge_kl_display_preprocess_tl} is the code to be used first before displaying. It does nothing for \cs{\kl}, but is set to \cs{\knowledge_kl_target_preprocess_tl} for \cs{\intro}, which performs the \cs{\label} command fir the introduction.
+% \item \csintro{\knowledge_kl_display_process_tl} is the code to be executed for displaying the \kl{knowledge}. This is not defined by default.
+% \item \csintro{\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 \csintro{\knowledge_kl_update:N} is a code to be executed to update the knowledge. By default, it increments the ktuple counter `\cs{countuse_int}'.
+% \item \csintro{\knowledge_kl_namespace_tl} is the \kl{namespace} in which the \kl{knowledge} is to be searched. Not defined by default.
+% \item \csintro{\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 \csintro{\knowledge_kl_max_recursion_int} is the maximum number of recursion allowed when searching for a \kl{knowledge}. It is by default 40.
+% \end{asparaitem}
+%
+% The codes can uses internally the following variables, that are accessible for the user when defining new \cs\kl-like commands:
+% \begin{asparaitem}
+% \item \csintro{\knowledge_kl_command_tl} the command that has triggered the search
+% \item \csintro{\knowledge_kl_base_key_tl} contains the name of the knowledge for which the search has started,
+% \item \csintro{\knowledge_kl_text_tl} contains the text to be displayed,
+% \item \csintro{\knowledge_kl_key_tl} contains the name of the knowledge searched at a particular moment,
+% \item \csintro{\knowledge_kl_recursion_int} counts the number of indirection in the current, starting from \cs{\knowledge_kl_max_recursion_int}, and going down,
+% \item \csintro{\knowledge_kl_link_tl} contains the link to be followed.
+% \item \cs{\knowledge_kl_resourcetoken_tl} contains a single token, which is the location of the knowledge.
+% \end{asparaitem}
+%
+% \begin{macrocode}
+\let\nointro\phantomintro
+% \end{macrocode}
+%
+% When the \cs{\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}
+\tl_new:Nn\knowledge_kl_target_preprocess_tl
+ {\tl_if_exist_ne:NTF\knowledge_kl_resourcetoken_tl
+ {\expandafter\ktuple_countintro_get_int:NN
+ \knowledge_kl_resourcetoken_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\knowledge_kl_autoref_tl
+ {\exp_args:Nx\knowledge_latex_label:n
+ {\expandafter\noexpand\knowledge_kl_autoref_tl\l_tmpa_tl}}
+ {}}
+% \end{macrocode}
+% \begin{macrocode}
+\tl_new:N\knowledge_kl_style_tl
+\tl_new:N\knowledge_kl_namespace_tl
+\tl_new:N\knowledge_kl_command_tl
+
+\cs_new:Nn\knowledge_kl_target_update:N
+ {\ktuple_countintro_gincr:N#1}
+\cs_gset:Nn\knowledge_kl_default_update:N
+ {\ktuple_countuse_gincr:N#1}
+% \end{macrocode}
+%
+%
+% \subsubsection{Code for mathematical variables (unstable)}
+%
+%
+%
+% \subsubsection{Display parameters}
+%
+%
+%\begin{compactdesc}
+%\item[\csintro{\kl_emphasize_bool}]
+%\item[\csintro{\kl_boldface_bool}]
+%\item[\csintro{\kl_underline_bool}]
+%\item[\csintro{\kl_typewriter_bool}]
+%\item[\csintro{\kl_fbox_bool}]
+%\item[\csintro{\kl_ensuremath_bool}]
+%\item[\csintro{\kl_ensuretext_bool}]
+%\item[\csintro{\kl_italic_bool}]
+%\item[\csintro{\kl_lowercase_bool}]
+%\item[\csintro{\kl_uppercase_bool}]
+%\item[\csintro{\knowledge_kl_forcedtext_tl}]
+%\item[\csreintro{\knowledge_kl_link_tl}]
+%\item[\csreintro{\knowledge_kl_linkscope_tl}]
+%\item[\csreintro{\knowledge_kl_display_process_tl}]
+%\item[\csintro{\knowledge_kl_default_invisible_display_process_tl}]
+%\end{compactdesc}
+%
+% \begin{macrocode}
+\NewKnowledgeParamBool*{fbox}\kl_fbox_bool
+\NewKnowledgeParamBool*{ensuremath}\kl_ensuremath_bool
+\NewKnowledgeParamBool*{ensuretext}\kl_ensuretext_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*{emphasize}\kl_emphasize_bool
+\NewKnowledgeParamBool*{underline}\kl_underline_bool
+\NewKnowledgeParamBool*{typewriter}\kl_typewriter_bool
+\NewKnowledgeParamBool*{autoref~target}\kl_autoreftarget_bool
+\NewKnowledgeParamBool*{autoref~link}\kl_autoreflink_bool
+\NewKnowledgeParamBool*{invisible}\kl_invisible_bool
+\NewKnowledgeParamBool*{italic}\kl_italic_bool
+\NewKnowledgeParamBool*{sc}\kl_sc_bool
+\NewKnowledgeParamBool*{md}\kl_md_bool
+\NewKnowledgeParamBool*{up}\kl_up_bool
+\NewKnowledgeParamBool*{boldface}\kl_boldface_bool
+\NewKnowledgeParamBool*{detokenize}\kl_detokenize_bool
+\NewKnowledgeParamBool*{remove~space}\kl_removespace_bool
+\NewKnowledgeParamBool*{protect~link}\kl_protect_link_bool
+\NewKnowledgeParamBool*{lowercase}\kl_lowercase_bool
+\NewKnowledgeParamBool*{uppercase}\kl_uppercase_bool
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewKnowledgeParamTl*{link}
+\NewKnowledgeParamTl*{link~scope}
+\NewKnowledgeParamTl*[\knowledge_kl_instance_tl]{link~instance}
+\NewKnowledgeParamTl*[\knowledge_kl_forcedtext_tl]{text}
+\NewKnowledgeParamTl*{wrap}
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
+
+\NewKnowledgeParamBool*{UnKnoWn~KNowLedGE}\kl_unknown_knowledge_bool
+\bool_gset_false:N\kl_unknown_knowledge_bool
+\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 },
+ also~now .code:n = { \bool_set_true:N\knowledge_knowledge_alsonow_bool }
+}
+% \end{macrocode}
+%
+% The special directive \kl{autorefhere} is used for variables, where for which it is not necessary
+% to explicitely use a \cs{\knowledge} command.
+% \begin{macrocode}
+\int_new:N\knowledge_autoref_count
+
+\keys_define:nn{ knowledge~directives }{
+ autoref .code:n = {
+ \int_gincr:N\knowledge_autoref_count
+ \knowledge_delay_directive:x
+ {autoref = {autoref-\int_use:N\knowledge_autoref_count}}
+ \bool_set_true:N\knowledge_knowledge_autoref_bool},
+ 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\knowledge_kl_autoref_tl{#1} }
+
+\keys_define:nn { knowledgenow~directives } {
+ autoref .code:n =
+ { \knowledge_at:c{ktuple_autoref_gset:Nn}{#1} }
+}
+% \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}.}
+\NewKAuxCommand\KAuxAutorefTarget{mmm}
+ {Package~knowledge:~Declares~the~use~of~a~target~to~an~autoref~knowledge.~
+ Arguments~{namespace}{instance}{knowledge}.}
+\DeclareKAuxPhaseCommand\KAuxAutoref{init}{}
+
+\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_compare:nNnTF\kl_countuse_int=1
+ {\int_gincr:N\kl_digest_autorefunused_int}
+ {\int_gincr:N\kl_digest_autorefused_int}
+ }
+ \int_compare:nNnT\kl_countintro_int=0
+ {\int_compare:nNnF\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-not-used}
+ {\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=1
+ {\int_compare:nNnT\kl_countintro_int=1
+ {\knowledge_diagnose_line:
+ \knowledge_diagnose:x{\kaux_current_location:\space
+ \exp_not:n{{#3}{#1}{#2}}}}}
+ \group_end:}
+\DeclareKAuxPhaseCommand\KAuxAutorefTarget{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:x{\kaux_current_location:\space
+ \exp_not:n{{#3}{#1}{#2}}}}
+ \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}
+%
+%
+%
+%
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_display_generic:n
+ {\tl_gset:Nx\knowledge_display_code_tl
+ {\exp_not:n{#1}{\exp_not:V\knowledge_display_code_tl}}}
+\cs_new:Nn\knowledge_kl_display_generic_cond:Nn
+ {\bool_if:NTF#1
+ {\tl_gset:Nx\knowledge_display_code_tl
+ {\exp_not:n{#2}{\exp_not:V\knowledge_display_code_tl
+ }}}{}}
+\cs_generate_variant:Nn\knowledge_kl_display_generic:n{x}
+\cs_generate_variant:Nn\knowledge_kl_display_generic_cond:Nn{Nx}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_compute_code:{
+ \tl_if_exist_ne:NTF\knowledge_kl_forcedtext_tl
+ {\tl_gset_eq:NN\knowledge_display_code_tl\knowledge_kl_forcedtext_tl}
+ {\tl_gset_eq:NN\knowledge_display_code_tl\knowledge_kl_text_tl}
+ \bool_if:NT\kl_detokenize_bool
+ {\tl_set:Nx\knowledge_display_code_tl
+ {\tl_to_str:V\knowledge_display_code_tl}}
+ \bool_if:NT\kl_removespace_bool
+ {\tl_remove_all:Nn\knowledge_display_code_tl{~}}
+ \bool_if:NT\kl_lowercase_bool
+ {\tl_set:Nx\knowledge_display_code_tl
+ {\exp_args:NV\tl_lower_case:n\knowledge_display_code_tl}}
+ \bool_if:NT\kl_uppercase_bool
+ {\tl_set:Nx\knowledge_display_code_tl
+ {\exp_args:NV\tl_upper_case:n\knowledge_display_code_tl}}
+ %
+ \tl_if_empty:NTF\knowledge_kl_wrap_tl
+ {}
+ {\exp_args:NV\knowledge_kl_display_generic:n\knowledge_kl_wrap_tl}
+ %
+ \bool_if:NT\knowledge_xcolor_active_bool
+ \knowledge_kl_compute_code_xcolor:
+ \bool_if:NT\knowledge_hyperref_active_bool
+ \knowledge_kl_compute_code_hyperref:
+ %
+ \knowledge_kl_display_generic_cond:Nn\kl_underline_bool\kl_underline:n
+ \knowledge_kl_display_generic_cond:Nn\kl_md_bool\kl_md:n
+ \knowledge_kl_display_generic_cond:Nn\kl_boldface_bool\kl_bf:n
+ \knowledge_kl_display_generic_cond:Nn\kl_up_bool\kl_up:n
+ \knowledge_kl_display_generic_cond:Nn\kl_italic_bool\kl_it:n
+ \knowledge_kl_display_generic_cond:Nn\kl_sc_bool\kl_sc:n
+ \knowledge_kl_display_generic_cond:Nn\kl_typewriter_bool\kl_tt:n
+ % if math
+ \knowledge_kl_display_generic_cond:Nn\kl_mathop_bool\mathop
+ \knowledge_kl_display_generic_cond:Nn\kl_mathord_bool\mathord
+ \knowledge_kl_display_generic_cond:Nn\kl_mathbin_bool\mathbin
+ \knowledge_kl_display_generic_cond:Nn\kl_mathrel_bool\mathrel
+ \knowledge_kl_display_generic_cond:Nn\kl_mathclose_bool\mathclose
+ \knowledge_kl_display_generic_cond:Nn\kl_mathopen_bool\mathopen
+ \knowledge_kl_display_generic_cond:Nn\kl_mathpunct_bool\mathpunct
+ % if text
+ \knowledge_kl_display_generic_cond:Nn\kl_emphasize_bool\kl_em:n
+ \knowledge_kl_display_generic_cond:Nn\kl_fbox_bool\fbox
+ %
+ \knowledge_kl_display_generic_cond:Nn\kl_ensuremath_bool\ensuremath
+ \knowledge_kl_display_generic_cond:Nn\kl_ensuretext_bool\ensuretext
+ %
+ \bool_if:NT\knowledge_makeidx_active_bool
+ \knowledge_kl_compute_code_makeidx:
+ %
+ \bool_if:NT\kl_invisible_bool
+ {\tl_gclear:N\knowledge_display_code_tl}
+}
+\cs_new:Nn\knowledge_kl_compute_code_xcolor:{
+ \tl_if_empty:NF\knowledge_kl_color_tl
+ {\knowledge_kl_display_generic:x{\exp_not:N\textcolor{\knowledge_kl_color_tl}}}
+ \tl_if_empty:NF\knowledge_kl_colorbox_tl
+ {\knowledge_kl_display_generic:x{\exp_not:N\colorbox{\knowledge_kl_colorbox_tl}}}
+}
+\cs_new:Nn\knowledge_kl_compute_code_hyperref:{
+ \tl_if_exist_ne:NT\knowledge_kl_ref_tl
+ {\knowledge_kl_display_generic:x
+ {\exp_not:N\kl_hyperlink_silentref:nn
+ {\exp_not:V\knowledge_kl_ref_tl}}}
+ %
+ \knowledge_kl_compute_code_hyperreftarget:
+ %
+ \bool_if:NT\kl_autoreflink_bool
+ {\tl_if_exist_ne:NT\knowledge_kl_autoref_tl
+ {\knowledge_kl_display_generic:x
+ {\exp_not:N\kl_hyperlink_silentref:nn
+ {\exp_not:V\knowledge_kl_autoref_tl}}
+ }}
+ %
+ \tl_if_exist_ne:NT\knowledge_kl_url_tl
+ {\knowledge_kl_display_generic:x
+ {\exp_not:N\kl_hyperlink_url:nn
+ {\exp_not:V\knowledge_kl_url_tl}}}
+}
+\cs_new:Nn\knowledge_kl_compute_code_hyperreftarget:{
+ \bool_if:NT\kl_autoreftarget_bool
+ {\tl_if_exist_ne:NT\knowledge_kl_autoref_tl
+ {\expandafter\ktuple_countintro_get_int:NN
+ \knowledge_kl_resourcetoken_tl\l_tmpa_int
+ \tl_set:Nx\l_tmpa_tl
+ {\int_compare:nNnTF\l_tmpa_int=1
+ {} {\int_to_alph:n\l_tmpa_int}}
+ \exp_args:Nx\label{\exp_not:V\knowledge_kl_autoref_tl\l_tmpa_tl}}
+ \expandafter\ktuple_countintro_gincr:N
+ \knowledge_kl_resourcetoken_tl
+ \KAuxWriteX
+ {\exp_not:N\KAuxAutorefTarget
+ \exp_not:o\knowledge_kl_resourcearguments_tl}}
+}
+\cs_new:Nn\knowledge_kl_compute_code_makeidx:{
+ \tl_if_exist_ne:NTF\knowledge_kl_index_tl
+ {\exp_args:Nx\index
+ {\tl_if_exist_ne:NTF\knowledge_kl_index_parent_key_tl
+ {\exp_not:V\knowledge_kl_index_parent_key_tl!}{}
+ \tl_if_exist_ne:NTF\knowledge_kl_index_key_tl
+ {\exp_not:V\knowledge_kl_index_key_tl@}{}
+ \expandafter\tl_to_str:n\expandafter{\knowledge_kl_index_tl}
+ }}{}
+}
+
+%\cs_new:Nn\knowledge_kl_default_display_code_fbox:n
+% {\bool_if:NTF\kl_fbox_bool{\exp_not:N\fbox{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Npn\kl_up:n{\mode_if_math:TF\mathup\textup}
+\cs_new:Npn\kl_md:n{\mode_if_math:TF\mathmd\textmd}
+\cs_new:Npn\kl_sc:n{\mode_if_math:TF\mathsc\textsc}
+\cs_new:Npn\kl_it:n{\mode_if_math:TF\mathit\textit}
+\cs_new:Npn\kl_tt:n{\mode_if_math:TF\mathtt\texttt}
+\cs_new:Npn\kl_bf:n{\mode_if_math:TF\mathbf\textbf}
+\cs_new:Npn\kl_underline:n{\mode_if_math:TF\use:n\underline}
+\cs_new:Npn\kl_em:n{\mode_if_math:TF\use:n\emph}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_default_display_code_color:n{
+ \bool_if:NTF\knowledge_xcolor_active_bool
+ {\tl_if_exist_ne:NTF\knowledge_kl_color_tl
+ {\exp_not:N\textcolor{\knowledge_kl_color_tl}{#1}}{#1}}
+ {#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_default_display_code_colorbox:n{
+ \bool_if:NTF\knowledge_xcolor_active_bool
+ {\tl_if_exist_ne:NTF\knowledge_kl_colorbox_tl
+ {\exp_not:N\colorbox{\knowledge_kl_colorbox_tl}{#1}}{#1}}
+ {#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_default_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_kl_default_code_wrap:n{
+ \tl_if_exist_ne:NTF\knowledge_kl_wrap_tl
+ {\exp_not:V\knowledge_kl_wrap_tl{#1}}{#1}}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\knowledge_kl_default_display_code_text:{
+ \knowledge_kl_default_code_wrap:n{
+ \tl_if_exist_ne:NTF\knowledge_kl_forcedtext_tl
+ {\exp_not:V\knowledge_kl_forcedtext_tl}
+ {\exp_not:V\knowledge_kl_text_tl}
+ }
+}
+% \end{macrocode}
+%
+% \subsubsection{Other commands}
+%
+% \paragraph{\cs{\AP} and \cs{\itemAP}}
+% The code for the command \cs{\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_ref: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:Npn\kl_hyperlink_silentref:nn#1
+ {\kl_if_hyperref_exist:nTF{#1}
+ {\kl_hyperlink_ref:nn{#1}}
+ \use:n}
+\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 takes
+% knowledge,key,scope and is equivalent to \cs{\kl}.
+% \begin{macrocode}
+\tl_new:Nn\knowledge_variant_quote_modifier_tl{\kl*}
+\tl_new:Nn\knowledge_variant_doublequote_modifier_tl{\intro*}
+% \end{macrocode}
+%\knowledgeconfigure{quotation=false}
+% \begin{macrocode}
+\ExplSyntaxOff
+\def\makequotationactive
+ {\catcode`"13\relax}
+\def\makequotationletter
+ {\catcode`"12\relax}
+% \end{macrocode}
+% \begin{macrocode}
+\let\quotesymbol"
+% \end{macrocode}
+% \begin{macrocode}
+\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\klquotation_expand:nnn
+ {\knowledge_variant_quote_modifier_tl
+ \klquotation_expand_base:nnn}
+\cs_new:Npn\kldoublequotation_expand:nnn
+ {\knowledge_variant_doublequote_modifier_tl
+ \klquotation_expand:nnn}
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new:Nn\klquotation_expand_base:nnn{
+ \tl_if_empty:nTF{#2}
+ {\klTKS{#1}{#1}{#3}}
+ {\klTKS{#1}{#2}{#3}}
+}
+% \end{macrocode}
+% \begin{macrocode}
+\def\klactivatequotation
+ {\makequotationactive
+ \let"\klactivequotationmark}
+\def\kldeactivatequotation
+ {\makequotationletter}
+
+\kldeactivatequotation
+% \end{macrocode}
+%\knowledgeconfigure{quotation=true}
+%
+% 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 \csintro{\klparse_absorb_modifiers:}.
+% This command parses all the subscripts and so on occurring after,
+% and then launches \csintro{\klparse_absorb_modifiers_exec:}
+% (that is supposed to have been set with the proper code).
+% At the end, the token lists \csintro{\klparse_primes_tl}, \csintro{\klparse_subscript_tl}
+% and \csintro{\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 \cs{\klparse_novalue_tl}. This is not the case for primes:
+% if there are no primes, then the token list \cs{\klparse_primes_tl} is simply empty.
+% Parsing subscripts, superscripts and primes can be deactivated or activated by setting appropriately the
+% macros \cs{\klparse_if_load_primes:TF}
+% \cs{\klparse_if_load_subscript:TF} and \cs{\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 \csintro{\klparse_absorb_subscript:Nn} and \csintro{\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 \kl{xcolor option}}
+%
+% \begin{macrocode}
+\NewKnowledgeParamTl*{color}
+\NewKnowledgeParamTl*{colorbox}
+\knowledge_directives_require_aci_package:nn
+ {color,colorbox,cyclic~color}{xcolor}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\tl_new:N\knowledge_cyclic_colors_tl
+\tl_new:N\knowledge_cyclic_color_tl
+% \end{macrocode}
+%
+% \begin{macrocode}
+\keys_define:nn{ knowledge~configuration~options }{
+ cyclic~colors .code:n = {\tl_gset:Nn\knowledge_cyclic_colors_tl{#1}}
+}
+\knowledgeconfigure{cyclic~colors =
+ {red,green,blue,cyan,magenta,yellow,gray,brown,lime,olive,orange,pink,purple,teal,violet}}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new:Npn\__knowledge_cyclic_color_next:w#1,#2\__knowledge_cyclic_end
+ {\tl_gset:Nn\knowledge_cyclic_colors_tl{#2,{#1}}
+ \tl_gset:Nn\knowledge_cyclic_color_tl{#1}}
+\cs_new:Nn\knowledge_cycle_colors:
+ {\expandafter\__knowledge_cyclic_color_next:w\knowledge_cyclic_colors_tl\__knowledge_cyclic_end}
+
+\keys_define:nn{ knowledge~directives }{
+ cyclic~color .code:n = {
+ \knowledge_cycle_colors:
+ \knowledge_delay_directive:x
+ {color = {\knowledge_cyclic_color_tl}}}
+}
+% \end{macrocode}
+%
+% \subsubsection{The \kl{hyperref option}}
+%
+% \begin{macrocode}
+\NewKnowledgeParamTl*{url}
+\NewKnowledgeParamTl*{ref}
+
+\knowledge_directives_require_aci_package:nn
+ {url,ref,autoref}{hyperref}
+% \end{macrocode}
+% The commands \cs{\intro}, \cs{\kl} and \cs{\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_klTKS{mmm}{#1}
+ \pdfstringdefDisableCommands{%
+ \let\klTKS\knowledge_fake_klTKS
+ }
+}
+% \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_kl_default_display_code_index:n}
+
+ \cs_new:Npn\knowledge_kl_default_display_code_index:n
+ {\tl_if_exist_ne:NT\knowledge_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\knowledge_kl_indexkey_tl
+ {\exp_not:V\knowledge_kl_indexkey_tl@}{}
+ \expandafter\tl_to_str:n\expandafter{\knowledge_kl_index_tl}
+ }}}}
+}
+
+\NewKnowledgeParamTl{index}
+\keys_define:nn { knowledge~directives }
+{ index .code:n = {
+ \tl_if_empty:nTF{#1}
+ {\knowledge_delay_directive:x{index={\exp_not:V\knowledge_knowledge_key_tl}}}
+ {\knowledge_delay_directive:n{index={#1}}}},
+ index .default:n = {}
+}
+
+\NewKnowledgeParamTl*{index~style}
+\NewKnowledgeParamTl*{index~parent~key}
+\NewKnowledgeParamTl*{index~key}
+% \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 \cs{\knowledgeFixHyperrefTwocolumn}
+% or \cs\knowledgeconfigure\texttt\{\kl{fix hyperref twocolumn}\texttt\}
+% \begin{macrocode}
+\ExplSyntaxOff\makeatletter
+\newcommand\knowledgeFixHyperrefTwocolumn{
+ \RequirePackage{etoolbox}
+ \newcount\c at additionalboxlevel
+ \setcounter{additionalboxlevel}{0}
+ \newcount\c at 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{Variants of the \cs{\kl} macro}
+%
+% \begin{macrocode}
+\tl_new:Nn\knowledge_kl_default_style_tl{kl}
+\tl_new:Nn\knowledge_kl_unknown_style_tl{kl~unknown}
+\tl_new:Nn\knowledge_kl_unknown_style_cont_tl{kl~unknown~cont}
+\tl_new:Nn\knowledge_kl_styledirectives_tl{\knowledge_kl_style_tl}
+
+\ExplSyntaxOff
+\knowledgestyle{autoref link}{autoref link}
+\knowledgestyle{autoref target}{autoref target}
+\knowledgestyle{invisible}{invisible}
+
+
+\knowledgenewvariant\kl{
+ namespace=default,
+ default style={kl,autoref link},
+ unknown style= kl unknown,
+ unknown style cont=kl unknown cont,
+ style directive={style}
+}
+\knowledgenewvariant\intro{
+ namespace=default,
+ default style={intro,autoref target},
+ unknown style= intro unknown,
+ unknown style cont= intro unknown cont,
+ style directive=intro style
+}
+\knowledgenewvariant\phantomintro{
+ namespace=default,
+ default style={invisible,autoref target},
+ unknown style=invisible,
+ unknown style cont=invisible
+}
+\knowledgenewvariant\reintro{
+ namespace=default,
+ default style=intro,
+ unknown style=intro unknown,
+ unknown style cont=intro unknown cont,
+ style directive=intro style
+}
+\knowledgevariantmodifier{\intro*\kl}{\intro}
+\knowledgevariantmodifier{\reintro*\kl}{\reintro}
+
+\ExplSyntaxOn
+% \end{macrocode}
+%
+% \subsubsection{Basic configuration}
+%
+% \begin{macrocode}
+\tl_gset_eq:NN\knowledge_kl_namespace_tl\knowledge_default_namespace_tl
+% \end{macrocode}
+%
+% \begin{macrocode}
+\newcommand\robustdisplay[1]
+ {\expandafter\use:n%\tl_trim_spaces:n
+ \expandafter{\tl_to_str:n{#1}}}
+\newcommand\robustdisplaybracket[1]
+ {[\robustdisplay{#1}]}
+
+\ExplSyntaxOff
+% in paper mode, nothing is displayed
+\IfKnowledgePaperModeTF{
+ \knowledgestyle{kl}{}
+ \knowledgestyle{kl unknown}{}
+ \knowledgestyle{kl unknown cont}{}
+ \knowledgestyle{intro}{emphasize}
+ \knowledgestyle{intro unknown}{emphasize}
+ \knowledgestyle{intro unknown cont}{emphasize}
+}{}
+
+\IfKnowledgeCompositionModeTF{
+ \IfXcolorTF{
+ \knowledgestyle{kl}{color={blue!70!black}}
+ \knowledgestyle{kl unknown}{color=orange}
+ \knowledgestyle{kl unknown cont}{color=brown}
+ \knowledgestyle{intro}{emphasize,color=blue}
+ \knowledgestyle{intro unknown}{emphasize,color=orange}
+ \knowledgestyle{intro unknown cont}{emphasize,color=brown}
+ }{
+ \knowledgestyle{kl}{}
+ \knowledgestyle{kl unknown}{underline}
+ \knowledgestyle{kl unknown cont}{underline}
+ \knowledgestyle{intro}{emphasize}
+ \knowledgestyle{intro unknown}{emphasize,underline}
+ \knowledgestyle{intro unknown cont}{emphasize,underline}
+ }
+}{}
+
+\IfKnowledgeElectronicModeTF{
+ \IfXcolorTF{
+ \knowledgestyle{kl}{color={blue!70!black}}
+ \knowledgestyle{kl unknown}{}
+ \knowledgestyle{kl unknown cont}{}
+ \knowledgestyle{intro}{emphasize,color=blue}
+ \knowledgestyle{intro unknown}{emphasize}
+ \knowledgestyle{intro unknown cont}{emphasize}
+ }{
+ \knowledgestyle{kl}{}
+ \knowledgestyle{kl unknown}{}
+ \knowledgestyle{kl unknown cont}{}
+ \knowledgestyle{intro}{emphasize}
+ \knowledgestyle{intro unknown}{emphasize}
+ \knowledgestyle{intro unknown cont}{emphasize}
+ }
+}{}
+
+\ExplSyntaxOn
+\let\nointro\phantomintro
+% \end{macrocode}
+%
+
+%
+% \subsubsection{The "notion" configurations}
+% \label{section:notion option}
+%
+%\paragraph{The configuration option `\kl{notion}'.}
+%
+%The macro \csintro{\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 \cs{\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
+
+
+
+
Property changes on: trunk/Master/texmf-dist/source/latex/knowledge/knowledge-code.dtx
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Deleted: trunk/Master/texmf-dist/source/latex/knowledge/knowledge.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/knowledge/knowledge.dtx 2017-10-19 21:28:59 UTC (rev 45559)
+++ trunk/Master/texmf-dist/source/latex/knowledge/knowledge.dtx 2017-10-19 21:29:32 UTC (rev 45560)
@@ -1,6006 +0,0 @@
-% \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/10/10}{v1.07}{}
-%<*driver>
-\def\knowledgeversion{v1.07}
-\def\knowledgedate{2017/10/13}
-\def\knowledgeversiondate{\knowledgeversion\ \knowledgedate}
-
-{
-\newwrite\tempfile
-\def\TXT#1{\expandafter\immediate\expandafter\write\expandafter\tempfile\expandafter{\detokenize{#1}}}
-\def\TXTx#1{\edef\tmp{\noexpand\TXT{#1}}\tmp}
-\immediate\openout\tempfile=README.txt
-\TXT{This directory contains the package}
-\TXT{}
-\TXT{ name: knowledge.sty }
-\TXTx{ version: \knowledgeversion }
-\TXTx{ date: \knowledgedate }
-\TXT{ license: LaTeX Project Public License version 1.2 or above }
-\TXT{ }
-\TXT{ author: Thomas Colcombet }
-\TXT{ mail: thomas.colcombet at irif.fr }
-\TXT{ web: https://www.irif.fr/~colcombe/knowledge_en.html }
-\TXT{ }
-\TXT{ }
-\TXT{ Purpose: }
-\TXT{ The knowledge package for LaTeX offers a systematic way to handle }
-\TXT{ notions/concepts/terms throughout a document. It helps building an }
-\TXT{ index. In combination with hyperref it makes it easy to have every }
-\TXT{ references of a concept linked to its introduction. It also offers }
-\TXT{ simple notations. }
-\TXT{ }
-\TXT{ }
-\TXT{Content of the file knowledge-sources.zip: }
-\TXT{ - README.txt: this file, generated while compiling knowledge.dtx }
-\TXT{ - knowledge.sty: the package file (generated) }
-\TXT{ - knowledge.pdf: the user documentation (generated) }
-\TXT{ - makefile: the makefile. Use 'make all' }
-\TXT{ to generate knowledge.sty and knowledge.pdf }
-\TXT{ - knowledge.dtx: the main file }
-\TXT{ (compiling it directly yields a developper version of the }
-\TXT{ documentation that contains the code. Use 'make all' }
-\TXT{ for the regular version. It also produces README.txt) }
-\TXT{ - all.ins: file generating knowledge.sty when compiled (docstrip) }
-\TXT{ - knowledge-configuration.dtx: file containing part of the configuration }
-\TXT{ - knowledge-utils.dtx: file containing several pieces of code not really }
-\TXT{ related specifically to knowledge }
-\TXT{ - knowledge-example.tex: an example file }
-\TXT{}
-\TXT{ Note: this file is created when compiling knowledge.dtx }
-\TXT{}
-\immediate\closeout\tempfile
-}
-
-
-
-
-\documentclass{ltxdoc}
-\usepackage[utf8]{inputenc}
-\usepackage[T1]{fontenc}
-\usepackage{paralist}
-\usepackage[svgnames]{xcolor}
-\usepackage[check-declarations]{expl3}
-
-\usepackage[hyperref,quotation,scope]{knowledge}
-
-\knowledgeconfigure{visible anchor points=false}
-\knowledgeconfigure{notion,diagnose line=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
-
-
-\NewDocumentCommand\ToImprove{m}{\marginpar{\textcolor{red}{To improve:} #1}}
-
-
-\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
-\knowledgedirective{kenvironment}{autoref,style=cs,intro style=csintro}
-
-
-
-% 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}
-
-
-
-\knowledgedirective{doc notion}
- {autoref,style=doc notion,intro style=intro doc notion}
-\knowledgestyle{doc notion}{color=DarkBlue}
-\knowledgestyle{intro doc notion}{color=blue,emphasize}
-
-\let\cs\undefined
-\knowledgenewvariant\cs
- {namespace=cs,
- default style={autoref link,cs},
- unknown style=cs unknown,
- unknown style cont=cs unknown,
- unknown warning=f alse,
- unknown diagnose=true,
- suggestion=cs,
- PDF string={\detokenize{#1}}}
-\knowledgestyle{cs}{wrap=\Robustdisplay,typewriter,up,md,color=NavyBlue}
-\knowledgestyle{cs unknown}{wrap=\Robustdisplay,typewriter,up,md,color=black}
-
-\knowledgenewvariant\csintro
- {namespace=cs,
- auto knowledge={autoref,scope=document,also now},
- default style={autoref target,csintro},
- unknown style=csintro unknown,
- unknown style cont=csintro unknown,
- unknown warning=false,
- unknown diagnose=false,
- PDF string = {\detokenize{#1}}}
-\knowledgestyle{csintro}{wrap=\Robustdisplay,typewriter,up,md,color=blue}
-\knowledgestyle{csintro unknown}{wrap=\Robustdisplay,typewriter,up,md,color=black}
-
-\knowledgenewvariant\csreintro
- {namespace=cs,
- default style=csintro,
- unknown style=csintro unknown,
- unknown style cont=csintro unknown,
- PDF string = {\Robustdisplay{#1}}}
-
-
-
-\knowledge{@token}{wrap=\Robustdisplay,up,md,typewriter,color=NavyBlue}
-
-
-
-\knowledge{_monoid}{style=kl unknown}
-\knowledge{_semigroup}{style=kl unknown}
-
-
-
-% style names
-\knowledgedirective{notion style}{autoref,style=style,intro style=intro style}
-\knowledgestyle{style}{typewriter,up,md,color=NavyBlue}
-\knowledgestyle{intro style}{typewriter,up,md,color=blue}
-
-\begin{scope}\label{style}
- \knowledge{notion}{notion style}
- \knowledge{intro notion}{notion style}
-
- \knowledge{kl}{notion style}
- \knowledge{kl unknown}{notion style}
- \knowledge{kl unknown cont}{notion style}
-
- \knowledge{intro}{notion style}
- \knowledge{intro unknown}{notion style}
- \knowledge{intro unknown cont}{notion style}
- \knowledge{autoref not introduced}{notion style}
- \knowledge{autoref reintroduced}{notion style}
-\end{scope}
-
-
-\knowledgedirective{kvariable}{style=cs}
-\knowledge {experimental}{doc notion,color=gray}
-
-
-\ExplSyntaxOn
-\NewDocumentCommand\robustdisplaycs{m}
- {\expandafter\robustdisplay\csname#1\endcsname}
-
-
-
-
-\knowledgeconfigure{quotation=false}
-\knowledge"{text=\quotesymbol}
-\knowledge{""}{text=\quotesymbol\quotesymbol}
-\knowledgeconfigure{quotation=true}
-
-\knowledge{CTAN}{color=blue,url=https://www.ctan.org/}
-\knowledge{AucTex}{typewriter}
-\knowledge{Emacs}[emacs|EMACS]{typewriter}
-
-\makeatletter
-\let\arobas @
-\makeatother
-
-\knowledgestyle{tt}{typewriter,up,md,color=NavyBlue}
-\knowledgestyle{tt intro}{typewriter,up,md,color=blue}
-\knowledgedirective{kcommand}{style=tt,intro style=tt intro,autoref}
-
-\knowledgedirective{kquotation}{style=tt,intro style=tt intro,autoref}
-\knowledge{"..."}{kquotation,text=\kl"$\cdots$\kl{"}}
-\knowledge{""...""}{kquotation,text=\kl{""}$\cdots$\kl{""}}
-\knowledge{"... at ..."}{kquotation,text=\kl{"}$\cdots\arobas\cdots$\kl{"}}
-\knowledge{""... at ...""}{kquotation,text=\kl{""}$\cdots\arobas\cdots$\kl{""}}
-\knowledge{"...@@..."}{kquotation,text=\kl{"}$\cdots\arobas\cdots\arobas\cdots$\kl{"}}
-\knowledge{""...@@...""}{kquotation,text=\kl{""}$\cdots\arobas\cdots\arobas\cdots$\kl{""}}
-\knowledge{"... at ...@..."}{kquotation,text=\kl{"}$\cdots\arobas\cdots\arobas\cdots$\kl{"}}
-\knowledge{""... at ...@...""}{kquotation,text=\kl{""}$\cdots\arobas\cdots\arobas\cdots$\kl{""}}
-\knowledge{@}{kcommand,text=\arobas}
-
-
-
-\knowledge{tex}{text=\TeX}
-
-\knowledgedirective{people}{emphasize,color=DarkGray}
-\knowledge{stackexchange}{people}
-\knowledge{egreg}{people}
-
-\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}
-
-
-\ExplSyntaxOff
-
-\begin{scope}\label{area}
- \knowledge{nesting_int}{directive}
- \knowledge{count_int}{directive}
- \knowledge{name_tl}{directive}
- \knowledge{pushcode_tl}{directive}
- \knowledge{popcode_tl}{directive}
- \knowledge{autoclose_bool}{directive}
- \knowledge{environment_bool}{directive}
- \knowledge{recursive_bool}{directive}
- \knowledge{multiple_bool}{directive}
- \knowledge{forces_tl}{directive}
- \knowledge{acceptsknowledge_bool}{directive}
- \knowledge{attractsknowledge_bool}{directive}
- \knowledge{labelizable_bool}{directive}
- \knowledge{scope_bool}{directive}
- \knowledge{mandatorybase_seq}{directive}
-
- \knowledge{autoclose=}{directive}
- \knowledge{environment=}{directive}
- \knowledge{parents=}{directive}
- \knowledge{scope=}{directive}
- \knowledge{label=}{directive}
- \knowledge{push code=}{directive}
- \knowledge{pop code=}{directive}
- \knowledge{occurrences=}{directive}
- \knowledge{forces=}{directive}
-\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{up}{directive}
-\knowledge{md}{directive}
-\knowledge{boldface}{directive}
-\knowledge{fbox}{directive}
-\knowledge{typewriter}{directive}
-\knowledge{ensuretext}{directive}
-\knowledge{ensuremath}{directive}
-\knowledge{italic}[italic=]{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{autoref link}{directive}
-\knowledge{autoref target}{directive}
-\knowledge{also now}{directive}
-\knowledge{notion}{directive}
-\knowledge{invisible=}[invisible]{directive}
-\knowledge{detokenize}{directive}
-\knowledge{remove space}{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{variant directives}[variant directive|Variant directives]{doc notion}
-\begin{scope}\label{variant}
- \knowledge{directive}[directives|Directives]{link=variant directive}
- \knowledge {namespace=}{directive}
- \knowledge {default style=}{directive}
- \knowledge {unknown style=}{directive}
- \knowledge {unknown style cont=}{directive}
- \knowledge {style directive=}{directive}
- \knowledge {auto knowledge=}{directive}
- \knowledge {unknown warning=}{directive}
- \knowledge {unknown diagnose=}{directive}
- \knowledge {suggestion=}{directive}
- \knowledge {PDF string=}{directive}
- \knowledge {starred sequence}{doc notion}
- \knowledge {modifier}[modifiers|Modifiers]{doc notion}
-\end{scope}
-
-\knowledge{align*}{typewriter}
-
-%\knowledgedefault{index}
-\knowledgedefault{}
-
-\knowledge{label}{}
-
-\knowledge{variant of \cs{\kl}}[variants of \cs{\kl}|Variants of \cs{\kl}]{doc notion}
-\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}
-
-\knowledge{latex}{text=\LaTeX}
-\knowledge{tex}{}
-\knowledge{pdflatex}{}
-
-\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}}}
-
-
-\ExplSyntaxOn
-\group_begin:
- \catcode`| = 11%
- \global\def\vbar{|}
-\group_end:
-\ExplSyntaxOff
-
-
-
-
-
-
-
-
-
-
-\begin{document}
-\label{paper:top}
-\title{The \texttt{knowledge} package\\\small[\knowledgeversion{} --- \knowledgedate]}
-\author{Thomas Colcombet \\ \texttt{thomas.colcombet at irif.fr}}
-\maketitle
-
-\begin{abstract}\phantomintro(package){knowledge}%
-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 at irif.fr}\\
-\texttt{version:}&\texttt{\knowledgeversion}\\
-\texttt{date:}&\texttt{\knowledgedate}
-(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 make quoatation work properly in the titles of section...,
-\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 \csintro{\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 \cs{\nointro}.
-\item Solve the problem of \cs{\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 \cs{\AP} and \cs{\itemAP} commands. For the moment \cs{\AP} silently fails inside the
- optional argument of \cs{\item}, and probably elsewhere too. See how this can be improved.
-\item solve the \kl(package){amsmath} problem that \cs{\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 \cs{\knowledgedirective}.
-\item[2017-01-13] \cs{\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 \cs{\begin} command.
-\item[2017-01-14] The overloading of \cs{\begin} and \cs{\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
-\cs{\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 \cs{\usepackage}) from the configuration options (see \cs{\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 \cs{\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 \cs{\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 \cs{\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 \cs{\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{"... at ..."} and \kl{""... at ...""} 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 \cs{\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{\cs\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 \cs{\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 \cs{environment_bool} 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 \cs{\kl} and \cs{\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-08-06] Now passes the compliance test \texttt{check-declarations} of "expl3@@package"
- (thanks to Marc Zeitoun)
-\item[2017-09-12] The "hidelinks" option of "hyperref@@package" is now always activated.
-\item[2017-09-25] Ancient version of "xparse@@package" does not have \cs{\NewExpandableDocumentCommand}. Corrected.
-\item[2017-09-26] Version 1.05 on CTAN.
-\item[2017-10-10] Bug in the implementation of \cs{\knowledgenewvariant} (that was invisible). Found and corrected (thanks to Marc Zeitoun).
-\item[2017-10-10] Version 1.06 on CTAN.
-\item[2017-10-15] Diagnose extended. Minor corrections. Version 1.07 on CTAN.
-\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 may be 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 at 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]
-\cs{\usepackage}["hyperref@@package",\kl(option){quotation}]\{"knowledge@@package"\}
-\end{code}
-\noindent or:
-\begin{code}[8cm]
-\cs\usepackage\{\kl(package){hyperref}\}\\
-\cs\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}
-\cs\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 \cs{\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 \cs{\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 \cs\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 \cs{\knowledge} command using
-extra "directives":
-\begin{code}[10.9cm]
-\cs\knowledge\{latex\}\{\kl{url=}https://en.wikipedia.org/wiki/LaTeX,\\
-\qquad\kl{text=}\cs\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 at 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 it is not explicitly named in the text. There are two ways to resolve this issue. The first is to use the syntax
-\begin{center}
-\smallcode{\cs\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\cs{\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]
- \cs{\knowledge}\{D. Knuth\}\\~~~~\{\kl{link=}Knuth\}
- \end{code}\noindent then \smallcode{\cs\kl\{D. Knuth\}}
- would also point to the same url.
- \begin{code}[4.3cm]
- \cs{\knowledge}\{D. Knuth\}\\~~~~\{\kl{synonym}\}
- \end{code}\noindent would also work if used just after the definition
- of \texttt{Knuth}.\\
- \end{hint}}
-%
-\begin{code}
-\cs{\knowledge}\{latex\}[LaTeX\vbar Latex\vbar LATEX]\\
- \{\kl{url=}http://en.wikipedia.org/wiki/LaTeX,~\kl{text=}\cs{\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]
- \cs\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{\cs\kl\{Knuth\}}~~~as well as~~~\smallcode{\cs\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]
-% \cs\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]
-\cs\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]
-\cs\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 \cs{\intro} (or \kl{""}$\cdots$\kl{""} if \kl(option){quotation} is activated) when a notion is defined/introduced, and
-\marginpar{\begin{hint} Using an \cs{\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}}
-\cs{\kl} (or \kl{"}$\cdots$\kl{"} if \kl(option){quotation} is activated) when it is used. For instance:
-\begin{code}[12cm]
-\cs\AP{}
-A \cs\intro\{semigroup\} is an ordered pair \verb|$(S,\cdot)$| where \verb|$\cdot$| is an
-associative binary operator over~\verb|$S$|.\\
-\kl{[...]}\\
-\cs{\AP}
-A \cs\intro\{monoid\} \verb|$(M,\cdot,1)$| is a \cs\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]
-\cs\AP{}
-A \kl{""}semigroup\kl{""} is an ordered pair \verb|$(S,\cdot)$| where \verb|$\cdot$| is an
-associative binary operator over~\verb|$S$|.\\
-\kl{[...]}\\
-\cs\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 \cs{\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{[...]}\\
-\AP 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 practice 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 \cs{\intro} command), i.e., in the preamble:
-\begin{code}[6.7cm]
-\cs\knowledge\{semigroup\}\{\kl{notion}\}\\
-\cs\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{[...]}\\
-\AP 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 \cs{\AP}-command.
-If now one adds the option \kl{electronic} while loading the package, then the colors and the red corner disappear. When using the option \kl{paper}, the links are still there, but all texts are in black.
-
-\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]
-\cs\knowledge\{semigroup\}[semigroups\vbar Semigroups]\{\kl{notion}\}\\
-\cs\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 \cs{\newrobustcmd} (of the \texttt{etoolbox} package), rather than the usual \cs{\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]
-\cs\newrobustcmd\kl[@token]\monoid\{\cs\mathcal\ M\}
-\end{code}\noindent
-Imagine that furthermore, you would like to hyperlink to the definition of a monoid. A standard \cs{\kl} command does the job\footnote{It is highly advised to not use the "quotation notation" in math mode or macros.}:
-\begin{code}[9cm]
-\cs\newrobustcmd\kl[@token]\monoid\{\cs\kl[monoid]\{\cs\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}
-\cs\knowledgeconfigureenvironment\{theorem,lemma,proof\}\{\}\par\noindent
-\kl{[...]}\par\noindent
-\cs\begin\{lemma\}\cs\label\{theorem:main\}\par\noindent
-~~~~\cs\knowledge\{n\}\{\kl{notion}\}\par\noindent
-~~~~For all number~\$\cs\intro\ n\$, \kl{[...]}\par\noindent
-\cs\end\{lemma\}\par\noindent
-\kl{[...]}\par\noindent
-Here \$\cs\kl\ n\$ is an undefined knowledge.\par\noindent
-\kl{[...]}\par\noindent
-\cs\begin\{proof\}[Proof of theorem\~\space\{theorem:main\}]\par\noindent
-~~~~\cs\knowledgeimport\{theorem:main\}\par\noindent
-~~~~Inside the proof, \$\cs\kl\ n\$ is hyperlinked to the theorem...\par\noindent
-\cs\end\{proof\}
-\end{code}
-More on \kl{scoping} can be found in Section~\ref{subsection:scoping}.
-
-The use of "variants of \cs{\kl}" is also useful for typesetting mathematics. It allows for instance, to implicitly execute the \cs{\knowledge} command at the same time of the introduction. See~\ref{subsubsection:variants} for more detail.
-
-\newpage
-
-\section{Usage of the \kl(package){knowledge} 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 \cs{\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 \cs{\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 \cs{\knowledgeconfigure} can be used when loading the package.
-\itemAP[Scoping] The \kl[scope option]{scope} "option at 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 are attached to a section of the documents.
-\end{compactdesc}
-
-\subsubsection{Writing mode}
-\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{\cs\usepackage[\kl{paper}]\{"knowledge@@package"\}}\\[2mm]
-or\quad&\smallcode{\cs\usepackage[\kl{electronic}]\{"knowledge@@package"\}}\\[2mm]
-or &\smallcode{\cs\usepackage[\kl{composition}]\{"knowledge@@package"\}}
-\end{tabular}\\
-\AP or by setting before loading the variable \csintro{\knowledgepackagemode} as in:\\
-\begin{tabular}[t]{ll}
- &\smallcode{\cs\def\cs\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} \quotesymbol\cs\def\cs\knowledgepackagemode%
- \texttt\{\kl{electronic}\texttt\}\cs\input\texttt\{file.tex\texttt\}\quotesymbol}
-\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.4cm]
-\AP
-\csintro\IfKnowledgePaperModeTF\texttt\{true code\texttt\}\texttt\{false code\texttt\}\\
-\AP
-\csintro{\ ifKnowledgePaperMode} true code [\cs{\ else} false code] \cs{\ fi}\\
-\AP
-\csintro{\IfKnowledgeElectronicModeTF}\texttt\{true code\texttt\}\texttt\{false code\texttt\}\\
-\AP
-\csintro{\ ifKnowledgeElectronicMode} true code [\cs{\ else} false code] \cs{\ fi}\\
-\AP
-\csintro{\IfKnowledgeCompositionModeTF}\texttt\{true code\texttt\}\texttt\{false code\texttt\}\\
-\AP
-\csintro{\ ifKnowledgeCompositionMode} true code [\cs{\ else} false code] \cs{\ 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 at 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]
-\cs\documentclass\{article\}\\
-%\cs\usepackage[utf8]\{inputenc\}\\
-%\cs\usepackage[T1]\{fontenc\}\\
-\cs\usepackage[svgnames]\{\kl(package){xcolor}\}\\
-\cs\usepackage[\texttt{draft}]\{\kl(package){hyperref}\}\\
-\cs\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 \cs{\knowledgeconfigure}}
-
-Some part of the configuration can be done outside of the \cs{\usepackage} command that loads the "knowledge@@package" package. \AP This is done using the
-\cs{\knowledgeconfigure} command:
-\begin{center}
-\smallcode{\csintro\knowledgeconfigure\{\kl{configuration directives}\}}
-\end{center}
-Note that by default, the \kl{configuration directives} used by \cs{\knowledgeconfigure} can
-be used in the optional parameter of \cs{\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". False is the default.
-\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{"... at ..."} and \kl{"... at ...@..."}
- instead of \cs{\kl} commands and \kl{""...""}, \kl{""... at ...""} and \kl{""... at ...@...""} instead of the \cs{\intro} command.
-\itemAP[\kl{visible anchor points}] is an option that makes visible or invisible the \kl{anchor points} of the \cs{\AP} and \cs{\itemAP} commands.
-\end{description}
-
-
-%\subsubsection{Other configuration}
-
-%Another option at loading is "scope at 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 \cs{\knowledge} command and variations}
-\label{subsection:knowledge command}
-
-In this section, we describe the main commands that create \kl{knowledges}.
-The main one is \cs{\knowledge}. It can also be used in combination with \cs{\knowledgedirective}, \cs{\knowledgestyle} and \cs{\knowledgedefault}.
-
-\subsubsection{General description of the \cs{\knowledge} command}
-
-The key command for introducing knowledges is \cs{\knowledge}.
-The syntax is:
-\begin{center}
-\smallcode{\csintro\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 \cs{\knowledgedirective} command.
-
-\AP
-The principle of the \cs{\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 \cs{\knowledge} has to decide what to do when defining something. The basic behaviour is as follows.
-\begin{itemize}
-\item If the \cs{\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 \cs\knowledge.
-\item Import/Export (\kl{not implemented}) writes a document containing a list of \cs{\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.
- \cs{\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 \cs{\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 \cs\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 \cs{\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).
-\itemAP[\intro{also now}] requires the \kl{knowledge} to be defined immediately as well as delayed to the next compilation phase. This is in particular how "autorefrences at autoref" should be handled. See the use of \cs{\knowledgenewvariant} for more examples.
-\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 `\cs{\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 `\cs{\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 `\cs{\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,
-\itemAP[""detokenize""] detokenizes the content, i.e., instead of executing it provides a string that displays it (this is useful for commands),
-\itemAP[""remove space""]
-\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 \cs\kl. For instance,
- \smallcode{\cs\knowledge \{latex\}\{\kl{text=}\cs{\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 \cs{\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 \cs{\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]
-\cs\knowledge\{Leslie Lamport\}\par
-~~~~~\{\kl{ref=}\{https://fr.wikipedia.org/wiki/Leslie\_Lamport\}\}\\
-\cs\knowledge\{L. Lamport\}\{\kl{synonym}\}\\
-\cs\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=}\cs\robustdisplay,
-(where \csintro{\robustdisplay} is a variant of \cs{\tl_to_str:n} removing the trailing space) is used in this document for typesetting the commands.
-\end{compactdesc}
-
-
-\subsubsection{\kl{Knowledge styles} and the \cs{\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 \cs{\intro} command is displayed.
-See below for some instances.
-
-\AP
-The central command is \cs{\knowledgestyle}, that has the following syntax:
-\begin{center}
-\smallcode{\csintro{\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 \cs{\knowledge}
-command. When defined, a \kl{style} can be used in a \cs{\knowledge}
-command using the \kl[\knowledge directives]{directives} `\kl{style=}style name' (it will be used when a \cs{\kl} command calls for the \kl{knowledge}) or `\kl{intro style=}style name' (that will be used by \cs{\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[""kl@@style""] is the default style for macros using \cs{\kl}.
- It can be modified dynamically using the `\kl{style=}' \kl[\knowledge directives]{directive}.
-\itemAP[""kl unknown@@style"" and ""kl unknown cont@@style""] are
- the default \kl{styles} used when an undefined \kl{knowledge} is met.
-\itemAP[""intro@@style"" and ] is the default style for macros using \cs{\intro}.
- It can be modified dynamically using the `\kl{intro style=}' \kl[\knowledge directives]{directive}.
-\itemAP[""intro unknown@@style"" and ""intro unknown cont@@style""]
- are the default \kl{styles} used when an undefined \kl{knowledge} is met.
-\end{compactdesc}
-
-\subsubsection{New directives: the \cs{\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 \cs{\knowledgedefault} and \cs{\knowledgestyle}). This is achieved using the \cs{\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{\csintro{\knowledgedirective}\{name\}[optional parameter]\{directives\}}
-\end{center}
-After such a command has been issued, `name' becomes a \kl[\knowledge directives]{directive}
-usable in \cs{\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}
-\cs\knowledgedirective\{highlight\}[brown]\{\kl{color=}\{\#1\},\kl{emphasize},\kl{md}\}\\{}
-\kl{[...]}\\{}
-\cs\knowledge\{notion A\}\{highlight\}\\
-\cs\knowledge\{notion B\}\{highlight\}\\
-\cs\knowledge\{notion C\}\{highlight\}\\
-\cs\knowledge\{important notion D\}\{highlight=red\}\\{}
-\cs{[...]}\\
-We shall now see \cs\kl\{notion A\}, \cs\kl\{notion B\}, \cs\kl\{notion C\}, as well as the \cs\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{\cs{\knowledgestyle} versus \cs{\knowledgedirective}}
-\label{subsubsection:style versus macro}
-
-The two commands \cs{\knowledgestyle} and \cs{\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 \cs{\knowledge} command works.
-
-In general when a \cs{\knowledge} (or \cs{\knowledgestyle}) command is found, the \kl[\knowledge directives]{directives} are parsed and a new internal form of the \cs{\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 \cs{\kl} and similar commands.
-
-When a \cs{\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 \cs{\knowledgedefault} command}
-\label{subsubsection:default directives}
-
-It may happen that a sequence of consecutive \cs{\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 \cs{\knowledgedefault} command:
-\begin{center}
-\smallcode{\csintro\knowledgedefault*\{\kl[\knowledge directives]{directives}\}}
-\end{center}
-When such a command is applied, then from that point, all \cs{\knowledge} commands
-will use the given \kl[\knowledge directives]{directives} as default. This will stop when another \cs{\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 \cs{\kl} command}
-\label{subsection:kl command}
-
-\subsubsection{The standard syntax}
-
-\marginpar{\begin{hint} Note that the \cs{\kl} command can often be replaced by the
-\kl{"..."}{} notation, activated by the "quotation@@option" option.\end{hint}}
-
-
-The \cs{\kl} command has one of the following syntaxes:
-\begin{center}
-\begin{tabular}{cc}
-&\smallcode{\csintro{\kl}(\kl[klab]{optional label})[\kl[knowledge name]{optional knowledge name}]\{text\}}\\
-or\quad&
-\smallcode{\csreintro{\kl}[\kl[knowledge name]{optional knowledge name}](\kl[klab]{optional label})\{text\}}\ .
-\end{tabular}
-\end{center}
-Its meaning 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} `"kl unknown@@style"' (or similar "styles", as defined by the "unknown style=@@variant" or "unknown style cont=@@variant") 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 \cs{\kl} such as in particular \cs{\intro}.
-
-
-\subsubsection{The "quotation notation"}
-
-\phantomintro{"}\phantomintro{@}\phantomintro{quotation notation}%
-When activated, the ""quotation@@option"" mode activates shorthand
-notations for the \cs{\kl} and \cs{\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{\cs\kl\{text\}}.
-\itemAP[\smallcode{\kl"text at knowledge\kl"}]\phantomintro{"... at ..."}%
- uses the "knowledge" pointed to by `knowledge to display `text'. Equivalent to~\texttt{\cs\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{\cs\kl(label)\{text\}}.
-\itemAP[\smallcode{\kl"text at knowledge@label\kl"}]\phantomintro{"... at ...@..."}%
- uses the "knowledge" pointed to by `knowledge in "scope" `scope' to display `text'. Equivalent to~\texttt{\cs\kl[knowledge](label)\{text\}}.
-\itemAP[\smallcode{\kl{""}text\kl{""}}]\phantomintro{""...""}%
- introduces the "knowledge" pointed to by `text'. Equivalent to~\texttt{\cs\intro\{text\}}.
-\itemAP[\smallcode{\kl{""}text at knowledge\kl{""}}]\phantomintro{""... at ...""}%
- introduces the "knowledge" pointed to by `knowledge while displaying `text'. Equivalent to~\texttt{\cs\intro[knowledge]\{text\}}.
-\itemAP[\smallcode{\kl{""}text@@label\kl{""}}]\phantomintro{""...@@...""}%
- introduces the "knowledge" pointed by `text' in "scope" `scope'. Equivalent to~\texttt{\cs\intro(label)\{text\}}.
-\itemAP[\smallcode{\kl{""}text at knowledge@label\kl{""}}]\phantomintro{""... at ...@...""}%
- introduces the "knowledge" pointed to by `knowledge in "scope" `scope' while displaying `text'. Equivalent to~\texttt{\cs\intro[knowledge](label)\{text\}}.
-\end{description}
-
-\noindent\AP Activating and deactivating the "quotation notation" is obtained using:
-\begin{center}
-\smallcode{\cs\knowledgeconfigure\{"quotation@@option"\}}\ ,
-\end{center}
-and deactivating it is obtained using:
-\begin{center}
-\smallcode{\cs\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]
-\cs\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 \cs{\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}
-
-
-
-\subsubsection{\kl{Variants of \cs{\kl}}, \cs{\knowledgenewvariant}, \cs{\knowledgevariantmodifier} }
-\label{subsubsection:variants}
-\phantomintro{variant of \cs{\kl}}%
-It may happen for several reasons that we may want to define new variants of the \cs{\kl} macros, that essentially perform the same task, but are configured differently. Typical examples may be:
-\begin{itemize}
-\item several sets of "knowledges" may intersect but should use different "namespace",
-\item some "knowledges" involve macros and for this reason should be non-expanded even if the \cs{\knowledge}
- command is not met,
-\item the \cs{\knowledge} command should be performed automatically,
-\item activate or desactivate the warnings or messages in the "diagnose file".
-\end{itemize}
-In fact, several macros in this document are instantiation of this mechanism. This is the case for for instance for \cs{\intro}, \cs{\phantomintro}, \cs{\reintro} or \cs{\mathkl} etc...
-
-
-\AP The macro for introducing a new \reintro{variant of \cs{\kl}} is:
-\begin{center}
-\smallcode{\csintro{\knowledgenewvariant}\cs\variant\{\kl{variant directives}\}}
-\end{center}
-and is similar to the one for modifying the behavior of a "variant of \cs{\kl}":
-\begin{center}
-\smallcode{\csintro{\knowledgesetvariant}\cs\variant\{\kl{variant directives}\}}\ .
-\end{center}
-These command define/modify a/the macro \cs{\variant} that uses the same syntax as \cs{\kl}. \AP The \intro{variant directives} consist of a comma separated list of "directives@@variant" as follows:
-\begin{compactdesc}
-\itemAP[""namespace=@@variant""namespace] declares in which "namespace" (a string) the knowledges are to be searched.
- This means in particular that the \cs{\knowledge} concerned should be defined using the the proper "namespace=" directive.
-\itemAP[""default style=@@variant"", ""unknown style=@@variant"", ""unknown style cont=@@variant""\{list of "style" names\}]
- declares the style name to be used (1) by default when the "knowledge" is found, (2) when it is not found for the first time, and (3) the subsequent times.
-\itemAP[""style directive=@@variant""\{directive names list\}] defines a list (comma separated) of directives that can
- be used in a \cs{\knowledge} command to modify the aspect (for instance, the \cs{\intro} behavior is modified by the "intro style=" directive, while the \cs{\kl} command is configured using the "style=" directive). If the "directives" do not exist, these are created.
-\itemAP[""auto knowledge=@@variant""\{directives\}] declares that the use of \cs{\variant} should automatically execute a \cs{\knowledge} command, and what should be the directives it uses. See examples below.
-\itemAP[""unknown warning=@@variant""true/false] activates or deactivates the warnings when a "knowledge" is not found
- (for instance, these are deactivated in "paper mode"). True by default.
-\itemAP[""unknown diagnose=@@variant""true/false] activates or deactivates the corresponding messages in the "diagnose file". True by default.
-\itemAP[""suggestion=@@variant""\{directives\}] configures the "directives" to be suggested in the "diagnose file"
-when the "knowledge" is unknown.
-\itemAP[""PDF string=@@variant""\{code\}] gives a substitute text for "hyperref@@package" to use for producing the bookmarks. This code has to be expandable. The code may use three parameters; $\sharp1$ is the main text of the command, $\sharp 2$ is the optional parameter, and $\sharp 3$ is the scope. The macro \cs{\IfNoValueTF} of the package "xparse@@package" can be used to test if the second and third arguments are present. By default, the code is \texttt{\{$\sharp1$\}}. Note that the star syntax cannot be used in this context. It the expected result cannot be achieved usinf this directive, the less convenient macro \cs{\texorpdfstring} of the "hyperref@@package" should be used.
-\end{compactdesc}
-\smallskip
-
-\AP The second feature is to use "modifiers@@variant". These correspond to the starred version of the command.
-For instance, one expects `\cs{\intro}*\cs{\kl}' to reduce to `\cs{\intro}'. For this, one has to declare explicitly the reduction using:
-\begin{center}
-\smallcode{\csintro{\knowledgevariantmodifier}\{"starred sequence@@variant"\}\cs\variant}\ ,
-\end{center}
-in which the "starred sequence@@variant" is of the form `\cs{variant1}*\cs{variant2}*\dots*\cs{variantk}'.
-This sequence is declared to reduce to \cs{\variant}.
-For instance, \smallcode{\cs{\knowledgevariantmodifier}\{\cs\intro*\cs\kl\}\cs\intro} declares `\cs{\intro}*\cs{\kl}' to reduce to `\cs{\intro}'.
-
-\subsubsection{Examples of \kl{variants of \cs{\kl}}}
-
-The best way for introducing new variants is to look at examples. We provide two of them now.
-the first one is the configuration of the \cs{\kl} and \cs{\intro} commands as defined in the "package at knowledge@package".
-The second one is the code used in this documentation for displaying macros, defining the macros \cs{\cs}
-and \cs{\csintro}.
-
-\paragraph{The configuration of \cs{\kl} and \cs{\intro}} It is also interesting to see this code since it gives more ideas on how to modify the standard behaviour of these commands correctly.
-\begin{code}
-\cs\knowledgestyle\{autoref link\}\{"autoref link"\}\par
-\cs\knowledgestyle\{autoref target\}\{"autoref target"\}\par
-\cs\knowledgestyle\{invisible\}\{"invisible"\}\par
-\cs\knowledgenewvariant\cs\kl\{\par
-~~~~"namespace=@@variant"default,\par
-~~~~"default style=@@variant"\{"kl@@style",autoref link\},\par
-~~~~"unknown style=@@variant" "kl unknown@@style",\par
-~~~~"unknown style cont=@@variant" "kl unknown cont@@style",\par
-~~~~"style directive=@@variant" "style at style="\par
-\}\par
-\cs\knowledgenewvariant\cs\intro\{\par
-~~~~"namespace=@@variant" default,\par
-~~~~"default style=@@variant" \{"intro@@style",autoref target\},\par
-~~~~"unknown style=@@variant" "intro unknown@@style",\par
-~~~~"unknown style cont=@@variant" "intro unknown cont@@style",\par
-~~~~"style directive=@@variant" "intro style at intro style="\par
-\}\par
-\cs\knowledgevariantmodifier\{\cs\intro*\cs\kl\}\cs\intro
-\end{code}
-Note that \cs{\reintro} and \cs{\phantomintro} are defined using similar code.
-
-\paragraph{Displaying control sequences}
-
-\AP The second code example is used in this document (the documentation of the package) and consists of two macros \csintro{\cs} and \csintro{\csintro} which have the
-following semantics:
-\begin{itemize}
-\item these have the same syntax as \cs{\kl} and \cs{\intro} respectively.
-\item these are used to display control sequences without executing it,
-\item if \cs{\csintro} is never used, it appears in black,
-\item is \cs{\csintro} is used, then it is in color blue, and the calls to \cs{\cs}
- are in dark blue, and furthermore, the \cs{\cs} calls possess an hyperlink to
- the call to \cs{\csintro}.
-\item no \cs{\knowledge} command is necessary, and no warnings are issued.
-\end{itemize}
-\begin{code}
-\cs\knowledgestyle\{cs\}\par
-~~~~\{"detokenize","remove space","typewriter","up","md","color="NavyBlue\}\par
-\cs\knowledgestyle\{cs unknown\}\par
-~~~~\{"detokenize","remove space","typewriter","up","md","color="black\}\par
-\cs\knowledgenewvariant\cs\cs\{\par
-~~~~"namespace=@@variant"cs,\par
-~~~~"default style=@@variant"\{autoref link,cs\},\par
-~~~~"unknown style=@@variant"cs unknown,\par
-~~~~"unknown style cont=@@variant"cs unknown,\par
-~~~~"unknown warning=@@variant"false,\par
-~~~~"unknown diagnose=@@variant"false,\par
-~~~~"suggestion=@@variant"cs\par
-\}\par
-\cs\knowledgestyle\{csintro\}\par
-~~~~\{"detokenize","remove space","typewriter","up","md","color="blue\}\par
-\cs\knowledgestyle\{csintro unknown\}\par
-~~~~\{"detokenize","remove space","typewriter","up","md","color="black\}\par
-\cs\knowledgenewvariant\cs\csintro\{\par
-~~~~"namespace=@@variant"cs,\par
-~~~~"auto knowledge=@@variant"\{"autoref","scope="document,"also now"\},\par
-~~~~"default style=@@variant"\{autoref target,csintro\},\par
-~~~~"unknown style=@@variant"csintro unknown,\par
-~~~~"unknown style cont=@@variant"csintro unknown,\par
-\}\par
-\cs\knowledgevariantmodifier\{\cs\intro*\cs\cs\}\cs\csintro\par
-\cs\knowledgevariantmodifier\{\cs\csintro*\cs\cs\}\cs\csintro\par
-\cs\knowledgevariantmodifier\{\cs\cs*\cs\kl\}\cs\cs\par
-\cs\knowledgevariantmodifier\{\cs\csintro*\cs\kl\}\cs\csintro
-\end{code}
-Several things can be noted about this code:
-\begin{asparaitem}
-\item the "directives" "detokenize" and "remove space" prevent the execution of the argument, and instead display its name, this is important since the argument is a control sequence,
-\item the "directives" "typewriter", "up" and "md" give a uniform aspect (no italic, no boldface) to the result in all contexts,
-\item the "namespace" is set to be different from the default one, avoiding possible clashes with \cs{\kl},
-\item when a \cs{\csintro} command is met, the corresponding \cs{\knowledge} command is automatically issued, in particular with `"scope="document' for guaranteeing the visibility of each command everywhere in the document,
-\item the "also now" directive is necessary for the compilation to (possibly) stabilize in
- two iterations, since it uses the proper \cs{\label} already at the first iteration (without "also now", it would be performed on the second one only, and with just "now", it would be visible only by the uses after the introduction).
-\item warnings and diagnose information is explicitly eliminated.
-\end{asparaitem}
-
-
-
-\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.
-
-Note that the use of "scopes" may overconstrain the latex code, in particular if the "scope@@option" is used. The result is that a code that was compiling before activating the option, will not after doing it. This may happen for instance if one uses a \cs{\section} command inside a
-a \cs{theorem} environment. Of course, though this is not forbidden by "latex", this is not something that one usually wants to do. At any rate, the scope handling of the "knowledge@@package" package --- at least in its current form --- complains in such a situation. Indeed, it attempts to reconstruct a full hierarchically decomposed version of the document. In the above example, when the \cs{\section} command is met, the package attempts to close the outer section, but this would force the theorem also to be closed. However, closing a theorem requires an \cs{\end} command. Error...
-
-\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]
- \cs\begin\{\kl(env){scope}\}\par
- ~~\cs\knowledge\{local notion\}\{\kl{color=}green\}\par
- ~~Here is a \cs\kl\{local notion\} that appears in green.\par
- \cs\end\{\kl(env){scope}\}\\
- But this \cs\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 \cs{\knowledgeconfigureenvironment}.
- \itemAP The use of the ""scope at 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, may cause some compiling document to not compile anymore if some weird (and unnatural) nesting of scopes are used.
-\end{itemize}
-
-\subsubsection{How is chosen the \kl{scope} of a \kl{knowledge}?}
-
-In general, when a \cs{\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 did not perform its own configuration), this is the inner most \kl(env){scope} environment (or similar environment if \cs{\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]
- \cs\section\{First section\}\par\noindent
- \cs\label\{section:first\}\par\noindent
- \cs\knowledge\{one\}\{\kl{scope=}section,\kl{color=}green\}\par\noindent
- \cs\knowledge\{two\}\{\kl{scope=}some label,\kl{color=}green\}\par\noindent
- ~\par\noindent
- \cs\begin\{\kl(env){scope}\}\cs\label\{some label\}\par\noindent
- ~~Here \cs\kl\{one\} and \cs\kl\{two\} are defined.\par\noindent
- \cs\end\{\kl(env){scope}\}\par\noindent
- Here \cs\kl\{one\} is defined but \cs\kl\{two\} isn't.\par\noindent
- ~\par\noindent
- \cs\section\{Second section\}\par\noindent
- Here neither \cs\kl\{one\} nor \cs\kl\{two\} is defined.
- However, I can still use them using \cs\kl(section:first)\{one\} and \cs\kl(some label)\{two\}
- (or \kl"one@@section:first\kl" and \kl"two@@some label\kl", or using the \cs{\knowledgeimport}\{section:first\}).
- \end{code}
-\end{itemize}
-
-\subsubsection{Accessing other scopes, the \cs{\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{\cs\kl(label)\{text\}} command (or the equivalent \smallcode{\kl{"... at ...@..."}} notation), or use the \cs{\knowledgeimport} command. We describe the second possibility now. The syntax is:
-\begin{center}
-\smallcode{\csintro\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]
-\cs\knowledgeconfigureenvironment\{theorem,proof\}\{\}\par\indent
-{[...]}\par\indent
-\cs\begin\{theorem\}\cs\label\{theorem:1\}\par\noindent
-~~\cs\knowledge\verb|\alpha|\{\kl{autoref},\kl{color=}red\}\par\noindent
-~~Let \$\cs\intro\verb|\alpha|\$ be an integer [...]\par\noindent
-\cs\end\{theorem\}\par\noindent
-{[...]}\par\indent
-Here \$\cs\kl\verb|\alpha|\$ is unknown.\par\noindent
-{[...]}\par\indent
-\cs\begin\{proof\}\par\noindent
-~~\cs\knowledgeimport\{theorem:1\}\par\noindent
-~~But now \$\cs\kl\verb|\alpha|\$ points to its definition.\par\noindent
-\cs\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 \cs{\knowledgeconfigureenvironment}, as well as adapt some of its characteristics using
-"scope directives".
-\begin{center}
- \smallcode{\csintro\knowledgeconfigureenvironment\{environments\}\{"scope directives"\}}
-\end{center}
-For instance:
-\begin{code}[12cm]
- \cs\knowledgeconfigureenvironment \{lemma,theorem,fact,proof\}\par
- ~~~~~~~~\{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 \cs{\begin} and \cs{\end}. Hence \cs{\proof}\dots\cs{\endproof} would
- not trigger a scoping environment while \cs{\begin{proof}}\dots\cs{\end{proof}}
- would.
-\end{remark}
-
-\AP The ""scope directives"" are low level and advanced features. These should not be used in general. Their list is 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 \cs{\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 using the \cs{\begin} and \cs{\end} commands of "latex".
- \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). It should be true for "latex" environments, and false when configuring, e.g, \cs{\section} to open an "scope" (since the end of the section is automatic: when another section is opened, or some higher level sectioning command).
- \itemAP[\intro(area){parents=}\{"area1 at area","area2 at area",\dots\}] takes a comma separated list of areas that are allowed as parent. For opening the area, some enclosing instances may be automatically closed for reaching such a parent (if their "autoclose=@@area" "directive at scope directive" is set to true).
- \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 \cs{\intro} and \cs{\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
-Very often there is some \kl[undefined knowledge]{undefined knowledge}.
-Such \kl{knowledges} are displayed using "kl unknown@@style" and "kl unknown cont@@style")
-\kl{styles} when issued by \cs{\kl}; using "intro unknown@@style" and "intro unknown cont@@style" when issued by \cs{\intro}.
-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 sometimes check 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 \texttt{\cs{\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. By default, no suggestion is offered (i.e., the \texttt{\{\}} braces are empty). Suggestion can be automatically configured using the "suggestion=@@variant" "directive@@variant" of the macros \cs{\knowledgenewvariant} and \cs{\knowledgesetvariant}.
-
-For instance, using:
-\begin{center}
-\smallcode{\cs\knowledgesetvariant\cs\kl\{"notion"\}}
-\end{center}
-the "directive" "notion" is suggested for more directly copying the content.
-\itemAP[\intro{Autoref not introduced}] This section lists all \kl{knowledges} that were declared using the \kl{autoref} \kl[\knowledge directives]{directive} (this can be the case indirectly using, e.g. "notion"), but have not been introduced in the document . When a document reaches its final states, this section should be empty.
-Usually, one should add the corresponding \cs{\intro} or \cs{\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 \cs{\intro} or \cs{\nointro}
-more than once are listed. When a document reaches its final states, this section should be empty. Consider using \cs{\kl} or \cs{\reintro} for solving the problem.
-Note that this may be caused by an \cs{\intro} used in some title (and repeated in the table of contents).
-\end{description}
-
-\AP By default, the "diagnose file" does not give the file and the line of the messages.
-This can be activated using the "diagnose line" boolean option:
-\begin{center}
-\smallcode{\cs\knowledgeconfigure\{""diagnose line=""true\}}
-\end{center}
-
-\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 \cs{\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}
-\cs\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 \csintro\knowledgeexportscopename
-\item \csintro\knowledgeexportbase
-\item \csintro\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 (this are visible in some viewers, and not in some others): this is deactivated by the "knowledge@@package" package using the "hidelinks" option of "hyperref@@package".\end{hint}}
-\begin{center}
-\smallcode{%
-\cs{\usepackage}[\kl(option){hyperref}]\{\kl(package){knowledge}\}}
-\end{center}\noindent
-or by loading the "hyperref@@package" before the "knowledge@@package" package.
-
-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 \cs{\intro} command.
-\item[\kl{autorefhere}] puts immediately a label at the location of the definition, and makes all \cs{\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 \csintro{\intro} (exactly once) --
-or the \kl{""...""} and \kl{""... at ...""} notations (and variants) if \kl(option){quotation} is active -- and \cs{\kl} (possibly several times) -- or the \kl{"..."} notation if \kl(option){quotation} is active. The use of \cs{\kl}
-will hyperlink to the location of the \cs{\intro}. The syntax of \cs{\intro} is the same as
-for \cs{\kl}:
-\begin{center}
-\smallcode{\cs{\intro}[optional knowledge name]\{knowledge name\}}
-\end{center}
-
-\emph{See \cs{\AP} below for improving the result.}
-
-A typical use looks as follows:
-\marginpar{\begin{hint}
- Though the \cs{\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}
-\cs\knowledge\{house\}[Houses\vbar houses]\{\kl{autoref}\}\\~
-\kl{[...]}\\
-\cs\begin\{document\}\\~
-\kl{[...]}\\
-In this document, we will see the very important notion of \kl{"}houses\kl{"}.\\~
-\kl{[...]}\\
-\cs\AP\\
-Let us define a \kl{""}house\kl{""} to be a building that functions as a home.\\~
-\kl{[...]}\\
-\cs\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 \csintro{\intro*} makes the next \cs{\kl} command behave like \cs{\intro}. This is useful in particular in math mode:
-\begin{code}
-\cs\newcommand\kl[@token]\monoid\{\cs\kl[\kl[@token]\monoid]\{\cs\mathcal M\}\}\\
-\cs\knowledge\kl[@token]\monoid\{autoref\}\\~
-\kl{[...]}\\
-\cs\AP\\~
-Let now \$\cs{\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 \csintro{\phantomintro} version:
-\begin{center}
-\smallcode{\cs{\phantomintro}(optional label)\{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{\cs\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 \csintro{\nointro} command:
-\begin{center}
-\smallcode{\cs{\nointro}\{knowledge\}}
-\end{center}
-does not display anything and silently prevents the knowledge from issuing warnings
-because it is not introduced.
-
-\AP
-The \csintro{\reintro} command:
-\begin{center}
-\smallcode{\cs{\reintro}[optional knowledge]\{knowledge\}}
-\end{center}
-is displayed as for \cs{\intro}, but without being an anchor for hyperlinks, and without counting as a real \cs\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 \csintro{\reintro*} that makes the next \cs{\kl} command behave like a \cs{\reintro} (similar to \cs{\intro*} with respect to \cs{\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 \cs{\intro},
-there are new directives:
-\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 \cs{\intro} or \cs{\reintro} command.
-\itemAP[\intro{autoref target}] declares the knowledge to be the target of the autoref (this is implicit when using \cs{\intro}).
-\itemAP[\intro{autoref link}] requires a link to the target of the autoref to be produced (this is implicit when using \cs{\kl}).
-\end{description}
-See the use of \cs{\knowledgesetvariant} for examples of configuration.
-%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 \cs{\knowledge} command invoking it.
-Uses of \cs{\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 \cs{\intro} command. This is a bit better since using \kl{autoref} in 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" package. This means that it puts à label at the place of the \cs{\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 \cs{\intro} happens in a `section' (but not inside a theorem-like envionment) then the \cs{\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 \csintro{\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[\csintro{\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 \cs{\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 \cs{\item}, one should use instead:
-\itemAP[\csintro{\itemAP}] Similar to \cs\AP, but to be used instead of an \cs\item.
-\end{compactdesc}
-\smallskip
-
-Usually putting an \cs{\AP} (a standard command of the "hyperref@@package") at the beginning of every paragraph, and replacing \cs{\item} by \cs{\itemAP} in itemize-like environments is most of the time good and safe option.
-
-For instance:
-\begin{code}[12.5cm]
-\cs\AP\\
- In order to describe what is a \cs\kl\{monoid\}, let us us first define
-a \cs\intro\{product\} to be an associative binary operator,
-and a \cs\intro\{unit\} to be \kl{[...]}
-\bigskip
-
-\cs\begin\{description\}\\
-\cs\itemAP[A \cs\intro\{semigroup\}] is a set equipped with a \cs\kl\{product\}.\\
-\cs\itemAP[A \cs\intro\{monoid\}] is a \cs\kl\{semigroup\} that has a \cs\kl\{unit\}.\\
-\cs\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 \cs{\AP} and \cs{\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
-this graphical help disappears.
-This can also be desactivated using:\phantomintro{visible anchor points}
- \begin{code}[9cm]
- \cs\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{\cs{\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 \cs{\index} command when a \cs{\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 \cs{\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 using using
-\begin{center}
-\smallcode{\cs\knowledgeconfigure\{""fix hyperref twocolumn""\}}.
-\end{center}
-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{\cs\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 \cs{\intro} commands (not in math mode) are emphasized, while the \cs{\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}
-\cs\documentclass\{article\}\\
-\cs\usepackage\{\kl(package){xcolor}\}\\
-\cs\usepackage\{\kl(package){hyperref}\}\\
-\cs\usepackage[\kl{paper}]\{"knowledge@@package"\}\\
-\cs\knowledgeconfigure\{"notion@@option"\}\\
-{[...]}\\
-\cs\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 \cs{\intro} command. When it is used, and all the \cs{\knowledge} commands are in the preamble, then two phases are necessary. When \cs{\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 \cs{\item} parameters}
-
-\paragraph{The use of~\cs{\AP} inside \cs{\item} does not work.} Do not use \cs{\AP} inside the optional argument of \cs{\item}, and rather use the command \cs{\itemAP}.
-
-\paragraph{Argument of \cs{\kl} has an extra `\texttt\}'.} This is a problem of using optional parameters inside optional parameters such as in \smallcode{\cs\item[\cs\kl[test]\{Test\}]}. You can surround the content of the optional parameter by two level of curly braces as in \smallcode{\cs\item[\{\{\cs\kl[test]\{Test\}\}\}]}.
-The notation \kl{"..."} does not have this issue.
-
-
-
-
-\subsection{Knowledges and moving arguments (table of contents, \dots).}
-
-
-
-\paragraph{The use of \cs{\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 \cs{\kl} command complains of not knowing the \kl{knowledge}. For instance\footnote{with \texttt{\cs\usepackage[utf8]\{inputenc\}} and, for instance \texttt{\cs\usepackage[T1]\{fontenc\}} for the accents.}:
-\begin{center}
-\begin{code}[11cm]
-\cs\newcommand\robustdisplay\Ltwo\{\cs\ensuremath\{L\^{}2\}\}\\
-\cs\knowledge\{\robustdisplay\Ltwo-space\}[\robustdisplay\Ltwo-spaces]\{autoref\}\\
-\cs\knowledge\{\'etale topology\}[\'Etale topology]\par
-~~~~~~~\{\kl{url=}\{https://en.wikipedia.org/wiki/\'Etale\_topology\}\}\\
-{[...]}\\
-\cs\begin\{document\}\\
-\cs\tableofcontents\\
-\cs\section\{On \cs\kl\{\robustdisplay\Ltwo-spaces\}\\
-{[...]}\\
-\cs\section\{On the \cs\kl\{\'etale topology\}\}\\
-{[...]}\\
-\cs\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 \cs{\newrobustcmd} (of the \kl(package){etoolbox} package) or \cs{\NewDocumentCommand} (of the \kl(package){xparse} package, with a different handling of arguments) instead of \cs{\newcommand}. Hence:
-\begin{code}
-\cs\newrobustcmd\robustdisplay\Ltwo\{\cs\ensuremath\{L\^{}2\}\}
-\end{code}\noindent
-solves the first problem.
-\item Using an equivalent text that does not have the problem:
- \begin{code}
- \cs\knowledge\{$\backslash$'etale topology\}\{\kl{link=}\'etale topology\}\\
- {[...]}\\
- \cs\section\{On the \cs\kl\{$\backslash$'etale topology\}\}
- \end{code}
-\item Both problems can be solved using synonyms/links that have no problem. For instance:
- \begin{code}
- \cs\knowledge\{Ltwo-space\}\{\kl{link=}\robustdisplay\Ltwo-space\}\\
- \cs\knowledge\{etale topology\}\{\kl{link=}\'etale topology\}\\
- {[...]}\\
- \cs\section\{On \cs\kl[Ltwo-space]\{\robustdisplay\Ltwo-spaces\}\}\\
- \cs\section\{On the \cs\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 \cs{\intro} in a section title causes introducing the knowledge twice.}
-Do not use \cs{\intro} in titles, but rather \cs{\reintro}. If you want the section to be the target of the \kl{knowledge}, then put after the section a \cs{\pantomintro} command.
-\begin{center}
-\begin{tabular}{ccc}
-%\hline
-\begin{code}[5.5cm]
-\cs\section\{On \cs\intro\{topology\}\}\\
-\end{code}&&
-\begin{code}[5.9cm]
-\cs\section\{On \cs{\reintro}\{topology\}\}\\
-\cs{\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"
-
-This can be doe either explicitely using before each figure:
-\begin{code}[8.5cm]
-\cs\knowledgeconfigure\{"quotation@@option"=false\}
-\end{code}
-\noindent
-and after the figure:
-\begin{code}[7cm]
-\cs\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]
-\cs\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 \cs{\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 \cs{\intro}, which internally uses {\cs\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 \cs\phantomsection, and then use \cs{\reintro} inside the environment. Imagine for instance a command
-\texttt{\robustdisplay\SomeCommand}, that inside uses \texttt{\cs\kl[\robustdisplay{\Somecommand}]}, then:
-\begin{center}
- \begin{tabular}{ccc}
- does not work&&works\\
- \begin{code}[5cm]
- \cs\begin\{\kl{align*}\}\\
- \cs\intro*\texttt{\robustdisplay{\SomeCommand}}\\
- \cs\end\{\kl{align*}\}\\
- \end{code}
- &&
- \begin{code}[5cm]
- \cs\phantomintro\texttt{\robustdisplay{\SomeCommand}}\\
- \cs\begin\{\kl{align*}\}\\
- \cs\reintro*\texttt{\robustdisplay{\SomeCommand}}\\
- \cs\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{\cs\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
-\cs\usepackage[\kl{breaklinks}]\{\kl(package){hyperref}\}\par\noindent
-\kl{[...]}\par\noindent
-\cs\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$\quotesymbol.}
-\end{pquote}\noindent
-or definitively using:
-\begin{pquote}
-\texttt{(defun my-hook () (local-unset-key \quotesymbol$\backslash$\quotesymbol\quotesymbol))\\
-(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 at irif.fr}.
-
-\newpage
-
-\section{Resources}
-\label{section:resources}
-
-\subsection{List of commands}
-\begin{compactdesc}
-\item[\cs\AP] introduces an "anchor point".
-\item[\cs\intro] searches for a \kl{knowledge} and put an anchor to it (to be used with the \kl{autoref} directive).
-\item[\cs\kl] searches for a \kl{knowledge} and displays it accordingly.
-\item[\cs\knowledge] defines new \kl{knowledges}.
-\item[\cs\knowledgeconfigure] configures the package.
-\item[\cs\knowledgedirective] defines a new \kl[\knowledge directives]{directive}.
-\item[\cs\knowledgedefault] declares the default \kl[\knowledge directives]{directives} to be automatically used in \cs{\knowledge} commands.
-\item[\cs\knowledgeimport] gives access to \kl{knowledges} existing in other scopes.
-\item[\cs\knowledgenewvariant] defines a new "variant of \cs{\kl}".
-\item[\cs\knowledgesetvariant] configures a "variant of \cs{\kl}".
-\item[\cs\knowledgestyle] defines a new \kl{style}.
-\item[\cs\knowledgevariantmodifier] declares a meaning of \cs{*} in "variants of \cs{\kl}".
-\item[\cs\nointro] declares that the knowledge will never be introduced (does not work properly yet).
-\item[\cs\phantomintro] performs an invisible \cs\intro.
-\item[\cs\reintro] uses the \kl{display style} of \cs{\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 \kl{directives} (to use with \cs{\knowledge})}
-\label{subsection:directive list}
-
-
-\begin{compactdesc}
-\item["autoref"] Activates the \cs{\intro} feature (requires the "hyperref@@package").
-\item["autoref link"] activates an hyperlink to the target.
-\item["autoref target"] puts a target for a hyperlink.
-\item[\kl{autorefhere}] creates an \kl{anchor point} that points to the \cs{\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{detokenize}] Avoids evaluation of the text.
-\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{invisible=}] no display
-\item[\kl{italic=}] displays in italic
-\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{remove space}] removes the spaces from the input
-\item[\kl{typewriter}] Typeset in as with \cs{\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 \cs{\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){kl unknown}, \kl(style){kl unknown cont}]
-\itemAP[\kl(style){intro unknown}, \kl(style){intro unknown cont}]
-\itemAP[\kl(style){notion}] (if "notion" is activated)
-\itemAP[\kl(style){intro notion}] (if "notion" is activated)
-\end{compactdesc}
-
-
-
-
-
-
-
-
-
-
-
-\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} %
-% \changes{v1.05}{2017/09/26}{minor changes,bug fixes} %
-% \changes{v1.06}{2017/10/10}{bug correction} %
-% \changes{v1.07}{2017/10/13}{minor improvements} %
-% \GetFileInfo{knowledge.sty} %
-% \DoNotIndex{}
-%
-%
-%\let\ifcode\iffalse
-%
-%%%%%%%%%%
-%
-% \section{Implementation}
-% \label{section:code}
-%
-% \subsection{Code preparation}
-%<*head>
-% \begin{macrocode}
-\RequirePackage{l3keys2e}
-\RequirePackage{etoolbox}
-\RequirePackage{xparse}
-\RequirePackage{etoolbox}
-\bool_if_exist:NTF\knowledge_package_loaded_bool
- {\endinput}
- {\bool_new:N\knowledge_package_loaded_bool
- \bool_set_true:N\knowledge_package_loaded_bool}
-% \end{macrocode}
-%</head>
-%\begin{center}
-% The content of \texttt{knowledge-utils.sty} is inserted here.\\
-%\end{center}
-%<*package>\\
-% Macros to skip pieces of code depending on some bool. This can certainly be done differently.
-% \begin{macrocode}
-\cs_new:Nn\knowledge_begin_module_if:n
- {\bool_if:NF#1\knowledge_skip_module:}
-\cs_new:Npn\knowledge_skip_module:#1\knowledge_end_module:
- {}
-\cs_new:Nn\knowledge_end_module:
- {}
-% \end{macrocode}
-%
-%\AP One defines the code of \csintro{\klparse_ifnextchar:NTF}
-% which is a link to \cs{\@ifnextchar},
-% as well as the constant \csintro{\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}
-% \end{macrocode}
-% \begin{macrocode}
-\tl_new:N\klparse_novalue_tl
-\NewDocumentCommand\klparse_setnovalue{o}
- {\tl_set:Nn\klparse_novalue_tl{#1}}
-\klparse_setnovalue\relax
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Npn\klparse_if_novalue:NTF
- {\tl_if_eq:NNTF\klparse_novalue_tl}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_generate_variant:Nn\tl_to_str:n{V}
-% \end{macrocode}
-%
-% \subsection{Messages of the package}
-%
-%\AP First, some generic messages that are produced using \csintro{\knowledge_info:n},
-% \csintro{\knowledge_warning:n} and \csintro{\knowledge_error:n}
-% as well as the argument expending versions.
-% These are mainly for development purposes.
-% \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}}
-% \end{macrocode}
-% \begin{macrocode}
-\msg_new:nnnn{knowledge}{knowledge~info}{#1}{#2}
-\msg_new:nnnn{knowledge}{knowledge~warning}{#1}{#2}
-\msg_new:nnnn{knowledge}{knowledge~error}{#1}{#2}
-% \end{macrocode}
-% \begin{macrocode}
-\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}
-%\AP We provide now the `official' messages \csintro{knowledge~recursion}, \csintro{knowledge~unknown},
-% \csintro{knowledge~unknown~in~scope}, \csintro{knowledge~unknown~label}, \csintro{package~required} and \csintro{knowledge~exists}.
-% \begin{macrocode}
-\msg_new:nnn{ knowledge }{ knowledge~recursion }
- { The~knowledges~are~probably~cyclic,~starting~from~'#1'~(namespace~'#2'),~
- currently~at~'#3'.}
-% \end{macrocode}
-% \begin{macrocode}
-\msg_new:nnn{ knowledge }{ knowledge~unknown }
- {The~knowledge~'#1'~could~not~be~found~in~scopes~<~#3~>~(namespace~'#2').}
-% \end{macrocode}
-% \begin{macrocode}
-\msg_new:nnn{ knowledge }{ knowledge~unknown~in~scope }
- {The~knowledge~'#1'~could~not~be~found~in~scope~'#3'~(namespace~'#2').}
-% \end{macrocode}
-% \begin{macrocode}
-\msg_new:nnn{ knowledge }{ knowledge~unknown~label }
- {The~label~'#2'~could~not~be~found~while~searching~for~'#1'.~Possibly~rerun~latex.}
-% \end{macrocode}
-% \begin{macrocode}
-\msg_new:nnn{ knowledge }{ package~required }
- {In~order~to~use~directive~'#1',~please~load~package~or~use~option~'#2'.}
-% \end{macrocode}
-% \begin{macrocode}
-\msg_new:nnn{ knowledge }{ knowledge~exists }
- { The~knowledge~'#1'~in~scope~'#2'~(namespace~'#3')~already~exists. }
-% \end{macrocode}
-%
-%\AP The messages when there is a problem with scoping are \csintro{area~exists}, \csintro{area~not~exist},
-% \csintro{empty~pop}, \csintro{no~pushing~here}, \csintro{no~popping},
-% \csintro{no~popping~here}, \csintro{unknown~label} and \csintro{area~not~in~context}.
-% \begin{macrocode}
-\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}
-%\AP We define new the final messages, that are thrown at the end of the compilation as a recap that some problems occured. These are: \csintro{recap~unknown~knowledge}, \csintro{recap~autoref~introduced~twice} and \csintro{recap~autoref~not~introduced}.
-% \begin{macrocode}
-\msg_new:nnn{knowledge}{recap~unknown~knowledge}
- {Some~knowledge~are~not~defined.~See~the~'.diagnose'~file~for~more~information.}
-\msg_new:nnn{knowledge}{recap~autoref~introduced~twice}
- {Some~knowledge~is~introduced~twice.~See~the~'.diagnose'~file~for~more~information.}
-\msg_new:nnn{knowledge}{recap~autoref~not~introduced}
- {Some~knowledge~is~used~but~not~introduced.~See~the~'.diagnose'~file~for~more~information.}
-% \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 \cs{\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 \csintro{\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.
-%
-% \ToImprove{I do not know why, but \cs{\ProcessKeysOptions} removes the spaces in the parameters.
-% So we have to do the same if we want to load options this way. This does not seem canonical.}
-%
-% We first provide a token list that stores the configurations (which are different from the options).
-% \begin{macrocode}
-\tl_clear_new:N\knowledge_configuration_pending_tl
-% \end{macrocode}
-%
-%
-% \paragraph{Configuration options}
-% We provide here the code that is used to create new options for \cs{\knowledgeconfigure}.
-% At the same time, it sets at package loading these options to be `posponed' (these will be executed)
-% when the package loading is completed.
-% \begin{macrocode}
-\newrobustcmd\knowledgeconfigure[1]{
- \keys_set:nn{ knowledge~configuration~options }{#1}
-}
-% \end{macrocode}
-%
-% \begin{quote}
-% \csintro{\KnowledgeConfigureBooleanOption}[\cs{optional_bool}]\{option name\}\par
-% \csintro{\KnowledgeConfigureBooleanOptionTF}[\cs{optional_bool}]\{option name\}\par
-% ~~~~~~~~\{true code\}\{false code\}
-% \end{quote}
-% It takes an optional bool (of \kl(package){expl3}) and the name of the configuration option.
-% The option is defined both in \cs{knowledge~package~options},
-% and in \cs{knowledge~configuration~options}.
-% In the former case, the option is simply appended to \cs{\knowledge_configuration_pending_tl} for
-% being executed at the end of package loading.
-% \begin{macrocode}
-\NewDocumentCommand\KnowledgeConfigureBooleanOption{om}
- {\KnowledgeConfigureBooleanOptionTF[#1]{#2}{}{}}
-\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}
-}}
-% \end{macrocode}
-%\begin{quote}\tt
-% \csintro{\KnowledgeConfigureTrigger}\{option name\}\{code\}
-%\end{quote}
-% triggers the code when the corresponding configuration option is required.
-% \begin{macrocode}
-\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}} }}
- }
-}
-% \end{macrocode}
-%
-%
-%
-% \paragraph{Package loading options}
-%
-% \begin{quote}\tt
-% \csintro{\KnowledgePackageTrigger}\{package option\}\{code\}
-% \end{quote}
-% is similar to \cs{\KnowledgeConfigureTrigger} but only valid at package loading and not in \cs{\knowledgeconfigure}.
-% \begin{macrocode}
-\newrobustcmd\KnowledgePackageTrigger[2]
- { \keys_define:nn{ knowledge~package~options }{ #1 .code:n = {#2} }
- \keys_define:nn{ knowledge~configuration~options }{
- #1 .code:n = {\knowledge_error:n
- {The~configuration~directive~`#1'~can~only~be~used~at~package~loading.}}
- }}
-% \end{macrocode}
-% \begin{quote}\tt
-% \csintro{\KnowledgePackageBooleanOption}[\cs{optional_bool}]\{optionname\}
-% \end{quote}
-% defines a Boolean package option, the value of which being stored in \cs{optional_bool}.
-% If no \cs{optional_bool} is given, then \cs{\knowledge_configuration_optioname_bool}
-% is chosen.
-% \begin{macrocode}
-\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 = {\knowledge_error:n
- {The~configuration~directive~`#2'~can~only~be~used~at~package~loading.}}
- }}
-% \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}
-%
-%
-% \subsubsection{List of options that have to be prepared}
-%
-% Code for a single feature. It takes the name of the trigger followed by the code.
-%
-% \begin{macrocode}
-\bool_new:N\knowledge_configuration_quotation_bool
-\KnowledgeConfigureBooleanOptionTF[\knowledge_configuration_quotation_bool]{quotation}{\klactivatequotation}{\kldeactivatequotation}
-\KnowledgeConfigureTrigger{protect~quotation}{\kl_protect_environment_quotation:n{#1}}
-% \end{macrocode}
-%
-% \begin{macrocode}
-\bool_new:N\knowledge_configuration_diagnoseline_bool
-\bool_gset_false: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 are stored in \csintro{\knowledge_option_mode_tl}.
-% \begin{macrocode}
-\tl_clear_new:N\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}
-%
-%\csintro{\knowledge_xcolor_active_bool}, \csintro{\knowledge_xcolor_syntax_bool},
-%\csintro{\knowledge_hyperref_active_bool}, \csintro{\knowledge_hyperref_syntax_bool},
-%\csintro{\knowledge_makeidx_active_bool}, \csintro{\knowledge_makeidx_syntax_bool}
-%
-% First, one tests the package available.
-% \csintro{\package_if_loaded:nTF} tests if a package is loaded.
-% \csintro{\knowledge_option_aci_test_loaded:n} uses it for setting the default values of the booleans
-% \begin{compactitem}
-% \item \csintro{\knowledge_packagename_active_bool} that sets all the functionalities linked to the corresponding package to be active.
-% \item \csintro{\knowledge_packagename_syntax_bool} that states that the syntax is allowed.
-% \end{compactitem}
-% \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}
-%\begin{quote}\tt
-%\csintro{\knowledge_option_aci_define:n}\{package name\}
-%\end{quote}
-% defines the different possible ways to use the package.
-% \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{quote}\tt
-% \csintro{\knowledge_option_aci_autoload:nn}\{package name\}\{options for the package\}
-% \end{quote}
-% is called for each package after the options have been processed.
-% It loads the package if required, possibly with options.
-% \begin{macrocode}
-\cs_new:Nn\knowledge_option_aci_autoload:nnn{
- \bool_if:cTF{knowledge_#1_active_bool}
- {\package_if_loaded:nTF{#1}{}
- {\RequirePackage[#2]{#1}{#3}}}
- {}
-}
-\cs_new:Nn\knowledge_option_aci_autoload:nn
- {\knowledge_option_aci_autoload:nnn{#1}{#2}{}}
-% \end{macrocode}
-%
-% \paragraph{The real 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}
-%
-% \subsubsection{Executing the package options}
-%
-% \begin{macrocode}
-\ProcessKeysOptions{knowledge~package~options}
-% \end{macrocode}
-%
-% \subsubsection{Options post treatment for the "writing mode"}
-%
-% \begin{macrocode}
-
-\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
-% \end{macrocode}
-% Testing if the "writing mode" has been chosen by setting \cs{\knowledgepackagemode}.
-% \begin{macrocode}
-\tl_if_exist:NTF\knowledgepackagemode
- {}
- {\tl_new:N\knowledgepackagemode
- \tl_set:Nn\knowledgepackagemode{}}
-% \end{macrocode}
-% \begin{macrocode}
-\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
- }}
-% \end{macrocode}
-%
-%
-% \begin{macrocode}
-\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}
-%
-%
-% \subsubsection{Options post-treatment for the other packages}
-% \begin{macrocode}
-\knowledge_option_aci_autoload:nnn{ hyperref }{}{\hypersetup{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_const:Nn\scope_tl{SC at PE}
-\tl_const:Nn\scopept_tl{SC at PE2}
-% \end{macrocode}
-% \csintro{\scope_instances_stack_seq} contains the stack of instances of areas.
-% \csintro{\scope_top_instance_tl} contains always the topmost instance of the stack.
-% \csintro{\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[\csintro{nesting_int}] is an int counting the nesting level of the area at the current moment.
-% \item[\csintro{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[\csintro{name_tl}] is the text name of the \kl{area}.
-% \item[\csintro{pushcode_tl}] is code to be executed when an \kl{instance} of the \kl{area} is created.
-% \item[\csintro{popcode_tl}] is code to be executed just before an \kl{instance} of the \kl{area} is closed.
-% \item[\csintro{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[\csintro{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[\csintro{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[\csintro{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[\csintro{acceptsknowledge_bool}] is a boolean telling whether a knowledge can be associated to an instance of this area.
-% \item[\csintro{labelizable_bool}] tells whether a label can point to such an environment.
-% \item[\csintro{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[\csintro{mandatorybase_seq}] is a \texttt{seq} containing the list of categories that are allowed to
-% be the parent of this area. For instance, \cs{\item}
-% would have \texttt{itemize}, \texttt{compactdesc} and \texttt{enumerate}.
-% \end{compactdesc}
-%
-% \begin{macrocode}
-\tl_new:N\l_self_tl
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\scope_area_show:n{
- \group_begin:
- \scope_area_if_exist:nTF{#1}
- { \tl_set:Nx\l_self_tl{\scope_tl.area[#1]}
- \tl_show:x
- {Area~name:~\use:c{\l_self_tl.name_tl},~
- autoclose=\bool_if:cTF{\l_self_tl.autoclose_bool}TF,~
- recursive=\bool_if:cTF{\l_self_tl.recursive_bool}TF,~
- multiple=\bool_if:cTF{\l_self_tl.multiple_bool}TF,~
- scope=\bool_if:cTF{\l_self_tl.scope_bool}TF,~
- environment=\bool_if:cTF{\l_self_tl.environment_bool}TF,~
- forces={\use:c{\l_self_tl.forces_tl}},~
- accepts~knowledge=\bool_if:cTF{\l_self_tl.accepts_knowledge_bool}TF,~
- attracts~knowledge=\bool_if:cTF{\l_self_tl.attracts_knowledge_bool}TF,~
- accepts~labels=\bool_if:cTF{\l_self_tl.labelizable_bool}TF.
- }
- }
- {\knowledge_error:n{Unknown~area~`#1'~in~`\noexpand\scope_area_show:n'.}}
- \group_end:
-}
-% \end{macrocode}
-%
-%
-%
-% Areas are created empty by \cs{\scope_area_create:n}.
-% \begin{macrocode}
-\cs_new:Nn\scope_area_create:n
- {\group_begin:
- \tl_set:Nx\l_self_tl{\scope_tl.area[#1]}
- %
- \scope_category_add_area:nn{all}{#1}
- %
- \tl_new:c{\l_self_tl.name_tl}
- \tl_gset:cn{\l_self_tl.name_tl}{#1}
- \seq_new:c{\l_self_tl.category_seq}
- \seq_gpush:cn{\l_self_tl.category_seq}{all}
- \seq_gpush:cn{\l_self_tl.category_seq}{#1}
- \bool_new:c{\l_self_tl.autoclose_bool}
- \bool_gset_false:c{\l_self_tl.autoclose_bool}
- \bool_new:c{\l_self_tl.environment_bool}
- \bool_gset_true:c{\l_self_tl.environment_bool}
- \bool_new:c{\l_self_tl.multiple_bool}
- \bool_gset_true:c{\l_self_tl.multiple_bool}
- \bool_new:c{\l_self_tl.attractsknowledge_bool}
- \bool_gset_true:c{\l_self_tl.attractsknowledge_bool}
- \bool_new:c{\l_self_tl.labelizable_bool}
- \bool_gset_true:c{\l_self_tl.labelizable_bool}
- \bool_new:c{\l_self_tl.scope_bool}
- \bool_gset_false:c{\l_self_tl.scope_bool}
- \bool_new:c{\l_self_tl.acceptsknowledge_bool}
- \bool_gset_true:c{\l_self_tl.acceptsknowledge_bool}
- \bool_new:c{\l_self_tl.recursive_bool}
- \tl_gclear_new:c{\l_self_tl.pushcode_tl}
- \tl_gclear_new:c{\l_self_tl.popcode_tl}
- \tl_gclear_new:c{\l_self_tl.forces_tl}
- \seq_new:c{\l_self_tl.mandatorybase_seq}
- \int_new:c{\l_self_tl.count_int}
- \int_gset:cn{\l_self_tl.count_int}{0}
- \int_new:c{\l_self_tl.nesting_int}
- \int_gset:cn{\l_self_tl.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}
-%
-%
-% \cs{\scope_area_if_exist:nTF}, \cs{\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 \cs{\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 \csintro{\ScopeConfigure}\{area~list\}\{directives\}.
-% \begin{macrocode}
-\newrobustcmd\ScopeConfigure[2]
- {\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}}}
-% \end{macrocode}
-% \begin{macrocode}
-\tl_new:N\scope_area_tl
-\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\l_self_tl{\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{\l_self_tl.autoclose_bool}},
- autoclose / true .code:n =
- {\bool_gset_true:c{\l_self_tl.autoclose_bool}},
- parents .code:n =
- {\seq_gset_from_clist:cn{\l_self_tl.mandatorybase_seq}{#1}},
- push~code .code:n =
- {\tl_gput_right:cn{\l_self_tl.pushcode_tl}{#1}},
- pop~code .code:n =
- {\tl_gput_right:cn{\l_self_tl.popcode_tl}{#1}},
- occurrences .choice:,
- occurrences / once .code:n =
- {\bool_gset_false:c{\l_self_tl.multiple_bool}
- \bool_gset_false:c{\l_self_tl.recursive_bool}},
- occurrences / multiple .code:n = {
- \bool_gset_true:c{\l_self_tl.multiple_bool}
- \bool_gset_false:c{\l_self_tl.recursive_bool}},
- occurrences / recursive .code:n = {
- \bool_gset_true:c{\l_self_tl.multiple_bool}
- \bool_gset_true:c{\l_self_tl.recursive_bool}},
- scope .choice:,
- scope / true .code:n = {
- \bool_gset_true:c{\l_self_tl.scope_bool}},
- scope / false .code:n = {
- \bool_gset_false:c{\l_self_tl.scope_bool}},
- environment .choice:,
- environment / true .code:n = {
- \bool_gset_true:c{\l_self_tl.environment_bool}},
- environment / false .code:n = {
- \bool_gset_false:c{\l_self_tl.environment_bool}},
- environment .default:n = {true},
- label .choice:,
- label / none .code:n = {
- \bool_gset_false:c{\l_self_tl.labelizable_bool}},
- label / accepts .code:n = {
- \bool_gset_true:c{\l_self_tl.labelizable_bool}},
- knowledge .choice:,
- knowledge / none .code:n = {
- \bool_gset_false:c{\l_self_tl.acceptsknowledge_bool}
- \bool_gset_false:c{\l_self_tl.attractsknowledge_bool}},
- knowledge / accepts .code:n = {
- \bool_gset_true:c{\l_self_tl.acceptsknowledge_bool}
- \bool_gset_false:c{\l_self_tl.attractsknowledge_bool}},
- knowledge / attracts .code:n = {
- \bool_gset_true:c{\l_self_tl.acceptsknowledge_bool}
- \bool_gset_true:c{\l_self_tl.attractsknowledge_bool}},
- forces .code:n =
- {\tl_gset:cn{\l_self_tl.forces_tl}{#1}}
-}
-% \end{macrocode}
-%
-% \paragraph{Categories}
-%
-%\begin{compactdesc}
-% \item[\csintro{\scope_category_if_exist:nTF}] tests if a \kl{category} does exist.
-% \item[\csintro{\scope_category_ensure:n}] guarantees that a \kl{category} exists, possibly creating it if necessary.
-% \item[\csintro{\scope_category_create:n}] creates a \kl{category}.
-% \item[\csintro{\scope_category_add_area:nn}] adds an \kl{area} to a \kl{category}.
-% \item[\csintro{\scope_category_use:n}] displays the \kl{category} as a comma separated list of \kl{area} names (expandable).
-% \item[\csintro{\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_new:c{\scope_tl.category[#1].name_tl}
- \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[\csintro{\scope_instance_if_exist:nTF}]
-% \item[\csintro{\scopept_instance_if_exist:nTF}]
-% \item[\csintro{\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 \csintro{\scope_area_push:n} and \csintro{\scope_area_pop:n}.
-%
-% The token lists \csintro{\scope_popped_area_tl} and \csintro{\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_new:c
- {\scope_tl.instance[\scope_top_instance_tl].area_tl}
- \tl_gset:cx
- {\scope_tl.instance[\scope_top_instance_tl].area_tl}
- {\scope_top_area_tl}
- \tl_new:c
- {\scope_tl.instance[\scope_top_instance_tl].parent_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_new:c
- {\scopept_tl.instance[\scope_top_instance_tl].context_seq}
- \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}
-%
-% \csintro{\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 \cs{\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 \cs{\label} command is used.
-% This requires to overload it for it to write on the \kl{kaux file}.
-% Thus, the new \cs{\label} command executes the original code,
-% and furthermore writes in the \kl{kaux file} a \cs{\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_new: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
-\cs_new:Npn\knowledge_latex_label:n{
- \cs_if_exist:NTF\LaTeXlabel\LaTeXlabel\label
-}
-% \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_new:cn{\scopept_tl.instance[#2].area_tl}{#1}
- \tl_new: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_if_exist:cTF{\scopept_tl.label[#1].instance_tl}{}
- {\tl_new: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 \cs{\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{}
- { \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}
-
-\tl_new:N\knowledge_diagnose_lastline_tl
-\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}}}
-
-\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}{recap~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}{recap~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}{recap~autoref~not~introduced}
- }
- \int_compare:nNnT\kl_digest_autorefunused_int>0{
- \knowledge_diagnose:n{***********************************}
- \knowledge_diagnose:n{*~Autoref~introduced~but~not~used~*}
- \knowledge_diagnose:n{***********************************}
- \knowledge_diagnose:n{}
- %
- \knowledge_diagnose_reset_line:
- \KAuxProcess{autoref-introduced-not-used}
- %
- \knowledge_diagnose:n{}
- \knowledge_diagnose:n{}
- %
- }
- %
- \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 \cs{\knowledge_namespace_tl}
-% stores the current namespace, i.e. the ones that is used by default.
-% It is sometimes temporarily modified.
-% \begin{macrocode}
-\tl_new:Nn\knowledge_default_namespace_tl {default}
-% \end{macrocode}
-% The macro
-% \begin{code}
-% \csintro{\knowledge_id:nnn}\{namespace\}\{instance\}\{knowledge key\}
-% \end{code}
-% takes these three arguments in
-% this order (namespace/instance/scope) and produces a unique string that can be used to access
-% (using \cs{\csname}, or \texttt{:c} in LaTeX3) the tuple.
-% \begin{macrocode}
-\makeatother
-\cell_new_type:nnn{knowledge}{nnnn}{KL@#2@#3@\tl_to_str:n{#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
-% \begin{code}
-% \csintro{\knowledge_sets_to:nnn}\{namespace\}\{knowledge key\}\{scope\}
-% \end{code}
-% which is followed by the same three arguments.
-% It defines
-% \begin{code}
-% \csintro{\knowledge_at:N}\cs{\token}
-% \end{code} that executes \cs{\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 \cs{ktuples}
-% for storing the \kl{knowledges}.
-% \begin{macrocode}
-\tuple_new:n{ktuple}
-% \end{macrocode}
-% Some more code for testing if a "knowledge" is defined:
-% \begin{code}
-% \csintro{\knowledge_knowledge_if_exist:nnnTF}\{namespace\}\{instance\}\{key\}\par
-% ~~~~~~~\{true code\}\{false code\}
-% \end{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{Generalities}
-%
-% The \cs{\knowledge} command is dealt in several steps.
-% \begin{asparaitem}
-% \item In a first phase, the "directives" are parsed using the keys \csintro{knowledge~directives}.
-% During this phase, all the information concerning the target is fixed, as well as other pieces of informations
-% such as the real reference of the "autoref" directive. The result is gathered in a second comma separated
-% list of directives
-% \item Then, depdnging on the targetting information, the
-% \end{asparaitem}
-% Essentially, the \cs{\keys_define:nn}\verb|{ knowledgenow~directives }|(...)
-% commands used throughout the code are here to add new functionalities to it.
-%
-%
-% \subsubsection{Defining directives}
-%
-%
-% The commands used for introducing new directives.
-% The command
-% \begin{code}
-% \csintro{\NewKnowledgeParamBool}[*]\{name\}\cs{\token}
-% \end{code}
-% creates a new boolean directive of name `name'.
-% When the knowledge is executed, the value will be stored in the \cs{\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 \cs{\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}
- \bool_new:N#3
- \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
-% \AP The command \cs{\NewKnowledgeParamTl} is similar to \cs{\NewKnowledgeParamBool},
-% but creates a directive that stores text.
-% \begin{code}
-% \csintro\NewKnowledgeParamTl*[\cs\token]\{name\}
-% \end{code}\noindent
-% \iffalse
-% \begin{macrocode}
-\NewDocumentCommand\NewKnowledgeParamTl{som}{
- %\tl_show:n{#2}
- \IfNoValueTF{#2}
- { \tl_set:Nn\l_tmpa_tl{#3}
- \tl_remove_all:Nn\l_tmpa_tl{~}
- \use:x{
- \exp_not:N\NewKnowledgeParamTl
- \IfBooleanT{#1}{*}
- [\exp_not:c{knowledge_kl_\l_tmpa_tl _tl}]
- {#3}
- }}
- {\cs_if_exist:cTF{ktuple_#3_expands_to:n}
- {}
- {\ktuple_new_tl_index:n{#3}}
- \tl_if_exist:NTF#2{}
- {\tl_new:N#2}
- \use:c{ktuple_#3_expands_to:n}
- {\tl_set:Nn#2{##1}}
- %
- \keys_define:nn { knowledgenow~directives }{
- #3 .code:n =
- { \knowledge_at:c{ktuple_#3_gset:Nn}{##1} },
- #3~X .code:n =
- { \knowledge_at:c{ktuple_#3_gset:Nx}{##1} },
- no~#3 .code:n =
- { \knowledge_at:c{ktuple_#3_gdel:N} }}
- \IfBooleanTF{#1}{\KnowledgeTransferTl{#3}}{}
-}}
-% \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 \cs{\NewKnowledgeParamCode} is similar to \cs{\NewKnowledgeParamBool},
-% but creates a directive that stores code. There is no optional star for code (never directly accessible to the user).
-% \begin{code}\AP
-% \csintro\NewKnowledgeParamCode\{name\}\cs{\token}
-% \end{code}\noindent
-% \begin{macrocode}
-\NewDocumentCommand\NewKnowledgeParamCode{mm}{
- \ktuple_new_tl_index:n{#1}
- \tl_new:N#2
- \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 \cs{\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}
-% \csintro\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{Scope basics}
-%
-%
-% \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.
-%
-% In this part of the code, we provide a small number of commands for dealing with instances.
-% The real code that computes the current context of scope if later.
-%
-%
-% \begin{compactdesc}
-% \item[\csintro{\knowledge_current_instance_tl}] contains the current
-% instance to be used.
-% \item[\cs{\knowledge_visible_instances_seq}] contains the sequence
-% of instances that are visible right now.
-% \item[\csintro{\knowledge_scope_track_instance:Nn}\cs\tokenlist\{scope name\}]
-% sets \cs{\tokenlist} to the outermost instance of the scope name.
-% Typically, if the request is `\texttt{subsection}', the answer will be `\texttt{subsection-3.1}',
-% identifying the subsection currently in scope.
-% \end{compactdesc}
-% \begin{macrocode}
-\tl_new:N\knowledge_current_instance_tl
-\tl_gset:Nn\knowledge_current_instance_tl{base}
-% \end{macrocode}
-%
-% \AP The sequence \csintro{\knowledge_visible_instances_seq} contains the
-% "instances" that are visible right now. This are searched through when
-% a knowledge is used. The leftmost instance is the most important one (innermost scope).
-% Note that \cs{\knowledge_visible_instances_seq} may only be correct after one compilation.
-% \begin{compactdesc}
-% \item[\csintro{\knowledge_push_visible_instance:n}]
-% \item[\csintro{\knowledge_pop_visible_instance:}]
-% \item[\csintro{\knowledge_pop_visible_instances_to:n}]
-% \item[\csintro{\knowledge_show_visible_instances:}]
-% \end{compactdesc}
-%
-% \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: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{,}>}}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\knowledge_import_instance:n
- {\seq_if_in:NnTF\knowledge_visible_instances_seq{#1}
- {}{\knowledge_push_visible_instance:n{#1}}}
-% \end{macrocode}
-% \begin{macrocode}
-\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}
-%%
-% \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 \csintro{\KAuxKnowledge} command is added to the \kl{kaux file} when
-% \cs{\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}
-\newrobustcmd\KAuxExport[4]
- {Package~knowledge:~undefined~so~far.}
-% \end{macrocode}
-%
-%\AP \csintro{\knowledge_set_now:nnnn}\cs{{}} takes the three parameters defining a knowledge and a list of \kl{knowledgenow directives}, checks that it was not existing before, and
-% then calls the \cs{\keys_set:nn}\{knowledgenow directives\} for defining it.
-% \begin{macrocode}
-\cs_new:Nn\knowledge_new_now:nnnn
- {\knowledge_sets_to:nnn{#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_new:Nn\knowledge_set_now:nnnn
- {\knowledge_sets_to:nnn{#1}{#2}{#3}
- \knowledge_at:N\ktuple_if_exist:NTF
- {\bool_if:NTF\knowledge_knowledgestyle_bool
- {\knowledge_at:N\ktuple_gclear:N}
- {}}
- {\knowledge_at:N\ktuple_new:N}
- \keys_set:nn { knowledgenow~directives } { #4 }
-}
-\cs_generate_variant:Nn\knowledge_new_now:nnnn{nnVn}
-\cs_generate_variant:Nn\knowledge_set_now:nnnn{nnVn}
-% \end{macrocode}
-%
-%
-%\AP We can now define the \cs{\knowledge} command itself.
-% It starts by writing the line number in the \kl{kaux file}
-% using \cs{\KAuxWriteLocation}, and then proceeds with \cs{\__knowledge_knowledge}.
-% \begin{macrocode}
-\NewDocumentCommand\knowledge{}
- {\KAuxWriteLocation\__knowledge_knowledge}
-% \end{macrocode}
-% The command \csintro{\__knowledge_knowledge} is the center of the \cs{\knowledge}
-% command. It parses its arguments (in particular separating the synonyms using the "xparse@@package"), and executes \cs{\knowledge_knowledge_process:nn}
-% \begin{macrocode}
-\NewDocumentCommand\__knowledge_knowledge{m >{\SplitList{|}}o m }
-{ \kl_hide_begin:
- \group_begin:
- \tl_set_eq:NN\knowledge_namespace_tl
- \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\knowledge_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:
-}
-% \end{macrocode}
-%
-%\AP The boolean \cs{\knowledge_knowledgestyle_bool}
-% is set to true in order \cs{\knowledge_knowledge_process:nn}
-% to know if it has been triggered by \cs{\knowledge}
-% or \cs{\knowledgestyle}.
-% \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}
-%
-%
-%
-%
-%
-%\AP The \cs{\knowledge_knowledge_process:nn} command is the internal
-% version of \cs{\knowledge}. It takes two parameters:
-% the key, and the comma separated list of directives.
-% \begin{macrocode}
-\bool_new:N\knowledge_knowledgestyle_bool
-\bool_new:N\knowledge_knowledgestyle_override_bool
-\bool_new:N\knowledge_knowledge_now_bool
-\bool_new:N\knowledge_knowledge_alsonow_bool
-\bool_new:N\knowledge_knowledge_is_synonym_bool
-\bool_new:N\knowledge_knowledge_autoref_bool
-\tl_clear_new:N\knowledge_knowledge_synonym_tl
-\tl_clear_new:N\knowledge_knowledge_synonyminstance_tl
-\tl_clear_new:N\knowledge_knowledge_clear_bool
-\tl_clear_new:N\knowledge_knowledge_force_bool
-\tl_clear_new:N\knowledge_knowledge_export_bool
-\tl_clear_new:N\knowledge_knowledge_key_tl
-\tl_clear_new:N\knowledge_knowledge_namespace_tl
-\tl_clear_new:N\knowledge_knowledge_instance_tl
-\tl_clear_new:N\knowledge_knowledge_directives_tl
-% \end{macrocode}
-% The macro \csintro{\knowledge_knowledge_process:nn}
-% is the heart of \cs{\knowledge} command.
-% \begin{macrocode}
-\cs_new:Nn\knowledge_knowledge_process:nn
-{ \bool_set_false:N\knowledge_knowledge_clear_bool
- \bool_set_false:N\knowledge_knowledge_force_bool
- \bool_set_false:N\knowledge_knowledge_export_bool
- \bool_set_false:N\knowledge_knowledge_autoref_bool
- \bool_set_false:N\knowledge_knowledge_now_bool
- \bool_set_false:N\knowledge_knowledge_alsonow_bool
- %
- \tl_set:Nn\knowledge_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_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_new_now:nnnn
- {\knowledge_knowledge_namespace_tl}
- {\knowledge_knowledge_instance_tl}
- {\exp_not:V\knowledge_knowledge_key_tl}
- {\exp_not:V\knowledge_knowledge_directives_tl}}
- }{}
- \bool_if:nTF{\knowledge_knowledge_alsonow_bool}
- {\use:x{
- \exp_not:N\knowledge_set_now:nnnn
- {\knowledge_knowledge_namespace_tl}
- {\knowledge_knowledge_instance_tl}
- {\exp_not:V\knowledge_knowledge_key_tl}
- {\exp_not:V\knowledge_knowledge_directives_tl}}
- }{}
- \bool_if:NTF\knowledge_knowledge_now_bool
- {}
- { \KAuxWriteX*{
- \exp_not:N\KAuxKnowledge
- {\knowledge_knowledge_namespace_tl}
- {\knowledge_knowledge_instance_tl}
- {\exp_not:V\knowledge_knowledge_key_tl}
- {\exp_not:V\knowledge_knowledge_directives_tl}}
- }
- \bool_if:NT\knowledge_knowledge_autoref_bool
- {\KAuxWriteX*
- {\exp_not:N\KAuxAutoref
- {\knowledge_knowledge_namespace_tl}
- {\knowledge_knowledge_instance_tl}
- {\exp_not:V\knowledge_knowledge_key_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_knowledge_key_tl}
- {\exp_not:V\knowledge_knowledge_directives_tl}}
- }
-}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\knowledge_delay_directive:n
- {\tl_if_empty:NTF\knowledge_knowledge_directives_tl
- {\tl_set:Nn\knowledge_knowledge_directives_tl{#1}}
- {\tl_put_right:Nn\knowledge_knowledge_directives_tl{,#1}}}
-\cs_generate_variant:Nn\knowledge_delay_directive:n{x}
-% \end{macrocode}
-%
-%
-%
-% \subsubsection{The \cs{\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 \cs{\knowledgedefault} command}
-%
-% It uses internally the variable \csintro{\knowledge_knowledgedefault_tl}.
-% \begin{macrocode}
-\tl_new:N\knowledge_knowledgedefault_tl
-\NewDocumentCommand\knowledgedefault{sm}{
- \kl_hide_begin:
- \IfBooleanTF{#1}
- {\tl_put_right:Nn\knowledge_knowledgedefault_tl{,#2}}
- {\tl_set:Nn\knowledge_knowledgedefault_tl{#2}}
- \kl_hide_end:
-}
-% \end{macrocode}
-%
-%
-% \subsubsection{Main \cs{\kl} code}
-%
-%
-% The \cs{\kl}, and its internal version \cs{\klTKS} are the central ones in the package. Indeed, all commands such as \cs{\intro}, \cs{\phantomintro}, \cs{\reintro} or the \kl{"... at ...@..."} notation eventually end to a call to these functions.
-%
-% Essentially, \cs{\kl} parses its parameters, and then call its internal version \cs{\knowledge_klTKS:nnn}
-% with proper parameters: Text, Knowledge, Scope (the scope can be empty):
-% \begin{macrocode}
-\NewDocumentCommand\__kl:w{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, \cs{\knowledge_klTKS:nnn} is the internal version of \cs{\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 \cs{\klTKS} which can be used, and does not require the \kl(package){expl3} syntax.
-% \begin{macrocode}
-\tl_clear_new:N\knowledge_kl_text_tl
-\tl_clear_new:N\knowledge_kl_base_key_tl
-\tl_clear_new:N\knowledge_kl_key_tl
-\tl_clear_new:N\knowledge_kl_autoref_tl
-\tl_clear_new:N\knowledge_kl_resourcetoken_tl
-\tl_clear_new:N\knowledge_kl_resourcearguments_tl
-\tl_clear_new:N\knowledge_kl_display_process_tl
-\tl_clear_new:N\knowledge_kl_display_sequence_tl
-\tl_new:N\knowledge_namespace_tl
-\tl_new:Nn\knowledge_display_code_tl{INTERNAL~ERROR~DISPLAY~CODE}
-% \end{macrocode}
-% \begin{macrocode}
-\NewDocumentCommand\klTKS{}{\knowledge_klTKS:nnn}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\knowledge_klTKS:nnn{
- \group_begin:
- %
- \tl_set:Nn\knowledge_kl_linkscope_tl{#3}
- \tl_set:Nn\knowledge_kl_instance_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
- %
- \tl_if_exist:cTF
- {knowledge_kl_\tl_to_str:V\knowledge_kl_modifiers_tl _init_tl}
- {\use:c{knowledge_kl_\tl_to_str:V\knowledge_kl_modifiers_tl _init_tl}}
- {\knowledge_error:x
- {Unknown~variant~modifier~sequence~`\exp_not:V\knowledge_kl_modifiers_tl'.}}
- %
- \knowledge_kl_modifiers_reset:
- %
- \knowledge_kl_use_styles:x{\knowledge_kl_default_style_tl}
- %
- \knowledge_kl_find:
- \group_end:
- \knowledge_display_code_tl
-}
-% \end{macrocode}
-%
-% At this step, the code has launched \cs{\knowledge_kl_find:}
-% Internally, it counts using \cs{\knowledge_kl_recursion_int}
-% the number of indirections, and bounds
-% starting from the integer \cs{\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 \cs{\kl} command is \csintro{\knowledge_kl_find:}.
-% It uses the variables \cs{\knowledge_kl_recursion_int} for checking non-recursion.
-% It searches for the entry \cs{\knowledge_kl_key_tl}, either in searching in the \kl{stack of visible scope instances},
-% or following \cs{\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:{
- \knowledge_kl_find_recursion_exceeded:TF
- {\knowledge_kl_error_recursion:}
- {\tl_if_empty:NTF\knowledge_kl_instance_tl
- {\tl_if_empty:NTF\knowledge_kl_linkscope_tl
- \knowledge_kl_find_withoutscope:
- \knowledge_kl_find_withscope:}
- \knowledge_kl_find_withinstance:}
-}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_set:Npn\knowledge_kl_find_recursion_exceeded:TF{
- \int_decr:N\knowledge_kl_recursion_int
- \int_compare:nNnTF\knowledge_kl_recursion_int=0
-}
-% \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_instance_tl
- \knowledge_kl_key_tl
- {\knowledge_kl_exec:nnV
- \knowledge_kl_namespace_tl
- \knowledge_kl_instance_tl
- \knowledge_kl_key_tl}
- { \knowledge_kl_error_unknown_in_scope_firsttime: }
-}
-\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_instance_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:{
- \knowledge_kl_find_in_scope:VNTF
- \knowledge_kl_key_tl
- \knowledge_kl_instance_tl
- {\knowledge_kl_exec:nnV
- \knowledge_kl_namespace_tl
- \knowledge_kl_instance_tl
- \knowledge_kl_key_tl}
- {\knowledge_kl_error_unknown_firsttime:}
-}
-% \end{macrocode}
-% We now code the macro \cs{\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}
-% \AP
-% When the \kl{knowledge} is found, it is eventually executed using
-% \begin{code}
-% \csintro{\knowledge_kl_exec:nnn}\{namespace\}\{instance\}\{key\}
-% \end{code} 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 \cs{\knowledge_kl_resourcetoken_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{
- \tl_set:Nx\knowledge_kl_resourcearguments_tl
- {{#1}{#2}{\exp_not:n{#3}}}
- \exp_args:NNc\tl_set:Nn\knowledge_kl_resourcetoken_tl
- {\knowledge_id:nnn{#1}{#2}{#3}}
- \expandafter\ktuple_countuse_gincr:N\knowledge_kl_resourcetoken_tl
- %
- \tl_clear:N\knowledge_kl_link_tl
- \tl_clear:N\knowledge_kl_linkscope_tl
- \tl_clear:N\knowledge_kl_instance_tl
- \tl_map_function:NN
- \knowledge_kl_styledirectives_tl
- \tl_clear:N
- %
- \knowledge_kl_resourcetoken_tl
- %
- \bool_if:NTF\kl_unknown_knowledge_bool
- {\knowledge_kl_error_unknown:}
- {\tl_map_function:NN
- \knowledge_kl_styledirectives_tl
- \knowledge_kl_use_styles:x
- %
- \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_compute_code:
- }
-}
-\cs_generate_variant:Nn\knowledge_kl_exec:nnn{nnV}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\knowledge_kl_use_styles:n
- {\clist_map_function:nN{#1}\knowledge_kl_use_style:n}
-\cs_generate_variant:Nn\knowledge_kl_use_styles:n {x}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\knowledge_kl_use_style:n{
- \tl_if_empty:nTF{#1}{}
- {\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'}}}
-}
-% \end{macrocode}
-%
-% \begin{macrocode}
-\cs_new:Nn\knowledge_usestyle:nn{
- \group_begin:
- \tl_set:Nn\knowledge_kl_forcedtext_tl{#2}
- \knowledge_kl_use_styles:x{#1}
- \knowledge_kl_compute_code:
- \group_end:
- \knowledge_display_code_tl
-}
-\NewDocumentCommand\knowledgeusestyle{mm}{\knowledge_usestyle:nn{#1}{#2}}
-% \end{macrocode}
-%
-%
-%
-%
-%
-%
-% \subsubsection{Error handling}
-%
-%
-%
-% \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}
-% \begin{macrocode}
-\NewKAuxCommand\KAuxErrorKnowledgeUnknown{mmmmm}
- {Package~'knowledge:~A~knowledge~is~not~defined.~
- {namespace}{scope/empty}{undefined~knowledge}{base~knowledge}{command}}
- {}
-\NewKAuxCommand\KAuxErrorLabelUnknown{m}
- {Package~'knowledge:~A~label~is~not~defined.~
- {label}}
- {}
-% \end{macrocode}
-% \begin{macrocode}
-\DeclareKAuxPhaseCommand\KAuxErrorKnowledgeUnknown{diagnose-unknown-suggest}
-{ \knowledge_diagnose_line:
- \tl_set_eq:Nc\l_tmpa_tl{knowledge_kl_\cs_to_str:N#5_suggestion_tl}
- \tl_if_empty:nTF{#2}{}
- {\tl_if_empty:NTF\l_tmpa_tl{}
- {\tl_put_right:Nn\l_tmpa_tl{,}}
- \tl_put_right:Nn\l_tmpa_tl{scope={#2}}}
- \knowledge_diagnose:x
- {\exp_not:n{\knowledge{#3}}{\exp_not:V\l_tmpa_tl}}
-}
-% \end{macrocode}
-% The code executed when an undefined knowledge is met. It
-% \begin{macrocode}
-\cs_new:Nn\knowledge_kl_error_unknown_firsttime:
- {\bool_if:cTF{\knowledge_variant_var:n{unknownwarning_bool}}
- {\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{~|~}}}
- }{}
- \bool_if:cTF{\knowledge_variant_var:n{unknowndiagnose_bool}}
- {\KAuxWriteX{
- \KAuxErrorKnowledgeUnknown
- {\knowledge_kl_namespace_tl}
- {}
- {\tl_to_str:V\knowledge_kl_key_tl}
- {\tl_to_str:V\knowledge_kl_base_key_tl}
- {\exp_not:V\knowledge_kl_command_tl}
- }}{}
- \use:x{\exp_not:N\knowledge_set_now:nnnn
- {\knowledge_kl_namespace_tl}{base}
- {\exp_not:V\knowledge_kl_key_tl}
- {UnKnoWn~KNowLedGE}}
- \tl_gset:Nx\knowledge_display_code_tl
- {\exp_not:N\knowledge_usestyle:nn
- {\use:c{\knowledge_variant_var:n{unknown_style_tl}}}
- {\exp_not:V\knowledge_kl_text_tl}}
-}
-\cs_new:Nn\knowledge_kl_error_unknown:{
- \tl_gset:Nx\knowledge_display_code_tl
- {\exp_not:N\knowledge_usestyle:nn
- {\use:c{\knowledge_variant_var:n{unknown_style_cont_tl}}}
- {\exp_not:V\knowledge_kl_text_tl}}
-}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\knowledge_kl_error_unknown_in_scope_firsttime:
- {\bool_if:cTF{\knowledge_variant_var:n{unknownwarning_bool}}
- {\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}}}{}
- \bool_if:cTF{\knowledge_variant_var:n{unknowndiagnose_bool}}
- {\KAuxWriteX{
- \KAuxErrorKnowledgeUnknown
- {\knowledge_kl_namespace_tl}
- {\knowledge_kl_linkscope_tl}
- {\tl_to_str:V\knowledge_kl_key_tl}
- {\tl_to_str:V\knowledge_kl_base_key_tl}
- {\exp_not:V\knowledge_kl_command_tl}
- }}{}
- \use:x{\exp_not:N\knowledge_set_now:nnnn
- {\knowledge_kl_namespace_tl}
- {\knowledge_kl_linkscope_tl}
- {\exp_not:V\knowledge_kl_key_tl}
- {UnKnoWn~KNowLedGE}}
- \tl_gset:Nx\knowledge_display_code_tl
- {\exp_not:N\knowledge_usestyle:nn
- {\use:c{\knowledge_variant_var:n{unknown_style_tl}}}
- {\exp_not:V\knowledge_kl_text_tl}}
-}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\knowledge_kl_error_label_unknown:{
- \KAuxWriteX{
- \KAuxErrorKnowledgeUnknown
- {\knowledge_kl_namespace_tl}
- {\knowledge_kl_linkscope_tl}
- {\tl_to_str:V\knowledge_kl_key_tl}
- {\tl_to_str:V\knowledge_kl_base_key_tl}
- {\exp_not:V\knowledge_kl_command_tl}
- }
- %
- \IfKnowledgePaperModeF{
- \msg_warning:nnxx{ knowledge }{ knowledge~unknown~label }
- {\exp_not:V\knowledge_kl_key_tl}
- {\knowledge_kl_linkscope_tl}}
- %
- \tl_gset:Nx\knowledge_display_code_tl
- {\exp_not:N\knowledge_usestyle:nn
- {\use:c{\knowledge_variant_var:n{unknown_style_tl}}}
- {\exp_not:V\knowledge_kl_text_tl}}
-}
-% \end{macrocode}
-% This is the code use by default when an error is met and the result has nevertheless to be displayed.
-% \ToImprove{this code is dependent on xcolor and shouldn't.}
-% \begin{macrocode}
-\cs_new:Nn\knowledge_kl_error_display:n
- {\textcolor{orange}{\tl_to_str:V\knowledge_kl_text_tl}}
-% \end{macrocode}
-%
-% \subsubsection{Variant modifiers and \cs{\knowledgevariantmodifier}}
-%
-% When a \cs\kl-like command is met, its name is added to
-% \csintro{\knowledge_kl_modifiers_tl}.
-% Each time a new command is added using \csintro{\knowledge_kl_modifiers_add:N},
-% it is appended to \cs{\knowledge_kl_modifiers_tl}, and a reduction is applied
-% using \cs{\knowledge_kl_modifiers_reduce:}:
-% \begin{macrocode}
-\tl_clear_new:N\knowledge_kl_modifiers_tl
-\cs_new:Nn\knowledge_kl_modifiers_reset:
- {\tl_gclear:N\knowledge_kl_modifiers_tl}
-\cs_new:Nn\knowledge_kl_modifiers_add:N
- {\tl_gput_right:Nn\knowledge_kl_modifiers_tl{#1*}
- \knowledge_kl_modifiers_reduce:}
-% \end{macrocode}
-%\AP This reduction is performed by \csintro{\knowledge_kl_modifiers_reduce:},
-% and configured using \cs{\knowledgevariantmodifier}.
-% \begin{macrocode}
-\NewDocumentCommand\knowledgevariantmodifier{mm}
- {\tl_new:cn
- {KLSV_\tl_to_str:n{#1*} _tl}
- {#2*}}
-\cs_new:Nn\knowledge_kl_modifiers_reduce:
- {\tl_if_exist:cTF
- {KLSV_\tl_to_str:V\knowledge_kl_modifiers_tl _tl}
- {\tl_gset_eq:Nc\knowledge_kl_modifiers_tl
- {KLSV_\tl_to_str:V\knowledge_kl_modifiers_tl _tl}}
- {}}
-% \end{macrocode}
-%
-% \begin{macrocode}
-% \end{macrocode}
-%
-% \begin{macrocode}
-% \end{macrocode}
-%
-% \subsubsection{Implementation of \cs{\knowledgenewvariant}}
-%
-% \begin{macrocode}
-\cs_new:Nn\knowledge_variant_var:n
- {knowledge_kl_\expandafter\cs_to_str:N\knowledge_kl_command_tl _#1}
-% \end{macrocode}
-% \begin{macrocode}
-\NewDocumentCommand\knowledgenewvariant{mm}{
- \exp_args:Nc\tl_new:Nn
- {knowledge_kl_\cs_to_str:N#1_command_tl}
- {#1}
- %
- %
- \NewDocumentCommand#1{s}
- {\knowledge_kl_modifiers_add:N#1
- \IfBooleanF{##1}{\__kl:w}}
- %
- \tl_new_eq:cN
- {knowledge_kl_\cs_to_str:N#1_namespace_tl}
- \knowledge_default_namespace_tl
- \tl_new:cx{knowledge_kl_\cs_to_str:N#1_suggestion_tl}{}
- \bool_new_true:c{knowledge_kl_\cs_to_str:N#1_unknownwarning_bool}
- \bool_new_true:c{knowledge_kl_\cs_to_str:N#1_unknowndiagnose_bool}
- \tl_new:cn{knowledge_kl_\cs_to_str:N#1_default_style_tl}{}
- \tl_new:cn{knowledge_kl_\cs_to_str:N#1_unknown_style_tl}{}
- \tl_new:cn{knowledge_kl_\cs_to_str:N#1_unknown_style_cont_tl}{}
- \tl_new:cx{knowledge_kl_\cs_to_str:N#1_autoknowledge_tl}{}
- \tl_new:cx{knowledge_kl_\cs_to_str:N#1_styledirectives_tl}{}
- %
- \bool_if:NT\knowledge_hyperref_active_bool
- {\exp_args:Nx\pdfstringdefDisableCommands
- {\exp_not:N\def\exp_not:N#1
- {\exp_not:N\knowledge_variant_arg_absorber:Nw
- \exp_not:c{\cs_to_str:N#1_PDFstring}}}}
- \exp_args:Nc\newcommand{\cs_to_str:N#1_PDFstring}[3]{##1}
- %
- \tl_new:cx{knowledge_kl_\tl_to_str:n{#1*} _init_tl}
- {
- \exp_not:n{\tl_set_eq:NN\knowledge_kl_command_tl}
- \exp_not:c{knowledge_kl_\cs_to_str:N#1_command_tl}
- \exp_not:n{\tl_set_eq:NN\knowledge_kl_namespace_tl}
- \exp_not:c{knowledge_kl_\cs_to_str:N#1_namespace_tl}
- \exp_not:n{\tl_set_eq:NN\knowledge_kl_default_style_tl}
- \exp_not:c{knowledge_kl_\cs_to_str:N#1_default_style_tl}
- \exp_not:n{\tl_set_eq:NN\knowledge_kl_unknown_style_tl}
- \exp_not:c{knowledge_kl_\cs_to_str:N#1_unknown_style_tl}
- \exp_not:n{\tl_set_eq:NN\knowledge_kl_unknown_style_cont_tl}
- \exp_not:c{knowledge_kl_\cs_to_str:N#1_unknown_style_cont_tl}
- \exp_not:n{\tl_set_eq:NN\knowledge_kl_styledirectives_tl}
- \exp_not:c{knowledge_kl_\cs_to_str:N#1 _styledirectives_tl}
- \exp_not:c{knowledge_kl_\cs_to_str:N#1 _autoknowledge_tl}
- }
- %
- %\bool_if:NT\knowledge_hyperref_active_bool
- % {\pdfstringdefDisableCommands{\let#1\knowledge_fake_kl:n}}
- %
- \knowledgesetvariant#1{#2}
-}
-\DeclareExpandableDocumentCommand\knowledge_variant_arg_absorber:Nw
- {m d() o d() m}
- {\IfNoValueTF{#2}
- {#1{#5}{#2}{#3}}
- {#1{#5}{#2}{#1}}}
-
-\tl_new:N\knowledge_variant_command_tl
-\tl_new:N\knowledge_variant_key_tl
-\NewDocumentCommand\knowledgesetvariant{mm}{
- \tl_set:Nn\knowledge_variant_command_tl{#1}
- \tl_set:Nx\knowledge_variant_key_tl{\cs_to_str:N#1}
- %
- \keys_set:nn{ knowledge~configure~variant }{#2}
-}
-% \end{macrocode}
-% \begin{macrocode}
-\keys_define:nn{ knowledge~configure~variant }{
- namespace .code:n =
- {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _namespace_tl}{#1}},
- %
- unknown~warning .choices:nn = {true,false}
- {\bool_set_text:cn{knowledge_kl_\knowledge_variant_key_tl _unknownwarning_bool}{#1}},
- %
- unknown~diagnose .choices:nn = {true,false}
- {\bool_set_text:cn{knowledge_kl_\knowledge_variant_key_tl _unknowndiagnose_bool}{#1}},
- %
- default~style .code:n =
- {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _default_style_tl}{#1}},
- unknown~style .code:n =
- {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _unknown_style_tl}{#1}},
- unknown~style~cont .code:n =
- {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _unknown_style_cont_tl}{#1}},
- %
- auto~knowledge .code:n =
- { \tl_set:cx{knowledge_kl_\knowledge_variant_key_tl _autoknowledge_tl}
- {\exp_not:N\exp_args:NV
- \exp_not:N\knowledge
- {\exp_not:N\knowledge_kl_key_tl}
- {namespace=\exp_not:N\knowledge_kl_namespace_tl,\exp_not:n{#1}}}},
- %
- style~directive .code:n = {
- \tl_clear:c{knowledge_kl_\knowledge_variant_key_tl _styledirectives_tl}
- \clist_map_inline:nn{#1}
- {\use:x{\NewKnowledgeParamTl*
- [\exp_not:c{knowledge_kl_##1_tl}]}
- {##1}
- \tl_put_right:cx{knowledge_kl_\knowledge_variant_key_tl _styledirectives_tl}
- {\exp_not:c{knowledge_kl_##1_tl}}}
- },
- %
- suggestion .code:n =
- {\tl_set:cn{knowledge_kl_\knowledge_variant_key_tl _suggestion_tl}{#1}},
- %
- PDF~string .code:n =
- {\exp_args:Nc\renewcommand{\knowledge_variant_key_tl _PDFstring}[3]{#1}}
-}
-% \end{macrocode}
-%
-%
-% \subsubsection{Variants of the \cs{\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 \csintro{\knowledge_kl_display_preprocess_tl} is the code to be used first before displaying. It does nothing for \cs{\kl}, but is set to \cs{\knowledge_kl_target_preprocess_tl} for \cs{\intro}, which performs the \cs{\label} command fir the introduction.
-% \item \csintro{\knowledge_kl_display_process_tl} is the code to be executed for displaying the \kl{knowledge}. This is not defined by default.
-% \item \csintro{\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 \csintro{\knowledge_kl_update:N} is a code to be executed to update the knowledge. By default, it increments the ktuple counter `\cs{countuse_int}'.
-% \item \csintro{\knowledge_kl_namespace_tl} is the \kl{namespace} in which the \kl{knowledge} is to be searched. Not defined by default.
-% \item \csintro{\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 \csintro{\knowledge_kl_max_recursion_int} is the maximum number of recursion allowed when searching for a \kl{knowledge}. It is by default 40.
-% \end{asparaitem}
-%
-% The codes can uses internally the following variables, that are accessible for the user when defining new \cs\kl-like commands:
-% \begin{asparaitem}
-% \item \csintro{\knowledge_kl_command_tl} the command that has triggered the search
-% \item \csintro{\knowledge_kl_base_key_tl} contains the name of the knowledge for which the search has started,
-% \item \csintro{\knowledge_kl_text_tl} contains the text to be displayed,
-% \item \csintro{\knowledge_kl_key_tl} contains the name of the knowledge searched at a particular moment,
-% \item \csintro{\knowledge_kl_recursion_int} counts the number of indirection in the current, starting from \cs{\knowledge_kl_max_recursion_int}, and going down,
-% \item \csintro{\knowledge_kl_link_tl} contains the link to be followed.
-% \item \cs{\knowledge_kl_resourcetoken_tl} contains a single token, which is the location of the knowledge.
-% \end{asparaitem}
-%
-% \begin{macrocode}
-\let\nointro\phantomintro
-% \end{macrocode}
-%
-% When the \cs{\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}
-\tl_new:Nn\knowledge_kl_target_preprocess_tl
- {\tl_if_exist_ne:NTF\knowledge_kl_resourcetoken_tl
- {\expandafter\ktuple_countintro_get_int:NN
- \knowledge_kl_resourcetoken_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\knowledge_kl_autoref_tl
- {\exp_args:Nx\knowledge_latex_label:n
- {\expandafter\noexpand\knowledge_kl_autoref_tl\l_tmpa_tl}}
- {}}
-% \end{macrocode}
-% \begin{macrocode}
-\tl_new:N\knowledge_kl_style_tl
-\tl_new:N\knowledge_kl_namespace_tl
-\tl_new:N\knowledge_kl_command_tl
-
-\cs_new:Nn\knowledge_kl_target_update:N
- {\ktuple_countintro_gincr:N#1}
-\cs_gset:Nn\knowledge_kl_default_update:N
- {\ktuple_countuse_gincr:N#1}
-% \end{macrocode}
-%
-%
-% \subsubsection{Code for mathematical variables (unstable)}
-%
-%
-%
-% \subsubsection{Display parameters}
-%
-%
-%\begin{compactdesc}
-%\item[\csintro{\kl_emphasize_bool}]
-%\item[\csintro{\kl_boldface_bool}]
-%\item[\csintro{\kl_underline_bool}]
-%\item[\csintro{\kl_typewriter_bool}]
-%\item[\csintro{\kl_fbox_bool}]
-%\item[\csintro{\kl_ensuremath_bool}]
-%\item[\csintro{\kl_ensuretext_bool}]
-%\item[\csintro{\kl_italic_bool}]
-%\item[\csintro{\kl_lowercase_bool}]
-%\item[\csintro{\kl_uppercase_bool}]
-%\item[\csintro{\knowledge_kl_forcedtext_tl}]
-%\item[\csreintro{\knowledge_kl_link_tl}]
-%\item[\csreintro{\knowledge_kl_linkscope_tl}]
-%\item[\csreintro{\knowledge_kl_display_process_tl}]
-%\item[\csintro{\knowledge_kl_default_invisible_display_process_tl}]
-%\end{compactdesc}
-%
-% \begin{macrocode}
-\NewKnowledgeParamBool*{fbox}\kl_fbox_bool
-\NewKnowledgeParamBool*{ensuremath}\kl_ensuremath_bool
-\NewKnowledgeParamBool*{ensuretext}\kl_ensuretext_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*{emphasize}\kl_emphasize_bool
-\NewKnowledgeParamBool*{underline}\kl_underline_bool
-\NewKnowledgeParamBool*{typewriter}\kl_typewriter_bool
-\NewKnowledgeParamBool*{autoref~target}\kl_autoreftarget_bool
-\NewKnowledgeParamBool*{autoref~link}\kl_autoreflink_bool
-\NewKnowledgeParamBool*{invisible}\kl_invisible_bool
-\NewKnowledgeParamBool*{italic}\kl_italic_bool
-\NewKnowledgeParamBool*{sc}\kl_sc_bool
-\NewKnowledgeParamBool*{md}\kl_md_bool
-\NewKnowledgeParamBool*{up}\kl_up_bool
-\NewKnowledgeParamBool*{boldface}\kl_boldface_bool
-\NewKnowledgeParamBool*{detokenize}\kl_detokenize_bool
-\NewKnowledgeParamBool*{remove~space}\kl_removespace_bool
-\NewKnowledgeParamBool*{protect~link}\kl_protect_link_bool
-\NewKnowledgeParamBool*{lowercase}\kl_lowercase_bool
-\NewKnowledgeParamBool*{uppercase}\kl_uppercase_bool
-% \end{macrocode}
-%
-% \begin{macrocode}
-\NewKnowledgeParamTl*{link}
-\NewKnowledgeParamTl*{link~scope}
-\NewKnowledgeParamTl*[\knowledge_kl_instance_tl]{link~instance}
-\NewKnowledgeParamTl*[\knowledge_kl_forcedtext_tl]{text}
-\NewKnowledgeParamTl*{wrap}
-% \end{macrocode}
-%
-%
-% \begin{macrocode}
-
-\NewKnowledgeParamBool*{UnKnoWn~KNowLedGE}\kl_unknown_knowledge_bool
-\bool_gset_false:N\kl_unknown_knowledge_bool
-\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 },
- also~now .code:n = { \bool_set_true:N\knowledge_knowledge_alsonow_bool }
-}
-% \end{macrocode}
-%
-% The special directive \kl{autorefhere} is used for variables, where for which it is not necessary
-% to explicitely use a \cs{\knowledge} command.
-% \begin{macrocode}
-\int_new:N\knowledge_autoref_count
-
-\keys_define:nn{ knowledge~directives }{
- autoref .code:n = {
- \int_gincr:N\knowledge_autoref_count
- \knowledge_delay_directive:x
- {autoref = {autoref-\int_use:N\knowledge_autoref_count}}
- \bool_set_true:N\knowledge_knowledge_autoref_bool},
- 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\knowledge_kl_autoref_tl{#1} }
-
-\keys_define:nn { knowledgenow~directives } {
- autoref .code:n =
- { \knowledge_at:c{ktuple_autoref_gset:Nn}{#1} }
-}
-% \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}.}
-\NewKAuxCommand\KAuxAutorefTarget{mmm}
- {Package~knowledge:~Declares~the~use~of~a~target~to~an~autoref~knowledge.~
- Arguments~{namespace}{instance}{knowledge}.}
-\DeclareKAuxPhaseCommand\KAuxAutoref{init}{}
-
-\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_compare:nNnTF\kl_countuse_int=1
- {\int_gincr:N\kl_digest_autorefunused_int}
- {\int_gincr:N\kl_digest_autorefused_int}
- }
- \int_compare:nNnT\kl_countintro_int=0
- {\int_compare:nNnF\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-not-used}
- {\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=1
- {\int_compare:nNnT\kl_countintro_int=1
- {\knowledge_diagnose_line:
- \knowledge_diagnose:x{\kaux_current_location:\space
- \exp_not:n{{#3}{#1}{#2}}}}}
- \group_end:}
-\DeclareKAuxPhaseCommand\KAuxAutorefTarget{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:x{\kaux_current_location:\space
- \exp_not:n{{#3}{#1}{#2}}}}
- \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}
-%
-%
-%
-%
-% \begin{macrocode}
-\cs_new:Nn\knowledge_kl_display_generic:n
- {\tl_gset:Nx\knowledge_display_code_tl
- {\exp_not:n{#1}{\exp_not:V\knowledge_display_code_tl}}}
-\cs_new:Nn\knowledge_kl_display_generic_cond:Nn
- {\bool_if:NTF#1
- {\tl_gset:Nx\knowledge_display_code_tl
- {\exp_not:n{#2}{\exp_not:V\knowledge_display_code_tl
- }}}{}}
-\cs_generate_variant:Nn\knowledge_kl_display_generic:n{x}
-\cs_generate_variant:Nn\knowledge_kl_display_generic_cond:Nn{Nx}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\knowledge_kl_compute_code:{
- \tl_if_exist_ne:NTF\knowledge_kl_forcedtext_tl
- {\tl_gset_eq:NN\knowledge_display_code_tl\knowledge_kl_forcedtext_tl}
- {\tl_gset_eq:NN\knowledge_display_code_tl\knowledge_kl_text_tl}
- \bool_if:NT\kl_detokenize_bool
- {\tl_set:Nx\knowledge_display_code_tl
- {\tl_to_str:V\knowledge_display_code_tl}}
- \bool_if:NT\kl_removespace_bool
- {\tl_remove_all:Nn\knowledge_display_code_tl{~}}
- \bool_if:NT\kl_lowercase_bool
- {\tl_set:Nx\knowledge_display_code_tl
- {\exp_args:NV\tl_lower_case:n\knowledge_display_code_tl}}
- \bool_if:NT\kl_uppercase_bool
- {\tl_set:Nx\knowledge_display_code_tl
- {\exp_args:NV\tl_upper_case:n\knowledge_display_code_tl}}
- %
- \tl_if_empty:NTF\knowledge_kl_wrap_tl
- {}
- {\exp_args:NV\knowledge_kl_display_generic:n\knowledge_kl_wrap_tl}
- %
- \bool_if:NT\knowledge_xcolor_active_bool
- \knowledge_kl_compute_code_xcolor:
- \bool_if:NT\knowledge_hyperref_active_bool
- \knowledge_kl_compute_code_hyperref:
- %
- \knowledge_kl_display_generic_cond:Nn\kl_underline_bool\kl_underline:n
- \knowledge_kl_display_generic_cond:Nn\kl_md_bool\kl_md:n
- \knowledge_kl_display_generic_cond:Nn\kl_boldface_bool\kl_bf:n
- \knowledge_kl_display_generic_cond:Nn\kl_up_bool\kl_up:n
- \knowledge_kl_display_generic_cond:Nn\kl_italic_bool\kl_it:n
- \knowledge_kl_display_generic_cond:Nn\kl_sc_bool\kl_sc:n
- \knowledge_kl_display_generic_cond:Nn\kl_typewriter_bool\kl_tt:n
- % if math
- \knowledge_kl_display_generic_cond:Nn\kl_mathop_bool\mathop
- \knowledge_kl_display_generic_cond:Nn\kl_mathord_bool\mathord
- \knowledge_kl_display_generic_cond:Nn\kl_mathbin_bool\mathbin
- \knowledge_kl_display_generic_cond:Nn\kl_mathrel_bool\mathrel
- \knowledge_kl_display_generic_cond:Nn\kl_mathclose_bool\mathclose
- \knowledge_kl_display_generic_cond:Nn\kl_mathopen_bool\mathopen
- \knowledge_kl_display_generic_cond:Nn\kl_mathpunct_bool\mathpunct
- % if text
- \knowledge_kl_display_generic_cond:Nn\kl_emphasize_bool\kl_em:n
- \knowledge_kl_display_generic_cond:Nn\kl_fbox_bool\fbox
- %
- \knowledge_kl_display_generic_cond:Nn\kl_ensuremath_bool\ensuremath
- \knowledge_kl_display_generic_cond:Nn\kl_ensuretext_bool\ensuretext
- %
- \bool_if:NT\knowledge_makeidx_active_bool
- \knowledge_kl_compute_code_makeidx:
- %
- \bool_if:NT\kl_invisible_bool
- {\tl_gclear:N\knowledge_display_code_tl}
-}
-\cs_new:Nn\knowledge_kl_compute_code_xcolor:{
- \tl_if_empty:NF\knowledge_kl_color_tl
- {\knowledge_kl_display_generic:x{\exp_not:N\textcolor{\knowledge_kl_color_tl}}}
- \tl_if_empty:NF\knowledge_kl_colorbox_tl
- {\knowledge_kl_display_generic:x{\exp_not:N\colorbox{\knowledge_kl_colorbox_tl}}}
-}
-\cs_new:Nn\knowledge_kl_compute_code_hyperref:{
- \tl_if_exist_ne:NT\knowledge_kl_ref_tl
- {\knowledge_kl_display_generic:x
- {\exp_not:N\kl_hyperlink_silentref:nn
- {\exp_not:V\knowledge_kl_ref_tl}}}
- %
- \knowledge_kl_compute_code_hyperreftarget:
- %
- \bool_if:NT\kl_autoreflink_bool
- {\tl_if_exist_ne:NT\knowledge_kl_autoref_tl
- {\knowledge_kl_display_generic:x
- {\exp_not:N\kl_hyperlink_silentref:nn
- {\exp_not:V\knowledge_kl_autoref_tl}}
- }}
- %
- \tl_if_exist_ne:NT\knowledge_kl_url_tl
- {\knowledge_kl_display_generic:x
- {\exp_not:N\kl_hyperlink_url:nn
- {\exp_not:V\knowledge_kl_url_tl}}}
-}
-\cs_new:Nn\knowledge_kl_compute_code_hyperreftarget:{
- \bool_if:NT\kl_autoreftarget_bool
- {\tl_if_exist_ne:NT\knowledge_kl_autoref_tl
- {\expandafter\ktuple_countintro_get_int:NN
- \knowledge_kl_resourcetoken_tl\l_tmpa_int
- \tl_set:Nx\l_tmpa_tl
- {\int_compare:nNnTF\l_tmpa_int=1
- {} {\int_to_alph:n\l_tmpa_int}}
- \exp_args:Nx\label{\exp_not:V\knowledge_kl_autoref_tl\l_tmpa_tl}}
- \expandafter\ktuple_countintro_gincr:N
- \knowledge_kl_resourcetoken_tl
- \KAuxWriteX
- {\exp_not:N\KAuxAutorefTarget
- \exp_not:o\knowledge_kl_resourcearguments_tl}}
-}
-\cs_new:Nn\knowledge_kl_compute_code_makeidx:{
- \tl_if_exist_ne:NTF\knowledge_kl_index_tl
- {\exp_args:Nx\index
- {\tl_if_exist_ne:NTF\knowledge_kl_index_parent_key_tl
- {\exp_not:V\knowledge_kl_index_parent_key_tl!}{}
- \tl_if_exist_ne:NTF\knowledge_kl_index_key_tl
- {\exp_not:V\knowledge_kl_index_key_tl@}{}
- \expandafter\tl_to_str:n\expandafter{\knowledge_kl_index_tl}
- }}{}
-}
-
-%\cs_new:Nn\knowledge_kl_default_display_code_fbox:n
-% {\bool_if:NTF\kl_fbox_bool{\exp_not:N\fbox{#1}}{#1}}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Npn\kl_up:n{\mode_if_math:TF\mathup\textup}
-\cs_new:Npn\kl_md:n{\mode_if_math:TF\mathmd\textmd}
-\cs_new:Npn\kl_sc:n{\mode_if_math:TF\mathsc\textsc}
-\cs_new:Npn\kl_it:n{\mode_if_math:TF\mathit\textit}
-\cs_new:Npn\kl_tt:n{\mode_if_math:TF\mathtt\texttt}
-\cs_new:Npn\kl_bf:n{\mode_if_math:TF\mathbf\textbf}
-\cs_new:Npn\kl_underline:n{\mode_if_math:TF\use:n\underline}
-\cs_new:Npn\kl_em:n{\mode_if_math:TF\use:n\emph}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\knowledge_kl_default_display_code_color:n{
- \bool_if:NTF\knowledge_xcolor_active_bool
- {\tl_if_exist_ne:NTF\knowledge_kl_color_tl
- {\exp_not:N\textcolor{\knowledge_kl_color_tl}{#1}}{#1}}
- {#1}}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\knowledge_kl_default_display_code_colorbox:n{
- \bool_if:NTF\knowledge_xcolor_active_bool
- {\tl_if_exist_ne:NTF\knowledge_kl_colorbox_tl
- {\exp_not:N\colorbox{\knowledge_kl_colorbox_tl}{#1}}{#1}}
- {#1}}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\knowledge_kl_default_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_kl_default_code_wrap:n{
- \tl_if_exist_ne:NTF\knowledge_kl_wrap_tl
- {\exp_not:V\knowledge_kl_wrap_tl{#1}}{#1}}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\knowledge_kl_default_display_code_text:{
- \knowledge_kl_default_code_wrap:n{
- \tl_if_exist_ne:NTF\knowledge_kl_forcedtext_tl
- {\exp_not:V\knowledge_kl_forcedtext_tl}
- {\exp_not:V\knowledge_kl_text_tl}
- }
-}
-% \end{macrocode}
-%
-% \subsubsection{Other commands}
-%
-% \paragraph{\cs{\AP} and \cs{\itemAP}}
-% The code for the command \cs{\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_ref: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:Npn\kl_hyperlink_silentref:nn#1
- {\kl_if_hyperref_exist:nTF{#1}
- {\kl_hyperlink_ref:nn{#1}}
- \use:n}
-\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 takes
-% knowledge,key,scope and is equivalent to \cs{\kl}.
-% \begin{macrocode}
-\tl_new:Nn\knowledge_variant_quote_modifier_tl{\kl*}
-\tl_new:Nn\knowledge_variant_doublequote_modifier_tl{\intro*}
-% \end{macrocode}
-%\knowledgeconfigure{quotation=false}
-% \begin{macrocode}
-\ExplSyntaxOff
-\def\makequotationactive
- {\catcode`"13\relax}
-\def\makequotationletter
- {\catcode`"12\relax}
-% \end{macrocode}
-% \begin{macrocode}
-\let\quotesymbol"
-% \end{macrocode}
-% \begin{macrocode}
-\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\klquotation_expand:nnn
- {\knowledge_variant_quote_modifier_tl
- \klquotation_expand_base:nnn}
-\cs_new:Npn\kldoublequotation_expand:nnn
- {\knowledge_variant_doublequote_modifier_tl
- \klquotation_expand:nnn}
-% \end{macrocode}
-% \begin{macrocode}
-\cs_new:Nn\klquotation_expand_base:nnn{
- \tl_if_empty:nTF{#2}
- {\klTKS{#1}{#1}{#3}}
- {\klTKS{#1}{#2}{#3}}
-}
-% \end{macrocode}
-% \begin{macrocode}
-\def\klactivatequotation
- {\makequotationactive
- \let"\klactivequotationmark}
-\def\kldeactivatequotation
- {\makequotationletter}
-
-\kldeactivatequotation
-% \end{macrocode}
-%\knowledgeconfigure{quotation=true}
-%
-% 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 \csintro{\klparse_absorb_modifiers:}.
-% This command parses all the subscripts and so on occurring after,
-% and then launches \csintro{\klparse_absorb_modifiers_exec:}
-% (that is supposed to have been set with the proper code).
-% At the end, the token lists \csintro{\klparse_primes_tl}, \csintro{\klparse_subscript_tl}
-% and \csintro{\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 \cs{\klparse_novalue_tl}. This is not the case for primes:
-% if there are no primes, then the token list \cs{\klparse_primes_tl} is simply empty.
-% Parsing subscripts, superscripts and primes can be deactivated or activated by setting appropriately the
-% macros \cs{\klparse_if_load_primes:TF}
-% \cs{\klparse_if_load_subscript:TF} and \cs{\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 \csintro{\klparse_absorb_subscript:Nn} and \csintro{\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 \kl{xcolor option}}
-%
-% \begin{macrocode}
-\NewKnowledgeParamTl*{color}
-\NewKnowledgeParamTl*{colorbox}
-
-\knowledge_directives_require_aci_package:nn
- {color,colorbox}{xcolor}
-% \end{macrocode}
-%
-%
-% \subsubsection{The \kl{hyperref option}}
-%
-% \begin{macrocode}
-\NewKnowledgeParamTl*{url}
-\NewKnowledgeParamTl*{ref}
-
-\knowledge_directives_require_aci_package:nn
- {url,ref,autoref}{hyperref}
-% \end{macrocode}
-% The commands \cs{\intro}, \cs{\kl} and \cs{\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_klTKS{mmm}{#1}
- \pdfstringdefDisableCommands{%
- \let\klTKS\knowledge_fake_klTKS
- }
-}
-% \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_kl_default_display_code_index:n}
-
- \cs_new:Npn\knowledge_kl_default_display_code_index:n
- {\tl_if_exist_ne:NT\knowledge_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\knowledge_kl_indexkey_tl
- {\exp_not:V\knowledge_kl_indexkey_tl@}{}
- \expandafter\tl_to_str:n\expandafter{\knowledge_kl_index_tl}
- }}}}
-}
-
-\NewKnowledgeParamTl{index}
-\keys_define:nn { knowledge~directives }
-{ index .code:n = {
- \tl_if_empty:nTF{#1}
- {\knowledge_delay_directive:x{index={\exp_not:V\knowledge_knowledge_key_tl}}}
- {\knowledge_delay_directive:n{index={#1}}}},
- index .default:n = {}
-}
-
-\NewKnowledgeParamTl*{index~style}
-\NewKnowledgeParamTl*{index~parent~key}
-\NewKnowledgeParamTl*{index~key}
-% \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 \cs{\knowledgeFixHyperrefTwocolumn}
-% or \cs\knowledgeconfigure\texttt\{\kl{fix hyperref twocolumn}\texttt\}
-% \begin{macrocode}
-\ExplSyntaxOff\makeatletter
-\newcommand\knowledgeFixHyperrefTwocolumn{
- \RequirePackage{etoolbox}
- \newcount\c at additionalboxlevel
- \setcounter{additionalboxlevel}{0}
- \newcount\c at 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{Variants of the \cs{\kl} macro}
-%
-% \begin{macrocode}
-\tl_new:Nn\knowledge_kl_default_style_tl{kl}
-\tl_new:Nn\knowledge_kl_unknown_style_tl{kl~unknown}
-\tl_new:Nn\knowledge_kl_unknown_style_cont_tl{kl~unknown~cont}
-\tl_new:Nn\knowledge_kl_styledirectives_tl{\knowledge_kl_style_tl}
-
-\ExplSyntaxOff
-\knowledgestyle{autoref link}{autoref link}
-\knowledgestyle{autoref target}{autoref target}
-\knowledgestyle{invisible}{invisible}
-
-
-\knowledgenewvariant\kl{
- namespace=default,
- default style={kl,autoref link},
- unknown style= kl unknown,
- unknown style cont=kl unknown cont,
- style directive={style}
-}
-\knowledgenewvariant\intro{
- namespace=default,
- default style={intro,autoref target},
- unknown style= intro unknown,
- unknown style cont= intro unknown cont,
- style directive=intro style
-}
-\knowledgenewvariant\phantomintro{
- namespace=default,
- default style={invisible,autoref target},
- unknown style=invisible,
- unknown style cont=invisible
-}
-\knowledgenewvariant\reintro{
- namespace=default,
- default style=intro,
- unknown style=intro unknown,
- unknown style cont=intro unknown cont,
- style directive=intro style
-}
-\knowledgevariantmodifier{\intro*\kl}{\intro}
-\knowledgevariantmodifier{\reintro*\kl}{\reintro}
-
-\ExplSyntaxOn
-% \end{macrocode}
-%
-% \subsubsection{Basic configuration}
-%
-% \begin{macrocode}
-\tl_gset_eq:NN\knowledge_kl_namespace_tl\knowledge_default_namespace_tl
-% \end{macrocode}
-%
-% \begin{macrocode}
-\newcommand\robustdisplay[1]
- {\expandafter\use:n%\tl_trim_spaces:n
- \expandafter{\tl_to_str:n{#1}}}
-\newcommand\robustdisplaybracket[1]
- {[\robustdisplay{#1}]}
-
-\ExplSyntaxOff
-% in paper mode, nothing is displayed
-\IfKnowledgePaperModeTF{
- \knowledgestyle{kl}{}
- \knowledgestyle{kl unknown}{}
- \knowledgestyle{kl unknown cont}{}
- \knowledgestyle{intro}{emphasize}
- \knowledgestyle{intro unknown}{emphasize}
- \knowledgestyle{intro unknown cont}{emphasize}
-}{}
-
-\IfKnowledgeCompositionModeTF{
- \IfXcolorTF{
- \knowledgestyle{kl}{color={blue!70!black}}
- \knowledgestyle{kl unknown}{color=orange}
- \knowledgestyle{kl unknown cont}{color=brown}
- \knowledgestyle{intro}{emphasize,color=blue}
- \knowledgestyle{intro unknown}{emphasize,color=orange}
- \knowledgestyle{intro unknown cont}{emphasize,color=brown}
- }{
- \knowledgestyle{kl}{}
- \knowledgestyle{kl unknown}{underline}
- \knowledgestyle{kl unknown cont}{underline}
- \knowledgestyle{intro}{emphasize}
- \knowledgestyle{intro unknown}{emphasize,underline}
- \knowledgestyle{intro unknown cont}{emphasize,underline}
- }
-}{}
-
-\IfKnowledgeElectronicModeTF{
- \IfXcolorTF{
- \knowledgestyle{kl}{color={blue!70!black}}
- \knowledgestyle{kl unknown}{}
- \knowledgestyle{kl unknown cont}{}
- \knowledgestyle{intro}{emphasize,color=blue}
- \knowledgestyle{intro unknown}{emphasize}
- \knowledgestyle{intro unknown cont}{emphasize}
- }{
- \knowledgestyle{kl}{}
- \knowledgestyle{kl unknown}{}
- \knowledgestyle{kl unknown cont}{}
- \knowledgestyle{intro}{emphasize}
- \knowledgestyle{intro unknown}{emphasize}
- \knowledgestyle{intro unknown cont}{emphasize}
- }
-}{}
-
-\ExplSyntaxOn
-\let\nointro\phantomintro
-% \end{macrocode}
-%
-
-%
-% \subsubsection{The "notion" configurations}
-% \label{section:notion option}
-%
-%\paragraph{The configuration option `\kl{notion}'.}
-%
-%The macro \csintro{\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 \cs{\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
-
-
-
-
Added: trunk/Master/texmf-dist/source/latex/knowledge/knowledge.ins
===================================================================
--- trunk/Master/texmf-dist/source/latex/knowledge/knowledge.ins (rev 0)
+++ trunk/Master/texmf-dist/source/latex/knowledge/knowledge.ins 2017-10-19 21:29:32 UTC (rev 45560)
@@ -0,0 +1,70 @@
+%%
+%% 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
+\askforoverwritefalse
+\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
+
+\generate{%
+ \file{knowledge.sty}{%
+ \from{knowledge-code.dtx}{head}%
+ \from{knowledge-utils.dtx}{package}%
+ \from{knowledge-code.dtx}{package}%
+ \from{knowledge-configuration.dtx}{package}%
+ \from{knowledge-code.dtx}{tail}}%
+}
+
+
+
+\nopreamble\nopostamble
+\def\MetaPrefix{}
+\generate{%
+ \file{README.md}{
+ \usepreamble\empty
+ \usepostamble\empty%
+ \from{knowledge-code.dtx}{readme}%
+ }}%
+
+
+
+
+\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
+
Modified: trunk/Master/texmf-dist/tex/latex/knowledge/knowledge.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/knowledge/knowledge.sty 2017-10-19 21:28:59 UTC (rev 45559)
+++ trunk/Master/texmf-dist/tex/latex/knowledge/knowledge.sty 2017-10-19 21:29:32 UTC (rev 45560)
@@ -4,11 +4,11 @@
%%
%% The original source files were:
%%
-%% knowledge.dtx (with options: `head')
+%% knowledge-code.dtx (with options: `head')
%% knowledge-utils.dtx (with options: `package')
-%% knowledge.dtx (with options: `package')
+%% knowledge-code.dtx (with options: `package')
%% knowledge-configuration.dtx (with options: `package')
-%% knowledge.dtx (with options: `tail')
+%% knowledge-code.dtx (with options: `tail')
%%
%% This is a generated file. Copyright (C) 2017 by Thomas Colcombet
%%
@@ -23,7 +23,7 @@
%% LaTeX version 1999/12/01 or later.
%%
\usepackage{expl3}
-\ProvidesExplPackage{knowledge}{2017/10/10}{v1.07}{}
+\ProvidesExplPackage{knowledge}{2017/10/18}{1.07}{}
%%%%%%%%%%
\RequirePackage{l3keys2e}
\RequirePackage{etoolbox}
@@ -2825,9 +2825,27 @@
\NewKnowledgeParamPackageError{#1}{#2}}}
\NewKnowledgeParamTl*{color}
\NewKnowledgeParamTl*{colorbox}
+\knowledge_directives_require_aci_package:nn
+ {color,colorbox,cyclic~color}{xcolor}
+\tl_new:N\knowledge_cyclic_colors_tl
+\tl_new:N\knowledge_cyclic_color_tl
+\keys_define:nn{ knowledge~configuration~options }{
+ cyclic~colors .code:n = {\tl_gset:Nn\knowledge_cyclic_colors_tl{#1}}
+}
+\knowledgeconfigure{cyclic~colors =
+ {red,green,blue,cyan,magenta,yellow,gray,brown,lime,olive,orange,pink,purple,teal,violet}}
+\cs_new:Npn\__knowledge_cyclic_color_next:w#1,#2\__knowledge_cyclic_end
+ {\tl_gset:Nn\knowledge_cyclic_colors_tl{#2,{#1}}
+ \tl_gset:Nn\knowledge_cyclic_color_tl{#1}}
+\cs_new:Nn\knowledge_cycle_colors:
+ {\expandafter\__knowledge_cyclic_color_next:w\knowledge_cyclic_colors_tl\__knowledge_cyclic_end}
-\knowledge_directives_require_aci_package:nn
- {color,colorbox}{xcolor}
+\keys_define:nn{ knowledge~directives }{
+ cyclic~color .code:n = {
+ \knowledge_cycle_colors:
+ \knowledge_delay_directive:x
+ {color = {\knowledge_cyclic_color_tl}}}
+}
\NewKnowledgeParamTl*{url}
\NewKnowledgeParamTl*{ref}
More information about the tex-live-commits
mailing list