Document ClassesNew Environment with corresponding Bookmarks

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
tumerictj
Posts: 3
Joined: Wed Feb 08, 2012 7:04 pm

New Environment with corresponding Bookmarks

Post by tumerictj »

Hi All,

I have been using LaTeX for a while, but this is my first post.

I would like to make a numbered "Exercise" environment that generates (via the hyperref package) a corresponding bookmark "Exercise #_" in the PDF output file.

I know how to define the envioronment and how to manually create a bookmark. But what is tripping me up is
  1. Linking the bookmark creation to the \begin{exercise} command
  2. Matching the bookmark title with the environment title (e.g. "Exercise 5").


Thank you in advance for any advice on this issue.

Recommended reading 2024:

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

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

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Re: New Environment with corresponding Bookmarks

Post by cgnieder »

Would you like to show us how you're defining the environment? Help could then be more specific.

Best
site moderator & package author
tumerictj
Posts: 3
Joined: Wed Feb 08, 2012 7:04 pm

New Environment with corresponding Bookmarks

Post by tumerictj »

I'm using

Code: Select all

\theoremstyle{plain} \newtheorem{ex}{Exercise}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
with AMS and hyperref packages in the preamble.

As it is,

Code: Select all

Code, edit and compile here:
\begin{exercise}[blaBlaBla]
...
\end{exercise}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
works nicely to name and number exercises, but I would like pdfLaTeX to make a bookmark called "Exercise #whatever," (I don't care if the name "blaBlaBla" shows up) as it does for the \section command. Ideally, the solution would work even if I changed the numbering level of the environment (e.g. "2.2" instead of "2").

Thank you for the time.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

New Environment with corresponding Bookmarks

Post by cgnieder »

I would wrap another environment around the one defined through »\newtheorem« and use hyperref's »\pdfbookmark[<level>]{<name>}{<label>}« inside it. Something like

Code: Select all

Code, edit and compile here:
\newtheorem{ex}{Exercise}
\newenvironment{exercise}[1]{%
\begin{ex}[#1]%
\def\exname{Exercise \theex #1}%
\def\exlabel{ex:\theex}%
\pdfbookmark[2]{\exname}{\exlabel}%
}{%
\end{ex}\ignorespaces
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
site moderator & package author
tumerictj
Posts: 3
Joined: Wed Feb 08, 2012 7:04 pm

Re: New Environment with corresponding Bookmarks

Post by tumerictj »

Clever.... This solves my question.

Thank You!
Post Reply