Skip to content

Instantly share code, notes, and snippets.

@clemsos
Last active August 7, 2023 04:14
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save clemsos/9e480b2b792b57f1b22d to your computer and use it in GitHub Desktop.
Save clemsos/9e480b2b792b57f1b22d to your computer and use it in GitHub Desktop.
Build Gitbook PDF using Pandoc
# #!/bin/bash
GITBOOK_REP=$1
SUMMARY_FILE="SUMMARY.md"
echo $OUTPUT_FILE
if [ -d "$GITBOOK_REP" ]; then
echo "Entering directory '$GITBOOK_REP'..."
cd $GITBOOK_REP
if [ -f "$SUMMARY_FILE" ]; then
# read summary and get texts by order in a single big file
pandoc $SUMMARY_FILE -t html | \
grep -o '<a href=['"'"'"][^"'"'"']*['"'"'"]' | \
sed -e 's/^<a href=["'"'"']//' -e 's/["'"'"']$//'| \
xargs cat | \
pandoc -f markdown --variable fontsize=10pt \
--variable=geometry:b5paper \
--variable mainfont="Arial" \
--variable documentclass=scrbook --toc --latex-engine=xelatex -o book.pdf
else
echo "File '$SUMMARY_FILE' does not exist"
fi
else
echo "Directory '$GITBOOK_REP' does not exist"
fi
@clemsos
Copy link
Author

clemsos commented Mar 6, 2016

This will generate a PDF from a set of markdown files described by links in SUMMARY.md (gitbook format)

@skilesare
Copy link

I kiss you!

@f-r-i-t-z
Copy link

Thank you!!

@mauricioaniche
Copy link

latex-engine was deprecated. Replace it by --pdf-engine=xelatex.

@gvanem
Copy link

gvanem commented Dec 10, 2021

Isn't possible to simplify the list of .MD files by e.g.:
MD_FILES = grep -o '[a-z0-9/-]\+\.md' SUMMARY.md | grep -v index.md

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