1

MWE:

\documentclass{book}

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

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

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

Compile with tex4ebook or htlatex, we get

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

No problem for pdflatex. The symbol option is essential: if we delete it, then it succeeds to compile.

2

It seems that the symbol option results in invalid .aux file, the definition of the \fnsymbol macro is written here instead of the current footnote number. It should be fixed with the following configuration file 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}                         %
%                                                        %
%                             gurari@cse.ohio-state.edu  %
%                 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

It uses the \@footnotetext command definition from latex.4ht and changes few things:

\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}}

The above code requires that the value of the \c@footnote counter is saved in the .aux file. \Configure{newlabel} has two parameters.

The first contains hypelink to the footnote: {\cur:th\the\csname c@footnote\endcsname} produces something like: <a id='x2-1001f1'></a>.

The second argument contains the text that should be shown in the document in \ref command: {\protect\p@footmisc@footnote{\the\csname c@footnote\endcsname}}.

We want to write something like {\p@footmisc@footnote {1}} to the .aux file, so we need to prevent expansion of the \p@footmisc@footnote command using the \protect command, but the footnote counter needs to be expanded.

In the last step, the \p@footmisc@footnote is defined, depending on the current value of \thefootnote command. It is redefined if the symbol or symbol* options of the Footmisc package were used. In that case, it prints the footnote symbols. It uses the numbers otherwise.

Here is a updated example:

\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}

And this is the result:

enter image description here

| improve this answer | |
  • Seemingly you forgot to add a versioning info in the comment. – Yai0Phah Dec 23 '19 at 17:44
  • @Yai0Phah yes, the correct version info will be generated from the literate sources once I update them. – michal.h21 Dec 23 '19 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.