Fix compile script
Fixed compile script to not use ifinstalled anymore. HACK Fixed compile script to correctly pass through output targets to RMarkdown, through the implementation is very rough currently. It will look for additional arguments passed through and run RMarkdown rendering once for each target. It would presumably be faster (and at the very least more elegant) to pass all arguments through at once, but I am not sure how to pass arguments through shell surrounded with quotes.
This commit is contained in:
parent
145548c01a
commit
b76b3ca4ca
1 changed files with 18 additions and 7 deletions
|
@ -11,8 +11,13 @@
|
|||
# Expects the file to compile as first argument.
|
||||
# Desired output format(s) can be specified in optional arguments following.
|
||||
|
||||
file=$(readlink -f "$1")
|
||||
printf "file: %s\n" "$file"
|
||||
file=$1
|
||||
if [ ! -f "$file" ]; then
|
||||
echo "File does not exist."
|
||||
exit 1
|
||||
else
|
||||
printf "file: %s\n" "$file"
|
||||
fi
|
||||
|
||||
if [ "$#" -gt 1 ]; then
|
||||
shift
|
||||
|
@ -25,9 +30,9 @@ base="${file%.*}"
|
|||
cd "$dir" || exit
|
||||
|
||||
textype() {
|
||||
if (sed 5q "$file" | grep -i -q 'xelatex') && ifinstalled xelatex; then
|
||||
if (sed 5q "$file" | grep -i -q 'xelatex') && exist xelatex; then
|
||||
command="xelatex"
|
||||
elif ifinstalled pdflatex; then
|
||||
elif exist pdflatex; then
|
||||
command="pdflatex"
|
||||
fi
|
||||
$command --output-directory="$dir" "$base" &&
|
||||
|
@ -38,10 +43,16 @@ textype() {
|
|||
}
|
||||
|
||||
sendtoRmd() {
|
||||
# v removed for too much magic that can break; simply input pdf_document if you want it
|
||||
# formats=$(echo "$formats" | perl -pe 's/([\w-]+)(?<!_document)\b/"\1_document"/gm' | tr ' ' ',')
|
||||
printf "formats: %s\n" "$formats"
|
||||
ifinstalled R && echo "require(rmarkdown); render('$1', c($formats))" | R -q --vanilla
|
||||
## FIXME this is horribly inefficient, should just pass all formats to R
|
||||
# but R expects them as "strings" and I don't know how to quote the individual words
|
||||
if [ -n "$formats" ]; then
|
||||
for fmt in $formats; do
|
||||
exist R critical && echo "require(rmarkdown); render('$1', c(\"$fmt\"))" | R -q --vanilla
|
||||
done
|
||||
else
|
||||
exist R critical && echo "require(rmarkdown); render('$1')" | R -q --vanilla
|
||||
fi
|
||||
}
|
||||
|
||||
case "$file" in
|
||||
|
|
Loading…
Reference in a new issue