TeX - LaTeX Asked on June 9, 2021
My code:
documentclass{article}
usepackage{hyperref}
begin{document}
Top of document
section{Section heading}
Top of section
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
phantomsection
label{fooref}
We want to create a reference to this part of the document.
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
Go to reference ref{fooref}.
Bottom of document.
end{document}
If I build my document with pdflatex foo.tex && pdflatex foo.tex
and open foo.pdf
with a PDF viewer, clicking on the reference created by ref{fooref}
takes me to the phantomsection
where label{fooref}
is present.
But if I build my document with make4ht foo.tex
and open foo.html
with a browser, clicking on the reference created by ref{fooref}
takes me to the top of the page. Is this a bug? Is there a way to resolve this?
Try this configuration file:
Preamble{xhtml}
makeatletter
defphantomsection{%
Hy@GlobalStepCountHy@linkcounter
xdef@currentHref{likesection.theHy@linkcounter}%
Hy@raisedlink{hyper@anchorstart{@currentHref}hyper@anchorend}%
edef@currentlabel{theHy@linkcounter}%
AnchorLabel%
}
makeatother
begin{document}
EndPreamble
It redefines the default definition of phantomesection
used by TeX4ht, it adds the label
support thanks to these lines:
edef@currentlabel{theHy@linkcounter}%
AnchorLabel%
The first line defines value of the reference that will be used in text, the second inserts the link destination into the text.
This is the resulting HTML code:
<!-- l. 5 --><p class='noindent'>Top of document
</p>
<h3 class='sectionHead' id='section-heading'><span class='titlemark'>1 </span> <a id='x1-10001'></a>Section heading</h3>
<!-- l. 8 --><p class='noindent'>Top of section
</p><!-- l. 10 --><p class='indent'> . <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />
</p><!-- l. 13 --><p class='indent'> <a id='likesection.1'></a> <a id='x1-1001x1'></a> We want to create a reference to this part of the document.
</p><!-- l. 17 --><p class='indent'> . <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />. <br class='newline' />
</p><!-- l. 24 --><p class='indent'> Go to reference <a href='#x1-1001x1'>1<!-- tex4ht:ref: fooref --></a>.
</p><!-- l. 26 --><p class='indent'> Bottom of document. </p>
As you can see, <a id='x1-1001x1'></a>
is inserted in the place of phantomsection
, and <a href='#x1-1001x1'>1</a>
points to that.
Correct answer by michal.h21 on June 9, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP