From 7cc58d5271c0d299dbefda7e7df7ff3369312210 Mon Sep 17 00:00:00 2001 From: Max Schwarz Date: Mon, 2 Aug 2021 16:09:00 +0200 Subject: [PATCH] Add "cachedir" option, see #12. This also adds unit tests for the new option. --- .github/actions/ubuntu16/entrypoint.sh | 9 +++++++ .github/actions/ubuntu18/entrypoint.sh | 13 ++++++++++ .github/actions/ubuntu20/entrypoint.sh | 13 ++++++++++ .github/actions/windows/entrypoint.ps1 | 6 +++++ example/nonstandard_cachedir.tex | 24 ++++++++++++++++++ graphicscache.dtx | 35 ++++++++++++++++---------- 6 files changed, 87 insertions(+), 13 deletions(-) create mode 100644 example/nonstandard_cachedir.tex diff --git a/.github/actions/ubuntu16/entrypoint.sh b/.github/actions/ubuntu16/entrypoint.sh index 5eb2b44..56590f4 100755 --- a/.github/actions/ubuntu16/entrypoint.sh +++ b/.github/actions/ubuntu16/entrypoint.sh @@ -14,3 +14,12 @@ echo "Compiling example using lualatex" rm -f paper.aux TEXINPUTS=..: lualatex -interaction=nonstopmode paper +echo "Clearing cache..." +rm -Rf graphicscache + +echo "Compiling nonstandard_cachedir using pdflatex" +TEXINPUTS=..: pdflatex -interaction=nonstopmode nonstandard_cachedir + +echo "Compiling nonstandard_cachedir using lualatex" +rm -f paper.aux +TEXINPUTS=..: lualatex -interaction=nonstopmode nonstandard_cachedir diff --git a/.github/actions/ubuntu18/entrypoint.sh b/.github/actions/ubuntu18/entrypoint.sh index a8ae942..8ecf64d 100755 --- a/.github/actions/ubuntu18/entrypoint.sh +++ b/.github/actions/ubuntu18/entrypoint.sh @@ -18,6 +18,19 @@ echo "::group::Compiling example using lualatex" rm -f paper.aux TEXINPUTS=..: lualatex -interaction=nonstopmode paper echo "::endgroup::" + +echo "::group::Clearing cache..." +rm -Rf graphicscache +echo "::endgroup::" + +echo "::group::Compiling nonstandard_cachedir using pdflatex" +TEXINPUTS=..: pdflatex -interaction=nonstopmode nonstandard_cachedir +echo "::endgroup::" + +echo "::group::Compiling nonstandard_cachedir using lualatex" +rm -f paper.aux +TEXINPUTS=..: lualatex -interaction=nonstopmode nonstandard_cachedir +echo "::endgroup::" ) echo "::group::Creating CTAN package" diff --git a/.github/actions/ubuntu20/entrypoint.sh b/.github/actions/ubuntu20/entrypoint.sh index a8ae942..8ecf64d 100755 --- a/.github/actions/ubuntu20/entrypoint.sh +++ b/.github/actions/ubuntu20/entrypoint.sh @@ -18,6 +18,19 @@ echo "::group::Compiling example using lualatex" rm -f paper.aux TEXINPUTS=..: lualatex -interaction=nonstopmode paper echo "::endgroup::" + +echo "::group::Clearing cache..." +rm -Rf graphicscache +echo "::endgroup::" + +echo "::group::Compiling nonstandard_cachedir using pdflatex" +TEXINPUTS=..: pdflatex -interaction=nonstopmode nonstandard_cachedir +echo "::endgroup::" + +echo "::group::Compiling nonstandard_cachedir using lualatex" +rm -f paper.aux +TEXINPUTS=..: lualatex -interaction=nonstopmode nonstandard_cachedir +echo "::endgroup::" ) echo "::group::Creating CTAN package" diff --git a/.github/actions/windows/entrypoint.ps1 b/.github/actions/windows/entrypoint.ps1 index e318d1e..f8a80d8 100644 --- a/.github/actions/windows/entrypoint.ps1 +++ b/.github/actions/windows/entrypoint.ps1 @@ -16,3 +16,9 @@ if (-not $?) { throw 'pdflatex failed' } + +& pdflatex -interaction=nonstopmode -shell-escape nonstandard_cachedir +if (-not $?) +{ + throw 'pdflatex failed' +} diff --git a/example/nonstandard_cachedir.tex b/example/nonstandard_cachedir.tex new file mode 100644 index 0000000..55bd72e --- /dev/null +++ b/example/nonstandard_cachedir.tex @@ -0,0 +1,24 @@ +\documentclass[a4paper,10pt]{article} +\usepackage[utf8]{inputenc} + +\usepackage{graphicx} +\usepackage[cachedir=nonstandard/cachedir]{graphicscache} + +%opening +\title{} +\author{} + +\begin{document} + +\maketitle + +\begin{abstract} + +\end{abstract} + +\section{} + +\includegraphics[height=5cm,clip,trim=100 0 100 0]{myimage} + +\end{document} + diff --git a/graphicscache.dtx b/graphicscache.dtx index 75dcf3e..50215f8 100644 --- a/graphicscache.dtx +++ b/graphicscache.dtx @@ -19,7 +19,7 @@ %\NeedsTeXFormat{LaTeX2e}[1999/12/01] %\ProvidesPackage{graphicscache} %<*package> - [2021/04/08 v0.2 Cache includegraphics calls] + [2021/08/02 v0.3 Cache includegraphics calls] % % %<*driver> @@ -59,6 +59,7 @@ % % \changes{v0.1}{2018/10/03}{Initial version} % \changes{v0.2}{2021/04/08}{Better compatibility with different graphicx versions} +% \changes{v0.3}{2021/08/02}{Added cachedir option} % % \DoNotIndex{\newcommand,\newenvironment} % @@ -155,6 +156,10 @@ % |graphicscache| will fall back to |graphicx| in-place rendering. % This can be used to perform a final release (see \cref{sec:release}). % +% \DescribeKey{cachedir}'=' +% This key can be used to move the cache directory to another location. +% The default value is |graphicscache|. +% % \subsection{Macros} % % \DescribeMacro{\includegraphics}[args]{path} @@ -229,6 +234,10 @@ render/.is if=graphicscache@render, render=true, % \end{macrocode} +% \begin{macrocode} + cachedir/.store in=\graphicscache@cachedir, + cachedir={graphicscache}, +% \end{macrocode} % \begin{macrocode} compress/.is choice, compress/false/.code={\graphicscache@compressfalse}, @@ -309,25 +318,25 @@ \newcommand{\graphicscache@dorender}{% \message{Rendering \graphicscache@outputhash: \graphicscache@fname\space with args: \graphicscache@graphicsargs\space (master file)}% \ifwindows - \immediate\write18{md graphicscache 2>NUL}% + \immediate\write18{md "\graphicscache@cachedir" 2>NUL}% \else - \immediate\write18{mkdir -p graphicscache}% + \immediate\write18{mkdir -p "\graphicscache@cachedir"}% \fi % \end{macrocode} % First, render the graphics. % \begin{macrocode} \ifwindows - \immediate\write18{del /q graphicscache\string\graphicscacheout.pdf} + \immediate\write18{del /q \graphicscache@cachedir\string\graphicscacheout.pdf} \immediate\write18{pdflatex -jobname graphicscacheout -interaction nonstopmode - -output-directory graphicscache + -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/graphicscacheout.pdf}{}{% + \IfFileExists{\graphicscache@cachedir/graphicscacheout.pdf}{}{% \PackageError{graphicscache}{External pdflatex call failed (see above)}{}% \def\graphicscache@output{}% } @@ -335,12 +344,12 @@ \immediate\write18{pdflatex -jobname graphicscacheout -interaction nonstopmode - -output-directory graphicscache + -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/graphicscacheout.pdf + > /dev/null || rm "\graphicscache@cachedir/graphicscacheout.pdf" }% \fi % \end{macrocode} @@ -368,7 +377,7 @@ /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\string\graphicscacheout.pdf + -f \graphicscache@cachedir\string\graphicscacheout.pdf }% \else \immediate\write18{gs @@ -389,18 +398,18 @@ /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/graphicscacheout.pdf || rm \graphicscache@output + -f \graphicscache@cachedir/graphicscacheout.pdf || rm \graphicscache@output }% \fi \else \message{Direct}% \ifwindows \immediate\write18{ - copy graphicscache\string\graphicscacheout.pdf \graphicscache@output + copy \graphicscache@cachedir\string\graphicscacheout.pdf \graphicscache@output }% \else \immediate\write18{ - cp graphicscache/graphicscacheout.pdf \graphicscache@output + cp \graphicscache@cachedir/graphicscacheout.pdf \graphicscache@output }% \fi \fi @@ -549,7 +558,7 @@ \edef\graphicscache@hashedname{\graphicscache@fname}% \fi \edef\graphicscache@outputhash{\pdf@mdfivesum{\graphicscache@options\graphicscache@graphicsargs\graphicscache@hashedname}}% - \edef\graphicscache@output{./graphicscache/\graphicscache@outputhash.pdf}% + \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}%