Avoid orphans in PDF. - tgtimes - The Gopher Times | |
git clone git://bitreich.org/tgtimes git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
--- | |
commit 1002873261d2894759c9e5854cfdf7568ad8e29e | |
parent c09232171a4703120c1aa9af28c3ae6b3f3a6f36 | |
Author: Troels Henriksen <[email protected]> | |
Date: Tue, 8 Aug 2023 22:14:14 +0200 | |
Avoid orphans in PDF. | |
Signed-off-by: Christoph Lohmann <[email protected]> | |
Diffstat: | |
M Makefile | 2 +- | |
A filters/nudge.filter | 28 ++++++++++++++++++++++++++++ | |
2 files changed, 29 insertions(+), 1 deletion(-) | |
--- | |
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 | |
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++; } | |
+ |