Debian Codegraph @

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

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %
3 % Documentation for the panda package
4 % A package to estimate the blackness of fonts
5 % Maintained by samcarter
6 %
7 % Project repository and bug tracker:
8 % https://github.com/samcarter/panda
9 %
10 % Released under the LaTeX Project Public License v1.3c or later
11 % See https://www.latex-project.org/lppl.txt
12 %
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 % arara: latexmk
15 \documentclass{scrartcl}
16
17 \usepackage[
18 themecolor=samdgray
19 ]{\jobname-settings}
20
21 % meta %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 \title{The panda package}
23 \subtitle{Estimating the blackness of fonts}
24 \author{%
25 \texorpdfstring{
26 \begin{tikzpicture}
27 \colorlet{black}{samdgray}
28 \panda
29 \end{tikzpicture}\\[0.8em]
30 \texttt{samcarter}\\
31 \url{https://github.com/samcarter/panda}\\
32 \url{https://ctan.org/pkg/panda}
33 }{samcarter}}
34 \date{Version v0.3 \textendash{} 2026/02/12}
35 \packagename{panda}
36
37 \usepackage{panda}
38 \usepackage{tikzlings}
39 \usepackage{tabularray}
40 \UseTblrLibrary{counter}
41 \newlength{\IHeight}
42 \NewTblrTheme{naked}{
43 \DefTblrTemplate{foot}{empty}{}
44 \SetTblrTemplate{foot}{empty}
45 \DefTblrTemplate{head}{empty}{}
46 \SetTblrTemplate{head}{empty}
47 }
48
49 \newcommand{\badbamboo}[2]{%
50 \rule{#1}{#2}\,\rule{#1}{#2}\,\rule{#1}{#2}%
51 }
52
53 \newcommand{\cleverbamboo}{%
54 \rule{ \CleverPanda{} }{ \fontcharht\font`I }%
55 }
56
57 \newcommand{\busybamboo}{%
58 \rule{ \BusyPanda{0.125}\fontcharht\font`I }{ \fontcharht\font`I }%
59 }
60
61 \newcommand{\tikzbamboo}{%
62 \setlength{\IHeight}{\fontcharht\font`I}%
63 \CleverPandaSet
64 \begin{tikzpicture}[baseline]
65 \draw[line width=\CleverPandaGet{}] (0,0) -- (0,\IHeight);
66 \end{tikzpicture}%
67 }
68
69 \begin{document}
70 \maketitle
71
72 \section{Introduction}
73 \label{intro}
74
75 Imagine the following problem:
76 there is a hungry panda sitting next to you and just today, you happen to not have any bamboo with you.
77 Now you are a \LaTeX\ user and the only limits are your own imagination, so of course you try to draw a couple of bamboo sticks with \LaTeX.
78 Here dear panda, have three bamboo sticks: \badbamboo{0.8pt}{\fontcharht\font`I}\,.
79 The panda likes them and wants to make more.
80 {\fontfamily{ugq}\selectfont However the panda uses a different font and the bamboo sticks suddenly look a lot less tasty, they look just too thin: \badbamboo{0.8pt}{\fontcharht\font`I}\,.}
81
82 The panda package provides estimates for the stroke width of fonts and how black the fonts look on the page.
83 Creators of symbols etc.\ can use these estimates to adjust their drawings to better blend in with the surrounding text.
84
85 {\fontfamily{ugq}\selectfont Yummy bamboo sticks: \busybamboo\,\busybamboo\,\busybamboo}
86
87 The results won't be a perfect match for all fonts and strokes can also look differently compared to the surrounding text depending on the PDF viewer and zoom level, but the results should be good enough to ensure that the symbols don't stand out immediately.
88
89 Note that this package was developed and tested with texts in Latin scripts -- results might be less satisfactory if used with other scripts.
90
91 \blurb
92
93 \section{Clever Panda}
94
95 The Clever Panda approach is inspired by a brilliant answer by @Skillmon\footnote{see \url{https://topanswers.xyz/tex?q=8139\#a7747}}, which uses the difference between the height of a full stop and 1\,pt to estimate a proxy for the stroke width of the current font.
96
97 The Clever Panda uses a simpler approach of directly employing a fraction of the full stop height and combines this with a manually curated list of exceptions.
98
99 Compared to the Busy Panda approach, described in the next section, this approach should be faster and isn't limited to what fonts are in a look-up table.
100
101 \subsection{Usage (simple case)}
102
103 After loading the package, the command \saminline|\CleverPanda{}| will expand to a length, which can be used as stroke width for drawing symbols etc.
104 \begin{tcolorbox}[title={Basic usage}]
105 \begin{samcode}
106 \documentclass{article}
107 \usepackage{CleverPanda}
108 \begin{document}
109 cmr: \rule{ \CleverPanda{} }{8pt}
110
111 \fontfamily{ugq}\selectfont
112 ugq: \rule{ \CleverPanda{} }{8pt}
113 \end{document}
114 \end{samcode}
115 \tcblower
116 \raggedright
117 cmr: \rule{\CleverPanda{}}{8pt}
118
119 \fontfamily{ugq}\selectfont
120 ugq: \rule{\CleverPanda{}}{8pt}
121 \end{tcolorbox}
122
123 There are two options for customisation: the \saminline|scale=...| package option sets a default scaling value.
124 For example, \saminline|scale=10| means that \saminline|\CleverPanda{}| returns a length ten times as long as it normally would.
125 The scaling factor can also be set locally in the mandatory argument, e.g.\ \saminline|\CleverPanda{42}|.
126 \begin{tcolorbox}[title={Options}]
127 \begin{samcode}
128 \documentclass{article}
129 \usepackage[scale=10]{CleverPanda}
130 \begin{document}
131 cmr: \rule{ \CleverPanda{} }{8pt}
132
133 cmr: \rule{ \CleverPanda{42} }{8pt}
134 \end{document}
135 \end{samcode}
136 \tcblower
137 \raggedright
138 cmr: \rule{\CleverPanda{10}}{8pt}
139
140 cmr: \rule{\CleverPanda{42}}{8pt}
141 \end{tcolorbox}
142
143 \subsection{Special Case (\TikZ)}
144
145 The \saminline|\CleverPanda{}| command works well, as long as the height of the full stop is available when the macro is used.
146 Unfortunately, that's not always the case.
147
148 One notable problem case are \TikZ\ options, e.g.\ while setting line widths.
149 As a workaround, one can use the command \saminline|\CleverPandaSet| before the \TikZ\ picture and then \saminline|\CleverPandaGet{}| in the \TikZ\ options to access the stroke width:
150 \begin{tcolorbox}[title={\TikZ}]
151 \begin{samcode}
152 \documentclass{article}
153 \usepackage{CleverPanda}
154 \usepackage{tikz}
155 \newlength{\IHeight}
156
157 \newcommand{\tikzbamboo}{%
158 \setlength{\IHeight}{\fontcharht\font`I}%
159 \CleverPandaSet
160 \begin{tikzpicture}[baseline]
161 \draw[line width=\CleverPandaGet{}]
162 (0,0) -- (0,\IHeight);
163 \end{tikzpicture}%
164 }
165
166 \begin{document}
167 cmr: \tikzbamboo
168
169 \fontfamily{ugq}\selectfont
170 ugq: \tikzbamboo
171 \end{document}
172 \end{samcode}
173 \tcblower
174 \raggedright
175 cmr: \tikzbamboo
176
177 \fontfamily{ugq}\selectfont
178 ugq: \tikzbamboo
179 \end{tcolorbox}
180
181 \clearpage
182 \section{Busy Panda}
183
184 The approach of the Busy Panda is different.
185 To get an estimate of how black text in a particular font looks like, the Busy Panda uses a sample PDF with:
186 \begin{center}
187 \ttfamily Lorem ipsum dolor sit amet, consectetur adip
188 \end{center}
189 After converting the PDF into a pixel graphic, the average blackness of the pixels can be calculated.
190 After repeating this for different fonts (including their bold versions), the Busy Panda now contains a look-up table with the average blackness for about 8800 fonts, normalised to the average blackness of Computer Modern Roman.
191 Tests with different sample texts and image resolutions indicate that the error of this method is about 10\%.
192 While not perfect, this is usually accurate enough to make symbols blend in with the surrounding text.
193
194 Compared to the Clever Panda approach from the previous section, this approach gives more accurate results, in particular for very heavy fonts, and is more versatile to use.
195
196 \subsection{Usage}
197
198 The basic usage is simple: after loading the package, the command \saminline|\BusyPanda{}| provides a normalised estimate of the blackness of the current font:
199 \begin{tcolorbox}[title={Basic usage}]
200 \begin{samcode}
201 \documentclass{article}
202 \usepackage{BusyPanda}
203 \begin{document}
204 cmr: \BusyPanda{}
205
206 \fontfamily{ugq}\selectfont
207 ugq: \BusyPanda{}
208 \end{document}
209 \end{samcode}
210 \tcblower
211 \raggedright
212 cmr: \BusyPanda{}
213
214 \fontfamily{ugq}\selectfont
215 ugq: \BusyPanda{}
216 \end{tcolorbox}
217
218 There are two options for customisation: the \saminline|scale=...| package option sets a default scaling value.
219 For example, \saminline|scale=10| means that \saminline|\BusyPanda{}| no longer returns 1 for Computer Modern Roman, but 10.
220 The scaling factor can also be set locally in the mandatory argument, e.g.\ \saminline|\BusyPanda{42}|.
221 \begin{tcolorbox}[title={Options}]
222 \begin{samcode}
223 \documentclass{article}
224 \usepackage[scale=10]{BusyPanda}
225 \begin{document}
226 cmr: \BusyPanda{}
227
228 cmr: \BusyPanda{42}
229 \end{document}
230 \end{samcode}
231 \tcblower
232 \raggedright
233 cmr: \BusyPanda{10}
234
235 cmr: \BusyPanda{42}
236 \end{tcolorbox}
237
238 \subsection{Creating symbols}
239
240 There is still a hungry panda sitting next to you, so let's create some extra yummy bamboo sticks:
241 \begin{tcolorbox}[title={Feeding the panda}]
242 \begin{samcode}
243 \documentclass{article}
244 \usepackage{BusyPanda}
245 \newlength{\IHeight}
246
247 \newcommand{\bamboo}{%
248 \setlength{\IHeight}{\fontcharht\font`I}%
249 \rule{%
250 \BusyPanda{0.125}\IHeight
251 }{%
252 \IHeight
253 }%
254 }
255
256 \begin{document}
257 Normal bamboo: \bamboo
258
259 \fontfamily{ugq}\selectfont
260 Extra yummy bamboo: \bamboo
261 \end{document}
262 \end{samcode}
263 \tcblower
264 \raggedright
265 Normal bamboo: \busybamboo
266
267 \fontfamily{ugq}\selectfont
268 Extra yummy bamboo: \busybamboo
269 \end{tcolorbox}
270
271 In the example above, \saminline|\BusyPanda{}| is used in combination with the height of the letter I.
272 This ensures that the stroke width will scale with the size of the text.
273
274 \subsection{Unsupported fonts}
275
276 Given the seemingly infinite number of fonts out there, this package will never be able to support them all -- but more can be added with your help!
277
278 If the font you are using isn't yet supported, then please get the test document from:
279
280 \url{https://github.com/samcarter/panda/blob/main/BusyPanda_unsupportedFonts.tex}
281
282 You only need to change the font name in the second line and compile with either \saminline|pdflatex| or \saminline|lualatex|.
283 Then open an issue at \url{https://github.com/samcarter/panda/issues} and upload the compiled PDF there.
284
285 How to know if your font is unsupported? \saminline|\BusyPanda{}| will return the same value as for Computer Modern Roman (1) and, if compiled with \LuaLaTeX\, a warning can be found in the .log file. Furthermore, the package option \saminline|unknown error| can be used to enable an error for all engines.
286
287 \clearpage
288 \section{Examples}
289
290 \ExplSyntaxOn
291
292 \clist_const:Nn \c_fonts_clist {
293 %<*fontlist>
294 AccanthisADFStdNoThree-LF, Alegreya-OsF, Alegreya-TLF, AnonymousPro, antp, antt, anttc, anttl, anttlc, artemisia, augie, auncl, bch, bodoni, Cabin-TLF, Caladea-TLF, cantarell-OsF, ccr, Cinzel-LF, CinzelDecorative-LF, ClearSans-TLF, clm, clmd, clmqs, clms, clmt, clmv, cmbr, cmdh, cmin, cmr, cmss, cmtt, cmvtt, comfortaa, Crlt-TLF, cyklop, DejaVuSans-TLF, DejaVuSansMono-TLF, DejaVuSerif-TLF, droidsans, droidsansmono, droidserif, EBGaramond-OsF, erewhon-OsF, fav, fbb-LF, FiraSans-TLF, frc, fve, fvm, fvs, GilliusADF-LF, GilliusADFNoTwo-LF, Heuristica-TLF, iwona, iwonac, iwonal, iwonalc, jkp, jkp, jkpl, jkpss, jkpss, jkptt, jkpx, kurier, kurierc, kurierl, kurierlc, lato-OsF, Lbstr-LF, LibreBskvl-LF, LibreCsln-TLF, LinuxBiolinumT-OsF, LinuxLibertineDisplayT-OsF, LinuxLibertineMonoT-TLF, LinuxLibertineT-OsF, lmr, lmss, lmtt, lmvtt, Merriwthr-OsF, MerriwthrSans-TLF, MintSpirit-LF, nanumgt, nanummj, neohellenic, opensans-TLF, Ovrlck-LF, Ovrlck-LF, pag, pbk, pcr, phv, PlyfrDisplay-OsF, pnc, ppl, ptm, PTMono-TLF, PTSans-TLF, PTSansCaption-TLF, PTSansNarrow-TLF, PTSerif-TLF, PTSerifCaption-TLF, put, pzc, qag, qbk, qcr, qcs, qhv, qhvc, qpl, qtm, Quattro-LF, QuattroSans-LF, Roboto-TLF, RobotoSlab-TLF, SourceCodePro-TLF, SourceSansPro-TLF, sqrc, stix, ua1, uaq, udidot, ugm, ugq, ul9, ulg, UniversalisADFStd-LF, ybd, ybv, yes, yfrak, yly, yrd, yv1, yv1d, yv2, yv3, yvo, yvod, yvt, yvtd, zgmx, zi4%
295 %</fontlist>
296 }
297
298 % from https://tex.stackexchange.com/a/728458/36296
299 \tl_new:N \l_panda_tblr_spec_tl
300 \cs_new:Npn \__panda_tblr_gen:n #1 { \clist_item:Nn \c_fonts_clist { #1 } & & \\}
301 \tl_set:Ne \l_panda_tblr_spec_tl { \int_step_function:nN {143} \__panda_tblr_gen:n }
302 \SetTblrOuter[longtblr]{expand=\l_panda_tblr_spec_tl}
303 \begin{longtblr}[theme=naked]{
304 colspec={@{}Xll@{}},
305 hline{1,2,Z}={0.7pt},
306 row{2-Z}={font=\fontfamily{\clist_item:Nn \c_fonts_clist {\therownum-1}}\selectfont},
307 cell{2-Z}{2}={cmd={Lorem~\cleverbamboo\space Lipsum}},
308 cell{2-Z}{3}={cmd={Lorem~\busybamboo\space Lipsum}},
309 rowhead = 1
310 }
311 Font~Family & Clever~Panda & Busy~Panda\\
312 \l_panda_tblr_spec_tl
313 \end{longtblr}
314
315 \ExplSyntaxOff
316
317 \end{document}