0

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 \renewcommand\section{
@startsection{section}{1}{\z@}{-1ex}{-1.5ex}{\bfseries\MakeUppercase}% }

\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?

  • see e.g. https://tex.stackexchange.com/a/271903/2388 – Ulrike Fischer Jan 30 '21 at 17:35
  • I see so the bookmark was being modified the by style argument of the section command. The pdfstringdefDisableCommands in the linked question is not enough since that only acts on the section title argument instead of the output of startsection. The linked accepted answer fixes this by redefining \Sectionformat to upper case the section heading instead of using startsection for upper caseing the section heading. – Frank Wilson Jan 30 '21 at 18:23

1 Answers1

0

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}% {@nonchangecase\ensuremath}% {@nonchangecase\ensuremath@nonchangecase\Hy@SectionAnchorHref}% {\message{!!! Patching successful !!!}}% {\message{!!! Patching failed !!!}}% \makeatother

\setcounter{secnumdepth}{-2}

\makeatletter \renewcommand\section{%%%% @startsection{section}{1}{\z@}{-1ex}{-1.5ex}{\bfseries\MakeUppercase}% } \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
[...]
Ulrich Diez
  • 28,770