Re: Footer trap in a A4 PDF
Hello again groffers! I want to thank Tadziu, Deri and Bjarni for their insights on how groff works. The different behaviour between measurement systems reported by Bjarni is not something I expected, nor something that makes any sense. Nonetheless I managed to understand a couple of new things about groff, which is a tool I really enjoy using it; one of them is how to achieve exact margins, something that's very useful for my use case. Thanks to Branden too, for his answers and his contribution to the GNU Project. Thank you everyone. groff forever! -- Matteo Bini
Re: Footer trap in a A4 PDF
The groff software is tuned to the imperial measurement system (inch etc.). Using another measurement system: A text line normally never touches exactly a trap but goes beyond it. Therefore a footer starts nearer the bottom edge than the measurement in metric (SI) units indicates.
Re: Footer trap in a A4 PDF
> A slight change and you can colour the margins with pure troff > so it works for both postscript and pdf:- Very good! Your example also demonstrates how setting the vertical spacing to zero allows directly positioning the baseline (which is the reference position for "\D" drawing commands) with ".sp" requests, without having to add "-1v".
Re: Footer trap in a A4 PDF
On Friday, 25 August 2023 17:00:23 BST Tadziu Hoffmann wrote: > I have attached a demonstration file you can use for experimenting. > (I have used 3 cm margins for this. Coloring the margins with XX > (for debugging purposes) only works with the PS device; you can > safely remove this.) A slight change and you can colour the margins with pure troff so it works for both postscript and pdf:- groff -Tpdf -P-pa4 -P-e margins.trf > margins.pdf Cheers Deri .\" .\" .pl 29.7c .po 2.5c .ll 16c .lt 16c .\" .ev 1 .ll 16c .lt 16c .gcolor blue .ft 2 .ev .\" .de HD .ev 1 .XX .sp |1.5c-1v .if o .tl '\\*[RH]''%' .if e .tl '%''\\*[LH]' .tl ''\v'-0.5v'\D'l \\n[.lt]u 0''' .sp |3c .ev .. .de FO .ev 1 .sp |29.7c-1.5c-2v .tl ''\D'l \\n[.lt]u 0''' .if o .tl '\\*[RF]''%' .if e .tl '%''\\*[LF]' .bp .ev .. .ds RH right header .ds LH left header .ds RF right footer .ds LF left footer .wh 0 HD .wh -3c-1v FO .\" .de XX .vpt 0 .ev XX .vs 0 .po 0 .sp |0 .fcolor pink \D'P 21c 0 0 3c -21c 0' .sp |26.7c \D'P 21c 0 0 3c -21c 0' .fcolor .fl .po .vs .ev .vpt 1 .. .\" .ft 3 5.2. Extra line-space. .ft .de ZZ .sp .5 If a word contains a tall construct requiring the output line containing it to have extra vertical space before and/or after it, the extra-line-space function x'N' can be embedded in or attached to that word. If N is negative, the output line containing the word will be preceded by N extra vertical space; if N is positive, the output line containing the word will be followed by N extra vertical space. If successive requests for extra space apply to the same line, the maximum values are used. The most recently utilized post-line extra line-space is available in the .a register. .. .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ margins.pdf Description: Adobe PDF document
Re: Footer trap in a A4 PDF
Hi Matteo, At 2023-08-25T18:32:02+0200, Matteo Bini wrote: > On 2023-08-25 10:20, G. Branden Robinson wrote: > > Attaching screenshots of Evince viewing the document in "Dual" mode, > > when produced with Debian's groff 1.22.4 and stock groff 1.23.0 > > I hate to be that meticulous, but if you open those images with GIMP, > you can see that the footer text is not at the same height on both > pages. kruler aside, there's another way to tell--inspect troff(1)'s output. ...and I get no difference. $ /usr/bin/groff -Z -K utf8 -P -pa4 -T pdf ATTIC/bini.roff \ >| ATTIC/bini-a4-1.22.4.grout $ groff -Z -K utf8 -P -pa4 -T pdf ATTIC/bini.roff >| \ ATTIC/bini-a4-1.23.0.grout $ cmp ATTIC/bini-a4-1.22.4.grout ATTIC/bini-a4-1.23.0.grout && echo SAME SAME > In the ROFF file you've sent me there are no unwanted blank lines. And yet the "footer" changes location from page 1 to page 2? > I honestly don't know how to debug this, even if it's not a big > problem. Something like $ grep '^ *$' mymacro.tmac is what I had in mind. Regards, Branden signature.asc Description: PGP signature
Re: Footer trap in a A4 PDF
At 2023-08-25T12:46:49-0400, Peter Schaffter wrote: > On Fri, Aug 25, 2023, G. Branden Robinson wrote: > > (Once upon a time, like 25 years ago, there was a tool called xruler or > > similar that made it easy to measure distances on the screen. > > Twenty-five years ago, I started running KDE just to get its screen > ruler. It's still around. Kruler. I use it frequently. Beautiful! And I already had so much KDE installed that grabbing it brought in _zero_ extra dependencies. The tool I'm remembering didn't look like a wooden ruler as this does. I have no idea if I'm misremembering an Athena app, or unfairly forgetting this one. Either way, happy day. Thanks! Regards, Branden signature.asc Description: PGP signature
Re: Footer trap in a A4 PDF
On Fri, Aug 25, 2023, G. Branden Robinson wrote: > (Once upon a time, like 25 years ago, there was a tool called xruler or > similar that made it easy to measure distances on the screen. Twenty-five years ago, I started running KDE just to get its screen ruler. It's still around. Kruler. I use it frequently. -- Peter Schaffter https://www.schaffter.ca
Re: Footer trap in a A4 PDF
Hello again Branden, On 2023-08-25 10:20, G. Branden Robinson wrote: > Attaching screenshots of Evince viewing the document in "Dual" mode, > when produced with Debian's groff 1.22.4 and stock groff 1.23.0 I hate to be that meticulous, but if you open those images with GIMP, you can see that the footer text is not at the same height on both pages. This means that this is not a version issue. In the ROFF file you've sent me there are no unwanted blank lines. I honestly don't know how to debug this, even if it's not a big problem. However I would love to know how to achieve precise margins with groff. Thank you for your hard work on the GNU Project. This issue can't erase the fact that I really like using groff. -- Matteo Bini
Re: Footer trap in a A4 PDF
> How should I proceed to achieve precise margin sizes? There's two things to consider here. One: the trap is sprung when a line is output that reaches OR SWEEPS PAST the trap position. If you set your trap at -2 cm, then an output line may nevertheless still intrude into the bottom margin of 2 cm. Unless you have over-tall lines, this will usually be not more than the baseline distance of the running text. If you want to keep the bottom 2 cm of the page free of text, then it may be a good idea to set the trap at -2c-1v. Two: if your footer macro just outputs the footer line without doing anything else, then the position of the footer line WILL DEPEND ON where the last line of text had been output, and thus may vary from page to page. To keep the footer line always in the same position, have the footer macro space absolutely to the desired position before outputting the footer line. Also, if the footer (and header) lines should be output in a different font, size, or color, it is best to reserve a separate environment for the headers and footers, in order to minimize interactions with the running text. E.g., you might use environment 0: normal running text environment 1: headers and footers environment 2: footnotes I have attached a demonstration file you can use for experimenting. (I have used 3 cm margins for this. Coloring the margins with XX (for debugging purposes) only works with the PS device; you can safely remove this.) .\" .\" .pl 29.7c .po 2.5c .ll 16c .lt 16c .\" .ev 1 .ll 16c .lt 16c .gcolor blue .ft 2 .ev .\" .de HD .ev 1 \Y[XX] .sp |1.5c-1v .if o .tl '\\*[RH]''%' .if e .tl '%''\\*[LH]' .tl ''\v'-0.5v'\D'l \\n[.lt]u 0''' .sp |3c .ev .. .de FO .ev 1 .sp |29.7c-1.5c-2v .tl ''\D'l \\n[.lt]u 0''' .if o .tl '\\*[RF]''%' .if e .tl '%''\\*[LF]' .bp .ev .. .ds RH right header .ds LH left header .ds RF right footer .ds LF left footer .wh 0 HD .wh -3c-1v FO .\" .de XX ps: exec gsave 72 2.54 div dup scale 1 .9 .8 setrgbcolor 0 0 21 3 rectfill 0 29.7 21 -3 rectfill grestore .. .\" .ft 3 5.2. Extra line-space. .ft .de ZZ .sp .5 If a word contains a tall construct requiring the output line containing it to have extra vertical space before and/or after it, the extra-line-space function x'N' can be embedded in or attached to that word. If N is negative, the output line containing the word will be preceded by N extra vertical space; if N is positive, the output line containing the word will be followed by N extra vertical space. If successive requests for extra space apply to the same line, the maximum values are used. The most recently utilized post-line extra line-space is available in the .a register. .. .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ .ZZ footer.pdf Description: Adobe PDF document
Re: Footer trap in a A4 PDF
Hi Matteo, At 2023-08-25T16:51:15+0200, Matteo Bini wrote: > Thanks for the answer Branden, > it's an honour to get a reply directly from you! It's an honor to have users who care enough to submit reports against a package, rather than casting it aside as unsatisfactory! > I've compiled your ROFF file and I've attached the resulting PDF. > My groff version is 1.22.4. I'm on Debian 12, stable. This looks like mine with groff 1.23.0, and I wouldn't have expected any difference, so it's reassuring to see that they're the same (as far as my eyeballs can tell). > Not only the word footer does not show up in the same place on the two > pages, I can't reproduce this problem, so we'd better get to the bottom of it. I used Evince to bring up the pages side-by-side, and they appear to be in the same place to me. Attaching screenshots of Evince viewing the document in "Dual" mode, when produced with Debian's groff 1.22.4 and stock groff 1.23.0 > but it's not at -2c from the bottom. On the first page, the word > footer shows up at -1.6c, whereas on the second at -1.8c. Considering > vertical spacing as well, I would say that the footer shows up as I > would expect to on the second page, but not on the first. I don't know > why. This may be a consequence of whatever is causing skew between 1.22.4 and 1.23.0 renderings. A blank line in a macro file somewhere, possibly the one you're writing, seems like a likely culprit. Look out for those. > Regarding Tadziu Hoffmann's answer, I don't know what to say. I thank > you for your help too, but I did not understand what you wrote me. How > should I proceed to achieve precise margin sizes? As far as roff language expertise goes, Tadziu is our master on top of the mountain, and people like me are still chopping his firewood. ;-) This is what I mean about us needing improved documentation. I don't think we have paper format and vertical margin management nailed down as well as could.[1] There could be bugs in this area, too. Speaking of documentation, I keep bleeding-edge versions of our docs in a DropBox account. Our documentation undergoes _constant_ revision. https://www.dropbox.com/sh/17ftu3z31couf07/AAC_9kq0ZA-Ra2ZhmZFWlLuva?dl=0 It's not even been 2 months since groff 1.23.0 finalized and I already wish people had the current version instead. Regards, Branden [1] Also see Alexis's effort to impose some order on our chaos. https://lists.gnu.org/archive/html/groff/2023-08/msg00027.html signature.asc Description: PGP signature
Re: Footer trap in a A4 PDF
Thanks for the answer Branden, it's an honour to get a reply directly from you! I've compiled your ROFF file and I've attached the resulting PDF. My groff version is 1.22.4. I'm on Debian 12, stable. Not only the word footer does not show up in the same place on the two pages, but it's not at -2c from the bottom. On the first page, the word footer shows up at -1.6c, whereas on the second at -1.8c. Considering vertical spacing as well, I would say that the footer shows up as I would expect to on the second page, but not on the first. I don't know why. > You may set the baseline separation to zero with ".vs 0", but it > is best to do this in a separate environment, in order to avoid > messing up the running text. Regarding Tadziu Hoffmann's answer, I don't know what to say. I thank you for your help too, but I did not understand what you wrote me. How should I proceed to achieve precise margin sizes? Thank you all. -- Matteo Bini bini.pdf Description: Adobe PDF document
Re: Footer trap in a A4 PDF
> I would expect the word "footer" to pop up at -2c from the page bottom, > then a page break. Footer does pop up, and there's the page break too, > however it does not show up at -2c from the bottom. It's lower. It is working as intended. When you say ".sp |0c" in troff, that does not mean that the baseline will be at 0 cm, but rather the "top of the text" will be at 0 cm. Think of it as an approximation to lead typesetting, except that in troff the baseline will be set 1v below the specified point (i.e., one whole baseline distance, and not some fraction of the total line height as it would be in real lead typesetting). You may set the baseline separation to zero with ".vs 0", but it is best to do this in a separate environment, in order to avoid messing up the running text.
Re: Footer trap in a A4 PDF
Hi Matteo, At 2023-08-25T14:25:06+0200, Matteo Bini wrote: > I'm writing some documents that will be exported in PDF with A4 paper > size. I'm using my own macro package. [...] > This is how I output to PDF: > groff -K utf8 -m mymacro -M . -P -pa4 -T pdf in.roff > out.pdf > > I would expect the word "footer" to pop up at -2c from the page bottom, > then a page break. Footer does pop up, and there's the page break too, > however it does not show up at -2c from the bottom. It's lower. > > What am I doing wrong? I couldn't reproduce your problem with groff 1.23.0. I used the attached input document, very similar to yours, but combining the page layout and page content stuff. With the `pl` request commented and the `-P -pa4` option sequence omitted, I get a page that numbers 54 lines before springing the footer trap, which writes the word "footer" and breaks the page. $ groff -K utf8 -T pdf ATTIC/bini.roff >| ATTIC/bini.pdf If I uncomment the `pl` request and restore the option sequence... $ groff -K utf8 -P -pa4 -T pdf ATTIC/bini.roff >| ATTIC/bini.pdf ...I get a page that is noticeably longer, numbering 58 lines before the footer trap springs. The visible bottom margin sizes _look_, to my eyeballs, about the same size. (Once upon a time, like 25 years ago, there was a tool called xruler or similar that made it easy to measure distances on the screen. Unfortunately, I guess as parcel of "making Linux ready for the desktop", this sort of practical application was discarded as being too ugly. Didn't help with that streamlined, configuration-free experience Sun was going for by taking over GNOME development, and didn't promote TrollTech's private dialect of C++, so it got consigned to the flames.) ...but I digress. Please verify that you can reproduce the results I'm getting. If you can, we'll look into the matter of achieving precise margin sizes, an area I have recently come to feel is under-documented in groff. If you _can't_ reproduce my results, we need to sort that out; there may be a bug somewhere wanting squashing. Regards, Branden .pl 29.7c .de FO footer . bp .. .wh -2c FO Hello, world! .sp I've set the page length to 29.7c (A4). .sp I've set up a trap at -2c with my macro FO. .sp Now I'm going to make a bunch of lines. .nf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 .fi All done\(embye! signature.asc Description: PGP signature
Footer trap in a A4 PDF
Hello groffers! I'm writing some documents that will be exported in PDF with A4 paper size. I'm using my own macro package. My macro package is very very simple: it's just for defining paragraphs and titles style. Then I've decided to add an empty footer, which is more like a bottom margin for my pages. I've defined a macro called FO. .de FO footer . bp .. I've set the page length to 29.7c (A4). .pl 29.7c I've set up a trap at -2c with my macro FO. .wh -2c FO This is how I output to PDF: groff -K utf8 -m mymacro -M . -P -pa4 -T pdf in.roff > out.pdf I would expect the word "footer" to pop up at -2c from the page bottom, then a page break. Footer does pop up, and there's the page break too, however it does not show up at -2c from the bottom. It's lower. What am I doing wrong? I'm quite new to groff, as well as to this mailing list, so, please, be gentle ;) -- Matteo Bini