以下 MWE 说明了这个问题:
\documentclass{scrreprt}
\usepackage[clean,pdf]{svg}
\usepackage{tocloft}
\begin{document}
\includesvg[width=\textwidth{}]{legacy-ip-only}
\end{document}
它不会编译,因为显示以下消息:
! LaTeX Error: Command \c@lofdepth already defined.
Or name \end... illegal, see p.192 of the manual.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.607 \newcounter{lofdepth}
\setcounter{lofdepth}{1}
?
如果在MWE 编译tocloft
之前包含它则不会出现任何错误。为什么?svg
答案1
内部svg
要求subfig
:
\@ifpackageloaded{subfig}{}{\RequirePackage{subfig}}%
并且subfig
已经定义了lofdepth
计数器。
当您tocloft
不使用该subfigure
选项进行加载时,包会创建lofdepth
计数器:
\if@cftsubfigopt\else
\newcounter{lofdepth}\setcounter{lofdepth}{1}
\newcounter{lotdepth}\setcounter{lotdepth}{1}
\fi
这显然会引发错误。
您可以通过改变加载包的顺序来防止这种情况,因为subfig
内部会检查计数器是否已定义,在这种情况下,它不会定义它:
\def\@newsubfloat[#1]#2{%
\@ifundefined{c@sub#2}{%
\newcounter{sub#2}[#2]
\newcounter{sub#2@save}%
\@namedef{sub#2name}{}%
\@namedef{p@sub#2}{\@nameuse{the#2}}%
\@namedef{thesub#2}{\alph{sub#2}}%
\@namedef{ext@sub#2}{\@nameuse{ext@#2}}%
\@namedef{l@sub#2}{%
\@dottedxxxline{#2}%
{\@nameuse{ext@sub#2}}{2}{\sf@indent}{\sf@numwidth}}%
\@ifundefined{c@\@nameuse{ext@#2}depth}{%
\expandafter\newcounter\expandafter{\@nameuse{ext@#2}depth}%
\expandafter\addtocounter\expandafter{\@nameuse{ext@#2}depth}\@ne}{}%
\@namedef{KV@caption@\@nameuse{ext@#2}depth@default\expandafter}%
\expandafter{\csname KV@caption@\@nameuse{ext@#2}depth\endcsname{2}}%
\@namedef{KV@caption@\@nameuse{ext@#2}depth}##1{%
\setcounter{\@nameuse{ext@#2}depth}{##1}}%
\edef\sf@counterlist{%
\@ifundefined{sf@counterlist}{}%
{\sf@counterlist,}sub#2}%
\captionsetup[sub#2]{#1}%
}{%
\PackageWarning{subfig}{%
The sub#2\space type is already defined.}%
}}
防止错误的另一种方法是使用subfigure
选项tocloft
:
\documentclass{scrreprt}
\usepackage[clean,pdf]{svg}
\usepackage[subfigure]{tocloft}
\begin{document}
\includesvg[width=\textwidth{}]{legacy-ip-only}
\end{document}