# How to NOT include a package in a TeX file?

I have a personalized style file (say main.sty) which I use for all my writings. In some writings however, there is a package in main.sty that I would not like included. As a concrete example, in main.sty I am calling the package eucal. However, for whatever reason, I do not want to include it in the particular .tex file that I am current working in. Is there a command to "remove" that package. What I am looking for is a code like

\documentclass[12pt]{article}
\usepackage{main}
\donotusepackage{eucal}

\begin{document}
blah
\end{document}


What should replace \donotusepackage{eucal}?

PS - Having thought of this, I think one solution would be to have the inclusion/non-inclusion of the package eucal as an option in main.sty. Then, we can have something like \usepackage[noeucal]{main}. Is this the only solution?

• Your solution is what I would use. It's not difficult. I'm not aware of anything that can systematically remove a package once loaded. – Paul Stanley Apr 4 '18 at 14:49
• You can also take it a step further, with your [noeucal] option: AtBeginDocument you can check to see if the package was loaded, then throw an error. That would prevent you from manually requesting the package in preamble. – user139954 Apr 4 '18 at 14:55
• – user36296 Apr 4 '18 at 15:26
• One KOMA script package provides preventpackage from loading. – Johannes_B Apr 4 '18 at 15:38

You can add this in your main.sty

\newif\ifMyEucal

\DeclareOption{Eucal}{\MyEucaltrue}
\DeclareOption{noEucal}{\MyEucalfalse}

\ExecuteOptions{Eucal}

\ProcessOptions\relax

\ifMyEucal
\RequirePackage{eucal}
\fi


That will provide two options to main package : Eucal (default) load eucal.sty and noEucal that doesn't.

\documentclass{article}
\usepackage[noEucal]{main}

\begin{document}
essia
\end{document}

• This works perfectly and does what I need. Thanks! – Prahar Apr 4 '18 at 17:01