[pstricks] grid as background in an environment

Martin Buchmann Martin_Buchmann at gmx.net
Thu Oct 9 11:30:12 CEST 2003


Hi,

a friend of mine wants to have the possibility to typeset math 
examples on a grid. It should look like an exercise book for 
students. I thought the best would be to save the material in a box 
determine the size of the box and take this size as parameters of the 
psgrid command:

<--- martin's grid --->

\documentclass{article}

\usepackage{calc}
\usepackage{pstricks}

\newcommand\grid[2]{\psgrid%
[subgriddiv=2,gridcolor=yellow,%
subgridcolor=yellow,gridwidth=0.5pt,%
griddots=0,gridlabels=0pt]%
(0,#1)(#2,0)}

\newsavebox\gridbox
\newlength\gridhoehe
\newlength\gridbreite
\newlength\boxbreite

\newenvironment{dogrid}[1][\linewidth]
{%
  \setlength{\boxbreite}{#1}%
  \begin{lrbox}{\gridbox}\begin{minipage}{\boxbreite}%
  \setlength{\baselineskip}{0.5cm}%
}%
{%
  \end{minipage}\end{lrbox}%
  \setlength{\gridhoehe}{\ht\gridbox+\dp\gridbox}%
  \setlength{\gridbreite}{\wd\gridbox}%
  \noindent\usebox{\gridbox}%
  \raisebox{-\dp\gridbox}{\grid{\gridhoehe}{-\gridbreite}}%
}

\begin{document}

\begin{dogrid}
    Test Test Test Test Test Test Test Test Test Test Test Test
    Test Test Test Test Test Test Test Test Test Test Test Test
    Test Test Test Test Test Test Test Test Test Test Test Test
    Test Test Test Test Test Test Test Test Test Test Test Test
\end{dogrid}

\end{document}

<------->

That's working better than i expected at first but there is a small 
problem because \psgrid takes integer values as coordinates. How can 
i convert the size of my box into coordinates for psgrid so that the 
grid is never to small?

Thanks
   Martin

-- 
"Ich habe viel gesunden Menschenverstand,
aber manchmal find' ich es besser, ihn nicht zu benutzen"
                                    -- Calvin



More information about the PSTricks mailing list