add mksvg function
This commit is contained in:
parent
1eada14ed1
commit
d6b58e7e83
2 changed files with 63 additions and 8 deletions
|
|
@ -36,6 +36,7 @@
|
|||
"localsend"
|
||||
"calibre"
|
||||
"linearmouse"
|
||||
"omnigraffle"
|
||||
];
|
||||
taps = [
|
||||
# Additional repositories if needed
|
||||
|
|
|
|||
|
|
@ -23,24 +23,23 @@
|
|||
|
||||
if [[ -z "$tex_file" ]]; then
|
||||
# Build all .tex files in current directory
|
||||
local tex_files=(*.tex)
|
||||
if [[ ''${#tex_files[@]} -eq 0 ]] || [[ ! -f "''${tex_files[0]}" ]]; then
|
||||
echo "No .tex files found in current directory"
|
||||
return 1
|
||||
fi
|
||||
|
||||
for file in "''${tex_files[@]}"; do
|
||||
local found=0
|
||||
for file in *.tex(N); do
|
||||
found=1
|
||||
echo "Building $file..."
|
||||
latexmk -pdf -bibtex -shell-escape -interaction=nonstopmode \
|
||||
-output-directory="$output_dir" -f "$file"
|
||||
|
||||
# Copy PDF to current directory
|
||||
local basename="''${file%.tex}"
|
||||
if [[ -f "$output_dir/$basename.pdf" ]]; then
|
||||
cp "$output_dir/$basename.pdf" "./"
|
||||
echo "Copied $basename.pdf to current directory"
|
||||
fi
|
||||
done
|
||||
if [[ $found -eq 0 ]]; then
|
||||
echo "No .tex files found in current directory"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
if [[ ! -f "$tex_file" ]]; then
|
||||
echo "File not found: $tex_file"
|
||||
|
|
@ -59,6 +58,61 @@
|
|||
fi
|
||||
}
|
||||
|
||||
# Generate standalone PDF from LaTeX equation
|
||||
# Usage: mksvg <equation> <filename>
|
||||
# Example: mksvg 'E = mc^2' energy
|
||||
function mksvg() {
|
||||
local equation="''${1}"
|
||||
local filename="''${2}"
|
||||
|
||||
if [[ -z "$equation" ]] || [[ -z "$filename" ]]; then
|
||||
echo "Usage: mksvg <equation> <filename>"
|
||||
echo "Example: mksvg 'E = mc^2' energy"
|
||||
return 1
|
||||
fi
|
||||
|
||||
printf '%s\n' "$equation" > "''${filename}.texeq"
|
||||
|
||||
local temp_tex="''${filename}_temp.tex"
|
||||
{
|
||||
printf '%s\n' '\documentclass{standalone}'
|
||||
printf '%s\n' '\usepackage{amsmath}'
|
||||
printf '%s\n' '\usepackage{amssymb}'
|
||||
printf '%s\n' '\begin{document}'
|
||||
printf '%s%s%s\n' '$' "$equation" '$'
|
||||
printf '%s\n' '\end{document}'
|
||||
} > "$temp_tex"
|
||||
|
||||
pdflatex -interaction=nonstopmode "$temp_tex" > /dev/null 2>&1
|
||||
|
||||
if [[ -f "''${filename}_temp.pdf" ]]; then
|
||||
mv "''${filename}_temp.pdf" "''${filename}.pdf"
|
||||
echo "Generated ''${filename}.pdf"
|
||||
else
|
||||
echo "Failed to generate PDF"
|
||||
rm -f "$temp_tex"
|
||||
return 1
|
||||
fi
|
||||
|
||||
rm -f "$temp_tex" "''${filename}_temp.aux" "''${filename}_temp.log"
|
||||
}
|
||||
|
||||
# Regenerate PDFs from all .texeq files in current directory
|
||||
function mksvg-all() {
|
||||
local found=0
|
||||
for file in *.texeq(N); do
|
||||
found=1
|
||||
local filename="''${file%.texeq}"
|
||||
local equation="$(cat "$file")"
|
||||
echo "Regenerating ''${filename}.pdf..."
|
||||
mksvg "$equation" "$filename"
|
||||
done
|
||||
if [[ $found -eq 0 ]]; then
|
||||
echo "No .texeq files found in current directory"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Continuous compilation mode - watch and auto-rebuild
|
||||
# Usage: mkpdf-watch <file.tex>
|
||||
function mkpdf-watch() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue