tex4ht:“footmisc”和“hyperref”中的“symbol”选项存在冲突

tex4ht:“footmisc”和“hyperref”中的“symbol”选项存在冲突

梅威瑟:

\documentclass{book}

\usepackage[symbol]{footmisc}
\usepackage{hyperref}

\begin{document}
Maintext\footnote{Footnote
  \phantomsection
  \label{gtag:xxx}
  }

Hyperref
\hyperref[gtag:xxx]{abcd}Something
\end{document}

使用tex4ebook或编译htlatex,我们得到

! Missing \endcsname inserted.
<to be read again> 
                   \protect 
l.13 \hyperref[gtag:xxx]{abcd}
                              Something
? 

没问题pdflatex。该symbol选项很重要:如果我们删除它,那么编译成功。

答案1

看来该symbol选项会导致.aux文件无效,宏的定义\fnsymbol写在这里而不是当前脚注编号。应使用以下配置文件进行修复footmisc.4ht

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% footmisc.4ht                          2009-05-21-09:32 %
% Copyright (C) 2004--2009       Eitan M. Gurari         %
%                                                        %
% This work may be distributed and/or modified under the %
% conditions of the LaTeX Project Public License, either %
% version 1.3c of this license or (at your option) any   %
% later version. The latest version of this license is   %
% in                                                     %
%   http://www.latex-project.org/lppl.txt                %
% and version 1.3c or later is part of all distributions %
% of LaTeX version 2005/12/01 or later.                  %
%                                                        %
% This work has the LPPL maintenance status "maintained".%
%                                                        %
% This Current Maintainer of this work                   %
% is Eitan M. Gurari.                                    %
%                                                        %
% If you modify this program your changing its signature %
% with a directive of the following form will be         %
% appreciated.                                           %
%            \message{signature}                         %
%                                                        %
%                             [email protected]  %
%                 http://www.cse.ohio-state.edu/~gurari  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\immediate\write-1{version 2009-05-21-09:32}

\long\def\@footnotetext#1{\leavevmode
   \vbox{%\IgnorePar
      \leftskip0pt {\ht:everypar{}\parindent0pt\leavevmode}%
      \long\def\:tempc##1{\protected@edef\@currentlabel{\the\csname c@footnote\endcsname}%
\anc:lbl f{footnote}%
\Configure{newlabel}{\cur:th\the\csname c@footnote\endcsname}{\protect\p@footmisc@footnote{\the\csname c@footnote\endcsname}}
\a:footnotetext
   \o:@makefntext:{\b:footnotetext \csname a:footnotebody\endcsname
                {##1}\csname b:footnotebody\endcsname}\c:footnotetext
}%
\HLet\@makefntext\:tempc
%
      \reset@font\footnotesize
      \color@begingroup
        \@makefntext{\ignorespaces#1}%
      \color@endgroup
      \ht:special{t4ht@[}}\ht:special{t4ht@]}}

% detect if the symbol or symbol* option were used
% we can detect that by testing of \thefootnote macro

\edef\footmisc:thefootnote{\expandafter\unexpanded\expandafter{\thefootnote}}
\edef\footmisc:symbol{\unexpanded{\fnsymbol{footnote}}}
\edef\footmisc:symbolstar{\unexpanded{\@fnsymbol\c@footnote}}

\ifx\footmisc:thefootnote\footmisc:symbol
  \newcommand\p@footmisc@footnote[1]{\@fnsymbol{#1}}
\else
  \ifx\footmisc:thefootnote\footmisc:symbolstar
    \newcommand\p@footmisc@footnote[1]{\@fnsymbol{#1}}
  \else
    \newcommand\p@footmisc@footnote[1]{\p@footnote{#1}}
  \fi
\fi

\Hinput{footmisc}
\endinput

它使用\@footnotetext来自的命令定义latex.4ht并改变了一些东西:

\long\def\:tempc##1{\protected@edef\@currentlabel{\the\csname c@footnote\endcsname}%
    \anc:lbl f{footnote}%
    \Configure{newlabel}{\cur:th\the\csname c@footnote\endcsname}{\protect\p@footmisc@footnote{\the\csname c@footnote\endcsname}}

上述代码要求将计数器的值\c@footnote保存在.aux文件中。\Configure{newlabel}有两个参数。

第一个包含指向脚注的超链接:{\cur:th\the\csname c@footnote\endcsname}产生类似这样的内容:<a id='x2-1001f1'></a>

\ref第二个参数包含应在命令中的文档中显示的文本: {\protect\p@footmisc@footnote{\the\csname c@footnote\endcsname}}

我们想要{\p@footmisc@footnote {1}}.aux文件中写入类似的内容,因此需要\p@footmisc@footnote使用命令来防止命令的扩展\protect,但脚注计数器需要进行扩展。

在最后一步中,\p@footmisc@footnote根据命令的当前值定义。如果使用了 Footmisc 包的或选项\thefootnote,则会重新定义。在这种情况下,它会打印脚注符号。否则,它会使用数字。symbolsymbol*

以下是更新的示例:

\documentclass{book}

\usepackage[symbol]{footmisc}
% \usepackage[]{footmisc}

\usepackage{hyperref}
\usepackage{lipsum}

\begin{document}

\chapter{Hello}\label{sec:first}

Maintext\footnote{Footnote
  \phantomsection
  \label{gtag:xxx}
  }

  Another paragraph\footnote{another footnote\label{gtag:second}}. First footnote reference \ref{gtag:xxx}

  \lipsum[1]

Hyperref 
\hyperref[gtag:xxx]{abcd} Something. Second footnote reference \ref{gtag:second}. Reference to the chapter \ref{sec:second}.

\chapter{World}\label{sec:second}
\end{document}

结果如下:

在此处输入图片描述

相关内容