# Uncomment only what you need to import, please.
-from parser_tools import count_pars_in_inset, del_token, find_token, find_token_exact, \
+from parser_tools import count_pars_in_inset, del_complete_lines, del_token, \
+ find_token, find_token_exact, \
find_token_backwards, find_end_of, find_end_of_inset, find_end_of_layout, \
find_end_of_sequence, find_re, get_option_value, get_containing_layout, \
get_containing_inset, get_value, get_quoted_value, set_option_value
#find_end_of_inset, find_end_of_layout, \
#is_in_inset, del_token, check_token
-from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert
+from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert, revert_language
#from lyx2lyx_tools import insert_to_preamble, \
# lyx2latex, latex_length, revert_flex_inset, \
else:
beginBrace = find_token(document.body, "{", endBrace, end_layout)
# assure that the ERTs are consecutive (11 or 12 depending if there is a space between the ERTs or not)
- if beginBrance != -1 and (beginBrace == endBrace + 11 or beginBrace == endBrace + 12):
+ if beginBrace != -1 and (beginBrace == endBrace + 11 or beginBrace == endBrace + 12):
end = find_token(document.body, "\\end_inset", beginBrace)
document.body[lineERT : end + 1] = ["\\end_layout", "", "\\end_inset"]
if loop == 1:
def revert_negative_space(document):
- "Revert InsetSpace negmedspace and negthickspace into its TeX-code counterpart"
+ "Revert InsetSpace negmedspace and negthickspace into their TeX-code counterparts"
i = 0
j = 0
reverted = False
if reverted == True:
i = find_token(document.header, "\\use_amsmath 2", 0)
if i == -1:
- add_to_preamble(document, ["\\@ifundefined{negthickspace}{\\usepackage{amsmath}}"])
+ add_to_preamble(document, ["\\@ifundefined{negthickspace}{\\usepackage{amsmath}}{}"])
return
if i == -1:
return
get_option_value(document.body[begin_row], 'endlastfoot') != 'true'):
document.body[begin_row] = set_option_value(document.body[begin_row], 'caption', 'true", endfirsthead="true')
elif get_option_value(document.body[begin_row], 'caption') == 'true':
- if get_option_value(document.body[begin_row], 'endfirsthead') == 'true':
- document.body[begin_row] = set_option_value(document.body[begin_row], 'endfirsthead', 'false')
if get_option_value(document.body[begin_row], 'endhead') == 'true':
document.body[begin_row] = set_option_value(document.body[begin_row], 'endhead', 'false')
if get_option_value(document.body[begin_row], 'endfoot') == 'true':
# oldauto defines how the version we are converting from behaves:
# if it is true, the old version uses the package automatically.
# if it is false, the old version never uses the package.
- i = find_token(document.header, "\\use_package", 0)
+ i = find_token(document.header, "\\use_package")
if i == -1:
document.warning("Malformed LyX document: Can't find \\use_package.")
return;
- j = find_token(document.preamble, "\\usepackage{" + pkg + "}", 0)
- if j != -1:
- # package was loaded in the preamble, convert this to header setting for round trip
+ packageline = "\\usepackage{%s}" % pkg
+ if (del_complete_lines(document.preamble,
+ ['% Added by lyx2lyx', packageline]) or
+ del_complete_lines(document.preamble, [packageline])):
+ # package was loaded in the preamble, convert this to header setting
document.header.insert(i + 1, "\\use_package " + pkg + " 2") # on
- del document.preamble[j]
# If oldauto is true we have two options:
# We can either set the package to auto - this is correct for files in
# format 425 to 463, and may create a conflict for older files which use
def revert_languages(document):
"Set the document language for new supported languages to English"
- languages = [
- "coptic", "divehi", "hindi", "kurmanji", "lao", "marathi", "occitan", "sanskrit",
- "syriac", "tamil", "telugu", "urdu"
- ]
- for n in range(len(languages)):
- if document.language == languages[n]:
- document.language = "english"
- i = find_token(document.header, "\\language", 0)
- if i != -1:
- document.header[i] = "\\language english"
- j = 0
- while j < len(document.body):
- j = find_token(document.body, "\\lang " + languages[n], j)
- if j != -1:
- document.body[j] = document.body[j].replace("\\lang " + languages[n], "\\lang english")
- j += 1
- else:
- j = len(document.body)
+ # polyglossia-only
+ polyglossia_languages = ["coptic", "divehi", "hindi", "lao", "marathi",
+ "occitan", "sanskrit", "syriac", "tamil",
+ "telugu", "urdu"]
+ # babel-only
+ babel_languages = ["kurmanji"]
+ for lang in polyglossia_languages:
+ revert_language(document, lang, "", lang)
+ for lang in babel_languages:
+ revert_language(document, lang, lang, "")
def convert_armenian(document):
"theorems-chap-bytype", "theorems-chap", "theorems-named", "theorems-sec-bytype",
"theorems-sec", "theorems-starred", "theorems-std", "todonotes"]
# Modules we need to take care of
- caveat_modules = ["initials"]
+ caveat_modules = ["initials"] # TODO: , "graphicboxes", "bicaption"]
# information about the relevant styles in caveat_modules (number of opt and req args)
# use this if we get more caveat_modules. For now, use hard coding (see below).
# initials = [{'Layout' : 'Initial', 'opt' : 1, 'req' : 1}]
+ # graphicboxes = { ... }
# Is this a known safe layout?
safe_layout = document.textclass in safe_layouts
"Bicaption" : "Bicaption",
}
- i = 0
- while True:
- i = find_token(document.body, "\\begin_layout", i)
- if i == -1:
- return
- val = get_value(document.body, "\\begin_layout", i)
- if val in list(caption_dict.keys()):
+ for captype in caption_dict.keys():
+ i = 0
+ while True:
+ i = find_token(document.body, "\\begin_layout " + captype, i)
+ if i == -1:
+ break
j = find_end_of_layout(document.body, i)
if j == -1:
document.warning("Malformed LyX document: Missing `\\end_layout'.")
- return
+ break
document.body[j:j] = ["\\end_layout", "", "\\end_inset", "", ""]
document.body[i:i+1] = ["\\begin_layout %s" % document.default_layout,
- "\\begin_inset Caption %s" % caption_dict[val], "",
+ "\\begin_inset Caption %s" % caption_dict[captype], "",
"\\begin_layout %s" % document.default_layout]
- i += 1
+ i = j + 1
def revert_captionlayouts(document):
def revert_tibetan(document):
"Set the document language for Tibetan to English"
- if document.language == "tibetan":
- document.language = "english"
- i = find_token(document.header, "\\language", 0)
- if i != -1:
- document.header[i] = "\\language english"
- j = 0
- while j < len(document.body):
- j = find_token(document.body, "\\lang tibetan", j)
- if j != -1:
- document.body[j] = document.body[j].replace("\\lang tibetan", "\\lang english")
- j += 1
- else:
- j = len(document.body)
+ revert_language(document, "tibetan", "", "tibetan")
#############