Debian Codegraph @

texmf-dist/source/latex/pxpic/pxpic.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: pxpic.dtx Copyright (C) 2021-2023 Jonathan P. Spratte
4 %
5 % This work may be distributed and/or modified under the conditions of the
6 % LaTeX Project Public License (LPPL), either version 1.3c of this license or
7 % (at your option) any later version. The latest version of this license is in
8 % the file:
9 %
10 % http://www.latex-project.org/lppl.txt
11 %
12 % ------------------------------------------------------------------------------
13 %
14 %<*driver>^^A>>=
15 \def\nameofplainTeX{plain}
16 \ifx\fmtname\nameofplainTeX\else
17 \expandafter\begingroup
18 \fi
19 \input l3docstrip.tex
20 \askforoverwritefalse
21 \preamble
22
23 --------------------------------------------------------------
24 pxpic -- draw pixel pictures
25 E-mail: [email protected]
26 Released under the LaTeX Project Public License v1.3c or later
27 See http://www.latex-project.org/lppl.txt
28 --------------------------------------------------------------
29
30 Copyright (C) 2021-2023 Jonathan P. Spratte
31
32 This work may be distributed and/or modified under the conditions of the
33 LaTeX Project Public License (LPPL), either version 1.3c of this license or
34 (at your option) any later version. The latest version of this license is in
35 the file:
36
37 http://www.latex-project.org/lppl.txt
38
39 This work is "maintained" (as per LPPL maintenance status) by
40 Jonathan P. Spratte.
41
42 This work consists of the file pxpic.dtx
43 and the derived files pxpic.pdf
44 pxpic.sty
45
46 \endpreamble
47 % stop docstrip adding \endinput
48 \postamble
49 \endpostamble
50 \generate{\file{pxpic.sty}{\from{pxpic.dtx}{pkg}}}
51 \ifx\fmtname\nameofplainTeX
52 \expandafter\endbatchfile
53 \else
54 \expandafter\endgroup
55 \fi
56 %
57 \ProvidesFile{pxpic.dtx}[2023-08-16 v1.5 draw pixel pictures]
58 \PassOptionsToPackage{full}{textcomp}
59 \documentclass{l3doc}
60 \RequirePackage[oldstylenums,nott]{kpfonts}
61 \usepackage{pxpic}
62 \usepackage{hologo}
63 \input{glyphtounicode}
64 \pdfgentounicode=1
65 \RequirePackage{listings}
66 \RequirePackage{booktabs}
67 \RequirePackage{array}
68 \RequirePackage{collcell}
69 \RequirePackage{xcolor}
70 \RequirePackage{caption}
71 \RequirePackage{microtype}
72 \RequirePackage{accsupp}
73 \RequirePackage{enumitem}
74 \lstset
75 {
76 ,flexiblecolumns=false
77 ,basewidth=.53em
78 ,gobble=2
79 ,basicstyle=\fontfamily{txtt}\selectfont
80 ,morekeywords=^^A
81 {^^A
82 \pxpic,\pxpicsetup,\pxpicnewmode,\pxpicsetmode,\pxpicnewcolorlist,
83 \pxpicsetcolorlist,\pxpicaddcolorlist,\pxpicforget,\px,\pxskip,\pxpicHT,
84 \pxpicWD,\pxpiclogo
85 }
86 ,morecomment=[l]\%
87 ,commentstyle=\color[gray]{0.4}
88 ,literate={\{}{{\CodeSymbol\{}}{1}
89 {\}}{{\CodeSymbol\}}}{1}
90 ^^A,literate=*{<key>}{\key}{4}{<set>}{\set}{4}
91 }
92 \newcommand*\CodeSymbol[1]{\textbf{#1}}
93 \RequirePackage{randtext}
94 \let\metaORIG\meta
95 \protected\def\meta #1{\texttt{\metaORIG{#1}}}
96 \newcommand*\CS{\cs[no-index]}
97 \renewcommand*\thefootnote{\fnsymbol{footnote}}
98 \definecolor{pxpicred}{HTML}{9F393D}
99 \colorlet{pxpicgrey}{black!75}
100 \makeatletter
101 \newcommand*\pxpicname
102 {^^A
103 \texorpdfstring
104 {^^A
105 \mbox
106 {^^A
107 \BeginAccSupp{ActualText=pxpic}^^A
108 \href{https://github.com/Skillmon/ltx_pxpic}{\pxpiclogo}^^A
109 \EndAccSupp{}^^A
110 }^^A
111 }
112 {pxpic}^^A
113 }
114 \definecolor{expkvred}{HTML}{9F393D}
115 \colorlet{expkvgrey}{black!75}
116 \newcommand*\expkv
117 {^^A
118 \texorpdfstring
119 {^^A
120 \mbox
121 {^^A
122 \BeginAccSupp{ActualText=expkv}^^A
123 \href{https://github.com/Skillmon/tex_expkv}
124 {^^A
125 \rmfamily
126 \bfseries
127 {\color{expkvgrey}e\kern-.05em x\kern-.05em}^^A
128 \lower.493ex
129 \hbox{{\color{expkvgrey}P}\kern-.1em{\color{expkvred}k}}^^A
130 \kern-.18em{\color{expkvred}v}^^A
131 }^^A
132 \EndAccSupp{}^^A
133 }^^A
134 }
135 {expkv}^^A
136 }
137 \hypersetup{linkcolor=red!80!black,urlcolor=purple!80!black}
138 \DoNotIndex{\advance}
139 \DoNotIndex{\baselineskip,\begingroup,\bgroup,\box}
140 \DoNotIndex{\csname}
141 \DoNotIndex{\def,\detokenize,\dimexpr}
142 \DoNotIndex{\edef,\egroup,\ekvdef,\ekvdefNoVal,\ekvifdefinedNoVal,\ekvletkv}
143 \DoNotIndex{\ekvparse,\ekvsetdef,\ekvcompile,\ekvmorekv}
144 \DoNotIndex{\endcsname,\endgroup,\expandafter}
145 \DoNotIndex{\hbox,\hskip,\ht}
146 \DoNotIndex{\iffalse,\fi}
147 \DoNotIndex{\kern}
148 \DoNotIndex{\leavevmode,\let,\long,\lower}
149 \DoNotIndex{\newcommand,\newdimen}
150 \DoNotIndex{\PackageError,\protected,\ProvidesPackage}
151 \DoNotIndex{\relax,\RequirePackage}
152 \DoNotIndex{\setbox}
153 \DoNotIndex{\@declaredcolor,\@empty,\@firstofone,\@gobble,\@ifdefinable}
154 \DoNotIndex{\@ifnextchar,\@ifundefined,\@undeclaredcolor}
155 \DoNotIndex{\ekv@ifempty,\ekv@name,\p@,\z@}
156 \DoNotIndex{\unexpanded}
157 \DoNotIndex{\vbox,\vrule,\vtop}
158 \@ifdefinable\gobbledocstriptag{\def\gobbledocstriptag#1>{}}
159 \makeatother
160 \newenvironment{options}[1][]
161 {%
162 \begin{description}
163 [
164 style=nextline
165 ,font=\normalfont\ttfamily
166 ,labelindent=-.5\marginparwidth
167 ,labelwidth=\dimexpr.5\marginparwidth-5pt\relax
168 ,labelsep*=5pt
169 ,leftmargin=!
170 ,#1
171 ]%
172 \renewenvironment{options}[1][]
173 {%
174 \begin{description}
175 [
176 style=nextline
177 ,font=\normalfont\ttfamily
178 ,labelwidth=\dimexpr.25\marginparwidth-5pt\relax
179 ,labelsep*=5pt
180 ,leftmargin=!
181 ,#1
182 ]%
183 }
184 {\end{description}}%
185 }
186 {\end{description}}
187 ^^A the following pixelart logo is taken from that package's dtx.
188 \newcommand*\pixelart
189 {^^A
190 \leavevmode
191 \pxpic[mode=px,colours={M=black},skip=.,size=.15ex]
192 {
193 {MMMMMM...MM...................MMM.....M...............M}
194 {.MM..MM..MM....................MM....MMM.............MM}
195 {.MM..MM........................MM...MM.MM............MM}
196 {.MM..MM.MMM..MM....MM..MMMMM...MM..MM...MM.MM.MMM..MMMMMM}
197 {.MMMMM...MM...MM..MM..MM...MM..MM..MM...MM..MMM.MM...MM}
198 {.MM......MM....MMMM...MMMMMMM..MM..MMMMMMM..MM..MM...MM}
199 {.MM......MM.....MM....MM.......MM..MM...MM..MM.......MM}
200 {.MM......MM....MMMM...MM.......MM..MM...MM..MM.......MM}
201 {.MM......MM...MM..MM..MM...MM..MM..MM...MM..MM.......MM.MM}
202 {MMMM....MMMM.MM....MM..MMMMM..MMMM.MM...MM.MMMM.......MMM}
203 }^^A
204 }
205 \ExplSyntaxOn
206 ^^A contains code from https://tex.stackexchange.com/a/25753/117050
207 \NewDocumentCommand \codeexample { O{\footnotesize} D(){\leavevmode} +v }
208 {
209 \begin{minipage}[c]{.5\linewidth}
210 #1
211 \newlinechar=\endlinechar
212 \exp_args:Nx \scantokens
213 {
214 \string\begin{lstlisting}
215 #3
216 \string\end{lstlisting}
217 }
218 \end{minipage}
219 \begin{minipage}[c]{.45\linewidth}
220 #2
221 \newlinechar=\endlinechar
222 \exp_args:Nx \scantokens {#3}
223 \end{minipage}
224 \par
225 }
226 \ExplSyntaxOff
227 \begin{document}
228 \title
229 {^^A
230 \texorpdfstring
231 {^^A
232 \Huge
233 \mbox
234 {^^A
235 \BeginAccSupp{ActualText=pxpic}^^A
236 \href{https://github.com/Skillmon/ltx_pxpic}{\pxpiclogo}^^A
237 \EndAccSupp{}^^A
238 }^^A
239 \\[\medskipamount]
240 \Large draw pixel pictures^^A
241 }{pxpic - draw pixel pictures}^^A
242 }
243 \date{2023-08-16 v1.5}
244 \author{Jonathan P. Spratte\thanks{\protect\randomize{[email protected]}}}
245 \DocInput{pxpic.dtx}
246 \end{document}
247 %</driver>^^A=<<
248 % \fi
249 %
250 % \maketitle
251 % \renewcommand*\thefootnote{\arabic{footnote}}
252 %
253 % \begin{abstract}
254 % \noindent\parfillskip=0pt
255 % With \pxpicname\ you draw pictures pixel by pixel. It was inspired by a
256 % \href{https://tex.stackexchange.com/a/63759/117050}
257 % {lovely post by Paulo Cereda},
258 % among other things (most notably a beautiful duck) showcasing the use of
259 % characters from the Mario video games by Nintendo in \LaTeX.
260 % \end{abstract}
261 %
262 % \tableofcontents
263 %
264 % \begin{documentation}^^A>>=
265 %
266 % \section{Documentation}
267 %
268 % \subsection{Drawing pictures}
269 %
270 % \pxpicname\ supports different input modes, all of them have the same basic
271 % parsing behaviour. A \meta{pixel list} contains the pixel colours. The image
272 % is built line wise from top left to bottom right.
273 % There are two different syntaxes how a single row is given (dependent on the
274 % setting of the |lines|-key, see \autoref{sec:options}):
275 % \begin{itemize}
276 % \item
277 % By default each row of pixels should be a single \TeX\ argument (so either
278 % just one token, or a group delimited by |{}|). (This is the behaviour for
279 % |lines=group|)
280 % \item
281 % Alternatively each row of pixels should be right delimited by a space (and
282 % since a newline is turned into a space in \TeX\ with default settings, a
283 % newline is also possible). (This is the behaviour for |lines=space| and
284 % |lines=csv|)
285 % \end{itemize}
286 % Inside each line there are also two different parsing modes:
287 % \begin{itemize}
288 % \item
289 % By default within each line each pixel in turn should be a single \TeX\
290 % argument (so either just one token, or a group delimited by |{}|). (This
291 % is the behaviour for |lines=group| and |lines=space|)
292 % \item
293 % Each pixel except the last one is separated from the next pixel by a
294 % comma, no space trimming is applied. (This is the behaviour of
295 % |lines=csv|)
296 % \end{itemize}
297 %
298 % The different modes that interpret a single pixel's input are explained in
299 % \autoref{sec:modes}. The only disallowed token in the \meta{pixel list} is the
300 % control sequence \CS{pxpic@end} (plus the usual restrictions of \TeX\ so no
301 % unbalanced braces, no macros defined as \CS{outer}).
302 %
303 % There is a small caveat however: \pxpicname\ draws each pixel individually,
304 % and there is really no space between them, however some \textsc{pdf} viewers
305 % fail to display such adjacent lines correctly and leave small gaps (basically
306 % the same issue which packages like \pkg{colortbl} suffer from as well). In
307 % print this shouldn't be an issue, but some rasterisation algorithms employed
308 % by viewers and conversion tools have this deficit.
309 %
310 % Another thing I should mention: The pictures you can draw with \pxpicname\
311 % can't be arbitrary large. Due to the design decision of the output as a single
312 % \CS{hbox} and the way the output routine works, pictures are limited by \TeX's
313 % memory size to roughly $440\times 440$ pixels in \hologo{pdfLaTeX} with the
314 % default settings in \TeX\ Live. The size is unlimited in \hologo{LuaLaTeX},
315 % due to dynamic memory allocation. In \hologo{XeLaTeX} the size should be even
316 % smaller than in \hologo{pdfLaTeX}.
317 %
318 % \begin{function}{\pxpic}
319 % \begin{syntax}
320 % \cs{pxpic}\oarg{options}\marg{pixel list}
321 % \end{syntax}
322 % \meta{options} might be any options as listed in \autoref{sec:options}, and
323 % \meta{pixel list} is a list of pixels as described above. \cs{pxpic} parses
324 % the \meta{pixel list} and draws the corresponding picture. The result is
325 % contained in an \CS{hbox} and can be used wherever \TeX\ expects an
326 % \CS{hbox}. As a result, when you're in vertical mode a \cs{pxpic} will form
327 % a text line, to prevent this you can use \CS{leavevmode} before it. The
328 % \cs{pxpic} will be bottom aligned by default (see the options |b|, |c|, and
329 % |t|), you can further tweak this using \CS{raisebox} (or, if you want,
330 % \TeX's \CS{raise} and \CS{lower} primitives).
331 %
332 % If you used the |file| option the mandatory argument should be a file name
333 % containing a \meta{pixel list} instead of the \meta{pixel list} itself.
334 % \end{function}
335 %
336 % \subsubsection{Examples}
337 %
338 % Since the above explanation of the \meta{pixel list} syntax might've been a
339 % bit cryptic, and a good documentation should contain examples (this doesn't
340 % claim this documentation is \emph{good}), well, here are some examples (you
341 % might need to take a look at \autoref{sec:options} and \autoref{sec:modes} to
342 % fully understand the examples). Examples in this section will use the
343 % following \CS{pxpicsetup}:
344 %
345 % \begingroup
346 % \footnotesize
347 % \begin{lstlisting}
348 % \pxpicsetup
349 % {
350 % mode = px
351 % ,colours = {k=black, r=[HTML]{9F393D}, g=green!75!black, b=[rgb]{0,0,1}}
352 % ,skip = .
353 % ,size = 10pt
354 % }
355 % \end{lstlisting}
356 % \endgroup
357 %
358 % \begingroup
359 % \pxpicsetup
360 % {
361 % mode = px
362 % ,colours = {k=black, r=[HTML]{9F393D}, g=green!75!black, b=[rgb]{0,0,1}}
363 % ,skip = .
364 % ,size = 10pt
365 % }
366 %
367 % We can draw a small cross rather easily:\par\nobreak
368 % \noindent
369 % \codeexample$
370 % \pxpic
371 % {
372 % {.k}
373 % {kkk}
374 % {.k}
375 % }
376 % $
377 %
378 % A small multicoloured grid:\par\nobreak
379 % \noindent
380 % \codeexample$
381 % \pxpic
382 % {
383 % {brgk}
384 % {kbrg}
385 % {gkbr}
386 % {rgkb}
387 % }
388 % $
389 %
390 % A heart (shamelessly copied example from \pixelart):\par\nobreak
391 % \noindent
392 % \codeexample$
393 % \pxpic[lines=space]
394 % {
395 % ..rr.rr
396 % .rrrrrrr
397 % rrrrrrrrr
398 % rrrrrrrrr
399 % rrrrrrrrr
400 % .rrrrrrr
401 % ..rrrrr
402 % ...rrr
403 % ....r
404 % }
405 % $
406 %
407 % A parrot (shamelessly copied example from \pkg{PixelArtTikz}):\par\nobreak
408 % \begingroup
409 % \footnotesize
410 % \begin{lstlisting}[belowskip=0pt]
411 % \begin{filecontents*}{\jobname-parrot.csv}
412 % .,.,.,.,.,.,k,k,k,k,.,.,.,.,.,.
413 % .,.,.,.,k,k,r,r,r,r,k,k,.,.,.,.
414 % .,.,.,k,r,r,r,r,r,r,r,r,k,.,.,.
415 % .,.,k,r,r,r,r,r,r,r,r,r,r,k,.,.
416 % .,.,k,r,r,r,r,r,r,r,r,r,r,k,.,.
417 % .,k,r,.,.,r,r,r,r,r,r,.,.,r,k,.
418 % .,k,.,.,.,.,k,k,k,k,.,.,.,.,k,.
419 % .,k,.,k,.,.,k,k,k,k,.,k,.,.,k,.
420 % .,k,r,.,.,.,k,k,k,k,.,.,.,r,k,.
421 % .,.,k,r,r,.,k,k,k,k,.,r,r,k,.,.
422 % .,.,k,r,r,r,k,k,k,k,r,r,r,k,.,.
423 % .,.,.,k,r,r,r,k,k,r,r,r,k,.,.,.
424 % .,.,k,3,r,r,r,r,r,r,r,r,3,k,.,.
425 % .,k,b,3,r,r,r,r,r,r,r,r,3,b,k,.
426 % .,k,b,b,r,r,r,r,r,r,r,r,b,b,k,.
427 % .,k,b,b,r,r,r,r,r,r,r,r,b,b,k,.
428 % .,k,b,k,r,r,r,k,k,r,r,r,k,b,k,.
429 % 2,2,k,2,k,k,k,2,2,k,k,k,2,k,2,2
430 % 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
431 % 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
432 % .,.,.,.,.,k,r,r,r,r,k,.,.,.,.,.
433 % .,.,.,.,.,.,k,r,r,k,.,.,.,.,.,.
434 % .,.,.,.,.,.,.,k,k,.,.,.,.,.,.,.
435 % \end{filecontents*}
436 % \end{lstlisting}
437 % \endgroup
438 % \noindent
439 % \codeexample$
440 % \pxpic
441 % [
442 % lines=csv,
443 % colours={2=brown,3=yellow},
444 % file,
445 % size=3pt
446 % ]
447 % {\jobname-parrot.csv}
448 % $
449 %
450 % Using |mode=rgb| to draw a short coloured line:\par\nobreak
451 % \noindent
452 % \codeexample$
453 % \pxpic[mode=rgb]{{{1,0,1}{1,1,0}{0,1,1}}}
454 % $
455 %
456 % A multicoloured grid using skips and |mode=cmy|:\par\nobreak
457 % \noindent
458 % \codeexample$
459 % \pxpic[mode=cmy]
460 % {
461 % {{1,0,1} {1,1,0} {0,1,1} {} }
462 % {{} {1,0,1} {1,1,0} {0,1,1}}
463 % {{0,1,1} {} {1,0,1} {1,1,0}}
464 % {{1,1,0} {0,1,1} {} {1,0,1}}
465 % }
466 % $
467 %
468 % Showing the difference between a skipped and a white pixel:\par\nobreak
469 % \noindent
470 % \codeexample()$
471 % \pxpicsetup{colours = {w=white}}
472 % \colorbox{gray}{\pxpic{{bbb}{b.b}{bbb}}}
473 % \colorbox{gray}{\pxpic{{bbb}{bwb}{bbb}}}
474 % $
475 %
476 % \enlargethispage{1.1\baselineskip}
477 % A biggish example: Tux.\footnote{Source:
478 % \url{https://www.reddit.com/r/linux/comments/hwpm9j/tux_pixel_art_v10/}} I
479 % put two rows of pixels per code line to reduce the size a bit and the code is
480 % displayed tinily.\par\nobreak
481 % \noindent
482 % \codeexample[\tiny]$
483 % \pxpic
484 % [
485 % size = 2.5pt
486 % ,colours = {:=orange,
487 % '=black!10,
488 % g=black!75,
489 % O=orange!80!black}
490 % ]
491 % {
492 % {...........gggg} {.........gggkkggg}
493 % {........ggkkkkkkkg} {........gkkkkkkkkg}
494 % {........kkkkkkkkkk} {.......gkk.kkkk.kkk}
495 % {.......gk.k.kk.k.kk} {.......gk.k.kk.k.kk}
496 % {.......gkkkkkkkkkkk} {.......gkkk::::kkkk}
497 % {.......gk::::::::kk} {.......gk.:kkkk:kkk}
498 % {......gkk..::::'kkkk} {......gkk....'''kkkk}
499 % {......gkk....''''kkk} {.....gkk.....''''kkkk}
500 % {.....gk.......''''kkk} {....gkk........'''kkkk}
501 % {....gkk........'''kkkk} {....gk..........''kkkk}
502 % {...gkkg.........'''kkkk} {...gkkkk........'''kkkk}
503 % {..OOOOkkk.......'''kOOOO} {..O::::kkk......'''O:::O}
504 % {.O::::::kk.....'''::::::O} {.O::::::kkk...''kk::::::O}
505 % {O:::::::kkk...'kkk:::::::O} {O:::::::kkk...'kkk:::::::O}
506 % {.O:::::::kkkkkkkk:::::::O} {..OO:::::kkkkkkkk:::::OO}
507 % {....OO::O.kkkkkk.O::OO} {......OOO........OOO}
508 % }
509 % $
510 %
511 % Just for Paulo, a duck. Also, showing that the colour definitions in |mode=px|
512 % can be arbitrary tokens or multiple letters:\par\nobreak
513 % \noindent
514 % \codeexample[\tiny]$
515 % \pxpic[colours = {oo=orange,
516 % \ylw=yellow,
517 % \blk=black},
518 % skip = \skp]
519 % {
520 % {\skp\skp\skp\ylw\ylw\ylw\ylw}
521 % {\skp\skp\ylw\ylw\ylw\ylw\ylw\ylw}
522 % {\skp\skp{oo}\ylw\blk\ylw\ylw\ylw}
523 % {{oo}{oo}{oo}\ylw\ylw\ylw\ylw\ylw}
524 % {\skp{oo}{oo}{oo}\ylw\ylw\ylw\skp\skp\skp\skp\skp\ylw}
525 % {\skp\skp\skp\ylw\ylw\ylw\ylw\ylw\ylw\ylw\skp\ylw\ylw}
526 % {\skp\skp\ylw\ylw\ylw\ylw\ylw\ylw\ylw\ylw\ylw\ylw\ylw}
527 % {\skp\ylw\ylw\ylw\ylw\ylw\ylw\ylw\ylw\skp\ylw\ylw}
528 % {\skp\ylw\ylw\skp\ylw\ylw\ylw\ylw\skp\ylw\ylw\ylw}
529 % {\skp\ylw\ylw\ylw\skp\skp\skp\skp\ylw\ylw\ylw}
530 % {\skp\skp\ylw\ylw\ylw\ylw\ylw\ylw\ylw\ylw}
531 % {\skp\skp\skp\skp\ylw\ylw\ylw\ylw\ylw}
532 % }
533 % $
534 %
535 % Another example might be the definition of \CS{pxpiclogo} in
536 % \autoref{sec:implementation:pxpiclogo}.
537 %
538 % Who still needs \env{picture}-mode or complicated packages like
539 % \pkg{pstricks} or Ti\emph{k}Z with such pretty pictures?
540 %
541 % \endgroup
542 %
543 % \subsection{Setting options}\label{sec:options}
544 %
545 % To control its behaviour \pxpicname\ uses a key=value interface powered by
546 % \expkv. Options can be set either in the optional argument of
547 % \CS{pxpic} or with
548 %
549 % \begin{function}{\pxpicsetup}
550 % \begin{syntax}
551 % \cs{pxpicsetup}\marg{options}
552 % \end{syntax}
553 % Sets the \meta{options} locally to the current \TeX\ group.
554 % \end{function}
555 %
556 % \medskip\noindent
557 % Package options are not supported.
558 %
559 % \bigskip
560 % The available options are
561 %
562 % \begin{options}
563 % \item[colors=\meta{colour list}]
564 % Define pixel colours for |mode=px|, see \autoref{sec:colours} for a
565 % description of the value's syntax. No pixel definitions are made by the
566 % package.
567 % \item[colours]
568 % \emph{see \texttt{colors}.}
569 % \item[color-list=\meta{choice}]
570 % loads a previously through \CS{pxpicnewcolorlist} defined colour list. No
571 % colour lists are defined by the package.
572 % \item[colour-list]
573 % \emph{see \texttt{color-list}.}
574 % \item[exp]
575 % \emph{see \texttt{expansion}}
576 % \item[expansion=\meta{choice}]
577 % This is a choice to control the expansion of the \meta{pixel list}. The
578 % choices are:
579 % \begin{options}
580 % \item[full]
581 % the \meta{pixel list} is subject to one full expansion via
582 % |\expanded|.
583 % \item[none]
584 % no expansion takes place, the \meta{pixel list} is used as it is.
585 % \end{options}
586 % The initial value is |none|, the default used if you don't provide a value
587 % is |full|.
588 % \item[file=\meta{bool}]
589 % If you pass in |true| the mandatory argument of \CS{pxpic} becomes a file
590 % name which's contents are used as a \meta{pixel list}. Using |false|
591 % results in the default behaviour of a \meta{pixel list}. If you omit the
592 % value the same as |true| is used.
593 % \item[gap-hack=\meta{dimen}]
594 % To fix the issues with visible gaps in \textsc{pdf} viewers you can
595 % introduce some negative kerns to make the pixels overlap (lines overlap to
596 % the top, pixels to the left). This option expects a dimension as its
597 % value. A positive value will (maybe) close the gaps, a negative value will
598 % introduce real gaps. In any case the outermost pixels' borders still
599 % coincide with the borders of the surrounding \CS{hbox}. Take a look at my
600 % babbling about this issue in \autoref{sec:misc}.
601 % \item[ht=\meta{dimen}]
602 % Set the height of the pixels.
603 % \item[lines=\meta{choice}]
604 % How the individual lines of a \meta{pixel list} are given. The choices
605 % are:
606 % \begin{options}
607 % \item[group]
608 % The default syntax in which each line is a single \TeX\ argument
609 % (group delimited by |{}|).
610 % \item[space]
611 % A different input syntax in which each line should be right-delimited
612 % by a space (or newline as, by default, a newline is the same as a
613 % space in \TeX).
614 % \item[csv]
615 % The same line-wise input as |space|, but in each line each pixel
616 % should be separated from the next with a comma.
617 % \end{options}
618 % \item[mode=\meta{choice}]
619 % Set the used mode, see \autoref{sec:modes} for available modes. Initial
620 % value is |px|.
621 % \item[size=\meta{dimen}]
622 % Set both |ht| and |wd|. Initial value is \the\pxpicHT.
623 % \item[skip=\meta{tokens}]
624 % Define \meta{tokens} to be a skip (an empty space of width |wd|) in
625 % |mode=px|. No skip definitions are made by the package.
626 % \item[wd=\meta{dimen}]
627 % Set the width of the pixels.
628 % \item[b]
629 % Set the bottom of the \CS{pxpic} on the surrounding baseline (vertical
630 % bottom alignment; this is the default).
631 % \item[c]
632 % Set the centre of the \CS{pxpic} on the surrounding baseline (vertical
633 % centre alignment).
634 % \item[t]
635 % Set the top of the \CS{pxpic} on the surrounding baseline (vertical top
636 % alignment).
637 % \end{options}
638 %
639 % \subsubsection{Colour syntax}\label{sec:colours}
640 %
641 % In the value of the |colours| option you'll have to use the following syntax.
642 % Use a comma separated key=value list in which each key corresponds to a new
643 % pixel name for |mode=px|, and each value to the used colour. If the colour
644 % starts with an opening bracket use the complete value as is behind \CS{color},
645 % else use the whole value as the first mandatory argument to \CS{color} with a
646 % set of braces added. For example to define |r| as the named colour |red|, and
647 % |x| as the colour |#abab0f| (in the \textsc{html} colour model) use:
648 % \begin{lstlisting}
649 % colours = {r=red, x=[HTML]{abab0f}}
650 % \end{lstlisting}
651 %
652 % \subsubsection{Available modes}\label{sec:modes}
653 %
654 % \begin{options}
655 % \item[px]
656 % As already mentioned, \pxpicname\ supports different modes of input. The
657 % easiest to use |mode| is |px|, in which each element of the \meta{pixel
658 % list} has been previously defined as either a coloured pixel (using the
659 % |colour| option) or as a skipped pixel (using the |skip| option, resulting
660 % in a fully transparent pixel). Each element will be \CS{detokenize}d, so
661 % (within \TeX's limitations) the name of a pixel can be arbitrary. This is
662 % the initial mode \pxpicname\ uses. But other options are available as
663 % well.
664 % \item[named]
665 % Another |mode| is |named|, in which each element of the \meta{pixel list}
666 % should be a named colour (or colour expression) known to \pkg{xcolor}.
667 % Each element will be used like so: |{\color{|\meta{element}|}\px}|. An
668 % exception is an element which is empty (|{}|), which will be a skipped
669 % pixel.
670 % \item[rgb, cmy, cmyk, hsb, Hsb, tHsb, gray, RGB, HTML, HSB, Gray, wave]
671 % The modes |rgb|, |cmy|, |cmyk|, |hsb|, |Hsb|, |tHsb|, |gray|, |RGB|,
672 % |HTML|, |HSB|, |Gray|, and |wave| correspond to the different colour
673 % models supported by \pkg{xcolor}. With these modes each element of the
674 % \meta{pixel list} will be the values in these colour models, so they'll be
675 % used like so: |{\color[|\meta{mode}|]{|\meta{element}|}\px}|. An
676 % exception is an element which is empty (|{}|), which will be a skipped
677 % pixel.
678 % \end{options}
679 %
680 % You can define additional modes selectable with the |mode| option using the
681 % macros |\pxpicnewmode| or |\pxpicsetmode|.
682 %
683 % \subsection{Other customisation macros}
684 %
685 % \begin{function}{\pxpicnewmode,\pxpicsetmode}
686 % \begin{syntax}
687 % \cs{pxpicnewmode}\marg{name}\marg{definition}
688 % \end{syntax}
689 % You can define your own modes with \cs{pxpicnewmode}. Inside
690 % \meta{definition} |#1| is the currently parsed item in the \CS{pxpic}
691 % \meta{pixel list}. You can output a pixel using \CS{px}, and skip a pixel
692 % using \CS{pxskip}. The pixel will use the currently active colour (so if you
693 % want to draw a red pixel you could use |{\color{red}\px}|).
694 % \cs{pxpicnewmode} will throw an error if you try to define a mode which
695 % already exists, \cs{pxpicsetmode} has no checks on the name.
696 % \end{function}
697 %
698 % \begin{function}{\pxpicnewcolorlist,\pxpicsetcolorlist,\pxpicaddcolorlist}
699 % \begin{syntax}
700 % \cs{pxpicnewcolorlist}\marg{name}\marg{colour list}
701 % \end{syntax}
702 % This defines a colour list (to be used with the |colour-list| option). The
703 % syntax of \meta{colour list} is the same as for the |colours| option. The
704 % pixels aren't directly defined, but only by the use of
705 % |colour-list=|\meta{name}. So
706 % \begin{lstlisting}
707 % \pxpicnewcolorlist{example}{r=red,b=blue,g=green,k=black,w=white}
708 % \pxpicsetup{colour-list=example}
709 % \end{lstlisting}
710 % would have the same effect as
711 % \begin{lstlisting}
712 % \pxpicsetup{colours={r=red,b=blue,g=green,k=black,w=white}}
713 % \end{lstlisting}
714 % but a |colour-list| is more efficient if used multiple times. The |new|
715 % variant will only throw an error if the colour list \meta{name} is already
716 % defined. The |set| variant has no such tests, and the |add| variant will add
717 % additional colours to an existing list.
718 % \end{function}
719 %
720 % \begin{function}{\pxpicforget}
721 % \begin{syntax}
722 % \cs{pxpicforget}\marg{px}
723 % \end{syntax}
724 % Undefines the \meta{px} definition for use in |mode=px| (or skip symbol)
725 % added with the |colours| (or |skip|) option.
726 % \end{function}
727 %
728 % \subsection{Other macros}
729 %
730 % \begin{function}{\px,\pxskip}
731 % Inside of a \CS{pxpic} the macro \cs{px} draws a pixel (of the currently
732 % active colour), and \cs{pxskip} leaves out a pixel (so this one pixel is
733 % fully transparent). Use this in the \meta{definition} of a mode in
734 % \CS{pxpicnewmode}.
735 % \end{function}
736 %
737 % \begin{variable}{\pxpicHT,\pxpicWD}
738 % These two are |dimen| registers storing the height and width of the pixels.
739 % \end{variable}
740 %
741 % \begin{function}{\pxpiclogo}
742 % \begin{syntax}
743 % \cs{pxpiclogo}\oarg{size}
744 % \end{syntax}
745 % This draws the logo of \pxpicname. The \meta{size} controls the pixel size.
746 % \end{function}
747 %
748 % \subsection{Miscellaneous}\label{sec:misc}
749 %
750 % If you find bugs or have suggestions I'll be glad to hear about it, you can
751 % either open a ticket on Github (\url{https://github.com/Skillmon/ltx_pxpic})
752 % or email me (see the first page).
753 %
754 % A similar package is \pixelart, which, at the time \pxpicname\ was created,
755 % was described as a ``working draft'' by its author. \pxpicname\ wasn't
756 % intended as a direct competitor (I already started coding \pxpicname\ when I
757 % learned about \pixelart's existence), but I took inspiration from the ``Bugs,
758 % Ideas, Undefined behaviours'' section of \pixelart's documentation for the
759 % syntax of |mode=px|. Also the |lines=space| option is a copy of the syntax the
760 % new stable version of \pixelart\ is using (so images created with it could be
761 % processed with \pkg{pxpic} and vice versa). A third package that allows
762 % drawing pixel art is \pkg{PixelArtTikz}, that uses a csv-syntax for its pixel
763 % definition lists (you may have luck and the mode |lines=csv| works for lists
764 % defined for \pkg{PixelArtTikz}).
765 %
766 % \paragraph{Regarding the gap issue:}
767 % The pixels are output touching each other with no real gap, however some
768 % \textsc{pdf} viewers and tools will display such a gap. To make things even
769 % worse, the effect depends on the viewers current magnification.
770 % \pxpicname\ has the |gap-hack| option to provide some crude hack that might
771 % fix the issue, at the cost that the pixels on the far right and bottom are
772 % bigger than they were specified to be. Also pixels next to skipped pixels have
773 % a different size (skipped pixels don't cover pixels to their left or top as
774 % they are transparent). You'll want to find a good trade-off value if you want
775 % to use |gap-hack|, that mitigates the effect but isn't too big (to make the
776 % errors less obvious). You can play with the value and decide for yourself
777 % what's the lesser evil. Or you do like me, don't use |gap-hack| and blame the
778 % viewers. Here are examples in which you can compare (the |gap-hack| is chosen
779 % way too big in the first example and skips are used close to white pixels on
780 % purpose, but it illustrates the effects):\par\nobreak
781 % \begingroup
782 % \footnotesize
783 % \def\mypxpic#1%
784 % {^^A
785 % \pxpic
786 % [
787 % gap-hack=#1
788 % ,colours={k=black,g=green,w=white}
789 % ,skip=.
790 % ,size=10pt
791 % ,t
792 % ]
793 % {
794 % {kkkkk}
795 % {kgggk}
796 % {kwg.k}
797 % {kg.gk}
798 % {kgwk}
799 % {kkkw}
800 % }^^A
801 % }^^A
802 % \noindent
803 % \begin{minipage}[c]{.45\linewidth}^^A
804 % \begin{lstlisting}
805 % \pxpicsetup
806 % {
807 % colours={k=black,g=green,w=white}
808 % ,skip=.
809 % ,size=10pt
810 % ,t
811 % }
812 % \pxpic
813 % {
814 % {kkkkk}
815 % {kgggk}
816 % {kwg.k}
817 % {kg.gk}
818 % {kgwk}
819 % {kkkw}
820 % }
821 % \end{lstlisting}
822 % \end{minipage}
823 % \fontfamily{txtt}\selectfont
824 % \begin{tabular}[c]{ccc}
825 % \texttt{gap-hack=2pt} & \texttt{gap-hack=0pt} & \texttt{gap-hack=.2pt} \\
826 % \mypxpic{2pt} & \mypxpic{0pt} & \mypxpic{.2pt} \\
827 % \end{tabular}
828 % \endgroup
829 %
830 % \paragraph{Exploiting the \texttt{gap-hack} to draw a grid:}
831 % It is possible to exploit the |gap-hack| option to draw a grid around your
832 % pixels (at least for a rectangular picture). For this we simply set a coloured
833 % background and use a negative |gap-hack| value:\par
834 % \noindent
835 % \codeexample$
836 % \newcommand\gridpxpic[3][]
837 % {{\setlength\fboxsep{#2}\colorbox{black}{\pxpic[gap-hack=-\fboxsep,#1]{#3}}}}
838 % \gridpxpic
839 % [colours={g=green,w=white},size=8pt]
840 % {1pt}
841 % {{gwgw}{wgwg}}%
842 % $
843 %
844 %
845 % \end{documentation}^^A=<<
846 %
847 % \begin{implementation}^^A>>=
848 %
849 % \gobbledocstriptag
850 %<*pkg>
851 %
852 % \clearpage
853 %
854 % \section{Implementation}^^A>>=
855 %
856 % Report who we are
857 % \begin{macrocode}
858 \ProvidesPackage{pxpic}[2023-08-16 v1.5 draw pixel pictures]
859 % \end{macrocode}
860 % and load dependencies
861 % \begin{macrocode}
862 \RequirePackage{xcolor}
863 \RequirePackage{expkv}
864 % \end{macrocode}
865 % \begin{variable}{\pxpicHT,\pxpicWD}
866 % These two variables store the height and width of a pixel.
867 % \begin{macrocode}
868 \@ifdefinable\pxpicHT{\newdimen\pxpicHT}
869 \@ifdefinable\pxpicWD{\newdimen\pxpicWD}
870 \pxpicHT=\p@
871 \pxpicWD=\pxpicHT
872 % \end{macrocode}
873 % \end{variable}
874 % \begin{variable}[internal]{\pxpic@kern}
875 % To fix the visible gaps in some \textsc{pdf} viewers if the user chooses so
876 % with the |gap-hack| option we introduce some \CS{kern}s of the length
877 % stored in this register.
878 % \begin{macrocode}
879 \@ifdefinable\pxpic@kern{\newdimen\pxpic@kern}
880 \pxpic@kern=\z@
881 % \end{macrocode}
882 % \end{variable}
883 % \begin{macro}[internal]{\pxpic@@kern}
884 % For some simplification of the output box (removing unnecessary kerns) we
885 % don't directly use \CS{kern} but one step of indirection. This macro is
886 % locally turned into \CS{@gobble} if \CS{pxpic@kern} is equal to \CS{z@}.
887 % \begin{macrocode}
888 \def\pxpic@@kern#1{\kern#1\pxpic@kern}
889 % \end{macrocode}
890 % \end{macro}
891 % \begin{macro}[internal]{\pxpic@inner@box,\pxpic@after@inner@box}
892 % To get different vertical alignments we nest one of |\vbox|, |\vtop|, and a
893 % lowered |\vbox| inside the outer |\hbox|. The macro \cs{pxpic@inner@box}
894 % will store this information, and since lowering can only be done after the
895 % box was set (the alternative would be |\vcenter|, which ends up on a
896 % different height), we need to be able to put the box output with |\lower|
897 % after the box was collected, which is why we need
898 % \cs{pxpic@after@inner@box}. We default to bottom alignment.
899 % \begin{macrocode}
900 \@ifdefinable\pxpic@inner@box{\let\pxpic@inner@box\vbox}
901 \@ifdefinable\pxpic@after@inner@box{\let\pxpic@after@inner@box\@empty}
902 % \end{macrocode}
903 % \end{macro}
904 %
905 %
906 % \subsection{Options}
907 %
908 % We define the options using \expkv\ directly (no fancy options are involved
909 % and these are just a few anyway).
910 %
911 % The first few options are straight forward. We use \expkv's name space to
912 % actually store the |skip| and |px| definitions, hence we use
913 % \CS{ekvdefNoVal} in the code of |skip|.
914 %
915 % \begin{macrocode}
916 \protected\ekvdef{pxpic}{size}
917 {\pxpicHT=\dimexpr#1\relax\pxpicWD=\pxpicHT}
918 \protected\ekvdef{pxpic}{ht}{\pxpicHT=\dimexpr#1\relax}
919 \protected\ekvdef{pxpic}{wd}{\pxpicWD=\dimexpr#1\relax}
920 \protected\ekvdef{pxpic}{gap-hack}{\pxpic@kern=\dimexpr#1\relax}
921 \protected\ekvdef{pxpic}{skip}{\ekvdefNoVal{pxpic@px}{#1}{\pxskip}}
922 % \end{macrocode}
923 % The |colours| option is parsed using \CS{ekvparse} and \CS{pxpic@setcolor}.
924 % \begin{macrocode}
925 \protected\ekvdef{pxpic}{colors}{\ekvparse\pxpic@err@noval\pxpic@setcolor{#1}}
926 \ekvletkv{pxpic}{colours}{pxpic}{colors}
927 % \end{macrocode}
928 % And the |mode| just checks whether the |mode| macro is defined and lets the
929 % auxiliary macro \CS{pxpic@parse@px} to the defined |mode|.
930 % \begin{macrocode}
931 \protected\ekvdef{pxpic}{mode}
932 {%
933 \@ifundefined{pxpic@parse@px@#1}%
934 {\pxpic@err@unknown@mode{#1}}%
935 {%
936 \expandafter\let\expandafter\pxpic@parse@px
937 \csname pxpic@parse@px@#1\endcsname
938 }%
939 }
940 % \end{macrocode}
941 % A similar check is done for the |colour-list| option.
942 % \begin{macrocode}
943 \protected\ekvdef{pxpic}{color-list}
944 {%
945 \@ifundefined{pxpic@colorlist@#1}%
946 {\pxpic@err@unknown@colorlist{#1}}%
947 {\csname pxpic@colorlist@#1\endcsname}%
948 }
949 \ekvletkv{pxpic}{colour-list}{pxpic}{color-list}
950 % \end{macrocode}
951 % The alignment options set the internals |\pxpic@inner@box| and
952 % |\pxpic@after@inner@box|.
953 % \begin{macrocode}
954 \protected\ekvdefNoVal{pxpic}{b}
955 {%
956 \let\pxpic@inner@box\vbox
957 \let\pxpic@after@inner@box\@empty
958 }
959 \protected\ekvdefNoVal{pxpic}{c}
960 {%
961 \def\pxpic@inner@box{\setbox0=\vbox}%
962 \def\pxpic@after@inner@box{\lower.5\ht0\box0}%
963 }
964 \protected\ekvdefNoVal{pxpic}{t}
965 {%
966 \let\pxpic@inner@box\vtop
967 \let\pxpic@after@inner@box\@empty
968 }
969 % \end{macrocode}
970 %
971 % The expansion related option will set an internal. It's yet another option
972 % which will need to check for a defined internal, as it's a choice of |none| or
973 % |full|. This is deliberately not defined |\protected| to allow expansion as
974 % far as possible.
975 % \begin{macrocode}
976 \ekvdef{pxpic}{expansion}
977 {%
978 \@ifundefined{pxpic@expansion@#1}%
979 {\pxpic@err@unknown@expansion{#1}}%
980 {\csname pxpic@expansion@#1\endcsname}%
981 }
982 \ekvdefNoVal{pxpic}{expansion}{\pxpic@expansion@full}
983 \ekvletkv {pxpic}{exp}{pxpic}{expansion}
984 \ekvletkvNoVal{pxpic}{exp}{pxpic}{expansion}
985 % \end{macrocode}
986 % And we define the choices and the initial behaviour:
987 % \begin{macrocode}
988 \protected\def\pxpic@expansion@none{\let\pxpic@expansion\@firstofone}
989 \protected\def\pxpic@expansion@full{\let\pxpic@expansion\expanded}
990 \pxpic@expansion@none
991 % \end{macrocode}
992 %
993 % Another key is the choice how lines are delimited, either as a single
994 % group/argument or by spaces (or newlines). The code defining the choices'
995 % behaviour is a bit down the road, here we only initialise the keys.
996 % \begin{macrocode}
997 \ekvdef{pxpic}{lines}
998 {%
999 \@ifundefined{pxpic@@parse@#1}%
1000 {\pxpic@err@unknown@lines{#1}}%
1001 {\csname pxpic@@parse@#1\endcsname}%
1002 }
1003 % \end{macrocode}
1004 %
1005 % We also want to be able to grab the \meta{pixel list} from a file, and we need
1006 % a key to define this behaviour.
1007 % \begin{macrocode}
1008 \ekvdef{pxpic}{file}
1009 {%
1010 \@ifundefined{pxpic@file@#1}%
1011 {\pxpic@err@unknown@file{#1}}%
1012 {\csname pxpic@file@#1\endcsname}%
1013 }
1014 \ekvdefNoVal{pxpic}{file}{\pxpic@file@true}
1015 % \end{macrocode}
1016 % The macro \CS{pxpic@@file@or@list} will get the argument in two sets of
1017 % braces. In the |false| case things are easy, we just directly go over to the
1018 % expansion step. In the |true| case we input the file.
1019 % \begin{macrocode}
1020 \ExplSyntaxOn
1021 \protected\def\pxpic@file@true
1022 {
1023 \def\pxpic@@file@or@list ##1
1024 {
1025 \file_get:nnNTF ##1 {} \l_tmpa_tl
1026 {
1027 \ekv@exparg { \expandafter\pxpic@parse\pxpic@expansion }
1028 { \expandafter { \l_tmpa_tl } }
1029 }
1030 { \pxpic@err@file@not@found ##1 }
1031 }
1032 }
1033 \ExplSyntaxOff
1034 \protected\def\pxpic@file@false
1035 {\def\pxpic@@file@or@list{\expandafter\pxpic@parse\pxpic@expansion}}
1036 \pxpic@file@false
1037 % \end{macrocode}
1038 %
1039 %
1040 % \subsection{User macros}\label{sec:implementation:pxpiclogo}
1041 %
1042 % \begin{macro}{\pxpic}
1043 % \begin{macro}[internal]{\pxpic@}
1044 % \CS{pxpic} expands directly to an opened \CS{hbox}, the auxiliary
1045 % \CS{pxpic@} checks for the optional argument and inserts the rest of the
1046 % code. We need to set \CS{baselineskip} to \CS{pxpicHT} so that the pixels
1047 % are stacked vertically without gaps. \CS{pxpic@parse} will parse the
1048 % \meta{pixel list} until \CS{pxpic@end} is hit. The final \CS{egroup} closes
1049 % the \CS{hbox}. The row-wise output is done via a \CS{vbox} in which each
1050 % pixel row will be wrapped inside an \CS{hbox}. The \CS{kern} negates a
1051 % negative \CS{kern} in \CS{pxpic@parse} so that the first line isn't moved.
1052 % \begin{macrocode}
1053 \@ifdefinable\pxpic{\protected\def\pxpic{\hbox\bgroup\pxpic@}}
1054 \newcommand\pxpic@[2][]
1055 {%
1056 \pxpicsetup{#1}%
1057 \pxpic@inner@box
1058 {%
1059 \let\px\pxpic@px
1060 \let\pxskip\pxpic@skip
1061 \ifdim\pxpic@kern=\z@
1062 \let\pxpic@@kern\@gobble
1063 \else
1064 \advance\pxpicHT\pxpic@kern
1065 \advance\pxpicWD\pxpic@kern
1066 \fi
1067 \baselineskip=\pxpicHT
1068 % \end{macrocode}
1069 % This here is the only spot we use \CS{kern} directly instead of the
1070 % wrapping \CS{pxpic@@kern}. Even if this is effectively a |\kern0pt| the
1071 % vertical alignment in top-aligned boxes is different this way (aligning at
1072 % the top of the top row instead of the bottom).
1073 % \begin{macrocode}
1074 \kern\pxpic@kern
1075 \pxpic@@file@or@list{{#2}}%
1076 }%
1077 \pxpic@after@inner@box
1078 \egroup
1079 }
1080 % \end{macrocode}
1081 % \end{macro}
1082 % \end{macro}
1083 %
1084 % \begin{macro}{\pxpicsetup}
1085 % Just directly defined to call \expkv's parser for the \pxpicname\ set.
1086 % \begin{macrocode}
1087 \ekvsetdef\pxpicsetup{pxpic}
1088 % \end{macrocode}
1089 % \end{macro}
1090 %
1091 % \begin{macro}{\pxpiclogo}
1092 % The logo is just a biggish pixel picture. The \CS{lower} will move it down a
1093 % bit so that it appears correctly aligned on the baseline. Since the logo
1094 % should be part of a normal sentence in most usages we put \CS{leavevmode}
1095 % before it. Also we make sure that the |mode| and |px| definitions are
1096 % correct and the output is bottom aligned.
1097 % \begin{macrocode}
1098 \ekvcompile\pxpiclogo@settings#1{pxpic}
1099 {
1100 size=#1,gap-hack=\z@,b,mode=px,colours={o=[HTML]{9F393D},g=black!75},skip=.
1101 ,lines=group
1102 }
1103 \newcommand*\pxpiclogo[1][.13ex]
1104 {%
1105 \begingroup
1106 \leavevmode
1107 \pxpiclogo@settings{#1}%
1108 \lower3.2\pxpicHT\pxpic
1109 {
1110 {............................................g}
1111 {...........................................gggg}
1112 {.oooo.......................gggg...........ggg}
1113 {.ooooo...oo......oo...oo....ggggg...gg......g..........g}
1114 {.ooooooooooo...ooooo..oooo..ggggggggggg...ggggg...ggggggg}
1115 {..ooooo..oooo.ooooooooooo....ggggg..gggg.ggggggg.ggggggggg}
1116 {...oooo..oooo....ooooo........gggg..gggg...gggg..gggg.ggg}
1117 {...oooo..oooo.....oooo........gggg..gggg...gggg..gggg}
1118 {.oooooo..oooo.....ooooo.....gggggg..gggg...gggg..gggg}
1119 {oooooooooooo...ooooooooo...gggggggggggg....gggg..ggggggggg}
1120 {o.oooooooo....ooooo.oooooo.g.gggggggg......ggggg..ggggggg}
1121 {...ooo.o......o.oo...oo.......ggg.g.........gg......ggg}
1122 {...ooo........................ggg}
1123 {...ooo........................ggg}
1124 {....o..........................g}
1125 }%
1126 \endgroup
1127 }
1128 % \end{macrocode}
1129 % \end{macro}
1130 %
1131 % \begin{macro}{\pxpicforget}
1132 % Straight forward, just let the |px| macro to an undefined macro.
1133 % \begin{macrocode}
1134 \newcommand\pxpicforget[1]
1135 {\expandafter\let\csname\ekv@name{pxpic@px}{#1}N\endcsname\pxpic@undef}
1136 % \end{macrocode}
1137 % \end{macro}
1138 %
1139 % \begin{macro}{\pxpicnewmode,\pxpicsetmode}
1140 % These are pretty simple as well, the |new| variant will use \CS{newcommand}
1141 % which will do the testing for us, the |set| variant uses \CS{def}.
1142 % \begin{macrocode}
1143 \protected\long\def\pxpicnewmode#1#2%
1144 {\expandafter\newcommand\csname pxpic@parse@px@#1\endcsname[1]{#2}}
1145 \protected\long\def\pxpicsetmode#1#2%
1146 {\long\expandafter\def\csname pxpic@parse@px@#1\endcsname##1{#2}}
1147 % \end{macrocode}
1148 % \end{macro}
1149 %
1150 % \begin{macro}{\pxpicnewcolorlist,\pxpicsetcolorlist,\pxpicaddcolorlist}
1151 % \begin{macro}[internal]{\pxpic@setcolorlist,\pxpic@addcolorlist}
1152 % The colour list is first parsed with \CS{ekvparse} inside an \CS{edef}.
1153 % \CS{ekvparse} will prevent the parsed list from further expanding, leaving
1154 % each list element and \CS{pxpic@experr@noval} or
1155 % \CS{pxpic@setcolor@colorlist} before it. In a second \CS{edef} these will be
1156 % expanded, \CS{pxpic@experr@noval} throwing an error for each element missing
1157 % a colour definition, and \CS{pxpic@setcolor@colorlist} testing for an
1158 % opening bracket (which we do expandably) and leaving the correct definition
1159 % protected against further expansion. The |add| variant uses a temporary
1160 % macro for the parsing part and adds the result to the list holding macro.
1161 % The second expansion step in |set| and both in |add| are done inside a group
1162 % to revert any definition (also those letting tokens to \CS{relax} by
1163 % \CS{csname}) made at this point except for the list macro itself.
1164 % \begin{macrocode}
1165 \protected\def\pxpicnewcolorlist#1%
1166 {%
1167 \@ifundefined{pxpic@colorlist@#1}%
1168 {\pxpicsetcolorlist{#1}}%
1169 {\pxpic@err@defined@colorlist{#1}\@gobble}%
1170 }
1171 \protected\def\pxpicsetcolorlist#1%
1172 {\expandafter\pxpic@setcolorlist\csname pxpic@colorlist@#1\endcsname}
1173 \protected\long\def\pxpic@setcolorlist#1#2%
1174 {%
1175 \edef#1{\ekvparse\pxpic@experr@noval\pxpic@setcolor@colorlist{#2}}%
1176 \begingroup\edef#1{\endgroup\protected\def\unexpanded{#1}{#1}}%
1177 #1%
1178 }
1179 \protected\def\pxpicaddcolorlist#1%
1180 {%
1181 \@ifundefined{pxpic@colorlist@#1}%
1182 {\pxpic@err@unknown@colorlist{#1}\@gobble}%
1183 {\expandafter\pxpic@addcolorlist\csname pxpic@colorlist@#1\endcsname}%
1184 }
1185 \protected\long\def\pxpic@addcolorlist#1#2%
1186 {%
1187 \begingroup
1188 \edef\pxpic@tmp
1189 {\ekvparse\pxpic@experr@noval\pxpic@setcolor@colorlist{#2}}%
1190 \edef\pxpic@tmp
1191 {%
1192 \endgroup
1193 \protected\def\unexpanded{#1}{\unexpanded\expandafter{#1}\pxpic@tmp}%
1194 }%
1195 \pxpic@tmp
1196 }
1197 % \end{macrocode}
1198 % \end{macro}
1199 % \end{macro}
1200 %
1201 %
1202 % \subsection{Parser}
1203 %
1204 % \begin{macro}[internal]{\pxpic@ifend,\pxpic@ifempty,\pxpic@ifbracket}
1205 % These are three helper macros. The first just gobbles everything until the
1206 % next \CS{pxpic@end}, and we borrow a fast test for an empty argument from
1207 % \expkv. The last can be used to check for an opening bracket if used like
1208 % |\pxpic@ifbracket|\hskip0pt|\pxpic@end|\hskip0pt|#1.\pxpic@end|\hskip0pt
1209 % |[]\pxpic@end|.
1210 % \begin{macrocode}
1211 \long\def\pxpic@ifend#1\pxpic@end{}
1212 \let\pxpic@ifempty\ekv@ifempty
1213 \long\def\pxpic@ifbracket#1\pxpic@end[#2]\pxpic@end{\pxpic@ifempty{#2}}
1214 % \end{macrocode}
1215 % \end{macro}
1216 %
1217 % \begin{macro}[internal]{\pxpic@openbrace}
1218 % For some weirder \TeX\ programming it is sometimes necessary to insert an
1219 % unmatched opening brace. This code does exactly that if it's expanded twice.
1220 % It is put into a single macro so that one can \CS{expandafter} it easier.
1221 % \begin{macrocode}
1222 \newcommand*\pxpic@openbrace{\expandafter{\iffalse}\fi}
1223 % \end{macrocode}
1224 % \end{macro}
1225 %
1226 % \begin{macro}[internal]
1227 % {\pxpic@parse,\pxpic@@parse,\pxpic@parse@aux,\pxpic@done,\pxpic@parseline}
1228 % \begin{macro}[internal]
1229 % {\pxpic@@parse@group,\pxpic@@parse@space,\pxpic@@parse@csv}
1230 % The parsing loop is pretty simple, first check whether we're done, else open
1231 % a new \CS{hbox} (which will form a row in the \CS{vbox} placed by
1232 % \CS{pxpic@}) in which the inner parsing loop is run. Then call the next
1233 % iteration. If we're done just gobble the remainder of the current iteration.
1234 % First we introduce our \CS{kern} which might fix the gap issue. Another
1235 % \CS{kern} is done at the start of each \CS{hbox} to compensate the
1236 % unnecessary \CS{kern} done by the first \CS{pxpic@parseline}.
1237 %
1238 % This parsing has one step of indirection, the first macro that is called is
1239 % \CS{pxpic@parse}, that'll set things up with the end marker for the row
1240 % parser \CS{pxpic@@parse}. Both the definition of \CS{pxpic@parse} and
1241 % \CS{pxpic@@parse} is dependent on the setting of the |lines| key, hence they
1242 % are set up with the two macros \CS{pxpic@@parse@group} and
1243 % \CS{pxpic@@parse@space} that represent the choices of said key.
1244 % \begin{macrocode}
1245 \protected\def\pxpic@parse@setarg#1#2%
1246 {%
1247 \long\def\pxpic@@parse##1#1%
1248 {%
1249 \pxpic@ifend##1\pxpic@done\pxpic@end
1250 \pxpic@@kern-%
1251 \hbox{\pxpic@@kern+\pxpic@parseline##1#2\pxpic@end#2}%
1252 \pxpic@@parse
1253 }%
1254 \long\def\pxpic@parseline##1#2%
1255 {%
1256 \pxpic@ifend##1\pxpic@linedone\pxpic@end
1257 \pxpic@@kern-%
1258 \pxpic@parse@px{##1}%
1259 \pxpic@parseline
1260 }%
1261 }
1262 \protected\def\pxpic@@parse@group
1263 {%
1264 \long\def\pxpic@parse##1{\pxpic@@parse##1\pxpic@end}%
1265 \pxpic@parse@setarg{}{}%
1266 }
1267 % \end{macrocode}
1268 % In the |space| and |csv| case we need to make sure that there are no extra
1269 % spaces that would result in empty lines. We borrow the space trimmer from
1270 % \pkg{expl3} for this.
1271 % \begin{macrocode}
1272 \ExplSyntaxOn
1273 \cs_new_protected:Npn \pxpic@@parse@space #1
1274 {
1275 \protected\def\pxpic@@parse@space
1276 {
1277 \protected\long\def\pxpic@parse ####1
1278 { \tl_trim_spaces_apply:nN {####1} \pxpic@parse@aux #1 \pxpic@end #1 }
1279 \pxpic@parse@setarg {#1} {}
1280 }
1281 \protected\def\pxpic@@parse@csv
1282 {
1283 \protected\long\def\pxpic@parse ####1
1284 { \tl_trim_spaces_apply:nN {####1} \pxpic@parse@aux #1 \pxpic@end #1 }
1285 \pxpic@parse@setarg {#1} { , }
1286 }
1287 }
1288 \ExplSyntaxOff
1289 \long\def\pxpic@parse@aux#1{\pxpic@@parse#1}
1290 \pxpic@@parse@space{ }
1291 % \end{macrocode}
1292 % Here we set up the default definition. Also the end of the parsing is
1293 % defined here.
1294 % \begin{macrocode}
1295 \pxpic@@parse@group
1296 \long\def\pxpic@done\pxpic@end\pxpic@@kern-\hbox#1\pxpic@@parse{}
1297 % \end{macrocode}
1298 % \end{macro}
1299 % \end{macro}
1300 %
1301 % \begin{macro}[internal]{\pxpic@linedone}
1302 % For \CS{pxpic@parseline}
1303 % the line parsing loop also checks whether we're done, if not we place a
1304 % pixel using the current definition of \CS{pxpic@parse@px} (which will be set
1305 % by the current |mode|) and afterwards call the next iteration. If we're done
1306 % we gobble the remainder of the current iteration and control goes back to
1307 % \CS{pxpic@parse}. Before each pixel we introduce a negative \CS{kern} to
1308 % maybe fix the gap issue by letting the pixels overlap a bit.
1309 % \begin{macrocode}
1310 \long\def\pxpic@linedone
1311 \pxpic@end\pxpic@@kern-\pxpic@parse@px#1\pxpic@parseline
1312 {}
1313 % \end{macrocode}
1314 % \end{macro}
1315 %
1316 %
1317 % \subsection{Modes}
1318 %
1319 % The modes define how a single element of the \meta{pixel list} is parsed.
1320 %
1321 % \begin{macro}[internal]{\pxpic@parse@px@px,\pxpic@parse@px}
1322 % In the |px| mode we check whether the pixel is defined (using the name space
1323 % of \expkv), if so call it, else throw an error and skip. Since this is also
1324 % the initial |mode| we \CS{let} the auxiliary macro \CS{pxpic@parse@px} to
1325 % this mode here.
1326 % \begin{macrocode}
1327 \newcommand\pxpic@parse@px@px[1]
1328 {%
1329 \ekvifdefinedNoVal{pxpic@px}{#1}%
1330 {\csname\ekv@name{pxpic@px}{#1}N\endcsname}%
1331 {%
1332 \pxpic@err@unknown@px{#1}%
1333 \pxskip
1334 }%
1335 }
1336 \let\pxpic@parse@px\pxpic@parse@px@px
1337 % \end{macrocode}
1338 % \end{macro}
1339 %
1340 % \begin{macro}[internal]{\pxpic@parse@px@named}
1341 % |named| just checks whether the skip is empty. If so skip, else call
1342 % \CS{color} with the element and output a pixel.
1343 % \begin{macrocode}
1344 \newcommand\pxpic@parse@px@named[1]
1345 {%
1346 \pxpic@ifempty{#1}%
1347 {\pxskip}%
1348 {{\@declaredcolor{#1}\px}}%
1349 }
1350 % \end{macrocode}
1351 % \end{macro}
1352 %
1353 % \begin{macro}[internal]
1354 % {
1355 % \pxpic@parse@px@rgb,
1356 % \pxpic@parse@px@cmy,
1357 % \pxpic@parse@px@cmyk,
1358 % \pxpic@parse@px@hsb,
1359 % \pxpic@parse@px@Hsb,
1360 % \pxpic@parse@px@tHsb,
1361 % \pxpic@parse@px@gray,
1362 % \pxpic@parse@px@RGB,
1363 % \pxpic@parse@px@HTML,
1364 % \pxpic@parse@px@HSB,
1365 % \pxpic@parse@px@Gray,
1366 % \pxpic@parse@px@wave
1367 % }
1368 % The colour model modes are all the same in principle. They test for an empty
1369 % element to introduce a skip, else they call \CS{color} with the respective
1370 % colour model and output a pixel. We use the auxiliary \CS{pxpic@tmp} to do
1371 % all those definitions and undefine it afterwards.
1372 % \begin{macrocode}
1373 \def\pxpic@tmp#1%
1374 {%
1375 \pxpicnewmode{#1}%
1376 {%
1377 \pxpic@ifempty{##1}%
1378 {\pxskip}%
1379 {{\@undeclaredcolor[#1]{##1}\px}}%
1380 }%
1381 }
1382 \pxpic@tmp{rgb}
1383 \pxpic@tmp{cmy}
1384 \pxpic@tmp{cmyk}
1385 \pxpic@tmp{hsb}
1386 \pxpic@tmp{Hsb}
1387 \pxpic@tmp{tHsb}
1388 \pxpic@tmp{gray}
1389 \pxpic@tmp{RGB}
1390 \pxpic@tmp{HTML}
1391 \pxpic@tmp{HSB}
1392 \pxpic@tmp{Gray}
1393 \pxpic@tmp{wave}
1394 \let\pxpic@tmp\pxpic@undef
1395 % \end{macrocode}
1396 % \end{macro}
1397 %
1398 %
1399 % \subsection{Pixel and Skip}
1400 %
1401 % \begin{macro}[internal]{\pxpic@px,\pxpic@skip}
1402 % The actual definition of pixels and skips is stored in macros to which the
1403 % frontend macros \CS{px} and \CS{pxskip} will be let inside of \CS{pxpic}.
1404 % \begin{macrocode}
1405 \newcommand\pxpic@px{\vrule height\pxpicHT width\pxpicWD depth\z@}
1406 \newcommand\pxpic@skip{\kern\pxpicWD}
1407 % \end{macrocode}
1408 % \end{macro}
1409 %
1410 %
1411 % \subsection{Parser for colours}
1412 %
1413 % \begin{macro}[internal]{\pxpic@setcolor,\pxpic@setcolor@a,\pxpic@setcolor@b}
1414 % First we test whether the colour starts with an opening bracket or not.
1415 % Depending on that we either just put the colour after \CS{color}, or put
1416 % braces around it (as it then is a colour expression for \pkg{xcolor} and
1417 % just a single argument). \CS{pxpic@setcolor} defines a |px| in the name
1418 % space of \expkv\ (this has a slight overhead during definition, but \expkv\
1419 % is fast in checking whether one of its keys is defined or not, and reduces
1420 % the amount of code in this package).
1421 % \begin{macrocode}
1422 \newcommand\pxpic@setcolor[2]
1423 {%
1424 \pxpic@ifbracket\pxpic@end#2.\pxpic@end[]\pxpic@end
1425 \pxpic@setcolor@a\pxpic@setcolor@b
1426 {#1}{#2}%
1427 }
1428 \newcommand\pxpic@setcolor@a[2]
1429 {%
1430 \expandafter\def\csname\ekv@name{pxpic@px}{#1}N\endcsname
1431 {{\@declaredcolor{#2}\px}}%
1432 }
1433 \newcommand\pxpic@setcolor@b[2]
1434 {%
1435 \expandafter\def\csname\ekv@name{pxpic@px}{#1}N\endcsname
1436 {{\@undeclaredcolor#2\px}}%
1437 }
1438 % \end{macrocode}
1439 % \end{macro}
1440 %
1441 % \begin{macro}[internal]{\pxpic@setcolor@colorlist}
1442 % This macro should leave the correct code in the input stream to define a
1443 % single pixel. It is to be used inside of \CS{edef}, hence using
1444 % \CS{unexpanded}, which doesn't have an opening brace directly after it
1445 % so that the \CS{pxpic@ifbracket} test is fully expanded. Next we expand
1446 % \CS{pxpic@setcolor@a}/|b| twice (which will expand the \CS{csname}
1447 % contained in it) and then leave the opening bracket for \CS{unexpanded} in
1448 % the input stream. The code should be used inside a group so that all the
1449 % implicit definitions to \CS{relax} done by \CS{csname} are reverted.
1450 % \begin{macrocode}
1451 \newcommand\pxpic@setcolor@colorlist[2]
1452 {%
1453 \unexpanded\iffalse{\fi
1454 \pxpic@ifbracket\pxpic@end#2.\pxpic@end[]\pxpic@end
1455 {\expandafter\expandafter\expandafter\pxpic@openbrace\pxpic@setcolor@a}%
1456 {\expandafter\expandafter\expandafter\pxpic@openbrace\pxpic@setcolor@b}%
1457 {#1}{#2}%
1458 }%
1459 }
1460 % \end{macrocode}
1461 % \end{macro}
1462 %
1463 %
1464 % \subsection{Messages}
1465 %
1466 % \begin{macro}[internal]
1467 % {
1468 % \pxpic@err@noval,\pxpic@err@unknown@px,\pxpic@err@unknown@mode,
1469 % \pxpic@err@unknown@colorlist,\pxpic@err@defined@colorlist,
1470 % \pxpic@err@unknown@expansion
1471 % }
1472 % These are just some macros throwing errors, nothing special here.
1473 % \begin{macrocode}
1474 \newcommand\pxpic@err@noval[1]
1475 {\PackageError{pxpic}{Missing colour definition for name `\detokenize{#1}'}{}}
1476 \newcommand\pxpic@err@unknown@px[1]
1477 {\PackageError{pxpic}{Unknown pixel `\detokenize{#1}'. Skipping}{}}
1478 \newcommand\pxpic@err@unknown@mode[1]
1479 {\PackageError{pxpic}{Unknown mode `#1'}{}}
1480 \newcommand\pxpic@err@unknown@colorlist[1]
1481 {\PackageError{pxpic}{Unknown colour list `#1'}{}}
1482 \newcommand\pxpic@err@defined@colorlist[1]
1483 {\PackageError{pxpic}{Colour list `#1' already defined}{}}
1484 \newcommand\pxpic@err@unknown@expansion[1]
1485 {\PackageError{pxpic}{Unknown expansion mode `#1'}{}}
1486 \newcommand\pxpic@err@unknown@lines[1]
1487 {\PackageError{pxpic}{Unknown lines mode `#1'}{}}
1488 \newcommand\pxpic@err@unknown@file[1]
1489 {\PackageError{pxpic}{Unknown file value `#1'}{}}
1490 \newcommand\pxpic@err@file@not@found[1]
1491 {\PackageError{pxpic}{Couldn't find file #1}{}}
1492 % \end{macrocode}
1493 % \end{macro}
1494 %
1495 % \begin{macro}[internal]{\pxpic@experr}
1496 % This macro can be used to throw an error expandably. For this an undefined
1497 % control sequence \verb*|\pxpic Error:| is used. The group containing
1498 % \CS{expandafter} keeps the definition of \verb*|\pxpic Error:| local (it is
1499 % \CS{relax} after the \CS{csname}) so that it is undefined when it's used.
1500 % The \CS{@firstofone} is needed to get the readable output (now the undefined
1501 % macro and actual message are always the same argument).
1502 % \begin{macrocode}
1503 \def\pxpic@experr#1%
1504 {%
1505 \long\def\pxpic@experr##1%
1506 {%
1507 \expandafter\expandafter\expandafter
1508 \pxpic@ifend
1509 \@firstofone{#1##1.}%
1510 \pxpic@end
1511 }%
1512 }
1513 \begingroup\expandafter\endgroup
1514 \expandafter\pxpic@experr\csname pxpic Error:\endcsname
1515 % \end{macrocode}
1516 % \end{macro}
1517 %
1518 % \begin{macro}[internal]{\pxpic@experr@noval}
1519 % With the expandable error throwing mechanism out of the way, the following
1520 % is straight forward again.
1521 % \begin{macrocode}
1522 \newcommand\pxpic@experr@noval[1]
1523 {\pxpic@experr{Missing colour definition for `#1'}}
1524 % \end{macrocode}
1525 % \end{macro}
1526 %
1527 %^^A=<<
1528 %
1529 % \gobbledocstriptag
1530 %</pkg>
1531 %
1532 % \end{implementation}^^A=<<
1533 %
1534 % \clearpage
1535 % \PrintIndex
1536 %
1537 \endinput
1538 %
1539 ^^A vim: ft=tex fdm=marker fmr=>>=,=<<