From 8a6925d269cdc240f181ca5887bbfba41528d001 Mon Sep 17 00:00:00 2001 From: Gustav Eek Date: Wed, 21 Aug 2024 20:20:25 +0200 Subject: [PATCH] Add a macro code padding script for compilation purpuses --- sh/macrocode.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 sh/macrocode.sh diff --git a/sh/macrocode.sh b/sh/macrocode.sh new file mode 100644 index 0000000..790d0e3 --- /dev/null +++ b/sh/macrocode.sh @@ -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" -- 2.39.2