gsalzer / subfiles

class and package for multi-file projects in LaTeX
LaTeX Project Public License v1.3c
25 stars 1 forks source link

Indenting \begin{document} in subfiles breaks compilation #13

Closed jlelong closed 3 years ago

jlelong commented 3 years ago

Consider the following example

main.tex

\documentclass{article}
\usepackage{subfiles}
\begin{document}
  main
  \subfile{sub/a}
\end{document}

sub/a.tex

\documentclass[../main.tex]{subfiles}
 \begin{document}
sub sub sub
\end{document}

Note the space before \begin{document}. Running latex main yields the error

Runaway argument?
! File ended while scanning use of \subfiles@tmp.
<inserted text>
                \par
l.5 \subfile{sub/a}

Removing the leading space in front of \begin{document} fixes the issue.

This happens with subfiles v2.0.

gsalzer commented 3 years ago

This is to be expected. v2.0 uses still the same technique for skipping stuff as, say the verbatim or comment package. For this to work, it is necessary that \begin{document} starts at the beginning of the line. See also the tips in the trouble-shooting section of the documentation.

The next version, v2.1, uses another method for skipping the preamble, which ignores these spaces. This version is currently only available on Github, see subfiles.sty in the top directory.

jlelong commented 3 years ago

Thanks for your detailed answer and sorry for not reading the troubleshooting section carefully enough.

gsalzer commented 3 years ago

No need to be sorry. The old behavior of subfiles is surprising for a normal user, it is reasonable to fix it. And who reads the docs anyway? ;-)

gsalzer commented 3 years ago

And thanks for reporting! Better to report than to live with the bugs ...