texlive[52591] Master/texmf-dist: subfiles (31oct19)

commits+karl at tug.org commits+karl at tug.org
Thu Oct 31 23:22:58 CET 2019


Revision: 52591
          http://tug.org/svn/texlive?view=revision&revision=52591
Author:   karl
Date:     2019-10-31 23:22:58 +0100 (Thu, 31 Oct 2019)
Log Message:
-----------
subfiles (31oct19)

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	2019-10-31 22:22:47 UTC (rev 52590)
+++ trunk/Master/texmf-dist/source/latex/subfiles/subfiles.dtx	2019-10-31 22:22:58 UTC (rev 52591)
@@ -23,13 +23,13 @@
 %
 %<*driver>
 % \fi
-\ProvidesFile{subfiles.dtx}[2019/10/25 v1.4 Multi-file projects]
+\ProvidesFile{subfiles.dtx}[2019/10/30 v1.5 Multi-file projects]
 % \iffalse
 \documentclass{ltxdoc}
 \GetFileInfo{subfiles.dtx}
 \title{A Document Class and a Package\\for Handling Multi-File Projects}
-\date{\filedate{}}
- \author{Federico Garcia, Gernot Salzer}
+\date{v1.5 2019/10/30}
+\author{Federico Garcia, Gernot Salzer}
 
 \begin{document}
 \maketitle
@@ -61,7 +61,7 @@
 % 
 % \section{Basic usage}
 %
-% The main file, i.e., the file with the preamble to be shared with the subfiles, has to load the package |subfiles| \emph{at the very end of the preamble}:
+% The main file, i.e., the file with the preamble to be shared with the subfiles, has to load the package |subfiles| \emph{at the end of the preamble}:
 % \begin{center}
 %   \begin{tabular}{l}
 %     |\usepackage{subfiles}|\\
@@ -171,14 +171,36 @@
 % \end{tabular}
 % \end{center}
 % Then each of the three files can be typeset individually in its respective directory, where \LaTeX\ is able to locate all included text files and images.
+%
+% \subsection{Including files instead of inputting them}
+%
+% In plain \LaTeX, you can use either |\input| or |\include| to load a file.
+% In most cases the first is appropriate, but sometimes there are reasons to prefer the latter.
+% Internally, the |\subfile| command uses |\input|.
+% For those cases where you need |\include|, the package provides the command  
+% \begin{center}
+%   |\subfileinclude{|\meta{subfile\_name}|}|
+% \end{center}
+%
+% \subsection{Bibliographies}
+%
+% Manual bibliographies with the |thebibliography| environment work as usual.
+% Problems may arise if external programs like |bibtex| or |biber| are used to generate the bibliography, in particular when the bibliographies are distributed over subfiles.
+% Here are some hints on how it may work.
+% \begin{itemize}
+% \item Make sure the command |\bibliography| is executed after loading the |subfiles| package.
+%   Put the command between |\usepackage{subfiles}| and |\begin{document}| or somewhere into the text part.
+% \item When you use the package |biblatex|, and programs like |biber| complain about not being able to find the bibliography files, use |\bibliography| instead of |\addbibresource| for local files (observing the hint above).
+% \end{itemize}
+% The |subfiles| package has been tested with the packages |biblatex|, |bibunits|, and |chapterbib| as well as the external programs |bibtex| and |biber|. 
 % 
-% \subsection{Additional definitions for subfiles}
+% \subsection{Unusual locations for placing definitions and text}
 %
 % Usually all definitions and packages required by the subfiles should go into the preamble of the main file.
-% There are some places, though, where one might consider adding definitions for the subfiles.
+% There are some further locations, though, where one might consider adding definitions and text.
 %
 % \paragraph{Code after the end of the main document} is added to the preamble of the subfiles, but is ignored when typesetting the main file.
-% This happens because a subfile typeset by itself does not really take the preamble of the main file, but \emph{everything outside} of \verb|\begin{document}| and \verb|\end{document}|.
+% This happens because a subfile typeset by itself does not really take the preamble of the main file, but \emph{everything outside} of |\begin{document}| and |\end{document}|.
 % This has two consequences: \emph{a)}~the user can add some commands to be processed as part of the preamble only when the subfiles are typeset by themselves; but also \emph{b)}~the user has to be careful even \emph{after} |\end{document}| in the main file, for any syntax error there will ruin the \LaTeX ing of the subfile(s).
 %
 % \paragraph{Code in the preamble of a subfile} is processed as part of the text when typesetting the main file, but as part of the preamble when typesetting the subfile.
@@ -186,11 +208,16 @@
 % One should also keep in mind that each subfile is input within a group, so definitions made within may not work outside.
 % A good practice when using |subfiles| (and also when not using it) is to make any definitions in the preamble of the main file, avoiding confusion and allowing the reader to find them easily.
 %
+% \paragraph{Code after the end of a subfile} is treated like the code preceding it when the subfile is loaded from the main file, but is ignored when typesetting the subfile.
+% The code after |\end{document}| behaves as if following the |\subfile| command in the main file, except that it is still part of the group enclosing the subfile.
+% As a consequence, empty lines at the end of the subfile lead to a new paragraph in the main document, even if the |\subfile| command is immediately followed by text.
+%
 % \subsection{Avoiding extra spaces}
 %
 % Sometimes you may want to load the contents of a subfile without white space separating it from the contents of the main file.
-% In this respect |\subfile| behaves like |\input|.
+% In this respect |\subfile| behaves similar to |\input|.
 % Any space or newline before and after the |\subfile| command will appear in the typeset document, as will any white space between the last character of the subfile and |\end{document}|.
+% Moreover, any stuff after |\end{document}| will end up in the main document, including spurious empty lines, which may lead to a new paragraph.
 % Therefore, to load the contents of a subfile without intervening spaces, you have either to add comment signs:
 % \begin{center}
 %   \begin{tabular}[t]{l}
@@ -210,6 +237,7 @@
 %       |\begin{document}|\\
 %       |contents of subfile%|\\
 %       |\end{document}|\\
+%       |% No empty lines after \end{document}!|\\
 %       \hline
 %   \end{tabular}
 % \end{center}
@@ -228,16 +256,30 @@
 % \section{Version history}
 %
 % \begin{description}
-% \item[v1.1 (FG):]
-%   Start of version history.
-% \item[v1.2 (GS):]
-%   The |subfiles| package becomes compatible with classes and packages that modify the |\document| command, like the class |revtex4|.
-% \item[v1.3 (GS):]
-%   Use of |import| package to handle directory hierarchies.
-%   |\ignorespaces| added to avoid spurious spaces.
-%   Incompatibility with commands removed that expect |\document| to be equal to |\@onlypreamble| after the preamble (thanks to Eric Domenjoud for analysing the problem).
-% \item[v1.3 (GS):]
-%   Incompatibility with |memoir| class and |comment| package removed.
+% \item[v1.1:]
+%   Initial version by Federico Garcia. Further versions by Gernot Salzer.
+% \item[v1.2:] \mbox{}
+%   \begin{itemize}
+%   \item Incompatibility with classes and packages removed that modify the |\document| command, like the class |revtex4|.
+%   \end{itemize}
+% \item[v1.3:] \mbox{}
+%   \begin{itemize}
+%   \item Use of |import| package to handle directory hierarchies.
+%   \item |\ignorespaces| added to avoid spurious spaces.
+%   \item Incompatibility with commands removed that expect |\document| to be equal to |\@onlypreamble| after the preamble (thanks to Eric Domenjoud for analysing the problem).
+%   \end{itemize}
+% \item[v1.4:] \mbox{}
+%   \begin{itemize}
+%   \item Incompatibility with |memoir| class and |comment| package removed.
+%   \item Bug `|\unskip| cannot be used in vertical mode` fixed.
+%   \end{itemize}
+% \item[v1.5:] \mbox{}
+%   \begin{itemize}
+%   \item Command |\subfileinclude| added.
+%   \item Basic support for |bibtex| related bibliographies in subfiles added.
+%      Seems to suffice also for sub-bibliographies with the package |chapterbib|.
+%   \item Support for sub-bibliographies with package |bibunits| added.
+%   \end{itemize}
 % \end{description}
 %
 %\section{The Implementation}
@@ -245,10 +287,10 @@
 %    \begin{macrocode}
 %<*class>
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesClass{subfiles}[2019/10/25 v1.4 Multi-file projects (class)]
+\ProvidesClass{subfiles}[2019/10/30 v1.5 Multi-file projects (class)]
 \DeclareOption*{\typeout{Preamble taken from file `\CurrentOption'}%
     \let\preamble at file\CurrentOption}
-\ProcessOptions  
+\ProcessOptions
 %    \end{macrocode}
 %
 % We start by saving the regular \LaTeX\ definition of |\documentclass|:
@@ -345,7 +387,7 @@
 %    \begin{macrocode}
 %<*package>
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{subfiles}[2019/10/25 v1.4 Multi-file projects (package)]
+\ProvidesPackage{subfiles}[2019/10/30 v1.5 Multi-file projects (package)]
 \DeclareOption*{\PackageWarning{\CurrentOption ignored}}
 \ProcessOptions
 %    \end{macrocode}
@@ -400,12 +442,29 @@
 % After executing e.g.\ |\subfiles at split{../dir1/dir2/file.tex}|, the commands |\subfiles at dir| and |\subfiles at base| expand to |../dir1/dir2/| and |file.tex|, respectively.
 %
 % \DescribeMacro{\subfile}
-% The command |\subfile| first redefines |\documentclass| and the |document| environment to do nothing.
-% To avoid spurious spaces we |\ignorespaces|.
-% Moreover, we have to set |\document| to the value it usually has after the end of the preamble, since some commands check this value and may raise an error.
+% The command |\subfile| specifies the command |\subimport| for |\input|ing the subfile, and then calls |\subfiles at subfile|.
+%    \begin{macrocode}
+\newcommand\subfile{%
+  \let\subfiles at loadfile\subimport
+  \subfiles at subfile
+}
+%    \end{macrocode}
 %
+% \DescribeMacro{\subfileinclude}
+% The command |\subfileinclude| specifies the command |\subincludefrom| for |\include|ing the subfile, and then calls |\subfiles at subfile|.
 %    \begin{macrocode}
-\newcommand\subfile[1]{%
+\newcommand\subfileinclude{%
+  \let\subfiles at loadfile\subincludefrom
+  \subfiles at subfile
+}
+%    \end{macrocode}
+%
+% The main functionality of the two |\subfile| commands is implemented in |\subfiles at subfile|.
+% It redefines |\documentclass| and the |document| environment to do nothing except avoiding spurious spaces.
+% Moreover, |\document| has to be set to the value it usually has after the end of the preamble, since some commands check this value and may raise an error otherwise.
+%
+%    \begin{macrocode}
+\newcommand\subfiles at subfile[1]{%
   \begingroup
   \renewcommand\documentclass[2][subfiles]{\ignorespaces}%
   \renewenvironment{document}{%
@@ -415,14 +474,46 @@
     \@ignoretrue
   }%
 %    \end{macrocode}
+% Now we split the file name into path and base name and load the file.
 %
-% Now we split the file name into path and base name and |\subimport| the file.
-%
 %    \begin{macrocode}
   \subfiles at split{#1}%
-  \subimport{\subfiles at dir}{\subfiles at base}%
+  \subfiles at loadfile{\subfiles at dir}{\subfiles at base}%
   \endgroup
 }
 %    \end{macrocode}
 %
 % Note that the changes to |\documentclass| and the |document| environment happen \emph{within a group}, so they are undone after inclusion of the subfile.
+%
+% To let external programs find files, we have to add the |\import at path| to file names.
+% This is accomplished with the command |\subfiles at addimportpath|.
+%    \begin{macrocode}
+\def\subfiles at addimportpath#1{%
+  \def\subfiles at filelist{}%
+  \def\subfiles at sep{}%
+  \@for\subfiles at filename:=#1\do{%
+    \edef\subfiles at filelist{\subfiles at filelist\subfiles at sep\import at path\subfiles at filename}%
+    \def\subfiles at sep{,}%
+  }
+}
+%    \end{macrocode}
+%
+% We redefine the |\bibliography| command such that the import path is added to the file names before the original command is called.
+%    \begin{macrocode}
+\let\subfiles at bibliography\bibliography
+\renewcommand\bibliography[1]{%
+  \subfiles at addimportpath{#1}%
+  \expandafter\subfiles at bibliography\expandafter{\subfiles at filelist}%
+}
+%    \end{macrocode}
+%
+% The |bibunits| package uses its own command to specify bib files, we have to patch it separately.
+%    \begin{macrocode}
+\@ifpackageloaded{bibunits}{%
+  \let\subfiles at putbib\@putbib
+  \def\@putbib[#1]{%
+    \subfiles at addimportpath{#1}%
+    \expandafter\subfiles at putbib\expandafter[\subfiles at filelist]%
+  }%
+}{}
+%    \end{macrocode}

Modified: trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.cls
===================================================================
--- trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.cls	2019-10-31 22:22:47 UTC (rev 52590)
+++ trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.cls	2019-10-31 22:22:58 UTC (rev 52591)
@@ -26,7 +26,7 @@
 %% and the derived files subfiles.sty and subfiles.pdf
 %% 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesClass{subfiles}[2019/10/25 v1.4 Multi-file projects (class)]
+\ProvidesClass{subfiles}[2019/10/30 v1.5 Multi-file projects (class)]
 \DeclareOption*{\typeout{Preamble taken from file `\CurrentOption'}%
     \let\preamble at file\CurrentOption}
 \ProcessOptions

Modified: trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.sty	2019-10-31 22:22:47 UTC (rev 52590)
+++ trunk/Master/texmf-dist/tex/latex/subfiles/subfiles.sty	2019-10-31 22:22:58 UTC (rev 52591)
@@ -26,7 +26,7 @@
 %% and the derived files subfiles.sty and subfiles.pdf
 %% 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{subfiles}[2019/10/25 v1.4 Multi-file projects (package)]
+\ProvidesPackage{subfiles}[2019/10/30 v1.5 Multi-file projects (package)]
 \DeclareOption*{\PackageWarning{\CurrentOption ignored}}
 \ProcessOptions
 \@ifclassloaded{subfiles}{%
@@ -56,7 +56,15 @@
     \subfiles at next
   }%
 }
-\newcommand\subfile[1]{%
+\newcommand\subfile{%
+  \let\subfiles at loadfile\subimport
+  \subfiles at subfile
+}
+\newcommand\subfileinclude{%
+  \let\subfiles at loadfile\subincludefrom
+  \subfiles at subfile
+}
+\newcommand\subfiles at subfile[1]{%
   \begingroup
   \renewcommand\documentclass[2][subfiles]{\ignorespaces}%
   \renewenvironment{document}{%
@@ -66,9 +74,29 @@
     \@ignoretrue
   }%
   \subfiles at split{#1}%
-  \subimport{\subfiles at dir}{\subfiles at base}%
+  \subfiles at loadfile{\subfiles at dir}{\subfiles at base}%
   \endgroup
 }
+\def\subfiles at addimportpath#1{%
+  \def\subfiles at filelist{}%
+  \def\subfiles at sep{}%
+  \@for\subfiles at filename:=#1\do{%
+    \edef\subfiles at filelist{\subfiles at filelist\subfiles at sep\import at path\subfiles at filename}%
+    \def\subfiles at sep{,}%
+  }
+}
+\let\subfiles at bibliography\bibliography
+\renewcommand\bibliography[1]{%
+  \subfiles at addimportpath{#1}%
+  \expandafter\subfiles at bibliography\expandafter{\subfiles at filelist}%
+}
+\@ifpackageloaded{bibunits}{%
+  \let\subfiles at putbib\@putbib
+  \def\@putbib[#1]{%
+    \subfiles at addimportpath{#1}%
+    \expandafter\subfiles at putbib\expandafter[\subfiles at filelist]%
+  }%
+}{}
 \endinput
 %%
 %% End of file `subfiles.sty'.



More information about the tex-live-commits mailing list