Avoid orphans in PDF. - tgtimes - The Gopher Times
(HTM) git clone git://bitreich.org/tgtimes git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/tgtimes
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
---
(DIR) commit 1002873261d2894759c9e5854cfdf7568ad8e29e
(DIR) parent c09232171a4703120c1aa9af28c3ae6b3f3a6f36
(HTM) Author: Troels Henriksen <athas@sigkill.dk>
Date: Tue, 8 Aug 2023 22:14:14 +0200
Avoid orphans in PDF.
Signed-off-by: Christoph Lohmann <20h@r-36.net>
Diffstat:
M Makefile | 2 +-
A filters/nudge.filter | 28 ++++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
---
(DIR) diff --git a/Makefile b/Makefile
@@ -38,7 +38,7 @@ rawptxtfiles=${rawfiles:.raw=.ptxt}
${tgtimes}.txt: ${mdptxtfiles} ${txtptxtfiles} ${rawptxtfiles}
- cat opus${v}/?-*.ptxt > ${tgtimes}.txt
+ cat opus${v}/?-*.ptxt | filters/nudge.filter > ${tgtimes}.txt
${tgtimes}.pdf: ${tgtimes}.txt
(DIR) diff --git a/filters/nudge.filter b/filters/nudge.filter
@@ -0,0 +1,28 @@
+#!/usr/bin/env -S awk -f
+#
+# Insert blank lines between sections to avoid ugly orphans in PDF
+# output.
+
+BEGIN {
+ LINES_PER_PAGE=73 # Determined by observation.
+ MAX_SPACING=5 # Max empty we wish to allow at bottom of page.
+
+ line=0
+ incontent=1
+}
+
+/./ {
+ if (incontent == 0) {
+ spaces=LINES_PER_PAGE - line % LINES_PER_PAGE + 1;
+ if (spaces < MAX_SPACING) {
+ for (i = 0; i < spaces; i++) {
+ print "";
+ line++;
+ }
+ }
+ incontent = 1;
+ }
+}
+/^$/ { incontent = 0; }
+{ print $0; line++; }
+