Debian Codegraph @

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

raw
1 \documentclass{ltxguidex}
2 \usepackage{changelog}
3 \usepackage{fontspec}
4 \setmainfont{Tiempos Text}
5 \usepackage{FiraSans}
6 \usepackage{FiraMono}
7 \def\labeladvise{→}
8
9 \newcommand{\ltx}{\ltxclass{ltxguidex}}
10 \newcommand{\ltxguide}{\ltxclass{ltxguide}}
11 \title{Towards Better \LaTeX\ Documentation With the \ltx\ Document Class}
12 \author{Rebecca Turner\thanks{Brandeis University;
13 \email{[email protected]}}}
14 \date{2019/04/15 0.2.0}
15 \begin{document}
16 \maketitle
17
18 \begin{abstract}
19 The \ltx\ document class extends \ltxguide\ with a set of
20 environments and commands that make writing beautiful \LaTeX\
21 documentation easier and more natural.
22
23 \ltx\ is licensed under the \textsc{lppl} version 1.3c, or any later
24 version at your choosing.
25
26 This document is written with the \ltx\ document class.
27 \end{abstract}
28
29 \begin{note}
30 This release of \ltx\ is an experimental public beta; it intends to
31 demonstrate a hopeful new direction without committing to a stable
32 public \textsc{api}.
33
34 Although \ltx\ is now suitable for use in your own documentation, do
35 not be surprised if future versions break your docs.
36 \end{note}
37
38 \begin{note}
39 Browse the sources, contribute, or complain at \\
40 \https{github.com/9999years/ltxguidex}
41 \end{note}
42
43 \tableofcontents
44 \vfill
45 \pagebreak
46
47 \section{The state of the docs}
48
49 \LaTeX\ documentation is easy enough to write that --- in general --- nobody
50 has bothered to package the improvements made to the \LaTeX documentation
51 systems. If one examines the documentation for their favorite package,
52 they'll likely find a few command definitions that make some aspect of
53 documentation writing more ergonomic. In the case of complex packages like
54 \ctan{listings} or --- in an extreme case --- \ctan{pgf}, it's commonplace
55 to see packages define their own internal documentation packages containing
56 hundreds-to-thousands of lines of documentation macros.
57
58 This class repackages useful macros from various packages' documentation,
59 often changing their form (e.g.\ the macro's interface) but keeping its
60 style. I've tried to balance versatility against specialization (i.e.\
61 determining which features are the \textit{most} useful) as well as
62 balancing short with descriptive names.
63
64 \LaTeX\ documentation is enabled with two document classes and several
65 packages. Document classes include:
66 \begin{classes}
67 \item[ltxdoc] Defines very little other than a few
68 shorthands for documenting commands. Designed to be integrated with
69 the \docstrip\ system, but I've seen plenty of \extension{dtx} files
70 documented with \ltxguide. However, I haven't yet used
71 \docstrip, so my experience here is limited.
72
73 \item[ltxguide] Provides several ergonomic features absent
74 in \ltxclass{ltxdoc}. However, \ltxguide\ is almost entirely
75 undocumented, a fact which is partially mitigated by the fact that
76 it's only about 150 lines long. \ltx\ is, as the name implies, based
77 on \ltxguide.
78 \end{classes}
79 And supporting packages include:
80 \begin{packages}
81 \item[hypdoc] One of many, many packages by Heiko Oberdiek.
82 \ctan{hypdoc} undertakes the ambitious task of patching the
83 \ctan{doc} package in order to generate better indexes. In my
84 experience, \ctan{hypdoc} is not compatible with
85 \ltxguide; as such, it isn't loaded in \ltx.
86
87 \item[doctools] Provides many useful secondary commands such as
88 |\ltxclass|, |\package|, and so on. Many are duplicated here.
89
90 \item[showexpl] Provides the |LTXexample| environment which typesets
91 \LaTeX\ code and displays it in a listing side-by-side.
92 \ctan{showexpl} provides the functionality of \ctan{listings}'
93 |\lstsample| command and more. \ctan{showexpl} does, however, rely
94 on the fairly hefty \ctan{listings} package.
95
96 Compare to more ``plain'' \LaTeX\ documentation, \ltx\ documentation
97 can be expected to compile somewhat slower. This author is of the
98 opinion that the improvements are so numerous that the slow-down is
99 worth it.
100 \end{packages}
101
102 \section{The \ltx\ document class}
103 Although \ltx\ provides many useful commands, much of its utility is in its
104 aesthetics. Much \LaTeX\ documentation is very ugly because producing
105 beautiful documentation requires significantly more code than most package
106 authors are interested in writing. This document is written with \ltx\ and
107 one package loaded (the \ctan{bera} font family). Because \ltx\ is written
108 with inherent beauty, it ends up being a bit heavier than its competitors;
109 notably, it loads \ctan{xcolor}, \ctan{listings}, \ctan{graphicx}, and
110 \ctan{calc} by default.
111
112 \section{A note on typefaces}
113
114 This document is set in
115 \href{https://klim.co.nz/retail-fonts/tiempos-text/}{Tiempos Text} and
116 \href{https://bboxtype.com/typefaces/FiraSans/}{Fira Sans} (available on
117 \textsc{ctan} as \ctan{fira}).
118
119 For your own documents, I would recommend \ctan{bera} or \ctan{plex},
120 although neither has small caps, which I consider essential.
121
122 When deciding on a serif font for \LaTeX\ documentation, I would recommend
123 picking one with a tall x-height, as larger overall glyphs makes documents
124 easier to read on small screens (nobody's going to be printing out your
125 documentation). This will rule out most old-style serif typefaces, such as
126 Garamond and Calson.
127
128 \section{Commands provided by \ltxguide}
129
130 In \ltxguide, pipe characters (\texttt{\pipe}) mark verbatim text.
131
132 However, between two pipes, the angle brackets |<<| and |>>| typeset as
133 pretty angle brackets with regular italics between them; therefore,
134 \texttt{\pipe}|<<package>>|\texttt{\pipe} typesets as |<package>|.
135
136 To write literal angle brackets, simply double the characters;
137 \texttt{\pipe}|<<<<|\texttt{\pipe} will render as |<<| and
138 \texttt{\pipe}|>>>>|\texttt{\pipe} will render as |>>|.
139
140 \begin{desc}
141 |\pipe|\\
142 |\bs|
143 \end{desc}
144 To write literal pipe characters, use the |\pipe| command. To write a
145 literal backslash, use the |\bs| command.
146
147 \begin{LTXexample}
148 \pipe \\
149 \texttt{\pipe} \\
150 \textit{\pipe} \\
151 \textbf{\texttt{\pipe}} \\
152 \bs \\
153 \texttt{\bs} \\
154 \textit{\bs} \\
155 \textbf{\texttt{\bs}}
156 \end{LTXexample}
157
158 \ltxguide\ uses \ctan{shortvrb} to activate pipes as a synonym for
159 short-verbatim material. There are some small conflicts with \ltx's use of
160 the \ctan{listings} package (in particular, pipes are silently gobbled from
161 |lstlistings| environments, although they work normally within |verbatim|),
162 which will hopefully be resolved with a coming change to \package{listings};
163 this simply depends on how quickly Jobst Hoffmann emails me back.
164
165 \ltxguide\ also provides the |decl| environment that powers the |desc|
166 environment.
167
168 \begin{desc}
169 |\m{<placeholder>}|\\
170 |\meta{<placeholder>}|
171 \end{desc}
172
173 Prints |<placeholder>| in italics within angle-brackets.
174
175 \ltx\ provides |\meta| as a synonym for |\m|.
176
177 \begin{LTXexample}
178 \m{placeholder}
179 \end{LTXexample}
180
181 \begin{desc}
182 |\arg{<argument>}|
183 |\oarg{<argument>}|
184 \end{desc}
185
186 Shorthands for mandatory and optional arguments.
187
188 \begin{LTXexample}
189 \arg{foo}\oarg{bar}
190 \end{LTXexample}
191
192 \begin{desc}
193 \begin{tabular}{@{}ll@{}}
194 |\NFSS| & \NFSS\\
195 |\AmS| & \AmS\\
196 |\AmSLaTeX| & \AmSLaTeX\\
197 |\babel| & \babel\\
198 |\SLiTeX| & \SLiTeX\\
199 |\ctanlogo| & \ctanlogo\\
200 \end{tabular}
201 \end{desc}
202
203 Various logos.
204
205 \begin{note}
206 \ltxguide\ actually defines the \ctanlogo\ logo as |\ctan|, but this
207 class uses |\ctan| to refer to a package, so the \ctanlogo\ logo is
208 typeset with |\ctanlogo|.
209 \end{note}
210
211 \begin{desc}
212 \begin{tabular}{@{}ll@{}}
213 |\clsguide| & \clsguide \\
214 |\usrguide| & \usrguide \\
215 |\fntguide| & \fntguide \\
216 |\cfgguide| & \cfgguide \\
217 |\cyrguide| & \cyrguide \\
218 |\modguide| & \modguide \\
219 |\sourcecode| & \sourcecode \\
220 |\LaTeXbook| & \LaTeXbook \\
221 |\LaTeXcomp| & \LaTeXcomp \\
222 |\LaTeXGcomp| & \LaTeXGcomp \\
223 |\LaTeXWcomp| & \LaTeXWcomp \\
224 \end{tabular}
225 \end{desc}
226
227 The names of various documents, presumably intended only for the original
228 \ltxguide\ document.
229
230 \begin{desc}
231 |\eg|\\
232 |\ie|
233 \end{desc}
234
235 Shortcuts for ``e.g.,''\ and ``i.e.,''\ followed by a non-breaking space.
236
237 \begin{LTXexample}
238 \ie the document class\dots\\
239 \eg the package\dots
240 \end{LTXexample}
241
242 \begin{desc}
243 |\NEWfeature{<version>}|\\
244 |\NEWdescription{<version>}|
245 \end{desc}
246
247 \NEWfeature{1.0.0}
248 \NEWdescription{1.0.0}
249 Typeset their arguments in a |\marginpar|. This paragraph is prepended by
250 |\NEWfeature{1.0.0}|
251 |\NEWdescription{1.0.0}|.
252
253 \begin{desc}
254 |\URL{<url>}|
255 \end{desc}
256
257 Typesets its argument in |\texttt|. Obsolete given that \ltx\ loads
258 \ctan{hyperref}.
259
260 \section{New commands}
261 \ltx\ provides several new commands for convenience.
262
263 \begin{desc}
264 |\begin{desc}...\end{desc}|
265 \end{desc}
266
267 Describes a command or environment, setting it out into the margin and
268 surrounding it with a frame. Originally written by Javier Bezos for the
269 \ctan{enumitem} documenation.
270
271 \begin{example}
272 Unfortunately, a side-by-side listing doesn't seem to be possible
273 here because pipes seem to be gobbled by the \package{listings}
274 package (a side-effect of loading both \ctan{listings} and
275 \ctan{shortvrb}, perhaps). However, here's how the |\email| command
276 is described in this document:
277
278 \begin{verbatim}
279 \begin{desc}
280 |\email{<<email>>}|
281 \end{desc}
282 \end{verbatim}
283 \end{example}
284
285 \begin{desc}
286 |\email{<email>}|
287 \end{desc}
288
289 Typesets an email address with a |mailto:| link.
290
291 \begin{example}
292 Emails, along with other hyperlinks, are colored |magenta|, although
293 \ltx's default magenta is a bit closer to purple.
294 \begin{LTXexample}
295 \email{[email protected]}
296 \end{LTXexample}
297 \end{example}
298
299 \begin{desc}
300 |\https{<url>}|\qquad|\http{<url>}|
301 \end{desc}
302
303 Typesets |<url>| with |https://| or |http://| prepended to the link address;
304 this makes links display a bit prettier than |\url| might.
305
306 \begin{example} The following two listings are equivalent:
307 \begin{LTXexample}
308 \https{ctan.org}
309 \end{LTXexample}
310 \begin{LTXexample}
311 \href{https://ctan.org}{ctan.org}
312 \end{LTXexample}
313 \end{example}
314
315 \begin{desc}
316 |\ctan{<package>}| \\
317 |\ctanlogo|
318 \end{desc}
319
320 Typesets a package name with a link to |ctan.org/pkg/<package>|.
321
322 \begin{warning}
323 \ltx's definition of |\ctan| differs from \ltxguide's,
324 which simply typesets ``\ctanlogo'' in small-caps. The \ctanlogo\
325 logo is typeset with |\ctanlogo|.
326 \end{warning}
327
328 \begin{LTXexample}
329 the \ctan{listings} package\dots
330 \end{LTXexample}
331
332 \begin{desc}
333 |\package{<package>}|\\
334 |\ltxclass{<document class>}|\\
335 |\option{<option name>}|\\
336 |\filename{<filename>}|\\
337 |\extension{<file extension>}|
338 \end{desc}
339
340 Typesets a \LaTeX\ package, option, file extension, etc.\ in |\texttt|.
341
342 \begin{note}
343 Unlike those defined in the \ctan{doctools} package, these commands
344 don't add entries to the index.
345 \end{note}
346
347 \begin{LTXexample}
348 \extension{tex} files
349 \end{LTXexample}
350
351 \begin{desc}
352 |\begin{warning}...\end{warning}|\\
353 |\begin{note}...\end{note}|\\
354 |\begin{example}...\end{example}|\\
355 |\begin{bug}...\end{bug}|
356 \end{desc}
357
358 These environments typeset ``notices'' with a hanging indent. Original
359 definitions written by Javier Bezos for the \ctan{enumitem} documenation.
360 |\noticestyle| is executed before the marker text (``warning,'' ``note,''
361 etc.). New notice environments can be created with |\newnotice|.
362
363 \begin{bug}
364 If the first content in a notice environment is vertical, the marker
365 text is hidden. This can be avoided by starting the
366 environment with |\leavevmode\\| or by adding some introductory
367 material to the first line.
368
369 This is actually a bug in the |\list| command that the notice
370 environments use.
371 \end{bug}
372
373 \begin{example}
374 Although this example is short, note that subsequent lines will
375 be indented. These environments only vary by text.
376
377 \begin{LTXexample}
378 \begin{warning}
379 Lorem ipsum\dots
380 \end{warning}
381 \end{LTXexample}
382 \end{example}
383
384 \begin{desc}
385 |\newnotice{<environment name>}{<marker text>}|
386 \end{desc}
387
388 Creates a new notice environment in the style of |warning|, |note|, and so
389 on. The marker text is automatically uppercased.
390
391 \begin{desc}
392 |\begin{LTXexample}[<options>]...\end{LTXexample}|
393 \end{desc}
394
395 Typesets \LaTeX\ code next to a listing of its source. Providing examples
396 makes your user's lives easier, and should be done as much as possible. The
397 |LTXexample| environment is provided by the \ctan{showexpl} package.
398 Excerpted from \ctan{showexpl}'s documentation as of v0.3o 2016/12/11, valid
399 options include:
400
401 \begin{keys}
402 \key{attachfile}[\bool][false]
403
404 If set to true the sourcecode will be attached to the
405 \extension{pdf} file---presumed that the document is processed by
406 |pdflatex|.
407
408 \key{codefile}[\m{filename}][\bs jobname.tmp]
409 Name of the (temporary) file that contains the code which will be
410 formatted as source code. The default value is |\jobname.tmp|.
411
412 \key{explpreset}[\m{key val list}][\{language=[LaTeX]TeX,\}]
413
414 A |<key val list>| which serves for presetting the properties of the
415 formatting of the source code, for values see the documentation of
416 the \ctan{listings} package. The default value is
417 empty.\footnote{\ltx\ redefines the default to perform syntax
418 highlighting for \LaTeX, in addition to the general improvements
419 made for all listings in the document.}
420
421 \key{graphic}[\m{filename}]
422
423 If present, includes and displays this file instead of the formatted
424 code.
425
426 \key{hsep}[\m{length}]
427 Defines the horizontal distance between the source code and the
428 formatted text.
429
430 \key{justification}[\m{code}][\bs raggedright]
431 Defines the justification of the formatted text: reasonable values
432 are |\raggedleft|, |\raggedright|, |\centering|.
433
434 \key{overhang}[\m{dimen}][0pt]
435 Defines the amount by which the formatted text and the source code
436 can overlap the print space. The default value is 0\,pt.
437
438 \key{pos}[\m{\alternative{t,b,l,r,o,i}}][l]
439 Defines the relative position of the formatted text relating to the
440 source code. Allowed values are |t|, |b|, |l|, |r|, |o|, and |i| for
441 top, bottom, left, right, outer, and inner. The last values give
442 sense only for two-sided printing, where there are outer and inner
443 margins of a page.
444
445 \key{preset}[\m{code}]
446 Any \TeX\ code executed before the sample code but not visible in
447 the listings area.
448
449 \key{rangeaccept}[\bool][false]
450 If set to true, one can define ranges of lines that will be
451 excerpted from the source code.
452
453 \key{rframe}[[\texttt{single}]][\textrm{\textit{(empty)}}]
454 Defines the form of the frame around the formatted text. With a
455 non-empty value (e.\,g. ``single'') a simple frame will be drawn. In
456 the future more kinds of frames will be supported. The default value
457 is empty (no frame).
458
459 \key{varwidth}[\bool][false]
460 If set to true, the formatted text is set with its ``natural'' width
461 instead of a fixed width as given by the value of the option
462 |width|.
463
464 \key{vsep}[\m{dimen}]
465 Defines the vertical distance between the source code and the
466 formatted text.
467
468 \key{wide}[\bool][false]
469 If set to true, the source code and the formatted text overlap the
470 print space and the margin area.
471
472 \key{width}[\m{dimen}]
473 Defines the width of the formatted text. The default value depends
474 of the relative positions of the source code and the formatted text.
475
476 \key{scaled}[[\m{scale factor}]]
477 Without a value the formatted text will be scaled to fit the given
478 width of the result area. With a number as value the formatted text
479 will be scaled by this number.
480 \end{keys}
481
482 In addition to these options the kind of the result box (default: |\fbox|)
483 can be changed. For example:
484 \begin{latexcode}
485 \renewcommand\ResultBox{\fcolorbox{green}{lightgray}}
486 \setlength\ResultBoxSep{5mm}% default: \fboxsep
487 \setlength\ResultBoxRule{2mm}% default: \fboxrule
488 \end{latexcode}
489
490 \begin{desc}
491 |\begin{packages}...\end{packages}|\\
492 |\begin{classes}...\end{classes}|\\
493 |\begin{options}...\end{options}|\\
494 \end{desc}
495
496 Frequently, package authors need to describe a series of options, packages,
497 or document classes. These environments wrap the |description| environment
498 and provide an |\item| which wraps a command like |\package|. In the
499 |packages| environment, |\item[listings]| translates to
500 |\item[\package{listings}]|.
501
502 \begin{LTXexample}
503 \begin{options}
504 \item[foo] \dots
505 \item[bar] \dots
506 \end{options}
507 \end{LTXexample}
508
509 \begin{desc}
510 |\begin{advise}...\end{advise}| $\equiv$\\
511 |\begin{faq}...\end{faq}|\\
512 |\Q|\qquad|\A|\qquad|\advisespace|
513 \end{desc}
514
515 Roughly copied from \ctan{listings}' internal \package{lstdoc} package,
516 these environments represent a list of questions and answers.
517
518 \begin{LTXexample}
519 \begin{faq}
520 \Q Lorem ipsum dolor sit amet?
521 \A Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
522
523 \Q Ut enim ad minim veniam, quis nostrud?
524 \A Exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
525 \end{faq}
526 \end{LTXexample}
527
528 Within these environments, |\Q| and |\A| indicate a question and an answer;
529 they're defined to |\item| and |\advisespace|, respectively.
530
531 \begin{note}
532 |faq| is an exact synonym for |advise|.
533
534 The list label for the |advise| environment is |\labeladvise|.
535
536 The font is set with |\advisestyle|.
537 \end{note}
538
539 \begin{desc}
540 |\alternative{<comma list>}|
541 \end{desc}
542
543 Prints a comma-separated list delimited by vertical bars. Space around
544 commas is not trimmed, and alternates are printed in
545 |\textup{\texttt{...}}|.
546
547 This environment is from \package{lstdoc}.
548
549 \begin{LTXexample}
550 \alternative{true,false}
551 \end{LTXexample}
552
553 \begin{desc}
554 |\begin{keys}...\end{keys}|\\
555 |\key[<options>]{<key name>}[<key value>][<default value>]|\\
556 |\bool|
557 \end{desc}
558
559 Describes keys. Within a |keys| environment, |\bool| indicates a true/false
560 value. This environment is a recreation of \package{lstdoc}'s |syntax|
561 environment with a more elegant interface.
562
563 |<options>| can include:
564
565 \begin{keys}
566 \key{v}[\m{version}]
567 The version a key was introduced.
568
569 \begin{warning}
570 This key is currently ignored.
571 \end{warning}
572
573 \key{default}[\m{default value}]
574 An alias for the final argument; a default value if the key isn't
575 given.
576
577 \key{note}[\m{note}]
578 A note set in the left margin; might note a group of features or
579 something else.
580 \end{keys}
581
582 \begin{example}
583 Note the use of |\bool|:
584 \begin{LTXexample}
585 \begin{keys}
586 \key[note=addon]{key}
587 [\m{value}][default]
588 Lorem ipsum\dots
589
590 \key{display}[\bool][true]
591 Lorem ipsum\dots
592
593 \key{foo}[\m{foo}]
594 \key[v=1.3]{bar}
595 Lorem ipsum\dots
596 \end{keys}
597 \end{LTXexample}
598 \end{example}
599
600 \begin{changelog}[author=Rebecca Turner]
601 \begin{version}[v=0.1.1, date=2019-04-15]
602 \added
603 \item Renamed \cs{ltxguidex@noticestyle} to \cs{noticestyle} and committed
604 it to the public \textsc{api}.
605 \item The \cs{cs} and \cs{command} commands.
606 \end{version}
607 \end{changelog}
608
609 \end{document}