1

I'm trying to design a package so that I can 'theme' a document quickly. I've done this, but as a sort of academic exercise I'm trying to design an option compact that adjusts margins, title, and layout to optimize the document for use of multicols.

The issue here is I want to use geometry to define the margins, but do not want to load thegeometry package otherwise. I have a little bit of a workaround by using \PassOptionsToPackage, but then the package is loaded even when the option is not selected and it changes LaTeX's default margins which I don't want to change in this default mode. Ideally, the textpos and multicol packages wouldn't be loaded unless the option is selected either, because they are otherwise unnecessary.

What is the most correct way of accomplishing this?


The custom package:

\NeedsTeXFormat{LaTeX2e}[1994/06/01]

\RequirePackage{graphics}
\RequirePackage{tikz}
\RequirePackage{libertine}

\pagestyle{empty}
\setlength{\parskip}{6pt plus 2pt minus 2pt}

\newcommand{\fullline}{%
    \noindent\rule{\linewidth}{.4pt}\\
    \vspace{-\baselineskip}\\
}

\newcommand{\stretchtitle}[1]{
    \vspace*{-5\baselineskip}\noindent\hspace*{-.75in}
    \resizebox{\dimexpr1.25in+\linewidth}{!}{\textsc{#1}}
    \vspace{\baselineskip}\\
}

\newcommand{\header}[1]{%
    \noindent{\sf\huge\\\\\noindent%
    \begin{tikzpicture}[remember picture, overlay]%
        \draw[right] (-.4em,.5em) node {#1};%
        \draw[line width=1pt] (-.4em,-2em) -- (-.4em,0em) -- (\dimexpr.4em+\linewidth, 0);%
    \end{tikzpicture}}\vspace{-1.25\baselineskip}\\\par\noindent%
}

\newcommand{\leveltwo}[1]{%
    \vspace{\baselineskip}\noindent{\Large\sf#1\normalsize\\\rule{.5\linewidth}{1pt}}
}

\RequirePackage[absolute]{textpos}
\RequirePackage{multicol}

\DeclareOption{compact}{
    \PassOptionsToPackage{margin=.62in}{geometry}
    \setlength{\columnsep}{18pt}
    \setlength{\TPHorizModule}{\paperwidth}
    \setlength{\TPVertModule}{\paperheight}
    \renewcommand{\stretchtitle}[1]{
        \newcommand{\titlewidth}{3.37in}
        \begin{textblock}{.88235294}(0.058823,0.045454545)
            \noindent
            \resizebox{\titlewidth}{!}{\Huge{\textsc{#1}}}\\
            \rule{\textwidth}{1pt}
            \normalsize
        \end{textblock} 
        \vspace*{.5in}
    }
}
\ProcessOptions\relax

\RequirePackage{geometry}

MWE for custom package use:

\documentclass[letterpaper]{article}
\usepackage{heavymodern}
\usepackage{lipsum}

\begin{document}
    \stretchtitle{Minimum Working Example}

    \header{Example}%
    \lipsum[1]

    \leveltwo{Second-Level Example}

    \lipsum[2]
\end{document}
  • 5
    See Loading a package conditionally, which states the use of an \if...\fi condition. – Werner Jan 13 '15 at 2:46
  • Use the [pass] option to geometry (tex.stackexchange.com/questions/179116/…). It loads the package without changing the existing parameters of the page. – Steven B. Segletes Jan 13 '15 at 2:48
  • Don't use \sf. It was deprecated 20+ years ago. Use \sffamily or \textsf{}. – cfr Jan 13 '15 at 2:50
  • @cfr oops... it's faster to type so I get lazy when I know I'm just going to be using article... but that's embarrassing... – Ryan Jan 13 '15 at 2:57
  • @Werner Thank you, that's a helpful answer, but in my case I want to manipulate the packages within the option definition, so I don't know how to make the program flow so that it will work. I'll read more on \if switches though. – Ryan Jan 13 '15 at 3:00