Hello, I find this package very useful for working with large LaTex documents. However, recently I have faced issues with using the algorithm environment in a standalone document.
When using algorithm environments I am able to compile the whole document without a problem.
However, when compiling documents with the standalone class on their own. I get an error, such as the one below:
Extra }, or forgotten \endgroup.
Too many }'s.
Undefined control sequence.
Missing number, treated as zero.
Extra \else.
Extra \fi.
LaTeX Error: \begin{document} ended by \end{algorithm}.
This issue has also been documented in Stack Exchange without a satisfactory answer since it suggests to drop standalone or not to use the algorithm environment.
As a workaround, I tried to use the option preview = false under the belief that the standalone document would compile without any extra packages, but this did not work.
Are there possible solutions to this problem? Or should it be treated as bug?
Hi,
algorithmis basically a float likefigureortablewhich cannot be catched inside a box (also not by a simpleminipageetc.). I would recommend you to simply use a separate file with thearticleclass instead and input that in the main file while loading thestandalonepackage in it.I posted an extended answer on tex.se: https://tex.stackexchange.com/a/629935/2975
Many thanks for the detailed answer.
The reason why I was using the class
standalonewas to be able to input it into the main document. So if I use thearticleclass instead do I also get all the benefits of using thestandalonepackage in the main file (eg. only a single preamble and imports, etc.)?Also, what would be the best way to use the macros provided by
standalone(eg.\onlyifstandalone{〈code〉}) in a document with thearticleclass? Would it just be a matter of importingstandaloneas a package with\usepackage?For instance, I am writing a very long report which is split into multiple chapters. Sometimes, I might want to compile only one of the chapters standalone. In these cases, I want the bibliography printed at the end of the chapter. However, when compiling the whole report I only want to print the bibliography at the end of the report.
Hi,
the
\onlyifstandalonemacro is provided by the package and the class. So just using anarticleclass and loading thestandalonepackage there would work. The manual states which macros are provided by the package and which by the class (and which by both).