TransWikia.com

Defining Lead-In Heading [with capitals] breaks automatic hyperref's pdf bookmarks

TeX - LaTeX Asked by Frank Wilson on March 25, 2021

I am trying to define my own document class with some lead-in style heading text and pdf bookmarks.

Here is my class file myclass.cls:

NeedsTeXFormat{LaTeX2e}
ProvidesClass{myclass}

LoadClass[12pt,oneside,a4paper]{article}

makeatletter

% disable section numbering
setcounter{secnumdepth}{-2}    

% define lead-in section
renewcommandsection{  
@startsection{section}{1}{z@}{-1ex}{-1.5ex}{bfseriesMakeUppercase}%
}

RequirePackage{hyperref}

hypersetup{bookmarksdepth=4}

makeatother

And here is my document source mydoc.tex:

documentclass{myclass}

usepackage[english]{babel}
usepackage{blindtext}

begin{document}

section{First Section}

blindtext[5]


section{Second Section}

blindtext[5]


section{Third Section}

blindtext[5]


end{document}

If I compile this with pdflatex I get the following warnings:

pdfTeX warning (dest): name{section*.
3} has been referenced but does not exist, replaced by a fixed one

pdfTeX warning (dest): name{section*.2} has been referenced but does not exist,
 replaced by a fixed one

pdfTeX warning (dest): name{section*.1} has been referenced but does not exist,
 replaced by a fixed one

And pdf bookmarks do not go to their respective heading with clicked in the pdfviewer.

If the renewcommand below the comment % define lead-in section is removed. The bookmarks work fine (but then I won’t have the heading style I was looking for. I’d strongly prefer to keep the automatic section labelling/bookmarking if possible. Any ideas on how this can be achieved?

One Answer

Probably you can use the MakeUppercase-variant of the textcase-package and patch its underlying @uclcnotmath-command to prevent case-changing also with Hy@SectionAnchorHref, which, when hyperref is loaded, creates anchors/named destinations of sections:

documentclass[12pt,oneside,a4paper]{article}

usepackage[overload]{textcase}
usepackage{etoolbox}
makeatletter
patchcmd{@uclcnotmath}%
         {@nonchangecaseensuremath}%
         {@nonchangecaseensuremath@nonchangecaseHy@SectionAnchorHref}%
         {message{!!! Patching successful !!!}}%
         {message{!!! Patching failed !!!}}%
makeatother


setcounter{secnumdepth}{-2}

makeatletter
renewcommandsection{%%%%
   @startsection{section}{1}{z@}{-1ex}{-1.5ex}{bfseriesMakeUppercase}%
}
makeatother

RequirePackage{hyperref}

hypersetup{bookmarksdepth=4}

usepackage[english]{babel}
usepackage{blindtext}

begin{document}

section{First Section}

blindtext[5]


section{Second Section}

blindtext[5]


section{Third Section}

blindtext[5]


end{document}

Things in use when writing/testing the code above:

This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex 2021.1.17)  30 JAN 2021 21:33
entering extended mode
[...]
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-01-09> xparse <2020-03-03>
[...]
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
[...]
Package: textcase 2019/09/14 v1.00 Text only upper/lower case changing (DPC)
[...]
Package: etoolbox 2020/10/05 v2.5k e-TeX tools for LaTeX (JAW)
[...]
Package: hyperref 2020-05-15 v7.00e Hypertext links for LaTeX
[...]
Package: blindtext 2012/01/06 V2.0 blindtext-Package
[...]
Package: babel 2020/12/16 3.52 The Babel package
[...]
File: babel.def 2020/12/16 3.52 Babel common definitions
[...]
Language: english 2017/06/06 v3.3r English support from the babel system
[...]

Answered by Ulrich Diez on March 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP