2

I have an existing document that was written using hyperref and natbib, and am trying to generate a website alongside the PDF that is already built. The document was written using autoref references and natbib author-year citations.

I am using hevea to generate the HTML version, and am having problems with cross-references.

If I use hyperref, hevea encounters these errors, and inline citations and references appear as ??:

./text.aux:14: Giving up command: \addtokens
./text.aux:4: Giving up command: \AtBeginDocument
./text.aux:4: Giving up command: \HyperFirstAtBeginDocument
./text.tex:15: Giving up command: \input
./text.tex:15: Giving up command: \@readaux
./text.tex:15: Warning: Failure while reading .aux, reading .haux

(note that if I use hevea -fix or bibhva to make an .haux, natbib fails in other ways, so I'd like to stick with the .aux file.)

If I use cleveref and not hyperref, the citaions work, but cross references still have ?? where words like "Figure", "Section," etc. ought to be generated.

In either case the PDF compiles fine.

I stripped down my document to something minimal, included below, with a Makefile, bibliography and other assets in this Gist.

\documentclass[english]{article}
\usepackage{hevea}
\usepackage{graphicx}
\usepackage[english]{babel}

%use one or the other of these
%\usepackage{hyperref}
%\newcommand{\Xref}[1]{\autoref{#1}}
\usepackage{cleveref}
\newcommand{\Xref}[1]{\Cref{#1}}

\usepackage[authoryear]{natbib}
\usepackage{trouble}

\begin{document}

\section{Introduction}\label{sec:intro}
This document has citations \cite{Ilg:2010vn}, using authoryear style
(\cite{Wertheimer:1912aa}, \cite{Wertheimer:2012aa};
\cite{Steinman:2000ap}). It should also have figure graphics and
internal references using cleveref or hyperref, such as the imminent reference
to \Xref{sec:graphics}.

\section{Section 2}\label{sec:graphics}

\begin{figure}
\includegraphics[height=2in,width=5in]{demo_carenv}
\caption{\label{fig:label} This is a figure, with a label.}
\end{figure}

\Xref{fig:label} has a picture in it, as was described in
\Xref{sec:intro} \cite{De-Valois:1991jt,Ramachandran:1990aa}.

\bibliographystyle{plain}
\bibliography{bib}

\end{document}
  • 1
    your sample is missing bibliography, so i cannot test natbib, but \hyperref's \autoref` is working with tex4ht if you want to try it instead of hevea – michal.h21 Jul 30 '14 at 8:53
  • There's a complete sample in this gist: gist.github.com/crowding/fc9fac3daa89f6c544b2 I'll see about trying tex4ht. – crowding Jul 30 '14 at 19:07
4

I've found some small problems with your document, it is compilable both with pdflatex and tex4ht after small fixes:

%use one or the other of these
\usepackage{hyperref}
\newcommand{\Xref}[1]{\autoref{#1}}
%\usepackage{cleveref}

\autoref seem to work better with tex4ht

\DeclareGraphicsExtensions{.png,.jpg,}

add this to the preamble, this enables direct inclusion of png and jpg images with tex4ht.

\bibliographystyle{plainnat}
\bibliography{bib}

you want author-year bibliography, but you used plain style, which is numeric. replace it with plainnat.

The result after compilation with

htlatex sample.tex

enter image description here

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.