使用常规命令时,以下代码运行正常latex
。
\documentclass[a4paper,11pt]{book}
\usepackage{hyperref}
\renewcommand{\sectionautorefname}[1]{Section~}
\begin{document}
Test
\end{document}
但是,运行时htlatex
,hyperref 包会提前停止,并且sectionautorefname
命令未定义。
完整日志输出:
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) (format=latex 2015.3.16) 6 AUG 2015 12:02
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCo
de"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.
{\g@addto@macro\@documentclasshook{\RequirePackage[#1,html]{tex4ht}}\let\HCode\
documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname
tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{
\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode .a.b.c.\input test2.tex
(./test2.tex (/usr/share/texlive/texmf-dist/tex/latex/base/book.cls
Document Class: book 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/bk10.clo
File: bk10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@chapter=\count80
\c@section=\count81
\c@subsection=\count82
\c@subsubsection=\count83
\c@paragraph=\count84
\c@subparagraph=\count85
\c@figure=\count86
\c@table=\count87
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(/usr/share/texmf/tex/generic/tex4ht/tex4ht.sty
version 2008-10-27-17:23
Package: tex4ht
--------------------------------------
--- Note --- for _ at preamble, use the command line option `early_'
--------------------------------------
--------------------------------------
--- Note --- for ^ at preamble, use the command line option `early^'
--------------------------------------
\tmp:toks=\toks14
)
(/usr/share/texmf/tex/generic/tex4ht/usepackage.4ht
version 2009-05-21-09:32
)
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty
Package: hyperref 2012/11/06 v6.83m Hypertext links for LaTeX
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty
Package: hobsub-hyperref 2012/05/28 v1.13 Bundle oberdiek, subset hyperref (HO)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty
Package: hobsub-generic 2012/05/28 v1.13 Bundle oberdiek, subset generic (HO)
Package: hobsub 2012/05/28 v1.13 Construct package bundles (HO)
Package: infwarerr 2010/04/08 v1.3 Providing info/warning/error messages (HO)
Package: ltxcmds 2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
Package: ifluatex 2010/03/01 v1.3 Provides the ifluatex switch (HO)
Package ifluatex Info: LuaTeX not detected.
Package: ifvtex 2010/03/01 v1.5 Detect VTeX and its facilities (HO)
Package ifvtex Info: VTeX not detected.
Package: intcalc 2007/09/27 v1.1 Expandable calculations with integers (HO)
Package: ifpdf 2011/01/30 v2.3 Provides the ifpdf switch (HO)
Package ifpdf Info: pdfTeX in PDF mode is not detected.
Package: etexcmds 2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO)
Package etexcmds Info: Could not find \expanded.
(etexcmds) That can mean that you are not using pdfTeX 1.50 or
(etexcmds) that some package has redefined \expanded.
(etexcmds) In the latter case, load this package earlier.
Package: kvsetkeys 2012/04/25 v1.16 Key value parser (HO)
Package: kvdefinekeys 2011/04/07 v1.3 Define keys (HO)
Package: pdftexcmds 2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO
)
Package pdftexcmds Info: LuaTeX not detected.
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
Package pdftexcmds Info: \pdfdraftmode is ignored in DVI mode.
Package: pdfescape 2011/11/25 v1.13 Implements pdfTeX's escape features (HO)
Package: bigintcalc 2012/04/08 v1.3 Expandable calculations on big integers (HO
)
Package: bitset 2011/01/30 v1.1 Handle bit-vector datatype (HO)
Package: uniquecounter 2011/01/30 v1.2 Provide unlimited unique counter (HO)
)
Package hobsub Info: Skipping package `hobsub' (already loaded).
Package: letltxmacro 2010/09/02 v1.4 Let assignment for LaTeX macros (HO)
Package: hopatch 2012/05/28 v1.2 Wrapper for package hooks (HO)
Package: xcolor-patch 2011/01/30 xcolor patch
Package: atveryend 2011/06/30 v1.8 Hooks at the very end of document (HO)
Package atveryend Info: \enddocument detected (standard20110627).
Package: atbegshi 2011/10/05 v1.16 At begin shipout hook (HO)
Package: refcount 2011/10/16 v3.4 Data extraction from label references (HO)
Package: hycolor 2011/01/30 v1.7 Color options for hyperref/bookmark (HO)
)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 1999/03/16 v1.13 key=value parser (DPC)
\KV@toks@=\toks15
)
(/usr/share/texlive/texmf-dist/tex/generic/ifxetex/ifxetex.sty
Package: ifxetex 2010/09/12 v0.6 Provides ifxetex conditional
)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/auxhook.sty
Package: auxhook 2011/03/04 v1.3 Hooks for auxiliary files (HO)
Package auxhook Warning: Cannot patch \document,
(auxhook) using \AtBeginDocument instead.
) (/usr/share/texlive/texmf-dist/tex/latex/oberdiek/kvoptions.sty
Package: kvoptions 2011/06/30 v3.11 Key value format for package options (HO)
)
\@linkdim=\dimen103
\Hy@linkcounter=\count88
\Hy@pagecounter=\count89
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def
File: pd1enc.def 2012/11/06 v6.83m Hyperref: PDFDocEncoding definition (HO)
)
\Hy@SavedSpaceFactor=\count90
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/hyperref.cfg
File: hyperref.cfg 2002/06/06 v1.2 hyperref configuration of TeXLive
)
Package hyperref Info: Option `colorlinks' set `true' on input line 4319.
Package hyperref Info: Hyper figures OFF on input line 4443.
Package hyperref Info: Link nesting OFF on input line 4448.
Package hyperref Info: Hyper index ON on input line 4451.
Package hyperref Info: Plain pages OFF on input line 4458.
Package hyperref Info: Backreferencing OFF on input line 4463.
Package hyperref Info: Implicit mode ON; LaTeX internals redefined.
Package hyperref Info: Bookmarks ON on input line 4688.
\c@Hy@tempcnt=\count91
(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty
\Urlmuskip=\muskip10
Package: url 2013/09/16 ver 3.4 Verb mode for urls, etc.
)
LaTeX Info: Redefining \url on input line 5041.
\XeTeXLinkMargin=\dimen104
\Fld@menulength=\count92
\Field@Width=\dimen105
\Fld@charsize=\dimen106
\Field@toks=\toks16
Package hyperref Info: Hyper figures OFF on input line 6295.
Package hyperref Info: Link nesting OFF on input line 6300.
Package hyperref Info: Hyper index ON on input line 6303.
Package hyperref Info: backreferencing OFF on input line 6310.
Package hyperref Info: Link coloring ON on input line 6313.
Package hyperref Info: Link coloring with OCG OFF on input line 6320.
Package hyperref Info: PDF/A mode OFF on input line 6325.
LaTeX Info: Redefining \ref on input line 6365.
LaTeX Info: Redefining \pageref on input line 6369.
\Hy@abspage=\count93
Package hyperref Message: Stopped early.
)
Package hyperref Message: Driver: htex4ht.
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/htex4ht.def
File: htex4ht.def 2012/11/06 v6.83m Hyperref driver for TeX4ht
Package hyperref Info: tex4ht is already loaded.
)
! LaTeX Error: \sectionautorefname undefined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.3 \renewcommand{\sectionautorefname}
[1]{Section~}
?
! Interruption.
\GenericError ...
\endgroup
l.3 \renewcommand{\sectionautorefname}
[1]{Section~}
? X
Here is how much of TeX's memory you used:
3787 strings out of 495029
56141 string characters out of 6181523
128583 words of memory out of 5000000
7043 multiletter control sequences out of 15000+600000
3640 words of font info for 14 fonts, out of 8000000 for 9000
14 hyphenation exceptions out of 8191
33i,0n,27p,661b,36s stack positions out of 5000i,500n,10000p,200000b,80000s
No pages of output.
这是在 Ubuntu 14.04 上,我运行后tlmgr update --all
显示没有可用的更新。
答案1
答案2
我使用\ifcsdef
which 测试命令是否已定义(不带\
)。 如果已定义,则使用\renewcommand
else\newcommand
或\providecommand
。
\documentclass[a4paper,11pt]{book}
\usepackage{etoolbox}
\usepackage{hyperref}
\ifcsdef{sectionautorefname}{%
\renewcommand{\sectionautorefname}[1]{Section~}
}{%
\providecommand{\sectionautorefname}[1]{Section~}
}
\begin{document}
\chapter{First chapter}
\section{First} \label{First}
Test
\clearpage
\section{Second} \label{Second}
In \autoref{First} we saw...
\end{document}