1

I noticed some really weird interaction between algorithms2e and the option newfloat of the minted package.

\documentclass{book}

\usepackage{algorithm2e} \usepackage[newfloat]{minted}

\begin{document}

\listofalgorithms % here the spacing is not correct

\chapter{A chapter} \begin{algorithm}\caption{An algorithm}\end{algorithm} \begin{algorithm}\caption{An algorithm}\end{algorithm}

\chapter{A chapter} \begin{algorithm}\caption{An algorithm}\end{algorithm} \begin{algorithm}\caption{An algorithm}\end{algorithm}

\end{document}

incorrect spacing

Whereas if I invert the order of the loading of the packages the list of algorithms return to behave normally

\usepackage[newfloat]{minted}
\usepackage{algorithm2e}

correct spacing

I must necessarily load first algorithms2e because I dump my preamble to speed up compilation time since I load a ton of packages for typesetting my book, and I can't dump minted because it seems it doesn't get along with the cache option.

Is there a way to avoid this annoying behaviour?

2 Answers2

2

The problem seems to be an incompatibility between algorithm2e and newfloat package, so it seems to be sufficient to load the newfloat package before the algorithm2e package:

\documentclass{book}

\usepackage{newfloat} \usepackage{algorithm2e} \usepackage[newfloat]{minted}

\begin{document}

\listofalgorithms

\chapter{A chapter} \begin{algorithm}\caption{An algorithm}\end{algorithm} \begin{algorithm}\caption{An algorithm}\end{algorithm}

\chapter{A chapter} \begin{algorithm}\caption{An algorithm}\end{algorithm} \begin{algorithm}\caption{An algorithm}\end{algorithm}

\end{document}

  • 1
    ...I've send an e-mail to both maintainers, the one from the newfloat package has already answered that she/he will fix it this week-end. –  Feb 27 '21 at 14:36
1

Some patchwork corrects the problem:

  • Writing algorithms to the <jobname>.lol rather than <jobname>.loa.

  • Update \listofalgorithms to load <jobname>.lol rather than <jobname>.loa.

enter image description here

\documentclass{book}

\usepackage{algorithm2e} \usepackage[newfloat]{minted}

\makeatletter % Write algorithm to <jobname>.lol rather than <jobname>.loa \renewcommand{\algocf@list}{lol}% % Let \listofalgorithms load <jobname>.lol rather than <jobname>.loa \patchcmd{\listofalgocfs}% <cmd> {loa}% <search> {lol}% <replace> {}{}% <success><failure> \makeatother

\begin{document}

\listofalgorithms

\chapter{A chapter}

\begin{algorithm}\caption{An algorithm}\end{algorithm} \begin{algorithm}\caption{An algorithm}\end{algorithm}

\chapter{A chapter} \begin{algorithm}\caption{An algorithm}\end{algorithm} \begin{algorithm}\caption{An algorithm}\end{algorithm}

\end{document}

Werner
  • 603,163
  • The solution resolve the spacing problems but it raises another one: now I can't distinguish between the list of pseudocode and the list of code, but there is only one list for both type of object. This a patch, not a solution – Emanuele Nardi Feb 27 '21 at 12:22