Verified Commit 0d8f10d0 authored by Sofus Albert Høgsbro Rose's avatar Sofus Albert Høgsbro Rose
Browse files

Made latexmk-clean.sh better. Consider moving to own repo?

parent fa638fc0
......@@ -17,16 +17,48 @@ TMP_LATEX=".textmp"
####################
# - Search Function
####################
search_path() {
## Search mechanism for latex-relevant files or directory.
# TODO: Consider using a 'realpath --relative-to' call to unify rosetex in some way. Or do something else instead of hard-coding search paths.
el="$1"
if [[ -d "$el" || -f "$el" ]]; then
echo "$el"
elif [[ -d "../$el" || -f "../$el" ]]; then
echo "../$el"
elif [[ -d "../../$el" || -f "../../$el" ]]; then
echo "../../$el"
elif [[ -d "../../../$el" || -f "../../../$el" ]]; then
echo "../../../$el"
else
echo ""
fi
}
####################
# - Directory Management
####################
if [[ "$@" == '-c' ]]; then
rm -rf "$TMP_LATEX"
elif [[ "$@" == '-C' ]]; then
rm -rf "$TMP_LATEX"
# RM the PDF that would be written to.
for path_tex in $(find . -name "*.tex" -type f); do
tex="$(basename "$path_tex")"
rm -i "${tex%.*}.pdf"
done
else
mkdir -p "$TMP_LATEX"
# Touch the PDF that will be written to via symbolic link.
for path_tex in $(find . -name "*.tex" -type f); do
for path_tex in $(find . -maxdepth 1 -name "*.tex" -type f); do
tex="$(basename "$path_tex")"
touch "${tex%.*}.pdf" 2>&1 >/dev/null
done
......@@ -36,14 +68,20 @@ else
ln -sfn ".$f" "$TMP_LATEX/$(basename "$f")"
done
# Add rosetex Course Standard files
if [ -d "../../ref/rosetex" ]; then
# TODO: Consider using a 'realpath --relative-to' call to unify rosetex in some way.
# Search: Custom .latexmkrc, rosetex.
# TODO: Consider making it rosetex-agnostic; merely have a way of loading custom packages and classes.
LATEXMKRC_PATH=$(search_path ".latexmkrc")
ROSETEX_PATH=$(search_path "ref/rosetex")
if [ -f "$LATEXMKRC_PATH" ]; then
# Use an extra '..', as we're one layer down.
ln -sfn "../$LATEXMKRC_PATH" $TMP_LATEX/
fi
if [ -d "$ROSETEX_PATH" ]; then
# Use an extra '..', as we're one layer down.
ln -sfn "../../../.latexmkrc" $TMP_LATEX/
ln -sfn "../../../ref/rosetex/rosetex.cls" $TMP_LATEX/
ln -sfn "../../../ref/rosetex/rosetex.sty" $TMP_LATEX/
ln -sfn "../$ROSETEX_PATH/rosetex.cls" $TMP_LATEX/
ln -sfn "../$ROSETEX_PATH/rosetex.sty" $TMP_LATEX/
fi
# Run latexmk In Temp Folder
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment