Extraction now takes the whole tree and copies the template out with tar -h, so symlinks into resources/ arrive as real files rather than as links pointing outside the new document. new_beamer_presentation is superseded; cdsc_tex_aliases.sh keeps the name as an alias. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
77 lines
1.6 KiB
Bash
Executable File
77 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Helper script to export LaTeX/knitr templates for new documents
|
|
# Copyright (c) 2009-2026 Benjamin Mako Hill <mako@atdot.cc>
|
|
# Released under the GPLv3 or later.
|
|
|
|
set -e
|
|
|
|
CURDIR=$(pwd)
|
|
|
|
usage() {
|
|
echo "Usage: $(basename "$0") <type> <directory>"
|
|
echo "Types: paper, memo, knitr, letter, slides"
|
|
exit 1
|
|
}
|
|
|
|
[ -n "$1" ] && [ -n "$2" ] || usage
|
|
|
|
TYPE="$1"
|
|
DEST="$2"
|
|
|
|
case "$TYPE" in
|
|
paper)
|
|
REPO="$HOME/tex/cdsc_tex"
|
|
BRANCH="master"
|
|
TEMPLATE="paper_template"
|
|
EXT="tex"
|
|
;;
|
|
memo)
|
|
REPO="$HOME/tex/cdsc_tex"
|
|
BRANCH="master"
|
|
TEMPLATE="memo_template"
|
|
EXT="tex"
|
|
;;
|
|
knitr)
|
|
REPO="$HOME/tex/cdsc_tex"
|
|
BRANCH="knitr"
|
|
TEMPLATE="paper_template"
|
|
EXT="Rtex"
|
|
;;
|
|
letter)
|
|
REPO="$HOME/tex/cdsc_tex"
|
|
BRANCH="master"
|
|
TEMPLATE="letter_template"
|
|
EXT="tex"
|
|
;;
|
|
slides)
|
|
REPO="$HOME/tex/cdsc_tex"
|
|
BRANCH="master"
|
|
TEMPLATE="slides_template"
|
|
EXT="tex"
|
|
;;
|
|
*)
|
|
echo "error: unknown type '$TYPE'"
|
|
usage
|
|
;;
|
|
esac
|
|
|
|
if [ -e "$DEST" ]; then
|
|
echo "error: '$DEST' already exists"
|
|
exit 1
|
|
fi
|
|
|
|
WORK_DIR=$(mktemp -d)
|
|
TREE_DIR=$(mktemp -d)
|
|
trap 'rm -rf "$TREE_DIR"' EXIT
|
|
|
|
# Extract the whole tree, then copy the template out with tar -h, so that
|
|
# symlinks into resources/ become real files in the new document.
|
|
cd "$REPO"
|
|
git archive --format=tar "$BRANCH" | tar x -C "$TREE_DIR"
|
|
tar -chf - -C "$TREE_DIR/$TEMPLATE" . | tar x -C "$WORK_DIR"
|
|
cd "$CURDIR"
|
|
mv "$WORK_DIR" "$DEST"
|
|
cd "$DEST"
|
|
mv "text.$EXT" "$(basename "$DEST").$EXT"
|