你能只加载一些包裹中的特定部件,没有加载其余的呢?例如,从下面的代码中,我只想加载\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}}
在我的.tex
文件中我想使用例如
\documentclass{article}
\usepackage['newcommands only']{file.sty}
或者类似的东西。
答案1
您必须添加包选项来通过选项决定应加载哪个部分。您可以在此处找到几乎所有 keyval 包的列表: 每个 keyval 包的大列表
例如kvoptions
:
\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
编辑:
关于注释,我给出了一个完整的最小示例。要测试不同的输入法,请使用注释中的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}