gsalzer / subfiles

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

Subfiles 2.x broke \newfontfamily in subfile preamble #27

Closed Maia-Everett closed 3 years ago

Maia-Everett commented 3 years ago

I have a subfile that defines and then uses a font family using the fontspec package, like this:

\documentclass[module]{subfiles}

\newfontfamily{\backpackfont}[
    Path=../fonts/Spectral/,
    Extension=.ttf,
    UprightFont=* Regular,
    BoldFont=* Bold,
    ItalicFont=* Italic,
    BoldItalicFont=* Bold Italic,
    Mapping=tex-text
]{Spectral}

\begin{document}
\clearpage

\chapter{Lorem Ipsum}

{
\backpackfont\fontsize{14}{18}\selectfont\addfontfeature{LetterSpace=0.5}\itshape

Some text...

}
\end{ddalspacing}

\end{document}

This works correctly with subfiles 1.6, but version 2.2 breaks it:

! Undefined control sequence.
l.20 \backpackfont
                  \fontsize{14}{18}\selectfont\addfontfeature{LetterSpace=0....
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

If I move the \newfontfamily command to the root .tex file, the document compiles correctly.

Maia-Everett commented 3 years ago

Looks like \newcommand in subfile preamble is now broken too. Is this intended behavior?

gsalzer commented 3 years ago

It is documented, so it is a feature, not a bug ;-) Let me guess: The problems occur when typesetting the main document that includes this file via \subfile, but it works when typesetting the subfile directly, right?

gsalzer commented 3 years ago

The default behavior since 2.0 is that the preamble is only processed when typesetting the subfile but is ignored when loading the subfile from the main file (together with \documentclass, \begin{document}, \end{document} and everything following \end{document}). These are the options: