remove_document_option(document, option):
Remove _option_ as a document option.
+
+revert_language(document, lyxname, babelname, polyglossianame):
+ Reverts native language support to ERT
+ If babelname or polyglossianame is empty, it is assumed
+ this language package is not supported for the given language.
'''
import re
-from parser_tools import find_token, find_end_of_inset, get_containing_layout
+from parser_tools import find_token, find_end_of_inset, get_containing_layout, get_value, get_bool_value
from unicode_symbols import unicode_reps
# This will accept either a list of lines or a single line.
return False
return True
+
+
+def revert_language(document, lyxname, babelname, polyglossianame):
+ " Revert native language support "
+
+ # Are we using polyglossia?
+ use_polyglossia = False
+ if get_bool_value(document.header, "\\use_non_tex_fonts"):
+ i = find_token(document.header, "\\language_package")
+ if i == -1:
+ document.warning("Malformed document! Missing \\language_package")
+ else:
+ pack = get_value(document.header, "\\language_package", i)
+ if pack == "default" or pack == "auto":
+ use_polyglossia = True
+
+ # Main language first
+ if document.language == lyxname:
+ document.language = "english"
+ i = find_token(document.header, "\\language %s" % lyxname, 0)
+ if i != -1:
+ document.header[i] = "\\language english"
+ j = find_token(document.header, "\\language_package default", 0)
+ if j != -1:
+ document.header[j] = "\\language_package default"
+ if use_polyglossia and polyglossianame != "":
+ add_to_preamble(document, ["\\AtBeginDocument{\setotherlanguage{%s}}" % polyglossianame])
+ document.body[2 : 2] = ["\\begin_layout Standard",
+ "\\begin_inset ERT", "status open", "",
+ "\\begin_layout Plain Layout", "", "",
+ "\\backslash",
+ "resetdefaultlanguage{%s}" % polyglossianame,
+ "\\end_layout", "", "\\end_inset", "", "",
+ "\\end_layout", ""]
+ elif babelname != "":
+ k = find_token(document.header, "\\options")
+ if k != -1:
+ document.header[k] = document.header[k].replace("\\options",
+ "\\options %s," % babelname)
+ else:
+ l = find_token(document.header, "\\use_default_options")
+ document.header.insert(l + 1, "\\options %s," % babelname)
+
+ # now inline switches
+ envname = babelname
+ if use_polyglossia:
+ envname = polyglossianame
+ i = 0
+ while True:
+ i = find_token(document.body, '\\lang', i)
+ if i == -1:
+ return
+ if document.body[i].startswith('\\lang %s' % lyxname):
+ if use_polyglossia and polyglossianame != "":
+ add_to_preamble(document, ["\\AtBeginDocument{\setotherlanguage{%s}}" % polyglossianame])
+ if (use_polyglossia and polyglossianame != "") or (use_polyglossia == False and babelname != ""):
+ parent = get_containing_layout(document.body, i)
+ document.body[parent[2] : parent[2]] = ["\\begin_layout Standard",
+ "\\begin_inset ERT", "status open", "",
+ "\\begin_layout Plain Layout", "", "",
+ "\\backslash",
+ "end{%s}" % envname,
+ "\\end_layout", "", "\\end_inset", "", "",
+ "\\end_layout", ""]
+ del document.body[i]
+ if (use_polyglossia and polyglossianame != "") or (use_polyglossia == False and babelname != ""):
+ document.body[i : i] = ["\\begin_inset ERT", "status open", "",
+ "\\begin_layout Plain Layout", "", "",
+ "\\backslash",
+ "begin{%s}" % envname,
+ "\\end_layout", "", "\\end_inset", "", "",
+ ""]
+
# is_in_inset, set_bool_value
# find_tokens, find_token_exact, check_token
-from lyx2lyx_tools import (put_cmd_in_ert, add_to_preamble)
+from lyx2lyx_tools import (put_cmd_in_ert, add_to_preamble, revert_language)
# revert_font_attrs, insert_to_preamble, latex_length
# get_ert, lyx2latex, lyx2verbatim, length_in_bp, convert_info_insets
# revert_flex_inset, hex2ratio, str2bool
"lowersorbian" : ["%A, %d. %B %Y", "%d.%m.%y", "%d %B %Y", "%d %b %Y", "%d.%m.%Y"],
"macedonian" : ["%A, %d %B %Y", "%d.%m.%y", "%d %B %Y", "%d %b %Y", "%d.%m.%Y"],
"magyar" : ["%Y. %B %d., %A", "%Y. %m. %d.", "%Y. %B %d.", "%Y. %b %d.", "%Y.%m.%d."],
+ "malayalam" : ["%A, %d %B, %Y", "%d/%m/%y", "%d %B %Y", "%d %b %Y", "%d-%m-%Y"],
"marathi" : ["%A, %d %B, %Y", "%d/%m/%y", "%d %B %Y", "%d %b %Y", "%d-%m-%Y"],
"mongolian" : ["%A, %Y оны %m сарын %d", "%Y-%m-%d", "%Y оны %m сарын %d", "%d-%m-%Y", "%d-%m-%Y"],
"naustrian" : ["%A, %d. %B %Y", "%d.%m.%y", "%d. %B %Y", "%d. %b %Y", "%d.%m.%Y"],
"lowersorbian" : ["%H:%M:%S %Z", "%H:%M"],
"macedonian" : ["%H:%M:%S %Z", "%H:%M"],
"magyar" : ["%H:%M:%S %Z", "%H:%M"],
+ "malayalam" : ["%p %I:%M:%S %Z", "%p %I:%M"],
"marathi" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"mongolian" : ["%H:%M:%S %Z", "%H:%M"],
"naustrian" : ["%H:%M:%S %Z", "%H:%M"],
convert_hebrew_parentheses(document)
+def revert_malayalam(document):
+ " Set the document language to English but assure Malayalam output "
+
+ revert_language(document, "malayalam", "", "malayalam")
+
+
##
# Conversion hub
#
[564, []],
[565, [convert_AdobeFonts]], # Handle adobe fonts in GUI
[566, [convert_hebrew_parentheses]],
+ [567, []],
]
revert = [
+ [566, [revert_malayalam]],
[565, [revert_hebrew_parentheses]],
[564, [revert_AdobeFonts]],
[563, [revert_lformatinfo]],