2

As shown by the following MCE, the standalone package loaded with its subpreambles option gives the expected result with \input, but not with \file_input:n when the input file has a non empty preamble. In such a case, the content’s of subfile2.tex isn't inserted and following warning is emitted:

Package standalone Warning: Sub-preamble of file 'test.tex' has changed. Content will be ignored. Please rerun LaTeX! on input line 7.

But the sub-preamble obviously didn't change. Do you understand what happens?

Edit

New MCE in order to clarify my question.

\begin{filecontents}[overwrite]{subfile1.tex}
\documentclass{article}
\begin{document}
Content's~of~\texttt{subfile1.tex}.\par
\end{document}
\end{filecontents}

\begin{filecontents}[overwrite]{subfile2.tex}
\documentclass{article}
\newcommand{\foo}{}
\begin{document}
Content's~of~\texttt{subfile2.tex}.\par
\end{document}
\end{filecontents}

\begin{filecontents*}[overwrite]{myclass.cls}
\ProvidesExplClass
  {myclass}
  {2023-01-03}
  {0.1}
  {
    My Nice Class
  }
\NeedsTeXFormat{LaTeX2e}
\LoadClass { article }
%
\RequirePackage[subpreambles]{standalone}
%
\NewDocumentCommand{\myinput}{ m }
{
  \input{#1}
}
\NewDocumentCommand{\myfileinput}{ m }
{
  \file_input:n{#1}
}
\end{filecontents*}

\documentclass{myclass}
\begin{document}
\myinput{subfile1}
\myinput{subfile2}
\myfileinput{subfile1}
\myfileinput{subfile2}
\end{document}

Original MCE:

\begin{filecontents}[overwrite]{subfile1.tex}
\documentclass{article}
\begin{document}
Content's~of~\texttt{subfile1.tex}.\par
\end{document}
\end{filecontents}

\begin{filecontents}[overwrite]{subfile2.tex}
\documentclass{article}
\newcommand{\foo}{}
\begin{document}
Content's~of~\texttt{subfile2.tex}.\par
\end{document}
\end{filecontents}

\documentclass{article}
\usepackage[subpreambles]{standalone}
\begin{document}
\input{subfile1}
\input{subfile2}
\ExplSyntaxOn
\file_input:n{subfile1}
\file_input:n{subfile2}
\ExplSyntaxOff
\end{document}
14
  • 1
    you are reading the files with expl3 catcodes, so spaces are different and the comparision fails. Commented Jan 2, 2023 at 17:31
  • 1
    I doubt it. This subpreambles stuff looks quite fragile, e.g. hyperref errors as it is loaded to late, and babel/french can affect catcodes too. Commented Jan 2, 2023 at 19:58
  • 1
    You should refrain from using \ExplSyntaxOn/Off as part of your document. It is intended to enable defining stuff not "running arbitrary content". Expecting that anything work if you enable \ExplSyntaxOn and then pass it arbitrary stuff is nearly ever going to work. Commented Jan 3, 2023 at 10:11
  • 1
    sorry I was wrong: the problem are not (only) catcodes but also the input command: standalone relies (through the currfile package) on the latex file hooks to get the names of the files. So the expl3 command can't work, you need \input. Commented Jan 4, 2023 at 22:55
  • 1
    no. there is imho nothing sensible he can or should do. If you want to make use of the extended options from the file hooks (and your example is doing that) then use a command which offers file hooks, and that means \input or \include and not \file_input:n or \@@input. Commented Jan 5, 2023 at 10:03

0

You must log in to answer this question.

Browse other questions tagged .