File: tweak-dblatex-tex.py

package info (click to toggle)
dvisvgm 3.5%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,968 kB
  • sloc: cpp: 82,173; ansic: 33,458; makefile: 918; xml: 201; python: 177; sh: 99
file content (18 lines) | stat: -rw-r--r-- 717 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import re
import os

def main (latex_file, stdout):
    latex_file_old = latex_file+"-old"
    os.rename(latex_file, latex_file_old)
    os.remove(os.path.splitext(latex_file)[0]+".pdf")
    with open(latex_file, "w") as outfile:
        with open(latex_file_old) as infile:
            lines = infile.readlines()
            for line in lines:
                if re.match(r'(.*\\def)|(.*\\href)', line) == None:
                    line = re.sub(r'([a-zA-Z0-9]+)/', r'\1\\slash{}', line)
                    line = re.sub(r'-{}-{}', r'\=/\=/', line)
                    line = re.sub(r'([^a-zA-Z0-9])-{}', r'\1\=/', line)
                print(line.rstrip(), file=outfile)
    os.remove(latex_file_old)
    return 0