# Invoke this prog, to get 10pt or 12pt cookbook ps and pdf files from recipes: # # command line parameters: # Mkpsnup2 [12 | 10] (default is 10) [ 0 ] (default is "" = no parameter) # OPTIONS #"12" option: Produce 12pt version, Cookbook-12.ps and related # Cookbook-12.ps # Cookbook-12-2up.ps # Cookbook-12-2up.pdf # 2up 12pt is close to size of (1up) 10pt text, # i.e., can read it # OR #"10" option or default: Produce 10pt version, Cookbook-10.ps + related # Cookbook-10.ps # Cookbook-10.pdf # Cookbook-10-2up.ps # not too useful as can't read 2up 10pt text # OR #no parameter - neither "10" nor "12" present - defaults to "10" # # AND #"0" option: do not run rcbook.t - use last Cookbook.ps file # "0" parameter option not expected to be often used # OR #no parameter - no "0" - defaults to empty string "": run rcbook.t # ##################### # Rearrange Cookbook.ps into a PS file, 2 logical pages per physical page, # in which each recipe of 2 or more pages starts on the left side of a # physical page, producing to the extent possible a format in which # each recipe is on a single physical page. # # Blocks of text (the cover page, table of contents, introduction, # the set of recipes, and the permuted index) are set to start each # on a new page of the final 2-up layout, and to appear in the order above. # # Files: # Scr.toc pagenum and contents information generated by rcbook.t # # Scr.blocks physical page of start and end of blocks of # text in Cookbook.ps (cover, body, TOC, ptx) # # Scr.contents recipe logical page numbers (body of text starts # with Intro. at page 1) and recipe names # # Scr.psselect physical page numbers of Cookbook.ps, specified in # format needed for command-line argument for psselect, # to produce desired PS output from rearrangement # of Cookbook.ps # # Cookbook-2up.ps the final product, from filtering Cookbook.ps # through psselect, pstops (to rescale), and psnup # # Sat Jul 12 19:09:47 MST 2008 # added rcbook.t, to produce 10pt or 12pt text of recipes book # add pstops filter, to rescale book to maximize text area after 2uping # trial-error adjustment of pstops pagespecs # # Fri Jul 11 18:01:09 MST 2008 j.a. rupley # modified code to correct for blank pages (inserts at start new # sections) in parent .ps/.pdf files; # the insertion of blank pages now appears appropriate # generate Cookbook.ps - by default for 10pt text, with run of rcbook.t TFLAG="" RCBOOK_FLAG="yes" while [ $# -gt 0 ]; do case $1 in *10*) TFLAG="";; *12*) TFLAG='-t "-rS12"';; 0|none) RCBOOK_FLAG="";; *) echo $0: Unknown option $1 1>&2 exit 1;; esac shift done if [ $RCBOOK_FLAG ] then rm Cookbook.ps Cookbook-2up.ps #if run rcbook.t, remove old ps files ../Programs/rcbook.t $TFLAG fi # get start and end physical page numbers of blocks of text in Cookbook.ps: # cover page # body == intro and recipes # table of contents # permuted index # the initial egrep pulls the logical and physical page number for each # page of Cookbook.ps # (the logical page number restarts at 0 or 1 for each new block of text) # 0) { if ($2 <= lastlogical) break } cover[2] = $3 - 1 if ($2 == 0) # eliminate blank pages == section separators getline body[1] = $3 lastlogical = $2 while (getline > 0) { if ($2 <= lastlogical) break } body[2] = $3 -1 if ($2 == 0) # eliminate blank pages == section separators getline toc[1] = $3 lastlogical = $2 while (getline > 0) { if ($2 <= lastlogical) break } toc[2] = $3 - 1 if ($2 == 0) # eliminate blank pages == section separators getline ptx[1] = $3 ptx[2] = 0 while (getline > 0) { if ($2 <= lastlogical) break ptx[2] = $3 } numcover = cover[2] - cover[1] + 1 numbody = body[2] - body[1] + 1 numtoc = toc[2] - toc[1] + 1 numptx = ptx[2] - ptx[1] + 1 # print block name, start phys page, end phys page, number of pages print "cover",cover[1], cover[2], numcover print "body ",body[1], body[2], numbody print "toc ",toc[1], toc[2], numtoc print "ptx ",ptx[1], ptx[2], numptx exit }' >Scr.blocks # extract table of contents information: the filename of the recipe and # the logical page number within body of recipes text Scr.contents # use the information in Scr.contents and Scr.blocks to create the # command line argument for psselect # # physpage is the physical page number of the _rearranged_ text # lastlogical is the logical page within the the body of the # (intro. + recipes) text # physical page 2 of Cookbook.ps is blank, and is inserted # many times where needed as a spacer for the final 2-up layout 0) { start[$1] = $2 end[$1] = $3 pages[$1] = $4 } # # print page specifiers for the cover page + following blank page; # then print page specifiers for the TOC pages, # followed if needed by a blank page separator; # the second page of the cover page block, its last page (2 of 2), # is a blank page (which is THE blank page, reproduced repeatedly # where a page separator is needed) # physpage = 1 printf "%s-%s(%s)",start["cover"],end["cover"], physpage physpage = physpage + end["cover"] - start["cover"] + 1 # # put in a page separator between cover and TOC = 2nd page cover block # printf ",2" physpage += 1 # # now print the TOC # printf ",%s-%s(%s)", start["toc"], end["toc"], physpage physpage = physpage + end["toc"] - start["toc"] + 1 # # in order to start the Introduction on a separate page in the # final 2-up layout, insert a blank page if needed # if (physpage %2 != 1) { printf ",2" physpage += 1 } } # NR == 1 { # the logical page number of the INTRODUCTION is on # the first line of the input, (Scr.contents) # if ($2 !~ "INTRODUCTION") { print "INTRODUCTION not first header" | "cat 1>&2" exit } lastlogical = $1 next } # NR == 2 { # the logical page number of the first Recipe is on # the second line of the input; # thus can calculate the page specifiers for the INTRODUCTION # and its length, from the logical page numbers of the start of # the INTRODUCTION and the first Recipe; # then print the page specifiers for the INTRODUCTION # numpages = $1 - lastlogical # printf ",%s-%s(%s)", start["body"]+lastlogical-1, start["body"]+$1-2 , physpage physpage = physpage + numpages # # start the Recipes on a new page of final 2-up layout # inserting a blank page if needed # if (physpage %2 != 1) { printf ",2" physpage += 1 } # lastlogical = $1 next } # { # now cycle through the Recipes # note: must read next Recipe line before can print # page specs for previous Recipe read # i.e., are always reading a Recipe ahead in info file # # put in a blank page, # if the Recipe to be printed is more than one page long and if the # current physical page number would not correspond to the leftmost # of the two pages on the 2-up output eventually generated # numpages = $1 - lastlogical # if ((numpages > 1) && (physpage %2 != 1)) { printf ",2" physpage += 1 } # # print the Recipe page specifiers # printf ",%s-%s(%s)", start["body"]+lastlogical-1, start["body"]+$1-2 , physpage physpage += numpages lastlogical = $1 # # if the Recipe just printed was more than two pages long # and it ends on the leftmost of a 2up presentation, add a blank page, # to force the next Recipe to begin on the leftmost of the 2up pages # i.e., start a new 2up page with the next Recipe; # this allows stapling of a set of 2up pages for a >2-page Recipe # if ((numpages > 1) && (physpage %2 != 1)) { printf ",2" physpage += 1 } } END { # # flush the last Recipe, as always inserting a blank page if needed # numpages = end["body"] - (start["body"]+lastlogical-1) + 1 if ((numpages > 1) && (physpage %2 != 1)) { printf ",2" physpage += 1 } # printf ",%s-%s(%s)", start["body"]+lastlogical-1, end["body"], physpage # # then do the INDEX, starting it on a fresh 2-up page # physpage += numpages if (physpage %2 != 1) { printf ",2" physpage += 1 } # printf ",%s-(%s)\n", start["ptx"], physpage }' | # # get rid of the physical page information, put in as a debug aid # sed -e 's/([^)]*)//g' >Scr.psselect # run psselect to rearrange Cookbook.ps, # run pstops to rescale and shift pages, so maximize readability, # run psnup to get 2 logical pages per physical page # to produce Cookbook-2up.ps # psselect `cat Scr.psselect` Cookbook-2up.ps # # branch according to test on $TFLAG, to xx=10pt or xx=12pt limb # remove old Cookbook-xx ps and pdf files # copy Cookbook.ps -> Cookbook-xx.ps. Cookbook-2up.ps -> Cookbook-xx-2up.ps # run adobe distiller: Cookbook-xx-2up.ps or Cookbook-xx.ps -> pdf file # if [ "${TFLAG}x" = "x" ] then rm Cookbook-10-2up.ps Cookbook-10.ps Cookbook-10-2up.pdf Cookbook-10.pdf cp -p Cookbook-2up.ps Cookbook-10-2up.ps cp -p Cookbook.ps Cookbook-10.ps open -a "/Applications/Adobe Acrobat 7.0 Professional/Acrobat Distiller 7.0.app" Cookbook-10-2up.ps open -a "/Applications/Adobe Acrobat 7.0 Professional/Acrobat Distiller 7.0.app" Cookbook-10.ps else rm Cookbook-12-2up.ps Cookbook-12.ps Cookbook-12-2up.pdf Cookbook-12.pdf cp -p Cookbook-2up.ps Cookbook-12-2up.ps cp -p Cookbook.ps Cookbook-12.ps open -a "/Applications/Adobe Acrobat 7.0 Professional/Acrobat Distiller 7.0.app" Cookbook-12-2up.ps open -a "/Applications/Adobe Acrobat 7.0 Professional/Acrobat Distiller 7.0.app" Cookbook-12.ps fi # cleanup - no trap, as want to see stuff if have a crash # rm Scr.blocks Scr.contents Scr.psselect