1

I wrote two simple files integrated using the standalone package:

main.tex:

\documentclass{article}
\usepackage[subpreambles]{standalone}

\begin{document}

\input{myfile}

\end{document}

myfile.tex:

\documentclass[class=article, crop=false]{standalone}
\usepackage{lipsum}
\usepackage{acronym}

\begin{document}

\acrodef{FB}{Foo Bar}
First call: \ac{FB} \par Later calls: \ac{FB}

\lipsum[1]

\end{document}

While the subfile compiles as intended, the main file compiles with error: myfilemain file

Seems like while the \lipsum and the \ac commands are both known to the main file, the \acrodef command is not so as suggested by the errors I get. Even if I move the \acrodef command to the preamble of the subfile, nothing changes.

The only way I could solve this so far was to add the acronym package also in the preamble of the main file while based on the documentation of the standalone package, this is what the subpreambles tag is expected to do and has already done with the lipsum package in this example.

So what am I missing or misunderstanding about the standalone package and how it handles the subpreambles?

Update

With using the command \newacro instead of \acrodef, the issue with the command \ac gets solved. So the first call and the other calls to \ac successfully resolves to correct outputs. But still there is an additional line showing up in the output when compiling main.tex (the first line): using newacro

1 Answer 1

1

The problem is that the .aux file where acronym puts the seemingly undefined stuff, is input before before the .sta file where standalone puts the subpreambles. The input of the .sta file happens when the begindocument hook is executed, which happens after the .aux file is being read.

However, there is a hook begindocument/before which happens before the .aux file is read.

In your example we can add the crucial code from standalone to this hook rather safely as your subfile only loads packages. Packages never get loaded twice so this is not a problem but custom definitions in a subpreamble may very well be a peoblem… use the following with caution.

Also: you should report this to the package author.

\documentclass{article}
\usepackage[subpreambles]{standalone}

\makeatletter
\AddToHook{begindocument/before}{%
  \let\subpreamble\@gobble
  \let\endsubpreamble\relax
  \let\standalonepreambles\relax
  \let\endstandalonepreambles\relax
  \ifsa@sortsubpreambles
    \let\sa@orig@usepackage\usepackage
    \let\usepackage\sa@usepackagewithoutoptions
  \fi
  \InputIfFileExists{\jobname.sta}{}{}%
}
\makeatother

\begin{document}

\input{myfile}

\end{document}

enter image description here

2
  • Thanks! And to which author should it be reported? standalone or acronym? From your answer I guess the standalone package should be responsible for this, right?
    – mhr
    Commented Jan 10, 2021 at 9:32
  • @mhr yes, this needs to be changed in the standalone package
    – cgnieder
    Commented Jan 10, 2021 at 9:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .