From 2efaed51f9d02655ebb6892ea0fa7969d2967c66 Mon Sep 17 00:00:00 2001 From: Francesco Urbani Date: Mon, 22 Mar 2021 14:48:21 +0100 Subject: [PATCH] added script to generate a pdf with pandoc. --- .gitignore | 5 ++++- createPdfFromReadme.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100755 createPdfFromReadme.sh diff --git a/.gitignore b/.gitignore index c63807c..d87b2fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# macOS garbage +.DS_Store + snippets book - +latex diff --git a/createPdfFromReadme.sh b/createPdfFromReadme.sh new file mode 100755 index 0000000..2da1206 --- /dev/null +++ b/createPdfFromReadme.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Execute this script to generate a PDF version from the single Readme.md file present in this repository. +# Usage: ./createPdfFromReadme.sh + +# -------------------- Utility Methods -------------------- +# Check for binaries +function checkEnvironment(){ + type pandoc >/dev/null 2>&1 || { echo "Install 'pandoc' first (e.g. via 'brew install pandoc')." >&2 && exit 1 ; } + type xelatex >/dev/null 2>&1 || { echo "Install 'xelatex' first" >&2 && exit 1 ; } +} + +# Cleanup the src directory before starting +function cleanupBeforeStarting(){ + rm -rf ./latex + mkdir latex +} + + +# Creates the summary from the generated chapters +function convertToLatex(){ + cd ./latex + + cp ../*.png . + + pandoc ../README.md -V geometry:margin=0.7in --standalone --from markdown --to latex > readme.tex + echo "Generated readme.tex file." + cp readme.tex easy_rust.tex + + xelatex --interaction=nonstopmode easy_rust.tex + echo "Generated PDF file easy_rust.pdf" + + cd .. +} + + + +# -------------------- Steps to create the mdBook version -------------------- +checkEnvironment +cleanupBeforeStarting +convertToLatex