texlive[70598] Master/texmf-dist: robust-externalize (11mar24)

commits+karl at tug.org commits+karl at tug.org
Mon Mar 11 20:59:49 CET 2024


Revision: 70598
          https://tug.org/svn/texlive?view=revision&revision=70598
Author:   karl
Date:     2024-03-11 20:59:49 +0100 (Mon, 11 Mar 2024)
Log Message:
-----------
robust-externalize (11mar24)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.pdf
    trunk/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.tex
    trunk/Master/texmf-dist/tex/latex/robust-externalize/robust-externalize.sty

Modified: trunk/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.tex	2024-03-11 19:59:31 UTC (rev 70597)
+++ trunk/Master/texmf-dist/doc/latex/robust-externalize/robust-externalize.tex	2024-03-11 19:59:49 UTC (rev 70598)
@@ -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 @@
 
 
 \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 @@
 }
 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 @@
 \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|

Modified: trunk/Master/texmf-dist/tex/latex/robust-externalize/robust-externalize.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/robust-externalize/robust-externalize.sty	2024-03-11 19:59:31 UTC (rev 70597)
+++ trunk/Master/texmf-dist/tex/latex/robust-externalize/robust-externalize.sty	2024-03-11 19:59:49 UTC (rev 70598)
@@ -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 @@
 
 \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,7 +932,19 @@
 }
 \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}
 %   def my_helper_function(bla):
@@ -940,8 +952,8 @@
 % \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 @@
   \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 @@
 %% \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 @@
   \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 @@
   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 @@
   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={



More information about the tex-live-commits mailing list.