From 576e049237a96c3bab680fd73ba1bc9c77ba9d4e Mon Sep 17 00:00:00 2001 From: tavo-wasd Date: Mon, 11 Sep 2023 12:09:04 -0600 Subject: [PATCH] groff ez images --- scripts/groff-compiler | 17 ++++++++++------- scripts/groff-img | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100755 scripts/groff-img diff --git a/scripts/groff-compiler b/scripts/groff-compiler index 85bc2b0..e44425c 100755 --- a/scripts/groff-compiler +++ b/scripts/groff-compiler @@ -1,20 +1,23 @@ #!/bin/sh # -# Small compiler script for groff +# Compiler script for groff # # [-k (preconv)] Convert encoding to something groff understands # [-e (eqn)] Format equations for troff or MathML # [-t (tbl)] Format tables for troff # [-p (pic)] Compile pictures for troff or TeX -# [-G (grap)] Typesetting graphs +# [-G (grap)] Typesetting graphs (grap usually not installed by default) # [-j (chem)] Chemical structure diagrams (messes up spacing!) # Configuration BIB="$HOME/Desktop/bibliography" # Bibliography file MAC="$HOME/.config/groff/" # Macros dir -PRE="ketp" # Preprocessors - -# Enable macros, grab references, include args -soelim -I "$MAC" "$1" | refer -p "$BIB" | - groff -mspdf -T pdf -U -"$PRE" +PRE="-ketpG" # Preprocessors +GROMACS="-mspdf" # groff macros +OUT="pdf" # Output format +# groff-img: Personal script, image manipulation +# soelim: Enable macros dir +# refer: Enable bibliography +groff-img "$1" | soelim -I "$MAC" | refer -p "$BIB" | + groff "$GROMACS" -T "$OUT" -U "$PRE" diff --git a/scripts/groff-img b/scripts/groff-img new file mode 100755 index 0000000..1e589c6 --- /dev/null +++ b/scripts/groff-img @@ -0,0 +1,20 @@ +#!/bin/sh +# Replace .IMG commands for proper +# .PDFPIC and convert given image files. + +FILE="$1" +OUTPUT="$(cat "$FILE")" + +format() { + LINE="$1" + IMAGE="$(echo "$LINE" | cut -d '"' -f 2)" + [ "$IMAGE" != "${IMAGE%%.*}.pdf" ] && ! [ -e "${IMAGE%%.*}.pdf" ] && convert -quiet "$IMAGE" "${IMAGE%%.*}.pdf" + echo "$LINE" | sed 's|^.IMG|.PDFPIC|' | sed "s|$IMAGE|${IMAGE%%.*}.pdf|" +} + +for i in $(seq $(grep '^.IMG\s' "$FILE" | wc -l)) ; do + LINE="$(echo "$OUTPUT" | grep '^.IMG\s' | head -n 1)" + [ -n "$LINE" ] && NEW_LINE="$(format "$LINE")" && OUTPUT=$(echo "$OUTPUT" | sed "s|$LINE|$NEW_LINE|") || break +done + +echo "$OUTPUT"