我使用hyperref
包在 pdf 文件中制作目录(你知道,pdf 阅读器可以显示目录)。但是,当使用 时,结构命令中的hyperref
命令(如或)会导致编译出现问题。\MakeUppercase
\section
\chapter
这是我的 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}
当我用它编译时xelatex main.tex
,我得到:
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.
我的输出 pdf 没问题。但是我得到了一个错误,正如你所看到的,我想没有得到它。当我使用 dellhyperref
包时,我没有遇到这个错误,但是 pdf 阅读器不知道我的目录。
那么如何在阅读器中保存我的目录但不出现错误?
答案1
问题在于生成 PDF 书签的代码。您需要使用\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}