Created
December 11, 2013 20:31
-
-
Save mavant/7917907 to your computer and use it in GitHub Desktop.
As a christmas present for a friend, I'm making a leatherbound copy of "The Bro Code" from How I Met Your Mother. This script generates the formatted pdf document of all the articles - takes a csv file with a list of articles and a .tex file showing the format of a single article page, and spits back out a finished PDF. Extremely quick and dirty.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import re | |
from subprocess import call | |
outputfilename = 'BroCode.pdf' | |
articlecsv = 'Articles.csv' | |
formatfilename = 'page.tex' | |
output = open('latextemp.tex','w') | |
formatfile = open('page.tex', 'r') | |
pageformat = formatfile.read() | |
formatfile.close() | |
t = re.split('(begin{document})',pageformat) | |
bodyformat = re.split('\\\end{document}', t[2])[0] | |
output.write(t[0] + t[1]) | |
with open(articlecsv, 'rb') as articles: | |
articlereader = csv.reader(articles, delimiter=' ', quotechar='|') | |
for row in articlereader: | |
n = "Article " + row[0] | |
text = row[1] | |
expl = '' | |
if len(row) > 2: | |
expl = row [2] | |
t = bodyformat | |
t = re.sub('ARTICLENAME',n,t) | |
t = re.sub('ARTICLETEXT',text,t) | |
t = re.sub('ARTICLEEXPLANATION',expl,t) | |
t = re.sub('%','\\\%',t) | |
output.write(t) | |
output.write('\end{document}') | |
output.close() | |
call(['pdflatex', 'latextemp']) | |
call(['mv', 'latextemp.pdf', outputfilename]) | |
call(['rm', 'latextemp.tex', 'latextemp.log', 'latextemp.aux']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass[english]{article} | |
\usepackage[T1]{fontenc} | |
\usepackage[latin9]{inputenc} | |
\usepackage{babel} | |
\begin{document} | |
\noindent \begin{center} | |
\rule[0.5ex]{1\columnwidth}{1pt} | |
\par\end{center} | |
\noindent \begin{center} | |
\bigskip{} | |
\par\end{center} | |
\medskip{} | |
\noindent \begin{center} | |
\textbf{\textsc{\Huge{ARTICLENAME}}} | |
\par\end{center}{\Huge \par} | |
\noindent \begin{center} | |
\medskip{} | |
\par\end{center} | |
\noindent \begin{center} | |
{\large{ARTICLETEXT}} | |
\par\end{center}{\large \par} | |
\noindent \begin{center} | |
\smallskip{} | |
\par\end{center} | |
\noindent \begin{center} | |
\textit{\scriptsize{ARTICLEEXPLANATION}} | |
\par\end{center}{\scriptsize \par} | |
\noindent \begin{center} | |
\vfill{} | |
\par\end{center} | |
\noindent \begin{center} | |
\rule[0.5ex]{1\columnwidth}{1pt} | |
\par\end{center} | |
\noindent \begin{center} | |
\pagebreak{} | |
\par\end{center} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment