Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 % (The MIT License)
3 %
4 % Copyright (c) 2021-2024 Yegor Bugayenko
5 %
6 % Permission is hereby granted, free of charge, to any person obtaining a copy
7 % of this software and associated documentation files (the 'Software'), to deal
8 % in the Software without restriction, including without limitation the rights
9 % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 % copies of the Software, and to permit persons to whom the Software is
11 % furnished to do so, subject to the following conditions:
12 %
13 % The above copyright notice and this permission notice shall be included in all
14 % copies or substantial portions of the Software.
15 %
16 % THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 % SOFTWARE.
23 % \fi
24
25 % \CheckSum{0}
26 %
27 % \CharacterTable
28 % {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
29 % 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
30 % Digits \0\1\2\3\4\5\6\7\8\9
31 % Exclamation \! Double quote \" Hash (number) \#
32 % Dollar \$ Percent \% Ampersand \&
33 % Acute accent \' Left paren \( Right paren \)
34 % Asterisk \* Plus \+ Comma \,
35 % Minus \- Point \. Solidus \/
36 % Colon \: Semicolon \; Less than \<
37 % Equals \= Greater than \> Question mark \?
38 % Commercial at \@ Left bracket \[ Backslash \\
39 % Right bracket \] Circumflex \^ Underscore \_
40 % Grave accent \` Left brace \{ Vertical bar \|
41 % Right brace \} Tilde \~}
42
43 % \GetFileInfo{docshots.dtx}
44 % \DoNotIndex{\endgroup,\begingroup,\let,\else,\s,\n,\r,\\,\1,\fi}
45
46 % \iffalse
47 %<*driver>
48 \ProvidesFile{docshots.dtx}
49 %</driver>
50 %<package>\NeedsTeXFormat{LaTeX2e}
51 %<package>\ProvidesPackage{docshots}
52 %<*package>
53 [2024-02-02 0.4.3 TeX Samples Next to Their PDF Snapshots in DTX]
54 %</package>
55 %<*driver>
56 \documentclass{ltxdoc}
57 \usepackage[tt=false, type1=true]{libertine}
58 \usepackage{microtype}
59 \AddToHook{env/verbatim/begin}{\microtypesetup{protrusion=false}}
60 \usepackage[dtx]{docshots}
61 \usepackage{href-ul}
62 \usepackage{xcolor}
63 \PageIndex
64 \EnableCrossrefs
65 \CodelineIndex
66 \RecordChanges
67 \begin{document}
68 \DocInput{docshots.dtx}
69 \PrintChanges
70 \PrintIndex
71 \end{document}
72 %</driver>
73 % \fi
74
75 % \title{|docshots|: \LaTeX{} Package that Renders \\ \TeX{} Samples Next to Their \\ PDF Snapshots\thanks{The sources are in GitHub at \href{https://github.com/yegor256/docshots}{yegor256/docshots}}}
76 % \author{Yegor Bugayenko \\ \texttt{[email protected]}}
77 % \date{\filedate, \fileversion}
78 %
79 % \maketitle
80 %
81 % \textbf{\color{red}NB!}
82 % This package doesn't work on Windows!
83 % Also, you must run \TeX{} processor with |--shell-escape| option.
84 % Also, you must have
85 % |pdlaftex|,
86 % \href{https://www.perl.org}{Perl},
87 % \href{https://www.ghostscript.com}{Ghostscript},
88 % and \href{https://ctan.org/pkg/pdfcrop}{pdfcrop}
89 % installed.
90
91 % \section{Introduction}
92 %
93 % When you want to demonstrate to the readers of your documentation
94 % how to use certain \TeX{} commands, the best way would be
95 % to show exactly how the entire document will be rendered in PDF,
96 % using a subprocess that would render it (via |pdflatex|, for example).
97 % To \href{https://tex.stackexchange.com/questions/661027}{my best}
98 % knowledge, there were no packages that would allow
99 % you do exactly this. That's why I created this simple package.
100
101 % For example, this code:
102 %\iffalse%
103 %<*verb>%
104 %\fi%
105 \begin{verbatim}
106 \begin{docshot}
107 \documentclass{article}
108 \usepackage{xcolor}
109 \pagestyle{empty}
110 \begin{document}
111 Hello, {\color{orange}\LaTeX}!
112 \end{document}
113 \end{docshot}
114 \end{verbatim}
115 %\iffalse
116 %</verb>
117 %\fi
118 % is rendered as such:
119 % \begin{docshot}
120 % \documentclass{article}
121 % \usepackage{xcolor}
122 % \pagestyle{empty}
123 % \begin{document}
124 % Hello, {\color{orange}\LaTeX}!
125 % \end{document}
126 % \end{docshot}
127
128 % Here is a more complex example:
129 % \begin{docshot}
130 % \documentclass{article}
131 % \usepackage{tikz}
132 % \pagestyle{empty}
133 % \begin{document}
134 % \begin{tikzpicture}
135 % \node [circle,draw] (v0) {$v_0$};
136 % \node [circle,draw=orange,thick,
137 % below right of=v0] (v1) {$v_1$};
138 % \draw [->] (v0) -- (v1);
139 % \end{tikzpicture}
140 % \end{document}
141 % \end{docshot}
142
143 % The picture you see on the left side is rendered by a subprocess
144 % executing |pdflatex| with the |.tex| content taken from the source file.
145 % After a successful processing of \TeX{} sources, we use
146 % \href{https://ctan.org/pkg/pdfcrop}{pdfcrop} to trim the document.
147
148 % We execute |pdflatex| with |-interaction=batchmode| and |-halt-on-error| options.
149 % This means that
150 % \TeX{} processing will stop at the first error. Check your \TeX{} log
151 % to understand what went wrong.
152
153 % When you render a text instead of a single picture, it's recommended to use
154 % \href{https://ctan.org/pkg/geometry}{geometry} package to change the size
155 % of the page:
156 % \begin{docshot}
157 % \documentclass{article}
158 % \usepackage[paperwidth=2in,
159 % paperheight=2.3in]{geometry}
160 % \begin{document}
161 % ``There is no sadder thing than
162 % a young pessimist, except an old
163 % pessimist'' --- \emph{Mark Twain}
164 % \end{document}
165 % \end{docshot}
166 % You can also use |\pagestyle{empty}| as was done in previous docshots.
167
168 % \section{Package Options}
169
170 % \DescribeMacro{pdflatex}
171 % The default command line tool for turning |.tex| into
172 % |.pdf| is |pdflatex|. However, you can change that by using |pdflatex| package option,
173 % for example:
174 %\iffalse
175 %<*verb>
176 %\fi
177 \begin{verbatim}
178 \documentclass{article}
179 \usepackage[pdflatex=/usr/local/bin/pdflatex]{docshot}
180 \begin{document}
181 \begin{docshot}
182 Hello, world!
183 \end{docshot}
184 \end{document}
185 \end{verbatim}
186 %\iffalse
187 %</verb>
188 %\fi
189
190 % \DescribeMacro{gs}
191 % The default location of Ghostscript is just |gs|.
192 % You can change that by using |gs| package option,
193 % for example:
194 %\iffalse
195 %<*verb>
196 %\fi
197 \begin{verbatim}
198 \usepackage[gs=/usr/bin/ghostscript]{docshot}
199 \end{verbatim}
200 %\iffalse
201 %</verb>
202 %\fi
203
204 % \DescribeMacro{pdfcrop}
205 % The default location of |pdfcrop| is just |pdfcrop|.
206 % You can change that by using |pdfcrop| package option,
207 % for example:
208 %\iffalse
209 %<*verb>
210 %\fi
211 \begin{verbatim}
212 \usepackage[pdfcrop=/bin/pdfcrop]{docshot}
213 \end{verbatim}
214 %\iffalse
215 %</verb>
216 %\fi
217
218 % \DescribeMacro{margin}
219 % When we crop the PDF rendered, we leave a margin around the content. The
220 % default value may be changed by the package option |margin|:
221 %\iffalse
222 %<*verb>
223 %\fi
224 \begin{verbatim}
225 \usepackage[margin=10]{docshot}
226 \end{verbatim}
227 %\iffalse
228 %</verb>
229 %\fi
230
231 % \DescribeMacro{nocrop}
232 % You may disable cropping with the help of |nocrop| option:
233 %\iffalse
234 %<*verb>
235 %\fi
236 \begin{verbatim}
237 \usepackage[nocrop]{docshot}
238 \end{verbatim}
239 %\iffalse
240 %</verb>
241 %\fi
242
243 % \DescribeMacro{hspace}
244 % The horizontal distance between the image and its verbatim \TeX{} source
245 % may be configured via |hspace| package option:
246 %\iffalse
247 %<*verb>
248 %\fi
249 \begin{verbatim}
250 \usepackage[hspace=1em]{docshot}
251 \end{verbatim}
252 %\iffalse
253 %</verb>
254 %\fi
255
256 % \DescribeMacro{left}
257 % \DescribeMacro{right}
258 % The default width of the image may be changed by |left| option, while
259 % the width of the verbatim \TeX{} source may be modified by |right| option:
260 %\iffalse
261 %<*verb>
262 %\fi
263 \begin{verbatim}
264 \usepackage[left=2in,right=.5\linewidth]{docshot}
265 \end{verbatim}
266 %\iffalse
267 %</verb>
268 %\fi
269
270 % \DescribeMacro{dtx}
271 % If you use this package inside |.dtx| documentation, add |dtx| package option. Thanks
272 % to this option all comment symbols will be removed from line starts:
273 %\iffalse
274 %<*verb>
275 %\fi
276 \begin{verbatim}
277 \usepackage[dtx]{docshot}
278 \end{verbatim}
279 %\iffalse
280 %</verb>
281 %\fi
282
283 % \DescribeMacro{tmpdir}
284 % The default location of temp files is |_docshots|. You can change this using |tmpdir| option:
285 %\iffalse
286 %<*verb>
287 %\fi
288 \begin{verbatim}
289 \usepackage[tmpdir=/tmp/foo]{docshot}
290 \end{verbatim}
291 %\iffalse
292 %</verb>
293 %\fi
294
295 % \DescribeMacro{runs}
296 % By default, we run |pdflatex| just once for each docshot. You can change this number using the package
297 % option |runs|. This may be helpful if you need Bib\TeX{} processing, for example:
298 %\iffalse
299 %<*verb>
300 %\fi
301 \begin{verbatim}
302 \usepackage[runs=3]{docshot}
303 \end{verbatim}
304 %\iffalse
305 %</verb>
306 %\fi
307
308 % \DescribeMacro{small}
309 % \DescribeMacro{tiny}
310 % You don't have too much freedom in formatting of verbatim texts, but you can make
311 % their font a bit smaller using |small| package option. You can also make it very
312 % small using |tiny| option:
313 %\iffalse
314 %<*verb>
315 %\fi
316 \begin{verbatim}
317 \usepackage[small]{docshot}
318 \end{verbatim}
319 %\iffalse
320 %</verb>
321 %\fi
322
323 % \DescribeMacro{log}
324 % With |log| option you can make us print all possible logs to the main \TeX{} log.
325 % By default, we don't do this and you won't see the output of |pdflatex| compilation, for example.
326 % Just use it like this:
327 %\iffalse
328 %<*verb>
329 %\fi
330 \begin{verbatim}
331 \usepackage[log]{docshot}
332 \end{verbatim}
333 %\iffalse
334 %</verb>
335 %\fi
336
337 % \DescribeMacro{inputminted}
338 % By default, we render the verbatim text using |\VerbatimInput| command. You
339 % can change that and make us use |\inputminted|
340 % from \href{https://ctan.org/pkg/minted}{minted} package instead, for example:
341 %\iffalse
342 %<*verb>
343 %\fi
344 \begin{verbatim}
345 \usepackage{minted}
346 \setminted[java]{frame=lines,framesep=2mm}
347 \usepackage[inputminted=java]{docshot}
348 \end{verbatim}
349 %\iffalse
350 %</verb>
351 %\fi
352
353 % \DescribeMacro{lstinputlisting}
354 % By default, we render the verbatim text using |\VerbatimInput| command. You
355 % can change that and make us use |\lstinputlisting| from
356 % \href{https://ctan.org/pkg/listings}{listings} package instead, for example:
357 %\iffalse
358 %<*verb>
359 %\fi
360 \begin{verbatim}
361 \usepackage{listings}
362 \lstset{basicstyle=\small}
363 \usepackage[lstinputlisting]{docshot}
364 \end{verbatim}
365 %\iffalse
366 %</verb>
367 %\fi
368
369 % \section{Fine-tuning Options}
370
371 % \DescribeMacro{\docshotOptions}
372 % By default, we render the verbatim text using |\VerbatimInput| command with
373 % no options. You can add your options using |\docshotOptions| command:
374 %\iffalse
375 %<*verb>
376 %\fi
377 \begin{verbatim}
378 \docshotOptions{firstline=4}
379 \begin{docshot}
380 ...
381 \end{docshot}
382 \end{verbatim}
383 %\iffalse
384 %</verb>
385 %\fi
386
387 % The options will be cleaned up by the first render of a docshot.
388
389 % \section{Prerequisites}
390
391 % \DescribeMacro{\docshotPrerequisite}
392 % \changes{0.0.3}{2022/10/14}{The command is added to enable copying of supplementary files into docshots snippets processing directory.}
393 % If you need some files to be present next to the |.tex| snippet while
394 % it's rendered by |pdflatex|, you can use |\docshotPrerequisite| with
395 % a single mandatory argument. The argument is the name of a file you need
396 % to be copied from current directory to the temporary directory, where
397 % all snippets are rendered. The command can be used either in the body
398 % of the document or in the preamble --- it doesn't matter, as long as
399 % it shows up before the docshot that needs the prerequisite. For example:
400 %\iffalse
401 %<*verb>
402 %\fi
403 \begin{verbatim}
404 \documentclass{article}
405 \usepackage{docshot}
406 \docshotPrerequisite{duck.jpg}
407 \begin{document}
408 \begin{docshot}
409 \documentclass{article}
410 \usepackage{graphicx}
411 \pagestyle{empty}
412 \begin{document}
413 This is my favorite picture of a duck:
414 \includegraphics[width=2in]{duck.jpg}
415 \end{document}
416 \end{docshot}
417 \end{document}
418 \end{verbatim}
419 %\iffalse
420 %</verb>
421 %\fi
422
423 % \DescribeMacro{\docshotAfter}
424 % If you need something to happen after each |pdflatex| run of a docshot, you may use
425 % |\docshotAfter| command right before |docshot| environment. For example, you have a bibliography file that
426 % you want to be visible for all snippets and you want all of them to
427 % run \href{https://ctan.org/pkg/biber}{biber} in order to process citations:
428 %\iffalse
429 %<*verb>
430 %\fi
431 \begin{verbatim}
432 \documentclass{article}
433 \usepackage{docshot}
434 \docshotPrerequisite{main.bib}
435 \begin{document}
436 \docshotAfter{biber $2}
437 \begin{docshot}
438 \documentclass{acmart}
439 \usepackage[natbib=true]{biblatex}
440 \addbibresource{main.bib}
441 \pagestyle{empty}
442 \begin{document}
443 You must read the book of \citet{knuth1984}.
444 \printbibliography
445 \end{document}
446 \end{docshot}
447 \end{document}
448 \end{verbatim}
449 %\iffalse
450 %</verb>
451 %\fi
452 % The script you specify in the first argument of |\docshotAfter| will get
453 % three arguments when it runs:
454 % \begin{description}\setlength\itemsep{0em}
455 % \item[|\$1|] the cycle of |pdflatex| processing (1, 2, ...),
456 % \item[|\$2|] the hash of the snippet,
457 % \item[|\$3|] the name of the |.tex| file.
458 % \end{description}
459 % |$2| is basically equals to |$1| with an
460 % attached |.tex| suffix. |\docshotAfter| applies only to the first |docshot|
461 % environment that goes after it! You must specify |\docshotAfter| before
462 % each |docshot| where you want such post-processing to happen.
463
464 % \StopEventually{}
465
466 % \section{Implementation}
467 % \changes{0.0.1}{2022/10/09}{Initial version}
468
469 % First, we include \href{https://ctan.org/pkg/iexec}{iexec}
470 % in order to execute shell commands, such as |pdflatex| and |pdfcrop|:
471 % \begin{macrocode}
472 \RequirePackage{iexec}
473 % \end{macrocode}
474
475 % Then, we include \href{https://ctan.org/pkg/fancyvrb}{fancyvrb}
476 % in order to render verbatim texts:
477 % \begin{macrocode}
478 \RequirePackage{fancyvrb}
479 % \end{macrocode}
480
481 % Then, we include \href{https://ctan.org/pkg/xcolor}{xcolor}
482 % in order to make borders gray:
483 % \begin{macrocode}
484 \RequirePackage{xcolor}
485 % \end{macrocode}
486
487 % Then, we include \href{https://ctan.org/pkg/graphicx}{graphicx}
488 % in order to be able to use |\includegraphics| command:
489 % \begin{macrocode}
490 \RequirePackage{graphicx}
491 % \end{macrocode}
492
493 % Then, we include \href{https://ctan.org/pkg/tikz}{tikz}
494 % in order to be able to position elements:
495 % \begin{macrocode}
496 \RequirePackage{tikz}
497 % \end{macrocode}
498
499 % Then, we process package options with the help of \href{https://ctan.org/pkg/pgfopts}{pgfopts}:
500 % \changes{0.0.4}{2022/10/18}{Package options "lstinputlisting" and "inputminted" introduced to enable printing of verbatim text either via listings or minted packages.}
501 % \changes{0.0.5}{2022/10/24}{Package option "log" added, which enables detailed logging via exec. By default, there is no logging at all.}
502 % \changes{0.2.0}{2022/10/26}{New package option "nocrop" added to allow disabling of "pdfcrop" execution.}
503 % \begin{macrocode}
504 \RequirePackage{pgfopts}
505 \RequirePackage{ifluatex}
506 \RequirePackage{ifxetex}
507 \def\docshots@log{}
508 \pgfkeys{
509 /docshots/.cd,
510 dtx/.store in=\docshots@dtx,
511 log/.code=\def\docshots@log{log},
512 nocrop/.code=\def\docshots@nocrop{},
513 lstinputlisting/.store in=\docshots@lstinputlisting,
514 inputminted/.store in=\docshots@inputminted,
515 tmpdir/.store in=\docshots@tmpdir,
516 tmpdir/.default=_docshots\ifxetex-xe\else\ifluatex-lua\fi\fi,
517 small/.store in=\docshots@small,
518 tiny/.store in=\docshots@tiny,
519 runs/.store in=\docshots@runs,
520 runs/.default=1,
521 pdflatex/.store in=\docshots@pdflatex,
522 pdflatex/.default=pdflatex,
523 gs/.store in=\docshots@gs,
524 gs/.default=gs,
525 pdfcrop/.store in=\docshots@pdfcrop,
526 pdfcrop/.default=pdfcrop,
527 margin/.store in=\docshots@margin,
528 margin/.default=5,
529 hspace/.store in=\docshots@hspace,
530 hspace/.default=.05\linewidth,
531 left/.store in=\docshots@left,
532 left/.default=.3\linewidth,
533 right/.store in=\docshots@right,
534 right/.default=.55\linewidth,
535 tmpdir,pdflatex,gs,pdfcrop,margin,hspace,left,right,runs
536 }
537 \ProcessPgfOptions{/docshots}
538 % \end{macrocode}
539
540 % Then, we print the version of |pdflatex| to \TeX{} log:
541 % \begin{macrocode}
542 \iexec[\docshots@log,quiet]{"\docshots@pdflatex" --version}%
543 % \end{macrocode}
544
545 % Then, we print the version of \href{https://ctan.org/pkg/pdfcrop}{pdfcrop} to \TeX{} log:
546 % \begin{macrocode}
547 \ifdefined\docshots@nocrop\else%
548 \iexec[\docshots@log,quiet]{"\docshots@pdfcrop" --version}%
549 \fi%
550 % \end{macrocode}
551
552 % Then, we print the version of |ghostscript| to \TeX{} log:
553 % \begin{macrocode}
554 \iexec[\docshots@log,quiet]{"\docshots@gs" --version}%
555 % \end{macrocode}
556
557 % Then, we make a directory where all temporary files will be kept:
558 % \begin{macrocode}
559 \iexec[null]{mkdir -p "\docshots@tmpdir/\jobname"}%
560 % \end{macrocode}
561
562 % \begin{macro}{\docshots@mdfive}
563 % \changes{0.1.1}{2022/10/26}{New supplementary command added to calculate MD5 sum of a file.}
564 % Then, we define a command for MD5 hash calculating of a file, with
565 % the help of \href{https://ctan.org/pkg/pdftexcmds}{pdftexcmds}:
566 % \begin{macrocode}
567 \RequirePackage{pdftexcmds}
568 \makeatletter
569 \newcommand\docshots@mdfive[1]{\pdf@filemdfivesum{#1}}
570 \makeatother
571 % \end{macrocode}
572 % \end{macro}
573
574 % \begin{macro}{docshot}
575 % Then, we define |docshot| environment:
576 % \begin{macrocode}
577 \makeatletter
578 \newenvironment{docshot}
579 {\VerbatimEnvironment\begin{VerbatimOut}
580 {\docshots@tmpdir/\jobname/verbatim.tex}}
581 {\end{VerbatimOut}%
582 % \end{macrocode}
583 % If we are in |dtx| mode, leading percent characters must be removed:
584 % \changes{0.3.1}{2022/11/20}{A bug fixed, now handling of leading percentage symbols is done right.}
585 % \begin{macrocode}
586 \ifdefined\docshots@dtx%
587 \iexec[null]{perl -i -0777pe "s/(\\n|^)\\x{25}\\s?/\\1/g"
588 \docshots@tmpdir/\jobname/verbatim.tex}%
589 \fi%
590 % \end{macrocode}
591 % We calculate MD5 hashsum of the file content:
592 % \begin{macrocode}
593 \def\hash{\docshots@mdfive{\docshots@tmpdir/\jobname/verbatim.tex}}%
594 % \end{macrocode}
595 % If the PDF with the required name already exists, we ignore this step.
596 % Otherwise, we copy |verbatim.tex| into new file and run |pdflatex|:
597 % \changes{0.1.0}{2022/10/26}{The output is saved to a hash-named file, for better uniqueness of temporary files.}
598 % \changes{0.4.0}{2022/11/29}{Now, \TeX output has a log message with the number of the line in the source file, which we render.}
599 % \begin{macrocode}
600 \IfFileExists{\docshots@tmpdir/\jobname/\hash.pdf}
601 {\message{docshots: Won't render,
602 the PDF '\docshots@tmpdir/\jobname/\hash.pdf' already exists^^J}}
603 {\iexec[\docshots@log,quiet]{cp "\docshots@tmpdir/\jobname/verbatim.tex"
604 "\docshots@tmpdir/\jobname/\hash.tex"}%
605 \message{docshots: rendering at line no. \the\inputlineno^^J}%
606 \foreach \n in {1,...,\docshots@runs}{%
607 \iexec[\docshots@log,
608 stdout=\docshots@tmpdir/\jobname/\hash.stdout,
609 exit=\docshots@tmpdir/\jobname/\hash.ret,
610 quiet,trace]{cd "\docshots@tmpdir/\jobname" &&
611 "\docshots@pdflatex"
612 -interaction=errorstopmode
613 -halt-on-error
614 -shell-escape
615 \hash.tex}%
616 \ifnum\n=1\else%
617 \message{docshots: pdflatex run no.\n^^J}%
618 \fi%
619 \IfFileExists{\docshots@tmpdir/\jobname/after.sh}
620 {\iexec[\docshots@log,quiet]{chmod a+x
621 "\docshots@tmpdir/\jobname/after.sh"}
622 \iexec[\docshots@log,quiet]{cd "\docshots@tmpdir/\jobname" &&
623 ./after.sh \n\space \hash\space \hash.tex}}
624 {}}}%
625 % \end{macrocode}
626 % Here we delete |after.sh| which may exist here after the last
627 % compilation of |pdflatex|:
628 % \begin{macrocode}
629 \iexec[\docshots@log,quiet]{rm -f "\docshots@tmpdir/\jobname/after.sh"}
630 % \end{macrocode}
631 % If a cropped version of the PDF with the required name already exists, we ignore this step.
632 % Otherwise, we ask |pdfcrop| to crop the PDF:
633 % \begin{macrocode}
634 \IfFileExists{\docshots@tmpdir/\jobname/\hash.crop.pdf}
635 {\message{docshots: Won't pdfcrop,
636 the PDF '\docshots@tmpdir/\jobname/\hash.crop.pdf'
637 already exists^^J}}
638 {\ifdefined\docshots@nocrop
639 \iexec[\docshots@log,quiet]{cp
640 "\docshots@tmpdir/\jobname/\hash.pdf"
641 "\docshots@tmpdir/\jobname/\hash.crop.pdf"}%
642 \else%
643 \iexec[\docshots@log,quiet]{"\docshots@pdfcrop"
644 --margins 0
645 "\docshots@tmpdir/\jobname/\hash.pdf"
646 "\docshots@tmpdir/\jobname/\hash.crop.pdf"}%
647 \fi}%
648 \message{docshots: the PDF is ready from line no. \the\inputlineno^^J}%
649 % \end{macrocode}
650 % Finally, we render the two-column content:
651 % \begin{macrocode}
652 \begingroup%
653 \par%
654 \tikz[baseline=(a.north)]
655 \node (a) [draw=gray,inner sep=\docshots@margin,
656 line width=.2pt]
657 {\includegraphics[width=\docshots@left]
658 {\docshots@tmpdir/\jobname/\hash.crop.pdf}};%
659 \hspace{\docshots@hspace}%
660 \begin{minipage}[t]{\docshots@right}%
661 \vspace{0pt}%
662 \ifdefined\docshots@lstinputlisting%
663 \ifdefined\docshots@opts%
664 \expandafter\lstset\expandafter{\docshots@opts}%
665 \fi%
666 \lstinputlisting{\docshots@tmpdir/\jobname/\hash.tex}%
667 \else\ifdefined\docshots@inputminted%
668 \expandafter\inputminted\expandafter[\docshots@opts]
669 {\docshots@inputminted}
670 {\docshots@tmpdir/\jobname/\hash.tex}%
671 \else%
672 \fvset{numbers=left,numbersep=3pt}%
673 \fvset{frame=leftline,framerule=.2pt,rulecolor=\color{gray}}%
674 \fvset{samepage=true}%
675 \fvset{commandchars=none}%
676 \fvset{baselinestretch=1}%
677 \ifdefined\docshots@small%
678 \fvset{fontsize=\small}%
679 \fi%
680 \ifdefined\docshots@tiny%
681 \fvset{fontsize=\scriptsize}%
682 \fi%
683 \ifdefined\docshots@opts%
684 \expandafter\fvset\expandafter{\docshots@opts}%
685 \fi%
686 \VerbatimInput{\docshots@tmpdir/\jobname/\hash.tex}%
687 \fi\fi%
688 \vspace{0pt}%
689 \end{minipage}%
690 \par%
691 \endgroup%
692 \docshotOptions{}%
693 }
694 \makeatother
695 % \end{macrocode}
696 % \end{macro}
697
698 % \begin{macro}{\docshotPrerequisite}
699 % Then, we define |\docshotPrerequisite| command:
700 % \begin{macrocode}
701 \makeatletter
702 \newcommand\docshotPrerequisite[1]{
703 \iexec[\docshots@log,quiet]{cp #1 "\docshots@tmpdir/\jobname"}%
704 \message{docshots: File '#1' copied to
705 '\docshots@tmpdir/\jobname/#1'^^J}%
706 }
707 \makeatother
708 % \end{macrocode}
709 % \end{macro}
710
711 % \begin{macro}{\docshotAfter}
712 % Then, we define |\docshotAfter| command:
713 % \begin{macrocode}
714 \makeatletter
715 \newcommand\docshotAfter[1]{
716 \iexec[\docshots@log,quiet]{/bin/echo -n '\detokenize{#1}'
717 > "\docshots@tmpdir/\jobname/after.sh"}%
718 \message{docshots: File
719 '\docshots@tmpdir/\jobname/after.sh' created^^J}%
720 }
721 \makeatother
722 % \end{macrocode}
723 % \end{macro}
724
725 % \begin{macro}{\docshotOptions}
726 % Finally, we define |\docshotOptions| command:
727 % \changes{0.3.0}{2022/11/10}{New command introduced to help specify custom options for verbatim environments.}
728 % \begin{macrocode}
729 \makeatletter
730 \gdef\docshots@opts{}
731 \newcommand\docshotOptions[1]{%
732 \gdef\docshots@opts{#1}%
733 }
734 \makeatother
735 % \end{macrocode}
736 % \end{macro}
737
738 % \begin{macrocode}
739 \endinput
740 % \end{macrocode}
741
742 % \Finale
743
744 %\clearpage
745
746 %\PrintChanges
747 %\clearpage
748 %\PrintIndex