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}
Ryan
  • 2,914
  • 5
    See Loading a package conditionally, which states the use of an \if...\fi condition. – Werner Jan 13 '15 at 02:46
  • Use the [pass] option to geometry (http://tex.stackexchange.com/questions/179116/what-is-the-equivalent-of-fullpage-in-geometry-package/179122#179122). It loads the package without changing the existing parameters of the page. – Steven B. Segletes Jan 13 '15 at 02:48
  • Don't use \sf. It was deprecated 20+ years ago. Use \sffamily or \textsf{}. – cfr Jan 13 '15 at 02: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 02: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 03:00
  • @StevenB.Segletes Thanks, that doesn't feel like a full solution but it works for this. – Ryan Jan 13 '15 at 03:01
  • @Ryan As seen in the cited example, you can invoke it with [pass] to stake out access to the package macros without changing the geometry. Then, and only if needed, you can issue a \newgeometry to change the page parameters. You can even save the old parameters before using a \newgeometry so that you can later return to the original settings. – Steven B. Segletes Jan 13 '15 at 03:05
  • @Ryan The answer Werner linked to shows you how to process it as part of the option definition i.e. by manipulating \if switches. You can combine that with the pass option of new geometry so that the margins are only altered \ifsomeoptionispassed. – cfr Jan 13 '15 at 04:28
  • Are there any news here? Did the linked question already answer your question )making this here a duplictae) or do you need further help? If so, please add a bit more information to the question on where you are stuck. – Johannes_B Feb 12 '15 at 21:01
  • One of the links worked, yes, maybe this title should be changed to "how to load packages conditionally within a package" or something and then marked as duplicate to help other people search for this problem. I'm not sure what to change the title to, as I had trouble searching for the answer myself. – Ryan Feb 12 '15 at 21:07

0 Answers0