From 1c4e16ab85d130d4a91d3a72dc2622a750225267 Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Mon, 6 Jan 2025 17:20:18 -0700 Subject: [PATCH] Adding new pandoc shell script (adapted from elisp) --- .scripts/panda.sh | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 .scripts/panda.sh diff --git a/.scripts/panda.sh b/.scripts/panda.sh new file mode 100755 index 0000000..5fbc68e --- /dev/null +++ b/.scripts/panda.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# PANDA, a wrapper for pandoc by ntnsndr + +# Check if the required arguments are provided +if [ $# -lt 1 ]; then + echo "Usage: $0 [required-filename] [output format]" + exit 1 +fi + +# Set the filename +FILENAME=$1 + +# Set the output format to html if not provided +if [ $# -eq 1 ]; then + OUTPUT_FORMAT="html" +else + OUTPUT_FORMAT=$2 +fi + +# Check if the input file exists +if [ ! -f $FILENAME ]; then + echo "Error: Input file '$FILENAME' does not exist." + exit 1 +fi + +# Set the file extension based on the output format +case $OUTPUT_FORMAT in + pdf) + FILE_EXT="pdf" + OUTPUT_FORMAT="latex --variable fontsize='11pt'" + ;; + reveal) + FILE_EXT="html" + OUTPUT_FORMAT="revealjs --standalone --embed-resources -V revealjs-url='/home/ntnsndr/.revealjs/reveal.js' -V theme=ntn -V controls=false --slide-level=2" + ;; + pptx) + FILE_EXT="pptx" + OUTPUT_FORMAT="pptx --reference-doc='/home/ntnsndr/.templates/Slideshow.pptx'" + ;; + *) + FILE_EXT=$OUTPUT_FORMAT + ;; +esac + +# Create temporary files +TMP_IN_FILE="/tmp/pandoc-in.tmp" +TMP_OUT_FILE="/tmp/pandoc-out.$FILE_EXT" + +# Check if the temporary files can be created +if [ ! -w /tmp ]; then + echo "Error: Cannot create temporary files in '/tmp' directory." + exit 1 +fi + +# Copy the input file to the temporary file +cp $FILENAME $TMP_IN_FILE + +# Convert the file using pandoc +iconv -t utf-8 $TMP_IN_FILE | pandoc -s -f markdown+smart --citeproc --bibliography $HOME/Zotero/lib.bib --pdf-engine=xelatex -t $OUTPUT_FORMAT -o $TMP_OUT_FILE + +# Check if the pandoc command is successful +if [ $? -ne 0 ]; then + echo "Error: Pandoc command failed." + exit 1 +fi + +# Open the output file +xdg-open $TMP_OUT_FILE + +# Check if the output file can be opened +if [ $? -ne 0 ]; then + echo "Error: Cannot open output file '$TMP_OUT_FILE'." + exit 1 +fi +