我在使用自定义文档类编译文档时遇到问题。我正在尝试使用 处理传递给文档类的键值参数xkeyval
。我还需要使用hyperref
包。这就是我出错的地方。我将两个文件都缩减到绝对(非)工作最小值。
文件long-table.tex
:
\documentclass[lang=czech]{myclass}
\begin{document}
hello
\end{document}
文件myclass.cls
:
% my class
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesClass{myclass}[2016/01/03 test class]
% Parameters
\RequirePackage{xkeyval}
\define@choicekey*+{myclass}{lang}[\value\position]{czech,english}{%
\ifcase\position\relax
\newcommand{\lang}{czech}
\or%
\newcommand{\lang}{english}
\fi
}{%
\PackageError{myclass}{Neplatná hodnota argumentu lang: \value}
}
\ProcessOptionsX<myclass>
\LoadClass[11pt,a4paper]{article}
\RequirePackage{hyperref}
\AtBeginDocument{%
\lang
}
\endinput
编译总是以错误结束,我找不到原因:
This is LuaTeX, Version beta-0.80.0 (TeX Live 2015/Arch Linux) (rev 5238)
restricted \write18 enabled.
(/home/jirka/tmp/pokus2/long-table.tex
LaTeX2e <2015/10/01> patch level 2
Babel <3.9m> and hyphenation patterns for 79 languages loaded.
(./myclass.cls
Document Class: myclass 2016/01/03 test class
(/usr/share/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/share/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/share/texmf-dist/tex/generic/xkeyval/xkvutils.tex
(/usr/share/texmf-dist/tex/generic/xkeyval/keyval.tex))))
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size11.clo))
(/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/scripts/oberdiek/oberdiek.luatex.lua)))
(/usr/share/texmf-dist/tex/generic/ifxetex/ifxetex.sty)
(/usr/share/texmf-dist/tex/latex/oberdiek/auxhook.sty)
(/usr/share/texmf-dist/tex/latex/oberdiek/kvoptions.sty)
(/usr/share/texmf-dist/tex/latex/hyperref/pd1enc.def)
(/usr/share/texmf-dist/tex/latex/latexconfig/hyperref.cfg)
(/usr/share/texmf-dist/tex/latex/url/url.sty))
Package hyperref Message: Driver (autodetected): hpdftex.
(/usr/share/texmf-dist/tex/latex/hyperref/hpdftex.def
(/usr/share/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty)))
(/home/jirka/tmp/pokus2/.tmp/l2iqdsbf/long-table.aux)
(/usr/share/texmf-dist/tex/latex/hyperref/nameref.sty
(/usr/share/texmf-dist/tex/generic/oberdiek/gettitlestring.sty))
(/home/jirka/tmp/pokus2/.tmp/l2iqdsbf/long-table.out)
(/home/jirka/tmp/pokus2/.tmp/l2iqdsbf/long-table.out)
! Missing number, treated as zero.
<to be read again>
c
l.7 \end{document}
?
[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}]
(/home/jirka/tmp/pokus2/.tmp/l2iqdsbf/long-table.aux))
264 words of node memory still in use:
2 hlist, 1 vlist, 1 rule, 2 glue, 40 glue_spec, 1 write nodes
avail lists: 2:19,3:4,4:27,5:8,6:18,7:1,8:2,9:13
<</usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on long-table.pdf (1 page, 10719 bytes).
SyncTeX written on long-table.synctex.gz.Transcript written on long-table.log.
návratová hodnota shellu 1
Press ENTER or type command to continue
我发现的唯一问题是,问题是由于hyperref
结合命令加载包\ProcessOptionsX<myclass>
而引起的xkeyval
。当我注释掉其中任何一个时,一切都正常。
答案1
该命令是\val\position
,不是\value\position
!!!
\value
期望有一个计数器名称,但是\position
这里没有计数器。
% my class
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesClass{myclassnew}[2016/01/03 test class]
% Parameters
\RequirePackage[utf8]{inputenc}
\RequirePackage{xkeyval}
\define@choicekey*+{myclassnew}{lang}[\val\position]{czech,english}{%
\ifcase\position\relax
\newcommand{\lang}{czech}
\or%
\newcommand{\lang}{english}
\fi
}{%
\ClassError{myclassnew}{Neplatná hodnota argumentu lang: #1}
}
\ProcessOptionsX<myclassnew>
\LoadClass[11pt,a4paper]{article}
\RequirePackage{hyperref}
\AtBeginDocument{%
\lang
}
\endinput
使用类
\documentclass[lang=czech]{myclassnew}
\begin{document}
hello
\end{document}
将输出
捷克你好