Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My custom class

The purpose of this class is to create a single PSTricks diagram in a tight paper size.

\ProvidesClass{pst-xport}[2011/07/23 v 0.01 class for creating a single PStricks diagram]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass[]{article}
\RequirePackage{pstricks}


\newcommand\LL{-1}
\newcommand\RR{1}
\newcommand\BB{-1}
\newcommand\TT{1}

\newlength\LPad\setlength{\LPad}{1cm}
\newlength\RPad\setlength{\RPad}{1cm}
\newlength\BPad\setlength{\BPad}{1cm}
\newlength\TPad\setlength{\TPad}{1cm}


\topmargin=\dimexpr\TPad-72.27pt\relax
\oddsidemargin=\dimexpr\LPad-72.27pt\relax
\paperwidth=\dimexpr\RR\psxunit-\LL\psxunit+\RPad+\LPad\relax
\paperheight=\dimexpr\TT\psyunit-\BB\psyunit+\TPad+\BPad\relax
\special{papersize=\the\paperwidth,\the\paperheight}


\headheight=0pt
\headsep=0pt
\parindent=0pt
\pagestyle{empty}

%%%%%%%%%%%%%%%%%%%
%%%% INTERFACE %%%%
%%%%%%%%%%%%%%%%%%%

\newcommand\SetCanvas[4]
{
    \renewcommand\LL{#1}
    \renewcommand\BB{#2}
    \renewcommand\RR{#3}    
    \renewcommand\TT{#4}
}

\newcommand\SetCan[1]
{
    \SetCanvas{-#1}{-#1}{#1}{#1}
}

\newcommand\SetPadding[4]
{
    \setlength{\LPad}{#1}
    \setlength{\BPad}{#2}
    \setlength{\RPad}{#3}
    \setlength{\TPad}{#4}
}

\newcommand\SetPad[1]
{
    \SetPadding{#1}{#1}{#1}{#1}
}

\endinput 

Consumer

The consumer uses pst-xport class as follows.

\documentclass{pst-xport}

%\SetCanvas{-2}{-2}{2}{2}
\SetCan{2}

%\SetPadding{1cm}{1cm}{1cm}{1cm}
\SetPad{1cm}

\psset
{
    xunit=1cm,
    yunit=2cm
}

\begin{document}
\begin{pspicture}[showgrid=true](\LL,\BB)(\RR,\TT)
\psframe[linecolor=red](\LL,\BB)(\RR,\TT)
\end{pspicture}
\end{document}

Problem

However, the consumer settings cannot affect because they come last. How to configure a custom class such that consumer settings must be loaded before the class settings?

Bonus question: How to translate those settings to key-value settings that are more sophisticated?

share|improve this question
    
You seem to forget about \AtBeginDocument –  egreg Jul 22 '11 at 18:51
add comment

1 Answer

up vote 1 down vote accepted

You could calculate your settings at the end of the preamble so that the user changes take effect.

\AtBeginDocument{%
\topmargin=\dimexpr\TPad-72.27pt\relax
\oddsidemargin=\dimexpr\LPad-72.27pt\relax
\paperwidth=\dimexpr\RR\psxunit-\LL\psxunit+\RPad+\LPad\relax
\paperheight=\dimexpr\TT\psyunit-\BB\psyunit+\TPad+\BPad\relax
\special{papersize=\the\paperwidth,\the\paperheight}
}

Or provide some \updatesettings macro which does all adjustsments.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.