summaryrefslogtreecommitdiff
path: root/convert.py
blob: 2c1d7d5bf9b0314d64f4001d86665e63bc8e6c9c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/env python
import re
from sys import argv

path = argv[1]
data = [line.rstrip("\n") for line in open(path)]
latex = [
    "\\documentclass[11pt]{article}",
    "\\usepackage[utf8]{inputenc}",
    "\\begin{document}"
]
rules = {
    "(# )(.*)": "\\section{input}",  # Caption 1
    "(## )(.*)": "\\subsection{input}",  # Caption 2
    "(### )(.*)": "\\subsubsection{input}",  # Caption 3
}

for i, line in enumerate(data):
    print(line)
    matched = False
    new_line = line
    for rule in rules:
        match = re.match(rule, new_line)
        if match:
            print(match.groups())
            matched = True
            new_line = rules[rule].replace("input", match.groups()[1])
    if new_line[-2:] == "  ":
        new_line = new_line[:-2]
        new_line += "\\\\"
    latex.append(new_line)

latex.append("\\end{document}")
open("output.tex", "w").write("\n".join(latex))
print(latex)