mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +00:00
Update covington support in linguistics module (file format change)
This commit is contained in:
parent
11f44c00e0
commit
2841a1c063
@ -7,6 +7,15 @@ changes happened in particular if possible. A good example would be
|
|||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
2023-07-20 Jürgen Spitzmüller <spitz@lyx.org>
|
||||||
|
* Format incremented to 617: Update covington support in linguistics module:
|
||||||
|
- Support enviroment option of example and examples
|
||||||
|
- Support angular item argument of examples and subexamples (this shifts item
|
||||||
|
argument structure)
|
||||||
|
- Support new optional arguments of \digloss and \trigloss (this shifts argument
|
||||||
|
structure)
|
||||||
|
- Support \expreamble and \subexpreamble macros
|
||||||
|
|
||||||
2022-12-25 Richard Kimberly Heck <rikiheck@lyx.org>
|
2022-12-25 Richard Kimberly Heck <rikiheck@lyx.org>
|
||||||
* Format incremented to 614: New "Other" type for hyperlinks
|
* Format incremented to 614: New "Other" type for hyperlinks
|
||||||
|
|
||||||
|
@ -81,6 +81,12 @@ Style Numbered_Example_(multiline)
|
|||||||
Color textlabel1
|
Color textlabel1
|
||||||
EndFont
|
EndFont
|
||||||
Requires covington
|
Requires covington
|
||||||
|
Argument 1
|
||||||
|
LabelString "Example options"
|
||||||
|
MenuString "Examples options|s"
|
||||||
|
Tooltip "Add examples options here"
|
||||||
|
PassThru 1
|
||||||
|
EndArgument
|
||||||
Category Linguistics
|
Category Linguistics
|
||||||
DocBookWrapperTag informalexample
|
DocBookWrapperTag informalexample
|
||||||
DocBookWrapperAttr role='numbered'
|
DocBookWrapperAttr role='numbered'
|
||||||
@ -108,6 +114,12 @@ Style Numbered_Examples_(consecutive)
|
|||||||
EndFont
|
EndFont
|
||||||
EndArgument
|
EndArgument
|
||||||
Argument item:1
|
Argument item:1
|
||||||
|
LabelString "Judgment|J"
|
||||||
|
Tooltip "Grammaticality judgment marker"
|
||||||
|
LeftDelim <
|
||||||
|
RightDelim >
|
||||||
|
EndArgument
|
||||||
|
Argument item:2
|
||||||
LabelString "Custom Numbering|s"
|
LabelString "Custom Numbering|s"
|
||||||
Tooltip "Customize the numeration"
|
Tooltip "Customize the numeration"
|
||||||
EndArgument
|
EndArgument
|
||||||
@ -135,6 +147,21 @@ Style Subexample
|
|||||||
HTMLClass SubExample
|
HTMLClass SubExample
|
||||||
End
|
End
|
||||||
|
|
||||||
|
InsetLayout Flex:Example_Preamble
|
||||||
|
LyXType custom
|
||||||
|
Decoration classic
|
||||||
|
LatexType command
|
||||||
|
LatexName expreamble
|
||||||
|
LabelString "Ex. Preamble"
|
||||||
|
ResetsFont true
|
||||||
|
End
|
||||||
|
|
||||||
|
InsetLayout Flex:Subexample_Preamble
|
||||||
|
CopyStyle Flex:Example_Preamble
|
||||||
|
LatexName subexpreamble
|
||||||
|
LabelString "Subex. Preamble"
|
||||||
|
End
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Interlinear Glosses
|
# Interlinear Glosses
|
||||||
@ -164,6 +191,11 @@ InsetLayout Flex:Interlinear_Gloss_(2_Lines)
|
|||||||
Tooltip "Add digloss options here"
|
Tooltip "Add digloss options here"
|
||||||
EndArgument
|
EndArgument
|
||||||
Argument post:1
|
Argument post:1
|
||||||
|
LabelString "Sentence Comment"
|
||||||
|
MenuString "Sentence Comment"
|
||||||
|
Tooltip "Add an optional sentence comment here"
|
||||||
|
EndArgument
|
||||||
|
Argument post:2
|
||||||
Decoration conglomerate
|
Decoration conglomerate
|
||||||
LabelString "Interlinear Gloss"
|
LabelString "Interlinear Gloss"
|
||||||
MenuString "Interlinear Gloss"
|
MenuString "Interlinear Gloss"
|
||||||
@ -173,7 +205,12 @@ InsetLayout Flex:Interlinear_Gloss_(2_Lines)
|
|||||||
FreeSpacing true
|
FreeSpacing true
|
||||||
InsertOnNewline true
|
InsertOnNewline true
|
||||||
EndArgument
|
EndArgument
|
||||||
Argument post:2
|
Argument post:3
|
||||||
|
LabelString "Gloss Comment"
|
||||||
|
MenuString "Gloss Comment"
|
||||||
|
Tooltip "Add an optional gloss comment here"
|
||||||
|
EndArgument
|
||||||
|
Argument post:4
|
||||||
Decoration conglomerate
|
Decoration conglomerate
|
||||||
LabelString "Translation"
|
LabelString "Translation"
|
||||||
MenuString "Gloss Translation"
|
MenuString "Gloss Translation"
|
||||||
@ -210,6 +247,11 @@ InsetLayout Flex:Interlinear_Gloss_(3_Lines)
|
|||||||
Tooltip "Add trigloss options here"
|
Tooltip "Add trigloss options here"
|
||||||
EndArgument
|
EndArgument
|
||||||
Argument post:1
|
Argument post:1
|
||||||
|
LabelString "Sentence Comment"
|
||||||
|
MenuString "Sentence Comment"
|
||||||
|
Tooltip "Add an optional sentence comment here"
|
||||||
|
EndArgument
|
||||||
|
Argument post:2
|
||||||
Decoration conglomerate
|
Decoration conglomerate
|
||||||
LabelString "Interlinear Gloss (1)"
|
LabelString "Interlinear Gloss (1)"
|
||||||
MenuString "Interlinear Gloss (Line 1)|1"
|
MenuString "Interlinear Gloss (Line 1)|1"
|
||||||
@ -219,17 +261,27 @@ InsetLayout Flex:Interlinear_Gloss_(3_Lines)
|
|||||||
FreeSpacing true
|
FreeSpacing true
|
||||||
InsertOnNewline true
|
InsertOnNewline true
|
||||||
EndArgument
|
EndArgument
|
||||||
Argument post:2
|
Argument post:3
|
||||||
|
LabelString "Gloss Comment (1)"
|
||||||
|
MenuString "Gloss Comment (Line 1)"
|
||||||
|
Tooltip "Add an optional gloss comment here"
|
||||||
|
EndArgument
|
||||||
|
Argument post:4
|
||||||
Decoration conglomerate
|
Decoration conglomerate
|
||||||
LabelString "Interlinear Gloss (2)"
|
LabelString "Interlinear Gloss (2)"
|
||||||
MenuString "Interlinear Gloss (Line 2)|2"
|
MenuString "Interlinear Gloss (Line 2)|2"
|
||||||
Tooltip "Add the first inter-linear gloss line here"
|
Tooltip "Add the second inter-linear gloss line here"
|
||||||
Mandatory true
|
Mandatory true
|
||||||
AutoInsert true
|
AutoInsert true
|
||||||
FreeSpacing true
|
FreeSpacing true
|
||||||
InsertOnNewline true
|
InsertOnNewline true
|
||||||
EndArgument
|
EndArgument
|
||||||
Argument post:3
|
Argument post:5
|
||||||
|
LabelString "Gloss Comment (2)"
|
||||||
|
MenuString "Gloss Comment (Line 2)"
|
||||||
|
Tooltip "Add an optional gloss comment here"
|
||||||
|
EndArgument
|
||||||
|
Argument post:6
|
||||||
Decoration conglomerate
|
Decoration conglomerate
|
||||||
LabelString "Translation"
|
LabelString "Translation"
|
||||||
MenuString "Gloss Translation"
|
MenuString "Gloss Translation"
|
||||||
|
@ -5007,6 +5007,521 @@ def convert_empty_macro(document):
|
|||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
|
def convert_cov_options(document):
|
||||||
|
"""Update examples item argument structure"""
|
||||||
|
|
||||||
|
if "linguistics" not in document.get_module_list():
|
||||||
|
return
|
||||||
|
|
||||||
|
layouts = ["Numbered Examples (consecutive)", "Subexample"]
|
||||||
|
|
||||||
|
for layout in layouts:
|
||||||
|
i = 0
|
||||||
|
while True:
|
||||||
|
i = find_token(document.body, "\\begin_layout %s" % layout, i)
|
||||||
|
if i == -1:
|
||||||
|
break
|
||||||
|
j = find_end_of_layout(document.body, i)
|
||||||
|
if j == -1:
|
||||||
|
document.warning("Malformed LyX document: Can't find end of example layout at line %d" % i)
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
k = find_token(document.body, '\\begin_inset Argument item:1', i, j)
|
||||||
|
if k != -1:
|
||||||
|
document.body[k] = '\\begin_inset Argument item:2'
|
||||||
|
i += 1
|
||||||
|
# Shift gloss arguments
|
||||||
|
i = 0
|
||||||
|
while True:
|
||||||
|
i = find_token(document.body, "\\begin_inset Flex Interlinear Gloss (2 Lines)", 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 gloss inset at line %d" % i)
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
k = find_token(document.body, '\\begin_inset Argument post:2', i, j)
|
||||||
|
if k != -1:
|
||||||
|
document.body[k] = '\\begin_inset Argument post:4'
|
||||||
|
k = find_token(document.body, '\\begin_inset Argument post:1', i, j)
|
||||||
|
if k != -1:
|
||||||
|
document.body[k] = '\\begin_inset Argument post:2'
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
while True:
|
||||||
|
i = find_token(document.body, "\\begin_inset Flex Interlinear Gloss (3 Lines)", 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 gloss inset at line %d" % i)
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
k = find_token(document.body, '\\begin_inset Argument post:3', i, j)
|
||||||
|
if k != -1:
|
||||||
|
document.body[k] = '\\begin_inset Argument post:6'
|
||||||
|
k = find_token(document.body, '\\begin_inset Argument post:2', i, j)
|
||||||
|
if k != -1:
|
||||||
|
document.body[k] = '\\begin_inset Argument post:4'
|
||||||
|
k = find_token(document.body, '\\begin_inset Argument post:1', i, j)
|
||||||
|
if k != -1:
|
||||||
|
document.body[k] = '\\begin_inset Argument post:2'
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
|
def revert_linggloss2(document):
|
||||||
|
" Revert gloss with new args to ERT "
|
||||||
|
|
||||||
|
if not "linguistics" in document.get_module_list():
|
||||||
|
return
|
||||||
|
|
||||||
|
cov_req = False
|
||||||
|
glosses = ["\\begin_inset Flex Interlinear Gloss (2 Lines)", "\\begin_inset Flex Interlinear Gloss (3 Lines)"]
|
||||||
|
for glosse in glosses:
|
||||||
|
i = 0
|
||||||
|
while True:
|
||||||
|
i = find_token(document.body, glosse, 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 Gloss inset")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Check if we have new options
|
||||||
|
arg = find_token(document.body, "\\begin_inset Argument post:1", i, j)
|
||||||
|
if arg == -1:
|
||||||
|
arg = find_token(document.body, "\\begin_inset Argument post:3", i, j)
|
||||||
|
if arg == -1:
|
||||||
|
arg = find_token(document.body, "\\begin_inset Argument post:5", i, j)
|
||||||
|
if arg == -1:
|
||||||
|
# nothing to do
|
||||||
|
continue
|
||||||
|
|
||||||
|
arg = find_token(document.body, "\\begin_inset Argument 1", i, j)
|
||||||
|
endarg = find_end_of_inset(document.body, arg)
|
||||||
|
optargcontent = []
|
||||||
|
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 optarg plain Layout")
|
||||||
|
continue
|
||||||
|
argendPlain = find_end_of_inset(document.body, argbeginPlain)
|
||||||
|
optargcontent = document.body[argbeginPlain + 1 : argendPlain - 2]
|
||||||
|
|
||||||
|
# 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]
|
||||||
|
|
||||||
|
arg = find_token(document.body, "\\begin_inset Argument post:1", i, j)
|
||||||
|
endarg = find_end_of_inset(document.body, arg)
|
||||||
|
marg1content = []
|
||||||
|
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 1 plain Layout")
|
||||||
|
continue
|
||||||
|
argendPlain = find_end_of_inset(document.body, argbeginPlain)
|
||||||
|
marg1content = document.body[argbeginPlain + 1 : argendPlain - 2]
|
||||||
|
|
||||||
|
# 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]
|
||||||
|
|
||||||
|
arg = find_token(document.body, "\\begin_inset Argument post:2", i, j)
|
||||||
|
endarg = find_end_of_inset(document.body, arg)
|
||||||
|
marg2content = []
|
||||||
|
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 2 plain Layout")
|
||||||
|
continue
|
||||||
|
argendPlain = find_end_of_inset(document.body, argbeginPlain)
|
||||||
|
marg2content = document.body[argbeginPlain + 1 : argendPlain - 2]
|
||||||
|
|
||||||
|
# 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]
|
||||||
|
|
||||||
|
arg = find_token(document.body, "\\begin_inset Argument post:3", i, j)
|
||||||
|
endarg = find_end_of_inset(document.body, arg)
|
||||||
|
marg3content = []
|
||||||
|
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 3 plain Layout")
|
||||||
|
continue
|
||||||
|
argendPlain = find_end_of_inset(document.body, argbeginPlain)
|
||||||
|
marg3content = document.body[argbeginPlain + 1 : argendPlain - 2]
|
||||||
|
|
||||||
|
# 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]
|
||||||
|
|
||||||
|
arg = find_token(document.body, "\\begin_inset Argument post:4", i, j)
|
||||||
|
endarg = find_end_of_inset(document.body, arg)
|
||||||
|
marg4content = []
|
||||||
|
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 4 plain Layout")
|
||||||
|
continue
|
||||||
|
argendPlain = find_end_of_inset(document.body, argbeginPlain)
|
||||||
|
marg4content = document.body[argbeginPlain + 1 : argendPlain - 2]
|
||||||
|
|
||||||
|
# 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]
|
||||||
|
|
||||||
|
arg = find_token(document.body, "\\begin_inset Argument post:5", i, j)
|
||||||
|
endarg = find_end_of_inset(document.body, arg)
|
||||||
|
marg5content = []
|
||||||
|
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 5 plain Layout")
|
||||||
|
continue
|
||||||
|
argendPlain = find_end_of_inset(document.body, argbeginPlain)
|
||||||
|
marg5content = document.body[argbeginPlain + 1 : argendPlain - 2]
|
||||||
|
|
||||||
|
# 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]
|
||||||
|
|
||||||
|
arg = find_token(document.body, "\\begin_inset Argument post:6", i, j)
|
||||||
|
endarg = find_end_of_inset(document.body, arg)
|
||||||
|
marg6content = []
|
||||||
|
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 6 plain Layout")
|
||||||
|
continue
|
||||||
|
argendPlain = find_end_of_inset(document.body, argbeginPlain)
|
||||||
|
marg6content = document.body[argbeginPlain + 1 : argendPlain - 2]
|
||||||
|
|
||||||
|
# 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]
|
||||||
|
|
||||||
|
cmd = "\\digloss"
|
||||||
|
if glosse == "\\begin_inset Flex Interlinear Gloss (3 Lines)":
|
||||||
|
cmd = "\\trigloss"
|
||||||
|
|
||||||
|
beginPlain = find_token(document.body, "\\begin_layout Plain Layout", i)
|
||||||
|
endInset = find_end_of_inset(document.body, i)
|
||||||
|
endPlain = find_end_of_layout(document.body, beginPlain)
|
||||||
|
precontent = put_cmd_in_ert(cmd)
|
||||||
|
if len(optargcontent) > 0:
|
||||||
|
precontent += put_cmd_in_ert("[") + optargcontent + put_cmd_in_ert("]")
|
||||||
|
precontent += put_cmd_in_ert("{")
|
||||||
|
|
||||||
|
postcontent = put_cmd_in_ert("}")
|
||||||
|
if len(marg1content) > 0:
|
||||||
|
postcontent += put_cmd_in_ert("[") + marg1content + put_cmd_in_ert("]")
|
||||||
|
postcontent += put_cmd_in_ert("{") + marg2content + put_cmd_in_ert("}")
|
||||||
|
if len(marg3content) > 0:
|
||||||
|
postcontent += put_cmd_in_ert("[") + marg3content + put_cmd_in_ert("]")
|
||||||
|
postcontent += put_cmd_in_ert("{") + marg4content + put_cmd_in_ert("}")
|
||||||
|
if cmd == "\\trigloss":
|
||||||
|
if len(marg5content) > 0:
|
||||||
|
postcontent += put_cmd_in_ert("[") + marg5content + put_cmd_in_ert("]")
|
||||||
|
postcontent += put_cmd_in_ert("{") + marg6content + put_cmd_in_ert("}")
|
||||||
|
|
||||||
|
document.body[endPlain:endInset + 1] = postcontent
|
||||||
|
document.body[beginPlain + 1:beginPlain] = precontent
|
||||||
|
del document.body[i : beginPlain + 1]
|
||||||
|
if not cov_req:
|
||||||
|
document.append_local_layout("Requires covington")
|
||||||
|
cov_req = True
|
||||||
|
i = beginPlain
|
||||||
|
|
||||||
|
|
||||||
|
def revert_exarg2(document):
|
||||||
|
" Revert linguistic examples with new arguments to ERT "
|
||||||
|
|
||||||
|
if not "linguistics" in document.get_module_list():
|
||||||
|
return
|
||||||
|
|
||||||
|
cov_req = False
|
||||||
|
|
||||||
|
layouts = ["Numbered Example", "Subexample"]
|
||||||
|
|
||||||
|
for layout in layouts:
|
||||||
|
i = 0
|
||||||
|
while True:
|
||||||
|
i = find_token(document.body, "\\begin_layout %s" % layout, i+1)
|
||||||
|
if i == -1:
|
||||||
|
break
|
||||||
|
j = find_end_of_layout(document.body, i)
|
||||||
|
if j == -1:
|
||||||
|
document.warning("Malformed LyX document: Can't find end of example layout")
|
||||||
|
continue
|
||||||
|
consecex = document.body[i] == "\\begin_layout Numbered Examples (consecutive)"
|
||||||
|
subexpl = document.body[i] == "\\begin_layout Subexample"
|
||||||
|
singleex = document.body[i] == "\\begin_layout Numbered Examples (multiline)"
|
||||||
|
layouttype = "\\begin_layout Numbered Examples (multiline)"
|
||||||
|
if consecex:
|
||||||
|
layouttype = "\\begin_layout Numbered Examples (consecutive)"
|
||||||
|
elif subexpl:
|
||||||
|
layouttype = "\\begin_layout Subexample"
|
||||||
|
k = i
|
||||||
|
l = j
|
||||||
|
while True:
|
||||||
|
if singleex:
|
||||||
|
break
|
||||||
|
m = find_end_of_layout(document.body, k)
|
||||||
|
# check for consecutive layouts
|
||||||
|
k = find_token(document.body, "\\begin_layout", m)
|
||||||
|
if k == -1 or document.body[k] != layouttype:
|
||||||
|
break
|
||||||
|
l = find_end_of_layout(document.body, k)
|
||||||
|
if l == -1:
|
||||||
|
document.warning("Malformed LyX document: Can't find end of example layout")
|
||||||
|
continue
|
||||||
|
|
||||||
|
arg = find_token(document.body, "\\begin_inset Argument 1", i, l)
|
||||||
|
if subexpl or arg == -1:
|
||||||
|
iarg = find_token(document.body, "\\begin_inset Argument item:1", i, l)
|
||||||
|
if iarg == -1:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if arg != -1:
|
||||||
|
endarg = find_end_of_inset(document.body, arg)
|
||||||
|
optargcontent = ""
|
||||||
|
argbeginPlain = find_token(document.body, "\\begin_layout Plain Layout", arg, endarg)
|
||||||
|
if argbeginPlain == -1:
|
||||||
|
document.warning("Malformed LyX document: Can't find optarg plain Layout")
|
||||||
|
continue
|
||||||
|
argendPlain = find_end_of_inset(document.body, argbeginPlain)
|
||||||
|
optargcontent = lyx2latex(document, document.body[argbeginPlain + 1 : argendPlain - 2])
|
||||||
|
# This is a verbatim argument
|
||||||
|
optargcontent = re.sub(r'textbackslash{}', r'', optargcontent)
|
||||||
|
|
||||||
|
itemarg = ""
|
||||||
|
iarg = find_token(document.body, "\\begin_inset Argument item:1", i, j)
|
||||||
|
if iarg != -1:
|
||||||
|
endiarg = find_end_of_inset(document.body, iarg)
|
||||||
|
iargcontent = ""
|
||||||
|
iargbeginPlain = find_token(document.body, "\\begin_layout Plain Layout", iarg, endiarg)
|
||||||
|
if iargbeginPlain == -1:
|
||||||
|
document.warning("Malformed LyX document: Can't find optarg plain Layout")
|
||||||
|
continue
|
||||||
|
iargendPlain = find_end_of_inset(document.body, iargbeginPlain)
|
||||||
|
itemarg = "<" + lyx2latex(document, document.body[iargbeginPlain : iargendPlain]) + ">"
|
||||||
|
|
||||||
|
iarg2 = find_token(document.body, "\\begin_inset Argument item:2", i, j)
|
||||||
|
if iarg2 != -1:
|
||||||
|
endiarg2 = find_end_of_inset(document.body, iarg2)
|
||||||
|
iarg2content = ""
|
||||||
|
iarg2beginPlain = find_token(document.body, "\\begin_layout Plain Layout", iarg2, endiarg2)
|
||||||
|
if iarg2beginPlain == -1:
|
||||||
|
document.warning("Malformed LyX document: Can't find optarg plain Layout")
|
||||||
|
continue
|
||||||
|
iarg2endPlain = find_end_of_inset(document.body, iarg2beginPlain)
|
||||||
|
itemarg += "[" + lyx2latex(document, document.body[iarg2beginPlain : iarg2endPlain]) + "]"
|
||||||
|
|
||||||
|
if itemarg == "":
|
||||||
|
itemarg = " "
|
||||||
|
|
||||||
|
# remove Arg insets and paragraph, if it only contains this inset
|
||||||
|
if arg != -1:
|
||||||
|
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]
|
||||||
|
if iarg != -1:
|
||||||
|
iarg = find_token(document.body, "\\begin_inset Argument item:1", i, j)
|
||||||
|
if iarg == -1:
|
||||||
|
document.warning("Unable to re-find item:1 Argument")
|
||||||
|
else:
|
||||||
|
endiarg = find_end_of_inset(document.body, iarg)
|
||||||
|
if document.body[iarg - 1] == "\\begin_layout Plain Layout" and find_end_of_layout(document.body, iarg - 1) == endiarg + 3:
|
||||||
|
del document.body[iarg - 1 : endiarg + 4]
|
||||||
|
else:
|
||||||
|
del document.body[iarg : endiarg + 1]
|
||||||
|
if iarg2 != -1:
|
||||||
|
iarg2 = find_token(document.body, "\\begin_inset Argument item:2", i, j)
|
||||||
|
if iarg2 == -1:
|
||||||
|
document.warning("Unable to re-find item:2 Argument")
|
||||||
|
else:
|
||||||
|
endiarg2 = find_end_of_inset(document.body, iarg2)
|
||||||
|
if document.body[iarg2 - 1] == "\\begin_layout Plain Layout" and find_end_of_layout(document.body, iarg2 - 1) == endiarg2 + 3:
|
||||||
|
del document.body[iarg2 - 1 : endiarg2 + 4]
|
||||||
|
else:
|
||||||
|
del document.body[iarg2 : endiarg2 + 1]
|
||||||
|
|
||||||
|
envname = "example"
|
||||||
|
if consecex:
|
||||||
|
envname = "examples"
|
||||||
|
elif subexpl:
|
||||||
|
envname = "subexamples"
|
||||||
|
|
||||||
|
cmd = put_cmd_in_ert("\\begin{" + envname + "}[" + optargcontent + "]")
|
||||||
|
|
||||||
|
# re-find end of layout
|
||||||
|
j = find_end_of_layout(document.body, i)
|
||||||
|
if j == -1:
|
||||||
|
document.warning("Malformed LyX document: Can't find end of Subexample layout")
|
||||||
|
continue
|
||||||
|
l = j
|
||||||
|
while True:
|
||||||
|
# check for consecutive layouts
|
||||||
|
k = find_token(document.body, "\\begin_layout", l)
|
||||||
|
if k == -1 or document.body[k] != layouttype:
|
||||||
|
break
|
||||||
|
if not singleex:
|
||||||
|
subitemarg = ""
|
||||||
|
m = find_end_of_layout(document.body, k)
|
||||||
|
iarg = find_token(document.body, "\\begin_inset Argument item:1", k, m)
|
||||||
|
if iarg != -1:
|
||||||
|
endiarg = find_end_of_inset(document.body, iarg)
|
||||||
|
iargcontent = ""
|
||||||
|
iargbeginPlain = find_token(document.body, "\\begin_layout Plain Layout", iarg, endiarg)
|
||||||
|
if iargbeginPlain == -1:
|
||||||
|
document.warning("Malformed LyX document: Can't find optarg plain Layout")
|
||||||
|
continue
|
||||||
|
iargendPlain = find_end_of_inset(document.body, iargbeginPlain)
|
||||||
|
subitemarg = "<" + lyx2latex(document, document.body[iargbeginPlain : iargendPlain]) + ">"
|
||||||
|
|
||||||
|
iarg2 = find_token(document.body, "\\begin_inset Argument item:2", k, m)
|
||||||
|
if iarg2 != -1:
|
||||||
|
endiarg2 = find_end_of_inset(document.body, iarg2)
|
||||||
|
iarg2content = ""
|
||||||
|
iarg2beginPlain = find_token(document.body, "\\begin_layout Plain Layout", iarg2, endiarg2)
|
||||||
|
if iarg2beginPlain == -1:
|
||||||
|
document.warning("Malformed LyX document: Can't find optarg plain Layout")
|
||||||
|
continue
|
||||||
|
iarg2endPlain = find_end_of_inset(document.body, iarg2beginPlain)
|
||||||
|
subitemarg += "[" + lyx2latex(document, document.body[iarg2beginPlain : iarg2endPlain]) + "]"
|
||||||
|
|
||||||
|
if subitemarg == "":
|
||||||
|
subitemarg = " "
|
||||||
|
document.body[k : k + 1] = ["\\begin_layout Standard"] + put_cmd_in_ert("\\item" + subitemarg)
|
||||||
|
# Refind and remove arg insets
|
||||||
|
if iarg != -1:
|
||||||
|
iarg = find_token(document.body, "\\begin_inset Argument item:1", k, m)
|
||||||
|
if iarg == -1:
|
||||||
|
document.warning("Unable to re-find item:1 Argument")
|
||||||
|
else:
|
||||||
|
endiarg = find_end_of_inset(document.body, iarg)
|
||||||
|
if document.body[iarg - 1] == "\\begin_layout Plain Layout" and find_end_of_layout(document.body, iarg - 1) == endiarg + 3:
|
||||||
|
del document.body[iarg - 1 : endiarg + 4]
|
||||||
|
else:
|
||||||
|
del document.body[iarg : endiarg + 1]
|
||||||
|
if iarg2 != -1:
|
||||||
|
iarg2 = find_token(document.body, "\\begin_inset Argument item:2", k, m)
|
||||||
|
if iarg2 == -1:
|
||||||
|
document.warning("Unable to re-find item:2 Argument")
|
||||||
|
else:
|
||||||
|
endiarg2 = find_end_of_inset(document.body, iarg2)
|
||||||
|
if document.body[iarg2 - 1] == "\\begin_layout Plain Layout" and find_end_of_layout(document.body, iarg2 - 1) == endiarg2 + 3:
|
||||||
|
del document.body[iarg2 - 1 : endiarg2 + 4]
|
||||||
|
else:
|
||||||
|
del document.body[iarg2 : endiarg2 + 1]
|
||||||
|
else:
|
||||||
|
document.body[k : k + 1] = ["\\begin_layout Standard"]
|
||||||
|
l = find_end_of_layout(document.body, k)
|
||||||
|
if l == -1:
|
||||||
|
document.warning("Malformed LyX document: Can't find end of example layout")
|
||||||
|
continue
|
||||||
|
|
||||||
|
endev = put_cmd_in_ert("\\end{" + envname + "}")
|
||||||
|
|
||||||
|
document.body[l : l] = ["\\end_layout", "", "\\begin_layout Standard"] + endev
|
||||||
|
document.body[i : i + 1] = ["\\begin_layout Standard"] + cmd \
|
||||||
|
+ ["\\end_layout", "", "\\begin_layout Standard"] + put_cmd_in_ert("\\item" + itemarg)
|
||||||
|
if not cov_req:
|
||||||
|
document.append_local_layout("Requires covington")
|
||||||
|
cov_req = True
|
||||||
|
|
||||||
|
|
||||||
|
def revert_cov_options(document):
|
||||||
|
"""Revert examples item argument structure"""
|
||||||
|
|
||||||
|
if "linguistics" not in document.get_module_list():
|
||||||
|
return
|
||||||
|
|
||||||
|
layouts = ["Numbered Examples (consecutive)", "Subexample"]
|
||||||
|
|
||||||
|
for layout in layouts:
|
||||||
|
i = 0
|
||||||
|
while True:
|
||||||
|
i = find_token(document.body, "\\begin_layout %s" % layout, i)
|
||||||
|
if i == -1:
|
||||||
|
break
|
||||||
|
j = find_end_of_layout(document.body, i)
|
||||||
|
if j == -1:
|
||||||
|
document.warning("Malformed LyX document: Can't find end of example layout at line %d" % i)
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
k = find_token(document.body, '\\begin_inset Argument item:2', i, j)
|
||||||
|
if k != -1:
|
||||||
|
document.body[k] = '\\begin_inset Argument item:1'
|
||||||
|
i += 1
|
||||||
|
# Shift gloss arguments
|
||||||
|
i = 0
|
||||||
|
while True:
|
||||||
|
i = find_token(document.body, "\\begin_inset Flex Interlinear Gloss (2 Lines)", 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 gloss inset at line %d" % i)
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
k = find_token(document.body, '\\begin_inset Argument post:2', i, j)
|
||||||
|
if k != -1:
|
||||||
|
document.body[k] = '\\begin_inset Argument post:1'
|
||||||
|
k = find_token(document.body, '\\begin_inset Argument post:4', i, j)
|
||||||
|
if k != -1:
|
||||||
|
document.body[k] = '\\begin_inset Argument post:2'
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
while True:
|
||||||
|
i = find_token(document.body, "\\begin_inset Flex Interlinear Gloss (3 Lines)", 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 gloss inset at line %d" % i)
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
k = find_token(document.body, '\\begin_inset Argument post:2', i, j)
|
||||||
|
if k != -1:
|
||||||
|
document.body[k] = '\\begin_inset Argument post:1'
|
||||||
|
k = find_token(document.body, '\\begin_inset Argument post:4', i, j)
|
||||||
|
if k != -1:
|
||||||
|
document.body[k] = '\\begin_inset Argument post:2'
|
||||||
|
k = find_token(document.body, '\\begin_inset Argument post:6', i, j)
|
||||||
|
if k != -1:
|
||||||
|
document.body[k] = '\\begin_inset Argument post:3'
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
|
def revert_expreambles(document):
|
||||||
|
"""Revert covington example preamble flex insets to ERT"""
|
||||||
|
|
||||||
|
revert_flex_inset(document.body, "Example Preamble", "\\expreamble")
|
||||||
|
revert_flex_inset(document.body, "Subexample Preamble", "\\subexpreamble")
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Conversion hub
|
# Conversion hub
|
||||||
#
|
#
|
||||||
@ -5084,10 +5599,12 @@ convert = [
|
|||||||
[613, []],
|
[613, []],
|
||||||
[614, [convert_hyper_other]],
|
[614, [convert_hyper_other]],
|
||||||
[615, [convert_acknowledgment,convert_ack_theorems]],
|
[615, [convert_acknowledgment,convert_ack_theorems]],
|
||||||
[616, [convert_empty_macro]]
|
[616, [convert_empty_macro]],
|
||||||
|
[617, [convert_cov_options]]
|
||||||
]
|
]
|
||||||
|
|
||||||
revert = [[615, [revert_empty_macro]],
|
revert = [[616, [revert_expreambles,revert_exarg2,revert_linggloss2,revert_cov_options]],
|
||||||
|
[615, [revert_empty_macro]],
|
||||||
[614, [revert_ack_theorems,revert_acknowledgment]],
|
[614, [revert_ack_theorems,revert_acknowledgment]],
|
||||||
[613, [revert_hyper_other]],
|
[613, [revert_hyper_other]],
|
||||||
[612, [revert_familydefault]],
|
[612, [revert_familydefault]],
|
||||||
|
@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
|
|||||||
|
|
||||||
// Do not remove the comment below, so we get merge conflict in
|
// Do not remove the comment below, so we get merge conflict in
|
||||||
// independent branches. Instead add your own.
|
// independent branches. Instead add your own.
|
||||||
#define LYX_FORMAT_LYX 616 // forenr: empty macros
|
#define LYX_FORMAT_LYX 617 // spitz: linguistics module enhancements
|
||||||
#define LYX_FORMAT_TEX2LYX 616
|
#define LYX_FORMAT_TEX2LYX 617
|
||||||
|
|
||||||
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
|
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
|
Loading…
Reference in New Issue
Block a user