| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
import sys |
| 11 |
import re |
| 12 |
|
| 13 |
in_synopsis = False |
| 14 |
|
| 15 |
if len(sys.argv) == 1: |
| 16 |
f = sys.stdin |
| 17 |
else: |
| 18 |
f = open(sys.argv[1]) |
| 19 |
|
| 20 |
for line in f: |
| 21 |
line = line.rstrip('\n') |
| 22 |
|
| 23 |
|
| 24 |
if re.match(r'\\section{Synopsis}', line): |
| 25 |
in_synopsis = True |
| 26 |
elif re.match(r'\\section{', line): |
| 27 |
in_synopsis = False |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
if re.match(r'\\documentclass', line): continue |
| 34 |
if re.match(r'\\setlength{\\parindent}', line): continue |
| 35 |
if re.match(r'\\setlength{\\parskip}', line): continue |
| 36 |
if re.match(r'\\begin\{document\}', line): continue |
| 37 |
|
| 38 |
|
| 39 |
if re.match(r'\\section\{Name\}', line): |
| 40 |
for line in f: |
| 41 |
if not re.fullmatch(r'\s*', line): |
| 42 |
break |
| 43 |
m = re.match(r'(\S+)\s*\\?-\s*(.+)$', line) |
| 44 |
if m: |
| 45 |
print(r'\section{{\texorpdfstring{{\monob{{{0}}}}}{{{0}}} - {1}}}'.format(m.group(1), m.group(2))) |
| 46 |
else: |
| 47 |
print("Error: no progname/description line found"); |
| 48 |
sys.exit(1) |
| 49 |
continue |
| 50 |
|
| 51 |
|
| 52 |
if re.match(r'\\section\{See', line) or re.match(r'\\end\{document', line): |
| 53 |
print("\\newpage"); |
| 54 |
break |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
if in_synopsis and re.match(r'\s*\\textbf{', line): |
| 64 |
line = re.sub(r'\\textbf\{', r'\\monob{', line) |
| 65 |
print("\\noindent") |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
line = re.sub(r'\\begin\{itemize\}', r'\\begin{wideitem}', line) |
| 72 |
line = re.sub(r'\\end\{itemize\}', r'\\end{wideitem}', line) |
| 73 |
line = re.sub(r'\\section\{', r'\\subsection*{', line) |
| 74 |
line = re.sub(r'--', r'{-}{-}', line) |
| 75 |
line = re.sub(r'\\item\s*\[\\textbf', r'\\item [\\monob', line) |
| 76 |
line = re.sub(r'\\textbf\{\\% ', r'\\user{\\% ', line) |
| 77 |
line = re.sub(r'\\textit\{', r'\\monoi{', line) |
| 78 |
line = re.sub(r'\\textbf\{', r'\\mono{', line) |
| 79 |
|
| 80 |
print(line) |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
if f != sys.stdin: |
| 85 |
f.close() |
| 86 |
|