# Extracting parts of a .sty file

Can you load only some specific parts from a package while not loading the rest at all? For example, from the code below I wanted to load only the \newcommands

%theorems
\usepackage{theorem}
\newtheorem{teo}{Teorema}[section]
\newtheorem{cor}[teo]{Corol\'ario}
\newtheorem{lem}[teo]{Lema}
\newtheorem{prop}[teo]{Proposi\c{c}\~ao}
%********************************************************************
%newcommands
\providecommand{\sin}{} \renewcommand{\sin}{\hspace{2pt}\textrm{sen}}
\providecommand{\tan}{} \renewcommand{\tan}{\hspace{2pt}\textrm{tg}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}

In my .tex file I would like to use for instance

\documentclass{article}
\usepackage['newcommands only']{file.sty}

or something similar to this.

-
The only way I can see this being done is you are able to provide a conditional to do this. This would require editing the .sty. Wouldn't it just be better to copy the contents you're after into a new myfile.sty and use \usepackage{myfile} instead? –  Werner Oct 1 '11 at 6:12
Is this a package you created or some other package? –  Martin Scharrer Oct 1 '11 at 10:01

You must add package options to decide via options which part should be loaded. A list of of nearly every keyval package can you find here: A big list of every keyval package

An example with kvoptions is:

\ProvidesPackage{file}

...

\RequirePackage{kvoptions}

\DeclareBoolOption{newcommand}
\DeclareBoolOption{theorem}

\ProcessKeyvalOptions*
....
\iffile@newcommand
\providecommand{\sin}{} \renewcommand{\sin}{\hspace{2pt}\textrm{sen}}
\providecommand{\tan}{} \renewcommand{\tan}{\hspace{2pt}\textrm{tg}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\fi
\iffile@theorem
%use theorem
\usepackage{theorem}
\newtheorem{teo}{Teorema}[section]
\newtheorem{cor}[teo]{Corol\'ario}
\newtheorem{lem}[teo]{Lema}
\newtheorem{prop}[teo]{Proposi\c{c}\~ao}
\fi
...
\endinput

EDIT:

In relation to the comments I present a whole minimal example. To test the different input methods use the commented usepackage.

\RequirePackage{filecontents}
\begin{filecontents}{mypackage.sty}
\ProvidesPackage{mypackage}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{%
family=MyPack,
prefix=MyPack@,%prefix of all command created by kvoptions
}

\DeclareBoolOption{newcommand}
\DeclareBoolOption{theorem}

\ProcessKeyvalOptions*
\ifMyPack@newcommand
\RequirePackage{amsfonts}
\providecommand{\sin}{} \renewcommand{\sin}{\hspace{2pt}\textrm{sen}}
\providecommand{\tan}{} \renewcommand{\tan}{\hspace{2pt}\textrm{tg}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\fi
\ifMyPack@theorem
%use theorem
\usepackage{theorem}
\newtheorem{teo}{Teorema}[section]
\newtheorem{cor}[teo]{Corol\'ario}
\newtheorem{lem}[teo]{Lema}
\newtheorem{prop}[teo]{Proposi\c{c}\~ao}
\fi
\endinput
\end{filecontents}
\documentclass{article}
\usepackage{mypackage}
%\usepackage[newcommand]{mypackage}
%\usepackage[newcommand=true]{mypackage}
\usepackage{blindtext}
\begin{document}
\ifdefined\Q
defined
\else
not defined
\fi
\end{document}
-
Marco, how to use? \usepackage[newcommand]{file}? –  Regis da Silva Oct 2 '11 at 19:31
Undefined control sequence \iffile@newcommand Extra \fi \fi \iffile@theorem Extra \fi \fi –  Regis da Silva Oct 2 '11 at 19:42
@RegisdaSilva: For a complete example see: tex.stackexchange.com/questions/30013/… –  Marco Daniel Oct 2 '11 at 19:48
I do not quite understand those codes, would you please be more clear? –  Regis da Silva Oct 2 '11 at 19:50