home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / text / tex / 14569 < prev    next >
Encoding:
Text File  |  1993-01-03  |  10.1 KB  |  255 lines

  1. Newsgroups: comp.text.tex
  2. Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!wupost!cs.uiuc.edu!vela!jafortun
  3. From: jafortun@vela.acs.oakland.edu (James Fortune)
  4. Subject: Latest LaTeX altnline.sty revisions
  5. Message-ID: <1993Jan3.123822.14693@vela.acs.oakland.edu>
  6. Organization: Oakland University, Rochester MI.
  7. Date: Sun, 3 Jan 1993 12:38:22 GMT
  8. Lines: 245
  9.  
  10. >From ntomczak@vega.math.ualberta.ca Sat Dec 26 02:20:15 1992
  11. >From: N Tomczak-Jaegermann <ntomczak@vega.math.ualberta.ca>
  12. >Subject: altnlines.sty - 1.1
  13. >To: jafortun@vela.acs.oakland.edu
  14. >Date: Sat, 26 Dec 92 0:19:13 MST
  15.  
  16. .
  17. .
  18. .
  19.  
  20. >I played some with 1.0 and added some stuff which you obviously
  21. >wanted to include but you left it alone for a time beeing.  I also
  22. >made some other changes throwing out excessive \global's, modyfying
  23. >the code a little bit and the like.  Unfortunately I do not know
  24. >enough about LaTeX output routine to really know how to code the
  25. >stuff to shut up error messages.  I managed to do that with plain
  26. >but this is obviously not good enough.  I do not know if this will
  27. >be of any help with your other problems.  With not too complicated
  28. >text this stuff seems to work ok.  Equations are not a problem, but
  29. >I did not try what will happen in a presence of float.
  30.  
  31. >   Merry Xmas and Happy New Year,
  32. >   Michal
  33.  
  34. Thanks Michal for helping to make it happier.
  35.  
  36. I was quite impressed with the changes Michal made and the underlying 
  37. understanding of output routines they demonstrate.  BTW, no one else
  38. sent me any comments at all this time.  Here are my remaining comments:
  39.  
  40. 1.  altnline.sty still wipes out hanging indentation.  For long quotations
  41.     the indentation is lost and the right side numbers are moved slightly
  42.     to the left on odd pages until the quotation is ended.  Anyone know
  43.     how I can preserve the indentation when line numbering is occurring?
  44.  
  45. 2.  Since it counts zero length lines I will try something like \parskip
  46.     rather than \\ to separate paragraphs (The editor insisted on a blank
  47.     line between paragraphs to keep in line with other books in the series).
  48.  
  49. 3.  Those using plain TeX can use a similar scheme much more easily.
  50.     I'll try putting \shipout\box255 in the \output definition to see
  51.     if it gets rid of the messages without messing things up.  If I
  52.     find a location that works I'll post it.
  53.  
  54. 4.  Thanks again to all who helped (Cameron Smith, Michal Jaegermann, and
  55.     Rainer Schoepf).  
  56.  
  57. JAF
  58. ---------------------------------------------------------------------------
  59. % altnline.sty    Version - 1.1
  60. %
  61. % Disclaimer - Use at your own risk.
  62. %
  63. % James Fortune                 
  64. % Oakland University            
  65. % jafortun@vela.acs.oakland.edu 
  66. %
  67. % Based upon the TUGboat article ``Output Routines: Examples and Techniques.''
  68. % that appeared in Volume 11 (1990), Nos. 1, 3 and 4.
  69. %
  70. % This version incorporates suggestions made by Michal Jaegermann, namely:
  71. %
  72. % * Include explicit reference to the TUGboat article
  73. % * ``You can use \def in style files without violating LaTeX spirit.
  74. %     If you are writing style it is assumed that you know what you are
  75. %     doing. :-)'' --- I don't know what I'm doing so I left the \newcommand
  76. %   and \renewcommand commands as is.
  77. % * Internal macros from style file should be protected against name conflicts
  78. %   with user stuff by inclusion of '@' character in names. --- This is quite
  79. %   reasonable so command names that the user is not expected to use in a
  80. %   LaTeX file have been changed to include the '@' character.
  81. % * He sent a new appendline command that adds numbers on a left margin
  82. %   only that was also inspired by the Salomon article.  He left it as an
  83. %   exercise for me to modify it for two-sided printing.  I probably shouldn't
  84. %   have picked something from the double dangerous bend signs for my first
  85. %   serious attempt at hacking on a style file :-).
  86. % * A global linesSoFar so that lineCount may be set to linesSoFar to deal
  87. %   with box255 being broken from the bottom up.  countlines (or its
  88. %   equivalent) advances linesSoFar by a count of lines on a current page.
  89. % * Use of a decremented remainder variable to determine when to add a number
  90. %   to a line. --- I'm trying to get all the lines first.
  91. % * He advised not trying to combine the countlines and duplicate operations
  92. %   into a single loop.  ``I am afraid that you really have to first count
  93. %   how many lines you have on a page and later use this value to produce
  94. %   line numbers.''
  95. %
  96. % Changes to version 1.1 - Michal Jaegermann, ntomczak@vega.math.ualberta.ca
  97. %
  98. % * Added logic to print line numbers only every \lineCountInterval
  99. % * Added a way to set up ONE range of numbered lines; use \nlinesBoundary
  100. %   to do that. (It is possible to sprinkle your text with \nlinesBoundary
  101. %   commands and they may even do the right thing if you will put them
  102. %   in right places - but this is a hack.)
  103. % * Miscellaneous cleanup
  104. % * Every implicit or explicit \clearpage will still cause
  105. %   'Output routine didn't use all of \box255' message.  Any volunteers
  106. %   who know enough about LaTeX output routine to repair that?
  107. %
  108.    
  109. % \font\sevenrm=cmr7
  110.  
  111. % Rainer showed me how to save the previous \output.  Thanks Rainer.
  112. \newtoks\LaTeX@output
  113. \LaTeX@output = \expandafter{\the\output}
  114.  
  115. \newcommand\zero@ToSp{\parskip=\@ne sp plus\@ne pt
  116.   \renewcommand\vfil{\vskip1sp plus1fil}
  117.   \renewcommand\vfill{\vskip1sp plus1fill}
  118.   \abovedisplayshortskip=\@ne sp plus3pt
  119.   \postdisplaypenalty=\@ne
  120.   \interlinepenalty=\@ne}
  121.  
  122. \zero@ToSp
  123.  
  124.  
  125. \newcount\lin@CountInit  % used to establish lineCount of first line on page
  126. \lin@CountInit=\z@
  127. \newcount\lineCountInterval  % used to determine how often lin@Count is printed
  128. \lineCountInterval=5
  129. %
  130. \newcount\lin@CountStart  % don't print line numbers below this value
  131. \lin@CountStart=\@ne
  132. \newcount\lin@CountFinish  % don't print line numbers higher than this
  133. \lin@CountFinish=\m@ne
  134. %
  135. % A command to set boundaries for line numbering.  Use as:
  136. %   \nlinesBoundary{12}, or \nlinesBoundary[50]{12}
  137. %   \nlinesBoundary[<optional upper limit>]<lower limit>
  138. % Any negative number for an upper limit means number to the very end.
  139. % This is a default!
  140. %
  141. \def\nlinesBoundary{\@ifnextchar[{\nlin@sBoundary}{\nlin@sBoundary[\m@ne]}}
  142. \edef\nlin@sBoundary[#1]#2{%
  143.   \global\lin@CountFinish=#1\relax
  144.   \global\lin@CountStart=#2\relax}
  145.  
  146. \newif\ifa@@lnum  % do we really want to print that line number?
  147.  
  148. \newcount\lin@sSoFar
  149. % remainder from division of \lin@sSoFar by \lineCountInterval
  150. \newcount\total@Rem
  151. % current value of remainder used to produce line numbers
  152. \newcount\lin@rem
  153. % these calculations allow to start with \lin@CountInit different from 0
  154. \newcommand\resetlin@sSoFar{%
  155.   \global\lin@sSoFar=\lin@CountInit
  156.   \total@Rem=\lin@CountInit
  157.   \divide\total@Rem by\lineCountInterval
  158.   \multiply\total@Rem by-\lineCountInterval
  159.   \global\advance\total@Rem by\lin@CountInit}
  160.  
  161. \resetlin@sSoFar
  162.  
  163. \newcount\lin@Count
  164. \newif\ifAnyleft \newcount\pen
  165. \newcommand\count@lines{%
  166.   \global\lin@Count=\lin@sSoFar
  167.   \loop \Anyleftfalse
  168.     \ifdim\lastskip=\z@ \ifdim\lastkern=\z@ \ifnum\lastpenalty=\z@
  169.       \setbox0=\lastbox
  170.     \ifvoid0
  171.     \else \Anylefttrue \global\advance\lin@Count by\@ne
  172.                        \global\advance\total@Rem by\@ne
  173.                        \ifnum\total@Rem=\lineCountInterval
  174.                           \global\total@Rem=\z@
  175.                        \fi\fi
  176.     \else \Anylefttrue \unpenalty \fi
  177.     \else \Anylefttrue \unkern \fi
  178.     \else \Anylefttrue \unskip \fi
  179.   \ifAnyleft \repeat}
  180.  
  181. \newcommand\@duplicate{%
  182.   \loop \Anyleftfalse
  183.     \ifdim\lastskip=\z@ \ifdim\lastkern=\z@ \ifnum\lastpenalty=\z@
  184.       \global\setbox0=\lastbox \ifvoid0 % end of breakup loop
  185.     \else \Anylefttrue                  % box present
  186.       \ifnum\lin@rem=0                  % if remainder non-zero we do not care
  187.         \lin@rem=\lineCountInterval
  188.         \ifnum\lin@Count<\lin@CountStart
  189.           \a@@lnumfalse
  190.         \else
  191.           \ifnum\lin@CountFinish<0      % no upper bound
  192.             \a@@lnumtrue                % print it
  193.           \else
  194.             \ifnum\lin@Count>\lin@CountFinish
  195.               \a@@lnumfalse
  196.             \else
  197.               \a@@lnumtrue              % this is the ticket
  198.             \fi
  199.           \fi
  200.         \fi
  201.       \else
  202.          \a@@lnumfalse
  203.       \fi
  204.       \ifa@@lnum
  205.          \append@line
  206.       \else
  207.          \global\setbox1=\vbox{\box0\unvbox1}
  208.       \fi
  209.       \advance\lin@Count\m@ne
  210.       \advance\lin@rem by\m@ne\fi
  211.     \else \Anylefttrue                  % penalty present
  212.       \pen=\lastpenalty
  213.       \global\setbox1=\vbox{\penalty\pen\unvbox1}\unpenalty\fi
  214.     \else \Anylefttrue                  % kern present
  215.       \dimen0=\lastkern
  216.       \global\setbox1=\vbox{\kern\dimen0\unvbox1}\unkern \fi
  217.     \else \Anylefttrue                  % skip present
  218.       \skip0=\lastskip
  219.       \global\setbox1=\vbox{\vskip\skip0\unvbox1}\unskip \fi
  220.     \ifAnyleft \repeat}
  221.  
  222. \newcommand\append@line{%  attach line number
  223.   \setbox2=\vbox to \z@{\smash{\footnotesize\the\lin@Count}}
  224.   \wd2=25pt                           % that much of space for a line number
  225.   \ifodd\count0                       % on the right margin for odd pages
  226.      \setbox0=\hbox{\box0\rlap{\rule{\wd2}{\z@}\box2}}  
  227.   \else                               % and on the left for even
  228.      \setbox0=\hbox{\llap{\box2}\box0}
  229.   \fi
  230.   \global\setbox1=\vbox{\box0\unvbox1}} % add this to a reconstructed page
  231.  
  232. \newbox\brk    % Use old output definition if page is not to be output
  233. \output={\ifnum\outputpenalty <-\@M
  234.   \output={\LaTeX@output}
  235. \else
  236.   \lin@Count=\lin@sSoFar
  237.   \setbox\brk=\vbox{\unvcopy\@cclv\count@lines}
  238.            \global\setbox1=\vbox{}
  239.            \lin@rem=\total@Rem
  240.   \global\lin@sSoFar=\lin@Count
  241.   \setbox\brk=\vbox{\unvcopy\@cclv\@duplicate}
  242.   \ifdim\ht\brk>\z@\message{Incomplete breakup}\fi
  243.   \ht1=\z@\dp1=\z@
  244.   \global\setbox\@cclv=\vbox to\vsize{\unvbox1}% attempt to get glues back
  245.   \@makecol\@opcol
  246. \fi}
  247. \endinput
  248.  
  249. ---------------------------------------------------------------------------
  250. -- 
  251. James Fortune                  - Internet: Thousands of people mostly unaware
  252. Oakland University             - of the sight and sound of each other, linked
  253. jafortun@vela.acs.oakland.edu  - together by the bits of our souls that can
  254. Disclaimer: Not O.U. opinions  - fit through computer keyboards.
  255.