ドキュメントクラス:testclass.cls

ドキュメントクラス:testclass.cls

私は、デフォルトで複数のパッケージをロードするドキュメントクラスを作成しています。ドキュメントクラスのオプションを使用して、ユーザーがこれらのパッケージにオプションを渡すことができるようにしたいと考えています。ほとんどのパッケージには複数のオプションがあるため、これらのオプションを何らかのリストのように渡す必要がありますが、現時点では機能しません。

これを実現する(簡単な)方法はありますか?

以下は、オプションを に渡すサンプル クラスを含む MWE ですamsmath

ドキュメントクラス:testclass.cls

\RequirePackage{expl3, l3keys2e}

\ExplSyntaxOn

\keys_define:nn {testclass} {
  amsmathoptions .tl_gset:N = \g_testclass_amsmathoptions_tl,
  amsmathoptions .initial:n = intlimits
}

\DeclareOption*{%
  \PassOptionsToClass{\CurrentOption}{article}%
}

\ProcessOptions
\ProcessKeysOptions{testclass}

\LoadClass{article}

\RequirePackage[\g_testclass_amsmathoptions_tl]{amsmath}

\ExplSyntaxOff

例 1: 単一のオプションを渡す (動作)

\documentclass[amsmathoptions=nonamelimits]{testclass}

\begin{document}

Integral: 
\[
  \int_a^b f(x) \mathop{}\!\mathrm{d}x
\]

Operators: 
\[
  \lim_{x \rightarrow \infty} f(x)
\]
\end{document}

結果1

例

例 2: 複数のオプションを渡す (動作しません)

\documentclass[amsmathoptions={nointlimits, nonamelimits}]{testclass}

\begin{document}

Integral: 
\[
  \int_a^b f(x) \mathop{}\!\mathrm{d}x
\]

Operators: 
\[
  \lim_{x \rightarrow \infty} f(x)
\]
\end{document}

結果2

[...]
(/usr/local/texlive/2017/texmf-dist/tex/latex/l3kernel/l3pdfmode.def
File: l3pdfmode.def 2017/03/18 v L3 Experimental driver: PDF mode
\l__driver_color_stack_int=\count162
\l__driver_tmp_box=\box41
))
(/usr/local/texlive/2017/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty
Package: l3keys2e 2017/12/16 LaTeX2e option processing using LaTeX3 keys
)
! LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.15 \ProcessKeysOptions
{testclass}
You're in trouble here. Try typing <return> to proceed.
If that doesn't work, type X <return> to quit.
Missing character: There is no , in font nullfont!
! You can't use `macro parameter character #' in horizontal mode.
\@removeelement #1#2#3->\def \reserved@a ##1,#1,##
2\reserved@a {##1,##2\rese...
l.15 \ProcessKeysOptions
{testclass}
Sorry, but I'm not programmed to handle this case;
I'll just pretend that you didn't ask for it.
If you're in the wrong mode, you might be able to
return to the right one by typing `I}' or `I$' or `I\par'.
Missing character: There is no 2 in font nullfont!
)
Runaway argument?
{##1,##2\reserved@b }\def \reserved@b ##1,\reserved@b ##2\reserved@b \ETC.
! File ended while scanning use of \reserved@a.
<inserted text>
\par
l.2 ^^M
I suspect you have forgotten a `}', causing me
to read past where you wanted me to stop.
I'll try to recover; but if the error is serious,
you'd better type `E' or `X' now and fix your file.
Overfull \hbox (20.0pt too wide) in paragraph at lines 15--2
[...]

関連情報