Using PDF boxes with groff and the ms macrosDeri Jamesderi@chuzzlewit.myzen.co.ukAn extension in version 1.23.0 of gropdf , the PDF output driver for the groff document formattingsystem, allows coloured rectangles to be placed beneath any output created by groff . The exten-sion can be accessed via a device extension escape sequence \X'pdf: background . . . ' or a con-venience macro pdfbackground supporting the same parameters.\X'pdf: background cmd left top right bottom weight'.pdfbackground cmd left top right bottom weightProduce a background rectangle on the page.cmdis the command, which can be any of “page|fill|box” in combination. Thus,“pagefill” would draw a rectangle that covers the whole current page size (inwhich case the rest of the parameters can be omitted because the box di-mensions are taken from the current media size). “boxfill”, on the otherhand, requires the given dimensions to place the box. Including “fill” in thecommand will paint the rectangle with the current fill colour (as with \M[ ])and including “box” will give the rectangle a border in the current strokecolour (as with \m[ ]).cmd may also be “offon its own, which will terminate drawing the currentbox. If you have specified a page colour with “pagefill”, it is always the firstbox in the stack, and if you specify it again, it will replace the first entry. Beaware that the “pagefill” box renders the page opaque, so tools that “water-mark” PDF pages are unlikely to be successful. To return the background totransparent, issue an “offcommand with no other boxes open.Finally, cmd may be “footnote” followed by a new value for bottom, whichwill be used for all open boxes on the current page. This is to allow room forfootnote areas that grow while a page is processed (to accommodate multi-ple footnotes, for instance).1lefttoprightbottomare the coordinates of the box. The top and bottom coordinates are theminimum and maximum for the box, since the actual start of the box isgroff s drawing position when you issue the command, and the bottom ofthe box is the point where you turn the box “off”. The top and bottom coor-dinates are used only if the box drawing extends onto the next page; ordi-narily, they would be set to the header and footer margins.weightprovides the line width for the border if “box” is included in the command.For an even more convenient interface, include -msboxes on the groff command line; the sboxespackage defines the macros BOXSTART and BOXSTOP. 1 If the value is negative, it is used as an offset from the bottom of the page.
2March 2021.BOXSTART SHADED colour OUTLINED colour INDENT size WEIGHT sizebegins a box, where the argument after SHADED gives the fill colour and that afterOUTLINED the border colour. Omit the former to get a borderless filled box and thelatter for a border with no fill. The specified WEIGHT is used if the box is OUT-LINED.INDENT precedes a value that leaves a gap between the border and the contents in-side the box.Each colour must be a defined groff colour name, and each size a valid groff nu-meric expression. The keyword/value pairs can be specified in any order.Boxes can be stacked, so you can start a box within another box; usually the later boxes would besmaller than the containing box, but this is not enforced. When using BOXSTART, the left positionis the current indent minus the INDENT in the command, and the right position is the left position(calculated above) plus the current line length and twice the indent. The synopsis of BOXSTARTabove itself uses a BOXSTART call without borders and with a 2p (two point) indent..BOXSTOPtakes no parameters. It closes the most recently started box at the current verticalposition after adding its INDENT spacing.Your groff documents can conditionally exercise the sboxes macros. The register GSBOX is de-fined if the package is loaded, and interpolates a true value if the pdf output device is in use.sboxes furthermore hooks into the groff ms package to receive notifications when footnotes aregrowing, so that it can close boxes on a page before footnotes are printed. When that condition ob-tains, sboxes will close open boxes two points2 above the footnote separator and re-open them onthe next page.This document was produced using the following code..\" groff -ms -msboxes -Tpdf..\" Copyright 2021 Free Software Foundation, Inc..\" 2021 G. Branden Robinson.\".\" Written by Deri James <deri@chuzzlewit.myzen.co.uk>.\".\" This file is part of sboxes..\".\" sboxes is distributed with groff, the GNU roff typesetting system..\".\" groff is free software; you can redistribute it and/or modify it.\" under the terms of the GNU General Public License as published by.\" the Free Software Foundation, either version 3 of the License, or.\" (at your option) any later version..\".\" groff is distributed in the hope that it will be useful, but WITHOUT.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 2 This amount probably will not match the box’s INDENT.
Using PDF boxes with groff and the ms macros3.\" or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public.\" License for more details..\".\" You should have received a copy of the GNU General Public License.\" along with this program. If not, see.\" <http://www.gnu.org/licenses/>...nr LL 17c.nr PO 2c.nr PS 11.nr VS 13.nr PI 3.5n.nr HM 2c.nr FM 2c.nr QI 7n.ss 12 0.ND March 2021.EH '%''March 2021'.EF ''''.OH 'Using PDF boxes with \f[I]groff\f[] and the \f[I]ms\f[] macros''%'.OF ''''.\" Define a quotation macro..de Qq. nop \[lq]\\$1\[rq]\\$2...\" Define a macro for code literals; use bold and disable hyphenation..de Lt. ft B. nh. nop \&\\$1\c. hy \\n[HY]. ft. nop \&\\$2...ds FAM H.ie '\*[.T]'pdf' .ds pgbkgd floralwhite.el .ds pgbkgd default.TLUsing PDF boxes with.BI groffand the.BI msmacros.AUDeri James.AIderi@chuzzlewit.myzen.co.uk.LPAn extension in version 1.23.0 of.I gropdf ,the PDF output driver for the.I groffdocument formatting system,
4March 2021allows coloured rectangles to be placed beneath any output created by.I groff .The extension can be accessed via a device extension escape sequence.Lt "\[rs]X\[aq]pdf: background" \~.\|.\|.\|\c.Lt \[aq]or a convenience macro.Lt pdfbackgroundsupporting the same parameters..QS.BOXSTART SHADED cornsilk OUTLINED brown INDENT 2n WEIGHT 1p\M[\*[pgbkgd]]\c.pdfbackground pagefill\M[]\c.B\[rs]X\[aq]pdf: background.BIcmd left top right bottom weight\[aq].br.Lt .pdfbackground.BIcmd left top right bottom weight.LPProduce a background rectangle on the page..IP \f[I]cmd 8n \" indent enough to fit "bottom" tagis the command, which can be any of.Qq page|fill|boxin combination.Thus,.Qq pagefillwould draw a rectangle that covers the whole current page size (inwhich case the rest of the parameters can be omitted because the boxdimensions are taken from the current media size)..Qq boxfill ,on the other hand, requires the given dimensions to place the box.Including.Qq fillin the command will paint the rectangle with the current fill colour (aswith.Lt \[rs]M[\|] )and including.Qq boxwill give the rectangle a border in the current stroke colour(as with.Lt \[rs]m[\|] )..sp \n[PD]u.I cmdmay also be.Qq offon its own, which will terminate drawing the current box.If you have specified a page colour with.Qq pagefill ,it is always the first box in the stack, and if you specify it again, itwill replace the first entry.
Using PDF boxes with groff and the ms macros5Be aware that the.Qq pagefillbox renders the page opaque, so tools that.Qq watermarkPDF pages are unlikely to be successful.To return the background to transparent, issue an.Qq offcommand with no other boxes open..sp \n[PD]uFinally,.I cmdmay be.Qq footnotefollowed by a new value for.I bottom ,which will be used for all open boxes on the current page.This is to allow room for footnote areas that grow while a page isprocessed (to accommodate multiple footnotes,for instance).\m[red]\**\m[]3.FSIf the value is negative, it is used as an offset from the bottom of thepage..FE.nr oldPD \n[PD].nr PD 0.IP \f[I]left.IP \f[I]top.IP \f[I]right.IP \f[I]bottom.nr PD \n[oldPD]are the coordinates of the box.The.I topand.I bottomcoordinates are the minimum and maximum for the box, since the actualstart of the box is.I groff 'sdrawing position when you issue the command, and the bottom of the boxis the point where you turn the box.Qq off .The top and bottom coordinates are used only if the box drawing extendsonto the next page; ordinarily, they would be set to the header andfooter margins..IP \f[I]weightprovides the line width for the border if.Qq boxis included in the command..BOXSTOP.QEFor an even more convenient interface, include 3 This is a long footnote occupying multiple output lines. Its only purpose is to verify that the bottom of thebox on this page has been adjusted upward to accommodate it.
6March 2021.Lt \-msboxeson the.I groffcommand line; the.I sboxespackage defines the macros.Lt BOXSTARTand.Lt BOXSTOP ..QS.BOXSTART SHADED cornsilk OUTLINED brown INDENT 2n WEIGHT 1p.BOXSTART SHADED cornsilk3 INDENT 2p.Lt .BOXSTART.Lt SHADED.I colour.Lt OUTLINED.I colour.Lt INDENT.I size.Lt WEIGHT.I size.BOXSTOP.LPbegins a box,where the argument after.Lt SHADEDgives the fill colour and that after.Lt OUTLINEDthe border colour.Omit the former to get a borderless filled box and the latter for aborder with no fill.The specified.Lt WEIGHTis used if the box is.Lt OUTLINED ..LP.Lt INDENTprecedes a value that leaves a gap between the border and the contentsinside the box..LPEach.I colourmust be a defined.I groffcolour name,and each.I sizea valid.I groffnumeric expression.The keyword/value pairs can be specified in any order..BOXSTOP.QE
Using PDF boxes with groff and the ms macros7Boxes can be stacked, so you can start a box within another box; usuallythe later boxes would be smaller than the containing box, but this isnot enforced.When using.Lt BOXSTART ,the left position is the current indent minus the.Lt INDENTin the command,and the right position is the left position (calculated above) plus thecurrent line length and twice the indent.The synopsis of.Lt BOXSTARTabove itself uses a.Lt BOXSTARTcall without borders and with a.Lt 2p(two point) indent..QS.BOXSTART SHADED cornsilk OUTLINED brown INDENT 2n WEIGHT 1p.BOXSTART SHADED cornsilk3 INDENT 2p.Lt .BOXSTOP.BOXSTOP.LPtakes no parameters.It closes the most recently started box at the current vertical positionafter adding its.Lt INDENTspacing..BOXSTOP.QEYour.I groffdocuments can conditionally exercise the.I sboxesmacros.The register.Lt GSBOXis defined if the package is loaded, and interpolates a true value ifthe.Lt pdfoutput device is in use..LP.I sboxesfurthermore hooks into the.I "groff ms"package to receive notifications when footnotes are growing, so that itcan close boxes on a page before footnotes are printed.When that condition obtains,.I sboxeswill close open boxes two points\**.FSThis amount probably will not match the box's.Lt INDENT .
8March 2021.FEabove the footnote separator and re-open them on the next page..LPThis document was produced using the following code..ds FAM C.nr PS 11.nr VS 13.LP.BOXSTART SHADED white OUTLINED brown INDENT 2n WEIGHT 1p.nf\# (replaced by source of this document).BOXSTOP.\" Local Variables:.\" mode: nroff.\" fill-column: 72.\" End:.\" vim: set filetype=groff textwidth=72: