Moved book generation code into PDF directory
Start of a reorganization of files to make book more browable and to reduce the size of links to chapters.
This commit is contained in:
0
pdf/__init__.py
Normal file
0
pdf/__init__.py
Normal file
27
pdf/book.tplx
Normal file
27
pdf/book.tplx
Normal file
@@ -0,0 +1,27 @@
|
||||
((* extends 'report.tplx' *))
|
||||
|
||||
%===============================================================================
|
||||
% Latex Book
|
||||
%===============================================================================
|
||||
|
||||
|
||||
((* block title *))
|
||||
\title{Kalman and Bayesian Filters in Python}
|
||||
\author{Roger R Labbe Jr}
|
||||
\date{}
|
||||
\setcounter{secnumdepth}{3}
|
||||
\setcounter{tocdepth}{3}
|
||||
((* endblock title *))
|
||||
|
||||
((* block abstract *))\tableofcontents((* endblock abstract *))
|
||||
|
||||
% Define block headings
|
||||
% Note: latex will only number headings that aren't starred
|
||||
% (i.e. \subsection , but not \subsection* )
|
||||
|
||||
((* block h1 -*))\chapter((* endblock h1 -*))
|
||||
((* block h2 -*))\section((* endblock h2 -*))
|
||||
((* block h3 -*))\subsection((* endblock h3 -*))
|
||||
((* block h4 -*))\subsubsection((* endblock h4 -*))
|
||||
((* block h5 -*))\paragraph((* endblock h5 -*))
|
||||
((* block h6 -*))\subparagraph((* endblock h6 -*))
|
||||
1
pdf/book_to_pdf.bat
Normal file
1
pdf/book_to_pdf.bat
Normal file
@@ -0,0 +1 @@
|
||||
ipython nbconvert --to latex --template book --post PDF book.ipynb
|
||||
12
pdf/build_book
Executable file
12
pdf/build_book
Executable file
@@ -0,0 +1,12 @@
|
||||
#! /bin/bash
|
||||
|
||||
echo "merging book..."
|
||||
|
||||
python merge_book.py > Kalman_and_Bayesian_Filters_in_Python.ipynb
|
||||
|
||||
echo "creating pdf..."
|
||||
ipython nbconvert --to latex --template book --post PDF Kalman_and_Bayesian_Filters_in_Python.ipynb
|
||||
|
||||
mv Kalman_and_Bayesian_Filters_in_Python ..
|
||||
echo "done."
|
||||
|
||||
7
pdf/build_book.bat
Normal file
7
pdf/build_book.bat
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
python merge_book.py >Kalman_and_Bayesian_Filters_in_Python.ipynb
|
||||
|
||||
|
||||
ipython nbconvert --to latex --template book --post PDF Kalman_and_Bayesian_Filters_in_Python.ipynb
|
||||
|
||||
|
||||
13
pdf/build_book_html.sh
Executable file
13
pdf/build_book_html.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#! /bin/bash
|
||||
|
||||
echo "merging book..."
|
||||
|
||||
|
||||
echo "creating html..."
|
||||
ipython nbconvert --to=html table_of_contents.ipynb
|
||||
ipython nbconvert --to=html Preface.ipynb
|
||||
ipython nbconvert --to=html 01_gh_filter/g-h_filter.ipynb
|
||||
|
||||
|
||||
echo "done."
|
||||
|
||||
19
pdf/clean_book
Executable file
19
pdf/clean_book
Executable file
@@ -0,0 +1,19 @@
|
||||
#! /bin/bash
|
||||
rm --f *.tex
|
||||
rm --f *.toc
|
||||
rm --f *.aux
|
||||
rm --f *.log
|
||||
rm --f *.out
|
||||
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
|
||||
rm --f short.ipynb
|
||||
|
||||
rmdir ./*_files/ 2> /dev/null
|
||||
|
||||
if (( $# == 1)); then
|
||||
if [ "@1" == all ]; then
|
||||
rm Kalman_and_Bayesian_Filters_in_Python.pdf;
|
||||
fi
|
||||
fi
|
||||
14
pdf/clean_book.bat
Executable file
14
pdf/clean_book.bat
Executable file
@@ -0,0 +1,14 @@
|
||||
#! /bin/bash
|
||||
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
|
||||
|
||||
if (( $# == 1)); then
|
||||
if [ "@1" == all ]; then
|
||||
rm Kalman_and_Bayesian_Filters_in_Python.pdf;
|
||||
fi
|
||||
fi
|
||||
81
pdf/merge_book.py
Normal file
81
pdf/merge_book.py
Normal file
@@ -0,0 +1,81 @@
|
||||
from __future__ import print_function
|
||||
import io
|
||||
from IPython.nbformat import current
|
||||
import sys
|
||||
|
||||
|
||||
def remove_formatting(nb):
|
||||
w = nb['worksheets']
|
||||
node = w[0]
|
||||
c = node['cells']
|
||||
for i in range (len(c)):
|
||||
if 'input' in c[i].keys():
|
||||
if c[i]['input'][0:16] == '#format the book':
|
||||
del c[i]
|
||||
return
|
||||
|
||||
|
||||
def remove_links(nb):
|
||||
w = nb['worksheets']
|
||||
node = w[0]
|
||||
c = node['cells']
|
||||
for i in range (len(c)):
|
||||
if 'source' in c[i].keys():
|
||||
if c[i]['source'][0:19] == '[Table of Contents]':
|
||||
del c[i]
|
||||
return
|
||||
|
||||
|
||||
def remove_links_add_appendix(nb):
|
||||
w = nb['worksheets']
|
||||
node = w[0]
|
||||
c = node['cells']
|
||||
for i in range (len(c)):
|
||||
if 'source' in c[i].keys():
|
||||
if c[i]['source'][0:19] == '[Table of Contents]':
|
||||
c[i]['source'] = '\\appendix'
|
||||
return
|
||||
|
||||
|
||||
def merge_notebooks(filenames):
|
||||
merged = None
|
||||
added_appendix = False
|
||||
for fname in filenames:
|
||||
with io.open(fname, 'r', encoding='utf-8') as f:
|
||||
nb = current.read(f, u'json')
|
||||
remove_formatting(nb)
|
||||
if not added_appendix and fname[0:8] == 'Appendix':
|
||||
remove_links_add_appendix(nb)
|
||||
added_appendix = True
|
||||
else:
|
||||
remove_links(nb)
|
||||
if merged is None:
|
||||
merged = nb
|
||||
else:
|
||||
merged.worksheets[0].cells.extend(nb.worksheets[0].cells)
|
||||
merged.metadata.name += "_merged"
|
||||
|
||||
print(current.writes(merged, u'json'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
#merge_notebooks(sys.argv[1:])
|
||||
merge_notebooks(
|
||||
['../Preface.ipynb',
|
||||
'../01_gh_filter/g-h_filter.ipynb',
|
||||
'../02_Discrete_Bayes/discrete_bayes.ipynb',
|
||||
'../03_Least_Squares/Least_Squares_Filters.ipynb',
|
||||
'../04_Gaussians/Gaussians.ipynb',
|
||||
'../05_Kalman_Filters/Kalman_Filters.ipynb',
|
||||
'../06_Multivariate_Kalman_filter/Multivariate_Kalman_Filters.ipynb',
|
||||
'../07_Kalman_Filter_Math/Kalman_Filter_Math.ipynb',
|
||||
'../08_Designing_Kalman_Filters/Designing_Kalman_Filters.ipynb',
|
||||
'../09_Extended_Kalman_Filters/Extended_Kalman_Filters.ipynb',
|
||||
'../10_Unscented_Kalman_Filters/Unscented_Kalman_Filter.ipynb',
|
||||
'../11_Ensemble_Kalman_Filter/Ensemble_Kalman_Filters.ipynb',
|
||||
'../12_Designing_Nonlinear_Kalman_Filters/Designing_Nonlinear_Kalman_Filters.ipynb',
|
||||
'../13_HInfinity_Filters/HInfinity_Filters.ipynb',
|
||||
'../14_Smoothing/Smoothing.ipynb',
|
||||
'../15_Adaptive_Filtering/Adaptive_Filtering.ipynb',
|
||||
'../Appendix_A_Installation/Appendix_Installation.ipynb',
|
||||
'../Appendix_B_Symbols_and_Notations/Appendix_Symbols_and_Notations.ipynb'])
|
||||
26
pdf/nbmerge.py
Normal file
26
pdf/nbmerge.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""
|
||||
usage:
|
||||
|
||||
python nbmerge.py A.ipynb B.ipynb C.ipynb > merged.ipynb
|
||||
"""
|
||||
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
|
||||
from IPython.nbformat import current
|
||||
|
||||
def merge_notebooks(filenames):
|
||||
merged = None
|
||||
for fname in filenames:
|
||||
with io.open(fname, 'r', encoding='utf-8') as f:
|
||||
nb = current.read(f, 'json')
|
||||
if merged is None:
|
||||
merged = nb
|
||||
else:
|
||||
merged.worksheets[0].cells.extend(nb.worksheets[0].cells)
|
||||
merged.metadata.name += "_merged"
|
||||
print current.writes(merged, 'json')
|
||||
|
||||
if __name__ == '__main__':
|
||||
merge_notebooks(sys.argv[1:])
|
||||
28
pdf/report.tplx
Normal file
28
pdf/report.tplx
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
% Default to the notebook output style
|
||||
((* if not cell_style is defined *))
|
||||
((* set cell_style = 'style_ipython.tplx' *))
|
||||
((* endif *))
|
||||
|
||||
% Inherit from the specified cell style.
|
||||
((* extends cell_style *))
|
||||
|
||||
|
||||
%===============================================================================
|
||||
% Latex Book
|
||||
%===============================================================================
|
||||
|
||||
%((* block predoc *))
|
||||
% ((( super() )))
|
||||
% ((* block tableofcontents *))\tableofcontents((* endblock tableofcontents *))
|
||||
%((* endblock predoc *))
|
||||
|
||||
((* block docclass *))
|
||||
\documentclass[4pt]{book}
|
||||
\setcounter{chapter}{-1}
|
||||
((* endblock docclass *))
|
||||
|
||||
((* block preamble *))
|
||||
\setcounter{secnumdepth}{3}
|
||||
\setcounter{tocdepth}{3}
|
||||
((* endblock preamble *))
|
||||
11
pdf/short_build_book
Executable file
11
pdf/short_build_book
Executable file
@@ -0,0 +1,11 @@
|
||||
#! /bin/bash
|
||||
|
||||
echo "merging book..."
|
||||
|
||||
python short_merge_book.py > short.ipynb
|
||||
|
||||
echo "creating pdf..."
|
||||
ipython nbconvert --to latex --template book --post PDF short.ipynb
|
||||
|
||||
echo "done."
|
||||
|
||||
65
pdf/short_merge_book.py
Normal file
65
pdf/short_merge_book.py
Normal file
@@ -0,0 +1,65 @@
|
||||
from __future__ import print_function
|
||||
import io
|
||||
from IPython.nbformat import current
|
||||
import sys
|
||||
|
||||
def remove_formatting(nb):
|
||||
w = nb['worksheets']
|
||||
node = w[0]
|
||||
c = node['cells']
|
||||
for i in range (len(c)):
|
||||
if 'input' in c[i].keys():
|
||||
if c[i]['input'][0:16] == '#format the book':
|
||||
del c[i]
|
||||
return
|
||||
|
||||
def remove_links(nb):
|
||||
w = nb['worksheets']
|
||||
node = w[0]
|
||||
c = node['cells']
|
||||
for i in range (len(c)):
|
||||
if 'source' in c[i].keys():
|
||||
if c[i]['source'][0:19] == '[Table of Contents]':
|
||||
del c[i]
|
||||
return
|
||||
|
||||
def remove_links_add_appendix(nb):
|
||||
w = nb['worksheets']
|
||||
node = w[0]
|
||||
c = node['cells']
|
||||
for i in range (len(c)):
|
||||
if 'source' in c[i].keys():
|
||||
if c[i]['source'][0:19] == '[Table of Contents]':
|
||||
c[i]['source'] = '\\appendix'
|
||||
return
|
||||
|
||||
|
||||
def merge_notebooks(filenames):
|
||||
merged = None
|
||||
added_appendix = False
|
||||
for fname in filenames:
|
||||
with io.open(fname, 'r', encoding='utf-8') as f:
|
||||
nb = current.read(f, u'json')
|
||||
remove_formatting(nb)
|
||||
if not added_appendix and fname[0:8] == 'Appendix':
|
||||
remove_links_add_appendix(nb)
|
||||
added_appendix = True
|
||||
else:
|
||||
remove_links(nb)
|
||||
if merged is None:
|
||||
merged = nb
|
||||
else:
|
||||
merged.worksheets[0].cells.extend(nb.worksheets[0].cells)
|
||||
merged.metadata.name += "_merged"
|
||||
|
||||
print(current.writes(merged, u'json'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
#merge_notebooks(sys.argv[1:])
|
||||
merge_notebooks(
|
||||
['Preface.ipynb',
|
||||
'01_gh_filter/g-h_filter.ipynb',
|
||||
'02_Discrete_Bayes/discrete_bayes.ipynb',
|
||||
'Appendix_A_Installation/Appendix_Installation.ipynb',
|
||||
'Appendix_B_Symbols_and_Notations/Appendix_Symbols_and_Notations.ipynb'])
|
||||
8
pdf/update_pdf.sh
Normal file
8
pdf/update_pdf.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#! /bin/bash
|
||||
|
||||
git checkout gh-pages
|
||||
git checkout master Kalman_and_Bayesian_Filters_in_Python.pdf
|
||||
git add Kalman_and_Bayesian_Filters_in_Python.pdf
|
||||
git commit -m 'updating PDF'
|
||||
git push
|
||||
git checkout master
|
||||
Reference in New Issue
Block a user