bugtex4ht - Bugs: bug #607, tex4ht with package hyperref and...

 
 
Show feedback again

You are not allowed to post comments on this tracker with your current authentification level.

bug #607: tex4ht with package hyperref and option destlabel creates no ancor

Submitted by:  Ernst Reissner <reissner>
Submitted on:  Wed Aug 16 16:33:01 2023  
 
Category: NonePriority: 5 - Normal
Severity: 5 - NormalStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Open

Mon Aug 21 09:19:54 2023, comment #5:

The solution in the linked answer on TeX.sx is a base for the code that make4ht executes by default. I just fixed some errors and issues that I found in the meantime.

On the TeX side, when we add any code to \label, it will always point under the section title. This is because of how HTML works. As soon as the section is closed, it inserts the </h2> tag, and everything that follows, such as the destination anchor for the label, is displayed on another line. It could be possible to move the anchor to a section using Lua filters, but it would be slower.

In PDF, it may be possible to insert the destination on the same line, because it doesn't insert an implicit line break with the end tag.

Michal Hoftich <michal_h21>
Project Member
Sat Aug 19 11:17:04 2023, comment #4:

I tried the solution with config.cfg.
It works approximately:
The anchor seems to be set a bit late
and so the headline is cut off.

The other solution works very well for me.

I found another one,
https://tex.stackexchange.com/questions/260932/destlabel-option-of-the-hyperref-package-does-not-work-in-combination-with-htlat
also from you.
I dont like as much as the above, because filtering makes the thing slower.

Still I think all these are kind of workarounds:
hyperref is the way links are added to PDF
but HTML came with links from the very beginning.

I think,

```
\usepackage[destlabels, tex4ht]{hyperref}
```

shall work in a way, that `test.pdf#label` can be just replaced by `test.html#label`.
Maybe your solution with the config file
can be corrected a bit that the placement is more precise
and is automatted if `destlabels` is used in conjunction with `tex4ht`.

This would be very good.
Then also it is not important whether one uses make4ht or htlatex.

Ernst Reissner <reissner>
Thu Aug 17 21:15:27 2023, comment #3:

Save that code as config.cfg. To use it with htlatex, execute:

$ htlatex filename.tex "config,uni-html4,2,svg,pic-tabular" " -cunihtf -utf8"

With make4ht, use:

$ make4ht -c config.cfg filename.tex "uni-html4,2,svg,pic-tabular"

make4ht uses UTF-8 by default, so you don't need to pass extra parameters for tex4htOptions.

Michal Hoftich <michal_h21>
Project Member
Thu Aug 17 21:05:25 2023, comment #2:

First of all, thank you a lot for your quick reply!

One thing I don't understand:

```
You can try something like this:
%%%%%%%%%%%%%%%%%%%
\Preamble{xhtml}
\let\origlabel\label
\def\label#1{%
\HCode{<span id="#1">}%
\origlabel{#1}%
\HCode{</span>}%
}
\begin{document}
\EndPreamble
%%%%%%%%%%%%%%%%%%%
```

Where shall I add this? in the source?
Please explain ....

Ernst Reissner <reissner>
Thu Aug 17 08:42:08 2023, comment #1:

You can try something like this:

%%%%%%%%%%%%%%%%%%%
\Preamble{xhtml}
\let\origlabel\label
\def\label#1{%
\HCode{<span id="#1">}%
\origlabel{#1}%
\HCode{</span>}%
}
\begin{document}
\EndPreamble
%%%%%%%%%%%%%%%%%%%

It will add <span id="label name"> elements at the point of \label.

In addition, if you use make4ht instead of htlatex, it sets every section to use id based on the section name. So your sample produces something like this:

<h3 class='sectionHead' id='exporting-in-various-formats'><span class='titlemark'>1 </span> <a id='x1-10001'></a>Exporting in various formats</h3>

You can then link to "#exporting-in-various-formats" which should be stable unless you change the section title.

Michal Hoftich <michal_h21>
Project Member
Wed Aug 16 16:33:01 2023, original submission:

I create html from latex with
htlatex
tex4htStyOptions xhtml,uni-html4,2,svg,pic-tabular
tex4htOptions ’ -cunihtf -utf8’
t4htOptions the empty string

The latex file has in header
`\usepackage[tex4ht,destlabel]{hyperref}`
and has a section

```
\section{Exporting in various formats}\label{sec:stableUsage}
```

As a result, I obtain a html file
with following headline

```
<h3 class="sectionHead"><span class="titlemark">3.2</span>
<a id="x8-130003.2"></a>Exporting in various formats</h3>
```

Here, the label in the latex source does not occur.
Instead there is a generated label which may change,
e.g. when inserting another section.

When referencing this, it reads in the output

```
included and a Section&#x00A0;<a
href="#x8-130003.2">3.2<!--tex4ht:ref: sec:stableUsage --></a>
```
and here, the label `sec:stableUsage` occurs,
i.e. it is know, but it occurs only as a comment.

I would expect, that there are two anchors,
one with generated id and an other one with id
taken from the label in the source.

I think, i cannot use the reference `file.html#x8-130003.2`
because it is not stable.
I could use `file.html#sec:stableUsage`.

Ernst Reissner <reissner>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by michal_h21 (Posted a comment)
  • -unavailable- added by reissner (Submitted the item)
  • -unavailable- added by reissner
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    1 latest change follows.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed Aug 16 16:33:01 2023reissnerCarbon-Copy-=>Added -unavailable-
    Show feedback again

    Back to the top


    Powered by Savane 3.1-cleanup+gray