summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tcolorbox/tcbprocessing.code.tex
blob: 522d1469ffa3247bdc25351f183c71b0cbd4e46f (plain)
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
%% The LaTeX package tcolorbox - version 4.30 (2020/04/28)
%% tcbprocessing.code.tex: Code for conditional processing
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2006-2020 by Prof. Dr. Dr. Thomas F. Sturm <thomas dot sturm at unibw dot de>
%% -------------------------------------------------------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `author-maintained'.
%%
%% This work consists of all files listed in README
%%
\tcb@set@library@version{4.30}

\RequirePackage{pdftexcmds}
\RequirePackage{shellesc}

\ifdefined\pdf@filemdfivesum\else% XeLaTeX presumed ...
  \def\pdf@filemdfivesum#1{\mdfivesum file {#1}}%
\fi
\ifdefined\pdf@filemoddate\else% very poor XeLaTeX bypassing
  \def\pdf@filemoddate#1{}%
\fi

\def\tcbproc@readmdfive#1#2{%
  \edef\tcbprocmdfivesum{\pdf@filemdfivesum{#1}}%
  \IfFileExists{#2}{\input{#2}}{\def\tcbproclastmdfivesum{}}%
}

\def\tcbproc@writemdfive#1{%
  \immediate\openout\tcb@out=#1%
  \immediate\write\tcb@out{\string\def\string\tcbproclastmdfivesum{\tcbprocmdfivesum}\@percentchar}%
  \immediate\closeout\tcb@out%
}

\newrobustcmd{\iftcb@process@on}[3]{%
  \tcbproc@readmdfive{#1}{#2}%
  \ifdefstrequal{\tcbproclastmdfivesum}{\tcbprocmdfivesum}{}{\tcbproc@writemdfive{#2}}%
  \expandafter\@firstoftwo%
}

\newrobustcmd{\iftcb@process@conditional}[3]{%
  \tcbproc@readmdfive{#1}{#2}%
  \ifdefstrequal{\tcbproclastmdfivesum}{\tcbprocmdfivesum}{%
    \IfFileExists{#3}{%
      \ifnum\pdf@strcmp{\pdf@filemoddate{#2}}{\pdf@filemoddate{#3}}>0\relax%
        \expandafter\@firstoftwo%
      \else%
        \expandafter\@secondoftwo%
      \fi%
    }{\expandafter\@firstoftwo}%
  }{%
    \tcbproc@writemdfive{#2}%
    \expandafter\@firstoftwo%
  }%
}

\newrobustcmd{\iftcb@process@off}[3]{%
  \tcbproc@readmdfive{#1}{#2}%
  \ifdefstrequal{\tcbproclastmdfivesum}{\tcbprocmdfivesum}{}{\tcbproc@writemdfive{#2}}%
  \expandafter\@secondoftwo%
}%

\newrobustcmd{\tcbiffileprocess}[1]{%
  \ifcase\numexpr#1\relax%
    \expandafter\iftcb@process@on%
  \or%
    \expandafter\iftcb@process@conditional%
  \else%
    \expandafter\iftcb@process@off%
  \fi%
}