Find the answer to your Linux question:
Results 1 to 3 of 3
I'm using plain groff to format pages for printing but I am using it without any of the macro packages such as ms or me. I want a way of ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2013
    Posts
    37

    groff page breaks


    I'm using plain groff to format pages for printing but I am using it without any of the macro packages such as ms or me. I want a way of setting a command at the head of the file which will allow me to let page breaks just happen automatically rather than having to put the .bp command in by hand at the end of each page. I was wondering whether someone was using a macro from plain groff that can do this reliably and share it?

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,286
    Hi.

    The core of this solution is simply to pipe groff output into utility pr:
    Code:
    #!/usr/bin/env bash
    
    # @(#) s1	Demonstrate pagination form groff through pr.
    
    # Utility functions: print-as-echo, print-line-with-visual-space, debug.
    # export PATH="/usr/local/bin:/usr/bin:/bin"
    pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
    pl() { pe;pe "-----" ;pe "$*"; }
    db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
    db() { : ; }
    C=$HOME/bin/context && [ -f $C ] && $C pll specimen groff pr
    
    # Default data file is Lincoln's Cooper Union.
    FILE=${1-data2}
    
    pl " Input data file $FILE, long lines shortened to fit:"
    pe
    pll -w 70 $FILE | specimen 3:3:3 -n
    
    pl " Results:"
    groff -T ascii $FILE |
    pr -F -l 20 |
    head -35 |
    sed 's/\o014/^L -- Form Feed/'
    
    exit 0
    producing:
    Code:
    % ./s1
    
    Environment: LC_ALL = C, LANG = C
    (Versions displayed with local utility "version")
    OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
    Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
    bash GNU bash 3.2.39
    pll (local) 1.18
    specimen (local) 1.17
    groff GNU groff version 1.18.1
    pr (GNU coreutils) 6.10
    
    -----
     Input data file data2, long lines shortened to fit:
    
     (Longest line: 1880; fit into lines of length 70)
    Edges: 3:3:3 of 156 lines in file "-"
         1	         1         2         3 ...        186        187        1
         2	1234567890123456789012345678901...8901234567890123456789012345678
         3	# Sun Nov 11 23:11:09 CST 2007 ... fellow citizens of New York: -
       ---
        78	
        79	Now, and here, let me guard a l...od the question better than we.
        80	
       ---
       154	
       155	Neither let us be slandered fro...DO OUR DUTY AS WE UNDERSTAND IT
       156	
    
    -----
     Results:
    
    
    2013-05-31 12:48                                                  Page 1
    
    
    #    Sun    Nov    11    23:11:09   CST   2007   #   http://show-
    case.netins.net/web/creative/lincoln/speeches/cooper.htm  #   fmt
    -66 Mr. President and fellow citizens of New York: -
    
    The facts with which I shall deal this evening are mainly old and
    familiar; nor is there anything new in the general  use  I  shall
    make  of  them.  If there shall be any novelty, it will be in the
    mode of presenting the facts, and the inferences and observations
    following that presentation.
    
    ^L -- Form Feed
    
    2013-05-31 12:48                                                  Page 2
    
    
    In his speech last autumn, at Columbus, Ohio, as reported in "The
    New-York Times," Senator Douglas said:
    
    "Our fathers, when they framed  the  Government  under  which  we
    live,  understood  this  question  just as well, and even better,
    than we do now."
    
    I fully indorse this, and I adopt it as  a  text  for  this  dis-
    course.  I  so  adopt  it  because  it furnishes a precise and an
    agreed starting point for a discussion  between  Republicans  and
    ^L -- Form Feed
    
    2013-05-31 12:48                                                  Page 3
    This uses groff to process the long lines of the data file. This produces a default right-left-justified stream, but without pagination.

    The pr utility with suitable options will place a form-feed character, control-L, at appropriate places.

    To make this apparent, I have shortened the page length to 20 lines, and printed only a few pages. The control-L is normally not visible, so I used a trick with sed to convert it to a long string that shows up in the output.

    See man pages for details.

    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    Just Joined!
    Join Date
    May 2013
    Posts
    37
    Hello drl,

    Wow! That's a wonderful piece of work you have offered for which I am very grateful, and an approach I hadn't considered. Thanks heaps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •