Skip to content

Instantly share code, notes, and snippets.

@idkqh7
Last active August 29, 2015 14:06
Show Gist options
  • Save idkqh7/ea94620ec6c5951bef30 to your computer and use it in GitHub Desktop.
Save idkqh7/ea94620ec6c5951bef30 to your computer and use it in GitHub Desktop.
Add a typeset of updfLatex for TexWorks
#!/usr/bin/python3
__author__ = 'idkqh7'
import os
import re
updfLatex = '''[001]
name=updfLatex
program=updflatex
arguments=$basename
showPdf=true
'''
tools_path = os.path.expanduser("~/.TeXworks/configuration/tools.ini")
tmp_path = tools_path + ".tmp"
with open(tools_path) as tools:
typeset = tools.read()
if "updfLatex" in typeset:
print("A typeset of updfLatex Already exist.")
exit()
sections = re.findall("[0-9]+", typeset)
if sections:
for section in reversed(sections):
next_section = "{0:03d}".format(int(section) + 1)
typeset = typeset.replace(section, next_section)
typeset = updfLatex + typeset
with open(tmp_path, mode='w') as tmp:
tmp.write(typeset)
#
os.rename(tools_path, tools_path + ".old")
os.rename(tmp_path, tools_path)
print("Adding a typeset of updfLatex is successful!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment