a user-defined class:
\ProvidesClass{preview}[2012/12/15 v 0.01 class for creating a tight PSTricks diagram]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass[]{article}
\RequirePackage{pstricks}
\RequirePackage[tightpage,active]{preview}
\PreviewEnvironment{pspicture}
\endinput
consumer's input file:
\documentclass[PreviewBorder=12pt]{preview}% the option will set \PreviewBorder=12pt.
\begin{document}
\begin{pspicture}[showgrid=true](-2,-2)(2,2)
\end{pspicture}
\end{document}
How to write a class that accepts an optional key-value pair to set PreviewBorder as shown in the code snippet?
Note: Its default value of the key is 0pt.
The reason I don't accept the existing answer:
Because the default value does not work as expected. Please make a try the following code and see there is still a thin white padding (CSS terminology) around the red rectangle.
\begin{filecontents}{preview.cls}
\ProvidesClass{preview}[2012/12/15 v 0.01 class for creating a tight PSTricks
diagram]
\RequirePackage{scrbase}
\DefineFamily{preview}
\DefineFamilyMember{preview}
\DefineFamilyKey{preview}{PreviewBorder}[0pt]{%
\if@atdocument% before or after \begin{document}?
\expandafter\@firstofone% after \begin{document} do it just now
\else
\expandafter\AtEndOfClass% \PreviewBorder first defined after loading
% preview package!
\fi{\setlength{\PreviewBorder}{#1}}%
}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\FamilyProcessOptions{preview}
\LoadClass{article}
\RequirePackage{pstricks}
\RequirePackage[tightpage,active]{preview}
\PreviewEnvironment{pspicture}
\endinput
\end{filecontents}
%\documentclass{preview}%default value 0pt does not work!
\documentclass[PreviewBorder=0pt]{preview}% works as expected.
\begin{document}
\begin{pspicture}(-2,-2)(2,2)
\psframe[linecolor=red](-2,-2)(2,2)
\end{pspicture}
\end{document}
In other words, I want both
\documentclass{preview}
and
\documentclass[PreviewBorder=0pt]{preview}
to produce the same result without border.
border=<value>option. Also your consumer file looks a lot like a usecase of thestandaloneclass.\documentclass[border=12pt,preview,multi=pspicture]{standalone}will do most of what you have above. (Themultioption will be ignored by v0.x, which is currently the official release. Please find v1.0beta at https://bitbucket.org/martin_scharrer/standalone/downloads. – Martin Scharrer Dec 15 '11 at 10:42