2

I need to make a package with options and need to load packages in some of these options. In the "Questions that may already have your answer" the topic of the link "Declare package options and loading packages leads to "options section" error "Should solve my problem, but unfortunately, it does not solve.

Here is a minimal example replicating the problem:

File 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

The compilation of

\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}

Returns

./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

If the code of the mat or image option is deleted from the suave.sty file the compilation is performed successfully.

I need a way to make this example work. For my actual needs, the suave.tex file needs many options.

1
  • Welcome! It would be better not to pass pdftex to graphicx. All it does is make your package less flexible. It ties you to a particular engine for no reason. graphicx can figure out you are using pdfTeX on its own.
    – cfr
    Commented Nov 13, 2016 at 3:36

1 Answer 1

7

You had two \ProcessOptions which can not work, you should only have one, and you had a missisng } from the final definition.

\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
4
  • Carlisle! Your answer completely solved my problem. Thank you very much. Commented Nov 13, 2016 at 4:46
  • You should have removed the pdftex option to graphicx
    – egreg
    Commented Nov 13, 2016 at 9:42
  • @egreg there's lots of changes I could make to the code bmmax being 0 looks odd as well but focus on the question.. Commented Nov 13, 2016 at 9:47
  • I am very grateful for the commentary on my problem. If you want to suggest improvements, I'm even more grateful. If it is not abuse on my part, I ask you to suggest me good readings. I removed all pdftex while loading my many packages. I also removed \newcommand\hmmax{0} \newcommand\bmmax{0} These were part of the solution to another problem. Thank you Commented Nov 13, 2016 at 20:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .