Created
October 9, 2024 07:58
-
-
Save 7enderhead/012f657d4c56309c0faa36d128777d8a to your computer and use it in GitHub Desktop.
Create Pandoc Beamer Presentations in Full and Incremental Mode With and Without Footers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Initialize default values | |
full=false | |
incremental=false | |
# Function to display usage instructions | |
usage() { | |
echo "Usage: $0 [OPTIONS] output_base_name" | |
echo "Options:" | |
echo " -f, --full generate full version with all bullet points on one page" | |
echo " -i, --incremental generate version with incremental bullet points" | |
echo " -h, --help show this help message" | |
exit 1 | |
} | |
#args: in_md ypp_output_file mode ("full" or "incremental") | |
run-ypp() { | |
ypp_command="ypp -e 'mode=\"$3\"' $1 -o $2" | |
echo -n "Running ypp preprocessor on $1 with mode '$3', generating $2... " | |
eval ${ypp_command} | |
echo "done." | |
} | |
# Parse options | |
PARSED_OPTIONS=$(getopt -o fih --long full,incremental,help -- "$@") | |
if [ $? -ne 0 ]; then | |
usage | |
fi | |
# Note the quotes around `$PARSED_OPTIONS`: they are essential! | |
eval set -- "$PARSED_OPTIONS" | |
# Parse command-line arguments | |
while true; do | |
case "$1" in | |
-i|--incremental) | |
incremental=true | |
shift | |
;; | |
-f|--full) | |
full=true | |
shift | |
;; | |
-h|--help) | |
usage | |
;; | |
--) | |
shift | |
break | |
;; | |
*) | |
echo "Invalid option: $1" | |
usage | |
;; | |
esac | |
done | |
# Ensure one of the building switches is present | |
if ! $full && ! $incremental; then | |
echo "Error: Either -f (full) or -i (incremental) must be specified, otherwise nothing will happen." | |
usage | |
fi | |
if [ $# -ne 1 ]; then | |
echo "Missing mandatory output 'base name parameter'." | |
usage | |
exit 1 | |
fi | |
base_name=$1 | |
in_md="${base_name}.ypp.md" | |
out_md_full="${base_name}-full.md" | |
out_md_inc="${base_name}-inc.md" | |
base_command="pandoc -f markdown+smart --filter pandoc-plantuml --filter pandoc-include -t beamer --standalone" | |
full_command="${base_command} -V mode=full -o ${base_name}-full.pdf ${out_md_full}" | |
incremental_command="${base_command} -i -V mode=incremental -o ${base_name}-inc.pdf ${out_md_inc}" | |
# Main script logic | |
if $full; then | |
run-ypp ${in_md} ${out_md_full} "full" | |
echo -n "Generating full output for ${base_name}... " | |
eval ${full_command} | |
echo "done." | |
fi | |
if $incremental; then | |
run-ypp ${in_md} ${out_md_inc} "incremental" | |
echo -n "Generating incremental output for ${base_name}... " | |
eval ${incremental_command} | |
echo "done." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
header-includes
) use something like thismode=="full"
andmode=="incremental"
-i
(incremental) parameter for Beamer accordingly