gsalzer / subfiles

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

Main file class options not available to packages when compiling a subfile #5

Closed crnkjck closed 4 years ago

crnkjck commented 4 years ago

When compiling a subfile, the packages used in the main file's preamble cannot see the options passed to the main file's \documentclass. They see the only option (the main file's path) of the subfiles class instead. Some packages (e.g., geometry, typearea, translator, babel) process these global options and will thus behave differently when a subfile and the main file are compiled, respectively.

main.tex:

\documentclass[slovak]{report}
\usepackage{babel}
\usepackage{subfiles}
\begin{document}
\subfile{sub}
\end{document}

sub.tex:

\documentclass[main]{subfiles}
\begin{document}
\chapter{Test}
\end{document}

Expected behaviour: When compiled with pdflatex main and pdflatex sub, both PDFs contain “Kapitola 1” (Slovak for “Chapter 1”).

Actual behaviour: sub.pdf contains “Chapter 1” and “LaTeX Warning: Unused global option(s): [slovak].” is issued during compilation. However, main.tex is compiled without warnings and main.pdf contains “Kapitola 1”.

Options given to the first class loaded are stored in the \@classoptionslist macro. The first class is detected by the test \ifx\@classoptionslist\relax in LaTeX source file N, line 385 (in version v1.3i). So one possible fix would be to add

\let\@classoptionslist\relax

just before

\let\documentclass\LoadClass

in line 8 of subfiles.cls.

gsalzer commented 4 years ago

Thanks for reporting the bug and proposing the fix!

gsalzer commented 4 years ago

The bug is fixed in release 1.6 that I have uploaded to CTAN a minute ago. Thanks for analysing the problem!

crnkjck commented 4 years ago

Thank you for the prompt fix.