%% %% This is file `docshots.sty', %% generated with the docstrip utility. %% %% The original source files were: %% %% docshots.dtx (with options: `package') %% (The MIT License) %% %% Copyright (c) 2021-2022 Yegor Bugayenko %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the 'Software'), to deal %% in the Software without restriction, including without limitation the rights %% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell %% copies of the Software, and to permit persons to whom the Software is %% furnished to do so, subject to the following conditions: %% %% The above copyright notice and this permission notice shall be included in all %% copies or substantial portions of the Software. %% %% THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR %% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, %% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE %% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER %% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, %% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE %% SOFTWARE. \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{docshots} [2022-11-20 0.3.1 TeX Samples Next to Their PDF Snapshots in DTX] \RequirePackage{iexec} \RequirePackage{fancyvrb} \RequirePackage{xcolor} \RequirePackage{graphicx} \RequirePackage{tikz} \RequirePackage{pgfopts} \RequirePackage{ifluatex} \RequirePackage{ifxetex} \def\docshots@log{} \pgfkeys{ /docshots/.cd, dtx/.store in=\docshots@dtx, log/.code=\def\docshots@log{log}, nocrop/.code=\def\docshots@nocrop{}, lstinputlisting/.store in=\docshots@lstinputlisting, inputminted/.store in=\docshots@inputminted, tmpdir/.store in=\docshots@tmpdir, tmpdir/.default=_docshots\ifxetex-xe\else\ifluatex-lua\fi\fi, small/.store in=\docshots@small, tiny/.store in=\docshots@tiny, runs/.store in=\docshots@runs, runs/.default=1, pdflatex/.store in=\docshots@pdflatex, pdflatex/.default=pdflatex, gs/.store in=\docshots@gs, gs/.default=gs, pdfcrop/.store in=\docshots@pdfcrop, pdfcrop/.default=pdfcrop, margin/.store in=\docshots@margin, margin/.default=5, hspace/.store in=\docshots@hspace, hspace/.default=.05\linewidth, left/.store in=\docshots@left, left/.default=.3\linewidth, right/.store in=\docshots@right, right/.default=.55\linewidth, tmpdir,pdflatex,gs,pdfcrop,margin,hspace,left,right,runs } \ProcessPgfOptions{/docshots} \iexec[\docshots@log,quiet]{"\docshots@pdflatex" --version}% \ifdefined\docshots@nocrop\else% \iexec[\docshots@log,quiet]{"\docshots@pdfcrop" --version}% \fi% \iexec[\docshots@log,quiet]{"\docshots@gs" --version}% \iexec[null]{mkdir -p "\docshots@tmpdir/\jobname"}% \RequirePackage{pdftexcmds} \makeatletter\newcommand\docshots@mdfive[1]{\pdf@filemdfivesum{#1}}\makeatother \makeatletter\newenvironment{docshot} {\VerbatimEnvironment\begin{VerbatimOut} {\docshots@tmpdir/\jobname/verbatim.tex}} {\end{VerbatimOut}% \ifdefined\docshots@dtx% \iexec[null]{perl -i -0777pe "s/(\\n|^)\\x{25}\\s?/\\1/g" \docshots@tmpdir/\jobname/verbatim.tex}% \fi% \def\hash{\docshots@mdfive{\docshots@tmpdir/\jobname/verbatim.tex}}% \IfFileExists{\docshots@tmpdir/\jobname/\hash.pdf} {\message{docshots: Won't render, the PDF '\docshots@tmpdir/\jobname/\hash.pdf' already exists^^J}} {\iexec[\docshots@log,quiet]{cp "\docshots@tmpdir/\jobname/verbatim.tex" "\docshots@tmpdir/\jobname/\hash.tex"}% \foreach \n in {1,...,\docshots@runs}{% \iexec[\docshots@log, stdout=\docshots@tmpdir/\jobname/\hash.stdout, exit=\docshots@tmpdir/\jobname/\hash.ret, quiet,trace]{cd "\docshots@tmpdir/\jobname" && "\docshots@pdflatex" -interaction=errorstopmode -halt-on-error -shell-escape \hash.tex}% \ifnum\n=1\else% \message{docshots: pdflatex run no.\n^^J}% \fi% \IfFileExists{\docshots@tmpdir/\jobname/after.sh} {\iexec[\docshots@log,quiet]{chmod a+x "\docshots@tmpdir/\jobname/after.sh"} \iexec[\docshots@log,quiet]{cd "\docshots@tmpdir/\jobname" && ./after.sh \n\space \hash\space \hash.tex}} {}}}% \iexec[\docshots@log,quiet]{rm -f "\docshots@tmpdir/\jobname/after.sh"} \IfFileExists{\docshots@tmpdir/\jobname/\hash.crop.pdf} {\message{docshots: Won't pdfcrop, the PDF '\docshots@tmpdir/\jobname/\hash.crop.pdf' already exists^^J}} {\ifdefined\docshots@nocrop \iexec[\docshots@log,quiet]{cp "\docshots@tmpdir/\jobname/\hash.pdf" "\docshots@tmpdir/\jobname/\hash.crop.pdf"}% \else% \iexec[\docshots@log,quiet]{"\docshots@pdfcrop" --margins 0 "\docshots@tmpdir/\jobname/\hash.pdf" "\docshots@tmpdir/\jobname/\hash.crop.pdf"}% \fi}% \fvset{numbers=left,numbersep=3pt}% \fvset{frame=leftline,framerule=.2pt,rulecolor=\color{gray}}% \fvset{samepage=true}% \fvset{baselinestretch=1}% \ifdefined\docshots@small% \fvset{fontsize=\small}% \fi% \ifdefined\docshots@tiny% \fvset{fontsize=\scriptsize}% \fi% \begingroup% \par% \tikz[baseline=(a.north)] \node (a) [draw=gray,inner sep=\docshots@margin, line width=.2pt] {\includegraphics[width=\docshots@left] {\docshots@tmpdir/\jobname/\hash.crop.pdf}};% \hspace{\docshots@hspace}% \begin{minipage}[t]{\docshots@right}% \vspace{0pt}% \ifdefined\docshots@lstinputlisting% \expandafter\lstinputlisting\expandafter[\docshots@opts] {\docshots@tmpdir/\jobname/\hash.tex}% \else\ifdefined\docshots@inputminted% \expandafter\inputminted\expandafter[\docshots@opts] {\docshots@inputminted} {\docshots@tmpdir/\jobname/\hash.tex}% \else% \expandafter\VerbatimInput\expandafter[\docshots@opts] {\docshots@tmpdir/\jobname/\hash.tex}% \fi\fi% \vspace{0pt}% \end{minipage}% \par% \endgroup% \docshotOptions{}% }\makeatother \makeatletter\newcommand\docshotPrerequisite[1]{ \iexec[\docshots@log,quiet]{cp #1 "\docshots@tmpdir/\jobname"}% \message{docshots: File '#1' copied to '\docshots@tmpdir/\jobname/#1'^^J}% }\makeatother \makeatletter\newcommand\docshotAfter[1]{ \iexec[\docshots@log,quiet]{/bin/echo -n '\detokenize{#1}' > "\docshots@tmpdir/\jobname/after.sh"}% \message{docshots: File '\docshots@tmpdir/\jobname/after.sh' created^^J}% }\makeatother \makeatletter \gdef\docshots@opts{} \newcommand\docshotOptions[1]{% \gdef\docshots@opts{#1}% }\makeatother \endinput %% %% End of file `docshots.sty'.