3

Using texlive 2013. The following MWE compiles fine with pdflatex, but gives the error:

./foo.aux) [1]
Chapter 1.
! LaTeX Error: \theHchapter undefined.

when I run it using the command:

htlatex foo.tex

Here is the file

\documentclass[12pt]{report}
\usepackage[toc,page]{appendix}
\usepackage{hyperref}
\begin{document}
\chapter{first}
  some text

\begin{appendices}
\chapter{some chapter}
  some text again
\end{appendices}

\end{document}

I really do not have to use the appendix package if that is the problem, I just wanted a way to obtain an Appendix title, before each chapter I add as an appendix. Without this package, I do not get this Appendix title on its own.

>htlatex foo.tex
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 restricted \write18 enabled.
entering extended mode

Update

Putting the new file appendix.4ht (thanks to michal.h21 answer below) in $TEXMFHOME/tex/latex/tex4ht worked. Strange why /usr/local/texlive/2013/texmf-dist/tex/generic/tex4ht does not work since that is where all the other .4ht files are?

But there are still issues with toc.

The table of contents links is not formatted correctly. Clicking on the appendix link from toc opens a web page that also contains the last section from the main body inside it. And clicking on the last section of the body opens a page that contains the appendix in it. So it seems that appendix is treated as part of the last section that appears in the body, instead of being a separate section on its own web page.

Here is a MWE example:

\documentclass{article}
\usepackage[toc,page]{appendix}
\usepackage{hyperref}
\begin{document}
\author{me}
\title{title}
\date{\today}
\maketitle
\tableofcontents

\section{first}
  some text

\section{two}
  some text in section 2

\begin{appendices}
\section{somesection inside appendices}
  some text again
\end{appendices}

\end{document}

Now compiled with

htlatex foo.tex "htm,2"   %now split 2 option to see the problem

enter image description here

update: To answer @egreg on using mktexlsr, I did now use that. As root, but still htlatex does not see the file appendix.4ht when this file is in /usr/local/texlive/2013/texmf-dist/tex/generic/tex4ht with all the other .4ht files. It only works when this file is in local $TEXMFHOME/tex/latex/tex4ht which is really strange. Here is screen shot:

enter image description here

  • When you add a file to /usr/local/texlive/2013/texmf-dist/tex/generic/tex4ht you should also run mktexlsr (or texhash which is the same). But don't add files there. – egreg Oct 24 '13 at 15:00
  • @egreg but I did ! that is what so strange. Please see my comment below. I did texconfig rehash which according to tex.stackexchange.com/questions/120150/… it says: texconfig rehash calls mktexlsr but I will try again with mktexlsr and see if that makes it work.... will need a minute – Nasser Oct 24 '13 at 15:06
  • texconfig is kept just for backwards compatibility. Did you acquire superuser privileges before running it? – egreg Oct 24 '13 at 15:10
  • @egreg yes, ofcourse as root. Please see update with screen shots. – Nasser Oct 24 '13 at 15:20
4

It means that \theHchapter in undefined when tex4ht is running and appendix.sty tries to redefine it. Quick fix is to provide appendix.4ht file, where \theHchapter is defined:

\ifdefined\theHchapter\else\newcommand\theHchapter{\Alph{chapter}}\fi
\ifdefined\theHsection\else\newcommand\theHsection{\Alph{section}}\fi

\ifdefined is used to prevent defining of the commands if they are already defined. Also \theHsection is defined as it would probably also raise issues.

We can also provide some redefinitions for providing configurable hooks, so final version of appendix.4ht is:

\def\@blockelement#1{% for handling paragraphs in block level elements
    \ifvmode\IgnorePar\fi\EndP\HCode{#1}
}
\NewConfigure{appendixpage}{2}

\Configure{appendixpage}{\@blockelement{<h2 class="appendixpage">}}{\HCode{</h2>}\par}
\renewcommand{\@chap@pppage}{%
    \a:appendixpage
    \appendixpagename
    \b:appendixpage
    \if@dotoc@pp
    \addappheadtotoc
    \fi
}

\renewcommand{\@sec@pppage}{%
    \a:appendixpage
    \appendixpagename
    \b:appendixpage
  \if@dotoc@pp
    \addappheadtotoc
  \fi
  \nobreak
  \@afterheading
}

\ConfigureEnv{appendices}{\@blockelement{<div class="appendices">}}{\@blockelement{</div>}}{}{}
\ifdefined\theHchapter\else\newcommand\theHchapter{\Alph{chapter}}\fi
\ifdefined\theHsection\else\newcommand\theHsection{\Alph{section}}\fi

Generated code:

 <div class="appendices">
    <h2 class="appendixpage">Appendices</h2><!--l. 9-->
    <p class="indent"><a id="likesection.1" name="likesection.1"></a><a id="Q1-1-3" name="Q1-1-3"></a></p>
    <h2 class="chapterHead"><span class="titlemark">Chapter&nbsp;A</span><br />
    <a id="x1-3000A" name="x1-3000A"></a>some chapter</h2><!--l. 11-->
    <p class="noindent">some text again</p>
  </div>

Edit: Version which prints Appendices as \section* or \chapter*

\def\@blockelement#1{% for handling paragraphs in block level elements
    \ifvmode\IgnorePar\fi\EndP\HCode{#1}
}
\renewcommand{\@chap@pppage}{%
    \chapter*{\appendixpagename}
}

\renewcommand{\@sec@pppage}{%
    \section*{\appendixpagename}
    \nobreak
    \@afterheading
}

\ConfigureEnv{appendices}{\@blockelement{<div class="appendices">}}{\@blockelement{</div>}}{}{}
\ifdefined\theHchapter\else\newcommand\theHchapter{\Alph{chapter}}\fi
\ifdefined\theHsection\else\newcommand\theHsection{\Alph{section}}\fi
  • Thanks, but I still get the error. This is what I did: I downloaded the above file. then copied it to /usr/local/texlive/2013/texmf-dist/tex/generic/tex4ht here: -rwxr-xr-x 1 root root 805 Oct 23 18:46 appendix.4ht then did texconfig rehash just in case. Rerun htlatex and this is what I get (screen shot): !Mathematica graphics I did this 2 times, just in case. Also tried it on the MWE posted above, with same error. Do I need to do any other setup changes? or did I copy the file to the wrong folder? I am using TL 2013 on Linux xmint. – Nasser Oct 24 '13 at 0:03
  • maybe put it rather to your TEXMFHOME dir. it is usually ~/texmf. and here put it to tex/latex/tex4ht – michal.h21 Oct 24 '13 at 10:12
  • thanks Michal, this work in $TEXMFHOME. But there is still a small problem with toc formating for HTML with split document. Not a big issue, but was wondering if there is a way to make it treat the appendix as separate section, similar to all other sections for splitting so that clicking on appendix from TOC, opens the appendix page only and not the section before it? MWE updated above. – Nasser Oct 24 '13 at 14:54
  • @Nasser see edited version – michal.h21 Oct 24 '13 at 16:25
  • thanks. I hope this file appendix.4ht will now go to tex4h main build source tree so that new versions of tex4ht will have this support for appendix package in it. (for example for TL 2014, etc...) – Nasser Oct 24 '13 at 17:00

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.