forked from Dhghomon/easy_rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatePdfFromReadme.sh
More file actions
executable file
·51 lines (37 loc) · 2.09 KB
/
createPdfFromReadme.sh
File metadata and controls
executable file
·51 lines (37 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/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' or 'apt-get 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 . # copy Easy_Rust_sample_image.png in the current folder in order to be found.
# Step 1: run pandoc on README.md which generates the `.tex` file.
# Commands used previously (didn't require metadata.yaml). Left here for reference...
# pandoc ../README.md -V geometry:margin=0.7in -V colorlinks=true -V linkcolor=blue -V urlcolor=blue -V toccolor=gray --standalone --from markdown --to latex > easy_rust.tex
# pandoc ../README.md --standalone --from markdown --to latex > easy_rust.tex
# generates `easy_rust.tex` in the current folder using the instructions given inside `../pdf_metadata.yaml`.
pandoc ../README.md ../pdf_metadata.yaml -s -o easy_rust.tex # --toc # The `toc` flag can be added or not depending on personal preferences.
# If added, the `xelatex` command right below needs to be run twice (the first time.)
echo "Generated easy_rust.tex file."
# Step 2: run `xelatex` on the `.tex` file to geneate the PDF.
xelatex --interaction=nonstopmode easy_rust.tex
# to generate the TOC you need to run this twice
# xelatex --interaction=nonstopmode easy_rust.tex
echo "Generated PDF file easy_rust.pdf"
cd ..
}
# -------------------- Steps to create the mdBook version --------------------
checkEnvironment
cleanupBeforeStarting
convertToLatex