2

The following code produces the following PDF.

\documentclass{article}
\usepackage[bookmarks=true] {hyperref}
\begin{document}

\part{\label{blah}Hi}

\section{Answers to Part \hyperref[blah]{Hehehe}}

\end{document}

enter image description here

I'm not sure why "[blah]" somehow appears in the PDF bookmark. How do I get rid of it?

[I'm using hyperref because I want to have any arbitrary text (e.g. "Hehehe") for my hyperlink.]

3

You wrote, in a comment on this answer:

I want to use \hyperref so I can put arbitrary text for my hyperlink.

You could use the \texorpdfstring macro.

enter image description here

It's not possible to have general hyperlinks in the Bookmarks portion of the pdf document.

\documentclass{article}
\usepackage[bookmarks=true] {hyperref}
\begin{document}
\part{Hi} \label{blah}
\section{Answers to \texorpdfstring{\hyperref[blah]{Part I}}{\autoref{blah}}}
\end{document}
2

It works fine if you use \ref.

\documentclass{article}
\usepackage[bookmarks=true] {hyperref}
\begin{document}

\part{Hi}
\label{blah}

\section{Answers to Part \ref{blah}}

\end{document}
  • I want to use hyperref so I can put arbitrary text for my hyperlink. – dtcm840 Jul 15 '18 at 8:47
2

Or based on this answer by Heiko Oberdiek:

\documentclass{article}
\usepackage[bookmarks=true] {hyperref}
\pdfstringdefDisableCommands{%
    \def\hyperref#1#{}%
}
\begin{document}
\part{\label{blah}Hi}
\section{Answers to \hyperref[blah]{Part I}}
\end{document}

Result:

enter image description here

  • Looks good, but I don't understand it fully and I'm worried there may be side effects especially if I declare it globally. – dtcm840 Jul 16 '18 at 3:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.