Monday, June 3, 2013

Advice to Future Physics Students

This year, I had my students (physics, honors physics, and AP physics) this year write some advice to future students, paying forward their experience: things to do, things not to do, encouragement, etc.

I was very pleased with the types of things that they advised, and I put together a sheet for next year's packets with some highlights. The file's linked here, but I thought that I'd also share the process for making these (with the rotating font sizes, types, and styles) yourself:

  • You'll need Python (script below) and LaTeX
  • Type the advice into a plain text document (UTF-8 encoding, so that the apostrophes don't get lost in the LaTeX), one nugget per line
  • I had it print only lines with * at the end, so that I could save all of the advice, but only use some of it. You can certainly modify the code to fit your needs
  • You'll need to make a few path and file mods (it's also calling Preview at the end to display, so if you're not on OSX you'll need to change that too)
  • Run and enjoy - let me know if you found it useful!

The script (quick and dirty - surely can be improved. For example, most of the imports don't really need to be there, but I was modifying an old script, and they weren't hurting anyone):


# Advice prepper - random fonts and sizes
# prep: UTF-8 file advice.txt - * on end of each included line

import sys
import os
import csv
import string
import subprocess
import math
from random import choice
from itertools import *

fontfams = [r'{\sffamily ', r'{\rmfamily ']
fiter = cycle(fontfams)
sizes = [r'\Large ', r'\small ', r'\large ', r'\normalsize ', r'\Large ']
siter = cycle(sizes)
types = [r'\scshape ', r'\itshape ', r'\bfseries ', ' ']
titer = cycle(types)

# open advice.txt
reader = open('advice.txt', 'r')
data = []
for lines in reader:
    data.append(lines)
data = data[1:]
reader.close()

# open output file
writer = open('advice.tex', 'w')

# This is just my default LaTeX header - insert your own
writer.write(r'\input{/Users/jgates/desktop/latex/headerforinput.tex}' +'\n')
writer.write(r'\linespread{1.6}')
writer.write(r'\begin{center}' + '\n' + r'{\huge \scshape Advice from former physics students}' + '\n' + r'\end{center}' + '\n' + r'\bigskip' + '\n')


for lines in data:
    # strip trailing spaces
    if lines[-1]==' ':
        lines = lines[:-1]
    if lines[-1]==' ':
        lines = lines[:-1]
    if lines[-1]==' ':
        lines = lines[:-1]
    # choose starred lines
    if '*' in lines:
        lines = lines.translate(None,'*')
        #writer.write(choice(fontfams) + choice(types) + choice(sizes) + lines + '}' + '\n' )
        writer.write(next(fiter) + next(titer) + next(siter) + lines + '}' + '\n' )
   
       
writer.write('\end{document}')
writer.write('\n')
writer.close()
# compile PDF, clean up
filename4exp = 'advice'
# fix the paths!
subprocess.check_output((r'/usr/local/texlive/2011/bin/universal-darwin/pdflatex', r'-aux-directory=/Users/jgates/desktop' , r'-output-directory=/Users/jgates/desktop' , filename4exp))
delfile = filename4exp + r'.log'
os.remove(delfile)
delfile = filename4exp + r'.tex'  
#os.remove(delfile)
# Open document with Preview
outname = r'open ' + filename4exp + r'.pdf'
#print outname
os.system(outname)
   



No comments:

Post a Comment