From 7158f7b58d81e89c8e0dcd3a6eb8a53b89dc2619 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Mon, 20 Apr 2015 18:14:42 +0200 Subject: [PATCH] Add support for linguistic trees (via forest) --- development/FORMAT | 5 + lib/chkconfig.ltx | 1 + lib/examples/de/linguistics.lyx | 237 +++++++++++++++++++++++++++++++- lib/examples/linguistics.lyx | 231 ++++++++++++++++++++++++++++++- lib/layouts/linguistics.module | 21 ++- lib/lyx2lyx/LyX.py | 2 +- lib/lyx2lyx/lyx_2_2.py | 44 +++++- src/LaTeXFeatures.cpp | 3 +- src/version.h | 4 +- 9 files changed, 538 insertions(+), 10 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index fd3be4cf0f..ff9cd12e9e 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx. ----------------------- +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 + verbatim, not as {[] and {]}. + 2015-04-20 Jürgen Spitzmüller * Format incremented to 486: Support item arguments in the "Numbered Examples (consecutive)" and "Subexample" layouts of diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx index 7429f60d10..e8cb02728f 100644 --- a/lib/chkconfig.ltx +++ b/lib/chkconfig.ltx @@ -308,6 +308,7 @@ \TestPackage{float} \TestPackage{fontspec} \TestPackage{footmisc} +\TestPackage{forest} \TestPackage{framed} \TestPackage{geometry} \TestPackage{graphicx} diff --git a/lib/examples/de/linguistics.lyx b/lib/examples/de/linguistics.lyx index df81805143..9fcbebe95b 100644 --- a/lib/examples/de/linguistics.lyx +++ b/lib/examples/de/linguistics.lyx @@ -1,5 +1,5 @@ #LyX 2.2 created this file. For more info see http://www.lyx.org/ -\lyxformat 486 +\lyxformat 487 \begin_document \begin_header \textclass article @@ -116,7 +116,8 @@ In diesem Text werden einige Funktionen von \SpecialChar LyX vorgestellt, die spezifisch auf die Bedürfnisse von Linguistinnen und Linguisten ausgerichtet sind. Es wird gezeigt, wie nummerierte Beispiele, Glossen, OT-Tableaux, semantische - Auszeichnung und phonetische Notation (IPA) erzeugt werden können. + Auszeichnung, Strukturbäume und phonetische Notation (IPA) erzeugt werden + können. \end_layout \begin_layout Section @@ -1400,6 +1401,217 @@ lingmeaning ) verändert werden. \end_layout +\begin_layout Section +Linguistische Strukturbäume +\end_layout + +\begin_layout Standard +Mittlerweile gibt es mehrere \SpecialChar LaTeX +-Pakete, die bei der Erstellung von Strukturbäumen + helfen. + \SpecialChar LyX + unterstützt das Paket +\family sans +forest +\family default +, welches hohe Flexibilität und Mächtigkeit mit einer intuitiven Syntax + vereint. + Das Linguistik-Modul enthält eine Strukturbaum-Einfügung, die unter +\family sans +Einfügen\SpecialChar menuseparator +Benutzerdefinierte Einfügungen +\family default + zu finden ist. + Innerhalb dieser Einfügung können Sie die Klammernotation verwenden, die + das Paket +\family sans +forest +\family default + (wie auch andere Pakete, z. +\begin_inset space \thinspace{} +\end_inset + +B. + +\family sans +qtree +\family default +) anbietet. +\end_layout + +\begin_layout Standard +Hier ist ein einfaches Beispiel: +\end_layout + +\begin_layout Standard +\begin_inset Flex Structure Tree +status open + +\begin_layout Plain Layout +[VP [DP[Hans]] [V' [V[schickt]] [DP[Maria]] [DP[D[einen]][NP[Brief]]] ] + ] +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +\noindent +Wenn Sie die PDF-Ausgabe ansehen, sehen Sie, dass die Notation +\end_layout + +\begin_layout Quote + +\family typewriter +\size footnotesize +[VP [DP[Hans]] [V' [V[schickt]] [DP[Maria]] [DP[D[einen]][NP[Brief]]]]] +\end_layout + +\begin_layout Standard +als Strukturbaum ausgegeben wird. + Um das Ergebnis bereits im \SpecialChar LyX + +\begin_inset ERT +status collapsed + +\begin_layout Plain Layout + +"= +\end_layout + +\end_inset + +Eingabefenster zu sehen, können Sie die Strukturbaum-Einfügung einfach in + eine Vorschau-Einfügung ( +\family sans +Einfügen\SpecialChar menuseparator +Vorschau +\family default +) einbetten. + Wenn +\begin_inset Quotes gld +\end_inset + +Sofortige Vorschau +\begin_inset Quotes grd +\end_inset + + richtig eingerichtet und aktiviert ist, sollten Sie den Baum sofort sehen + (zur Bearbeitung klicken Sie einfach auf das Bild): +\end_layout + +\begin_layout Standard +\begin_inset Preview + +\begin_layout Standard +\begin_inset Flex Structure Tree +status open + +\begin_layout Plain Layout +[VP [DP[Maria]] [V' [V[schickt]] [DP[Hans]] [DP[D[eine]][NP[Antwort]]] ] + ] +\end_layout + +\end_inset + + +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +\noindent +Dächer ( +\begin_inset Quotes gld +\end_inset + +roofs +\begin_inset Quotes grd +\end_inset + +) können mittels der Option +\begin_inset Quotes gld +\end_inset + +triangle +\begin_inset Quotes grd +\end_inset + + erzeugt werden (beachten Sie, dass Kommata eine spezielle Bedeutung haben; + sie markieren Optionen): +\end_layout + +\begin_layout Standard +\begin_inset Flex Structure Tree +status open + +\begin_layout Plain Layout +[VP [DP[Hans]] [V' [V[schickt]] [DP[Maria]] [DP[einen weiteren Brief, triangle]] + ] ] +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +\noindent +Um die Knoten des Baums besser auszurichten, verwenden Sie die Option +\begin_inset Quotes gld +\end_inset + +tier +\begin_inset Quotes grd +\end_inset + +. + Alle Knoten, denen dieselbe +\begin_inset Quotes gld +\end_inset + +tier +\begin_inset Quotes grd +\end_inset + + (Ebene) zugewiesen wurde, werden in einer vertikalen Linie ausgerichtet. + Hier ist ein Beispiel: +\end_layout + +\begin_layout Standard +\begin_inset Flex Structure Tree +status open + +\begin_layout Plain Layout +[VP [DP[Hans, tier=word]] [V' [V[schickt, tier=word]] [DP[Maria, tier=word]] + [DP[D[einen, tier=word]][NP[Brief, tier=word]]] ] ] +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +\noindent +Das Paket bietet viel mehr Möglichkeiten, wie bspw. + Bewegungspfeile und Dekorationen. + Sie können hier nicht eingehend besprochen werden. + Bitte konsultieren Sie die ausführliche Dokumentation des Pakets +\begin_inset CommandInset citation +LatexCommand cite +key "forest" + +\end_inset + +. +\end_layout + \begin_layout Section Phonetische Notation (IPA) \end_layout @@ -1736,6 +1948,27 @@ http://www.ctan.org/tex-archive/macros/latex/contrib/float/ . \end_layout +\begin_layout Bibliography +\begin_inset CommandInset bibitem +LatexCommand bibitem +key "forest" + +\end_inset + +Das forest-Paket: +\begin_inset Flex URL +status collapsed + +\begin_layout Plain Layout + +http://www.ctan.org/tex-archive/macros/latex/contrib/forest/ +\end_layout + +\end_inset + +. +\end_layout + \begin_layout Bibliography \begin_inset CommandInset bibitem LatexCommand bibitem diff --git a/lib/examples/linguistics.lyx b/lib/examples/linguistics.lyx index 5536e2bfb4..f0dc8539f6 100644 --- a/lib/examples/linguistics.lyx +++ b/lib/examples/linguistics.lyx @@ -1,5 +1,5 @@ #LyX 2.2 created this file. For more info see http://www.lyx.org/ -\lyxformat 486 +\lyxformat 487 \begin_document \begin_header \textclass article @@ -115,7 +115,8 @@ type "mailto:" This paper describes some features that \SpecialChar LyX provides to linguists. It demonstrates how to use some native support in order to produce numbered - examples, glosses, OT tableaux, semantic markup, and phonetic symbols (IPA). + examples, glosses, OT tableaux, semantic markup, structure trees, and phonetic + symbols (IPA). \end_layout \begin_layout Section @@ -317,6 +318,37 @@ arg "float" . \end_layout +\end_deeper +\begin_layout Enumerate + +\emph on +forest.sty +\emph default + +\begin_inset CommandInset citation +LatexCommand cite +key "forest" + +\end_inset + +: This package is used to generate structure trees. +\begin_inset Separator parbreak +\end_inset + + +\end_layout + +\begin_deeper +\begin_layout Itemize +Installed on your system: +\begin_inset Info +type "package" +arg "forest" +\end_inset + +. +\end_layout + \end_deeper \begin_layout Section Numbered examples @@ -1325,6 +1357,180 @@ lingmeaning ) can be modified. \end_layout +\begin_layout Section +Linguistic structure trees +\end_layout + +\begin_layout Standard +Meanwhile, many \SpecialChar LaTeX + are available which help producing structure trees. + \SpecialChar LyX + supports the +\family sans +forest +\family default + package, which combines high flexibility and mightiness with a comfortable + input syntax. + The Linguistics module provides a Structure Tree inset, which can be inserted + via +\family sans +Insert\SpecialChar menuseparator +Custom Insets +\family default +. + Within this inset, you can insert the bracket notation used by +\family sans +forest +\family default + (and also by other similar packages such as +\family sans +qtree +\family default +). +\end_layout + +\begin_layout Standard +Here is a simple example: +\end_layout + +\begin_layout Standard +\begin_inset Flex Structure Tree +status open + +\begin_layout Plain Layout +[VP [DP[John]] [V' [V[sent]] [DP[Mary]] [DP[D[a]][NP[letter]]] ] ] +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +\noindent +If you view the PDF output, you will see that the input +\end_layout + +\begin_layout Quote + +\family typewriter +\size small +[VP [DP[John]] [V' [V[sent]] [DP[Mary]] [DP[D[a]][NP[letter]]]]] +\end_layout + +\begin_layout Standard +expands to a real structure tree. + To view the result within the \SpecialChar LyX + workarea, you can simply embed the Structure + Tree inset into a Preview inset ( +\family sans +Insert\SpecialChar menuseparator +Preview +\family default +). + If instant preview is correctly installed and activated, you should see + the tree immediately (just click on the image in order to edit): +\end_layout + +\begin_layout Standard +\begin_inset Preview + +\begin_layout Standard +\begin_inset Flex Structure Tree +status open + +\begin_layout Plain Layout +[VP [DP[Mary]] [V' [V[sent]] [DP[John]] [DP[D[a]][NP[response]]] ] ] +\end_layout + +\end_inset + + +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +\noindent +Roofs can be easily generated by means of the +\begin_inset Quotes eld +\end_inset + +triangle +\begin_inset Quotes erd +\end_inset + + option (note that the comma has special meaning, as it marks options): +\end_layout + +\begin_layout Standard +\begin_inset Flex Structure Tree +status open + +\begin_layout Plain Layout +[VP [DP[John]] [V' [V[sent]] [DP[Mary]] [DP[another letter, triangle]] ] + ] +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +\noindent +In order to align nodes of the tree more elegantly, use the +\begin_inset Quotes eld +\end_inset + +tier +\begin_inset Quotes erd +\end_inset + + option. + All nodes which have the same +\begin_inset Quotes eld +\end_inset + +tier +\begin_inset Quotes erd +\end_inset + + allocated get aligned. + Here is an example: +\end_layout + +\begin_layout Standard +\begin_inset Flex Structure Tree +status open + +\begin_layout Plain Layout +[VP [DP[John,tier=word]] [V' [V[sent,tier=word]] [DP[Mary,tier=word]] [DP[D[a,ti +er=word]][NP[letter,tier=word]]] ] ] +\end_layout + +\end_inset + + +\end_layout + +\begin_layout Standard +\noindent +The package supports many additional features, such as movement arrows and + decorations, that cannot documented here (please refer to the detailed + package documentation +\begin_inset CommandInset citation +LatexCommand cite +key "forest" + +\end_inset + +). +\end_layout + \begin_layout Section Phonetic Symbols (IPA) \end_layout @@ -1682,6 +1888,27 @@ http://www.ctan.org/tex-archive/macros/latex/contrib/float/ . \end_layout +\begin_layout Bibliography +\begin_inset CommandInset bibitem +LatexCommand bibitem +key "forest" + +\end_inset + +The forest package: +\begin_inset Flex URL +status collapsed + +\begin_layout Plain Layout + +http://www.ctan.org/tex-archive/macros/latex/contrib/forest/ +\end_layout + +\end_inset + +. +\end_layout + \begin_layout Bibliography \begin_inset CommandInset bibitem LatexCommand bibitem diff --git a/lib/layouts/linguistics.module b/lib/layouts/linguistics.module index 1527f8f8eb..22da764099 100644 --- a/lib/layouts/linguistics.module +++ b/lib/layouts/linguistics.module @@ -1,4 +1,4 @@ -#\DeclareLyXModule[covington.sty]{Linguistics} +#\DeclareLyXModule[covington.sty,enumitem.sty,forest.sty]{Linguistics} #DescriptionBegin #Defines some special environments useful for linguistics (numbered examples, #glosses, semantic markup, tableau floats). @@ -123,6 +123,25 @@ InsetLayout Flex:Tri-Glosse ResetsFont true End +# Structure trees via the forest package +InsetLayout Flex:Structure_Tree + LyXType custom + LabelString Tree + LatexType environment + LatexName forest + Decoration classic + LabelFont + Size Small + EndFont + MultiPar true + CustomPars false + ParbreakIsNewline true + FreeSpacing true + Requires forest + ResetsFont true + PassThruChars [] +End + # Some semantik markup for Semantics InsetLayout Flex:Expression diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index 9df4b422a1..055fcbd010 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,487)), minor_versions("2.2" , 0)) + ("2_2", list(range(475,488)), minor_versions("2.2" , 0)) ] #################################################################### diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py index 95966197c1..f885f57792 100644 --- a/lib/lyx2lyx/lyx_2_2.py +++ b/lib/lyx2lyx/lyx_2_2.py @@ -768,6 +768,46 @@ def revert_ex_itemargs(document): i += 1 +def revert_forest(document): + " Reverts the forest environment (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 Structure Tree", 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 Structure Tree 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) + + add_to_preamble(document, ["\\usepackage{forest}"]) + + document.body[i:j + 1] = ["\\begin_inset ERT", "status collapsed", "", + "\\begin_layout Plain Layout", "", "\\backslash", + "begin{forest}", "\\end_layout", "", "\\begin_layout Plain Layout", + content, "\\end_layout", "", "\\begin_layout Plain Layout", + "\\backslash", "end{forest}", "", "\\end_layout", "", "\\end_inset"] + # no need to reset i + + ## # Conversion hub # @@ -788,10 +828,12 @@ convert = [ [483, [convert_specialchar]], [484, []], [485, []], - [486, []] + [486, []], + [487, []] ] revert = [ + [485, [revert_forest]], [485, [revert_ex_itemargs]], [484, [revert_sigplan_doi]], [483, [revert_georgian]], diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 7491ef3757..dcfb44c8ec 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -753,7 +753,8 @@ char const * simplefeatures[] = { "tcolorbox", "pdfcomment", "fixme", - "todonotes" + "todonotes", + "forest" }; char const * bibliofeatures[] = { diff --git a/src/version.h b/src/version.h index 7109a1da61..31466b4637 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 486 // spitz: support item argument in linguistic examples -#define LYX_FORMAT_TEX2LYX 486 +#define LYX_FORMAT_LYX 487 // spitz: support for forest environment +#define LYX_FORMAT_TEX2LYX 487 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER -- 2.39.2