Fixed PDF generation in Windows

This commit is contained in:
Roger Labbe 2015-04-04 10:30:50 -07:00
parent c92aaee306
commit 7f2b152c9d
4 changed files with 21 additions and 22 deletions

View File

@ -1,7 +1,6 @@
python merge_book.py >Kalman_and_Bayesian_Filters_in_Python.ipynb
ipython nbconvert --to pdf --template book Kalman_and_Bayesian_Filters_in_Python.ipynb
python merge_book.py
ipython nbconvert --to latex --template book book.ipynb
ipython to_pdf.py
move /Y book.pdf ../Kalman_and_Bayesian_Filters_in_Python.pdf

View File

@ -1,14 +1,12 @@
#! /bin/bash
REM WINDOWS script to delete all files
rm --f *.tex
rm --f *.toc
rm --f ./*_files/*.png
rm --f Kalman_and_Bayesian_Filters_in_Python.ipynb
rm --f Kalman_and_Bayesian_Filters_in_Python.toc
rm --f Kalman_and_Bayesian_Filters_in_Python.tex
rmdir ./*_files/ 2> /dev/null
rm --f *.aux
rm --f *.log
rm --f *.out
if (( $# == 1)); then
if [ "@1" == all ]; then
rm Kalman_and_Bayesian_Filters_in_Python.pdf;
fi
fi
rm --f book.ipynb
rm --f book.toc
rm --f book.tex
rmdir /S /Q book_files

View File

@ -5,7 +5,7 @@ import sys
from formatting import *
def merge_notebooks(filenames):
def merge_notebooks(outfile, filenames):
merged = None
added_appendix = False
for fname in filenames:
@ -23,16 +23,17 @@ def merge_notebooks(filenames):
merged.cells.extend(nb.cells)
#merged.metadata.name += "_merged"
print(nbformat.writes(merged, nbformat.NO_CONVERT))
outfile.write(nbformat.writes(merged, nbformat.NO_CONVERT))
if __name__ == '__main__':
f = open('book.ipynb', 'w', encoding='utf-8')
'''merge_notebooks(
['../00_Preface.ipynb',
'../01_g-h_filter.ipynb',
'../Appendix_A_Installation.ipynb'])'''
merge_notebooks(
merge_notebooks(f,
['../00_Preface.ipynb',
'../01_g-h_filter.ipynb',
'../02_Discrete_Bayes.ipynb',

View File

@ -4,10 +4,11 @@ import io
import IPython.nbconvert.exporters.pdf as pdf
import fileinput
for line in fileinput.input('Kalman_and_Bayesian_Filters_in_Python.tex', inplace=True):
print(line.replace('\chapter{Preface}', '\chapter*{Preface}'), end='')
for line in fileinput.input('book.tex', openhook=fileinput.hook_encoded("iso-8859-1")):
# print(line.replace('\chapter{Preface}', '\chapter*{Preface}'), end='')
line.replace('\chapter{Preface}', '\chapter*{Preface}')
p = pdf.PDFExporter()
p.run_latex('Kalman_and_Bayesian_Filters_in_Python.tex')
p.run_latex('book.tex')