preprocessor.py 605 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
15
16
17
18
19

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

    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
20
21
22
23
    print(data, copy)
    if data == copy:
      break

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

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