I would like to create and option (namely grid
) to my sty
file to produce a grid covering the whole page.
I had success using
\newif\if@sigur@grid
\DeclareOption{grid}{\@sigur@gridtrue}
and using the code below, which I copied from somewhere here on SE, inside some blocks of codes.
\if@sigur@grid
\IfFileExists{tikz.sty}
{\RequirePackage{tikz}%
\usetikzlibrary{shapes.misc}%
\usepackage{eso-pic}%
}
{\PackageWarning{sigur}{You requested `tikz.sty' %MessageBreak
which doesn't exist on your system}
}
\AtBeginDocument{
\AddToShipoutPicture{%
\begin{tikzpicture}[overlay,remember picture]
\draw[red!30!white]
(current page.south west) grid[step=1mm]
(current page.north east);
\draw[red!80!white]
(current page.south west) grid[step=10mm]
(current page.north east);
\end{tikzpicture}
}
}
\fi
Well, this is fine and it is working. I simply load my sty
file with the option grid
and the red grid appears.
Now here comes my problem. As you can see the grid was drawn in red color. I'd like to be able to pass its color to the grid
option when loading it. For example, the default color is red but if I want blue grid I'd simply use grid=blue
as option and the grid would appear in blue color.
How to do this?
ps: I'd like to test first if some additional package is installed. I'm doing this for other packages using \IfFileExists{}
and it is working. But I'm not able to do this for the solution proposed by @cgnieder below.
The reason for the test is that sometimes I share this style file with other users and I'd like to inform them with some option is not working instead of just show many errors caused by the missing packages.
Best Answer
The
pgfopts
is a convenient way of usingpgf
's keys as package options. Here's an example wheredoes not draw a grid,
draws the default red grid, and
draws a green grid.