mhchem 和 beamer:标题中使用“\ce”会导致“未定义的控制序列”。

mhchem 和 beamer:标题中使用“\ce”会导致“未定义的控制序列”。

当我尝试\ce{CH4}在标题中使用 documentclass beamer 时,出现Undefined control sequence错误。

以下是(几乎)最小(不)工作示例:

\documentclass{beamer}
\listfiles
\usepackage{mhchem}
\title{\ce{CH4}}
\begin{document}
\begin{frame}
\ce{CH4}
\end{frame}
\end{document}

运行后pdflatex mini,这是写入 stdout+stderr 的输出(mini.log对于 Stack Exchange 帖子来说太长了)。有什么解决方法或其他方法可以用来在标题中排版化学公式吗?

(我的实际的用例在海报的标题中)

This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 restricted \write18 enabled.
entering extended mode
(./mini.tex
LaTeX2e <2011/06/27>
Babel <3.9h> and hyphenation patterns for 78 languages loaded.
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamer.cls
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasercs.s
ty)
Document Class: beamer 2013/12/02 3.33 A class for typesetting presentations (r
cs-revision 332bfd3ce558)

(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasemodes
.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasedecod
e.sty))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbaseoptio
ns.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/graphics/keyval.sty))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/geometry/geometry.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/oberdiek/ifvtex.sty)
 (/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/ifxetex/ifxetex.sty
)) (/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/base/size11.clo)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/pgf/basiclayer/pgfcore
.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/graphics/graphicx.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/graphics/graphics.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/graphics/trig.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/latexconfig/graphics.c
fg)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/pdftex-def/pdftex.def
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/oberdiek/infwarerr.s
ty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/oberdiek/ltxcmds.sty
))))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/pgf/systemlayer/pgfsys
.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/pgf/utilities/pgfrcs.s
ty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/utilities/pgfuti
l-common.tex
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/utilities/pgfuti
l-common-lists.tex))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/utilities/pgfuti
l-latex.def
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/ms/everyshi.sty))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/utilities/pgfrcs
.code.tex))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/systemlayer/pgfs
ys.code.tex
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/utilities/pgfkey
s.code.tex
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/utilities/pgfkey
sfiltered.code.tex))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/systemlayer/pgf.
cfg)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/systemlayer/pgfs
ys-pdftex.def
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/systemlayer/pgfs
ys-common-pdf.def)))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/systemlayer/pgfs
yssoftpath.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/systemlayer/pgfs
ysprotocol.code.tex))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/xcolor/xcolor.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/latexconfig/color.cfg)
)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
re.code.tex
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmath.cod
e.tex
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmathcalc
.code.tex
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmathutil
.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmathpars
er.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmathfunc
tions.code.tex
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmathfunc
tions.basic.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmathfunc
tions.trigonometric.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmathfunc
tions.random.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmathfunc
tions.comparison.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmathfunc
tions.base.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmathfunc
tions.round.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmathfunc
tions.misc.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmathfunc
tions.integerarithmetics.code.tex)))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/math/pgfmathfloa
t.code.tex))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
repoints.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
repathconstruct.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
repathusage.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
rescopes.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
regraphicstate.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
retransformations.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
requick.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
reobjects.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
repathprocessing.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
rearrows.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
reshade.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
reimage.code.tex
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
reexternal.code.tex))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
relayers.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
retransparency.code.tex)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/pgf/basiclayer/pgfco
repatterns.code.tex)))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/pgf/utilities/xxcolor.
sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/oberdiek/atbegshi.st
y)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/hyperref/hyperref.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/oberdiek/hobsub-hype
rref.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/generic/oberdiek/hobsub-gene
ric.sty))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/oberdiek/auxhook.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/oberdiek/kvoptions.sty
) (/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/hyperref/pd1enc.def)

(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/latexconfig/hyperref.c
fg) (/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/url/url.sty)

Package hyperref Message: Stopped early.

)

Package hyperref Message: Driver (autodetected): hpdftex.

(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/hyperref/hpdftex.def
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/oberdiek/rerunfilechec
k.sty))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbaserequi
res.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasecompa
tibility.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasefont.
sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/amsfonts/amsfonts.sty)
)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/sansmathaccent/sansmat
haccent.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/filehook/filehook.sty)
))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasetrans
lator.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/translator/tran
slator.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/translator/tran
slator-language-mappings.tex)))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasemisc.
sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasetwosc
reens.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbaseoverl
ay.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasetitle
.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasesecti
on.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbaseframe
.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbaseverba
tim.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbaseframe
size.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbaseframe
components.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasecolor
.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasenotes
.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasetoc.s
ty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasetempl
ates.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbaseauxte
mplates.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbaseboxes
.sty)))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbaselocal
structure.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/tools/enumerate.sty))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasenavig
ation.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasetheor
ems.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/amsmath/amstext.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/amscls/amsthm.sty))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/beamerbasetheme
s.sty))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/themes/theme/be
amerthemedefault.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/themes/font/bea
merfontthemedefault.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/themes/color/be
amercolorthemedefault.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/themes/inner/be
amerinnerthemedefault.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/beamer/themes/outer/be
amerouterthemedefault.sty)))
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/mhchem/mhchem.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/base/ifthen.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/tools/calc.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/oberdiek/twoopt.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/expl3.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3names.sty
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3bootstrap.s
ty)) (/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/etex-pkg/etex.sty
)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3basics.sty)
 (/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3expan.sty)
 (/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3tl.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3seq.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3int.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3quark.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3prg.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3clist.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3token.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3prop.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3msg.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3file.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3skip.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3keys.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3fp.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3box.sty)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3coffins.sty
) (/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3color.sty
)
(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3luatex.sty)

(/home/gerrit/software/texlive/2013/texmf-dist/tex/latex/l3kernel/l3candidates.
sty))

Package mhchem Warning: You did not specify a 'version' option for the mhchem
(mhchem)                package. If you are about to create a new document,
(mhchem)                please write \usepackage[version=3]{mhchem} in your
(mhchem)                preamble in order to use the most recent version of
(mhchem)                mhchem.

)
! Undefined control sequence.
\mhchem@ce ...ate {s}\chardef \mhchem@ce@substate 
                                                  =0\relax \mhchem@ce@result...
l.4 \begin{document}

? No pages of output.
Transcript written on mini.log.

答案1

\ce如果您在之后才定义标题,则标题中有效\begin{document}。此外,软件包作者强烈建议您[version=3]在加载软件包时使用该选项。

\documentclass{beamer}
\usepackage[version=3]{mhchem}
\begin{document}
\title{\ce{CH4}}
\titlepage
\begin{frame}
\ce{CH4}
\end{frame}
\end{document}

相关内容