我怎样才能使 cleveref 中的 \cref{foo,bar} 与 htlatex 一起工作?

我怎样才能使 cleveref 中的 \cref{foo,bar} 与 htlatex 一起工作?

我有以下test2.tex文件:

\documentclass{article}
\usepackage{tex4ht}
\usepackage{etoolbox}
\usepackage{hyperref}
\AtEndPreamble{\usepackage{cleveref}}
\begin{document}
\section{foo}\label{foo}
\cref{bar,baz}
\section{bar}\label{bar}
\section{baz}\label{baz}
\end{document}

当我跑latex两次时,我得到

D:\Documents\GitHub\book>rm test2.aux && latex test2.tex && latex test2.tex
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (MiKTeX 2.9 64-bit)
entering extended mode
(D:\Documents\GitHub\book\test2.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, afrikaans, ancientgreek, ar
abic, armenian, assamese, basque, bengali, bokmal, bulgarian, catalan, coptic,
croatian, czech, danish, dutch, esperanto, estonian, farsi, finnish, french, ga
lician, german, german-x-2012-05-30, greek, gujarati, hindi, hungarian, iceland
ic, indonesian, interlingua, irish, italian, kannada, kurmanji, latin, latvian,
 lithuanian, malayalam, marathi, mongolian, mongolianlmc, monogreek, ngerman, n
german-x-2012-05-30, nynorsk, oriya, panjabi, pinyin, polish, portuguese, roman
ian, russian, sanskrit, serbian, slovak, slovenian, spanish, swedish, swissgerm
an, tamil, telugu, turkish, turkmen, ukenglish, ukrainian, uppersorbian, usengl
ishmax, welsh, loaded.
("D:\Program Files\MiKTeX 2.9\tex\latex\base\article.cls"
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
("D:\Program Files\MiKTeX 2.9\tex\latex\base\size10.clo"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\tex4ht.sty")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\usepackage.4ht")
("D:\Program Files\MiKTeX 2.9\tex\latex\etoolbox\etoolbox.sty"
("D:\Program Files\MiKTeX 2.9\tex\latex\misc\etex.sty"))
("D:\Program Files\MiKTeX 2.9\tex\latex\hyperref\hyperref.sty"
("D:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\hobsub-hyperref.sty"
("D:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\hobsub-generic.sty"))
("D:\Program Files\MiKTeX 2.9\tex\latex\graphics\keyval.sty")
(D:\Documents\GitHub\book\ifxetex.sty)
("D:\Program Files\MiKTeX 2.9\tex\latex\oberdiek\auxhook.sty"

Package auxhook Warning: Cannot patch \document,
(auxhook)                using \AtBeginDocument instead.

) ("D:\Program Files\MiKTeX 2.9\tex\latex\oberdiek\kvoptions.sty")
("D:\Program Files\MiKTeX 2.9\tex\latex\hyperref\pd1enc.def")
("D:\Program Files\MiKTeX 2.9\tex\latex\00miktex\hyperref.cfg")
("D:\Program Files\MiKTeX 2.9\tex\latex\ltxmisc\url.sty")

Package hyperref Message: Stopped early.

)

Package hyperref Message: Driver: htex4ht.

("D:\Program Files\MiKTeX 2.9\tex\latex\hyperref\htex4ht.def")
(D:\Documents\GitHub\book\cleveref.sty)
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\tex4ht.4ht"
::::::::::::::::::::::::::::::::::::::::::
 TeX4ht info is available in the log file
::::::::::::::::::::::::::::::::::::::::::
) ("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\tex4ht.sty"
("D:\Program Files\MiKTeX 2.9\tex\latex\graphics\color.sty"
("D:\Program Files\MiKTeX 2.9\tex\latex\00miktex\color.cfg")
("D:\Program Files\MiKTeX 2.9\tex\latex\graphics\dvips.def")
("D:\Program Files\MiKTeX 2.9\tex\latex\graphics\dvipsnam.def"))
--- needs --- tex4ht test2 ---
(D:\Documents\GitHub\book\test2.tmp) (D:\Documents\GitHub\book\test2.xref)
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\latex.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\fontmath.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\article.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\hyperref.4ht"
("D:\Program Files\MiKTeX 2.9\tex\latex\hyperref\nameref.sty"
("D:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\gettitlestring.sty"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\nameref.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\pd1enc.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\url.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\color.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\dvips.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\dvipsnam.4ht"
("D:\Program Files\MiKTeX 2.9\tex\latex\graphics\dvipsnam.def")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
No file test2.aux.

LaTeX Warning: Reference `baz' on page 1 undefined on input line 8.


LaTeX Warning: Reference `bar' on page 1 undefined on input line 8.

[1] (D:\Documents\GitHub\book\test2.aux)

LaTeX Warning: There were undefined references.


LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

 )
Output written on test2.dvi (1 page, 10112 bytes).
Transcript written on test2.log.
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (MiKTeX 2.9 64-bit)
entering extended mode
(D:\Documents\GitHub\book\test2.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, afrikaans, ancientgreek, ar
abic, armenian, assamese, basque, bengali, bokmal, bulgarian, catalan, coptic,
croatian, czech, danish, dutch, esperanto, estonian, farsi, finnish, french, ga
lician, german, german-x-2012-05-30, greek, gujarati, hindi, hungarian, iceland
ic, indonesian, interlingua, irish, italian, kannada, kurmanji, latin, latvian,
 lithuanian, malayalam, marathi, mongolian, mongolianlmc, monogreek, ngerman, n
german-x-2012-05-30, nynorsk, oriya, panjabi, pinyin, polish, portuguese, roman
ian, russian, sanskrit, serbian, slovak, slovenian, spanish, swedish, swissgerm
an, tamil, telugu, turkish, turkmen, ukenglish, ukrainian, uppersorbian, usengl
ishmax, welsh, loaded.
("D:\Program Files\MiKTeX 2.9\tex\latex\base\article.cls"
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
("D:\Program Files\MiKTeX 2.9\tex\latex\base\size10.clo"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\tex4ht.sty")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\usepackage.4ht")
("D:\Program Files\MiKTeX 2.9\tex\latex\etoolbox\etoolbox.sty"
("D:\Program Files\MiKTeX 2.9\tex\latex\misc\etex.sty"))
("D:\Program Files\MiKTeX 2.9\tex\latex\hyperref\hyperref.sty"
("D:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\hobsub-hyperref.sty"
("D:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\hobsub-generic.sty"))
("D:\Program Files\MiKTeX 2.9\tex\latex\graphics\keyval.sty")
(D:\Documents\GitHub\book\ifxetex.sty)
("D:\Program Files\MiKTeX 2.9\tex\latex\oberdiek\auxhook.sty"

Package auxhook Warning: Cannot patch \document,
(auxhook)                using \AtBeginDocument instead.

) ("D:\Program Files\MiKTeX 2.9\tex\latex\oberdiek\kvoptions.sty")
("D:\Program Files\MiKTeX 2.9\tex\latex\hyperref\pd1enc.def")
("D:\Program Files\MiKTeX 2.9\tex\latex\00miktex\hyperref.cfg")
("D:\Program Files\MiKTeX 2.9\tex\latex\ltxmisc\url.sty")

Package hyperref Message: Stopped early.

)

Package hyperref Message: Driver: htex4ht.

("D:\Program Files\MiKTeX 2.9\tex\latex\hyperref\htex4ht.def")
(D:\Documents\GitHub\book\cleveref.sty)
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\tex4ht.4ht"
::::::::::::::::::::::::::::::::::::::::::
 TeX4ht info is available in the log file
::::::::::::::::::::::::::::::::::::::::::
) ("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\tex4ht.sty"
("D:\Program Files\MiKTeX 2.9\tex\latex\graphics\color.sty"
("D:\Program Files\MiKTeX 2.9\tex\latex\00miktex\color.cfg")
("D:\Program Files\MiKTeX 2.9\tex\latex\graphics\dvips.def")
("D:\Program Files\MiKTeX 2.9\tex\latex\graphics\dvipsnam.def"))
--- needs --- tex4ht test2 ---
(D:\Documents\GitHub\book\test2.tmp) (D:\Documents\GitHub\book\test2.xref)
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\latex.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\fontmath.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\article.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\hyperref.4ht"
("D:\Program Files\MiKTeX 2.9\tex\latex\hyperref\nameref.sty"
("D:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\gettitlestring.sty"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\nameref.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\pd1enc.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\url.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\color.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\dvips.4ht"
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\dvipsnam.4ht"
("D:\Program Files\MiKTeX 2.9\tex\latex\graphics\dvipsnam.def")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4.4ht")
("D:\Program Files\MiKTeX 2.9\tex\generic\tex4ht\html4-math.4ht"))
(D:\Documents\GitHub\book\test2.aux)
! Missing number, treated as zero.
<to be read again>
                   <
l.8 \cref{bar,baz}

?

出了什么问题?我该如何修复?

答案1

我回答了较新的问题对于同样的问题,该答案中提供了解决方案的详细描述。

使用提供的配置文件,cleveref.4ht

\def\refstepcounter@noarg#1{%
  \cref@old@refstepcounter{#1}%
  \cref@constructprefix{#1}{\cref@result}%
  \@ifundefined{cref@#1@alias}%
    {\def\@tempa{#1}}%
    {\def\@tempa{\csname cref@#1@alias\endcsname}}%
  \protected@xdef\cref@currentlabel{%
    [\@tempa][\arabic{#1}][\cref@result]%
    \csname p@#1\endcsname\csname the#1\endcsname}
    }%
\def\refstepcounter@optarg[#1]#2{%
  \cref@old@refstepcounter{#2}%
  \cref@constructprefix{#2}{\cref@result}%
  \@ifundefined{cref@#1@alias}%
    {\def\@tempa{#1}}%
    {\def\@tempa{\csname cref@#1@alias\endcsname}}%
  \protected@edef\cref@currentlabel{%
    [\@tempa][\arabic{#2}][\cref@result]%
    \csname p@#2\endcsname\csname the#2\endcsname}}%

结果是:

在此处输入图片描述

相关内容