From c8866791605df4310b8c1dbcaeb67714007dac2a Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Tue, 21 Apr 2015 20:33:35 +0200 Subject: [PATCH] Rewrite the linguistic Glosse insets. This gets rid of the PassThru hack and makes the inset actually usable for linguistists. Fixes: #7773 File format change. --- development/FORMAT | 5 ++ lib/layouts/linguistics.module | 49 ++++++++--- lib/lyx2lyx/LyX.py | 2 +- lib/lyx2lyx/lyx_2_2.py | 154 ++++++++++++++++++++++++++++++++- src/version.h | 4 +- 5 files changed, 195 insertions(+), 19 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index ff9cd12e9e..a0bf4fa315 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx. ----------------------- +2015-04-21 Jürgen Spitzmüller + * Format incremented to 488: Rewrite the Glosse insets (Glosse and Tri-Glosse). + These insets now do not any longer use PassThru. Instead, they use an optional + argument which is output as the glosse translation. + 2015-04-20 Jürgen Spitzmüller * Format incremented to 487: Support the forest environment of the forest package. Note that this inset does not escape brackets in braces, i.e. [ and ] are output diff --git a/lib/layouts/linguistics.module b/lib/layouts/linguistics.module index 22da764099..c887e239f1 100644 --- a/lib/layouts/linguistics.module +++ b/lib/layouts/linguistics.module @@ -65,7 +65,6 @@ End # glosse (2 lines) with covington.sty -# mandatory translation must be entered verbatim! InsetLayout Flex:Glosse LyXType custom LabelString Glosse @@ -78,24 +77,29 @@ InsetLayout Flex:Glosse MultiPar true CustomPars false ForcePlain true - PassThru true ParbreakIsNewline true FreeSpacing true - ForceLTR true Requires covington Preamble + \def\glosstr{} \@ifundefined{linggloss}{% - \newenvironment{linggloss}[1]{% - \gll #1} - {\glend}}{} + \newenvironment{linggloss}[2][]{ + \def\glosstr{\glt #1}% + \gll #2} + {\glosstr\glend}}{} EndPreamble InToc true - ResetsFont true + ResetsFont true + Argument 1 + Decoration conglomerate + LabelString "Translation" + MenuString "Glosse Translation|s" + Tooltip "Add a translation for the glosse" + EndArgument End # glosse (3 lines) with covington.sty -# mandatory translation must be entered verbatim! InsetLayout Flex:Tri-Glosse LyXType custom LabelString Tri-Glosse @@ -108,21 +112,28 @@ InsetLayout Flex:Tri-Glosse MultiPar true CustomPars false ForcePlain true - PassThru true ParbreakIsNewline true FreeSpacing true - ForceLTR true InToc true Requires covington Preamble + \def\glosstr{} \@ifundefined{lingglosss}{% - \newenvironment{lingglosss}[1]{% - \glll #1} - {\glend}}{} + \newenvironment{lingglosss}[2][]{ + \def\glosstr{\glt #1}% + \glll #2} + {\glosstr\glend}}{} EndPreamble - ResetsFont true + ResetsFont true + Argument 1 + Decoration conglomerate + LabelString "Translation" + MenuString "Glosse Translation|s" + Tooltip "Add a translation for the glosse" + EndArgument End + # Structure trees via the forest package InsetLayout Flex:Structure_Tree LyXType custom @@ -190,6 +201,16 @@ InsetLayout Flex:Meaning End +# A helper to group words in Glosses +InsetLayout Flex:GroupGlossedWords + LyxType charstyle + LabelString Group + LeftDelim { + RightDelim } + ResetsFont true +End + + # Tableaux for Optimality Theory Float Type tableau diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index 055fcbd010..f5e6e4079b 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -85,7 +85,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)), ("1_6", list(range(277,346)), minor_versions("1.6" , 10)), ("2_0", list(range(346,414)), minor_versions("2.0" , 8)), ("2_1", list(range(414,475)), minor_versions("2.1" , 0)), - ("2_2", list(range(475,488)), minor_versions("2.2" , 0)) + ("2_2", list(range(475,489)), minor_versions("2.2" , 0)) ] #################################################################### diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py index 98c0779881..024ce8724e 100644 --- a/lib/lyx2lyx/lyx_2_2.py +++ b/lib/lyx2lyx/lyx_2_2.py @@ -796,7 +796,6 @@ def revert_forest(document): beginPlain = find_token(document.body, "\\begin_layout Plain Layout", i) endPlain = find_end_of_layout(document.body, beginPlain) content = lyx2latex(document, document.body[beginPlain : endPlain]) - document.warning("content: %s" % content) add_to_preamble(document, ["\\usepackage{forest}"]) @@ -808,6 +807,155 @@ def revert_forest(document): # no need to reset i +def revert_glossgroup(document): + " Reverts the GroupGlossedWords inset (Linguistics module) to TeX-code " + + # Do we use the linguistics module? + have_mod = False + mods = document.get_module_list() + for mod in mods: + if mod == "linguistics": + have_mod = True + continue + + if not have_mod: + return + + i = 0 + while True: + i = find_token(document.body, "\\begin_inset Flex GroupGlossedWords", i) + if i == -1: + return + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Malformed LyX document: Can't find end of GroupGlossedWords inset") + i += 1 + continue + + beginPlain = find_token(document.body, "\\begin_layout Plain Layout", i) + endPlain = find_end_of_layout(document.body, beginPlain) + content = lyx2latex(document, document.body[beginPlain : endPlain]) + document.warning("content: %s" % content) + + document.body[i:j + 1] = ["{", "", content, "", "}"] + # no need to reset i + + +def revert_newgloss(document): + " Reverts the new Glosse insets (Linguistics module) to the old format " + + # Do we use the linguistics module? + have_mod = False + mods = document.get_module_list() + for mod in mods: + if mod == "linguistics": + have_mod = True + continue + + if not have_mod: + return + + glosses = ("\\begin_inset Flex Glosse", "\\begin_inset Flex Tri-Glosse") + for glosse in glosses: + i = 0 + while True: + i = find_token(document.body, glosse, i) + 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 Glosse inset") + i += 1 + continue + + arg = find_token(document.body, "\\begin_inset Argument 1", i, j) + endarg = find_end_of_inset(document.body, arg) + argcontent = "" + if arg != -1: + argbeginPlain = find_token(document.body, "\\begin_layout Plain Layout", arg, endarg) + if argbeginPlain == -1: + document.warning("Malformed LyX document: Can't find arg plain Layout") + i += 1 + continue + argendPlain = find_end_of_inset(document.body, argbeginPlain) + argcontent = lyx2latex(document, document.body[argbeginPlain : argendPlain - 2]) + + document.body[j:j] = ["", "\\begin_layout Plain Layout","\\backslash", "glt ", + argcontent, "\\end_layout"] + + # remove Arg insets and paragraph, if it only contains this inset + if document.body[arg - 1] == "\\begin_layout Plain Layout" and find_end_of_layout(document.body, arg - 1) == endarg + 3: + del document.body[arg - 1 : endarg + 4] + else: + del document.body[arg : endarg + 1] + + beginPlain = find_token(document.body, "\\begin_layout Plain Layout", i) + endPlain = find_end_of_layout(document.body, beginPlain) + content = lyx2latex(document, document.body[beginPlain : endPlain]) + + document.body[beginPlain + 1:endPlain] = [content] + i = beginPlain + 1 + + +def convert_newgloss(document): + " Converts Glosse insets (Linguistics module) to the new format " + + # Do we use the linguistics module? + have_mod = False + mods = document.get_module_list() + for mod in mods: + if mod == "linguistics": + have_mod = True + continue + + if not have_mod: + return + + glosses = ("\\begin_inset Flex Glosse", "\\begin_inset Flex Tri-Glosse") + for glosse in glosses: + i = 0 + while True: + i = find_token(document.body, glosse, i) + 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 Glosse inset") + i += 1 + continue + + k = i + while True: + argcontent = [] + beginPlain = find_token(document.body, "\\begin_layout Plain Layout", k, j) + if beginPlain == -1: + break + endPlain = find_end_of_layout(document.body, beginPlain) + if endPlain == -1: + document.warning("Malformed LyX document: Can't find end of Glosse layout") + i += 1 + continue + + glt = find_token(document.body, "\\backslash", beginPlain, endPlain) + if glt != -1 and document.body[glt + 1].startswith("glt"): + document.body[glt + 1] = document.body[glt + 1].lstrip("glt").lstrip() + argcontent = document.body[glt + 1 : endPlain] + document.body[beginPlain + 1 : endPlain] = ["\\begin_inset Argument 1", "status open", "", + "\\begin_layout Plain Layout", "\\begin_inset ERT", "status open", "", + "\\begin_layout Plain Layout", ""] + argcontent + ["\\end_layout", "", "\\end_inset", "", + "\\end_layout", "", "\\end_inset"] + else: + content = document.body[beginPlain + 1 : endPlain] + document.body[beginPlain + 1 : endPlain] = ["\\begin_inset ERT", "status open", "", + "\\begin_layout Plain Layout"] + content + ["\\end_layout", "", "\\end_inset"] + + endPlain = find_end_of_layout(document.body, beginPlain) + k = endPlain + j = find_end_of_inset(document.body, i) + + i = endPlain + 1 + + ## # Conversion hub # @@ -829,10 +977,12 @@ convert = [ [484, []], [485, []], [486, []], - [487, []] + [487, []], + [488, [convert_newgloss]] ] revert = [ + [486, [revert_newgloss, revert_glossgroup]], [486, [revert_forest]], [485, [revert_ex_itemargs]], [484, [revert_sigplan_doi]], diff --git a/src/version.h b/src/version.h index 31466b4637..e52d96babe 100644 --- a/src/version.h +++ b/src/version.h @@ -32,8 +32,8 @@ extern char const * const lyx_version_info; // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -#define LYX_FORMAT_LYX 487 // spitz: support for forest environment -#define LYX_FORMAT_TEX2LYX 487 +#define LYX_FORMAT_LYX 488 // spitz: rework the Glosse insets +#define LYX_FORMAT_TEX2LYX 488 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER -- 2.39.2