Menu

#6 Unable to use algorithm environment in standalone document

1.0
wont-fix
None
2022-07-16
2022-01-12
No

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?

Discussion

  • Martin Scharrer

    Martin Scharrer - 2022-01-12

    Hi, algorithm is basically a float like figure or table which cannot be catched inside a box (also not by a simple minipage etc.). I would recommend you to simply use a separate file with the article class instead and input that in the main file while loading the standalone package in it.

    I posted an extended answer on tex.se: https://tex.stackexchange.com/a/629935/2975

     
  • Guilherme Zagatti

    Many thanks for the detailed answer.

    The reason why I was using the class standalone was to be able to input it into the main document. So if I use the article class instead do I also get all the benefits of using the standalone package 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 the article class? Would it just be a matter of importing standalone as 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.

     
    • Martin Scharrer

      Martin Scharrer - 2022-07-16

      Hi,
      the \onlyifstandalone macro is provided by the package and the class. So just using an article class and loading the standalone package there would work. The manual states which macros are provided by the package and which by the class (and which by both).

       
  • Martin Scharrer

    Martin Scharrer - 2022-07-16
    • status: open --> wont-fix
    • assigned_to: Martin Scharrer
     

Log in to post a comment.