-
Notifications
You must be signed in to change notification settings - Fork 2
/
make-handout.py
74 lines (55 loc) · 1.98 KB
/
make-handout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Generates a file <chapter>-handout.tex that can then be processed to make a
handout. Adjust the string `frontmatter` to make the fonts to your liking.
"""
import argparse
parser = argparse.ArgumentParser(description="writes out handout for a specified chapter.")
parser.add_argument('chapter_name',type=str,default=None,help="file name for chapter.")
frontmatter=r'''% !TEX TS-program = xelatex
\documentclass[handout]{astro-bookshelf}
\hypersetup{colorlinks=true,linkcolor=blue,citecolor=black,urlcolor=blue}
\usepackage{aasjournals}
\graphicspath{%
{frontmatter/}{starlight/figs/}{hydrostatic-balance/figs/}{radiative-transport/figs/}{classifying-stars/figs/}{nuclear-burning/figs/}{main-sequence/figs/}{post-main-sequence/figs/}
}
\usepackage{starType}
\input{symbols}
\newcommand{\newterm}[1]{\textsc{#1}}
% for aligning table columns
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\newcommand{\tabhead}[1]{\multicolumn{1}{c}{#1}}
% for coloring rows
\usepackage{colortbl}
\usepackage{aasjournals}
\newcommand*{\maintitle}{To Build a Star}
\author{Edward Brown}
%\publisher{Open Astrophysics Bookshelf}
\date{\today}'''
backmatter=r'''
\bibliographystyle{plainnat}
\bibliography{bibs/stellar-astro}
\end{document}
'''
titles = {
"starlight":"Starlight",
"hydrostatic-balance":"Under Pressure",
"radiative-transport":"Edge of Darkness",
"classifying-stars":"Rainbow in the Dark",
"nuclear-burning":"Burn",
"main-sequence":"Star",
"post-main-sequence":"End of the Line",
"numerical-methods":"Algorithm"
}
# execution starts here
args = parser.parse_args()
chapter = args.chapter_name
# check name
if chapter not in titles.keys():
raise ValueError('invalid name for the chapter')
texfile=chapter.strip()+'-handout.tex'
title = r'\title{{{0}}}'.format(titles[chapter])
chapter = r'\input{{{0}/{0}}}'.format(chapter)
folios = (frontmatter,title,r'\begin{document}',r'\maketitle',chapter,backmatter)
with open(texfile,'w') as f:
f.write('\n\n'.join(folios))