Debian Codegraph @

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

raw
1 % !TEX TS-program = latexmkl
2 % !TEX encoding = UTF-8 Unicode
3 % !TeX spellcheck = en_GB
4 % -----------------------------------------------------
5 % tagging.tex
6 % Copyright 2019 Brent Longborough
7 % -----------------------------------------------------
8 % This work may be distributed and/or modified under the
9 % conditions of the LaTeX Project Public License, either version 1.3
10 % of this license or (at your option) any later version.
11 % The latest version of this license is in
12 % http://www.latex-project.org/lppl.txt
13 % and version 1.3 or later is part of all distributions of LaTeX
14 % version 2005/12/01 or later.
15 %
16 % This work has the LPPL maintenance status `maintained'.
17 % The Current Maintainer of this work is Brent Longborough.
18 %
19 % This work consists of these files:
20 % tagging.sty, tagging.tex, and tagging.pdf
21 % -----------------------------------------------------
22 \documentclass[a4paper,12pt,twoside,openany]{memoir}
23 \usepackage{showexpl}
24 \usepackage{tgpagella}
25 \usepackage{tgadventor}
26 \usepackage{fontspec}
27 \defaultfontfeatures{Ligatures=TeX}
28 \setmainfont[Numbers={Proportional,OldStyle}]{TeX Gyre Pagella}
29 \setsansfont[Numbers={Proportional,OldStyle}]{TeX Gyre Adventor}
30 \setmonofont{Consolas}
31 \usepackage{tagging}
32 \setulmarginsandblock{0.11111\paperwidth}{0.22222\paperwidth}{*}
33 \setlrmarginsandblock{0.11111\paperwidth}{0.22222\paperwidth}{*}
34 \setheadfoot{1.2\baselineskip}{0.0849\paperwidth}
35 \setmarginnotes{0.125\foremargin}{0.75\foremargin}{\onelineskip}
36 \setheaderspaces{*}{*}{0.618}
37 \checkandfixthelayout[fixed]
38 \tightlists
39 \chapterstyle{bringhurst}
40 \pagestyle{ruled}
41 \settocdepth{section}
42 \setsecnumdepth{none}
43 \newcommand{\tpn}{tagging}
44 \newcommand{\tpfname}{\textsf{\tpn.sty}}
45 \newcommand{\tpname}{\textsf{\itshape \tpn}}
46 \newcommand{\gitVtag}{\space1.1.0.1}
47 \newcommand{\gitVtagn}{\space1.1.0.1}
48 % -----------------------------------------------------
49 \usepackage[%
50 bookmarksnumbered,
51 bookmarksopen,
52 linktocpage,
53 ]{hyperref}
54 \hypersetup{
55 pdfauthor={Brent Longborough},
56 pdftitle={The tagging package for configuring documents},
57 pdfsubject={Document configuration with LaTeX},
58 pdfkeywords={tagging;document configuration},
59 }
60 \begin{document}
61 % -----------------------------------------------------
62 \title{%
63 \Huge \tpfname\\[2ex]%
64 \Large A package for document configuration
65 }
66 \author{Brent Longborough}
67 \date{9th September, 2019}
68 \maketitle
69
70 {\centering
71 Version:\gitVtagn\\
72 }
73 %\vspace*{2\baselineskip}
74 % -----------------------------------------------------
75 \begingroup
76 \aliaspagestyle{chapter}{empty}
77 \setlength{\afterchapskip}{20pt}
78 \let\clearpage\relax
79 \let\chaptitlefont\Large\bfseries
80 \vspace*{5\baselineskip}
81 \tableofcontents*
82 \clearpage
83 \endgroup
84 % -----------------------------------------------------
85 \chapter{Introduction}
86 \tpname\ is a \LaTeX\ package to help you easily to
87 produce multiple editions of a document from a single source,
88 or to reuse varying parts of an input file
89 to produce more than one result at different places
90 in a single document.
91
92 To use \tpname, just include a standard
93 \verb!\usepackage{tagging}! in your document preamble; there
94 are no package options which alter its intrinsic behaviour,
95 although later you will see how any options you may give are
96 subverted.
97
98 With \tpname, you mark up parts of your
99 \LaTeX source code with \textit{tags} --- labels which
100 make some kind of sense for you in relation to
101 the document you are writing.
102
103 For example, imagine you are writing a car owners' manual.
104 The car can have optional features, such as automatic transmission
105 or a navigation system, and can be powered by diesel or petrol.
106
107 In your source code, \tpname\ allows you to
108 mark up different parts of the text that
109 are required (or not) for a particular label
110 (such as \textbf{petrol}, \textbf{diesel}, \textbf{satnav},
111 and \textbf{auto} in this case).
112
113 Separately, you specify which of your tags you wish to activate;
114 when you process the document, different marked pieces are then
115 included or excluded in accordance with your markup
116 and the active tags.
117
118 Alternatively, you might prefer to tag pieces of the document
119 as applying to given models, by labelling them with one more
120 model designations.
121 For such an application, you would probably have
122 a number of master document source files,
123 each of which would activate the appropriate tags,
124 and then input or include one or more source files
125 containing the marked-up content.
126
127 Another application, such as writing standard letters,
128 might involve simply changing the tags to be activated
129 in the preamble of a marked-up source file.
130
131 Yet another application might involve describing the way
132 in which something --- an idea, an algorithm, for instance --- has evolved.
133 The description of the evolving thing could be labelled with its stages,
134 and then repeatedly imbedded from a master source document with different
135 active tags to reflect the stage in its evolution.
136
137 The possibilities are, if not limitless,
138 at least very extensive.
139 Here are a few more:
140 \begin{itemize}
141 \item Redacted v. unredacted
142 \item Report v. management summary
143 \item Teacher v. Student material
144 \item Question v. Answer
145 \end{itemize}
146 % -----------------------------------------------------
147 \chapter{Tagging commands}
148 \section{Tags and tag lists}
149 All the commands and environments provided by \tpname\
150 take a list of one or more tags as their first parameter.
151 Each tag must consist of one or more
152 alphabetic characters
153 (A-Z,a-z)%
154 \footnote{%
155 Sorry, I haven't yet worked out
156 how to provide support for accented characters.
157 I suspect it means messing with catcodes,
158 so please don't hold your breath waiting for it
159 }
160 which have some meaning for the user.
161 A tag list is a set of one or more tags separated by commas.
162
163 Tagged text is included in the document, or excluded,
164 if any of its tags is `active' at that point in the document.
165 Commands are available to include or exclude text based on its
166 particular tag markup.
167
168 Examples:
169
170 \begin{centering}
171 \begin{tabularx}{0.618\textwidth}{lX}
172 \textbf{Three tags:}&\texttt{draft redacted student}\\
173 \textbf{A tag list:}&\texttt{draft,student,linux}
174 \end{tabularx}\\[\baselineskip]
175 \end{centering}
176
177 \tpname\ does not (deliberately, anyway) restrict the use of tagging to text;
178 it may also be used to control document setup and formatting in the preamble
179 as well as in the body of the document.
180 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
181 \section{Text tagging commands}
182 The three markup commands provided by \tpname\
183 take as parameters a tag list and some text to be included or excluded.
184 Here they are:
185 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
186 \subsection{{\ttfamily\textbackslash tagged\{{\itshape<taglist>}\}\{{\itshape<source text>}\}}}
187 If \emph{any} of the tags in \texttt{\itshape<taglist>} is active,
188 then the \texttt{\itshape<source text>} will be included as part of the document;
189 if not, it will be excluded.
190 \subsection{{\ttfamily\textbackslash untagged\{{\itshape<taglist>}\}\{{\itshape<alt text>}\}}}
191 If \emph{none} of the tags in \texttt{\itshape<taglist>} is active,
192 then the \texttt{\itshape<alt text>} will be included as part of the document;
193 if not, it will be excluded.
194 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
195 \subsection{{\ttfamily\textbackslash iftagged\{{\itshape<taglist>}\}\{{\itshape<source text>}\}\{{\itshape<alt text>}\}}}
196 This is a combination of {\ttfamily\textbackslash tagged} and {\ttfamily\textbackslash untagged}:
197 If \emph{any} of the tags in \texttt{\itshape<taglist>} is active,
198 then the \texttt{\itshape<source text>} will be included as part of the document;
199 if \emph{none} of the tags is active,
200 then \texttt{\itshape<alt text>} will replace \texttt{\itshape<source text>}.
201
202 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
203 \section{Tagged environments}
204 \tpname\ defines two environments: one to include and one to exclude text.
205 As you might expect, these environments are both coded with a
206 {\ttfamily\textbackslash begin\{\}}-{\ttfamily\textbackslash end\{\}} pair.
207 \subsection{{\ttfamily\textbackslash begin\{taggedblock\}\{{\itshape<taglist>}\}}}
208 Source text placed inside a \texttt{taggedblock} environment
209 is included in the document if \emph{at least one} of the tags in
210 \texttt{\itshape<taglist>} is active.
211 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
212 \subsection{{\ttfamily\textbackslash begin\{untaggedblock\}\{{\itshape<taglist>}\}}}
213 Source text placed inside an \texttt{untaggedblock} environment
214 is included in the document only if \emph{none} of the tags in
215 \texttt{\itshape<taglist>} is active.
216
217 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
218 \section{Tag activation and control}
219 The tag control commands determine which tags
220 are active at any point in the document.
221 The document starts with all tags inactive;
222 \tpname\ requires that you explicitly activate
223 the tags you need.
224
225 Once a tag has been activated, it remains active from that point
226 in the document to the point at which it is deactivated,
227 or to the end of the document if not deactivated.
228 All tags operate independently:
229 activating or deactivating a given tag has no hidden effect on other tags.
230
231 \subsection{{\ttfamily\textbackslash usetag\{{\itshape<taglist>}\}}}
232 This command activates \emph{all} the tags in \texttt{\itshape<taglist>}.
233 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
234 \subsection{{\ttfamily\textbackslash usepackage[{\itshape<taglist>}]\{\tpn\}}}
235 If you wish, you may activate one or more tags, once, in your
236 document preamble by passing a taglist as options when you call
237 the package.
238 \emph{All} the tags in \texttt{\itshape<taglist>} are activated.
239 Any tags activated this way can still be deactivated and
240 reactivated as many times as you may need in the body of the
241 document.
242 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
243 \subsection{{\ttfamily\textbackslash droptag\{{\itshape<taglist>}\}}}
244 This command deactivates \emph{all} the tags in \texttt{\itshape<taglist>}.
245 \tpname\ is too simple to include a command
246 to ``deactivate all known tags'' --- sorry.
247
248 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
249 \section{Tag nesting}
250 It is possible to nest markup, though it maybe confusing unless you lay it out carefully.
251 For example,
252 \begin{verbatim}
253 \tagged{lux}{\untagged{nav}{Sorry, something's wrong here!}}
254 \end{verbatim}
255 would apologise if it's a luxury model without a satnav.
256
257 % -----------------------------------------------------
258 \chapter{Examples}
259 These examples show first the markup, then the formatted result in a box below it.
260 \section{Example 1: Tailoring a simple letter}
261 \noindent 1a:
262 \begin{LTXexample}[pos=b]
263 \usetag{good}
264
265 Dear Don,
266
267 The results of your latest evaluation were
268 \tagged{good}{excellent.}
269 \tagged{bad}{disappointing.}
270 \untagged{good,bad}{satisfactory.}
271
272 \iftagged{bad}{I hope you will be able to improve.
273 Please let me know if I can do anything to help.
274 }{Keep up the good work!}
275 \end{LTXexample}
276
277 \noindent 1b:
278 \droptag{good}
279 \begin{LTXexample}[pos=b]
280 \usetag{bad}
281
282 Dear Don,
283
284 The results of your latest evaluation were
285 \tagged{good}{excellent.}
286 \tagged{bad}{disappointing.}
287 \untagged{good,bad}{satisfactory.}
288
289 \iftagged{bad}{I hope you will be able to improve.
290 Please let me know if I can do anything to help.
291 }{Keep up the good work!}
292 \end{LTXexample}
293
294 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
295 \clearpage
296 \section{Example 2: Tailoring a customer brochure}
297 \noindent 2a:
298 \begin{LTXexample}[pos=b]
299 \droptag{deluxe} % Not needed here; for illustration only
300 Welcome to your new mobile phone!
301 \iftagged{deluxe}{Tailored for}{For} your convenience,
302 it comes with:
303 \begin{itemize}
304 \item A screen
305 \begin{taggedblock}{deluxe}
306 \item A built-in microwave oven and Shrubbery
307 \end{taggedblock}
308 \item An operating system
309 \end{itemize}
310 \end{LTXexample}
311 \vspace*{\baselineskip}
312 \noindent 2b:
313 \begin{LTXexample}[pos=b]
314 \usetag{deluxe}
315 Welcome to your new mobile phone!
316 \iftagged{deluxe}{Tailored for}{For} your convenience,
317 it comes with:
318 \begin{itemize}
319 \item A screen
320 \begin{taggedblock}{deluxe}
321 \item A built-in microwave oven and Shrubbery
322 \end{taggedblock}
323 \item An operating system
324 \end{itemize}
325 \end{LTXexample}
326 % -----------------------------------------------------
327 \chapter{Etc}
328 \section{Acknowledgements and dependencies}
329
330 \tpname\ is based on an idea by \href{http://tex.stackexchange.com/users/2674/leo-liu}{Leo Liu}.
331 It would have been a lot more difficult to implement without the help of
332 Philipp Lehman's
333 \href{http://www.ctan.org/tex-archive/macros/latex/contrib/etoolbox}{etoolbox}
334 and of
335 \href{http://www.ctan.org/pkg/verbatim}{verbatim}, currently maintained by
336 Rainer Schöpf, both of which are required for \tpname\ to work.
337
338 I am most grateful to Frank Mittelbach, who intervened to fix my
339 dodgy code and to provide the ability to activate tags as
340 package options, thereby directly inspiring v1.1.
341
342 The \href{http://tex.stackexchange.com}{\TeX.SE community} has
343 been a constant source of help, inspiration, and amazement.
344
345 Of course, we all stand on the shoulders of giants: Donald
346 Knuth, and then too many others to name.
347
348 Thank you all. Any failings that remain are entirely
349 ``an ill-favoured thing, sir, but mine own''.
350
351 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
352 \clearpage
353 \section{Copyright \& licence}
354 Copyright \copyright\ 2019, Brent Longborough.
355
356 This work --- \tpname\ --- may be distributed and/or modified under the
357 conditions of the LaTeX Project Public License: either version 1.3
358 of this license, or (at your option) any later version.
359
360 The latest version of this license is at
361 \url{http://www.latex-project.org/lppl.txt},
362 and version 1.3 or later is part of all distributions of \LaTeX
363 version 2005/12/01 or later.
364
365 This work has the LPPL maintenance status `maintained';
366 the Current Maintainer of this work is Brent Longborough.
367
368 This work consists of the files
369 tagging.sty, tagging.tex, and tagging.pdf
370
371 % - - - - - - - - - - - - - - - - - - - - - - - - - - -
372 \section{From the author}
373 I hope you find this package useful.
374 Please bear in mind that I am very much an amateur \TeX nician,
375 so \tpname\ may be incompatible with some packages, and,
376 if you find such an incompatibility, I may not have the skill to fix it.
377
378 However, I'll be very happy to receive your comments by email.\\[\baselineskip]
379 Enjoy!\\
380 Brent Longborough\\[\baselineskip]
381 \textsf{brent+ctan (at) llwyd-consulting (dot) cymru}\\
382 and at \href{http://tex.stackexchange.com/users/344/brent-longborough}{\TeX.SE}
383 % -----------------------------------------------------
384 \end{document}