Skip to content

Instantly share code, notes, and snippets.

@7enderhead
Created October 9, 2024 07:58
Show Gist options
  • Save 7enderhead/012f657d4c56309c0faa36d128777d8a to your computer and use it in GitHub Desktop.
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
#!/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
@7enderhead
Copy link
Author

7enderhead commented Oct 9, 2024

  • uses the ypp preprocessor to put in the source for the footer in full mode
  • in Pandoc's YAML header for LaTeX (header-includes) use something like this
@when(mode=="full") [[
  % LaTeX Beamer stuff to create a footer
]]
  • the script runs ypp twice with mode=="full" and mode=="incremental"
  • Pandoc invocations set the -i (incremental) parameter for Beamer accordingly
  • typically, run a monitoring script like
#!/usr/bin/env bash
base_name="$1"
shift
options="$@"
command="gen-panbeam.sh ${options} ${base_name}"
${command} # initial run
inotify-hookable -f ${base_name}.ypp.md -c "${command}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment