Skip to content

Commit

Permalink
Fix #45, introduce if matches else, and fix infinite compilation (war…
Browse files Browse the repository at this point in the history
…ning: invalidate latex cache of previous versions)
  • Loading branch information
tobiasBora committed May 21, 2024
1 parent 177e677 commit 75beeaa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Binary file modified doc/robust-externalize.pdf
Binary file not shown.
9 changes: 6 additions & 3 deletions doc/robust-externalize.tex
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ \section{A taste of this library}

Since v2.3 we also provide a way to include online pictures with |\includegraphicsWeb|:
\begin{codeexample}[width=0pt,vbox]
Here is a picture of cat downloaded online: \includegraphicsWeb[width=3cm]{http://placekitten.com/400/300}.
Here is a picture of cat downloaded online: \includegraphicsWeb[width=3cm]{https://placebear.com/400/300}.
\end{codeexample}

You can also cache arbitrary code (e.g.\ python). Note that if you use a version before 2.7, you cannot indent the python code. You can also define arbitrary compilation commands, inclusion commands, and presets to fit you need. For instance, you can create a preset to obtain:
Expand Down Expand Up @@ -3547,6 +3547,7 @@ \subsubsection{Forward macros}\label{sec:forward}
\makeatletter%
\def\extrakeytext{style, }
\extractkey/robExt/if matches=\marg{string}\marg{style to apply}\@nil
\extractkey/robExt/if matches else=\marg{string}\marg{style to apply if match}\marg{style to apply if no match}\@nil
\extractkey/robExt/if matches word=\marg{string}\marg{style to apply}\@nil
\extractkey/robExt/if matches regex=\marg{latex3 regex}\marg{style to apply}\@nil
\extractkey/robExt/register word with namespace=\marg{namespace}\marg{word}\marg{style}\@nil
Expand Down Expand Up @@ -4138,7 +4139,7 @@ \subsubsection{Online images}
\pgfmanualbody
|\includegraphicsWeb| is used in place of |\includegraphics| to download online images:
\begin{codeexample}[width=0pt,vbox]
Here is a cat downloaded online: \includegraphicsWeb[width=3cm]{http://placekitten.com/400/300}.
Here is a cat downloaded online: \includegraphicsWeb[width=3cm]{https://placebear.com/400/300}.
\end{codeexample}
By default, the engine uses |wget| in linux (since it is installed by default) and |curl| on windows (should also be installed by default on recent windows). But you can change it by modifying the |web image| preset (or using the optional robExt options that are loaded after |web image|):
\begin{codeexample}[width=0pt,vbox]
Expand All @@ -4148,7 +4149,7 @@ \subsubsection{Online images}
},
}
Here is a cat downloaded online: \includegraphicsWeb[width=3cm]{http://placekitten.com/400/303}.
Here is a cat downloaded online: \includegraphicsWeb[width=3cm]{https://placebear.com/400/303}.
\end{codeexample}
By default, the |wget| and |curl| presets are defined as:
\begin{verbatim}
Expand Down Expand Up @@ -4966,6 +4967,8 @@ \section{Changelog}
\item Fix bug with |no cache folder|
\item Fix bug with |add to compilation command options| not working
\item Added |forward counter and back| and |forward counter back|
\item Fix infinite compilation time when input does not exist (WARNING:, it will invalidate all previously cached LaTeX documents since this adds a compilation option to LaTeX by default! If you want to use the old buggy behavior to preserve your cache, define |\robExtSetPlaceholder{__ROBEXT_LATEX_COMPILATION_COMMAND_OPTIONS__}{-halt-on-error}|. Anyway, if you want truly reproducible caching, just copy the .sty file in your project)
\item Support |if matches else|
\end{itemize}
\item v2.9 (2024/03/15)
\begin{itemize}
Expand Down
9 changes: 5 additions & 4 deletions robust-externalize.sty
Original file line number Diff line number Diff line change
Expand Up @@ -2373,8 +2373,8 @@ if __name__ == '__main__':
\regex_match:nVTF {#1} \l__robExt_placeholder___ROBEXT_MAIN_CONTENT_ORIG___str {\pgfkeysalso{#2}} {}
}

\NewDocumentCommand{\robExtIfMatchesString}{mm}{
\str_if_in:NnTF \l__robExt_placeholder___ROBEXT_MAIN_CONTENT_ORIG___str {#1} {\pgfkeysalso{#2}} {}
\NewDocumentCommand{\robExtIfMatchesString}{mmm}{
\str_if_in:NnTF \l__robExt_placeholder___ROBEXT_MAIN_CONTENT_ORIG___str {#1} {\pgfkeysalso{#2}} {\pgfkeysalso{#3}}
}

% \robExtRegisterWord {namespace} {word} {style}
Expand Down Expand Up @@ -3080,7 +3080,8 @@ if __name__ == '__main__':
auto forward words/.style={auto forward words namespace={}},
%% This will
if matches regex/.code 2 args={\robExtIfMatchesRegex{#1}{#2}},
if matches/.code 2 args={\robExtIfMatchesString{#1}{#2}},
if matches/.code 2 args={\robExtIfMatchesString{#1}{#2}{}},
if matches else/.code n args={3}{\robExtIfMatchesString{#1}{#2}{#3}},
if matches word/.code 2 args={%
\robExtRegisterWord{}{#1}{#2}%
% If ran inside a preset, we want to enable it, otherwise we enable it on the latex preset
Expand Down Expand Up @@ -3476,7 +3477,7 @@ __ROBEXT_LATEX_WRITE_DEPTH_TO_OUT_FILE__%

%% Compilation commands
\robExtSetPlaceholder{__ROBEXT_LATEX_COMPILATION_COMMAND__}{__ROBEXT_LATEX_ENGINE__ __ROBEXT_LATEX_COMPILATION_COMMAND_OPTIONS__ "__ROBEXT_SOURCE_FILE__"}
\robExtSetPlaceholder{__ROBEXT_LATEX_COMPILATION_COMMAND_OPTIONS__}{-halt-on-error}
\robExtSetPlaceholder{__ROBEXT_LATEX_COMPILATION_COMMAND_OPTIONS__}{-halt-on-error -interaction=nonstopmode}
\robExtSetPlaceholder{__ROBEXT_LATEX_ENGINE__}{pdflatex}

\robExtConfigure{
Expand Down

0 comments on commit 75beeaa

Please sign in to comment.