% VERTICAL RULERS for LaTeX      
%    Written by Zhuhan JIANG: zhuhan@neumann.une.edu.au
%    University of New England, Australia NSW 2351.                    
%
% 
% Filename: VRULER.STY
% Version:  1.0 July 1993                   
%
% 
% PURPOSE:
%    1. Make a vertical ruler numbers consecutively so that any part
%       of an article can be pinpointed immediately. Move vruler 
%       freely.
%    2. Make raw text print-out
% 
% To use:
%    Load in this macro before \begin{document} environment
%
%
% 1. VRULER COMMAND:
%    \setvruler[<SCALE>][<INITIAL_COUNT>][<STEP>][<MODE>][<HSHIFT]>][<VSHIFT>]
%        <general LaTeX material-01>
%    \unsetvruler  % optional
%        <general LaTeX material-02> 
%
%    <SCALE> distance between two vruler markings
%    <INITIAL_COUNT> first marking reading
%    <STEP> is the line counte increment
%    <MODE> =0 if each page has same vruler marking, =1 if otherwise
%    <HSHIFT>  horizontal shift from the default value for the vruler
%    <VSHIFT>  vertical shift from default value for vruler
%
%
%  
%    \setvruler will enable the ruler markings from the current page
%    \unsetvruler will disable it from the current page
%    The both are used in a same pages, the later-appeared one
%    takes the priority.
%   
%    The general text stays where it is, change #5 and #6 to move to vruler
%    to the position that is wanted.
%
% Example:
%    \documentstyle{article}
%    \input <this macro>
%    \textwidth=5.5in
%    \begin{document}
%      \setvruler[20pt][1000][20][0][0pt][0pt]
%          % i.e. print a line number every 20pt, starting from 1000
%          % sequentially with increment 20
%        <your latest achievement here in LaTeX>
%      \eject  % you may not want to \eject at all, just remove it then.
%      \unsetvruler
%         <something you don't want to be lined on the margin>
%      \eject
%      \setvruler[30pt][\rulercount][20][0][6.5in][10pt]
%          % ( 6.5in is approximately \textwidth+1in)
%          % print line number every 30pt on the RIGHT hand side, 
%          % starting from where it was left,
%          % sequentially only for a single page, all following papers
%          % will have same vruler markings (until e.g. \unsetvruler)
%          % Vruler will now be 10pt below its default position 
%        <futher text to be lined starting from where it was left>
%          
%    \end{document}
%
%
%
%   2. RAW DATA TEXT:
%      \setraw[<CHARACTER>]
%        <general text to be processed line by line>
%        % everything apart from <CHARACTER> will be regarded as
%        % the normal letters to be printed out
%      <CHARACTER>unsetraw
%
%   Note: <CHARACTER> is any (but not '\') that is not contained 
%         in the text to be processed line by line     
%
%    e.g.   \setraw[*]  bla bla bla *unset
%
%
%   WARNING:
%         If you are already using other macros which TAKE OVER the
%         control of \outpout routine, then you will have problem using
%         them and this macro together.
%
%   TRICKS:
%         Given a chosen \baselineskip etc as format for article 
%         which contains mostly text, one may fine tune via
%          #3=<STEP> and #6=<VSHIFT> to synchronise the marking 
%         of the vruler with the lines
%
%   
%   PRINTOUT AND DEMONSTRATION:
%         See at the end of file (Guess why I have to put it at the end?)
%  
%
%
%   MAIN MACRO STARTS:
%
\newdimen\boxheight\newdimen\lineheight
\newbox\outputbox\newbox\buffbox\newbox\tempboxnum
\newcount\refno\newcount\total\newcount\rulercount
%
%
\def\makevrule[#1][#2][#3]{\begingroup\offinterlineskip
\vbadness=10000\vfuzz=120ex\overfullrule=0pt%
\global\setbox\buffbox=\vbox to \textheight{%
{\parskip=0pt\hfuzz=150em\boxheight=\textheight
\lineheight=#1\global\rulercount=#2%
\total\boxheight\divide\total\lineheight\advance\total2%
\refno1\vskip-\lineheight\vskip1ex%
\loop\setbox\tempboxnum=\hbox to0cm{{\tiny\hfil\the\rulercount}}%
\ht\tempboxnum\lineheight\dp\tempboxnum0pt\box\tempboxnum\break
\advance\refno1\global\advance\rulercount#3\relax
\ifnum\refno<\total\repeat}}%
\endgroup}%
%
%
%\catcode`\@=11%
%
\gdef\unsetvruler{\global
\output{\ifnum\outputpenalty <-\@M\@specialoutput\else
  \@makecol\@opcol\@floatplacement\@startcolumn
  \@whilesw\if@fcolmade \fi{\@opcol\@startcolumn}\fi
  \global\vsize\ifnum\outputpenalty >-\@Miv \@colroom
                  \else \maxdimen\fi}
%
%
\global\def\@outputpage{\begingroup\catcode`\ =10
     \let\-\@dischyph \let\'\@acci \let\`\@accii \let\=\@acciii
    \if@specialpage
     \global\@specialpagefalse\@nameuse{ps@\@specialstyle}\fi
     \if@twoside
       \ifodd\count\z@ \let\@thehead\@oddhead \let\@thefoot\@oddfoot
            \let\@themargin\oddsidemargin
          \else \let\@thehead\@evenhead
          \let\@thefoot\@evenfoot \let\@themargin\evensidemargin
     \fi\fi
     \shipout
     \vbox{\normalsize \baselineskip\z@ \lineskip\z@
           \let\par\@@par %% 15 Sep 87
           \vskip \topmargin \moveright\@themargin
           \vbox{\setbox\@tempboxa
                   \vbox to\headheight{\vfil \hbox to\textwidth
                                       {\let\label\@gobble \let\index\@gobble
                                         \@thehead}} %% 22 Feb 87
                 \dp\@tempboxa\z@
                 \box\@tempboxa
                 \vskip \headsep
                 \box\@outputbox
                 \baselineskip\footskip
                 \hbox to\textwidth{\let\label\@gobble
                           \let\index\@gobble  %% 22 Feb 87
                           \@thefoot}}}\global\@colht\textheight
           \endgroup\stepcounter{page}\let\firstmark\botmark}}
% end of \unsetruler
%
%
\def\setvruler[#1][#2][#3][#4][#5][#6]{\global\rulercount=#2%
\global\output{\begingroup\hbadness=10000\hfuzz=150em%
\ifnum#4=0\makevrule[#1][#2][#3]\else
\makevrule[#1][\rulercount][#3]\fi
\ifnum\outputpenalty <-\@M\@specialoutput\else
  \@makecol\@opcol\@floatplacement\@startcolumn
  \@whilesw\if@fcolmade \fi{\@opcol\@startcolumn}\fi
  \global\vsize\ifnum\outputpenalty >-\@Miv \@colroom
                  \else \maxdimen\fi
\endgroup}%
%
\global\def\@outputpage{\begingroup\catcode`\ =10
     \let\-\@dischyph \let\'\@acci \let\`\@accii \let\=\@acciii
    \if@specialpage
     \global\@specialpagefalse\@nameuse{ps@\@specialstyle}\fi
     \if@twoside
       \ifodd\count\z@ \let\@thehead\@oddhead \let\@thefoot\@oddfoot
            \let\@themargin\oddsidemargin
          \else \let\@thehead\@evenhead
          \let\@thefoot\@evenfoot \let\@themargin\evensidemargin
     \fi\fi
     \setbox\tempboxnum%
     \vbox{\normalsize \baselineskip\z@ \lineskip\z@
           \let\par\@@par %% 15 Sep 87
           \vskip \topmargin \moveright\@themargin
           \vbox{\setbox\@tempboxa
                   \vbox to\headheight{\vfil \hbox to\textwidth
                                       {\let\label\@gobble \let\index\@gobble
                                         \@thehead}} %% 22 Feb 87
                 \dp\@tempboxa\z@
                 \box\@tempboxa
                 \vskip \headsep
                 \box\@outputbox
                 \baselineskip\footskip
                 \hbox to\textwidth{\let\label\@gobble
                           \let\index\@gobble  %% 22 Feb 87
                           \@thefoot}}}%
%  above copied from LaTeX.tex
%
\boxheight=\ht\tempboxnum\advance\boxheight\dp\tempboxnum
\begingroup\vfuzz=120ex\vbadness=10000%
\global\setbox\outputbox=\vbox{%
\boxheight=\ht\buffbox\advance\boxheight\topmargin
\advance\boxheight\headsep
\advance\boxheight\headheight
%
\lineheight=\headsep\advance\lineheight\headheight
\advance\lineheight\topmargin
\ifdim\lineheight<0pt\lineheight=-\lineheight
\else\lineheight0pt\fi
\kern-\lineheight
%
\hbox{\hskip\oddsidemargin\hskip-50pt%
\advance\boxheight#6%
\lower\boxheight%
\hbox{\hskip#5\copy\buffbox}\nobreak\hskip-\oddsidemargin\hskip50pt%
\hskip-#5\nobreak
\lower\ht\tempboxnum\hbox{\box\tempboxnum}}}%
\endgroup\shipout\box\outputbox
% above new ingredient
%
           \global\@colht\textheight
           \endgroup\stepcounter{page}\let\firstmark\botmark}}
%  end of \setvruler
%
%
%
% The followings may be deleted if only VRULER macros
% are needed.
%
%
\catcode`\^^M=13% 
\newcount\linecount\linecount=1%
{\obeyspaces\gdef {\ }}
\gdef\endprogram{\catcode`\^^M=13%
\catcode`\ =10\let^^M=\par\catcode`\^^M=5}%
\gdef\beginprogram[#1]{\global\linecount=#1\catcode`\^^M=13%
\gdef\putlinenumber{\par\noindent\hbox{}%
\hang\textindent{\hbox to0em{\hss\tt \the\linecount~~}}%
%% remove the above line if you don't want line numbers
\global\advance\linecount1\relax}%
\global\let^^M=\putlinenumber\catcode`\ =13\relax}%
\catcode`\^^M=5\relax%
%
%
\catcode`\^^M=13% 
{\obeyspaces\gdef {\ }}
\gdef\endascii{\catcode`\^^M=13%
\catcode`\ =10\let^^M=\par\catcode`\^^M=5}%
\gdef\beginascii{\catcode`\^^M=13%
\gdef\putemptynum{\par\noindent\hang\textindent{}}%
\global\let^^M=\putemptynum\catcode`\ =13\relax}%
\catcode`\^^M=5\relax%
%
\def\unsetraw{\endgroup\message{Escape Restored>}}
\def\setraw[#1]{\begingroup\message{<Escape=#1 }\beginascii
\hsize=\textwidth
\catcode`\%=11\catcode`\^=11\catcode`\_=11%
\catcode`\&=11\catcode`\$=11\catcode`\#=11\catcode`\~=11%
\catcode`\{=11\catcode`\}=11\catcode`\@=11%
\catcode`\\=11\catcode`#1=0\relax}
%\catcode`\@=12\relax
%
% End of LaTeX macros
%
%
%
%
% PRINTOUT AND DEMONSTRATION:
%         
% |unsetraw % this token will become active if you run the
%           % following program, by removing the leading characters '%' below
%
%     %    Write a file that contains the followings, then LaTeX 
%     %    it. You will obtain a copy of this file demonstrating itself!
%  
%     \documentstyle[vruler]{article}
%     \begin{document}
%     \textwidth=6in
%     \def\myfilename{vruler.sty}
%     \setvruler[12pt][1000][20][0][0pt][4.5pt]
%     \tt\setraw[|]|expandafter|input|myfilename %|unsetraw
%     \end{document}
%     % Note: '%' in front of |unsetraw above shouldn't be there
%     % under normal circumstances. This is because the program has
%     % to read in itself.

