0

In the following example, I have added the belowpdfbookmark command of the hyperref package after the lettrine numbers to add these to the bookmarks manually.

How can I do this automatically, so that I don't have to add the belowpdfbookmark command after every instance of gChapter? Would I need to use the 'addtohook' option? And if so, how?

\documentclass[12pt]{memoir}

\usepackage{lettrine}
\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{bookmark}

\newcommand{\gChapter}[1]{\lettrine{{{#1}}}\ignorespaces}

\begin{document}
\chapter{Sayings}
\gChapter{1}\belowpdfbookmark{1}{one}
\lipsum[2]
\gChapter{2}\belowpdfbookmark{2}{two}
\lipsum[3]
\gChapter{3}\belowpdfbookmark{3}{three}
\lipsum[4]
\end{document}
  • I don't understand your question really: \chapter does use bookmarks with hyperref already, you want to add bookmarks for something like numbered paragraphs with your \gchapter macro? – user31729 Aug 24 '17 at 6:05
  • Yes, maybe the question needs to be edited. – dietz Aug 24 '17 at 8:25
  • The format is that of the Bible, with each Bible book divided up into numbered text units (the Bible chapters=gChapter). Each text unit comprises of a number of (not numbered) paragraphs. – dietz Aug 24 '17 at 8:36
2

As by the comments you want to numbered manually, you can use this. The counter is there to get unique bookmark names.

\documentclass[12pt]{memoir}

\usepackage{lettrine}
\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{bookmark}

\newcounter{gChapter}[chapter]
\newcommand{\gChapter}[1]{\par\refstepcounter{gChapter}\belowpdfbookmark{#1}{\thechapter.\thegChapter}\lettrine{#1}\ignorespaces}

\begin{document}
\chapter{Sayings}
\gChapter{1}
\lipsum[2]
\gChapter{2}
\lipsum[3]
\gChapter{3}
\lipsum[4]

\chapter{Sayings}
\gChapter{1}
\lipsum[2]
\gChapter{2}
\lipsum[3]
\gChapter{1} %to check if the link is unique
\lipsum[4]

\end{document}
  • this answers my question well, so I accepted it. However, I don't actually want the gChapters to be numbered automatically. How can I modify the example to accommodate this? – dietz Aug 24 '17 at 9:53
  • After second thoughts I've undone the acceptance of the answer. Although the answer is excellent, I need to number the gChapters manually and so keep the number in curly brackets after gChapters. – dietz Aug 24 '17 at 10:19
  • Then simply use #1 inside the argument instead of \thegchapter and remove the \refstepcounter. But if the numbering is not unique you will need another argument to get a unique bookmark name. – Ulrike Fischer Aug 24 '17 at 11:06
  • Thinking a bit: better keep the counter and use only #1 in the lettrine. Then you will get unique names and manual representation. I will edit the answer later. – Ulrike Fischer Aug 24 '17 at 11:14

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.