Debian Codegraph @

texmf-dist/doc/latex/pkgloader/pkgloader.tex

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \iffalse %%%%
2 % %
3 % Copyright (c) 2018 - Michiel Helvensteijn (www.mhelvens.net) %
4 % %
5 % https://github.com/mhelvens/latex-pkgloader %
6 % %
7 % This work may be distributed and/or modified under the conditions %
8 % of the LaTeX Project Public License, either version 1.3 of this %
9 % license or (at your option) any later version. The latest version %
10 % of this license is in http://www.latex-project.org/lppl.txt %
11 % and version 1.3 or later is part of all distributions of LaTeX %
12 % version 2005/12/01 or later. %
13 % %
14 % This work has the LPPL maintenance status `maintained'. %
15 % %
16 % The Current Maintainer of this work is Michiel Helvensteijn. %
17 % %
18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \fi %%%%
19
20 \documentclass[a4paper]{pkgloader-packagedoc}
21
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23 % Setup %
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25
26 \def\nt#1{\ensuremath{\hbox{\footnotesize$\langle$}\mathit{#1}\hbox{\footnotesize$\rangle$}}}
27 \def\|{\ \mid\ }
28
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 % Global Changes %
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32
33 \changes{0.1.0}{2014/01/29}
34 {initial version}
35
36 \changes{0.2.0}{2014/05/10}
37 {an important release, which implements most features described in
38 the pkgloader TUGBoat article, and fixes a ton of bugs}
39
40 \changes{0.3.0}{2014/08/31}
41 {fixed the package to work with more recent releases of expl3,
42 which removed the individual l3kernel .sty files; additionally,
43 pkgloader now understands preferred loading orders of cleveref}
44
45 \changes{0.4.1}{2014/10/26}
46 {integrates a number of new package loading rules contributed by the community}
47
48 \changes{0.5.0}{2014/11/30}
49 {integrates a number of new package loading rules contributed by the community}
50
51 \changes{0.5.1}{2017/09/20}
52 {fixed the package to work aafter \cs_new:Nn was changed to only allow 'N' and 'n' in function signatures (2016/08/20)}
53
54 \changes{0.6.0}{2018/03/24}
55 {integrates a number of new package loading rules contributed by the community}
56
57 \changes{0.7.0}{2018/04/29}
58 {integrates a number of new package loading rules contributed by the community}
59
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 \begin{document} %
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
64 \maketitle
65
66 \section {Introduction} % % % % % % % % % % % % % % % % % % % % % % % % % % % %
67
68 \LaTeX\ can be extended by loading packages
69 using a \lstinline+\usepackage+, \lstinline+\RequirePackage+
70 or \lstinline+\RequirePackageWithOptions+ command. Similarly, documents load
71 a document class using \lstinline+\documentclass+, \lstinline+\LoadClass+
72 or \lstinline+\LoadClassWithOptions+.
73 Packages and classes can add definitions, change existing ones,
74 or otherwise extend functionality of the language.
75
76 While the Turing-complete power of the \TeX\ language is quite useful at times,
77 it does make it all too easy for independent package authors to step on each
78 others toes. CTAN is full of conceptually independent packages that cannot be
79 loaded together, or break if they are not loaded in a specific order.
80
81 Yet, until now, there has been no automated package management to speak of.
82 Document authors are usually told to avoid certain package combinations,
83 or to load packages in some specific order.
84 Occasionally, package authors patch their code to be aware of specific
85 other packages, circumventing known conflicts.
86 But this makes maintenance more difficult, because these package authors
87 are `mixing concerns'; they put code related to other packages into their
88 own package. And it is all done in an ad-hoc fashion.
89
90 Enter \lstinline+pkgloader+.
91
92
93
94 \subsection {Package Description} % % % % % % % % % % % % % % % % % % % % % %
95
96 Here is an example of main file for a \LaTeX\ document
97 which uses \lstinline+pkgloader+:
98
99 \newcommand{\morecode}{\hbox{\vphantom{\LARGE(}\smash{\ \small\vdots}}}
100 \newcommand{\anyorder}{
101 \smash{\small\hbox{
102 \(
103 \qquad\left.\vrule height 1em depth 1.4em width 0pt\right\}
104 \hbox{\textit{\rmfamily any order}}
105 \)
106 } } }
107 \newcommand{\optional}{
108 \smash{\small\raisebox{-.7\baselineskip}{
109 \(
110 \qquad\left.
111 \begin{array}{l}\\[.8em]\end{array}
112 \right\}
113 \hbox{\textit{\rmfamily optional}}
114 \)
115 } } }
116 \begin{latex}
117 \RequirePackage{pkgloader}
118 \documentclass{article}
119 \usepackage{algorithm}
120 \usepackage{hyperref} $\anyorder$
121 \usepackage{float}
122 \LoadPackagesNow $\hskip44.3pt\optional$
123 $\morecode$
124 \begin{document} $\hdots$ \end{document}
125 \end{latex}
126
127 The idea is to load \lstinline+pkgloader+ before loading any other
128 package or class.
129 It can then intercept all loading requests, analyze them
130 and load them properly, taking this burden off the shoulders of
131 the average document author.
132
133 Between the second and fifth line, the loading of all packages
134 and classes is postponed. The \lstinline+\LoadPackagesNow+ command then
135 loads the packages in some valid order. This also happens automatically
136 upon reaching the end of the preamble. During this process,
137 `conflict resolving' code may also be run, meant specifically to make
138 other packages work together properly. If the above code were
139 compiled without \lstinline+pkgloader+,
140 the given package order would cause errors.
141 %%
142 The main advantage to this approach is that the complexity of dealing
143 with package conflicts is moved to the \lstinline+pkgloader+ package and handled
144 in a systematic manner.
145
146 If you are a document author, this may be all you need to know to use
147 \lstinline+pkgloader+. If you are interested in more advanced functionality,
148 read on!
149
150
151 \subsection {The \texttt{pkgloader} Area} % % % % % % % %
152
153 \describeanymacro
154 {\ttfamily\bfseries\textbackslash RequirePackage\!\!\!\!\!}
155 {{\ttfamily{\bfseries\{}pkgloader{\bfseries\}}\quad\ldots\quad{\bfseries\textbackslash LoadPackagesNow}}}
156
157 The \lstinline+pkgloader+ area is the area between
158 \lstinline+\RequirePackage{pkgloader}+ and
159 \lstinline+\LoadPackagesNow+.
160 Within it, the three traditional package-loading commands
161 are `hijacked', recording information rather than loading
162 packages directly. Also, a \lstinline+\Load+ command is
163 available, which offers more flexibility in regulating
164 package loading behavior.
165
166 |pkgloader| accepts sets of rules coming from outside
167 packages, though support is still somewhat limited.
168 Any |pkgloader-|\nt{something}|.sty| file can be loaded
169 within the |pkgloader| area by passing \nt{something}
170 as a package option. The file |pkgloader-recommended.sty|
171 is loaded this way by default. You can overwrite this by
172 passing |recommended=false| as an option. For example:
173
174 \begin{latex}
175 \RequirePackage[recommended=false, my-better-rules]{pkgloader}
176 $\smash{\raisebox{-1pt}{\small\vdots}}$
177 \LoadPackagesNow
178 \end{latex}
179
180 This area does not play by the recommended package loading
181 rules, but uses the rules in |pkgloader-my-better-rules.sty|
182 instead.
183
184
185
186 \subsection {Package / Class Loading Requests} % % % % % % % %
187
188
189 \marginnote{\ttfamily\bfseries\textbackslash usepackage\\
190 \textbackslash RequirePackage\\
191 \textbackslash RequirePackageW{\ldots}s
192 \textbackslash documentclass\\
193 \textbackslash LoadClass\\
194 \textbackslash LoadClassW{\ldots}s}\noindent
195 For requesting specific packages or classes inside the
196 |pkgloader| area, just use the commands always used
197 for this purpose:
198 \lstinline+\usepackage+,
199 \lstinline+\RequirePackage+ and
200 \lstinline+\RequirePackageWithOptions+, as well as
201 \lstinline+\documentclass+,
202 \lstinline+\LoadClass+ and
203 \lstinline+\LoadClassWithOptions+.
204 Their syntax and effective semantics
205 are the same as they have always been. Their effects are just delayed,
206 reordered and perhaps modified by the active \emph{package loading rules}.
207
208
209
210 \subsection {Package Loading Rules} % % % % % % % %
211
212 \marginnote{\ttfamily\bfseries\textbackslash Load}\noindent
213 Each invocation if the \lstinline+\Load+ command sets up a rule about
214 a class, package or packages, which are not necessarily ever loaded.
215 These rules can come from any number of different sources.
216 A central registry will be maintained together with \lstinline+pkgloader+ itself
217 in the form of |pkgloader-recommended.sty|,
218 specifying well-known conflicts and resolutions.
219 Individual package authors, however, can supply their own rules,
220 as can document authors. Though ideally, for the
221 average document author, things should `just work'.
222
223 The \lstinline+\Load+ command expects the following syntax:
224
225 \vskip\abovedisplayskip
226 \begingroup
227 \centering
228 \begin{tabular}{r@{\ \ \ \ }r@{\ \ \ \ }l}
229 \nt{load} &$::=$& \lstinline+\Load+$\ \nt{package}\ \ \nt{clause}_1\ \ldots\ \nt{clause}_i$ \\
230 &$ \|$& \lstinline+\Load class+$\ \nt{package}\ \ \nt{clause}_1\ \ldots\ \nt{clause}_i$ \\
231 &$ \|$& \lstinline+\Load error+ $\ \ \ \,\nt{clause}_1\ \ldots\ \nt{clause}_i$ \\[2mm]
232
233 \nt{package} &$::=$& \lstinline+[+$\;\nt{options}\;$\lstinline+] {+$\;\nt{pkg}\;$\lstinline+} [+$\;\nt{version}\;$\lstinline+]+ \\[2mm]
234
235 \nt{clause} &$::=$& $\nt{order}\ \ \|\ \ \nt{condition}\ \ \|\ \ \nt{reason}$ \\[2mm]
236
237 \nt{order} &$::=$& \lstinline+before {+ $\nt{pkg}_1\,$\lstinline+, +$\ldots\,$\lstinline+, +$\nt{pkg}_j$ \lstinline+}+ \\
238 &$ \|$& \lstinline+after {+ $\nt{pkg}_1\,$\lstinline+, +$\ldots\,$\lstinline+, +$\nt{pkg}_j$ \lstinline+}+ \\
239 &$ \|$& \lstinline+early+ \\
240 &$ \|$& \lstinline+late+ \\[2mm]
241
242 \nt{condition} &$::=$& \lstinline+always+ $\ \ \|\ \ $
243 \lstinline+if loaded+ $\ \ \|\ \ $
244 \lstinline+if {+ $\nt{\phi}$ \lstinline+}+ \\[2mm]
245
246 \nt{\phi} &$::=$& $\nt{pkg}$ $\ \ \|\ \ $
247 $\nt{\phi}\ $\lstinline+&&+$\ \nt{\phi}$ $\ \ \|\ \ $
248 $\nt{\phi}\ $\lstinline+||+$\ \nt{\phi}$ $\ \ \|\ \ $
249 \lstinline+!+$\;\nt{\phi}$ $\ \ \|\ \ $
250 \lstinline+(+$\;\nt{\phi}\;$\lstinline+)+ \\[2mm]
251
252 \nt{reason} &$::=$& \lstinline+because {+ $\nt{token{-}list}$ \lstinline+}+
253 \end{tabular}
254 \endgroup
255 \vskip\belowdisplayskip
256
257 \noindent
258 \nt{pkg} represents a package or class name.
259 \nt{token{-}list} should expand to a human-readable text without formatting.
260
261 \marginnote{\ttfamily\bfseries if}\noindent
262 The \( \nt{condition} \) clause determines under which package loading
263 conditions any and all parts of a rule are invoked.
264 Here is an example of the use of the \( \nt{condition} \) clause:
265 \begin{latex}
266 \Load {res-ie-lst} if {inputenc && listings}
267 \Load {fixltx2e} always
268 \end{latex}
269
270 \lstinline+res-ie-lst+ (a fictional package built specifically to resolve the
271 conflict between \lstinline+inputenc+ and \lstinline+listings+) will be loaded if requested
272 specifically, or if both \lstinline+inputenc+ and \lstinline+listings+ are loaded. The \lstinline+fixltx2e+ package is
273 always loaded, as it was created to smooth over some mistakes in the
274 \LaTeXe\ core.
275
276 \marginnote{\ttfamily\bfseries always\\ if loaded}
277 The \lstinline+always+ keyword makes a rule unconditional. The \lstinline+if loaded+
278 directive makes a rule conditional on its package already being loaded anyway.
279 This can be used to order two packages only when they are being loaded by other
280 means, and is actually the default behavior (in other words, \lstinline+if loaded+
281 really does nothing).
282
283 \marginnote{\ttfamily\bfseries before\\ after}
284 The \lstinline+before+ and \lstinline+after+ keywords should be pretty straightforward. They
285 can be used for things like:
286 \begin{latex}
287 \Load {xltxtra} after {graphicx}
288 \end{latex}
289 which fixes the loading order between these two packages when they are both loaded.
290
291 \marginnote{\ttfamily\bfseries early\\ late}
292 But the set of \LaTeX\ packages is constantly growing, and it appears that
293 some big packages should almost always be loaded early in the process,
294 and others should almost always be loaded late. Therefore the \lstinline+early+
295 and \lstinline+late+ stages are provided as a fallback mechanism. If two packages
296 are not related by an explicit application order, their loading order
297 may still be decided by their relative stages: \lstinline+early+ before `normal' before \lstinline+late+.
298 That way, conflicts may be avoided in a majority of cases.
299 This is implemented with |pkgloader-early| and |pkgloader-late| stubs in
300 the loading order graph.
301
302 The following example uses the \( \nt{order} \) clause
303 in addition to the \( \nt{condition} \) clause:
304 \begin{latex}
305 \Load {res-ie-lst} if {inputenc && listings}
306 after {inputenc , listings}
307 \Load {fixltx2e} always early
308 \end{latex}
309 An important observation about the loading order is that it
310 might form a cycle when contradictory ordering rules are specified:
311 \begin{latex}
312 \Load {pkg1} after {pkg2}
313 \Load {pkg2} after {pkg1}
314 \end{latex}
315 In practice this could happen if the authors of \lstinline+pkg1+ and \lstinline+pkg2+
316 independently discover a conflict, and both try to solve it by patching
317 their code and having their own package be loaded last. \lstinline+pkgloader+
318 can provide a clear error message when this happens, allowing the
319 two package authors to seek contact and collaborate on a solution.
320
321 \marginnote{\ttfamily\bfseries error}
322 Now, about the \lstinline+error+ keyword.
323 Initially all package combinations are valid. But if two packages
324 are irredeemably incompatible, their combination can be made to trigger
325 an error message by a command such as the following:
326 \begin{latex}
327 \Load error if {algorithms && pseudocode}
328 \end{latex}
329 These two packages provide almost identical functionality and conflict
330 on many command-names. It was generally agreed upon that they should
331 never be loaded together. Document authors should simply choose one
332 or the other.
333
334 \marginnote{\ttfamily\bfseries because}
335 Finally, the \( \nt{reason} \) clause can be used to supply a
336 human-readable explanation of a rule.
337 We finish the above examples by providing reasons:
338 \begin{latex}[basewidth=.598em]
339 \Load {res-ie-lst} if {inputenc && listings}
340 after {inputenc , listings}
341 because {it allows the use of 1 byte unicode
342 characters in code listings}
343
344 \Load {fixltx2e} always early
345 because {it fixes some imperfections in LaTeX2e}
346
347 \Load error when {algorithms && pseudocode}
348 because {they provide almost identical functionality
349 and conflict on many command names}
350 \end{latex}
351 In the future, reasons will be extracted automatically to
352 generate documentation. For now, they are displayed with error
353 messages related to the rule in question.
354
355
356 \subsection {Status} % % % % % % % %
357
358 So far, \lstinline+pkgloader+ seems to work as expected, but has not
359 yet been tested as extensively as it should be. Therefore, bug-reports
360 on the |pkgloader| issue tracker on Github would be most welcome.
361 Also, lots more recommended package loading rules are needed.
362
363 I nonetheless decided to publish the package now, because I've been
364 promising to do so for a while now:
365
366 \begin{center}
367 \url{http://tex.stackexchange.com/questions/123174}
368 \end{center}
369
370 \noindent
371 I hope that, with feedback and community collaboration,
372 use of this package will become widespread and package
373 authors will be able to work in a more modular fashion.
374
375 \emph{Future versions} of |pkgloader| will be able to
376 intelligently merge package options
377 and to track packages loaded by other packages in order
378 to better inform the user --- perhaps even fix problems
379 by carrying information into the next run through auxiliary files.
380 But most of this will depend on feedback.
381
382
383
384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
385 \end{document} %
386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%