# Uncomment only what you need to import, please.
-#from parser_tools import find_token, find_end_of, find_tokens, \
-# find_token_exact, find_end_of_inset, find_end_of_layout, \
-# find_token_backwards, is_in_inset, get_value, get_quoted_value, \
-# del_token, check_token, get_option_value
-
from lyx2lyx_tools import (add_to_preamble, put_cmd_in_ert, get_ert,
- lyx2latex, lyx2verbatim, length_in_bp, convert_info_insets)
-# insert_to_preamble, latex_length, revert_flex_inset,
-# revert_font_attrs, hex2ratio, str2bool
+ lyx2latex, lyx2verbatim, length_in_bp, convert_info_insets, insert_document_option)
from parser_tools import (check_token, del_complete_lines,
find_end_of_inset, find_end_of_layout, find_nonempty_line, find_re,
if document.backend != "latex":
return
- for phrase in phrases:
- i = 0
- while i < len(document.body):
+ i = 0
+ while i < len(document.body):
+ if document.body[i] and document.body[i][0] == "\\":
words = document.body[i].split()
if len(words) > 1 and words[0] == "\\begin_inset" and \
- words[1] in ["CommandInset", "External", "Formula", "Graphics", "listings"]:
+ words[1] in ["CommandInset", "External", "Formula", "Graphics", "listings"]:
# must not replace anything in insets that store LaTeX contents in .lyx files
# (math and command insets without overridden read() and write() methods)
j = find_end_of_inset(document.body, i)
if j == -1:
- document.warning("Malformed LyX document: Can't find end of inset at line " + str(i))
+ document.warning("Malformed LyX document: Can't find end of inset at line %d" % (i))
i += 1
else:
i = j
- continue
- if document.body[i].find("\\") == 0:
+ else:
i += 1
- continue
+ continue
+ for phrase in phrases:
j = document.body[i].find(phrase)
if j == -1:
- i += 1
continue
if not is_part_of_converted_phrase(document.body[i], j, phrase):
front = document.body[i][:j]
document.body.insert(i+1, back)
# We cannot use SpecialChar since we do not know whether we are outside passThru
document.body[i] = front + "\\SpecialCharNoPassThru \\" + phrase
- i += 1
+ i += 1
def revert_phrases(document):
- "convert special phrases to plain text"
+ "revert special phrases to plain text"
i = 0
while i < len(document.body):
i = 0
while i < len(document.body):
- words = document.body[i].split()
- if len(words) > 1 and words[0] == "\\begin_inset" and \
- words[1] in ["CommandInset", "External", "Formula", "Graphics", "listings"]:
- # see convert_phrases
- j = find_end_of_inset(document.body, i)
- if j == -1:
- document.warning("Malformed LyX document: Can't find end of Formula inset at line " + str(i))
- i += 1
- else:
- i = j
+ if document.body[i] and document.body[i][0] == "\\":
+ words = document.body[i].split()
+ if len(words) > 1 and words[0] == "\\begin_inset" and \
+ words[1] in ["CommandInset", "External", "Formula", "Graphics", "listings"]:
+ # see convert_phrases
+ j = find_end_of_inset(document.body, i)
+ if j == -1:
+ document.warning("Malformed LyX document: Can't find end of %s inset at line %d" % (words[1], i))
+ i += 1
+ else:
+ i = j
+ continue
+ # else...
+ if not "\\SpecialChar" in document.body[i]:
+ i += 1
continue
for key, value in specialchars.items():
if forward:
j = find_token(document.header, "\\language_package default", 0)
if j != -1:
document.header[j] = "\\language_package babel"
- k = find_token(document.header, "\\options", 0)
- if k != -1:
- document.header[k] = document.header[k].replace("\\options", "\\options georgian,")
- else:
- l = find_token(document.header, "\\use_default_options", 0)
- document.header.insert(l + 1, "\\options georgian")
+ insert_document_option(document, "georgian")
def revert_sigplan_doi(document):