![使用 \DeclareOptions 声明多个加载包的包选项时出现问题](https://linux22.com/image/344213/%E4%BD%BF%E7%94%A8%20%5CDeclareOptions%20%E5%A3%B0%E6%98%8E%E5%A4%9A%E4%B8%AA%E5%8A%A0%E8%BD%BD%E5%8C%85%E7%9A%84%E5%8C%85%E9%80%89%E9%A1%B9%E6%97%B6%E5%87%BA%E7%8E%B0%E9%97%AE%E9%A2%98.png)
我需要制作一个带有选项的包,并且需要加载其中一些选项中的包。在“可能已经有答案的问题”链接的主题中“声明包选项并加载包导致“选项部分”错误“应该可以解决我的问题,但不幸的是,它并没有解决。
这是一个复制该问题的最小示例:
文件 suave.sty
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{suave}[2016/11/11 v1. Pacote de facilidades]
\newif\if@loadgraphicx
\DeclareOption{imagem}{\@loadgraphicxtrue}\ProcessOptions
\if@loadgraphicx
\RequirePackage[pdftex]{graphicx}%
\newcommand{\imagem}[2][]{\includegraphics[#1]{#2}}%
\newcommand{\imagens}[2][]{\includegraphics[#1]{./Imagens/#2}}%
\fi
\newif\if@loadmate
\DeclareOption{mat}{\@loadmatetrue}\ProcessOptions
\if@loadmate
\RequirePackage{amsmath} \RequirePackage{wasysym}
\RequirePackage{amsfonts} \RequirePackage{amssymb}
\newcommand\hmmax{0} % default 3
\newcommand\bmmax{0} % default 4
\RequirePackage[amsmath]{ntheorem}
\theoremheaderfont{\normalfont\bfseries\sffamily}
\theorembodyfont{\itshape} \theoremindent 0cm
\theoremseparator{:}
\newtheorem{teorema}{Teorema}[chapter]
\newtheorem{defi}{Definição}[chapter]
\theoremstyle{plain}
\newcommand{\rn}[1][n]{\ensuremath{\mathbb{R}^{#1}}}
\newcommand{\Z}{\ensuremath{\mathbb{Z}}}
\newcommand{\anel}[1]{\ensuremath{(#1,+,\cdot)}
\fi
\endinput
汇编
\documentclass[a4paper,10pt]{report}
\usepackage[mat,imagem]{suave}
\begin{document}
Você não gosta de mim, mas sua filha gosta.
\[
\varphi: \mathcal{A}/Ker(f) \longrightarrow \mathcal{B}.
\]
\end{document}
返回
./suave.sty:6:Unknown option 'mat' for package 'suave'. \if@loadgraphicx
./suave.sty:14:Unknown option 'imagem' for package 'suave'. \if@loadmate
./Teste.tex:3:File ended while scanning use of \@argdef
如果从 suave.sty 文件中删除 mat 或 image 选项的代码,则编译成功完成。
我需要一种方法来使这个示例工作。对于我的实际需要,suave.tex 文件需要很多选项。
答案1
你有两个\ProcessOptions
无法工作的功能,你应该只有一个,而且你}
在最终定义中缺少一个。
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{suave}[2016/11/11 v1. Pacote de facilidades]
\newif\if@loadgraphicx
\DeclareOption{imagem}{\@loadgraphicxtrue}
\newif\if@loadmate
\DeclareOption{mat}{\@loadmatetrue}
\ProcessOptions\relax
\if@loadgraphicx
\RequirePackage[pdftex]{graphicx}%
\newcommand{\imagem}[2][]{\includegraphics[#1]{#2}}%
\newcommand{\imagens}[2][]{\includegraphics[#1]{./Imagens/#2}}%
\fi
\if@loadmate
\RequirePackage{amsmath} \RequirePackage{wasysym}
\RequirePackage{amsfonts} \RequirePackage{amssymb}
\newcommand\hmmax{0} % default 3
\newcommand\bmmax{0} % default 4
\RequirePackage[amsmath]{ntheorem}
\theoremheaderfont{\normalfont\bfseries\sffamily}
\theorembodyfont{\itshape} \theoremindent 0cm
\theoremseparator{:}
\newtheorem{teorema}{Teorema}[chapter]
\newtheorem{defi}{Definição}[chapter]
\theoremstyle{plain}
\newcommand{\rn}[1][n]{\ensuremath{\mathbb{R}^{#1}}}
\newcommand{\Z}{\ensuremath{\mathbb{Z}}}
\newcommand{\anel}[1]{\ensuremath{(#1,+,\cdot)}}%
\fi
\endinput