Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2021 by Max Schwarz <[email protected]>
4 % ---------------------------------------------------------------------------
5 % This work may be distributed and/or modified under the
6 % conditions of the BSD 3-clause license. See LICENSE for details.
7 %
8 % The Current Maintainer of this work is Max Schwarz.
9 %
10 % This work consists of the files graphicscache.dtx and graphicscache.ins
11 % and the derived filebase graphicscache.sty.
12 %
13 % \fi
14 %
15 % \iffalse
16 %<*driver>
17 \ProvidesFile{graphicscache.dtx}
18 %</driver>
19 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
20 %<package>\ProvidesPackage{graphicscache}
21 %<*package>
22 [2022/12/20 v0.4 Windows support and special character escaping]
23 %</package>
24 %
25 %<*driver>
26 \documentclass[a4paper,11pt]{ydoc}
27 \usepackage{ydoc-expl}
28 % \usepackage{graphicscache}
29 \usepackage[capitalize]{cleveref}
30 \EnableCrossrefs
31 \CodelineIndex
32 \RecordChanges
33 \begin{document}
34 \DocInput{graphicscache.dtx}
35 \PrintChanges
36 \PrintIndex
37 \end{document}
38 %</driver>
39 % \fi
40 %
41 % \CheckSum{0}
42 %
43 % \CharacterTable
44 % {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
45 % 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
46 % Digits \0\1\2\3\4\5\6\7\8\9
47 % Exclamation \! Double quote \" Hash (number) \#
48 % Dollar \$ Percent \% Ampersand \&
49 % Acute accent \' Left paren \( Right paren \)
50 % Asterisk \* Plus \+ Comma \,
51 % Minus \- Point \. Solidus \/
52 % Colon \: Semicolon \; Less than \<
53 % Equals \= Greater than \> Question mark \?
54 % Commercial at \@ Left bracket \[ Backslash \\
55 % Right bracket \] Circumflex \^ Underscore \_
56 % Grave accent \` Left brace \{ Vertical bar \|
57 % Right brace \} Tilde \~}
58 %
59 %
60 % \changes{v0.1}{2018/10/03}{Initial version}
61 % \changes{v0.2}{2021/04/08}{Better compatibility with different graphicx versions}
62 % \changes{v0.3}{2021/08/02}{Added cachedir option}
63 % \changes{v0.4}{2022/12/20}{Windows support and special character escaping}
64 %
65 % \DoNotIndex{\newcommand,\newenvironment}
66 %
67 % \providecommand*{\url}{\texttt}
68 % \GetFileInfo{graphicscache.dtx}
69 % \title{The \textsf{graphicscache} package}
70 % \author{Max Schwarz \\ \url{[email protected]}}
71 % \date{\fileversion~from \filedate}
72 %
73 % \maketitle
74 %
75 % \section{Introduction}
76 %
77 % The \texttt{graphicx} package offers the versatile |\includegraphics| command,
78 % which offers image transformations like scaling, cropping, rotation, etc.
79 % However, these transformations have to be performed on every compilation of
80 % the document. Users can avoid this with the |draft| option at the cost of
81 % not seeing the images.
82 %
83 % Furthermore, images are always included as-is with full resolution, even if
84 % they are shown at a very small actual size. This increases compilation time
85 % again and leads to large output files. A typical solution is to resize the
86 % input images to a lower resolution---but here, the user has to manually
87 % calculate or guess the required resolution. What we really want is to specify
88 % a \textit{document DPI}, which automatically leads to the correct image
89 % resolution. This is possible using post-processing tools like ghostscript,
90 % but these do not help with compilation times and are typically not applicable
91 % for preprint servers or journals which require LaTeX sources.
92 %
93 % |graphicscache| aims to solve these problems by decoupling the rendering
94 % of images from the actual inclusion. Images are rendered to the correct size
95 % using a separate |pdflatex| call, post-processed with ghostscript, and then
96 % included as PDF. As a bonus, the resulting PDF is cached, resulting in very
97 % fast recompilation times.
98 %
99 % \section{Usage}
100 %
101 % |graphicscache| requires the usage of the |\write18| call (also called shell
102 % escape). For |pdflatex|, you have to specify the |-shell-escape| argument
103 % during compilation. After enabling shell-escape, simply call
104 %
105 % \begin{example}
106 % |\usepackage{graphicscache}|
107 % \end{example}
108 %
109 % to enable caching.
110 %
111 % |graphicscache| overrides the |\includegraphics| command so that you can use
112 % it as usual. Internally, it calculates a hash from the |includegraphics|
113 % arguments and the package options to generate a cache key.
114 % If you change the input image file or the options, the file will be
115 % automatically rendered again.
116 %
117 % \textbf{Note:} The first compilation process might take a while, since the
118 % cached PDFs are generated one-by-one.
119 %
120 % \subsection{Generated files}
121 %
122 % |graphicscache| will create a folder called |graphicscache| in the compilation
123 % directory. Additionally, latex output files under the jobname
124 % |graphicscacheout| will be created. All of these files and folders are
125 % temporary and can be deleted safely (at the cost of re-creating the cache).
126 %
127 % \subsection{Package options}
128 %
129 % \DescribeKey{compress}'=false|flat|jpeg'
130 % Specifies the image compression algorithm. If |false|, the ghostscript call
131 % is skipped, thus embedding the image at its original resolution and format.
132 % If |flat|, the lossless |FlatEncode| algorithm is chosen. Finally, |jpeg|
133 % indicates that JPEG encoding using |DCTEncode| is to be performed.
134 %
135 % \textbf{Note:} In the |flat| case, the images are still downsampled to match
136 % the DPI specified using the |dpi| key.
137 %
138 % \DescribeKey{dpi}'='<number>
139 % Controls the image resolution in dots per inch. The default value is 300.
140 % This option only takes effect if |compress| is not |false|.
141 %
142 % \DescribeKey{qfactor}'='<number>
143 % This controls the quality parameter of the JPEG encoder (see |compress|).
144 % Smaller values give higher quality. The default value is 0.15, which
145 % corresponds to the ``Maximum'' setting mentioned by Adobe.
146 %
147 % \DescribeKey{listing}'=true|false'
148 % If enabled, |graphicscache| will write an extra |.graphicscache| file with
149 % mappings from |includegraphics| arguments to cache files. This can be used
150 % to produce a version of the TeX source code that directly references the
151 % PDF files instead of the original sources.
152 %
153 % \DescribeKey{render}'=true|false'
154 % Controls whether rendering is allowed. The default is |true|. If |false|,
155 % |graphicscache| is not allowed to create new cache files. Instead, it will
156 % attempt to use the appropriate cache file. If it does not exist,
157 % |graphicscache| will fall back to |graphicx| in-place rendering.
158 % This can be used to perform a final release (see \cref{sec:release}).
159 %
160 % \DescribeKey{cachedir}'='<dir>
161 % This key can be used to move the cache directory to another location.
162 % The default value is |graphicscache|.
163 %
164 % \subsection{Macros}
165 %
166 % \DescribeMacro{\includegraphics}[args]{path}
167 % This behaves exactly like the original |graphicx| |\includegraphics|.
168 % However, only a limited number of keys in |args| is supported at the moment:
169 % |width|, |height|, |trim|, |clip|, |angle|, |origin|, |keepaspectratio|,
170 % |scale|. In addition, you can specify any of the package options above
171 % here as well. For example, you might want to disable compression for
172 % a particular image with
173 %
174 % \begin{example}
175 % |\includegraphics[width=...,compress=false]{...}|.
176 % \end{example}
177 %
178 % \StopEventually{}
179 %
180 % \section{Tips \& Tricks}
181 % \subsection{Releasing your manuscript}
182 % \label{sec:release}
183 %
184 % In case you want to upload your manuscript to a journal or preprint server,
185 % you can use |graphicscache| to make your work easier:
186 % \begin{enumerate}
187 % \item Use |latexpand| to strip comments and flatten your tex sources into
188 % one file (optional).
189 % \item Compile the file as usual to generate the cache files.
190 % \item Compile the file again with the |-recorder| command line option.
191 % Here, we want to hide accesses of the original image files
192 % (|render=false|), but changing the package options will change the
193 % cache hash. For this purpose, |graphicspath| also reacts to a global
194 % definition of |\graphicscache@inhibit|, which has the same effect as
195 % |render=false|.
196 % \item The generated |.fls| file will contain all cache files that are needed
197 % to compile your manuscript. Package them and your |.tex| file.
198 % \end{enumerate}
199 %
200 % This process is automated in the |release.sh| script included in the
201 % distribution.
202 %
203 % \section{Implementation}
204 %
205 % \iffalse
206 %<*package>
207 % \fi
208 %
209 % \begin{macrocode}
210 \NeedsTeXFormat{LaTeX2e}[1994/06/01]
211 \ProvidesPackage{graphicscache}[2018/10/02 Graphics Cache]
212 \RequirePackage{graphicx}
213 \RequirePackage{xstring}
214 \RequirePackage{filemod}
215 \RequirePackage{letltxmacro}
216 \RequirePackage{pgfopts}
217 \RequirePackage{pgffor}
218 \RequirePackage{ifplatform}
219 \RequirePackage{pdftexcmds}
220 \RequirePackage{ltxcmds}
221 \newif\ifgraphicscache@render
222 \newif\ifgraphicscache@compress
223 \newif\ifgraphicscache@listing
224 \newif\ifgraphicscache@hashshortnames
225 \newif\ifgraphicscache@gsnotavailable\graphicscache@gsnotavailablefalse
226 \def\graphicscache@graphicsargs{}
227 \newlength\graphicscache@tmplen
228 \newcommand{\graphicscache@addarg}[1]{%
229 \ifx\graphicscache@graphicsargs\empty
230 \edef\graphicscache@graphicsargs{#1}%
231 \else
232 \edef\graphicscache@graphicsargs{\graphicscache@graphicsargs,#1}%
233 \fi
234 }
235 \pgfkeys{
236 /graphicscache/.cd,
237 render/.is if=graphicscache@render,
238 render=true,
239 % \end{macrocode}
240 % \begin{macrocode}
241 cachedir/.store in=\graphicscache@cachedir,
242 cachedir={graphicscache},
243 % \end{macrocode}
244 % \begin{macrocode}
245 compress/.is choice,
246 compress/false/.code={\graphicscache@compressfalse},
247 compress/jpeg/.code={\graphicscache@compresstrue \def\graphicscache@compress@mode{DCTEncode}},
248 compress/flat/.code={\graphicscache@compresstrue \def\graphicscache@compress@mode{FlatEncode}},
249 compress=jpeg,
250 % \end{macrocode}
251 % \begin{macrocode}
252 dpi/.store in=\graphicscache@dpi,
253 dpi=300,
254 % \end{macrocode}
255 % \begin{macrocode}
256 qfactor/.store in=\graphicscache@qfactor,
257 qfactor={0.15},
258 % \end{macrocode}
259 % \begin{macrocode}
260 hashshortnames/.is if=graphicscache@hashshortnames,
261 hashshortnames=false,
262 % \end{macrocode}
263 % We now define the list of supported graphicx arguments:
264 % \begin{macrocode}
265 width/.code={%
266 \setlength\graphicscache@tmplen{#1}%
267 \graphicscache@addarg{width=\the\graphicscache@tmplen}%
268 },
269 height/.code={%
270 \setlength\graphicscache@tmplen{#1}%
271 \graphicscache@addarg{height=\the\graphicscache@tmplen}%
272 },
273 trim/.code={\graphicscache@addarg{trim=#1}},
274 clip/.code={\graphicscache@addarg{clip}},
275 angle/.code={%
276 \edef\graphicscache@tmp{#1}%
277 \graphicscache@addarg{angle=\graphicscache@tmp}%
278 },
279 origin/.code={\graphicscache@addarg{origin=#1}},
280 keepaspectratio/.code={\graphicscache@addarg{keepaspectratio}},
281 scale/.code={%
282 \edef\graphicscache@tmp{#1}%
283 \graphicscache@addarg{scale=\graphicscache@tmp}%
284 },
285 page/.code={%
286 \edef\graphicscache@tmp{#1}%
287 \graphicscache@addarg{page=\graphicscache@tmp}%
288 },
289 listing/.is if=graphicscache@listing,
290 listing=false,
291 %
292 % adjustbox package
293 %
294 frame/.code={%
295 \edef\graphicscache@tmp{#1}%
296 \graphicscache@addarg{frame=\graphicscache@tmp}%
297 },
298 valign/.code={%
299 \edef\graphicscache@tmp{#1}%
300 \graphicscache@addarg{valign=\graphicscache@tmp}%
301 },
302 raise/.code={%
303 \edef\graphicscache@tmp{#1}%
304 \graphicscache@addarg{raise=\graphicscache@tmp}%
305 },
306 }
307 \ProcessPgfOptions{/graphicscache}\relax
308 \ifdefined\graphicscache@inhibit
309 \pgfkeys{/graphicscache/render=false}%
310 \fi
311 \ifgraphicscache@listing
312 \newwrite\graphicscache@listout
313 \immediate\openout\graphicscache@listout=\jobname.graphicscache
314 \fi
315 %
316 % shellesc has a bug on Ubuntu 16.04 (\ShellEscape is not immediate).
317 % So we simply define our own shellescape macro.
318 \ifx\lastsavedimageresourcepages\@undefined
319 \protected\def\graphicscache@ShellEscape{\immediate\write18 }
320 \else
321 \protected\def\graphicscache@ShellEscape#1{%
322 \directlua{os.execute("\luaescapestring{#1}")}}
323 \fi
324 % \end{macrocode}
325 %
326 % \begin{macro}{\graphicscache@callgswithname}
327 % This macro calls ghostscript using the name specified in the first argument.
328 % \begin{macrocode}
329 \newcommand{\graphicscache@callgswithname}[1]{%
330 \ifwindows
331 \graphicscache@ShellEscape{#1
332 -sOutputFile=\graphicscache@output\space
333 -sDEVICE=pdfwrite
334 -dCompatibilityLevel=1.4
335 -dPDFSETTINGS=/prepress
336 -dNOPAUSE -dQUIET -dBATCH
337 -c "<<
338 /AutoFilterColorImages false
339 /EncodeColorImages true
340 /ColorImageFilter /\graphicscache@compress@mode\space
341 /ColorImageDict << /ColorTransform 1 /QFactor \graphicscache@qfactor\space /Blend 1 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >>
342 /ColorImageResolution \graphicscache@dpi\space
343 /AutoFilterGrayImages false
344 /EncodeGrayImages true
345 /GrayImageFilter /\graphicscache@compress@mode\space
346 /GrayImageDict << /ColorTransform 1 /QFactor \graphicscache@qfactor\space /Blend 1 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >>
347 /GrayImageResolution \graphicscache@dpi\space
348 >> setdistillerparams"
349 -f \graphicscache@cachedir\string\graphicscacheout.pdf
350 }%
351 \else
352 \graphicscache@ShellEscape{#1
353 -sOutputFile=\graphicscache@output\space
354 -sDEVICE=pdfwrite
355 -dCompatibilityLevel=1.4
356 -dPDFSETTINGS=/prepress
357 -dNOPAUSE -dQUIET -dBATCH
358 -c '<<
359 /AutoFilterColorImages false
360 /EncodeColorImages true
361 /ColorImageFilter /\graphicscache@compress@mode\space
362 /ColorImageDict << /ColorTransform 1 /QFactor \graphicscache@qfactor\space /Blend 1 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >>
363 /ColorImageResolution \graphicscache@dpi\space
364 /AutoFilterGrayImages false
365 /EncodeGrayImages true
366 /GrayImageFilter /\graphicscache@compress@mode\space
367 /GrayImageDict << /ColorTransform 1 /QFactor \graphicscache@qfactor\space /Blend 1 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >>
368 /GrayImageResolution \graphicscache@dpi\space
369 >> setdistillerparams'
370 -f \graphicscache@cachedir/graphicscacheout.pdf \string|\string| rm \graphicscache@output
371 }%
372 \fi
373 }
374 % \end{macrocode}
375 % \end{macro}
376 % \begin{macro}{\graphicscache@callgs}
377 % This macro finds the correct ghostscript executable to call.
378 % \begin{macrocode}
379 \newcommand{\graphicscache@callgs}{%
380 % \end{macrocode}
381 % If we previously established gs is not available, do nothing.
382 % \begin{macrocode}
383 \ifgraphicscache@gsnotavailable
384 \else
385 \@ifundefined{graphicscache@gscommand}{%
386 \foreach \cmd in {rungs,gs,mgs} {%
387 \PackageInfo{graphicscache}{Trying \cmd\space to call ghostscript...^^J}%
388 \graphicscache@callgswithname{\cmd}%
389 \IfFileExists{\graphicscache@output}{%
390 \PackageInfo{graphicscache}{Found a working ghostscript called '\cmd'.}%
391 \global\edef\graphicscache@gscommand{\cmd}%
392 \breakforeach
393 }{}%
394 }%
395 \@ifundefined{graphicscache@gscommand}{%
396 \PackageWarning{graphicscache}{Could not find a working ghostscript executable. I will not compress any images.}{}%
397 \graphicscache@gsnotavailabletrue
398 }{}%
399 }{%
400 \PackageInfo{graphicscache}{Calling gs with name '\graphicscache@gscommand'^^J}
401 \graphicscache@callgswithname{\graphicscache@gscommand}
402 }%
403 \fi
404 }
405 % \end{macrocode}
406 % \end{macro}
407 % \begin{macro}{\graphicscache@dorender}
408 % Here, we actually perform the rendering. Sadly, this is quite complex due
409 % to cross-platform support.
410 % \begin{macrocode}
411 \newcommand{\graphicscache@dorender}{%
412 \PackageInfo{graphicscache}{Rendering \graphicscache@outputhash: \graphicscache@fname\space with args: \graphicscache@graphicsargs\space (master file)}%
413 \ifwindows
414 \graphicscache@ShellEscape{md "\graphicscache@cachedir" 2>NUL}%
415 \else
416 \graphicscache@ShellEscape{mkdir -p "\graphicscache@cachedir"}%
417 \fi
418 % \end{macrocode}
419 % First, render the graphics.
420 % \begin{macrocode}
421 \ifwindows
422 \graphicscache@ShellEscape{del /q \graphicscache@cachedir\string\graphicscacheout.pdf}
423 \graphicscache@ShellEscape{pdflatex
424 -jobname graphicscacheout
425 -interaction nonstopmode
426 -output-directory "\graphicscache@cachedir"
427 "\string\documentclass{standalone}
428 \string\usepackage{graphicx}
429 \string\usepackage[export]{adjustbox}
430 \string\begin{document}\string\includegraphics[\graphicscache@graphicsargs]{\graphicscache@fname}\string\end{document}"
431 }%
432 \IfFileExists{\graphicscache@cachedir/graphicscacheout.pdf}{}{%
433 \PackageWarning{graphicscache}{External pdflatex call failed (see above)}%
434 \def\graphicscache@output{}%
435 }
436 \else
437 \graphicscache@ShellEscape{pdflatex
438 -jobname graphicscacheout
439 -interaction nonstopmode
440 -output-directory "\graphicscache@cachedir"
441 '\string\documentclass{standalone}
442 \string\usepackage{graphicx}
443 \string\usepackage[export]{adjustbox}
444 \string\begin{document}\string\includegraphics[\graphicscache@graphicsargs]{\graphicscache@fname}\string\end{document}'
445 > /dev/null \string|\string| rm "\graphicscache@cachedir/graphicscacheout.pdf"
446 }%
447 \fi
448 % \end{macrocode}
449 % Now, call ghostscript for compression---if required, otherwise just copy the
450 % file.
451 % \begin{macrocode}
452 \ifgraphicscache@compress
453 \PackageInfo{graphicscache}{With compression: \graphicscache@compress@mode}%
454 \graphicscache@callgs
455 \else
456 \PackageInfo{graphicscache}{Direct}%
457 \ifwindows
458 \graphicscache@ShellEscape{
459 copy \graphicscache@cachedir\string\graphicscacheout.pdf \graphicscache@output
460 }%
461 \else
462 \graphicscache@ShellEscape{
463 cp \graphicscache@cachedir/graphicscacheout.pdf \graphicscache@output
464 }%
465 \fi
466 \fi
467 }
468 % \end{macrocode}
469 % \end{macro}
470 %
471 % save original |\includegraphics|
472 % \begin{macrocode}
473 \LetLtxMacro\graphicscache@includegraphics\includegraphics%
474 \newcommand\graphicscache@native{%
475 \expandafter\graphicscache@includegraphics\expandafter[\graphicscache@graphicsargs]{\graphicscache@fname}%
476 }
477 % \end{macrocode}
478 %
479 % \begin{macro}{\graphicscache@work}
480 % This macro performs the update check: Do we need to render the file again
481 % or can we just include the cached version?
482 % \begin{macrocode}
483 \newcommand{\graphicscache@work}{%
484 \ifgraphicscache@render
485 % \end{macrocode}
486 % Check if output file exists and is newer than input
487 % \begin{macrocode}
488 \filemodcmp{\graphicscache@fname}{\graphicscache@output}{% input is newer
489 \graphicscache@dorender%
490 }{% Output is newer
491 \PackageInfo{graphicscache}{Already have \graphicscache@outputhash: \graphicscache@fname}%
492 }%
493 % \end{macrocode}
494 % If it still does not exist, we are likely in a strange environment
495 % (e.g. tabu). In that case, fall back to original includegraphics.
496 % \begin{macrocode}
497 \filemodcmp{\graphicscache@fname}{\graphicscache@output}{% input is newer/output does not exist
498 \graphicscache@native
499 }{% otherwise, use the generated file!
500 \graphicscache@includegraphics{\graphicscache@output}%
501 }%
502 \else
503 % \end{macrocode}
504 % Here, we just look if the output file exists. If not, fall back to
505 % original includegraphics.
506 % \begin{macrocode}
507 \IfFileExists{\graphicscache@output}{%
508 \graphicscache@includegraphics{\graphicscache@output}%
509 }{%
510 \PackageWarning{graphicscache}{Could not find cache file \graphicscache@output, for \graphicscache@fname, falling back to native...}{}%
511 \graphicscache@native
512 }%
513 \fi
514 }
515 % \end{macrocode}
516 % \end{macro}
517 % \begin{macro}{\graphicscache@getfname}
518 % This macro resolves base names (i.e. includegraphics arguments with or
519 % without extensions) to relative paths.
520 % \begin{macrocode}
521 \catcode`\*=11
522 \newif\ifgraphicscache@exists
523 \newcommand{\graphicscache@getfname}[1]{%
524 \ifx\detokenize\@undefined\else
525 \edef\Gin@extensions{\detokenize\expandafter{\Gin@extensions}}%
526 \fi
527 \begingroup
528 \global\graphicscache@existstrue
529 \let\input@path\Ginput@path
530 \ltx@ifpackagelater{graphics}{2017/06/26}{%
531 \set@curr@file{#1}%
532 \expandafter\filename@parse\expandafter{\@curr@file}%
533 \ifx\filename@ext\Gin@gzext
534 \expandafter\filename@parse\expandafter{\filename@base}%
535 \ifx\filename@ext\relax
536 \let\filename@ext\Gin@gzext
537 \else
538 \edef\Gin@ext{\Gin@ext\Gin@sepdefault\Gin@gzext}%
539 \fi
540 \fi
541 }{%
542 \filename@parse{#1}%
543 }%
544 \ifx\filename@ext\relax
545 \@for\Gin@temp:=\Gin@extensions\do{%
546 \ifx\Gin@ext\relax
547 \Gin@getbase\Gin@temp
548 \fi}%
549 \else
550 \Gin@getbase{\Gin@sepdefault\filename@ext}%
551 \ltx@ifpackagelater{graphics}{2017/06/26}{%
552 \ifx\Gin@ext\relax
553 \let\Gin@savedbase\filename@base
554 \let\Gin@savedext\filename@ext
555 \edef\filename@base{\filename@base\Gin@sepdefault\filename@ext}%
556 \let\filename@ext\relax
557 \@for\Gin@temp:=\Gin@extensions\do{%
558 \ifx\Gin@ext\relax
559 \Gin@getbase\Gin@temp
560 \fi}%
561 \ifx\Gin@ext\relax
562 \let\filename@base\Gin@savedbase
563 \let\filename@ext\Gin@savedext
564 \fi
565 \fi
566 }{}%
567 \fi
568 \ifx\Gin@ext\relax
569 \global\graphicscache@existsfalse
570 \else
571 \@ifundefined{Gin@rule@\Gin@ext}%
572 {\global\graphicscache@existsfalse}%
573 {}%
574 \fi
575 \ifgraphicscache@exists
576 \xdef\graphicscache@fname{\Gin@base\Gin@ext}%
577 \fi
578 \endgroup
579 }
580 \catcode`\*=12
581 % \end{macrocode}
582 % \end{macro}
583 % \begin{macro}{\includegraphics}
584 % Main entry point.
585 % \begin{macrocode}
586 \renewcommand{\includegraphics}[2][]{%
587 \begingroup
588 \expandarg
589 % \end{macrocode}
590 % Hash everything!
591 % \begin{macrocode}
592 \edef\graphicscache@options{\@nameuse{[email protected]}}%
593 \pgfkeys{/graphicscache/.cd,#1}%
594 % \end{macrocode}
595 % If we are rendering, we need the actual filename, so that we can check
596 % modification times. Otherwise, just assume the file exists, |\includegraphics|
597 % will throw an error itself otherwise.
598 % \begin{macrocode}
599 \ifgraphicscache@render
600 \graphicscache@getfname{#2}%
601 \else
602 \edef\graphicscache@fname{#2}%
603 \graphicscache@existstrue
604 \fi
605 \ifgraphicscache@exists
606 \ifgraphicscache@hashshortnames
607 \edef\graphicscache@hashedname{#2}%
608 \else
609 \edef\graphicscache@hashedname{\graphicscache@fname}%
610 \fi
611 \edef\graphicscache@outputhash{\pdf@mdfivesum{\graphicscache@options\graphicscache@graphicsargs\graphicscache@hashedname}}%
612 \edef\graphicscache@output{\graphicscache@cachedir/\[email protected]}%
613 \ifgraphicscache@listing
614 \PackageInfo{graphicscache}{graphicscache: includegraphics\{#2\} => \graphicscache@output}%
615 \immediate\write\graphicscache@listout{#2 \graphicscache@fname\space \graphicscache@output}%
616 \fi
617 \graphicscache@work
618 \else
619 \PackageError{graphicscache}{Could not find file #2}{}%
620 \fi
621 \endgroup
622 }
623 % \end{macrocode}
624 % \end{macro}
625 % \begin{macro}{\includegraphicscache}
626 % \begin{macrocode}
627 \newcommand{\includegraphicscache}[3][]{%
628 \begingroup
629 \expandarg
630 \pgfkeys{/graphicscache/.cd,#2}%
631 \includegraphics[#1]{#3}%
632 \endgroup
633 }
634 % \end{macrocode}
635 % \end{macro}
636 %
637 % \begin{macrocode}
638 \endinput
639 % \end{macrocode}
640
641 %
642 % \iffalse
643 %</package>
644 % \fi
645 %
646 % \Finale
647 \endinput