Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need to draw a simple symbol with tikz/pgf to a chapter command, for example:

\documentclass{book}
\usepackage{tikz}

\begin{document}

\chapter{hello tikz\tikz\node{pgf};}

\end{document}

but this does not work, is there anyway to fix this? thanks.

share|improve this question
add comment

3 Answers

up vote 8 down vote accepted

Anything inside sectioning commands must be robust or protected using \protect. If you are using hyperref (which I assume) you need also take special care because the content will then end up as PDF bookmarks which don't support anything expect normal text.

I would suggest using the following code:

\documentclass{book}
\usepackage{tikz}
\usepackage{hyperref}

\DeclareRobustCommand{\TikzStuff}{\texorpdfstring{\tikz\node{pgf};}{replacement text}}

\begin{document}
\chapter{hello \TikzStuff}
\end{document}

Instead of the older \DeclareRobustCommand (which doesn't produce an error if the command already exists) the \newrobustcmd command from etoolbox can be used which takes advantage of the e-TeX extension of LaTeX. This can also be used directly using \protected\def\TikzStuff{..}.

share|improve this answer
add comment

I believe that your porblem is similar to Undefined color error, if have symbol in Chapter Title. Try this:

\documentclass{book}
\usepackage{tikz}

\DeclareRobustCommand{\MyTikzNode}{\tikz\tikz\node{pgf};}

\begin{document}
\chapter{hello \MyTikzNode}
\end{document}
share|improve this answer
add comment

I stumbled upon this post while trying to do something similar; I ended up implementing the following new commands, which, though naive, worked smoothly enough for my document:

\documentclass{amsart}

\newcommand{\ellipse}[1]
{
     \begin{center} \tikz\node[draw, fill = blue!20!white, ellipse]{#1}; \end{center}
}
\newcommand{\hide}[1]
{
    \texorpdfstring{\protect\phantom{\hspace*{5em}#1}}{#1}
}
\newcommand{\csec}[1]
{
    \section{\hide{#1}} 
    \vspace*{-5ex}\ellipse{#1}
}

\usepackage{amsfonts, amsmath, amssymb, amsthm}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes, snakes}
\usepackage{hyperref}

\begin{document}
\section*{Note}
To make a circled, unnumbered section, you could define a new command \verb`csecun` just like \verb`csec` but using the \verb`section*` command.
\csec{First Section}
\csec{Second Section}
\end{document}
share|improve this answer
    
Welcome to TeX.sx! –  texenthusiast Apr 5 '13 at 18:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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