# Why do some packages not work in section titles?

Sincere apologies if I am not using the format of this site correctly.

I am using XeLaTeX with article class, and am trying to create commands for abreviations I use often. In two cases, however, commands which work fine in the main text make LaTeX crash when I use them in section titles.

Specifically, it seems that the \relsize and \relscale commands from the relsize package make the compilation crash when used in section titles (\smaller, oddly, does not). I encounter the same problem with \xperiod from the xpunctuate package.

Is there something going on I don't know about?

EDIT : in creating minimum working example, I may know what is wrong, but not how to fix it. Context is creating the styling for centuries in French, which are written in small caps, but small caps don't exist in some bold fonts. So I am trying to create a workaround.

The following code works:

\documentclass{article}

\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{relsize}
\usepackage{polyglossia}
\usepackage{xspace}
\usepackage{xpunctuate}

\newcommand{\siecle}[1]{\textsc{#1}\textsuperscript{e} siècle}

\newcommand{\boldsiecle}[1]{{\relscale{0.75}\uppercase{#1}}\textsuperscript{e} siècle}

\providecommand{\BC}[0]{\mbox{av. J.-C}\xperiod}

\begin{document}

Nous sommes au \siecle{ii} \BC

Nous sommes au \boldsiecle{ii} \BC

\textbf{Nous sommes au \siecle{ii} \BC}

\textbf{Nous sommes au \boldsiecle{ii} \BC}

\section{La vie au \boldsiecle{ii} \BC}

Lorem ipsum

\end{document}


This code crashes (only hyperref has been added):

\documentclass{article}

\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{relsize}
\usepackage{polyglossia}
\usepackage{xspace}
\usepackage{xpunctuate}
\usepackage{hyperref}

\newcommand{\siecle}[1]{\textsc{#1}\textsuperscript{e} siècle}

\newcommand{\boldsiecle}[1]{{\relscale{0.75}\uppercase{#1}}\textsuperscript{e} siècle}

\providecommand{\BC}[0]{\mbox{av. J.-C}\xperiod}

\begin{document}

Nous sommes au \siecle{ii} \BC

Nous sommes au \boldsiecle{ii} \BC

\textbf{Nous sommes au \siecle{ii} \BC}

\textbf{Nous sommes au \boldsiecle{ii} \BC}

\section{La vie au \boldsiecle{ii} \BC}

Lorem ipsum

\end{document}


I imagine hyperref must be clashing with something? What is going on?

• As always on this site please provide a full (but minimal) self contained example. Then it is a lot easier to help you. RIght now we have no idea what you're doing. – daleif Feb 17 at 14:25
• Please provide a MWE. The macros provided by relscale are robust and worked for me in a simple test, so whatever is happening is due to some code you are withholding. – campa Feb 17 at 14:26
• The general problem is that the text of each section title get written to the .toc file, and a problem often arises because most commands expand to something other than text. You can try putting \protected in front of the problematic command, but an example would be more helpful. (And it's a command not working in the section title, not a package.) – Teepeemm Feb 17 at 14:33
• That's a standard issue: not all TeX macros are allowed in the argument of \section & Co when hyperref is loaded. You need \texorpdfstring, in your case \section{La vie au \texorpdfstring{\boldsiecle{ii} \BC}{iie av. J.-C}} or similar. The first argument is what will be typed in the pdf file, the second argument is the content of the bookmark. – campa Feb 17 at 16:06
• Try \section[simple title for TOC]{My complicated title with macros} – Fran Feb 17 at 16:40