# find_tokens, find_token_exact, check_token, get_option_value
from lyx2lyx_tools import (add_to_preamble, put_cmd_in_ert, revert_font_attrs,
- insert_to_preamble, latex_length, revert_language)
+ insert_to_preamble, latex_length, is_document_option,
+ insert_document_option, remove_document_option, revert_language)
####################################################################
# Private helper functions
if j == -1:
document.warning("Malformed LyX document! Can't find end of branch " + old)
continue
- # ourbranches[old] - 1 inverts the selection status of the old branch
lines = ["\\branch " + new,
- "\\selected " + str(ourbranches[old] - 1)]
+ "\\selected %d" % (not ourbranches[old])]
# these are the old lines telling us color, etc.
lines += document.header[i+2 : j+1]
document.header[i:i] = lines
# These are supported by babel and polyglossia
revert_language(document, lang, lang, lang)
-
# TODO:
# def convert_new_babel_languages(document)
# set to native support if get_value(document.header, "\\options") in
# ["bosnian", "friulan", "macedonian", "piedmontese", "romansh"]
-# and "\\language_package babel".
+# and Babel is used.
+
def revert_amharic(document):
"Set the document language to English but assure Amharic output"
i += 1
# href is already fully latexified. Here we can switch off literal.
if inset == "href":
- document.body.insert(i, "literal \"false\"")
+ document.body.insert(i, 'literal "false"')
else:
- document.body.insert(i, "literal \"true\"")
+ document.body.insert(i, 'literal "true"')
i = j + 1
for inset in command_insets:
i = 0
while True:
- i = find_token(document.body, '\\begin_inset CommandInset %s' % inset, i)
+ i = find_token(document.body, '\\begin_inset CommandInset %s' % inset, i+1)
if i == -1:
break
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" % (inset, i))
- i += 1
- continue
- k = find_token(document.body, 'literal', i, j)
- if k == -1:
- i += 1
continue
- del document.body[k]
+ del_token(document.body, 'literal', i, j)
def revert_multibib(document):
def convert_mathnumberpos(document):
" add the \\math_number_before tag "
+ i = find_token(document.header, "\\quotes_style")
# check if the document uses the class option "leqno"
- i = find_token(document.header, "\\options")
- k = find_token(document.header, "\\quotes_style")
- if 'leqno' in document.header[i]:
- document.header.insert(k, "\\math_number_before 1")
- # delete the found option
- document.header[i] = document.header[i].replace(",leqno", "")
- document.header[i] = document.header[i].replace(", leqno", "")
- document.header[i] = document.header[i].replace("leqno,", "")
- if 'leqno' in document.header[i]:
- # then we have leqno as the only option
- del document.header[i]
+ if is_document_option(document, "leqno"):
+ remove_document_option(document, "leqno")
+ document.header.insert(i, "\\math_number_before 1")
else:
- document.header.insert(k, "\\math_number_before 0")
+ document.header.insert(i, "\\math_number_before 0")
def revert_mathnumberpos(document):
"""Remove \\math_number_before tag,
add the document class option leqno if required.
"""
- math_number_before = get_bool_value(document.header,
- '\\math_number_before', delete=True)
+ math_number_before = get_bool_value(document.header, '\\math_number_before',
+ delete=True)
if math_number_before:
- i = find_token(document.header, "\\options")
- if i != -1 and 'leqno' not in document.header[i]:
- document.header[i] = document.header[i].replace("\\options", "\\options leqno,")
- else:
- i = find_token(document.header, "\\use_default_options")
- document.header.insert(i, "\\options leqno")
+ insert_document_option(document, "leqno")
def convert_mathnumberingname(document):