Add support for building book in epub format
Add epub metadata & placeholder cover image Refactor parseBook.py and extend Makefile to enable support for more formats Update appendix 2 Add book.epub to .gitignore
This commit is contained in:
parent
967c5cced1
commit
3c85984cb0
|
|
@ -4,6 +4,7 @@ tmp.md
|
||||||
tmp*.png
|
tmp*.png
|
||||||
book.tex
|
book.tex
|
||||||
book.pdf
|
book.pdf
|
||||||
|
book.epub
|
||||||
log/*
|
log/*
|
||||||
/.idea
|
/.idea
|
||||||
.idea/
|
.idea/
|
||||||
|
|
|
||||||
13
Makefile
13
Makefile
|
|
@ -1,3 +1,5 @@
|
||||||
|
.PHONY: default clean all epub pdf tex
|
||||||
|
|
||||||
default: clean all
|
default: clean all
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
@ -6,4 +8,13 @@ clean:
|
||||||
rm -rf book.*
|
rm -rf book.*
|
||||||
|
|
||||||
all:
|
all:
|
||||||
python2.7 src/parseBook.py
|
python2.7 src/parseBook.py -f tex -f pdf -f epub
|
||||||
|
|
||||||
|
epub:
|
||||||
|
python2.7 src/parseBook.py -f epub
|
||||||
|
|
||||||
|
pdf:
|
||||||
|
python2.7 src/parseBook.py -f pdf
|
||||||
|
|
||||||
|
tex:
|
||||||
|
python2.7 src/parseBook.py -f tex
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,7 @@ For printing this book you need first to parse it. For that you will need [`glsl
|
||||||
In **MacOSX** get sure to have [homebrew](http://brew.sh/) installed and then on your terminal do:
|
In **MacOSX** get sure to have [homebrew](http://brew.sh/) installed and then on your terminal do:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
brew update
|
brew install glslviewer
|
||||||
brew upgrade
|
|
||||||
brew tap homebrew/versions
|
|
||||||
brew install glfw3
|
|
||||||
cd ~
|
|
||||||
git clone http://github.com/patriciogonzalezvivo/glslViewer.git
|
|
||||||
cd glslViewer
|
|
||||||
make
|
|
||||||
make install
|
|
||||||
```
|
```
|
||||||
|
|
||||||
On **Raspberry Pi** you need to get [Raspbian](https://www.raspberrypi.org/downloads/raspbian/), a Debian-based Linux distribution made for Raspberry Pi and then do:
|
On **Raspberry Pi** you need to get [Raspbian](https://www.raspberrypi.org/downloads/raspbian/), a Debian-based Linux distribution made for Raspberry Pi and then do:
|
||||||
|
|
@ -35,16 +27,16 @@ For parsing the Markdown chapters into Latex and then into a PDF file we will us
|
||||||
|
|
||||||
In **MacOSX**:
|
In **MacOSX**:
|
||||||
|
|
||||||
Download and Install [basictex & MacTeX-Additions] by:
|
Download and Install MacTeX by:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
brew cask install mactex-no-gui
|
brew cask install mactex-no-gui
|
||||||
```
|
```
|
||||||
|
|
||||||
and then install [Pandoc](http://johnmacfarlane.net/pandoc/), Python 2 & glslViewer by:
|
and then install [Pandoc](http://johnmacfarlane.net/pandoc/) and Python 2 by:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
brew install pandoc python@2 glslviewer
|
brew install pandoc python@2
|
||||||
```
|
```
|
||||||
|
|
||||||
On **Raspberry Pi** (Raspbian):
|
On **Raspberry Pi** (Raspbian):
|
||||||
|
|
@ -63,7 +55,18 @@ For that open your terminal once again and type:
|
||||||
cd ~
|
cd ~
|
||||||
git clone https://github.com/patriciogonzalezvivo/thebookofshaders.git
|
git clone https://github.com/patriciogonzalezvivo/thebookofshaders.git
|
||||||
cd thebookofshaders
|
cd thebookofshaders
|
||||||
make
|
make clean pdf
|
||||||
```
|
```
|
||||||
|
|
||||||
If everything goes well, you will see a `book.pdf` file which you can read on your favorite device or print.
|
If everything goes well, you will see a `book.pdf` file which you can read on your favorite device or print.
|
||||||
|
|
||||||
|
#### Compile the book into an epub for use with an e-reader
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd ~
|
||||||
|
git clone https://github.com/patriciogonzalezvivo/thebookofshaders.git
|
||||||
|
cd thebookofshaders
|
||||||
|
make clean epub
|
||||||
|
```
|
||||||
|
|
||||||
|
The generated `book.epub` can be used directly, or converted to a `.mobi` file for use with Kindle by using a converter, for example Calibre.
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 558 KiB |
Binary file not shown.
|
|
@ -0,0 +1,5 @@
|
||||||
|
<dc:title>The Book of Shaders</dc:title>
|
||||||
|
<dc:language>en-US</dc:language>
|
||||||
|
<dc:creator opf:file-as="Gonzalez Vivo, Patricio" opf:role="aut">Patricio Gonzalez Vivo</dc:creator>
|
||||||
|
<dc:creator opf:file-as="Lowe, Jen" opf:role="aut">Jen Lowe</dc:creator>
|
||||||
|
<dc:rights>Copyright 2015 by Patricio Gonzalez Vivo & Jen Lowe</dc:rights>
|
||||||
|
|
@ -4,6 +4,12 @@ import os
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("-f", "--format", action='append', choices=['tex', 'pdf', 'epub'], type=str.lower, required=True)
|
||||||
|
parser.add_argument("--skip-image-generation", help="skip image generation", action="store_true")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
latexEngine = "xelatex"
|
latexEngine = "xelatex"
|
||||||
|
|
||||||
|
|
@ -12,12 +18,9 @@ outputPath = "."
|
||||||
|
|
||||||
if not os.path.exists(outputPath):
|
if not os.path.exists(outputPath):
|
||||||
os.makedirs(outputPath)
|
os.makedirs(outputPath)
|
||||||
pdfBookPath = os.path.join(outputPath, "book.pdf")
|
|
||||||
texBookPath = os.path.join(outputPath, "book.tex")
|
|
||||||
|
|
||||||
chapters = []
|
chapters = []
|
||||||
|
|
||||||
|
|
||||||
def injectShaderBlocks(_folder, _text):
|
def injectShaderBlocks(_folder, _text):
|
||||||
rta = ""
|
rta = ""
|
||||||
lines = _text.split('\n')
|
lines = _text.split('\n')
|
||||||
|
|
@ -44,7 +47,8 @@ def injectShaderBlocks(_folder, _text):
|
||||||
" ".join(shaderTexturePaths) + \
|
" ".join(shaderTexturePaths) + \
|
||||||
" -s 0.5 --headless -o " + shaderImage
|
" -s 0.5 --headless -o " + shaderImage
|
||||||
print shaderCommand
|
print shaderCommand
|
||||||
returnCode = subprocess.call(shaderCommand, shell=True)
|
if not args.skip_image_generation:
|
||||||
|
returnCode = subprocess.call(shaderCommand, shell=True)
|
||||||
rta += "\n"
|
rta += "\n"
|
||||||
elif line.find('.gif') >= 0:
|
elif line.find('.gif') >= 0:
|
||||||
gifPath = re.sub(r'\!\[.*\]\((.*\.gif)\)', r'\1', line.rstrip())
|
gifPath = re.sub(r'\!\[.*\]\((.*\.gif)\)', r'\1', line.rstrip())
|
||||||
|
|
@ -52,7 +56,8 @@ def injectShaderBlocks(_folder, _text):
|
||||||
pngImage = gifName + ".png"
|
pngImage = gifName + ".png"
|
||||||
convertCommand = "convert " + gifPath + " " + pngImage
|
convertCommand = "convert " + gifPath + " " + pngImage
|
||||||
print convertCommand
|
print convertCommand
|
||||||
returnCode = subprocess.call(convertCommand, shell=True)
|
if not args.skip_image_generation:
|
||||||
|
returnCode = subprocess.call(convertCommand, shell=True)
|
||||||
rta += re.sub(r'\!\[(.*)\]\((.*)\.gif\)',
|
rta += re.sub(r'\!\[(.*)\]\((.*)\.gif\)',
|
||||||
r'', line) + '\n'
|
r'', line) + '\n'
|
||||||
else:
|
else:
|
||||||
|
|
@ -83,36 +88,33 @@ for folder in folders:
|
||||||
|
|
||||||
# Set up the appropriate options for the pandoc command
|
# Set up the appropriate options for the pandoc command
|
||||||
inputOptions = chapters
|
inputOptions = chapters
|
||||||
generalOptions = ["-N", "--toc", "--standalone",
|
generalOptions = ["-N", "--toc", "--standalone",
|
||||||
"--preserve-tabs", "-V documentclass=scrbook", "-V papersize=a4", "-V links-as-note"]
|
"--preserve-tabs", "-V documentclass=scrbook",
|
||||||
|
"-V papersize=a4", "-V links-as-note"]
|
||||||
latexOptions = ["--pdf-engine=" + latexEngine]
|
latexOptions = ["--pdf-engine=" + latexEngine]
|
||||||
outputOptions = ["--output={0}".format(pdfBookPath)]
|
|
||||||
pandocCommand = ["pandoc"] + outputOptions + \
|
|
||||||
inputOptions + generalOptions + latexOptions
|
|
||||||
|
|
||||||
# Print out of the chapters being built and the flags being used
|
for outputFormat in args.format:
|
||||||
print "Generating {0} from:".format(pdfBookPath)
|
bookPath = os.path.join(outputPath, "book.{0}".format(outputFormat))
|
||||||
for chapter in inputOptions:
|
formatOutputOptions = []
|
||||||
print "\t{0}".format(chapter)
|
|
||||||
print "Using the following flags:"
|
|
||||||
for flag in generalOptions + latexOptions:
|
|
||||||
print "\t{0}".format(flag)
|
|
||||||
|
|
||||||
# For debugging purposes, it's a good idea to generate the .tex. Errors
|
if outputFormat == 'epub':
|
||||||
# printed out through pandoc aren't as useful as those printed
|
formatOutputOptions = ["--epub-metadata=epub/metadata.xml",
|
||||||
# directly from trying to build a PDF in TeXworks.
|
"--epub-cover-image=epub/cover.png"]
|
||||||
texOutputOptions = ["--output={0}".format(texBookPath)]
|
|
||||||
texPandocCommand = ["pandoc"] + texOutputOptions + \
|
|
||||||
inputOptions + generalOptions + latexOptions
|
|
||||||
returnCode = subprocess.call(texPandocCommand)
|
|
||||||
if returnCode == 0:
|
|
||||||
print "Successful building of {0}".format(texBookPath)
|
|
||||||
else:
|
|
||||||
print "Error in building of {0}".format(texBookPath)
|
|
||||||
|
|
||||||
# Call pandoc
|
outputOptions = ["--output={0}".format(bookPath)] + formatOutputOptions
|
||||||
returnCode = subprocess.call(pandocCommand)
|
pandocCommand = ["pandoc"] + inputOptions + outputOptions \
|
||||||
if returnCode == 0:
|
+ generalOptions + latexOptions
|
||||||
print "Successful building of {0}".format(pdfBookPath)
|
|
||||||
else:
|
# Print out of the chapters being built and the flags being used
|
||||||
print "Error in building of {0}".format(pdfBookPath)
|
print "Generating {0} from:".format(bookPath)
|
||||||
|
for chapter in inputOptions:
|
||||||
|
print "\t{0}".format(chapter)
|
||||||
|
print "Using the following flags:"
|
||||||
|
for flag in outputOptions + generalOptions + latexOptions:
|
||||||
|
print "\t{0}".format(flag)
|
||||||
|
|
||||||
|
returnCode = subprocess.call(pandocCommand)
|
||||||
|
if returnCode == 0:
|
||||||
|
print "Successful building of {0}".format(bookPath)
|
||||||
|
else:
|
||||||
|
print "Error in building of {0}".format(bookPath)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue