## LaTeX forum ⇒ Others ⇒ Handling of passed Option in a custom Package Topic is solved

Information and discussion about other tools not listed above.
mas
Posts: 206
Joined: Thu Dec 04, 2008 4:39 am

### Handling of passed Option in a custom Package

I have a collection of commands in a sty file, say myown.sty, which I call from my document. What I want to do is use the following construct:
\documentclass{article}\usepackage[color]{myown} \begin{document}   some text \ldots\end{document}

In the "myown" package, I would like to take different actions based on the parameter "color" like

Many pages on the net talk about handling options to a class file. I need a simpler way of just looking at the option and take appropriate action. I would like some pointers to achieve this.

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim

Johannes_B
Site Moderator
Posts: 3639
Joined: Thu Nov 01, 2012 4:08 pm
Hi,

you could have a look at »LaTeX2e for Class and Package writers«. The LaTeX Companion is also very good to learn how to write classes and packages.

Give it a try.

Regards
Johannes_B
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

mas
Posts: 206
Joined: Thu Dec 04, 2008 4:39 am
Johannes_B wrote:you could have a look at »LaTeX2e for Class and Package writers«.

Thanks, I already had given that a look, but found some difficulty in getting what I wanted. I have now some MWE which gives me the error. It might be due to my improper understanding of the option processing in a style/package file.

The main file:
\documentclass[svgnames,x11names]{article}   \usepackage[color]{myown} \begin{document}  Hello. \end{document}

The package file:

When I tried this with
pdflatex test.tex...(/home/software/texlive/2012/texmf-dist/tex/latex/hyperref/hpdftex.def(/home/software/texlive/2012/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty)) ! Undefined control sequence.\GenericError  ...                                                                                     #4  \errhelp \@err@     ...l.27  ? xNo pages of output.

Hope to get some pointers to understand the options better.

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim

cgnieder
Site Moderator
Posts: 1985
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
You're simply missing the option name for your second option. I guess it should read:


Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

mas
Posts: 206
Joined: Thu Dec 04, 2008 4:39 am
cgnieder wrote:You're simply missing the option name for your second option. I guess it should read:


Tried that and got the same error. My understanding of the DeclareOption* was that it would be, sort of, default behaviour if nothing is mentioned on \usepackage line.

I even included
\ExecuteOptions{color,mono}

\errorcontextlines=999

gives the following output

Regards.

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim

cgnieder
Site Moderator
Posts: 1985
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
mas wrote:Tried that and got the same error.

Then you used a different sty file than the one you posted because it works there (I tried it before I answered).
\usepackage[color,mono]{myown}
can't work, though, as both options define the same commands with \newcommand so you'd get
! LaTeX Error: Command \CHPCOL already defined.

Maybe you can elaborate a bit on what it is you're trying to achieve?

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

mas
Posts: 206
Joined: Thu Dec 04, 2008 4:39 am
cgnieder wrote:Then you used a different sty file than the one you posted because it works there (I tried it before I answered).

It was the same thing except for the addition of \errorcontextlines=999 which I had included to get a detailed error message.

I removed that and it is working now.
Maybe you can elaborate a bit on what it is you're trying to achieve?

I thought it was a bit obvious I wanted the chapter titles and the running titles in color for the screen version and in black for the print version.

Thanks for the help.

Regards.

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim