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}
\file_input:n
or\@@input
.