-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpgfcache.sty
More file actions
87 lines (78 loc) · 2.19 KB
/
pgfcache.sty
File metadata and controls
87 lines (78 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pgfcache}
\RequirePackage{graphicx}
\RequirePackage{pgf}
\RequirePackage{standalone}
\RequirePackage{xkeyval}
\edef\@figdir{_pgfcache}
\edef\@outdir{}
\DeclareOptionX{outdir}{\edef\@outdir{#1/}}
\DeclareOptionX*{\PackageWarning{pgfcache}{`\CurrentOption' ignored}}
\ProcessOptionsX\relax
\catcode`\#=11
\catcode`\|=6
\newcommand{\@basicpgfpreamble}[1]{%
\unexpanded{%
\documentclass{standalone}^^J
\usepackage{pgf}^^J
\let\oldpgfimage\pgfimage^^J
\renewcommand{\pgfimage}[2][]{\oldpgfimage[#1]{|1/#2}}^^J
}%
}
\catcode`\#=6
\catcode`\|=12
\let\@pgfpreamble\@basicpgfpreamble
\newcommand{\setpgfpreamble}[1]{%
\renewcommand{\@pgfpreamble}[1]{\@basicpgfpreamble{##1}\unexpanded{#1}}
}
\newcounter{@pgfcounter}
\newwrite\@pgfout
\newread\@pgfin
\newcommand{\importpgf}[3][]{%
\IfFileExists{#2/#3}{}{\errmessage{importpgf: File #2/#3 not found}}%
\edef\@figfile{\jobname-\the@pgfcounter}%
\providecommand{\@writetempfile}{}%
\renewcommand{\@writetempfile}[1]%
{%
\immediate\openout\@pgfout=##1%
\immediate\write\@pgfout{\@pgfpreamble{#2}}%
\immediate\write\@pgfout{\string\begin{document}}%
\immediate\openin\@pgfin=#2/#3%
\begingroup\endlinechar=-1%
\loop\unless\ifeof\@pgfin%
\readline\@pgfin to \@fileline%
\ifx\@fileline\@empty\else%
\immediate\write\@pgfout{\@fileline}%
\fi%
\repeat%
\endgroup%
\immediate\closein\@pgfin%
\immediate\write\@pgfout{\string\end{document}}%
\immediate\closeout\@pgfout%
}%
\def\@compile%
{%
\immediate\write18{pdflatex -interaction=batchmode -output-directory="\@outdir\@figdir" \@outdir\@figdir/\@figfile.tex}%
}%
\IfFileExists{\@figdir/\@figfile.pdf}%
{%
\@writetempfile{\@figdir/tmp.tex}%
\edef\@hashold{\pdfmdfivesum file {\@figdir/\@figfile.tex}}%
\edef\@hashnew{\pdfmdfivesum file {\@figdir/tmp.tex}}%
\ifnum\pdfstrcmp{\@hashold}{\@hashnew}=0%
\relax%
\else%
\@writetempfile{\@figdir/\@figfile.tex}%
\@compile%
\fi%
}%
{%
\@writetempfile{\@figdir/\@figfile.tex}%
\@compile%
}%
\IfFileExists{\@figdir/\@figfile.pdf}%
{\includegraphics[#1]{\@figdir/\@figfile.pdf}}%
{\errmessage{Error during compilation of figure #2/#3}}%
\stepcounter{@pgfcounter}%
}
\endinput