From 0974ea361a66df39886d4bd18ae1b721e40701aa Mon Sep 17 00:00:00 2001 From: Guilherme Rugai Freire Date: Wed, 11 Feb 2026 01:10:09 -0300 Subject: [PATCH] latex_hotreload: new --- bin/latex_hotreload | 1 + latex_hotreload/README.md | 7 ++++ latex_hotreload/latex_hotreload.sh | 51 ++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 120000 bin/latex_hotreload create mode 100644 latex_hotreload/README.md create mode 100755 latex_hotreload/latex_hotreload.sh diff --git a/bin/latex_hotreload b/bin/latex_hotreload new file mode 120000 index 0000000..836f42f --- /dev/null +++ b/bin/latex_hotreload @@ -0,0 +1 @@ +../latex_hotreload/latex_hotreload.sh \ No newline at end of file diff --git a/latex_hotreload/README.md b/latex_hotreload/README.md new file mode 100644 index 0000000..a76f9d2 --- /dev/null +++ b/latex_hotreload/README.md @@ -0,0 +1,7 @@ +# latex_hotreload + +## About +-- about section here -- + +## Requirements +-- any requirements -- diff --git a/latex_hotreload/latex_hotreload.sh b/latex_hotreload/latex_hotreload.sh new file mode 100755 index 0000000..f30d5fc --- /dev/null +++ b/latex_hotreload/latex_hotreload.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +entry="$1" +files_to_watch=$() + +if [ -z "$entry" ]; then + echo "Error: no entry provided. See --help for usage" + exit 1 +fi + +if [ "$entry" == "--help" ]; then + echo "Usage: latex_hotreload [OPTIONS] entry_tex_file" + echo "" + echo " OPTIONS:" + echo " --help: show this help" + echo "" + echo " STDIN:" + echo " The stdin should contain the files that should be watched for recompilation" + echo " Defaults to ./*.tex" + echo "" + echo " ARGUMENTS:" + echo " entry_tex_file: the entry latex file for compilation" + echo "" + exit 0 +fi + +output="$(echo "$entry" | sed 's/\.tex$/.pdf/')" + +if test ! -t 0; then + while IFS= read -r line + do + files_to_watch+=("$line") + done + + files=$(printf "%s" "${files_to_watch[*]}") + files="$(echo $files | sed 's/ /\n/')" +else + files="$(find . -type f | grep "\.tex")" +fi + +echo $files | sed 's/ /\n/g' | entr -s "pdflatex -shell-escape $entry" & +entr_pid=$! + +while [ ! -f "$output" ] +do + sleep 0.5 +done + +zathura "$output" + +kill -s 2 "$entr_pid"