X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Flyx2lyx%2Flyx_1_6.py;h=c022b875aace420de486f41791ee2e74988c797e;hb=9f0dd70ed377bb98d5ce8d0aa4755dc7e04bd55f;hp=991400da85e969610e7a8bf467cc749220d65bdb;hpb=b87297b8a0b1f79cf2af96d4538658c043a120b5;p=lyx.git diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index 991400da85..c022b875aa 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -23,6 +23,7 @@ import unicodedata import sys, os from parser_tools import find_token, find_end_of, find_tokens, get_value +from unicode_symbols import unicode_reps #################################################################### # Private helper functions @@ -94,7 +95,7 @@ def convert_len(len): "theight%":"\\backslash\ntextheight", "pheight%":"\\backslash\npageheight"} # Convert LyX units to LaTeX units - for unit in units.keys(): + for unit in list(units.keys()): if len.find(unit) != -1: len = '%f' % (len2value(len) / 100) len = len.strip('0') + units[unit] @@ -145,44 +146,6 @@ def set_option(document, m, option, value): return l -def read_unicodesymbols(): - " Read the unicodesymbols list of unicode characters and corresponding commands." - pathname = os.path.abspath(os.path.dirname(sys.argv[0])) - fp = open(os.path.join(pathname.strip('lyx2lyx'), 'unicodesymbols')) - spec_chars = [] - # Two backslashes, followed by some non-word character, and then a character - # in brackets. The idea is to check for constructs like: \"{u}, which is how - # they are written in the unicodesymbols file; but they can also be written - # as: \"u or even \" u. - r = re.compile(r'\\\\(\W)\{(\w)\}') - for line in fp.readlines(): - if line[0] != '#' and line.strip() != "": - line=line.replace(' "',' ') # remove all quotation marks with spaces before - line=line.replace('" ',' ') # remove all quotation marks with spaces after - line=line.replace(r'\"','"') # replace \" by " (for characters with diaeresis) - try: - [ucs4,command,dead] = line.split(None,2) - if command[0:1] != "\\": - continue - spec_chars.append([command, unichr(eval(ucs4))]) - except: - continue - m = r.match(command) - if m != None: - command = "\\\\" - # If the character is a double-quote, then we need to escape it, too, - # since it is done that way in the LyX file. - if m.group(1) == "\"": - command += "\\" - commandbl = command - command += m.group(1) + m.group(2) - commandbl += m.group(1) + ' ' + m.group(2) - spec_chars.append([command, unichr(eval(ucs4))]) - spec_chars.append([commandbl, unichr(eval(ucs4))]) - fp.close() - return spec_chars - - def extract_argument(line): 'Extracts a LaTeX argument from the start of line. Returns (arg, rest).' @@ -269,8 +232,6 @@ def latex2ert(line, isindex): return retval -unicode_reps = read_unicodesymbols() - #Bug 5022.... #Might should do latex2ert first, then deal with stuff that DOESN'T #end up inside ERT. That routine could be modified so that it returned @@ -423,7 +384,7 @@ def lyx2latex(document, lines): continue inert = ert_end >= curline content += lyxline2latex(document, lines[curline], inert) - + return content @@ -793,7 +754,7 @@ def convert_flex(document): document.body[i] = document.body[i].replace('\\begin_inset CharStyle', '\\begin_inset Flex') def revert_flex(document): - "Revert Flex to Charstyle" + "Revert Flex to CharStyle" i = 0 while True: i = find_token(document.body, "\\begin_inset Flex", i) @@ -965,7 +926,7 @@ def revert_pdf_options(document): def remove_inzip_options(document): "Remove inzipName and embed options from the Graphics inset" i = 0 - while 1: + while True: i = find_token(document.body, "\\begin_inset Graphics", i) if i == -1: return @@ -993,7 +954,7 @@ def convert_inset_command(document): LatexCommand cmd """ i = 0 - while 1: + while True: i = find_token(document.body, "\\begin_inset LatexCommand", i) if i == -1: return @@ -1032,7 +993,7 @@ def revert_inset_command(document): will not be able to recognize. Not sure what to do about that. """ i = 0 - while 1: + while True: i = find_token(document.body, "\\begin_inset CommandInset", i) if i == -1: return @@ -1102,7 +1063,7 @@ def revert_wrapfig_options(document): def convert_latexcommand_index(document): - "Convert from LatexCommand form to collapsable form." + "Convert from LatexCommand form to collapsible form." i = 0 r1 = re.compile('name "(.*)"') while True: @@ -1134,7 +1095,7 @@ def convert_latexcommand_index(document): def revert_latexcommand_index(document): - "Revert from collapsable form to LatexCommand form." + "Revert from collapsible form to LatexCommand form." i = 0 while True: i = find_token(document.body, "\\begin_inset Index", i) @@ -1255,7 +1216,7 @@ def revert_japanese_encoding(document): def revert_inset_info(document): 'Replace info inset with its content' i = 0 - while 1: + while True: i = find_token(document.body, '\\begin_inset Info', i) if i == -1: return @@ -1600,7 +1561,7 @@ def convert_macro_global(document): "Remove TeX code command \global when it is in front of a macro" # math macros are nowadays already defined \global, so that an additional # \global would make the document uncompilable, see - # http://bugzilla.lyx.org/show_bug.cgi?id=5371 + # http://www.lyx.org/trac/ticket/5371 # We're looking for something like this: # \begin_inset ERT # status collapsed @@ -1736,7 +1697,7 @@ def convert_serbocroatian(document): def convert_framed_notes(document): "Convert framed notes to boxes. " i = 0 - while 1: + while True: i = find_tokens(document.body, ["\\begin_inset Note Framed", "\\begin_inset Note Shaded"], i) if i == -1: return @@ -1765,7 +1726,7 @@ def convert_module_names(document): return newmodlist = [] for mod in modlist: - if modulemap.has_key(mod): + if mod in modulemap: newmodlist.append(modulemap[mod]) else: document.warning("Can't find module %s in the module map!" % mod) @@ -1813,7 +1774,7 @@ def revert_colsep(document): def revert_framed_notes(document): "Revert framed boxes to notes. " i = 0 - while 1: + while True: i = find_tokens(document.body, ["\\begin_inset Box Framed", "\\begin_inset Box Shaded"], i) if i == -1: @@ -1931,7 +1892,7 @@ def revert_nocite_key(body, start, end): def revert_nocite(document): "Revert LatexCommand nocite to ERT" i = 0 - while 1: + while True: i = find_token(document.body, "\\begin_inset CommandInset citation", i) if i == -1: return @@ -2049,7 +2010,7 @@ def revert_serbianlatin(document): def revert_rotfloat(document): " Revert sideways custom floats. " i = 0 - while 1: + while True: # whitespace intended (exclude \\begin_inset FloatList) i = find_token(document.body, "\\begin_inset Float ", i) if i == -1: @@ -2112,7 +2073,7 @@ def revert_rotfloat(document): def revert_widesideways(document): " Revert wide sideways floats. " i = 0 - while 1: + while True: # whitespace intended (exclude \\begin_inset FloatList) i = find_token(document.body, '\\begin_inset Float ', i) if i == -1: @@ -2164,7 +2125,7 @@ def revert_widesideways(document): def revert_inset_embedding(document, type): ' Remove embed tag from certain type of insets' i = 0 - while 1: + while True: i = find_token(document.body, "\\begin_inset %s" % type, i) if i == -1: return @@ -2189,7 +2150,7 @@ def revert_external_embedding(document): def convert_subfig(document): " Convert subfigures to subfloats. " i = 0 - while 1: + while True: addedLines = 0 i = find_token(document.body, '\\begin_inset Graphics', i) if i == -1: @@ -2229,7 +2190,7 @@ def convert_subfig(document): def revert_subfig(document): " Revert subfloats. " i = 0 - while 1: + while True: # whitespace intended (exclude \\begin_inset FloatList) i = find_tokens(document.body, ['\\begin_inset Float ', '\\begin_inset Wrap'], i) if i == -1: @@ -2733,7 +2694,7 @@ def convert_japanese_plain(document): def revert_pdfpages(document): ' Revert pdfpages external inset to ERT ' i = 0 - while 1: + while True: i = find_token(document.body, "\\begin_inset External", i) if i == -1: return @@ -2835,7 +2796,7 @@ def revert_master(document): def revert_graphics_group(document): ' Revert group information from graphics insets ' i = 0 - while 1: + while True: i = find_token(document.body, "\\begin_inset Graphics", i) if i == -1: return @@ -2865,7 +2826,7 @@ def update_apa_styles(document): "Paragraph*": "Paragraph", "Subparagraph*": "Subparagraph"} i = 0 - while 1: + while True: i = find_token(document.body, "\\begin_layout", i) if i == -1: return @@ -2879,7 +2840,7 @@ def update_apa_styles(document): def convert_paper_sizes(document): ' exchange size options legalpaper and executivepaper to correct order ' - # routine is needed to fix http://bugzilla.lyx.org/show_bug.cgi?id=4868 + # routine is needed to fix http://www.lyx.org/trac/ticket/4868 i = 0 j = 0 i = find_token(document.header, "\\papersize executivepaper", 0)