Fixed formatting for PDF.
I finally learned that the raw cells let you put latex directly into the output. So now I have the appendix being created without the [1] %%latex showing up in the output. Also wrote code to parse the .tex file to make the Preface a chapter without numbering, so it is now a proper preface, and not "chapter 0". I have not touched the Windows generation tools, so PDF generation in Windows is now broken. I don't think I care.
This commit is contained in:
parent
e1c3e8a8eb
commit
515b03ec63
@ -14,6 +14,13 @@
|
||||
"# Preface"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\\addcontentsline{toc}{chapter}{Preface}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
|
@ -8,27 +8,11 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"cell_type": "raw",
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/latex": [
|
||||
"\\appendix"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.Latex object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%%latex\n",
|
||||
"\\appendix"
|
||||
]
|
||||
},
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
((* block docclass *))
|
||||
\documentclass{book}
|
||||
\setcounter{chapter}{-1}
|
||||
\setcounter{chapter}{0}
|
||||
((* endblock docclass *))
|
||||
|
||||
((* block preamble *))
|
||||
@ -13,7 +13,6 @@
|
||||
((* block title *))
|
||||
\title{Kalman and Bayesian Filters in Python}
|
||||
\author{Roger R Labbe Jr}
|
||||
\date{}
|
||||
((* endblock title *))
|
||||
|
||||
((* block markdowncell scoped *))
|
||||
|
@ -5,7 +5,8 @@ echo "merging book..."
|
||||
python merge_book.py > Kalman_and_Bayesian_Filters_in_Python.ipynb
|
||||
|
||||
echo "creating pdf..."
|
||||
ipython nbconvert --to PDF --template book Kalman_and_Bayesian_Filters_in_Python.ipynb
|
||||
ipython nbconvert --to latex --template book Kalman_and_Bayesian_Filters_in_Python.ipynb
|
||||
ipython to_pdf.py
|
||||
|
||||
mv Kalman_and_Bayesian_Filters_in_Python.pdf ..
|
||||
echo "done."
|
||||
|
@ -5,11 +5,11 @@ import sys
|
||||
|
||||
|
||||
def remove_formatting(nb):
|
||||
c = nb['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]
|
||||
cells = nb['cells']
|
||||
for i in range (len(cells)):
|
||||
if 'source' in cells[i].keys():
|
||||
if cells[i]['source'][0:16] == '#format the book':
|
||||
del cells[i]
|
||||
return
|
||||
|
||||
|
||||
@ -53,6 +53,11 @@ def merge_notebooks(filenames):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
'''merge_notebooks(
|
||||
['../00_Preface.ipynb',
|
||||
'../01_g-h_filter.ipynb',
|
||||
'../Appendix_A_Installation.ipynb'])'''
|
||||
|
||||
merge_notebooks(
|
||||
['../00_Preface.ipynb',
|
||||
'../01_g-h_filter.ipynb',
|
||||
|
@ -1,32 +1,29 @@
|
||||
from __future__ import print_function
|
||||
import io
|
||||
from IPython.nbformat import current
|
||||
import IPython.nbformat as nbformat
|
||||
import sys
|
||||
|
||||
|
||||
def remove_formatting(nb):
|
||||
w = nb['worksheets']
|
||||
node = w[0]
|
||||
c = node['cells']
|
||||
c = nb['cells']
|
||||
for i in range (len(c)):
|
||||
if 'input' in c[i].keys():
|
||||
if c[i]['input'][0:16] == '#format the book':
|
||||
if 'source' in c[i].keys():
|
||||
if c[i]['source'][0:16] == '#format the book':
|
||||
del c[i]
|
||||
return
|
||||
|
||||
|
||||
def remove_links(nb):
|
||||
w = nb['worksheets']
|
||||
node = w[0]
|
||||
c = node['cells']
|
||||
c = nb['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']
|
||||
c = nb['cells']
|
||||
for i in range (len(c)):
|
||||
if 'source' in c[i].keys():
|
||||
if c[i]['source'][0:19] == '[Table of Contents]':
|
||||
@ -39,7 +36,7 @@ def merge_notebooks(filenames):
|
||||
added_appendix = False
|
||||
for fname in filenames:
|
||||
with io.open(fname, 'r', encoding='utf-8') as f:
|
||||
nb = current.read(f, u'json')
|
||||
nb = nbformat.read(f, nbformat.NO_CONVERT)
|
||||
remove_formatting(nb)
|
||||
if not added_appendix and fname[0:8] == 'Appendix':
|
||||
remove_links_add_appendix(nb)
|
||||
@ -49,14 +46,15 @@ def merge_notebooks(filenames):
|
||||
if merged is None:
|
||||
merged = nb
|
||||
else:
|
||||
merged.worksheets[0].cells.extend(nb.worksheets[0].cells)
|
||||
merged.metadata.name += "_merged"
|
||||
merged.cells.extend(nb.cells)
|
||||
#merged.metadata.name += "_merged"
|
||||
|
||||
print(current.writes(merged, u'json'))
|
||||
print(nbformat.writes(merged, nbformat.NO_CONVERT))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
#merge_notebooks(sys.argv[1:])
|
||||
merge_notebooks(
|
||||
['../01_g-h_filter.ipynb',
|
||||
'../02_Discrete_Bayes.ipynb'])
|
||||
['../00_Preface.ipynb',
|
||||
'../01_g-h_filter.ipynb',
|
||||
'../Appendix_A_Installation.ipynb'])
|
||||
|
13
pdf/to_pdf.py
Normal file
13
pdf/to_pdf.py
Normal file
@ -0,0 +1,13 @@
|
||||
from __future__ import print_function
|
||||
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='')
|
||||
|
||||
|
||||
p = pdf.PDFExporter()
|
||||
p.run_latex('Kalman_and_Bayesian_Filters_in_Python.tex')
|
||||
|
Loading…
Reference in New Issue
Block a user