This is somehow related to this Load a package as optional argument:
I'm trying to load geometry package as optional, meaning: if is defined in preamble should be load with my margins, if not document will have the default geometry of article, book, report etc.
I have to mention that I'm not a programmer at all, but in my mind what I have wrote in MWE makes sens :). Basicaly I'm trying to find a formula (for my Humanistic mind) -- i.e. in simple steps, to load some packages with my specifications when I need them.
I would also appreciate some %%% comments %%% on the code, because I want to understand and to reproduce on other packages that I want to load.
With my code, margins are changing, but not with my specs...
The MWE
% !TEX program = pdflatex
% !TeX encoding = UTF-8
\documentclass{article}
\usepackage{kantlipsum}
\usepackage{testpckg}
%\usepackage{geometry}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{filecontents}[force]{testpckg.sty}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{testpckg}[2021/02/26 Test package]
\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}
%\RequirePackage{xstring}
%\RequirePackage{geometry}
% -- if specified in preamble load with this specs
\newif\iftestpckg@geometry
\DeclareOption{geometry}{%
\testpckg@geometrytrue
\geometry{top=.5cm,bottom=.5cm,right=.5cm,left=.5cm} % <-- just for better visualization
}
\ProcessOptions
\iftestpckg@geometry
\RequirePackage{geometry} % <-- else load default geometry from article, book, report...
\fi
\end{filecontents}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\kant
\end{document}


geometrythemselves and choose their own parameters. – egreg Feb 26 '21 at 10:59