在 TL 2013 中使用 htlatex 和 \usepackage{hyperref} 时显示额外的“]”

在 TL 2013 中使用 htlatex 和 \usepackage{hyperref} 时显示额外的“]”

我注意到 HTML 页面上显示了一个新字符,而当我使用 TL 2012 和 htlatex 时,这个字符并不存在。我将其范围缩小到包括\usepackage{hyperref}这个额外的“]”仅显示在 HTML 中,而不显示在 PDF 中

\documentclass[12pt]{article}%
\begin{document}
text
\section{example using Table[Plot...]}
text
\end{document}

给出预期的输出

在此处输入图片描述

现在添加\usepackage{hyperref} 得到:

\documentclass[12pt]{article}%
\usepackage{hyperref}
\begin{document}
text
\section{example using Table[Plot...]}
text
\end{document}

在此处输入图片描述

注意那里多余的“]”。

使用的命令和屏幕显示的部分内容:

>htlatex foo5.tex
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2011/06/27>

(/usr/local/texlive/2013/texmf-dist/tex/latex/oberdiek/auxhook.sty

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

) (/usr/local/texlive/2013/texmf-dist/tex/latex/oberdiek/kvoptions.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/hyperref/pd1enc.def)
(/usr/local/texlive/2013/texmf-dist/tex/latex/latexconfig/hyperref.cfg)
(/usr/local/texlive/2013/texmf-dist/tex/latex/url/url.sty)

Package hyperref Message: Stopped early.

)

Package hyperref Message: Driver: htex4ht.

[1 file foo5.html
 file foo5.css
 file foo5.tmp
]
Execute script `foo5.lg'
----------------------------
t4ht.c (2012-07-25-19:28 kpathsea)
t4ht -f/foo5.tex 
(/usr/local/texlive/2013/texmf-dist/tex4ht/base/unix/tex4ht.env)
Entering foo5.lg
Entering foo5.css
Entering foo5.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.cse.ohio-state.edu/~gurari/TeX4ht/)"> 
<meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)"> 
<!-- html --> 
<meta name="src" content="foo5.tex"> 
<meta name="date" content="2013-06-22 21:56:00"> 
<link rel="stylesheet" type="text/css" href="foo5.css"> 
</head><body 
>
<!--l. 4--><p class="noindent" >text
   <span 
class="cmbx-12x-x-144">]</span>
   <h3 class="sectionHead"><span class="titlemark">1   </span> <a 
 id="x1-10001"></a>example using Table[Plot...]</h3>
<!--l. 6--><p class="noindent" >text  
</body></html> 

在 Linux mint 15 上全新安装 TL2013

>which htlatex
/usr/local/texlive/2013/bin/i386-linux/htlatex

>latex -v
pdfTeX 3.1415926-2.5-1.40.14 (TeX Live 2013)
kpathsea version 6.1.1
Copyright 2013 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.5.16; using libpng 1.5.16
Compiled with zlib 1.2.7; using zlib 1.2.7
Compiled with xpdf version 3.03
>

>tex4ht
----------------------------
tex4ht.c (2012-07-25-19:36 kpathsea)

答案1

这是包nameref.4ht的支持文件中的一个错误:tex4htnameref

\def\no@sect#1#2#3#4#5#6[#7]#8{\gdef\NR:Title{\a:newlabel{#7}}%
    \gdef\NR:Type{#1}%
    \NR:no@sect{#1}{#2}{#3}{#4}{#5}{#6}[#7]{#8}}
\def\:tempc#1#2#3#4#5#6[#7]#8{%
   \gdef\NR:Title{\a:newlabel{#7}}%
   \gdef\NR:Type{#1}%
   \o:NR@sect:{#1}{#2}{#3}{#4}{#5}{#6}[#7]{#8}}
\HLet\NR@sect\:tempc

参数#7包含带有的标题字符串example using Table[Plot...],将其作为可选参数调用变为:

\...{<#1>}...{<#6>}[example using Table[Plot...]]{<#8>}

这意味着,第一的右括号]匹配并关闭可选参数。第二个括号]代替 成为下一个参数{<#8>}

修补:

诀窍是使用花括号:[{#7}]而不是[#7]。如果#7包含方括号,那么这是健壮的:

\documentclass[12pt]{article}%
\usepackage{hyperref}

\makeatletter
\catcode`\:=11 %
\AtBeginDocument{%
  \@ifpackageloaded{tex4ht}{%
    \def\no@sect#1#2#3#4#5#6[#7]#8{\gdef\NR:Title{\a:newlabel{#7}}%
        \gdef\NR:Type{#1}%
        \NR:no@sect{#1}{#2}{#3}{#4}{#5}{#6}[{#7}]{#8}%
    }
    \def\:tempc#1#2#3#4#5#6[#7]#8{%
       \gdef\NR:Title{\a:newlabel{#7}}%
       \gdef\NR:Type{#1}%
       \o:NR@sect:{#1}{#2}{#3}{#4}{#5}{#6}[{#7}]{#8}}
    \HLet\NR@sect\:tempc
  }{}%
}%
\@makeother\:
\makeatother

\begin{document}
text
\section{example using Table[Plot...]}
text
\end{document}

更新:

感谢错误报告 #185michael.h21 的(参见他的评论), CV Radhakrishnan 已更新nameref.ht4在源存储库中,日期为 2013-06-28。此更新修复了该问题。

相关内容