From e2f81b3a8486e70a89b7293701e1b6eced636256 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Tue, 4 Jun 2019 11:01:19 +0200 Subject: [PATCH] Rework linguistic gloss support This now uses the new and enhanced \digloss ad \trigloss macros of convington 2.0 rather than the deficient self-baked ones. File format change. --- development/FORMAT | 7 +- lib/examples/Modules/Linguistics.lyx | 699 ++++++++++++++++++++++++++- lib/layouts/linguistics.module | 95 ++-- lib/lyx2lyx/lyx_2_4.py | 208 +++++++- src/tex2lyx/TODO.txt | 3 + src/version.h | 4 +- 6 files changed, 954 insertions(+), 62 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 2202e8791e..084faaf20d 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -7,7 +7,12 @@ changes happened in particular if possible. A good example would be ----------------------- -2019-04-16 Günter Milde +2019-06-04 Jürgen Spitzmüller + * Format incremented to 577: Rework linguistic gloss support. + This now uses the covington 2.0 gloss macros (\digloss, \trigloss) + rather than self-baked ones. + +2019-06-03 Günter Milde * Format incremented to 576: Support for the document languages azerbaijani, bengali, churchslavonic, and oldrussian. diff --git a/lib/examples/Modules/Linguistics.lyx b/lib/examples/Modules/Linguistics.lyx index 2351dde4e1..1d20c95998 100644 --- a/lib/examples/Modules/Linguistics.lyx +++ b/lib/examples/Modules/Linguistics.lyx @@ -1,5 +1,5 @@ -#LyX 2.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 544 +#LyX 2.4 created this file. For more info see https://www.lyx.org/ +\lyxformat 577 \begin_document \begin_header \save_transient_properties true @@ -39,7 +39,7 @@ linguistics \language english \language_package default \inputencoding utf8 -\fontencoding global +\fontencoding auto \font_roman "lmodern" "FreeSerif" \font_sans "default" "FreeSans" \font_typewriter "default" "FreeMono" @@ -57,6 +57,8 @@ linguistics \output_sync 0 \bibtex_command default \index_command default +\float_placement class +\float_alignment class \paperfontsize default \spacing single \use_hyperref true @@ -91,6 +93,7 @@ linguistics \justification true \use_refstyle 0 \use_minted 0 +\use_lineno 0 \index Index \shortcut idx \color #008000 @@ -106,11 +109,13 @@ linguistics \papercolumns 1 \papersides 1 \paperpagestyle default -\tracking_changes false +\tablestyle default +\tracking_changes true \output_changes false \html_math_output 0 \html_css_as_file 0 \html_be_strict false +\author -712698321 "Jürgen Spitzmüller" \end_header \begin_body @@ -218,6 +223,12 @@ literal "true" \end_inset : This is the base package used for numbered examples and glosses. + +\change_inserted -712698321 1559635690 + Note that at least version 2.0 of the covington package is required to use + all features. +\change_unchanged + \end_layout \begin_deeper @@ -234,6 +245,8 @@ arg "covington" \end_deeper \begin_layout Enumerate +\change_deleted -712698321 1559635693 + \emph on enumitem.sty \emph default @@ -263,6 +276,8 @@ description \begin_deeper \begin_layout Itemize + +\change_deleted -712698321 1559635693 Installed on your system: \begin_inset Info type "package" @@ -270,6 +285,8 @@ arg "enumitem" \end_inset . +\change_unchanged + \end_layout \end_deeper @@ -290,7 +307,11 @@ literal "true" \emph on Meaning \emph default - character style. + character style +\change_inserted -712698321 1559635744 + and for glosses +\change_unchanged +. The package provides context sensitive quotation marks, depending on the language in use. \end_layout @@ -468,44 +489,298 @@ The Linguistics module provides two kinds of glosses, which can be inserted via \family sans Insert\SpecialChar menuseparator -Custom Insets +Custom Inset +\change_deleted -712698321 1559635796 +s +\change_unchanged + \family default -: The standard +: +\change_deleted -712698321 1559635812 +The standard \emph on Glosse +\change_inserted -712698321 1559635861 +Interlinear Gloss (2 +\begin_inset space ~ +\end_inset + +Lines) +\change_unchanged + \emph default - provides a gloss that consists of two lines (a gloss pair) and a translation, - the + provides a gloss that consists of two lines (a gloss pair +\change_inserted -712698321 1559635998 + consisting of the original language representation and and interlinear, + i. +\begin_inset space \thinspace{} +\end_inset + +e. + word-to-word translation +\change_unchanged +) +\change_deleted -712698321 1559636571 +and a +\change_inserted -712698321 1559636571 +plus +\change_unchanged + +\change_inserted -712698321 1559635981 +free +\change_unchanged +translation, the +\change_deleted -712698321 1559635825 + \emph on Tri-Glosse +\change_inserted -712698321 1559635858 +Interlinear Gloss (3 +\begin_inset space ~ +\end_inset + +Lines) +\change_unchanged + \emph default - insets consists of three lines and a translation (the third line is usually - needed to give morphological or phonological information next to the gloss - pair). + insets consists of three lines +\change_deleted -712698321 1559636589 + and a +\change_inserted -712698321 1559636589 + plus +\change_unchanged + translation (the third line is usually needed to give morphological or + phonological information next to the gloss pair). Each translation line might span multiple lines in the output, i. \begin_inset space \thinspace{} \end_inset e., the paragraphs are automatically broken if they exceed the text width. - The translation line is inserted by means of + +\change_inserted -712698321 1559636240 +The original language representation (first line in the gloss) is input + in the Gloss inset directly, the other information in specific sub-insets + ( +\family sans +Interlinear Gloss +\family default + or with the 3-line-gloss +\family sans +Interlinear Gloss (Line 1) +\family default + and +\family sans +Interlinear Gloss (Line 2) +\family default +, respectively, and +\family sans +Gloss Translation +\family default +). + \SpecialChar LyX + automatically inserts these sub-insets if you insert a new gloss. + +\change_unchanged +The +\change_inserted -712698321 1559636247 +y +\change_unchanged + +\change_inserted -712698321 1559636252 +can also be +\change_deleted -712698321 1559636256 +translation line is +\change_unchanged +inserted +\change_inserted -712698321 1559636649 +manually +\change_unchanged +by means of \family sans Insert\SpecialChar menuseparator -Glosse Translation +Gloss +\change_deleted -712698321 1559635897 +e +\change_unchanged + Translation +\change_inserted -712698321 1559636277 + +\family default + and +\family sans +Insert\SpecialChar menuseparator +Interlinear Gloss +\change_unchanged + \family default . - It does not matter where you insert the translation, it is always printed - as the last line. + It does not matter where you insert the +\change_inserted -712698321 1559636292 +se sub-insets +\change_deleted -712698321 1559636298 + translation +\change_unchanged +, +\change_deleted -712698321 1559636300 +it is +\change_inserted -712698321 1559636302 +they are +\change_unchanged + always printed +\change_deleted -712698321 1559636305 +as the last line +\change_inserted -712698321 1559636308 +in the right order +\change_unchanged +. + +\change_inserted -712698321 1559636755 + Finally, you can also insert gloss options via +\family sans +Insert\SpecialChar menuseparator +Gloss Options +\family default +. + These options let you customize the line appearance, add example numbers + or preceding text. + Please refer to the +\emph on +covington +\emph default + manual +\begin_inset CommandInset citation +LatexCommand cite +key "covington" +literal "false" + +\end_inset + + for details. +\begin_inset Foot +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559636976 +Note that the gloss support has been completely rewritten for \SpecialChar LyX + 2.4. + It now uses the new and enhanced +\emph on +covington +\emph default + (2.0) gloss macros. + Due to the major changes, old glosses cannot be converted to the new style. + Instead, the old insets are imported (and saved in the document as a +\family sans +Local Layout +\family default +). + Likewise, new gloss insets are converted to \SpecialChar TeX + code if you export to a previous + \SpecialChar LyX + version. +\change_unchanged + +\end_layout + +\end_inset + + +\change_unchanged + \end_layout \begin_layout Standard Here is a simple example for a +\change_inserted -712698321 1559636502 + \emph on -Glosse +two-line +\change_unchanged +Gloss +\change_deleted -712698321 1559636506 +e +\change_unchanged + \emph default : +\change_inserted -712698321 1559637042 + \end_layout \begin_layout Standard + +\change_inserted -712698321 1559637046 +\begin_inset Flex Interlinear Gloss (2 Lines) +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637057 +C'est un exemple simple +\end_layout + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637046 +\begin_inset Argument post:1 +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637065 +\begin_inset Flex GroupGlossedWords +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637065 +This is +\end_layout + +\end_inset + + an example simple +\change_unchanged + +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637046 +\begin_inset Argument post:2 +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637069 +This is a simple example +\change_unchanged + +\end_layout + +\end_inset + + +\change_unchanged + +\end_layout + +\end_inset + + +\change_unchanged + +\end_layout + +\begin_layout Standard + +\change_deleted -712698321 1559637072 \begin_inset Flex Glosse status open @@ -549,6 +824,8 @@ This is a simple example \end_inset +\change_unchanged + \end_layout \begin_layout Standard @@ -589,14 +866,122 @@ status open \end_layout \begin_layout Standard -Here is a three-line gloss ( +Here is a three-line gloss +\change_deleted -712698321 1559637102 + ( \emph on Tri-Glosse \emph default -); the procedure is the same: +) +\change_unchanged +; the procedure is the same: +\change_inserted -712698321 1559637107 + \end_layout \begin_layout Standard + +\change_inserted -712698321 1559637110 +\begin_inset Flex Interlinear Gloss (3 Lines) +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637135 +C'est un exemple simple +\end_layout + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637110 +\begin_inset Argument post:1 +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637118 +\begin_inset Flex GroupGlossedWords +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637118 +Das ist +\end_layout + +\end_inset + + ein Beispiel einfach +\change_unchanged + +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637111 +\begin_inset Argument post:2 +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637125 +\begin_inset Flex GroupGlossedWords +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637125 +This is +\end_layout + +\end_inset + + an example simple +\change_unchanged + +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637111 +\begin_inset Argument post:3 +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637130 +This is a simple example +\change_unchanged + +\end_layout + +\end_inset + + +\change_unchanged + +\end_layout + +\end_inset + + +\change_unchanged + +\end_layout + +\begin_layout Standard + +\change_deleted -712698321 1559637137 \begin_inset Flex Tri-Glosse status open @@ -653,15 +1038,109 @@ This is a simple example \end_inset +\change_unchanged + \end_layout \begin_layout Standard \noindent -If you want to have numbered glosses, simply insert the gloss inset to a - numbered examples paragraph, as follows: +If you want to have numbered glosses, +\change_inserted -712698321 1559637163 +either +\change_deleted -712698321 1559637165 +simply +\change_unchanged + insert the gloss inset to a numbered examples paragraph, as follows: \end_layout \begin_layout Numbered Examples (consecutive) + +\change_inserted -712698321 1559637185 +\begin_inset Flex Interlinear Gloss (3 Lines) +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637191 +Mein Luftkissenfahrzeug ist voller Aale +\end_layout + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637185 +\begin_inset Argument post:1 +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637197 +My skeertuig is vol palings +\change_unchanged + +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637185 +\begin_inset Argument post:2 +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637201 +My hovercraft is +\begin_inset Flex GroupGlossedWords +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637201 +full of +\end_layout + +\end_inset + + eels +\change_unchanged + +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637185 +\begin_inset Argument post:3 +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637206 +Do you have matches? +\change_unchanged + +\end_layout + +\end_inset + + +\change_unchanged + +\end_layout + +\end_inset + + +\change_deleted -712698321 1559637208 + \begin_inset Flex Tri-Glosse status open @@ -710,6 +1189,119 @@ Do you have matches? \end_inset +\change_inserted -712698321 1559637228 + +\end_layout + +\begin_layout Standard + +\change_inserted -712698321 1559637243 +or use the +\emph on +ex +\emph default + gloss option: +\end_layout + +\begin_layout Standard + +\change_inserted -712698321 1559637243 +\begin_inset Flex Interlinear Gloss (3 Lines) +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637251 +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637252 +ex +\change_unchanged + +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637243 +Mein Luftkissenfahrzeug ist voller Aale +\end_layout + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637243 +\begin_inset Argument post:1 +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637243 +My skeertuig is vol palings +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637243 +\begin_inset Argument post:2 +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637243 +My hovercraft is +\begin_inset Flex GroupGlossedWords +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637243 +full of +\end_layout + +\end_inset + + eels +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637243 +\begin_inset Argument post:3 +status open + +\begin_layout Plain Layout + +\change_inserted -712698321 1559637243 +Do you have matches? +\end_layout + +\end_inset + + +\end_layout + +\end_inset + + +\change_unchanged + \end_layout \begin_layout Subsection* @@ -721,14 +1313,60 @@ Avoiding Page Breaks within Glosses \end_layout \begin_layout Standard -Page breaks might occur within glosses, which is not desirable. - A workaround is to wrap glosses into boxes (via + +\change_inserted -712698321 1559637546 +By default, +\change_deleted -712698321 1559637546 +P +\change_inserted -712698321 1559637547 +p +\change_unchanged +age breaks might occur within glosses, which is not desirable. + +\change_inserted -712698321 1559637701 +You can avoid most of them by entering +\emph on +noglossbreaks +\emph default + to +\family sans +Document\SpecialChar menuseparator +Settings\SpecialChar ldots +\SpecialChar menuseparator +Document Class\SpecialChar menuseparator +Class Options\SpecialChar menuseparator +Custom +\family default +. + If page breaks still occur, you can +\change_deleted -712698321 1559637705 +A workaround is to +\change_unchanged + wrap +\change_inserted -712698321 1559637709 + the whole +\change_unchanged + gloss +\change_deleted -712698321 1559637710 +es +\change_unchanged + into +\change_inserted -712698321 1559637714 +a +\change_unchanged +box +\change_deleted -712698321 1559637716 +es +\change_unchanged + (via \family sans Insert\SpecialChar menuseparator Box\SpecialChar menuseparator Frameless \family default ). + +\change_deleted -712698321 1559637727 If you want to automate this for all glosses, you can copy the following code to \family sans @@ -740,6 +1378,8 @@ LaTeX Preamble \end_layout \begin_layout Quote + +\change_deleted -712698321 1559637727 \begin_inset listings lstparams "language={[LaTeX]TeX},basicstyle={\footnotesize\ttfamily}" inline false @@ -808,6 +1448,8 @@ end{minipage}} \end_layout \begin_layout Quote + +\change_deleted -712698321 1559637727 \begin_inset listings lstparams "language={[LaTeX]TeX},basicstyle={\footnotesize\ttfamily}" inline false @@ -876,6 +1518,8 @@ end{minipage}} \end_layout \begin_layout Standard + +\change_deleted -712698321 1559637727 You might have to adapt the minipage width ( \family typewriter .7 @@ -883,6 +1527,8 @@ You might have to adapt the minipage width ( textwidth \family default in the example code) to fit the glosses to your actual page width. +\change_unchanged + \end_layout \begin_layout Subsubsection* @@ -910,7 +1556,11 @@ footnotetext{Actual footnote ...} \family default , also in TeX mode, right behind the \emph on -Glosse +Gloss +\change_deleted -712698321 1559637777 +e +\change_unchanged + \emph default inset. If you need several footnotes, just insert multiple of these constructs. @@ -1166,6 +1816,7 @@ Floats \begin_layout Standard \begin_inset Float tableau placement h +alignment document wide false sideways false status open diff --git a/lib/layouts/linguistics.module b/lib/layouts/linguistics.module index 1ab6db418f..1716f720b0 100644 --- a/lib/layouts/linguistics.module +++ b/lib/layouts/linguistics.module @@ -1,4 +1,4 @@ -#\DeclareLyXModule[covington.sty,enumitem.sty,forest.sty]{Linguistics} +#\DeclareLyXModule[covington.sty,forest.sty]{Linguistics} #\DeclareCategory{Academic Field Specifics} #DescriptionBegin #Defines some special environments useful for linguistics (numbered examples, @@ -93,11 +93,11 @@ End # glosse (2 lines) with covington.sty -InsetLayout Flex:Glosse +InsetLayout Flex:Interlinear_Gloss_(2_Lines) LyXType custom - LabelString Glosse - LatexType environment - LatexName linggloss + LabelString Gloss + LatexType command + LatexName digloss Decoration minimalistic LabelFont Size Small @@ -105,34 +105,45 @@ InsetLayout Flex:Glosse MultiPar true CustomPars false ForcePlain true - ParbreakIsNewline true + ParbreakIgnored true FreeSpacing true - Requires covington - Preamble - \def\glosstr{} - \@ifundefined{linggloss}{% - \newenvironment{linggloss}[2][]{ - \def\glosstr{\glt #1}% - \gll #2} - {\glosstr\glend}}{} - EndPreamble + Requires covington,csquotes InToc true ResetsFont true Argument 1 + LabelString "Gloss options" + MenuString "Gloss Options|s" + Tooltip "Add digloss options here" + EndArgument + Argument post:1 + Decoration conglomerate + LabelString "Interlinear Gloss" + MenuString "Interlinear Gloss" + Tooltip "Add the inter-linear gloss here" + AutoInsert true + Mandatory true + FreeSpacing true + InsertOnNewline true + EndArgument + Argument post:2 Decoration conglomerate LabelString "Translation" - MenuString "Glosse Translation|s" - Tooltip "Add a translation for the glosse" + MenuString "Gloss Translation" + Tooltip "Add a free translation for the gloss" + AutoInsert true + Mandatory true + FreeSpacing true + InsertOnNewline true EndArgument End # glosse (3 lines) with covington.sty -InsetLayout Flex:Tri-Glosse +InsetLayout Flex:Interlinear_Gloss_(3_Lines) LyXType custom - LabelString Tri-Glosse - LatexType environment - LatexName lingglosss + LabelString Tri-Gloss + LatexType command + LatexName trigloss Decoration minimalistic LabelFont Size Small @@ -140,24 +151,44 @@ InsetLayout Flex:Tri-Glosse MultiPar true CustomPars false ForcePlain true - ParbreakIsNewline true + ParbreakIgnored true FreeSpacing true InToc true - Requires covington - Preamble - \def\glosstr{} - \@ifundefined{lingglosss}{% - \newenvironment{lingglosss}[2][]{ - \def\glosstr{\glt #1}% - \glll #2} - {\glosstr\glend}}{} - EndPreamble + Requires covington,csquotes ResetsFont true Argument 1 + LabelString "Gloss options" + MenuString "Gloss Options|s" + Tooltip "Add trigloss options here" + EndArgument + Argument post:1 + Decoration conglomerate + LabelString "Interlinear Gloss (1)" + MenuString "Interlinear Gloss (Line 1)|1" + Tooltip "Add the first inter-linear gloss line here" + Mandatory true + AutoInsert true + FreeSpacing true + InsertOnNewline true + EndArgument + Argument post:2 + Decoration conglomerate + LabelString "Interlinear Gloss (2)" + MenuString "Interlinear Gloss (Line 2)|2" + Tooltip "Add the first inter-linear gloss line here" + Mandatory true + AutoInsert true + FreeSpacing true + InsertOnNewline true + EndArgument + Argument post:3 Decoration conglomerate LabelString "Translation" - MenuString "Glosse Translation|s" + MenuString "Gloss Translation" Tooltip "Add a translation for the glosse" + Mandatory true + AutoInsert true + InsertOnNewline true EndArgument End diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index f14090d0e3..de47d2e203 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -27,11 +27,11 @@ from datetime import (datetime, date, time) # Uncomment only what you need to import, please. from parser_tools import (count_pars_in_inset, del_token, find_end_of_inset, - find_end_of_layout, find_token, find_re, get_bool_value, + find_end_of_layout, find_token, find_token_backwards, find_re, get_bool_value, get_containing_layout, get_option_value, get_value, get_quoted_value) # del_value, del_complete_lines, # find_complete_lines, find_end_of, -# find_re, find_substring, find_token_backwards, +# find_re, find_substring, # get_containing_inset, # is_in_inset, set_bool_value # find_tokens, find_token_exact, check_token @@ -1751,6 +1751,206 @@ def revert_new_languages(document): revert_language(document, "korean", "", "korean") +gloss_inset_def = [ + r'### Inserted by lyx2lyx (deprecated ling glosses) ###', + r'InsetLayout Flex:Glosse', + r' LyXType custom', + r' LabelString "Gloss (old version)"', + r' MenuString "Gloss (old version)"', + r' LatexType environment', + r' LatexName linggloss', + r' Decoration minimalistic', + r' LabelFont', + r' Size Small', + r' EndFont', + r' MultiPar true', + r' CustomPars false', + r' ForcePlain true', + r' ParbreakIsNewline true', + r' FreeSpacing true', + r' Requires covington', + r' Preamble', + r' \def\glosstr{}', + r' \@ifundefined{linggloss}{%', + r' \newenvironment{linggloss}[2][]{', + r' \def\glosstr{\glt #1}%', + r' \gll #2}', + r' {\glosstr\glend}}{}', + r' EndPreamble', + r' InToc true', + r' ResetsFont true', + r' Argument 1', + r' Decoration conglomerate', + r' LabelString "Translation"', + r' MenuString "Glosse Translation|s"', + r' Tooltip "Add a translation for the glosse"', + r' EndArgument', + r'End' +] + +glosss_inset_def = [ + r'### Inserted by lyx2lyx (deprecated ling glosses) ###', + r'InsetLayout Flex:Tri-Glosse', + r' LyXType custom', + r' LabelString "Tri-Gloss (old version)"', + r' MenuString "Tri-Gloss (old version)"', + r' LatexType environment', + r' LatexName lingglosss', + r' Decoration minimalistic', + r' LabelFont', + r' Size Small', + r' EndFont', + r' MultiPar true', + r' CustomPars false', + r' ForcePlain true', + r' ParbreakIsNewline true', + r' FreeSpacing true', + r' InToc true', + r' Requires covington', + r' Preamble', + r' \def\glosstr{}', + r' \@ifundefined{lingglosss}{%', + r' \newenvironment{lingglosss}[2][]{', + r' \def\glosstr{\glt #1}%', + r' \glll #2}', + r' {\glosstr\glend}}{}', + r' EndPreamble', + r' ResetsFont true', + r' Argument 1', + r' Decoration conglomerate', + r' LabelString "Translation"', + r' MenuString "Glosse Translation|s"', + r' Tooltip "Add a translation for the glosse"', + r' EndArgument', + r'End' +] + +def convert_linggloss(document): + " Move old ling glosses to local layout " + if find_token(document.body, '\\begin_inset Flex Glosse', 0) != -1: + document.append_local_layout(gloss_inset_def) + if find_token(document.body, '\\begin_inset Flex Tri-Glosse', 0) != -1: + document.append_local_layout(glosss_inset_def) + +def revert_linggloss(document): + " Revert to old ling gloss definitions " + document.del_local_layout(gloss_inset_def) + document.del_local_layout(glosss_inset_def) + + 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) + 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") + i += 1 + 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") + i += 1 + 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") + i += 1 + 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") + i += 1 + 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") + i += 1 + 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] + + 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_token_backwards(document.body, "\\end_layout", endInset) + 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("}{") + marg1content + put_cmd_in_ert("}{") + marg2content + if cmd == "\\trigloss": + postcontent += put_cmd_in_ert("}{") + marg3content + postcontent += 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 + 1 + ## # Conversion hub @@ -1790,9 +1990,11 @@ convert = [ [574, [convert_ruby_module, convert_utf8_japanese]], [575, [convert_lineno]], [576, []], + [577, [convert_linggloss]] ] -revert = [[575, [revert_new_languages]], +revert = [[576, [revert_linggloss]], + [575, [revert_new_languages]], [574, [revert_lineno]], [573, [revert_ruby_module, revert_utf8_japanese]], [572, [revert_inputencoding_namechange]], diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index c64cdccab0..685dd40787 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -35,6 +35,9 @@ Format LaTeX feature LyX feature 453 automatic stmaryrd loading \use_package stmaryrd 457 automatic stackrel loading \use_package stackrel 575 numbering of lines (lineno) \use_lineno, \lineno_options +577 new covington gloss macros + \digloss[opt]{one}{two}{three} \begin_inset Flex Interlinear Gloss (2 Lines) (Argument 1, Argument post:1, Argument:post 2) + \trigloss[opt]{one}{two}{three} \begin_inset Flex Interlinear Gloss (3 Lines) (Argument 1, Argument post:1, Argument:post 2, Argument:post 3) diff --git a/src/version.h b/src/version.h index 021a1e333a..61d5ee6b34 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 576 // ps: new languages -#define LYX_FORMAT_TEX2LYX 576 +#define LYX_FORMAT_LYX 577 // spitz: new ling glosses +#define LYX_FORMAT_TEX2LYX 577 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER