]> git.g-eek.se Git - guitarsections.git/commitdiff
Add a macro code padding script for compilation purpuses
authorGustav Eek <gustav.eek@fripost.org>
Wed, 21 Aug 2024 18:20:25 +0000 (20:20 +0200)
committerGustav Eek <gustav.eek@fripost.org>
Thu, 22 Aug 2024 21:43:01 +0000 (23:43 +0200)
sh/macrocode.sh [new file with mode: 0644]

diff --git a/sh/macrocode.sh b/sh/macrocode.sh
new file mode 100644 (file)
index 0000000..790d0e3
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+
+# Between stdin and -out, padds level-tree comment sections ("%%%")
+# with LaTeX documentation macrocode environments.
+
+BEGIN='# Strip empty lines and provide begin-end placeholders
+  /^%%%/,$ {
+    $ a %    \\end{macrocode}
+    /^\s*$/ d
+    /^%%%/ {
+      i %    \\end{macrocode}
+      a %    \\begin{macrocode}
+    }
+  }
+'
+
+END='# Remove odd begin-end items
+  1,/end.*macrocode/ {
+    /end.*macrocode/ d
+  }
+  /begin.*macrocode/ {
+    N
+    /begin.*macrocode.*end.*macrocode/ d
+  }
+'
+
+cat - | \
+    sed -e "$BEGIN" | sed -e "$END"