Skip to content

Instantly share code, notes, and snippets.

@samvrlewis
Last active December 18, 2016 03:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samvrlewis/8a1522084bc99eda7651 to your computer and use it in GitHub Desktop.
Save samvrlewis/8a1522084bc99eda7651 to your computer and use it in GitHub Desktop.
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])
phant.log(words)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment