Last active
August 29, 2015 14:06
-
-
Save idkqh7/ea94620ec6c5951bef30 to your computer and use it in GitHub Desktop.
Add a typeset of updfLatex for TexWorks
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
#!/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