6

I am trying to compile a standalone file containing pseudocode created with the algorithmicx package. According to algorithmicx crashes standalone it should work with the preview option set for standalone, however it does not. Also the mentioned vbox hack does not work. What am I doing wrong?

The first compiler error:

! Extra }, or forgotten \endgroup.
\@endfloatbox ...pagefalse \outer@nobreak \egroup 
                                                  \color@endbox
l.13 \end{algorithm}

The (generic) pseudocode file:

\documentclass[preview]{standalone}
\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}
\vbox{
\begin{algorithm}
  \caption{Euclid’s algorithm}\label{euclid}
  \begin{algorithmic}[1]
    \State $r\gets a\bmod b$
  \end{algorithmic}
\end{algorithm}
}
\end{document}

Thank you for your help.

Sven


UPDATE:

Using the algorithm2e package (as suggested by David Carlisle) and not using the vbox lets the pseudocode file compile without errors.

When I use \KwIn{foo} it breaks again. This in turn is fixed by using \usepackage[varwidth]{standalone}. The pseudocode file compiles without errors.

However now when I try to include the pseudocode file in my main file, I get the following compilation error in the algorithm2e.sty when compiling the main file:

! Undefined control sequence.
<argument> \SetAlgoLined 

l.1177 ...etcount,titlenotnumbered,lined,shortend}
                                                  %

The new pseudocode file (without ~\\ there is no line break after \KwIn{foo}):

\documentclass[varwidth]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{algorithm2e}

\begin{document}
\begin{algorithm}
  ~\\
  \KwIn{foo}
  $r\gets a\bmod b$\;  
\end{algorithm}
\end{document}

The main file where pseudocode is included:

\documentclass[a4paper,10pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[subpreambles]{standalone}

\begin{document}
\include{pseudocode}
\end{document}
3

I've lost track a bit of the various packages but your example runs without error (with or without the \vbox) if you change

\usepackage{algorithm}

to

\usepackage{algorithm2e}
  • That does work with the example I provided. However as soon as I use \KwIn{foo} it breaks again. – svenhuebner May 9 '13 at 11:21
1

It is the algorithm environment that breaks the whole thing. With only the algorithmic environment it does work. So a workaround (albeit without the perks of algorithm) would be the following.

The file with the algorithm pseudocode.tex:

\documentclass[preview]{standalone}
\usepackage{algpseudocode}

\begin{document}
  some introduction
  \begin{algorithmic}[1]
    \State $r\gets a\bmod b$
  \end{algorithmic}
\end{document}

The main file:

\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[subpreambles]{standalone}

\begin{document}

\begin{figure}
  \input{pseudocode}
  \caption{Euclid's algorithm}
\end{figure}
\end{document}

The same should work with algorithm2e, I did not try that though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.