Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
4  
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
add comment

1 Answer

up vote 5 down vote accepted

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}
share|improve this answer
    
Marco, how to use? \usepackage[newcommand]{file}? –  Regis da Silva Oct 2 '11 at 19:31
    
@RegisdaSilva: \usepackage[newcommand]{file} or \usepackage[newcommand=true]{file} –  Marco Daniel Oct 2 '11 at 19:33
    
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
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.