commit 8e06c2ffa9d2c4ab17a793c309b8c93ffadaa9fe
Author: Günter Milde <[email protected]>
Date: Mon Jun 3 09:03:13 2019 +0200
Fix some problems with lyx2lyx_tools.revert_languages().
Amends 7bb30286.
Tested cases are now handled fine.
(There are still many cases where the language support emulation
is too complex for lyx2lyx and manual fixes are required after
lyx2lyx conversion.)
---
development/autotests/invertedTests | 6 ------
lib/lyx2lyx/lyx2lyx_tools.py | 23 +++++++++++++++++++----
lib/lyx2lyx/lyx_2_3.py | 4 ++--
3 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/development/autotests/invertedTests
b/development/autotests/invertedTests
index d5df2ec..c9bd826 100644
--- a/development/autotests/invertedTests
+++ b/development/autotests/invertedTests
@@ -77,12 +77,6 @@ export/examples/ja/Graphics_and_Insets/XY-Pic.*_systemF
# Document class js*.cls requires platex <-> Xe/LuaTeX,
# fixed with "bxjs*.cls"
-# lyx2lyx: revert_language() compilation errors (cf. #9633)
-# ! LaTeX Error: \begin{otherlanguage} on input line 36 ended by \end{quote}.
-# with friulan, occitan, and piedmontese also:
-# ! LaTeX Error: Can be used only in preamble.
-# l.42 \AtEndPreamble
-export/export/lyx2lyx/revert-languages-.*_lyx(16|2[012])
# ================================================
Sublabel: lyxbugs
diff --git a/lib/lyx2lyx/lyx2lyx_tools.py b/lib/lyx2lyx/lyx2lyx_tools.py
index d59ec15..97745b1 100644
--- a/lib/lyx2lyx/lyx2lyx_tools.py
+++ b/lib/lyx2lyx/lyx2lyx_tools.py
@@ -657,7 +657,7 @@ def revert_language(document, lyxname, babelname="",
polyglossianame=""):
document.warning("Malformed document! Missing \\language_package")
else:
pack = get_value(document.header, "\\language_package", i)
- if pack == "default" or pack == "auto":
+ if pack in ("default", "auto"):
use_polyglossia = True
# Do we use this language with polyglossia?
@@ -704,6 +704,18 @@ def revert_language(document, lyxname, babelname="",
polyglossianame=""):
document.body.insert(i, " ")
continue
+ # TODO: handle nesting issues with font attributes, e.g.
+ # \begin_layout Standard
+ #
+ # \emph on
+ # \lang macedonian
+ # Македонски јазик
+ # \emph default
+ # — јужнословенски јазик, дел од групата на словенски јазици од
јазичното
+ # семејство на индоевропски јазици.
+ # Македонскиот е службен и национален јазик во Македонија.
+ # \end_layout
+
# Ensure correct handling of list labels
if (parent[0] in ["Labeling", "Description"]
and not " " in "\n".join(document.body[parent[3]:i])):
@@ -767,8 +779,11 @@ def revert_language(document, lyxname, babelname="",
polyglossianame=""):
end_cmd = "\\end{otherlanguage}"
if (not primary or texname == "english"):
- document.body[i_e:i_e] = put_cmd_in_ert(end_cmd)
- document.body[i+1:i+1] = put_cmd_in_ert(begin_cmd)
+ try:
+ document.body[i_e:i_e] = put_cmd_in_ert(end_cmd)
+ document.body[i+1:i+1] = put_cmd_in_ert(begin_cmd)
+ except UnboundLocalError:
+ pass
del document.body[i]
if not (primary or secondary):
@@ -794,6 +809,6 @@ def revert_language(document, lyxname, babelname="",
polyglossianame=""):
doc_lang_switch = "\\resetdefaultlanguage{%s}" % polyglossianame
# Reset LaTeX main language if required and not already done
- if doc_lang_switch and doc_lang_switch not in document.body[8:20] !=
doc_lang_switch:
+ if doc_lang_switch and doc_lang_switch[1:] not in document.body[8:20]:
document.body[2:2] = put_cmd_in_ert(doc_lang_switch,
is_open=True, as_paragraph=True)
diff --git a/lib/lyx2lyx/lyx_2_3.py b/lib/lyx2lyx/lyx_2_3.py
index 48e0dab..ff9f784 100644
--- a/lib/lyx2lyx/lyx_2_3.py
+++ b/lib/lyx2lyx/lyx_2_3.py
@@ -221,12 +221,12 @@ def revert_new_babel_languages(document):
# 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"