-
Notifications
You must be signed in to change notification settings - Fork 33
/
build_latex.py
executable file
·92 lines (77 loc) · 3.08 KB
/
build_latex.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# coding:utf8
import io
import os
import shutil
import subprocess
import sys
rebuild = True
path = os.path.join("build", "latex")
if rebuild:
if os.path.exists(path):
shutil.rmtree(path)
# TODO: encodings:: column or row spanning cells are not yet implemented.
tableBefore = os.linesep.join((
u"+--------------------------------------------------------+------------------------------------------+",
u"| Character | Replaced by |",
))
tableAfter = os.linesep.join((
u"+--------------------------------------------+-----------+---------+--------------------------------+",
u"| Character | | | Replaced by |",
))
with io.open("encodings.rst", encoding="utf-8") as fp:
encodings = fp.read()
try:
with io.open("encodings.rst", "w", encoding="utf-8") as fp:
fp.write(encodings.replace(tableBefore, tableAfter))
shutil.copyfile("encodings.rst", "encodings.rst.new")
ret = subprocess.call(("make", "latex"))
finally:
with io.open("encodings.rst", "w", encoding="utf-8") as fp:
fp.write(encodings)
if ret != 0:
sys.exit(ret)
os.chdir(path)
with io.open("programming_with_unicode.tex", encoding="utf-8") as fp:
content = fp.read()
DUlineblock = os.linesep.join((
u"\\begin{DUlineblock}{0em}",
u"\\item[] ",
u"\\end{DUlineblock}",
))
REPLACE = (
(u"\\usepackage[T1]{fontenc}", u"\\usepackage[T1,T2A]{fontenc}"),
(u"\\usepackage{babel}", u"\\usepackage[english]{babel}"),
# TODO: ! Package inputenc Error: Unicode char \u8:� not set up for use with LaTeX.
# TODO: ! Package textcomp Error: Symbol \textcurrency not provided by
# (textcomp) font family ptm in TS1 encoding.
# (textcomp) Default family used instead.
# Try: \usepackage[force,almostfull]{textcomp}
(u"�", u"<?>"),
# U+00B8 or U+0327: cedilla
(u"\xB8", u"\\c{ }"),
(DUlineblock, u"|"),
(u"Русский",
u"\\foreignlanguage{russian}{Русский}"),
(u"``Кракозя\u0301бры'' (krakozyabry)",
u"\\foreignlanguage{russian}{``Кракоз\\'{я}бры'' (krakozyabry)}"),
(u'Big5 (大五碼, Big Five Encoding, 1984)',
u'Big5 (Big Five Encoding, 1984)'),
(u'Katakana middle dot (・)',
u'Katakana middle dot'),
# TODO: ! LaTeX Error: Command \DH unavailable in encoding T2A.
# TODO: ! LaTeX Error: Command \TH unavailable in encoding T2A.
# TODO: ! LaTeX Error: Command \dh unavailable in encoding T2A.
# TODO: ! LaTeX Error: Command \th unavailable in encoding T2A.
(u"Ð", u"D"),
(u"ð", u"d"),
(u"Þ", u"P"),
(u"þ", u"p"),
)
for before, after in REPLACE:
content = content.replace(before, after)
with io.open("programming_with_unicode.tex", "w", encoding="utf-8") as fp:
fp.write(content)
ret = subprocess.call(("make", "all-pdf", "clean"))
if ret != 0:
sys.exit(ret)