-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcreate-latexmap.py
executable file
·57 lines (46 loc) · 1.72 KB
/
create-latexmap.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
#!/usr/bin/env python3
# SDAPS - Scripts for data acquisition with paper based surveys
# Copyright(C) 2011, Benjamin Berg <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
This file generates the latexmap.py file which is needed
to convert latex symbols into their unicode counterpart.
Run with create-latexmap.py path/to/utf8enc.dfu
"""
import re
import sys
if len(sys.argv) != 2:
print(__doc__)
sys.exit(1)
output = open('latexmap.py', 'w')
input = open(sys.argv[1])
data = input.read()
regexp = re.compile(r'^\\DeclareUnicodeCharacter\{(?P<unicode>[0-9a-fA-F]{4})\}\{(?P<str>[^\}]+)\}', re.MULTILINE)
mapping = []
for match in regexp.finditer(data):
repr = match.group('str')
repr = repr.replace('\\@tabacckludge', '\\')
repr = repr.replace('\\', '\\\\').replace('\'', '\\\'')
mapping.append(''' u\'%s\': u\'\\u%s\'''' %
(repr,
match.group('unicode')))
output.write('''#This file is auto generated from the latex unicode mapping.
#: Mapping from LaTeX commands to unicode characters.
mapping = {
''')
output.write(',\n'.join(mapping))
output.write('''
}
''')