0

I am in a habit of defining a standard collection of CTAN packages in an .sty file and call that file in all documents with a \usepackage{MyUseCTANPackages} statement in the preamble of a document. On occasion, rather than voiding MyUseCTANPackages.sty, I would like to override a package defined there, in this instance the geometry package to define different margins, which however leads to ! LaTeX Error: Option clash for package geometry. Is there a way to override what was said in the package definitions in MyUseCTANPackages.sty for geometry, and similarly also for other packages?

MyUseCTANPackages.sty contains, amongst a large collection of other packages,

...
\usepackage[a4paper, vmargin=2.0cm, outer=1.5cm, inner=1.5cm,marginparwidth=2.0cm, marginparsep=0.5cm]{geometry}
...
\documentclass{article}
% RN. 20 May 2023
% BRIEF DESCRIPTION:
%   overriding package definitions in package geometry.

%=======================
\usepackage{MyUseCTANPackages}
% attempting to override the definition contained in MyUseCTANPackages.sty:
%\usepackage[a4paper, vmargin=2.0cm, outer=0.5cm, inner=1.5cm]{geometry}

\begin{document}

sdf asgadf gadf g DGRFe rg ERG edg RSG drg G edgRGedtg G gE TG etrgERGetr gERGer g ERGe rgERG erg ERG erg RG g G rg ERG  rg RG reg RG 

\end{document}
3
  • 1
    not unless you write your MyUseCTANPackages package to only load geometry if not already loaded, then load geometry first when needed, but loading a large collection of packages not used in the document is an anti-pattern May 20, 2023 at 9:57
  • 1
    you could simply use \geometry{a4paper, vmargin=2.0cm, outer=0.5cm, inner=1.5cm} to overwrite the settings. May 20, 2023 at 9:58
  • @david carlisle point taken May 21, 2023 at 2:41

1 Answer 1

1

You can load geometry this way inside your MyUseCTANPackages

\ifdefined\MyGeometryOptions
\expandafter\usepackage\MyGeometryOptions{geometry}
\else
\usepackage[a4paper, vmargin=2.0cm, outer=1.5cm, inner=1.5cm,marginparwidth=2.0cm, marginparsep=0.5cm]{geometry}
\fi

and then do

\def\MyGeometryOptions{[a4paper, vmargin=2.0cm, outer=0.5cm, inner=1.5cm]}
\usepackage{MyUseCTANPackages}

if desired.

The rationale here is in case the order of loading with respect to other packages matters (which probably it doesn't much, but with hyperref for example in place of geometry it would often).

1
  • This works! But David Carlisle's comment "loading a large collection of packages not used in the document is an anti-pattern" makes me think that my idea of MyUseCTANPackages was not such a good idea after all. It did take a long period of trial and error to get the packages into an order that made the whole thing work. May 21, 2023 at 2:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .