40 lines
870 B
Bash
40 lines
870 B
Bash
#!/bin/bash
|
|
|
|
# big-latex-blob.sh — concatenate \input files from a LaTeX master into a single blob
|
|
|
|
if [ $# -ne 1 ]; then
|
|
echo "Usage: $0 <master.tex>" >&2
|
|
exit 1
|
|
fi
|
|
|
|
MASTER="$1"
|
|
|
|
if [ ! -f "$MASTER" ]; then
|
|
echo "Error: '$MASTER' not found." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Derive output filename: Longing.tex -> Longing-Blob.tex
|
|
BASENAME="${MASTER%.tex}"
|
|
OUTPUT="${BASENAME}-Blob.tex"
|
|
|
|
# Check that at least one \input line exists
|
|
if ! grep -q '\\input' "$MASTER"; then
|
|
echo "Error: no \\input lines found in '$MASTER'." >&2
|
|
exit 1
|
|
fi
|
|
|
|
grep '\\input' "$MASTER" | \
|
|
sed 's/.*\\input{\(.*\)}/\1/' | \
|
|
xargs -I{} sh -c '
|
|
if [ ! -f "$1" ]; then
|
|
echo "Warning: input file not found: $1" >&2
|
|
else
|
|
printf "\n%% --- %s ---\n\n" "$1"
|
|
cat "$1"
|
|
fi
|
|
' _ {} > "$OUTPUT"
|
|
|
|
echo "Written to: $OUTPUT"
|
|
|