summaryrefslogtreecommitdiff
path: root/Build
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2020-08-16 21:36:48 +0000
committerKarl Berry <karl@freefriends.org>2020-08-16 21:36:48 +0000
commitf2ddeb34c8c5b158be426a21845025267f17dea1 (patch)
tree61e269bbd614bcd6792c9c97fb760cd1df41064b /Build
parent54319b9ec014682aec96a7b67f2debf26fd0757d (diff)
tikztosvg (16aug20)
git-svn-id: svn://tug.org/texlive/trunk@56122 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build')
-rwxr-xr-xBuild/source/texk/texlive/linked_scripts/tikztosvg/tikztosvg234
1 files changed, 128 insertions, 106 deletions
diff --git a/Build/source/texk/texlive/linked_scripts/tikztosvg/tikztosvg b/Build/source/texk/texlive/linked_scripts/tikztosvg/tikztosvg
index 8e9523347c4..664aea37020 100755
--- a/Build/source/texk/texlive/linked_scripts/tikztosvg/tikztosvg
+++ b/Build/source/texk/texlive/linked_scripts/tikztosvg/tikztosvg
@@ -1,181 +1,203 @@
-#!/bin/bash
+#!/bin/sh
puts()
{
- echo "[$1] $2"
+ printf "\033[1m\033[38;5;%sm[%s]\033[m %s\n" "$3" "$1" "$2"
}
error()
{
- puts "ERROR" "$1" r
-
- if [ -n "$2" ]
- then
- exit $2
- else
- exit 1
- fi
+ puts "ERROR" "$1" "9"
+
+ if [ -n "$2" ]
+ then
+ exit "$2"
+ else
+ exit 1
+ fi
}
message()
{
- puts "TIKZTOSVG" "$1" g
+ puts "TIKZTOSVG" "$1" "2"
}
showHelp()
{
- man tikztosvg
- exit 0
+ man tikztosvg
+ exit 0
}
showVersion()
{
- echo 0.1.0
- exit 0
+ echo 0.1.2
+ exit 0
}
-if [ -z "$(which xelatex)" ]
+if ! [ -x "$(command -v xelatex)" ]
then
- error "xelatex could not be found"
+ error "xelatex could not be found"
fi
-if [ -z "$(which pdf2svg)" ]
+if ! [ -x "$(command -v pdf2svg)" ]
then
- error "pdf2svg could not be found"
+ error "pdf2svg could not be found"
fi
# Parsing the arguments
-PACKAGES=()
+PACKAGES=""
while [ $# -gt 1 ]
do
- case "$1" in
- -h|--help)
- showHelp
- ;;
- -v|--version)
- showVersion
- ;;
- -p|--package)
- if [ -z "$2" ]
- then
- error "Unnexpected EOF"
- else
- PACKAGES+=("$2")
- shift
- shift
- fi
- ;;
- -o|--output)
- if [ -n "$OUTPUT" ]
- then
- error "The output path was specified multiple times"
- else if [ -z "$2" ]
- then
- error "Unexpected EOF"
- exit 1
- else
- OUTPUT="$2"
- shift
- shift
- fi
- fi
- ;;
- -q|--quit)
- QUIET=1
- shift
- ;;
- *)
- error "Unexpected token: \"$1\""
- ;;
- esac
+ case "$1" in
+ -h|--help)
+ showHelp
+ ;;
+ -v|--version)
+ showVersion
+ ;;
+ -p|--package)
+ case "$2" in
+ "")
+ error "Unnexpected EOF"
+ ;;
+ # Check if the name of the package is valid
+ *" "*)
+ error "Invalid package name. LaTeX package names cannot contain scapes!"
+ ;;
+ *)
+ PACKAGES="$PACKAGES $2"
+ shift
+ shift
+ esac
+ ;;
+ -o|--output)
+ if [ -n "$OUTPUT" ]
+ then
+ error "The output path was specified multiple times"
+ elif [ -z "$2" ]
+ then
+ error "Unexpected EOF"
+ else
+ OUTPUT="$2"
+ shift
+ shift
+ fi
+ ;;
+ -q|--quit)
+ QUIET=1
+ shift
+ ;;
+ *)
+ error "Unexpected token: \"$1\""
+ ;;
+ esac
done
case "$1" in
- -h|--help)
- showHelp
- ;;
- -v|--version)
- showVersion
- ;;
- "")
- error "No input path provided"
- ;;
- *)
- INPUT="$1"
+ -h|--help)
+ showHelp
+ ;;
+ -v|--version)
+ showVersion
+ ;;
+ "")
+ error "No input path provided"
+ ;;
+ "-")
+ INPUT=/dev/stdin
+ ;;
+ *)
+ INPUT="$1"
+ ;;
esac
-if [ -z "$OUTPUT" ]
-then
- OUTPUT="$(echo $(basename $INPUT) | cut -d "." -f1)"
-fi
+case "$OUTPUT" in
+ # Set the output to stdout
+ -)
+ QUIET=1
+ OUTPUT=/dev/stdout
+ ;;
+
+ # If no output path is provided, use the basename of the input
+ "")
+ if [ -x "$(command -v dirname)" ]
+ then
+ OUTPUT="$(dirname "$INPUT")/$(basename "$INPUT" | cut -d "." -f1).svg"
+ fi
+ ;;
+
+ # If the output path is provided, but it resolves to directory, output a
+ # a file with the same basename as the input in the target directory
+ */)
+ OUTPUT="$OUTPUT$(basename "$INPUT" | cut -d "." -f1).svg"
+ ;;
+esac
TEMP_DIR="$(mktemp -d)"
TEX_FILE="$TEMP_DIR/tmp.tex"
# Generate the LaTeX document
-echo "\documentclass[crop,tikz,multi=false]{standalone}" > $TEX_FILE
+printf "\documentclass[crop,tikz,multi=false]{standalone}\n" > "$TEX_FILE"
-for PACKAGE in "${PACKAGES[@]}"
+for PACKAGE in $PACKAGES
do
- echo "\usepackage{$PACKAGE}" >> $TEX_FILE
+ printf "\usepackage{%s}\n" "$PACKAGE" >> "$TEX_FILE"
done
-echo "\begin{document}" >> $TEX_FILE
-echo "\huge" >> $TEX_FILE
-
-cat $INPUT >> $TEX_FILE
+printf "\\\begin{document} \huge\n" >> "$TEX_FILE"
+cat "$INPUT" >> "$TEX_FILE"
if [ $? -ne 0 ]
then
- rm $TEMP_DIR -r
- error "File not found: $INPUT"
+ rm "$TEMP_DIR" -r
+ error "File not found: $INPUT"
fi
-echo "\end{document}" >> $TEX_FILE
+printf "\\\end{document}\n" >> "$TEX_FILE"
if [ -z "$QUIET" ]
then
- message "Rendering the LaTeX document. . ."
- xelatex -output-directory=$TEMP_DIR $TEX_FILE
+ message "Rendering the LaTeX document. . ."
+ xelatex -halt-on-error -output-directory="$TEMP_DIR" "$TEX_FILE"
else
- xelatex -halt-on-error -output-directory=$TEMP_DIR $TEX_FILE 1> /dev/null 2>&1
+ xelatex -halt-on-error -output-directory="$TEMP_DIR" "$TEX_FILE" 1> /dev/null 2>&1
fi
S=$?
if [ $S -ne 0 ]
then
- rm $TEMP_DIR -r
- if [ -z "$QUIET" ]
- then
- error "xelatex exited with code $S" $S
- else
- exit $S
- fi
+ rm "$TEMP_DIR" -r
+ if [ -z "$QUIET" ]
+ then
+ error "xelatex exited with code $S" $S
+ else
+ exit $S
+ fi
fi
if [ -z "$QUIET" ]
then
- message "Converting the output to SVG. . ."
+ message "Converting the output to SVG. . ."
fi
-pdf2svg "$TEMP_DIR/tmp.pdf" $OUTPUT 1
+pdf2svg "$TEMP_DIR/tmp.pdf" "$OUTPUT" 1
S=$?
if [ $S -ne 0 ]
then
- rm $TEMP_DIR -r
- if [ -z "$QUIET" ]
- then
- error "pdf2svg exited with code $S" $S
- else
- exit $S
- fi
+ rm "$TEMP_DIR" -r
+ if [ -z "$QUIET" ]
+ then
+ error "pdf2svg exited with code $S" $S
+ else
+ exit $S
+ fi
fi
if [ -z "$QUIET" ]
then
- message "Done!"
+ message "Done!"
fi
-rm "$TEMP_DIR" -r
+rm "$TEMP_DIR" -rf