-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnostarch.dtx
3347 lines (3331 loc) · 99.7 KB
/
nostarch.dtx
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse
%
% Copyright 2008-2023, Boris Veytsman
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3 of this license or (at your option) any
% later version.
% The latest version of the license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of
% LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Boris Veytsman,
%
% This work consists of the file nostarch.dtx and the
% derived file nostarch.cls
%
% \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 \~}
%
%\iffalse
% Taken from xkeyval.dtx
%\fi
%\makeatletter
%\def\DescribeOption#1{\leavevmode\@bsphack
% \marginpar{\raggedleft\PrintDescribeOption{#1}}%
% \SpecialOptionIndex{#1}\@esphack\ignorespaces}
%\def\PrintDescribeOption#1{\strut\emph{option}\\\MacroFont #1\ }
%\def\SpecialOptionIndex#1{\@bsphack
% \index{#1\actualchar{\protect\ttfamily#1}
% (option)\encapchar usage}%
% \index{options:\levelchar#1\actualchar{\protect\ttfamily#1}\encapchar
% usage}\@esphack}
%\def\DescribeOptions#1{\leavevmode\@bsphack
% \marginpar{\raggedleft\strut\emph{options}%
% \@for\@tempa:=#1\do{%
% \\\strut\MacroFont\@tempa\SpecialOptionIndex\@tempa
% }}\@esphack\ignorespaces}
%\makeatother
%
% \MakeShortVerb{|}
% \GetFileInfo{nostarch.dtx}
% \newcommand{\progname}[1]{\textsf{#1}}
% \title{\LaTeX{} Style For \emph{No Starch Press}
% \thanks{\copyright 2008--2023, Boris Veytsman}}
% \author{Boris Veytsman\thanks{%
% \href{mailto:[email protected]}{\texttt{[email protected]}},
% \href{mailto:[email protected]}{\texttt{[email protected]}}}}
% \date{\filedate, \fileversion}
% \maketitle
% \begin{abstract}
% This package provides class for typesetting books for No Starch
% Press, \url{http://www.nostarch.com}
% \end{abstract}
% \tableofcontents
%
% \clearpage
%
% \changes{v0.1}{2008/02/27}{First fully functional version}
% \changes{v0.5}{2008/03/19}{Documentation update}
% \changes{v0.6}{2008/03/21}{Documentation update}
% \changes{v1.0}{2008/04/07}{First public release}
% \changes{v1.1}{2008/05/24}{Added interface to listings package and
% upquote package. Updated documentation}
% \changes{v1.4}{2020/04/29}{Updated interface with listings package}
% \changes{v2.0}{2023/03/30}{Incorporated in-house changes by No
% Starch Press}
%
%
%\section{Introduction}
%\label{sec:intro}
%
% This is the ``official'' \LaTeX{} style for \emph{No Starch Press,}
% \url{http://www.nostarch.com}. The class is intended to typeset
% books for this publisher---both hard copies and electronic books.
%
% The suite provides main class, |nostarch.cls|, hyperref interface
% |nshyper.sty| and MakeIndex style |nostarch.ist|.
%
% The initial version of this class was written in 2008. Since then a
% number of changes was made for in-house processing by the \emph{No
% Starch} team, with special thanks to Alex Freed. In 2023 these
% changes were incorporated back to the publicly released version.
%
%\section{User's Guide}
%\label{sec:manual}
%
%
%\subsection{Installation}
%\label{sec:installation}
%
% The installation of the class follows the usual
% practice~\cite{TeXFAQ} for \LaTeX{} packages:
% \begin{enumerate}
% \item Run \progname{latex} on |nostarch.ins|. This will produce the
% following files:
% \LaTeX{} class |nostarch.cls|, \LaTeX{} style |nshyper.sty| and
% MakeIndex style |nostarch.ist|.
% \item Put the files |nostarch.cls|, |nshypher.sty| and
% |nostarch.ist| to
% the places where \LaTeX{} and MakeIndex can find them (see
% \cite{TeXFAQ} or the documentation for your \TeX{}
% system).\label{item:install}
% \item Update the database of file names. Again, see \cite{TeXFAQ}
% or the documentation for your \TeX{} system for the system-specific
% details.\label{item:update}
% \item The file |nostarch.pdf| provides the documentation for the
% package (this is the file you are probably reading now).
% \end{enumerate}
% As an alternative to items~\ref{item:install} and~\ref{item:update}
% you can just put the files in the working directory where your
% |.tex| file is.
%
% To typeset the books in the distinctive \emph{No Starch Press} style
% you will need the fonts used by them. Unfortunately these fonts
% (New Baskerville, Futura, The Sans Mono Condensed and Dogma) are not
% free. You have the following options:
% \begin{enumerate}
% \item Typeset your book using only free fonts (the option |nocfonts|
% discussed below).
% \item Buy the fonts and install them.
% \item Arrange with \emph{No Starch Press} for the use of these fonts
% for your book.
% \end{enumerate}
% The details of the installation are discussed below in
% Section~\ref{sec:ug_fonts}.
%
%
%
%\subsection{Fonts installation}
%\label{sec:ug_fonts}
%
% If you wish to try \progname{nostarch} class without bothering to
% typeset camera-ready copy, you may use the option |nocfonts| for
% \emph{no commercial fonts,} and the class will use only the free
% fonts available in \TeX\ distributions.
%
% If you work with \emph{No Starch Press} on your book, you might be
% provided with the fonts. Today \emph{No Starch Press} typically
% uses \progname{xelatex} and expects the fonts in True~Type format.
% If this is the case, use the option |cfonts|. \emph{No Starch
% Press} recommends the authors to put the font files in the
% subdirectory \path{fonts} of their main directory. This is where
% \progname{nostarch} expects them. This is also the layout of
% directories in the \emph{No Starch Press} \emph{Overleaf}
% templates. However, if you prefer to put the fonts in another
% directory, searcheable by \progname{xelatex}, use the option
% |nofontsdir| in the invocation.
%
% These options are summarized in Figure~\ref{fig:fonts}.
%
% \begin{figure}
% \centering
% \begin{tikzpicture}
% \node[draw, circle, radius=0.1] (start) {};
% \node[draw, align=center, below=of start]
% (haveFonts) {Do you have \\commercial fonts?};
% \node[draw, left=of haveFonts, align=center] (nocfonts)
% {Use |nocfonts|\\ option};
% \node[draw, below=of nocfonts, rounded corners]
% (any) {Use any engine};
% \node[draw, right=of haveFonts, align=center] (cfonts)
% {Use |cfonts|\\option};
% \node[draw, below=of cfonts, align=center] (haveSubdir) {Are the fonts
% \\in |fonts| \\subdirectory?};
% \node[draw, left=of haveSubdir, align=center]
% (nofontsdir) {Use |nofontsdir|\\option};
% \node[draw, below=of haveSubdir, align=center] (fontsdir)
% {Use |fontsdir|\\option};
% \node[draw, below=of fontsdir, rounded corners] (xelatex)
% {Use \progname{xelatex} engine};
% \draw[-latex] (start) -- (haveFonts);
% \draw[-latex] (haveFonts) -- node[above] {No} (nocfonts);
% \draw[-latex] (haveFonts) -- node[above] {Yes} (cfonts);
% \draw[-latex] (nocfonts) -- (any);
% \draw[-latex] (cfonts) -- (haveSubdir);
% \draw[-latex] (haveSubdir) -- node[above] {No} (nofontsdir);
% \draw[-latex] (haveSubdir) -- node[right] {Yes} (fontsdir);
% \draw[-latex] (nofontsdir) |- (xelatex);
% \draw[-latex] (fontsdir) -- (xelatex);
% \end{tikzpicture}
% \caption{Flowchart for font-related options}
% \label{fig:fonts}
% \end{figure}
%
%
%\subsection{Invocation}
%\label{sec:invocation}
%
% To use the class, put in the preamble of your document
% \begin{flushleft}
% |\documentclass[|\meta{options}|]{nostarch}|
% \end{flushleft}
%
% \DescribeOptions{cfonts,nocfonts}%
% As discussed above, \emph{No Starch Press} uses a number of
% commercial fonts to typeset their books.
% The option |cfonts| (default) tells \LaTeX{} that you do have these
% commercial fonts. On the other hand, the option |nocfonts| instructs
% \LaTeX{}
% to use freely available fonts for typesetting. Of course in this
% case the result will not look like a \emph{No Starch Press} Book.
%
% \DescribeOptions{fontsdir,nofontsdir}%
% If you use commercial fonts \emph{and} \progname{xelatex}, the
% latter usually expects them in the subdirectory \path{fonts} of the
% main directory (see Section~\ref{sec:ug_fonts}). The options
% |fontsdir| (default) sets up this behavior. Use the option
% |nofontsdir| to tell \progname{xelatex} to search standard font
% directories insted.
%
% Figure~\ref{fig:fonts} may help to choose the right options.
%
%
%\subsection{Use of \progname{hyperref} Package}
%\label{sec:guide:hyperref}
%
% The books typeset by \emph{No Starch Press} can be sold either as
% traditional printed and bound hard copies, or as PDF files. If you,
% the author, envisage the second possibility, you may want additional
% possibilites provided by \progname{hyperref}
% package~\cite{Rahtz06:Hyperref}, like ``clickable'' entries in the
% table of context and index, etc. The provided package |nshyper.sty|
% adds the functionality of \progname{hyperref} to the class. This
% package is highly recommended for the books that are going to be
% distributed in an electronic form.
%
% To use the package, just add the line |\uspackage{nshyper}| to your
% preamble. This package should be loaded last since it redefines
% internals of many other packages. Note that a direct call of
% \progname{hyperref} by |\usepackage{hyperref}| will not work since
% \progname{nshyper} patches hyperref to work with our class.
%
%
%
%\subsection{Front Matter}
%\label{sec:guide:frontmatter}
%
% \DescribeMacro{\frontmatter}
% A book can be divided into three parts: front matter, main matter
% and back matter. Front matter starts with the command
% |\frontmatter|. Normally this is the first command in the class.
% Front matter contains half page, title page, copyright page, brief
% contents, detailed contents, foreword(s) and other stuff which is
% traditionally typeset on roman-numbered pages. The commands in main
% matter can be divides into \emph{declarations} and
% \emph{directives.} Declarations do not typeset anything. Rather,
% they up parameters for the typesetting. Directives use them to
% typeset the stuff.
%
%
%\subsubsection{Front Matter Declarations}
%\label{sec:guide:decls}
%
%
%
% \DescribeMacro{\title}
% There are five declarations defined by |nostarch.cls|: |\title|,
% |\subtitle|,
% |\author|, |\nostarchlogo| and |\nostarchlocation|. The macro
% |\title|, like the standard \LaTeX{} |\title|, sets the title of the
% book, for example |\title|\texttt{\{The book about everything\}}.
%
% \DescribeMacro{\subtitle}
% The macro |\subtitle| takes one argument and sets up the subtitle of
% your book, for example |\subtitle|\texttt{\{A Guide For
% Perplexed\}}.
%
% \DescribeMacro{\author}
% The command |\author| has just one argument, which is the list of
% authors, separated by commas and (for the last author) the word
% ``and''. Do not use the command |\and| defined in the standard
% \LaTeX. For example,
% |\author|\texttt{\{Ralph Alpher, Hans Bethe and George Gamow\}}.
%
% \DescribeMacro{\nostarchlogo}
% Due to copyright reasons the logo of \emph{No Starch Press} is not
% distribuded with the package. You should get the logo as a graphics
% file from the publishers and put in the directory where \LaTeX{} can
% find it (for example, the directory with the other sources of your
% book). The command |\nostarchlogo| has one argument: the name of
% the file, for example, |\nostarchlogo{biglogo.pdf}|.
% The file will be automatically scaled to the proper size.
%
% \DescribeMacro{\nostarchlocation}
% \emph{No Starch Press} books are usually published in San
% Francisco. If you need to change this setting, use
% |\nostarchlocation| declaration, for example,
% |\nostarchlocation|\texttt{\{San Francisco; London; Tokyo\}}.
%
%
%
%\subsubsection{Front Matter Directives}
%\label{sec:guide:directives}
%
%
%
% \DescribeMacro{\makehalftitle}
% The command |\makehalftitle| creates \emph{half title page.}
% This is normally the first page of the book.
%
% \DescribeMacro{\maketitle}
% The command |\maketitle| creates \emph{title page.} It uses logo
% and full title of the book.
%
% \DescribeMacro{copyrightpage}
% The copyright page is the \emph{verso} of the title page. It has
% information about copyright, edition history, the credits of the
% people who helped you to make the book, CIP information, etc. The
% exact contents of the copyright page differ from book to book.
% Therefore the class does not try to create this page automatically,
% and rather sets up the typographic style for arbitrary contents.
% For this purpose the environment |copyrigthtpage| is used. So just
% put the information provided by the publisher between
% |\begin{copyrightpage}| and |\end{copyrightpage}|. Use
% |\textbf{\sffamily title}| for the title of the book on the
% copyright line.
%
% \DescribeMacro{cipblock}
% One of important parts of the copyright page is \emph{CIP block.}
% It contains catalogue data for your book (CIP means Cataloguing in
% Publication, by the way). Again, the contents of this field will be
% provied by the publishers; you just need to put them inside
% |cipblock| environment, i.e. between |\begin{cipblock}| and
% |\end{cipblock}|. To make your life easier, this block is typeset
% verbatim, so line ends and spaces are typeset as is.
%
%
% \DescribeMacro{dedicationpage}
% Dedications, if any, are included in the special dedication page,
% for which a special environment |dedicationpage| is provided.
%
% \DescribeMacro{\brieftableofcontents}
% \DescribeMacro{\tableofcontents}
% The standard \LaTeX{} provides just one table of contents. This
% class uses two tables: brief contents and contents in detail. They
% are correspondingly typeset by the commands |\brieftableofcontents|
% and |\tableofcontents|.
%
%
% \DescribeMacro{\sectionnumberwidth}
% \DescribeMacro{\subsectionnumberwidth}
% In most books by \emph{No Starch Press} sections and subsections are
% unnumbered. However, sometimes the books use numbered sections or
% subsections. In these cases you may want to adjust the widths left
% for section and subsection numbers in the detailed table of
% contents. They are set by
% |\sectionnumberwidth| and |\subsectionnumberwidth|, and can be
% changed with the usual |\setlength| command.
%
%
% Forewords and similar front matter materials are unnumbered
% chapters: |\chapter*[Foreword by R. E.~Viewer]{Foreword}|.
%
%
% Front matter with its formal parts like copyright page, CIP
% information, etc., can be daunting, especially for novice authors.
% Feel free to use the sample enclosed and ask the publisher for
% advice.
%
%\subsection{Main Matter}
%\label{sec:guide:mainmatter}
%
% \DescribeMacro{\mainmatter}
% The command |\mainmatter| finishes the front matter and starts the
% main matter of the book. The main matter is divided into chapters,
% sections, subsections, etc. They are discussed below.
%
%
%\subsubsection{Parts, Chapters and Sections}
%\label{sec:guide:sections}
%
% \DescribeMacro{\chapter}
% \DescribeMacro{\section}
% \DescribeMacro{\subsection}
% \DescribeMacro{\subsubsection}
% \emph{No Starch Press} books have chapters, sections, subsections and
% subsubsections. The chapters are usually numbered, but sections ande
% below are not. The commands for them are the same as in the
% standard \LaTeX: |\chapter|\oarg{short title}\marg{long title},
% |\section|\oarg{short title}\marg{long title}, etc. For
% example:
% \begin{verbatim}
% \section[Building Lego Fire Track]{How To Build A Lego Fire Track
% And Why It Is Fun}
% \end{verbatim}
% The ``starred'' forms |\chapter*|, |\section*| etc. are used when
% the corresponding division has no number (like unnumbered chapters in
% the front matter). Since our sections, subsections and
% subsusbsections are unnumbered anyway, this form has meaning only
% for chapters (but can be used for other divisions as well).
%
% \DescribeMacro{\chapterart}
% \DescribeMacro{\chapterartfile}
% \emph{No Starch Press} books use ``circular art'' for chapter
% openings (except for unnumbered chapters in the front matter). The
% command |\chapterart| should be issued immediately
% after |\chapter| command and before the first paragraph. Its
% argument is the artwork used for the current chapter:
% |\chapterart|\marg{\LaTeX{} commands}. In the
% simplest case it is just inclusion of an external graphics file, for
% example:
% \begin{verbatim}
% \chapterart{\includegraphics[width=1.264in]{firetrack.jpg}}
% \end{verbatim}
% Actually, this simplest case is so ubiquitous, that there is a
% special command |\chapterartfile|\marg{filename} for it, so the
% previous example can be simplified as
% \begin{verbatim}
% \chapterartfile{firetrack.jpg}
% \end{verbatim}
% However, you can use instead any \LaTeX{} commands to produce
% the artwork. Rememer that it must be $1.264''\times1.222''$.
%
% The first paragraph after chapter start is typeset in larger size
% font than the body font. If this paragraph is too long, you may
% need to manually change the font size back in the middle of it. The
% simplest way to do this is the combination
% |\par\noindent\normalfont| in a strategic place.
%
%
% \DescribeMacro{\part}
% Sometimes larger books are separated into parts. The command
% |\part|\marg{Title} is used to typeset parts.
%
%\subsubsection{Environments}
%\label{sec:guide:lists}
%
%
% \DescribeMacro{itemize}
% \DescribeMacro{enumerate}
% \DescribeMacro{description}
% \DescribeMacro{aside}
% \DescribeMacro{note}
% \DescribeMacro{warning}
% The class offers standard |itemize|, |enumerate| and |description|
% environment. There are also special environments reserverd for
% asides. The |aside| environment has a mandatory argument: aside
% name. It typesets its contents in italics with the name in bold on
% the marginh:
% \begin{verbatim}
% \begin{aside}{Reminder}
% Do not forget to plug off the computer before doing any
% modifications!
% \end{aside}
% \end{verbatim}
% The environments |note| and |warning| are similar, but have
% pre-defined names NOTE and WARNING, e.g
% \begin{verbatim}
% \begin{note}
% Do not forget to plug off the computer before doing any
% modifications!
% \end{note}
% \begin{warning}
% Do not forget to plug off the computer before doing any
% modifications!
% \end{warning}
% \end{verbatim}
%
%
%\subsubsection{Tables and Figures}
%\label{sec:guide:floats}
%
% There are several things to keep in mind when using tables and
% figures with the class.
%
% The tables and figures are not centered. Neither are their
% captions. The captions for figures go \emph{below} the figures, the
% captions for tables go \emph{above} the tabular data.
%
% \DescribeMacro{\NextCaptionWidth}%
% The captions of tables and figures are automatically typeset with
% the same width as the table or figure. Sometimes, however, \LaTeX\
% makes a mistake in the calculation. In this case the macro
% \cs{NextCaptionWidth}\marg{length} overrides this calculation and
% sets the width of the caption for the next figure or table to
% \marg{length}, for example
% \begin{verbatim}
% \NextCaptionWidth{2in}
% \begin{figure}
% ...
% \caption{...}
% \end{figure}
% \end{verbatim}
%
%
% Typesetting tables, unfortunately, is rarely done right, and
% standard \LaTeX{} is not an exception. The authors are urged to
% read the introduction to \progname{booktabs}
% package~\cite{Fear05:Booktabs}. To summarize,
% \begin{enumerate}
% \item Never ever use vertical rules.
% \item Never ever use double rules.
% \item Use only |\toprule|, |\midrule| and |\bottomrule| for tables.
% \end{enumerate}
% \DescribeMacro{\tbfont}
% \DescribeMacro{\thfont}
% \DescribeMacro{tabular}
% \emph{No Starch Press} uses special fonts for table body and table
% header. Since there are too many tabular-like environments
% (|tabular|, |tabbing|, |longtable|, \dots) we do not redefine them
% switch on these fonts automatically, but rather provide two font
% switching commands. The command |\tbfont| should be used
% \emph{before} tabular environment, and the command |\thfont| should
% be used in all header cells. Also, usually the table entries are
% flushed left, so you might want to put |@{}| before the first column
% declaration in |\begin{tabular}| to suppress the padding on the
% left. Here is an example of a properly
% done table layout:
% \begin{verbatim}
% \begin{table}
% \caption{Starch Content of Foods}
% \label{tab:starch}
% \tbfont
% \begin{tabular}{@{}lr}
% \toprule
% \thfont Product & \thfont Starch Content, \% \\
% \midrule
% Bran (wheat) & 23.0\\
% Brown rice (raw) & 80.0\\
% Brown bread (average) & 41.3\\
% White bread (average) & 46.7\\
% \bottomrule
% \end{tabular}
% \end{table}
% \end{verbatim}
%
%
%
%\subsubsection{Code Fragments}
%\label{sec:guide:code}
%
% The class provides two facilities for including code fragments in
% the books.
%
% \DescribeMacro{Code}
% For short unformatted code fragments the \progname{fancyvrb}
% package~\cite{VanZandt98:Fancyvrb} facilities are recommended. This
% package is automatically automatically loaded by the class. Long code
% fragments should be
% separated by rules; the class defines verbatim-like |Code|
% environment, which does exactly this:
% \begin{verbatim}
% \begin{Code}
% main() {
% printf("Hello, World\n");
% }
% \end{Code}
% \end{verbatim}
% See the documentation of~\cite{VanZandt98:Fancyvrb} about many
% features of this package.
%
% For longer code fragments the \progname{listings}
% package~\cite{Heinz07:Listings} is more appropriate. It is also
% automatically loaded. This package provides a number of useful
% features, well describe in its manual. We will briefly mention
% several of them, which might be of interest for the authors of
% \emph{No Starch Press}:
% \begin{enumerate}
% \item Automatic code formatting according to the rules of the chosen
% program language (for example, |\lstset{language=C}| or
% |\lstset{language=Lisp}|).
% \item A rich set of different frames: ruled code with
% |frame=lines|, boxed code with |frame=single| etc.
% \item An option to add captions to the listings (the class
% automatically formats the captions according to the style of
% \emph{No Starch Press}).
% \item An option to make a listing floating.
% \item An option to automatically number code lines.
% \item An option to add list of listings (with the command
% |\lstlistoflistings|).
% \end{enumerate}
%
% To make the code in |\verb| commands and |verbatim|-like
% environments be typeset with the \progname{listings} package, you
% may want to set |fancyvrb=true| in the preamble of your document.
%
% It should be noted that the authors are recommended \emph{not} to
% use |\texttt| or |\tt| for inline code fragments. The proper way to
% add inline code is |\verb| or |\lstinline| from the
% \progname{listings} package. The difference is obvious, for
% example, in quote characters.
%
%
%\subsection{Boxes}
%\label{sec:ug_boxes}
%
% \DescribeEnv{nspbox}%
% You may put some information into \emph{boxes}. Boxes have a \emph{heading}
% and a \emph{text}. The environment |nspbox| can be used to typeset
% them, for example:
% \begin{verbatim}
% \begin{nspbox}{This is a heading}
% This is a text for the box.
% \end{nspbox}
% \end{verbatim}
%
%\subsection{Back Matter}
%\label{sec:guide:backmatter}
%
% \DescribeMacro{\backmatter}
% Back matter includes bibliography, index, update page, colophon and
% other material. It starts with the command |\backmatter|.
%
%
%
%\subsubsection{Bibliography}
%\label{sec:guide:bibliography}
%
% \emph{No Starch Press} at present has no special style for
% bibliography, so the authors have a relative freedom to choose one.
% However, it would be a good idea to use the \progname{natbib}
% package~\cite{Daly07:Natbib}. This class should work with
% \progname{natbib}.
%
% No support for per chapter bibliography lists is provided by the
% package.
%
%
%\subsubsection{Index}
%\label{sec:guide:index}
%
% The books published by \emph{No Starch Press} usually have index.
% This package provides special style file |nostarch.ist| for index
% formatting.
%
%
% \DescribeMacro{\makeindex}
% \DescribeMacro{\printindex}
% To create index:
% \begin{enumerate}
%
% \item Put in the preamble of your
% document the command |\makeindex|.
% \item In the body of your document use |\index| commands as
% described in~\cite{Lamport94}.
% \item Put in the Back Matter the command |\printindex| at the place
% you want the index to be printed.
% \item After a \progname{latex} run \progname{makeindex} with the
% style |nostarch.ist|. In a Unix system the corresponding command is
% \begin{verbatim}
% makeindex -s nostarch.ist mydocument
% \end{verbatim}
% or, in a more verbose way
% \begin{verbatim}
% makeindex -s nostarch.ist -o mydocument.ind mydocument.idx
% \end{verbatim}
% (here we assume that your main file is |mydocument.tex|).
%
% Refer to the documentation of your \TeX{} system for the way to run
% \progname{makeindex} on your computer.
% \end{enumerate}
%
%
%\subsubsection{Updates and Colophon}
%\label{sec:guide:updates}
%
% \DescribeMacro{\updatespage}
% \emph{No Starch Press} books usually have updates page, which lists
% the Web address for updates, errata, etc. The command
% |\updatespage| starts such page. You are free to choose any text
% there. Note that if you use the package
% \progname{nshypher}~\ref{sec:guide:hyperref}, then the command
% |\url|\marg{URL} becomes a hyperlink in the electronic edition.
%
%
% \DescribeMacro{\colophon}
% The last part of Back Matter is usually a \emph{colophon} which
% describes how the book was printed and typeset. The command
% |\colophon| starts this part and prints some standard information
% about your fonts and \LaTeX{} package. You may want to add some
% information after this command.
%
%
% \StopEventually{%
% \clearpage
% \bibliography{nostarch}
% \bibliographystyle{unsrt}}
%
% \clearpage
%
%
%\section{Implementation}
%\label{sec:impl}
%
%\subsection{Identification}
%\label{sec:ident}
%
% We start with the declaration who we are. Most |.dtx| files put
% driver code in a separate driver file |.drv|. We roll this code into the
% main file, and use the pseudo-guard |<gobble>| for it.
% \begin{macrocode}
%<class>\NeedsTeXFormat{LaTeX2e}
%<*gobble>
\ProvidesFile{nostarch.dtx}
%</gobble>
%<class>\ProvidesClass{nostarch}
%<nshyper>\ProvidesPackage{nshyper}
%<*!ist>
[2023/07/19 v2.4 Typesetting books for No Starch Press]
%</!ist>
% \end{macrocode}
%
% And the driver code:
% \begin{macrocode}
%<*gobble>
\documentclass{ltxdoc}
\usepackage{array}
\usepackage{url,amsfonts, tikz}
\usepackage[breaklinks,colorlinks,linkcolor=black,citecolor=black,
pagecolor=black,urlcolor=black,hyperindex=false]{hyperref}
\usetikzlibrary{positioning}
\PageIndex
\CodelineIndex
\RecordChanges
\EnableCrossrefs
\begin{document}
\DocInput{nostarch.dtx}
\end{document}
%</gobble>
%<*class>
% \end{macrocode}
%
%
%\subsection{Options}
%\label{sec:options}
%
%\begin{macro}{\ifnostarch@cfonts}
% First, let us decide whether we have non-free fonts:
% \begin{macrocode}
\newif\ifnostarch@cfonts
\nostarch@cfontstrue
\DeclareOption{cfonts}{\nostarch@cfontstrue}
\DeclareOption{nocfonts}{\nostarch@cfontsfalse}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifnostarch@fontsdir}
% \changes{v2.0}{2023/03/31}{Introduced macro}
% We also need to check whether we want to use \emph{No Starch} in
% house |fonts| directory
% \begin{macrocode}
\newif\ifnostarch@fontsdir
\nostarch@fontsdirtrue
\DeclareOption{fontsdir}{\nostarch@fontsdirtrue}
\DeclareOption{nofontsdir}{\nostarch@fontsdirfalse}
% \end{macrocode}
% \end{macro}
%
% The size-changing options produce a warning:
% \begin{macrocode}
\long\def\nostarch@size@warning#1{%
\ClassWarning{nostarch}{Size-changing option #1 will not be
honored}}%
\DeclareOption{8pt}{\nostarch@size@warning{\CurrentOption}}%
\DeclareOption{9pt}{\nostarch@size@warning{\CurrentOption}}%
\DeclareOption{10pt}{\nostarch@size@warning{\CurrentOption}}%
\DeclareOption{11pt}{\nostarch@size@warning{\CurrentOption}}%
\DeclareOption{12pt}{\nostarch@size@warning{\CurrentOption}}%
% \end{macrocode}
%
%
%
% All other options are passed to \progname{book}:
% \begin{macrocode}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
% \end{macrocode}
%
% Now we read the configuration file
% \begin{macrocode}
\InputIfFileExists{nostarch.cfg}{%
\ClassInfo{nostarch}{%
Loading configuration file nostarch.cfg}}{%
\ClassInfo{nostarch}{%
Configuration file nostarch.cfg is not found}}
% \end{macrocode}
% And process the options:
% \begin{macrocode}
\ProcessOptions\relax
% \end{macrocode}
%
%
%
%
%
%\subsection{Loading Class and Packages}
%\label{sec:loading}
%
% We start with the base class
% \begin{macrocode}
\LoadClass[10pt]{book}
% \end{macrocode}
%
% A bunch of packages:
% \begin{macrocode}
\RequirePackage[table]{xcolor}
\RequirePackage{iftex, ifpdf, longtable,
fancyhdr, fancyvrb, booktabs, graphicx,
listings, caption, makeidx, upquote, pifont,
textcomp, xcolor, lmodern, nameref, float, amssymb, etoolbox,
setspace, marginnote, url, subfigure}
\RequirePackage[framemethod=TikZ]{mdframed}
\RequirePackage{soul}
\RequirePackage[T1]{fontenc}
\RequirePackage{ragged2e}
% \end{macrocode}
%
% We do not want the option |document| with \progname{ragged2e}: this
% calls \progname{footmisc}, while we want our own footnotes:
% \begin{macrocode}
\RequirePackage{ragged2e}
\setlength\RaggedRightParindent{\parindent}
\RaggedRight
% \end{macrocode}
%
%
% \begin{macro}{\@nschapterpreamble}
% This is the preamble to bibliography and index commands used when
% \progname{nshyper} is loaded. Normally it is empty.
% \begin{macrocode}
\def\@nschapterpreamble{}
% \end{macrocode}
%
% \end{macro}
%
%
%\subsection{Fonts}
%\label{sec:fonts}
%
% \begin{macro}{\nostarch@fontspath}
% \changes{v2.0}{2023/03/31}{Introduced macro}
% The path to load fonts
% \begin{macrocode}
\ifnostarch@fontsdir
\def\nostarch@fontspath#1{Path=fonts/#1/,}
\else
\def\nostarch@fontspath#1{Path,}
\fi
% \end{macrocode}
% \end{macro}
%
% If we have commercial fonts, we load them.
% \begin{macrocode}
\ifnostarch@cfonts
\ifpdftex
\ClassWarning{nostarch}{Commercial fonts usually require xelatex engine}
\RequirePackage{nbaskerv}%
\RequirePackage{futurans}%
\RequirePackage[scaled=0.85]{thsmc}%
\RequirePackage{dogma}%
\newcommand{\dogma}{\fontfamily{fdg}\selectfont}%
\else %XeTeX or LuaTeX
\RequirePackage{fontspec}
\newfontface\dogma[
\nostarch@fontspath{dogma}
UprightFont=dogmab01.ttf,
Ligatures=TeX
]{dogma} % Font used for chapter titles
\newfontface\timesnewroman[
\nostarch@fontspath{tnr}
UprightFont=times.ttf,
BoldFont=timesbd.ttf,
ItalicFont=timesi.ttf,
BoldItalicFont=timesbi.ttf,
Ligatures=TeX
]{timesnewroman}
\newfontface\futurabook[
\nostarch@fontspath{futurans}
UprightFont=FuturB37.ttf,
BoldFont=FuturH79.ttf,
ItalicFont=FutuBO08.ttf,
BoldItalicFont=FutCBO63.ttf,
Ligatures=TeX
]{futurabook}
\newfontface\futuraheavy[
\nostarch@fontspath{futurans}
UprightFont=FuturH79.ttf,
Ligatures=TeX
]{futuraheavy}
\newfontface\futuraboldc[
\nostarch@fontspath{futurans}
UprightFont=futucb18.ttf,
Ligatures=TeX
]{futuraboldc}
\newfontface\futuraboldcoblique[
\nostarch@fontspath{futurans}
UprightFont=FutCBO63.ttf,
Ligatures=TeX
]{futuraboldcoblique}
\newfontface\futuraoblique[
\nostarch@fontspath{futurans}
UprightFont=FutuBO08.ttf,
Ligatures=TeX
]{futuraoblique}
\setmainfont{nbaskerv}[
\nostarch@fontspath{nbaskerv}
UprightFont=NewBaskervilleEF-Roman.ttf,
BoldFont=NewBaskervilleEF-Bold.ttf,
ItalicFont=NewBaskervilleEF-RomanIta.ttf,
BoldItalicFont=NewBaskervilleEF-BoldIta.ttf,
Ligatures=TeX]
\setmonofont[Scale=0.85,
\nostarch@fontspath{thsmc}
UprightFont=ThSMCP25.ttf,
BoldFont=ThSMCB02.ttf,
ItalicFont=ThSMCI29.ttf,
BoldItalicFont=TSMCBI56.ttf]{thsmc}
\setsansfont[
\nostarch@fontspath{futurans}
UprightFont=futura.ttf,
BoldFont=FuturB41.ttf,
ItalicFont=FutuBO08.ttf,
BoldItalicFont=FutCBO63.ttf,
Ligatures=TeX
]{futurans}
\fi
% \end{macrocode}
% Otherwise we just use sans serif font for dogma.
% \begin{macrocode}
\else
\newcommand{\dgdefault}{\sfdefault}%
\fi
% \end{macrocode}
%
% A number of commands to provide font defaults in case we use
% non-commercial fonts
% \begin{macrocode}
\providecommand{\dogma}{\fontfamily{dgdefault}\selectfont}
\providecommand{\futuraboldc}{\fontfamily{\sfdefault}\fontseries{bc}%
\selectfont}
\providecommand{\futuraboldcoblique}{\fontfamily{\sfdefault}\fontseries{bc}%
\itshape\selectfont}
\providecommand{\futuraheavy}{\fontfamily{\sfdefault}\fontseries{hq}%
\selectfont}
\providecommand{\futurabook}{\fontfamily{\sfdefault}\fontseries{k}%
\selectfont}
% \end{macrocode}
%
% And switch to normal size---just in case
% \begin{macrocode}
\normalsize
% \end{macrocode}
%
% Special commands for number balls
% \begin{macro}{\wingding}
% \changes{v2.0}{2023/03/31}{Introduced macro}
% The number ball
% \begin{macrocode}
\newcommand{\wingding}[1]{\ding{\the\numexpr #1 + 181 \relax}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\codewingding}
% \changes{v2.0}{2023/03/31}{Introduced macro}
% The number ball inside code
% \begin{macrocode}
\newcommand{\codewingding}[1]{\vbox{\llap{\wingding{#1}\hskip 0.5em}}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\menuarrow}
% \changes{v2.0}{2023/04/08}{Introduced macro}
% \begin{macrocode}
\newcommand\menuarrow{\raisebox{.2ex}{\small $\blacktriangleright$}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\bettertilde}
% \changes{v2.0}{2023/04/04}{Introduced macro}
% A tilde uses for some texts
% \begin{macrocode}
\newcommand{\bettertilde}{\raisebox{-1ex}{\textasciitilde}}