summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/knowledge/knowledge-configuration.dtx
blob: 4852d1fa4e989b9a0b81b07f70e585d8c24e0489 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
% \iffalse meta-comment
%
% Copyright (C) 2016 by Thomas Colcombet
% -----------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2 % of this license or (at your option) any later version.
% The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.2 or later is part of all distributions of LaTeX
% version 1999/12/01 or later.
%
% \fi
%
% \iffalse
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{paralist}
\EnableCrossrefs
\CodelineIndex
\RecordChanges

\begin{document}
\DocInput{knowledge-configuration.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v2.0}{2016/02/26}{Initial version} %
% \GetFileInfo{scopearticle.def} %
% \DoNotIndex{}
%
%
% \let\ifcode\iffalse
%
%
% \title{The \textsf{knowledge-configuration} part of the \textsf{knowledge} package}
% \author{Thomas Colcombet \\ \texttt{thomas.colcombet@irif.fr}}
% \date{\today}
% \maketitle
%
% \begin{abstract}
% Some code for configuring the scope option of the package knowledge.
% Essentially, it contains configurations for reconstructing the tree of the structure of the document. It is to be expanded when the use requires it.
%
% So far, it stands as a standalone file scopearticle.def. It should eventually be part of knowledge.sty, and be extra configurable (detect the style, and tries to automatically overload it).
% \end{abstract}
%
% \section{Introduction}
%
% This package is in fact part of the code used by \texttt{knowledge} when the scope option is activated.
% Its goal is to configure the hooks for the \texttt{article} class. It works also for similar classes.
%
% \StopEventually{\PrintIndex}
%
%
%
% This package patches the article class for making it compatible with
% the scope package. Essentially, it modifies all the structure and the commands
% that interact with the structure of an article, and weave into it the update of the
% scope structure.
%
%
% \section{Implementation}
%
% \subsection{Code preparation}
%    \begin{macrocode}
\knowledge_begin_module_if:n\knowledge_option_scope_bool
%    \end{macrocode}
%
% \section{Main structure}
%
% Note that the scopes \texttt{base}, \texttt{document}, \texttt{body} and \texttt{scope} are already configured in knowledge.sty.
%
% \subsection{Standard sectioning command}
%
%
%    \begin{macrocode}
\scope_area_set:nn
  {part, section,subsection,subsubsection,
   paragraph,subparagraph,subsubparagraph}
   { category=structure,
     autoclose = true,
     occurrences = multiple,
     knowledge=accepts
   }
\scope_area_set:nn
  {base,document,section,subsection,subsubsection,
   paragraph,subparagraph,subsubparagraph}
  {knowledge=accepts}
\scope_area_set:nn
  {base,document}
  {knowledge=attracts}
\scope_area_set:nn
  {body}
  {knowledge=none}

\scope_area_set:nn{part}{parents = {body}, forces = body }
\scope_area_set:nn{section}{parents = {body,part}, forces = body }
\scope_area_set:nn{subsection}{parents = section }
\scope_area_set:nn{subsubsection}{parents = subsection }
\scope_area_set:nn{paragraph}{parents = {document,section,subsection,subsubsection} }
\scope_area_set:nn{subparagraph}{parents =  {paragraph}  }
\scope_area_set:nn{subsubparagraph}{parents =  {subparagraph} }
%    \end{macrocode}
%
%    \begin{macrocode}
\scope_area_set:nn{abstract}
  {autoclose=false,
   occurrences=once,
   parents={body,structure},
   forces=body,
   knowledge=none
}
%    \end{macrocode}
%  \subsubsection{Overloading the commands}
%
%    \begin{macrocode}
\OverloadCommand\section{som}
  {\scope_area_push:n{section}
   \XparseArgs\SUPERsection{som}{#1}{#2}{#3}}
\OverloadCommand\subsection{som}
  {\scope_area_push:n{subsection}
   \XparseArgs\SUPERsubsection{som}{#1}{#2}{#3}}
\OverloadCommand\subsubsection{som}
  {\scope_area_push:n{subsubsection}
   \XparseArgs\SUPERsubsubsection{som}{#1}{#2}{#3}}
\OverloadCommand\paragraph{som}
  {\scope_area_push:n{paragraph}
   \XparseArgs\SUPERparagraph{som}{#1}{#2}{#3}}
\OverloadCommand\subparagraph{som}
  {\scope_area_push:n{subparagraph}
   \XparseArgs\SUPERsubparagraph{som}{#1}{#2}{#3}}
\OverloadCommand\subsubparagraph{som}
  {\scope_area_push:n{subsubparagraph}
   \XparseArgs\SUPERsubsubparagraph{som}{#1}{#2}{#3}}
%    \end{macrocode}
%
% \subsection{Creation of new environments}
%
%
%
%    \begin{macrocode}
\KnowledgeConfigureEnvironment?
   {theorem,lemma,proposition,fact,conjecture,problem}
   {category=theorem-like,label=accepts}
\KnowledgeConfigureEnvironment?
   {remark,proof}
   {label=accepts,knowledge=accepts}
\KnowledgeConfigureEnvironment?
   {center,flushleft,flushright,minipage,quotation,quote,verbatim,verse}
   {knowledge=accepts,label=none}
%    \end{macrocode}
%
% Command overloading...
%    \begin{macrocode}  
\OverloadCommand\newtheorem{m}
  {\KnowledgeConfigureEnvironment!{#1}{category=theorem-like,label=accepts}
  \SUPERnewtheorem{#1}}
\OverloadCommand\newenvironment{m}
  {\KnowledgeConfigureEnvironment!{#1}{label=accepts}
   \SUPERnewenvironment{#1}}
\OverloadCommand\NewDocumentEnvironment{m}
  {\KnowledgeConfigureEnvironment!{#1}{label=none}
   \SUPERNewDocumentEnvironment{#1}}
%    \end{macrocode}
%
%
% \subsection{Upgrading scope}
%
% \subsection{Itemizing}
% The default code for \LaTeX{} is absolutely catastrophic. 
% In particular, trivlist is used implicitly, making impossible to
% simply Overload the list environements.
% Indeed, some of environments (like theorems) use trivlists and |\item|
% for their internal display. However, one does not want this to be considered
% as a list. Futhremore, normal lists make call to the code of trivlist too.
% Thus we are in the situation in which trivlists have to be patched because otherwise
% items could not guarantee the structure.
% However, trivlist should not be treates as norm lists since these are fake lists used
% for displaying purposes. The below code tries to patch this as cleanly as possible in order
% to obtain a reasonable behaviour.
%    \begin{macrocode}
\scope_area_set:nn
  {itemize,enumerate,description}
  {category=itemize-like}
%  {knowledge=none}

\scope_area_set:nn{item}
  {autoclose=true,
   parents = itemize-like}


\OverloadCommand\item{o}
  {%\scope_categoryseq_pop_to:n{itemize-like}
   %\scope_category_if_area_in:nnTF{trivlist}\scope_top_area_tl
   %  {}
   %  {\scope_area_push:n{item}}
   \XparseArgs\SUPERitem{o}{#1}}

%\OverloadCommand\trivlist{}
%  {\scope_area_push:n{trivlist}
%   \SUPERtrivlist}

%\OverloadCommand\endtrivlist{}{
%  \SUPERendtrivlist
%  \scope_categoryseq_pop_to:n{itemize-like}
%  \exp_args:NV\tl_if_eq:nnTF\scope_top_area_tl{trivlist}
%      {\scope_area_pop:n{trivlist}}{}}
%    \end{macrocode}
% \subsubsection{Micro areas}
%    \begin{macrocode}
\scope_area_set:nn{emph,textit,texttt,textbf}{
    autoclose = false,
    occurrences = multiple,
    forces = body
  }
%    \end{macrocode}
%
%
%    \begin{macrocode}
\knowledge_end_module:
%    \end{macrocode}
% \Finale