%% %% This is file `graphicscache.sty', %% generated with the docstrip utility. %% %% The original source files were: %% %% graphicscache.dtx (with options: `package') %% %% This is a generated file. %% %% Copyright (C) 2021 by Max Schwarz %% based on the sty2dtx template by Scott Pakin . %% %% This file may be distributed and/or modified under the conditions of %% the BSD 3-clause license (see LICENSE). %% \NeedsTeXFormat{LaTeX2e}[1999/12/01] \ProvidesPackage{graphicscache} [2021/08/02 v0.3 Cache includegraphics calls] \NeedsTeXFormat{LaTeX2e}[1994/06/01] \ProvidesPackage{graphicscache}[2018/10/02 Graphics Cache] \RequirePackage{graphicx} \RequirePackage{xstring} \RequirePackage{filemod} \RequirePackage{letltxmacro} \RequirePackage{pgfopts} \RequirePackage{ifplatform} \RequirePackage{pdftexcmds} \RequirePackage{ltxcmds} \newif\ifgraphicscache@render \newif\ifgraphicscache@compress \newif\ifgraphicscache@listing \newif\ifgraphicscache@hashshortnames \def\graphicscache@graphicsargs{} \newlength\graphicscache@tmplen \newcommand{\graphicscache@addarg}[1]{% \ifx\graphicscache@graphicsargs\empty \edef\graphicscache@graphicsargs{#1}% \else \edef\graphicscache@graphicsargs{\graphicscache@graphicsargs,#1}% \fi } \pgfkeys{ /graphicscache/.cd, render/.is if=graphicscache@render, render=true, cachedir/.store in=\graphicscache@cachedir, cachedir={graphicscache}, compress/.is choice, compress/false/.code={\graphicscache@compressfalse}, compress/jpeg/.code={\graphicscache@compresstrue \def\graphicscache@compress@mode{DCTEncode}}, compress/flat/.code={\graphicscache@compresstrue \def\graphicscache@compress@mode{FlatEncode}}, compress=jpeg, dpi/.store in=\graphicscache@dpi, dpi=300, qfactor/.store in=\graphicscache@qfactor, qfactor={0.15}, hashshortnames/.is if=graphicscache@hashshortnames, hashshortnames=false, width/.code={% \setlength\graphicscache@tmplen{#1}% \graphicscache@addarg{width=\the\graphicscache@tmplen}% }, height/.code={% \setlength\graphicscache@tmplen{#1}% \graphicscache@addarg{height=\the\graphicscache@tmplen}% }, trim/.code={\graphicscache@addarg{trim=#1}}, clip/.code={\graphicscache@addarg{clip}}, angle/.code={% \edef\graphicscache@tmp{#1}% \graphicscache@addarg{angle=\graphicscache@tmp}% }, origin/.code={\graphicscache@addarg{origin=#1}}, keepaspectratio/.code={\graphicscache@addarg{keepaspectratio}}, scale/.code={% \edef\graphicscache@tmp{#1}% \graphicscache@addarg{scale=\graphicscache@tmp}% }, page/.code={% \edef\graphicscache@tmp{#1}% \graphicscache@addarg{page=\graphicscache@tmp}% }, listing/.is if=graphicscache@listing, listing=false, frame/.code={% \edef\graphicscache@tmp{#1}% \graphicscache@addarg{frame=\graphicscache@tmp}% }, valign/.code={% \edef\graphicscache@tmp{#1}% \graphicscache@addarg{valign=\graphicscache@tmp}% }, raise/.code={% \edef\graphicscache@tmp{#1}% \graphicscache@addarg{raise=\graphicscache@tmp}% }, } \ProcessPgfOptions{/graphicscache}\relax \ifdefined\graphicscache@inhibit \pgfkeys{/graphicscache/render=false}% \fi \ifgraphicscache@listing \newwrite\graphicscache@listout \immediate\openout\graphicscache@listout=\jobname.graphicscache \fi \newcommand{\graphicscache@dorender}{% \message{Rendering \graphicscache@outputhash: \graphicscache@fname\space with args: \graphicscache@graphicsargs\space (master file)}% \ifwindows \immediate\write18{md "\graphicscache@cachedir" 2>NUL}% \else \immediate\write18{mkdir -p "\graphicscache@cachedir"}% \fi \ifwindows \immediate\write18{del /q \graphicscache@cachedir\string\graphicscacheout.pdf} \immediate\write18{pdflatex -jobname graphicscacheout -interaction nonstopmode -output-directory "\graphicscache@cachedir" "\string\documentclass{standalone} \string\usepackage{graphicx} \string\usepackage[export]{adjustbox} \string\begin{document}\string\includegraphics[\graphicscache@graphicsargs]{\graphicscache@fname}\string\end{document}" }% \IfFileExists{\graphicscache@cachedir/graphicscacheout.pdf}{}{% \PackageError{graphicscache}{External pdflatex call failed (see above)}{}% \def\graphicscache@output{}% } \else \immediate\write18{pdflatex -jobname graphicscacheout -interaction nonstopmode -output-directory "\graphicscache@cachedir" '\string\documentclass{standalone} \string\usepackage{graphicx} \string\usepackage[export]{adjustbox} \string\begin{document}\string\includegraphics[\graphicscache@graphicsargs]{\graphicscache@fname}\string\end{document}' > /dev/null || rm "\graphicscache@cachedir/graphicscacheout.pdf" }% \fi \ifgraphicscache@compress \message{With compression: \graphicscache@compress@mode}% \ifwindows \immediate\write18{mgs -sOutputFile=\graphicscache@output\space -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -c ".setpdfwrite << /AutoFilterColorImages false /EncodeColorImages true /ColorImageFilter /\graphicscache@compress@mode\space /ColorImageDict << /ColorTransform 1 /QFactor \graphicscache@qfactor\space /Blend 1 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >> /ColorImageResolution \graphicscache@dpi\space /AutoFilterGrayImages false /EncodeGrayImages true /GrayImageFilter /\graphicscache@compress@mode\space /GrayImageDict << /ColorTransform 1 /QFactor \graphicscache@qfactor\space /Blend 1 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >> /GrayImageResolution \graphicscache@dpi\space >> setdistillerparams" -f \graphicscache@cachedir\string\graphicscacheout.pdf }% \else \immediate\write18{gs -sOutputFile=\graphicscache@output\space -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -c '.setpdfwrite << /AutoFilterColorImages false /EncodeColorImages true /ColorImageFilter /\graphicscache@compress@mode\space /ColorImageDict << /ColorTransform 1 /QFactor \graphicscache@qfactor\space /Blend 1 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >> /ColorImageResolution \graphicscache@dpi\space /AutoFilterGrayImages false /EncodeGrayImages true /GrayImageFilter /\graphicscache@compress@mode\space /GrayImageDict << /ColorTransform 1 /QFactor \graphicscache@qfactor\space /Blend 1 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >> /GrayImageResolution \graphicscache@dpi\space >> setdistillerparams' -f \graphicscache@cachedir/graphicscacheout.pdf || rm \graphicscache@output }% \fi \else \message{Direct}% \ifwindows \immediate\write18{ copy \graphicscache@cachedir\string\graphicscacheout.pdf \graphicscache@output }% \else \immediate\write18{ cp \graphicscache@cachedir/graphicscacheout.pdf \graphicscache@output }% \fi \fi } \LetLtxMacro\graphicscache@includegraphics\includegraphics% \newcommand\graphicscache@native{% \expandafter\graphicscache@includegraphics\expandafter[\graphicscache@graphicsargs]{\graphicscache@fname}% } \newcommand{\graphicscache@work}{% \ifgraphicscache@render \filemodcmp{\graphicscache@fname}{\graphicscache@output}{% input is newer \graphicscache@dorender% }{% Output is newer \message{Already have \graphicscache@outputhash: \graphicscache@fname}% }% \filemodcmp{\graphicscache@fname}{\graphicscache@output}{% input is newer/output does not exist \graphicscache@native }{% otherwise, use the generated file! \graphicscache@includegraphics{\graphicscache@output}% }% \else \IfFileExists{\graphicscache@output}{% \graphicscache@includegraphics{\graphicscache@output}% }{% \PackageWarning{graphicscache}{Could not find cache file \graphicscache@output, for \graphicscache@fname, falling back to native...}{}% \graphicscache@native }% \fi } \catcode`\*=11 \newif\ifgraphicscache@exists \newcommand{\graphicscache@getfname}[1]{% \ifx\detokenize\@undefined\else \edef\Gin@extensions{\detokenize\expandafter{\Gin@extensions}}% \fi \begingroup \global\graphicscache@existstrue \let\input@path\Ginput@path \ltx@ifpackagelater{graphics}{2017/06/26}{% \set@curr@file{#1}% \expandafter\filename@parse\expandafter{\@curr@file}% \ifx\filename@ext\Gin@gzext \expandafter\filename@parse\expandafter{\filename@base}% \ifx\filename@ext\relax \let\filename@ext\Gin@gzext \else \edef\Gin@ext{\Gin@ext\Gin@sepdefault\Gin@gzext}% \fi \fi }{% \filename@parse{#1}% }% \ifx\filename@ext\relax \@for\Gin@temp:=\Gin@extensions\do{% \ifx\Gin@ext\relax \Gin@getbase\Gin@temp \fi}% \else \Gin@getbase{\Gin@sepdefault\filename@ext}% \ltx@ifpackagelater{graphics}{2017/06/26}{% \ifx\Gin@ext\relax \let\Gin@savedbase\filename@base \let\Gin@savedext\filename@ext \edef\filename@base{\filename@base\Gin@sepdefault\filename@ext}% \let\filename@ext\relax \@for\Gin@temp:=\Gin@extensions\do{% \ifx\Gin@ext\relax \Gin@getbase\Gin@temp \fi}% \ifx\Gin@ext\relax \let\filename@base\Gin@savedbase \let\filename@ext\Gin@savedext \fi \fi }{}% \fi \ifx\Gin@ext\relax \global\graphicscache@existsfalse \else \@ifundefined{Gin@rule@\Gin@ext}% {\global\graphicscache@existsfalse}% {}% \fi \ifgraphicscache@exists \xdef\graphicscache@fname{\Gin@base\Gin@ext}% \fi \endgroup } \catcode`\*=12 \renewcommand{\includegraphics}[2][]{% \begingroup \expandarg \edef\graphicscache@options{\@nameuse{opt@graphicscache.sty}}% \pgfkeys{/graphicscache/.cd,#1}% \ifgraphicscache@render \graphicscache@getfname{#2}% \else \edef\graphicscache@fname{#2}% \graphicscache@existstrue \fi \ifgraphicscache@exists \ifgraphicscache@hashshortnames \edef\graphicscache@hashedname{#2}% \else \edef\graphicscache@hashedname{\graphicscache@fname}% \fi \edef\graphicscache@outputhash{\pdf@mdfivesum{\graphicscache@options\graphicscache@graphicsargs\graphicscache@hashedname}}% \edef\graphicscache@output{\graphicscache@cachedir/\graphicscache@outputhash.pdf}% \ifgraphicscache@listing \message{graphicscache: includegraphics\{#2\} => \graphicscache@output}% \immediate\write\graphicscache@listout{#2 \graphicscache@fname\space \graphicscache@output}% \fi \graphicscache@work \else \PackageError{graphicscache}{Could not find file #2}{}% \fi \endgroup } \newcommand{\includegraphicscache}[3][]{% \begingroup \expandarg \pgfkeys{/graphicscache/.cd,#2}% \includegraphics[#1]{#3}% \endgroup } \endinput %% %% End of file `graphicscache.sty'.