preprocessor.py 724 Bytes
Newer Older
Harry Fuchs's avatar
Harry Fuchs committed
1 2
#TODO Algorithmic efficiency

Harry Fuchs's avatar
Harry Fuchs committed
3 4
import re

Harry Fuchs's avatar
Harry Fuchs committed
5 6 7 8 9 10 11
filename = "tmp.tex"

with open(filename, 'r') as file:
  data = file.read()
  copy = data
  while True:
    data = copy
Harry Fuchs's avatar
Harry Fuchs committed
12 13 14

    copy = re.sub("(?<!\\\\)\%.*\n", '', copy)

Harry Fuchs's avatar
Harry Fuchs committed
15 16 17 18
    #turn on/off personal comments
    #copy = re.sub("(?<!\\\\)\§.*\n", '', copy)
    copy = re.sub("§", '', copy)

Harry Fuchs's avatar
Harry Fuchs committed
19 20 21 22 23
    copy = re.sub("\$\$\n", '\\\\begin{eqnarray*}\n', copy, 1)
    copy = re.sub("\$\$\n", '\\\\end{eqnarray*}\n', copy, 1)
    copy = re.sub("\$\$1\n", '\\\\begin{equation*}\n', copy, 1)
    copy = re.sub("\$\$1\n", '\\\\end{equation*}\n', copy, 1)

Harry Fuchs's avatar
Harry Fuchs committed
24 25 26 27
    print(data, copy)
    if data == copy:
      break

Harry Fuchs's avatar
Harry Fuchs committed
28 29
data = re.sub(r'\\%', '%', data)

Harry Fuchs's avatar
Harry Fuchs committed
30 31
with open(filename, 'w') as file:
  file.write(data)