GeneralList of Equation PDF bookmark bug?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Shea12Shea12
Posts: 2
Joined: Mon Feb 12, 2024 6:06 pm

List of Equation PDF bookmark bug?

Post by Shea12Shea12 »

Hello, this is my first time on this forum so please excuse any mistakes.

I am currently trying to create a technical report which contains: chapters, figures, tables and equations. I currently use Rmarkdown to render the PDF, and when I create the PDF, there is a Bookmarks panel that helps navigate to chapters, sections, etc. (If this question needs to be taken to an R forum please let me know!) However, when I click on the "List of Equation" Bookmark, it jumps to "List of Tables".

Below is the Code used in my .Rmd file

Code: Select all

---
output:
  pdf_document:
    includes:
      in_header: preamble.tex
fontsize: 11pt
documentclass: book
---
\tableofcontents
\clearpage

\listoffigures
\clearpage

\listoftables
\clearpage

\listofmyequations
\clearpage

\chapter{First chapter}

\section{First section}

\begin{equation}
E=mc^2 
\end{equation}
\myequations{Some equation}
and my preamble.tex file

Code: Select all

\usepackage{tocbibind}
\usepackage{tocloft}
\usepackage{xpatch}

\newcommand{\listequationsname}{List of Equations}
\newlistof{myequations}{equ}{\listequationsname}
\newcommand{\myequations}[1]{%
\addcontentsline{equ}{myequations}{\protect\numberline{\theequation}#1}\par}

\xpretocmd{\listofmyequations}{\addcontentsline{toc}{chapter}{\listequationsname}}{}{}
From my understanding, the "\xpretocmd ..." line is what adds the LoE to the bookmarks, but it must share the same reference as LoT?

Thank you for reading this post, and any help is much appreciated.

Alan

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10360
Joined: Mon Mar 10, 2008 9:44 pm

List of Equation PDF bookmark bug?

Post by Stefan Kottwitz »

Hello Alan,

welcome to the forum!

Try inserting \phantomsection (explained here):

Code: Select all

\newcommand{\myequations}[1]{%
\phantomsection%
\addcontentsline{equ}{myequations}{\protect\numberline{\theequation}#1}\par}
and / or

Code: Select all

\xpretocmd{\listofmyequations}{\phantomsection\addcontentsline{toc}{chapter}{\listequationsname}}{}{}
Stefan
LaTeX.org admin
Shea12Shea12
Posts: 2
Joined: Mon Feb 12, 2024 6:06 pm

List of Equation PDF bookmark bug?

Post by Shea12Shea12 »

Stefan,

Thank you for your quick response. With your insight, I managed to use /phantomsection to correct my report. The following is the fix.

Code: Select all

---
output:
  pdf_document:
    includes:
      in_header: preamble.tex
fontsize: 11pt
documentclass: book
---
\tableofcontents
\clearpage

\listoffigures
\clearpage

\listoftables
\clearpage

\phantomsection
\listofmyequations
\clearpage

\chapter{First chapter}

\section{First section}

\begin{equation}
E=mc^2 
\end{equation}
\myequations{Some equation}
Again, thank you.
Alan
Post Reply