Rule in textarea every n points

I am currently developing a new layout. This must be typeset on a grid, and every line starts at a multiple of 13bp from the top of the text area. To help me check, I'd like to have rules every 13bp from the top of that area on every page without interfering with the typeset text. This is similar to my previous question A package to help with layout generation? Graph paper in the background? where I asked about a grid, but in difference to that question, the grid should start at the top (left) of the text area, not the page.

As far as I see the eso-pic solution is not possible here. What else can I do?

(I am using PDFTeX on Mac and Windows)

-
The grid package provides some support. –  Marc van Dongen Sep 4 '12 at 14:36
@MarcvanDongen I don't see how it can help me. Could you extend your comment? How can I use that to draw rules? –  topskip Sep 4 '12 at 14:39
Grundla The grid package provides support for a grid layout. See the reference below for more relevant information about how to avoid LaTeX's strech: –  Marc van Dongen Sep 4 '12 at 17:55
See the following reference for information on how to avoid LaTeX stretch: @Article{Bazargan:Radhakrishnan, title = {Removing vertical stretch\emdash mimicking traditional typesetting with {\TeX}}, author = {Bazargan, Kaveh and Radhakrishnan, C.{\thinspace}V.}, journal = {{TUGboat}}, year = {2007}, volume = {28}, number = {1}, pages = {\Range{133}{136}}, url = {http://www.tug.org/TUGboat/tb28-1/tb88bazargan.pdf}, } –  Marc van Dongen Sep 4 '12 at 18:02
@MarcvanDongen Thanks for the pointer. Interestingly the paper doesn't mention \pdfsavepos and such, which I am using now for getting grid typesetting. –  topskip Sep 8 '12 at 15:44

The following solution is independent from the output routine and uses a eso-pic like approach:

\documentclass[11pt]{article}
\usepackage{lipsum}
% \usepackage[showframe]{geometry}

\usepackage{atbegshi,picture}
\makeatletter
\AtBeginShipout{%
\AtBeginShipoutUpperLeft{%
\put(\dimexpr
\ifodd\value{page}\oddsidemargin\else\evensidemargin\fi + 1in\relax,
-\dimexpr\topmargin + 1in + \headheight + \headsep\relax){%
\begin{picture}(0,0)%
\setlength{\unitlength}{13bp}%
\setlength{\dimen0 }{0pt}%
\@whiledim\dimen0<\dimexpr\textheight+1sp\relax\do{%
\put(0,-\dimen0){\line(1,0){\textwidth}}%
}%
\end{picture}%
}%
}%
}
\makeatother

\makeatletter
\setlength{\topskip}{13bp}
\renewcommand\normalsize{%
\@setfontsize\normalsize\@xipt{13bp}%
% the following values are taken from size11.clo.
\abovedisplayskip 11\p@ \@plus3\p@ \@minus6\p@
\abovedisplayshortskip \z@ \@plus3\p@
\belowdisplayshortskip 6.5\p@ \@plus3.5\p@ \@minus3\p@
\belowdisplayskip \abovedisplayskip
\let\@listi\@listI
}
% \parskip without glue:
% \setlength{\parskip}{0pt}
% or with positive \parskip:
\usepackage{parskip}
\setlength{\parskip}{13bp}
\makeatother

\begin{document}
\lipsum[1-3]
\end{document}


-
Thanks once again! I think I will make a separate package from that. Great solution! –  topskip Sep 4 '12 at 15:33

That are simple lines, can also be done with \rule, package pict2e or something similiar.

\documentclass{article}
\usepackage{pstricks,multido}

\begin{document}
\setlength\baselineskip{13bp}\noindent%
\multido{\iA=0+13}{45}{\psline[linecolor=gray](0,-\iA bp)(\linewidth,-\iA bp)}%
%
foo\\
bar\\
baz\\
foobar\\
foobarbaz

\end{document}


and the same with \rule

\documentclass{article}
\usepackage{multido}
\begin{document}
\makeatletter%
\newdimen\tempL%
\setlength\baselineskip{13bp}\noindent%
\makebox(0,0)[t]{\multido{\iA=0+13}{40}{%
\put(0,-\strip@pt\tempL){\rule{\linewidth}{0.5pt}}%
\makeatother%
%
foo\\
bar\\
baz\\
foobar\\
foobarbaz

\end{document}

-
It would be great to extend the solution so that every page will have the grid in the background. Feature request :-) –  topskip Sep 4 '12 at 15:24

Something like this (I also changed baselineskip and parskip to the grid)

\documentclass{article}

\makeatletter
\renewcommand\normalsize{%
\@setfontsize\normalsize\@xpt{13bp}
\abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@
\abovedisplayshortskip \z@ \@plus3\p@
\belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
\belowdisplayskip \abovedisplayskip
\let\@listi\@listI}
\normalsize
\setlength\parskip{13bp}

\setlength\unitlength{13bp}
\raisebox{-\topskip}{\begin{picture}(0,0)%
\multiput(0,0)(0,-1){40}{\line(1,0){30}}%
\end{picture}}\hfill}
\makeatother

\def\a{One two three four five. }
\def\b{\a\a Red green blue. \a\a}
\def\c{\b\b Black white. \b\a\b}

\begin{document}

\c

\c

\c

\end{document}

-