texlive[56941] Master/texmf-dist: subfiles (15nov20)

commits+karl at tug.org commits+karl at tug.org
Sun Nov 15 23:21:32 CET 2020


Revision: 56941
          http://tug.org/svn/texlive?view=revision&revision=56941
Author:   karl
Date:     2020-11-15 23:21:31 +0100 (Sun, 15 Nov 2020)
Log Message:
-----------
subfiles (15nov20)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/subfiles/subfiles.pdf
    trunk/Master/texmf-dist/source/latex/subfiles/subfiles.dtx
    trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.cls
    trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.sty

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

Modified: trunk/Master/texmf-dist/source/latex/subfiles/subfiles.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/subfiles/subfiles.dtx	2020-11-15 22:21:18 UTC (rev 56940)
+++ trunk/Master/texmf-dist/source/latex/subfiles/subfiles.dtx	2020-11-15 22:21:31 UTC (rev 56941)
@@ -23,12 +23,12 @@
 %
 %<*driver>
 % \fi
-\ProvidesFile{subfiles.dtx}[2020/10/29 v2.1 Multi-file projects]
+\ProvidesFile{subfiles.dtx}[2020/11/14 v2.2 Multi-file projects]
 % \iffalse
 \documentclass{ltxdoc}
 \GetFileInfo{subfiles.dtx}
 \title{A Document Class and a Package\\for Handling Multi-File Projects}
-\date{2020/10/29 v2.1}
+\date{2020/11/14 v2.2}
 \author{Federico Garcia, Gernot Salzer}
 \usepackage{hyperref}
 \begin{document}
@@ -340,7 +340,7 @@
 % \item
 %   Make sure to use the most recent version of the |subfiles| package, available from CTAN\footnote{\url{https://ctan.org/pkg/subfiles}} and Github\footnote{\url{https://github.com/gsalzer/subfiles}}.
 % \item
-%   Make sure that |\usepackage{subfiles}| appears near the end of the main preamble.
+%   Make sure that |\usepackage{subfiles}| appears near the end of the main preamble. If you need the package |standalone|, then it has to be loaded before |subfiles|.
 % \item
 %   If some external program that cooperates with \TeX, like |bibtex| or |biber|, complains about not being able to find a file, locate the name of the file in the \LaTeX\ source and replace \meta{filename} by |\subfix{|\meta{filename}|}|.
 % \item
@@ -410,6 +410,10 @@
 %   \item Section about cross-referencing added.
 %     Thanks to Github user |ndvanforeest| for the input.
 %   \end{itemize}
+% \item[v2.2]
+%   \begin{itemize}
+%   \item Bugfix: The bugfix of v2.1 introduced an incompatibility with |tabular| environments in subfiles. Thanks to |yuishin-kikuchi| and |nvmnghia| on Github for reporting the issue. Kudos to |Phelype Oleinik| on tex.stackexchange.com for explaining the intricacies of the |tabular| environment and its interaction with the |\end| command.
+%   \end{itemize}
 % \end{enumerate}
 %
 %\section{The Implementation}
@@ -421,7 +425,7 @@
 %
 %    \begin{macrocode}
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesClass{subfiles}[2020/10/29 v2.1 Multi-file projects (class)]
+\ProvidesClass{subfiles}[2020/11/14 v2.2 Multi-file projects (class)]
 \DeclareOption*{%
   \typeout{Preamble taken from file `\CurrentOption'}%
   \let\preamble at file\CurrentOption
@@ -484,62 +488,59 @@
 %
 %    \begin{macrocode}
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{subfiles}[2020/10/29 v2.1 Multi-file projects (package)]
+\ProvidesPackage{subfiles}[2020/11/14 v2.2 Multi-file projects (package)]
 %    \end{macrocode}
 % \subsubsection*{Auxiliary commands}
-% \begin{flushleft}
-%   |\ifDOCUMENT{|\meta{string}|}{|\meta{then code}|}{|\meta{else code}|}|\\
-%   If \meta{string} equals |document|, then execute \meta{then code}, else \meta{else code}.
-% \end{flushleft}
+%
+% When redefining the |\end| command, we have to have to keep it expandable to a certain depth.
+% Therefore we need an expandable way to compare strings.
+% We borrow the function from LaTeX's |expl3| part.
+%
 %    \begin{macrocode}
-\def\subfiles at DOCUMENT{document}
-\def\ifDOCUMENT#1#2#3{%
-  \def\subfiles at tmp{#1}%
-  \ifx\subfiles at tmp\subfiles at DOCUMENT
-    \def\subfiles at tmp{#2}%
-  \else
-    \def\subfiles at tmp{#3}%
-  \fi
-  \subfiles at tmp
-}
+\ExplSyntaxOn
+\cs_new_eq:NN \subfiles at StrIfEqTF \str_if_eq:nnTF
+\ExplSyntaxOff
 %    \end{macrocode}
 %
-% \begin{flushleft}
-%   |\subfiles at renewDocument{begin}{|\meta{begin-document-code}|}|\\ 
-%   |\subfiles at renewDocument{end}{|\meta{end-document-code}|}|\\
-% Redefines |\begin|/|\end| to execute the given code in place of the next |\begin{document}|/|\end{document}|.
-% \end{flushleft}
+% The macro |\subfiles at renewBeginDocument{|\meta{code}|}| redefines |\begin| such that the next |\begin{document}| executes \meta{code} (and then restores the original definition of |\begin|).
+%
 %    \begin{macrocode}
-\def\subfiles at renewDocument#1#2{%
-  \expandafter\def\csname#1\endcsname##1{%
-    \ifDOCUMENT{##1}{%
-      \expandafter\let\csname#1\expandafter\endcsname\csname subfiles@#1\endcsname
-      #2%
+\def\subfiles at renewBeginDocument#1{%
+  \let\subfiles at begin\begin
+  \def\begin##1{%
+    \subfiles at StrIfEqTF{##1}{document}{%
+      \let\begin\subfiles at begin
+      #1%
     }{%
-      \csname subfiles@#1\endcsname{##1}%
+      \csname subfiles at begin\endcsname{##1}%
     }%
   }%
 }
 %    \end{macrocode}
-% |\subfiles at renewDocument{begin}{<code>}| is actually the same as
-% \begin{verbatim}
-%\def\begin#1{%
-%    \ifDOCUMENT{#1}{%
-%        \let\begin\subfiles at begin
-%        <code>
-%    }{%
-%        \subfiles at begin{#1}%
-%    }%
-%}%\end{verbatim}
-% \begin{flushleft}
-% |\subfiles at newSkipToDocument\begin|\meta{cmd}|{|\meta{continuation}|}|\\
-% |\subfiles at newSkipToDocument\end|\meta{cmd}|{|\meta{continuation}|}|\\
-% Defines \meta{cmd} to skip to the next |\begin{document}| or |\end{document}| and to execute \meta{continuation}.
-% \end{flushleft}
 %
+% The macro |\subfiles at renewEndDocument{|\meta{code}|}| redefines |\end| such that the next |\end{document}| executes \meta{code} (and then restores the original definition of |\end|).
+% This macro is more complex then the previous one, as we have to ensure that
+% |\expandafter\expandafter\expandafter\relax\end{env}| expands to |\relax\endenv|.
+% This is necessary for |tabular|s to work correctly.
+%
 %    \begin{macrocode}
-\def\subfiles at newSkipToDocument#1#2#3{%
-  \long\def#2##1#1##2{\ifDOCUMENT{##2}{#3}{#2}}%
+\def\subfiles at saveEndTo#1{\expandafter\let\expandafter#1\csname end \endcsname}
+\def\subfiles at restoreEndFrom{\expandafter\let\csname end \endcsname}
+\def\subfiles at renewEndDocument#1{%
+  \ifcsname subfiles at end\endcsname
+  \else
+    \subfiles at saveEndTo\subfiles at end
+  \fi
+  \expandafter\def\csname end \endcsname##1{%
+    \romannumeral
+    \subfiles at StrIfEqTF{##1}{document}{%
+      \z@
+      \subfiles at restoreEndFrom\subfiles at end
+      #1%
+    }{%
+      \expandafter\expandafter\expandafter\z@\subfiles at end{##1}%
+    }%
+  }%
 }
 %    \end{macrocode}
 %
@@ -546,19 +547,27 @@
 % \subsubsection*{Handling the main document}
 %
 % When the main document is loaded from a subfile, the preamble is read, but the document itself is skipped.
-% The lines after |\end{document}| are treated again as part of the preamble in old versions (1.x), but are ignored in new versions (2.x).
+% The end of the preamble is marked by |\begin{document}|.
+% In version 1.x of the |subfiles| package, everything up to (and including) |\end{document}| is skipped, but the lines following it are treated again as part of the preamble.
+% The macro |\subfiles at handleMainDocumentVi| redefines |\begin{document}| accordingly.
 % 
 %    \begin{macrocode}
 \def\subfiles at handleMainDocumentVi{%
-  \let\subfiles at begin\begin
-  \subfiles at renewDocument{begin}{%
-    \subfiles at newSkipToDocument\end\subfiles at skipToEndDocument\ignorespaces
+  \long\def\subfiles at skipToEndDocument##1\end##2{%
+    \subfiles at StrIfEqTF{##2}{document}{\ignorespaces}{\subfiles at skipToEndDocument}%
+  }%
+  \subfiles at renewBeginDocument{%
     \subfiles at skipToEndDocument
   }%
 }
+%    \end{macrocode}
+%
+% In version 2.x of the |subfiles| package, everything following |\begin{document}| is ignored.
+% The macro |\subfiles at handleMainDocumentVii| redefines this command accordingly.
+% 
+%    \begin{macrocode}
 \def\subfiles at handleMainDocumentVii{%
-  \let\subfiles at begin\begin
-  \subfiles at renewDocument{begin}{%
+  \subfiles at renewBeginDocument{%
     \endinput
     \ignorespaces
   }%
@@ -587,10 +596,8 @@
     \let\documentclass\subfiles at documentclass
     \ignorespaces
   }%
-  \let\subfiles at begin\begin
-  \subfiles at renewDocument{begin}{%
-    \subfiles at saveEnd
-    \subfiles at renewDocument{end}\ignorespaces
+  \subfiles at renewBeginDocument{%
+    \subfiles at renewEndDocument\ignorespaces
     \ignorespaces
   }%
 }
@@ -604,34 +611,19 @@
 %    \begin{macrocode}
 \def\subfiles at handleSubDocumentVii{%
   \let\subfiles at documentclass\documentclass
-  \subfiles at newSkipToDocument\begin\documentclass{%
-    \let\documentclass\subfiles at documentclass
-    \subfiles at saveEnd
-    \subfiles at renewDocument{end}{%
-      \endinput
+  \long\def\documentclass##1\begin##2{%
+    \subfiles at StrIfEqTF{##2}{document}{%
+      \let\documentclass\subfiles at documentclass
+      \subfiles at renewEndDocument{%
+        \endinput
+        \ignorespaces
+      }%
       \ignorespaces
-    }%
-    \ignorespaces
+    }{\documentclass}
   }%
 }
 %    \end{macrocode}
 %
-% Before redefining |\begin| and |\end|, we remember their original definitions in |\subfiles at begin| and |\subfiles at end|.
-% We don't do this once and for all in the preamble, because there might be other packages also fiddling with these commands.
-% To reset |\begin| to the definition it had at the point where we modified it, we do |\let\subfiles at begin\begin| immediately before redefining it.
-% For |\end|, the situation is different.
-% For nested subfiles, |\end| does not have its original definition but ours.
-% Therefore we save |\end| only if |\subfiles at end| is still undefined (meaning that we are outside of subfiles).
-%
-%    \begin{macrocode}
-\def\subfiles at saveEnd{%
-  \ifcsname subfiles at end\endcsname
-  \else
-    \let\subfiles at end\end
-  \fi
-}
-%    \end{macrocode}
-%
 % \subsubsection*{Processing the package options}
 %
 % The package has currently only one option, |v1|, which affects the way how the text after |\end{document}| and in the preamble of subfiles is handled.
@@ -766,12 +758,12 @@
 \@ifpackageloaded{standalone}{
   \RequirePackage{xpatch}
   \xpretocmd\includestandalone{%
-    \let\subfiles at end@\end
+    \subfiles at saveEndTo\subfiles at end@
     \ifcsname subfiles at end\endcsname
-      \let\end\subfiles at end
+      \subfiles at restoreEndFrom\subfiles at end
     \fi
   }{}{}
-  \xapptocmd\includestandalone{\let\end\subfiles at end@}{}{}
+  \xapptocmd\includestandalone{\subfiles at restoreEndFrom\subfiles at end@}{}{}
 }{}
 %    \end{macrocode}
 %

Modified: trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.cls
===================================================================
--- trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.cls	2020-11-15 22:21:18 UTC (rev 56940)
+++ trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.cls	2020-11-15 22:21:31 UTC (rev 56941)
@@ -26,7 +26,7 @@
 %% and the derived files subfiles.sty and subfiles.pdf
 %% 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesClass{subfiles}[2020/10/29 v2.1 Multi-file projects (class)]
+\ProvidesClass{subfiles}[2020/11/14 v2.2 Multi-file projects (class)]
 \DeclareOption*{%
   \typeout{Preamble taken from file `\CurrentOption'}%
   \let\preamble at file\CurrentOption

Modified: trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.sty	2020-11-15 22:21:18 UTC (rev 56940)
+++ trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.sty	2020-11-15 22:21:31 UTC (rev 56941)
@@ -26,40 +26,49 @@
 %% and the derived files subfiles.sty and subfiles.pdf
 %% 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{subfiles}[2020/10/29 v2.1 Multi-file projects (package)]
-\def\subfiles at DOCUMENT{document}
-\def\ifDOCUMENT#1#2#3{%
-  \def\subfiles at tmp{#1}%
-  \ifx\subfiles at tmp\subfiles at DOCUMENT
-    \def\subfiles at tmp{#2}%
+\ProvidesPackage{subfiles}[2020/11/14 v2.2 Multi-file projects (package)]
+\ExplSyntaxOn
+\cs_new_eq:NN \subfiles at StrIfEqTF \str_if_eq:nnTF
+\ExplSyntaxOff
+\def\subfiles at renewBeginDocument#1{%
+  \let\subfiles at begin\begin
+  \def\begin##1{%
+    \subfiles at StrIfEqTF{##1}{document}{%
+      \let\begin\subfiles at begin
+      #1%
+    }{%
+      \csname subfiles at begin\endcsname{##1}%
+    }%
+  }%
+}
+\def\subfiles at saveEndTo#1{\expandafter\let\expandafter#1\csname end \endcsname}
+\def\subfiles at restoreEndFrom{\expandafter\let\csname end \endcsname}
+\def\subfiles at renewEndDocument#1{%
+  \ifcsname subfiles at end\endcsname
   \else
-    \def\subfiles at tmp{#3}%
+    \subfiles at saveEndTo\subfiles at end
   \fi
-  \subfiles at tmp
-}
-\def\subfiles at renewDocument#1#2{%
-  \expandafter\def\csname#1\endcsname##1{%
-    \ifDOCUMENT{##1}{%
-      \expandafter\let\csname#1\expandafter\endcsname\csname subfiles@#1\endcsname
-      #2%
+  \expandafter\def\csname end \endcsname##1{%
+    \romannumeral
+    \subfiles at StrIfEqTF{##1}{document}{%
+      \z@
+      \subfiles at restoreEndFrom\subfiles at end
+      #1%
     }{%
-      \csname subfiles@#1\endcsname{##1}%
+      \expandafter\expandafter\expandafter\z@\subfiles at end{##1}%
     }%
   }%
 }
-\def\subfiles at newSkipToDocument#1#2#3{%
-  \long\def#2##1#1##2{\ifDOCUMENT{##2}{#3}{#2}}%
-}
 \def\subfiles at handleMainDocumentVi{%
-  \let\subfiles at begin\begin
-  \subfiles at renewDocument{begin}{%
-    \subfiles at newSkipToDocument\end\subfiles at skipToEndDocument\ignorespaces
+  \long\def\subfiles at skipToEndDocument##1\end##2{%
+    \subfiles at StrIfEqTF{##2}{document}{\ignorespaces}{\subfiles at skipToEndDocument}%
+  }%
+  \subfiles at renewBeginDocument{%
     \subfiles at skipToEndDocument
   }%
 }
 \def\subfiles at handleMainDocumentVii{%
-  \let\subfiles at begin\begin
-  \subfiles at renewDocument{begin}{%
+  \subfiles at renewBeginDocument{%
     \endinput
     \ignorespaces
   }%
@@ -73,31 +82,24 @@
     \let\documentclass\subfiles at documentclass
     \ignorespaces
   }%
-  \let\subfiles at begin\begin
-  \subfiles at renewDocument{begin}{%
-    \subfiles at saveEnd
-    \subfiles at renewDocument{end}\ignorespaces
+  \subfiles at renewBeginDocument{%
+    \subfiles at renewEndDocument\ignorespaces
     \ignorespaces
   }%
 }
 \def\subfiles at handleSubDocumentVii{%
   \let\subfiles at documentclass\documentclass
-  \subfiles at newSkipToDocument\begin\documentclass{%
-    \let\documentclass\subfiles at documentclass
-    \subfiles at saveEnd
-    \subfiles at renewDocument{end}{%
-      \endinput
+  \long\def\documentclass##1\begin##2{%
+    \subfiles at StrIfEqTF{##2}{document}{%
+      \let\documentclass\subfiles at documentclass
+      \subfiles at renewEndDocument{%
+        \endinput
+        \ignorespaces
+      }%
       \ignorespaces
-    }%
-    \ignorespaces
+    }{\documentclass}
   }%
 }
-\def\subfiles at saveEnd{%
-  \ifcsname subfiles at end\endcsname
-  \else
-    \let\subfiles at end\end
-  \fi
-}
 \let\subfiles at handleMainDocument\subfiles at handleMainDocumentVii
 \let\subfiles at handleSubDocument\subfiles at handleSubDocumentVii
 \DeclareOption{v1}{%
@@ -159,12 +161,12 @@
 \@ifpackageloaded{standalone}{
   \RequirePackage{xpatch}
   \xpretocmd\includestandalone{%
-    \let\subfiles at end@\end
+    \subfiles at saveEndTo\subfiles at end@
     \ifcsname subfiles at end\endcsname
-      \let\end\subfiles at end
+      \subfiles at restoreEndFrom\subfiles at end
     \fi
   }{}{}
-  \xapptocmd\includestandalone{\let\end\subfiles at end@}{}{}
+  \xapptocmd\includestandalone{\subfiles at restoreEndFrom\subfiles at end@}{}{}
 }{}
 \newcommand\ifSubfilesClassLoaded{%
   \expandafter\ifx\csname ver at subfiles.cls\endcsname\relax



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