Skip to content

Instantly share code, notes, and snippets.

Last active Dec 18, 2016
What would you like to do?
Count words in LaTeX python script
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#-*- mode: python -*-
import subprocess
import os
import phant
THESIS_SECTIONS_DIR = '/Users/Sam/Dropbox/Uni/Thesis/thesis/sections/'
page_names = os.listdir(THESIS_SECTIONS_DIR)
tex_files = [THESIS_SECTIONS_DIR + page_name for page_name in page_names if '.tex' in page_name]
public = '0lz0p2DvR1CNJly320Nr'
private = 'privatekey'
phant = phant.Phant(public, 'words', private_key=private)
words = 0
for tex_file in tex_files:
process = subprocess.Popen(['texcount', '-1', tex_file], stdout=subprocess.PIPE)
out, err = process.communicate()
words += eval(out.split()[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment