From 7f2b152c9dad5fa95584980252bd5d6bdd5dacde Mon Sep 17 00:00:00 2001 From: Roger Labbe Date: Sat, 4 Apr 2015 10:30:50 -0700 Subject: [PATCH] Fixed PDF generation in Windows --- pdf/build_book.bat | 9 ++++----- pdf/clean_book.bat | 20 +++++++++----------- pdf/merge_book.py | 7 ++++--- pdf/to_pdf.py | 7 ++++--- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/pdf/build_book.bat b/pdf/build_book.bat index 0e189e9..0c6ee1c 100644 --- a/pdf/build_book.bat +++ b/pdf/build_book.bat @@ -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 diff --git a/pdf/clean_book.bat b/pdf/clean_book.bat index c0dcd8c..3d6fdf8 100644 --- a/pdf/clean_book.bat +++ b/pdf/clean_book.bat @@ -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 diff --git a/pdf/merge_book.py b/pdf/merge_book.py index 3e501e1..b6d68c3 100644 --- a/pdf/merge_book.py +++ b/pdf/merge_book.py @@ -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', diff --git a/pdf/to_pdf.py b/pdf/to_pdf.py index 90795d8..96ce330 100644 --- a/pdf/to_pdf.py +++ b/pdf/to_pdf.py @@ -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')