Mercurial > hg > Members > kono > os9 > sbc09
comparison doc/latex2creole.py @ 57:2088fd998865
sbc09 directry clean up
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 23 Jul 2018 16:07:12 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
56:4fa2bdb0c457 | 57:2088fd998865 |
---|---|
1 #!/usr/bin/env python | |
2 # coding: utf-8 | |
3 | |
4 """ | |
5 latex2creole | |
6 ~~~~~~~~~~~~ | |
7 | |
8 Hacked script to convert a LaTeX file into creole markup. | |
9 | |
10 Note: | |
11 Some hand-editing is needed. | |
12 | |
13 :created: 2013 by Jens Diemer - www.jensdiemer.de | |
14 :copyleft: 2013 by the DragonPy team, see AUTHORS for more details. | |
15 :license: GNU GPL v3 or above, see LICENSE for more details. | |
16 """ | |
17 | |
18 import sys | |
19 | |
20 sourcefile = r"sbc09/sbc09.tex" | |
21 destination = r"sbc09.creole" | |
22 | |
23 | |
24 HEADLINES = ( | |
25 r"\title{", | |
26 r"\chapter{", | |
27 r"\section{", | |
28 r"\subsection{", | |
29 ) | |
30 SKIPS = ( | |
31 r"\begin", | |
32 r"\end", | |
33 r"\document", | |
34 r"\maketitle", | |
35 r"\tableofcontents", | |
36 "\\def\\", | |
37 ) | |
38 | |
39 in_list = 0 | |
40 | |
41 def should_skip(line): | |
42 for skip in SKIPS: | |
43 if line.startswith(skip): | |
44 return True | |
45 | |
46 | |
47 with open(sourcefile, "r") as infile: | |
48 with open(destination, "w") as outfile: | |
49 for line in infile: | |
50 # ~ print line | |
51 | |
52 line = line.strip() | |
53 | |
54 if line.startswith(r"\begin{itemize}"): | |
55 in_list += 1 | |
56 continue | |
57 if line.startswith(r"\end{itemize}"): | |
58 in_list -= 1 | |
59 if in_list == 0: | |
60 outfile.write("\n") | |
61 continue | |
62 | |
63 if in_list: | |
64 if line.startswith(r"\item"): | |
65 line = "\n%s%s" % ("*"*in_list, line[5:]) | |
66 outfile.write(line) | |
67 continue | |
68 | |
69 if line == r"\begin{verbatim}": | |
70 line = "{{{" | |
71 elif line == r"\end{verbatim}": | |
72 line = "}}}" | |
73 | |
74 if should_skip(line): | |
75 continue | |
76 | |
77 for no, prefix in enumerate(HEADLINES, 1): | |
78 if line.startswith(prefix): | |
79 line = line.replace("{\\tt ", "").replace("}", "") | |
80 line = line.split("{", 1)[1].replace("{", "").replace("}", "") | |
81 line = "\n%(m)s %(l)s %(m)s\n" % { | |
82 "m": "="*no, | |
83 "l": line | |
84 } | |
85 break | |
86 | |
87 if line.startswith(r"\item["): | |
88 item, txt = line[6:].split("]") | |
89 item = item.strip() | |
90 txt = txt.strip() | |
91 line = "** %s **\n%s" % (item, txt) | |
92 | |
93 if "{\\tt" in line: | |
94 line = line.replace("{\\tt ", "{{{").replace("}", "}}}") | |
95 if "{\\em" in line: | |
96 line = line.replace("{\\em ", "{{{").replace("}", "}}}") | |
97 | |
98 line = line.replace("\\", "") | |
99 | |
100 print line | |
101 line += "\n" | |
102 outfile.write(line) |