Document Classesmemoir's sidebar, addcontents, and hyperref

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
magister
Posts: 17
Joined: Sun Aug 02, 2009 4:42 am

memoir's sidebar, addcontents, and hyperref

Post by magister »

Hi --

I'm using memoir's sidebar feature extensively in a book, and I want the sidebars to appear in the TOC, so I have things like this:

Code: Select all

\sidebar{
\phantomsection\addcontentsline{toc}{section}{\hspace{.3in}Tech Note: Supplementary Characters} 
sidebar text } 
I'm also using hyperref to generate PDF bookmarks. The bookmarks for the sidebars all have an extra space in front of them, which is caused by the inclusion of the \hspace command; if I remove that, the bookmarks look fine but the sidebar TOC entries appear at the left margin, not indented correctly. (In other words, I have a TOC entry like "1.3 Subsection title" and I want the TOC sidebar entry to be indented to align with the actual 'Subsection title', not at the margin where the numerals 1.3 and so forth are.) Does anyone know a better way than using \hspace to get the indents, or a way to remove the spaces before the bookmarks?

Thanks - David

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

memoir's sidebar, addcontents, and hyperref

Post by frabjous »

Hyperref (see the manual page 17), defines a command which presents two alternatives, one to put in the TeX file and another in the PDF bookmarks:

Code: Select all

\texorpdfstring{TEXstring}{PDFstring}
So in your case, you might use:

Code: Select all

\texorpdfstring{\hspace{.3in}}{}
To produce an \hspace in the TeX file and nothing in the bookmarks.

Is that the best solution to your problem? Probably not, but it's hard to know how to address the spacing problem otherwise without a minimal working example. I was struck however that you're using \addcontentsline{toc}{section} rather than \addcontentsline{toc}{subsection} given the description of the problem which follows.
magister
Posts: 17
Joined: Sun Aug 02, 2009 4:42 am

memoir's sidebar, addcontents, and hyperref

Post by magister »

Frabjous,

Thank you for the suggestions and reference to the hyperref manual. I'll study them and see what happens.

As for the section/subsection thing: my book has chapters and sections (memoir's default), and I chose not to show subsections in the TOC, so the TOC looks like:

Code: Select all

Chapter 1: Blah blah
    1.1    Section One
    1.2    Section Two
           Sidebar: First One
So that's why I used \addcontentsline{toc}{section}. Just now, as an experiment, I tried subsection rather than section, without the \hspace. It mostly worked; I say "mostly" because the sidebar entries were just slightly less indented than the section entries, about a point or so. I guess hyperref doesn't know about chapters (or I need to tell it explicitly what my various levels are). This is the most complex book I've ever done, so I'm new at things like messing around with the TOC.

Thanks - David
magister
Posts: 17
Joined: Sun Aug 02, 2009 4:42 am

Re: memoir's sidebar, addcontents, and hyperref

Post by magister »

Hi frabjous,

Your suggestion of \texorpdfstring{\hspace{.3in}}{} works just fine!

Thanks again - David
Post Reply