Created
January 15, 2018 17:25
-
-
Save TAJD/2a9aeb4d2764f15e5e816700d9311ddd to your computer and use it in GitHub Desktop.
Assist latex file compilation and spell check.
This file contains 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
"""Assist latex file editing. | |
Functions to assist with editing and compiling latex documents. | |
Thomas Dickson | |
26/12/2017 | |
""" | |
import click | |
import subprocess | |
@click.group() | |
def latex_assist(): | |
""" | |
Group latex assistant functions. | |
This script relies on the click and subprocess packages being installed | |
for python 3.*. | |
It uses latex to compile documents and uses texcount to provide a word | |
count at the end of the compilation process. | |
It relies on aspell to check the spelling contained in latex files. | |
aspell can be installed from brew on osx. | |
""" | |
pass | |
@latex_assist.command() | |
@click.argument('fname') | |
def compile(fname): | |
"""Compile latex document.""" | |
commands = [ | |
['pdflatex', fname + '.tex'], | |
['bibtex', fname + '.aux'], | |
['makeindex', fname + '.nlo', ' -s', 'nomencl.ist', ' -o', | |
fname + '.nls'], | |
['makeglossaries', fname], | |
['pdflatex', fname + '.tex'], | |
['pdflatex', fname + '.tex'], | |
['texcount', fname + '.tex', '-inc', '-incbib', '-sum'], | |
] | |
for c in commands: | |
subprocess.call(c) | |
@latex_assist.command() | |
@click.argument('fname') | |
def spell_check(fname): | |
"""Run aspell on a single tex file.""" | |
for c in ['aspell --lang=en --mode=tex -c ' + fname+'.tex']: | |
subprocess.call(c, shell=True) | |
if __name__ == '__main__': | |
latex_assist() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment