3

When i used \pageref in the document, i am getting wrong page number in the TeX4HT output (ie., Html file)

MWE

\documentclass{article}

\title{Sample TeX4HT}

\begin{document}
\maketitle

\section{A Head}\label{sec1}

Macro language has evolved gradually: as the need arose for actions beyond a predefined set of commands. As a consequence, it is a pretty non-standard language that implements loops and conditional statements with macro functions rather than keywords. 
\pageref{sec1}
\end{document}

like below, i am getting "x" instead of 1 in the output,

<span class="pageref"><a href="#x1-10001"><span class="cmsy-10">x</span></a></span>

I compiled the file with the argument

htlatex filename "xhtml"

Please suggest how to get the correct page no

1
  • The HTML output does not really have a concept of numbered separate pages, because the whole document is rendered in one long vertical 'page'. So wouldn't it be strange to, for example, refer to page 2 when there is no page 2?
    – Marijn
    Jul 23, 2019 at 14:04

1 Answer 1

3

There is no concept of page in HTML, so the section (\S) symbol is used by tex4ht by default. But internally, the pages are still used, so it is in fact possible to use them. They just don't have any presence in the HTML file, so it may be a bit confusing.

The pageref configuration takes three arguments, the first two insert tags before and after the reference, the third argument contains text that should be used in the reference. When the third argument is empty, the default text is used, which is the page of the referenced object in the DVI file:

\Preamble{xhtml}
\Configure{pageref}{\HCode{<span class="pageref">}}{\HCode{</span>}}{}
\begin{document}
\EndPreamble

The following example:

%https://tex.stackexchange.com/q/501041/2891
\documentclass{article}

\usepackage{lipsum}
\title{Sample TeX4HT}

\begin{document}
\maketitle

\section{A Head}\label{sec1}

\lipsum[1-12]
Macro language has evolved gradually: as the need arose for actions beyond a predefined set of commands. As a consequence, it is a pretty non-standard language that implements loops and conditional statements with macro functions rather than keywords. 
\section{another}\label{sec2}
\pageref{sec1}, \pageref{sec2}
\end{document}

Produces a following result:

enter image description here

Note that the page numbers don't correspond to the PDF version produced by the same document at all, as tex4ht inserts page breaks for it's own purposes!

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.