1 # This file is part of lyx2lyx
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2011 The LyX team
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 " Import unicode_reps from this module for access to the unicode<->LaTeX mapping. "
23 def read_unicodesymbols():
24 " Read the unicodesymbols list of unicode characters and corresponding commands."
25 pathname = os.path.abspath(os.path.dirname(sys.argv[0]))
26 fp = open(os.path.join(pathname.strip('lyx2lyx'), 'unicodesymbols'))
28 # Two backslashes, followed by some non-word character, and then a character
29 # in brackets. The idea is to check for constructs like: \"{u}, which is how
30 # they are written in the unicodesymbols file; but they can also be written
31 # as: \"u or even \" u.
32 r = re.compile(r'\\\\(\W)\{(\w)\}')
33 for line in fp.readlines():
34 if line[0] != '#' and line.strip() != "":
35 line=line.replace(' "',' ') # remove all quotation marks with spaces before
36 line=line.replace('" ',' ') # remove all quotation marks with spaces after
37 line=line.replace(r'\"','"') # replace \" by " (for characters with diaeresis)
39 [ucs4,command,dead] = line.split(None,2)
40 if command[0:1] != "\\":
42 spec_chars.append([command, unichr(eval(ucs4))])
48 # If the character is a double-quote, then we need to escape it, too,
49 # since it is done that way in the LyX file.
50 if m.group(1) == "\"":
53 command += m.group(1) + m.group(2)
54 commandbl += m.group(1) + ' ' + m.group(2)
55 spec_chars.append([command, unichr(eval(ucs4))])
56 spec_chars.append([commandbl, unichr(eval(ucs4))])
61 unicode_reps = read_unicodesymbols()