5

I use hyperref package to make TOC in the pdf file (you know, the pdf reader can display a toc). But, when hyperref is used, the command \MakeUppercase in a structure command (like \section or \chapter) cause trouble in compilation.

This is my MWE:

\documentclass[a4paper,12pt,oneside,french]{article}

\usepackage{xltxtra}
\usepackage{ucs}
\usepackage{fontenc}
\usepackage[frenchb,french,francais]{babel}
\usepackage{graphicx}
\usepackage[babel=true]{csquotes}

\usepackage{hyperref}

\author{Me}
\title{Lorem ipsum}
\date{This day}

\begin{document}
  \maketitle

  \section{Lorem ipsum {\MakeUppercase dolor}}
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi.


\end{document}

And when I compile it with xelatex main.tex, I get:

This is XeTeX, Version 3.1415926-2.5-0.9999.3 (TeX Live 2013)
restricted \write18 enabled.
entering extended mode
(./main.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ar
abic, farsi, pinyin, ukenglish, usenglishmax, basque, french, loaded.
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size12.clo))
(/usr/share/texmf-dist/tex/latex/xltxtra/xltxtra.sty
(/usr/share/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/share/texmf-dist/tex/generic/ifxetex/ifxetex.sty)
(/usr/share/texmf-dist/tex/latex/fontspec/fontspec.sty
(/usr/share/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/share/texmf-dist/tex/latex/l3kernel/l3names.sty
(/usr/share/texmf-dist/tex/latex/l3kernel/l3bootstrap.sty))
(/usr/share/texmf-dist/tex/latex/etex-pkg/etex.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3basics.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3expan.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3tl.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3seq.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3int.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3quark.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3prg.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3clist.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3token.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3prop.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3msg.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3file.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3skip.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3keys.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3fp.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3box.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3coffins.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3color.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3luatex.sty)
(/usr/share/texmf-dist/tex/latex/l3kernel/l3candidates.sty)
(/usr/share/texmf-dist/tex/generic/oberdiek/ifpdf.sty))
(/usr/share/texmf-dist/tex/latex/l3packages/xparse/xparse.sty)
(/usr/share/texmf-dist/tex/latex/fontspec/fontspec-patches.sty
(/usr/share/texmf-dist/tex/latex/base/fixltx2e.sty)
*************************************************
* LaTeX warning: "xparse/redefine-command"
* 
* Redefining document command \oldstylenums with arg. spec. 'm' on line 107.
*************************************************
) (/usr/share/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty
(/usr/share/texmf-dist/tex/latex/base/fontenc.sty
(/usr/share/texmf-dist/tex/latex/euenc/eu1enc.def)
(/usr/share/texmf-dist/tex/latex/euenc/eu1lmr.fd))
(/usr/share/texmf-dist/tex/xelatex/xunicode/xunicode.sty
(/usr/share/texmf-dist/tex/latex/tipa/t3enc.def
(/usr/share/texmf-dist/tex/latex/euenc/eu1lmss.fd))
(/usr/share/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/share/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/share/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/share/texmf-dist/tex/latex/latexconfig/graphics.cfg)
(/usr/share/texmf-dist/tex/xelatex/xetex-def/xetex.def))))
(/usr/share/texmf-dist/tex/latex/fontspec/fontspec.cfg)))
(/usr/share/texmf-dist/tex/latex/realscripts/realscripts.sty
*************************************************
* LaTeX warning: "xparse/redefine-command"
* 
* Redefining document command \textsubscript with arg. spec. 's' on line 25.                                                                                                          [0/15232]
*************************************************
*************************************************
* LaTeX warning: "xparse/redefine-command"
* 
* Redefining document command \textsuperscript with arg. spec. 's' on line 28.
*************************************************
) (/usr/share/texmf-dist/tex/latex/metalogo/metalogo.sty))
(/usr/share/texmf-dist/tex/latex/ucs/ucs.sty
(/usr/share/texmf-dist/tex/latex/ucs/data/uni-global.def))
(/usr/share/texmf-dist/tex/latex/base/fontenc.sty)
(/usr/share/texmf-dist/tex/generic/babel/babel.sty
(/usr/share/texmf-dist/tex/generic/babel/frenchb.ldf
(/usr/share/texmf-dist/tex/generic/babel/babel.def)
*************************************
* Local config file frenchb.cfg used
*
(/usr/share/texmf-dist/tex/generic/babel/frenchb.cfg))
(/usr/share/texmf-dist/tex/generic/babel/frenchb.ldf)
(/usr/share/texmf-dist/tex/generic/babel/frenchb.ldf))
(/usr/share/texmf-dist/tex/latex/carlisle/scalefnt.sty)
(/usr/share/texmf-dist/tex/latex/csquotes/csquotes.sty
(/usr/share/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/share/texmf-dist/tex/latex/csquotes/csquotes.def)
(/usr/share/texmf-dist/tex/latex/csquotes/csquotes.cfg))
(/usr/share/texmf-dist/tex/latex/hyperref/hyperref.sty
(/usr/share/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty
(/usr/share/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty))
(/usr/share/texmf-dist/tex/latex/oberdiek/kvoptions.sty)
(/usr/share/texmf-dist/tex/latex/hyperref/pd1enc.def)
(/usr/share/texmf-dist/tex/xelatex/xetexconfig/hyperref.cfg)
(/usr/share/texmf-dist/tex/latex/url/url.sty))

Package hyperref Message: Driver (autodetected): hxetex.

(/usr/share/texmf-dist/tex/latex/hyperref/hxetex.def
(/usr/share/texmf-dist/tex/latex/hyperref/puenc.def)
(/usr/share/texmf-dist/tex/generic/oberdiek/stringenc.sty)
(/usr/share/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty)) (./main.aux)
(/usr/share/texmf-dist/tex/latex/tipa/t3cmr.fd)
(/usr/share/texmf-dist/tex/latex/ucs/ucsencs.def
fontencoding T3 patched
) (/usr/share/texmf-dist/tex/latex/hyperref/nameref.sty
(/usr/share/texmf-dist/tex/generic/oberdiek/gettitlestring.sty)) (./main.out)
(./main.out)
! Undefined control sequence.
l.19       \chapter
                   {Lorem ipsum {\MakeUppercase dolor}}
? 
(/usr/share/texmf-dist/tex/generic/oberdiek/se-ascii-print.def) [1] (./main.aux
)
** WARNING ** Couldn't open font map file "cid-x.map".
 )
Output written on main.pdf (1 page).
Transcript written on main.log.

My output pdf is fine. But I get an error as you see and I want to didn’t get it. When I dell hyperref package I didn’t have this error but the pdf reader didn’t know my TOC.

So how to conserve my TOC in the reader but didn’t have the error?

fauve
  • 2,501
  • 1
    The undefined control sequence is \chapter; the article class hasn't chapters. – egreg Sep 03 '14 at 19:01
  • 2
    This post is very similar to Undefined control sequence and \chapter error as the fundamental problem is with \chapter being undefined within the article document class. – Werner Sep 03 '14 at 19:10
  • 1
    Don't use packages inputenc nor ucs nor xltxtra (outdated) with xelatex. Use utf8-encoded files and package fontspec. – Johannes_B Sep 03 '14 at 19:23
  • Excuse me, when I was writing my MWE I forget to pass \chapter to \section when I convert book to article. But, anyway, this isn’t the problem. In twice article or book class, I have problem with \chapter{Lorem ipsum {\MakeUppercase dolor}}, \section{Lorem ipsum {\MakeUppercase dolor}}, and \subsection{Lorem ipsum {\MakeUppercase dolor}}. The problem is here. I will correct my post now. – fauve Sep 03 '14 at 19:53

1 Answers1

7

The problem is with the code to generate the PDF bookmark. You need to use \texorpdfstring:

\documentclass{article}

\usepackage{fontspec}

\usepackage{hyperref}

\author{Me}
\title{Lorem ipsum}
\date{This day}

\begin{document}
  \maketitle

  \section{Lorem ipsum \texorpdfstring{\MakeUppercase dolor}{dolor}}

  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi.


\end{document}
Nicola Talbot
  • 41,153
  • Thank you, is nice and now, it work :) But, to be honest, I use a definition of command:

    \newcommand{\taxon}[1]{\emph{\texorpdfstring{\MakeUppercase #1}{#1}}}

    to print names of scientific taxon like Homo sapiens or Felix catus. So, I can use \taxon out of a structure command. And, in this cases, I will have an anecessary \texorpdfstring. It isn’t matter?

    – fauve Sep 03 '14 at 20:15
  • 1
    @fauve You can also use \section[Lorem ipsum dolor]{Lorem ipsum \MakeUppercase dolor} –  Sep 03 '14 at 22:49
  • 1
    @fauve Outside of the bookmarks, \texorpdfstring just does its first argument, so it should be fine to use it outside of the \section or \chapter argument. Another possiblity (untested) is to add \let\MakeUppercase\@empty to \pdfstringdefDisableCommands. (See this answer.) – Nicola Talbot Sep 04 '14 at 12:08
  • @user11232, you cannot do \section[Lorem ipsum]{Lorem ipsum \MakeUppercase dolor} when you have the package hyperref included. – user Aug 29 '17 at 19:28