mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
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.
This commit is contained in:
parent
efb4a26512
commit
c886679160
@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
|
||||
|
||||
-----------------------
|
||||
|
||||
2015-04-21 Jürgen Spitzmüller <spitz@lyx.org>
|
||||
* 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 <spitz@lyx.org>
|
||||
* 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
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
]
|
||||
|
||||
####################################################################
|
||||
|
@ -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]],
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user