Skip to content

Commit

Permalink
Merge pull request #14 from xqms/cachedir
Browse files Browse the repository at this point in the history
Add "cachedir" option
  • Loading branch information
xqms authored Aug 2, 2021
2 parents 9b61b15 + 7cc58d5 commit 5b6e8db
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 13 deletions.
9 changes: 9 additions & 0 deletions .github/actions/ubuntu16/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions .github/actions/ubuntu18/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions .github/actions/ubuntu20/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions .github/actions/windows/entrypoint.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ if (-not $?)
{
throw 'pdflatex failed'
}

& pdflatex -interaction=nonstopmode -shell-escape nonstandard_cachedir
if (-not $?)
{
throw 'pdflatex failed'
}
24 changes: 24 additions & 0 deletions example/nonstandard_cachedir.tex
Original file line number Diff line number Diff line change
@@ -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}

35 changes: 22 additions & 13 deletions graphicscache.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{graphicscache}
%<*package>
[2021/04/08 v0.2 Cache includegraphics calls]
[2021/08/02 v0.3 Cache includegraphics calls]
%</package>
%
%<*driver>
Expand Down Expand Up @@ -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}
%
Expand Down Expand Up @@ -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}'='<dir>
% This key can be used to move the cache directory to another location.
% The default value is |graphicscache|.
%
% \subsection{Macros}
%
% \DescribeMacro{\includegraphics}[args]{path}
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -309,38 +318,38 @@
\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{}%
}
\else
\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}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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}%
Expand Down

0 comments on commit 5b6e8db

Please sign in to comment.