更新:
正如我在下面的评论中提到的,无论进行何种拆分,目录都应该相同。因此,解决方案应该通过以下命令在 HTML 中生成相同的目录
htlatex foo.tex
htlatex foo.tex "htm,2"
以下是原始问题
在报告类中设置时\setcounter{tocdepth}{0}
,PDF 文件仅显示目录中预期的章节,但 HTML 在目录中显示章节和部分。
在文章类中设置时\setcounter{tocdepth}{1}
,PDF 文件仅显示目录中预期的部分,现在 HTML 也仅显示目录中预期的部分。
所以,问题是:为什么 tex4ht 同意文章的 pdf toc 而不是报告的 pdf toc?
下图说明了这一点。除了标准命令之外,我没有使用任何选项或配置文件来构建这些。使用的 MWE 和命令如下。
文章
\documentclass{article}%
\setcounter{tocdepth}{1}
\begin{document}
\tableofcontents
\clearpage
\section{This is section 1}
some text in section 1
\subsection{1}
some text in section, subsection
\section{This is section 2}
some text in section 2
\subsection{1}
some text in section, subsection
\section{This is section 3}
some text in section 3
\subsection{1}
some text in section, subsection
\end{document}
使用的命令
pdflatex foo.tex
htlatex foo.tex
报告
\documentclass{report}%
\setcounter{tocdepth}{0}
\begin{document}
\tableofcontents
\clearpage
\chapter{This is chapter 1}
some text in chapter 1
\section{1}
some text in chapter, section
\chapter{This is chapter 2}
some text in chapter 2
\section{1}
some text in chapter, section
\chapter{This is chapter 3}
some text in chapter 3
\section{1}
some text in chapter, section
\end{document}
附录
我知道一种解决报告案例的方法。但问题实际上不是找到解决方法,而是为什么会发生这种情况。以下是感兴趣的人可以使用的解决方法。
\documentclass{report}%
\setcounter{tocdepth}{0}
\begin{document}
\ifdefined\HCode
\Configure{tableofcontents*}{chapter} %force htlatex to only show chapters
\else
\tableofcontents
\fi
\clearpage
\chapter{This is chapter 1}
some text in chapter 1
\section{1}
some text in chapter, section
\chapter{This is chapter 2}
some text in chapter 2
\section{1}
some text in chapter, section
\chapter{This is chapter 3}
some text in chapter 3
\section{1}
some text in chapter, section
\end{document}
HTML 结果现在符合预期
这是报告案例的 htlatex 输出的完整输出。它不是太大,但由于下面的评论说这不能在其他机器上生成,所以发布它。我使用的是 texlive 2014,从日志中可以看出:
>htlatex foo.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(./foo.tex (/usr/local/texlive/2014/texmf-dist/tex/latex/base/report.cls
Document Class: report 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.sty)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.4ht
::::::::::::::::::::::::::::::::::::::::::
TeX4ht info is available in the log file
::::::::::::::::::::::::::::::::::::::::::
) (/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.sty
--- needs --- tex4ht foo ---
(./foo.tmp) (./foo.xref)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/latex.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/fontmath.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/report.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(./foo.aux) [1] (./foo.4ct) [2] [3]
Chapter 1.
[4]
Chapter 2.
[5]
Chapter 3.
[6] (./foo.aux) )
Output written on foo.dvi (6 pages, 12504 bytes).
Transcript written on foo.log.
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(./foo.tex (/usr/local/texlive/2014/texmf-dist/tex/latex/base/report.cls
Document Class: report 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.sty)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.4ht
::::::::::::::::::::::::::::::::::::::::::
TeX4ht info is available in the log file
::::::::::::::::::::::::::::::::::::::::::
) (/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.sty
--- needs --- tex4ht foo ---
(./foo.tmp) (./foo.xref)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/latex.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/fontmath.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/report.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(./foo.aux) [1] (./foo.4ct) [2] [3]
Chapter 1.
[4]
Chapter 2.
[5]
Chapter 3.
[6] (./foo.aux) )
Output written on foo.dvi (6 pages, 12504 bytes).
Transcript written on foo.log.
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(./foo.tex (/usr/local/texlive/2014/texmf-dist/tex/latex/base/report.cls
Document Class: report 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.sty)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.4ht
::::::::::::::::::::::::::::::::::::::::::
TeX4ht info is available in the log file
::::::::::::::::::::::::::::::::::::::::::
) (/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.sty
--- needs --- tex4ht foo ---
(./foo.tmp) (./foo.xref)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/latex.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/fontmath.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/report.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(./foo.aux) [1] (./foo.4ct) [2] [3]
Chapter 1.
[4]
Chapter 2.
[5]
Chapter 3.
[6] (./foo.aux) )
Output written on foo.dvi (6 pages, 12504 bytes).
Transcript written on foo.log.
----------------------------
tex4ht.c (2012-07-25-19:36 kpathsea)
tex4ht -f/foo.tex
-i~/tex4ht.dir/texmf/tex4ht/ht-fonts/
(/usr/local/texlive/2014/texmf-dist/tex4ht/base/unix/tex4ht.env)
(/usr/local/texlive/2014/texmf-dist/tex4ht/ht-fonts/iso8859/1/charset/unicode.4hf)
(/usr/local/texlive/2014/texmf-dist/fonts/tfm/public/cm/cmr10.tfm)
(/usr/local/texlive/2014/texmf-dist/tex4ht/ht-fonts/alias/lm/lm-rep-cmrm/cmr.htf)
Searching `lm-rep-cmrm.htf' for `cmr10.htf'
(/usr/local/texlive/2014/texmf-dist/tex4ht/ht-fonts/unicode/lm/lm-rep-cmrm.htf)
[1 file foo.html
file foo.css
file foo.tmp
] [2] [3] [4] [5] [6]
Execute script `foo.lg'
----------------------------
t4ht.c (2012-07-25-19:28 kpathsea)
t4ht -f/foo.tex
(/usr/local/texlive/2014/texmf-dist/tex4ht/base/unix/tex4ht.env)
Entering foo.lg
Entering foo.css
Entering foo.tmp
>
这也是实际生成的 HTML。(也不是太大)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html >
<head><title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)">
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)">
<!-- html -->
<meta name="src" content="foo.tex">
<meta name="date" content="2014-08-09 11:55:00">
<link rel="stylesheet" type="text/css" href="foo.css">
</head><body
>
<h2 class="likechapterHead"><a
id="x1-1000"></a>Contents</h2> <div class="tableofcontents">
<span class="chapterToc" >1 <a
href="#x1-20001" id="QQ2-1-2">This is chapter 1</a></span>
<br />  <span class="sectionToc" >1.1 <a
href="#x1-30001.1" id="QQ2-1-3">1</a></span>
<br /> <span class="chapterToc" >2 <a
href="#x1-40002" id="QQ2-1-4">This is chapter 2</a></span>
<br />  <span class="sectionToc" >2.1 <a
href="#x1-50002.1" id="QQ2-1-5">1</a></span>
<br /> <span class="chapterToc" >3 <a
href="#x1-60003" id="QQ2-1-6">This is chapter 3</a></span>
<br />  <span class="sectionToc" >3.1 <a
href="#x1-70003.1" id="QQ2-1-7">1</a></span>
</div>
<h2 class="chapterHead"><span class="titlemark">Chapter 1</span><br /><a
id="x1-20001"></a>This is chapter 1</h2>
<!--l. 10--><p class="noindent" >some text in chapter 1
<h3 class="sectionHead"><span class="titlemark">1.1 </span> <a
id="x1-30001.1"></a>1</h3>
<!--l. 12--><p class="noindent" >some text in chapter, section
<h2 class="chapterHead"><span class="titlemark">Chapter 2</span><br /><a
id="x1-40002"></a>This is chapter 2</h2>
<!--l. 15--><p class="noindent" >some text in chapter 2
<h3 class="sectionHead"><span class="titlemark">2.1 </span> <a
id="x1-50002.1"></a>1</h3>
<!--l. 17--><p class="noindent" >some text in chapter, section
<h2 class="chapterHead"><span class="titlemark">Chapter 3</span><br /><a
id="x1-60003"></a>This is chapter 3</h2>
<!--l. 21--><p class="noindent" >some text in chapter 3
<h3 class="sectionHead"><span class="titlemark">3.1 </span> <a
id="x1-70003.1"></a>1</h3>
<!--l. 23--><p class="noindent" >some text in chapter, section
</body></html>
答案1
每个文档类的\:TOC
支持文件中都有一个宏:.4ht
\edef\:TOC{
\noexpand\ifx [\noexpand\:temp
\noexpand\expandafter\noexpand\:TableOfContents
\noexpand\else
\noexpand\Auto:ent{\ifnum \c@tocdepth >-2 part,\fi
\expandafter\ifx \csname @chapter\endcsname\relax
\ifnum \c@tocdepth >\z@ section,\fi
\else
\ifnum \c@tocdepth >\m@ne chapter,appendix,\fi
\ifnum \z@>\c@tocdepth\else section,\fi
\ifnum 1>\c@tocdepth \else subsection,\fi
\fi
\ifnum 2>\c@tocdepth \else subsection,\fi
\ifnum 3>\c@tocdepth \else subsubsection,\fi
\ifnum 4>\c@tocdepth \else paragraph,\fi
\ifnum 5>\c@tocdepth \else subparagraph,\fi
UnDFexyz}%
列出将toc
由此宏创建的将形成的值部分命令。
参见以下几行:
\expandafter\ifx \csname @chapter\endcsname\relax
\ifnum \c@tocdepth >\z@ section,\fi
\else
\ifnum \c@tocdepth >\m@ne chapter,appendix,\fi
\ifnum \z@>\c@tocdepth\else section,\fi
解释一下,对于没有\chapter
命令的文档类,使用此声明:
\ifnum \c@tocdepth >\z@ section,\fi
否则,这样:
\ifnum \c@tocdepth >\m@ne chapter,appendix,\fi
\ifnum \z@>\c@tocdepth\else section,\fi
第一个声明在类中使用article
,第二个在chapter
或中使用book
。我不知道为什么节的声明有如此复杂的形式:
\ifnum \z@>\c@tocdepth\else section,\fi
如果我没记错的话,这意味着如果大于或等于零,则section
包含在列表中,这是不正确的。您可以复制一份本地副本,并将更正后的版本放在此处:\c@tocdepth
report.4ht
\:TOC
\edef\:TOC{%
\noexpand\ifx [\noexpand\:temp
\noexpand\expandafter\noexpand\:TableOfContents
\noexpand\else
\noexpand\Auto:ent{\ifnum \c@tocdepth >-2 part,\fi
\expandafter\ifx \csname @chapter\endcsname\relax
\ifnum \c@tocdepth >\z@ section,\fi
\else
\ifnum \c@tocdepth >\m@ne chapter,appendix,\fi
\ifnum \c@tocdepth>0 section,\fi
\ifnum \c@tocdepth>1 subsection,\fi
\fi
\ifnum \c@tocdepth>2 subsection,\fi
\ifnum \c@tocdepth>3 subsubsection,\fi
\ifnum \c@tocdepth>4 paragraph,\fi
\ifnum \c@tocdepth>5 subparagraph,\fi
UnDFexyz}%
\noexpand\fi}
如果你在错误跟踪器上为此提交错误报告tex4ht
,我们可能会为文学源制作补丁并将更正后的版本放到 texlive