summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2024-03-11 19:59:49 +0000
committerKarl Berry <karl@freefriends.org>2024-03-11 19:59:49 +0000
commit1d36187d0b42d19c20d56b50639435da78d29053 (patch)
tree211b5a55a7fcb8be8edec6ffb54f3aeb110f659c
parent3e08c0302428b01ef3e7afdb4d101b03791a625f (diff)
robust-externalize (11mar24)
git-svn-id: svn://tug.org/texlive/trunk@70598 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.pdfbin1630257 -> 1653583 bytes
-rw-r--r--Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.tex31
-rw-r--r--Master/texmf-dist/tex/latex/robust-externalize/robust-externalize.sty54
3 files changed, 64 insertions, 21 deletions
diff --git a/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.pdf b/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.pdf
index 4eca1dad3fd..60be5cb58bb 100644
--- a/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.pdf
+++ b/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.tex b/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.tex
index 93d7f664e07..be0c689b612 100644
--- a/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.tex
+++ b/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.tex
@@ -105,7 +105,7 @@
{\Large\bfseries Cache anything (\tikzname, tikz-cd, python…),\\in a robust, efficient and pure way.}
\vspace{1em}
- {Léo Colisson \quad Version 2.6}\\[3mm]
+ {Léo Colisson \quad Version 2.7}\\[3mm]
{\href{https://github.com/leo-colisson/robust-externalize}{\texttt{github.com/leo-colisson/robust-externalize}}}
\end{center}
@@ -1711,8 +1711,8 @@ This is contrary to |\getPlaceholder| that is not expandable, so if you do want
\begin{pgfmanualentry}
- \extractenvironement{PlaceholderFromCode}\opt{*}\marg{name placeholder}\@@
- \extractenvironement{SetPlaceholderCode}\opt{*}\marg{name placeholder}\@@
+ \extractenvironement{PlaceholderFromCode}\opt{*}\opt{\oarg{style}}\marg{name placeholder}\@@
+ \extractenvironement{SetPlaceholderCode}\opt{*}\opt{\oarg{style}}\marg{name placeholder}\@@
\pgfmanualbody
These two (aliased) environments are useful to set a verbatim value to a given placeholder: the advantage is that you can put inside any code, including \LaTeX{} comments, the downside is that you cannot use it inside macros and some environments (so you typically define it before the macros and call it inside).
@@ -1758,6 +1758,27 @@ def my_function(b): # this is a python code
}
Note that of course, you can define a placeholder before a macro and call it inside (explaining how we can generate this documentation).
+You can use the optional style (only after 2.7; note that it defaults to |defaultPlaceholderFromCodeStyle|, which contains by default |remove leading spaces|) to apply some operations on the style. This way, by default, it will remove any leading indentation, allowing you, for instance, to indent your python code based on the surrounding LaTeX environment):
+\begin{codeAndResult}
+\begin{PlaceholderFromCode}{__TMP_MAIN_CONTENT__}
+ # See, you can indent this code with two spaces without disturbing python (that expects no indentation)
+ import matplotlib.pyplot as plt
+ year = [2014, 2015, 2016, 2017, 2018, 2019]
+ tutorial_count = [39, 117, 111, 110, 67, 29]
+ plt.plot(year, tutorial_count, color="#6c3376", linewidth=3)
+ plt.xlabel('Year')
+ plt.ylabel('Number of futurestud.io Tutorials')
+ plt.savefig("__ROBEXT_OUTPUT_PDF__")
+\end{PlaceholderFromCode}
+
+\fbox{\begin{CacheMeNoContent}
+ python,
+ set includegraphics options={width=.8\linewidth},
+ set main content={__TMP_MAIN_CONTENT__},
+\end{CacheMeNoContent}}
+\end{codeAndResult}
+
+
Note that the star and no import version does NOT import the placeholder it the main group (unless you try to optimize the compilation time you should not need it, but see \cref{sec:importSystem} for details).
\end{pgfmanualentry}
@@ -4911,6 +4932,10 @@ Options > Configure TeXstudio > Editor > Replace tabs in text with spaces
\section{Changelog}
\begin{itemize}
+\item v2.7:
+ \begin{itemize}
+ \item apply |remove leading spaces| by default also in |placeholderFromCode| and |PlaceholderPathFromCode|, and allow the user to customize the style. This produces a very minor backward incompatibility as it might disturb code where all lines start with a space.
+ \end{itemize}
\item v2.6:
\begin{itemize}
\item Added |\lenToCmNoUnit|
diff --git a/Master/texmf-dist/tex/latex/robust-externalize/robust-externalize.sty b/Master/texmf-dist/tex/latex/robust-externalize/robust-externalize.sty
index 488cbb7c8f0..fa9500e82d5 100644
--- a/Master/texmf-dist/tex/latex/robust-externalize/robust-externalize.sty
+++ b/Master/texmf-dist/tex/latex/robust-externalize/robust-externalize.sty
@@ -1,4 +1,4 @@
-\ProvidesPackage{robust-externalize}[2.6 Cache anything (tikz, latex, python) in a robust, efficient and pure way.]
+\ProvidesPackage{robust-externalize}[2.7 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
@@ -653,7 +653,7 @@ if __name__ == '__main__':
\NewDocumentCommand{\robExtShowPlaceholder}{sm}{
\cs_if_exist:cTF {l__robExt_placeholder_#2_str} {
- \message{Placeholder ~ #2 ~ contains:^^J~ \use:c{l__robExt_placeholder_#2_str}}
+ \message{Placeholder ~ #2 ~ contains:^^J \use:c{l__robExt_placeholder_#2_str}}
}{
\message{Placeholder ~ #2 ~ does ~ not ~ exist.}
}
@@ -932,6 +932,18 @@ if __name__ == '__main__':
}
\let\addBeforePlaceholderNoImport\robExtAddBeforePlaceholderNoImport
+\ExplSyntaxOff
+
+% except inside setplaceholderfromcode, we want to modify by default the main content orig placeholder
+\def\robExtCurrentPlaceholderName{__ROBEXT_MAIN_CONTENT_ORIG__}
+
+\pgfqkeys{/robExt}{
+ defaultPlaceholderFromCodeStyle/.style={
+ remove leading spaces,
+ },
+}
+
+\ExplSyntaxOn
% Usage:
% \begin{placeholderFromCode}{HELPERFUNCTION}
@@ -940,8 +952,8 @@ if __name__ == '__main__':
% \end{placeholderFromCode}
% HELPERFUNCTION will contain at the end "def ..."
% This environment cannot be placed inside any other macro/align/...
-\NewDocumentEnvironment{RobExtPlaceholderFromCode}{sm}{%
- \checkIfPlaceholderNameIsLegal{#2}%
+\NewDocumentEnvironment{RobExtPlaceholderFromCode}{sO{defaultPlaceholderFromCodeStyle}m}{%
+ \checkIfPlaceholderNameIsLegal{#3}%
% % debug part
% \str_set:Nn \l_test_str {#1}
% \show\l_test_str
@@ -960,14 +972,17 @@ if __name__ == '__main__':
\ior_str_map_inline:Nn \g__robExt_read_ior {%
\str_gput_right:Nx \l__robExt_tmp_str {\tl_to_str:n{##1}^^J}%
}%
- \str_set_eq:cN {l__robExt_placeholder_#2_str} \l__robExt_tmp_str%
+ \str_set_eq:cN {l__robExt_placeholder_#3_str} \l__robExt_tmp_str%
+ %% We apply the style, useful for instance to remove indentation
+ \def\robExtCurrentPlaceholderName{#3}%
+ \pgfqkeys{/robExt}{#2}%
\IfBooleanTF {#1} {} {
- \robExtAddPlaceholderToList{#2}
+ \robExtAddPlaceholderToList{#3}
%% Otherwise they will be lost when the environment ends
\robExtKeepaftergroup{l__robExt_placeholder_group_main_seq}%
- }
+ }%
%% for other variable
- \robExtKeepaftergroup{l__robExt_placeholder_#2_str}%
+ \robExtKeepaftergroup{l__robExt_placeholder_#3_str}%
}%
\let\PlaceholderFromCode\RobExtPlaceholderFromCode
\let\endPlaceholderFromCode\endRobExtPlaceholderFromCode
@@ -1050,7 +1065,7 @@ if __name__ == '__main__':
%% \end{PlaceholderPathFromCode}
%% This will copy "some code" in the cache, and set MYLIBPATH to the name of the file in the cache like
%% MYLIBPATH = robExt-abc.py
-\NewDocumentEnvironment{RobExtPlaceholderPathFromCode}{sO{}m}{
+\NewDocumentEnvironment{RobExtPlaceholderPathFromCode}{sO{}O{defaultPlaceholderFromCodeStyle}m}{
\XSIMfilewritestart*{\jobnameNoQuotes-robExt-tmp-file-you-can-remove.tmp}
}{
\XSIMfilewritestop
@@ -1068,13 +1083,16 @@ if __name__ == '__main__':
\iow_now:NV \g__robExt_write_iow \l__robExt_tmp_contain_file_str
\iow_close:N \g__robExt_write_iow
%% sets the template name to the relative path to the file
- \str_set:cx { l__robExt_placeholder_#3_str } {\robExtPrefixFilename\l__robExt_tmp_filename_no_prefix_str}
+ \str_set:cx { l__robExt_placeholder_#4_str } {\robExtPrefixFilename\l__robExt_tmp_filename_no_prefix_str}
+ %% We apply the style, useful for instance to remove indentation
+ \def\robExtCurrentPlaceholderName{#4}%
+ \pgfqkeys{/robExt}{#3}%
\IfBooleanTF {#1} {} {
- \robExtAddPlaceholderToList{#3}
+ \robExtAddPlaceholderToList{#4}
\robExtKeepaftergroup{l__robExt_placeholder_group_main_seq}
}
%% Otherwise they will be lost when the environment ends
- \robExtKeepaftergroup{l__robExt_placeholder_#3_str}
+ \robExtKeepaftergroup{l__robExt_placeholder_#4_str}
}
\let\PlaceholderPathFromCode\RobExtPlaceholderPathFromCode
\let\endPlaceholderPathFromCode\endRobExtPlaceholderPathFromCode
@@ -2618,7 +2636,7 @@ if __name__ == '__main__':
remove placeholders/.style={
remove placeholder/.list={#1},
},
- set main content/.style={
+ set main content/.style={
set placeholder={__ROBEXT_MAIN_CONTENT_ORIG__}{#1}
},
copy placeholder/.code 2 args={\robExtCopyPlaceholder{#1}{#2}},
@@ -2661,19 +2679,19 @@ if __name__ == '__main__':
placeholder replace in place eval/.code n args={3}{\robExtPlaceholderReplaceInplaceEval{#1}{#2}{#3}},
placeholder prepend all lines/.code 2 args={\robExtPlaceholderPrependAllLines{#1}{#2}},
prepend all lines/.style={
- placeholder prepend all lines={__ROBEXT_MAIN_CONTENT_ORIG__}{#1},
+ placeholder prepend all lines={\robExtCurrentPlaceholderName}{#1},
},
placeholder remove spaces until/.code 2 args={\robExtPlaceholderRemoveSpacesUntil{#1}{#2}},
remove spaces until/.style={
- placeholder remove spaces until={__ROBEXT_MAIN_CONTENT_ORIG__}{#1},
+ placeholder remove spaces until={\robExtCurrentPlaceholderName}{#1},
},
placeholder strictly remove spaces until/.code 2 args={\robExtPlaceholderRemoveSpacesUntil{#1}[0]{#2}},
strictly remove spaces until/.style={
- placeholder remove spaces until nospace={__ROBEXT_MAIN_CONTENT_ORIG__}{#1},
+ placeholder remove spaces until nospace={\robExtCurrentPlaceholderName}{#1},
},
placeholder remove leading spaces/.code={\robExtPlaceholderRemoveLeadingSpaces{#1}},
- remove leading spaces/.code={\robExtPlaceholderRemoveLeadingSpaces{__ROBEXT_MAIN_CONTENT_ORIG__}},
- remove leading spaces if not disabled/.code={\ifdefined\robExtDoNotRemoveLeadingSpaces\else\robExtPlaceholderRemoveLeadingSpaces{__ROBEXT_MAIN_CONTENT_ORIG__}\fi},
+ remove leading spaces/.code={\robExtPlaceholderRemoveLeadingSpaces{\robExtCurrentPlaceholderName}},
+ remove leading spaces if not disabled/.code={\ifdefined\robExtDoNotRemoveLeadingSpaces\else\robExtPlaceholderRemoveLeadingSpaces{\robExtCurrentPlaceholderName}\fi},
do not remove leading spaces/.code={\def\robExtDoNotRemoveLeadingSpaces{}},
% Interface to set template
set template/.style={