Automatic Document Update with Python Scripts

pythonscripts

As many of you I do quite a bit of teaching to make living. The worst part of the semester is usually beginning when I create and upload course Syllabi as well as the end of the semester when I process my grade books. As I am growing older and wiser I try to automatize most of these things. Currently, I have a fairly elaborate set of AWK scripts which essentially do grade book processing for me. It is still not so with the Syllabi. Here you can find bunch of Syllabi samples/templates for the courses I recently taught.

As you can see in many cases the manual update of Syllabi boils down to updating only a few basic information about the course (meeting time, places, in-class exam dates, textbook (I now use BibTeX to do that for me) and so on) as well as day by day course calendar (which I usually keep separately and use \include to include into the source file). I am thinking of creating a script to do all that instead of me. Essentially, I would like to download info from the University portal, format and put into text file. Then use the script to feed info to the Syllabi source files. Could people share their experience on this topic? To make a more formal question.

How can you use a script to update certain parts of the TeX source file?

Edit: I would like to link this question and answer to the following related question I posted which also has a great and a very useful answer.

Best Answer

A related problem might be separating the formatting and content of the syllabus, which could make it easier to generate as many of these syllabi as needed. It would definitely make any scripting much more robust, since you'd be generating only a simple .sty file instead of modifying a full .tex document. Sample result (close to what you had posted):

enter image description here

built from a customized document class, a course-specific style file, and an instructor-specific style file. In theory, this could be used to generate syllabi for an entire department with appropriate scripting. The class file also replaces some of the repeated formatting commands you had (\noindent and other things for paragraphs) with default section formatting and similar items.

.tex file for a specific syllabus:

\documentclass{pp-syllabus}
\usepackage{csci3030-a} % for course-specific information
\usepackage{pp} % for instructor-specific information
% Items specific to this particular course and section, for this term
\newcommand{\courseterm}{Spring 2011}
\newcommand{\coursetime}{MW 4:00 PM--5:15 PM}
\newcommand{\courseroom}{Allgood Hall E364}
\begin{document}
\courseheader{}
\section*{Office Hours} \instructorhours{}.
\section*{Text(s)} \coursetexts{}
\end{document}

Course style file (csci3010-a.sty):

% Items common to a course or section, things that don't change on a
% semester-by-semester basis. Use as little formatting as possible,
% since this file might be used in several different styles of
% syllabi.
\newcommand{\coursename}{CSC 3030}
\newcommand{\sectionname}{A}
\newcommand{\coursetitle}{Mathematical Structures for Computer Science}
\newcommand{\coursedescription}{
The course prepares Computer Science majors for advanced study by
emphasizing components of Discrete Mathematics related to Computer
Science. The topics include sets, functions and relations, logic,
Boolean algebra, graph theory, proof techniques, and matrices. Examples
will emphasize Computer Science applications.
}
\newcommand{\coursecredit}{3}
\newcommand{\coursetexts}{
\textit{A Short Course in Discrete Mathematics} and
\textit{Mathematics for Algorithm and Systems Analysis},
by Edward A. Bender \& S. Gill Williamson, Dover Publications 2005.
}

Instructor style file (pp.sty):

% Items specific to a particular instructor
\newcommand{\instructor}{Dr. Predrag Puno\v sevac}
\newcommand{\instructoroffice}{Allgood Hall N334}
\newcommand{\instructorphone}{(706) 667-4481}
\newcommand{\instructoremail}{\href{mailto:ppunosev@aug.edu}{ppunosev@aug.edu}}
\newcommand{\instructorhours}{MW 2:30 PM--4:00 PM, T 3:30 PM--4:30 PM, or by appointment}

Class file (pp-syllabus.cls):

% Items common to a particular visual style of syllabus -- in theory, can be
% used for all syllabi in a particular department.
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{pp-syllabus}[2012/01/19 v0.1 Modified article class for syllabi]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\LoadClass{article}
\RequirePackage{enumitem}
\setlist{noitemsep}
\RequirePackage{multicol}
% Two-column lists (itemize, description, etc.)
\SetEnumitemKey{twocol}{
itemsep=1\itemsep,
parsep=1\parsep,
before=\raggedcolumns\begin{multicols}{2},
after=\end{multicols}}

\RequirePackage{amsmath}
\RequirePackage{booktabs}
\RequirePackage{multirow}

\RequirePackage[margin=1in]{geometry}

\RequirePackage{titlesec}
% titlesec documentation, section 3.1
\titleformat{\section}[runin]{\normalfont\bfseries}{}{.5em}{}[:]

\RequirePackage{hyperref}

\newcommand{\courseheader}{
\begin{center}
{\Large \textbf{Syllabus for \coursename{} {\tiny Section \sectionname{}}}}

{\large \textbf{\coursetitle{}}}
\end{center}

\begin{description}[twocol,leftmargin=1.1in,style=nextline]
\item[Term:] \courseterm{}
\item[Time:] \coursetime{}
\item[Room:] \courseroom{}
\item[Credit Hours:] \coursecredit{}
\item[Instructor:] \instructor{}
\item[Office:] \instructoroffice{}
\item[Phone:] \instructorphone{}
\item[E-mail:] \instructoremail{}
\end{description}
}