我注意到包选项之间存在一些非常奇怪的algorithms2e
交互。newfloat
minted
\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}
而如果我颠倒包的加载顺序,算法列表就会恢复正常运行
\usepackage[newfloat]{minted}
\usepackage{algorithm2e}
我必须先加载,algorithms2e
因为我放弃了序言以加快编译时间因为我加载了大量用于排版我的书的包,而且我无法转储,minted
因为它似乎与缓存选项不一致。
有没有什么办法可以避免这种令人厌烦的行为?
答案1
问题似乎是 algorithm2e 和 newfloat 包之间不兼容,因此在 algorithm2e 包之前加载 newfloat 包似乎就足够了:
\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}
答案2
一些补丁解决了这个问题:
algorithm
将s写入<jobname>.lol
而不是<jobname>.loa
。更新
\listofalgorithms
以加载<jobname>.lol
而不是<jobname>.loa
。
\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}