summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/robust-externalize/robust-externalize.sty
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/robust-externalize/robust-externalize.sty')
-rw-r--r--macros/latex/contrib/robust-externalize/robust-externalize.sty118
1 files changed, 109 insertions, 9 deletions
diff --git a/macros/latex/contrib/robust-externalize/robust-externalize.sty b/macros/latex/contrib/robust-externalize/robust-externalize.sty
index 75d55b268c..3bf14a9f95 100644
--- a/macros/latex/contrib/robust-externalize/robust-externalize.sty
+++ b/macros/latex/contrib/robust-externalize/robust-externalize.sty
@@ -1,4 +1,4 @@
-\ProvidesPackage{robust-externalize}[2.1 Cache anything (tikz, latex, python) in a robust, efficient and pure way.]
+\ProvidesPackage{robust-externalize}[2.2 Cache anything (tikz, latex, python) in a robust, efficient and pure way.]
% todo:
% change order argument replace from list, it is hard to read this way
@@ -20,6 +20,11 @@
%%%%%%%%%%% Utils %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\ExplSyntaxOn
+\NewDocumentCommand{\robExtIfWindowsTF}{mm}{%
+ \sys_if_platform_windows:TF {#1}{#2}%
+}
+\ExplSyntaxOff
% Debug function: by default, do nothing
\def\robExtDebugMessage#1{}
@@ -81,6 +86,8 @@
\cs_generate_variant:Nn \robExt_set_hash_robust:Nn { cn }
\cs_generate_variant:Nn \robExt_set_hash_robust:Nn { cx }
+\NewDocumentCommand{\robExt@set@hash@robust}{mm}{\robExt_set_hash_robust:Nn #1 {#2}}
+
% Double the number of hashes... quite dirty but cannot find any solution or the user need to double it itself
%% See also https://tex.stackexchange.com/questions/695432/latex3-latex-doubles-the-number-of-hashes-when-storing-them-in-string/695460#695460
\NewDocumentCommand{\robExtStrSetDoubleHash}{mm}{
@@ -1658,11 +1665,11 @@ if __name__ == '__main__':
\tl_set_rescan:NnV \robExtUserInputCacheMe {} \l__robExt_placeholder___ROBEXT_MAIN_CONTENT_ORIG___str
\fi
\robExt@normalBraces\robExtUserInputCacheMe
- \expandafter\robExt@getfromstringA\robExtUserInputCacheMe\end
+ \expandafter\robExt@getfromstringA\robExtUserInputCacheMe\robExt@getfromstringA%\robExt@getfromstringA is added to know when to stop
}
% https://tex.stackexchange.com/questions/700834/efficiently-program-search-of-macro-in-string/700844
-\def\robExt@getfromstringA#1{\ifx#1\end \else
+\def\robExt@getfromstringA#1{\ifx#1\robExt@getfromstringA \else
%\ifcsname L:\string#1\endcsname \addto\listmacros{#1}\fi
\robExtLoadAutoForwardMacroConfig{#1}%
\expandafter\robExt@getfromstringA\fi
@@ -1746,11 +1753,78 @@ if __name__ == '__main__':
\robExtAutoForwardMacro{#1}[#3]
}
+\NewDocumentCommand{\NewExpandableDocumentCommandAutoForward}{mmO{}m}{
+ \NewExpandableDocumentCommand{#1}{#2}{#4}
+ \robExtAutoForwardMacro{#1}[#3]
+}
+
+\NewDocumentCommand{\RenewExpandableDocumentCommandAutoForward}{mmO{}m}{
+ \RenewExpandableDocumentCommand{#1}{#2}{#4}
+ \robExtAutoForwardMacro{#1}[#3]
+}
+
+\NewDocumentCommand{\ProvideExpandableDocumentCommandAutoForward}{mmO{}m}{
+ \ProvideExpandableDocumentCommand{#1}{#2}{#4}
+ \robExtAutoForwardMacro{#1}[#3]
+}
+
+\NewDocumentCommand{\DeclareExpandableDocumentCommandAutoForward}{mmO{}m}{
+ \DeclareExpandableDocumentCommand{#1}{#2}{#4}
+ \robExtAutoForwardMacro{#1}[#3]
+}
+
\NewDocumentCommand{\defAutoForward}{mO{}mO{}}{
\def#1#2{#3}
\robExtAutoForwardMacro{#1}[#4]
}
+% \robExtGenericAutoForward[tikz]{string to match}[additional style to run]{
+% code to run in cached file if string matches, and to always run in current folder if not using
+% the star version
+% }
+\ExplSyntaxOff
+\NewDocumentCommand{\robExtGenericAutoForward}{sO{latex}mO{}m}{%
+ \IfBooleanTF{#1}{}{#5}% We run the code right now
+ \robExt@set@hash@robust\zxTmpMacro{#5}%
+ \robExtConfigure{%
+ add to preset={#2}{%
+ if matches word={#3}{
+ command if externalization/.append code={
+ \expanded{%
+ \noexpand\robExtAddBeforePlaceholder*{__ROBEXT_MAIN_CONTENT__}{%
+ \expandonce{\zxTmpMacro}%
+ % #1%%
+ }%
+ }%
+ },#4%
+ }%
+ }%
+ }%
+}
+\let\genericAutoForward\robExtGenericAutoForward
+
+% uses "if matches" instead of "if matches word"
+\NewDocumentCommand{\robExtGenericAutoForwardStringMatch}{sO{latex}mO{}m}{%
+ \IfBooleanTF{#1}{}{#5}% We run the code right now
+ \robExt@set@hash@robust\zxTmpMacro{#5}%
+ \robExtConfigure{%
+ add to preset={#2}{%
+ if matches={#3}{
+ command if externalization/.append code={
+ \expanded{%
+ \noexpand\robExtAddBeforePlaceholder*{__ROBEXT_MAIN_CONTENT__}{%
+ \expandonce{\zxTmpMacro}%
+ % #1%%
+ }%
+ }%
+ },#4%
+ }%
+ }%
+ }%
+}
+\let\genericAutoForwardStringMatch\robExtGenericAutoForwardStringMatch
+\ExplSyntaxOn
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Automatically forward (regex-based)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -2119,6 +2193,25 @@ if __name__ == '__main__':
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
command if externalization/.code={},
fw/.style={forward=#1},
+ run code before main content if externalization enabled/.code={\message{#1}},
+ % run code before main content if externalization enabled/.code={
+ % \message{aaa #1}
+ % \def\zx@tmp{#1}%
+ % \message{xxx}
+ % \show\zx@tmp%
+ % \scantokens{%
+ % \pgfkeysalso{
+ % command if externalization/.append code={%
+ % \expanded{%
+ % \noexpand\robExtAddBeforePlaceholder*{__ROBEXT_MAIN_CONTENT__}{%
+ % % \expandonce{\zx@tmp}%
+ % #1%%
+ % }%
+ % }%
+ % }%
+ % }%
+ % },
+ % },
forward/.style={%
command if externalization/.append code={%
\robExtGetCommandDefinitionInMacro{#1}%
@@ -2186,6 +2279,7 @@ if __name__ == '__main__':
load auto forward macro config/.code={\robExtLoadAutoForwardMacroConfig{#1}},
%% This will
if matches regex/.code 2 args={\robExtIfMatchesRegex{#1}{#2}},
+ if matches word/.code 2 args={\robExtIfMatchesString{#1}{#2}},
if matches/.code 2 args={\robExtIfMatchesString{#1}{#2}},
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Run code before/after inclusion %%%
@@ -2216,6 +2310,13 @@ if __name__ == '__main__':
\gdef\robExt@compile@parallel@after{#1}%
},
compile in parallel after/.default=0,
+ disable compile in parallel/.code={\let\robExt@compile@parallel@after\undefined},
+ if windows/.code={%
+ \robExtIfWindowsTF{\pgfkeysalso{zx@tmp@key/.estyle={\unexpanded{#1}},zx@tmp@key}}{}%
+ },
+ if unix/.code={%
+ \robExtIfWindowsTF{}{\pgfkeysalso{zx@tmp@key/.estyle={\unexpanded{#1}},zx@tmp@key}}%
+ },
compile in parallel command/.store in=\robExt@compile@parallel@command,
% Different backends to compile in parallel
compile in parallel with gnu parallel/.style={
@@ -2223,15 +2324,14 @@ if __name__ == '__main__':
},
compile in parallel with gnu parallel/.default={200\%},
compile in parallel with xargs/.style={
- compile in parallel command={xargs -t -a '\jobname-\robExtAddPrefixName{compile-missing-figures.sh}' -I "{}" -P #1 \robExtParallelShell\space '{}'},
+ % Use " instead of ' as Windows does not consider ' as a valid surrounding for strings
+ compile in parallel command={xargs -t -I "{}" -P #1 \robExtParallelShell\space "{}" < "\jobname-\robExtAddPrefixName{compile-missing-figures.sh}"},
},
+ % With 0 it spawns as many shells at possible, i.e. it compiles all 200 pictures at the same time, making the
+ % system a laggy, and it is actually *slower* (2:05mn vs 1:15mn) than when using 16 threads.
compile in parallel with xargs/.default={16},
% By default, we compile with xargs and 16 processes:
compile in parallel with xargs,
- compile in parallel with rush/.style={
- compile in parallel command={rush -i "\jobname-\robExtAddPrefixName{compile-missing-figures.sh}" #1 "\robExtParallelShell\space '{}'"},
- },
- compile in parallel with rush/.default={},
}
\ExplSyntaxOn
@@ -2309,7 +2409,7 @@ if __name__ == '__main__':
\NewDocumentCommand{\robExtCacheMe}{O{}m}{%
{% Group
%% We store the input in a non-string element for efficiently implementing "auto forward"
- \def\robExtUserInputCacheMe{#2}
+ \edef\robExtUserInputCacheMe{\unexpanded{#2}}% \unexpanded is needed if the macro contains a #1
\pgfkeys{%
/robExt/.cd,%
set placeholder={__ROBEXT_MAIN_CONTENT_ORIG__}{#2},%