[LyX features/feature/docbook] DocBook: better output with the Linguistics module.

Thibaut Cuvelier tcuvelier at lyx.org
Wed Sep 2 13:25:03 UTC 2020


The branch, feature/docbook, has been updated.
  discards  1df6c7c69d876dbb444ec6e88250c73819c6962a (commit)
  discards  9ca1ab5122f4acc13855f9ee3475fa309b8cd570 (commit)
  discards  cb389136a921b0a156ee025fd630b3e4e3970f5e (commit)
  discards  960350159397f95408ac673362030265a5290f87 (commit)
  discards  d3355d261d151ca0e65848838856848c1689ec55 (commit)
  discards  f9c40e51a134ca4c9e50ebef8f545231b93d7ead (commit)
  discards  3c4bba42c2dee82b147f25a09b5d6bb07823a0cf (commit)
  discards  dac715d9c290fbed32b38cd2d879f80b2496241e (commit)
  discards  29faee9fe2032d79eadd49c6535ffe458d19aafe (commit)
  discards  67dbb4c8d8d0abf9808dc923dc6cfd3ecd8cb553 (commit)
  discards  2c689e4f0d8094d4bd029937a34adcce79881d09 (commit)
  discards  db71701ab0ade3a48c3e0e7ee327141c72e80acc (commit)
  discards  a5bafb87e11c650fed7c71ff2cb20f11990c483e (commit)
  discards  5a50f2cb45d82fecb251ba7888cfd09f45a7e772 (commit)
  discards  0ca67fb290b8f7f4e3300c416507a93f00dcb5a8 (commit)
  discards  7c768b0384c6bbd17c9fa4a88eb6953dbb71d30d (commit)
  discards  80480fff9939cde4f6532f71ae5d512b76196606 (commit)
  discards  e2e74ff695bd0f0ee8edbc127aca283f29880d6b (commit)
  discards  1490cc3bf78d3c0659d0269886afd7c613f10a12 (commit)
  discards  d132bb6e7c76ca9ff74989ed182bf90088239d3b (commit)
  discards  50c25f1c913d9b4c1dcb6ddb3b6c5c7714ba24b1 (commit)
  discards  bfb6b6d4ca6410da1db94e19de8bcbc90bf31f86 (commit)
  discards  3f87869c4b801aac811933d0d006800c77dff6a6 (commit)
  discards  316e00a3da39a5ddb650181b7c87363c1e317c04 (commit)
  discards  8bf328c1ce3e3f63fcdbfcb26c9219aa7f5d2510 (commit)
  discards  191d63ccde59674de6058d2605ef177b64a124ad (commit)
  discards  71c1f2826ad6558b31d2ca08f217b0a9aebef043 (commit)
  discards  b5c8ca573bbe9cefc6b403a734208923aea8304e (commit)
  discards  c3101e3d8488057c403610d5c79614af3a86e6b1 (commit)
  discards  2a8c22b697d0b697758a645ff485c7cded9e2836 (commit)
  discards  16a4c3469b4188782bebe2d32169369f7bb858c3 (commit)
  discards  eec4a2428e481e91037a69467e7167017ba0534e (commit)
  discards  31d89d001c9f25bc8d02af7ff3a3bde536e45339 (commit)
  discards  3484d1b5a555be8331f1c16dc67f25b745d0a513 (commit)
  discards  9bf56b8cb0c1cdd03b41aa0044f9bf994c298062 (commit)
  discards  94b4fe3813c824e141d1a70cb2024cbba4036752 (commit)
  discards  84c53549163368e4f89d40ae22d94b02dd3c133b (commit)
  discards  a043ef062be408ff8a7ec255e13d4fce0b593f30 (commit)
  discards  fe28e8c92e1d092773000bfea994ddbc9c725ba0 (commit)
  discards  ed56c49e8ea3f603635357ce4aeb3699b8b6a2fb (commit)
  discards  9486096b51f6902dda940aa191b3895b10147ea7 (commit)
  discards  a93a700a2428036e179d7104542c43d6e6d0b561 (commit)
  discards  e3034490e581ccc77c67957f9239c2d6c4c7007a (commit)
  discards  fc96941abeadf36898fe1216d1ace34fac6266fd (commit)
  discards  fb7e0dcc11c6ac6457eb7a6f1015469516845863 (commit)
  discards  8137278e04d1c7fa95aac5cd3e1f0687d4cc4733 (commit)
  discards  ddda8ae09bd22bdc410c755c9c6d62527ae68faf (commit)
  discards  85b643c1d7da48090530c3f7220dbee78fbb3d84 (commit)
  discards  6eb7ff2b675c95d97c77d122a39921f3cbfd35df (commit)
  discards  aff8b0de2ef4600b23208278a0adcfbd6d573ac5 (commit)
  discards  9c23f315f067a1833562a91c3c057e554fd6ee96 (commit)
  discards  3bd49984b4be17ed1d574a7a7c41baa97907f0c8 (commit)
  discards  d6324dc3d9636ab60dc8136a8446ce1c1550264f (commit)
  discards  a195b1197ca69b5ce13c821fda0249b39d47e0e0 (commit)
  discards  c1d3a486fe0d085da40e54fd434bb02ce1c37e41 (commit)
  discards  5f15f3cdac5ad21253eda592ead1b8ff9aaa0d9d (commit)
  discards  da8d50f16ad16ba735eeeaa9f87f741ea6da9bfa (commit)
  discards  6f8e320eae15de162e3fcb722b8f152112228d98 (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (1df6c7c69d876dbb444ec6e88250c73819c6962a)
            \
             N -- N -- N (f6c054e5f567be2fb11b7e2962e540c29953c7e9)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.

- Log -----------------------------------------------------------------

commit f6c054e5f567be2fb11b7e2962e540c29953c7e9
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Wed Sep 2 00:46:08 2020 +0200

    DocBook: better output with the Linguistics module.
    
    One issue left: <table> output within an <informaltable>, that does not make sense... I'm debugging it.

diff --git a/autotests/export/docbook/Linguistics.lyx b/autotests/export/docbook/Linguistics.lyx
new file mode 100644
index 0000000..39978c3
--- /dev/null
+++ b/autotests/export/docbook/Linguistics.lyx
@@ -0,0 +1,3209 @@
+#LyX 2.4 created this file. For more info see https://www.lyx.org/
+\lyxformat 598
+\begin_document
+\begin_header
+\save_transient_properties true
+\origin unavailable
+\textclass article
+\begin_preamble
+%% Kommentieren Sie das Folgende aus, um Tableaux-Ãœberschriften zu erzeugen:
+%\floatstyle{plaintop}
+%\restylefloat{tableau}
+
+% Rückwärtskompatibilität zu forest 1.x
+% Wenn Sie forest 2.0.1 oder neuer verwenden,
+% können Sie das Folgende löschen.
+\@ifpackageloaded{forest}{%
+  \@ifpackagelater{forest}{2016/02/20}{}{%
+    \forestset{
+      roof/.style={edge path={\noexpand\path[\forestoption{edge}]%
+          (.north west)--(!u.south)--(.north east)--cycle
+          \forestoption{edge label};
+        }
+      },
+      sn edges/.style={
+        for tree={parent anchor=south, child anchor=north},
+      },
+      linguistics preamble/.style={sn edges, baseline, for tree={align=center}}
+    }
+    \preto\forest at do{%
+      \forestOpreto{\forest at root}{given options}{linguistics preamble,}%
+    }
+  }
+}{}
+
+% Trennausnahmen
+\hyphenation{Dis-kurs-reprä-sen-ta-tions-struk-tur}
+\end_preamble
+\use_default_options false
+\begin_modules
+linguistics
+\end_modules
+\maintain_unincluded_children no
+\language ngerman
+\language_package default
+\inputencoding utf8
+\fontencoding auto
+\font_roman "lmodern" "FreeSerif"
+\font_sans "default" "FreeSans"
+\font_typewriter "default" "FreeMono"
+\font_math "auto" "auto"
+\font_default_family default
+\use_non_tex_fonts false
+\font_sc false
+\font_roman_osf false
+\font_sans_osf false
+\font_typewriter_osf false
+\font_sf_scale 100 100
+\font_tt_scale 100 100
+\use_microtype false
+\use_dash_ligatures false
+\graphics default
+\default_output_format default
+\output_sync 0
+\bibtex_command default
+\index_command default
+\float_placement class
+\float_alignment class
+\paperfontsize default
+\spacing single
+\use_hyperref true
+\pdf_bookmarks true
+\pdf_bookmarksnumbered false
+\pdf_bookmarksopen false
+\pdf_bookmarksopenlevel 1
+\pdf_breaklinks false
+\pdf_pdfborder true
+\pdf_colorlinks false
+\pdf_backref false
+\pdf_pdfusetitle true
+\papersize default
+\use_geometry false
+\use_package amsmath 1
+\use_package amssymb 1
+\use_package cancel 1
+\use_package esint 1
+\use_package mathdots 1
+\use_package mathtools 1
+\use_package mhchem 1
+\use_package stackrel 1
+\use_package stmaryrd 1
+\use_package undertilde 1
+\cite_engine basic
+\cite_engine_type default
+\biblio_style plain
+\use_bibtopic false
+\use_indices false
+\paperorientation portrait
+\suppress_date false
+\justification true
+\use_refstyle 0
+\use_minted 0
+\use_lineno 0
+\index Stichwortverzeichnis
+\shortcut idx
+\color #008000
+\end_index
+\secnumdepth 3
+\tocdepth 3
+\paragraph_separation indent
+\paragraph_indentation default
+\is_math_indent 0
+\math_numbering_side default
+\quotes_style german
+\dynamic_quotes 0
+\papercolumns 1
+\papersides 1
+\paperpagestyle default
+\tablestyle default
+\tracking_changes false
+\output_changes false
+\change_bars false
+\postpone_fragile_content false
+\html_math_output 0
+\html_css_as_file 0
+\html_be_strict false
+\docbook_table_output 0
+\end_header
+
+\begin_body
+
+\begin_layout Title
+Linguistische Arbeiten mit \SpecialChar LyX
+
+\end_layout
+
+\begin_layout Author
+Jürgen Spitzmüller
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset CommandInset href
+LatexCommand href
+target "spitz at lyx.org"
+type "mailto:"
+literal "false"
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Date
+21.04.2015
+\end_layout
+
+\begin_layout Abstract
+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, Interlinear-Glossierung, OT-Tableau
+x, semantische Auszeichnung, Strukturbäume, Diskursrepräsentationsstrukturen
+ und phonetische Notation (IPA) erzeugt werden können.
+\end_layout
+
+\begin_layout Section
+Voraussetzungen und Ziele
+\end_layout
+
+\begin_layout Standard
+Die meisten der hier beschriebenen Funktionen werden vom 
+\begin_inset Quotes gld
+\end_inset
+
+Linguistik
+\begin_inset Quotes grd
+\end_inset
+
+-Modul bereitgestellt, das seit Version 1.6.0 mit \SpecialChar LyX
+ mitgeliefert wird.
+ 
+\begin_inset Quotes gld
+\end_inset
+
+Module
+\begin_inset Quotes grd
+\end_inset
+
+ – das Konzept wurde ebenfalls mit \SpecialChar LyX
+ 1.6.0 eingeführt – sind Ergänzungsdateien,
+ welche die von der Dokumentklasse bereitgestellten Möglichkeiten zumeist
+ für sehr spezifische Aufgaben erweitern und die für jedes Dokument (egal
+ welcher Klasse) einfach ausgewählt werden können.
+ Um das Linguistik-Modul zu verwenden, gehen sie zu 
+\family sans
+Dokument\SpecialChar menuseparator
+Einstellungen\SpecialChar menuseparator
+Module
+\family default
+, wählen Sie 
+\begin_inset Quotes gld
+\end_inset
+
+Linguistik
+\begin_inset Quotes grd
+\end_inset
+
+ aus der Liste der verfügbaren Module und drücken auf den Knopf 
+\family sans
+Hinzufügen
+\family default
+ (so wie es für dieses Dokument bereits getan wurde).
+\end_layout
+
+\begin_layout Standard
+Grundsätzlich sollte das Modul in jeder von \SpecialChar LyX
+ unterstützten Dokumentklasse
+ funktionieren (falls nicht, informieren Sie bitte den Autor dieses Textes).
+ Allerdings müssen Sie, um alle Features nutzen zu können, die folgenden
+ \SpecialChar LaTeX
+-Pakete installiert haben:
+\end_layout
+
+\begin_layout Enumerate
+
+\emph on
+covington.sty
+\emph default
+ 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "covington"
+literal "true"
+
+\end_inset
+
+: Dieses Paket wird benötigt, um nummerierte Beispiele, Glossen und semantische
+ Auszeichnungen zu erzeugen.
+ Beachten Sie, dass mindestens Version 2.3 des Pakets erforderlich ist, um
+ alle Funktionen zu nutzen.
+\end_layout
+
+\begin_deeper
+\begin_layout Itemize
+Auf Ihrem System installiert: 
+\begin_inset Info
+type  "package"
+arg   "covington"
+\end_inset
+
+.
+\end_layout
+
+\end_deeper
+\begin_layout Enumerate
+
+\emph on
+csquotes.sty
+\emph default
+ 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "csquotes"
+literal "true"
+
+\end_inset
+
+: Voraussetzung für den Textstil 
+\emph on
+Bedeutung
+\emph default
+ und für Glossen.
+ Das Paket erlaubt es, kontextsensible Anführungszeichen zu generieren (bspw.
+ je nach aktuell verwendeter Sprache).
+\end_layout
+
+\begin_deeper
+\begin_layout Itemize
+Auf Ihrem System installiert: 
+\begin_inset Info
+type  "package"
+arg   "csquotes"
+\end_inset
+
+.
+\end_layout
+
+\end_deeper
+\begin_layout Enumerate
+
+\emph on
+drs.sty
+\emph default
+ 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "drs"
+literal "true"
+
+\end_inset
+
+: Voraussetzung für Diskursrepräsentationsstrukturen.
+ Beachten Sie, dass mindestens Version 2.3 des Pakets 
+\emph on
+covington
+\emph default
+ erforderlich ist, um dies mit anderen Funktionen gemeinsam zu nutzen.
+\end_layout
+
+\begin_deeper
+\begin_layout Itemize
+Auf Ihrem System installiert: 
+\begin_inset Info
+type  "package"
+arg   "drs"
+\end_inset
+
+.
+\end_layout
+
+\end_deeper
+\begin_layout Enumerate
+
+\emph on
+float.sty
+\emph default
+ 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "float"
+literal "true"
+
+\end_inset
+
+: Dieses Paket brauchen wir für die OT-Tableaux und das Tableaux-Verzeichnis.
+ Es sollte Bestandteil jeder \SpecialChar LaTeX
+-Distribution sein.
+\end_layout
+
+\begin_deeper
+\begin_layout Itemize
+Auf Ihrem System installiert: 
+\begin_inset Info
+type  "package"
+arg   "float"
+\end_inset
+
+.
+\end_layout
+
+\end_deeper
+\begin_layout Enumerate
+
+\emph on
+forest.sty
+\emph default
+ 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "forest"
+literal "true"
+
+\end_inset
+
+: Dieses Paket wird zur Erzeugung von Strukturbäumen verwendet.
+\end_layout
+
+\begin_deeper
+\begin_layout Itemize
+Auf Ihrem System installiert: 
+\begin_inset Info
+type  "package"
+arg   "forest"
+\end_inset
+
+.
+\end_layout
+
+\end_deeper
+\begin_layout Enumerate
+
+\emph on
+pict2e.sty
+\emph default
+ 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "pict2e"
+literal "true"
+
+\end_inset
+
+: Voraussetzung für 
+\emph on
+Duplex-Bedingungs-DRS
+\emph default
+.
+\end_layout
+
+\begin_deeper
+\begin_layout Itemize
+Auf Ihrem System installiert: 
+\begin_inset Info
+type  "package"
+arg   "pict2e"
+\end_inset
+
+.
+\end_layout
+
+\end_deeper
+\begin_layout Section
+Nummerierte Beispiele
+\end_layout
+
+\begin_layout Standard
+Nummerierte Beispiele werden über die Absatzstil-Auswahlliste in der Werkzeuglei
+ste eingefügt.
+ Es gibt drei Varianten:
+\end_layout
+
+\begin_layout Numbered Example (multiline)
+Das ist ein mehrzeiliges Beispiel [Stil 
+\emph on
+Nummeriertes Beispiel (mehrere Zeilen)
+\emph default
+]
+\end_layout
+
+\begin_layout Numbered Example (multiline)
+Wie der Name sagt, kann es mehrere Absätze enthalten
+\end_layout
+
+\begin_layout Numbered Examples (consecutive)
+Das ist ein einzeiliges Beispiel
+\begin_inset CommandInset label
+LatexCommand label
+name "exa:Beispiel-einzeilig"
+
+\end_inset
+
+ [Stil 
+\emph on
+Nummeriertes Beispiel (konsekutiv)
+\emph default
+]
+\end_layout
+
+\begin_layout Numbered Examples (consecutive)
+Jeder Absatz wird in diesem Stil neu nummeriert
+\end_layout
+
+\begin_layout Subexample
+Dies ist ein Unterbeispiel
+\begin_inset CommandInset label
+LatexCommand label
+name "subsec:Unterbeispiel"
+
+\end_inset
+
+ [Stil 
+\emph on
+Unterbeispiel
+\emph default
+]
+\end_layout
+
+\begin_layout Subexample
+Und hier noch eines
+\end_layout
+
+\begin_layout Standard
+Querverweise auf Beispiele erzeugen Sie wie gewohnt: Sie fügen im Beispiel
+ eine Marke ein, und an der Stelle, an der der Querverweis erscheinen soll,
+ einen Verweis mittels 
+\family sans
+Einfügen\SpecialChar menuseparator
+Querverweis\SpecialChar ldots
+
+\family default
+ 
+\end_layout
+
+\begin_layout Standard
+Als kleine Demonstration verweisen wir hier auf die Beispiele 
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "exa:Beispiel-einzeilig"
+
+\end_inset
+
+ und 
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "subsec:Unterbeispiel"
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Standard
+Wenn Sie die Nummerierung für einzelne Beispiele ändern möchten, verwenden
+ Sie 
+\family sans
+Einfügen\SpecialChar menuseparator
+Benutzerdef.
+ Nummerierung
+\family default
+.
+ Für globale Anpassungen bietet 
+\emph on
+covington
+\emph default
+ selbst Möglichkeiten.
+ Bitte konsultieren Sie das Handbuch des Pakets 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "covington"
+literal "false"
+
+\end_inset
+
+ für Einzelheiten.
+\end_layout
+
+\begin_layout Standard
+Ab Version 2.3 bietet 
+\emph on
+covingtons
+\emph default
+ subexamples-Umgebung ein optionales Argument (mit dem man Text zwischen
+ der Hauptnummer und dem ersten Unterbeispiel einfügen kann).
+ Dieses können Sie über 
+\family sans
+Einfügen\SpecialChar menuseparator
+Optionen für Unterbeispiele
+\family default
+ eingeben.
+ Bitte konsultieren Sie auch hier das Handbuch des Pakets 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "covington"
+literal "false"
+
+\end_inset
+
+ für Einzelheiten.
+\end_layout
+
+\begin_layout Section
+Interlinear-Glossierung
+\end_layout
+
+\begin_layout Standard
+Das Linguistikmodul stellt zwei Arten von Glossen zur Verfügung.
+ Beide sind über 
+\family sans
+Einfügen\SpecialChar menuseparator
+Spezifische Einfügung
+\family default
+ zugänglich.
+ Die 
+\emph on
+Interlinear-Glosse (2
+\begin_inset space ~
+\end_inset
+
+Zeilen)
+\emph default
+ besteht aus zwei Zeilen für das Glossenpaar (bestehend aus der Darstellung
+ in der zu beschreibenden Sprache und einer interlinearen Wort-zu-Wort-Ãœbersetzu
+ng) sowie einer weiteren Zeile für die freie Übersetzung, die 
+\emph on
+Interlinear-Glosse (3
+\begin_inset space ~
+\end_inset
+
+Zeilen)
+\emph default
+ bietet eine zusätzliche Zeile für Interlinear-Glossierung (diese dritte
+ Zeile wird zumeist für morphologische oder phonologische Angaben verwendet).
+ Die freie Übersetzung kann länger sein als eine Zeile, sie wird dann einfach
+ automatisch und korrekt umbrochen.
+ Die Version in der zu beschreibenden Sprache (erste Zeile der Glosse) wird
+ direkt in die Glosse-Einfügung geschrieben, alle anderen Teile der Glosse
+ in spezifische Unter-Einfügungen (
+\family sans
+Interlinear-Glosse
+\family default
+, bzw.
+ mit dreizeiligen Glossen: 
+\family sans
+Interlinear-Glosse (Zeile
+\begin_inset space ~
+\end_inset
+
+1)
+\family default
+ und 
+\family sans
+Interlinear-Glosse (Zeile
+\begin_inset space ~
+\end_inset
+
+2)
+\family default
+, sowie 
+\family sans
+Glossen-Ãœbersetzung
+\family default
+).
+ \SpecialChar LyX
+ fügt diese Unter-Einfügungen automatisch ein, wenn Sie eine neue Glosse
+ einfügen.
+ Sie können aber auch manuell eingefügt werden, und zwar über 
+\family sans
+Einfügen\SpecialChar menuseparator
+Glossen-Ãœbersetzung
+\family default
+ und 
+\family sans
+Einfügen\SpecialChar menuseparator
+Interlinear-Glosse
+\family default
+.
+ Ungeachtet wo Sie diese Untereinfügungen innerhalb der Glosse einfügen,
+ wird alles in der richtigen Reihenfolge ausgegeben.
+ Schließlich können Sie über 
+\family sans
+Einfügen\SpecialChar menuseparator
+Glossen-Optionen
+\family default
+ auch Glossen-Optionen eingeben.
+ Diese Optionen erlauben es Ihnen, die Darstellung der einzelnen Zeilen
+ zu verändern, eine Nummerierung oder vorangestellten Text hinzuzufügen.
+ Bitte konsultieren Sie das Handbuch des Pakets 
+\emph on
+covington 
+\emph default
+
+\begin_inset CommandInset citation
+LatexCommand cite
+key "covington"
+literal "false"
+
+\end_inset
+
+ für Einzelheiten.
+\begin_inset Foot
+status collapsed
+
+\begin_layout Plain Layout
+Bitte beachten Sie, dass die Unterstützung für Glossen für \SpecialChar LyX
+ 2.4 komplett
+ überarbeitet wurde.
+ Nun werden die neuen und verbesserten Glossen-Makros verwendet, die 
+\emph on
+covington
+\emph default
+ seit der Version 2.0 anbietet.
+ Wegen der erheblichen Veränderungen können alte Glossen leider nicht in
+ die neuen konvertiert werden.
+ Statt dessen werden sie in ihrer ursprünglichen Form importiert (und als
+ 
+\family sans
+Lokales Format
+\family default
+ im Dokument gespeichert).
+ Umgekehrt werden neue Glossen in \SpecialChar TeX
+-Code exportier, wenn Sie in eine ältere
+ \SpecialChar LyX
+-Version exportieren.
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Hier ist ein einfaches Beispiel für eine zweizeilige Glosse:
+\end_layout
+
+\begin_layout Standard
+\begin_inset Flex Interlinear Gloss (2 Lines)
+status open
+
+\begin_layout Plain Layout
+C'est       un exemple simple
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:1
+status open
+
+\begin_layout Plain Layout
+\begin_inset Flex GroupGlossedWords
+status open
+
+\begin_layout Plain Layout
+Dies ist
+\end_layout
+
+\end_inset
+
+ ein Beispiel einfach
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:2
+status open
+
+\begin_layout Plain Layout
+Dies ist ein einfaches Beispiel
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+\noindent
+Verwenden Sie 
+\family sans
+Bearbeiten\SpecialChar menuseparator
+Textstil\SpecialChar menuseparator
+Glossierte Wortgruppen
+\family default
+, um Mehrwortelemente zusammenzuhalten (alternativ können Sie auch im TeX-Modus
+ 
+\begin_inset ERT
+status open
+
+\begin_layout Plain Layout
+
+{
+\end_layout
+
+\end_inset
+
+diese Wörter geschweift einklammern
+\begin_inset ERT
+status open
+
+\begin_layout Plain Layout
+
+}
+\end_layout
+
+\end_inset
+
+).
+ Beachten Sie, dass Sie im \SpecialChar LyX
+-Fenster mehrere Leerzeichen nacheinander einfügen
+ können, um die Glossen dort schöner auszurichten.
+ Die Ausgabe wird davon nicht berührt.
+\end_layout
+
+\begin_layout Standard
+Hier ist eine dreizeilige Glosse.
+ Sie wird analog erzeugt:
+\end_layout
+
+\begin_layout Standard
+\begin_inset Flex Interlinear Gloss (3 Lines)
+status open
+
+\begin_layout Plain Layout
+Hoc est aliud exemplum
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:1
+status open
+
+\begin_layout Plain Layout
+n.sg.nom 3sg n.sg.nom n.sg.nom
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:2
+status open
+
+\begin_layout Plain Layout
+Dies ist anderes Beispiel 
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:3
+status open
+
+\begin_layout Plain Layout
+Dies ist ein anderes Beispiel
+\end_layout
+
+\end_inset
+
+
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+\begin_inset ERT
+status open
+
+\begin_layout Plain Layout
+
+fsii={
+\backslash
+normalfont
+\backslash
+scshape}
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Beachten Sie, wie wir hier mit Hilfe der Glossen-Optionen die zweite Zeile
+ in Kapitälchen ausgeben lassen.
+\end_layout
+
+\begin_layout Standard
+\noindent
+Wenn Sie nummerierte Glossen benötigen, fügen Sie die Glosse entweder einfach
+ in einen Absatz mit dem Format 
+\emph on
+Nummeriertes Beispiel
+\emph default
+ ein, so wie hier:
+\end_layout
+
+\begin_layout Numbered Examples (consecutive)
+\begin_inset Flex Interlinear Gloss (3 Lines)
+status open
+
+\begin_layout Plain Layout
+Mein Luftkissenfahrzeug ist voller  Aale
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:1
+status open
+
+\begin_layout Plain Layout
+My    skeertuig                   is   vol      palings
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:2
+status open
+
+\begin_layout Plain Layout
+My    hovercraft                 is 
+\begin_inset Flex GroupGlossedWords
+status open
+
+\begin_layout Plain Layout
+full of
+\end_layout
+
+\end_inset
+
+  eels
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:3
+status open
+
+\begin_layout Plain Layout
+Do you have matches?
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+oder verwenden Sie die Glossen-Option 
+\emph on
+ex
+\emph default
+:
+\end_layout
+
+\begin_layout Standard
+\begin_inset Flex Interlinear Gloss (3 Lines)
+status open
+
+\begin_layout Plain Layout
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+ex
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+Mein Luftkissenfahrzeug ist voller  Aale
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:1
+status open
+
+\begin_layout Plain Layout
+My    skeertuig                   is   vol      palings
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:2
+status open
+
+\begin_layout Plain Layout
+My    hovercraft                 is 
+\begin_inset Flex GroupGlossedWords
+status open
+
+\begin_layout Plain Layout
+full of
+\end_layout
+
+\end_inset
+
+  eels
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:3
+status open
+
+\begin_layout Plain Layout
+Do you have matches?
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Subsection*
+Tipps & Tricks
+\end_layout
+
+\begin_layout Subsubsection*
+Seitenumbrüche innerhalb von Glossen vermeiden
+\end_layout
+
+\begin_layout Standard
+In der Standardeinstellung können innerhalb von Glossen Seiten umbrochen
+ werden, was natürlich nicht erwünscht ist.
+ Um dies zu umgehen, können Sie in 
+\family sans
+Dokument\SpecialChar menuseparator
+Einstellungen\SpecialChar ldots
+\SpecialChar menuseparator
+Dokumentklasse\SpecialChar menuseparator
+Klassenoptionen\SpecialChar menuseparator
+Benutzerdefiniert
+\family default
+ die Option 
+\emph on
+noglossbreaks
+\emph default
+ eingeben; dies wird die meisten Umbrüche verhindern.
+ Wenn trotzdem welche vorkommen, können Sie Glossen in Boxen packen (über
+ 
+\family sans
+Einfügen\SpecialChar menuseparator
+Box\SpecialChar menuseparator
+Rahmenlos
+\family default
+).
+\end_layout
+
+\begin_layout Subsubsection*
+Fußnoten in Glossen
+\end_layout
+
+\begin_layout Standard
+Sie können zwar eine Fußnote in eine 
+\emph on
+Glosse 
+\emph default
+einfügen, dies führt aber zu einem LaTeX-Fehler.
+ Wenn Sie Fußnoten benötigen, schreiben Sie an der Stelle, an der das Fußnotenze
+ichen erscheinen soll, im TeX-Modus 
+\family typewriter
+
+\backslash
+footnotemark
+\family default
+ in die Glosse.
+ Direkt nach (und außerhalb) der Glosse schreiben Sie, ebenfalls im TeX-Modus,
+\family typewriter
+ 
+\backslash
+footnotetext{Die Fußnote ...}
+\family default
+.
+ Sollten Sie mehrere Fußnoten brauchen, geben Sie einfach mehrere dieser
+ Befehlspaare ein.
+\end_layout
+
+\begin_layout Subsubsection*
+Glossen (und Beispiele) in Beamer-Präsentationen
+\end_layout
+
+\begin_layout Standard
+Wenn Sie das Linguistik-Modul in einer Beamer-Präsentation verwenden wollen,
+ beachten Sie bitte folgendes:
+\end_layout
+
+\begin_layout Itemize
+Für Glossen müssen Sie in Beamer immer einen 
+\begin_inset Quotes gld
+\end_inset
+
+fragilen
+\begin_inset Quotes grd
+\end_inset
+
+ Rahmen verwenden.
+ 
+\end_layout
+
+\begin_layout Itemize
+Ältere Versionen des Pakets 
+\emph on
+covington
+\emph default
+ und die 
+\emph on
+Beamer
+\emph default
+-Klasse arbeiten von Haus aus nicht gut zusammen, da beide die Befehle 
+\family typewriter
+
+\backslash
+example
+\family default
+ und 
+\family typewriter
+
+\backslash
+examples
+\family default
+ zu definieren versuchen, was in diesen älteren Versionen eine \SpecialChar LaTeX
+-Fehlermeldung
+ erzeugt, sobald sie Glossen oder Beispiele einfügen.
+ Sie können das Problem beheben, indem Sie in 
+\family sans
+Dokument\SpecialChar menuseparator
+Einstellungen\SpecialChar menuseparator
+Lokales Format
+\family default
+ folgenden Code kopieren:
+\end_layout
+
+\begin_deeper
+\begin_layout Quote
+\begin_inset listings
+lstparams "basicstyle={\footnotesize\ttfamily},tabsize=4"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+Provides covington 1
+\end_layout
+
+\begin_layout Plain Layout
+
+AddToPreamble
+\end_layout
+
+\begin_layout Plain Layout
+
+		
+\backslash
+let
+\backslash
+example
+\backslash
+relax
+\end_layout
+
+\begin_layout Plain Layout
+
+		
+\backslash
+let
+\backslash
+endexample
+\backslash
+relax
+\end_layout
+
+\begin_layout Plain Layout
+
+		
+\backslash
+let
+\backslash
+examples
+\backslash
+relax
+\end_layout
+
+\begin_layout Plain Layout
+
+		
+\backslash
+let
+\backslash
+endexamples
+\backslash
+relax
+\end_layout
+
+\begin_layout Plain Layout
+
+		
+\backslash
+usepackage{covington}
+\end_layout
+
+\begin_layout Plain Layout
+
+EndPreamble
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Drücken Sie 
+\begin_inset Quotes gld
+\end_inset
+
+Validieren
+\begin_inset Quotes grd
+\end_inset
+
+ und dann 
+\begin_inset Quotes gld
+\end_inset
+
+OK
+\begin_inset Quotes grd
+\end_inset
+
+.
+ Dies hat den Effekt, dass die Beispiel-Umgebungen von Beamer deaktiviert
+ werden (und also nicht mehr verwendet werden können), dafür können Sie
+ dann aber die des Linguistik-Moduls verwenden.
+\end_layout
+
+\begin_layout Standard
+Ab 
+\emph on
+covington
+\emph default
+ 1.1 besteht dieses Problem nicht mehr.
+\end_layout
+
+\end_deeper
+\begin_layout Section
+Tableaux für Optimalitätstheorie
+\end_layout
+
+\begin_layout Standard
+Die OT-Tableaux selbst können natürlich einfach als normale Tabellen eingegeben
+ werden (Spezifika wie gestrichelte Tabellenlinien und schattierte Tabellenzelle
+n, die man hierfür manchmal braucht, sind in 
+\family sans
+Hilfe\SpecialChar menuseparator
+Eingebettete Objekt
+\family default
+e beschrieben).
+ 
+\end_layout
+
+\begin_layout Standard
+Wenn Sie allerdings Ihre Tableaux durch das Dokument hindurch nummerieren
+ und ein eigenes Tableaux-Verzeichnis einrichten möchten, reichen die Bordmittel
+ von \SpecialChar LyX
+ nicht aus.
+ Auch hier hilft das Linguistikmodul.
+ Wenn es ausgewählt ist, finden Sie unter 
+\family sans
+Einfügen\SpecialChar menuseparator
+Gleitobjekte
+\family default
+ zusätzlich ein Tableau-Gleitobjekt (siehe Tableau
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "tab:Beispiel-Tableau"
+
+\end_inset
+
+ für ein Beispiel).
+\end_layout
+
+\begin_layout Standard
+\begin_inset Float tableau
+placement h
+alignment document
+wide false
+sideways false
+status open
+
+\begin_layout Plain Layout
+\align center
+\begin_inset Tabular
+<lyxtabular version="3" rows="5" columns="5">
+<features tabularvalignment="middle">
+<column alignment="right" valignment="top">
+<column alignment="center" valignment="top">
+<column alignment="center" valignment="top">
+<column alignment="center" valignment="top" special="|c">
+<column alignment="center" valignment="top">
+<row>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+/atikap/
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\noun on
+Onset
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\noun on
+NoCoda
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\noun on
+Dep
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\noun on
+Max
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+\begin_inset Formula $\mbox{☞}$
+\end_inset
+
+ 
+\begin_inset Formula $\mbox{\textipa{P}}$
+\end_inset
+
+a.ti.ka
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+*
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+*
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+a.ti.ka
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+*!
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+*
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+\begin_inset Formula $\mbox{\textipa{P}}$
+\end_inset
+
+a.ti.kap
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+*!
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+*
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+a.ti.kap
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+*!
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+*!
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Caption Standard
+
+\begin_layout Plain Layout
+Beispiel-Tableau
+\begin_inset CommandInset label
+LatexCommand label
+name "tab:Beispiel-Tableau"
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Bitte beachten Sie, dass die Legende in der Standardeinstellung immer unter
+ dem Tableau ausgegeben wird, egal, wohin Sie sie im \SpecialChar LyX
+-Arbeitsfenster setzen.
+ Um die Legende über das Tableau zu setzen, müssen Sie den folgenden Code
+ in 
+\family sans
+Dokument\SpecialChar menuseparator
+Einstellungen\SpecialChar menuseparator
+Präambel 
+\family default
+eingeben:
+\end_layout
+
+\begin_layout Quote
+\begin_inset listings
+lstparams "language={[LaTeX]TeX},basicstyle={\footnotesize\ttfamily}"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+
+\backslash
+floatstyle{plaintop}
+\end_layout
+
+\begin_layout Plain Layout
+
+
+\backslash
+restylefloat{tableau}
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Wenn Sie eine KOMA-Klasse verwenden, nehmen Sie statt dessen das Folgende
+ (welches im Kontext der KOMA-Klassen bessere Abstände erzeugt):
+\end_layout
+
+\begin_layout Quote
+\begin_inset listings
+lstparams "language={[LaTeX]TeX},basicstyle={\footnotesize\ttfamily}"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+
+\backslash
+floatstyle{komaabove}
+\end_layout
+
+\begin_layout Plain Layout
+
+
+\backslash
+restylefloat{tableau}
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Ein Verzeichnis der Tableaux geben Sie, wie bei normalen Tabellen auch,
+ über 
+\family sans
+Einfügen\SpecialChar menuseparator
+Liste\SpecialChar breakableslash
+Inhaltsverzeichnis
+\family default
+ ein.
+ Dies sieht dann so aus:
+\end_layout
+
+\begin_layout Standard
+\begin_inset FloatList tableau
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Section
+Semantische Auszeichnung (Textstile)
+\end_layout
+
+\begin_layout Standard
+Das Linguistikmodul stellt einige Textstile zur Verfügung, die in linguistischen
+ Arbeiten allgemein gebräuchlich sind:
+\end_layout
+
+\begin_layout Enumerate
+Konzept (in Kapitälchen): 
+\begin_inset Flex Concepts
+status collapsed
+
+\begin_layout Plain Layout
+Konzept
+\end_layout
+
+\end_inset
+
+ 
+\end_layout
+
+\begin_layout Enumerate
+Ausdruck (hervorgehoben): 
+\begin_inset Flex Expression
+status collapsed
+
+\begin_layout Plain Layout
+Ausdruck
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Enumerate
+Bedeutung (in einfachen Anführungszeichen): 
+\begin_inset Flex Meaning
+status collapsed
+
+\begin_layout Plain Layout
+Bedeutung
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Diese Textstile finden Sie unter 
+\family sans
+Bearbeiten\SpecialChar menuseparator
+Textstil
+\family default
+.
+ Der Vorteil solcher Stile gegenüber direkter Hervorhebung und Auszeichnung
+ ist vor allem der, dass sie alle (und nur die) damit markierten Textteile
+ leicht global verändern können.
+ Wenn Sie (oder Ihr Verlag) also etwa Ausdrücke doch fett gesetzt haben
+ wollen, geben Sie einfach den folgenden Code in 
+\family sans
+Dokument\SpecialChar menuseparator
+Einstellungen\SpecialChar menuseparator
+Präambel
+\family default
+ ein:
+\end_layout
+
+\begin_layout Quote
+\begin_inset listings
+lstparams "language={[LaTeX]TeX},basicstyle={\footnotesize\ttfamily}"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+
+\backslash
+renewcommand
+\backslash
+lexp[1]{
+\backslash
+textbf{#1}}
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Auf ähnliche Weise kann auch das Aussehen von 
+\emph on
+Konzept
+\emph default
+ (
+\family typewriter
+
+\backslash
+lcon
+\family default
+) und 
+\emph on
+Bedeutung
+\emph default
+ (
+\family typewriter
+
+\backslash
+lmean
+\family default
+) verändert werden.
+ Bitte konsultieren Sie das Handbuch des Pakets 
+\emph on
+covington
+\emph default
+ 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "covington"
+literal "false"
+
+\end_inset
+
+ für Einzelheiten.
+\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
+Spezifische Einfügung
+\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
+
+roof
+\begin_inset Quotes grd
+\end_inset
+
+
+\begin_inset Foot
+status collapsed
+
+\begin_layout Plain Layout
+\noindent
+Bitte beachten Sie, dass die Option 
+\begin_inset Quotes gld
+\end_inset
+
+roof
+\begin_inset Quotes grd
+\end_inset
+
+ erst ab Version 2.0 des Pakets 
+\family sans
+forest
+\family default
+ verfügbar ist.
+ Für frühere Versionen haben wir in den Vorspann dieses Dokuments Code eingefügt
+, die die Verwendung dennoch gestattet.
+ Wenn Ihre Version des Pakets 
+\family sans
+forest
+\family default
+ kleiner ist als 2.0 und Sie 
+\begin_inset Quotes gld
+\end_inset
+
+roof
+\begin_inset Quotes grd
+\end_inset
+
+ verwenden wollen, müssen Sie diesen Code in den Vorspann Ihres Dokuments
+ kopieren.
+ Statt dessen können Sie auch die alte Option 
+\begin_inset Quotes gld
+\end_inset
+
+triangle
+\begin_inset Quotes grd
+\end_inset
+
+ (statt 
+\begin_inset Quotes gld
+\end_inset
+
+roof
+\begin_inset Quotes grd
+\end_inset
+
+) verwenden.
+\end_layout
+
+\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, roof]]
+ ] ]
+\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"
+literal "true"
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Section
+Diskursrepräsentationsstrukturen
+\end_layout
+
+\begin_layout Standard
+Das Linguistik-Modul stellt auch Einfügungen zur Erzeugung von Diskursrepräsenta
+tionsstrukturen (DRSen) in der Box-Notation von 
+\noun on
+Hans Kamps
+\noun default
+ 
+\emph on
+Diskursrepräsentationstheorie
+\emph default
+ zur Verfügung.
+ Diese Einfügungen finden Sie unter 
+\family sans
+Einfügen\SpecialChar menuseparator
+Spezifische Einfügung
+\family default
+.
+\end_layout
+
+\begin_layout Standard
+Eine einfache DRS erzeugen Sie mit der Einfügung 
+\family sans
+Diskursrepräsentationsstruktur
+\family default
+.
+ Eine DRS besteht aus (Diskurs-)
+\emph on
+Bedingungen
+\emph default
+, die direkt in die Einfügung geschrieben werden, uns den (u.
+\begin_inset space \thinspace{}
+\end_inset
+
+U.
+ leeren) (Diskurs-)
+\emph on
+Referenten
+\emph default
+ (bzw., im DRT-Jargon, dem 
+\emph on
+Universum
+\emph default
+), welche in die (automatisch eingefügte) Untereinfügung 
+\emph on
+Referenten
+\emph default
+ geschrieben werden.
+\begin_inset Foot
+status collapsed
+
+\begin_layout Plain Layout
+Sollte diese nicht eingefügt werden, finden Sie sie unter 
+\family sans
+Einfügen\SpecialChar menuseparator
+DRS-Referenten
+\family default
+.
+ 
+\end_layout
+
+\end_inset
+
+ Zeilenwechsel müssen mittels 
+\begin_inset Info
+type  "shortcut"
+arg   "newline-insert newline"
+\end_inset
+
+ eingefügt werden.
+ Hier ist ein einfaches Beispiel:
+\end_layout
+
+\begin_layout Standard
+\begin_inset VSpace defskip
+\end_inset
+
+
+\begin_inset Flex DRS
+status open
+
+\begin_layout Plain Layout
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+x
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+Esel(x)
+\begin_inset Newline newline
+\end_inset
+
+grün(x)
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+\begin_inset VSpace defskip
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+DRSen sind durch spezifische Layout-Anpassungen so gestaltet, dass Sie gut
+ auf der Seite platziert werden.
+ Die Variante 
+\family sans
+Diskursrepräsentationsstruktur (einfach)
+\family default
+ unterdrückt diese Anpassungen.
+ 
+\end_layout
+
+\begin_layout Standard
+Zusätzlich zu diesen einfachen DRSen werden die folgenden konditionalen
+ DRSen unterstützt (sie werden in der Regel in einfache eingebettet):
+\end_layout
+
+\begin_layout Enumerate
+Die 
+\family sans
+Implikative DRS
+\family default
+ repräsentiert eine konditionale (implikative) Satzkonstruktion der Form
+ 
+\emph on
+wenn S
+\begin_inset script subscript
+
+\begin_layout Plain Layout
+
+\emph off
+1
+\end_layout
+
+\end_inset
+
+, dann S
+\emph default
+
+\begin_inset script subscript
+
+\begin_layout Plain Layout
+2
+\end_layout
+
+\end_inset
+
+:
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset Flex IfThen-DRS
+status open
+
+\begin_layout Plain Layout
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+x
+\begin_inset space ~
+\end_inset
+
+y
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+Joseph(x)
+\begin_inset Newline newline
+\end_inset
+
+Esel(y)
+\begin_inset Newline newline
+\end_inset
+
+besitzen(x,y)
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:1
+status open
+
+\begin_layout Plain Layout
+z
+\begin_inset space ~
+\end_inset
+
+w
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:2
+status open
+
+\begin_layout Plain Layout
+z = x
+\begin_inset Newline newline
+\end_inset
+
+w = y
+\begin_inset Newline newline
+\end_inset
+
+füttern(z,w)
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_deeper
+\begin_layout Enumerate
+Die 
+\family sans
+Konditionale DRS
+\family default
+ ist eine allgemeinere Variante, bei der Sie selbst eine beliebige Bedingung
+ (statt der implikativen) spezifizieren können.
+ In die Untereinfügung 
+\family sans
+Bedingung
+\family default
+ können Sie ein beliebiges Symbol eingeben:
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset Flex Cond-DRS
+status open
+
+\begin_layout Plain Layout
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+x
+\begin_inset space ~
+\end_inset
+
+y
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+Joseph(x)
+\begin_inset Newline newline
+\end_inset
+
+Esel(y)
+\begin_inset Newline newline
+\end_inset
+
+besitzen(x,y)
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:1
+status open
+
+\begin_layout Plain Layout
+\begin_inset Formula $\wedge\!\,$
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:2
+status open
+
+\begin_layout Plain Layout
+z
+\begin_inset space ~
+\end_inset
+
+w
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:3
+status open
+
+\begin_layout Plain Layout
+z = x
+\begin_inset Newline newline
+\end_inset
+
+w = y
+\begin_inset Newline newline
+\end_inset
+
+lieben(w,z)
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_deeper
+\begin_layout Enumerate
+Die 
+\family sans
+Duplex-Bedingungs-DRS
+\family default
+ können Sie für sog.
+ 
+\emph on
+Duplex-Bedingungen
+\emph default
+ verwenden:
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset Flex QDRS
+status open
+
+\begin_layout Plain Layout
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+x
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+x 
+\begin_inset Formula $\in$
+\end_inset
+
+ X
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:1
+status open
+
+\begin_layout Plain Layout
+alle
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:2
+status open
+
+\begin_layout Plain Layout
+x
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:3
+status open
+
+\begin_layout Plain Layout
+y
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument post:4
+status open
+
+\begin_layout Plain Layout
+Sekretärin(y)
+\begin_inset Newline newline
+\end_inset
+
+anstellen(x,y)
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_deeper
+\begin_layout Enumerate
+Die 
+\family sans
+Negierte DRS
+\family default
+ fügt eine DRS ein, der ein Negationszeichen vorangestellt ist:
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset Flex NegDRS
+status open
+
+\begin_layout Plain Layout
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+x
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+Esel(x)
+\begin_inset Newline newline
+\end_inset
+
+grün(x)
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_deeper
+\begin_layout Standard
+
+\family sans
+DRS mit Satz oberhalb
+\family default
+ schließlich tut, was es verspricht: Es setzt einen Satz über die Box-Repräsenta
+tion:
+\end_layout
+
+\begin_layout Standard
+\begin_inset VSpace defskip
+\end_inset
+
+
+\begin_inset Flex SDRS
+status open
+
+\begin_layout Plain Layout
+\begin_inset Argument 1
+status open
+
+\begin_layout Plain Layout
+Ein Esel ist grün
+\end_layout
+
+\end_inset
+
+ 
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Argument 2
+status open
+
+\begin_layout Plain Layout
+x
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+Esel(x)
+\begin_inset Newline newline
+\end_inset
+
+grün(x)
+\end_layout
+
+\end_inset
+
+
+\begin_inset VSpace defskip
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Das Paket 
+\emph on
+drs
+\emph default
+ bietet einige Möglichkeiten, um das Erscheinungsbild der DRS-Modelle anzupassen.
+ Bitte konsultieren Sie das Handbuch des Pakets 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "drs"
+literal "false"
+
+\end_inset
+
+ für Einzelheiten.
+\end_layout
+
+\begin_layout Section
+Phonetische Notation (IPA)
+\end_layout
+
+\begin_layout Standard
+Um phonetische Zeichen einzugeben, brauchen Sie das Linguistikmodul nicht.
+ IPA-Unterstützung ist mittlerweile eine Grundfunktion von \SpecialChar LyX
+.
+ Da IPA aber von Linguistinnen und Linguisten sehr häufig gebraucht wird,
+ wird die Verwendung der IPA-Funktion hier trotzdem (kurz) beschrieben.
+\end_layout
+
+\begin_layout Standard
+Um \SpecialChar LyX
+' IPA-Funktion mit klassischem \SpecialChar LaTeX
+ oder PDF\SpecialChar LaTeX
+ zu benutzen, müssen Sie das
+ Paket 
+\emph on
+tipa
+\emph default
+ 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "tipa"
+literal "true"
+
+\end_inset
+
+ installiert haben.
+ Es wird von \SpecialChar LyX
+ automatisch geladen, wenn Sie dem unten beschriebenen Vorgehen
+ folgen.
+ Wenn Sie Xe\SpecialChar TeX
+ oder Lua\SpecialChar TeX
+ verwenden (und 
+\begin_inset Quotes gld
+\end_inset
+
+Nicht-\SpecialChar TeX
+-Schriften verwenden
+\begin_inset Quotes grd
+\end_inset
+
+ in 
+\family sans
+Dokument\SpecialChar menuseparator
+Einstellungen\SpecialChar menuseparator
+Schriften
+\family default
+ aktiviert haben), wird statt dessen das Paket 
+\emph on
+xunicode
+\emph default
+ geladen, da 
+\emph on
+tipa
+\emph default
+ in diesem Fall nicht funktioniert.
+ Das Paket 
+\emph on
+xunicode
+\emph default
+ emuliert die Ausgabe von 
+\emph on
+tipa
+\emph default
+, ist aber nicht perfekt, so dass die Ausgabe möglicherweise nicht wie erwartet
+ ist.
+ Außerdem müssen Sie in diesem Fall darauf achten, dass die Nicht-\SpecialChar TeX
+-Schrift
+ die IPA-Symbole auch enthält (empfehlenswert sind Schriften wie 
+\emph on
+CMU Serif
+\emph default
+ oder 
+\emph on
+SIL Doulos
+\emph default
+).
+ Sie können auch eine Schrift nur für IPA definieren, indem sie das Folgende
+ in 
+\family sans
+Dokument\SpecialChar menuseparator
+Einstellungen\SpecialChar menuseparator
+LaTeX-Vorspann
+\family default
+ eingeben:
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+lstparams "language={[LaTeX]TeX},basicstyle={\footnotesize\ttfamily}"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+
+\backslash
+AtBeginDocument{%
+\end_layout
+
+\begin_layout Plain Layout
+
+
+\backslash
+newfontfamily{
+\backslash
+ipafont}{CMU Serif}% oder eine ander Schriftart
+\end_layout
+
+\begin_layout Plain Layout
+
+
+\backslash
+def
+\backslash
+useTIPAfont{
+\backslash
+ipafont}
+\end_layout
+
+\begin_layout Plain Layout
+
+}
+\end_layout
+
+\end_inset
+
+Für eine direkte Vorschau der IPA-Symbole im Arbeitsfenster sollten Sie
+ weiterhin (egal, welche der oben beschriebenen Ausgabeformate Sie verwenden)
+ das 
+\emph on
+preview-latex
+\emph default
+-Paket 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "preview"
+literal "true"
+
+\end_inset
+
+ installiert haben.
+\end_layout
+
+\begin_layout Standard
+Phonetische Zeichen werden in eine spezielle Umgebung eingegeben, die Sie
+ über 
+\family sans
+Einfügen\SpecialChar menuseparator
+Sonderzeichen\SpecialChar menuseparator
+Phonetische Symbole 
+\family default
+aktivieren.
+ Es wird ein kleiner umrahmter Eingabebereich eingefügt, in den Sie einzelne
+ Zeichen, Wörter und Wortfolgen sowie auch mehrere Absätze mit phonetischer
+ Notation eingeben können.
+ Wenn Sie in dem Eingabebereich sind, wird eine Symbolleiste aktiviert,
+ die die wichtigsten IPA-Symbole (nach den IPA-Kategorien sortiert) bereitstellt.
+\begin_inset Foot
+status collapsed
+
+\begin_layout Plain Layout
+Es fehlt ein Symbol: der (2005 in das IPA aufgenommene) labiodentale Flap.
+ Dieses Zeichen unterstützt das 
+\emph on
+Tipa-
+\emph default
+Paket noch nicht; daher kann es auch nicht von LyX unterstützt werden.
+\end_layout
+
+\end_inset
+
+ Jeder Symbolbereich dieser Symbolleiste kann durch Klicken auf die gestrichelte
+ Linie abgetrennt werden.
+ Dadurch kann phonetische Notation recht komfortabel eingegeben werden:
+ 
+\begin_inset IPA
+
+\begin_layout Standard
+[ˈɛtva zo:]
+\end_layout
+
+\end_inset
+
+.
+\begin_inset Foot
+status collapsed
+
+\begin_layout Plain Layout
+Wenn Sie ein diakritisches Zeichen einfügen möchten, müssen Sie das Diakritikum
+ 
+\emph on
+nach
+\emph default
+ dem Basiszeichen einfügen.
+ Das heißt, für 
+\begin_inset IPA
+
+\begin_layout Standard
+[d̥]
+\end_layout
+
+\end_inset
+
+ geben Sie zuerst 
+\family typewriter
+<d>
+\family default
+ ein und dann direkt danach das Diakritikum 
+\family typewriter
+<Stimmlos>
+\family default
+ von der Symbolleiste.
+ Wenn Sie nur ein Diakritikum eingeben möchten, können Sie das direkt nach
+ einem Leerzeichen tun, so wie hier: 
+\begin_inset IPA
+
+\begin_layout Standard
+ ̼
+\end_layout
+
+\end_inset
+
+ (
+\family typewriter
+=
+\begin_inset space ~
+\end_inset
+
+<Leerzeichen>+<Lingolabial>
+\family default
+).
+\end_layout
+
+\end_inset
+
+ Wenn
+\emph on
+ preview-latex
+\emph default
+ installiert ist und Sie außerdem in
+\family sans
+ Werkzeuge\SpecialChar menuseparator
+Einstellungen\SpecialChar ldots
+\SpecialChar menuseparator
+Grafik
+\family default
+ 
+\begin_inset Quotes gld
+\end_inset
+
+Sofortige Vorschau
+\begin_inset Quotes grd
+\end_inset
+
+ aktiviert haben, zeigt \SpecialChar LyX
+ eine WYSIWYG-Vorschau der Notation an, sobald der
+ Cursor den IPA-Bereich verlässt.
+ Alternativ zur Symbolleiste können Sie die Zeichen auch direkt mithilfe
+ der Kurznotation eingeben können, die im 
+\emph on
+tipa
+\emph default
+-Handbuch erläutert wird: hier eine 
+\begin_inset IPA
+
+\begin_layout Standard
+[kOst"pro:b@]
+\end_layout
+
+\end_inset
+
+ (
+\emph on
+tipa
+\emph default
+-Kurznotation: 
+\family typewriter
+[kOst"pro:b@
+\family default
+]).
+ Alternativ können Sie die meisten IPA-Zeichen auch über 
+\family sans
+Einfügen\SpecialChar menuseparator
+Sonderzeichen\SpecialChar menuseparator
+Symbole\SpecialChar ldots
+
+\family default
+ in das Eingabefeld eingeben oder sie aus einem anderen Dokument kopieren
+ und dort einfügen.
+ Die Ausgabe sollte immer identisch sein, egal welche Eingabemethode Sie
+ wählen.
+\end_layout
+
+\begin_layout Standard
+Bitte beachten Sie, dass Sie die meisten IPA-Zeichen über die zuletzt genannten
+ Methoden auch außerhalb des IPA-Eingabebereichs einfügen können: [zoː viː
+ hiːɐ̯].
+ In der Ausgabe werden diese Zeichen dann ebenfalls direkt in die korrekten
+ 
+\emph on
+tipa
+\emph default
+-Makros umgewandelt (lassen Sie es uns wissen, falls das nicht der Fall
+ ist).
+ Dieses Verfahren hat aber gravierende Nachteile gegenüber der IPA-Umgebung,
+ denn die direkte Eingabe resultiert in der Regel in unerwünschter Schriftmischu
+ng (die lateinischen Buchstaben werden aus der Grundschrift, die speziellen
+ IPA-Zeichen aber aus der IPA-Schrift genommen, und diese beiden Schriften
+ passen nicht notwendigerweise zusammen).
+ Innerhalb der IPA-Eingabeumgebung wird dagegen für alle Zeichen dieselbe
+ Schrift verwendet.
+ Deshalb sollten Sie, wenn Sie nicht nur Einzelzeichen eingeben, unbedingt
+ den IPA-Eingabebereich verwenden.
+\end_layout
+
+\begin_layout Section
+Weitere Informationen
+\end_layout
+
+\begin_layout Standard
+Mehr und ausführlichere Informationen über die Möglichkeiten des Einsatzes
+ von \SpecialChar LyX
+ für linguistische Zwecke finden Sie auf der (englischsprachigen) 
+\emph on
+Linguist\SpecialChar LyX
+
+\emph default
+-Seite auf dem \SpecialChar LyX
+-Wiki 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "linguistlyx"
+literal "true"
+
+\end_inset
+
+.
+ Sie sind übrigens herzlich eingeladen, dort aktiv mitzuschreiben!
+\end_layout
+
+\begin_layout Bibliography
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+key "covington"
+literal "true"
+
+\end_inset
+
+Das covington-Paket: 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+http://www.ctan.org/tex-archive/macros/latex/contrib/covington/
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Bibliography
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+key "csquotes"
+literal "true"
+
+\end_inset
+
+Das csquotes-Paket: 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+http://www.ctan.org/tex-archive/macros/latex/contrib/csquotes/
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Bibliography
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+key "drs"
+literal "false"
+
+\end_inset
+
+ Das drs-Paket: 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+https://ctan.org/tex-archive/macros/latex/contrib/drs
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Bibliography
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+key "enumitem"
+literal "true"
+
+\end_inset
+
+Das enumitem-Paket: 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+http://www.ctan.org/tex-archive/macros/latex/contrib/enumitem/
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Bibliography
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+key "float"
+literal "true"
+
+\end_inset
+
+Das float-Paket: 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+http://www.ctan.org/tex-archive/macros/latex/contrib/float/
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Bibliography
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+key "forest"
+literal "true"
+
+\end_inset
+
+Das forest-Paket: 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+http://www.ctan.org/tex-archive/graphics/pgf/contrib/forest
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Bibliography
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+key "linguistlyx"
+literal "true"
+
+\end_inset
+
+Maria Gouskova, Stacia Hartleben und Jürgen Spitzmüller: Using \SpecialChar LyX
+ for Linguistic
+ Papers.
+ 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+https://wiki.lyx.org/LyX/LinguistLyX
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Bibliography
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+key "pict2e"
+literal "false"
+
+\end_inset
+
+Das pict2e-Paket: 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+https://ctan.org/tex-archive/macros/latex/contrib/pict2e
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Bibliography
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+key "preview"
+literal "true"
+
+\end_inset
+
+Das preview-latex-Paket: 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+http://www.ctan.org/tex-archive/macros/latex/contrib/preview/
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Bibliography
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+key "tipa"
+literal "true"
+
+\end_inset
+
+Das tipa-Paket und die zugehörigen Schriften: 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+http://www.ctan.org/tex-archive/fonts/tipa/
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\end_body
+\end_document
diff --git a/autotests/export/docbook/Linguistics.xml b/autotests/export/docbook/Linguistics.xml
new file mode 100644
index 0000000..688ee2d
--- /dev/null
+++ b/autotests/export/docbook/Linguistics.xml
@@ -0,0 +1,339 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This DocBook file was created by LyX 2.4.0dev
+  See http://www.lyx.org/ for more information -->
+<article xml:lang="de_DE" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
+<info>
+<title>Linguistische Arbeiten mit LyX</title>
+<author>
+<personname>Jürgen Spitzmüller<emphasis role='size_large'><link xlink:href="spitz at lyx.org"></link></emphasis></personname>
+</author>
+<date>21.04.2015</date>
+<abstract>
+<para>In diesem Text werden einige Funktionen von LyX vorgestellt, die spezifisch auf die Bedürfnisse von Linguistinnen und Linguisten ausgerichtet sind. Es wird gezeigt, wie nummerierte Beispiele, Interlinear-Glossierung, OT-Tableaux, semantische Auszeichnung, Strukturbäume, Diskursrepräsentationsstrukturen und phonetische Notation (IPA) erzeugt werden können.</para>
+</abstract>
+
+</info>
+<section>
+<title>Voraussetzungen und Ziele</title>
+<para>Die meisten der hier beschriebenen Funktionen werden vom „Linguistik“-Modul bereitgestellt, das seit Version 1.6.0 mit LyX mitgeliefert wird. „Module“ – das Konzept wurde ebenfalls mit LyX 1.6.0 eingeführt – sind Ergänzungsdateien, welche die von der Dokumentklasse bereitgestellten Möglichkeiten zumeist für sehr spezifische Aufgaben erweitern und die für jedes Dokument (egal welcher Klasse) einfach ausgewählt werden können. Um das Linguistik-Modul zu verwenden, gehen sie zu <emphasis role='sans'>Dokument&#x21D2;Einstellungen&#x21D2;Module</emphasis>, wählen Sie „Linguistik“ aus der Liste der verfügbaren Module und drücken auf den Knopf <emphasis role='sans'>Hinzufügen</emphasis> (so wie es für dieses Dokument bereits getan wurde).</para>
+<para>Grundsätzlich sollte das Modul in jeder von LyX unterstützten Dokumentklasse funktionieren (falls nicht, informieren Sie bitte den Autor dieses Textes). Allerdings müssen Sie, um alle Features nutzen zu können, die folgenden LaTeX-Pakete installiert haben:</para>
+<orderedlist>
+<listitem>
+<para><emphasis>covington.sty</emphasis> <biblioref endterm="covington" />: Dieses Paket wird benötigt, um nummerierte Beispiele, Glossen und semantische Auszeichnungen zu erzeugen. Beachten Sie, dass mindestens Version 2.3 des Pakets erforderlich ist, um alle Funktionen zu nutzen.</para>
+<itemizedlist>
+<listitem>
+<para>Auf Ihrem System installiert: nein.</para>
+</listitem>
+</itemizedlist>
+</listitem>
+<listitem>
+<para><emphasis>csquotes.sty</emphasis> <biblioref endterm="csquotes" />: Voraussetzung für den Textstil <emphasis>Bedeutung</emphasis> und für Glossen. Das Paket erlaubt es, kontextsensible Anführungszeichen zu generieren (bspw. je nach aktuell verwendeter Sprache).</para>
+<itemizedlist>
+<listitem>
+<para>Auf Ihrem System installiert: nein.</para>
+</listitem>
+</itemizedlist>
+</listitem>
+<listitem>
+<para><emphasis>drs.sty</emphasis> <biblioref endterm="drs" />: Voraussetzung für Diskursrepräsentationsstrukturen. Beachten Sie, dass mindestens Version 2.3 des Pakets <emphasis>covington</emphasis> erforderlich ist, um dies mit anderen Funktionen gemeinsam zu nutzen.</para>
+<itemizedlist>
+<listitem>
+<para>Auf Ihrem System installiert: nein.</para>
+</listitem>
+</itemizedlist>
+</listitem>
+<listitem>
+<para><emphasis>float.sty</emphasis> <biblioref endterm="float" />: Dieses Paket brauchen wir für die OT-Tableaux und das Tableaux-Verzeichnis. Es sollte Bestandteil jeder LaTeX-Distribution sein.</para>
+<itemizedlist>
+<listitem>
+<para>Auf Ihrem System installiert: nein.</para>
+</listitem>
+</itemizedlist>
+</listitem>
+<listitem>
+<para><emphasis>forest.sty</emphasis> <biblioref endterm="forest" />: Dieses Paket wird zur Erzeugung von Strukturbäumen verwendet.</para>
+<itemizedlist>
+<listitem>
+<para>Auf Ihrem System installiert: nein.</para>
+</listitem>
+</itemizedlist>
+</listitem>
+<listitem>
+<para><emphasis>pict2e.sty</emphasis> <biblioref endterm="pict2e" />: Voraussetzung für <emphasis>Duplex-Bedingungs-DRS</emphasis>.</para>
+<itemizedlist>
+<listitem>
+<para>Auf Ihrem System installiert: nein.</para>
+</listitem>
+</itemizedlist>
+</listitem>
+</orderedlist>
+</section>
+<section>
+<title>Nummerierte Beispiele</title>
+<para>Nummerierte Beispiele werden über die Absatzstil-Auswahlliste in der Werkzeugleiste eingefügt. Es gibt drei Varianten:</para>
+<informalexample role='numbered'>
+<para>Das ist ein mehrzeiliges Beispiel [Stil <emphasis>Nummeriertes Beispiel (mehrere Zeilen)</emphasis>]</para>
+<para>Wie der Name sagt, kann es mehrere Absätze enthalten</para>
+</informalexample>
+<informalexample role='consecutive'>
+<para>Das ist ein einzeiliges Beispiel<anchor xml:id="exa.Beispiel-einzeilig" /> [Stil <emphasis>Nummeriertes Beispiel (konsekutiv)</emphasis>]Jeder Absatz wird in diesem Stil neu nummeriert</para>
+</informalexample>
+<informalexample role='consecutive'>
+<para>Dies ist ein Unterbeispiel<anchor xml:id="subsec.Unterbeispiel" /> [Stil <emphasis>Unterbeispiel</emphasis>]Und hier noch eines</para>
+</informalexample>
+<para>Querverweise auf Beispiele erzeugen Sie wie gewohnt: Sie fügen im Beispiel eine Marke ein, und an der Stelle, an der der Querverweis erscheinen soll, einen Verweis mittels <emphasis role='sans'>Einfügen&#x21D2;Querverweis&#x2026;</emphasis> </para>
+<para>Als kleine Demonstration verweisen wir hier auf die Beispiele <xref linkend="exa.Beispiel-einzeilig" /> und <xref linkend="subsec.Unterbeispiel" />.</para>
+<para>Wenn Sie die Nummerierung für einzelne Beispiele ändern möchten, verwenden Sie <emphasis role='sans'>Einfügen&#x21D2;Benutzerdef. Nummerierung</emphasis>. Für globale Anpassungen bietet <emphasis>covington</emphasis> selbst Möglichkeiten. Bitte konsultieren Sie das Handbuch des Pakets <biblioref endterm="covington" /> für Einzelheiten.</para>
+<para>Ab Version 2.3 bietet <emphasis>covingtons</emphasis> subexamples-Umgebung ein optionales Argument (mit dem man Text zwischen der Hauptnummer und dem ersten Unterbeispiel einfügen kann). Dieses können Sie über <emphasis role='sans'>Einfügen&#x21D2;Optionen für Unterbeispiele</emphasis> eingeben. Bitte konsultieren Sie auch hier das Handbuch des Pakets <biblioref endterm="covington" /> für Einzelheiten.</para>
+</section>
+<section>
+<title>Interlinear-Glossierung</title>
+<para>Das Linguistikmodul stellt zwei Arten von Glossen zur Verfügung. Beide sind über <emphasis role='sans'>Einfügen&#x21D2;Spezifische Einfügung</emphasis> zugänglich. Die <emphasis>Interlinear-Glosse (2&#xA0;Zeilen)</emphasis> besteht aus zwei Zeilen für das Glossenpaar (bestehend aus der Darstellung in der zu beschreibenden Sprache und einer interlinearen Wort-zu-Wort-Übersetzung) sowie einer weiteren Zeile für die freie Übersetzung, die <emphasis>Interlinear-Glosse (3&#xA0;Zeilen)</emphasis> bietet eine zusätzliche Zeile für Interlinear-Glossierung (diese dritte Zeile wird zumeist für morphologische oder phonologische Angaben verwendet). Die freie Übersetzung kann länger sein als eine Zeile, sie wird dann einfach automatisch und korrekt umbrochen. Die Version in der zu beschreibenden Sprache (erste Zeile der Glosse) wird direkt in die Glosse-Einfügung geschrieben, alle anderen Teile der Glosse in spezifische Unter-Einfügungen (<emphasis role='sans'>Inter
 linear-Glosse</emphasis>, bzw. mit dreizeiligen Glossen: <emphasis role='sans'>Interlinear-Glosse (Zeile&#xA0;1)</emphasis> und <emphasis role='sans'>Interlinear-Glosse (Zeile&#xA0;2)</emphasis>, sowie <emphasis role='sans'>Glossen-Übersetzung</emphasis>). LyX fügt diese Unter-Einfügungen automatisch ein, wenn Sie eine neue Glosse einfügen. Sie können aber auch manuell eingefügt werden, und zwar über <emphasis role='sans'>Einfügen&#x21D2;Glossen-Übersetzung</emphasis> und <emphasis role='sans'>Einfügen&#x21D2;Interlinear-Glosse</emphasis>. Ungeachtet wo Sie diese Untereinfügungen innerhalb der Glosse einfügen, wird alles in der richtigen Reihenfolge ausgegeben. Schließlich können Sie über <emphasis role='sans'>Einfügen&#x21D2;Glossen-Optionen</emphasis> auch Glossen-Optionen eingeben. Diese Optionen erlauben es Ihnen, die Darstellung der einzelnen Zeilen zu verändern, eine Nummerierung oder vorangestellten Text hinzuzufügen. Bitte konsultieren Sie das Handb
 uch des Pakets <emphasis>covington </emphasis><biblioref endterm="covington" /> für Einzelheiten.<footnote>
+<para>Bitte beachten Sie, dass die Unterstützung für Glossen für LyX 2.4 komplett überarbeitet wurde. Nun werden die neuen und verbesserten Glossen-Makros verwendet, die <emphasis>covington</emphasis> seit der Version 2.0 anbietet. Wegen der erheblichen Veränderungen können alte Glossen leider nicht in die neuen konvertiert werden. Statt dessen werden sie in ihrer ursprünglichen Form importiert (und als <emphasis role='sans'>Lokales Format</emphasis> im Dokument gespeichert). Umgekehrt werden neue Glossen in TeX-Code exportier, wenn Sie in eine ältere LyX-Version exportieren.</para>
+</footnote></para>
+<para>Hier ist ein einfaches Beispiel für eine zweizeilige Glosse:</para>
+<para>C'est       un exemple simple</para>
+<para>Verwenden Sie <emphasis role='sans'>Bearbeiten&#x21D2;Textstil&#x21D2;Glossierte Wortgruppen</emphasis>, um Mehrwortelemente zusammenzuhalten (alternativ können Sie auch im TeX-Modus <!-- { -->
+diese Wörter geschweift einklammern<!-- } -->
+). Beachten Sie, dass Sie im LyX-Fenster mehrere Leerzeichen nacheinander einfügen können, um die Glossen dort schöner auszurichten. Die Ausgabe wird davon nicht berührt.</para>
+<para>Hier ist eine dreizeilige Glosse. Sie wird analog erzeugt:</para>
+<para>Hoc est aliud exemplum</para>
+<para>Beachten Sie, wie wir hier mit Hilfe der Glossen-Optionen die zweite Zeile in Kapitälchen ausgeben lassen.</para>
+<para>Wenn Sie nummerierte Glossen benötigen, fügen Sie die Glosse entweder einfach in einen Absatz mit dem Format <emphasis>Nummeriertes Beispiel</emphasis> ein, so wie hier:</para>
+<informalexample role='consecutive'>
+<para>Mein Luftkissenfahrzeug ist voller  Aale</para>
+</informalexample>
+<para>oder verwenden Sie die Glossen-Option <emphasis>ex</emphasis>:</para>
+<para>Mein Luftkissenfahrzeug ist voller  Aale</para>
+<bridgehead renderas="sect2">Tipps & Tricks</bridgehead>
+<bridgehead renderas="sect3">Seitenumbrüche innerhalb von Glossen vermeiden</bridgehead>
+<para>In der Standardeinstellung können innerhalb von Glossen Seiten umbrochen werden, was natürlich nicht erwünscht ist. Um dies zu umgehen, können Sie in <emphasis role='sans'>Dokument&#x21D2;Einstellungen&#x2026;&#x21D2;Dokumentklasse&#x21D2;Klassenoptionen&#x21D2;Benutzerdefiniert</emphasis> die Option <emphasis>noglossbreaks</emphasis> eingeben; dies wird die meisten Umbrüche verhindern. Wenn trotzdem welche vorkommen, können Sie Glossen in Boxen packen (über <emphasis role='sans'>Einfügen&#x21D2;Box&#x21D2;Rahmenlos</emphasis>).</para>
+<bridgehead renderas="sect3">Fußnoten in Glossen</bridgehead>
+<para>Sie können zwar eine Fußnote in eine <emphasis>Glosse </emphasis>einfügen, dies führt aber zu einem LaTeX-Fehler. Wenn Sie Fußnoten benötigen, schreiben Sie an der Stelle, an der das Fußnotenzeichen erscheinen soll, im TeX-Modus <code>\footnotemark</code> in die Glosse. Direkt nach (und außerhalb) der Glosse schreiben Sie, ebenfalls im TeX-Modus,<code> \footnotetext{Die Fußnote ...}</code>. Sollten Sie mehrere Fußnoten brauchen, geben Sie einfach mehrere dieser Befehlspaare ein.</para>
+<bridgehead renderas="sect3">Glossen (und Beispiele) in Beamer-Präsentationen</bridgehead>
+<para>Wenn Sie das Linguistik-Modul in einer Beamer-Präsentation verwenden wollen, beachten Sie bitte folgendes:</para>
+<itemizedlist>
+<listitem>
+<para>Für Glossen müssen Sie in Beamer immer einen „fragilen“ Rahmen verwenden. </para>
+</listitem>
+<listitem>
+<para>Ältere Versionen des Pakets <emphasis>covington</emphasis> und die <emphasis>Beamer</emphasis>-Klasse arbeiten von Haus aus nicht gut zusammen, da beide die Befehle <code>\example</code> und <code>\examples</code> zu definieren versuchen, was in diesen älteren Versionen eine LaTeX-Fehlermeldung erzeugt, sobald sie Glossen oder Beispiele einfügen. Sie können das Problem beheben, indem Sie in <emphasis role='sans'>Dokument&#x21D2;Einstellungen&#x21D2;Lokales Format</emphasis> folgenden Code kopieren:</para>
+<blockquote>
+<para><programlisting>Provides covington 1
+AddToPreamble
+		\let\example\relax
+		\let\endexample\relax
+		\let\examples\relax
+		\let\endexamples\relax
+		\usepackage{covington}
+EndPreamble</programlisting>
+</para>
+</blockquote>
+<para>Drücken Sie „Validieren“ und dann „OK“. Dies hat den Effekt, dass die Beispiel-Umgebungen von Beamer deaktiviert werden (und also nicht mehr verwendet werden können), dafür können Sie dann aber die des Linguistik-Moduls verwenden.</para>
+<para>Ab <emphasis>covington</emphasis> 1.1 besteht dieses Problem nicht mehr.</para>
+</listitem>
+</itemizedlist>
+</section>
+<section>
+<title>Tableaux für Optimalitätstheorie</title>
+<para>Die OT-Tableaux selbst können natürlich einfach als normale Tabellen eingegeben werden (Spezifika wie gestrichelte Tabellenlinien und schattierte Tabellenzellen, die man hierfür manchmal braucht, sind in <emphasis role='sans'>Hilfe&#x21D2;Eingebettete Objekt</emphasis>e beschrieben). </para>
+<para>Wenn Sie allerdings Ihre Tableaux durch das Dokument hindurch nummerieren und ein eigenes Tableaux-Verzeichnis einrichten möchten, reichen die Bordmittel von LyX nicht aus. Auch hier hilft das Linguistikmodul. Wenn es ausgewählt ist, finden Sie unter <emphasis role='sans'>Einfügen&#x21D2;Gleitobjekte</emphasis> zusätzlich ein Tableau-Gleitobjekt (siehe Tableau&#xA0;<xref linkend="tab.Beispiel-Tableau" /> für ein Beispiel).</para>
+<table xml:id="tab.Beispiel-Tableau">
+<caption>Beispiel-Tableau</caption>
+<informaltable>
+<tbody>
+<tr>
+<td align='right' valign='top'>/atikap/</td>
+<td align='center' valign='top'>Onset</td>
+<td align='center' valign='top'>NoCoda</td>
+<td align='center' valign='top'>Dep</td>
+<td align='center' valign='top'>Max</td>
+</tr>
+<tr>
+<td align='right' valign='top'><inlineequation>
+<alt role='tex'>\mbox{☞}</alt>
+ <m:math>
+ 
+ <m:mrow>
+  <m:mstyle class='mathbox'>☞
+  </m:mstyle>
+ </m:mrow>
+ </m:math>
+</inlineequation> <inlineequation>
+<alt role='tex'>\mbox{\textipa{P}}</alt>
+ <m:math>
+ 
+ <m:mrow>
+  <m:mstyle class='mathbox'>P
+  </m:mstyle>
+ </m:mrow>
+ </m:math>
+</inlineequation>a.ti.ka</td>
+<td align='center' valign='top'></td>
+<td align='center' valign='top'></td>
+<td align='center' valign='top'>*</td>
+<td align='center' valign='top'>*</td>
+</tr>
+<tr>
+<td align='right' valign='top'>a.ti.ka</td>
+<td align='center' valign='top'>*!</td>
+<td align='center' valign='top'></td>
+<td align='center' valign='top'></td>
+<td align='center' valign='top'>*</td>
+</tr>
+<tr>
+<td align='right' valign='top'><inlineequation>
+<alt role='tex'>\mbox{\textipa{P}}</alt>
+ <m:math>
+ 
+ <m:mrow>
+  <m:mstyle class='mathbox'>P
+  </m:mstyle>
+ </m:mrow>
+ </m:math>
+</inlineequation>a.ti.kap</td>
+<td align='center' valign='top'></td>
+<td align='center' valign='top'>*!</td>
+<td align='center' valign='top'>*</td>
+<td align='center' valign='top'></td>
+</tr>
+<tr>
+<td align='right' valign='top'>a.ti.kap</td>
+<td align='center' valign='top'>*!</td>
+<td align='center' valign='top'>*!</td>
+<td align='center' valign='top'></td>
+<td align='center' valign='top'></td>
+</tr>
+</tbody>
+</informaltable>
+</table>
+
+<para>Bitte beachten Sie, dass die Legende in der Standardeinstellung immer unter dem Tableau ausgegeben wird, egal, wohin Sie sie im LyX-Arbeitsfenster setzen. Um die Legende über das Tableau zu setzen, müssen Sie den folgenden Code in <emphasis role='sans'>Dokument&#x21D2;Einstellungen&#x21D2;Präambel </emphasis>eingeben:</para>
+<blockquote>
+<para><programlisting language="[LaTeX]TeX">\floatstyle{plaintop}
+\restylefloat{tableau}</programlisting>
+</para>
+</blockquote>
+<para>Wenn Sie eine KOMA-Klasse verwenden, nehmen Sie statt dessen das Folgende (welches im Kontext der KOMA-Klassen bessere Abstände erzeugt):</para>
+<blockquote>
+<para><programlisting language="[LaTeX]TeX">\floatstyle{komaabove}
+\restylefloat{tableau}</programlisting>
+</para>
+</blockquote>
+<para>Ein Verzeichnis der Tableaux geben Sie, wie bei normalen Tabellen auch, über <emphasis role='sans'>Einfügen&#x21D2;Liste&#x2044;Inhaltsverzeichnis</emphasis> ein. Dies sieht dann so aus:</para>
+</section>
+<section>
+<title>Semantische Auszeichnung (Textstile)</title>
+<para>Das Linguistikmodul stellt einige Textstile zur Verfügung, die in linguistischen Arbeiten allgemein gebräuchlich sind:</para>
+<orderedlist>
+<listitem>
+<para>Konzept (in Kapitälchen): Konzept </para>
+</listitem>
+<listitem>
+<para>Ausdruck (hervorgehoben): Ausdruck</para>
+</listitem>
+<listitem>
+<para>Bedeutung (in einfachen Anführungszeichen): Bedeutung</para>
+</listitem>
+</orderedlist>
+<para>Diese Textstile finden Sie unter <emphasis role='sans'>Bearbeiten&#x21D2;Textstil</emphasis>. Der Vorteil solcher Stile gegenüber direkter Hervorhebung und Auszeichnung ist vor allem der, dass sie alle (und nur die) damit markierten Textteile leicht global verändern können. Wenn Sie (oder Ihr Verlag) also etwa Ausdrücke doch fett gesetzt haben wollen, geben Sie einfach den folgenden Code in <emphasis role='sans'>Dokument&#x21D2;Einstellungen&#x21D2;Präambel</emphasis> ein:</para>
+<blockquote>
+<para><programlisting language="[LaTeX]TeX">\renewcommand\lexp[1]{\textbf{#1}}</programlisting>
+</para>
+</blockquote>
+<para>Auf ähnliche Weise kann auch das Aussehen von <emphasis>Konzept</emphasis> (<code>\lcon</code>) und <emphasis>Bedeutung</emphasis> (<code>\lmean</code>) verändert werden. Bitte konsultieren Sie das Handbuch des Pakets <emphasis>covington</emphasis> <biblioref endterm="covington" /> für Einzelheiten.</para>
+</section>
+<section>
+<title>Linguistische Strukturbäume</title>
+<para>Mittlerweile gibt es mehrere LaTeX-Pakete, die bei der Erstellung von Strukturbäumen helfen. LyX unterstützt das Paket <emphasis role='sans'>forest</emphasis>, welches hohe Flexibilität und Mächtigkeit mit einer intuitiven Syntax vereint. Das Linguistik-Modul enthält eine Strukturbaum-Einfügung, die unter <emphasis role='sans'>Einfügen&#x21D2;Spezifische Einfügung</emphasis> zu finden ist. Innerhalb dieser Einfügung können Sie die Klammernotation verwenden, die das Paket <emphasis role='sans'>forest</emphasis> (wie auch andere Pakete, z.&#x2009;B. <emphasis role='sans'>qtree</emphasis>) anbietet.</para>
+<para>Hier ist ein einfaches Beispiel:</para>
+<para>[VP [DP[Hans]] [V' [V[schickt]] [DP[Maria]] [DP[D[einen]][NP[Brief]]] ] ]</para>
+<para>Wenn Sie die PDF-Ausgabe ansehen, sehen Sie, dass die Notation</para>
+<blockquote>
+<para><code><emphasis role='size_footnote'>[VP [DP[Hans]] [V' [V[schickt]] [DP[Maria]] [DP[D[einen]][NP[Brief]]]]]</emphasis></code></para>
+</blockquote>
+<para>als Strukturbaum ausgegeben wird. Um das Ergebnis bereits im LyX<!-- "= -->
+Eingabefenster zu sehen, können Sie die Strukturbaum-Einfügung einfach in eine Vorschau-Einfügung (<emphasis role='sans'>Einfügen&#x21D2;Vorschau</emphasis>) einbetten. Wenn „Sofortige Vorschau“ richtig eingerichtet und aktiviert ist, sollten Sie den Baum sofort sehen (zur Bearbeitung klicken Sie einfach auf das Bild):</para>
+<para>[VP [DP[Maria]] [V' [V[schickt]] [DP[Hans]] [DP[D[eine]][NP[Antwort]]] ] ]</para>
+<para>Dächer („roofs“) können mittels der Option „roof“<footnote>
+<para>Bitte beachten Sie, dass die Option „roof“ erst ab Version 2.0 des Pakets <emphasis role='sans'>forest</emphasis> verfügbar ist. Für frühere Versionen haben wir in den Vorspann dieses Dokuments Code eingefügt, die die Verwendung dennoch gestattet. Wenn Ihre Version des Pakets <emphasis role='sans'>forest</emphasis> kleiner ist als 2.0 und Sie „roof“ verwenden wollen, müssen Sie diesen Code in den Vorspann Ihres Dokuments kopieren. Statt dessen können Sie auch die alte Option „triangle“ (statt „roof“) verwenden.</para>
+</footnote> erzeugt werden (beachten Sie, dass Kommata eine spezielle Bedeutung haben; sie markieren Optionen):</para>
+<para>[VP [DP[Hans]] [V' [V[schickt]] [DP[Maria]] [DP[einen weiteren Brief, roof]] ] ]</para>
+<para>Um die Knoten des Baums besser auszurichten, verwenden Sie die Option „tier“. Alle Knoten, denen dieselbe „tier“ (Ebene) zugewiesen wurde, werden in einer vertikalen Linie ausgerichtet. Hier ist ein Beispiel:</para>
+<para>[VP [DP[Hans, tier=word]] [V' [V[schickt, tier=word]] [DP[Maria, tier=word]] [DP[D[einen, tier=word]][NP[Brief, tier=word]]] ] ]</para>
+<para>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 <biblioref endterm="forest" />.</para>
+</section>
+<section>
+<title>Diskursrepräsentationsstrukturen</title>
+<para>Das Linguistik-Modul stellt auch Einfügungen zur Erzeugung von Diskursrepräsentationsstrukturen (DRSen) in der Box-Notation von <personname>Hans Kamps</personname> <emphasis>Diskursrepräsentationstheorie</emphasis> zur Verfügung. Diese Einfügungen finden Sie unter <emphasis role='sans'>Einfügen&#x21D2;Spezifische Einfügung</emphasis>.</para>
+<para>Eine einfache DRS erzeugen Sie mit der Einfügung <emphasis role='sans'>Diskursrepräsentationsstruktur</emphasis>. Eine DRS besteht aus (Diskurs-)<emphasis>Bedingungen</emphasis>, die direkt in die Einfügung geschrieben werden, uns den (u.&#x2009;U. leeren) (Diskurs-)<emphasis>Referenten</emphasis> (bzw., im DRT-Jargon, dem <emphasis>Universum</emphasis>), welche in die (automatisch eingefügte) Untereinfügung <emphasis>Referenten</emphasis> geschrieben werden.<footnote>
+<para>Sollte diese nicht eingefügt werden, finden Sie sie unter <emphasis role='sans'>Einfügen&#x21D2;DRS-Referenten</emphasis>. </para>
+</footnote> Zeilenwechsel müssen mittels <keycap>Ctrl+Return</keycap> eingefügt werden. Hier ist ein einfaches Beispiel:</para>
+<para>
+Esel(x)grün(x)</para>
+<para>DRSen sind durch spezifische Layout-Anpassungen so gestaltet, dass Sie gut auf der Seite platziert werden. Die Variante <emphasis role='sans'>Diskursrepräsentationsstruktur (einfach)</emphasis> unterdrückt diese Anpassungen. </para>
+<para>Zusätzlich zu diesen einfachen DRSen werden die folgenden konditionalen DRSen unterstützt (sie werden in der Regel in einfache eingebettet):</para>
+<orderedlist>
+<listitem>
+<para>Die <emphasis role='sans'>Implikative DRS</emphasis> repräsentiert eine konditionale (implikative) Satzkonstruktion der Form <emphasis>wenn S<subscript>1</subscript>, dann S</emphasis><subscript>2</subscript>:</para>
+<para>Joseph(x)Esel(y)besitzen(x,y)</para>
+</listitem>
+<listitem>
+<para>Die <emphasis role='sans'>Konditionale DRS</emphasis> ist eine allgemeinere Variante, bei der Sie selbst eine beliebige Bedingung (statt der implikativen) spezifizieren können. In die Untereinfügung <emphasis role='sans'>Bedingung</emphasis> können Sie ein beliebiges Symbol eingeben:</para>
+<para>Joseph(x)Esel(y)besitzen(x,y)</para>
+</listitem>
+<listitem>
+<para>Die <emphasis role='sans'>Duplex-Bedingungs-DRS</emphasis> können Sie für sog. <emphasis>Duplex-Bedingungen</emphasis> verwenden:</para>
+<para>x <inlineequation>
+<alt role='tex'>\in</alt>
+ <m:math>
+ 
+ <m:mrow><m:mo>&#x2208;</m:mo>
+ </m:mrow>
+ </m:math>
+</inlineequation> X</para>
+</listitem>
+<listitem>
+<para>Die <emphasis role='sans'>Negierte DRS</emphasis> fügt eine DRS ein, der ein Negationszeichen vorangestellt ist:</para>
+<para>Esel(x)grün(x)</para>
+</listitem>
+</orderedlist>
+<para><emphasis role='sans'>DRS mit Satz oberhalb</emphasis> schließlich tut, was es verspricht: Es setzt einen Satz über die Box-Repräsentation:</para>
+<para>
+Esel(x)grün(x)
+</para>
+<para>Das Paket <emphasis>drs</emphasis> bietet einige Möglichkeiten, um das Erscheinungsbild der DRS-Modelle anzupassen. Bitte konsultieren Sie das Handbuch des Pakets <biblioref endterm="drs" /> für Einzelheiten.</para>
+</section>
+<section>
+<title>Phonetische Notation (IPA)</title>
+<para>Um phonetische Zeichen einzugeben, brauchen Sie das Linguistikmodul nicht. IPA-Unterstützung ist mittlerweile eine Grundfunktion von LyX. Da IPA aber von Linguistinnen und Linguisten sehr häufig gebraucht wird, wird die Verwendung der IPA-Funktion hier trotzdem (kurz) beschrieben.</para>
+<para>Um LyX' IPA-Funktion mit klassischem LaTeX oder PDFLaTeX zu benutzen, müssen Sie das Paket <emphasis>tipa</emphasis> <biblioref endterm="tipa" /> installiert haben. Es wird von LyX automatisch geladen, wenn Sie dem unten beschriebenen Vorgehen folgen. Wenn Sie XeTeX oder LuaTeX verwenden (und „Nicht-TeX-Schriften verwenden“ in <emphasis role='sans'>Dokument&#x21D2;Einstellungen&#x21D2;Schriften</emphasis> aktiviert haben), wird statt dessen das Paket <emphasis>xunicode</emphasis> geladen, da <emphasis>tipa</emphasis> in diesem Fall nicht funktioniert. Das Paket <emphasis>xunicode</emphasis> emuliert die Ausgabe von <emphasis>tipa</emphasis>, ist aber nicht perfekt, so dass die Ausgabe möglicherweise nicht wie erwartet ist. Außerdem müssen Sie in diesem Fall darauf achten, dass die Nicht-TeX-Schrift die IPA-Symbole auch enthält (empfehlenswert sind Schriften wie <emphasis>CMU Serif</emphasis> oder <emphasis>SIL Doulos</emphasis>). Sie können auch eine 
 Schrift nur für IPA definieren, indem sie das Folgende in <emphasis role='sans'>Dokument&#x21D2;Einstellungen&#x21D2;LaTeX-Vorspann</emphasis> eingeben:</para>
+<para><programlisting language="[LaTeX]TeX">\AtBeginDocument{%
+\newfontfamily{\ipafont}{CMU Serif}% oder eine ander Schriftart
+\def\useTIPAfont{\ipafont}
+}</programlisting>
+Für eine direkte Vorschau der IPA-Symbole im Arbeitsfenster sollten Sie weiterhin (egal, welche der oben beschriebenen Ausgabeformate Sie verwenden) das <emphasis>preview-latex</emphasis>-Paket <biblioref endterm="preview" /> installiert haben.</para>
+<para>Phonetische Zeichen werden in eine spezielle Umgebung eingegeben, die Sie über <emphasis role='sans'>Einfügen&#x21D2;Sonderzeichen&#x21D2;Phonetische Symbole </emphasis>aktivieren. Es wird ein kleiner umrahmter Eingabebereich eingefügt, in den Sie einzelne Zeichen, Wörter und Wortfolgen sowie auch mehrere Absätze mit phonetischer Notation eingeben können. Wenn Sie in dem Eingabebereich sind, wird eine Symbolleiste aktiviert, die die wichtigsten IPA-Symbole (nach den IPA-Kategorien sortiert) bereitstellt.<footnote>
+<para>Es fehlt ein Symbol: der (2005 in das IPA aufgenommene) labiodentale Flap. Dieses Zeichen unterstützt das <emphasis>Tipa-</emphasis>Paket noch nicht; daher kann es auch nicht von LyX unterstützt werden.</para>
+</footnote> Jeder Symbolbereich dieser Symbolleiste kann durch Klicken auf die gestrichelte Linie abgetrennt werden. Dadurch kann phonetische Notation recht komfortabel eingegeben werden: [ˈɛtva zo:].<footnote>
+<para>Wenn Sie ein diakritisches Zeichen einfügen möchten, müssen Sie das Diakritikum <emphasis>nach</emphasis> dem Basiszeichen einfügen. Das heißt, für [d̥] geben Sie zuerst <code><d></code> ein und dann direkt danach das Diakritikum <code><Stimmlos></code> von der Symbolleiste. Wenn Sie nur ein Diakritikum eingeben möchten, können Sie das direkt nach einem Leerzeichen tun, so wie hier:  ̼ (<code>=&#xA0;<Leerzeichen>+<Lingolabial></code>).</para>
+</footnote> Wenn<emphasis> preview-latex</emphasis> installiert ist und Sie außerdem in<emphasis role='sans'> Werkzeuge&#x21D2;Einstellungen&#x2026;&#x21D2;Grafik</emphasis> „Sofortige Vorschau“ aktiviert haben, zeigt LyX eine WYSIWYG-Vorschau der Notation an, sobald der Cursor den IPA-Bereich verlässt. Alternativ zur Symbolleiste können Sie die Zeichen auch direkt mithilfe der Kurznotation eingeben können, die im <emphasis>tipa</emphasis>-Handbuch erläutert wird: hier eine [kOst"pro:b@] (<emphasis>tipa</emphasis>-Kurznotation: <code>[kOst"pro:b@</code>]). Alternativ können Sie die meisten IPA-Zeichen auch über <emphasis role='sans'>Einfügen&#x21D2;Sonderzeichen&#x21D2;Symbole&#x2026;</emphasis> in das Eingabefeld eingeben oder sie aus einem anderen Dokument kopieren und dort einfügen. Die Ausgabe sollte immer identisch sein, egal welche Eingabemethode Sie wählen.</para>
+<para>Bitte beachten Sie, dass Sie die meisten IPA-Zeichen über die zuletzt genannten Methoden auch außerhalb des IPA-Eingabebereichs einfügen können: [zoː viː hiːɐ̯]. In der Ausgabe werden diese Zeichen dann ebenfalls direkt in die korrekten <emphasis>tipa</emphasis>-Makros umgewandelt (lassen Sie es uns wissen, falls das nicht der Fall ist). Dieses Verfahren hat aber gravierende Nachteile gegenüber der IPA-Umgebung, denn die direkte Eingabe resultiert in der Regel in unerwünschter Schriftmischung (die lateinischen Buchstaben werden aus der Grundschrift, die speziellen IPA-Zeichen aber aus der IPA-Schrift genommen, und diese beiden Schriften passen nicht notwendigerweise zusammen). Innerhalb der IPA-Eingabeumgebung wird dagegen für alle Zeichen dieselbe Schrift verwendet. Deshalb sollten Sie, wenn Sie nicht nur Einzelzeichen eingeben, unbedingt den IPA-Eingabebereich verwenden.</para>
+</section>
+<section>
+<title>Weitere Informationen</title>
+<para>Mehr und ausführlichere Informationen über die Möglichkeiten des Einsatzes von LyX für linguistische Zwecke finden Sie auf der (englischsprachigen) <emphasis>LinguistLyX</emphasis>-Seite auf dem LyX-Wiki <biblioref endterm="linguistlyx" />. Sie sind übrigens herzlich eingeladen, dort aktiv mitzuschreiben!</para>
+</section>
+<bibliography>
+<bibliomixed xml:id='covington'>Das covington-Paket: <link xlink:href="http://www.ctan.org/tex-archive/macros/latex/contrib/covington/">http://www.ctan.org/tex-archive/macros/latex/contrib/covington/</link>.</bibliomixed>
+<bibliomixed xml:id='csquotes'>Das csquotes-Paket: <link xlink:href="http://www.ctan.org/tex-archive/macros/latex/contrib/csquotes/">http://www.ctan.org/tex-archive/macros/latex/contrib/csquotes/</link>.</bibliomixed>
+<bibliomixed xml:id='drs'> Das drs-Paket: <link xlink:href="https://ctan.org/tex-archive/macros/latex/contrib/drs">https://ctan.org/tex-archive/macros/latex/contrib/drs</link>.</bibliomixed>
+<bibliomixed xml:id='enumitem'>Das enumitem-Paket: <link xlink:href="http://www.ctan.org/tex-archive/macros/latex/contrib/enumitem/">http://www.ctan.org/tex-archive/macros/latex/contrib/enumitem/</link>.</bibliomixed>
+<bibliomixed xml:id='float'>Das float-Paket: <link xlink:href="http://www.ctan.org/tex-archive/macros/latex/contrib/float/">http://www.ctan.org/tex-archive/macros/latex/contrib/float/</link>.</bibliomixed>
+<bibliomixed xml:id='forest'>Das forest-Paket: <link xlink:href="http://www.ctan.org/tex-archive/graphics/pgf/contrib/forest">http://www.ctan.org/tex-archive/graphics/pgf/contrib/forest</link>.</bibliomixed>
+<bibliomixed xml:id='linguistlyx'>Maria Gouskova, Stacia Hartleben und Jürgen Spitzmüller: Using LyX for Linguistic Papers. <link xlink:href="https://wiki.lyx.org/LyX/LinguistLyX">https://wiki.lyx.org/LyX/LinguistLyX</link>.</bibliomixed>
+<bibliomixed xml:id='pict2e'>Das pict2e-Paket: <link xlink:href="https://ctan.org/tex-archive/macros/latex/contrib/pict2e">https://ctan.org/tex-archive/macros/latex/contrib/pict2e</link></bibliomixed>
+<bibliomixed xml:id='preview'>Das preview-latex-Paket: <link xlink:href="http://www.ctan.org/tex-archive/macros/latex/contrib/preview/">http://www.ctan.org/tex-archive/macros/latex/contrib/preview/</link>.</bibliomixed>
+<bibliomixed xml:id='tipa'>Das tipa-Paket und die zugehörigen Schriften: <link xlink:href="http://www.ctan.org/tex-archive/fonts/tipa/">http://www.ctan.org/tex-archive/fonts/tipa/</link>.</bibliomixed>
+</bibliography>
+</article>
\ No newline at end of file
diff --git a/lib/layouts/linguistics.module b/lib/layouts/linguistics.module
index d272c25..bcfc370 100644
--- a/lib/layouts/linguistics.module
+++ b/lib/layouts/linguistics.module
@@ -82,6 +82,10 @@ Style Numbered_Example_(multiline)
 	EndFont
 	Requires	      covington
 	Category              Linguistics
+	DocBookWrapperTag     informalexample
+	DocBookWrapperAttr    role='numbered'
+	DocBookWrapperMergeWithPrevious  true
+	DocBookTag            para
 End
 
 
@@ -107,6 +111,10 @@ Style Numbered_Examples_(consecutive)
 		LabelString   "Custom Numbering|s"
 		Tooltip       "Customize the numeration"
 	EndArgument
+	DocBookWrapperTag     informalexample
+	DocBookWrapperAttr    role='consecutive'
+	DocBookWrapperMergeWithPrevious  true
+	DocBookTag            para
 End
 
 
diff --git a/src/Floating.cpp b/src/Floating.cpp
index bdd8bf7..7ee042c 100644
--- a/src/Floating.cpp
+++ b/src/Floating.cpp
@@ -90,9 +90,10 @@ string const & Floating::docbookAttr() const
 
 string Floating::docbookTag(bool hasTitle) const
 {
+	// TODO: configure this in the layouts?
 	if (floattype_ == "figure") {
 		return hasTitle ? "figure" : "informalfigure";
-	} else if (floattype_ == "table") {
+	} else if (floattype_ == "table" || floattype_ == "tableau") {
 		return hasTitle ? "table" : "informaltable";
 	} else if (floattype_ == "algorithm") {
 		// TODO: no good translation for now! Figures are the closest match, as they can contain text.
@@ -119,7 +120,7 @@ string const & Floating::docbookCaption() const
 	docbook_caption_ = "";
 	if (floattype_ == "figure") {
 		docbook_caption_ = "title";
-	} else if (floattype_ == "table") {
+	} else if (floattype_ == "table" || floattype_ == "tableau") {
 		docbook_caption_ = "caption";
 	} else if (floattype_ == "algorithm") {
 		// TODO: no good translation for now! Figures are the closest match, as they can contain text.
diff --git a/src/Floating.h b/src/Floating.h
index 977958b..46816af 100644
--- a/src/Floating.h
+++ b/src/Floating.h
@@ -37,7 +37,7 @@ public:
 		 std::string const & listName, std::string const & listCmd,
 		 std::string const & refPrefix, std::string const & allowedplacement,
 		 std::string const & htmlType, std::string const & htmlClass,
-		 docstring const & htmlStyle, std::string const & docbookTag,
+		 docstring const & htmlStyle,
 		 std::string const & docbookAttr, std::string const & docbookTagType,
 		 std::string const & required, bool usesfloat, bool isprefined,
 		 bool allowswide, bool allowssideways);
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index e413403..2bb1a04 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -1574,7 +1574,7 @@ bool TextClass::readFloat(Lexer & lexrc)
 		}
 		Floating fl(type, placement, ext, within, style, name,
 			listname, listcommand, refprefix, allowed_placement,
-			htmltag, htmlattr, htmlstyle, docbooktag, docbookattr,
+			htmltag, htmlattr, htmlstyle, docbookattr,
 			docbooktagtype, required, usesfloat, ispredefined,
 	        allowswide, allowssideways);
 		floatlist_.newFloat(fl);
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 28d2e1e..addf24a 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -293,7 +293,8 @@ void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar
 	if (prevpar != nullptr) {
 		Layout const & prevlay = prevpar->layout();
 		if (prevlay.docbookwrappertag() != "NONE") {
-			if (prevlay.docbookwrappertag() == lay.docbookwrappertag())
+			if (prevlay.docbookwrappertag() == lay.docbookwrappertag() &&
+					prevlay.docbookwrapperattr() == lay.docbookwrapperattr())
 				openWrapper = !lay.docbookwrappermergewithprevious();
 			else
 				openWrapper = true;
@@ -329,7 +330,8 @@ void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpa
 	if (nextpar != nullptr) {
 		Layout const & nextlay = nextpar->layout();
 		if (nextlay.docbookwrappertag() != "NONE") {
-			if (nextlay.docbookwrappertag() == lay.docbookwrappertag())
+			if (nextlay.docbookwrappertag() == lay.docbookwrappertag() &&
+					nextlay.docbookwrapperattr() == lay.docbookwrapperattr())
 				closeWrapper = !nextlay.docbookwrappermergewithprevious();
 			else
 				closeWrapper = true;

commit 81a73c7fd750fd1e210f5971cb633059bc8cae39
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Wed Sep 2 00:36:46 2020 +0200

    DocBook: fix crash with Linguistics example.
    
    This was due to Floating::docbookTag not returning anything with the floattype_ tableau. Another issue that happened with that document is that the standard library's isspace crashed for some characters. I therefore implemented a more efficient version of the part that required it, and inlined the definition of isspace (even though that part becomes irrespective of locale, but was that feature ever used?).

diff --git a/src/Floating.cpp b/src/Floating.cpp
index 19fbf5f..bdd8bf7 100644
--- a/src/Floating.cpp
+++ b/src/Floating.cpp
@@ -30,7 +30,7 @@ Floating::Floating(string const & type, string const & placement,
 		   string const & listName, std::string const & listCmd,
 		   string const & refPrefix, std::string const & allowedplacement,
 		   string const & htmlTag, string const & htmlAttrib,
-		   docstring const & htmlStyle, string const & docbookTag,
+		   docstring const & htmlStyle,
 		   string const & docbookAttr, string const & docbookTagType,
            string const & required, bool usesfloat, bool ispredefined,
 		   bool allowswide, bool allowssideways)
@@ -98,6 +98,10 @@ string Floating::docbookTag(bool hasTitle) const
 		// TODO: no good translation for now! Figures are the closest match, as they can contain text.
 		// Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer.
 		return "figure";
+	} else {
+		// If nothing matches, return something that will not be valid.
+		LYXERR0("Unrecognised float type: " + floattype_);
+		return "float";
 	}
 }
 
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 087d5a9..28d2e1e 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -427,6 +427,16 @@ void makeBibliography(
 }
 
 
+bool isNotOnlySpace(docstring const & str)
+{
+	for (auto const & c: str) {
+		if (c != ' ' && c != '\t' && c != '\n' && c != '\v' && c != '\f' && c != '\r')
+			return true;
+	}
+	return false;
+}
+
+
 void makeParagraph(
 		Text const & text,
 		Buffer const & buf,
@@ -518,8 +528,8 @@ void makeParagraph(
 	auto nextpar = par;
 	++nextpar;
 	auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(distance(begin, par)), 0, nextpar == end, special_case);
-	for (auto & parXML : pars) {
-		if (!std::all_of(parXML.begin(), parXML.end(), ::isspace)) {
+	for (docstring const & parXML : pars) {
+		if (isNotOnlySpace(parXML)) {
 			if (open_par)
 				openParTag(xs, &*par, prevpar);
 

commit 5e4c0aafc42d76e1024800e34d3d671c7eadba08
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Wed Sep 2 00:00:54 2020 +0200

    Fix a few warnings.

diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 9dea24b..a409d20 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3860,8 +3860,8 @@ bool Paragraph::isHardHyphenOrApostrophe(pos_type pos) const
 	char_type const c = d->text_[pos];
 	if (c != '-' && c != '\'')
 		return false;
-	int nextpos = pos + 1;
-	int prevpos = pos > 0 ? pos - 1 : 0;
+	pos_type nextpos = pos + 1;
+	pos_type prevpos = pos > 0 ? pos - 1 : 0;
 	if ((nextpos == psize || isSpace(nextpos))
 		&& (pos == 0 || isSpace(prevpos)))
 		return false;
diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp
index b33cf00..4c6f17e 100644
--- a/src/insets/InsetNewline.cpp
+++ b/src/insets/InsetNewline.cpp
@@ -172,7 +172,7 @@ int InsetNewline::plaintext(odocstringstream & os,
 }
 
 
-void InsetNewline::docbook(XMLStream & xs, OutputParams const & runparams) const
+void InsetNewline::docbook(XMLStream &, OutputParams const &) const
 {
 	// New lines are handled by Paragraph::simpleDocBookOnePar.
 }
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 1f17351..087d5a9 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -471,7 +471,7 @@ void makeParagraph(
 	// Plain layouts must be ignored.
 	special_case |= buf.params().documentClass().isPlainLayout(par->layout()) && !runparams.docbook_force_pars;
 	// Equations do not deserve their own paragraph (DocBook allows them outside paragraphs).
-	special_case |= nInsets == par->size() && std::all_of(par->insetList().begin(), par->insetList().end(), [](InsetList::Element inset) {
+	special_case |= nInsets == (size_t) par->size() && std::all_of(par->insetList().begin(), par->insetList().end(), [](InsetList::Element inset) {
 		return inset.inset && inset.inset->asInsetMath();
 	});
 

commit e82edf7795ba7ba5cde91dc7377383efba73258f
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 31 03:09:16 2020 +0200

    DocBook: do a little something for shapepar.

diff --git a/lib/layouts/shapepar.module b/lib/layouts/shapepar.module
index f5068dc..6b38cdf 100644
--- a/lib/layouts/shapepar.module
+++ b/lib/layouts/shapepar.module
@@ -35,41 +35,51 @@ Style "CD label"
 	ParSkip		0.4
 	Align		Block
 	LabelType	No_Label
+	DocBookWrapperTag  sidebar
+	DocBookWrapperAttr role="cd-label"
+	DocBookTag  para
 End
 
 Style "Circle"
 	CopyStyle	"CD label"
 	LatexName	circlepar
+	DocBookWrapperAttr role="circle"
 End
 
 Style "Diamond"
 	CopyStyle	"CD label"
 	LatexName	diamondpar
+	DocBookWrapperAttr role="diamond"
 End
 
 Style "Heart"
 	CopyStyle	"CD label"
 	LatexName	heartpar
+	DocBookWrapperAttr role="heart"
 End
 
 Style "Hexagon"
 	CopyStyle	"CD label"
 	LatexName	hexagonpar
+	DocBookWrapperAttr role="hexagon"
 End
 
 Style "Nut"
 	CopyStyle	"CD label"
 	LatexName	nutpar
+	DocBookWrapperAttr role="nut"
 End
 
 Style "Square"
 	CopyStyle	"CD label"
 	LatexName	squarepar
+	DocBookWrapperAttr role="square"
 End
 
 Style "Star"
 	CopyStyle	"CD label"
 	LatexName	starpar
+	DocBookWrapperAttr role="star"
 End
 
 # now the shapes defined in the .def files
@@ -77,41 +87,49 @@ End
 Style "Candle"
 	CopyStyle	"CD label"
 	LatexName	shapepar{\candle}
+	DocBookWrapperAttr role="candle"
 End
 
 Style "Drop down"
 	CopyStyle	"CD label"
 	LatexName	droppar
+	DocBookWrapperAttr role="drop-down"
 End
 
 Style "Drop up"
 	CopyStyle	"CD label"
 	LatexName	dropuppar
+	DocBookWrapperAttr role="drop-up"
 End
 
 Style "TeX"
 	CopyStyle	"CD label"
 	LatexName	shapepar{\TeXshape}
+	DocBookWrapperAttr role="tex"
 End
 
 Style "Triangle up"
 	CopyStyle	"CD label"
 	LatexName	triangleuppar
+	DocBookWrapperAttr role="triangle-up"
 End
 
 Style "Triangle down"
 	CopyStyle	"CD label"
 	LatexName	triangledownpar
+	DocBookWrapperAttr role="triangle-down"
 End
 
 Style "Triangle left"
 	CopyStyle	"CD label"
 	LatexName	triangleleftpar
+	DocBookWrapperAttr role="triangle-left"
 End
 
 Style "Triangle right"
 	CopyStyle	"CD label"
 	LatexName	trianglerightpar
+	DocBookWrapperAttr role="triangle-right"
 End
 
 # finally the low-level commands

commit 25ef483686b3b68292e43d4fb2f4c99040de546c
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 31 02:39:37 2020 +0200

    DocBook: implement theorems.
    
    This is a minimal implementation, as DocBook lacks a serious way of encoding all of this. Maybe a <formalpara> could do the trick, but I'd need to find a way to shoehorn a title through the styles (i.e. a first complete tag):
    
    Theorem: Bla bla
    
    <formalpara>
    <title>Theorem</title>
    <para>Bla bla</para>
    </formalpara>
    
    This would also only be a solution for single-paragraph things, as formalpara only allows one paragraph. Or a sidebar, but it's semantically very remote.

diff --git a/autotests/export/docbook/Additional_lyxcode.lyx b/autotests/export/docbook/Additional_lyxcode.lyx
index fe2d428..797e315 100644
--- a/autotests/export/docbook/Additional_lyxcode.lyx
+++ b/autotests/export/docbook/Additional_lyxcode.lyx
@@ -367,5 +367,169 @@ This section is somewhat out of date.
 
 \end_layout
 
+\begin_layout Section
+AMS \SpecialChar LaTeX
+
+\end_layout
+
+\begin_layout Standard
+These same environments are provided only in the starred versions by the
+ 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+Theorems (Starred)
+\end_layout
+
+\end_inset
+
+ module:
+\end_layout
+
+\begin_layout Theorem
+This is typically used for the statements of major results.
+ 
+\end_layout
+
+\begin_layout Corollary*
+This is used for statements which follow fairly directly from previous statement
+s.
+ Again, these can be major results.
+ 
+\end_layout
+
+\begin_layout Lemma
+These are smaller results needed to prove other statements.
+\end_layout
+
+\begin_layout Proposition
+These are less major results which (hopefully) add to the general theory
+ being discussed.
+\end_layout
+
+\begin_layout Conjecture
+These are statements provided without justification, which the author does
+ not know how to prove, but which seem to be true (to the author, at least).
+\end_layout
+
+\begin_layout Definition*
+Guess what this is for.
+ The font is different for this environment than for the previous ones.
+ 
+\end_layout
+
+\begin_layout Example*
+Used for examples illustrating proven results.
+\end_layout
+
+\begin_layout Problem
+It's not really known what this is for.
+ You should figure it out.
+\end_layout
+
+\begin_layout Exercise*
+Write a description for this one.
+\end_layout
+
+\begin_layout Remark
+This environment is also a type of theorem, usually a lesser sort of observation.
+\end_layout
+
+\begin_layout Claim*
+Often used in the course of giving a proof of a larger result.
+\end_layout
+
+\begin_layout Case
+Generally, these are used to break up long arguments, using specific instances
+ of some condition.
+ 
+\end_layout
+
+\begin_layout Case
+The numbering scheme for cases is on its own, not together with other numbered
+ statements.
+ 
+\end_layout
+
+\begin_layout Proof
+At the end of this environment, a QED symbol (usually a square, but it can
+ vary with different styles) is placed.
+ If you want to have other environments within this one—for example, Case
+ environments—and have the QED symbol appear only after them, then the other
+ environments need to be nested within the proof environment.
+ See the section 
+\emph on
+Nesting Environments
+\emph default
+ of the 
+\emph on
+User's Guide
+\emph default
+ for information on nesting.
+\end_layout
+
+\begin_layout Standard
+And these environments are provided by 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+Theorems (AMS-Extended)
+\end_layout
+
+\end_inset
+
+:
+\end_layout
+
+\begin_layout Criterion*
+A required condition.
+\end_layout
+
+\begin_layout Algorithm*
+A general procedure to be used.
+\end_layout
+
+\begin_layout Axiom*
+This is a property or statement taken as true within the system being discussed.
+\end_layout
+
+\begin_layout Condition*
+Sometimes used to state a condition assumed within the present context of
+ discussion.
+\end_layout
+
+\begin_layout Note*
+Similar to a Remark.
+\end_layout
+
+\begin_layout Notation*
+Used for the explanation of, yes, notation.
+\end_layout
+
+\begin_layout Summary
+Do we really need to tell you? 
+\end_layout
+
+\begin_layout Acknowledgement*
+Acknowledgement.
+\end_layout
+
+\begin_layout Conclusion*
+Sometimes used at the end of a long train of argument.
+\end_layout
+
+\begin_layout Fact
+Used in a way similar to Proposition, though perhaps lower on the scale.
+\end_layout
+
+\begin_layout Standard
+In addition, the AMS classes automatically provide the AMS \SpecialChar LaTeX
+ and AMS fonts
+ packages.
+ They need to be available on your system in order to use these environments.
+\end_layout
+
 \end_body
 \end_document
diff --git a/autotests/export/docbook/Additional_lyxcode.xml b/autotests/export/docbook/Additional_lyxcode.xml
index b677971..f42ac9f 100644
--- a/autotests/export/docbook/Additional_lyxcode.xml
+++ b/autotests/export/docbook/Additional_lyxcode.xml
@@ -36,5 +36,40 @@ This ...
 <para>This section is somewhat out of date. Need to describe default master documents and how children are opened when the master is. [[FIXME]]</para>
 </sidebar>
 </section>
+<section>
+<title>AMS LaTeX</title>
+<para>These same environments are provided only in the starred versions by the <code>Theorems (Starred)</code> module:</para>
+<para role='theorem'>This is typically used for the statements of major results. </para>
+<para role='corollary'>This is used for statements which follow fairly directly from previous statements. Again, these can be major results. </para>
+<para role='lemma'>These are smaller results needed to prove other statements.</para>
+<para role='proposition'>These are less major results which (hopefully) add to the general theory being discussed.</para>
+<para role='conjecture'>These are statements provided without justification, which the author does not know how to prove, but which seem to be true (to the author, at least).</para>
+<para role='definition'>Guess what this is for. The font is different for this environment than for the previous ones. </para>
+<informalexample>
+<para>Used for examples illustrating proven results.</para>
+</informalexample>
+<para role='problem'>It's not really known what this is for. You should figure it out.</para>
+<para role='exercise'>Write a description for this one.</para>
+<note role='theorem'>
+<para>This environment is also a type of theorem, usually a lesser sort of observation.</para>
+</note>
+<para role='claim'>Often used in the course of giving a proof of a larger result.</para>
+<para role='cases'>Generally, these are used to break up long arguments, using specific instances of some condition. The numbering scheme for cases is on its own, not together with other numbered statements. </para>
+<para role='proof'>At the end of this environment, a QED symbol (usually a square, but it can vary with different styles) is placed. If you want to have other environments within this one—for example, Case environments—and have the QED symbol appear only after them, then the other environments need to be nested within the proof environment. See the section <emphasis>Nesting Environments</emphasis> of the <emphasis>User's Guide</emphasis> for information on nesting.</para>
+<para>And these environments are provided by <code>Theorems (AMS-Extended)</code>:</para>
+<para role='criterion'>A required condition.</para>
+<para role='algorithm'>A general procedure to be used.</para>
+<para role='axiom'>This is a property or statement taken as true within the system being discussed.</para>
+<para role='condition'>Sometimes used to state a condition assumed within the present context of discussion.</para>
+<note role='theorem'>
+<para>Similar to a Remark.</para>
+</note>
+<para role='notation'>Used for the explanation of, yes, notation.</para>
+<para role='summary'>Do we really need to tell you? </para>
+<para role='acknowledgement'>Acknowledgement.</para>
+<para role='conclusion'>Sometimes used at the end of a long train of argument.</para>
+<para role='fact'>Used in a way similar to Proposition, though perhaps lower on the scale.</para>
+<para>In addition, the AMS classes automatically provide the AMS LaTeX and AMS fonts packages. They need to be available on your system in order to use these environments.</para>
+</section>
 </chapter>
 </book>
\ No newline at end of file
diff --git a/development/DocBookToDo b/development/DocBookToDo
index 39ca534..6b6ca34 100644
--- a/development/DocBookToDo
+++ b/development/DocBookToDo
@@ -17,4 +17,25 @@ TableRefs, TableComments: no mapping in DocBook, not really a way to add these t
 
 Clearly, with this kind of template, we're reaching the limits of such a system! Having a really good converter for all these cases would require a lot of very specific code. 
 
-More general: what the heck with appendices? It's not handled in the LyX way (Document > Start Appendix Here), but in a custom way. Making this work would solve some correctness issues with this template. 
\ No newline at end of file
+More general: what the heck with appendices? It's not handled in the LyX way (Document > Start Appendix Here), but in a custom way. Making this work would solve some correctness issues with this template. 
+
+
+
+Things specific to modules
+==========================
+
+AMS
+---
+
+Theorems and the like do not have counter parts in DocBook. Maybe a <formalpara> could do the trick, but I'd need to find a way to shoehorn a title through the styles (i.e. a first complete tag): 
+
+	LyX:
+		Theorem: Bla bla
+
+	DocBook:
+		<formalpara>
+			<title>Theorem</title>
+			<para>Bla bla</para>
+		</formalpara>
+
+This would also only be a solution for single-paragraph things, as formalpara only allows one paragraph. Or a sidebar, but it's semantically very remote. 
\ No newline at end of file
diff --git a/lib/layouts/theorems-ams-bytype.inc b/lib/layouts/theorems-ams-bytype.inc
index a306f15..fede0e8 100644
--- a/lib/layouts/theorems-ams-bytype.inc
+++ b/lib/layouts/theorems-ams-bytype.inc
@@ -110,6 +110,8 @@ Style Theorem
 		\addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
 	Requires              amsthm
+	DocBookTag            para
+	DocBookAttr           role='theorem'
 End
 
 
@@ -128,6 +130,8 @@ Style Corollary
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='corollary'
 End
 
 
@@ -146,6 +150,8 @@ Style Lemma
 	  \addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
 	LabelCounter          lemma
+	DocBookTag            para
+	DocBookAttr           role='lemma'
 End
 
 
@@ -164,6 +170,8 @@ Style Proposition
 	  \addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
 	LabelCounter          proposition
+	DocBookTag            para
+	DocBookAttr           role='proposition'
 End
 
 
@@ -182,6 +190,8 @@ Style Conjecture
 	  \addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
 	LabelCounter          conjecture
+	DocBookTag            para
+	DocBookAttr           role='conjecture'
 End
 
 
@@ -200,6 +210,8 @@ Style Fact
 	  \addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
 	LabelCounter          fact
+	DocBookTag            para
+	DocBookAttr           role='fact'
 End
 
 
@@ -225,6 +237,8 @@ Style Definition
 	  \addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
 	LabelCounter          definition
+	DocBookTag            para
+	DocBookAttr           role='definition'
 End
 
 
@@ -244,6 +258,9 @@ Style Example
 	  \addto\captions$$lang{\renewcommand{\examplename}{_(Example)}}
 	EndBabelPreamble
 	LabelCounter          example
+	DocBookWrapperTag     informalexample
+	DocBookTag            para
+	DocBookAttr        ""
 End
 
 
@@ -263,6 +280,8 @@ Style Problem
 	  \addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
 	LabelCounter          problem
+	DocBookTag            para
+	DocBookAttr           role='problem'
 End
 
 
@@ -282,6 +301,8 @@ Style Exercise
 	  \addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
 	LabelCounter          exercise
+	DocBookTag            para
+	DocBookAttr           role='exercise'
 End
 
 
@@ -301,6 +322,8 @@ Style Solution
 		\addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
 	LabelCounter          solution
+	DocBookTag            para
+	DocBookAttr           role='solution'
 End
 
 
@@ -348,6 +371,9 @@ Style Claim
 	  \addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
 	LabelCounter          claim
+	DocBookTag            para
+	DocBookAttr           role='claim'
+	DocBookItemTag        ""
 End
 
 Input theorems-case.inc
diff --git a/lib/layouts/theorems-ams-chap-bytype.inc b/lib/layouts/theorems-ams-chap-bytype.inc
index e4528f7..faaa2d0 100644
--- a/lib/layouts/theorems-ams-chap-bytype.inc
+++ b/lib/layouts/theorems-ams-chap-bytype.inc
@@ -129,6 +129,8 @@ Style Theorem
 		\addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
 	Requires              amsthm
+	DocBookTag            para
+	DocBookAttr           role='theorem'
 End
 
 
@@ -151,6 +153,8 @@ Style Corollary
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='corollary'
 End
 
 
@@ -173,6 +177,8 @@ Style Lemma
 	  \addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
 	LabelCounter          lemma
+	DocBookTag            para
+	DocBookAttr           role='lemma'
 End
 
 
@@ -195,6 +201,8 @@ Style Proposition
 	  \addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
 	LabelCounter          proposition
+	DocBookTag            para
+	DocBookAttr           role='proposition'
 End
 
 
@@ -217,6 +225,8 @@ Style Conjecture
 	  \addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
 	LabelCounter          conjecture
+	DocBookTag            para
+	DocBookAttr           role='conjecture'
 End
 
 
@@ -239,6 +249,8 @@ Style Fact
 	  \addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
 	LabelCounter          fact
+	DocBookTag            para
+	DocBookAttr           role='fact'
 End
 
 
@@ -268,6 +280,8 @@ Style Definition
 	  \addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
 	LabelCounter          definition
+	DocBookTag            para
+	DocBookAttr           role='definition'
 End
 
 
@@ -291,6 +305,9 @@ Style Example
 	  \addto\captions$$lang{\renewcommand{\examplename}{_(Example)}}
 	EndBabelPreamble
 	LabelCounter          example
+	DocBookWrapperTag     informalexample
+	DocBookTag            para
+	DocBookAttr        ""
 End
 
 
@@ -314,6 +331,8 @@ Style Problem
 	  \addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
 	LabelCounter          problem
+	DocBookTag            para
+	DocBookAttr           role='problem'
 End
 
 
@@ -337,6 +356,8 @@ Style Exercise
 	  \addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
 	LabelCounter          exercise
+	DocBookTag            para
+	DocBookAttr           role='exercise'
 End
 
 
@@ -360,6 +381,8 @@ Style Solution
 		\addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
 	LabelCounter          solution
+	DocBookTag            para
+	DocBookAttr           role='solution'
 End
 
 
@@ -415,6 +438,9 @@ Style Claim
 	  \addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
 	LabelCounter          claim
+	DocBookTag            para
+	DocBookAttr           role='claim'
+	DocBookItemTag        ""
 End
 
 
diff --git a/lib/layouts/theorems-ams-extended-bytype.module b/lib/layouts/theorems-ams-extended-bytype.module
index e031a74..c537def 100644
--- a/lib/layouts/theorems-ams-extended-bytype.module
+++ b/lib/layouts/theorems-ams-extended-bytype.module
@@ -87,6 +87,9 @@ Style Criterion
 	  \addto\captions$$lang{\renewcommand{\criterionname}{_(Criterion)}}
 	EndBabelPreamble
 	LabelCounter          criterion
+	DocBookTag            para
+	DocBookAttr           role='criterion'
+	DocBookItemTag        ""
 End
 
 Style Criterion*
@@ -103,6 +106,9 @@ Style Criterion*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\criterionname}{_(Criterion)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='criterion'
+	DocBookItemTag        ""
 End
 
 
@@ -121,6 +127,9 @@ Style Algorithm
 	  \addto\captions$$lang{\renewcommand{\algorithmname}{_(Algorithm)}}
 	EndBabelPreamble
 	LabelCounter          algorithm
+	DocBookTag            para
+	DocBookAttr           role='algorithm'
+	DocBookItemTag        ""
 End
 
 
@@ -138,6 +147,9 @@ Style Algorithm*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\algorithmname}{_(Algorithm)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='algorithm'
+	DocBookItemTag        ""
 End
 
 
@@ -156,6 +168,9 @@ Style Axiom
 	  \addto\captions$$lang{\renewcommand{\axiomname}{_(Axiom)}}
 	EndBabelPreamble
 	LabelCounter          axiom
+	DocBookTag            para
+	DocBookAttr           role='axiom'
+	DocBookItemTag        ""
 End
 
 
@@ -173,6 +188,9 @@ Style Axiom*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\axiomname}{_(Axiom)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='axiom'
+	DocBookItemTag        ""
 End
 
 
@@ -191,6 +209,9 @@ Style Condition
 	  \addto\captions$$lang{\renewcommand{\conditionname}{_(Condition)}}
 	EndBabelPreamble
 	LabelCounter          condition
+	DocBookTag            para
+	DocBookAttr           role='condition'
+	DocBookItemTag        ""
 End
 
 
@@ -208,6 +229,9 @@ Style Condition*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conditionname}{_(Condition)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='condition'
+	DocBookItemTag        ""
 End
 
 
@@ -226,6 +250,8 @@ Style Note
 	  \addto\captions$$lang{\renewcommand{\notename}{_(Note)}}
 	EndBabelPreamble
 	LabelCounter          note
+	DocBookTag            note
+	DocBookItemTag        para
 End
 
 
@@ -243,6 +269,8 @@ Style Note*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\notename}{_(Note)}}
 	EndBabelPreamble
+	DocBookTag            note
+	DocBookItemTag        para
 End
 
 
@@ -261,6 +289,9 @@ Style Notation
 	  \addto\captions$$lang{\renewcommand{\notationname}{_(Notation)}}
 	EndBabelPreamble
 	LabelCounter          notation
+	DocBookTag            para
+	DocBookAttr           role='notation'
+	DocBookItemTag        ""
 End
 
 
@@ -278,6 +309,9 @@ Style Notation*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\notationname}{_(Notation)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='notation'
+	DocBookItemTag        ""
 End
 
 
@@ -296,6 +330,9 @@ Style Summary
 	  \addto\captions$$lang{\renewcommand{\summaryname}{_(Summary)}}
 	EndBabelPreamble
 	LabelCounter          summary
+	DocBookTag            para
+	DocBookAttr           role='summary'
+	DocBookItemTag        ""
 End
 
 
@@ -313,6 +350,9 @@ Style Summary*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\summaryname}{_(Summary)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='summary'
+	DocBookItemTag        ""
 End
 
 
@@ -331,6 +371,9 @@ Style Acknowledgement
 	  \addto\captions$$lang{\renewcommand{\acknowledgementname}{_(Acknowledgement)}}
 	EndBabelPreamble
 	LabelCounter          acknowledgement
+	DocBookTag            para
+	DocBookAttr           role='acknowledgement'
+	DocBookItemTag        ""
 End
 
 
@@ -348,6 +391,9 @@ Style Acknowledgement*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\acknowledgementname}{_(Acknowledgement)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='acknowledgement'
+	DocBookItemTag        ""
 End
 
 
@@ -366,6 +412,9 @@ Style Conclusion
 	  \addto\captions$$lang{\renewcommand{\conclusionname}{_(Conclusion)}}
 	EndBabelPreamble
 	LabelCounter          conclusion
+	DocBookTag            para
+	DocBookAttr           role='conclusion'
+	DocBookItemTag        ""
 End
 
 
@@ -383,6 +432,9 @@ Style Conclusion*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conclusionname}{_(Conclusion)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='conclusion'
+	DocBookItemTag        ""
 End
 
 
@@ -401,6 +453,9 @@ Style Assumption
 	  \addto\captions$$lang{\renewcommand{\assumptionname}{_(Assumption)}}
 	EndBabelPreamble
 	LabelCounter          assumption
+	DocBookTag            para
+	DocBookAttr           role='assumption'
+	DocBookItemTag        ""
 End
 
 
@@ -418,6 +473,9 @@ Style Assumption*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\assumptionname}{_(Assumption)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='assumption'
+	DocBookItemTag        ""
 End
 
 Style Question
@@ -436,6 +494,9 @@ Style Question
 	  \addto\captions$$lang{\renewcommand{\questionname}{_(Question)}}
 	EndBabelPreamble
 	LabelCounter          question
+	DocBookTag            para
+	DocBookAttr           role='question'
+	DocBookItemTag        ""
 End
 
 Style Question*
@@ -452,6 +513,9 @@ Style Question*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\questionname}{_(Question)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='question'
+	DocBookItemTag        ""
 End
 
 Input theorems-refprefix.inc
diff --git a/lib/layouts/theorems-ams-extended-chap-bytype.module b/lib/layouts/theorems-ams-extended-chap-bytype.module
index 435eb65..7252073 100644
--- a/lib/layouts/theorems-ams-extended-chap-bytype.module
+++ b/lib/layouts/theorems-ams-extended-chap-bytype.module
@@ -105,6 +105,9 @@ Style Criterion
 	  \addto\captions$$lang{\renewcommand{\criterionname}{_(Criterion)}}
 	EndBabelPreamble
 	LabelCounter          criterion
+	DocBookTag            para
+	DocBookAttr           role='criterion'
+	DocBookItemTag        ""
 End
 
 
@@ -122,6 +125,9 @@ Style Criterion*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\criterionname}{_(Criterion)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='criterion'
+	DocBookItemTag        ""
 End
 
 
@@ -144,6 +150,9 @@ Style Algorithm
 	  \addto\captions$$lang{\renewcommand{\algorithmname}{_(Algorithm)}}
 	EndBabelPreamble
 	LabelCounter          algorithm
+	DocBookTag            para
+	DocBookAttr           role='algorithm'
+	DocBookItemTag        ""
 End
 
 
@@ -161,6 +170,9 @@ Style Algorithm*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\algorithmname}{_(Algorithm)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='algorithm'
+	DocBookItemTag        ""
 End
 
 
@@ -183,6 +195,9 @@ Style Axiom
 	  \addto\captions$$lang{\renewcommand{\axiomname}{_(Axiom)}}
 	EndBabelPreamble
 	LabelCounter          axiom
+	DocBookTag            para
+	DocBookAttr           role='axiom'
+	DocBookItemTag        ""
 End
 
 
@@ -200,6 +215,9 @@ Style Axiom*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\axiomname}{_(Axiom)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='axiom'
+	DocBookItemTag        ""
 End
 
 
@@ -222,6 +240,9 @@ Style Condition
 	  \addto\captions$$lang{\renewcommand{\conditionname}{_(Condition)}}
 	EndBabelPreamble
 	LabelCounter          condition
+	DocBookTag            para
+	DocBookAttr           role='condition'
+	DocBookItemTag        ""
 End
 
 
@@ -239,6 +260,9 @@ Style Condition*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conditionname}{_(Condition)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='condition'
+	DocBookItemTag        ""
 End
 
 
@@ -261,6 +285,8 @@ Style Note
 	  \addto\captions$$lang{\renewcommand{\notename}{_(Note)}}
 	EndBabelPreamble
 	LabelCounter          note
+	DocBookTag            note
+	DocBookItemTag        para
 End
 
 
@@ -278,6 +304,8 @@ Style Note*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\notename}{_(Note)}}
 	EndBabelPreamble
+	DocBookTag            note
+	DocBookItemTag        para
 End
 
 
@@ -300,6 +328,9 @@ Style Notation
 	  \addto\captions$$lang{\renewcommand{\notationname}{_(Notation)}}
 	EndBabelPreamble
 	LabelCounter          notation
+	DocBookTag            para
+	DocBookAttr           role='notation'
+	DocBookItemTag        ""
 End
 
 
@@ -317,6 +348,9 @@ Style Notation*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\notationname}{_(Notation)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='notation'
+	DocBookItemTag        ""
 End
 
 
@@ -340,6 +374,9 @@ Style Summary
 	  \addto\captions$$lang{\renewcommand{\summaryname}{_(Summary)}}
 	EndBabelPreamble
 	LabelCounter          summary
+	DocBookTag            para
+	DocBookAttr           role='summary'
+	DocBookItemTag        ""
 End
 
 
@@ -357,6 +394,9 @@ Style Summary*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\summaryname}{_(Summary)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='summary'
+	DocBookItemTag        ""
 End
 
 
@@ -379,6 +419,9 @@ Style Acknowledgement
 	  \addto\captions$$lang{\renewcommand{\acknowledgementname}{_(Acknowledgement)}}
 	EndBabelPreamble
 	LabelCounter          acknowledgement
+	DocBookTag            para
+	DocBookAttr           role='acknowledgement'
+	DocBookItemTag        ""
 End
 
 
@@ -396,6 +439,9 @@ Style Acknowledgement*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\acknowledgementname}{_(Acknowledgement)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='acknowledgement'
+	DocBookItemTag        ""
 End
 
 
@@ -418,6 +464,9 @@ Style Conclusion
 	  \addto\captions$$lang{\renewcommand{\conclusionname}{_(Conclusion)}}
 	EndBabelPreamble
 	LabelCounter          conclusion
+	DocBookTag            para
+	DocBookAttr           role='conclusion'
+	DocBookItemTag        ""
 End
 
 
@@ -435,6 +484,9 @@ Style Conclusion*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conclusionname}{_(Conclusion)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='conclusion'
+	DocBookItemTag        ""
 End
 
 
@@ -457,6 +509,9 @@ Style Assumption
 	  \addto\captions$$lang{\renewcommand{\assumptionname}{_(Assumption)}}
 	EndBabelPreamble
 	LabelCounter          assumption
+	DocBookTag            para
+	DocBookAttr           role='assumption'
+	DocBookItemTag        ""
 End
 
 
@@ -474,6 +529,9 @@ Style Assumption*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\assumptionname}{_(Assumption)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='assumption'
+	DocBookItemTag        ""
 End
 
 Style Question
@@ -496,6 +554,9 @@ Style Question
 	  \addto\captions$$lang{\renewcommand{\questionname}{_(Question)}}
 	EndBabelPreamble
 	LabelCounter          question
+	DocBookTag            para
+	DocBookAttr           role='question'
+	DocBookItemTag        ""
 End
 
 Style Question*
@@ -512,6 +573,9 @@ Style Question*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\questionname}{_(Question)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='question'
+	DocBookItemTag        ""
 End
 
 Input theorems-refprefix.inc
diff --git a/lib/layouts/theorems-ams-extended.module b/lib/layouts/theorems-ams-extended.module
index 0f33a90..f2c4cf0 100644
--- a/lib/layouts/theorems-ams-extended.module
+++ b/lib/layouts/theorems-ams-extended.module
@@ -48,6 +48,9 @@ Style Criterion
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\criterionname}{_(Criterion)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='criterion'
+	DocBookItemTag        ""
 End
 
 Style Criterion*
@@ -64,6 +67,9 @@ Style Criterion*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\criterionname}{_(Criterion)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='criterion'
+	DocBookItemTag        ""
 End
 
 
@@ -82,6 +88,9 @@ Style Algorithm
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\algorithmname}{_(Algorithm)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='algorithm'
+	DocBookItemTag        ""
 End
 
 
@@ -99,6 +108,9 @@ Style Algorithm*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\algorithmname}{_(Algorithm)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='algorithm'
+	DocBookItemTag        ""
 End
 
 
@@ -117,6 +129,9 @@ Style Axiom
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\axiomname}{_(Axiom)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='axiom'
+	DocBookItemTag        ""
 End
 
 
@@ -134,6 +149,9 @@ Style Axiom*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\axiomname}{_(Axiom)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='axiom'
+	DocBookItemTag        ""
 End
 
 
@@ -151,6 +169,9 @@ Style Condition
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conditionname}{_(Condition)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='condition'
+	DocBookItemTag        ""
 End
 
 
@@ -168,6 +189,9 @@ Style Condition*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conditionname}{_(Condition)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='condition'
+	DocBookItemTag        ""
 End
 
 
@@ -185,6 +209,8 @@ Style Note
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\notename}{_(Note)}}
 	EndBabelPreamble
+	DocBookTag            note
+	DocBookItemTag        para
 End
 
 
@@ -202,6 +228,8 @@ Style Note*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\notename}{_(Note)}}
 	EndBabelPreamble
+	DocBookTag            note
+	DocBookItemTag        para
 End
 
 
@@ -219,6 +247,9 @@ Style Notation
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\notationname}{_(Notation)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='notation'
+	DocBookItemTag        ""
 End
 
 
@@ -236,6 +267,9 @@ Style Notation*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\notationname}{_(Notation)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='notation'
+	DocBookItemTag        ""
 End
 
 
@@ -253,6 +287,9 @@ Style Summary
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\summaryname}{_(Summary)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='summary'
+	DocBookItemTag        ""
 End
 
 
@@ -270,6 +307,9 @@ Style Summary*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\summaryname}{_(Summary)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='summary'
+	DocBookItemTag        ""
 End
 
 
@@ -287,6 +327,9 @@ Style Acknowledgement
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\acknowledgementname}{_(Acknowledgement)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='acknowledgement'
+	DocBookItemTag        ""
 End
 
 
@@ -304,6 +347,9 @@ Style Acknowledgement*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\acknowledgementname}{_(Acknowledgement)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='acknowledgement'
+	DocBookItemTag        ""
 End
 
 
@@ -321,6 +367,9 @@ Style Conclusion
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conclusionname}{_(Conclusion)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='conclusion'
+	DocBookItemTag        ""
 End
 
 
@@ -338,6 +387,9 @@ Style Conclusion*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conclusionname}{_(Conclusion)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='conclusion'
+	DocBookItemTag        ""
 End
 
 
@@ -356,6 +408,9 @@ Style Assumption
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\assumptionname}{_(Assumption)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='assumption'
+	DocBookItemTag        ""
 End
 
 
@@ -373,6 +428,9 @@ Style Assumption*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\assumptionname}{_(Assumption)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='assumption'
+	DocBookItemTag        ""
 End
 
 Style Question
@@ -390,6 +448,9 @@ Style Question
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\questionname}{_(Question)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='question'
+	DocBookItemTag        ""
 End
 
 Style Question*
@@ -406,6 +467,9 @@ Style Question*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\questionname}{_(Question)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='question'
+	DocBookItemTag        ""
 End
 
 Input theorems-refprefix.inc
diff --git a/lib/layouts/theorems-ams.inc b/lib/layouts/theorems-ams.inc
index 99fcbf9..44cc806 100644
--- a/lib/layouts/theorems-ams.inc
+++ b/lib/layouts/theorems-ams.inc
@@ -69,6 +69,8 @@ Style Theorem
 	  \addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
 	Requires              amsthm
+	DocBookTag            para
+	DocBookAttr           role='theorem'
 End
 
 
@@ -87,6 +89,8 @@ Style Corollary
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='corollary'
 End
 
 
@@ -105,6 +109,8 @@ Style Lemma
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='lemma'
 End
 
 
@@ -123,6 +129,8 @@ Style Proposition
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='proposition'
 End
 
 
@@ -141,6 +149,8 @@ Style Conjecture
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='conjecture'
 End
 
 
@@ -159,6 +169,8 @@ Style Fact
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='fact'
 End
 
 
@@ -184,6 +196,8 @@ Style Definition
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='definition'
 End
 
 
@@ -201,6 +215,9 @@ Style Example
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\examplename}{_(Example)}}
 	EndBabelPreamble
+	DocBookWrapperTag     informalexample
+	DocBookTag            para
+	DocBookAttr           ""
 End
 
 
@@ -218,6 +235,8 @@ Style Problem
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='problem'
 End
 
 
@@ -235,6 +254,8 @@ Style Exercise
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='exercise'
 End
 
 
@@ -252,6 +273,8 @@ Style Solution
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='solution'
 End
 
 
@@ -297,6 +320,9 @@ Style Claim
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='claim'
+	DocBookItemTag        ""
 End
 
 Input theorems-case.inc
diff --git a/lib/layouts/theorems-bytype.inc b/lib/layouts/theorems-bytype.inc
index a61a4df..a40098b 100644
--- a/lib/layouts/theorems-bytype.inc
+++ b/lib/layouts/theorems-bytype.inc
@@ -66,6 +66,8 @@ Style Theorem
 		\addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
 	Requires              amsthm
+	DocBookTag            para
+	DocBookAttr           role='theorem'
 End
 
 
@@ -84,6 +86,8 @@ Style Corollary
 		\addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
 	LabelCounter          corollary
+	DocBookTag            para
+	DocBookAttr           role='corollary'
 End
 
 
@@ -102,6 +106,8 @@ Style Lemma
 		\addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
 	LabelCounter          lemma
+	DocBookTag            para
+	DocBookAttr           role='lemma'
 End
 
 
@@ -120,6 +126,8 @@ Style Proposition
 		\addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
 	LabelCounter          proposition
+	DocBookTag            para
+	DocBookAttr           role='proposition'
 End
 
 
@@ -138,6 +146,8 @@ Style Conjecture
 		\addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
 	LabelCounter          conjecture
+	DocBookTag            para
+	DocBookAttr           role='conjecture'
 End
 
 
@@ -156,6 +166,8 @@ Style Fact
 		\addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
 	LabelCounter          fact
+	DocBookTag            para
+	DocBookAttr           role='fact'
 End
 
 
@@ -181,6 +193,8 @@ Style Definition
 		\addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
 	LabelCounter          definition  
+	DocBookTag            para
+	DocBookAttr           role='definition'
 End
 
 
@@ -200,6 +214,9 @@ Style Example
 		\addto\captions$$lang{\renewcommand{\examplename}{_(Example)}}
 	EndBabelPreamble
 	LabelCounter          example
+	DocBookWrapperTag     informalexample
+	DocBookTag            para
+	DocBookAttr        ""
 End
 
 
@@ -219,6 +236,8 @@ Style Problem
 		\addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
 	LabelCounter          problem
+	DocBookTag            para
+	DocBookAttr           role='problem'
 End
 
 
@@ -238,6 +257,8 @@ Style Exercise
 		\addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
 	LabelCounter          exercise
+	DocBookTag            para
+	DocBookAttr           role='exercise'
 End
 
 
@@ -257,6 +278,8 @@ Style Solution
 		\addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
 	LabelCounter          solution
+	DocBookTag            para
+	DocBookAttr           role='solution'
 End
 
 
@@ -304,6 +327,9 @@ Style Claim
 		\addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
 	LabelCounter          claim
+	DocBookTag            para
+	DocBookAttr           role='claim'
+	DocBookItemTag        ""
 End
 
 Input theorems-case.inc
diff --git a/lib/layouts/theorems-case.inc b/lib/layouts/theorems-case.inc
index cf85b48..1ee52a3 100644
--- a/lib/layouts/theorems-case.inc
+++ b/lib/layouts/theorems-case.inc
@@ -86,4 +86,6 @@ Style Case
     \addto\captions$$lang{\renewcommand{\casename}{_(Case)}}
   EndBabelPreamble
   RefPrefix OFF
+  DocBookTag            para
+  DocBookAttr           role='cases'
 End
diff --git a/lib/layouts/theorems-proof-std.inc b/lib/layouts/theorems-proof-std.inc
index 89c4173..8ba18cf 100644
--- a/lib/layouts/theorems-proof-std.inc
+++ b/lib/layouts/theorems-proof-std.inc
@@ -18,4 +18,6 @@ Style Proof
 		\fi
 	EndPreamble
 # No LangPreamble or BabelPreamble, since babel knows \proofname already.
+	DocBookTag            para
+	DocBookAttr           role='proof'
 End
diff --git a/lib/layouts/theorems-proof.inc b/lib/layouts/theorems-proof.inc
index 345ba38..949a35e 100644
--- a/lib/layouts/theorems-proof.inc
+++ b/lib/layouts/theorems-proof.inc
@@ -40,5 +40,7 @@ Style Proof
 	LabelFont
 	  Shape               Italic
 	EndFont
+	DocBookTag            para
+	DocBookAttr           role='proof'
 End
 
diff --git a/lib/layouts/theorems-starred.inc b/lib/layouts/theorems-starred.inc
index 4add989..fa02b21 100644
--- a/lib/layouts/theorems-starred.inc
+++ b/lib/layouts/theorems-starred.inc
@@ -67,6 +67,8 @@ Style Theorem*
 	  \addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
 	Requires              amsthm
+	DocBookTag            para
+	DocBookAttr           role='theorem'
 End
 
 
@@ -84,6 +86,8 @@ Style Corollary*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='corollary'
 End
 
 
@@ -101,6 +105,8 @@ Style Lemma*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='lemma'
 End
 
 
@@ -118,6 +124,8 @@ Style Proposition*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='proposition'
 End
 
 
@@ -135,6 +143,8 @@ Style Conjecture*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='conjecture'
 End
 
 
@@ -152,6 +162,8 @@ Style Fact*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='fact'
 End
 
 
@@ -177,6 +189,8 @@ Style Definition*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='definition'
 End
 
 
@@ -194,6 +208,9 @@ Style Example*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\examplename}{_(Example)}}
 	EndBabelPreamble
+	DocBookWrapperTag     informalexample
+	DocBookTag            para
+	DocBookAttr        ""
 End
 
 
@@ -211,6 +228,8 @@ Style Problem*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='problem'
 End
 
 
@@ -228,6 +247,8 @@ Style Exercise*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='exercise'
 End
 
 
@@ -245,6 +266,8 @@ Style Solution*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='solution'
 End
 
 
@@ -270,6 +293,8 @@ Style Remark*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\remarkname}{_(Remark)}}
 	EndBabelPreamble
+	DocBookTag            note
+	DocBookItemTag        para
 End
 
 
@@ -287,5 +312,8 @@ Style Claim*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='claim'
+	DocBookItemTag        ""
 End
 
diff --git a/lib/layouts/theorems-without-preamble.inc b/lib/layouts/theorems-without-preamble.inc
index 80beb8e..43b8c0c 100644
--- a/lib/layouts/theorems-without-preamble.inc
+++ b/lib/layouts/theorems-without-preamble.inc
@@ -72,6 +72,8 @@ Style Theorem
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='theorem'
 End
 
 
@@ -89,6 +91,8 @@ Style Corollary
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='corollary'
 End
 
 
@@ -106,6 +110,8 @@ Style Lemma
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='lemma'
 End
 
 
@@ -123,6 +129,8 @@ Style Proposition
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='proposition'
 End
 
 
@@ -140,6 +148,8 @@ Style Prop
 	LabelFont
 	  Series	Medium
 	EndFont
+	DocBookTag            para
+	DocBookAttr           role='proposition'
 End
 
 
@@ -164,6 +174,8 @@ Style Conjecture
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='conjecture'
 End
 
 
@@ -181,6 +193,8 @@ Style Fact
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='fact'
 End
 
 
@@ -206,6 +220,8 @@ Style Definition
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='definition'
 End
 
 
@@ -224,6 +240,9 @@ Style Example
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\examplename}{_(Example)}}
 	EndBabelPreamble
+	DocBookWrapperTag     informalexample
+	DocBookTag            para
+	DocBookAttr        ""
 End
 
 
@@ -243,6 +262,8 @@ Style Problem
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='problem'
 End
 
 
@@ -276,6 +297,8 @@ Style Prob
 	EndFont
 	AddToToc	thm
 	IsTocCaption	true
+	DocBookTag            para
+	DocBookAttr           role='problem'
 End
 
 
@@ -294,6 +317,8 @@ Style Solution
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='solution'
 End
 
 
@@ -308,6 +333,8 @@ Style Sol
 	  Tooltip	"Label of the corresponding problem"
 	  IsTocCaption true
 	EndArgument
+	DocBookTag            para
+	DocBookAttr           role='solution'
 End
 
 
@@ -326,6 +353,8 @@ Style Exercise
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='exercise'
 End
 
 
@@ -344,6 +373,8 @@ Style Remark
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\remarkname}{_(Remark)}}
 	EndBabelPreamble
+	DocBookTag            note
+	DocBookItemTag        para
 End
 
 
@@ -357,6 +388,9 @@ Style		Claim
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='claim'
+	DocBookItemTag        ""
 End
 
 
@@ -375,6 +409,8 @@ Style Case
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\casename}{_(Case)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='case'
 End
 
 
@@ -393,6 +429,8 @@ Style Property
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\propertyname}{_(Property)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='property'
 End
 
 
@@ -411,6 +449,8 @@ Style Question
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\questionname}{_(Question)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='question'
 End
 
 
@@ -429,5 +469,7 @@ Style Note
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\notename}{_(Note)}}
 	EndBabelPreamble
+	DocBookTag            note
+	DocBookItemTag        para
 End
 
diff --git a/lib/layouts/theorems.inc b/lib/layouts/theorems.inc
index 9017ca6..822ee94 100644
--- a/lib/layouts/theorems.inc
+++ b/lib/layouts/theorems.inc
@@ -69,6 +69,8 @@ Style Theorem
 		\addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
 	Requires              amsthm
+	DocBookTag            para
+	DocBookAttr           role='theorem'
 End
 
 
@@ -87,6 +89,8 @@ Style Corollary
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='corollary'
 End
 
 
@@ -105,6 +109,8 @@ Style Lemma
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='lemma'
 End
 
 
@@ -123,6 +129,8 @@ Style Proposition
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='proposition'
 End
 
 
@@ -141,6 +149,8 @@ Style Conjecture
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='conjecture'
 End
 
 
@@ -159,6 +169,8 @@ Style Fact
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='fact'
 End
 
 
@@ -184,6 +196,8 @@ Style Definition
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='definition'
 End
 
 
@@ -201,6 +215,9 @@ Style Example
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\examplename}{_(Example)}}
 	EndBabelPreamble
+	DocBookWrapperTag     informalexample
+	DocBookTag            para
+	DocBookAttr        ""
 End
 
 
@@ -218,6 +235,8 @@ Style Problem
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='problem'
 End
 
 
@@ -235,6 +254,8 @@ Style Exercise
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='exercise'
 End
 
 
@@ -252,6 +273,8 @@ Style Solution
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='solution'
 End
 
 
@@ -278,6 +301,8 @@ Style Remark
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\remarkname}{_(Remark)}}
 	EndBabelPreamble
+	DocBookTag            note
+	DocBookItemTag        para
 End
 
 
@@ -295,6 +320,9 @@ Style Claim
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
+	DocBookTag            para
+	DocBookAttr           role='claim'
+	DocBookItemTag        ""
 End
 
 Input theorems-case.inc

commit 24ef420148fb3c6eb7377a9adba567b7c506a42d
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 31 01:41:09 2020 +0200

    DocBook: several missing features for Additional.lyx.
    
    Includes: semantic markup (sorry about noun: Additional.lyx uses it to mark menus; there is something better in DocBook, but it looks like the LaTeX equivalent is really for person names), boxes, info layouts.

diff --git a/autotests/export/docbook/Additional_lyxcode.lyx b/autotests/export/docbook/Additional_lyxcode.lyx
new file mode 100644
index 0000000..fe2d428
--- /dev/null
+++ b/autotests/export/docbook/Additional_lyxcode.lyx
@@ -0,0 +1,371 @@
+#LyX 2.4 created this file. For more info see https://www.lyx.org/
+\lyxformat 598
+\begin_document
+\begin_header
+\save_transient_properties true
+\origin unavailable
+\textclass scrbook
+\begin_preamble
+% DO NOT ALTER THIS PREAMBLE!!!
+%
+% This preamble is designed to ensure that the manual prints
+% out as advertised. If you mess with this preamble,
+% parts of the manual may not print out as expected.  If you
+% have problems LaTeXing this file, please contact 
+% the documentation team
+% email: lyx-docs at lists.lyx.org
+
+% the pages of the TOC are numbered roman
+% and a PDF-bookmark for the TOC is added
+\pagenumbering{roman}
+\let\myTOC\tableofcontents
+\renewcommand{\tableofcontents}{%
+ \pdfbookmark[1]{\contentsname}{}
+ \myTOC
+ \cleardoublepage
+ \pagenumbering{arabic}}
+
+% extra space for tables
+\newcommand{\extratablespace}[1]{\noalign{\vskip#1}}
+\end_preamble
+\options bibliography=totoc,index=totoc,BCOR7.5mm,titlepage,captions=tableheading
+\use_default_options false
+\begin_modules
+logicalmkup
+theorems-ams
+theorems-ams-extended
+multicol
+shapepar
+\end_modules
+\maintain_unincluded_children no
+\language english
+\language_package default
+\inputencoding utf8
+\fontencoding auto
+\font_roman "lmodern" "default"
+\font_sans "lmss" "default"
+\font_typewriter "lmtt" "default"
+\font_math "auto" "auto"
+\font_default_family default
+\use_non_tex_fonts false
+\font_sc false
+\font_roman_osf false
+\font_sans_osf false
+\font_typewriter_osf false
+\font_sf_scale 100 100
+\font_tt_scale 100 100
+\use_microtype false
+\use_dash_ligatures true
+\graphics default
+\default_output_format pdf2
+\output_sync 0
+\bibtex_command default
+\index_command default
+\paperfontsize 12
+\spacing single
+\use_hyperref true
+\pdf_title "LyX's Additional Features manual"
+\pdf_author "LyX Team"
+\pdf_subject "LyX's additional features documentation"
+\pdf_keywords "LyX, Documentation, Additional"
+\pdf_bookmarks true
+\pdf_bookmarksnumbered true
+\pdf_bookmarksopen false
+\pdf_bookmarksopenlevel 1
+\pdf_breaklinks false
+\pdf_pdfborder false
+\pdf_colorlinks true
+\pdf_backref false
+\pdf_pdfusetitle false
+\pdf_quoted_options "linkcolor=black, citecolor=black, urlcolor=blue, filecolor=blue, pdfpagelayout=OneColumn, pdfnewwindow=true, pdfstartview=XYZ, plainpages=false"
+\papersize a4
+\use_geometry false
+\use_package amsmath 1
+\use_package amssymb 1
+\use_package cancel 1
+\use_package esint 1
+\use_package mathdots 1
+\use_package mathtools 1
+\use_package mhchem 1
+\use_package stackrel 1
+\use_package stmaryrd 1
+\use_package undertilde 1
+\cite_engine basic
+\cite_engine_type default
+\biblio_style plain
+\use_bibtopic false
+\use_indices false
+\paperorientation portrait
+\suppress_date false
+\justification true
+\use_refstyle 0
+\use_minted 0
+\use_lineno 0
+\notefontcolor #0000ff
+\index Index
+\shortcut idx
+\color #008000
+\end_index
+\secnumdepth 3
+\tocdepth 3
+\paragraph_separation indent
+\paragraph_indentation default
+\is_math_indent 1
+\math_indentation default
+\math_numbering_side default
+\quotes_style english
+\dynamic_quotes 0
+\papercolumns 1
+\papersides 2
+\paperpagestyle headings
+\tablestyle default
+\tracking_changes false
+\output_changes false
+\change_bars false
+\postpone_fragile_content false
+\html_math_output 0
+\html_css_as_file 0
+\html_be_strict true
+\docbook_table_output 0
+\end_header
+
+\begin_body
+
+\begin_layout Title
+Additional \SpecialChar LyX
+ Features
+\end_layout
+
+\begin_layout Subtitle
+Version 2.3.x
+\end_layout
+
+\begin_layout Author
+by the \SpecialChar LyX
+ Team
+\begin_inset Foot
+status collapsed
+
+\begin_layout Plain Layout
+\noindent
+Principal maintainer of this file is
+\noun on
+ Richard Heck
+\noun default
+.
+ If you have comments or error corrections, please send them to the \SpecialChar LyX
+ Documentati
+on mailing list, 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+<lyx-docs at lists.lyx.org>
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+\begin_inset CommandInset toc
+LatexCommand tableofcontents
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Chapter
+\begin_inset CommandInset label
+LatexCommand label
+name "sec:Inserting-TeX-Code"
+
+\end_inset
+
+Inserting \SpecialChar TeX
+ Code into \SpecialChar LyX
+ Documents
+\end_layout
+
+\begin_layout Standard
+Anything you can do in \SpecialChar LaTeX
+ you can do in \SpecialChar LyX
+, for a very simple reason: You can
+ always insert \SpecialChar TeX
+ code into any \SpecialChar LyX
+ document.
+ \SpecialChar LyX
+ cannot, and will never be able to, display every possible \SpecialChar LaTeX
+ construct.
+ If ever you need to insert \SpecialChar LaTeX
+ commands into your \SpecialChar LyX
+ document, you can use the
+ 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+\SpecialChar TeX
+ Code
+\end_layout
+
+\end_inset
+
+ box, which you can insert into your document with 
+\begin_inset Flex Noun
+status collapsed
+
+\begin_layout Plain Layout
+Insert\SpecialChar menuseparator
+
+\family sans
+TeX
+\family default
+ Code
+\end_layout
+
+\end_inset
+
+ or the keyboard shortcut 
+\begin_inset Info
+type  "shortcut"
+arg   "ert-insert"
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Standard
+Here's an example of inserting \SpecialChar LaTeX
+ commands in a \SpecialChar LyX
+ document.
+ The code looks like this:
+\end_layout
+
+\begin_layout LyX-Code
+
+\backslash
+begin{tabular}{ll}
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+begin{minipage}{5cm}
+\begin_inset Newline newline
+\end_inset
+
+This is an example of a minipage environment.
+ You 
+\begin_inset Newline newline
+\end_inset
+
+can put nearly everything in it, even (non-floating) 
+\begin_inset Newline newline
+\end_inset
+
+figures and tables.
+ 
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+end{minipage}
+\begin_inset Newline newline
+\end_inset
+
+&
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+begin{minipage}{5cm}
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+begin{verbatim}
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+begin{minipage}{5cm}
+\begin_inset Newline newline
+\end_inset
+
+This ...
+ 
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+end{minipage}
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+end{verbatim}
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+end{minipage}
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+end{tabular}
+\end_layout
+
+\begin_layout Section
+Cross-References Between Files
+\end_layout
+
+\begin_layout Standard
+\begin_inset Box Shadowbox
+position "t"
+hor_pos "c"
+has_inner_box 1
+inner_pos "t"
+use_parbox 0
+use_makebox 0
+width "100col%"
+special "none"
+height "1in"
+height_special "totalheight"
+thickness "0.4pt"
+separation "3pt"
+shadowsize "4pt"
+framecolor "black"
+backgroundcolor "none"
+status open
+
+\begin_layout Plain Layout
+This section is somewhat out of date.
+ Need to describe default master documents and how children are opened when
+ the master is.
+ [[FIXME]]
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_body
+\end_document
diff --git a/autotests/export/docbook/Additional_lyxcode.xml b/autotests/export/docbook/Additional_lyxcode.xml
new file mode 100644
index 0000000..b677971
--- /dev/null
+++ b/autotests/export/docbook/Additional_lyxcode.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This DocBook file was created by LyX 2.4.0dev
+  See http://www.lyx.org/ for more information -->
+<book xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
+<info>
+<title>Additional LyX Features</title>
+<subtitle>Version 2.3.x</subtitle>
+<author>
+<personname>by the LyX Team<footnote>
+<para>Principal maintainer of this file is<personname> Richard Heck</personname>. If you have comments or error corrections, please send them to the LyX Documentation mailing list, <code><lyx-docs at lists.lyx.org></code>.</para>
+</footnote></personname>
+</author>
+</info>
+<chapter xml:id="sec.Inserting-TeX-Code">
+<title>Inserting TeX Code into LyX Documents</title>
+<para>Anything you can do in LaTeX you can do in LyX, for a very simple reason: You can always insert TeX code into any LyX document. LyX cannot, and will never be able to, display every possible LaTeX construct. If ever you need to insert LaTeX commands into your LyX document, you can use the <code>TeX Code</code> box, which you can insert into your document with <personname>Insert&#x21D2;TeX Code</personname> or the keyboard shortcut <keycap>Ctrl+L</keycap>.</para>
+<para>Here's an example of inserting LaTeX commands in a LyX document. The code looks like this:</para>
+<programlisting language='lyx'>\begin{tabular}{ll}
+\begin{minipage}{5cm}
+This is an example of a minipage environment. You 
+can put nearly everything in it, even (non-floating) 
+figures and tables. 
+\end{minipage}
+&
+\begin{minipage}{5cm}
+\begin{verbatim}
+\begin{minipage}{5cm}
+This ... 
+\end{minipage}
+\end{verbatim}
+\end{minipage}
+\end{tabular}</programlisting>
+<section>
+<title>Cross-References Between Files</title>
+<sidebar role='shadowbox'>
+<para>This section is somewhat out of date. Need to describe default master documents and how children are opened when the master is. [[FIXME]]</para>
+</sidebar>
+</section>
+</chapter>
+</book>
\ No newline at end of file
diff --git a/lib/layouts/logicalmkup.module b/lib/layouts/logicalmkup.module
index bedf6dc..005a3c9 100644
--- a/lib/layouts/logicalmkup.module
+++ b/lib/layouts/logicalmkup.module
@@ -27,6 +27,8 @@ InsetLayout Flex:Noun
 	EndHTMLStyle
 	ResetsFont            true
 	CustomPars            false
+	DocBookTag            personname
+	DocBookTagType        inline
 End
 
 
@@ -42,6 +44,8 @@ InsetLayout Flex:Emph
 	HTMLTag               em
 	ResetsFont            true
 	CustomPars            false
+	DocBookTag            emphasis
+	DocBookTagType        inline
 End
 
 
@@ -60,6 +64,9 @@ InsetLayout Flex:Strong
 	HTMLTag               strong
 	ResetsFont            true
 	CustomPars            false
+	DocBookTag            personname
+	DocBookAttr           role='bold'
+	DocBookTagType        inline
 End
 
 
@@ -79,4 +86,6 @@ InsetLayout Flex:Code
 	ResetsFont            true
 	CustomPars            false
 	Spellcheck            false
+	DocBookTag            code
+	DocBookTagType        inline
 End
diff --git a/lib/layouts/stdinsets.inc b/lib/layouts/stdinsets.inc
index ab15f77..2127440 100644
--- a/lib/layouts/stdinsets.inc
+++ b/lib/layouts/stdinsets.inc
@@ -434,6 +434,8 @@ InsetLayout Box
 	  Size                Small
 	EndFont
 	MultiPar              true
+	DocBookWrapperTag     sidebar
+	DocBookTag            para
 End
 
 InsetLayout Box:Frameless
@@ -441,6 +443,9 @@ InsetLayout Box:Frameless
 	HTMLStyle
 		div.Frameless { margin: 1em; }
 	EndHTMLStyle
+	DocBookWrapperTag     sidebar
+	DocBookTag            para
+	DocBookWrapperAttr    role='frameless'
 End
 
 InsetLayout Box:Shaded
@@ -452,6 +457,9 @@ InsetLayout Box:Shaded
 			padding: 0.5ex;
 		}
 	EndHTMLStyle
+	DocBookWrapperTag     sidebar
+	DocBookTag            para
+	DocBookWrapperAttr    role='shaded'
 End
 
 InsetLayout Box:Boxed
@@ -462,6 +470,9 @@ InsetLayout Box:Boxed
 			padding: 0.5ex;
 		}
 	EndHTMLStyle
+	DocBookWrapperTag     sidebar
+	DocBookTag            para
+	DocBookWrapperAttr    role='boxed'
 End
 
 InsetLayout Box:Framed
@@ -472,6 +483,9 @@ InsetLayout Box:Framed
 			padding: 0.5ex;
 		}
 	EndHTMLStyle
+	DocBookWrapperTag     sidebar
+	DocBookTag            para
+	DocBookWrapperAttr    role='framed'
 End
 
 InsetLayout Box:ovalbox
@@ -482,6 +496,9 @@ InsetLayout Box:ovalbox
 			padding: 0.5ex;
 		}
 	EndHTMLStyle
+	DocBookWrapperTag     sidebar
+	DocBookTag            para
+	DocBookWrapperAttr    role='ovalbox'
 End
 
 InsetLayout Box:Ovalbox
@@ -492,6 +509,9 @@ InsetLayout Box:Ovalbox
 			padding: 0.5ex;
 		}
 	EndHTMLStyle
+	DocBookWrapperTag     sidebar
+	DocBookTag            para
+	DocBookWrapperAttr    role='ovalbox-var'
 End
 
 InsetLayout Box:Shadowbox
@@ -499,6 +519,9 @@ InsetLayout Box:Shadowbox
 	HTMLStyle
 		div.Shadowbox { border: solid gray medium; border-bottom: solid black 1ex; border-right: solid black 1ex; padding: 0.5ex; }
 	EndHTMLStyle
+	DocBookWrapperTag     sidebar
+	DocBookTag            para
+	DocBookWrapperAttr    role='shadowbox'
 End
 
 InsetLayout Box:Doublebox
@@ -509,6 +532,9 @@ InsetLayout Box:Doublebox
 			padding: 0.5ex;
 		}
 	EndHTMLStyle
+	DocBookWrapperTag     sidebar
+	DocBookTag            para
+	DocBookWrapperAttr    role='doublebox'
 End
 
 InsetLayout Float
@@ -609,6 +635,8 @@ InsetLayout Info:menu
 	HTMLStyle
 		span.menu { font-family: sans-serif; }
 	EndHTMLStyle
+	DocBookTag            guimenu
+	DocBookTagType        inline
 End
 
 InsetLayout Info:shortcut
@@ -626,6 +654,10 @@ InsetLayout Info:shortcut
 	HTMLStyle
 		span.shortcut { font-family: sans-serif; }
 	EndHTMLStyle
+	DocBookTagWrapper     keycombo
+	DocBookTagWrapperType inline
+	DocBookTag            keycap
+	DocBookTagType        inline
 End
 
 InsetLayout Info:shortcuts
@@ -643,6 +675,10 @@ InsetLayout Info:shortcuts
 	HTMLStyle
 		span.shortcuts { font-family: sans-serif; }
 	EndHTMLStyle
+	DocBookTagWrapper     keycombo
+	DocBookTagWrapperType inline
+	DocBookTag            keycap
+	DocBookTagType        inline
 End
 
 InsetLayout Caption:Standard
diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp
index c61efe6..db76f53 100644
--- a/src/insets/InsetBox.cpp
+++ b/src/insets/InsetBox.cpp
@@ -717,7 +717,25 @@ int InsetBox::plaintext(odocstringstream & os,
 
 void InsetBox::docbook(XMLStream & xs, OutputParams const & runparams) const
 {
+	if (!getLayout().docbookwrappertag().empty()) {
+		if (!xs.isLastTagCR())
+			xs << xml::CR();
+
+		xs << xml::StartTag(getLayout().docbookwrappertag(), getLayout().docbookwrapperattr());
+		xs << xml::CR();
+	} else {
+		LYXERR0("Assertion failed: box layout " + getLayout().name() + " missing DocBookWrapperTag.");
+	}
+
 	InsetText::docbook(xs, runparams);
+
+	if (!getLayout().docbookwrappertag().empty()) {
+		if (!xs.isLastTagCR())
+			xs << xml::CR();
+
+		xs << xml::EndTag(getLayout().docbookwrappertag());
+		xs << xml::CR();
+	}
 }
 
 
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index ce0d25a..d758a1c 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -110,7 +110,11 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
 		IL_HTMLSTYLE,
 		IL_HTMLPREAMBLE,
 		IL_DOCBOOKTAG,
+		IL_DOCBOOKTAGTYPE,
 		IL_DOCBOOKATTR,
+		IL_DOCBOOKWRAPPERTAG,
+		IL_DOCBOOKWRAPPERTAGTYPE,
+		IL_DOCBOOKWRAPPERATTR,
 		IL_INTOC,
 		IL_ISTOCCAPTION,
 		IL_LABELFONT,
@@ -157,6 +161,10 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
 		{ "display", IL_DISPLAY },
 		{ "docbookattr", IL_DOCBOOKATTR },
 		{ "docbooktag", IL_DOCBOOKTAG },
+		{ "docbooktagtype", IL_DOCBOOKTAGTYPE },
+		{ "docbookwrapperattr", IL_DOCBOOKWRAPPERATTR },
+		{ "docbookwrappertag", IL_DOCBOOKWRAPPERTAG },
+		{ "docbookwrappertagtype", IL_DOCBOOKWRAPPERTAGTYPE },
 		{ "editexternal", IL_EDITEXTERNAL },
 		{ "end", IL_END },
 		{ "fixedwidthpreambleencoding", IL_FIXEDWIDTH_PREAMBLE_ENCODING },
@@ -500,9 +508,21 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
 		case IL_DOCBOOKTAG:
 			lex >> docbooktag_;
 			break;
+		case IL_DOCBOOKTAGTYPE:
+			lex >> docbooktagtype_;
+			break;
 		case IL_DOCBOOKATTR:
 			lex >> docbookattr_;
 			break;
+		case IL_DOCBOOKWRAPPERTAG:
+			lex >> docbookwrappertag_;
+			break;
+		case IL_DOCBOOKWRAPPERTAGTYPE:
+			lex >> docbookwrappertagtype_;
+			break;
+		case IL_DOCBOOKWRAPPERATTR:
+			lex >> docbookwrapperattr_;
+			break;
 		case IL_REQUIRES: {
 			lex.eatLine();
 			vector<string> const req
diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h
index 00e3ba6..f11071f 100644
--- a/src/insets/InsetLayout.h
+++ b/src/insets/InsetLayout.h
@@ -150,8 +150,16 @@ public:
 	///
 	std::string docbooktag() const { return docbooktag_; }
 	///
+	std::string docbooktagtype() const { return docbooktagtype_; }
+	///
 	std::string docbookattr() const { return docbookattr_; }
 	///
+	std::string docbookwrappertag() const { return docbookwrappertag_; }
+	///
+	std::string docbookwrappertagtype() const { return docbookwrappertagtype_; }
+	///
+	std::string docbookwrapperattr() const { return docbookwrapperattr_; }
+	///
 	std::set<std::string> required() const { return required_; }
 	///
 	bool isMultiPar() const { return multipar_; }
@@ -281,8 +289,16 @@ private:
 	///
 	std::string docbooktag_;
 	///
+	std::string docbooktagtype_;
+	///
 	std::string docbookattr_;
 	///
+	std::string docbookwrappertag_;
+	///
+	std::string docbookwrappertagtype_;
+	///
+	std::string docbookwrapperattr_;
+	///
 	std::set<std::string> required_;
 	///
 	bool multipar_;
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index cf3873b..1f17351 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -493,6 +493,10 @@ void makeParagraph(
 		// Listings should not get into their own paragraph.
 		if (!special_case && firstInset->lyxCode() == lyx::LISTINGS_CODE)
 			special_case = true;
+
+		// Boxes cannot get into their own paragraph.
+		if (!special_case && firstInset->lyxCode() == lyx::BOX_CODE)
+			special_case = true;
 	}
 
 	bool const open_par = runparams.docbook_make_pars

commit ad7832b383ce34646dac3fa477c29c807d6b6824
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 31 01:24:28 2020 +0200

    DocBook: implement LyX-Code.
    
    This is quite ugly.

diff --git a/lib/layouts/beamer.layout b/lib/layouts/beamer.layout
index f6d17c3..4438482 100644
--- a/lib/layouts/beamer.layout
+++ b/lib/layouts/beamer.layout
@@ -1408,6 +1408,9 @@ Style LyX-Code
   Font
     Family         Typewriter
   EndFont
+  DocBookTag            programlisting
+  DocBookTagType        paragraph
+  DocBookAttr			language='lyx'
 End
  
 Style NoteItem
diff --git a/lib/layouts/egs.layout b/lib/layouts/egs.layout
index 6ee01ed..0bd4543 100644
--- a/lib/layouts/egs.layout
+++ b/lib/layouts/egs.layout
@@ -734,6 +734,9 @@ Style LyX-Code
 	Font
 	  Family              Typewriter
 	EndFont
+	DocBookTag            programlisting
+    DocBookTagType        paragraph
+	DocBookAttr			  language='lyx'
 End
 
 
diff --git a/lib/layouts/lyxmacros.inc b/lib/layouts/lyxmacros.inc
index 1696ffd..4cf5cf6 100644
--- a/lib/layouts/lyxmacros.inc
+++ b/lib/layouts/lyxmacros.inc
@@ -38,6 +38,9 @@ Style LyX-Code
 	Font
 	  Family              Typewriter
 	EndFont
+	DocBookTag            programlisting
+    DocBookTagType        paragraph
+	DocBookAttr			  language='lyx'
 End
 
 
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index ce631e9..cf3873b 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -534,8 +534,19 @@ void makeEnvironment(Text const &text,
                      OutputParams const &runparams,
                      ParagraphList::const_iterator const & par)
 {
-	// TODO: simplify me!
 	auto const end = text.paragraphs().end();
+	auto nextpar = par;
+	++nextpar;
+
+	// Special cases for listing-like environments provided in layouts. This is quite ad-hoc, but provides a useful
+	// default. This should not be used by too many environments (only LyX-Code right now).
+	// This would be much simpler if LyX-Code was implemented as InsetListings...
+	bool mimicListing = false;
+	bool ignoreFonts = false;
+	if (par->layout().docbooktag() == "programlisting") {
+		mimicListing = true;
+		ignoreFonts = true;
+	}
 
 	// Output the opening tag for this environment, but only if it has not been previously opened (condition
 	// implemented in openParTag).
@@ -547,65 +558,25 @@ void makeEnvironment(Text const &text,
 	if (style.latextype == LATEX_COMMAND) {
 		// Nothing to do (otherwise, infinite loops).
 	} else if (style.latextype == LATEX_ENVIRONMENT) {
-		// Open a wrapper tag if needed.
-		if (style.docbookitemwrappertag() != "NONE")
-			openTag(xs, style.docbookitemwrappertag(), style.docbookitemwrapperattr(), style.docbookitemwrappertagtype());
-
-		// Generate the label, if need be. If it is taken from the text, sep != 0 and corresponds to the first
-		// character after the label.
-		pos_type sep = 0;
-		if (style.labeltype != LABEL_NO_LABEL && style.docbookitemlabeltag() != "NONE") {
-			// At least one condition must be met:
-			//  - this environment is not a list
-			//  - if this is a list, the label must not be manual (i.e. it must be taken from the layout)
-			if (style.latextype != LATEX_LIST_ENVIRONMENT || style.labeltype != LABEL_MANUAL) {
-				// Usual cases: maybe there is something specified at the layout level. Highly unlikely, though.
-				docstring const lbl = par->params().labelString();
+		// Generate the paragraph, if need be.
+		auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(std::distance(text.paragraphs().begin(), par)), 0, false, ignoreFonts);
 
-				if (!lbl.empty()) {
-					openLabelTag(xs, style);
-					xs << lbl;
-					closeLabelTag(xs, style);
-				}
-			} else {
-				// Only variablelist gets here (or similar items defined as an extension in the layout).
-				openLabelTag(xs, style);
-				sep = par->firstWordDocBook(xs, runparams);
-				closeLabelTag(xs, style);
-			}
-		}
-
-		// Maybe the item is completely empty, i.e. if the first word ends at the end of the current paragraph
-		// AND if the next paragraph doesn't have the same depth (if there is such a paragraph).
-		// Common case: there is only the first word on the line, but there is a nested list instead
-		// of more text.
-		bool emptyItem = false;
-		if (sep == par->size()) { // If the separator is already at the end of this paragraph...
-			auto next_par = par;
-			++next_par;
-			if (next_par == text.paragraphs().end()) // There is no next paragraph.
-				emptyItem = true;
-			else // There is a next paragraph: check depth.
-				emptyItem = par->params().depth() >= next_par->params().depth();
-		}
-
-		if (emptyItem) {
-			// Avoid having an empty item, this is not valid DocBook. A single character is enough to force
-			// generation of a full <para>.
-			// TODO: this always worked only by magic...
-			xs << ' ';
-		} else {
-			// Generate the rest of the paragraph, if need be. Open as many inner tags as necessary.
-			auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(std::distance(text.paragraphs().begin(), par)), sep);
+		if (mimicListing) {
 			auto p = pars.begin();
-			while (true) {
+			while (p != pars.end()) {
+				openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(), par->layout().docbookiteminnertagtype());
 				xs << XMLStream::ESCAPE_NONE << *p;
+				closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
 				++p;
-				if (p != pars.end()) {
-					closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
-					openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(), par->layout().docbookiteminnertagtype());
-				} else
-					break;
+
+				if (p != pars.end())
+					xs << xml::CR();
+			}
+		} else {
+			for (auto const & p : pars) {
+				openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(), par->layout().docbookiteminnertagtype());
+				xs << XMLStream::ESCAPE_NONE << p;
+				closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
 			}
 		}
 	} else {
@@ -613,8 +584,6 @@ void makeEnvironment(Text const &text,
 	}
 
 	// Close the environment.
-	auto nextpar = par;
-	++nextpar;
 	closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr); // TODO: switch in layout for par/block?
 }
 

commit 51a91ffe3caaad900e0afd916adb85bec5641401
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 31 00:50:37 2020 +0200

    DocBook: <person> is not valid per se, rather use <personname>.
    
    The cleanest solution would still be <person><personname>, but this ought to be enough. Otherwise, that would imply having two tags for some fonts...

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index c80988b..ce631e9 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -49,7 +49,7 @@ std::string fontToDocBookTag(xml::FontTypes type)
 	case xml::FontTypes::FT_BOLD:
 		return "emphasis";
 	case xml::FontTypes::FT_NOUN:
-		return "person";
+		return "personname";
 	case xml::FontTypes::FT_UBAR:
 	case xml::FontTypes::FT_WAVE:
 	case xml::FontTypes::FT_DBAR:

commit cd6a3e563934480e881e44c5bfc3f9a62e9b9f6c
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 31 00:46:49 2020 +0200

    DocBook: subfigures example is fixed.
    
    Probably thanks to the magic of the previous commits.

diff --git a/autotests/export/docbook/subfigures.xml b/autotests/export/docbook/subfigures.xml
index 4a7c122..622edb8 100644
--- a/autotests/export/docbook/subfigures.xml
+++ b/autotests/export/docbook/subfigures.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- This DocBook file was created by LyX 2.4.0dev
   See http://www.lyx.org/ for more information -->
-<article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.1">
+<article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
 <title>Test document</title>
 <para>Formalgroup with two images: </para>
 <formalgroup>
@@ -10,7 +10,7 @@
 <title>Subfigure a.</title>
 <mediaobject>
 <imageobject>
-<imagedata fileref="C:/Users/Thibaut/Documents/GitHub/Apprentissage_automatique/01_manus_lyx/lyx-logo.png"  />
+<imagedata fileref="D:/LyX/lyx-unstable/autotests/export/docbook/lyx-logo.png"  />
 </imageobject>
 </mediaobject>
 </figure>
@@ -18,7 +18,7 @@
 <title>Subfigure b.</title>
 <mediaobject>
 <imageobject>
-<imagedata fileref="C:/Users/Thibaut/Documents/GitHub/Apprentissage_automatique/01_manus_lyx/lyx-logo.png"  />
+<imagedata fileref="D:/LyX/lyx-unstable/autotests/export/docbook/lyx-logo.png"  />
 </imageobject>
 </mediaobject>
 </figure>
@@ -29,7 +29,7 @@
 <title>Subfigure a.</title>
 <mediaobject>
 <imageobject>
-<imagedata fileref="C:/Users/Thibaut/Documents/GitHub/Apprentissage_automatique/01_manus_lyx/lyx-logo.png"  />
+<imagedata fileref="D:/LyX/lyx-unstable/autotests/export/docbook/lyx-logo.png"  />
 </imageobject>
 </mediaobject>
 </figure>
@@ -37,11 +37,12 @@
 <title>Subfigure b.</title>
 <mediaobject>
 <imageobject>
-<imagedata fileref="C:/Users/Thibaut/Documents/GitHub/Apprentissage_automatique/01_manus_lyx/lyx-logo.png"  />
+<imagedata fileref="D:/LyX/lyx-unstable/autotests/export/docbook/lyx-logo.png"  />
 </imageobject>
 </mediaobject>
 </figure>
 </formalgroup>
+
 <para>Formalgroup with two tables: </para>
 <formalgroup>
 <title>Formalgroup, tables above.</title>
@@ -51,10 +52,12 @@
 <tr>
 <td align='center' valign='top'>a</td>
 <td align='center' valign='top'>b</td>
-</tr><tr>
+</tr>
+<tr>
 <td align='center' valign='top'>c</td>
 <td align='center' valign='top'>d</td>
-</tr></tbody>
+</tr>
+</tbody>
 </table>
 <table>
 <caption>Subtable b.</caption>
@@ -62,7 +65,8 @@
 <tr>
 <td align='center' valign='top'>a</td>
 <td align='center' valign='top'>b</td>
-</tr><tr>
+</tr>
+<tr>
 <td align='center' valign='top'>c</td>
 <td align='center' valign='top'>d</td>
 </tr>
@@ -77,10 +81,12 @@
 <tr>
 <td align='center' valign='top'>a</td>
 <td align='center' valign='top'>b</td>
-</tr><tr>
+</tr>
+<tr>
 <td align='center' valign='top'>c</td>
 <td align='center' valign='top'>d</td>
-</tr></tbody>
+</tr>
+</tbody>
 </table>
 <table>
 <caption>Subtable b.</caption>
@@ -88,11 +94,12 @@
 <tr>
 <td align='center' valign='top'>a</td>
 <td align='center' valign='top'>b</td>
-</tr><tr>
+</tr>
+<tr>
 <td align='center' valign='top'>c</td>
 <td align='center' valign='top'>d</td>
-</tr></tbody>
+</tr>
+</tbody>
 </table>
 </formalgroup>
-
-</article>
+</article>
\ No newline at end of file

commit 378151d17c6e8fce06530aaf5ca478ebbfacf75c
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 31 00:45:19 2020 +0200

    DocBook: new-line behaviour in bibliographies.

diff --git a/autotests/export/docbook/Tufte_Book.xml b/autotests/export/docbook/Tufte_Book.xml
index 4968e25..3289cfd 100644
--- a/autotests/export/docbook/Tufte_Book.xml
+++ b/autotests/export/docbook/Tufte_Book.xml
@@ -34,12 +34,15 @@ Working with Text
 <bibliography>
 <title>References</title>
 <biblioentry xml:id="Bringhurst2005">
-<title>The Elements of Typographic Style</title><edition>3.1</edition><bibliomisc role="type">book</bibliomisc>
+<title>The Elements of Typographic Style</title>
+<edition>3.1</edition>
+<bibliomisc role="type">book</bibliomisc>
 <publisher>
 <publishername>Hartley & Marks</publishername>
 </publisher>
 <pubdate>2005</pubdate>
-<authorgroup><author>
+<authorgroup>
+<author>
 <personname>
 <firstname>Robert</firstname>
 <surname>Bringhurst</surname>
diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
index 7005519..6d2af6c 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -1700,6 +1700,8 @@ docstring authorsToDocBookAuthorGroup(docstring const & authorsString, XMLStream
 
 	// Output the list of authors.
 	xs << xml::StartTag("authorgroup");
+	xs << xml::CR();
+
 	auto it = authors.cbegin();
 	auto en = authors.cend();
 	for (size_t i = 0; it != en; ++it, ++i) {
diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index 05fd23d..bee485e 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -1200,6 +1200,7 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
 					xs << xml::StartTag(toDocBookTag[match[1]]);
 					xs << from_utf8(match[2].str());
 					xs << xml::EndTag(toDocBookTag[match[1]]);
+					xs << xml::CR();
 				}
 			} else {
 				LYXERR0("The BibTeX field " << match[1].str() << " is unknown.");

commit df23a52ea95f329e05a42f181df01245fff4271e
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 31 00:43:02 2020 +0200

    DocBook: support Full Width from Tufte Book.

diff --git a/autotests/export/docbook/Tufte_Book.xml b/autotests/export/docbook/Tufte_Book.xml
index 3fb7f24..4968e25 100644
--- a/autotests/export/docbook/Tufte_Book.xml
+++ b/autotests/export/docbook/Tufte_Book.xml
@@ -3,26 +3,32 @@
   See http://www.lyx.org/ for more information -->
 <book xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
 <info>
-
 <title>Tufte Examples</title>
+<author>
+<personname>Fake Author</personname>
+</author>
 </info>
 <chapter>
-<title>The Features of the Tufte-book Class</title>
+<title>
+The Features of the Tufte-book Class
+</title>
 <para>In this document, it was endeavored to show some of the features of the <emphasis role='sans'>Tufte-book</emphasis> class. In the first chapter, their use is outlined. In the second chapter, their use through a handout that was created in a calculus class is demonstrated.</para>
 <section>
-<title>Working with Text</title>
-<para>One of the most prominent and distinctive features of this style is the extensive use of sidenotes. There is a wide margin to provide ample room for sidenotes and small figures. Any footnotes will automatically be converted to sidenotes.<footnote><para>This is a sidenote that was entered using a <code>footnote</code>.</para>
-</footnote> Alternatively, you can also use the <code>Sidenote</code> inset directly; you'll find it in the <emphasis role='sans'>Insert&#x21D2;Custom Insets</emphasis> menu.This is a sidenote that was entered using a <code>sidenote</code>.</para>
+<title>
+Working with Text
+</title>
+<para>One of the most prominent and distinctive features of this style is the extensive use of sidenotes. There is a wide margin to provide ample room for sidenotes and small figures. Any footnotes will automatically be converted to sidenotes.<footnote>
+<para>This is a sidenote that was entered using a <code>footnote</code>.</para>
+</footnote> Alternatively, you can also use the <code>Sidenote</code> inset directly; you'll find it in the <emphasis role='sans'>Insert&#x21D2;Custom Insets</emphasis> menu.This is a sidenote that was entered using a sidenote.</para>
 <para>If you like to place ancillary information in the margin without the sidenote mark (the superscript number), you can use the <code>Marginnote</code> inset. This is Tufte's margin note. Notice that there isn't a number preceding the note, and there is no number in the main text where this note was written. The normal margin note will work as well, but it will look rather odd.<sidebar role="margin">
-<?dbfo float-type="margin.note"?><sidebar role="margin">This is a normal margin note. Don't use it.</sidebar></sidebar></para>
-<para>Another useful innovation is Tufte's <code>NewThought</code> character style (<emphasis role='sans'>Edit&#x21D2;TextStyle&#x21D2;NewThought</emphasis>). It introduces new thoughts by means of small caps, as demonstrated in this paragraph. </para>
+<?dbfo float-type="margin.note"?>
+<para>This is a normal margin note. Don't use it.</para></sidebar></para>
+<para><emphasis role='newthought'>Another useful</emphasis> innovation is Tufte's <code>NewThought</code> character style (<emphasis role='sans'>Edit&#x21D2;TextStyle&#x21D2;NewThought</emphasis>). It introduces new thoughts by means of small caps, as demonstrated in this paragraph. </para>
 <para>The Tufte document classes include two new character styles and some improvements on existing commands for letterspacing.</para>
-<para>When setting strings of <emphasis role='allcaps'>ALL CAPS</emphasis> or small caps, the letterspacing—that is, the spacing between the letters—should be increased slightly.<biblioref endterm="Bringhurst2005" /> The <emphasis>AllCaps</emphasis> character style (<emphasis role='sans'>Edit&#x21D2;TextStyle&#x21D2;AllCaps</emphasis>) has proper letterspacing for strings of <emphasis role='allcaps'>FULL CAPITAL LETTERS</emphasis>, and the <emphasis>SmallCaps</emphasis> character style (<emphasis role='sans'>Edit&#x21D2;TextStyle&#x21D2;SmallCaps</emphasis>) has letterspacing for small capital letters. These commands will also automatically convert the case of the text to upper- or lowercase, respectively.</para>
+<para>When setting strings of <emphasis role='allcaps'>ALL CAPS</emphasis> or <emphasis role='smallcaps'>small caps</emphasis>, the letterspacing—that is, the spacing between the letters—should be increased slightly.<biblioref endterm="Bringhurst2005" /> The <emphasis>AllCaps</emphasis> character style (<emphasis role='sans'>Edit&#x21D2;TextStyle&#x21D2;AllCaps</emphasis>) has proper letterspacing for strings of <emphasis role='allcaps'>FULL CAPITAL LETTERS</emphasis>, and the <emphasis>SmallCaps</emphasis> character style (<emphasis role='sans'>Edit&#x21D2;TextStyle&#x21D2;SmallCaps</emphasis>) has letterspacing for <emphasis role='smallcaps'>small capital letters</emphasis>. These commands will also automatically convert the case of the text to upper- or lowercase, respectively.</para>
 <para>The normal <emphasis>Small Caps</emphasis> shape has also been redefined to include letterspacing. Its case is left as is, however. This allows one to use both uppercase and lowercase letters: <emphasis role='smallcaps'>The Initial Letters Of The Words In This Sentence Are Capitalized.</emphasis></para>
 <para>Finally, the<emphasis> Full Width</emphasis> paragraph environment provides a paragraph layout that stretches across the main text block and the sidenotes area:</para>
-<Full Width>
-Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.
-</Full Width>
+<para role='fullwidth'>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.</para>
 </section>
 </chapter>
 <bibliography>
diff --git a/lib/layouts/tufte-book.layout b/lib/layouts/tufte-book.layout
index 2b88ca3..e469996 100644
--- a/lib/layouts/tufte-book.layout
+++ b/lib/layouts/tufte-book.layout
@@ -243,6 +243,8 @@ Style Full_Width
 	Align			Block
 	AlignPossible	Block, Left, Right, Center
 	LabelType		No_Label
+	DocBookTag      para
+	DocBookAttr     role='fullwidth'
 End
 
 # this steps the counters

commit cdbc11f1c4325b12daeafba6f138b2ce638d79a6
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 31 00:42:32 2020 +0200

    DocBook: fix margin notes.
    
    They were nested twice in <sidebar>. Also fixes a new line issue.

diff --git a/lib/layouts/stdinsets.inc b/lib/layouts/stdinsets.inc
index 04c464a..ab15f77 100644
--- a/lib/layouts/stdinsets.inc
+++ b/lib/layouts/stdinsets.inc
@@ -44,8 +44,7 @@ InsetLayout Marginal
 	EndHTMLStyle
 	AddToToc              marginalnote
 	IsTocCaption          true
-	DocBookTag            sidebar
-	DocBookAttr           role="margin"
+	DocBookTag            para
 End
 
 InsetLayout Foot
diff --git a/src/insets/InsetMarginal.cpp b/src/insets/InsetMarginal.cpp
index 5d2fb90..3a5296d 100644
--- a/src/insets/InsetMarginal.cpp
+++ b/src/insets/InsetMarginal.cpp
@@ -49,6 +49,7 @@ void InsetMarginal::docbook(XMLStream & xs, OutputParams const & runparams) cons
 	xs << xml::StartTag("sidebar", "role=\"margin\"");
 	xs << xml::CR();
 	xs << XMLStream::ESCAPE_NONE << "<?dbfo float-type=\"margin.note\"?>";
+	xs << xml::CR();
 	InsetText::docbook(xs, runparams);
 	xs << xml::EndTag("sidebar");
 }

commit 8cb5fdfa8124dfd08e64f8fa4084d38e6d5117df
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 31 00:21:12 2020 +0200

    DocBook: new lines around formulae.

diff --git a/autotests/export/docbook/mathml_ns_entities.xml b/autotests/export/docbook/mathml_ns_entities.xml
index 2ee7f39..0c1509e 100644
--- a/autotests/export/docbook/mathml_ns_entities.xml
+++ b/autotests/export/docbook/mathml_ns_entities.xml
@@ -1,21 +1,24 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- This DocBook file was created by LyX 2.4.0dev
   See http://www.lyx.org/ for more information -->
-<article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.1">
+<article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
 <title>Test document</title>
 <para>A formula: 
- <informalequation>
-  <m:math>
-  <m:alt role='tex'>\Vert,\vert</m:alt>
+<informalequation>
+<alt role='tex'>\Vert,\vert</alt>
+ <m:math>
+ 
  <m:mrow>
   <m:mrow><m:mi>&#x2225;</m:mi><m:mo>,</m:mo><m:mi>&#x007C;</m:mi>
   </m:mrow>
  </m:mrow>
-  </m:math>
- </informalequation>A second formula: 
- <informalequation>
-  <m:math>
-  <m:alt role='tex'>\left\Vert \mathbf{a^{T}\,x}\right\Vert _{2}\leq x_{0}</m:alt>
+ </m:math>
+</informalequation>
+A second formula: 
+<informalequation>
+<alt role='tex'>\left\Vert \mathbf{a^{T}\,x}\right\Vert _{2}\leq x_{0}</alt>
+ <m:math>
+ 
  <m:mrow>
   <m:mrow>
    <m:msub>
@@ -45,7 +48,7 @@
    </m:msub>
   </m:mrow>
  </m:mrow>
-  </m:math>
- </informalequation></para>
-
-</article>
+ </m:math>
+</informalequation>
+</para>
+</article>
\ No newline at end of file
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index af30e8e..e7326b6 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -2418,13 +2418,11 @@ void InsetMathHull::docbook(XMLStream & xs, OutputParams const & runparams) cons
 {
 	// Choose the tag around the MathML equation.
 	docstring name;
+	bool doCR = false;
 	if (getType() == hullSimple)
 		name = from_ascii("inlineequation");
 	else {
-		// This is a block equation, always have <informalequation> on its own line.
-		if (!xs.isLastTagCR())
-			xs << xml::CR();
-
+		doCR = true; // This is a block equation, always have <informalequation> on its own line.
 		name = from_ascii("informalequation");
 	}
 
@@ -2439,6 +2437,10 @@ void InsetMathHull::docbook(XMLStream & xs, OutputParams const & runparams) cons
 		}
 	}
 
+	if (doCR)
+		if (!xs.isLastTagCR())
+			xs << xml::CR();
+
 	xs << xml::StartTag(name, attr);
 	xs << xml::CR();
 
@@ -2485,6 +2487,8 @@ void InsetMathHull::docbook(XMLStream & xs, OutputParams const & runparams) cons
 	xs << XMLStream::ESCAPE_NONE << osmath.str();
 	xs << xml::CR();
 	xs << xml::EndTag(name);
+	if (doCR)
+		xs << xml::CR();
 }
 
 

commit 6577bf8d25c1adaeaf39f0a2c14e0cb59cb7fa4b
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 31 00:18:35 2020 +0200

    DocBook: avoid generating fonts for "special cases" like equations.

diff --git a/autotests/export/docbook/lists.xml b/autotests/export/docbook/lists.xml
index 6812230..ce2d970 100644
--- a/autotests/export/docbook/lists.xml
+++ b/autotests/export/docbook/lists.xml
@@ -125,7 +125,7 @@
 <varlistentry>
 <term>LyX:</term>
 <listitem>
-
+<para />
 <variablelist>
 <varlistentry>
 <term>lyx16</term>
diff --git a/autotests/export/docbook/math_in_font.xml b/autotests/export/docbook/math_in_font.xml
index 0758a2e..45bb544 100644
--- a/autotests/export/docbook/math_in_font.xml
+++ b/autotests/export/docbook/math_in_font.xml
@@ -4,7 +4,8 @@
 <article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
 <title>LyX</title>
 <para>Some text before.</para>
-<informalequation><alt role='tex'>\cfrac[l]{A}{B+C}\,,\,\cfrac{A}{B+C}\,,\,\cfrac[r]{A}{B+C}</alt>
+<informalequation>
+<alt role='tex'>\cfrac[l]{A}{B+C}\,,\,\cfrac{A}{B+C}\,,\,\cfrac[r]{A}{B+C}</alt>
  <m:math>
  
  <m:mrow>
@@ -35,6 +36,7 @@
    </m:mfrac>
   </m:mrow>
  </m:mrow>
- </m:math></informalequation><para>Some text after.</para>
-
+ </m:math>
+</informalequation>
+<para>Some text after.</para>
 </article>
\ No newline at end of file
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index b88c381..9dea24b 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3333,7 +3333,8 @@ std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
                                                       OutputParams const & runparams,
                                                       Font const & outerfont,
                                                       pos_type initial,
-                                                      bool is_last_par) const
+                                                      bool is_last_par,
+                                                      bool ignore_fonts) const
 {
 	// Track whether we have opened these tags
 	DocBookFontState fs;
@@ -3362,33 +3363,37 @@ std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
 		// If this is an InsetNewline, generate a new paragraph. Also reset the fonts, so that tags are closed in
 		// this paragraph.
 		if (getInset(i) != nullptr && getInset(i)->lyxCode() == NEWLINE_CODE) {
-			xs->closeFontTags();
+			if (!ignore_fonts)
+				xs->closeFontTags();
 			generatedParagraphs.push_back(os.str());
 			os = odocstringstream();
 			delete xs;
 			xs = new XMLStream(os);
-			font_old = outerfont.fontInfo();
+			if (!ignore_fonts)
+				font_old = outerfont.fontInfo();
 		}
 
-		// Determine which tags should be opened or closed.
+		// Determine which tags should be opened or closed regarding fonts.
 		Font const font = getFont(buf.masterBuffer()->params(), i, outerfont);
-		tie(tagsToOpen, tagsToClose) = computeDocBookFontSwitch(font_old, font, default_family, fs);
+		if (!ignore_fonts) {
+			tie(tagsToOpen, tagsToClose) = computeDocBookFontSwitch(font_old, font, default_family, fs);
 
-		// FIXME XHTML
-		// Other such tags? What about the other text ranges?
+			// FIXME XHTML
+			// Other such tags? What about the other text ranges?
 
-		vector<xml::EndFontTag>::const_iterator cit = tagsToClose.begin();
-		vector<xml::EndFontTag>::const_iterator cen = tagsToClose.end();
-		for (; cit != cen; ++cit)
-			*xs << *cit;
+			vector<xml::EndFontTag>::const_iterator cit = tagsToClose.begin();
+			vector<xml::EndFontTag>::const_iterator cen = tagsToClose.end();
+			for (; cit != cen; ++cit)
+				*xs << *cit;
 
-		vector<xml::FontTag>::const_iterator sit = tagsToOpen.begin();
-		vector<xml::FontTag>::const_iterator sen = tagsToOpen.end();
-		for (; sit != sen; ++sit)
-			*xs << *sit;
+			vector<xml::FontTag>::const_iterator sit = tagsToOpen.begin();
+			vector<xml::FontTag>::const_iterator sen = tagsToOpen.end();
+			for (; sit != sen; ++sit)
+				*xs << *sit;
 
-		tagsToClose.clear();
-		tagsToOpen.clear();
+			tagsToClose.clear();
+			tagsToOpen.clear();
+		}
 
 		if (Inset const * inset = getInset(i)) {
 			if (!runparams.for_toc || inset->isInToc()) {
@@ -3409,7 +3414,8 @@ std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
 	// FIXME, this code is just imported from XHTML
 	// I'm worried about what happens if a branch, say, is itself
 	// wrapped in some font stuff. I think that will not work.
-	xs->closeFontTags();
+	if (!ignore_fonts)
+		xs->closeFontTags();
 
 	// In listings, new lines are very important. Avoid generating one for the last line.
 	if (runparams.docbook_in_listing && !is_last_par)
diff --git a/src/Paragraph.h b/src/Paragraph.h
index 96c19c0..597a10b 100644
--- a/src/Paragraph.h
+++ b/src/Paragraph.h
@@ -214,7 +214,8 @@ public:
 							                   OutputParams const & runparams,
 							                   Font const & outerfont,
 							                   pos_type initial = 0,
-							                   bool is_last_par = false) const;
+							                   bool is_last_par = false,
+							                   bool ignore_fonts = false) const;
 
 	/// \return any material that has had to be deferred until after the
 	/// paragraph has closed.
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 808b4cf..c80988b 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -513,7 +513,7 @@ void makeParagraph(
 	// Open and close tags around each contained paragraph.
 	auto nextpar = par;
 	++nextpar;
-	auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(distance(begin, par)), 0, nextpar == end);
+	auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(distance(begin, par)), 0, nextpar == end, special_case);
 	for (auto & parXML : pars) {
 		if (!std::all_of(parXML.begin(), parXML.end(), ::isspace)) {
 			if (open_par)

commit b41c62c3088efb16b084794a3f06eaab0bfc912b
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 23:56:16 2020 +0200

    DocBook: fix line issues around programlisting.

diff --git a/autotests/export/docbook/listings.xml b/autotests/export/docbook/listings.xml
index e65de60..1ed2694 100644
--- a/autotests/export/docbook/listings.xml
+++ b/autotests/export/docbook/listings.xml
@@ -5,6 +5,5 @@
 <title>Test document</title>
 <para>This is a programlisting: </para>
 <programlisting>First line of programlisting
-Second line of programlisting
-</programlisting>
+Second line of programlisting</programlisting>
 </article>
\ No newline at end of file
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index b4e4bc3..b88c381 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3332,7 +3332,8 @@ std::tuple<vector<xml::FontTag>, vector<xml::EndFontTag>> computeDocBookFontSwit
 std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
                                                       OutputParams const & runparams,
                                                       Font const & outerfont,
-                                                      pos_type initial) const
+                                                      pos_type initial,
+                                                      bool is_last_par) const
 {
 	// Track whether we have opened these tags
 	DocBookFontState fs;
@@ -3409,7 +3410,9 @@ std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
 	// I'm worried about what happens if a branch, say, is itself
 	// wrapped in some font stuff. I think that will not work.
 	xs->closeFontTags();
-	if (runparams.docbook_in_listing)
+
+	// In listings, new lines are very important. Avoid generating one for the last line.
+	if (runparams.docbook_in_listing && !is_last_par)
 		*xs << xml::CR();
 
 	// Finalise the last (and most likely only) paragraph.
diff --git a/src/Paragraph.h b/src/Paragraph.h
index ee31403..96c19c0 100644
--- a/src/Paragraph.h
+++ b/src/Paragraph.h
@@ -213,7 +213,8 @@ public:
 	std::vector<docstring> simpleDocBookOnePar(Buffer const & buf,
 							                   OutputParams const & runparams,
 							                   Font const & outerfont,
-							                   pos_type initial = 0) const;
+							                   pos_type initial = 0,
+							                   bool is_last_par = false) const;
 
 	/// \return any material that has had to be deferred until after the
 	/// paragraph has closed.
diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp
index 848e4ae..93daab4 100644
--- a/src/insets/InsetListings.cpp
+++ b/src/insets/InsetListings.cpp
@@ -485,6 +485,9 @@ void InsetListings::docbook(XMLStream & xs, OutputParams const & rp) const
 {
 	InsetLayout const & il = getLayout();
 
+	if (!xs.isLastTagCR())
+		xs << xml::CR();
+
 	// Forge the attributes.
 	string attrs;
 	if (!il.docbookattr().empty())
@@ -517,6 +520,7 @@ void InsetListings::docbook(XMLStream & xs, OutputParams const & rp) const
 	// Done with the listing.
 	xs.endDivision();
 	xs << xml::EndTag(il.docbooktag());
+	xs << xml::CR();
 }
 
 
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index d672144..808b4cf 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -504,8 +504,6 @@ void makeParagraph(
 	//		or we're not in the last paragraph, anyway.
 	//   (ii) We didn't open it and docbook_in_par is true,
 	//		but we are in the first par, and there is a next par.
-	auto nextpar = par;
-	++nextpar;
 	bool const close_par = open_par && (!runparams.docbook_in_par);
 
 	// Determine if this paragraph has some real content. Things like new pages are not caught
@@ -513,7 +511,9 @@ void makeParagraph(
 	// Thus, remove all spaces (including new lines: \r, \n) before checking for emptiness.
 	// std::all_of allows doing this check without having to copy the string.
 	// Open and close tags around each contained paragraph.
-	auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(distance(begin, par)), 0);
+	auto nextpar = par;
+	++nextpar;
+	auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(distance(begin, par)), 0, nextpar == end);
 	for (auto & parXML : pars) {
 		if (!std::all_of(parXML.begin(), parXML.end(), ::isspace)) {
 			if (open_par)

commit 16d6cb62c93e24a32b1c239ab91107a349d5ce4a
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 23:38:40 2020 +0200

    DocBook: fix font issues when a paragraph has an InsetNewline.

diff --git a/autotests/export/docbook/issue5165.xml b/autotests/export/docbook/issue5165.xml
index 2e24ebc..81d840d 100644
--- a/autotests/export/docbook/issue5165.xml
+++ b/autotests/export/docbook/issue5165.xml
@@ -4,9 +4,10 @@
 <article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
 <info>
 <title>Title</title>
-<author><personname>Author</personname></author>
+<author>
+<personname>Author</personname>
+</author>
 <date>Date</date>
 </info>
 <para>Content</para>
-
 </article>
\ No newline at end of file
diff --git a/autotests/export/docbook/labeling_list_nested.xml b/autotests/export/docbook/labeling_list_nested.xml
index 261605c..4ecb1c6 100644
--- a/autotests/export/docbook/labeling_list_nested.xml
+++ b/autotests/export/docbook/labeling_list_nested.xml
@@ -7,22 +7,19 @@
 <variablelist>
 <varlistentry>
 <term>LyX:</term>
-
 <listitem>
-
+<para />
 <variablelist>
 <varlistentry>
 <term>lyx16</term>
-
 <listitem>
-<para> LyX 1.6 file format (lyx2lyx)</para>
+<para>LyX 1.6 file format (lyx2lyx)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>lyx21</term>
-
 <listitem>
-<para> </para>
+<para />
 </listitem>
 </varlistentry>
 </variablelist>
@@ -30,27 +27,23 @@
 </varlistentry>
 <varlistentry>
 <term>LyX:</term>
-
 <listitem>
-
+<para />
 <variablelist>
 <varlistentry>
 <term>lyx16</term>
-
 <listitem>
-<para> LyX 1.6 file format (lyx2lyx)</para>
+<para>LyX 1.6 file format (lyx2lyx)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>lyx21</term>
-
 <listitem>
-<para> </para>
+<para />
 </listitem>
 </varlistentry>
 </variablelist>
 </listitem>
 </varlistentry>
 </variablelist>
-
 </article>
\ No newline at end of file
diff --git a/autotests/export/docbook/list_depth.xml b/autotests/export/docbook/list_depth.xml
index 3833931..5eaa83c 100644
--- a/autotests/export/docbook/list_depth.xml
+++ b/autotests/export/docbook/list_depth.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- This DocBook file was created by LyX 2.4.0dev
   See http://www.lyx.org/ for more information -->
-<article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.1">
+<article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
 <title>Test document</title>
 <itemizedlist>
 <listitem>
@@ -9,5 +9,4 @@
 <para>Content.</para>
 </listitem>
 </itemizedlist>
-
-</article>
+</article>
\ No newline at end of file
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index aad1ccf..b4e4bc3 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3358,12 +3358,15 @@ std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
 		if (isDeleted(i))
 			continue;
 
-		// If this is an InsetNewline, generate a new paragraph.
+		// If this is an InsetNewline, generate a new paragraph. Also reset the fonts, so that tags are closed in
+		// this paragraph.
 		if (getInset(i) != nullptr && getInset(i)->lyxCode() == NEWLINE_CODE) {
+			xs->closeFontTags();
 			generatedParagraphs.push_back(os.str());
 			os = odocstringstream();
 			delete xs;
 			xs = new XMLStream(os);
+			font_old = outerfont.fontInfo();
 		}
 
 		// Determine which tags should be opened or closed.

commit aff8af737826e7ddc64b737d0d696562bbccbda9
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 23:29:02 2020 +0200

    DocBook: fix issue with fonts.

diff --git a/autotests/export/docbook/issue1732_charstyles-docbook.xml b/autotests/export/docbook/issue1732_charstyles-docbook.xml
index 0ed9b87..fc9bffe 100644
--- a/autotests/export/docbook/issue1732_charstyles-docbook.xml
+++ b/autotests/export/docbook/issue1732_charstyles-docbook.xml
@@ -3,5 +3,4 @@
   See http://www.lyx.org/ for more information -->
 <article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
 <para><emphasis role='bold'>Fett </emphasis><emphasis>hervorgehoben</emphasis> <code>monospace</code><emphasis role='underline'> unterstrichen.</emphasis></para>
-
 </article>
\ No newline at end of file
diff --git a/src/xml.cpp b/src/xml.cpp
index 150f4c5..dd9790f 100644
--- a/src/xml.cpp
+++ b/src/xml.cpp
@@ -208,9 +208,6 @@ bool XMLStream::closeFontTags()
 		if (**curtag != xml::parsep_tag)
 			os_ << (*curtag)->writeEndTag();
 		tag_stack_.pop_back();
-		// this shouldn't happen, since then the font tags
-		// weren't in any other tag.
-		LASSERT(!tag_stack_.empty(), return true);
 		if (tag_stack_.empty())
 			return true;
 		curtag = &tag_stack_.back();

commit 1e383dd6fb505362ce7f605fd0c4a0a181df94fb
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 22:08:01 2020 +0200

    DocBook: fixes in bibliography (missing new line at the end).

diff --git a/autotests/export/docbook/easy.xml b/autotests/export/docbook/easy.xml
index 883c982..e301321 100644
--- a/autotests/export/docbook/easy.xml
+++ b/autotests/export/docbook/easy.xml
@@ -12,8 +12,9 @@
 <para>I am an abstract</para>
 <para>I am also an abstract</para>
 </abstract>
+
 </info>
-<section xml:id="sec.Sec-1-0">
+<section xml:id="sec.Sec-1">
 <title>I am the first section </title>
 <para>I am the first paragraph of the first section. </para>
 <para>I am the second paragraph of the first section. </para>
@@ -50,7 +51,7 @@
 <section>
 <title>I am the second section </title>
 <para>I am the only paragraph of the second section. <link xlink:href="http://example.org">Hyperlink.</link> “Text between quotes.”</para>
-<para>See <xref linkend="sec.Sec-1-0" />.</para>
+<para>See <xref linkend="sec.Sec-1" />.</para>
 </section>
 <section>
 <title>I am the third section and I deal with star sections</title>
diff --git a/autotests/export/docbook/issue_infinite_loop.xml b/autotests/export/docbook/issue_infinite_loop.xml
index d6e55ee..e262ed4 100644
--- a/autotests/export/docbook/issue_infinite_loop.xml
+++ b/autotests/export/docbook/issue_infinite_loop.xml
@@ -5,7 +5,8 @@
 <title>William Shakespeare</title>
 <section>
 <title>Publications</title>
-<bibliography>First Folio. Me. 1623..</bibliography>
 </section>
-
+<bibliography>
+<bibliomixed xml:id='firstref'>First Folio. Me. 1623..</bibliomixed>
+</bibliography>
 </article>
\ No newline at end of file
diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index c03a8e2..05fd23d 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -1411,6 +1411,7 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
 
 	// Footer for bibliography.
 	xs << xml::EndTag("bibliography");
+	xs << xml::CR();
 }
 
 

commit 10f9b8c9a66a763af8d1f71b809f325201e94c57
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 22:05:40 2020 +0200

    DocBook: fixes in lists.
    
    Actually output something when list item is empty. XMLStream discarded the sequence StartTag/EndTag (nothing in between).
    
    New-line behaviour around term in description lists.

diff --git a/autotests/export/docbook/Development.xml b/autotests/export/docbook/Development.xml
index d0bc9a4..9ec891d 100644
--- a/autotests/export/docbook/Development.xml
+++ b/autotests/export/docbook/Development.xml
@@ -6,7 +6,7 @@
 <subtitle>Version 2.3.x</subtitle>
 <section>
 <title>File formats</title>
-<section xml:id="sec.When-is-an-0">
+<section xml:id="sec.When-is-an">
 <title>When is an update of the .lyx file format number needed?</title>
 <para>When you are working on a new feature you may ask yourself whether it needs an update of the .lyx file format number. Whether an update is needed or not is not always obvious. Rule of thumb: </para>
 <blockquote>
@@ -17,30 +17,30 @@
 <varlistentry>
 <term>New&#xA0;document&#xA0;setting</term>
 <listitem>
-<para> Whenever you introduce a new setting that is stored in the document header, a file format update is needed.</para>
+<para>Whenever you introduce a new setting that is stored in the document header, a file format update is needed.</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>Removed&#xA0;document&#xA0;setting</term>
 <listitem>
-<para> If a certain setting becomes obsolete and gets removed, a file format update is needed.</para>
+<para>If a certain setting becomes obsolete and gets removed, a file format update is needed.</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>New&#xA0;valid&#xA0;value&#xA0;for&#xA0;an&#xA0;existing&#xA0;setting,</term>
 <listitem>
-<para> e.&#x2009;g.</para>
+<para>e.&#x2009;g.</para>
 <variablelist>
 <varlistentry>
 <term>Automatically&#xA0;loaded&#xA0;math&#xA0;package</term>
 <listitem>
-<para> The reason for this is that there is no true ERT inset for math formulas: Each command is parsed, and if a user happens to define a local command with the same name as a command that triggers an automatic load of a package, they need to be able to switch off the automatic loading of that package. This switch is stored by the use_package header setting.</para>
+<para>The reason for this is that there is no true ERT inset for math formulas: Each command is parsed, and if a user happens to define a local command with the same name as a command that triggers an automatic load of a package, they need to be able to switch off the automatic loading of that package. This switch is stored by the use_package header setting.</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>New&#xA0;language</term>
 <listitem>
-<para> that is stored in \language. </para>
+<para>that is stored in \language. </para>
 </listitem>
 </varlistentry>
 </variablelist>
@@ -49,49 +49,49 @@
 <varlistentry>
 <term>New&#xA0;inset</term>
 <listitem>
-<para> Of course a new inset requires a file format update.</para>
+<para>Of course a new inset requires a file format update.</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>New&#xA0;style</term>
 <listitem>
-<para> If a new style or inset layout is added to any layout file or module shipped with LyX, then a new file format is needed in the master (development) branch. It is possible to backport new styles to the stable version without a file format change.</para>
+<para>If a new style or inset layout is added to any layout file or module shipped with LyX, then a new file format is needed in the master (development) branch. It is possible to backport new styles to the stable version without a file format change.</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>Removed&#xA0;style</term>
 <listitem>
-<para> If a style or inset layout is removed in any layout file or module shipped with LyX, a new file format is required.</para>
+<para>If a style or inset layout is removed in any layout file or module shipped with LyX, a new file format is required.</para>
 </listitem>
 </varlistentry>
 </variablelist>
 <para>However, <emphasis role='bold'>new</emphasis> layouts and modules do <emphasis role='bold'>not</emphasis> require a file format update (changed 03/16). </para>
 <para>If you are still unsure, please ask on the development list.</para>
-<section xml:id="par.export-test-output-formats-1">
+<section xml:id="par.export-test-output-formats">
 <title>Output formats</title>
 <para>The following output formats are currently tested for each sample document:</para>
 <variablelist>
 <varlistentry>
 <term>LyX:</term>
 <listitem>
-
+<para />
 <variablelist>
 <varlistentry>
 <term>lyx16</term>
 <listitem>
-<para> LyX 1.6 file format (lyx2lyx)</para>
+<para>LyX 1.6 file format (lyx2lyx)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>lyx21</term>
 <listitem>
-<para> LyX 2.1 file format (lyx2lyx)</para>
+<para>LyX 2.1 file format (lyx2lyx)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>xhtml</term>
 <listitem>
-<para> LyXHTML (native LyX HTML export)</para>
+<para>LyXHTML (native LyX HTML export)</para>
 </listitem>
 </varlistentry>
 </variablelist>
@@ -100,54 +100,54 @@
 <varlistentry>
 <term>LyX&#xA0;+&#xA0;LaTeX:</term>
 <listitem>
-
+<para />
 <variablelist>
 <varlistentry>
 <term>dvi</term>
 <listitem>
-<para> DVI (8-bit latex)</para>
+<para>DVI (8-bit latex)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>dvi3_texF</term>
 <listitem>
-<para> DVI (LuaTeX with 8-bit TeX fonts)</para>
+<para>DVI (LuaTeX with 8-bit TeX fonts)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>dvi3_systemF</term>
 <listitem>
-<para> DVI (LuaTeX with Unicode fonts)</para>
+<para>DVI (LuaTeX with Unicode fonts)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>pdf2</term>
 <listitem>
-<para> PDF (pdflatex)</para>
+<para>PDF (pdflatex)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>pdf4_texF</term>
 <listitem>
-<para> PDF (XeTeX with 8-bit TeX fonts)</para>
+<para>PDF (XeTeX with 8-bit TeX fonts)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>pdf4_systemF</term>
 <listitem>
-<para> PDF (XeTeX with Unicode fonts)</para>
+<para>PDF (XeTeX with Unicode fonts)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>pdf5_texF</term>
 <listitem>
-<para> PDF (LuaTeX with 8-bit TeX fonts)</para>
+<para>PDF (LuaTeX with 8-bit TeX fonts)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>pdf5_systemF</term>
 <listitem>
-<para> PDF (LuaTeX with Unicode fonts)</para>
+<para>PDF (LuaTeX with Unicode fonts)</para>
 </listitem>
 </varlistentry>
 </variablelist>
@@ -156,18 +156,18 @@
 <varlistentry>
 <term>LyX&#xA0;+&#xA0;LaTeX&#xA0;+&#xA0;postprocessing:</term>
 <listitem>
-
+<para />
 <variablelist>
 <varlistentry>
 <term>pdf</term>
 <listitem>
-<para> DVI -> PS (dvips) -> PDF (ps2pdf)</para>
+<para>DVI -> PS (dvips) -> PDF (ps2pdf)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>pdf3</term>
 <listitem>
-<para> DVI -> PDF (dvipdfm)</para>
+<para>DVI -> PDF (dvipdfm)</para>
 </listitem>
 </varlistentry>
 </variablelist>
@@ -176,90 +176,90 @@
 <varlistentry>
 <term>not&#xA0;tested:</term>
 <listitem>
-<para> (or only if set as default output format in the document source)</para>
+<para>(or only if set as default output format in the document source)</para>
 <variablelist>
 <varlistentry>
 <term>latex</term>
 <listitem>
-<para> LaTeX (plain)</para>
+<para>LaTeX (plain)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>luatex</term>
 <listitem>
-<para> LaTeX (LuaTeX)</para>
+<para>LaTeX (LuaTeX)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>dviluatex</term>
 <listitem>
-<para> LaTeX (dviluatex)</para>
+<para>LaTeX (dviluatex)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>pdflatex</term>
 <listitem>
-<para> LaTeX (pdflatex)</para>
+<para>LaTeX (pdflatex)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>platex</term>
 <listitem>
-<para> LaTeX (pLaTeX)</para>
+<para>LaTeX (pLaTeX)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>xetex</term>
 <listitem>
-<para> LaTeX (XeTeX) </para>
+<para>LaTeX (XeTeX) </para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>eps3</term>
 <listitem>
-<para> EPS (encapsulated Postscript) (cropped)</para>
+<para>EPS (encapsulated Postscript) (cropped)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>ps</term>
 <listitem>
-<para> DVI -> Postscript (dvips)</para>
+<para>DVI -> Postscript (dvips)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>odf</term>
 <listitem>
-<para> </para>
+<para />
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>text</term>
 <listitem>
-<para> (nor text2, ..., text4)</para>
+<para>(nor text2, ..., text4)</para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>textparagraph</term>
 <listitem>
-<para> </para>
+<para />
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>word</term>
 <listitem>
-<para> </para>
+<para />
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>word2</term>
 <listitem>
-<para> </para>
+<para />
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>wordhtml</term>
 <listitem>
-<para> </para>
+<para />
 </listitem>
 </varlistentry>
 </variablelist>
@@ -269,5 +269,4 @@
 </section>
 </section>
 </section>
-
 </article>
\ No newline at end of file
diff --git a/lib/layouts/beamer.layout b/lib/layouts/beamer.layout
index b316b14..f6d17c3 100644
--- a/lib/layouts/beamer.layout
+++ b/lib/layouts/beamer.layout
@@ -234,6 +234,7 @@ Style Description
   DocBookItemTag        listitem
   DocBookItemInnerTag   para
   DocBookItemLabelTag   term
+  DocBookItemLabelTagType   paragraph
 End
 
 
diff --git a/lib/layouts/egs.layout b/lib/layouts/egs.layout
index 0298b69..6ee01ed 100644
--- a/lib/layouts/egs.layout
+++ b/lib/layouts/egs.layout
@@ -269,6 +269,7 @@ Style Description
 	DocBookItemTag        listitem
 	DocBookItemInnerTag   para
 	DocBookItemLabelTag   term
+	DocBookItemLabelTagType   paragraph
 End
 
 
diff --git a/lib/layouts/hollywood.layout b/lib/layouts/hollywood.layout
index 38767c4..7d10bb9 100644
--- a/lib/layouts/hollywood.layout
+++ b/lib/layouts/hollywood.layout
@@ -142,6 +142,7 @@ Style Description
 	DocBookItemTag        listitem
 	DocBookItemInnerTag   para
 	DocBookItemLabelTag   term
+	DocBookItemLabelTagType   paragraph
 End
 
 
diff --git a/lib/layouts/scrclass.inc b/lib/layouts/scrclass.inc
index 1a41a4d..9524ec0 100644
--- a/lib/layouts/scrclass.inc
+++ b/lib/layouts/scrclass.inc
@@ -69,6 +69,7 @@ Style Labeling
 	DocBookItemTag        listitem
 	DocBookItemInnerTag   para
 	DocBookItemLabelTag   term
+	DocBookItemLabelTagType   paragraph
 End
 
 Input stdsections.inc
diff --git a/lib/layouts/svcommon.inc b/lib/layouts/svcommon.inc
index 57573cc..67ed799 100644
--- a/lib/layouts/svcommon.inc
+++ b/lib/layouts/svcommon.inc
@@ -620,6 +620,7 @@ Style Description
 	DocBookItemTag        listitem
 	DocBookItemInnerTag   para
 	DocBookItemLabelTag   term
+	DocBookItemLabelTagType   paragraph
 End
 
 Style Petit
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index cf76bf4..d672144 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -255,6 +255,25 @@ void closeTag(XMLStream & xs, const std::string & tag, const std::string & tagty
 }
 
 
+void compTag(XMLStream & xs, const std::string & tag, const std::string & attr, const std::string & tagtype)
+{
+	if (tag.empty() || tag == "NONE")
+		return;
+
+	// Special case for <para>: always considered as a paragraph.
+	if (tag == "para" || tagtype == "paragraph" || tagtype == "block") {
+		if (!xs.isLastTagCR())
+			xs << xml::CR();
+		xs << xml::CompTag(tag, attr);
+		xs << xml::CR();
+	} else if (tagtype == "inline") {
+		xs << xml::CompTag(tag, attr);
+	} else {
+		xs.writeError("Unrecognised tag type '" + tagtype + "' for '" + tag + "'");
+	}
+}
+
+
 // Higher-level convenience functions.
 
 void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar)
@@ -692,9 +711,8 @@ ParagraphList::const_iterator makeListEnvironment(Text const &text,
 			}
 		} else {
 			// DocBook doesn't like emptiness.
-			openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(),
+			compTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(),
 			        par->layout().docbookiteminnertagtype());
-			closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
 		}
 
 		// If the next item is deeper, it must go entirely within this item (do it recursively).
diff --git a/src/xml.cpp b/src/xml.cpp
index 557bb01..150f4c5 100644
--- a/src/xml.cpp
+++ b/src/xml.cpp
@@ -651,7 +651,8 @@ docstring xml::cleanID(docstring const & orig)
 	// as both of them would be transformed as "a.b". With this procedure, one will become "a.b" and the other "a.b-1".
 	if (mangle && mangledNames.find(content) != mangledNames.end()) {
 		int & mangleID = tMangleID.localData();
-		content += "-" + convert<docstring>(mangleID);
+		if (mangleID > 0)
+			content += "-" + convert<docstring>(mangleID);
 		mangleID += 1;
 	}
 

commit 132c29e55ee141e3dfac610bed9982136b02424e
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 21:51:40 2020 +0200

    DocBook: fix titles in KOMA Script.

diff --git a/autotests/export/docbook/description_list_nested.xml b/autotests/export/docbook/description_list_nested.xml
index fc50c2c..ec57aaa 100644
--- a/autotests/export/docbook/description_list_nested.xml
+++ b/autotests/export/docbook/description_list_nested.xml
@@ -6,22 +6,19 @@
 <variablelist>
 <varlistentry>
 <term>New&#xA0;valid&#xA0;value&#xA0;for&#xA0;an&#xA0;existing&#xA0;setting,</term>
-
 <listitem>
-<para> e.&#x2009;g.</para>
+<para>e.&#x2009;g.</para>
 <variablelist>
 <varlistentry>
 <term>Automatically&#xA0;loaded&#xA0;math&#xA0;package</term>
-
 <listitem>
-<para> The reason </para>
+<para>The reason </para>
 </listitem>
 </varlistentry>
 <varlistentry>
 <term>New&#xA0;language</term>
-
 <listitem>
-<para> that is stored</para>
+<para>that is stored</para>
 </listitem>
 </varlistentry>
 </variablelist>
@@ -29,11 +26,9 @@
 </varlistentry>
 <varlistentry>
 <term>New&#xA0;inset</term>
-
 <listitem>
-<para> Of course a new inset requires a file format update.</para>
+<para>Of course a new inset requires a file format update.</para>
 </listitem>
 </varlistentry>
 </variablelist>
-
 </article>
\ No newline at end of file
diff --git a/autotests/export/docbook/deutsches_ert.xml b/autotests/export/docbook/deutsches_ert.xml
index 1d9b725..3e12603 100644
--- a/autotests/export/docbook/deutsches_ert.xml
+++ b/autotests/export/docbook/deutsches_ert.xml
@@ -5,12 +5,19 @@
 <info>
 <title>Erweiterte LyX Features</title>
 <subtitle>Version 2.3.x</subtitle>
-<author><personname>vom LyX-Team<footnote>Übersetzung und Bearbeitung: Hartmut<person> Haase (<person>HHa, bis März 2010),Jürgen Spitzmüller (Version 2.3.x, 2017)</person></person></footnote></personname></author>
+<author>
+<personname>vom LyX-Team<footnote>
+<para>Übersetzung und Bearbeitung: Hartmut<person> </person>Haase (<person>HHa</person>, bis März 2010),</para>
+<para>Jürgen Spitzmüller (Version 2.3.x, 2017)</para>
+</footnote></personname>
+</author>
 </info>
 <chapter>
-<chapter>Einleitung</chapter>
-<para>Wählen Sie hierfür <emphasis role='sans'>Dokument&#x21D2;Einstellungen&#x21D2;LaTeX-Vorspann. Dies öffnet ein Editierfenster, in das Sie Ihre bevorzugten Befehle schreiben können.<footnote><para>Das Editierverhalten in diesem Fenster ist spezifisch, also erwarten Sie nicht, dass die LyX<!-- „= -->Tastenkombinationen darin funktionieren.</para>
-</footnote> LyX fügt alles im <emphasis role='sans'>LaTeX-Vorspann-Fenster zu seinem eingebauten Vorspann hinzu. Bevor Sie Ihre eigenen Deklarationen zum Vorspann hinzufügen, sollten Sie prüfen, ob LyX das nicht bereits unterstützt (Erinnern Sie sich, was wir über das Rad noch einmal erfinden sagten?). Außerdem: <emphasis>stellen Sie sicher, dass Ihre Vorspannzeilen richtig sind. LyX prüft das nicht. Wenn der Vorspann fehlerhaft ist, bekommen Sie sehr wahrscheinlich die Fehlermeldung Missing \begin{document}. Sollten Sie diese jemals bekommen, prüfen Sie Ihren Vorspann!. <!-- -- --></emphasis></emphasis></emphasis></para>
+<title>Einleitung</title>
+<para>Wählen Sie hierfür <emphasis role='sans'>Dokument&#x21D2;Einstellungen&#x21D2;LaTeX-Vorspann.</emphasis> Dies öffnet ein Editierfenster, in das Sie Ihre bevorzugten Befehle schreiben können.<footnote>
+<para>Das Editierverhalten in diesem Fenster ist spezifisch, also erwarten Sie nicht, dass die LyX<!-- „= -->
+Tastenkombinationen darin funktionieren.</para>
+</footnote> LyX fügt alles im <emphasis role='sans'>LaTeX-Vorspann</emphasis>-Fenster zu seinem eingebauten Vorspann hinzu. Bevor Sie Ihre eigenen Deklarationen zum Vorspann hinzufügen, sollten Sie prüfen, ob LyX das nicht bereits unterstützt (Erinnern Sie sich, was wir über das Rad noch einmal erfinden sagten?). Außerdem: <emphasis>stellen Sie sicher, dass Ihre Vorspannzeilen richtig sind</emphasis>. LyX prüft das nicht. Wenn der Vorspann fehlerhaft ist, bekommen Sie sehr wahrscheinlich die Fehlermeldung Missing \begin{document}. Sollten Sie diese jemals bekommen, prüfen Sie Ihren Vorspann!. <!-- -- -->
+</para>
 </chapter>
-
 </book>
\ No newline at end of file
diff --git a/lib/layouts/scrartcl.layout b/lib/layouts/scrartcl.layout
index 1b27e89..4f2a8d4 100644
--- a/lib/layouts/scrartcl.layout
+++ b/lib/layouts/scrartcl.layout
@@ -26,7 +26,9 @@ Style Part
 	Font
 	  Size		Larger
 	EndFont
-	DocBookTag            part
+	DocBookTag            title
+	DocBookTagType        paragraph
+	DocBookSectionTag     part
 End
 
 Style Part*
@@ -36,5 +38,7 @@ Style Part*
 	Font
 	  Size		Larger
 	EndFont
-	DocBookTag            part
+	DocBookTag            title
+	DocBookTagType        paragraph
+	DocBookSectionTag     part
 End
diff --git a/lib/layouts/scrbook.layout b/lib/layouts/scrbook.layout
index 60caa1c..01d16ca 100644
--- a/lib/layouts/scrbook.layout
+++ b/lib/layouts/scrbook.layout
@@ -18,7 +18,9 @@ NoStyle Abstract
 Style Chapter
 	LabelString	"\thechapter"
 	TocLevel 0
-	DocBookTag            chapter
+	DocBookTag            title
+	DocBookTagType        paragraph
+	DocBookSectionTag     chapter
 End
 
 
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 2bffb0a..cf76bf4 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -978,6 +978,9 @@ void outputDocBookInfo(
 
 	// End the <info> tag if it was started.
 	if (needInfo) {
+		if (!xs.isLastTagCR())
+			xs << xml::CR();
+
 		xs << xml::EndTag("info");
 		xs << xml::CR();
 		xs.endDivision();

commit 7e6f709f62f488487129d9fcf0dfb48ce0931dc5
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 03:30:56 2020 +0200

    DocBook: bug fixing with wrapper merging.

diff --git a/autotests/export/docbook/bibliography_precooked_aastex.xml b/autotests/export/docbook/bibliography_precooked_aastex.xml
index 70b19af..2ab4a79 100644
--- a/autotests/export/docbook/bibliography_precooked_aastex.xml
+++ b/autotests/export/docbook/bibliography_precooked_aastex.xml
@@ -40,16 +40,15 @@
 <affiliation role="alternate">
 <orgname>Patron, Alonso's Bar and Grill</orgname>
 </affiliation>
-<keyword>
-clusters: globular, peanut—bosons: bozos
-</keyword>
-<!-- Output Error: Tried to close `keywordset' when tag was not open. Tag discarded. -->
-
+</author>
+<keywordset>
+<keyword>clusters: globular, peanut—bosons: bozos</keyword>
+</keywordset>
+<abstract>
 <para>This is a preliminary report on surface photometry of the major fraction of known globular clusters, to see which of them show the signs of a collapsed core. We also explore some diversionary mathematics and recreational tables. </para>
+</abstract>
 
-<!-- Output Error: Closing tag `info' when other tags are open, namely: -->
-<!-- Output Error: author -->
-</author></info>
+</info>
 <section>
 <title>Introduction</title>
 <para>A focal problem today in the dynamics of globular clusters is core collapse. It has been predicted by theory for decades <biblioref endterm="hen61" />, <biblioref endterm="lyn68" />, <biblioref endterm="spi85" />, but observation has been less alert to the phenomenon. For many years the central brightness peak in M15 <biblioref endterm="kin75" />, <biblioref endterm="new78" /> seemed a unique anomaly. Then <biblioref endterm="aur82" /> suggested a central peak in NGC 6397, and a limited photographic survey of ours <biblioref endterm="djo84" /> found three more cases, including NGC 6624, whose sharp center had often been remarked on <biblioref endterm="can78" />. </para>
@@ -1005,11 +1004,8 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
 </inlineequation> of the electronically submitted abstracts for AAS meetings are error-free. </para>
 <acknowledgements>
 <para>We are grateful to V. Barger, T. Han, and R. J. N. Phillips for doing the math in section&#xA0;<xref linkend="bozomath" />. More information on the AASTeX macros package are available at <link xlink:href="http://www.aas.org/publications/aastex">http://www.aas.org/publications/aastex</link> or the <link xlink:href="ftp://www.aas.org/pubs/AAS ftp site">AAS ftp site</link>.</para>
-<application>
-IRAF, AIPS, Astropy, ...
-</application>
-<!-- Output Error: Tried to close `para' when tag was not open. Tag discarded. -->
-
+</acknowledgements>
+<remark role='software'>IRAF, AIPS, Astropy, ...</remark>
 </section>
 <bibliography>
 <bibliomixed xml:id='aur82'>Aurière, M. 1982, <!-- \aap -->
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 19bd1d8..2bffb0a 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -274,8 +274,10 @@ void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar
 	if (prevpar != nullptr) {
 		Layout const & prevlay = prevpar->layout();
 		if (prevlay.docbookwrappertag() != "NONE") {
-			openWrapper = prevlay.docbookwrappertag() == lay.docbookwrappertag()
-			              && !lay.docbookwrappermergewithprevious();
+			if (prevlay.docbookwrappertag() == lay.docbookwrappertag())
+				openWrapper = !lay.docbookwrappermergewithprevious();
+			else
+				openWrapper = true;
 		}
 	}
 
@@ -308,8 +310,10 @@ void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpa
 	if (nextpar != nullptr) {
 		Layout const & nextlay = nextpar->layout();
 		if (nextlay.docbookwrappertag() != "NONE") {
-			closeWrapper = nextlay.docbookwrappertag() == lay.docbookwrappertag()
-			               && !nextlay.docbookwrappermergewithprevious();
+			if (nextlay.docbookwrappertag() == lay.docbookwrappertag())
+				closeWrapper = !nextlay.docbookwrappermergewithprevious();
+			else
+				closeWrapper = true;
 		}
 	}
 
@@ -948,8 +952,7 @@ void outputDocBookInfo(
 		// that mandating a wrapper like <info> would repel users. Thus, generate them first.
 		makeAny(text, buf, xs, runparams, paragraphs.iterator_at(pit));
 	for (auto pit : info.mustBeInInfo)
-		if (info.abstract.find(pit) == info.abstract.end()) // The abstract must be in info, but is dealt with after.
-			makeAny(text, buf, xs, runparams, paragraphs.iterator_at(pit));
+		makeAny(text, buf, xs, runparams, paragraphs.iterator_at(pit));
 
 	// Always output the abstract as the last item of the <info>, as it requires special treatment (especially if
 	// it contains several paragraphs that are empty).

commit 1a1752ecd44f793ada166a203da54b57660eed26
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 03:08:55 2020 +0200

    DocBook: bug fixing in AASTeX layout.
    
    That's mostly generating DocBook tags at an inappropriate place with some metadata, rather than outputting whatever you have at your disposal. Far from satisfying, but good enough for a generic tool (see details in the new TODO). Doesn't trigger assertions. Is valid XML.

diff --git a/autotests/export/docbook/bibliography_precooked_aastex.xml b/autotests/export/docbook/bibliography_precooked_aastex.xml
index 71fe700..70b19af 100644
--- a/autotests/export/docbook/bibliography_precooked_aastex.xml
+++ b/autotests/export/docbook/bibliography_precooked_aastex.xml
@@ -382,9 +382,7 @@ clusters: globular, peanut—bosons: bozos
  </m:mrow>
  </m:math>
 </inlineequation> may be formed from particle four-momenta, gauge-boson polarization vectors or fermion strings with an uncontracted Lorentz index associated with final-state fermions.</para>
-<NoteToEditor>
-Figures 1 and 2 should appear side-by-side in print
-</NoteToEditor>
+<remark role='to-editor'>Figures 1 and 2 should appear side-by-side in print</remark>
 <para>In the chiral representation the <inlineequation>
 <alt role='tex'>\gamma</alt>
  <m:math>
@@ -634,7 +632,6 @@ Figures 1 and 2 should appear side-by-side in print
  </m:mrow>
  </m:math>
 </inlineequation> by </para>
-<MathLetters>
 <informalequation>
 <alt role='tex'>u(p,\lambda)_{\pm} & = & (E\pm\lambda|{\textbf{p}}|)^{1/2}\chi_{\lambda}(p),\\
 v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi_{-\lambda}(p)
@@ -724,9 +721,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
   </m:mtr>
  </m:mtable>
  </m:math>
-</informalequation>
-</MathLetters>
-</section>
+</informalequation></section>
 </section>
 <section>
 <title>Floating material and so forth</title>
@@ -1008,7 +1003,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation> of the electronically submitted abstracts for AAS meetings are error-free. </para>
-<acknowledgement>
+<acknowledgements>
 <para>We are grateful to V. Barger, T. Han, and R. J. N. Phillips for doing the math in section&#xA0;<xref linkend="bozomath" />. More information on the AASTeX macros package are available at <link xlink:href="http://www.aas.org/publications/aastex">http://www.aas.org/publications/aastex</link> or the <link xlink:href="ftp://www.aas.org/pubs/AAS ftp site">AAS ftp site</link>.</para>
 <application>
 IRAF, AIPS, Astropy, ...
@@ -1139,7 +1134,7 @@ IRAF, AIPS, Astropy, ...
  <m:mrow><m:mi>P</m:mi>
  </m:mrow>
  </m:math>
-</inlineequation>a</td>
+</inlineequation><remark role='tablenotemark'>a</remark></td>
 <td align='right' valign='top'> <inlineequation>
 <alt role='tex'>PR_{maj}</alt>
  <m:math>
@@ -1183,7 +1178,7 @@ IRAF, AIPS, Astropy, ...
  <m:mrow><m:mo>&#x398;</m:mo>
  </m:mrow>
  </m:math>
-</inlineequation>b</td>
+</inlineequation><remark role='tablenotemark'>b</remark></td>
 <td align='center' valign='top'>Ref.</td>
 </tr>
 <tr>
@@ -1235,7 +1230,7 @@ IRAF, AIPS, Astropy, ...
 <tr>
 <td align='center' valign='top'> 4 </td>
 <td align='right' valign='top'>32733.8 </td>
-<td align='right' valign='top'>-1.2c</td>
+<td align='right' valign='top'>-1.2<remark role='tablenotemark'>c</remark></td>
 <td align='right' valign='top'>-0.5 </td>
 <td align='right' valign='top'>41 </td>
 <td align='right' valign='top'>54.8 </td>
@@ -1254,7 +1249,7 @@ IRAF, AIPS, Astropy, ...
 <td align='right' valign='top'>-0.4 </td>
 <td align='right' valign='top'>60 </td>
 <td align='right' valign='top'>1.4 </td>
-<td align='right' valign='top'>1.669c</td>
+<td align='right' valign='top'>1.669<remark role='tablenotemark'>c</remark></td>
 <td align='right' valign='top'>1.574 </td>
 <td align='right' valign='top'>2.343 </td>
 <td align='right' valign='top'>8.0 </td>
@@ -1279,23 +1274,13 @@ IRAF, AIPS, Astropy, ...
 </tr>
 </tbody>
 
-<Table note>
-a<!-- }{ -->
-Sample footnote for table&#xA0;<xref linkend="tbl-2" /> that was generated with the LaTeX table environment
-</Table note>
-<Table note>
-b<!-- }{ -->
-Yet another sample footnote for table&#xA0;<xref linkend="tbl-2" />
-</Table note>
-<Table note>
-c<!-- }{ -->
-Another sample footnote for table&#xA0;<xref linkend="tbl-2" />
-</Table note>
-<TableComments>
-We can also attach a long-ish paragraph of explanatory material to a table. Use \tablerefs to append a list of references. The following references were from a different table: I've patched them in here to show how they look, but don't take them too seriously—I certainly have not.
-</TableComments>
-<TableRefs>
-(1) Barbuy, Spite, & Spite 1985; (2) Bond 1980; (3) Carbon et al. 1987; (4) Hobbs & Duncan 1987; (5) Gilroy et al. 1988: (6) Gratton & Ortolani 1986; (7) Gratton & Sneden 1987; (8) Gratton & Sneden (1988); (9) Gratton & Sneden 1991; (10) Kraft et al. 1982; (11) LCL, or Laird, 1990; (12) Leep & Wallerstein 1981; (13) Luck & Bond 1981; (14) Luck & Bond 1985; (15) Magain 1987; (16) Magain 1989; (17) Peterson 1981; (18) Peterson, Kurucz, & Carney 1990; (19) RMB; (20) Schuster & Nissen 1988; (21) Schuster & Nissen 1989b; (22) Spite et al. 1984; (23) Spite & Spite 1986; (24) Hobbs & Thorburn 1991; (25) Hobbs et al. 1991; (26) Olsen 1983.
-</TableRefs>
+<remark role='tablenote'>a<!-- }{ -->
+Sample footnote for table&#xA0;<xref linkend="tbl-2" /> that was generated with the LaTeX table environment</remark>
+<remark role='tablenote'>b<!-- }{ -->
+Yet another sample footnote for table&#xA0;<xref linkend="tbl-2" /></remark>
+<remark role='tablenote'>c<!-- }{ -->
+Another sample footnote for table&#xA0;<xref linkend="tbl-2" /></remark>
+<remark role='tablecomments'>We can also attach a long-ish paragraph of explanatory material to a table. Use \tablerefs to append a list of references. The following references were from a different table: I've patched them in here to show how they look, but don't take them too seriously—I certainly have not.</remark>
+<remark role='tablerefs'>(1) Barbuy, Spite, & Spite 1985; (2) Bond 1980; (3) Carbon et al. 1987; (4) Hobbs & Duncan 1987; (5) Gilroy et al. 1988: (6) Gratton & Ortolani 1986; (7) Gratton & Sneden 1987; (8) Gratton & Sneden (1988); (9) Gratton & Sneden 1991; (10) Kraft et al. 1982; (11) LCL, or Laird, 1990; (12) Leep & Wallerstein 1981; (13) Luck & Bond 1981; (14) Luck & Bond 1985; (15) Magain 1987; (16) Magain 1989; (17) Peterson 1981; (18) Peterson, Kurucz, & Carney 1990; (19) RMB; (20) Schuster & Nissen 1988; (21) Schuster & Nissen 1989b; (22) Spite et al. 1984; (23) Spite & Spite 1986; (24) Hobbs & Thorburn 1991; (25) Hobbs et al. 1991; (26) Olsen 1983.</remark>
 </table>
 </article>
\ No newline at end of file
diff --git a/development/DocBookToDo b/development/DocBookToDo
new file mode 100644
index 0000000..39ca534
--- /dev/null
+++ b/development/DocBookToDo
@@ -0,0 +1,20 @@
+Things specific to layouts
+==========================
+
+AASTeX
+------
+
+No support for table notes. They could be implemented through <footnoteref>, but it becomes a nightmare to ensure xml:id uniqueness (the only ID available here is in the inset; mix it with the table ID?). Anyway, it would require a lot of specific code to make it work, probably not worth the effort right now. 
+
+	Related parts of the layout: 
+		Style "Table note"
+		InsetLayout "Flex:tablenotemark"
+	Alreayd used in the following test: 
+		bibliography_precooked_aastex.lyx
+		
+Notion of MathLetters: a group of equations. No good mapping in DocBook, maybe an informalgroup? To discuss with DocBook TC. 
+TableRefs, TableComments: no mapping in DocBook, not really a way to add these things. To discuss with DocBook TC. 
+
+Clearly, with this kind of template, we're reaching the limits of such a system! Having a really good converter for all these cases would require a lot of very specific code. 
+
+More general: what the heck with appendices? It's not handled in the LyX way (Document > Start Appendix Here), but in a custom way. Making this work would solve some correctness issues with this template. 
\ No newline at end of file
diff --git a/lib/layouts/aastex.layout b/lib/layouts/aastex.layout
index d79cd02..78089a4 100644
--- a/lib/layouts/aastex.layout
+++ b/lib/layouts/aastex.layout
@@ -285,6 +285,11 @@ Style Abstract
 	  Series	Bold
 	  Size		Normal
 	EndFont
+	DocBookAbstract       true
+	DocBookInInfo         always
+	DocBookWrapperTag     abstract
+	DocBookWrapperMergeWithPrevious    true
+	DocBookTag            para
 End
 
 
@@ -335,6 +340,7 @@ Style Keywords
 	  Size		Normal
 	EndFont
 	DocBookTag          keyword
+	DocBookTagType      paragraph
 	DocBookWrapperTag   keywordset
 	DocBookInInfo       always
 End
@@ -359,7 +365,7 @@ Style Acknowledgements
 	  Shape		Italic
 	EndFont
 	DocBookTag            para
-	DocBookWrapperTag     acknowledgement
+	DocBookWrapperTag     acknowledgements
 End
 
 
@@ -432,6 +438,7 @@ Style MathLetters
 	Font
 	  Size		Normal
 	EndFont
+	DocBookTag  NONE
 End
 
 
@@ -495,6 +502,9 @@ Style NoteToEditor
 	  Size		Normal
 	  Shape		Italic
 	EndFont
+	DocBookTag      remark
+	DocBookTagType  paragraph
+	DocBookAttr     role='to-editor'
 End
 
 
@@ -515,6 +525,9 @@ Style TableRefs
 	  Family	Roman
 	  Size		Normal
 	EndFont
+	DocBookTag      remark
+	DocBookTagType  paragraph
+	DocBookAttr     role='tablerefs'
 End
 
 
@@ -535,6 +548,9 @@ Style TableComments
 	  Family	Roman
 	  Size		Normal
 	EndFont
+	DocBookTag      remark
+	DocBookTagType  paragraph
+	DocBookAttr     role='tablecomments'
 End
 
 
@@ -550,6 +566,9 @@ Style "Table note"
 	LabelFont
 	  Color		magenta
 	EndFont
+	DocBookTag      remark
+	DocBookTagType  paragraph
+	DocBookAttr     role='tablenote'
 End
 
 
@@ -572,6 +591,9 @@ InsetLayout "Flex:tablenotemark"
 	  Color		magenta
 	  Size		Small
 	EndFont
+	DocBookTag      remark
+	DocBookTagType  paragraph
+	DocBookAttr     role='tablenotemark'
 End
 
 
diff --git a/lib/layouts/aastex6.layout b/lib/layouts/aastex6.layout
index 03d585e..6935365 100644
--- a/lib/layouts/aastex6.layout
+++ b/lib/layouts/aastex6.layout
@@ -67,8 +67,11 @@ Style Software
 	LabelFont
 	  Shape		Italic
 	EndFont
-	DocBookWrapperTag   para
-	DocBookTag          application
+	DocBookTag      remark
+	DocBookAttr     role='software'
+	# Override what's taken from Keywords, but not really wanted.
+	DocBookWrapperTag   NONE
+	DocBookInInfo       never
 End
 
 # other new commands are mainly for the user preamble
diff --git a/lib/layouts/aastex62.layout b/lib/layouts/aastex62.layout
index 3eb7dcc..1ef8636 100644
--- a/lib/layouts/aastex62.layout
+++ b/lib/layouts/aastex62.layout
@@ -78,8 +78,11 @@ Style Software
 	LabelFont
 		Shape           Italic
 	EndFont
-	DocBookWrapperTag   para
-	DocBookTag          application
+	DocBookTag      remark
+	DocBookAttr     role='software'
+	# Override what's taken from Keywords, but not really wanted.
+	DocBookWrapperTag   NONE
+	DocBookInInfo       never
 End
 
 # other new commands are mainly for the user preamble

commit 71a2e3141ee033385f415ff47d44fb9f042bd256
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 02:34:49 2020 +0200

    DocBook: adapt AASTeX for tag types (new-line behaviour).

diff --git a/autotests/export/docbook/bibliography_precooked_aastex.xml b/autotests/export/docbook/bibliography_precooked_aastex.xml
index fe77b72..71fe700 100644
--- a/autotests/export/docbook/bibliography_precooked_aastex.xml
+++ b/autotests/export/docbook/bibliography_precooked_aastex.xml
@@ -3,25 +3,53 @@
   See http://www.lyx.org/ for more information -->
 <article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
 <info>
-<!-- shouldBeInInfo --><title>Collapsed Cores in Globular Clusters,  Gauge-Boson Couplings, and AASTeX Examples</title>
-<!-- mustBeInInfo --><author><personname>S. Djorgovski and Ivan R. King</personname>
-<affiliation><orgname>Astronomy Department, University of California, Berkeley, CA 94720</orgname></affiliation>
-<affiliation role="alternate"><orgname>Visiting Astronomer Cerro Tololo Inter-American Observatory.CTIO is operated by AURA Inc. under contract to the National Science Foundation.</orgname></affiliation>
-<affiliation role="alternate"><orgname>Society of Fellows, Harvard University.</orgname></affiliation>
-<affiliation role="alternate"><orgname>present address: Center for Astrophysics60 Garden Street, Cambridge, MA 02138</orgname></affiliation></author>
-<author><personname>C. D. Biemesderfer</personname>
-<affiliation><orgname>National Optical Astronomy Observatories, Tucson, AZ 85719</orgname></affiliation>
-<affiliation role="alternate"><orgname>Visiting Programmer, Space Telescope Science Institute</orgname></affiliation>
-<affiliation role="alternate"><orgname>Patron, Alonso's Bar and Grill</orgname></affiliation>
-<email>aastex-help at aas.org</email></author>
-<author><personname>R. J. Hanisch</personname>
-<affiliation><orgname>Space Telescope Science Institute, Baltimore, MD 21218</orgname></affiliation>
-<affiliation role="alternate"><orgname>Patron, Alonso's Bar and Grill</orgname></affiliation></author>
-<keywordset><keyword>clusters: globular, peanut—bosons: bozos</keyword></keywordset>
-<!-- /info --><!-- abs --><abstract><para>
+<title>Collapsed Cores in Globular Clusters,  Gauge-Boson Couplings, and AASTeX Examples</title>
+<author>
+<personname>S. Djorgovski and Ivan R. King</personname>
+<affiliation>
+<orgname>Astronomy Department, University of California, Berkeley, CA 94720</orgname>
+</affiliation>
+<affiliation role="alternate">
+<orgname>Visiting Astronomer Cerro Tololo Inter-American Observatory.CTIO is operated by AURA Inc. under contract to the National Science Foundation.</orgname>
+</affiliation>
+<affiliation role="alternate">
+<orgname>Society of Fellows, Harvard University.</orgname>
+</affiliation>
+<affiliation role="alternate">
+<orgname>present address: Center for Astrophysics60 Garden Street, Cambridge, MA 02138</orgname>
+</affiliation>
+</author>
+<author>
+<personname>C. D. Biemesderfer</personname>
+<affiliation>
+<orgname>National Optical Astronomy Observatories, Tucson, AZ 85719</orgname>
+</affiliation>
+<affiliation role="alternate">
+<orgname>Visiting Programmer, Space Telescope Science Institute</orgname>
+</affiliation>
+<affiliation role="alternate">
+<orgname>Patron, Alonso's Bar and Grill</orgname>
+</affiliation>
+<email>aastex-help at aas.org</email>
+</author>
+<author>
+<personname>R. J. Hanisch</personname>
+<affiliation>
+<orgname>Space Telescope Science Institute, Baltimore, MD 21218</orgname>
+</affiliation>
+<affiliation role="alternate">
+<orgname>Patron, Alonso's Bar and Grill</orgname>
+</affiliation>
+<keyword>
+clusters: globular, peanut—bosons: bozos
+</keyword>
+<!-- Output Error: Tried to close `keywordset' when tag was not open. Tag discarded. -->
+
 <para>This is a preliminary report on surface photometry of the major fraction of known globular clusters, to see which of them show the signs of a collapsed core. We also explore some diversionary mathematics and recreational tables. </para>
-</para></abstract>
-<!-- 15 --><!-- /abs --></info>
+
+<!-- Output Error: Closing tag `info' when other tags are open, namely: -->
+<!-- Output Error: author -->
+</author></info>
 <section>
 <title>Introduction</title>
 <para>A focal problem today in the dynamics of globular clusters is core collapse. It has been predicted by theory for decades <biblioref endterm="hen61" />, <biblioref endterm="lyn68" />, <biblioref endterm="spi85" />, but observation has been less alert to the phenomenon. For many years the central brightness peak in M15 <biblioref endterm="kin75" />, <biblioref endterm="new78" /> seemed a unique anomaly. Then <biblioref endterm="aur82" /> suggested a central peak in NGC 6397, and a limited photographic survey of ours <biblioref endterm="djo84" /> found three more cases, including NGC 6624, whose sharp center had often been remarked on <biblioref endterm="can78" />. </para>
@@ -107,7 +135,8 @@
 </section>
 <section>
 <title>Helicity Amplitudes</title>
-<para>It has been realized that helicity amplitudes provide a convenient means for Feynman diagram<footnote><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><para>Footnotes can be inserted like this.</para>
+<para>It has been realized that helicity amplitudes provide a convenient means for Feynman diagram<footnote>
+<para>Footnotes can be inserted like this.</para>
 </footnote> evaluations. These amplitude-level techniques are particularly convenient for calculations involving many Feynman diagrams, where the usual trace techniques for the amplitude squared becomes unwieldy. Our calculations use the helicity techniques developed by other authors <biblioref endterm="hag86" />; we briefly summarize below.</para>
 <section>
 <title>Formalism</title>
@@ -133,7 +162,8 @@
   </m:mrow>
  </m:mrow>
  </m:math>
-</inlineequation> collisions can be expressed in terms of fermion strings of the form <informalequation>
+</inlineequation> collisions can be expressed in terms of fermion strings of the form 
+<informalequation>
 <alt role='tex'>\bar{v}(p_{2},\sigma_{2})P_{-\tau}\hat{a}_{1}\hat{a}_{2}\cdots\hat{a}_{n}u(p_{1},\sigma_{1}),</alt>
  <m:math>
  
@@ -352,7 +382,9 @@
  </m:mrow>
  </m:math>
 </inlineequation> may be formed from particle four-momenta, gauge-boson polarization vectors or fermion strings with an uncontracted Lorentz index associated with final-state fermions.</para>
-<NoteToEditor>Figures 1 and 2 should appear side-by-side in print</NoteToEditor>
+<NoteToEditor>
+Figures 1 and 2 should appear side-by-side in print
+</NoteToEditor>
 <para>In the chiral representation the <inlineequation>
 <alt role='tex'>\gamma</alt>
  <m:math>
@@ -376,7 +408,8 @@
  <m:mrow><m:mi>&#x3C3;</m:mi>
  </m:mrow>
  </m:math>
-</inlineequation> and the unit matrix 1 as <informalequation>
+</inlineequation> and the unit matrix 1 as 
+<informalequation>
 <alt role='tex'>\gamma^{\mu} & = & \left(\begin{array}{cc}
 0 & \sigma_{+}^{\mu}\\
 \sigma_{-}^{\mu} & 0
@@ -486,7 +519,8 @@
   </m:mtr>
  </m:mtable>
  </m:math>
-</informalequation> giving <informalequation>
+</informalequation> giving 
+<informalequation>
 <alt role='tex'>\hat{a}=\left(\begin{array}{cc}
 0 & (\hat{a})_{+}\\
 (\hat{a})_{-} & 0
@@ -564,11 +598,13 @@
   </m:mrow>
  </m:mrow>
  </m:math>
-</informalequation> The spinors are expressed in terms of two-component Weyl spinors as <informalequation>
+</informalequation> The spinors are expressed in terms of two-component Weyl spinors as 
+<informalequation>
 <alt role='tex'>u=\left(\begin{array}{c}
 (u)_{-}\\
 (u)_{+}
-\end{array}\right),v={\textbf{(}}\vdag_{+}{\textbf{,}}\vdag_{-}{\textbf{)}}.</alt>MathML export failed. Please report this as a bug.
+\end{array}\right),v={\textbf{(}}\vdag_{+}{\textbf{,}}\vdag_{-}{\textbf{)}}.</alt>
+<mathphrase>MathML export failed. Please report this as a bug.</mathphrase>
 </informalequation></para>
 <para>The Weyl spinors are given in terms of helicity eigenstates <inlineequation>
 <alt role='tex'>\chi_{\lambda}(p)</alt>
@@ -694,7 +730,8 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
 </section>
 <section>
 <title>Floating material and so forth</title>
-<para>Consider a task that computes profile parameters for a modified Lorentzian of the form <informalequation>
+<para>Consider a task that computes profile parameters for a modified Lorentzian of the form 
+<informalequation>
 <alt role='tex'>I=\frac{1}{1+d_{1}^{P(1+d_{2})}}</alt>
  <m:math>
  
@@ -732,7 +769,8 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
   </m:mrow>
  </m:mrow>
  </m:math>
-</informalequation> where <informalequation>
+</informalequation> where 
+<informalequation>
 <alt role='tex'>d_{1}=\sqrt{\left(\begin{array}{c}
 \frac{x_{1}}{R_{maj}}\end{array}\right)^{2}+\left(\begin{array}{c}
 \frac{y_{1}}{R_{min}}\end{array}\right)^{2}}</alt>
@@ -817,11 +855,14 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
   </m:mrow>
  </m:mrow>
  </m:math>
-</informalequation><informalequation>
+</informalequation>
+<informalequation>
 <alt role='tex'>d_{2}=\sqrt{\left(\begin{array}{c}
 \frac{x_{1}}{PR_{maj}}\end{array}\right)^{2}+\left(\begin{array}{c}
-\case{y_{1}}{PR_{min}}\end{array}\right)^{2}}</alt>MathML export failed. Please report this as a bug.
-</informalequation><informalequation>
+\case{y_{1}}{PR_{min}}\end{array}\right)^{2}}</alt>
+<mathphrase>MathML export failed. Please report this as a bug.</mathphrase>
+</informalequation>
+<informalequation>
 <alt role='tex'>x_{1}=(x-x_{0})\cos\Theta+(y-y_{0})\sin\Theta</alt>
  <m:math>
  
@@ -858,7 +899,8 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
   </m:mrow>
  </m:mrow>
  </m:math>
-</informalequation><informalequation>
+</informalequation>
+<informalequation>
 <alt role='tex'>y_{1}=-(x-x_{0})\sin\Theta+(y-y_{0})\cos\Theta</alt>
  <m:math>
  
@@ -951,7 +993,8 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
   </m:msub>
  </m:mrow>
  </m:math>
-</inlineequation>, but the assumption is that the alternate results should be less than 90° out of phase with previous values. We have no observations of <!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><!-- \ion{Ca}{2} -->. Roughly <inlineequation>
+</inlineequation>, but the assumption is that the alternate results should be less than 90° out of phase with previous values. We have no observations of <!-- \ion{Ca}{2} -->
+. Roughly <inlineequation>
 <alt role='tex'>\nicefrac{4}{5}</alt>
  <m:math>
  
@@ -965,33 +1008,49 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation> of the electronically submitted abstracts for AAS meetings are error-free. </para>
-<acknowledgement><para>We are grateful to V. Barger, T. Han, and R. J. N. Phillips for doing the math in section&#xA0;<xref linkend="bozomath" />. More information on the AASTeX macros package are available at <link xlink:href="http://www.aas.org/publications/aastex"><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->http://www.aas.org/publications/aastex</link> or the <link xlink:href="ftp://www.aas.org/pubs/AAS ftp site">AAS ftp site</link>.</para>
-<application>IRAF, AIPS, Astropy, ...</application><!-- Output Error: Tried to close `para' when tag was not open. Tag discarded. -->
+<acknowledgement>
+<para>We are grateful to V. Barger, T. Han, and R. J. N. Phillips for doing the math in section&#xA0;<xref linkend="bozomath" />. More information on the AASTeX macros package are available at <link xlink:href="http://www.aas.org/publications/aastex">http://www.aas.org/publications/aastex</link> or the <link xlink:href="ftp://www.aas.org/pubs/AAS ftp site">AAS ftp site</link>.</para>
+<application>
+IRAF, AIPS, Astropy, ...
+</application>
+<!-- Output Error: Tried to close `para' when tag was not open. Tag discarded. -->
 
+</section>
 <bibliography>
-<bibliomixed xml:id='aur82'>Aurière, M. 1982, <!-- \aap -->, 109, 301 </bibliomixed>
-<bibliomixed xml:id='can78'>Canizares, C. R., Grindlay, J. E., Hiltner, W. A., Liller, W., and McClintock, J. E. 1978, <!-- \apj -->, 224, 39 </bibliomixed>
-<bibliomixed xml:id='djo84'>Djorgovski, S., and King, I. R. 1984, <!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><!-- \apjl -->, 277, L49 </bibliomixed>
+<bibliomixed xml:id='aur82'>Aurière, M. 1982, <!-- \aap -->
+, 109, 301 </bibliomixed>
+<bibliomixed xml:id='can78'>Canizares, C. R., Grindlay, J. E., Hiltner, W. A., Liller, W., and McClintock, J. E. 1978, <!-- \apj -->
+, 224, 39 </bibliomixed>
+<bibliomixed xml:id='djo84'>Djorgovski, S., and King, I. R. 1984, <!-- \apjl -->
+, 277, L49 </bibliomixed>
 <bibliomixed xml:id='hag86'>Hagiwara, K., and Zeppenfeld, D. 1986, Nucl.Phys., 274, 1 </bibliomixed>
-<bibliomixed xml:id='har84'>Harris, W. E., and van den Bergh, S. 1984, <!-- \aj -->, 89, 1816 </bibliomixed>
+<bibliomixed xml:id='har84'>Harris, W. E., and van den Bergh, S. 1984, <!-- \aj -->
+, 89, 1816 </bibliomixed>
 <bibliomixed xml:id='hen61'>Hénon, M. 1961, Ann.d'Ap., 24, 369 </bibliomixed>
-<bibliomixed xml:id='kin66'>King, I. R. 1966, <!-- \aj -->, 71, 276 </bibliomixed>
+<bibliomixed xml:id='kin66'>King, I. R. 1966, <!-- \aj -->
+, 71, 276 </bibliomixed>
 <bibliomixed xml:id='kin75'>King, I. R. 1975, Dynamics of Stellar Systems, A. Hayli, Dordrecht: Reidel, 1975, 99 </bibliomixed>
-<bibliomixed xml:id='kin68'>King, I. R., Hedemann, E., Hodge, S. M., and White, R. E. 1968, <!-- \aj -->, 73, 456 </bibliomixed>
-<bibliomixed xml:id='kro84'>Kron, G. E., Hewitt, A. V., and Wasserman, L. H. 1984, <!-- \pasp -->, 96, 198 </bibliomixed>
-<bibliomixed xml:id='lyn68'>Lynden-Bell, D., and Wood, R. 1968, <!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><!-- \mnras -->, 138, 495 </bibliomixed>
-<bibliomixed xml:id='new78'>Newell, E. B., and O'Neil, E. J. 1978, <!-- \apjs -->, 37, 27 </bibliomixed>
-<bibliomixed xml:id='ort85'>Ortolani, S., Rosino, L., and Sandage, A. 1985, <!-- \aj -->, 90, 473 </bibliomixed>
-<bibliomixed xml:id='pet76'>Peterson, C. J. 1976, <!-- \aj -->, 81, 617 </bibliomixed>
+<bibliomixed xml:id='kin68'>King, I. R., Hedemann, E., Hodge, S. M., and White, R. E. 1968, <!-- \aj -->
+, 73, 456 </bibliomixed>
+<bibliomixed xml:id='kro84'>Kron, G. E., Hewitt, A. V., and Wasserman, L. H. 1984, <!-- \pasp -->
+, 96, 198 </bibliomixed>
+<bibliomixed xml:id='lyn68'>Lynden-Bell, D., and Wood, R. 1968, <!-- \mnras -->
+, 138, 495 </bibliomixed>
+<bibliomixed xml:id='new78'>Newell, E. B., and O'Neil, E. J. 1978, <!-- \apjs -->
+, 37, 27 </bibliomixed>
+<bibliomixed xml:id='ort85'>Ortolani, S., Rosino, L., and Sandage, A. 1985, <!-- \aj -->
+, 90, 473 </bibliomixed>
+<bibliomixed xml:id='pet76'>Peterson, C. J. 1976, <!-- \aj -->
+, 81, 617 </bibliomixed>
 <bibliomixed xml:id='spi85'>Spitzer, L. 1985, Dynamics of Star Clusters, J. Goodman and P. Hut, Dordrecht: Reidel, 109 </bibliomixed>
 </bibliography>
 <table xml:id="tbl-2">
-<caption><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->Terribly relevant tabular information.</caption>
-<!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><tbody>
+<caption>Terribly relevant tabular information.</caption>
+<tbody>
 <tr>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->Star </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> Height </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
+<td align='center' valign='top'>Star </td>
+<td align='right' valign='top'> Height </td>
+<td align='right' valign='top'> <inlineequation>
 <alt role='tex'>d_{x}</alt>
  <m:math>
  
@@ -1005,7 +1064,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
+<td align='right' valign='top'> <inlineequation>
 <alt role='tex'>d_{y}</alt>
  <m:math>
  
@@ -1019,7 +1078,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
+<td align='right' valign='top'> <inlineequation>
 <alt role='tex'>n</alt>
  <m:math>
  
@@ -1027,7 +1086,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
+<td align='right' valign='top'> <inlineequation>
 <alt role='tex'>\chi^{2}</alt>
  <m:math>
  
@@ -1041,7 +1100,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
+<td align='right' valign='top'> <inlineequation>
 <alt role='tex'>R_{maj}</alt>
  <m:math>
  
@@ -1057,7 +1116,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
+<td align='right' valign='top'> <inlineequation>
 <alt role='tex'>R_{min}</alt>
  <m:math>
  
@@ -1073,15 +1132,15 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='center' valign='top' colspan='1'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><inlineequation>
+<td align='center' valign='top' colspan='1'><inlineequation>
 <alt role='tex'>P</alt>
  <m:math>
  
  <m:mrow><m:mi>P</m:mi>
  </m:mrow>
  </m:math>
-</inlineequation><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->a</td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
+</inlineequation>a</td>
+<td align='right' valign='top'> <inlineequation>
 <alt role='tex'>PR_{maj}</alt>
  <m:math>
  
@@ -1099,7 +1158,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
+<td align='right' valign='top'> <inlineequation>
 <alt role='tex'>PR_{min}</alt>
  <m:math>
  
@@ -1117,113 +1176,126 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='center' valign='top' colspan='1'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><inlineequation>
+<td align='center' valign='top' colspan='1'><inlineequation>
 <alt role='tex'>\Theta</alt>
  <m:math>
  
  <m:mrow><m:mo>&#x398;</m:mo>
  </m:mrow>
  </m:math>
-</inlineequation><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->b</td>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->Ref.</td>
+</inlineequation>b</td>
+<td align='center' valign='top'>Ref.</td>
 </tr>
 <tr>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><!-- \tableline\tableline -->1 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->33472.5 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-0.1 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->0.4 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->53 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->27.4 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->2.065 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.940 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->3.900 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->68.3 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->116.2 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-27.639</td>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1,2</td>
+<td align='center' valign='top'><!-- \tableline\tableline -->
+1 </td>
+<td align='right' valign='top'>33472.5 </td>
+<td align='right' valign='top'>-0.1 </td>
+<td align='right' valign='top'>0.4 </td>
+<td align='right' valign='top'>53 </td>
+<td align='right' valign='top'>27.4 </td>
+<td align='right' valign='top'>2.065 </td>
+<td align='right' valign='top'>1.940 </td>
+<td align='right' valign='top'>3.900 </td>
+<td align='right' valign='top'>68.3 </td>
+<td align='right' valign='top'>116.2 </td>
+<td align='right' valign='top'>-27.639</td>
+<td align='center' valign='top'>1,2</td>
 </tr>
 <tr>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 2 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->27802.4 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-0.3 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-0.2 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->60 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->3.7 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.628 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.510 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->2.156 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->6.8 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->7.5 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-26.764</td>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->3</td>
+<td align='center' valign='top'> 2 </td>
+<td align='right' valign='top'>27802.4 </td>
+<td align='right' valign='top'>-0.3 </td>
+<td align='right' valign='top'>-0.2 </td>
+<td align='right' valign='top'>60 </td>
+<td align='right' valign='top'>3.7 </td>
+<td align='right' valign='top'>1.628 </td>
+<td align='right' valign='top'>1.510 </td>
+<td align='right' valign='top'>2.156 </td>
+<td align='right' valign='top'>6.8 </td>
+<td align='right' valign='top'>7.5 </td>
+<td align='right' valign='top'>-26.764</td>
+<td align='center' valign='top'>3</td>
 </tr>
 <tr>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 3 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->29210.6 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->0.9 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->0.3 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->60 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->3.4 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.622 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.551 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->2.159 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->6.7 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->7.3 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-40.272</td>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->4</td>
+<td align='center' valign='top'> 3 </td>
+<td align='right' valign='top'>29210.6 </td>
+<td align='right' valign='top'>0.9 </td>
+<td align='right' valign='top'>0.3 </td>
+<td align='right' valign='top'>60 </td>
+<td align='right' valign='top'>3.4 </td>
+<td align='right' valign='top'>1.622 </td>
+<td align='right' valign='top'>1.551 </td>
+<td align='right' valign='top'>2.159 </td>
+<td align='right' valign='top'>6.7 </td>
+<td align='right' valign='top'>7.3 </td>
+<td align='right' valign='top'>-40.272</td>
+<td align='center' valign='top'>4</td>
 </tr>
 <tr>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 4 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->32733.8 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-1.2<!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->c</td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-0.5 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->41 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->54.8 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->2.282 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->2.156 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->4.313 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->117.4 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->78.2 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-35.847</td>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->5,6</td>
+<td align='center' valign='top'> 4 </td>
+<td align='right' valign='top'>32733.8 </td>
+<td align='right' valign='top'>-1.2c</td>
+<td align='right' valign='top'>-0.5 </td>
+<td align='right' valign='top'>41 </td>
+<td align='right' valign='top'>54.8 </td>
+<td align='right' valign='top'>2.282 </td>
+<td align='right' valign='top'>2.156 </td>
+<td align='right' valign='top'>4.313 </td>
+<td align='right' valign='top'>117.4 </td>
+<td align='right' valign='top'>78.2 </td>
+<td align='right' valign='top'>-35.847</td>
+<td align='center' valign='top'>5,6</td>
 </tr>
 <tr>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 5 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 9607.4 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-0.4 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-0.4 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->60 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.4 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.669<!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->c</td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.574 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->2.343 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->8.0 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->8.9 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-33.417</td>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->7</td>
+<td align='center' valign='top'> 5 </td>
+<td align='right' valign='top'> 9607.4 </td>
+<td align='right' valign='top'>-0.4 </td>
+<td align='right' valign='top'>-0.4 </td>
+<td align='right' valign='top'>60 </td>
+<td align='right' valign='top'>1.4 </td>
+<td align='right' valign='top'>1.669c</td>
+<td align='right' valign='top'>1.574 </td>
+<td align='right' valign='top'>2.343 </td>
+<td align='right' valign='top'>8.0 </td>
+<td align='right' valign='top'>8.9 </td>
+<td align='right' valign='top'>-33.417</td>
+<td align='center' valign='top'>7</td>
 </tr>
 <tr>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 6 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->31638.6 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.6 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->0.1 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->39 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->315.2 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 3.433 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->3.075 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->7.488 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->92.1 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->25.3 </td>
-<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-12.052 </td>
-<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->8</td>
+<td align='center' valign='top'> 6 </td>
+<td align='right' valign='top'>31638.6 </td>
+<td align='right' valign='top'>1.6 </td>
+<td align='right' valign='top'>0.1 </td>
+<td align='right' valign='top'>39 </td>
+<td align='right' valign='top'>315.2 </td>
+<td align='right' valign='top'> 3.433 </td>
+<td align='right' valign='top'>3.075 </td>
+<td align='right' valign='top'>7.488 </td>
+<td align='right' valign='top'>92.1 </td>
+<td align='right' valign='top'>25.3 </td>
+<td align='right' valign='top'>-12.052 </td>
+<td align='center' valign='top'>8</td>
 </tr>
 </tbody>
-<Table note>a<!-- }{ -->Sample footnote for table&#xA0;<xref linkend="tbl-2" /> that was generated with the LaTeX table environment</Table note>
-<Table note>b<!-- }{ -->Yet another sample footnote for table&#xA0;<xref linkend="tbl-2" /></Table note>
-<Table note>c<!-- }{ -->Another sample footnote for table&#xA0;<xref linkend="tbl-2" /></Table note>
-<TableComments>We can also attach a long-ish paragraph of explanatory material to a table. Use \tablerefs to append a list of references. The following references were from a different table: I've patched them in here to show how they look, but don't take them too seriously—I certainly have not.</TableComments>
-<TableRefs>(1) Barbuy, Spite, & Spite 1985; (2) Bond 1980; (3) Carbon et al. 1987; (4) Hobbs & Duncan 1987; (5) Gilroy et al. 1988: (6) Gratton & Ortolani 1986; (7) Gratton & Sneden 1987; (8) Gratton & Sneden (1988); (9) Gratton & Sneden 1991; (10) Kraft et al. 1982; (11) LCL, or Laird, 1990; (12) Leep & Wallerstein 1981; (13) Luck & Bond 1981; (14) Luck & Bond 1985; (15) Magain 1987; (16) Magain 1989; (17) Peterson 1981; (18) Peterson, Kurucz, & Carney 1990; (19) RMB; (20) Schuster & Nissen 1988; (21) Schuster & Nissen 1989b; (22) Spite et al. 1984; (23) Spite & Spite 1986; (24) Hobbs & Thorburn 1991; (25) Hobbs et al. 1991; (26) Olsen 1983.</TableRefs>
-</table>
-</section>
 
+<Table note>
+a<!-- }{ -->
+Sample footnote for table&#xA0;<xref linkend="tbl-2" /> that was generated with the LaTeX table environment
+</Table note>
+<Table note>
+b<!-- }{ -->
+Yet another sample footnote for table&#xA0;<xref linkend="tbl-2" />
+</Table note>
+<Table note>
+c<!-- }{ -->
+Another sample footnote for table&#xA0;<xref linkend="tbl-2" />
+</Table note>
+<TableComments>
+We can also attach a long-ish paragraph of explanatory material to a table. Use \tablerefs to append a list of references. The following references were from a different table: I've patched them in here to show how they look, but don't take them too seriously—I certainly have not.
+</TableComments>
+<TableRefs>
+(1) Barbuy, Spite, & Spite 1985; (2) Bond 1980; (3) Carbon et al. 1987; (4) Hobbs & Duncan 1987; (5) Gilroy et al. 1988: (6) Gratton & Ortolani 1986; (7) Gratton & Sneden 1987; (8) Gratton & Sneden (1988); (9) Gratton & Sneden 1991; (10) Kraft et al. 1982; (11) LCL, or Laird, 1990; (12) Leep & Wallerstein 1981; (13) Luck & Bond 1981; (14) Luck & Bond 1985; (15) Magain 1987; (16) Magain 1989; (17) Peterson 1981; (18) Peterson, Kurucz, & Carney 1990; (19) RMB; (20) Schuster & Nissen 1988; (21) Schuster & Nissen 1989b; (22) Spite et al. 1984; (23) Spite & Spite 1986; (24) Hobbs & Thorburn 1991; (25) Hobbs et al. 1991; (26) Olsen 1983.
+</TableRefs>
+</table>
 </article>
\ No newline at end of file
diff --git a/lib/layouts/aastex.layout b/lib/layouts/aastex.layout
index 74d2ab6..d79cd02 100644
--- a/lib/layouts/aastex.layout
+++ b/lib/layouts/aastex.layout
@@ -179,6 +179,7 @@ Style Affiliation
 	DocBookWrapperTag                 author
 	DocBookWrapperMergeWithPrevious   true
 	DocBookItemTag                    orgname
+	DocBookItemTagType                paragraph
 	DocBookInInfo                     always
 End
 
@@ -207,6 +208,7 @@ Style Altaffilation
 	DocBookWrapperTag                 author
 	DocBookWrapperMergeWithPrevious   true
 	DocBookItemTag                    orgname
+	DocBookItemTagType                paragraph
 	DocBookInInfo                     always
 End
 
@@ -228,6 +230,7 @@ Style Email
 	  Shape		Italic
 	EndFont
 	DocBookTag                        email
+	DocBookTagType                    paragraph
 	DocBookWrapperTag                 author
 	DocBookWrapperMergeWithPrevious   true
 	DocBookInInfo                     always

commit f9ea791f50f09942aedb5a52fa7926bd0e8dc605
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 02:30:24 2020 +0200

    DocBook: adapt SimpleCV for tag types (new-line behaviour).

diff --git a/lib/layouts/simplecv.layout b/lib/layouts/simplecv.layout
index 0a69f1e..1cf6c30 100644
--- a/lib/layouts/simplecv.layout
+++ b/lib/layouts/simplecv.layout
@@ -54,6 +54,7 @@ Style Section
 		IsTocCaption   1
 	EndArgument
 	DocBookTag            title
+	DocBookTagType        paragraph
 	DocBookSectionTag     section
 End
 
@@ -176,6 +177,7 @@ Style Title
 	EndFont
 	HTMLTitle             true
 	DocBookTag            title
+	DocBookTagType        paragraph
 	DocBookInInfo         maybe
 End
 

commit 18f4a3ecc474b8c4279bba7f3b559c733c2a2882
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 02:30:04 2020 +0200

    DocBook: fix bibliographies (end of <bibliography> and sections).

diff --git a/autotests/export/docbook/bibliography_precooked.xml b/autotests/export/docbook/bibliography_precooked.xml
index 1f103bc..901abd4 100644
--- a/autotests/export/docbook/bibliography_precooked.xml
+++ b/autotests/export/docbook/bibliography_precooked.xml
@@ -5,11 +5,10 @@
 <title>William Shakespeare</title>
 <section>
 <title>Publications</title>
+</section>
 <bibliography>
 <bibliomixed xml:id='first'>First Folio. </bibliomixed>
 <bibliomixed xml:id='second'>Second Folio. </bibliomixed>
 <bibliomixed xml:id='third'>Third Folio. </bibliomixed>
 </bibliography>
-</section>
-
 </article>
\ No newline at end of file
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index a0ac96a..19bd1d8 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -393,12 +393,9 @@ void makeBibliography(
 
 	// If this is the last paragraph in a bibliography, close the bibliography tag.
 	auto const end = text.paragraphs().end();
-	bool endBibliography = par == end;
-	if (!endBibliography) {
-		auto nextpar = par;
-		++nextpar;
-		endBibliography = par->layout().latextype != LATEX_BIB_ENVIRONMENT;
-	}
+	auto nextpar = par;
+	++nextpar;
+	bool endBibliography = nextpar == end || nextpar->layout().latextype != LATEX_BIB_ENVIRONMENT;
 
 	if (endBibliography) {
 		xs << xml::EndTag("bibliography");
@@ -1124,7 +1121,7 @@ void docbookParagraphs(Text const &text,
 		auto insetsLength = distance(par->insetList().begin(), par->insetList().end());
 		if (insetsLength > 0) {
 			Inset const *firstInset = par->getInset(0);
-			if (firstInset && dynamic_cast<InsetBibtex const *>(firstInset)) {
+			if (firstInset && (firstInset->lyxCode() == BIBITEM_CODE || firstInset->lyxCode() == BIBTEX_CODE)) {
 				while (!headerLevels.empty()) {
 					int level = headerLevels.top().first;
 					docstring tag = from_utf8("</" + headerLevels.top().second + ">");

commit e43d749aff6bcef69af7f43487fa07a955fe6ac4
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 01:14:44 2020 +0200

    DocBook: generate <partintro> when required.

diff --git a/autotests/export/docbook/basic.xml b/autotests/export/docbook/basic.xml
index ea91d3d..49ec1f4 100644
--- a/autotests/export/docbook/basic.xml
+++ b/autotests/export/docbook/basic.xml
@@ -12,7 +12,9 @@
 <para>I am an abstract</para>
 <para>I am also an abstract</para>
 </abstract>
+
 </info>
+<para>I am a standard paragraph. </para>
 <section xml:id="sec.Sec-1">
 <title>I am the first section </title>
 <para>I am the first paragraph of the first section. </para>
diff --git a/autotests/export/docbook/basic_book.xml b/autotests/export/docbook/basic_book.xml
index 18496b9..c6e9078 100644
--- a/autotests/export/docbook/basic_book.xml
+++ b/autotests/export/docbook/basic_book.xml
@@ -17,7 +17,9 @@
 </chapter>
 <part>
 <title>First part</title>
+<partintro>
 <para>Part intro. </para>
+</partintro>
 <chapter>
 <title>First chapter of first part</title>
 <para>Paragraph. </para>
@@ -29,7 +31,9 @@
 </part>
 <part>
 <title>Second part</title>
+<partintro>
 <para>Part 2 intro. </para>
+</partintro>
 <chapter>
 <title>First chapter of second part</title>
 <para>Paragraph. </para>
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 3e37f90..a0ac96a 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -821,7 +821,7 @@ bool hasOnlyNotes(Paragraph const & par)
 	for (int i = 0; i < par.size(); ++i)
 		// If you find something that is not an inset (like actual text) or an inset that is not a note,
 		// return false.
-		if (!par.isInset(i) || !dynamic_cast<InsetNote *>(par.insetList().get(i)))
+		if (!par.isInset(i) || par.getInset(i)->lyxCode() != NOTE_CODE)
 			return false;
 	return true;
 }
@@ -851,7 +851,7 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs,
 	for (; cpit < epit; ++cpit) {
 		// Skip paragraphs that don't generate anything in DocBook.
 		Paragraph const & par = paragraphs[cpit];
-		if (par.empty() || par.emptyTag() || hasOnlyNotes(par))
+		if (hasOnlyNotes(par))
 			continue;
 
 		// There should never be any section here. (Just a sanity check: if this fails, this function could end up
@@ -869,14 +869,14 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs,
 		}
 
 		// Based on layout information, store this paragraph in one set: should be in <info>, must be,
-		// or abstract ().
+		// or abstract (either because of layout or of position).
 		Layout const &style = par.layout();
 
 		if (style.docbookininfo() == "always")
 			mustBeInInfo.emplace(cpit);
 		else if (style.docbookininfo() == "maybe")
 			shouldBeInInfo.emplace(cpit);
-		else if (!hasAbstractLayout)
+		else if (documentHasSections && !hasAbstractLayout)
 			abstractNoLayout.emplace(cpit);
 		else // This should definitely not be in <info>.
 			break;
@@ -993,17 +993,17 @@ void docbookSimpleAllParagraphs(
 {
 	// Handle the given text, supposing it has no sections (i.e. a "simple" text). The input may vary in length
 	// between a single paragraph to a whole document.
+	pit_type const bpit = runparams.par_begin;
+	pit_type const epit = runparams.par_end;
+	ParagraphList const &paragraphs = text.paragraphs();
 
 	// First, the <info> tag.
-	ParagraphList const &paragraphs = text.paragraphs();
-	pit_type bpit = runparams.par_begin;
-	pit_type const epit = runparams.par_end;
 	DocBookInfoTag info = getParagraphsWithInfo(paragraphs, bpit, epit, false);
 	outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
 
 	// Then, the content. It starts where the <info> ends.
-	auto par = text.paragraphs().iterator_at(info.epit);
-	auto end = text.paragraphs().iterator_at(epit);
+	auto par = paragraphs.iterator_at(info.epit);
+	auto end = paragraphs.iterator_at(epit);
 	while (par != end) {
 		if (!hasOnlyNotes(*par))
 			par = makeAny(text, buf, xs, runparams, par);
@@ -1040,7 +1040,7 @@ void docbookParagraphs(Text const &text,
 	tie(documentHasSections, eppit) = hasDocumentSectioning(paragraphs, bpit, epit);
 
 	// Deal with "simple" documents, i.e. those without sections.
-	if (!documentHasSections){
+	if (!documentHasSections) {
 		docbookSimpleAllParagraphs(text, buf, xs, runparams);
 		return;
 	}
@@ -1048,7 +1048,7 @@ void docbookParagraphs(Text const &text,
 	// Output the first <info> tag (or just the title).
 	DocBookInfoTag info = getParagraphsWithInfo(paragraphs, bpit, eppit, true);
 	outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
-	bpit = eppit;
+	bpit = info.epit;
 
 	// Then, iterate through the paragraphs of this document.
 	bool currentlyInAppendix = false;
@@ -1141,6 +1141,29 @@ void docbookParagraphs(Text const &text,
 
 		// Generate this paragraph.
 		par = makeAny(text, buf, xs, ourparams, par);
+
+		// Some special sections may require abstracts (mostly parts, in books).
+		// TODO: docbookforceabstracttag is a bit contrived here, but it does the job. Having another field just for this would be cleaner, but that's just for <part> and <partintro>, so it's probably not worth the effort.
+		if (isLayoutSectioning(style) && style.docbookforceabstracttag() != "NONE") {
+			// This abstract may be found between the next paragraph and the next title.
+			pit_type cpit = std::distance(text.paragraphs().begin(), par);
+			pit_type ppit = std::get<1>(hasDocumentSectioning(paragraphs, cpit, epit));
+
+			// Generate this abstract (this code corresponds to parts of outputDocBookInfo).
+			DocBookInfoTag secInfo = getParagraphsWithInfo(paragraphs, cpit, ppit, true);
+
+			if (!secInfo.abstract.empty()) {
+				xs << xml::StartTag(style.docbookforceabstracttag());
+				xs << xml::CR();
+				for (auto const &p : secInfo.abstract)
+					makeAny(text, buf, xs, runparams, paragraphs.iterator_at(p));
+				xs << xml::EndTag(style.docbookforceabstracttag());
+				xs << xml::CR();
+			}
+
+			// Skip all the text that just has been generated.
+			par = paragraphs.iterator_at(ppit);
+		}
 	}
 
 	// If need be, close <section>s, but only at the end of the document (otherwise, dealt with at the beginning

commit 175cb77ae1d55a993cc5c5116cfb819302b1dcc4
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 00:58:50 2020 +0200

    DocBook: streamline code to handle sections.

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 38bcf05..3e37f90 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -1071,18 +1071,18 @@ void docbookParagraphs(Text const &text,
 		if (isLayoutSectioning(style)) {
 			int level = style.toclevel;
 
-			// Need to close a previous section if it has the same level or a higher one (close <section> if opening a <h2>
-			// after a <h2>, <h3>, <h4>, <h5> or <h6>). More examples:
+			// Need to close a previous section if it has the same level or a higher one (close <section> if opening a
+			// <h2> after a <h2>, <h3>, <h4>, <h5> or <h6>). More examples:
 			//   - current: h2; back: h1; do not close any <section>
 			//   - current: h1; back: h2; close two <section> (first the <h2>, then the <h1>, so a new <h1> can come)
 			while (!headerLevels.empty() && level <= headerLevels.top().first) {
+				// Output the tag only if it corresponds to a legit section.
 				int stackLevel = headerLevels.top().first;
-				docstring stackTag = from_utf8("</" + headerLevels.top().second + ">");
+				if (stackLevel != Layout::NOT_IN_TOC) {
+					xs << xml::EndTag(headerLevels.top().second);
+					xs << xml::CR();
+				}
 				headerLevels.pop();
-
-				// Output the tag only if it corresponds to a legit section.
-				if (stackLevel != Layout::NOT_IN_TOC)
-					xs << XMLStream::ESCAPE_NONE << stackTag << xml::CR();
 			}
 
 			// Open the new section: first push it onto the stack, then output it in DocBook.
@@ -1111,11 +1111,10 @@ void docbookParagraphs(Text const &text,
 				}
 
 				// Write the open tag for this section.
-				docstring tag = from_utf8("<" + sectionTag);
+				docstring attrs;
 				if (!id.empty())
-					tag += from_utf8(" ") + id;
-				tag += from_utf8(">");
-				xs << XMLStream::ESCAPE_NONE << tag;
+					attrs = id;
+				xs << xml::StartTag(sectionTag, attrs);
 				xs << xml::CR();
 			}
 		}

commit 8b9e5aa198124161c3374af5cb8a09bda49defc4
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 30 00:35:47 2020 +0200

    DocBook: streamline code to handle abstracts.

diff --git a/autotests/export/docbook/basic_book.xml b/autotests/export/docbook/basic_book.xml
index c94d2fa..18496b9 100644
--- a/autotests/export/docbook/basic_book.xml
+++ b/autotests/export/docbook/basic_book.xml
@@ -1,12 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- This DocBook file was created by LyX 2.4.0dev
   See http://www.lyx.org/ for more information -->
-<book xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.1">
-
-<info><title>Book title</title>
-<author><personname>Book author</personname></author>
-
-<abstract><para>Book abstract in info. </para>
+<book xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
+<info>
+<title>Book title</title>
+<author>
+<personname>Book author</personname>
+</author>
+<abstract>
+<para>Book abstract in info. </para>
 </abstract>
 </info>
 <chapter>
@@ -15,9 +17,7 @@
 </chapter>
 <part>
 <title>First part</title>
-
-<partintro><para>Part intro. </para>
-</partintro>
+<para>Part intro. </para>
 <chapter>
 <title>First chapter of first part</title>
 <para>Paragraph. </para>
@@ -29,9 +29,7 @@
 </part>
 <part>
 <title>Second part</title>
-
-<partintro><para>Part 2 intro. </para>
-</partintro>
+<para>Part 2 intro. </para>
 <chapter>
 <title>First chapter of second part</title>
 <para>Paragraph. </para>
@@ -41,5 +39,4 @@
 <para>Paragraph. </para>
 </chapter>
 </part>
-
 </book>
\ No newline at end of file
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index e609f39..38bcf05 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -773,21 +773,28 @@ ParagraphList::const_iterator makeAny(Text const &text,
 }
 
 
+bool isLayoutSectioning(Layout const & lay)
+{
+	return lay.category() == from_utf8("Sectioning");
+}
+
+
 using DocBookDocumentSectioning = tuple<bool, pit_type>;
 
 
 struct DocBookInfoTag
 {
 	const set<pit_type> shouldBeInInfo;
-	const set<pit_type> mustBeInInfo;
+	const set<pit_type> mustBeInInfo; // With the notable exception of the abstract!
 	const set<pit_type> abstract;
+	const bool abstractLayout;
 	pit_type bpit;
 	pit_type epit;
 
 	DocBookInfoTag(const set<pit_type> & shouldBeInInfo, const set<pit_type> & mustBeInInfo,
-				   const set<pit_type> & abstract, pit_type bpit, pit_type epit) :
+				   const set<pit_type> & abstract, bool abstractLayout, pit_type bpit, pit_type epit) :
 				   shouldBeInInfo(shouldBeInInfo), mustBeInInfo(mustBeInInfo), abstract(abstract),
-				   bpit(bpit), epit(epit) {}
+				   abstractLayout(abstractLayout), bpit(bpit), epit(epit) {}
 };
 
 
@@ -796,7 +803,7 @@ DocBookDocumentSectioning hasDocumentSectioning(ParagraphList const &paragraphs,
 
 	while (bpit < epit) {
 		Layout const &style = paragraphs[bpit].layout();
-		documentHasSections |= style.category() == from_utf8("Sectioning");
+		documentHasSections |= isLayoutSectioning(style);
 
 		if (documentHasSections)
 			break;
@@ -820,10 +827,14 @@ bool hasOnlyNotes(Paragraph const & par)
 }
 
 
-DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs, pit_type bpit, pit_type const epit) {
+DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs,
+									 pit_type bpit, pit_type const epit,
+									 // Typically, bpit is the beginning of the document and epit the end *or* the first section.
+									 bool documentHasSections) {
 	set<pit_type> shouldBeInInfo;
 	set<pit_type> mustBeInInfo;
-	set<pit_type> abstract;
+	set<pit_type> abstractWithLayout;
+	set<pit_type> abstractNoLayout;
 
 	// Find the first non empty paragraph by mutating bpit.
 	while (bpit < epit) {
@@ -834,78 +845,48 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs, pit_type b
 			break;
 	}
 
-	// Find the last info-like paragraph.
-	pit_type cpit = bpit;
+	// Traverse everything that might belong to <info>.
 	bool hasAbstractLayout = false;
-	while (cpit < epit) {
-		// Skip paragraphs only containing one note.
+	pit_type cpit = bpit;
+	for (; cpit < epit; ++cpit) {
+		// Skip paragraphs that don't generate anything in DocBook.
 		Paragraph const & par = paragraphs[cpit];
-		if (hasOnlyNotes(par)) {
-			cpit += 1;
+		if (par.empty() || par.emptyTag() || hasOnlyNotes(par))
 			continue;
+
+		// There should never be any section here. (Just a sanity check: if this fails, this function could end up
+		// processing the whole document.)
+		if (isLayoutSectioning(par.layout())) {
+			LYXERR0("Assertion failed: section found in potential <info> paragraphs.");
+			break;
 		}
 
-		if (par.layout().docbookabstract())
+		// If this is marked as an abstract by the layout, put it in the right set.
+		if (par.layout().docbookabstract()) {
 			hasAbstractLayout = true;
+			abstractWithLayout.emplace(cpit);
+			continue;
+		}
 
-		// Based on layout information, store this paragraph in one set: should be in <info>, must be.
+		// Based on layout information, store this paragraph in one set: should be in <info>, must be,
+		// or abstract ().
 		Layout const &style = par.layout();
 
-		if (style.docbookininfo() == "always") {
+		if (style.docbookininfo() == "always")
 			mustBeInInfo.emplace(cpit);
-		} else if (style.docbookininfo() == "maybe") {
+		else if (style.docbookininfo() == "maybe")
 			shouldBeInInfo.emplace(cpit);
-		} else {
-			// Hypothesis: the <info> parts should be grouped together near the beginning bpit.
-			// There may be notes in between, but nothing else.
+		else if (!hasAbstractLayout)
+			abstractNoLayout.emplace(cpit);
+		else // This should definitely not be in <info>.
 			break;
-		}
-		cpit += 1;
 	}
-	// Now, cpit points to the last paragraph that has things that could go in <info>.
+	// Now, cpit points to the first paragraph that no more has things that could go in <info>.
 	// bpit is the beginning of the <info> part.
 
-	// Go once again through the list of paragraphs to find the abstract. If there is an abstract
-	// layout, only consider it. Otherwise, an abstract is just a sequence of paragraphs with text.
-	if (hasAbstractLayout) {
-		pit_type pit = bpit;
-		while (pit < cpit) { // Don't overshoot the <info> part.
-			if (paragraphs[pit].layout().docbookabstract())
-				abstract.emplace(pit);
-			pit++;
-		}
-	} else {
-		pit_type lastAbstract = epit + 1; // A nonsensical value.
-		docstring lastAbstractLayout;
-
-		pit_type pit = bpit;
-		while (pit < cpit) { // Don't overshoot the <info> part.
-			const Paragraph & par = paragraphs.at(pit);
-			if (!par.insetList().empty()) {
-				for (const auto &i : par.insetList()) {
-					if (i.inset->getText(0) != nullptr) {
-						if (lastAbstract == epit + 1) {
-							// First paragraph that matches the heuristic definition of abstract.
-							lastAbstract = pit;
-							lastAbstractLayout = par.layout().name();
-						} else if (pit > lastAbstract + 1 || par.layout().name() != lastAbstractLayout) {
-							// This is either too far from the last abstract paragraph or doesn't
-							// have the right layout name, BUT there has already been an abstract
-							// in this document: done with detecting the abstract.
-							goto done; // Easier to get out of two nested loops.
-						}
-
-						abstract.emplace(pit);
-						break;
-					}
-				}
-			}
-			pit++;
-		}
-	}
-
-	done:
-	return DocBookInfoTag(shouldBeInInfo, mustBeInInfo, abstract, bpit, cpit);
+	return DocBookInfoTag(shouldBeInInfo, mustBeInInfo,
+					      hasAbstractLayout ? abstractWithLayout : abstractNoLayout,
+					      hasAbstractLayout, bpit, cpit);
 }
 
 } // end anonymous namespace
@@ -940,17 +921,9 @@ void outputDocBookInfo(
 	if (hasAbstract) {
 		// Generate the abstract XML into a string before further checks.
 		odocstringstream os2;
-		{
-			XMLStream xs2(os2);
-			auto bpit = *std::min_element(info.abstract.begin(), info.abstract.end());
-			auto epit = 1 + *std::max_element(info.abstract.begin(), info.abstract.end());
-			// info.abstract is inclusive, epit is exclusive, hence +1 for looping.
-
-			while (bpit < epit) {
-				makeAny(text, buf, xs2, runparams, paragraphs.iterator_at(bpit));
-				bpit += 1;
-			}
-		}
+		XMLStream xs2(os2);
+		for (auto const & p : info.abstract)
+			makeAny(text, buf, xs2, runparams, paragraphs.iterator_at(p));
 
 		// Actually output the abstract if there is something to do. Don't count line feeds or spaces in this,
 		// even though they must be properly output if there is some abstract.
@@ -974,27 +947,33 @@ void outputDocBookInfo(
 	}
 
 	// Output the elements that should go in <info>, before and after the abstract.
-	for (auto pit : info.shouldBeInInfo) { // Typically, the title: these elements are so important and ubiquitous
+	for (auto pit : info.shouldBeInInfo) // Typically, the title: these elements are so important and ubiquitous
 		// that mandating a wrapper like <info> would repel users. Thus, generate them first.
 		makeAny(text, buf, xs, runparams, paragraphs.iterator_at(pit));
-	}
-	for (auto pit : info.mustBeInInfo) {
+	for (auto pit : info.mustBeInInfo)
 		if (info.abstract.find(pit) == info.abstract.end()) // The abstract must be in info, but is dealt with after.
 			makeAny(text, buf, xs, runparams, paragraphs.iterator_at(pit));
-	}
 
 	// Always output the abstract as the last item of the <info>, as it requires special treatment (especially if
 	// it contains several paragraphs that are empty).
 	if (hasAbstract) {
-//		string tag = paragraphs[*info.abstract.begin()].layout().docbookforceabstracttag();
-//		if (tag == "NONE")
-//			tag = "abstract";
-//
-//		xs << xml::StartTag(tag);
-//		xs << xml::CR();
-		xs << XMLStream::ESCAPE_NONE << abstract;
-//		xs << xml::EndTag(tag);
-//		xs << xml::CR();
+		if (info.abstractLayout) {
+			xs << XMLStream::ESCAPE_NONE << abstract;
+			xs << xml::CR();
+		} else {
+			string tag = paragraphs[*info.abstract.begin()].layout().docbookforceabstracttag();
+			if (tag == "NONE")
+				tag = "abstract";
+
+			if (!xs.isLastTagCR())
+				xs << xml::CR();
+
+			xs << xml::StartTag(tag);
+			xs << xml::CR();
+			xs << XMLStream::ESCAPE_NONE << abstract;
+			xs << xml::EndTag(tag);
+			xs << xml::CR();
+		}
 	}
 
 	// End the <info> tag if it was started.
@@ -1006,23 +985,6 @@ void outputDocBookInfo(
 }
 
 
-void docbookFirstParagraphs(
-		Text const &text,
-		Buffer const &buf,
-		XMLStream &xs,
-		OutputParams const &runparams,
-		pit_type epit)
-{
-	// Handle the beginning of the document, supposing it has sections.
-	// Major role: output the first <info> tag.
-
-	ParagraphList const &paragraphs = text.paragraphs();
-	pit_type bpit = runparams.par_begin;
-	DocBookInfoTag info = getParagraphsWithInfo(paragraphs, bpit, epit);
-	outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
-}
-
-
 void docbookSimpleAllParagraphs(
 		Text const & text,
 		Buffer const & buf,
@@ -1036,7 +998,7 @@ void docbookSimpleAllParagraphs(
 	ParagraphList const &paragraphs = text.paragraphs();
 	pit_type bpit = runparams.par_begin;
 	pit_type const epit = runparams.par_end;
-	DocBookInfoTag info = getParagraphsWithInfo(paragraphs, bpit, epit);
+	DocBookInfoTag info = getParagraphsWithInfo(paragraphs, bpit, epit, false);
 	outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
 
 	// Then, the content. It starts where the <info> ends.
@@ -1071,20 +1033,24 @@ void docbookParagraphs(Text const &text,
 	std::stack<std::pair<int, string>> headerLevels; // Used to determine when to open/close sections: store the depth
 	// of the section and the tag that was used to open it.
 
-	// Detect whether the document contains sections. If there are no sections, there can be no automatically
-	// discovered abstract.
+	// Detect whether the document contains sections. If there are no sections, treatment is largely simplified.
+	// In particular, there can't be an abstract, unless it is manually marked.
 	bool documentHasSections;
 	pit_type eppit;
 	tie(documentHasSections, eppit) = hasDocumentSectioning(paragraphs, bpit, epit);
 
-	if (documentHasSections) {
-		docbookFirstParagraphs(text, buf, xs, runparams, eppit);
-		bpit = eppit;
-	} else {
+	// Deal with "simple" documents, i.e. those without sections.
+	if (!documentHasSections){
 		docbookSimpleAllParagraphs(text, buf, xs, runparams);
 		return;
 	}
 
+	// Output the first <info> tag (or just the title).
+	DocBookInfoTag info = getParagraphsWithInfo(paragraphs, bpit, eppit, true);
+	outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
+	bpit = eppit;
+
+	// Then, iterate through the paragraphs of this document.
 	bool currentlyInAppendix = false;
 
 	auto par = text.paragraphs().iterator_at(bpit);
@@ -1102,8 +1068,7 @@ void docbookParagraphs(Text const &text,
 		Layout const &style = par->layout();
 
 		// Think about adding <section> and/or </section>s.
-		const bool isLayoutSectioning = style.category() == from_utf8("Sectioning");
-		if (isLayoutSectioning) {
+		if (isLayoutSectioning(style)) {
 			int level = style.toclevel;
 
 			// Need to close a previous section if it has the same level or a higher one (close <section> if opening a <h2>

commit 736c778fff26d8dfc250d0142e420621883525a3
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sat Aug 29 23:41:28 2020 +0200

    DocBook: fix handling of index end-of-range.

diff --git a/autotests/export/docbook/basic.xml b/autotests/export/docbook/basic.xml
index a4dc276..ea91d3d 100644
--- a/autotests/export/docbook/basic.xml
+++ b/autotests/export/docbook/basic.xml
@@ -205,9 +205,9 @@ I am a second line of code.
 <para>Then several terms for the first index: <indexterm type="idx"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>. </para>
 <para>With a see: <indexterm type="idx"><primary>Term</primary><see>index</see></indexterm>. With a see also: <indexterm type="idx"><primary>Term</primary><seealso>index</seealso></indexterm>. </para>
 <para>Several terms with a see: <indexterm type="idx"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary><see>index</see></indexterm>. Several terms with a see also: <indexterm type="idx"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary><seealso>index</seealso></indexterm>. </para>
-<para>A start of range: <indexterm type="idx" class="startofrange" xml:id="Term-to-index"><primary>Term to index</primary></indexterm>. The corresponding end of range: <indexterm type="idx" class="endofrange" startref="Term-to-index"><primary>Term to index</primary></indexterm>.</para>
-<para>Several terms with a start of range: <indexterm type="idx" class="startofrange" xml:id="Term.to.index"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>. The corresponding end of range: <indexterm type="idx" class="endofrange" startref="Term.to.index"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>.</para>
-<para>These terms already appeared before! Start of range: <indexterm type="idx" class="startofrange" xml:id="Term.to.index-0"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>. The corresponding end of range: <indexterm type="idx" class="endofrange" startref="Term.to.index-0"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>.</para>
+<para>A start of range: <indexterm type="idx" class="startofrange" xml:id="Term-to-index"><primary>Term to index</primary></indexterm>. The corresponding end of range: <indexterm class="endofrange" startref="Term-to-index" />.</para>
+<para>Several terms with a start of range: <indexterm type="idx" class="startofrange" xml:id="Term.to.index"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>. The corresponding end of range: <indexterm class="endofrange" startref="Term.to.index" />.</para>
+<para>These terms already appeared before! Start of range: <indexterm type="idx" class="startofrange" xml:id="Term.to.index-0"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>. The corresponding end of range: <indexterm class="endofrange" startref="Term.to.index-0" />.</para>
 </section>
 <section>
 <title>I am the eight section and I deal with star sections</title>
diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp
index 987c138..149ef65 100644
--- a/src/insets/InsetIndex.cpp
+++ b/src/insets/InsetIndex.cpp
@@ -287,14 +287,17 @@ void InsetIndex::docbook(XMLStream & xs, OutputParams const & runparams) const
 		// Hence the thread-local storage, as the numbers must strictly be unique, and thus cannot be shared across
 		// a paragraph (making the solution used for HTML worthless). This solution is very similar to the one used in
 		// xml::cleanID.
-		docstring attrs = indexType;
-		if (hasStartRange || hasEndRange) {
+		// indexType can only be used for singular and startofrange types!
+		docstring attrs;
+		if (!hasStartRange && !hasEndRange) {
+			attrs = indexType;
+		} else {
 			// Append an ID if uniqueness is not guaranteed across the document.
 			static QThreadStorage<set<docstring>> tKnownTermLists;
 			static QThreadStorage<int> tID;
 
-			set<docstring> & knownTermLists = tKnownTermLists.localData();
-			int & ID = tID.localData();
+			set<docstring> &knownTermLists = tKnownTermLists.localData();
+			int &ID = tID.localData();
 
 			if (!tID.hasLocalData()) {
 				tID.localData() = 0;
@@ -319,47 +322,51 @@ void InsetIndex::docbook(XMLStream & xs, OutputParams const & runparams) const
 			// Generate the attributes.
 			docstring id = xml::cleanID(newIndexTerms);
 			if (hasStartRange) {
-				attrs += " class=\"startofrange\" xml:id=\"" + id + "\"";
+				attrs = indexType + " class=\"startofrange\" xml:id=\"" + id + "\"";
 			} else {
-				attrs += " class=\"endofrange\" startref=\"" + id + "\"";
+				attrs = " class=\"endofrange\" startref=\"" + id + "\"";
 			}
 		}
 
 		// Handle the index terms (including the specific index for this entry).
-		xs << xml::StartTag("indexterm", attrs);
-		if (terms.size() > 0) { // hasEndRange has no content.
-			xs << xml::StartTag("primary");
-			xs << terms[0];
-			xs << xml::EndTag("primary");
-		}
-		if (terms.size() > 1) {
-			xs << xml::StartTag("secondary");
-			xs << terms[1];
-			xs << xml::EndTag("secondary");
-		}
-		if (terms.size() > 2) {
-			xs << xml::StartTag("tertiary");
-			xs << terms[2];
-			xs << xml::EndTag("tertiary");
-		}
+		if (hasEndRange) {
+			xs << xml::CompTag("indexterm", attrs);
+		} else {
+			xs << xml::StartTag("indexterm", attrs);
+			if (!terms.empty()) { // hasEndRange has no content.
+				xs << xml::StartTag("primary");
+				xs << terms[0];
+				xs << xml::EndTag("primary");
+			}
+			if (terms.size() > 1) {
+				xs << xml::StartTag("secondary");
+				xs << terms[1];
+				xs << xml::EndTag("secondary");
+			}
+			if (terms.size() > 2) {
+				xs << xml::StartTag("tertiary");
+				xs << terms[2];
+				xs << xml::EndTag("tertiary");
+			}
 
-		// Handle see and see also.
-		if (!see.empty()) {
-			xs << xml::StartTag("see");
-			xs << see;
-			xs << xml::EndTag("see");
-		}
+			// Handle see and see also.
+			if (!see.empty()) {
+				xs << xml::StartTag("see");
+				xs << see;
+				xs << xml::EndTag("see");
+			}
 
-		if (!seeAlsoes.empty()) {
-			for (auto & entry : seeAlsoes) {
-				xs << xml::StartTag("seealso");
-				xs << entry;
-				xs << xml::EndTag("seealso");
+			if (!seeAlsoes.empty()) {
+				for (auto &entry : seeAlsoes) {
+					xs << xml::StartTag("seealso");
+					xs << entry;
+					xs << xml::EndTag("seealso");
+				}
 			}
-		}
 
-		// Close the entry.
-		xs << xml::EndTag("indexterm");
+			// Close the entry.
+			xs << xml::EndTag("indexterm");
+		}
 	}
 }
 
diff --git a/src/xml.cpp b/src/xml.cpp
index 0daa9d8..557bb01 100644
--- a/src/xml.cpp
+++ b/src/xml.cpp
@@ -140,11 +140,11 @@ docstring EndTag::writeEndTag() const
 
 docstring CompTag::writeTag() const
 {
-	docstring output = '<' + from_utf8(tag_);
+	docstring output = '<' + tag_;
 	if (!attr_.empty()) {
 		// Erase the beginning of the attributes if it contains space characters: this function deals with that
 		// automatically.
-		docstring attributes = escapeString(from_utf8(attr_), XMLStream::ESCAPE_NONE);
+		docstring attributes = escapeString(attr_, XMLStream::ESCAPE_NONE);
 		attributes.erase(attributes.begin(), std::find_if(attributes.begin(), attributes.end(),
                                                           [](int c) {return !std::isspace(c);}));
 		if (!attributes.empty()) {
diff --git a/src/xml.h b/src/xml.h
index bbf5b58..ebb8b8e 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -242,16 +242,19 @@ struct CompTag
 {
 	///
 	explicit CompTag(std::string const & tag)
-			: tag_(tag) {}
+			: tag_(from_utf8(tag)) {}
 	///
 	explicit CompTag(std::string const & tag, std::string const & attr)
-			: tag_(tag), attr_(attr) {}
+			: tag_(from_utf8(tag)), attr_(from_utf8(attr)) {}
+	///
+	explicit CompTag(std::string const & tag, docstring const & attr)
+			: tag_(from_utf8(tag)), attr_(attr) {}
 	/// <tag_ attr_ />
 	docstring writeTag() const;
 	///
-	std::string tag_;
+	docstring tag_;
 	///
-	std::string attr_;
+	docstring attr_;
 };
 
 

commit 296df10ea019669d70ff743bac1278c44eb58067
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sat Aug 29 22:58:23 2020 +0200

    DocBook: fix float tags (was unduly overridden).
    
    The output was not valid for floats without title.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d3aa192..9085355 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,6 +6,11 @@
 
 cmake_minimum_required(VERSION 3.1.0)
 
+set(CMAKE_CXX_STANDARD 20)
+set(GNUWIN32_DIR D:/LyX/lyx-unstable/lyx-windows-deps-msvc2017)
+set(LYX_USE_QT "QT5")
+set(LYX_REQUIRE_SPELLCHECK true)
+
 set(LYX_PROJECT LyX)
 
 # Instruct cmake to not use gnu extensions,
diff --git a/autotests/export/docbook/basic.xml b/autotests/export/docbook/basic.xml
index 430611e..a4dc276 100644
--- a/autotests/export/docbook/basic.xml
+++ b/autotests/export/docbook/basic.xml
@@ -164,7 +164,7 @@ I am a second line of code.
 </tr>
 </tbody>
 </table>
-<table>
+<informaltable>
 <tbody>
 <tr>
 <td align='center' valign='top'>Table that has no caption 1</td>
@@ -182,7 +182,7 @@ I am a second line of code.
 <td align='center' valign='top'>Col 3, row 2</td>
 </tr>
 </tbody>
-</table>
+</informaltable>
 
 <para>Then, one figure: </para>
 <figure>
diff --git a/lib/layouts/stdfloats.inc b/lib/layouts/stdfloats.inc
index cd6614a..044fcb2 100644
--- a/lib/layouts/stdfloats.inc
+++ b/lib/layouts/stdfloats.inc
@@ -20,7 +20,6 @@ Float
 	UsesFloatPkg          false
 	ListCommand           listoftables
 	RefPrefix             tab
-	DocBookTag            table
 End
 
 
@@ -36,7 +35,6 @@ Float
 	UsesFloatPkg          false
 	ListCommand           listoffigures
 	RefPrefix             fig
-	DocBookTag            figure
 End
 
 
@@ -51,7 +49,6 @@ Float
 	IsPredefined          false
 	UsesFloatPkg          true
 	RefPrefix             alg
-	DocBookTag            figure # TODO: No DocBook tag really corresponds...
 End
 
 
diff --git a/src/Floating.cpp b/src/Floating.cpp
index d44afc3..19fbf5f 100644
--- a/src/Floating.cpp
+++ b/src/Floating.cpp
@@ -40,8 +40,7 @@ Floating::Floating(string const & type, string const & placement,
 	  usesfloatpkg_(usesfloat), ispredefined_(ispredefined),
 	  allowswide_(allowswide), allowssideways_(allowssideways),
 	  html_tag_(htmlTag), html_attrib_(htmlAttrib), html_style_(htmlStyle),
-	  docbook_tag_(docbookTag), docbook_attr_(docbookAttr),
-	  docbook_tag_type_(docbookTagType)
+	  docbook_attr_(docbookAttr), docbook_tag_type_(docbookTagType)
 {}
 
 
@@ -89,21 +88,17 @@ string const & Floating::docbookAttr() const
 }
 
 
-string const & Floating::docbookTag(bool hasTitle) const
+string Floating::docbookTag(bool hasTitle) const
 {
-	if (docbook_tag_.empty()) {
-		docbook_tag_ = "";
-		if (floattype_ == "figure") {
-			docbook_tag_ = hasTitle ? "figure" : "informalfigure";
-		} else if (floattype_ == "table") {
-			docbook_tag_ = hasTitle ? "table" : "informaltable";
-		} else if (floattype_ == "algorithm") {
-			// TODO: no good translation for now! Figures are the closest match, as they can contain text.
-			// Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer.
-			docbook_tag_ = "figure";
-		}
+	if (floattype_ == "figure") {
+		return hasTitle ? "figure" : "informalfigure";
+	} else if (floattype_ == "table") {
+		return hasTitle ? "table" : "informaltable";
+	} else if (floattype_ == "algorithm") {
+		// TODO: no good translation for now! Figures are the closest match, as they can contain text.
+		// Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer.
+		return "figure";
 	}
-	return docbook_tag_;
 }
 
 
diff --git a/src/Floating.h b/src/Floating.h
index 5cfea08..977958b 100644
--- a/src/Floating.h
+++ b/src/Floating.h
@@ -81,7 +81,7 @@ public:
 	/// tag type, defaults to "div"
 	std::string const & htmlTag() const;
 	///
-	std::string const & docbookTag(bool hasTitle = false) const;
+	std::string docbookTag(bool hasTitle = false) const;
 	///
 	std::string const & docbookAttr() const;
 	///
@@ -129,8 +129,8 @@ private:
 	mutable std::string defaultcssclass_;
 	///
 	docstring html_style_;
-	/// DocBook tag
-	mutable std::string docbook_tag_;
+	// There is no way to override the DocBook tag based on the layouts: half of it is determined by whether the float
+	// has a title or not, an information that is not available in the layouts.
 	/// attribute (mostly, role)
 	mutable std::string docbook_caption_;
 	/// caption tag (mostly, either caption or title)
diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp
index 24e06b5..86bcf9d 100644
--- a/src/insets/InsetFloat.cpp
+++ b/src/insets/InsetFloat.cpp
@@ -654,7 +654,7 @@ void docbookNoSubfigures(XMLStream & xs, OutputParams const & runparams, const I
 
 	xs << xml::StartTag(ftype.docbookTag(caption != nullptr), attr);
 	xs << xml::CR();
-	if (caption != nullptr) {
+	if (caption) {
 		xs << xml::StartTag(titleTag);
 		caption->getCaptionAsDocBook(xs, rpNoLabel);
 		xs << xml::EndTag(titleTag);
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 5847121..af30e8e 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -2429,7 +2429,7 @@ void InsetMathHull::docbook(XMLStream & xs, OutputParams const & runparams) cons
 	}
 
 	// DocBook also has <equation>, but it comes with a title.
-	// TODO: recognise \tag from amsmath?
+	// TODO: recognise \tag from amsmath? This would allow having <equation> with a proper title.
 
 	docstring attr;
 	for (row_type i = 0; i < nrows(); ++i) {

commit 85834ff127ffa5946e0ddd9562e3870a1e2d7c4d
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sat Aug 29 19:05:59 2020 +0200

    DocBook: improve equation formatting (new lines for block equations).

diff --git a/autotests/export/docbook/basic.lyx b/autotests/export/docbook/basic.lyx
index 1735dc4..fa98d65 100644
--- a/autotests/export/docbook/basic.lyx
+++ b/autotests/export/docbook/basic.lyx
@@ -185,7 +185,7 @@ noprefix "false"
 
 \begin_layout Standard
 Also, a formula with an user-defined macro that outputs well in LaTeX but
- cannot in MathML (hence replaced by picture): 
+ cannot in MathML: 
 \begin_inset Formula $\testmacro$
 \end_inset
 
diff --git a/autotests/export/docbook/basic.xml b/autotests/export/docbook/basic.xml
index 7980289..430611e 100644
--- a/autotests/export/docbook/basic.xml
+++ b/autotests/export/docbook/basic.xml
@@ -30,7 +30,7 @@
 </inlineequation>. </para>
 </blockquote>
 <para>Now, we're outside quotes.</para>
-<para><informalequation>
+<informalequation>
 <alt role='tex'>Formula!</alt>
  <m:math>
  
@@ -39,7 +39,8 @@
   </m:mrow>
  </m:mrow>
  </m:math>
-</informalequation><informalequation xml:id="eq.EQ.">
+</informalequation>
+<informalequation xml:id="eq.EQ.">
 <alt role='tex'>\text{I am a formula with a ref.}\label{eq:EQ.}</alt>
  <m:math>
  
@@ -50,9 +51,9 @@
   </m:mstyle>
  </m:mrow>
  </m:math>
-</informalequation></para>
+</informalequation>
 <para>See <xref linkend="sec.Sec-2kqgsdiflhqsdlifgjuzer-povtuizmvnuer-t-vmsrmfli--uh--a--rtpfuo----rtpc.m-ca-rgifzapeu-tvgz" />.</para>
-<para>Also, a formula with an user-defined macro that outputs well in LaTeX but cannot in MathML (hence replaced by picture): <inlineequation>
+<para>Also, a formula with an user-defined macro that outputs well in LaTeX but cannot in MathML: <inlineequation>
 <alt role='tex'>\testmacro</alt>
 <mathphrase>MathML export failed. Please report this as a bug.</mathphrase>
 </inlineequation>. </para>
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index e87ef88..aad1ccf 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3349,7 +3349,8 @@ std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
 
 	std::vector<docstring> generatedParagraphs;
 	odocstringstream os;
-	auto * xs = new XMLStream(os);
+	auto * xs = new XMLStream(os); // XMLStream has no copy constructor: to create a new object, the only solution
+	// is to hold a pointer to the XMLStream (xs = XMLStream(os) is not allowed once the first object is built).
 
 	// Parsing main loop.
 	for (pos_type i = initial; i < size(); ++i) {
@@ -3361,7 +3362,6 @@ std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
 		if (getInset(i) != nullptr && getInset(i)->lyxCode() == NEWLINE_CODE) {
 			generatedParagraphs.push_back(os.str());
 			os = odocstringstream();
-			// XMLStream has no copy constructor.
 			delete xs;
 			xs = new XMLStream(os);
 		}
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 800cbeb..5847121 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -2420,10 +2420,16 @@ void InsetMathHull::docbook(XMLStream & xs, OutputParams const & runparams) cons
 	docstring name;
 	if (getType() == hullSimple)
 		name = from_ascii("inlineequation");
-	else
+	else {
+		// This is a block equation, always have <informalequation> on its own line.
+		if (!xs.isLastTagCR())
+			xs << xml::CR();
+
 		name = from_ascii("informalequation");
+	}
 
 	// DocBook also has <equation>, but it comes with a title.
+	// TODO: recognise \tag from amsmath?
 
 	docstring attr;
 	for (row_type i = 0; i < nrows(); ++i) {
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 9d51853..e609f39 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -446,10 +446,16 @@ void makeParagraph(
 			special_case = true;
 	}
 
+	size_t nInsets = std::distance(par->insetList().begin(), par->insetList().end());
+
 	// Plain layouts must be ignored.
-	if (!special_case && buf.params().documentClass().isPlainLayout(par->layout()) && !runparams.docbook_force_pars)
-		special_case = true;
-	// TODO: Could get rid of this with a DocBook equivalent to htmlisblock?
+	special_case |= buf.params().documentClass().isPlainLayout(par->layout()) && !runparams.docbook_force_pars;
+	// Equations do not deserve their own paragraph (DocBook allows them outside paragraphs).
+	special_case |= nInsets == par->size() && std::all_of(par->insetList().begin(), par->insetList().end(), [](InsetList::Element inset) {
+		return inset.inset && inset.inset->asInsetMath();
+	});
+
+	// TODO: Could get rid of this with a DocBook equivalent to htmlisblock? Not for all cases, unfortunately... See above for those that have been determined not to be allowable for this potential refactoring.
 	if (!special_case && par->size() == 1 && par->getInset(0)) {
 		Inset const * firstInset = par->getInset(0);
 
@@ -460,10 +466,6 @@ void makeParagraph(
 		if (!special_case && firstInset->asInsetCommand())
 			special_case = firstInset->asInsetCommand()->params().getCmdName() == "bibtex";
 
-		// Equations do not deserve their own paragraph (DocBook allows them outside paragraphs).
-		if (!special_case && firstInset->asInsetMath())
-			special_case = true;
-
 		// ERTs are in comments, not paragraphs.
 		if (!special_case && firstInset->lyxCode() == lyx::ERT_CODE)
 			special_case = true;

commit b980018e908b823f485710a8b3c98f61590fbd26
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sat Aug 29 18:40:31 2020 +0200

    DocBook: fix indentation for section titles (including stars).

diff --git a/autotests/export/docbook/basic.lyx b/autotests/export/docbook/basic.lyx
index 0bd87ce..1735dc4 100644
--- a/autotests/export/docbook/basic.lyx
+++ b/autotests/export/docbook/basic.lyx
@@ -1,5 +1,5 @@
-#LyX 2.4 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 598
 \begin_document
 \begin_header
 \save_transient_properties true
@@ -9,11 +9,11 @@
 \newcommand{\testmacro}{\ensuremath{\operatorname{testmacro}}}
 \end_preamble
 \use_default_options true
-\maintain_unincluded_children false
+\maintain_unincluded_children no
 \language english
 \language_package default
-\inputencoding auto
-\fontencoding global
+\inputencoding auto-legacy
+\fontencoding auto
 \font_roman "default" "default"
 \font_sans "default" "default"
 \font_typewriter "default" "default"
@@ -21,7 +21,9 @@
 \font_default_family default
 \use_non_tex_fonts false
 \font_sc false
-\font_osf false
+\font_roman_osf false
+\font_sans_osf false
+\font_typewriter_osf false
 \font_sf_scale 100 100
 \font_tt_scale 100 100
 \use_microtype false
@@ -56,6 +58,7 @@
 \justification true
 \use_refstyle 1
 \use_minted 0
+\use_lineno 0
 \index Index
 \shortcut idx
 \color #008000
@@ -75,11 +78,15 @@
 \papercolumns 1
 \papersides 1
 \paperpagestyle default
+\tablestyle default
 \tracking_changes false
 \output_changes false
+\change_bars false
+\postpone_fragile_content false
 \html_math_output 0
 \html_css_as_file 0
 \html_be_strict false
+\docbook_table_output 0
 \end_header
 
 \begin_body
@@ -140,6 +147,10 @@ I am a quote
 \end_layout
 
 \begin_layout Standard
+Now, we're outside quotes.
+\end_layout
+
+\begin_layout Standard
 \begin_inset Formula 
 \[
 Formula!
@@ -386,6 +397,8 @@ Now, three tables:
 
 \begin_layout Standard
 \begin_inset Float table
+placement document
+alignment document
 wide false
 sideways false
 status open
@@ -511,6 +524,8 @@ I am a table caption below the table.
 
 \begin_layout Standard
 \begin_inset Float table
+placement document
+alignment document
 wide false
 sideways false
 status open
@@ -636,6 +651,8 @@ Col 3, row 2
 
 \begin_layout Standard
 \begin_inset Float table
+placement document
+alignment document
 wide false
 sideways false
 status open
@@ -753,6 +770,8 @@ Then, one figure:
 
 \begin_layout Standard
 \begin_inset Float figure
+placement document
+alignment document
 wide false
 sideways false
 status open
diff --git a/autotests/export/docbook/basic.xml b/autotests/export/docbook/basic.xml
index 6f4a828..7980289 100644
--- a/autotests/export/docbook/basic.xml
+++ b/autotests/export/docbook/basic.xml
@@ -29,6 +29,7 @@
  </m:math>
 </inlineequation>. </para>
 </blockquote>
+<para>Now, we're outside quotes.</para>
 <para><informalequation>
 <alt role='tex'>Formula!</alt>
  <m:math>
@@ -72,22 +73,37 @@
 </section>
 <section>
 <title>I am the third section and I have fun with lists</title>
-<orderedlist><listitem>First item. 
-<br />
-Second line of the first item, after a line break. </listitem></orderedlist>
-<orderedlist><listitem>Second item. </listitem></orderedlist>
-<itemizedlist><listitem>Item has no order (1). </listitem></itemizedlist>
-<itemizedlist><listitem>Item has no order (2). </listitem></itemizedlist>
-<variablelist><listitem><varlistentry>
-
-Word description<!-- Output Error: Closing tag `listitem' when other tags are open, namely: -->
-<!-- Output Error: varlistentry -->
-</varlistentry></listitem></variablelist>
-<variablelist><listitem><varlistentry>
-
-Sentence meaning<!-- Output Error: Closing tag `listitem' when other tags are open, namely: -->
-<!-- Output Error: varlistentry -->
-</varlistentry></listitem></variablelist>
+<orderedlist>
+<listitem>
+<para>First item. </para>
+<para>Second line of the first item, after a line break. </para>
+</listitem>
+<listitem>
+<para>Second item. </para>
+</listitem>
+</orderedlist>
+<itemizedlist>
+<listitem>
+<para>Item has no order (1). </para>
+</listitem>
+<listitem>
+<para>Item has no order (2). </para>
+</listitem>
+</itemizedlist>
+<variablelist>
+<varlistentry>
+<term>Word</term>
+<listitem>
+<para>description</para>
+</listitem>
+</varlistentry>
+<varlistentry>
+<term>Sentence</term>
+<listitem>
+<para>meaning</para>
+</listitem>
+</varlistentry>
+</variablelist>
 </section>
 <section>
 <title>I am the fourth section and I deal with formatting. </title>
@@ -95,9 +111,11 @@ Sentence meaning<!-- Output Error: Closing tag `listitem' when other tags are op
 <para><programlisting>I am some code. 
 I am a second line of code. 
 </programlisting>I am no more code. </para>
-<para>This line has inline code. <code>This has typewriter font</code><footnote><para>I repeat that in a footnote.</para>
+<para>This line has inline code. <code>This has typewriter font</code><footnote>
+<para>I repeat that in a footnote.</para>
 </footnote>. </para>
-<para>On the other hand, <footnote><para>this footnote</para>
+<para>On the other hand, <footnote>
+<para>this footnote</para>
 <para>has multiple </para>
 <para>paragraphs.</para>
 </footnote>. </para>
@@ -145,7 +163,7 @@ I am a second line of code.
 </tr>
 </tbody>
 </table>
-<informaltable>
+<table>
 <tbody>
 <tr>
 <td align='center' valign='top'>Table that has no caption 1</td>
@@ -163,7 +181,8 @@ I am a second line of code.
 <td align='center' valign='top'>Col 3, row 2</td>
 </tr>
 </tbody>
-</informaltable>
+</table>
+
 <para>Then, one figure: </para>
 <figure>
 <title>Caption.</title>
@@ -334,5 +353,4 @@ I am a second line of code.
 </author>
 </authorgroup>
 </biblioentry>
-</bibliography>
-</article>
\ No newline at end of file
+</bibliography></article>
\ No newline at end of file
diff --git a/lib/layouts/stdsections.inc b/lib/layouts/stdsections.inc
index fa42eac..30b64ea 100644
--- a/lib/layouts/stdsections.inc
+++ b/lib/layouts/stdsections.inc
@@ -7,7 +7,7 @@
 # commands that are useful for article-like document classes, but not
 # for letters.
 
-Format 82
+Format 84
 
 Style Part
 	Category              Sectioning
@@ -40,6 +40,7 @@ Style Part
 	EndFont
 	HTMLTag               h1
 	DocBookTag            title
+	DocBookTagType        paragraph
 	DocBookSectionTag     part
 	DocBookForceAbstractTag	partintro
 End
@@ -75,6 +76,7 @@ Style Chapter
 	EndFont
 	HTMLTag               h1
 	DocBookTag            title
+	DocBookTagType        paragraph
 	DocBookSectionTag     chapter
 End
 
@@ -108,6 +110,7 @@ Style Section
 	EndFont
 	HTMLTag               h2
 	DocBookTag            title
+	DocBookTagType        paragraph
 	DocBookSectionTag     section
 End
 

commit 259b5569fc39a08600593fda9ac69583ed921e13
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Thu Aug 27 00:52:06 2020 +0200

    DocBook: rewrite makeListEnvironment.

diff --git a/autotests/export/docbook/lists.lyx b/autotests/export/docbook/lists.lyx
index f4a58c2..1c1e88b 100644
--- a/autotests/export/docbook/lists.lyx
+++ b/autotests/export/docbook/lists.lyx
@@ -102,11 +102,71 @@ Second item on two lines
 I'm the second line
 \end_layout
 
+\begin_layout Itemize
+Third item
+\end_layout
+
 \begin_layout Standard
-\begin_inset Note Note
-status collapsed
+A simple enumerated list: 
+\end_layout
+
+\begin_layout Enumerate
+First item
+\end_layout
+
+\begin_layout Enumerate
+Second item on two lines
+\begin_inset Newline newline
+\end_inset
+
+I'm the second line
+\end_layout
+
+\begin_layout Standard
+A simple description list: 
+\end_layout
+
+\begin_layout Description
+Word description
+\end_layout
+
+\begin_layout Description
+Sentence meaning
+\end_layout
+
+\begin_layout Standard
+Nested lists:
+\end_layout
+
+\begin_layout Itemize
+First item
+\end_layout
+
+\begin_deeper
+\begin_layout Itemize
+First first item
+\end_layout
+
+\begin_layout Itemize
+First second item
+\end_layout
+
+\end_deeper
+\begin_layout Itemize
+Second item
+\end_layout
+
+\begin_deeper
+\begin_layout Itemize
+Second first item
+\end_layout
+
+\begin_layout Itemize
+Second second item
+\end_layout
 
-\begin_layout Plain Layout
+\end_deeper
+\begin_layout Standard
 A complex list:
 \end_layout
 
@@ -123,7 +183,47 @@ First first item
 First second item
 \end_layout
 
-\begin_layout Plain Layout
+\begin_layout Standard
+Text after first item
+\end_layout
+
+\end_deeper
+\begin_layout Itemize
+Second item
+\end_layout
+
+\begin_deeper
+\begin_layout Itemize
+Second first item
+\end_layout
+
+\begin_layout Itemize
+Second second item
+\end_layout
+
+\begin_layout Standard
+Text after second item
+\end_layout
+
+\end_deeper
+\begin_layout Standard
+A very complex list:
+\end_layout
+
+\begin_layout Itemize
+First item
+\end_layout
+
+\begin_deeper
+\begin_layout Itemize
+First first item
+\end_layout
+
+\begin_layout Itemize
+First second item
+\end_layout
+
+\begin_layout Standard
 Text after first item
 \end_layout
 
@@ -141,15 +241,32 @@ Second first item
 Second second item
 \end_layout
 
-\begin_layout Plain Layout
+\begin_layout Standard
 Text after second item
 \end_layout
 
 \end_deeper
-\end_inset
+\begin_layout Standard
+Nested description lists: 
+\end_layout
 
+\begin_layout Description
+LyX:
+\end_layout
 
+\begin_deeper
+\begin_layout Description
+lyx16 LyX 1.6 file format (lyx2lyx)
+\end_layout
+
+\begin_layout Description
+lyx21 LyX 2.1 file format (lyx2lyx)
 \end_layout
 
+\begin_layout Description
+xhtml LyXHTML (native LyX HTML export)
+\end_layout
+
+\end_deeper
 \end_body
 \end_document
diff --git a/autotests/export/docbook/lists.xml b/autotests/export/docbook/lists.xml
index d7b24f6..6812230 100644
--- a/autotests/export/docbook/lists.xml
+++ b/autotests/export/docbook/lists.xml
@@ -12,5 +12,141 @@
 <para>Second item on two lines</para>
 <para>I'm the second line</para>
 </listitem>
+<listitem>
+<para>Third item</para>
+</listitem>
+</itemizedlist>
+<para>A simple enumerated list: </para>
+<orderedlist>
+<listitem>
+<para>First item</para>
+</listitem>
+<listitem>
+<para>Second item on two lines</para>
+<para>I'm the second line</para>
+</listitem>
+</orderedlist>
+<para>A simple description list: </para>
+<variablelist>
+<varlistentry>
+<term>Word</term>
+<listitem>
+<para>description</para>
+</listitem>
+</varlistentry>
+<varlistentry>
+<term>Sentence</term>
+<listitem>
+<para>meaning</para>
+</listitem>
+</varlistentry>
+</variablelist>
+<para>Nested lists:</para>
+<itemizedlist>
+<listitem>
+<para>First item</para>
+<itemizedlist>
+<listitem>
+<para>First first item</para>
+</listitem>
+<listitem>
+<para>First second item</para>
+</listitem>
+</itemizedlist>
+</listitem>
+<listitem>
+<para>Second item</para>
+<itemizedlist>
+<listitem>
+<para>Second first item</para>
+</listitem>
+<listitem>
+<para>Second second item</para>
+</listitem>
+</itemizedlist>
+</listitem>
+</itemizedlist>
+<para>A complex list:</para>
+<itemizedlist>
+<listitem>
+<para>First item</para>
+<itemizedlist>
+<listitem>
+<para>First first item</para>
+</listitem>
+<listitem>
+<para>First second item</para>
+</listitem>
+</itemizedlist>
+<para>Text after first item</para>
+</listitem>
+<listitem>
+<para>Second item</para>
+<itemizedlist>
+<listitem>
+<para>Second first item</para>
+</listitem>
+<listitem>
+<para>Second second item</para>
+</listitem>
+</itemizedlist>
+<para>Text after second item</para>
+</listitem>
+</itemizedlist>
+<para>A very complex list:</para>
+<itemizedlist>
+<listitem>
+<para>First item</para>
+<itemizedlist>
+<listitem>
+<para>First first item</para>
+</listitem>
+<listitem>
+<para>First second item</para>
+</listitem>
 </itemizedlist>
+<para>Text after first item</para>
+</listitem>
+<listitem>
+<para>Second item</para>
+<orderedlist>
+<listitem>
+<para>Second first item</para>
+</listitem>
+<listitem>
+<para>Second second item</para>
+</listitem>
+</orderedlist>
+<para>Text after second item</para>
+</listitem>
+</itemizedlist>
+<para>Nested description lists: </para>
+<variablelist>
+<varlistentry>
+<term>LyX:</term>
+<listitem>
+
+<variablelist>
+<varlistentry>
+<term>lyx16</term>
+<listitem>
+<para>LyX 1.6 file format (lyx2lyx)</para>
+</listitem>
+</varlistentry>
+<varlistentry>
+<term>lyx21</term>
+<listitem>
+<para>LyX 2.1 file format (lyx2lyx)</para>
+</listitem>
+</varlistentry>
+<varlistentry>
+<term>xhtml</term>
+<listitem>
+<para>LyXHTML (native LyX HTML export)</para>
+</listitem>
+</varlistentry>
+</variablelist>
+</listitem>
+</varlistentry>
+</variablelist>
 </article>
\ No newline at end of file
diff --git a/lib/layouts/stdlists.inc b/lib/layouts/stdlists.inc
index c0b346d..d05e896 100644
--- a/lib/layouts/stdlists.inc
+++ b/lib/layouts/stdlists.inc
@@ -43,9 +43,7 @@ Style Itemize
 			Color latex
 		EndFont
 	EndArgument
-	DocBookWrapperTag     itemizedlist
-	DocBookWrapperMergeWithPrevious    true
-	DocBookTag            NONE
+	DocBookTag            itemizedlist
 	DocBookItemTag        listitem
 	DocBookItemInnerTag   para
 End
@@ -134,6 +132,7 @@ Style Description
 	DocBookItemTag        listitem
 	DocBookItemInnerTag   para
 	DocBookItemLabelTag   term
+	DocBookItemLabelTagType   paragraph
 End
 
 
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 356de07..9d51853 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -225,7 +225,7 @@ void closeBlockTag(XMLStream & xs, const std::string & tag)
 
 void openTag(XMLStream & xs, const std::string & tag, const std::string & attr, const std::string & tagtype)
 {
-	if (tag.empty() || tag == "NONE")
+	if (tag.empty() || tag == "NONE") // Common check to be performed elsewhere, if it was not here.
 		return;
 
 	if (tag == "para" || tagtype == "paragraph") // Special case for <para>: always considered as a paragraph.
@@ -275,7 +275,7 @@ void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar
 		Layout const & prevlay = prevpar->layout();
 		if (prevlay.docbookwrappertag() != "NONE") {
 			openWrapper = prevlay.docbookwrappertag() == lay.docbookwrappertag()
-					&& !lay.docbookwrappermergewithprevious();
+			              && !lay.docbookwrappermergewithprevious();
 		}
 	}
 
@@ -308,32 +308,8 @@ void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpa
 	if (nextpar != nullptr) {
 		Layout const & nextlay = nextpar->layout();
 		if (nextlay.docbookwrappertag() != "NONE") {
-			if (nextpar->getDepth() == par->getDepth()) {
-				// Same depth: the basic condition applies.
-				closeWrapper = nextlay.docbookwrappertag() == lay.docbookwrappertag()
-				               && !nextlay.docbookwrappermergewithprevious();
-			} else if (nextpar->getDepth() > par->getDepth()) {
-				// The next paragraph is deeper: no need to close the wrapper, only to open it (cf. openParTag).
-				closeWrapper = 0;
-			} else {
-				// This paragraph is deeper than the next one: close the wrapper,
-				// disregarding docbookwrappermergewithprevious.
-				// Hypothesis: nextlay.docbookwrappertag() == lay.docbookwrappertag(). TODO: THIS IS WRONG! Loop back until a layout with the right depth is found?
-				closeWrapper = 1L + (long long) par->getDepth() - (long long) nextpar->getDepth(); // > 0, as nextpar->getDepth() < par->getDepth()
-			}
-		} else {
-			if (nextpar->getDepth() == par->getDepth()) {
-				// This is not wrapped: this must be the rest of the item, still within the wrapper.
-				closeWrapper = 1;
-			} else if (nextpar->getDepth() > par->getDepth()) {
-				// The next paragraph is deeper: no need to close the wrapper, only to open it (cf. openParTag).
-				closeWrapper = 0;
-			} else {
-				// This paragraph is deeper than the next one: close the wrapper,
-				// disregarding docbookwrappermergewithprevious.
-				// Hypothesis: nextlay.docbookwrappertag() == lay.docbookwrappertag(). TODO: THIS IS WRONG! Loop back until a layout with the right depth is found?
-				closeWrapper = 1L + (long long) par->getDepth() - (long long) nextpar->getDepth(); // > 0, as nextpar->getDepth() < par->getDepth()
-			}
+			closeWrapper = nextlay.docbookwrappertag() == lay.docbookwrappertag()
+			               && !nextlay.docbookwrappermergewithprevious();
 		}
 	}
 
@@ -564,9 +540,7 @@ void makeEnvironment(Text const &text,
 				// Usual cases: maybe there is something specified at the layout level. Highly unlikely, though.
 				docstring const lbl = par->params().labelString();
 
-				if (lbl.empty()) {
-					xs << xml::CR();
-				} else {
+				if (!lbl.empty()) {
 					openLabelTag(xs, style);
 					xs << lbl;
 					closeLabelTag(xs, style);
@@ -628,7 +602,6 @@ ParagraphList::const_iterator findEndOfEnvironment(
 		ParagraphList::const_iterator const & pend)
 {
 	// Copy-paste from XHTML. Should be factored out at some point...
-
 	ParagraphList::const_iterator p = pstart;
 	Layout const & bstyle = p->layout();
 	size_t const depth = p->params().depth();
@@ -662,95 +635,84 @@ ParagraphList::const_iterator makeListEnvironment(Text const &text,
 												  Buffer const &buf,
 		                                          XMLStream &xs,
 		                                          OutputParams const &runparams,
-		                                          ParagraphList::const_iterator const & par)
+		                                          ParagraphList::const_iterator const & begin)
 {
+	auto par = begin;
 	auto const end = text.paragraphs().end();
+	auto const envend = findEndOfEnvironment(par, end);
 
-	// Output the opening tag for this environment, but only if it has not been previously opened (condition
-	// implemented in openParTag).
-	auto prevpar = text.paragraphs().getParagraphBefore(par);
-	openParTag(xs, &*par, prevpar); // TODO: switch in layout for par/block?
+	// Output the opening tag for this environment.
+	Layout const & envstyle = par->layout();
+	openTag(xs, envstyle.docbookwrappertag(), envstyle.docbookwrapperattr(), envstyle.docbookwrappertagtype());
+	openTag(xs, envstyle.docbooktag(), envstyle.docbookattr(), envstyle.docbooktagtype());
 
-	// Generate the contents of this environment. There is a special case if this is like some environment.
-	Layout const & style = par->layout();
-	if (style.latextype == LATEX_COMMAND) {
-		// Nothing to do (otherwise, infinite loops).
-	} else if (style.latextype == LATEX_ENVIRONMENT ||
-			style.latextype == LATEX_LIST_ENVIRONMENT ||
-			style.latextype == LATEX_ITEM_ENVIRONMENT) {
-		// Open a wrapper tag if needed.
-		if (style.docbookitemwrappertag() != "NONE")
-			openTag(xs, style.docbookitemwrappertag(), style.docbookitemwrapperattr(), style.docbookitemwrappertagtype());
+	// Handle the content of the list environment, item by item.
+	while (par != envend) {
+		Layout const & style = par->layout();
+
+		// Open the item wrapper.
+		openTag(xs, style.docbookitemwrappertag(), style.docbookitemwrapperattr(), style.docbookitemwrappertagtype());
 
 		// Generate the label, if need be. If it is taken from the text, sep != 0 and corresponds to the first
 		// character after the label.
 		pos_type sep = 0;
 		if (style.labeltype != LABEL_NO_LABEL && style.docbookitemlabeltag() != "NONE") {
-			// At least one condition must be met:
-			//  - this environment is not a list
-			//  - if this is a list, the label must not be manual (i.e. it must be taken from the layout)
-			if (style.latextype != LATEX_LIST_ENVIRONMENT || style.labeltype != LABEL_MANUAL) {
+			if (style.labeltype == LABEL_MANUAL) {
+				// Only variablelist gets here (or similar items defined as an extension in the layout).
+				openLabelTag(xs, style);
+				sep = 1 + par->firstWordDocBook(xs, runparams);
+				closeLabelTag(xs, style);
+			} else {
 				// Usual cases: maybe there is something specified at the layout level. Highly unlikely, though.
 				docstring const lbl = par->params().labelString();
 
-				if (lbl.empty()) {
-					xs << xml::CR();
-				} else {
+				if (!lbl.empty()) {
 					openLabelTag(xs, style);
 					xs << lbl;
 					closeLabelTag(xs, style);
 				}
-			} else {
-				// Only variablelist gets here (or similar items defined as an extension in the layout).
-				openLabelTag(xs, style);
-				sep = par->firstWordDocBook(xs, runparams);
-				closeLabelTag(xs, style);
 			}
 		}
 
-		// Maybe the item is completely empty, i.e. if the first word ends at the end of the current paragraph
-		// AND if the next paragraph doesn't have the same depth (if there is such a paragraph).
-		// Common case: there is only the first word on the line, but there is a nested list instead
-		// of more text.
-		bool emptyItem = false;
-		if (sep == par->size()) { // If the separator is already at the end of this paragraph...
-			auto next_par = par;
-			++next_par;
-			if (next_par == text.paragraphs().end()) // There is no next paragraph.
-				emptyItem = true;
-			else // There is a next paragraph: check depth.
-				emptyItem = par->params().depth() >= next_par->params().depth();
-		}
-
-		if (emptyItem) {
-			// Avoid having an empty item, this is not valid DocBook. A single character is enough to force
-			// generation of a full <para>.
-			// TODO: this always worked only by magic...
-			xs << ' ';
-		} else {
-			// Generate the rest of the paragraph, if need be. Open as many inner tags as necessary.
-			auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(std::distance(text.paragraphs().begin(), par)), sep);
-			auto p = pars.begin();
-			while (true) {
-				xs << XMLStream::ESCAPE_NONE << *p;
-				++p;
-				if (p != pars.end()) {
-					closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
-					openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(), par->layout().docbookiteminnertagtype());
-				} else
-					break;
+		// Open the item (after the wrapper and the label).
+		openTag(xs, style.docbookitemtag(), style.docbookitemattr(), style.docbookitemtagtype());
+
+		// Generate the content of the item.
+		if (sep < par->size()) {
+			auto pars = par->simpleDocBookOnePar(buf, runparams,
+			                                     text.outerFont(std::distance(text.paragraphs().begin(), par)), sep);
+			for (auto &p : pars) {
+				openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(),
+				        par->layout().docbookiteminnertagtype());
+				xs << XMLStream::ESCAPE_NONE << p;
+				closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
 			}
+		} else {
+			// DocBook doesn't like emptiness.
+			openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(),
+			        par->layout().docbookiteminnertagtype());
+			closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
 		}
-	} else {
-		makeAny(text, buf, xs, runparams, par);
+
+		// If the next item is deeper, it must go entirely within this item (do it recursively).
+		// By construction, with findEndOfEnvironment, depth can only stay constant or increase, never decrease.
+		depth_type currentDepth = par->getDepth();
+		++par;
+		while (par != envend && par->getDepth() != currentDepth)
+			par = makeAny(text, buf, xs, runparams, par);
+		// Usually, this loop only makes one iteration, except in complex scenarios, like an item with a paragraph,
+		// a list, and another paragraph; or an item with two types of list (itemise then enumerate, for instance).
+
+		// Close the item.
+		closeTag(xs, style.docbookitemtag(), style.docbookitemtagtype());
+		closeTag(xs, style.docbookitemwrappertag(), style.docbookitemwrappertagtype());
 	}
 
-	// Close the environment.
-	auto nextpar = par;
-	++nextpar;
-	closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr); // TODO: switch in layout for par/block?
+	// Close this environment in exactly the same way as it was opened.
+	closeTag(xs, envstyle.docbooktag(), envstyle.docbooktagtype());
+	closeTag(xs, envstyle.docbookwrappertag(), envstyle.docbookwrappertagtype());
 
-	return nextpar;
+	return envend;
 }
 
 
diff --git a/src/xml.cpp b/src/xml.cpp
index 2f49667..0daa9d8 100644
--- a/src/xml.cpp
+++ b/src/xml.cpp
@@ -185,6 +185,12 @@ void XMLStream::writeError(docstring const &s)
 }
 
 
+XMLStream::TagPtr XMLStream::getLastStackTag()
+{
+	return tag_stack_.back();
+}
+
+
 bool XMLStream::closeFontTags()
 {
 	if (isTagPending(xml::parsep_tag))
diff --git a/src/xml.h b/src/xml.h
index cdc3b56..bbf5b58 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -127,7 +127,6 @@ private:
 	// own these pointers and how they will be deleted, so we use shared
 	// pointers.
 	///
-	typedef std::shared_ptr<xml::StartTag> TagPtr;
 	typedef std::deque<TagPtr> TagDeque;
 	///
 	template <typename T>

commit b77cf07fda6f1bd590f83cc1150135a2f900a7e7
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sat Aug 29 03:03:16 2020 +0200

    DocBook: start splitting environment handling in two, to have proper things for lists.

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 12c0089..356de07 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -370,12 +370,11 @@ void closeItemTag(XMLStream & xs, Layout const & lay)
 }
 
 
-void makeAny(
-		Text const &,
-		Buffer const &,
-		XMLStream &,
-		OutputParams const &,
-		ParagraphList::const_iterator);
+ParagraphList::const_iterator makeAny(Text const &,
+		                              Buffer const &,
+		                              XMLStream &,
+		                              OutputParams const &,
+		                              ParagraphList::const_iterator);
 
 
 void makeBibliography(
@@ -664,7 +663,6 @@ ParagraphList::const_iterator makeListEnvironment(Text const &text,
 		                                          XMLStream &xs,
 		                                          OutputParams const &runparams,
 		                                          ParagraphList::const_iterator const & par)
->>>>>>> be6480e59c... DocBook: same refactoring for docbookSimpleAllParagraphs.
 {
 	auto const end = text.paragraphs().end();
 
@@ -751,6 +749,8 @@ ParagraphList::const_iterator makeListEnvironment(Text const &text,
 	auto nextpar = par;
 	++nextpar;
 	closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr); // TODO: switch in layout for par/block?
+
+	return nextpar;
 }
 
 
@@ -791,10 +791,12 @@ ParagraphList::const_iterator makeAny(Text const &text,
 		makeCommand(text, buf, xs, runparams, par);
 		break;
 	case LATEX_ENVIRONMENT:
+		makeEnvironment(text, buf, xs, runparams, par);
+		break;
 	case LATEX_LIST_ENVIRONMENT:
 	case LATEX_ITEM_ENVIRONMENT:
-		makeEnvironment(buf, xs, ourparams, text, par);
-		break;
+		// Only case when makeAny() might consume more than one paragraph.
+		return makeListEnvironment(text, buf, xs, runparams, par);
 	case LATEX_PARAGRAPH:
 		makeParagraph(text, buf, xs, runparams, par);
 		break;
@@ -802,6 +804,8 @@ ParagraphList::const_iterator makeAny(Text const &text,
 		makeBibliography(text, buf, xs, runparams, par);
 		break;
 	}
+	++par;
+	return par;
 }
 
 
@@ -1208,7 +1212,7 @@ void docbookParagraphs(Text const &text,
 		}
 
 		// Generate this paragraph.
-		makeAny(text, buf, xs, ourparams, par);
+		par = makeAny(text, buf, xs, ourparams, par);
 	}
 
 	// If need be, close <section>s, but only at the end of the document (otherwise, dealt with at the beginning

commit 71dd6683f53796ff21143654f45533ea0c3a1124
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sat Aug 29 03:46:30 2020 +0200

    DocBook: make all make* functions have the same argument order.

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index ff47aa6..12c0089 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -378,11 +378,11 @@ void makeAny(
 		ParagraphList::const_iterator);
 
 
-void makeParagraphBibliography(
+void makeBibliography(
+		Text const & text,
 		Buffer const & buf,
 		XMLStream & xs,
 		OutputParams const & runparams,
-		Text const & text,
 		ParagraphList::const_iterator const & par)
 {
 	// If this is the first paragraph in a bibliography, open the bibliography tag.
@@ -433,10 +433,10 @@ void makeParagraphBibliography(
 
 
 void makeParagraph(
+		Text const & text,
 		Buffer const & buf,
 		XMLStream & xs,
 		OutputParams const & runparams,
-		Text const & text,
 		ParagraphList::const_iterator const & par)
 {
 	auto const begin = text.paragraphs().begin();
@@ -531,10 +531,10 @@ void makeParagraph(
 }
 
 
-void makeEnvironment(Buffer const &buf,
+void makeEnvironment(Text const &text,
+					 Buffer const &buf,
                      XMLStream &xs,
                      OutputParams const &runparams,
-                     Text const &text,
                      ParagraphList::const_iterator const & par)
 {
 	// TODO: simplify me!
@@ -659,10 +659,10 @@ ParagraphList::const_iterator findEndOfEnvironment(
 }
 
 
-ParagraphList::const_iterator makeListEnvironment(Buffer const &buf,
+ParagraphList::const_iterator makeListEnvironment(Text const &text,
+												  Buffer const &buf,
 		                                          XMLStream &xs,
 		                                          OutputParams const &runparams,
-		                                          Text const &text,
 		                                          ParagraphList::const_iterator const & par)
 >>>>>>> be6480e59c... DocBook: same refactoring for docbookSimpleAllParagraphs.
 {
@@ -755,10 +755,10 @@ ParagraphList::const_iterator makeListEnvironment(Buffer const &buf,
 
 
 void makeCommand(
+		Text const & text,
 		Buffer const & buf,
 		XMLStream & xs,
 		OutputParams const & runparams,
-		Text const & text,
 		ParagraphList::const_iterator const & par)
 {
 	// Unlike XHTML, no need for labels, as they are handled by DocBook tags.
@@ -780,16 +780,15 @@ void makeCommand(
 }
 
 
-void makeAny(
-		Text const &text,
-		Buffer const &buf,
-		XMLStream &xs,
-		OutputParams const &ourparams,
-		ParagraphList::const_iterator par)
+ParagraphList::const_iterator makeAny(Text const &text,
+		                              Buffer const &buf,
+		                              XMLStream &xs,
+		                              OutputParams const &runparams,
+		                              ParagraphList::const_iterator par)
 {
 	switch (par->layout().latextype) {
 	case LATEX_COMMAND:
-		makeCommand(buf, xs, ourparams, text, par);
+		makeCommand(text, buf, xs, runparams, par);
 		break;
 	case LATEX_ENVIRONMENT:
 	case LATEX_LIST_ENVIRONMENT:
@@ -797,10 +796,10 @@ void makeAny(
 		makeEnvironment(buf, xs, ourparams, text, par);
 		break;
 	case LATEX_PARAGRAPH:
-		makeParagraph(buf, xs, ourparams, text, par);
+		makeParagraph(text, buf, xs, runparams, par);
 		break;
 	case LATEX_BIB_ENVIRONMENT:
-		makeParagraphBibliography(buf, xs, ourparams, text, par);
+		makeBibliography(text, buf, xs, runparams, par);
 		break;
 	}
 }

commit 5e8b0cd037e40d4fe227667c14d64266a2898612
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sat Aug 29 02:55:47 2020 +0200

    DocBook: partially remove use of bpit/epit in docbookParagraphs and docbookSimpleAllParagraphs.
    
    This will help with the next refactoring to be much cleaner (only work with iterators, don't maintain twice the same information).

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 0dc5257..ff47aa6 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -308,8 +308,32 @@ void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpa
 	if (nextpar != nullptr) {
 		Layout const & nextlay = nextpar->layout();
 		if (nextlay.docbookwrappertag() != "NONE") {
-			closeWrapper = nextlay.docbookwrappertag() == lay.docbookwrappertag()
-					&& !nextlay.docbookwrappermergewithprevious();
+			if (nextpar->getDepth() == par->getDepth()) {
+				// Same depth: the basic condition applies.
+				closeWrapper = nextlay.docbookwrappertag() == lay.docbookwrappertag()
+				               && !nextlay.docbookwrappermergewithprevious();
+			} else if (nextpar->getDepth() > par->getDepth()) {
+				// The next paragraph is deeper: no need to close the wrapper, only to open it (cf. openParTag).
+				closeWrapper = 0;
+			} else {
+				// This paragraph is deeper than the next one: close the wrapper,
+				// disregarding docbookwrappermergewithprevious.
+				// Hypothesis: nextlay.docbookwrappertag() == lay.docbookwrappertag(). TODO: THIS IS WRONG! Loop back until a layout with the right depth is found?
+				closeWrapper = 1L + (long long) par->getDepth() - (long long) nextpar->getDepth(); // > 0, as nextpar->getDepth() < par->getDepth()
+			}
+		} else {
+			if (nextpar->getDepth() == par->getDepth()) {
+				// This is not wrapped: this must be the rest of the item, still within the wrapper.
+				closeWrapper = 1;
+			} else if (nextpar->getDepth() > par->getDepth()) {
+				// The next paragraph is deeper: no need to close the wrapper, only to open it (cf. openParTag).
+				closeWrapper = 0;
+			} else {
+				// This paragraph is deeper than the next one: close the wrapper,
+				// disregarding docbookwrappermergewithprevious.
+				// Hypothesis: nextlay.docbookwrappertag() == lay.docbookwrappertag(). TODO: THIS IS WRONG! Loop back until a layout with the right depth is found?
+				closeWrapper = 1L + (long long) par->getDepth() - (long long) nextpar->getDepth(); // > 0, as nextpar->getDepth() < par->getDepth()
+			}
 		}
 	}
 
@@ -507,12 +531,140 @@ void makeParagraph(
 }
 
 
-void makeEnvironment(
-		Buffer const &buf,
-		XMLStream &xs,
-		OutputParams const &runparams,
-		Text const &text,
-		ParagraphList::const_iterator const & par)
+void makeEnvironment(Buffer const &buf,
+                     XMLStream &xs,
+                     OutputParams const &runparams,
+                     Text const &text,
+                     ParagraphList::const_iterator const & par)
+{
+	// TODO: simplify me!
+	auto const end = text.paragraphs().end();
+
+	// Output the opening tag for this environment, but only if it has not been previously opened (condition
+	// implemented in openParTag).
+	auto prevpar = text.paragraphs().getParagraphBefore(par);
+	openParTag(xs, &*par, prevpar); // TODO: switch in layout for par/block?
+
+	// Generate the contents of this environment. There is a special case if this is like some environment.
+	Layout const & style = par->layout();
+	if (style.latextype == LATEX_COMMAND) {
+		// Nothing to do (otherwise, infinite loops).
+	} else if (style.latextype == LATEX_ENVIRONMENT) {
+		// Open a wrapper tag if needed.
+		if (style.docbookitemwrappertag() != "NONE")
+			openTag(xs, style.docbookitemwrappertag(), style.docbookitemwrapperattr(), style.docbookitemwrappertagtype());
+
+		// Generate the label, if need be. If it is taken from the text, sep != 0 and corresponds to the first
+		// character after the label.
+		pos_type sep = 0;
+		if (style.labeltype != LABEL_NO_LABEL && style.docbookitemlabeltag() != "NONE") {
+			// At least one condition must be met:
+			//  - this environment is not a list
+			//  - if this is a list, the label must not be manual (i.e. it must be taken from the layout)
+			if (style.latextype != LATEX_LIST_ENVIRONMENT || style.labeltype != LABEL_MANUAL) {
+				// Usual cases: maybe there is something specified at the layout level. Highly unlikely, though.
+				docstring const lbl = par->params().labelString();
+
+				if (lbl.empty()) {
+					xs << xml::CR();
+				} else {
+					openLabelTag(xs, style);
+					xs << lbl;
+					closeLabelTag(xs, style);
+				}
+			} else {
+				// Only variablelist gets here (or similar items defined as an extension in the layout).
+				openLabelTag(xs, style);
+				sep = par->firstWordDocBook(xs, runparams);
+				closeLabelTag(xs, style);
+			}
+		}
+
+		// Maybe the item is completely empty, i.e. if the first word ends at the end of the current paragraph
+		// AND if the next paragraph doesn't have the same depth (if there is such a paragraph).
+		// Common case: there is only the first word on the line, but there is a nested list instead
+		// of more text.
+		bool emptyItem = false;
+		if (sep == par->size()) { // If the separator is already at the end of this paragraph...
+			auto next_par = par;
+			++next_par;
+			if (next_par == text.paragraphs().end()) // There is no next paragraph.
+				emptyItem = true;
+			else // There is a next paragraph: check depth.
+				emptyItem = par->params().depth() >= next_par->params().depth();
+		}
+
+		if (emptyItem) {
+			// Avoid having an empty item, this is not valid DocBook. A single character is enough to force
+			// generation of a full <para>.
+			// TODO: this always worked only by magic...
+			xs << ' ';
+		} else {
+			// Generate the rest of the paragraph, if need be. Open as many inner tags as necessary.
+			auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(std::distance(text.paragraphs().begin(), par)), sep);
+			auto p = pars.begin();
+			while (true) {
+				xs << XMLStream::ESCAPE_NONE << *p;
+				++p;
+				if (p != pars.end()) {
+					closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
+					openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(), par->layout().docbookiteminnertagtype());
+				} else
+					break;
+			}
+		}
+	} else {
+		makeAny(text, buf, xs, runparams, par);
+	}
+
+	// Close the environment.
+	auto nextpar = par;
+	++nextpar;
+	closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr); // TODO: switch in layout for par/block?
+}
+
+
+ParagraphList::const_iterator findEndOfEnvironment(
+		ParagraphList::const_iterator const & pstart,
+		ParagraphList::const_iterator const & pend)
+{
+	// Copy-paste from XHTML. Should be factored out at some point...
+
+	ParagraphList::const_iterator p = pstart;
+	Layout const & bstyle = p->layout();
+	size_t const depth = p->params().depth();
+	for (++p; p != pend; ++p) {
+		Layout const & style = p->layout();
+		// It shouldn't happen that e.g. a section command occurs inside
+		// a quotation environment, at a higher depth, but as of 6/2009,
+		// it can happen. We pretend that it's just at lowest depth.
+		if (style.latextype == LATEX_COMMAND)
+			return p;
+
+		// If depth is down, we're done
+		if (p->params().depth() < depth)
+			return p;
+
+		// If depth is up, we're not done
+		if (p->params().depth() > depth)
+			continue;
+
+		// FIXME I am not sure about the first check.
+		// Surely we *could* have different layouts that count as
+		// LATEX_PARAGRAPH, right?
+		if (style.latextype == LATEX_PARAGRAPH || style != bstyle)
+			return p;
+	}
+	return pend;
+}
+
+
+ParagraphList::const_iterator makeListEnvironment(Buffer const &buf,
+		                                          XMLStream &xs,
+		                                          OutputParams const &runparams,
+		                                          Text const &text,
+		                                          ParagraphList::const_iterator const & par)
+>>>>>>> be6480e59c... DocBook: same refactoring for docbookSimpleAllParagraphs.
 {
 	auto const end = text.paragraphs().end();
 
@@ -921,12 +1073,13 @@ void docbookSimpleAllParagraphs(
 	outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
 
 	// Then, the content. It starts where the <info> ends.
-	bpit = info.epit;
-	while (bpit < epit) {
-		auto par = paragraphs.iterator_at(bpit);
+	auto par = text.paragraphs().iterator_at(info.epit);
+	auto end = text.paragraphs().iterator_at(epit);
+	while (par != end) {
 		if (!hasOnlyNotes(*par))
-			makeAny(text, buf, xs, runparams, par);
-		bpit += 1;
+			par = makeAny(text, buf, xs, runparams, par);
+		else
+			++par;
 	}
 }
 
@@ -967,21 +1120,20 @@ void docbookParagraphs(Text const &text,
 
 	bool currentlyInAppendix = false;
 
-	while (bpit < epit) {
+	auto par = text.paragraphs().iterator_at(bpit);
+	auto end = text.paragraphs().iterator_at(epit);
+	while (par != end) {
 		OutputParams ourparams = runparams;
 
-		auto par = paragraphs.iterator_at(bpit);
 		if (par->params().startOfAppendix())
 			currentlyInAppendix = true;
-		Layout const &style = par->layout();
-		ParagraphList::const_iterator const lastStartedPar = par;
-		ParagraphList::const_iterator send;
-
 		if (hasOnlyNotes(*par)) {
-			bpit += 1;
+			++par;
 			continue;
 		}
 
+		Layout const &style = par->layout();
+
 		// Think about adding <section> and/or </section>s.
 		const bool isLayoutSectioning = style.category() == from_utf8("Sectioning");
 		if (isLayoutSectioning) {
@@ -1058,7 +1210,6 @@ void docbookParagraphs(Text const &text,
 
 		// Generate this paragraph.
 		makeAny(text, buf, xs, ourparams, par);
-		bpit += 1;
 	}
 
 	// If need be, close <section>s, but only at the end of the document (otherwise, dealt with at the beginning

commit e8a72d730ab9f3ffc235bcde6b32400109843185
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sat Aug 29 02:43:30 2020 +0200

    XML: use the new mechanisms for CR detection with errors.
    
    This helps tracking down line problems even in the presence of errors.

diff --git a/src/xml.cpp b/src/xml.cpp
index b4004af..2f49667 100644
--- a/src/xml.cpp
+++ b/src/xml.cpp
@@ -167,17 +167,21 @@ bool FontTag::operator==(StartTag const & tag) const
 } // namespace xml
 
 
-void XMLStream::writeError(std::string const &s) const
+void XMLStream::writeError(std::string const &s)
 {
 	LYXERR0(s);
-	os_ << from_utf8("<!-- Output Error: " + s + " -->\n");
+	*this << ESCAPE_NONE << from_utf8("<!-- Output Error: " + s + " -->");
+	*this << xml::CR();
 }
 
 
-void XMLStream::writeError(docstring const &s) const
+void XMLStream::writeError(docstring const &s)
 {
 	LYXERR0(s);
-	os_ << from_utf8("<!-- Output Error: ") << s << from_utf8(" -->\n");
+	*this << ESCAPE_NONE << from_utf8("<!-- Output Error: ");
+	*this << s;
+	*this << ESCAPE_NONE << from_utf8(" -->");
+	*this << xml::CR();
 }
 
 
diff --git a/src/xml.h b/src/xml.h
index 576a4f2..cdc3b56 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -105,9 +105,13 @@ public:
 	/// that simplifies the logic using this code.
 	bool isLastTagCR() const { return is_last_tag_cr_; };
 	///
-	void writeError(std::string const &) const;
+	void writeError(std::string const &);
 	///
-	void writeError(docstring const &) const;
+	void writeError(docstring const &);
+	///
+	typedef std::shared_ptr<xml::StartTag> TagPtr;
+	/// Returns the last element on the tag stack. XMLStream keeps ownership of the item.
+	TagPtr getLastStackTag();
 private:
 	///
 	void clearTagDeque();

commit edda3ad9cfe02fddb7c0722ee47a339d77a21f8e
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Wed Aug 26 21:19:38 2020 +0200

    DocBook: make Paragraph::simpleDocBookOnePar return a list of paragraphs.
    
    Before, it directly wrote to the XMLStream, but it made implementation of new lines tricky. Now, it returns the XML for each sub-paragraph (delimited by new lines) as a string, so that the caller can adopt a more precise behaviour (such as in lists).

diff --git a/autotests/export/docbook/lists.lyx b/autotests/export/docbook/lists.lyx
index f903372..f4a58c2 100644
--- a/autotests/export/docbook/lists.lyx
+++ b/autotests/export/docbook/lists.lyx
@@ -103,6 +103,10 @@ I'm the second line
 \end_layout
 
 \begin_layout Standard
+\begin_inset Note Note
+status collapsed
+
+\begin_layout Plain Layout
 A complex list:
 \end_layout
 
@@ -119,7 +123,7 @@ First first item
 First second item
 \end_layout
 
-\begin_layout Standard
+\begin_layout Plain Layout
 Text after first item
 \end_layout
 
@@ -137,10 +141,15 @@ Second first item
 Second second item
 \end_layout
 
-\begin_layout Standard
+\begin_layout Plain Layout
 Text after second item
 \end_layout
 
 \end_deeper
+\end_inset
+
+
+\end_layout
+
 \end_body
 \end_document
diff --git a/autotests/export/docbook/lists.xml b/autotests/export/docbook/lists.xml
index 4621e30..d7b24f6 100644
--- a/autotests/export/docbook/lists.xml
+++ b/autotests/export/docbook/lists.xml
@@ -2,61 +2,15 @@
 <!-- This DocBook file was created by LyX 2.4.0dev
   See http://www.lyx.org/ for more information -->
 <article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
-<title>
-Test document
-</title>
-<para>
-A simple list: 
-</para>
+<title>Test document</title>
+<para>A simple list: </para>
 <itemizedlist>
 <listitem>
 <para>First item</para>
 </listitem>
 <listitem>
-<para>Second item on two lines<!-- Is para open? yes --><!-- Output Error: Closing tag `para' when other tags are open, namely: -->
-<!-- Output Error: &LyX_parsep_tag& -->
-</para>
-<para>I'm the second line<!-- Output Error: Tags still open in closeFontTags(). Probably not a problem,
-but you might want to check these tags: -->
-<!-- Output Error: para -->
-<!-- Output Error: listitem -->
-<!-- Output Error: itemizedlist -->
-<!-- Output Error: No division separation tag found in endDivision(). -->
-</para>
+<para>Second item on two lines</para>
+<para>I'm the second line</para>
 </listitem>
 </itemizedlist>
-<para>
-A complex list:
-</para>
-<itemizedlist>
-<listitem>
-<para>First item</para>
-</listitem>
-<listitem>
-<para>First first item</para>
-</listitem>
-<listitem>
-<para>First second item</para>
-</listitem>
-</itemizedlist>
-<para>
-Text after first item
-</para>
-<itemizedlist>
-<listitem>
-<para>Second item</para>
-</listitem>
-</itemizedlist>
-<orderedlist><listitem>
-<para>Second first item</para>
-</listitem>
-</orderedlist>
-<orderedlist><listitem>
-<para>Second second item</para>
-</listitem>
-</orderedlist>
-<para>
-Text after second item
-</para>
-
 </article>
\ No newline at end of file
diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index d6f5f17..357845a 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -27479,6 +27479,8 @@ status collapsed
 
 \change_inserted 1075283030 1597698872
 DocBookTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27542,6 +27544,8 @@ status collapsed
 
 \change_inserted 1075283030 1597698987
 DocBook*TagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27563,6 +27567,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699012
 block
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27621,6 +27627,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699113
 paragraph
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27667,6 +27675,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699307
 inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27702,6 +27712,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699585
 block
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28415,8 +28427,34 @@ NONE
  This parameter only makes sense when itemising layouts are used, such as
  lists.
  
-\change_inserted 1075283030 1597699848
+\change_inserted 1075283030 1598469472
+The most likely value is 
+\begin_inset Quotes eld
+\end_inset
+
 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1598469476
+para
+\end_layout
+
+\end_inset
+
+
+\begin_inset Quotes erd
+\end_inset
+
+.
+\begin_inset Newline newline
+\end_inset
+
+When a list item is split using a new line, the item inner tag will be repeated
+ for each part of the paragraph, parts being separated by new lines.
+ 
 \end_layout
 
 \begin_layout Description
@@ -28429,6 +28467,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699853
 DocBookItemInnerTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28441,6 +28481,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699866
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28594,6 +28636,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699880
 DocBookItemLabelTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28606,6 +28650,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699874
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28715,6 +28761,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699890
 DocBookItemTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28727,6 +28775,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699890
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28898,6 +28948,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699900
 DocBookItemWrapperTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28910,6 +28962,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699897
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29075,6 +29129,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699904
 DocBookInnerTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29087,6 +29143,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699904
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29238,6 +29296,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699924
 DocBookTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29250,6 +29310,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699924
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29415,6 +29477,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699932
 DocBookWrapperTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29427,6 +29491,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699929
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29635,6 +29701,8 @@ status collapsed
 
 \change_inserted 1075283030 1597700120
 biblioentry
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29660,6 +29728,8 @@ status collapsed
 
 \change_inserted 1075283030 1597700076
 bibliomixed
+\change_unchanged
+
 \end_layout
 
 \end_inset
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 24947f8..e87ef88 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3329,19 +3329,14 @@ std::tuple<vector<xml::FontTag>, vector<xml::EndFontTag>> computeDocBookFontSwit
 } // anonymous namespace
 
 
-void Paragraph::simpleDocBookOnePar(Buffer const & buf,
-                                    XMLStream & xs,
-                                    OutputParams const & runparams,
-                                    Font const & outerfont,
-                                    bool start_paragraph, bool close_paragraph,
-                                    pos_type initial) const
+std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
+                                                      OutputParams const & runparams,
+                                                      Font const & outerfont,
+                                                      pos_type initial) const
 {
-	// track whether we have opened these tags
+	// Track whether we have opened these tags
 	DocBookFontState fs;
 
-	if (start_paragraph)
-		xs.startDivision(allowEmpty());
-
 	Layout const & style = *d->layout_;
 	FontInfo font_old =
 			style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
@@ -3352,15 +3347,27 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
 	vector<xml::FontTag> tagsToOpen;
 	vector<xml::EndFontTag> tagsToClose;
 
-	// parsing main loop
+	std::vector<docstring> generatedParagraphs;
+	odocstringstream os;
+	auto * xs = new XMLStream(os);
+
+	// Parsing main loop.
 	for (pos_type i = initial; i < size(); ++i) {
-		// let's not show deleted material in the output
+		// Don't show deleted material in the output.
 		if (isDeleted(i))
 			continue;
 
-		Font const font = getFont(buf.masterBuffer()->params(), i, outerfont);
+		// If this is an InsetNewline, generate a new paragraph.
+		if (getInset(i) != nullptr && getInset(i)->lyxCode() == NEWLINE_CODE) {
+			generatedParagraphs.push_back(os.str());
+			os = odocstringstream();
+			// XMLStream has no copy constructor.
+			delete xs;
+			xs = new XMLStream(os);
+		}
 
 		// Determine which tags should be opened or closed.
+		Font const font = getFont(buf.masterBuffer()->params(), i, outerfont);
 		tie(tagsToOpen, tagsToClose) = computeDocBookFontSwitch(font_old, font, default_family, fs);
 
 		// FIXME XHTML
@@ -3369,12 +3376,12 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
 		vector<xml::EndFontTag>::const_iterator cit = tagsToClose.begin();
 		vector<xml::EndFontTag>::const_iterator cen = tagsToClose.end();
 		for (; cit != cen; ++cit)
-			xs << *cit;
+			*xs << *cit;
 
 		vector<xml::FontTag>::const_iterator sit = tagsToOpen.begin();
 		vector<xml::FontTag>::const_iterator sen = tagsToOpen.end();
 		for (; sit != sen; ++sit)
-			xs << *sit;
+			*xs << *sit;
 
 		tagsToClose.clear();
 		tagsToOpen.clear();
@@ -3386,11 +3393,11 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
 
 				// TODO: special case will bite here.
 				np.docbook_in_par = true;
-				inset->docbook(xs, np);
+				inset->docbook(*xs, np);
 			}
 		} else {
 			char_type c = getUChar(buf.masterBuffer()->params(), runparams, i);
-			xs << c;
+			*xs << c;
 		}
 		font_old = font.fontInfo();
 	}
@@ -3398,11 +3405,15 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
 	// FIXME, this code is just imported from XHTML
 	// I'm worried about what happens if a branch, say, is itself
 	// wrapped in some font stuff. I think that will not work.
-	xs.closeFontTags();
+	xs->closeFontTags();
 	if (runparams.docbook_in_listing)
-		xs << xml::CR();
-	if (close_paragraph)
-		xs.endDivision();
+		*xs << xml::CR();
+
+	// Finalise the last (and most likely only) paragraph.
+	generatedParagraphs.push_back(os.str());
+	delete xs;
+
+	return generatedParagraphs;
 }
 
 
diff --git a/src/Paragraph.h b/src/Paragraph.h
index 58b2762..ee31403 100644
--- a/src/Paragraph.h
+++ b/src/Paragraph.h
@@ -24,6 +24,7 @@
 #include "support/types.h"
 
 #include <set>
+#include <vector>
 
 namespace lyx {
 
@@ -208,14 +209,11 @@ public:
 	/// Output the first word of a paragraph, return the position where it left.
 	pos_type firstWordLyXHTML(XMLStream & xs, OutputParams const & runparams) const;
 
-	/// Writes to stream the DocBook representation
-	void simpleDocBookOnePar(Buffer const & buf,
-							 XMLStream &,
-							 OutputParams const & runparams,
-							 Font const & outerfont,
-							 bool start_paragraph = true,
-							 bool close_paragraph = true,
-							 pos_type initial = 0) const;
+	/// Outputs to stream the DocBook representation, one element per paragraph.
+	std::vector<docstring> simpleDocBookOnePar(Buffer const & buf,
+							                   OutputParams const & runparams,
+							                   Font const & outerfont,
+							                   pos_type initial = 0) const;
 
 	/// \return any material that has had to be deferred until after the
 	/// paragraph has closed.
diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp
index 8e69e88..1af67e1 100644
--- a/src/insets/InsetERT.cpp
+++ b/src/insets/InsetERT.cpp
@@ -98,23 +98,33 @@ void InsetERT::docbook(XMLStream & xs, OutputParams const & runparams) const
 	auto par = begin;
 	auto const end = paragraphs().end();
 
-	odocstringstream os2;
-	XMLStream xs2(os2);
+	odocstringstream os; // No need for XML handling here.
 
 	// Recreate the logic of makeParagraph in output_docbook.cpp, but much simplified: never open <para>
 	// in an ERT, use simple line breaks.
-	while (par != end) {
-		par->simpleDocBookOnePar(buffer(), xs2, runparams, text().outerFont(distance(begin, par)));
+	// New line after each paragraph of the ERT, save the last one.
+	while (true) { // For each paragraph in the ERT...
+		auto pars = par->simpleDocBookOnePar(buffer(), runparams, text().outerFont(distance(begin, par)));
+		auto p = pars.begin();
+		while (true) { // For each line of this ERT paragraph...
+			os << *p;
+			++p;
+			if (p != pars.end())
+				os << "\n";
+			else
+				break;
+		}
 
-		// New line after each paragraph of the ERT, save the last one.
 		++par;
 		if (par != end)
-			xs << "\n";
+			os << "\n";
+		else
+			break;
 	}
 
 	// Output the ERT as a comment with the appropriate escaping.
 	xs << XMLStream::ESCAPE_NONE << "<!-- ";
-	xs << XMLStream::ESCAPE_COMMENTS << os2.str();
+	xs << XMLStream::ESCAPE_COMMENTS << os.str();
 	xs << XMLStream::ESCAPE_NONE << " -->";
 	xs << xml::CR();
 }
diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp
index 7cba0f7..b33cf00 100644
--- a/src/insets/InsetNewline.cpp
+++ b/src/insets/InsetNewline.cpp
@@ -174,20 +174,7 @@ int InsetNewline::plaintext(odocstringstream & os,
 
 void InsetNewline::docbook(XMLStream & xs, OutputParams const & runparams) const
 {
-	if (runparams.docbook_in_par) {
-		xs.closeFontTags();
-
-		// TODO: what if within a list item, and docbookiteminnertag is not para? This would require information
-		// about the paragraph's layout... Good for now, though, this should not happen in DocBook, only maybe
-		// extensions.
-		xs << XMLStream::ESCAPE_NONE << from_utf8("<!-- Is para open? " + string((xs.isTagOpen(xml::StartTag("para"))) ? "yes" : "no") +" -->");
-		xs << XMLStream::ESCAPE_NONE << from_utf8("</para>\n<para>");
-		// TODO: that's a hack...
-//		xs << xml::EndTag("para");
-//		xs << xml::CR();
-//		xs << xml::StartTag("para");
-	}
-	// Outside a paragraph, no need to handle new lines.
+	// New lines are handled by Paragraph::simpleDocBookOnePar.
 }
 
 
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index ce3f699..0dc5257 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -382,9 +382,11 @@ void makeParagraphBibliography(
 	}
 	xs << xml::StartTag(from_utf8("bibliomixed"), attr);
 
-	// Generate the entry.
+	// Generate the entry. Concatenate the different parts of the paragraph if any.
 	auto const begin = text.paragraphs().begin();
-	par->simpleDocBookOnePar(buf, xs, runparams, text.outerFont(std::distance(begin, par)), true, true, 0);
+	auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(std::distance(begin, par)), 0);
+	for (auto & parXML : pars)
+		xs << XMLStream::ESCAPE_NONE << parXML;
 
 	// End the precooked bibliography entry.
 	xs << xml::EndTag("bibliomixed");
@@ -488,21 +490,19 @@ void makeParagraph(
 	// Determine if this paragraph has some real content. Things like new pages are not caught
 	// by Paragraph::empty(), even though they do not generate anything useful in DocBook.
 	// Thus, remove all spaces (including new lines: \r, \n) before checking for emptiness.
-	odocstringstream os2;
-	XMLStream xs2(os2);
-	par->simpleDocBookOnePar(buf, xs2, runparams, text.outerFont(distance(begin, par)), open_par, close_par, 0);
-
-	docstring cleaned = os2.str();
-	cleaned.erase(std::remove_if(cleaned.begin(), cleaned.end(), ::isspace), cleaned.end());
-
-	if (!cleaned.empty()) {
-		if (open_par)
-			openParTag(xs, &*par, prevpar);
-
-		xs << XMLStream::ESCAPE_NONE << os2.str();
-
-		if (close_par)
-			closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr);
+	// std::all_of allows doing this check without having to copy the string.
+	// Open and close tags around each contained paragraph.
+	auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(distance(begin, par)), 0);
+	for (auto & parXML : pars) {
+		if (!std::all_of(parXML.begin(), parXML.end(), ::isspace)) {
+			if (open_par)
+				openParTag(xs, &*par, prevpar);
+
+			xs << XMLStream::ESCAPE_NONE << parXML;
+
+			if (close_par)
+				closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr);
+		}
 	}
 }
 
@@ -529,10 +529,8 @@ void makeEnvironment(
 			style.latextype == LATEX_LIST_ENVIRONMENT ||
 			style.latextype == LATEX_ITEM_ENVIRONMENT) {
 		// Open a wrapper tag if needed.
-		if (style.docbookitemwrappertag() != "NONE") {
-			xs << xml::StartTag(style.docbookitemwrappertag(), style.docbookitemwrapperattr());
-			xs << xml::CR();
-		}
+		if (style.docbookitemwrappertag() != "NONE")
+			openTag(xs, style.docbookitemwrappertag(), style.docbookitemwrapperattr(), style.docbookitemwrappertagtype());
 
 		// Generate the label, if need be. If it is taken from the text, sep != 0 and corresponds to the first
 		// character after the label.
@@ -580,9 +578,18 @@ void makeEnvironment(
 			// TODO: this always worked only by magic...
 			xs << ' ';
 		} else {
-			// Generate the rest of the paragraph, if need be.
-			par->simpleDocBookOnePar(buf, xs, runparams, text.outerFont(std::distance(text.paragraphs().begin(), par)),
-							         true, true, sep);
+			// Generate the rest of the paragraph, if need be. Open as many inner tags as necessary.
+			auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(std::distance(text.paragraphs().begin(), par)), sep);
+			auto p = pars.begin();
+			while (true) {
+				xs << XMLStream::ESCAPE_NONE << *p;
+				++p;
+				if (p != pars.end()) {
+					closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
+					openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(), par->layout().docbookiteminnertagtype());
+				} else
+					break;
+			}
 		}
 	} else {
 		makeAny(text, buf, xs, runparams, par);
@@ -612,8 +619,10 @@ void makeCommand(
 	auto prevpar = text.paragraphs().getParagraphBefore(par);
 	openParTag(xs, &*par, prevpar);
 
-	par->simpleDocBookOnePar(buf, xs, runparams,
-	                         text.outerFont(distance(begin, par)));
+	auto pars = par->simpleDocBookOnePar(buf, runparams,text.outerFont(distance(begin, par)));
+	for (auto & parXML : pars)
+		// TODO: decide what to do with openParTag/closeParTag in new lines.
+		xs << XMLStream::ESCAPE_NONE << parXML;
 
 	closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr);
 }
diff --git a/src/xml.h b/src/xml.h
index b65e4e7..576a4f2 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -134,8 +134,6 @@ private:
 	TagDeque tag_stack_;
 	///
 	bool is_last_tag_cr_;
-public:
-	bool pending_tags_empty() { return pending_tags_.empty();};
 };
 
 namespace xml {

commit 2650f3bde07aaa959868748922c22c99560cf2e3
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Tue Aug 25 02:41:07 2020 +0200

    DocBook: fix compilation issues.

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 4e6c30e..ce3f699 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -30,8 +30,6 @@
 
 #include "support/lassert.h"
 
-#include "support/regex.h"
-
 #include <stack>
 #include <iostream>
 #include <algorithm>
@@ -166,18 +164,6 @@ string fontToAttribute(xml::FontTypes type) {
 }
 
 
-xml::FontTag docbookStartFontTag(xml::FontTypes type)
-{
-	return xml::FontTag(from_utf8(fontToDocBookTag(type)), from_utf8(fontToAttribute(type)), type);
-}
-
-
-xml::EndFontTag docbookEndFontTag(xml::FontTypes type)
-{
-	return xml::EndFontTag(from_utf8(fontToDocBookTag(type)), type);
-}
-
-
 // Convenience functions to open and close tags. First, very low-level ones to ensure a consistent new-line behaviour.
 // Block style:
 //	  Content before
@@ -501,13 +487,13 @@ void makeParagraph(
 
 	// Determine if this paragraph has some real content. Things like new pages are not caught
 	// by Paragraph::empty(), even though they do not generate anything useful in DocBook.
+	// Thus, remove all spaces (including new lines: \r, \n) before checking for emptiness.
 	odocstringstream os2;
 	XMLStream xs2(os2);
 	par->simpleDocBookOnePar(buf, xs2, runparams, text.outerFont(distance(begin, par)), open_par, close_par, 0);
 
 	docstring cleaned = os2.str();
-	static const lyx::regex reg("[ \\r\\n]*");
-	cleaned = from_utf8(lyx::regex_replace(to_utf8(cleaned), reg, string("")));
+	cleaned.erase(std::remove_if(cleaned.begin(), cleaned.end(), ::isspace), cleaned.end());
 
 	if (!cleaned.empty()) {
 		if (open_par)
@@ -658,8 +644,6 @@ void makeAny(
 	}
 }
 
-} // end anonymous namespace
-
 
 using DocBookDocumentSectioning = tuple<bool, pit_type>;
 
@@ -796,6 +780,20 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs, pit_type b
 	return DocBookInfoTag(shouldBeInInfo, mustBeInInfo, abstract, bpit, cpit);
 }
 
+} // end anonymous namespace
+
+
+xml::FontTag docbookStartFontTag(xml::FontTypes type)
+{
+	return xml::FontTag(from_utf8(fontToDocBookTag(type)), from_utf8(fontToAttribute(type)), type);
+}
+
+
+xml::EndFontTag docbookEndFontTag(xml::FontTypes type)
+{
+	return xml::EndFontTag(from_utf8(fontToDocBookTag(type)), type);
+}
+
 
 void outputDocBookInfo(
 		Text const & text,
@@ -829,11 +827,11 @@ void outputDocBookInfo(
 		// Actually output the abstract if there is something to do. Don't count line feeds or spaces in this,
 		// even though they must be properly output if there is some abstract.
 		abstract = os2.str();
-		static const lyx::regex reg("[ \\r\\n]*");
-		docstring abstractContent = from_utf8(lyx::regex_replace(to_utf8(abstract), reg, string("")));
+		docstring cleaned = abstract;
+		cleaned.erase(std::remove_if(cleaned.begin(), cleaned.end(), ::isspace), cleaned.end());
 
 		// Nothing? Then there is no abstract!
-		if (abstractContent.empty())
+		if (cleaned.empty())
 			hasAbstract = false;
 	}
 

commit af334eda47264419d748fb4f399478fa6cd8118f
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Tue Aug 25 02:11:08 2020 +0200

    DocBook: Coverity potential problem for precooked bibliographies.

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 3f6a692..4e6c30e 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -386,9 +386,10 @@ void makeParagraphBibliography(
 	// Don't forget the citation ID!
 	docstring attr;
 	for (auto i = 0; i < par->size(); ++i) {
-		Inset const *ip = par->getInset(0);
-		if (ip != nullptr && ip->lyxCode() == BIBITEM_CODE) {
-			const auto * bibitem = dynamic_cast<const InsetBibitem*>(par->getInset(i));
+		Inset const *ip = par->getInset(i);
+		if (!ip)
+			continue;
+		if (const auto * bibitem = dynamic_cast<const InsetBibitem*>(ip)) {
 			attr = from_utf8("xml:id='") + bibitem->getParam("key") + from_utf8("'");
 			break;
 		}

commit 1b66662336bfadedbf20e5200ddd8b5c557e5e72
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Tue Aug 18 05:46:40 2020 +0200

    DocBook: simplify precooked bibliography code.

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 0481890..3f6a692 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -360,63 +360,59 @@ void closeItemTag(XMLStream & xs, Layout const & lay)
 }
 
 
+void makeAny(
+		Text const &,
+		Buffer const &,
+		XMLStream &,
+		OutputParams const &,
+		ParagraphList::const_iterator);
+
+
 void makeParagraphBibliography(
 		Buffer const & buf,
 		XMLStream & xs,
 		OutputParams const & runparams,
 		Text const & text,
-		ParagraphList::const_iterator const & pbegin)
+		ParagraphList::const_iterator const & par)
 {
-	auto const begin = text.paragraphs().begin();
-	auto const end = text.paragraphs().end();
-	auto pend = pbegin;
-	++pend;
-
-	// Find the paragraph *before* pbegin.
-	ParagraphList::const_iterator pbegin_before = begin;
-	if (pbegin != begin) {
-		ParagraphList::const_iterator pbegin_before_next = begin;
-		++pbegin_before_next;
-
-		while (pbegin_before_next != pbegin) {
-			++pbegin_before;
-			++pbegin_before_next;
-		}
-	}
-
-	ParagraphList::const_iterator par = pbegin;
-
 	// If this is the first paragraph in a bibliography, open the bibliography tag.
-	if (pbegin != begin && pbegin_before->layout().latextype != LATEX_BIB_ENVIRONMENT) {
+	auto pbegin_before = text.paragraphs().getParagraphBefore(par);
+	if (pbegin_before->layout().latextype != LATEX_BIB_ENVIRONMENT) {
 		xs << xml::StartTag("bibliography");
 		xs << xml::CR();
 	}
 
-	// Generate the required paragraphs, but only if they are .
-	for (; par != pend; ++par) {
-		// Start the precooked bibliography entry. This is very much like opening a paragraph tag.
-		// Don't forget the citation ID!
-		docstring attr;
-		for (auto i = 0; i < par->size(); ++i) {
-			Inset const *ip = par->getInset(0);
-			if (ip != nullptr && ip->lyxCode() == BIBITEM_CODE) {
-				const auto * bibitem = dynamic_cast<const InsetBibitem*>(par->getInset(i));
-				attr = from_utf8("xml:id='") + bibitem->getParam("key") + from_utf8("'");
-				break;
-			}
+	// Start the precooked bibliography entry. This is very much like opening a paragraph tag.
+	// Don't forget the citation ID!
+	docstring attr;
+	for (auto i = 0; i < par->size(); ++i) {
+		Inset const *ip = par->getInset(0);
+		if (ip != nullptr && ip->lyxCode() == BIBITEM_CODE) {
+			const auto * bibitem = dynamic_cast<const InsetBibitem*>(par->getInset(i));
+			attr = from_utf8("xml:id='") + bibitem->getParam("key") + from_utf8("'");
+			break;
 		}
-		xs << xml::StartTag(from_utf8("bibliomixed"), attr);
+	}
+	xs << xml::StartTag(from_utf8("bibliomixed"), attr);
 
-		// Generate the entry.
-		par->simpleDocBookOnePar(buf, xs, runparams, text.outerFont(distance(begin, par)), true, true, 0);
+	// Generate the entry.
+	auto const begin = text.paragraphs().begin();
+	par->simpleDocBookOnePar(buf, xs, runparams, text.outerFont(std::distance(begin, par)), true, true, 0);
 
-		// End the precooked bibliography entry.
-		xs << xml::EndTag("bibliomixed");
-		xs << xml::CR();
-	}
+	// End the precooked bibliography entry.
+	xs << xml::EndTag("bibliomixed");
+	xs << xml::CR();
 
 	// If this is the last paragraph in a bibliography, close the bibliography tag.
-	if (par == end || par->layout().latextype != LATEX_BIB_ENVIRONMENT) {
+	auto const end = text.paragraphs().end();
+	bool endBibliography = par == end;
+	if (!endBibliography) {
+		auto nextpar = par;
+		++nextpar;
+		endBibliography = par->layout().latextype != LATEX_BIB_ENVIRONMENT;
+	}
+
+	if (endBibliography) {
 		xs << xml::EndTag("bibliography");
 		xs << xml::CR();
 	}
@@ -524,14 +520,6 @@ void makeParagraph(
 }
 
 
-void makeAny(
-		Text const &text,
-		Buffer const &buf,
-		XMLStream &xs,
-		OutputParams const &ourparams,
-		ParagraphList::const_iterator par);
-
-
 void makeEnvironment(
 		Buffer const &buf,
 		XMLStream &xs,

commit 7fb2bc3646d837b1a98b260a841d24972c55e8b9
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Tue Aug 18 05:40:34 2020 +0200

    DocBook: remove useless includes.

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 12601c5..0481890 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -16,8 +16,6 @@
 #include "BufferParams.h"
 #include "Font.h"
 #include "InsetList.h"
-#include "Layout.h"
-#include "OutputParams.h"
 #include "Paragraph.h"
 #include "ParagraphList.h"
 #include "ParagraphParameters.h"
@@ -30,11 +28,7 @@
 #include "insets/InsetLabel.h"
 #include "insets/InsetNote.h"
 
-#include "support/convert.h"
-#include "support/debug.h"
 #include "support/lassert.h"
-#include "support/lstrings.h"
-#include "support/textutils.h"
 
 #include "support/regex.h"
 
@@ -159,6 +153,7 @@ string fontToRole(xml::FontTypes type)
 	}
 }
 
+
 string fontToAttribute(xml::FontTypes type) {
 	// If there is a role (i.e. nonstandard use of a tag), output the attribute. Otherwise, the sheer tag is sufficient
 	// for the font.

commit 534bacf72e047273bd064b5569909163393ab35a
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Tue Aug 18 05:39:46 2020 +0200

    More functions in anonymous namespace.

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index ad683c7..12601c5 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -170,8 +170,6 @@ string fontToAttribute(xml::FontTypes type) {
 	}
 }
 
-} // end anonymous namespace
-
 
 xml::FontTag docbookStartFontTag(xml::FontTypes type)
 {
@@ -185,8 +183,6 @@ xml::EndFontTag docbookEndFontTag(xml::FontTypes type)
 }
 
 
-namespace {
-
 // Convenience functions to open and close tags. First, very low-level ones to ensure a consistent new-line behaviour.
 // Block style:
 //	  Content before

commit b6e2699fae3a1f1b5f6d48f20d8d4f42e5aab40e
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Tue Aug 18 05:37:46 2020 +0200

    DocBook: fine tuning of new lines.

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 9de281d..4477886 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -2140,8 +2140,6 @@ Buffer::ExportStatus Buffer::writeDocBookSource(odocstream & os,
 	bool const output_body =
 	  output == FullSource || output == OnlyBody;
 
-	XMLStream xs(os);
-
 	if (output_preamble) {
 		// XML preamble, no doctype needed.
 		// Not using XMLStream for this, as the root tag would be in the tag stack and make troubles with the error
@@ -2164,16 +2162,17 @@ Buffer::ExportStatus Buffer::writeDocBookSource(odocstream & os,
 	}
 
 	if (output_body) {
-		params().documentClass().counters().reset();
-
 		// Start to output the document.
+		XMLStream xs(os);
 		docbookParagraphs(text(), *this, xs, runparams);
 	}
 
 	if (output_preamble) {
-		// Close the root element.
-		os << "\n</" << from_ascii(tclass.docbookroot()) << ">";
+		// Close the root element. No need for a line break, as free text is never allowed
+		// in a root element, it must always be wrapped in some container.
+		os << "</" << from_ascii(tclass.docbookroot()) << ">";
 	}
+
 	return ExportSuccess;
 }
 
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index b7b5941..ad683c7 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -239,7 +239,8 @@ void openBlockTag(XMLStream & xs, const std::string & tag, const std::string & a
 
 void closeBlockTag(XMLStream & xs, const std::string & tag)
 {
-	xs << xml::CR();
+	if (!xs.isLastTagCR())
+		xs << xml::CR();
 	xs << xml::EndTag(tag);
 	xs << xml::CR();
 }

commit e6e57c92a8c1692a1f03dc70b546ed1066cce9ec
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Tue Aug 18 04:56:25 2020 +0200

    DocBook: improve comments.

diff --git a/src/xml.h b/src/xml.h
index 2461eb1..b65e4e7 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -41,7 +41,7 @@ struct CR;
 class XMLStream {
 public:
 	///
-	explicit XMLStream(odocstream & os): os_(os), escape_(ESCAPE_ALL), is_last_tag_cr_(false) {}
+	explicit XMLStream(odocstream & os): os_(os), escape_(ESCAPE_ALL), is_last_tag_cr_(true) {}
 	///
 	odocstream & os() { return os_; }
 	///
@@ -84,7 +84,7 @@ public:
 	enum EscapeSettings {
 		ESCAPE_NONE,
 		ESCAPE_AND, // meaning &
-		ESCAPE_ALL, // meaning <, >, &, at present
+		ESCAPE_ALL, // meaning <, >, &, at present, except things that are forbidden in comments
 		ESCAPE_COMMENTS // Anything that is forbidden within comments
 	};
 	/// Sets what we are going to escape on the NEXT write.
@@ -100,7 +100,9 @@ public:
 	bool isTagOpen(xml::EndTag const &, int maxdepth = -1) const;
 	///
 	bool isTagPending(xml::StartTag const &, int maxdepth = -1) const;
-	///
+	/// Is the last tag that was added to the stream a new line (CR)? This is mostly to known
+	/// whether a new line must be added. Therefore, consider that an empty stream just had a CR,
+	/// that simplifies the logic using this code.
 	bool isLastTagCR() const { return is_last_tag_cr_; };
 	///
 	void writeError(std::string const &) const;

commit 33abbf5e0b27052cb91164b6245ff278a4019736
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Tue Aug 18 00:37:34 2020 +0200

    DocBook: new logic to handle the new lines, only used in output_docbook for now.

diff --git a/lib/layouts/stdlayouts.inc b/lib/layouts/stdlayouts.inc
index 1670695..e550518 100644
--- a/lib/layouts/stdlayouts.inc
+++ b/lib/layouts/stdlayouts.inc
@@ -7,7 +7,7 @@
 # quotations and such.
 
 
-Format 82
+Format 84
 
 Style Quotation
 	Category              MainText
diff --git a/lib/layouts/stdlists.inc b/lib/layouts/stdlists.inc
index 16a9e81..c0b346d 100644
--- a/lib/layouts/stdlists.inc
+++ b/lib/layouts/stdlists.inc
@@ -6,7 +6,7 @@
 # This include files contains various standard environments for lists.
 
 
-Format 82
+Format 84
 
 Input stdlyxlist.inc
 
diff --git a/lib/layouts/stdstruct.inc b/lib/layouts/stdstruct.inc
index c8b7eb4..2a81117 100644
--- a/lib/layouts/stdstruct.inc
+++ b/lib/layouts/stdstruct.inc
@@ -8,7 +8,7 @@
 # a document, like abstract, bibliography and such.
 
 
-Format 82
+Format 84
 
 Style Abstract
 	Margin                Static
diff --git a/lib/layouts/stdtitle.inc b/lib/layouts/stdtitle.inc
index ad989a6..44b1b8e 100644
--- a/lib/layouts/stdtitle.inc
+++ b/lib/layouts/stdtitle.inc
@@ -8,7 +8,7 @@
 # a document, like title, author and such.
 
 
-Format 82
+Format 84
 
 Style Title
 	Margin                Static
@@ -29,6 +29,7 @@ Style Title
 	HTMLTag               h1
 	HTMLTitle             true
 	DocBookTag            title
+	DocBookTagType        paragraph
 	DocBookInInfo         maybe
 End
 
@@ -50,7 +51,9 @@ Style Author
 	  Size                Large
 	EndFont
 	DocBookTag            personname
+	DocBookTagType        paragraph
 	DocBookWrapperTag     author
+	DocBookWrapperTagType inline
 	DocBookInInfo         always
 End
 
@@ -72,5 +75,6 @@ Style Date
 	  Size                Large
 	EndFont
 	DocBookTag            date
+	DocBookTagType        paragraph
 	DocBookInInfo         always
 End
diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp
index 00b276e..7cba0f7 100644
--- a/src/insets/InsetNewline.cpp
+++ b/src/insets/InsetNewline.cpp
@@ -181,7 +181,7 @@ void InsetNewline::docbook(XMLStream & xs, OutputParams const & runparams) const
 		// about the paragraph's layout... Good for now, though, this should not happen in DocBook, only maybe
 		// extensions.
 		xs << XMLStream::ESCAPE_NONE << from_utf8("<!-- Is para open? " + string((xs.isTagOpen(xml::StartTag("para"))) ? "yes" : "no") +" -->");
-		xs << XMLStream::ESCAPE_NONE << from_utf8("</para>\n<para");
+		xs << XMLStream::ESCAPE_NONE << from_utf8("</para>\n<para>");
 		// TODO: that's a hack...
 //		xs << xml::EndTag("para");
 //		xs << xml::CR();
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index b29da56..b7b5941 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -43,8 +43,6 @@
 #include <algorithm>
 #include <sstream>
 
-// #define DOCBOOK_DEBUG_NEWLINES
-
 using namespace std;
 using namespace lyx::support;
 
@@ -189,14 +187,100 @@ xml::EndFontTag docbookEndFontTag(xml::FontTypes type)
 
 namespace {
 
-// convenience functions
+// Convenience functions to open and close tags. First, very low-level ones to ensure a consistent new-line behaviour.
+// Block style:
+//	  Content before
+//	  <blocktag>
+//	    Contents of the block.
+//	  </blocktag>
+//	  Content after
+// Paragraph style:
+//	  Content before
+//	    <paratag>Contents of the paragraph.</paratag>
+//	  Content after
+// Inline style:
+//    Content before<inlinetag>Contents of the paragraph.</inlinetag>Content after
+
+void openInlineTag(XMLStream & xs, const std::string & tag, const std::string & attr)
+{
+	xs << xml::StartTag(tag, attr);
+}
+
 
-void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar)
+void closeInlineTag(XMLStream & xs, const std::string & tag)
+{
+	xs << xml::EndTag(tag);
+}
+
+
+void openParTag(XMLStream & xs, const std::string & tag, const std::string & attr)
+{
+	if (!xs.isLastTagCR())
+		xs << xml::CR();
+	xs << xml::StartTag(tag, attr);
+}
+
+
+void closeParTag(XMLStream & xs, const std::string & tag)
+{
+	xs << xml::EndTag(tag);
+	xs << xml::CR();
+}
+
+
+void openBlockTag(XMLStream & xs, const std::string & tag, const std::string & attr)
+{
+	if (!xs.isLastTagCR())
+		xs << xml::CR();
+	xs << xml::StartTag(tag, attr);
+	xs << xml::CR();
+}
+
+
+void closeBlockTag(XMLStream & xs, const std::string & tag)
+{
+	xs << xml::CR();
+	xs << xml::EndTag(tag);
+	xs << xml::CR();
+}
+
+
+void openTag(XMLStream & xs, const std::string & tag, const std::string & attr, const std::string & tagtype)
+{
+	if (tag.empty() || tag == "NONE")
+		return;
+
+	if (tag == "para" || tagtype == "paragraph") // Special case for <para>: always considered as a paragraph.
+		openParTag(xs, tag, attr);
+	else if (tagtype == "block")
+		openBlockTag(xs, tag, attr);
+	else if (tagtype == "inline")
+		openInlineTag(xs, tag, attr);
+	else
+		xs.writeError("Unrecognised tag type '" + tagtype + "' for '" + tag + " " + attr + "'");
+}
+
+
+void closeTag(XMLStream & xs, const std::string & tag, const std::string & tagtype)
 {
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- openParTag -->";
-#endif
+	if (tag.empty() || tag == "NONE")
+		return;
 
+	if (tag == "para" || tagtype == "paragraph") // Special case for <para>: always considered as a paragraph.
+		closeParTag(xs, tag);
+	else if (tagtype == "block")
+		closeBlockTag(xs, tag);
+	else if (tagtype == "inline")
+		closeInlineTag(xs, tag);
+	else
+		xs.writeError("Unrecognised tag type '" + tagtype + "' for '" + tag + "'");
+}
+
+
+// Higher-level convenience functions.
+
+void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar)
+{
 	Layout const & lay = par->layout();
 
 	if (par == prevpar)
@@ -218,38 +302,25 @@ void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar
 	}
 
 	// Main logic.
-	if (openWrapper) {
-		xs << xml::StartTag(lay.docbookwrappertag(), lay.docbookwrapperattr());
-		xs << xml::CR();
-	}
+	if (openWrapper)
+		openTag(xs, lay.docbookwrappertag(), lay.docbookwrapperattr(), lay.docbookwrappertagtype());
 
-	string tag = lay.docbooktag();
+	const string & tag = lay.docbooktag();
 	if (tag != "NONE") {
 		auto xmltag = xml::ParTag(tag, lay.docbookattr());
-		if (!xs.isTagOpen(xmltag, 1)) // Don't nest a paragraph directly in a paragraph. TODO: required or not?
-			xs << xmltag;
-	}
-
-	if (lay.docbookitemtag() != "NONE") {
-		xs << xml::StartTag(lay.docbookitemtag(), lay.docbookitemattr());
-		xs << xml::CR();
+		if (!xs.isTagOpen(xmltag, 1)) // Don't nest a paragraph directly in a paragraph.
+			// TODO: required or not?
+			// TODO: avoid creating a ParTag object just for this query...
+			openTag(xs, lay.docbooktag(), lay.docbookattr(), lay.docbooktagtype());
 	}
 
-	if (lay.docbookiteminnertag() != "NONE")
-		xs << xml::StartTag(lay.docbookiteminnertag(), lay.docbookiteminnerattr());
-
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- /openParTag -->";
-#endif
+	openTag(xs, lay.docbookitemtag(), lay.docbookitemattr(), lay.docbookitemtagtype());
+	openTag(xs, lay.docbookiteminnertag(), lay.docbookiteminnerattr(), lay.docbookiteminnertagtype());
 }
 
 
 void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpar)
 {
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- closeParTag -->";
-#endif
-
 	if (par == nextpar)
 		nextpar = nullptr;
 
@@ -265,119 +336,35 @@ void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpa
 	}
 
 	// Main logic.
-	if (lay.docbookiteminnertag() != "NONE") {
-		xs << xml::EndTag(lay.docbookiteminnertag());
-		xs << xml::CR();
-	}
-
-	if (lay.docbookitemtag() != "NONE") {
-		xs << xml::EndTag(lay.docbookitemtag());
-		xs << xml::CR();
-	}
-
-	if (lay.docbooktag() != "NONE") {
-		xs << xml::EndTag(lay.docbooktag());
-		xs << xml::CR();
-	}
-
-	if (closeWrapper) {
-		xs << xml::EndTag(lay.docbookwrappertag());
-		xs << xml::CR();
-	}
-
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- /closeParTag -->";
-#endif
-}
-
-
-void openBlockTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar)
-{
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- openBlockTag -->";
-#endif
-
-	// Similar as openParTag, but with a line feed after.
-	openParTag(xs, par, prevpar);
-	xs << xml::CR();
-
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- /openBlockTag -->";
-#endif
-}
-
-
-void closeBlockTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar)
-{
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- closeBlockTag -->";
-#endif
-
-	// Similar as closeParTag, but with a line feed before.
-	xs << xml::CR();
-	closeParTag(xs, par, prevpar);
-
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- /closeBlockTag -->";
-#endif
+	closeTag(xs, lay.docbookiteminnertag(), lay.docbookiteminnertagtype());
+	closeTag(xs, lay.docbookitemtag(), lay.docbookitemtagtype());
+	closeTag(xs, lay.docbooktag(), lay.docbooktagtype());
+	if (closeWrapper)
+		closeTag(xs, lay.docbookwrappertag(), lay.docbookwrappertagtype());
 }
 
 
 void openLabelTag(XMLStream & xs, Layout const & lay) // Mostly for definition lists.
 {
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- openLabelTag -->";
-#endif
-
-	xs << xml::StartTag(lay.docbookitemlabeltag(), lay.docbookitemlabelattr());
-
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- /openLabelTag -->";
-#endif
+	openTag(xs, lay.docbookitemlabeltag(), lay.docbookitemlabelattr(), lay.docbookitemlabeltagtype());
 }
 
 
 void closeLabelTag(XMLStream & xs, Layout const & lay)
 {
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- closeLabelTag -->";
-#endif
-
-	xs << xml::EndTag(lay.docbookitemlabeltag());
-	xs << xml::CR();
-
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- closeLabelTag -->";
-#endif
+	closeTag(xs, lay.docbookitemlabeltag(), lay.docbookitemlabeltagtype());
 }
 
 
 void openItemTag(XMLStream & xs, Layout const & lay)
 {
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- openItemTag -->";
-#endif
-
-	xs << xml::StartTag(lay.docbookitemtag(), lay.docbookitemattr());
-
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- /openItemTag -->";
-#endif
+	openTag(xs, lay.docbookitemtag(), lay.docbookitemattr(), lay.docbookitemtagtype());
 }
 
 
 void closeItemTag(XMLStream & xs, Layout const & lay)
 {
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- closeItemTag -->";
-#endif
-
-	xs << xml::EndTag(lay.docbookitemtag());
-	xs << xml::CR();
-
-#ifdef DOCBOOK_DEBUG_NEWLINES
-	xs << XMLStream::ESCAPE_NONE << "<!-- /closeItemTag -->";
-#endif
+	closeTag(xs, lay.docbookitemtag(), lay.docbookitemtagtype());
 }
 
 
diff --git a/src/xml.h b/src/xml.h
index 8248102..2461eb1 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -102,13 +102,13 @@ public:
 	bool isTagPending(xml::StartTag const &, int maxdepth = -1) const;
 	///
 	bool isLastTagCR() const { return is_last_tag_cr_; };
-private:
-	///
-	void clearTagDeque();
 	///
 	void writeError(std::string const &) const;
 	///
 	void writeError(docstring const &) const;
+private:
+	///
+	void clearTagDeque();
 	///
 	odocstream & os_;
 	///

commit 338780958368826128b83e0bee35794acd7aed7c
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 17 23:44:02 2020 +0200

    XML: memorise if the last thing that is getting output is a line feed.

diff --git a/src/xml.cpp b/src/xml.cpp
index 147eadd..b4004af 100644
--- a/src/xml.cpp
+++ b/src/xml.cpp
@@ -290,6 +290,7 @@ void XMLStream::clearTagDeque()
 
 XMLStream &XMLStream::operator<<(docstring const &d)
 {
+	is_last_tag_cr_ = false;
 	clearTagDeque();
 	os_ << xml::escapeString(d, escape_);
 	escape_ = ESCAPE_ALL;
@@ -299,6 +300,7 @@ XMLStream &XMLStream::operator<<(docstring const &d)
 
 XMLStream &XMLStream::operator<<(const char *s)
 {
+	is_last_tag_cr_ = false;
 	clearTagDeque();
 	docstring const d = from_ascii(s);
 	os_ << xml::escapeString(d, escape_);
@@ -309,6 +311,7 @@ XMLStream &XMLStream::operator<<(const char *s)
 
 XMLStream &XMLStream::operator<<(char_type c)
 {
+	is_last_tag_cr_ = false;
 	clearTagDeque();
 	os_ << xml::escapeChar(c, escape_);
 	escape_ = ESCAPE_ALL;
@@ -318,6 +321,7 @@ XMLStream &XMLStream::operator<<(char_type c)
 
 XMLStream &XMLStream::operator<<(char c)
 {
+	is_last_tag_cr_ = false;
 	clearTagDeque();
 	os_ << xml::escapeChar(c, escape_);
 	escape_ = ESCAPE_ALL;
@@ -327,6 +331,7 @@ XMLStream &XMLStream::operator<<(char c)
 
 XMLStream &XMLStream::operator<<(int i)
 {
+	is_last_tag_cr_ = false;
 	clearTagDeque();
 	os_ << i;
 	escape_ = ESCAPE_ALL;
@@ -336,6 +341,7 @@ XMLStream &XMLStream::operator<<(int i)
 
 XMLStream &XMLStream::operator<<(EscapeSettings e)
 {
+	// Don't update is_last_tag_cr_ here, as this does not output anything.
 	escape_ = e;
 	return *this;
 }
@@ -343,6 +349,7 @@ XMLStream &XMLStream::operator<<(EscapeSettings e)
 
 XMLStream &XMLStream::operator<<(xml::StartTag const &tag)
 {
+	is_last_tag_cr_ = false;
 	if (tag.tag_.empty())
 		return *this;
 	pending_tags_.push_back(makeTagPtr(tag));
@@ -354,6 +361,7 @@ XMLStream &XMLStream::operator<<(xml::StartTag const &tag)
 
 XMLStream &XMLStream::operator<<(xml::ParTag const &tag)
 {
+	is_last_tag_cr_ = false;
 	if (tag.tag_.empty())
 		return *this;
 	pending_tags_.push_back(makeTagPtr(tag));
@@ -363,6 +371,7 @@ XMLStream &XMLStream::operator<<(xml::ParTag const &tag)
 
 XMLStream &XMLStream::operator<<(xml::CompTag const &tag)
 {
+	is_last_tag_cr_ = false;
 	if (tag.tag_.empty())
 		return *this;
 	clearTagDeque();
@@ -373,6 +382,7 @@ XMLStream &XMLStream::operator<<(xml::CompTag const &tag)
 
 XMLStream &XMLStream::operator<<(xml::FontTag const &tag)
 {
+	is_last_tag_cr_ = false;
 	if (tag.tag_.empty())
 		return *this;
 	pending_tags_.push_back(makeTagPtr(tag));
@@ -382,6 +392,7 @@ XMLStream &XMLStream::operator<<(xml::FontTag const &tag)
 
 XMLStream &XMLStream::operator<<(xml::CR const &)
 {
+	is_last_tag_cr_ = true;
 	clearTagDeque();
 	os_ << from_ascii("\n");
 	return *this;
@@ -434,6 +445,8 @@ bool XMLStream::isTagPending(xml::StartTag const &stag, int maxdepth) const
 // best to make things work.
 XMLStream &XMLStream::operator<<(xml::EndTag const &etag)
 {
+	is_last_tag_cr_ = false;
+
 	if (etag.tag_.empty())
 		return *this;
 
diff --git a/src/xml.h b/src/xml.h
index e63623c..8248102 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -41,7 +41,7 @@ struct CR;
 class XMLStream {
 public:
 	///
-	explicit XMLStream(odocstream & os): os_(os), escape_(ESCAPE_ALL) {}
+	explicit XMLStream(odocstream & os): os_(os), escape_(ESCAPE_ALL), is_last_tag_cr_(false) {}
 	///
 	odocstream & os() { return os_; }
 	///
@@ -100,6 +100,8 @@ public:
 	bool isTagOpen(xml::EndTag const &, int maxdepth = -1) const;
 	///
 	bool isTagPending(xml::StartTag const &, int maxdepth = -1) const;
+	///
+	bool isLastTagCR() const { return is_last_tag_cr_; };
 private:
 	///
 	void clearTagDeque();
@@ -128,6 +130,8 @@ private:
 	TagDeque pending_tags_;
 	///
 	TagDeque tag_stack_;
+	///
+	bool is_last_tag_cr_;
 public:
 	bool pending_tags_empty() { return pending_tags_.empty();};
 };

commit fcab3303ef158e27ed42ec09b932bec44b28ec6a
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 17 23:35:40 2020 +0200

    DocBook: documentation for the new tags.

diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index 541e562..d6f5f17 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -27208,13 +27208,24 @@ Labels are rarely output, as they are redundant in DocBook: this information
 
 \begin_layout Subsection
 
-\change_inserted -970929547 1496610966
+\change_inserted 1075283030 1597699417
+\begin_inset CommandInset label
+LatexCommand label
+name "subsec:Paragraph-Style-DocBook"
+
+\end_inset
+
+
+\change_deleted 1075283030 1597699417
+
 \begin_inset CommandInset label
 LatexCommand label
 name "subsec:Paragraph-Style-XHTML-1"
 
 \end_inset
 
+
+\change_inserted -970929547 1496610966
 Paragraph styles
 \end_layout
 
@@ -27454,6 +27465,252 @@ tag
  in the example above.
  The default is the name of the float and always needs to be changed, as
  DocBook provides no generic tag.
+\change_inserted 1075283030 1597698868
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted 1075283030 1597699399
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597698872
+DocBookTagType
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597700585
+block, paragraph, inline
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+] The new-line policy for this tag, see Section
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "subsec:DocBook-New-line-policy"
+plural "false"
+caps "false"
+noprefix "false"
+
+\end_inset
+
+ for the details.
+ 
+\change_unchanged
+
+\end_layout
+
+\begin_layout Subsection
+
+\change_inserted 1075283030 1597699385
+New-line policy
+\begin_inset CommandInset label
+LatexCommand label
+name "subsec:DocBook-New-line-policy"
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+
+\change_inserted 1075283030 1597698993
+For all tags, there are three possible policies for outputting new lines
+ (given in the 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597698987
+DocBook*TagType
+\end_layout
+
+\end_inset
+
+ attribute): 
+\end_layout
+
+\begin_layout Itemize
+
+\change_inserted 1075283030 1597699279
+\begin_inset Quotes eld
+\end_inset
+
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699012
+block
+\end_layout
+
+\end_inset
+
+
+\begin_inset Quotes erd
+\end_inset
+
+: the opening and closing tags are on their own lines (i.e.
+ a line feed after and before the opening and the closing tags).
+ Typical elements are floats.
+ For instance: 
+\end_layout
+
+\begin_layout LyX-Code
+
+\change_inserted 1075283030 1597699194
+Content before
+\end_layout
+
+\begin_layout LyX-Code
+
+\change_inserted 1075283030 1597699194
+<blocktag>
+\end_layout
+
+\begin_layout LyX-Code
+
+\change_inserted 1075283030 1597699098
+  Contents of the block.
+\end_layout
+
+\begin_layout LyX-Code
+
+\change_inserted 1075283030 1597699196
+</blocktag>
+\end_layout
+
+\begin_layout LyX-Code
+
+\change_inserted 1075283030 1597699198
+Content after
+\end_layout
+
+\begin_layout Itemize
+
+\change_inserted 1075283030 1597699289
+\begin_inset Quotes eld
+\end_inset
+
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699113
+paragraph
+\end_layout
+
+\end_inset
+
+
+\begin_inset Quotes erd
+\end_inset
+
+: the opening and closing tags are on the same, new line; a line feed is
+ output before the opening tag and after the closing tag.
+ Typical elements are paragraphs and list items.
+ For instance: 
+\end_layout
+
+\begin_layout LyX-Code
+
+\change_inserted 1075283030 1597699186
+Content before
+\end_layout
+
+\begin_layout LyX-Code
+
+\change_inserted 1075283030 1597699357
+<paratag>Contents of the paragraph.</paratag>
+\end_layout
+
+\begin_layout LyX-Code
+
+\change_inserted 1075283030 1597699231
+Content after
+\end_layout
+
+\begin_layout Itemize
+
+\change_inserted 1075283030 1597699343
+\begin_inset Quotes eld
+\end_inset
+
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699307
+inline
+\end_layout
+
+\end_inset
+
+
+\begin_inset Quotes erd
+\end_inset
+
+: the opening and closing tags are on the same line as the rest of the content.
+ No line feeds are output.
+ Typical elements are fonts.
+ For instance: 
+\end_layout
+
+\begin_layout LyX-Code
+
+\change_inserted 1075283030 1597699585
+Content before<inlinetag>Contents of the paragraph.</inlinetag>Content after
+\end_layout
+
+\begin_layout Standard
+
+\change_inserted 1075283030 1597699585
+The default value is always 
+\begin_inset Quotes eld
+\end_inset
+
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699585
+block
+\end_layout
+
+\end_inset
+
+
+\begin_inset Quotes erd
+\end_inset
+
+.
 \change_unchanged
 
 \end_layout
@@ -28158,6 +28415,52 @@ NONE
  This parameter only makes sense when itemising layouts are used, such as
  lists.
  
+\change_inserted 1075283030 1597699848
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted 1075283030 1597699866
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699853
+DocBookItemInnerTagType
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699866
+block, paragraph, inline
+\end_layout
+
+\end_inset
+
+] The new-line policy for this tag, see Section
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "subsec:DocBook-New-line-policy"
+plural "false"
+caps "false"
+noprefix "false"
+
+\end_inset
+
+ for the details.
+ 
 \change_unchanged
 
 \end_layout
@@ -28277,6 +28580,52 @@ itemlabeltag
  This parameter only makes sense when itemising layouts are used with a
  notion of labels, such as definition lists.
  
+\change_inserted 1075283030 1597699874
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted 1075283030 1597699874
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699880
+DocBookItemLabelTagType
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699874
+block, paragraph, inline
+\end_layout
+
+\end_inset
+
+] The new-line policy for this tag, see Section
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "subsec:DocBook-New-line-policy"
+plural "false"
+caps "false"
+noprefix "false"
+
+\end_inset
+
+ for the details.
+ 
 \change_unchanged
 
 \end_layout
@@ -28352,6 +28701,54 @@ NONE
  This parameter only makes sense when itemising layouts are used, such as
  lists.
  
+\change_inserted 1075283030 1597699890
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted 1075283030 1597699890
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699890
+DocBookItemTagType
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699890
+block, paragraph, inline
+\end_layout
+
+\end_inset
+
+] The new-line policy for this tag, see Section
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "subsec:DocBook-New-line-policy"
+plural "false"
+caps "false"
+noprefix "false"
+
+\end_inset
+
+ for the details.
+ 
+\change_unchanged
+
 \end_layout
 
 \begin_layout Description
@@ -28487,6 +28884,52 @@ NONE
  This parameter only makes sense when itemising layouts are used, such as
  lists.
  
+\change_inserted 1075283030 1597699897
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted 1075283030 1597699897
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699900
+DocBookItemWrapperTagType
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699897
+block, paragraph, inline
+\end_layout
+
+\end_inset
+
+] The new-line policy for this tag, see Section
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "subsec:DocBook-New-line-policy"
+plural "false"
+caps "false"
+noprefix "false"
+
+\end_inset
+
+ for the details.
+ 
 \change_unchanged
 
 \end_layout
@@ -28618,6 +29061,54 @@ NONE
 
 , indicating that there is no inner tag: content is directly output without
  it.
+\change_inserted 1075283030 1597699904
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted 1075283030 1597699904
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699904
+DocBookInnerTagType
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699904
+block, paragraph, inline
+\end_layout
+
+\end_inset
+
+] The new-line policy for this tag, see Section
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "subsec:DocBook-New-line-policy"
+plural "false"
+caps "false"
+noprefix "false"
+
+\end_inset
+
+ for the details.
+ 
+\change_unchanged
+
 \end_layout
 
 \begin_layout Description
@@ -28668,7 +29159,11 @@ section
 \end_inset
 
 , and is only overridden when DocBook uses something else for sectioning
- (parts and chapters of a book).
+ (
+\change_inserted 1075283030 1597699921
+typically, 
+\change_inserted -970929547 1515110753
+parts and chapters of a book).
  
 \change_unchanged
 
@@ -28729,6 +29224,54 @@ tag
  in the example above.
  The default is the name of the float and always needs to be changed, as
  DocBook provides no generic inset tag.
+\change_inserted 1075283030 1597699924
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted 1075283030 1597699924
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699924
+DocBookTagType
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699924
+block, paragraph, inline
+\end_layout
+
+\end_inset
+
+] The new-line policy for this tag, see Section
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "subsec:DocBook-New-line-policy"
+plural "false"
+caps "false"
+noprefix "false"
+
+\end_inset
+
+ for the details.
+ 
+\change_unchanged
+
 \end_layout
 
 \begin_layout Description
@@ -28858,7 +29401,53 @@ NONE
 
 , indicating that there is no wrapper tag: tag and content are directly
  output without it.
-\change_deleted -970929547 1515111523
+\change_inserted 1075283030 1597699929
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted 1075283030 1597699929
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699932
+DocBookWrapperTagType
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597699929
+block, paragraph, inline
+\end_layout
+
+\end_inset
+
+] The new-line policy for this tag, see Section
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "subsec:DocBook-New-line-policy"
+plural "false"
+caps "false"
+noprefix "false"
+
+\end_inset
+
+ for the details.
+ 
+\change_unchanged
 
 \end_layout
 
@@ -29024,9 +29613,59 @@ Bibliography formatting
 
 \begin_layout Standard
 
+\change_deleted 1075283030 1597699984
+The 
+\change_inserted 1075283030 1597699985
+Included 
+\change_inserted -970929547 1515110187
+bibliograph
+\change_deleted 1075283030 1597699987
+y
+\change_inserted 1075283030 1597699987
+ies
+\change_inserted -970929547 1515110187
+ cannot be formatted: all fields are always output in the database-like
+ DocBook format (equivalent to a BibTeX file)
+\change_inserted 1075283030 1597700117
+, using the 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597700120
+biblioentry
+\end_layout
+
+\end_inset
+
+ tag
 \change_inserted -970929547 1515110187
-The bibliography cannot be formatted: all fields are always output in the
- database-like DocBook format (equivalent to a BibTeX file).
+.
+\change_inserted 1075283030 1597700092
+
+\end_layout
+
+\begin_layout Standard
+
+\change_inserted 1075283030 1597700112
+When the bibliographic entries are manually inserted into the LyX document
+ as Bibliography Items, the user deals with formatting themself: there is
+ no attempt of parsing what the user wrote, the string is directly used
+ (with the 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1597700076
+bibliomixed
+\end_layout
+
+\end_inset
+
+ tag).
+ 
 \change_unchanged
 
 \end_layout
diff --git a/lib/generate_contributions.py b/lib/generate_contributions.py
index 4e3e191..e864ebd 100755
--- a/lib/generate_contributions.py
+++ b/lib/generate_contributions.py
@@ -650,7 +650,7 @@ contributors = [
                  "Re: Patches to improve compatibility with modern C++ standard",
                  "m=158862338815864",
                  "4 May 2020",
-                 u"Windows compatibility patches, Docbook backend"),
+                 u"Windows compatibility patches, DocBook backend"),
 
      contributor(u"Matthias Kalle Dalheimer",
                  "kalle () kdab ! net",

commit 53a6cdb1f777c4ce6c65e600b9adaadbd68d96cd
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 17 23:06:26 2020 +0200

    DocBook: define new arguments in layouts to configure new-line behaviour.

diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py
index 2bb62e3..1164a12 100644
--- a/lib/scripts/layout2layout.py
+++ b/lib/scripts/layout2layout.py
@@ -11,7 +11,7 @@
 # This script will update a .layout file to current format
 
 # The latest layout format is also defined in src/TextClass.cpp
-currentFormat = 83
+currentFormat = 84
 
 
 # Incremented to format 4, 6 April 2007, lasgouttes
@@ -284,6 +284,11 @@ currentFormat = 83
 # Incremented to format 83, 2 August 2020 by dourouc05
 # New tags DocBookWrapperMergeWithPrevious and DocBookAbstract
 
+# Incremented to format 84, 17 August 2020 by dourouc05
+# New tags DocBookTagType, DocBookWrapperTagTagType,
+# DocBookItemWrapperTagTagType, DocBookItemTagTagType,
+# DocBookLabelTag
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
diff --git a/src/Floating.cpp b/src/Floating.cpp
index ebd1e41..d44afc3 100644
--- a/src/Floating.cpp
+++ b/src/Floating.cpp
@@ -31,8 +31,8 @@ Floating::Floating(string const & type, string const & placement,
 		   string const & refPrefix, std::string const & allowedplacement,
 		   string const & htmlTag, string const & htmlAttrib,
 		   docstring const & htmlStyle, string const & docbookTag,
-		   string const & docbookAttr, string const & required,
-		   bool usesfloat, bool ispredefined,
+		   string const & docbookAttr, string const & docbookTagType,
+           string const & required, bool usesfloat, bool ispredefined,
 		   bool allowswide, bool allowssideways)
 	: floattype_(type), placement_(placement), ext_(ext), within_(within),
 	  style_(style), name_(name), listname_(listName), listcommand_(listCmd),
@@ -40,7 +40,8 @@ Floating::Floating(string const & type, string const & placement,
 	  usesfloatpkg_(usesfloat), ispredefined_(ispredefined),
 	  allowswide_(allowswide), allowssideways_(allowssideways),
 	  html_tag_(htmlTag), html_attrib_(htmlAttrib), html_style_(htmlStyle),
-	  docbook_tag_(docbookTag), docbook_attr_(docbookAttr)
+	  docbook_tag_(docbookTag), docbook_attr_(docbookAttr),
+	  docbook_tag_type_(docbookTagType)
 {}
 
 
@@ -90,20 +91,30 @@ string const & Floating::docbookAttr() const
 
 string const & Floating::docbookTag(bool hasTitle) const
 {
-	docbook_tag_ = "";
-	if (floattype_ == "figure") {
-		docbook_tag_ = hasTitle ? "figure" : "informalfigure";
-	} else if (floattype_ == "table") {
-		docbook_tag_ = hasTitle ? "table" : "informaltable";
-	} else if (floattype_ == "algorithm") {
-		// TODO: no good translation for now! Figures are the closest match, as they can contain text.
-		// Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer.
-		docbook_tag_ = "figure";
+	if (docbook_tag_.empty()) {
+		docbook_tag_ = "";
+		if (floattype_ == "figure") {
+			docbook_tag_ = hasTitle ? "figure" : "informalfigure";
+		} else if (floattype_ == "table") {
+			docbook_tag_ = hasTitle ? "table" : "informaltable";
+		} else if (floattype_ == "algorithm") {
+			// TODO: no good translation for now! Figures are the closest match, as they can contain text.
+			// Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer.
+			docbook_tag_ = "figure";
+		}
 	}
 	return docbook_tag_;
 }
 
 
+string const & Floating::docbookTagType() const
+{
+	if (docbook_tag_type_ != "block" && docbook_tag_type_ != "paragraph" && docbook_tag_type_ != "inline")
+		docbook_tag_type_ = "block";
+	return docbook_tag_type_;
+}
+
+
 string const & Floating::docbookCaption() const
 {
 	docbook_caption_ = "";
diff --git a/src/Floating.h b/src/Floating.h
index d10694f..5cfea08 100644
--- a/src/Floating.h
+++ b/src/Floating.h
@@ -38,8 +38,9 @@ public:
 		 std::string const & refPrefix, std::string const & allowedplacement,
 		 std::string const & htmlType, std::string const & htmlClass,
 		 docstring const & htmlStyle, std::string const & docbookTag,
-		 std::string const & docbookAttr, std::string const & required,
-		 bool usesfloat, bool isprefined, bool allowswide, bool allowssideways);
+		 std::string const & docbookAttr, std::string const & docbookTagType,
+		 std::string const & required, bool usesfloat, bool isprefined,
+		 bool allowswide, bool allowssideways);
 	///
 	std::string const & floattype() const { return floattype_; }
 	///
@@ -84,6 +85,8 @@ public:
 	///
 	std::string const & docbookAttr() const;
 	///
+	std::string const & docbookTagType() const;
+	///
 	std::string const & docbookCaption() const;
 private:
 	///
@@ -115,9 +118,9 @@ private:
 	///
 	bool ispredefined_;
 	///
-	bool  allowswide_;
+	bool allowswide_;
 	///
-	bool  allowssideways_;
+	bool allowssideways_;
 	///
 	mutable std::string html_tag_;
 	///
@@ -132,6 +135,8 @@ private:
 	mutable std::string docbook_caption_;
 	/// caption tag (mostly, either caption or title)
 	std::string docbook_attr_;
+	/// DocBook tag type (block, paragraph, inline)
+	mutable std::string docbook_tag_type_;
 };
 
 
diff --git a/src/Layout.cpp b/src/Layout.cpp
index 5047506..102410d 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -106,20 +106,26 @@ enum LayoutTags {
 	LT_HTMLFORCECSS,
 	LT_DOCBOOKTAG,
 	LT_DOCBOOKATTR,
+	LT_DOCBOOKTAGTYPE,
 	LT_DOCBOOKININFO,
 	LT_DOCBOOKABSTRACT,
 	LT_DOCBOOKWRAPPERTAG,
 	LT_DOCBOOKWRAPPERATTR,
+	LT_DOCBOOKWRAPPERTAGTYPE,
 	LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS,
 	LT_DOCBOOKSECTIONTAG,
 	LT_DOCBOOKITEMWRAPPERTAG,
 	LT_DOCBOOKITEMWRAPPERATTR,
+	LT_DOCBOOKITEMWRAPPERTAGTYPE,
 	LT_DOCBOOKITEMTAG,
 	LT_DOCBOOKITEMATTR,
+	LT_DOCBOOKITEMTAGTYPE,
 	LT_DOCBOOKITEMLABELTAG,
 	LT_DOCBOOKITEMLABELATTR,
+	LT_DOCBOOKITEMLABELTAGTYPE,
 	LT_DOCBOOKITEMINNERTAG,
 	LT_DOCBOOKITEMINNERATTR,
+	LT_DOCBOOKITEMINNERTAGTYPE,
 	LT_DOCBOOKFORCEABSTRACTTAG,
 	LT_INPREAMBLE,
 	LT_HTMLTITLE,
@@ -223,23 +229,29 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 		{ "commanddepth",   LT_COMMANDDEPTH },
 		{ "copystyle",      LT_COPYSTYLE },
 		{ "dependson",      LT_DEPENDSON },
-		{ "docbookabstract",         LT_DOCBOOKABSTRACT },
-		{ "docbookattr",             LT_DOCBOOKATTR },
-		{ "docbookforceabstracttag", LT_DOCBOOKFORCEABSTRACTTAG },
-		{ "docbookininfo",           LT_DOCBOOKININFO },
-		{ "docbookitemattr",         LT_DOCBOOKITEMATTR },
-		{ "docbookiteminnerattr",    LT_DOCBOOKITEMINNERATTR },
-		{ "docbookiteminnertag",     LT_DOCBOOKITEMINNERTAG },
-		{ "docbookitemlabelattr",    LT_DOCBOOKITEMLABELATTR },
-		{ "docbookitemlabeltag",     LT_DOCBOOKITEMLABELTAG },
-		{ "docbookitemtag",          LT_DOCBOOKITEMTAG },
-		{ "docbookitemwrapperattr",  LT_DOCBOOKITEMWRAPPERATTR },
-		{ "docbookitemwrappertag",   LT_DOCBOOKITEMWRAPPERTAG },
-		{ "docbooksectiontag",       LT_DOCBOOKSECTIONTAG },
-		{ "docbooktag",              LT_DOCBOOKTAG },
-		{ "docbookwrapperattr",      LT_DOCBOOKWRAPPERATTR },
+		{ "docbookabstract",           LT_DOCBOOKABSTRACT },
+		{ "docbookattr",               LT_DOCBOOKATTR },
+		{ "docbookforceabstracttag",   LT_DOCBOOKFORCEABSTRACTTAG },
+		{ "docbookininfo",             LT_DOCBOOKININFO },
+		{ "docbookitemattr",           LT_DOCBOOKITEMATTR },
+		{ "docbookiteminnerattr",      LT_DOCBOOKITEMINNERATTR },
+		{ "docbookiteminnertag",       LT_DOCBOOKITEMINNERTAG },
+		{ "docbookiteminnertagtype",   LT_DOCBOOKITEMINNERTAGTYPE },
+		{ "docbookitemlabelattr",      LT_DOCBOOKITEMLABELATTR },
+		{ "docbookitemlabeltag",       LT_DOCBOOKITEMLABELTAG },
+		{ "docbookitemlabeltagtype",   LT_DOCBOOKITEMLABELTAGTYPE },
+		{ "docbookitemtag",            LT_DOCBOOKITEMTAG },
+		{ "docbookitemtagtype",        LT_DOCBOOKITEMTAGTYPE },
+		{ "docbookitemwrapperattr",    LT_DOCBOOKITEMWRAPPERATTR },
+		{ "docbookitemwrappertag",     LT_DOCBOOKITEMWRAPPERTAG },
+		{ "docbookitemwrappertagtype", LT_DOCBOOKITEMWRAPPERTAGTYPE },
+		{ "docbooksectiontag",         LT_DOCBOOKSECTIONTAG },
+		{ "docbooktag",                LT_DOCBOOKTAG },
+		{ "docbooktagtype",            LT_DOCBOOKTAGTYPE },
+		{ "docbookwrapperattr",        LT_DOCBOOKWRAPPERATTR },
 		{ "docbookwrappermergewithprevious", LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS },
-		{ "docbookwrappertag",       LT_DOCBOOKWRAPPERTAG },
+		{ "docbookwrappertag",         LT_DOCBOOKWRAPPERTAG },
+		{ "docbookwrappertagtype",     LT_DOCBOOKWRAPPERTAGTYPE },
 		{ "end",            LT_END },
 		{ "endlabelstring", LT_ENDLABELSTRING },
 		{ "endlabeltype",   LT_ENDLABELTYPE },
@@ -733,6 +745,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 			lex >> docbookattr_;
 			break;
 
+		case LT_DOCBOOKTAGTYPE:
+			lex >> docbooktagtype_;
+			break;
+
 		case LT_DOCBOOKFORCEABSTRACTTAG:
 			lex >> docbookforceabstracttag_;
 			break;
@@ -753,6 +769,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 			lex >> docbookwrapperattr_;
 			break;
 
+		case LT_DOCBOOKWRAPPERTAGTYPE:
+			lex >> docbookwrappertagtype_;
+			break;
+
 		case LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS:
 			lex >> docbookwrappermergewithprevious_;
 			break;
@@ -769,6 +789,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 			lex >> docbookitemwrapperattr_;
 			break;
 
+		case LT_DOCBOOKITEMWRAPPERTAGTYPE:
+			lex >> docbookitemwrappertagtype_;
+			break;
+
 		case LT_DOCBOOKITEMTAG:
 			lex >> docbookitemtag_;
 			break;
@@ -777,6 +801,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 			lex >> docbookitemattr_;
 			break;
 
+		case LT_DOCBOOKITEMTAGTYPE:
+			lex >> docbookitemtagtype_;
+			break;
+
 		case LT_DOCBOOKITEMLABELTAG:
 			lex >> docbookitemlabeltag_;
 			break;
@@ -785,6 +813,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 			lex >> docbookitemlabelattr_;
 			break;
 
+		case LT_DOCBOOKITEMLABELTAGTYPE:
+			lex >> docbookitemlabeltagtype_;
+			break;
+
 		case LT_DOCBOOKITEMINNERTAG:
 			lex >> docbookiteminnertag_;
 			break;
@@ -793,6 +825,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 			lex >> docbookiteminnerattr_;
 			break;
 
+		case LT_DOCBOOKITEMINNERTAGTYPE:
+			lex >> docbookiteminnertagtype_;
+			break;
+
 		case LT_SPELLCHECK:
 			lex >> spellcheck;
 			break;
@@ -1608,6 +1644,8 @@ void Layout::write(ostream & os) const
 		os << "\tDocBookTag " << docbooktag_ << '\n';
 	if(!docbookattr_.empty())
 		os << "\tDocBookAttr " << docbookattr_ << '\n';
+	if(!docbooktagtype_.empty())
+		os << "\tDocBookTagType " << docbooktagtype_ << '\n';
 	if(!docbookininfo_.empty())
 		os << "\tDocBookInInfo " << docbookininfo_ << '\n';
 	os << "\tDocBookAbstract " << docbookabstract_ << '\n';
@@ -1615,25 +1653,35 @@ void Layout::write(ostream & os) const
 		os << "\tDocBookWrapperTag " << docbookwrappertag_ << '\n';
 	if(!docbookwrapperattr_.empty())
 		os << "\tDocBookWrapperAttr " << docbookwrapperattr_ << '\n';
+	if(!docbookwrappertagtype_.empty())
+		os << "\tDocBookWrapperTagType " << docbookwrappertagtype_ << '\n';
 	if(!docbooksectiontag_.empty())
 		os << "\tDocBookSectionTag " << docbooksectiontag_ << '\n';
 	if(!docbookitemtag_.empty())
 		os << "\tDocBookItemTag " << docbookitemtag_ << '\n';
 	if(!docbookitemattr_.empty())
 		os << "\tDocBookItemAttr " << docbookitemattr_ << '\n';
+	if(!docbookitemtagtype_.empty())
+		os << "\tDocBookItemTagType " << docbookitemtagtype_ << '\n';
 	if(!docbookitemwrappertag_.empty())
 		os << "\tDocBookItemWrapperTag " << docbookitemwrappertag_ << '\n';
 	if(!docbookitemwrapperattr_.empty())
 		os << "\tDocBookItemWrapperAttr " << docbookitemwrapperattr_ << '\n';
+	if(!docbookitemwrappertagtype_.empty())
+		os << "\tDocBookItemWrapperTagType " << docbookitemwrappertagtype_ << '\n';
 	os << "\tDocBookItemWrapperMergeWithPrevious " << docbookwrappermergewithprevious_ << '\n';
 	if(!docbookitemlabeltag_.empty())
 		os << "\tDocBookItemLabelTag " << docbookitemlabeltag_ << '\n';
 	if(!docbookitemlabelattr_.empty())
 		os << "\tDocBookItemLabelAttr " << docbookitemlabelattr_ << '\n';
+	if(!docbookitemlabeltagtype_.empty())
+		os << "\tDocBookItemLabelTagType " << docbookitemlabeltagtype_ << '\n';
 	if(!docbookiteminnertag_.empty())
 		os << "\tDocBookItemInnerTag " << docbookiteminnertag_ << '\n';
 	if(!docbookiteminnerattr_.empty())
 		os << "\tDocBookItemInnerAttr " << docbookiteminnerattr_ << '\n';
+	if(!docbookiteminnertagtype_.empty())
+		os << "\tDocBookItemInnerTagType " << docbookiteminnertagtype_ << '\n';
 	if(!docbookforceabstracttag_.empty())
 		os << "\tDocBookForceAbstractTag " << docbookforceabstracttag_ << '\n';
 	os << "\tSpellcheck " << spellcheck << "\n"
@@ -1786,9 +1834,12 @@ string Layout::defaultCSSClass() const
 
 string const & Layout::docbooktag() const
 {
-	// No sensible default value, unhappily...
-	if (docbooktag_.empty())
-		docbooktag_ = to_utf8(name_);
+	if (docbooktag_.empty()) {
+		if (to_ascii(name_) == "Plain Layout")
+			docbooktag_ = "para";
+		else // No sensible default value, unhappily...
+			docbooktag_ = to_utf8(name_);
+	}
 	return docbooktag_;
 }
 
@@ -1800,6 +1851,20 @@ string const & Layout::docbookattr() const
 }
 
 
+bool isValidTagType(std::string type)
+{
+	return !(type.empty() || (type != "block" && type != "paragraph" && type != "inline"));
+}
+
+
+string const & Layout::docbooktagtype() const
+{
+	if (!isValidTagType(docbooktagtype_))
+		docbooktagtype_ = "block";
+	return docbooktagtype_;
+}
+
+
 string const & Layout::docbookininfo() const
 {
 	// Indeed, a trilean. Only titles should be "maybe": otherwise, metadata is "always", content is "never". 
@@ -1823,6 +1888,14 @@ string const & Layout::docbookwrapperattr() const
 }
 
 
+string const & Layout::docbookwrappertagtype() const
+{
+	if (!isValidTagType(docbookwrappertagtype_))
+		docbookwrappertagtype_ = "block";
+	return docbookwrappertagtype_;
+}
+
+
 string const & Layout::docbooksectiontag() const
 {
 	if (docbooksectiontag_.empty())
@@ -1845,9 +1918,19 @@ string const & Layout::docbookitemwrapperattr() const
 }
 
 
+string const & Layout::docbookitemwrappertagtype() const
+{
+	if (!isValidTagType(docbookitemwrappertagtype_))
+		docbookitemwrappertagtype_ = "block";
+	return docbookitemwrappertagtype_;
+}
+
+
 string const & Layout::docbookitemtag() const
 {
-    return docbookitemtag_;
+	if (docbookitemtag_.empty())
+		docbookitemtag_ = "NONE";
+	return docbookitemtag_;
 }
 
 
@@ -1857,6 +1940,14 @@ string const & Layout::docbookitemattr() const
 }
 
 
+string const & Layout::docbookitemtagtype() const
+{
+	if (!isValidTagType(docbookitemtagtype_))
+		docbookitemtagtype_ = "block";
+	return docbookitemtagtype_;
+}
+
+
 string const & Layout::docbookitemlabeltag() const
 {
 	if (docbookitemlabeltag_.empty())
@@ -1871,6 +1962,14 @@ string const & Layout::docbookitemlabelattr() const
 }
 
 
+string const & Layout::docbookitemlabeltagtype() const
+{
+	if (!isValidTagType(docbookitemlabeltagtype_))
+		docbookitemlabeltagtype_ = "block";
+	return docbookitemlabeltagtype_;
+}
+
+
 string const & Layout::docbookiteminnertag() const
 {
 	if (docbookiteminnertag_.empty())
@@ -1885,6 +1984,14 @@ string const & Layout::docbookiteminnerattr() const
 }
 
 
+string const & Layout::docbookiteminnertagtype() const
+{
+	if (!isValidTagType(docbookiteminnertagtype_))
+		docbookiteminnertagtype_ = "block";
+	return docbookiteminnertagtype_;
+}
+
+
 std::string const & Layout::docbookforceabstracttag() const
 {
 	if (docbookforceabstracttag_.empty())
diff --git a/src/Layout.h b/src/Layout.h
index a894142..14784a2 100644
--- a/src/Layout.h
+++ b/src/Layout.h
@@ -197,6 +197,8 @@ public:
 	///
 	std::string const & docbookattr() const;
 	///
+	std::string const & docbooktagtype() const;
+	///
 	std::string const & docbookininfo() const;
 	///
 	bool docbookabstract() const { return docbookabstract_; }
@@ -205,6 +207,8 @@ public:
 	///
 	std::string const & docbookwrapperattr() const;
 	///
+	std::string const & docbookwrappertagtype() const;
+	///
 	bool docbookwrappermergewithprevious() const { return docbookwrappermergewithprevious_; }
 	///
 	std::string const & docbooksectiontag() const;
@@ -213,18 +217,26 @@ public:
 	///
 	std::string const & docbookitemwrapperattr() const;
 	///
+	std::string const & docbookitemwrappertagtype() const;
+	///
 	std::string const & docbookitemlabeltag() const;
 	///
 	std::string const & docbookitemlabelattr() const;
 	///
+	std::string const & docbookitemlabeltagtype() const;
+	///
 	std::string const & docbookiteminnertag() const;
 	///
 	std::string const & docbookiteminnerattr() const;
 	///
+	std::string const & docbookiteminnertagtype() const;
+	///
 	std::string const & docbookitemtag() const;
 	///
 	std::string const & docbookitemattr() const;
 	///
+	std::string const & docbookitemtagtype() const;
+	///
 	std::string const & docbookforceabstracttag() const;
 	///
 	bool isParagraph() const { return latextype == LATEX_PARAGRAPH; }
@@ -495,27 +507,39 @@ private:
 	mutable std::string docbooktag_;
 	/// Roles to add to docbooktag_, if any (default: none).
 	mutable std::string docbookattr_;
+	/// DocBook tag type corresponding to this layout (block, paragraph, or inline; default: block).
+	mutable std::string docbooktagtype_;
 	/// DocBook tag corresponding to this item (mainly for lists).
 	mutable std::string docbookitemtag_;
 	/// Roles to add to docbookitemtag_, if any (default: none).
 	mutable std::string docbookitemattr_;
+	/// DocBook tag type corresponding to this item (block, paragraph, or inline; default: block).
+	mutable std::string docbookitemtagtype_;
 	/// DocBook tag corresponding to the wrapper around an item (mainly for lists).
 	mutable std::string docbookitemwrappertag_;
 	/// Roles to add to docbookitemwrappertag_, if any (default: none).
 	mutable std::string docbookitemwrapperattr_;
-	/// DocBook tag corresponding to this label (only for description lists;
+	/// DocBook tag type corresponding to the wrapper around an item (block, paragraph, or inline; default: block).
+	mutable std::string docbookitemwrappertagtype_;
+	/// DocBook tag corresponding to this label (mostly for description lists;
 	/// labels in the common sense do not exist with DocBook).
 	mutable std::string docbookitemlabeltag_;
 	/// Roles to add to docbooklabeltag_, if any (default: none).
 	mutable std::string docbookitemlabelattr_;
+	/// DocBook tag corresponding to this label (block, paragraph, or inline; default: block).
+	mutable std::string docbookitemlabeltagtype_;
 	/// DocBook tag to add within the item, around its direct content (mainly for lists).
 	mutable std::string docbookiteminnertag_;
 	/// Roles to add to docbookiteminnertag_, if any (default: none).
 	mutable std::string docbookiteminnerattr_;
+	/// DocBook tag to add within the item, around its direct content (block, paragraph, or inline; default: block).
+	mutable std::string docbookiteminnertagtype_;
 	/// DocBook tag corresponding to this wrapper around the main tag.
 	mutable std::string docbookwrappertag_;
 	/// Roles to add to docbookwrappertag_, if any (default: none).
 	mutable std::string docbookwrapperattr_;
+	/// DocBook tag corresponding to this wrapper around the main tag (block, paragraph, or inline; default: block).
+	mutable std::string docbookwrappertagtype_;
 	/// Whether this wrapper tag may be merged with the previously opened wrapper tag.
 	bool docbookwrappermergewithprevious_;
 	/// Outer tag for this section, only if this layout represent a sectionning item, including chapters
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index 79cdabd..e413403 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -62,7 +62,7 @@ namespace lyx {
 // You should also run the development/tools/updatelayouts.py script,
 // to update the format of all of our layout files.
 //
-int const LAYOUT_FORMAT = 83; // tcuvelier: DocBookWrapperMergeWithPrevious.
+int const LAYOUT_FORMAT = 84; // tcuvelier: DocBook*TagType.
 
 
 // Layout format for the current lyx file format. Controls which format is
@@ -1378,6 +1378,7 @@ bool TextClass::readFloat(Lexer & lexrc)
 		FT_HTMLTAG,
 		FT_DOCBOOKATTR,
 		FT_DOCBOOKTAG,
+		FT_DOCBOOKTAGTYPE,
 		FT_LISTCOMMAND,
 		FT_REFPREFIX,
 		FT_ALLOWED_PLACEMENT,
@@ -1393,6 +1394,7 @@ bool TextClass::readFloat(Lexer & lexrc)
 		{ "allowswide", FT_ALLOWS_WIDE },
 		{ "docbookattr", FT_DOCBOOKATTR },
 		{ "docbooktag", FT_DOCBOOKTAG },
+		{ "docbooktagtype", FT_DOCBOOKTAGTYPE },
 		{ "end", FT_END },
 		{ "extension", FT_EXT },
 		{ "guiname", FT_NAME },
@@ -1419,6 +1421,7 @@ bool TextClass::readFloat(Lexer & lexrc)
 	string htmltag;
 	string docbookattr;
 	string docbooktag;
+	string docbooktagtype;
 	string listname;
 	string listcommand;
 	string name;
@@ -1540,6 +1543,10 @@ bool TextClass::readFloat(Lexer & lexrc)
 			lexrc.next();
 			docbooktag = lexrc.getString();
 			break;
+		case FT_DOCBOOKTAGTYPE:
+			lexrc.next();
+			docbooktagtype = lexrc.getString();
+			break;
 		case FT_END:
 			getout = true;
 			break;
@@ -1568,8 +1575,8 @@ bool TextClass::readFloat(Lexer & lexrc)
 		Floating fl(type, placement, ext, within, style, name,
 			listname, listcommand, refprefix, allowed_placement,
 			htmltag, htmlattr, htmlstyle, docbooktag, docbookattr,
-			required, usesfloat, ispredefined, allowswide,
-			allowssideways);
+			docbooktagtype, required, usesfloat, ispredefined,
+	        allowswide, allowssideways);
 		floatlist_.newFloat(fl);
 		// each float has its own counter
 		counters_.newCounter(from_ascii(type), from_ascii(within),

commit f7194ce2f53756a6ede98fe443957c73df6854a7
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 16 00:59:43 2020 +0200

    Simplify code to generate only one paragraph at a time.

diff --git a/autotests/export/docbook/basic.xml b/autotests/export/docbook/basic.xml
index f208ae6..6f4a828 100644
--- a/autotests/export/docbook/basic.xml
+++ b/autotests/export/docbook/basic.xml
@@ -1,69 +1,62 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- This DocBook file was created by LyX 2.4.0dev
   See http://www.lyx.org/ for more information -->
-<article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.1">
-
-<info><title>I am a title</title>
-<author><personname>I am an author</personname></author>
+<article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
+<info>
+<title>I am a title</title>
+<author>
+<personname>I am an author</personname>
+</author>
 <date>I am a date</date>
-
-<abstract><para>I am an abstract</para>
+<abstract>
+<para>I am an abstract</para>
 <para>I am also an abstract</para>
 </abstract>
 </info>
-<para>I am a standard paragraph. </para>
-<section xml:id="sec.Sec-1-0">
+<section xml:id="sec.Sec-1">
 <title>I am the first section </title>
 <para>I am the first paragraph of the first section. </para>
-
 <para>I am the second paragraph of the first section. </para>
-
-<blockquote><para>I am a quote
- <inlineequation>
-  <m:math>
-  <m:alt role='tex'>\,with\,a\,formula</m:alt>
+<blockquote>
+<para>I am a quote<inlineequation>
+<alt role='tex'>\,with\,a\,formula</alt>
+ <m:math>
+ 
  <m:mrow>
-  <m:mrow>
-  <m:mspace width="6px"/><m:mi>w</m:mi><m:mi>i</m:mi><m:mi>t</m:mi><m:mi>h</m:mi>
-  <m:mspace width="6px"/><m:mi>a</m:mi>
-  <m:mspace width="6px"/><m:mi>f</m:mi><m:mi>o</m:mi><m:mi>r</m:mi><m:mi>m</m:mi><m:mi>u</m:mi><m:mi>l</m:mi><m:mi>a</m:mi>
+  <m:mrow><m:mspace width="6px" /><m:mi>w</m:mi><m:mi>i</m:mi><m:mi>t</m:mi><m:mi>h</m:mi><m:mspace width="6px" /><m:mi>a</m:mi><m:mspace width="6px" /><m:mi>f</m:mi><m:mi>o</m:mi><m:mi>r</m:mi><m:mi>m</m:mi><m:mi>u</m:mi><m:mi>l</m:mi><m:mi>a</m:mi>
   </m:mrow>
  </m:mrow>
-  </m:math>
- </inlineequation>. </para>
+ </m:math>
+</inlineequation>. </para>
 </blockquote>
-<para>
- <informalequation>
-  <m:math>
-  <m:alt role='tex'>Formula!</m:alt>
+<para><informalequation>
+<alt role='tex'>Formula!</alt>
+ <m:math>
+ 
  <m:mrow>
   <m:mrow><m:mi>F</m:mi><m:mi>o</m:mi><m:mi>r</m:mi><m:mi>m</m:mi><m:mi>u</m:mi><m:mi>l</m:mi><m:mi>a</m:mi><m:mo>!</m:mo>
   </m:mrow>
  </m:mrow>
-  </m:math>
- </informalequation>
- <informalequation xml:id='eq.EQ.-1'>
-  <m:math>
-  <m:alt role='tex'>\text{I am a formula with a ref.}\label{eq:EQ.}</m:alt>
+ </m:math>
+</informalequation><informalequation xml:id="eq.EQ.">
+<alt role='tex'>\text{I am a formula with a ref.}\label{eq:EQ.}</alt>
+ <m:math>
+ 
  <m:mrow>
   <m:mstyle mathvariant='normal'>
    <m:mrow><m:mi>I</m:mi> <m:mi>a</m:mi><m:mi>m</m:mi> <m:mi>a</m:mi> <m:mi>f</m:mi><m:mi>o</m:mi><m:mi>r</m:mi><m:mi>m</m:mi><m:mi>u</m:mi><m:mi>l</m:mi><m:mi>a</m:mi> <m:mi>w</m:mi><m:mi>i</m:mi><m:mi>t</m:mi><m:mi>h</m:mi> <m:mi>a</m:mi> <m:mi>r</m:mi><m:mi>e</m:mi><m:mi>f</m:mi><m:mn>.</m:mn>
    </m:mrow>
   </m:mstyle>
  </m:mrow>
-  </m:math>
- </informalequation></para>
-
-<para>See <xref linkend="sec.Sec-2kqgsdiflhqsdlifgjuzer-povtuizmvnuer-t-vmsrmfli--uh--a--rtpfuo----rtpc.m-ca-rgifzapeu-tvgz-2" />.</para>
-
-<para>Also, a formula with an user-defined macro that outputs well in LaTeX but cannot in MathML (hence replaced by picture): 
- <inlineequation>
-  <m:math>
-  <m:alt role='tex'>\testmacro</m:alt>
-  </m:math>
- </inlineequation>. </para>
-
-<!-- \latexCommandThatShouldBeCommented --><section>
+ </m:math>
+</informalequation></para>
+<para>See <xref linkend="sec.Sec-2kqgsdiflhqsdlifgjuzer-povtuizmvnuer-t-vmsrmfli--uh--a--rtpfuo----rtpc.m-ca-rgifzapeu-tvgz" />.</para>
+<para>Also, a formula with an user-defined macro that outputs well in LaTeX but cannot in MathML (hence replaced by picture): <inlineequation>
+<alt role='tex'>\testmacro</alt>
+<mathphrase>MathML export failed. Please report this as a bug.</mathphrase>
+</inlineequation>. </para>
+<!-- \latexCommandThatShouldBeCommented -->
+<section>
 <title>I am the first subsection</title>
 <para>I am the only paragraph of the first subsection. </para>
 </section>
@@ -72,174 +65,150 @@
 <para>I am the only paragraph of the second subsection. </para>
 </section>
 </section>
-<section xml:id="sec.Sec-2kqgsdiflhqsdlifgjuzer-povtuizmvnuer-t-vmsrmfli--uh--a--rtpfuo----rtpc.m-ca-rgifzapeu-tvgz-2">
+<section xml:id="sec.Sec-2kqgsdiflhqsdlifgjuzer-povtuizmvnuer-t-vmsrmfli--uh--a--rtpfuo----rtpc.m-ca-rgifzapeu-tvgz">
 <title>I am the second section </title>
 <para>I am the only paragraph of the second section. <link xlink:href="http://example.org">Hyperlink.</link> “Text between quotes.”</para>
-
-<para>See <xref linkend="sec.Sec-1-0" />.</para>
+<para>See <xref linkend="sec.Sec-1" />.</para>
 </section>
 <section>
 <title>I am the third section and I have fun with lists</title>
-
-
-<orderedlist><listitem><para>First item. </para>
-<para>Second line of the first item, after a line break. </para>
-</listitem>
-
-<listitem><para>Second item. </para>
-</listitem>
-</orderedlist>
-
-
-<itemizedlist><listitem><para>Item has no order (1). </para>
-</listitem>
-
-<listitem><para>Item has no order (2). </para>
-</listitem>
-</itemizedlist>
-
-<variablelist><varlistentry><term>Word</term>
-
-
-<listitem><para> description</para>
-</listitem></varlistentry>
-<varlistentry><term>Sentence</term>
-
-
-<listitem><para> meaning</para>
-</listitem></varlistentry>
-</variablelist>
+<orderedlist><listitem>First item. 
+<br />
+Second line of the first item, after a line break. </listitem></orderedlist>
+<orderedlist><listitem>Second item. </listitem></orderedlist>
+<itemizedlist><listitem>Item has no order (1). </listitem></itemizedlist>
+<itemizedlist><listitem>Item has no order (2). </listitem></itemizedlist>
+<variablelist><listitem><varlistentry>
+
+Word description<!-- Output Error: Closing tag `listitem' when other tags are open, namely: -->
+<!-- Output Error: varlistentry -->
+</varlistentry></listitem></variablelist>
+<variablelist><listitem><varlistentry>
+
+Sentence meaning<!-- Output Error: Closing tag `listitem' when other tags are open, namely: -->
+<!-- Output Error: varlistentry -->
+</varlistentry></listitem></variablelist>
 </section>
 <section>
 <title>I am the fourth section and I deal with formatting. </title>
 <para>The following paragraph should be code. </para>
-
 <para><programlisting>I am some code. 
-I am a second line of code. </programlisting>I am no more code. </para>
-
+I am a second line of code. 
+</programlisting>I am no more code. </para>
 <para>This line has inline code. <code>This has typewriter font</code><footnote><para>I repeat that in a footnote.</para>
 </footnote>. </para>
-
 <para>On the other hand, <footnote><para>this footnote</para>
-
 <para>has multiple </para>
-
 <para>paragraphs.</para>
 </footnote>. </para>
 </section>
 <section>
 <title>I am the fifth section and I deal with floats</title>
 <para>Now, three tables: </para>
-
-
-<table><caption>I am a table caption below the table.</caption>
-
-
-<tbody><tr><td align='center' valign='top'>Table 1</td>
+<table>
+<caption>I am a table caption below the table.</caption>
+<tbody>
+<tr>
+<td align='center' valign='top'>Table 1</td>
 <td align='center' valign='top'>Table 2</td>
 <td align='center' valign='top'>Table 3</td>
 </tr>
-<tr><td align='center' valign='top'>Row 1</td>
+<tr>
+<td align='center' valign='top'>Row 1</td>
 <td align='center' valign='top'></td>
 <td align='center' valign='top'>Col 3, row 1</td>
 </tr>
-<tr><td align='center' valign='top'>Row 2</td>
+<tr>
+<td align='center' valign='top'>Row 2</td>
 <td align='center' valign='top'></td>
 <td align='center' valign='top'>Col 3, row 2</td>
-</tr></tbody>
-
+</tr>
+</tbody>
 </table>
-
-
-<table><caption>I am a table caption above the table.</caption>
-
-
-
-<tbody><tr><td align='center' valign='top'>Table 1</td>
+<table>
+<caption>I am a table caption above the table.</caption>
+<tbody>
+<tr>
+<td align='center' valign='top'>Table 1</td>
 <td align='center' valign='top'>Table 2</td>
 <td align='center' valign='top'>Table 3</td>
 </tr>
-<tr><td align='center' valign='top'>Row 1</td>
+<tr>
+<td align='center' valign='top'>Row 1</td>
 <td align='center' valign='top'></td>
 <td align='center' valign='top'>Col 3, row 1</td>
 </tr>
-<tr><td align='center' valign='top'>Row 2</td>
+<tr>
+<td align='center' valign='top'>Row 2</td>
 <td align='center' valign='top'></td>
 <td align='center' valign='top'>Col 3, row 2</td>
-</tr></tbody>
+</tr>
+</tbody>
 </table>
-
-
-
-
-<informaltable><tbody><tr><td align='center' valign='top'>Table that has no caption 1</td>
+<informaltable>
+<tbody>
+<tr>
+<td align='center' valign='top'>Table that has no caption 1</td>
 <td align='center' valign='top'>Table that has no caption 2</td>
 <td align='center' valign='top'>Table that has no caption 3</td>
 </tr>
-<tr><td align='center' valign='top'>Row 1</td>
+<tr>
+<td align='center' valign='top'>Row 1</td>
 <td align='center' valign='top'></td>
 <td align='center' valign='top'>Col 3, row 1</td>
 </tr>
-<tr><td align='center' valign='top'>Row 2</td>
+<tr>
+<td align='center' valign='top'>Row 2</td>
 <td align='center' valign='top'></td>
 <td align='center' valign='top'>Col 3, row 2</td>
-</tr></tbody>
+</tr>
+</tbody>
 </informaltable>
-
 <para>Then, one figure: </para>
-
-
-<figure><title>Caption.</title>
-
-
-<mediaobject><imageobject><imagedata fileref="0_mnt_d_Thibaut_LyX_autotests_export_docbook_lyx-logo.png"  />
+<figure>
+<title>Caption.</title>
+<mediaobject>
+<imageobject>
+<imagedata fileref="D:/LyX/lyx-unstable/autotests/export/docbook/lyx-logo.png"  />
 </imageobject>
 </mediaobject>
-
 </figure>
 </section>
 <section>
 <title>I am the sixth section and I really like bibliographies</title>
 <para>This text has references. First reference: <biblioref endterm="big" />. Second reference: <biblioref endterm="small" />. Both at the same time: <biblioref endterm="big" />, <biblioref endterm="small" />. A book: <biblioref endterm="Gro60" />. </para>
-
 <para>Many things, just testing for completeness: <biblioref endterm="article" />, <biblioref endterm="book" />, <biblioref endterm="booklet" />, <biblioref endterm="conference" />, <biblioref endterm="inbook" />, <biblioref endterm="incollection" />. </para>
 </section>
 <section>
 <title>I am the seventh section and I deal with indices</title>
 <para>First, a term to index: <indexterm type="idx"><primary>Term to index</primary></indexterm>. Then a term to add to the second index: <indexterm type="oth"><primary>Term to add to the second index</primary></indexterm>. </para>
-
 <para>Then several terms for the first index: <indexterm type="idx"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>. </para>
-
 <para>With a see: <indexterm type="idx"><primary>Term</primary><see>index</see></indexterm>. With a see also: <indexterm type="idx"><primary>Term</primary><seealso>index</seealso></indexterm>. </para>
-
 <para>Several terms with a see: <indexterm type="idx"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary><see>index</see></indexterm>. Several terms with a see also: <indexterm type="idx"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary><seealso>index</seealso></indexterm>. </para>
-
-<para>A start of range: <indexterm type="idx" class="startofrange" xml:id="Term-to-index-3"><primary>Term to index</primary></indexterm>. The corresponding end of range: <indexterm type="idx" class="endofrange" startref="Term-to-index-3"><primary>Term to index</primary></indexterm>.</para>
-
-<para>Several terms with a start of range: <indexterm type="idx" class="startofrange" xml:id="Term.to.index-4"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>. The corresponding end of range: <indexterm type="idx" class="endofrange" startref="Term.to.index-4"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>.</para>
-
-<para>These terms already appeared before! Start of range: <indexterm type="idx" class="startofrange" xml:id="Term.to.index-0-5"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>. The corresponding end of range: <indexterm type="idx" class="endofrange" startref="Term.to.index-0-5"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>.</para>
+<para>A start of range: <indexterm type="idx" class="startofrange" xml:id="Term-to-index"><primary>Term to index</primary></indexterm>. The corresponding end of range: <indexterm type="idx" class="endofrange" startref="Term-to-index"><primary>Term to index</primary></indexterm>.</para>
+<para>Several terms with a start of range: <indexterm type="idx" class="startofrange" xml:id="Term.to.index"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>. The corresponding end of range: <indexterm type="idx" class="endofrange" startref="Term.to.index"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>.</para>
+<para>These terms already appeared before! Start of range: <indexterm type="idx" class="startofrange" xml:id="Term.to.index-0"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>. The corresponding end of range: <indexterm type="idx" class="endofrange" startref="Term.to.index-0"><primary>Term</primary><secondary>to</secondary><tertiary>index</tertiary></indexterm>.</para>
 </section>
 <section>
 <title>I am the eight section and I deal with star sections</title>
-<bridgehead renderas="part">Star part</bridgehead>
+<bridgehead renderas='other' otherrenderas='part'>Star part</bridgehead>
 <bridgehead renderas="sect1">Star section (sect1)</bridgehead>
 <bridgehead renderas="sect2">Star subsection (sect2)</bridgehead>
 <bridgehead renderas="sect3">Star subsubsection (sect3)</bridgehead>
 <bridgehead renderas="sect4">Star paragraph (sect4)</bridgehead>
 <bridgehead renderas="sect5">Star subparagraph (sect5)</bridgehead>
 </section>
-
-<bibliography><title>References</title>
-
-<biblioentry xml:id="article"><title>The title of the work</title><volumenum>4</volumenum><artpagenums>201-213</artpagenums><bibliomisc role="type">article</bibliomisc>
+<bibliography>
+<title>References</title>
+<biblioentry xml:id="article">
+<title>The title of the work</title><volumenum>4</volumenum><artpagenums>201-213</artpagenums><bibliomisc role="type">article</bibliomisc>
 <pubdate>1993</pubdate>
-
-<biblioset relation="journal"><title>The name of the journal</title>
+<biblioset relation="journal">
+<title>The name of the journal</title>
 </biblioset>
-
-
-<authorgroup><author><personname><firstname>Peter</firstname>
+<authorgroup><author>
+<personname>
+<firstname>Peter</firstname>
 <surname>Adams</surname>
 </personname>
 </author>
@@ -247,119 +216,119 @@ I am a second line of code. </programlisting>I am no more code. </para>
 <biblioid class="pubsnumber">2</biblioid>
 <bibliomisc role="note">An optional note</bibliomisc>
 </biblioentry>
-
-<biblioentry xml:id="book"><title>The title of the work</title><volumenum>4</volumenum><edition>3</edition><bibliomisc role="type">book</bibliomisc>
-
-<publisher><publishername>The name of the publisher</publishername>
+<biblioentry xml:id="book">
+<title>The title of the work</title><volumenum>4</volumenum><edition>3</edition><bibliomisc role="type">book</bibliomisc>
+<publisher>
+<publishername>The name of the publisher</publishername>
 <address>The address</address></publisher>
 <pubdate>1993</pubdate>
-
-
-<authorgroup><author><personname><firstname>Peter</firstname>
+<authorgroup><author>
+<personname>
+<firstname>Peter</firstname>
 <surname>Babington</surname>
 </personname>
 </author>
 </authorgroup>
 <bibliomisc role="note">An optional note</bibliomisc>
 </biblioentry>
-
-<biblioentry xml:id="booklet"><title>The title of the work</title><bibliomisc role="type">booklet</bibliomisc>
+<biblioentry xml:id="booklet">
+<title>The title of the work</title><bibliomisc role="type">booklet</bibliomisc>
 <pubdate>1993</pubdate>
-
-
-<authorgroup><author><personname><firstname>Peter</firstname>
+<authorgroup><author>
+<personname>
+<firstname>Peter</firstname>
 <surname>Caxton</surname>
 </personname>
 </author>
 </authorgroup>
 </biblioentry>
-
-<biblioentry xml:id="conference"><title>The title of the work</title><artpagenums>213</artpagenums><bibliomisc role="type">conference</bibliomisc>
-
-<publisher><publishername>The publisher</publishername>
+<biblioentry xml:id="conference">
+<title>The title of the work</title><artpagenums>213</artpagenums><bibliomisc role="type">conference</bibliomisc>
+<publisher>
+<publishername>The publisher</publishername>
 </publisher>
 <pubdate>1993</pubdate>
-
-
-<authorgroup><author><personname><firstname>Peter</firstname>
+<authorgroup><author>
+<personname>
+<firstname>Peter</firstname>
 <surname>Draper</surname>
 </personname>
 </author>
 </authorgroup>
 </biblioentry>
-
-<biblioentry xml:id="inbook"><title>The title of the work</title><artpagenums>201-213</artpagenums><bibliomisc role="type">inbook</bibliomisc>
-
-<publisher><publishername>The name of the publisher</publishername>
+<biblioentry xml:id="inbook">
+<title>The title of the work</title><artpagenums>201-213</artpagenums><bibliomisc role="type">inbook</bibliomisc>
+<publisher>
+<publishername>The name of the publisher</publishername>
 </publisher>
 <pubdate>1993</pubdate>
-
-
-<authorgroup><author><personname><firstname>Peter</firstname>
+<authorgroup><author>
+<personname>
+<firstname>Peter</firstname>
 <surname>Eston</surname>
 </personname>
 </author>
 </authorgroup>
 </biblioentry>
-
-<biblioentry xml:id="incollection"><title>The title of the work</title><volumenum>4</volumenum><edition>3</edition><artpagenums>201-213</artpagenums><bibliomisc role="type">incollection</bibliomisc>
-
-<publisher><publishername>The name of the publisher</publishername>
+<biblioentry xml:id="incollection">
+<title>The title of the work</title><volumenum>4</volumenum><edition>3</edition><artpagenums>201-213</artpagenums><bibliomisc role="type">incollection</bibliomisc>
+<publisher>
+<publishername>The name of the publisher</publishername>
 <address>The address of the publisher</address></publisher>
 <pubdate>1993</pubdate>
-
-<biblioset relation="book"><title>The title of the book</title>
+<biblioset relation="book">
+<title>The title of the book</title>
 </biblioset>
-
-
-<authorgroup><author><personname><firstname>Peter</firstname>
+<authorgroup><author>
+<personname>
+<firstname>Peter</firstname>
 <surname>Farindon</surname>
 </personname>
 </author>
 </authorgroup>
 <bibliomisc role="note">An optional note</bibliomisc>
 </biblioentry>
-
-<biblioentry xml:id="small"><title>A small paper</title><volumenum>-1</volumenum><bibliomisc role="type">article</bibliomisc>
+<biblioentry xml:id="small">
+<title>A small paper</title><volumenum>-1</volumenum><bibliomisc role="type">article</bibliomisc>
 <pubdate>1997</pubdate>
-
-<biblioset relation="journal"><title>The journal of small papers</title>
+<biblioset relation="journal">
+<title>The journal of small papers</title>
 </biblioset>
-
-
-<authorgroup><author><personname><surname>Freely</surname>
+<authorgroup><author>
+<personname>
+<surname>Freely</surname>
 <othername role="suffix">I. P.</othername>
 </personname>
 </author>
-
-
-<author><personname><firstname>Ditto</firstname>
+<author>
+<personname>
+<firstname>Ditto</firstname>
 <surname>Johannes</surname>
 </personname>
 </author>
 </authorgroup>
 <bibliomisc role="note">to appear</bibliomisc>
 </biblioentry>
-
-<biblioentry xml:id="Gro60."><title>Éléments de géométrie algébrique</title><bibliomisc role="type">book</bibliomisc>
+<biblioentry xml:id="Gro60">
+<title>Éléments de géométrie algébrique</title><bibliomisc role="type">book</bibliomisc>
 <pubdate>1960</pubdate>
-
-
-<authorgroup><author><personname><firstname>Alexander</firstname>
+<authorgroup><author>
+<personname>
+<firstname>Alexander</firstname>
 <surname>Grothendieck</surname>
 </personname>
 </author>
 </authorgroup>
 </biblioentry>
-
-<biblioentry xml:id="big"><title>A big paper</title><volumenum>MCMXCVII</volumenum><bibliomisc role="type">article</bibliomisc>
+<biblioentry xml:id="big">
+<title>A big paper</title><volumenum>MCMXCVII</volumenum><bibliomisc role="type">article</bibliomisc>
 <pubdate>7991</pubdate>
-
-<biblioset relation="journal"><title>The journal of big papers</title>
+<biblioset relation="journal">
+<title>The journal of big papers</title>
 </biblioset>
-
-
-<authorgroup><author><personname><firstname>Hugh</firstname>
+<authorgroup><author>
+<personname>
+<firstname>Hugh</firstname>
 <surname>Jass</surname>
 </personname>
 </author>
diff --git a/autotests/export/docbook/easy.lyx b/autotests/export/docbook/easy.lyx
new file mode 100644
index 0000000..0ea08e7
--- /dev/null
+++ b/autotests/export/docbook/easy.lyx
@@ -0,0 +1,253 @@
+#LyX 2.4 created this file. For more info see https://www.lyx.org/
+\lyxformat 598
+\begin_document
+\begin_header
+\save_transient_properties true
+\origin unavailable
+\textclass article
+\begin_preamble
+\newcommand{\testmacro}{\ensuremath{\operatorname{testmacro}}}
+\end_preamble
+\use_default_options true
+\maintain_unincluded_children no
+\language english
+\language_package default
+\inputencoding auto-legacy
+\fontencoding auto
+\font_roman "default" "default"
+\font_sans "default" "default"
+\font_typewriter "default" "default"
+\font_math "auto" "auto"
+\font_default_family default
+\use_non_tex_fonts false
+\font_sc false
+\font_roman_osf false
+\font_sans_osf false
+\font_typewriter_osf false
+\font_sf_scale 100 100
+\font_tt_scale 100 100
+\use_microtype false
+\use_dash_ligatures true
+\graphics default
+\default_output_format default
+\output_sync 0
+\bibtex_command default
+\index_command default
+\paperfontsize default
+\spacing single
+\use_hyperref false
+\papersize default
+\use_geometry false
+\use_package amsmath 1
+\use_package amssymb 1
+\use_package cancel 1
+\use_package esint 1
+\use_package mathdots 1
+\use_package mathtools 1
+\use_package mhchem 1
+\use_package stackrel 1
+\use_package stmaryrd 1
+\use_package undertilde 1
+\cite_engine basic
+\cite_engine_type default
+\biblio_style plain
+\use_bibtopic false
+\use_indices true
+\paperorientation portrait
+\suppress_date false
+\justification true
+\use_refstyle 1
+\use_minted 0
+\use_lineno 0
+\index Index
+\shortcut idx
+\color #008000
+\end_index
+\index Other index
+\shortcut oth
+\color #cc0000
+\end_index
+\secnumdepth 3
+\tocdepth 3
+\paragraph_separation indent
+\paragraph_indentation default
+\is_math_indent 0
+\math_numbering_side default
+\quotes_style english
+\dynamic_quotes 0
+\papercolumns 1
+\papersides 1
+\paperpagestyle default
+\tablestyle default
+\tracking_changes false
+\output_changes false
+\change_bars false
+\postpone_fragile_content false
+\html_math_output 0
+\html_css_as_file 0
+\html_be_strict false
+\docbook_table_output 0
+\end_header
+
+\begin_body
+
+\begin_layout Title
+I am a title
+\end_layout
+
+\begin_layout Author
+I am an author
+\end_layout
+
+\begin_layout Date
+I am a date
+\end_layout
+
+\begin_layout Abstract
+I am an abstract
+\end_layout
+
+\begin_layout Abstract
+I am also an abstract
+\end_layout
+
+\begin_layout Section
+I am the first section 
+\begin_inset CommandInset label
+LatexCommand label
+name "sec:Sec-1"
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+I am the first paragraph of the first section.
+ 
+\end_layout
+
+\begin_layout Standard
+I am the second paragraph of the first section.
+ 
+\end_layout
+
+\begin_layout Quote
+I am a quote
+\begin_inset Formula $\,with\,a\,formula$
+\end_inset
+
+.
+ 
+\end_layout
+
+\begin_layout Standard
+\begin_inset Formula 
+\[
+Formula!
+\]
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Subsection
+I am the first subsection
+\end_layout
+
+\begin_layout Standard
+I am the only paragraph of the first subsection.
+ 
+\end_layout
+
+\begin_layout Subsection
+I am the second subsection
+\end_layout
+
+\begin_layout Standard
+I am the only paragraph of the second subsection.
+ 
+\end_layout
+
+\begin_layout Section
+I am the second section 
+\end_layout
+
+\begin_layout Standard
+I am the only paragraph of the second section.
+ 
+\begin_inset CommandInset href
+LatexCommand href
+name "Hyperlink."
+target "http://example.org"
+literal "false"
+
+\end_inset
+
+ 
+\begin_inset Quotes eld
+\end_inset
+
+Text between quotes.
+\begin_inset Quotes erd
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+See 
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "sec:Sec-1"
+plural "false"
+caps "false"
+noprefix "false"
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Section
+I am the third section and I deal with star sections
+\end_layout
+
+\begin_layout Part*
+Star part
+\end_layout
+
+\begin_layout Section*
+Star section (sect1)
+\end_layout
+
+\begin_layout Subsection*
+Star subsection (sect2)
+\end_layout
+
+\begin_layout Subsubsection*
+Star subsubsection (sect3)
+\end_layout
+
+\begin_layout Paragraph*
+Star paragraph (sect4)
+\end_layout
+
+\begin_layout Subparagraph*
+Star subparagraph (sect5)
+\end_layout
+
+\begin_layout Standard
+\begin_inset CommandInset bibtex
+LatexCommand bibtex
+bibfiles "basic"
+options "plain"
+
+\end_inset
+
+
+\end_layout
+
+\end_body
+\end_document
diff --git a/autotests/export/docbook/easy.xml b/autotests/export/docbook/easy.xml
new file mode 100644
index 0000000..883c982
--- /dev/null
+++ b/autotests/export/docbook/easy.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This DocBook file was created by LyX 2.4.0dev
+  See http://www.lyx.org/ for more information -->
+<article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
+<info>
+<title>I am a title</title>
+<author>
+<personname>I am an author</personname>
+</author>
+<date>I am a date</date>
+<abstract>
+<para>I am an abstract</para>
+<para>I am also an abstract</para>
+</abstract>
+</info>
+<section xml:id="sec.Sec-1-0">
+<title>I am the first section </title>
+<para>I am the first paragraph of the first section. </para>
+<para>I am the second paragraph of the first section. </para>
+<blockquote>
+<para>I am a quote<inlineequation>
+<alt role='tex'>\,with\,a\,formula</alt>
+ <m:math>
+ 
+ <m:mrow>
+  <m:mrow><m:mspace width="6px" /><m:mi>w</m:mi><m:mi>i</m:mi><m:mi>t</m:mi><m:mi>h</m:mi><m:mspace width="6px" /><m:mi>a</m:mi><m:mspace width="6px" /><m:mi>f</m:mi><m:mi>o</m:mi><m:mi>r</m:mi><m:mi>m</m:mi><m:mi>u</m:mi><m:mi>l</m:mi><m:mi>a</m:mi>
+  </m:mrow>
+ </m:mrow>
+ </m:math>
+</inlineequation>. </para>
+</blockquote>
+<informalequation>
+<alt role='tex'>Formula!</alt>
+ <m:math>
+ 
+ <m:mrow>
+  <m:mrow><m:mi>F</m:mi><m:mi>o</m:mi><m:mi>r</m:mi><m:mi>m</m:mi><m:mi>u</m:mi><m:mi>l</m:mi><m:mi>a</m:mi><m:mo>!</m:mo>
+  </m:mrow>
+ </m:mrow>
+ </m:math>
+</informalequation><section>
+<title>I am the first subsection</title>
+<para>I am the only paragraph of the first subsection. </para>
+</section>
+<section>
+<title>I am the second subsection</title>
+<para>I am the only paragraph of the second subsection. </para>
+</section>
+</section>
+<section>
+<title>I am the second section </title>
+<para>I am the only paragraph of the second section. <link xlink:href="http://example.org">Hyperlink.</link> “Text between quotes.”</para>
+<para>See <xref linkend="sec.Sec-1-0" />.</para>
+</section>
+<section>
+<title>I am the third section and I deal with star sections</title>
+<bridgehead renderas='other' otherrenderas='part'>Star part</bridgehead>
+<bridgehead renderas="sect1">Star section (sect1)</bridgehead>
+<bridgehead renderas="sect2">Star subsection (sect2)</bridgehead>
+<bridgehead renderas="sect3">Star subsubsection (sect3)</bridgehead>
+<bridgehead renderas="sect4">Star paragraph (sect4)</bridgehead>
+<bridgehead renderas="sect5">Star subparagraph (sect5)</bridgehead>
+</section>
+<bibliography>
+<title>References</title>
+<!-- No entry in the bibliography. -->
+</bibliography>
+</article>
\ No newline at end of file
diff --git a/autotests/export/docbook/lists.lyx b/autotests/export/docbook/lists.lyx
index 4e46d70..f903372 100644
--- a/autotests/export/docbook/lists.lyx
+++ b/autotests/export/docbook/lists.lyx
@@ -87,7 +87,23 @@ Test document
 \end_layout
 
 \begin_layout Standard
-A list:
+A simple list: 
+\end_layout
+
+\begin_layout Itemize
+First item
+\end_layout
+
+\begin_layout Itemize
+Second item on two lines
+\begin_inset Newline newline
+\end_inset
+
+I'm the second line
+\end_layout
+
+\begin_layout Standard
+A complex list:
 \end_layout
 
 \begin_layout Itemize
diff --git a/autotests/export/docbook/lists.xml b/autotests/export/docbook/lists.xml
index a00ab4f..4621e30 100644
--- a/autotests/export/docbook/lists.xml
+++ b/autotests/export/docbook/lists.xml
@@ -2,33 +2,61 @@
 <!-- This DocBook file was created by LyX 2.4.0dev
   See http://www.lyx.org/ for more information -->
 <article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
-<title>Test document</title>
-<para>A list:</para>
+<title>
+Test document
+</title>
+<para>
+A simple list: 
+</para>
 <itemizedlist>
 <listitem>
 <para>First item</para>
+</listitem>
+<listitem>
+<para>Second item on two lines<!-- Is para open? yes --><!-- Output Error: Closing tag `para' when other tags are open, namely: -->
+<!-- Output Error: &LyX_parsep_tag& -->
+</para>
+<para>I'm the second line<!-- Output Error: Tags still open in closeFontTags(). Probably not a problem,
+but you might want to check these tags: -->
+<!-- Output Error: para -->
+<!-- Output Error: listitem -->
+<!-- Output Error: itemizedlist -->
+<!-- Output Error: No division separation tag found in endDivision(). -->
+</para>
+</listitem>
+</itemizedlist>
+<para>
+A complex list:
+</para>
 <itemizedlist>
 <listitem>
+<para>First item</para>
+</listitem>
+<listitem>
 <para>First first item</para>
 </listitem>
 <listitem>
 <para>First second item</para>
 </listitem>
 </itemizedlist>
-<para>Text after first item</para>
-</listitem>
+<para>
+Text after first item
+</para>
+<itemizedlist>
 <listitem>
 <para>Second item</para>
-<orderedlist>
-<listitem>
+</listitem>
+</itemizedlist>
+<orderedlist><listitem>
 <para>Second first item</para>
 </listitem>
-<listitem>
+</orderedlist>
+<orderedlist><listitem>
 <para>Second second item</para>
 </listitem>
 </orderedlist>
-<para>Text after second item</para>
-</listitem>
-</itemizedlist>
+<para>
+Text after second item
+</para>
 
 </article>
\ No newline at end of file
diff --git a/lib/layouts/stdlayouts.inc b/lib/layouts/stdlayouts.inc
index 3b10ff4..1670695 100644
--- a/lib/layouts/stdlayouts.inc
+++ b/lib/layouts/stdlayouts.inc
@@ -28,8 +28,9 @@ Style Quotation
 	AlignPossible         Block, Left, Right, Center
 	HTMLTag               blockquote
 	HTMLItem              div
-	DocBookTag            blockquote
-	DocBookItemTag        para
+	DocBookWrapperTag     blockquote
+	DocBookWrapperMergeWithPrevious    true
+	DocBookTag            para
 End
 
 
@@ -50,8 +51,9 @@ Style Quote
 	LabelType             No_Label
 	HTMLTag               blockquote
 	HTMLItem              div
-	DocBookTag            blockquote
-	DocBookItemTag        para
+	DocBookWrapperTag     blockquote
+	DocBookWrapperMergeWithPrevious    true
+	DocBookTag            para
 End
 
 
diff --git a/lib/layouts/stdlists.inc b/lib/layouts/stdlists.inc
index 0eef65c..16a9e81 100644
--- a/lib/layouts/stdlists.inc
+++ b/lib/layouts/stdlists.inc
@@ -43,7 +43,9 @@ Style Itemize
 			Color latex
 		EndFont
 	EndArgument
-	DocBookTag            itemizedlist
+	DocBookWrapperTag     itemizedlist
+	DocBookWrapperMergeWithPrevious    true
+	DocBookTag            NONE
 	DocBookItemTag        listitem
 	DocBookItemInnerTag   para
 End
diff --git a/lib/layouts/stdstarsections.inc b/lib/layouts/stdstarsections.inc
index 7d6865f..60354b1 100644
--- a/lib/layouts/stdstarsections.inc
+++ b/lib/layouts/stdstarsections.inc
@@ -19,7 +19,7 @@ Style Part*
 	LabelCounter	""
 	ResetArgs       1
 	DocBookTag            bridgehead
-	DocBookAttr           renderas="part"
+	DocBookAttr           "renderas='other' otherrenderas='part'"
 	DocBookSectionTag     NONE
 	DocBookForceAbstractTag	NONE
 End
@@ -34,7 +34,7 @@ Style Chapter*
 	LabelCounter	""
 	ResetArgs       1
 	DocBookTag            bridgehead
-	DocBookAttr           renderas="chapter"
+	DocBookAttr           "renderas='other' otherrenderas='chapter'"
 	DocBookSectionTag     NONE
 	DocBookForceAbstractTag	NONE
 End
diff --git a/lib/layouts/stdstruct.inc b/lib/layouts/stdstruct.inc
index b02499f..c8b7eb4 100644
--- a/lib/layouts/stdstruct.inc
+++ b/lib/layouts/stdstruct.inc
@@ -51,8 +51,9 @@ Style Abstract
 	EndHTMLStyle
 	DocBookAbstract       true
 	DocBookInInfo         always
-	DocBookTag            abstract
-	DocBookItemTag        para
+	DocBookWrapperTag     abstract
+	DocBookWrapperMergeWithPrevious    true
+	DocBookTag            para
 End
 
 
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 2465cc4..24947f8 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3383,12 +3383,9 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
 			if (!runparams.for_toc || inset->isInToc()) {
 				OutputParams np = runparams;
 				np.local_font = &font;
-				// If the paragraph has size 1, then we are in the "special
-				// case" where we do not output the containing paragraph info.
-				// This "special case" is defined in more details in output_docbook.cpp, makeParagraphs. The results
-				// of that brittle logic is passed to this function through open_par.
-				if (!inset->getLayout().htmlisblock() && size() != 1) // TODO: htmlisblock here too!
-					np.docbook_in_par = true;
+
+				// TODO: special case will bite here.
+				np.docbook_in_par = true;
 				inset->docbook(xs, np);
 			}
 		} else {
diff --git a/src/ParagraphList.h b/src/ParagraphList.h
index a57deb4..7e5cc1a 100644
--- a/src/ParagraphList.h
+++ b/src/ParagraphList.h
@@ -29,6 +29,17 @@ public:
 	ParagraphList(InputIterator first, InputIterator last)
 		: RandomAccessList<Paragraph>(first, last)
 	{}
+
+	const Paragraph * getParagraphBefore(const_iterator const & par) const
+	{
+		// No previous paragraph.
+		if (par == begin())
+			return nullptr;
+
+		auto prevpar = par;
+		--prevpar;
+		return &*prevpar;
+	}
 };
 
 } // namespace lyx
diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index 34b22c1..c03a8e2 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -1157,10 +1157,11 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
 
 	if (vit == ven) {
 		xs << XMLStream::ESCAPE_NONE << "<!-- No entry in the bibliography. -->";
+		xs << xml::CR();
 	}
 
 	for (; vit != ven; ++vit) {
-		BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
+		auto const biit = bibinfo.find(*vit);
 		if (biit == bibinfo.end())
 			continue;
 
diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp
index a023f7a..8e69e88 100644
--- a/src/insets/InsetERT.cpp
+++ b/src/insets/InsetERT.cpp
@@ -101,7 +101,7 @@ void InsetERT::docbook(XMLStream & xs, OutputParams const & runparams) const
 	odocstringstream os2;
 	XMLStream xs2(os2);
 
-	// Recreate the logic of makeParagraphs in output_docbook.cpp, but much simplified: never open <para>
+	// Recreate the logic of makeParagraph in output_docbook.cpp, but much simplified: never open <para>
 	// in an ERT, use simple line breaks.
 	while (par != end) {
 		par->simpleDocBookOnePar(buffer(), xs2, runparams, text().outerFont(distance(begin, par)));
@@ -116,6 +116,7 @@ void InsetERT::docbook(XMLStream & xs, OutputParams const & runparams) const
 	xs << XMLStream::ESCAPE_NONE << "<!-- ";
 	xs << XMLStream::ESCAPE_COMMENTS << os2.str();
 	xs << XMLStream::ESCAPE_NONE << " -->";
+	xs << xml::CR();
 }
 
 
diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp
index 45d52b2..00b276e 100644
--- a/src/insets/InsetNewline.cpp
+++ b/src/insets/InsetNewline.cpp
@@ -176,17 +176,18 @@ void InsetNewline::docbook(XMLStream & xs, OutputParams const & runparams) const
 {
 	if (runparams.docbook_in_par) {
 		xs.closeFontTags();
-		if (!xs.pending_tags_empty()) {
-			xs << xml::EndTag("para");
-			xs << xml::StartTag("para");
-		}
-		else {
-			xs << xml::CR() << xml::CompTag("br") << xml::CR();
-		}
-	}
-	else {
-		xs << xml::CR() << xml::CompTag("br") << xml::CR();
+
+		// TODO: what if within a list item, and docbookiteminnertag is not para? This would require information
+		// about the paragraph's layout... Good for now, though, this should not happen in DocBook, only maybe
+		// extensions.
+		xs << XMLStream::ESCAPE_NONE << from_utf8("<!-- Is para open? " + string((xs.isTagOpen(xml::StartTag("para"))) ? "yes" : "no") +" -->");
+		xs << XMLStream::ESCAPE_NONE << from_utf8("</para>\n<para");
+		// TODO: that's a hack...
+//		xs << xml::EndTag("para");
+//		xs << xml::CR();
+//		xs << xml::StartTag("para");
 	}
+	// Outside a paragraph, no need to handle new lines.
 }
 
 
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index cb6cec5..800cbeb 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -2471,7 +2471,8 @@ void InsetMathHull::docbook(XMLStream & xs, OutputParams const & runparams) cons
 		osmath << ostmp.str(); // osmath is not a XMLStream, so no need for XMLStream::ESCAPE_NONE.
 		ms << ETag("math");
 	} catch (MathExportException const &) {
-		osmath << "MathML export failed. Please report this as a bug.";
+		ms.cr();
+		osmath << "<mathphrase>MathML export failed. Please report this as a bug.</mathphrase>";
 	}
 
 	// Output the complete formula to the DocBook stream.
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 4430041..b29da56 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -43,6 +43,8 @@
 #include <algorithm>
 #include <sstream>
 
+// #define DOCBOOK_DEBUG_NEWLINES
+
 using namespace std;
 using namespace lyx::support;
 
@@ -191,6 +193,10 @@ namespace {
 
 void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar)
 {
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- openParTag -->";
+#endif
+
 	Layout const & lay = par->layout();
 
 	if (par == prevpar)
@@ -212,29 +218,43 @@ void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar
 	}
 
 	// Main logic.
-	if (openWrapper)
+	if (openWrapper) {
 		xs << xml::StartTag(lay.docbookwrappertag(), lay.docbookwrapperattr());
+		xs << xml::CR();
+	}
 
 	string tag = lay.docbooktag();
-	if (tag == "Plain Layout")
-		tag = "para";
-
-	if (!xs.isTagOpen(xml::ParTag(tag, lay.docbookattr()), 1)) // Don't nest a paragraph directly in a paragraph.
-		xs << xml::ParTag(tag, lay.docbookattr());
+	if (tag != "NONE") {
+		auto xmltag = xml::ParTag(tag, lay.docbookattr());
+		if (!xs.isTagOpen(xmltag, 1)) // Don't nest a paragraph directly in a paragraph. TODO: required or not?
+			xs << xmltag;
+	}
 
-	if (lay.docbookitemtag() != "NONE")
+	if (lay.docbookitemtag() != "NONE") {
 		xs << xml::StartTag(lay.docbookitemtag(), lay.docbookitemattr());
+		xs << xml::CR();
+	}
+
+	if (lay.docbookiteminnertag() != "NONE")
+		xs << xml::StartTag(lay.docbookiteminnertag(), lay.docbookiteminnerattr());
+
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- /openParTag -->";
+#endif
 }
 
 
-void closeTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpar)
+void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpar)
 {
-	Layout const & lay = par->layout();
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- closeParTag -->";
+#endif
 
 	if (par == nextpar)
 		nextpar = nullptr;
 
 	// See comment in openParTag.
+	Layout const & lay = par->layout();
 	bool closeWrapper = lay.docbookwrappertag() != "NONE";
 	if (nextpar != nullptr) {
 		Layout const & nextlay = nextpar->layout();
@@ -245,132 +265,133 @@ void closeTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpar)
 	}
 
 	// Main logic.
-	if (lay.docbookitemtag() != "NONE")
+	if (lay.docbookiteminnertag() != "NONE") {
+		xs << xml::EndTag(lay.docbookiteminnertag());
+		xs << xml::CR();
+	}
+
+	if (lay.docbookitemtag() != "NONE") {
 		xs << xml::EndTag(lay.docbookitemtag());
+		xs << xml::CR();
+	}
 
-	string tag = lay.docbooktag();
-	if (tag == "Plain Layout")
-		tag = "para";
+	if (lay.docbooktag() != "NONE") {
+		xs << xml::EndTag(lay.docbooktag());
+		xs << xml::CR();
+	}
 
-	xs << xml::EndTag(tag);
-	if (closeWrapper)
+	if (closeWrapper) {
 		xs << xml::EndTag(lay.docbookwrappertag());
-}
-
+		xs << xml::CR();
+	}
 
-void openLabelTag(XMLStream & xs, Layout const & lay) // Mostly for definition lists.
-{
-	xs << xml::StartTag(lay.docbookitemlabeltag(), lay.docbookitemlabelattr());
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- /closeParTag -->";
+#endif
 }
 
 
-void closeLabelTag(XMLStream & xs, Layout const & lay)
+void openBlockTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar)
 {
-	xs << xml::EndTag(lay.docbookitemlabeltag());
-	xs << xml::CR();
-}
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- openBlockTag -->";
+#endif
 
+	// Similar as openParTag, but with a line feed after.
+	openParTag(xs, par, prevpar);
+	xs << xml::CR();
 
-void openItemTag(XMLStream & xs, Layout const & lay)
-{
-	xs << xml::StartTag(lay.docbookitemtag(), lay.docbookitemattr());
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- /openBlockTag -->";
+#endif
 }
 
 
-// Return true when new elements are output in a paragraph, false otherwise.
-bool openInnerItemTag(XMLStream & xs, Layout const & lay)
+void closeBlockTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar)
 {
-	if (lay.docbookiteminnertag() != "NONE") {
-		xs << xml::CR();
-		xs << xml::ParTag(lay.docbookiteminnertag(), lay.docbookiteminnerattr());
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- closeBlockTag -->";
+#endif
 
-		if (lay.docbookiteminnertag() == "para") {
-			return true;
-		}
-	}
-	return false;
+	// Similar as closeParTag, but with a line feed before.
+	xs << xml::CR();
+	closeParTag(xs, par, prevpar);
+
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- /closeBlockTag -->";
+#endif
 }
 
 
-void closeInnerItemTag(XMLStream & xs, Layout const & lay)
+void openLabelTag(XMLStream & xs, Layout const & lay) // Mostly for definition lists.
 {
-	if (lay.docbookiteminnertag()!= "NONE") {
-		xs << xml::EndTag(lay.docbookiteminnertag());
-		xs << xml::CR();
-	}
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- openLabelTag -->";
+#endif
+
+	xs << xml::StartTag(lay.docbookitemlabeltag(), lay.docbookitemlabelattr());
+
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- /openLabelTag -->";
+#endif
 }
 
 
-inline void closeItemTag(XMLStream & xs, Layout const & lay)
+void closeLabelTag(XMLStream & xs, Layout const & lay)
 {
-	xs << xml::EndTag(lay.docbookitemtag());
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- closeLabelTag -->";
+#endif
+
+	xs << xml::EndTag(lay.docbookitemlabeltag());
 	xs << xml::CR();
-}
 
-// end of convenience functions
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- closeLabelTag -->";
+#endif
+}
 
-ParagraphList::const_iterator findLast(
-		ParagraphList::const_iterator p,
-		ParagraphList::const_iterator const & pend,
-		LatexType type) {
-	for (++p; p != pend && p->layout().latextype == type; ++p);
 
-	return p;
-}
+void openItemTag(XMLStream & xs, Layout const & lay)
+{
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- openItemTag -->";
+#endif
 
-ParagraphList::const_iterator findLastBibliographyParagraph(
-		ParagraphList::const_iterator p,
-		ParagraphList::const_iterator const & pend) {
-	for (++p; p != pend && p->layout().latextype == LATEX_BIB_ENVIRONMENT; ++p);
+	xs << xml::StartTag(lay.docbookitemtag(), lay.docbookitemattr());
 
-	return p;
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- /openItemTag -->";
+#endif
 }
 
 
-ParagraphList::const_iterator findEndOfEnvironment(
-		ParagraphList::const_iterator const & pstart,
-		ParagraphList::const_iterator const & pend)
+void closeItemTag(XMLStream & xs, Layout const & lay)
 {
-	ParagraphList::const_iterator p = pstart;
-	size_t const depth = p->params().depth();
-
-	for (++p; p != pend; ++p) {
-		Layout const &style = p->layout();
-		// It shouldn't happen that e.g. a section command occurs inside
-		// a quotation environment, at a higher depth, but as of 6/2009,
-		// it can happen. We pretend that it's just at lowest depth.
-		if (style.latextype == LATEX_COMMAND)
-			return p;
-
-		// If depth is down, we're done
-		if (p->params().depth() < depth)
-			return p;
-
-		// If depth is up, we're not done
-		if (p->params().depth() > depth)
-			continue;
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- closeItemTag -->";
+#endif
 
-		// FIXME I am not sure about the first check.
-		// Surely we *could* have different layouts that count as
-		// LATEX_PARAGRAPH, right?
-		if (style.latextype == LATEX_PARAGRAPH || style != p->layout())
-			return p;
-	}
+	xs << xml::EndTag(lay.docbookitemtag());
+	xs << xml::CR();
 
-	return pend;
+#ifdef DOCBOOK_DEBUG_NEWLINES
+	xs << XMLStream::ESCAPE_NONE << "<!-- /closeItemTag -->";
+#endif
 }
 
 
-ParagraphList::const_iterator makeParagraphBibliography(
-		Buffer const &buf,
-		XMLStream &xs,
-		OutputParams const &runparams,
-		Text const &text,
-		ParagraphList::const_iterator const & pbegin,
-		ParagraphList::const_iterator const & pend)
+void makeParagraphBibliography(
+		Buffer const & buf,
+		XMLStream & xs,
+		OutputParams const & runparams,
+		Text const & text,
+		ParagraphList::const_iterator const & pbegin)
 {
 	auto const begin = text.paragraphs().begin();
 	auto const end = text.paragraphs().end();
+	auto pend = pbegin;
+	++pend;
 
 	// Find the paragraph *before* pbegin.
 	ParagraphList::const_iterator pbegin_before = begin;
@@ -420,322 +441,203 @@ ParagraphList::const_iterator makeParagraphBibliography(
 		xs << xml::EndTag("bibliography");
 		xs << xml::CR();
 	}
-
-	return pend;
 }
 
 
-ParagraphList::const_iterator makeParagraphs(
-		Buffer const &buf,
-		XMLStream &xs,
-		OutputParams const &runparams,
-		Text const &text,
-		ParagraphList::const_iterator const & pbegin,
-		ParagraphList::const_iterator const & pend)
+void makeParagraph(
+		Buffer const & buf,
+		XMLStream & xs,
+		OutputParams const & runparams,
+		Text const & text,
+		ParagraphList::const_iterator const & par)
 {
 	auto const begin = text.paragraphs().begin();
 	auto const end = text.paragraphs().end();
-	ParagraphList::const_iterator par = pbegin;
-	ParagraphList::const_iterator prevpar = pbegin;
-
-	for (; par != pend; prevpar = par, ++par) {
-		// We want to open the paragraph tag if:
-		//   (i) the current layout permits multiple paragraphs
-		//  (ii) we are either not already inside a paragraph (HTMLIsBlock) OR
-		//	   we are, but this is not the first paragraph
-		//
-		// But there is also a special case, and we first see whether we are in it.
-		// We do not want to open the paragraph tag if this paragraph contains
-		// only one item, and that item is "inline", i.e., not HTMLIsBlock (such
-		// as a branch). On the other hand, if that single item has a font change
-		// applied to it, then we still do need to open the paragraph.
-		//
-		// Obviously, this is very fragile. The main reason we need to do this is
-		// because of branches, e.g., a branch that contains an entire new section.
-		// We do not really want to wrap that whole thing in a <div>...</div>.
-		bool special_case = false;
-		Inset const *specinset = par->size() == 1 ? par->getInset(0) : nullptr;
-		if (specinset && !specinset->getLayout().htmlisblock()) { // TODO: Convert htmlisblock to a DocBook parameter?
-			Layout const &style = par->layout();
-			FontInfo const first_font = style.labeltype == LABEL_MANUAL ?
-										style.labelfont : style.font;
-			FontInfo const our_font =
-					par->getFont(buf.masterBuffer()->params(), 0,
-								 text.outerFont(distance(begin, par))).fontInfo();
-
-			if (first_font == our_font)
-				special_case = true;
-		}
+	auto prevpar = text.paragraphs().getParagraphBefore(par);
+
+	// We want to open the paragraph tag if:
+	//   (i) the current layout permits multiple paragraphs
+	//  (ii) we are either not already inside a paragraph (HTMLIsBlock) OR
+	//	   we are, but this is not the first paragraph
+	//
+	// But there is also a special case, and we first see whether we are in it.
+	// We do not want to open the paragraph tag if this paragraph contains
+	// only one item, and that item is "inline", i.e., not HTMLIsBlock (such
+	// as a branch). On the other hand, if that single item has a font change
+	// applied to it, then we still do need to open the paragraph.
+	//
+	// Obviously, this is very fragile. The main reason we need to do this is
+	// because of branches, e.g., a branch that contains an entire new section.
+	// We do not really want to wrap that whole thing in a <div>...</div>.
+	bool special_case = false;
+	Inset const *specinset = par->size() == 1 ? par->getInset(0) : nullptr;
+	if (specinset && !specinset->getLayout().htmlisblock()) { // TODO: Convert htmlisblock to a DocBook parameter?
+		Layout const &style = par->layout();
+		FontInfo const first_font = style.labeltype == LABEL_MANUAL ?
+									style.labelfont : style.font;
+		FontInfo const our_font =
+				par->getFont(buf.masterBuffer()->params(), 0,
+							 text.outerFont(std::distance(begin, par))).fontInfo();
 
-		// Plain layouts must be ignored.
-		if (!special_case && buf.params().documentClass().isPlainLayout(par->layout()) && !runparams.docbook_force_pars)
+		if (first_font == our_font)
 			special_case = true;
-		// TODO: Could get rid of this with a DocBook equivalent to htmlisblock?
-		if (!special_case && par->size() == 1 && par->getInset(0)) {
-			Inset const * firstInset = par->getInset(0);
+	}
+
+	// Plain layouts must be ignored.
+	if (!special_case && buf.params().documentClass().isPlainLayout(par->layout()) && !runparams.docbook_force_pars)
+		special_case = true;
+	// TODO: Could get rid of this with a DocBook equivalent to htmlisblock?
+	if (!special_case && par->size() == 1 && par->getInset(0)) {
+		Inset const * firstInset = par->getInset(0);
 
-			// Floats cannot be in paragraphs.
-			special_case = to_utf8(firstInset->layoutName()).substr(0, 6) == "Float:";
+		// Floats cannot be in paragraphs.
+		special_case = to_utf8(firstInset->layoutName()).substr(0, 6) == "Float:";
 
-			// Bibliographies cannot be in paragraphs.
-			if (!special_case && firstInset->asInsetCommand())
-				special_case = firstInset->asInsetCommand()->params().getCmdName() == "bibtex";
+		// Bibliographies cannot be in paragraphs.
+		if (!special_case && firstInset->asInsetCommand())
+			special_case = firstInset->asInsetCommand()->params().getCmdName() == "bibtex";
 
-			// Equations do not deserve their own paragraph (DocBook allows them outside paragraphs).
-			if (!special_case && firstInset->asInsetMath())
-				special_case = true;
+		// Equations do not deserve their own paragraph (DocBook allows them outside paragraphs).
+		if (!special_case && firstInset->asInsetMath())
+			special_case = true;
 
-			// ERTs are in comments, not paragraphs.
-			if (!special_case && firstInset->lyxCode() == lyx::ERT_CODE)
-				special_case = true;
+		// ERTs are in comments, not paragraphs.
+		if (!special_case && firstInset->lyxCode() == lyx::ERT_CODE)
+			special_case = true;
 
-			// Listings should not get into their own paragraph.
-			if (!special_case && firstInset->lyxCode() == lyx::LISTINGS_CODE)
-				special_case = true;
-		}
+		// Listings should not get into their own paragraph.
+		if (!special_case && firstInset->lyxCode() == lyx::LISTINGS_CODE)
+			special_case = true;
+	}
 
-		bool const open_par = runparams.docbook_make_pars
-							  && (!runparams.docbook_in_par || par != pbegin)
-							  && !special_case;
-
-		// We want to issue the closing tag if either:
-		//   (i)  We opened it, and either docbook_in_par is false,
-		//		or we're not in the last paragraph, anyway.
-		//   (ii) We didn't open it and docbook_in_par is true,
-		//		but we are in the first par, and there is a next par.
-		auto nextpar = par;
-		++nextpar;
-		bool const close_par =
-				((open_par && (!runparams.docbook_in_par || nextpar != pend))
-				|| (!open_par && runparams.docbook_in_par && par == pbegin && nextpar != pend));
-
-		// Determine if this paragraph has some real content. Things like new pages are not caught
-		// by Paragraph::empty(), even though they do not generate anything useful in DocBook.
-		odocstringstream os2;
-		XMLStream xs2(os2);
-		par->simpleDocBookOnePar(buf, xs2, runparams, text.outerFont(distance(begin, par)), open_par, close_par, 0);
+	bool const open_par = runparams.docbook_make_pars
+						  && !runparams.docbook_in_par
+						  && !special_case;
 
-		docstring cleaned = os2.str();
-		static const lyx::regex reg("[ \\r\\n]*");
-		cleaned = from_utf8(lyx::regex_replace(to_utf8(cleaned), reg, string("")));
+	// We want to issue the closing tag if either:
+	//   (i)  We opened it, and either docbook_in_par is false,
+	//		or we're not in the last paragraph, anyway.
+	//   (ii) We didn't open it and docbook_in_par is true,
+	//		but we are in the first par, and there is a next par.
+	auto nextpar = par;
+	++nextpar;
+	bool const close_par = open_par && (!runparams.docbook_in_par);
 
-		if (!cleaned.empty()) {
-			if (open_par)
-				openParTag(xs, &*par, &*prevpar);
+	// Determine if this paragraph has some real content. Things like new pages are not caught
+	// by Paragraph::empty(), even though they do not generate anything useful in DocBook.
+	odocstringstream os2;
+	XMLStream xs2(os2);
+	par->simpleDocBookOnePar(buf, xs2, runparams, text.outerFont(distance(begin, par)), open_par, close_par, 0);
 
-			xs << XMLStream::ESCAPE_NONE << os2.str();
+	docstring cleaned = os2.str();
+	static const lyx::regex reg("[ \\r\\n]*");
+	cleaned = from_utf8(lyx::regex_replace(to_utf8(cleaned), reg, string("")));
 
-			if (close_par) {
-				closeTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr);
-				xs << xml::CR();
-			}
-		}
+	if (!cleaned.empty()) {
+		if (open_par)
+			openParTag(xs, &*par, prevpar);
+
+		xs << XMLStream::ESCAPE_NONE << os2.str();
+
+		if (close_par)
+			closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr);
 	}
-	return pend;
 }
 
 
-bool isNormalEnv(Layout const &lay)
-{
-	return lay.latextype == LATEX_ENVIRONMENT
-		   || lay.latextype == LATEX_BIB_ENVIRONMENT;
-}
+void makeAny(
+		Text const &text,
+		Buffer const &buf,
+		XMLStream &xs,
+		OutputParams const &ourparams,
+		ParagraphList::const_iterator par);
 
 
-ParagraphList::const_iterator makeEnvironment(
+void makeEnvironment(
 		Buffer const &buf,
 		XMLStream &xs,
 		OutputParams const &runparams,
 		Text const &text,
-		ParagraphList::const_iterator const & pbegin,
-		ParagraphList::const_iterator const & pend)
+		ParagraphList::const_iterator const & par)
 {
-	auto const begin = text.paragraphs().begin();
 	auto const end = text.paragraphs().end();
-	ParagraphList::const_iterator par = pbegin;
-	depth_type const origdepth = pbegin->params().depth();
-
-	// Output the opening tag for this environment.
-	{
-		// Find the previous paragraph.
-		auto prevpar = begin;
-		if (prevpar != par) {
-			auto prevpar_next = prevpar;
-			++prevpar_next;
-
-			while (prevpar_next != par) {
-				++prevpar_next;
-				++prevpar;
-			}
-		}
 
-		// Open tag for this environment.
-		openParTag(xs, &*par, &*prevpar);
-		xs << xml::CR();
-	}
-
-	// we will on occasion need to remember a layout from before.
-	Layout const *lastlay = nullptr;
-	auto prevpar = par;
-
-	while (par != pend) {
-		Layout const & style = par->layout();
-		ParagraphList::const_iterator send;
-
-		auto parnext = par;
-		++parnext;
-
-		// Actual content of this paragraph.
-		prevpar = par;
-		switch (style.latextype) {
-		case LATEX_ENVIRONMENT:
-		case LATEX_LIST_ENVIRONMENT:
-		case LATEX_ITEM_ENVIRONMENT: {
-			// There are two possibilities in this case.
-			// One is that we are still in the environment in which we
-			// started---which we will be if the depth is the same.
-			if (par->params().depth() == origdepth) {
-				LATTEST(par->layout() == style);
-				if (lastlay != nullptr) {
-					closeItemTag(xs, *lastlay);
-					if (lastlay->docbookitemwrappertag() != "NONE") {
-						xs << xml::EndTag(lastlay->docbookitemwrappertag());
-						xs << xml::CR();
-					}
-					lastlay = nullptr;
-				}
-
-				// this will be positive if we want to skip the
-				// initial word (if it's been taken for the label).
-				pos_type sep = 0;
+	// Output the opening tag for this environment, but only if it has not been previously opened (condition
+	// implemented in openParTag).
+	auto prevpar = text.paragraphs().getParagraphBefore(par);
+	openParTag(xs, &*par, prevpar); // TODO: switch in layout for par/block?
+
+	// Generate the contents of this environment. There is a special case if this is like some environment.
+	Layout const & style = par->layout();
+	if (style.latextype == LATEX_COMMAND) {
+		// Nothing to do (otherwise, infinite loops).
+	} else if (style.latextype == LATEX_ENVIRONMENT ||
+			style.latextype == LATEX_LIST_ENVIRONMENT ||
+			style.latextype == LATEX_ITEM_ENVIRONMENT) {
+		// Open a wrapper tag if needed.
+		if (style.docbookitemwrappertag() != "NONE") {
+			xs << xml::StartTag(style.docbookitemwrappertag(), style.docbookitemwrapperattr());
+			xs << xml::CR();
+		}
 
-				// Open a wrapper tag if needed.
-				if (style.docbookitemwrappertag() != "NONE") {
-					xs << xml::StartTag(style.docbookitemwrappertag(), style.docbookitemwrapperattr());
+		// Generate the label, if need be. If it is taken from the text, sep != 0 and corresponds to the first
+		// character after the label.
+		pos_type sep = 0;
+		if (style.labeltype != LABEL_NO_LABEL && style.docbookitemlabeltag() != "NONE") {
+			// At least one condition must be met:
+			//  - this environment is not a list
+			//  - if this is a list, the label must not be manual (i.e. it must be taken from the layout)
+			if (style.latextype != LATEX_LIST_ENVIRONMENT || style.labeltype != LABEL_MANUAL) {
+				// Usual cases: maybe there is something specified at the layout level. Highly unlikely, though.
+				docstring const lbl = par->params().labelString();
+
+				if (lbl.empty()) {
 					xs << xml::CR();
-				}
-
-				// label output
-				if (style.labeltype != LABEL_NO_LABEL &&
-						style.docbookitemlabeltag() != "NONE") {
-
-					if (isNormalEnv(style)) {
-						// in this case, we print the label only for the first
-						// paragraph (as in a theorem or an abstract).
-						if (par == pbegin) {
-							docstring const lbl = pbegin->params().labelString();
-							if (!lbl.empty()) {
-								openLabelTag(xs, style);
-								xs << lbl;
-								closeLabelTag(xs, style);
-							} else {
-								// No new line after closeLabelTag.
-								xs << xml::CR();
-							}
-						}
-					} else { // some kind of list
-						if (style.labeltype == LABEL_MANUAL) {
-							// Only variablelist gets here.
-
-							openLabelTag(xs, style);
-							sep = par->firstWordDocBook(xs, runparams);
-							closeLabelTag(xs, style);
-						} else {
-							openLabelTag(xs, style);
-							xs << par->params().labelString();
-							closeLabelTag(xs, style);
-						}
-					}
-				} // end label output
-
-				// Start generating the item.
-				bool wasInParagraph = runparams.docbook_in_par;
-				openItemTag(xs, style);
-				bool getsIntoParagraph = openInnerItemTag(xs, style);
-				OutputParams rp = runparams;
-				rp.docbook_in_par = wasInParagraph | getsIntoParagraph;
-
-				// Maybe the item is completely empty, i.e. if the first word ends at the end of the current paragraph
-				// AND if the next paragraph doesn't have the same depth (if there is such a paragraph).
-				// Common case: there is only the first word on the line, but there is a nested list instead
-				// of more text.
-				bool emptyItem = false;
-				if (sep == par->size()) {
-					auto next_par = par;
-					++next_par;
-					if (next_par == text.paragraphs().end()) // There is no next paragraph.
-						emptyItem = true;
-					else // There is a next paragraph: check depth.
-						emptyItem = par->params().depth() >= next_par->params().depth();
-				}
-
-				if (emptyItem) {
-					// Avoid having an empty item, this is not valid DocBook. A single character is enough to force
-					// generation of a full <para>.
-					xs << ' ';
 				} else {
-					// Generate the rest of the paragraph, if need be.
-					par->simpleDocBookOnePar(buf, xs, rp, text.outerFont(distance(begin, par)), true, true, sep);
+					openLabelTag(xs, style);
+					xs << lbl;
+					closeLabelTag(xs, style);
 				}
-
-				++par;
-				if (getsIntoParagraph)
-					closeInnerItemTag(xs, style);
-
-				// We may not want to close the tag yet, in particular:
-				// If we're not at the end of the item...
-				if (par != pend
-					//  and are doing items...
-					&& !isNormalEnv(style)
-					// and if the depth has changed...
-					&& par->params().depth() != origdepth) {
-					// then we'll save this layout for later, and close it when
-					// we get another item.
-					lastlay = &style;
-				} else {
-					closeItemTag(xs, style);
-
-					// Eventually, close the item wrapper.
-					if (style.docbookitemwrappertag() != "NONE") {
-						xs << xml::EndTag(style.docbookitemwrappertag());
-						xs << xml::CR();
-					}
-				}
-			}
-			// The other possibility is that the depth has increased.
-			else {
-				send = findEndOfEnvironment(par, pend);
-				par = makeEnvironment(buf, xs, runparams, text, par, send);
+			} else {
+				// Only variablelist gets here (or similar items defined as an extension in the layout).
+				openLabelTag(xs, style);
+				sep = par->firstWordDocBook(xs, runparams);
+				closeLabelTag(xs, style);
 			}
-			break;
 		}
-		case LATEX_PARAGRAPH:
-//			send = findLast(par, pend, LATEX_PARAGRAPH);
-			par = makeParagraphs(buf, xs, runparams, text, par, parnext);
-			break;
-		case LATEX_BIB_ENVIRONMENT:
-//			send = findLast(par, pend, LATEX_BIB_ENVIRONMENT);
-			makeParagraphBibliography(buf, xs, runparams, text, par, parnext);
-			break;
-		case LATEX_COMMAND:
-			par = parnext;
-			break;
+
+		// Maybe the item is completely empty, i.e. if the first word ends at the end of the current paragraph
+		// AND if the next paragraph doesn't have the same depth (if there is such a paragraph).
+		// Common case: there is only the first word on the line, but there is a nested list instead
+		// of more text.
+		bool emptyItem = false;
+		if (sep == par->size()) { // If the separator is already at the end of this paragraph...
+			auto next_par = par;
+			++next_par;
+			if (next_par == text.paragraphs().end()) // There is no next paragraph.
+				emptyItem = true;
+			else // There is a next paragraph: check depth.
+				emptyItem = par->params().depth() >= next_par->params().depth();
 		}
-	}
 
-	if (lastlay != nullptr) {
-		closeItemTag(xs, *lastlay);
-		if (lastlay->docbookitemwrappertag() != "NONE") {
-			xs << xml::EndTag(lastlay->docbookitemwrappertag());
-			xs << xml::CR();
+		if (emptyItem) {
+			// Avoid having an empty item, this is not valid DocBook. A single character is enough to force
+			// generation of a full <para>.
+			// TODO: this always worked only by magic...
+			xs << ' ';
+		} else {
+			// Generate the rest of the paragraph, if need be.
+			par->simpleDocBookOnePar(buf, xs, runparams, text.outerFont(std::distance(text.paragraphs().begin(), par)),
+							         true, true, sep);
 		}
+	} else {
+		makeAny(text, buf, xs, runparams, par);
 	}
-//	auto nextpar = par;
-//	++nextpar;
-	closeTag(xs, &*prevpar, &*par);
-//	closeTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr);
-	xs << xml::CR();
-	return pend;
+
+	// Close the environment.
+	auto nextpar = par;
+	++nextpar;
+	closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr); // TODO: switch in layout for par/block?
 }
 
 
@@ -744,117 +646,48 @@ void makeCommand(
 		XMLStream & xs,
 		OutputParams const & runparams,
 		Text const & text,
-		ParagraphList::const_iterator const & pbegin)
+		ParagraphList::const_iterator const & par)
 {
-	// No need for labels, as they are handled by DocBook tags.
+	// Unlike XHTML, no need for labels, as they are handled by DocBook tags.
 	auto const begin = text.paragraphs().begin();
 	auto const end = text.paragraphs().end();
-	auto nextpar = pbegin;
+	auto nextpar = par;
 	++nextpar;
 
-	// Find the previous paragraph.
-	auto prevpar = begin;
-	if (prevpar != pbegin) {
-		auto prevpar_next = prevpar;
-		++prevpar_next;
-
-		while (prevpar_next != pbegin) {
-			++prevpar_next;
-			++prevpar;
-		}
-	}
-
 	// Generate this command.
-	openParTag(xs, &*pbegin, &*prevpar);
+	auto prevpar = text.paragraphs().getParagraphBefore(par);
+	openParTag(xs, &*par, prevpar);
 
-	pbegin->simpleDocBookOnePar(buf, xs, runparams,
-								text.outerFont(distance(begin, pbegin)));
+	par->simpleDocBookOnePar(buf, xs, runparams,
+	                         text.outerFont(distance(begin, par)));
 
-	closeTag(xs, &*pbegin, (nextpar != end) ? &*nextpar : nullptr);
-	xs << xml::CR();
+	closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr);
 }
 
-pair<ParagraphList::const_iterator, ParagraphList::const_iterator> makeAny(
+
+void makeAny(
 		Text const &text,
 		Buffer const &buf,
 		XMLStream &xs,
 		OutputParams const &ourparams,
-		ParagraphList::const_iterator par,
-		ParagraphList::const_iterator send,
-		ParagraphList::const_iterator pend)
+		ParagraphList::const_iterator par)
 {
 	switch (par->layout().latextype) {
-	case LATEX_COMMAND: {
-		// The files with which we are working never have more than
-		// one paragraph in a command structure.
-		// FIXME
-		// if (ourparams.docbook_in_par)
-		//   fix it so we don't get sections inside standard, e.g.
-		// note that we may then need to make runparams not const, so we
-		// can communicate that back.
-		// FIXME Maybe this fix should be in the routines themselves, in case
-		// they are called from elsewhere.
+	case LATEX_COMMAND:
 		makeCommand(buf, xs, ourparams, text, par);
-		++par;
 		break;
-	}
 	case LATEX_ENVIRONMENT:
 	case LATEX_LIST_ENVIRONMENT:
 	case LATEX_ITEM_ENVIRONMENT:
-		// FIXME Same fix here.
-		send = findEndOfEnvironment(par, pend);
-		par = makeEnvironment(buf, xs, ourparams, text, par, send);
+		makeEnvironment(buf, xs, ourparams, text, par);
 		break;
 	case LATEX_PARAGRAPH:
-		send = findLast(par, pend, LATEX_PARAGRAPH);
-		par = makeParagraphs(buf, xs, ourparams, text, par, send);
+		makeParagraph(buf, xs, ourparams, text, par);
 		break;
 	case LATEX_BIB_ENVIRONMENT:
-		send = findLast(par, pend, LATEX_BIB_ENVIRONMENT);
-		par = makeParagraphBibliography(buf, xs, ourparams, text, par, send);
+		makeParagraphBibliography(buf, xs, ourparams, text, par);
 		break;
 	}
-
-	return make_pair(par, send);
-}
-
-ParagraphList::const_iterator makeAnySimple(
-		Text const &text,
-		Buffer const &buf,
-		XMLStream &xs,
-		OutputParams const &ourparams,
-		ParagraphList::const_iterator par)
-{
-	auto parnext = par;
-	++parnext;
-
-	switch (par->layout().latextype) {
-	case LATEX_COMMAND: {
-		// The files with which we are working never have more than
-		// one paragraph in a command structure.
-		// FIXME
-		// if (ourparams.docbook_in_par)
-		//   fix it so we don't get sections inside standard, e.g.
-		// note that we may then need to make runparams not const, so we
-		// can communicate that back.
-		// FIXME Maybe this fix should be in the routines themselves, in case
-		// they are called from elsewhere.
-		makeCommand(buf, xs, ourparams, text, par);
-		return parnext;
-	}
-	case LATEX_ENVIRONMENT:
-	case LATEX_LIST_ENVIRONMENT:
-	case LATEX_ITEM_ENVIRONMENT:
-		// FIXME Same fix here.
-		return makeEnvironment(buf, xs, ourparams, text, par, parnext);
-	case LATEX_PARAGRAPH:
-		return makeParagraphs(buf, xs, ourparams, text, par, parnext);
-	case LATEX_BIB_ENVIRONMENT:
-		return makeParagraphBibliography(buf, xs, ourparams, text, par, parnext);
-	}
-
-	// This should never happen. Return the next paragraph to avoid an infinite loop.
-	return parnext;
 }
 
 } // end anonymous namespace
@@ -885,9 +718,8 @@ DocBookDocumentSectioning hasDocumentSectioning(ParagraphList const &paragraphs,
 		Layout const &style = paragraphs[bpit].layout();
 		documentHasSections |= style.category() == from_utf8("Sectioning");
 
-		if (documentHasSections) {
+		if (documentHasSections)
 			break;
-		}
 		bpit += 1;
 	}
 	// Paragraphs before the first section: [ runparams.par_begin ; eppit )
@@ -898,7 +730,10 @@ DocBookDocumentSectioning hasDocumentSectioning(ParagraphList const &paragraphs,
 
 bool hasOnlyNotes(Paragraph const & par)
 {
+	// Precondition: the paragraph is not empty. Otherwise, the function will always return true...
 	for (int i = 0; i < par.size(); ++i)
+		// If you find something that is not an inset (like actual text) or an inset that is not a note,
+		// return false.
 		if (!par.isInset(i) || !dynamic_cast<InsetNote *>(par.insetList().get(i)))
 			return false;
 	return true;
@@ -994,37 +829,6 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs, pit_type b
 }
 
 
-pit_type generateDocBookParagraphWithoutSectioning(
-		Text const & text,
-		Buffer const & buf,
-		XMLStream & xs,
-		OutputParams const & runparams,
-		ParagraphList const & paragraphs,
-		DocBookInfoTag const & info)
-{
-	auto bpit = info.bpit;
-	auto par = paragraphs.iterator_at(bpit);
-	auto lastStartedPar = par;
-	ParagraphList::const_iterator send;
-	auto const pend =
-			(info.epit == (int) paragraphs.size()) ?
-			paragraphs.end() : paragraphs.iterator_at(info.epit);
-
-	while (bpit < info.epit) {
-		if (info.abstract.find(bpit) != info.abstract.end()) {
-			bpit += 1;
-			continue;
-		}
-
-		tie(par, send) = makeAny(text, buf, xs, runparams, par, send, pend);
-		bpit += distance(lastStartedPar, par);
-		lastStartedPar = par;
-	}
-
-	return bpit;
-}
-
-
 void outputDocBookInfo(
 		Text const & text,
 		Buffer const & buf,
@@ -1040,6 +844,7 @@ void outputDocBookInfo(
 	bool hasAbstract = !info.abstract.empty();
 	docstring abstract;
 	if (hasAbstract) {
+		// Generate the abstract XML into a string before further checks.
 		odocstringstream os2;
 		{
 			XMLStream xs2(os2);
@@ -1048,8 +853,7 @@ void outputDocBookInfo(
 			// info.abstract is inclusive, epit is exclusive, hence +1 for looping.
 
 			while (bpit < epit) {
-				makeAnySimple(text, buf, xs2, runparams, paragraphs.iterator_at(bpit));
-				xs2 << XMLStream::ESCAPE_NONE << from_ascii("<!-- " + to_string(bpit) + " -->");
+				makeAny(text, buf, xs2, runparams, paragraphs.iterator_at(bpit));
 				bpit += 1;
 			}
 		}
@@ -1065,7 +869,7 @@ void outputDocBookInfo(
 			hasAbstract = false;
 	}
 
-	// The abstract must go in <info>.
+	// The abstract must go in <info>. Otherwise, decide whether to open <info> based on the layouts.
 	bool needInfo = !info.mustBeInInfo.empty() || hasAbstract;
 
 	// Start the <info> tag if required.
@@ -1076,16 +880,17 @@ void outputDocBookInfo(
 	}
 
 	// Output the elements that should go in <info>, before and after the abstract.
-	xs << XMLStream::ESCAPE_NONE << "<!-- shouldBeInInfo -->";
-	for (auto pit : info.shouldBeInInfo) // Typically, the title: these elements are so important and ubiquitous
-		// that mandating a wrapper like <info> would repel users.
-		makeAnySimple(text, buf, xs, runparams, paragraphs.iterator_at(pit));
-	xs << XMLStream::ESCAPE_NONE << "<!-- mustBeInInfo -->";
-	for (auto pit : info.mustBeInInfo)
+	for (auto pit : info.shouldBeInInfo) { // Typically, the title: these elements are so important and ubiquitous
+		// that mandating a wrapper like <info> would repel users. Thus, generate them first.
+		makeAny(text, buf, xs, runparams, paragraphs.iterator_at(pit));
+	}
+	for (auto pit : info.mustBeInInfo) {
 		if (info.abstract.find(pit) == info.abstract.end()) // The abstract must be in info, but is dealt with after.
-			makeAnySimple(text, buf, xs, runparams, paragraphs.iterator_at(pit));
-	xs << XMLStream::ESCAPE_NONE << "<!-- /info -->";
+			makeAny(text, buf, xs, runparams, paragraphs.iterator_at(pit));
+	}
 
+	// Always output the abstract as the last item of the <info>, as it requires special treatment (especially if
+	// it contains several paragraphs that are empty).
 	if (hasAbstract) {
 //		string tag = paragraphs[*info.abstract.begin()].layout().docbookforceabstracttag();
 //		if (tag == "NONE")
@@ -1093,9 +898,7 @@ void outputDocBookInfo(
 //
 //		xs << xml::StartTag(tag);
 //		xs << xml::CR();
-		xs << XMLStream::ESCAPE_NONE << "<!-- abs -->";
 		xs << XMLStream::ESCAPE_NONE << abstract;
-		xs << XMLStream::ESCAPE_NONE << "<!-- /abs -->";
 //		xs << xml::EndTag(tag);
 //		xs << xml::CR();
 	}
@@ -1147,7 +950,7 @@ void docbookSimpleAllParagraphs(
 	while (bpit < epit) {
 		auto par = paragraphs.iterator_at(bpit);
 		if (!hasOnlyNotes(*par))
-			makeAnySimple(text, buf, xs, runparams, par);
+			makeAny(text, buf, xs, runparams, par);
 		bpit += 1;
 	}
 }
@@ -1170,9 +973,6 @@ void docbookParagraphs(Text const &text,
 				return;
 			});
 
-	ParagraphList::const_iterator const pend =
-			(epit == (int) paragraphs.size()) ?
-			paragraphs.end() : paragraphs.iterator_at(epit);
 	std::stack<std::pair<int, string>> headerLevels; // Used to determine when to open/close sections: store the depth
 	// of the section and the tag that was used to open it.
 
@@ -1203,8 +1003,7 @@ void docbookParagraphs(Text const &text,
 		ParagraphList::const_iterator send;
 
 		if (hasOnlyNotes(*par)) {
-			++par;
-			bpit += distance(lastStartedPar, par);
+			bpit += 1;
 			continue;
 		}
 
@@ -1283,8 +1082,8 @@ void docbookParagraphs(Text const &text,
 		}
 
 		// Generate this paragraph.
-		tie(par, send) = makeAny(text, buf, xs, ourparams, par, send, pend);
-		bpit += distance(lastStartedPar, par);
+		makeAny(text, buf, xs, ourparams, par);
+		bpit += 1;
 	}
 
 	// If need be, close <section>s, but only at the end of the document (otherwise, dealt with at the beginning
diff --git a/src/xml.cpp b/src/xml.cpp
index e16a784..147eadd 100644
--- a/src/xml.cpp
+++ b/src/xml.cpp
@@ -200,7 +200,7 @@ bool XMLStream::closeFontTags()
 		tag_stack_.pop_back();
 		// this shouldn't happen, since then the font tags
 		// weren't in any other tag.
-//		LASSERT(!tag_stack_.empty(), return true);
+		LASSERT(!tag_stack_.empty(), return true);
 		if (tag_stack_.empty())
 			return true;
 		curtag = &tag_stack_.back();
@@ -583,62 +583,57 @@ docstring xml::uniqueID(docstring const & label)
 
 docstring xml::cleanID(docstring const & orig)
 {
-	// The standard xml:id only allows letters,
-	// digits, '-' and '.' in a name.
-	// This routine replaces illegal characters by '-' or '.'
-	// and adds a number for uniqueness if need be.
-	docstring const allowed = from_ascii(".-_");
+	// The standard xml:id only allows letters, digits, '-' and '.' in a name.
+	// This routine replaces illegal characters by '-' or '.' and adds a number for uniqueness if need be.
 
 	// Use a cache of already mangled names: the alterations may merge several IDs as one. This ensures that the IDs
 	// are not mixed up in the document.
+	// This code could be improved: it uses Qt outside the GUI part. Any TLS implementation could do the trick.
 	typedef map<docstring, docstring> MangledMap;
 	static QThreadStorage<MangledMap> tMangledNames;
 	static QThreadStorage<int> tMangleID;
 
-	MangledMap & mangledNames = tMangledNames.localData();
-
 	// If the name is already known, just return it.
-	MangledMap::const_iterator const known = mangledNames.find(orig);
+	MangledMap & mangledNames = tMangledNames.localData();
+	auto const known = mangledNames.find(orig);
 	if (known != mangledNames.end())
 		return known->second;
 
 	// Start creating the mangled name by iterating over the characters.
 	docstring content;
-	docstring::const_iterator it  = orig.begin();
-	docstring::const_iterator end = orig.end();
+	auto it = orig.cbegin();
+	auto end = orig.cend();
 
 	// Make sure it starts with a letter.
-	if (!isAlphaASCII(*it) && allowed.find(*it) >= allowed.size())
+	if (!isAlphaASCII(*it))
 		content += "x";
 
-	// Do the mangling.
+	// Parse the ID character by character and change what needs to.
 	bool mangle = false; // Indicates whether the ID had to be changed, i.e. if ID no more ensured to be unique.
 	for (; it != end; ++it) {
 		char_type c = *it;
-		if (isAlphaASCII(c) || isDigitASCII(c) || c == '-' || c == '.'
-		      || allowed.find(c) < allowed.size())
+		if (isAlphaASCII(c) || isDigitASCII(c) || c == '-' || c == '.' || c == '_') {
 			content += c;
-		else if (c == '_' || c == ' ') {
-			mangle = true;
-			content += "-";
-		}
-		else if (c == ':' || c == ',' || c == ';' || c == '!') {
+		} else if (c == ':' || c == ',' || c == ';' || c == '!') {
 			mangle = true;
 			content += ".";
-		}
-		else {
+		} else { // Other invalid characters, such as ' '.
 			mangle = true;
 			content += "-";
 		}
 	}
 
-	if (mangle) {
+	// If there had to be a change, check if ID unicity is still guaranteed.
+	// This avoids having a clash if satisfying XML requirements for ID makes two IDs identical, like "a:b" and "a!b",
+	// as both of them would be transformed as "a.b". With this procedure, one will become "a.b" and the other "a.b-1".
+	if (mangle && mangledNames.find(content) != mangledNames.end()) {
 		int & mangleID = tMangleID.localData();
-		content += "-" + convert<docstring>(mangleID++);
+		content += "-" + convert<docstring>(mangleID);
+		mangleID += 1;
 	}
 
+	// Save the new ID to avoid recomputing it afterwards and to ensure stability over the document.
 	mangledNames[orig] = content;
-
 	return content;
 }
 

commit 587ceabfd5b9fb0c99dea0960e2f5cc83e3189f0
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 16 19:07:14 2020 +0200

    A few more constants to avoid copies

diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index 876adea..34b22c1 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -1216,9 +1216,9 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
 		if (! delayedTags.empty()) {
 			unsigned long remainingTags = delayedTags.size(); // Used as a workaround. With GCC 7, when erasing all
 			// elements one by one, some elements may still pop in later on (even though they were deleted previously).
-			auto hasTag = [&delayedTags](string key) { return delayedTags.find(key) != delayedTags.end(); };
-			auto getTag = [&delayedTags](string key) { return from_utf8(delayedTags[key]); };
-			auto eraseTag = [&delayedTags, &remainingTags](string key) {
+			auto hasTag = [&delayedTags](const string & key) { return delayedTags.find(key) != delayedTags.end(); };
+			auto getTag = [&delayedTags](const string & key) { return from_utf8(delayedTags[key]); };
+			auto eraseTag = [&delayedTags, &remainingTags](const string & key) {
 				remainingTags -= 1;
 				delayedTags.erase(key);
 			};

commit f0570e4b975171602c3ee779d22a3dc693584569
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Aug 3 16:04:26 2020 +0200

    DocBook: add a layout tag to tell whether an item is the abstract or not.

diff --git a/autotests/export/docbook/bibliography_precooked_aastex.xml b/autotests/export/docbook/bibliography_precooked_aastex.xml
index e15bfdd..fe77b72 100644
--- a/autotests/export/docbook/bibliography_precooked_aastex.xml
+++ b/autotests/export/docbook/bibliography_precooked_aastex.xml
@@ -3,8 +3,8 @@
   See http://www.lyx.org/ for more information -->
 <article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
 <info>
-<title>Collapsed Cores in Globular Clusters,  Gauge-Boson Couplings, and AASTeX Examples</title>
-<author><personname>S. Djorgovski and Ivan R. King</personname>
+<!-- shouldBeInInfo --><title>Collapsed Cores in Globular Clusters,  Gauge-Boson Couplings, and AASTeX Examples</title>
+<!-- mustBeInInfo --><author><personname>S. Djorgovski and Ivan R. King</personname>
 <affiliation><orgname>Astronomy Department, University of California, Berkeley, CA 94720</orgname></affiliation>
 <affiliation role="alternate"><orgname>Visiting Astronomer Cerro Tololo Inter-American Observatory.CTIO is operated by AURA Inc. under contract to the National Science Foundation.</orgname></affiliation>
 <affiliation role="alternate"><orgname>Society of Fellows, Harvard University.</orgname></affiliation>
@@ -17,16 +17,11 @@
 <author><personname>R. J. Hanisch</personname>
 <affiliation><orgname>Space Telescope Science Institute, Baltimore, MD 21218</orgname></affiliation>
 <affiliation role="alternate"><orgname>Patron, Alonso's Bar and Grill</orgname></affiliation></author>
-<abstract><para>
-<para>This is a preliminary report on surface photometry of the major fraction of known globular clusters, to see which of them show the signs of a collapsed core. We also explore some diversionary mathematics and recreational tables. </para>
-<!-- Output Error: Tried to close `keyword' when tag was not open. Tag discarded. -->
-<!-- Output Error: Tried to close `keywordset' when tag was not open. Tag discarded. -->
-
 <keywordset><keyword>clusters: globular, peanut—bosons: bozos</keyword></keywordset>
-<!-- Output Error: Closing tag `info' when other tags are open, namely: -->
-<!-- Output Error: para -->
-</para><!-- Output Error: abstract -->
-</abstract></info>
+<!-- /info --><!-- abs --><abstract><para>
+<para>This is a preliminary report on surface photometry of the major fraction of known globular clusters, to see which of them show the signs of a collapsed core. We also explore some diversionary mathematics and recreational tables. </para>
+</para></abstract>
+<!-- 15 --><!-- /abs --></info>
 <section>
 <title>Introduction</title>
 <para>A focal problem today in the dynamics of globular clusters is core collapse. It has been predicted by theory for decades <biblioref endterm="hen61" />, <biblioref endterm="lyn68" />, <biblioref endterm="spi85" />, but observation has been less alert to the phenomenon. For many years the central brightness peak in M15 <biblioref endterm="kin75" />, <biblioref endterm="new78" /> seemed a unique anomaly. Then <biblioref endterm="aur82" /> suggested a central peak in NGC 6397, and a limited photographic survey of ours <biblioref endterm="djo84" /> found three more cases, including NGC 6624, whose sharp center had often been remarked on <biblioref endterm="can78" />. </para>
@@ -112,7 +107,7 @@
 </section>
 <section>
 <title>Helicity Amplitudes</title>
-<para>It has been realized that helicity amplitudes provide a convenient means for Feynman diagram<footnote><para>Footnotes can be inserted like this.</para>
+<para>It has been realized that helicity amplitudes provide a convenient means for Feynman diagram<footnote><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><para>Footnotes can be inserted like this.</para>
 </footnote> evaluations. These amplitude-level techniques are particularly convenient for calculations involving many Feynman diagrams, where the usual trace techniques for the amplitude squared becomes unwieldy. Our calculations use the helicity techniques developed by other authors <biblioref endterm="hag86" />; we briefly summarize below.</para>
 <section>
 <title>Formalism</title>
@@ -694,8 +689,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mtable>
  </m:math>
 </informalequation>
-<!-- Output Error: Tried to close `title' when tag was not open. Tag discarded. -->
-
+</MathLetters>
 </section>
 </section>
 <section>
@@ -957,7 +951,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
   </m:msub>
  </m:mrow>
  </m:math>
-</inlineequation>, but the assumption is that the alternate results should be less than 90° out of phase with previous values. We have no observations of <!-- \ion{Ca}{2} -->. Roughly <inlineequation>
+</inlineequation>, but the assumption is that the alternate results should be less than 90° out of phase with previous values. We have no observations of <!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><!-- \ion{Ca}{2} -->. Roughly <inlineequation>
 <alt role='tex'>\nicefrac{4}{5}</alt>
  <m:math>
  
@@ -971,14 +965,13 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation> of the electronically submitted abstracts for AAS meetings are error-free. </para>
-<acknowledgement><para>We are grateful to V. Barger, T. Han, and R. J. N. Phillips for doing the math in section&#xA0;<xref linkend="bozomath" />. More information on the AASTeX macros package are available at <link xlink:href="http://www.aas.org/publications/aastex">http://www.aas.org/publications/aastex</link> or the <link xlink:href="ftp://www.aas.org/pubs/AAS ftp site">AAS ftp site</link>.</para>
+<acknowledgement><para>We are grateful to V. Barger, T. Han, and R. J. N. Phillips for doing the math in section&#xA0;<xref linkend="bozomath" />. More information on the AASTeX macros package are available at <link xlink:href="http://www.aas.org/publications/aastex"><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->http://www.aas.org/publications/aastex</link> or the <link xlink:href="ftp://www.aas.org/pubs/AAS ftp site">AAS ftp site</link>.</para>
 <application>IRAF, AIPS, Astropy, ...</application><!-- Output Error: Tried to close `para' when tag was not open. Tag discarded. -->
 
-<Appendix></Appendix>
 <bibliography>
 <bibliomixed xml:id='aur82'>Aurière, M. 1982, <!-- \aap -->, 109, 301 </bibliomixed>
 <bibliomixed xml:id='can78'>Canizares, C. R., Grindlay, J. E., Hiltner, W. A., Liller, W., and McClintock, J. E. 1978, <!-- \apj -->, 224, 39 </bibliomixed>
-<bibliomixed xml:id='djo84'>Djorgovski, S., and King, I. R. 1984, <!-- \apjl -->, 277, L49 </bibliomixed>
+<bibliomixed xml:id='djo84'>Djorgovski, S., and King, I. R. 1984, <!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><!-- \apjl -->, 277, L49 </bibliomixed>
 <bibliomixed xml:id='hag86'>Hagiwara, K., and Zeppenfeld, D. 1986, Nucl.Phys., 274, 1 </bibliomixed>
 <bibliomixed xml:id='har84'>Harris, W. E., and van den Bergh, S. 1984, <!-- \aj -->, 89, 1816 </bibliomixed>
 <bibliomixed xml:id='hen61'>Hénon, M. 1961, Ann.d'Ap., 24, 369 </bibliomixed>
@@ -986,19 +979,19 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
 <bibliomixed xml:id='kin75'>King, I. R. 1975, Dynamics of Stellar Systems, A. Hayli, Dordrecht: Reidel, 1975, 99 </bibliomixed>
 <bibliomixed xml:id='kin68'>King, I. R., Hedemann, E., Hodge, S. M., and White, R. E. 1968, <!-- \aj -->, 73, 456 </bibliomixed>
 <bibliomixed xml:id='kro84'>Kron, G. E., Hewitt, A. V., and Wasserman, L. H. 1984, <!-- \pasp -->, 96, 198 </bibliomixed>
-<bibliomixed xml:id='lyn68'>Lynden-Bell, D., and Wood, R. 1968, <!-- \mnras -->, 138, 495 </bibliomixed>
+<bibliomixed xml:id='lyn68'>Lynden-Bell, D., and Wood, R. 1968, <!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><!-- \mnras -->, 138, 495 </bibliomixed>
 <bibliomixed xml:id='new78'>Newell, E. B., and O'Neil, E. J. 1978, <!-- \apjs -->, 37, 27 </bibliomixed>
 <bibliomixed xml:id='ort85'>Ortolani, S., Rosino, L., and Sandage, A. 1985, <!-- \aj -->, 90, 473 </bibliomixed>
 <bibliomixed xml:id='pet76'>Peterson, C. J. 1976, <!-- \aj -->, 81, 617 </bibliomixed>
 <bibliomixed xml:id='spi85'>Spitzer, L. 1985, Dynamics of Star Clusters, J. Goodman and P. Hut, Dordrecht: Reidel, 109 </bibliomixed>
 </bibliography>
 <table xml:id="tbl-2">
-<caption>Terribly relevant tabular information.</caption>
-<tbody>
+<caption><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->Terribly relevant tabular information.</caption>
+<!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><tbody>
 <tr>
-<td align='center' valign='top'>Star </td>
-<td align='right' valign='top'> Height </td>
-<td align='right' valign='top'> <inlineequation>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->Star </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> Height </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
 <alt role='tex'>d_{x}</alt>
  <m:math>
  
@@ -1012,7 +1005,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='right' valign='top'> <inlineequation>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
 <alt role='tex'>d_{y}</alt>
  <m:math>
  
@@ -1026,7 +1019,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='right' valign='top'> <inlineequation>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
 <alt role='tex'>n</alt>
  <m:math>
  
@@ -1034,7 +1027,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='right' valign='top'> <inlineequation>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
 <alt role='tex'>\chi^{2}</alt>
  <m:math>
  
@@ -1048,7 +1041,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='right' valign='top'> <inlineequation>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
 <alt role='tex'>R_{maj}</alt>
  <m:math>
  
@@ -1064,7 +1057,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='right' valign='top'> <inlineequation>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
 <alt role='tex'>R_{min}</alt>
  <m:math>
  
@@ -1080,15 +1073,15 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='center' valign='top' colspan='1'><inlineequation>
+<td align='center' valign='top' colspan='1'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><inlineequation>
 <alt role='tex'>P</alt>
  <m:math>
  
  <m:mrow><m:mi>P</m:mi>
  </m:mrow>
  </m:math>
-</inlineequation>a</td>
-<td align='right' valign='top'> <inlineequation>
+</inlineequation><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->a</td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
 <alt role='tex'>PR_{maj}</alt>
  <m:math>
  
@@ -1106,7 +1099,7 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='right' valign='top'> <inlineequation>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> <inlineequation>
 <alt role='tex'>PR_{min}</alt>
  <m:math>
  
@@ -1124,105 +1117,105 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation></td>
-<td align='center' valign='top' colspan='1'><inlineequation>
+<td align='center' valign='top' colspan='1'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><inlineequation>
 <alt role='tex'>\Theta</alt>
  <m:math>
  
  <m:mrow><m:mo>&#x398;</m:mo>
  </m:mrow>
  </m:math>
-</inlineequation>b</td>
-<td align='center' valign='top'>Ref.</td>
+</inlineequation><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->b</td>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->Ref.</td>
 </tr>
 <tr>
-<td align='center' valign='top'><!-- \tableline\tableline -->1 </td>
-<td align='right' valign='top'>33472.5 </td>
-<td align='right' valign='top'>-0.1 </td>
-<td align='right' valign='top'>0.4 </td>
-<td align='right' valign='top'>53 </td>
-<td align='right' valign='top'>27.4 </td>
-<td align='right' valign='top'>2.065 </td>
-<td align='right' valign='top'>1.940 </td>
-<td align='right' valign='top'>3.900 </td>
-<td align='right' valign='top'>68.3 </td>
-<td align='right' valign='top'>116.2 </td>
-<td align='right' valign='top'>-27.639</td>
-<td align='center' valign='top'>1,2</td>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --><!-- \tableline\tableline -->1 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->33472.5 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-0.1 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->0.4 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->53 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->27.4 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->2.065 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.940 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->3.900 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->68.3 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->116.2 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-27.639</td>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1,2</td>
 </tr>
 <tr>
-<td align='center' valign='top'> 2 </td>
-<td align='right' valign='top'>27802.4 </td>
-<td align='right' valign='top'>-0.3 </td>
-<td align='right' valign='top'>-0.2 </td>
-<td align='right' valign='top'>60 </td>
-<td align='right' valign='top'>3.7 </td>
-<td align='right' valign='top'>1.628 </td>
-<td align='right' valign='top'>1.510 </td>
-<td align='right' valign='top'>2.156 </td>
-<td align='right' valign='top'>6.8 </td>
-<td align='right' valign='top'>7.5 </td>
-<td align='right' valign='top'>-26.764</td>
-<td align='center' valign='top'>3</td>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 2 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->27802.4 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-0.3 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-0.2 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->60 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->3.7 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.628 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.510 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->2.156 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->6.8 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->7.5 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-26.764</td>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->3</td>
 </tr>
 <tr>
-<td align='center' valign='top'> 3 </td>
-<td align='right' valign='top'>29210.6 </td>
-<td align='right' valign='top'>0.9 </td>
-<td align='right' valign='top'>0.3 </td>
-<td align='right' valign='top'>60 </td>
-<td align='right' valign='top'>3.4 </td>
-<td align='right' valign='top'>1.622 </td>
-<td align='right' valign='top'>1.551 </td>
-<td align='right' valign='top'>2.159 </td>
-<td align='right' valign='top'>6.7 </td>
-<td align='right' valign='top'>7.3 </td>
-<td align='right' valign='top'>-40.272</td>
-<td align='center' valign='top'>4</td>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 3 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->29210.6 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->0.9 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->0.3 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->60 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->3.4 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.622 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.551 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->2.159 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->6.7 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->7.3 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-40.272</td>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->4</td>
 </tr>
 <tr>
-<td align='center' valign='top'> 4 </td>
-<td align='right' valign='top'>32733.8 </td>
-<td align='right' valign='top'>-1.2c</td>
-<td align='right' valign='top'>-0.5 </td>
-<td align='right' valign='top'>41 </td>
-<td align='right' valign='top'>54.8 </td>
-<td align='right' valign='top'>2.282 </td>
-<td align='right' valign='top'>2.156 </td>
-<td align='right' valign='top'>4.313 </td>
-<td align='right' valign='top'>117.4 </td>
-<td align='right' valign='top'>78.2 </td>
-<td align='right' valign='top'>-35.847</td>
-<td align='center' valign='top'>5,6</td>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 4 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->32733.8 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-1.2<!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->c</td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-0.5 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->41 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->54.8 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->2.282 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->2.156 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->4.313 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->117.4 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->78.2 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-35.847</td>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->5,6</td>
 </tr>
 <tr>
-<td align='center' valign='top'> 5 </td>
-<td align='right' valign='top'> 9607.4 </td>
-<td align='right' valign='top'>-0.4 </td>
-<td align='right' valign='top'>-0.4 </td>
-<td align='right' valign='top'>60 </td>
-<td align='right' valign='top'>1.4 </td>
-<td align='right' valign='top'>1.669c</td>
-<td align='right' valign='top'>1.574 </td>
-<td align='right' valign='top'>2.343 </td>
-<td align='right' valign='top'>8.0 </td>
-<td align='right' valign='top'>8.9 </td>
-<td align='right' valign='top'>-33.417</td>
-<td align='center' valign='top'>7</td>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 5 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 9607.4 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-0.4 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-0.4 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->60 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.4 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.669<!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->c</td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.574 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->2.343 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->8.0 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->8.9 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-33.417</td>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->7</td>
 </tr>
 <tr>
-<td align='center' valign='top'> 6 </td>
-<td align='right' valign='top'>31638.6 </td>
-<td align='right' valign='top'>1.6 </td>
-<td align='right' valign='top'>0.1 </td>
-<td align='right' valign='top'>39 </td>
-<td align='right' valign='top'>315.2 </td>
-<td align='right' valign='top'> 3.433 </td>
-<td align='right' valign='top'>3.075 </td>
-<td align='right' valign='top'>7.488 </td>
-<td align='right' valign='top'>92.1 </td>
-<td align='right' valign='top'>25.3 </td>
-<td align='right' valign='top'>-12.052 </td>
-<td align='center' valign='top'>8</td>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 6 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->31638.6 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->1.6 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->0.1 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->39 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->315.2 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info --> 3.433 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->3.075 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->7.488 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->92.1 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->25.3 </td>
+<td align='right' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->-12.052 </td>
+<td align='center' valign='top'><!-- shouldBeInInfo --><!-- mustBeInInfo --><!-- /info -->8</td>
 </tr>
 </tbody>
 <Table note>a<!-- }{ -->Sample footnote for table&#xA0;<xref linkend="tbl-2" /> that was generated with the LaTeX table environment</Table note>
diff --git a/lib/layouts/aastex.layout b/lib/layouts/aastex.layout
index 97c8b64..74d2ab6 100644
--- a/lib/layouts/aastex.layout
+++ b/lib/layouts/aastex.layout
@@ -282,9 +282,6 @@ Style Abstract
 	  Series	Bold
 	  Size		Normal
 	EndFont
-	DocBookTag            abstract
-	DocBookItemTag        para
-	DocBookInInfo         always
 End
 
 
diff --git a/lib/layouts/stdstruct.inc b/lib/layouts/stdstruct.inc
index 83d46e9..b02499f 100644
--- a/lib/layouts/stdstruct.inc
+++ b/lib/layouts/stdstruct.inc
@@ -49,9 +49,10 @@ Style Abstract
 			font-weight: bold;
 		}
 	EndHTMLStyle
+	DocBookAbstract       true
+	DocBookInInfo         always
 	DocBookTag            abstract
 	DocBookItemTag        para
-	DocBookInInfo         always
 End
 
 
diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py
index e69deba..2bb62e3 100644
--- a/lib/scripts/layout2layout.py
+++ b/lib/scripts/layout2layout.py
@@ -282,7 +282,7 @@ currentFormat = 83
 # - Removed tag Element for flex insets
 
 # Incremented to format 83, 2 August 2020 by dourouc05
-# New tag DocBookWrapperMergeWithPrevious
+# New tags DocBookWrapperMergeWithPrevious and DocBookAbstract
 
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
diff --git a/src/Layout.cpp b/src/Layout.cpp
index eeb58d0..5047506 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -107,6 +107,7 @@ enum LayoutTags {
 	LT_DOCBOOKTAG,
 	LT_DOCBOOKATTR,
 	LT_DOCBOOKININFO,
+	LT_DOCBOOKABSTRACT,
 	LT_DOCBOOKWRAPPERTAG,
 	LT_DOCBOOKWRAPPERATTR,
 	LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS,
@@ -177,6 +178,7 @@ Layout::Layout()
 	htmllabelfirst_ = false;
 	htmlforcecss_ = false;
 	htmltitle_ = false;
+	docbookabstract_ = false;
 	docbookwrappermergewithprevious_ = false;
 	spellcheck = true;
 	forcelocal = 0;
@@ -221,6 +223,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 		{ "commanddepth",   LT_COMMANDDEPTH },
 		{ "copystyle",      LT_COPYSTYLE },
 		{ "dependson",      LT_DEPENDSON },
+		{ "docbookabstract",         LT_DOCBOOKABSTRACT },
 		{ "docbookattr",             LT_DOCBOOKATTR },
 		{ "docbookforceabstracttag", LT_DOCBOOKFORCEABSTRACTTAG },
 		{ "docbookininfo",           LT_DOCBOOKININFO },
@@ -738,6 +741,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 			lex >> docbookininfo_;
 			break;
 
+		case LT_DOCBOOKABSTRACT:
+			lex >> docbookabstract_;
+			break;
+
 		case LT_DOCBOOKWRAPPERTAG:
 			lex >> docbookwrappertag_;
 			break;
@@ -1603,6 +1610,7 @@ void Layout::write(ostream & os) const
 		os << "\tDocBookAttr " << docbookattr_ << '\n';
 	if(!docbookininfo_.empty())
 		os << "\tDocBookInInfo " << docbookininfo_ << '\n';
+	os << "\tDocBookAbstract " << docbookabstract_ << '\n';
 	if(!docbookwrappertag_.empty())
 		os << "\tDocBookWrapperTag " << docbookwrappertag_ << '\n';
 	if(!docbookwrapperattr_.empty())
diff --git a/src/Layout.h b/src/Layout.h
index d9eb893..a894142 100644
--- a/src/Layout.h
+++ b/src/Layout.h
@@ -199,6 +199,8 @@ public:
 	///
 	std::string const & docbookininfo() const;
 	///
+	bool docbookabstract() const { return docbookabstract_; }
+	///
 	std::string const & docbookwrappertag() const;
 	///
 	std::string const & docbookwrapperattr() const;
@@ -516,11 +518,14 @@ private:
 	mutable std::string docbookwrapperattr_;
 	/// Whether this wrapper tag may be merged with the previously opened wrapper tag.
 	bool docbookwrappermergewithprevious_;
-	/// Outer tag for this section, only if this layout represent a sectionning item, including chapters (default: section).
+	/// Outer tag for this section, only if this layout represent a sectionning item, including chapters
+	/// (default: section).
 	mutable std::string docbooksectiontag_;
 	/// Whether this tag must/can/can't go into an <info> tag (default: never, as it only makes sense for metadata).
 	mutable std::string docbookininfo_;
-	/// whether this element (root or not) does not accept text without a section(i.e. the first text that is met
+	/// Wehther this paragraph should be considered as abstract.
+	bool docbookabstract_;
+	/// Whether this element (root or not) does not accept text without a section (i.e. the first text that is met
 	/// in LyX must be considered as the abstract if this is true); this text must be output with the specific tag
 	/// held by this attribute
 	mutable std::string docbookforceabstracttag_;
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index fd38940..4430041 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -219,7 +219,8 @@ void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar
 	if (tag == "Plain Layout")
 		tag = "para";
 
-	xs << xml::ParTag(tag, lay.docbookattr());
+	if (!xs.isTagOpen(xml::ParTag(tag, lay.docbookattr()), 1)) // Don't nest a paragraph directly in a paragraph.
+		xs << xml::ParTag(tag, lay.docbookattr());
 
 	if (lay.docbookitemtag() != "NONE")
 		xs << xml::StartTag(lay.docbookitemtag(), lay.docbookitemattr());
@@ -554,30 +555,38 @@ ParagraphList::const_iterator makeEnvironment(
 	ParagraphList::const_iterator par = pbegin;
 	depth_type const origdepth = pbegin->params().depth();
 
-	// Find the previous paragraph.
-	auto prevpar = begin;
-	if (prevpar != par) {
-		auto prevpar_next = prevpar;
-		++prevpar_next;
-
-		while (prevpar_next != par) {
+	// Output the opening tag for this environment.
+	{
+		// Find the previous paragraph.
+		auto prevpar = begin;
+		if (prevpar != par) {
+			auto prevpar_next = prevpar;
 			++prevpar_next;
-			++prevpar;
+
+			while (prevpar_next != par) {
+				++prevpar_next;
+				++prevpar;
+			}
 		}
-	}
 
-	// open tag for this environment
-	openParTag(xs, &*par, &*prevpar);
-	xs << xml::CR();
+		// Open tag for this environment.
+		openParTag(xs, &*par, &*prevpar);
+		xs << xml::CR();
+	}
 
 	// we will on occasion need to remember a layout from before.
 	Layout const *lastlay = nullptr;
+	auto prevpar = par;
 
 	while (par != pend) {
 		Layout const & style = par->layout();
 		ParagraphList::const_iterator send;
 
+		auto parnext = par;
+		++parnext;
+
 		// Actual content of this paragraph.
+		prevpar = par;
 		switch (style.latextype) {
 		case LATEX_ENVIRONMENT:
 		case LATEX_LIST_ENVIRONMENT:
@@ -701,15 +710,15 @@ ParagraphList::const_iterator makeEnvironment(
 			break;
 		}
 		case LATEX_PARAGRAPH:
-			send = findLast(par, pend, LATEX_PARAGRAPH);
-			par = makeParagraphs(buf, xs, runparams, text, par, send);
+//			send = findLast(par, pend, LATEX_PARAGRAPH);
+			par = makeParagraphs(buf, xs, runparams, text, par, parnext);
 			break;
 		case LATEX_BIB_ENVIRONMENT:
-			send = findLast(par, pend, LATEX_BIB_ENVIRONMENT);
-			par = makeParagraphBibliography(buf, xs, runparams, text, par, send);
+//			send = findLast(par, pend, LATEX_BIB_ENVIRONMENT);
+			makeParagraphBibliography(buf, xs, runparams, text, par, parnext);
 			break;
 		case LATEX_COMMAND:
-			++par;
+			par = parnext;
 			break;
 		}
 	}
@@ -721,9 +730,10 @@ ParagraphList::const_iterator makeEnvironment(
 			xs << xml::CR();
 		}
 	}
-	auto nextpar = par;
-	++nextpar;
-	closeTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr);
+//	auto nextpar = par;
+//	++nextpar;
+	closeTag(xs, &*prevpar, &*par);
+//	closeTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr);
 	xs << xml::CR();
 	return pend;
 }
@@ -773,43 +783,80 @@ pair<ParagraphList::const_iterator, ParagraphList::const_iterator> makeAny(
 		ParagraphList::const_iterator send,
 		ParagraphList::const_iterator pend)
 {
-	Layout const & style = par->layout();
-
-	switch (style.latextype) {
-		case LATEX_COMMAND: {
-			// The files with which we are working never have more than
-			// one paragraph in a command structure.
-			// FIXME
-			// if (ourparams.docbook_in_par)
-			//   fix it so we don't get sections inside standard, e.g.
-			// note that we may then need to make runparams not const, so we
-			// can communicate that back.
-			// FIXME Maybe this fix should be in the routines themselves, in case
-			// they are called from elsewhere.
-			makeCommand(buf, xs, ourparams, text, par);
-			++par;
-			break;
-		}
-		case LATEX_ENVIRONMENT:
-		case LATEX_LIST_ENVIRONMENT:
-		case LATEX_ITEM_ENVIRONMENT:
-			// FIXME Same fix here.
-			send = findEndOfEnvironment(par, pend);
-			par = makeEnvironment(buf, xs, ourparams, text, par, send);
-			break;
-		case LATEX_PARAGRAPH:
-			send = findLast(par, pend, LATEX_PARAGRAPH);
-			par = makeParagraphs(buf, xs, ourparams, text, par, send);
-			break;
-		case LATEX_BIB_ENVIRONMENT:
-			send = findLast(par, pend, LATEX_BIB_ENVIRONMENT);
-			par = makeParagraphBibliography(buf, xs, ourparams, text, par, send);
-			break;
+	switch (par->layout().latextype) {
+	case LATEX_COMMAND: {
+		// The files with which we are working never have more than
+		// one paragraph in a command structure.
+		// FIXME
+		// if (ourparams.docbook_in_par)
+		//   fix it so we don't get sections inside standard, e.g.
+		// note that we may then need to make runparams not const, so we
+		// can communicate that back.
+		// FIXME Maybe this fix should be in the routines themselves, in case
+		// they are called from elsewhere.
+		makeCommand(buf, xs, ourparams, text, par);
+		++par;
+		break;
+	}
+	case LATEX_ENVIRONMENT:
+	case LATEX_LIST_ENVIRONMENT:
+	case LATEX_ITEM_ENVIRONMENT:
+		// FIXME Same fix here.
+		send = findEndOfEnvironment(par, pend);
+		par = makeEnvironment(buf, xs, ourparams, text, par, send);
+		break;
+	case LATEX_PARAGRAPH:
+		send = findLast(par, pend, LATEX_PARAGRAPH);
+		par = makeParagraphs(buf, xs, ourparams, text, par, send);
+		break;
+	case LATEX_BIB_ENVIRONMENT:
+		send = findLast(par, pend, LATEX_BIB_ENVIRONMENT);
+		par = makeParagraphBibliography(buf, xs, ourparams, text, par, send);
+		break;
 	}
 
 	return make_pair(par, send);
 }
 
+ParagraphList::const_iterator makeAnySimple(
+		Text const &text,
+		Buffer const &buf,
+		XMLStream &xs,
+		OutputParams const &ourparams,
+		ParagraphList::const_iterator par)
+{
+	auto parnext = par;
+	++parnext;
+
+	switch (par->layout().latextype) {
+	case LATEX_COMMAND: {
+		// The files with which we are working never have more than
+		// one paragraph in a command structure.
+		// FIXME
+		// if (ourparams.docbook_in_par)
+		//   fix it so we don't get sections inside standard, e.g.
+		// note that we may then need to make runparams not const, so we
+		// can communicate that back.
+		// FIXME Maybe this fix should be in the routines themselves, in case
+		// they are called from elsewhere.
+		makeCommand(buf, xs, ourparams, text, par);
+		return parnext;
+	}
+	case LATEX_ENVIRONMENT:
+	case LATEX_LIST_ENVIRONMENT:
+	case LATEX_ITEM_ENVIRONMENT:
+		// FIXME Same fix here.
+		return makeEnvironment(buf, xs, ourparams, text, par, parnext);
+	case LATEX_PARAGRAPH:
+		return makeParagraphs(buf, xs, ourparams, text, par, parnext);
+	case LATEX_BIB_ENVIRONMENT:
+		return makeParagraphBibliography(buf, xs, ourparams, text, par, parnext);
+	}
+
+	// This should never happen. Return the next paragraph to avoid an infinite loop.
+	return parnext;
+}
+
 } // end anonymous namespace
 
 
@@ -883,7 +930,7 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs, pit_type b
 			continue;
 		}
 
-		if (par.layout().name() == from_ascii("Abstract"))
+		if (par.layout().docbookabstract())
 			hasAbstractLayout = true;
 
 		// Based on layout information, store this paragraph in one set: should be in <info>, must be.
@@ -908,7 +955,7 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs, pit_type b
 	if (hasAbstractLayout) {
 		pit_type pit = bpit;
 		while (pit < cpit) { // Don't overshoot the <info> part.
-			if (paragraphs[pit].layout().name() == from_ascii("Abstract"))
+			if (paragraphs[pit].layout().docbookabstract())
 				abstract.emplace(pit);
 			pit++;
 		}
@@ -953,17 +1000,22 @@ pit_type generateDocBookParagraphWithoutSectioning(
 		XMLStream & xs,
 		OutputParams const & runparams,
 		ParagraphList const & paragraphs,
-		pit_type bpit,
-		pit_type epit)
+		DocBookInfoTag const & info)
 {
+	auto bpit = info.bpit;
 	auto par = paragraphs.iterator_at(bpit);
 	auto lastStartedPar = par;
 	ParagraphList::const_iterator send;
 	auto const pend =
-			(epit == (int) paragraphs.size()) ?
-			paragraphs.end() : paragraphs.iterator_at(epit);
+			(info.epit == (int) paragraphs.size()) ?
+			paragraphs.end() : paragraphs.iterator_at(info.epit);
+
+	while (bpit < info.epit) {
+		if (info.abstract.find(bpit) != info.abstract.end()) {
+			bpit += 1;
+			continue;
+		}
 
-	while (bpit < epit) {
 		tie(par, send) = makeAny(text, buf, xs, runparams, par, send, pend);
 		bpit += distance(lastStartedPar, par);
 		lastStartedPar = par;
@@ -988,18 +1040,25 @@ void outputDocBookInfo(
 	bool hasAbstract = !info.abstract.empty();
 	docstring abstract;
 	if (hasAbstract) {
-		pit_type bpitAbstract = *std::min_element(info.abstract.begin(), info.abstract.end());
-		pit_type epitAbstract = *std::max_element(info.abstract.begin(), info.abstract.end());
-
 		odocstringstream os2;
-		XMLStream xs2(os2);
-		generateDocBookParagraphWithoutSectioning(text, buf, xs2, runparams, paragraphs, bpitAbstract, epitAbstract);
+		{
+			XMLStream xs2(os2);
+			auto bpit = *std::min_element(info.abstract.begin(), info.abstract.end());
+			auto epit = 1 + *std::max_element(info.abstract.begin(), info.abstract.end());
+			// info.abstract is inclusive, epit is exclusive, hence +1 for looping.
+
+			while (bpit < epit) {
+				makeAnySimple(text, buf, xs2, runparams, paragraphs.iterator_at(bpit));
+				xs2 << XMLStream::ESCAPE_NONE << from_ascii("<!-- " + to_string(bpit) + " -->");
+				bpit += 1;
+			}
+		}
 
 		// Actually output the abstract if there is something to do. Don't count line feeds or spaces in this,
 		// even though they must be properly output if there is some abstract.
-		docstring abstractContent = os2.str();
+		abstract = os2.str();
 		static const lyx::regex reg("[ \\r\\n]*");
-		abstractContent = from_utf8(lyx::regex_replace(to_utf8(abstractContent), reg, string("")));
+		docstring abstractContent = from_utf8(lyx::regex_replace(to_utf8(abstract), reg, string("")));
 
 		// Nothing? Then there is no abstract!
 		if (abstractContent.empty())
@@ -1016,19 +1075,29 @@ void outputDocBookInfo(
 		xs << xml::CR();
 	}
 
-	// Output the elements that should go in <info>.
-	generateDocBookParagraphWithoutSectioning(text, buf, xs, runparams, paragraphs, info.bpit, info.epit);
+	// Output the elements that should go in <info>, before and after the abstract.
+	xs << XMLStream::ESCAPE_NONE << "<!-- shouldBeInInfo -->";
+	for (auto pit : info.shouldBeInInfo) // Typically, the title: these elements are so important and ubiquitous
+		// that mandating a wrapper like <info> would repel users.
+		makeAnySimple(text, buf, xs, runparams, paragraphs.iterator_at(pit));
+	xs << XMLStream::ESCAPE_NONE << "<!-- mustBeInInfo -->";
+	for (auto pit : info.mustBeInInfo)
+		if (info.abstract.find(pit) == info.abstract.end()) // The abstract must be in info, but is dealt with after.
+			makeAnySimple(text, buf, xs, runparams, paragraphs.iterator_at(pit));
+	xs << XMLStream::ESCAPE_NONE << "<!-- /info -->";
 
-	if (hasAbstract && !abstract.empty()) { // The second test is probably superfluous.
-		string tag = paragraphs[*info.abstract.begin()].layout().docbookforceabstracttag();
-		if (tag == "NONE")
-			tag = "abstract";
-
-		xs << xml::StartTag(tag);
-		xs << xml::CR();
+	if (hasAbstract) {
+//		string tag = paragraphs[*info.abstract.begin()].layout().docbookforceabstracttag();
+//		if (tag == "NONE")
+//			tag = "abstract";
+//
+//		xs << xml::StartTag(tag);
+//		xs << xml::CR();
+		xs << XMLStream::ESCAPE_NONE << "<!-- abs -->";
 		xs << XMLStream::ESCAPE_NONE << abstract;
-		xs << xml::EndTag(tag);
-		xs << xml::CR();
+		xs << XMLStream::ESCAPE_NONE << "<!-- /abs -->";
+//		xs << xml::EndTag(tag);
+//		xs << xml::CR();
 	}
 
 	// End the <info> tag if it was started.
@@ -1057,23 +1126,14 @@ void docbookFirstParagraphs(
 }
 
 
-bool isParagraphEmpty(const Paragraph &par)
-{
-	InsetList const &insets = par.insetList();
-	size_t insetsLength = distance(insets.begin(), insets.end());
-	bool hasParagraphOnlyNote = insetsLength == 1 && insets.get(0) && insets.get(0)->asInsetCollapsible() &&
-								dynamic_cast<InsetNote *>(insets.get(0));
-	return hasParagraphOnlyNote;
-}
-
-
 void docbookSimpleAllParagraphs(
 		Text const & text,
 		Buffer const & buf,
 		XMLStream & xs,
 		OutputParams const & runparams)
 {
-	// Handle the document, supposing it has no sections (i.e. a "simple" document).
+	// Handle the given text, supposing it has no sections (i.e. a "simple" text). The input may vary in length
+	// between a single paragraph to a whole document.
 
 	// First, the <info> tag.
 	ParagraphList const &paragraphs = text.paragraphs();
@@ -1081,27 +1141,14 @@ void docbookSimpleAllParagraphs(
 	pit_type const epit = runparams.par_end;
 	DocBookInfoTag info = getParagraphsWithInfo(paragraphs, bpit, epit);
 	outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
-	bpit = info.bpit;
-
-	// Then, the content.
-	ParagraphList::const_iterator const pend =
-			(epit == (int) paragraphs.size()) ?
-			paragraphs.end() : paragraphs.iterator_at(epit);
 
+	// Then, the content. It starts where the <info> ends.
+	bpit = info.epit;
 	while (bpit < epit) {
 		auto par = paragraphs.iterator_at(bpit);
-		ParagraphList::const_iterator const lastStartedPar = par;
-		ParagraphList::const_iterator send;
-
-		if (isParagraphEmpty(*par)) {
-			++par;
-			bpit += distance(lastStartedPar, par);
-			continue;
-		}
-
-		// Generate this paragraph.
-		tie(par, send) = makeAny(text, buf, xs, runparams, par, send, pend);
-		bpit += distance(lastStartedPar, par);
+		if (!hasOnlyNotes(*par))
+			makeAnySimple(text, buf, xs, runparams, par);
+		bpit += 1;
 	}
 }
 
@@ -1155,7 +1202,7 @@ void docbookParagraphs(Text const &text,
 		ParagraphList::const_iterator const lastStartedPar = par;
 		ParagraphList::const_iterator send;
 
-		if (isParagraphEmpty(*par)) {
+		if (hasOnlyNotes(*par)) {
 			++par;
 			bpit += distance(lastStartedPar, par);
 			continue;
@@ -1250,4 +1297,4 @@ void docbookParagraphs(Text const &text,
 	}
 }
 
-} // namespace lyx
+} // namespace lyx
\ No newline at end of file
diff --git a/src/xml.h b/src/xml.h
index b585a48..e63623c 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -18,6 +18,8 @@
 #include <deque>
 #include <memory>
 
+#include <iostream>
+
 namespace lyx {
 
 class Buffer;

commit 95448e0403aa79d37164a9aa8f1771476d4721ce
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 2 20:43:39 2020 +0200

    DocBook: simplify code to handle abstracts.

diff --git a/autotests/export/docbook/bibliography_precooked_aastex.xml b/autotests/export/docbook/bibliography_precooked_aastex.xml
index 2c9f5bd..e15bfdd 100644
--- a/autotests/export/docbook/bibliography_precooked_aastex.xml
+++ b/autotests/export/docbook/bibliography_precooked_aastex.xml
@@ -19,8 +19,10 @@
 <affiliation role="alternate"><orgname>Patron, Alonso's Bar and Grill</orgname></affiliation></author>
 <abstract><para>
 <para>This is a preliminary report on surface photometry of the major fraction of known globular clusters, to see which of them show the signs of a collapsed core. We also explore some diversionary mathematics and recreational tables. </para>
-<!-- Output Error: Tried to close `Keywords' when tag was not open. Tag discarded. -->
+<!-- Output Error: Tried to close `keyword' when tag was not open. Tag discarded. -->
+<!-- Output Error: Tried to close `keywordset' when tag was not open. Tag discarded. -->
 
+<keywordset><keyword>clusters: globular, peanut—bosons: bozos</keyword></keywordset>
 <!-- Output Error: Closing tag `info' when other tags are open, namely: -->
 <!-- Output Error: para -->
 </para><!-- Output Error: abstract -->
diff --git a/lib/layouts/aastex.layout b/lib/layouts/aastex.layout
index 445d25f..97c8b64 100644
--- a/lib/layouts/aastex.layout
+++ b/lib/layouts/aastex.layout
@@ -282,6 +282,9 @@ Style Abstract
 	  Series	Bold
 	  Size		Normal
 	EndFont
+	DocBookTag            abstract
+	DocBookItemTag        para
+	DocBookInInfo         always
 End
 
 
@@ -331,6 +334,9 @@ Style Keywords
 	  Shape		Italic
 	  Size		Normal
 	EndFont
+	DocBookTag          keyword
+	DocBookWrapperTag   keywordset
+	DocBookInInfo       always
 End
 
 
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index d0536ee..fd38940 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -50,7 +50,7 @@ namespace lyx {
 
 namespace {
 
-std::string const fontToDocBookTag(xml::FontTypes type)
+std::string fontToDocBookTag(xml::FontTypes type)
 {
 	switch (type) {
 	case xml::FontTypes::FT_EMPH:
@@ -90,6 +90,7 @@ std::string const fontToDocBookTag(xml::FontTypes type)
 	}
 }
 
+
 string fontToRole(xml::FontTypes type)
 {
 	// Specific fonts are achieved with roles. The only common ones are "" for basic emphasis,
@@ -103,14 +104,13 @@ string fontToRole(xml::FontTypes type)
 		return "";
 	case xml::FontTypes::FT_BOLD:
 		return "bold";
-	case xml::FontTypes::FT_NOUN:
-		return ""; // Outputs a <person>
-	case xml::FontTypes::FT_TYPE:
-		return ""; // Outputs a <code>
+	case xml::FontTypes::FT_NOUN: // Outputs a <person>
+	case xml::FontTypes::FT_TYPE: // Outputs a <code>
+		return "";
 	case xml::FontTypes::FT_UBAR:
 		return "underline";
 
-		// All other roles are non-standard for DocBook.
+	// All other roles are non-standard for DocBook.
 
 	case xml::FontTypes::FT_WAVE:
 		return "wave";
@@ -814,7 +814,21 @@ pair<ParagraphList::const_iterator, ParagraphList::const_iterator> makeAny(
 
 
 using DocBookDocumentSectioning = tuple<bool, pit_type>;
-using DocBookInfoTag = tuple<set<pit_type>, set<pit_type>, pit_type, pit_type>;
+
+
+struct DocBookInfoTag
+{
+	const set<pit_type> shouldBeInInfo;
+	const set<pit_type> mustBeInInfo;
+	const set<pit_type> abstract;
+	pit_type bpit;
+	pit_type epit;
+
+	DocBookInfoTag(const set<pit_type> & shouldBeInInfo, const set<pit_type> & mustBeInInfo,
+				   const set<pit_type> & abstract, pit_type bpit, pit_type epit) :
+				   shouldBeInInfo(shouldBeInInfo), mustBeInInfo(mustBeInInfo), abstract(abstract),
+				   bpit(bpit), epit(epit) {}
+};
 
 
 DocBookDocumentSectioning hasDocumentSectioning(ParagraphList const &paragraphs, pit_type bpit, pit_type const epit) {
@@ -847,6 +861,7 @@ bool hasOnlyNotes(Paragraph const & par)
 DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs, pit_type bpit, pit_type const epit) {
 	set<pit_type> shouldBeInInfo;
 	set<pit_type> mustBeInInfo;
+	set<pit_type> abstract;
 
 	// Find the first non empty paragraph by mutating bpit.
 	while (bpit < epit) {
@@ -859,14 +874,18 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs, pit_type b
 
 	// Find the last info-like paragraph.
 	pit_type cpit = bpit;
+	bool hasAbstractLayout = false;
 	while (cpit < epit) {
 		// Skip paragraphs only containing one note.
-		Paragraph const &par = paragraphs[cpit];
+		Paragraph const & par = paragraphs[cpit];
 		if (hasOnlyNotes(par)) {
 			cpit += 1;
 			continue;
 		}
 
+		if (par.layout().name() == from_ascii("Abstract"))
+			hasAbstractLayout = true;
+
 		// Based on layout information, store this paragraph in one set: should be in <info>, must be.
 		Layout const &style = par.layout();
 
@@ -876,42 +895,55 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs, pit_type b
 			shouldBeInInfo.emplace(cpit);
 		} else {
 			// Hypothesis: the <info> parts should be grouped together near the beginning bpit.
+			// There may be notes in between, but nothing else.
 			break;
 		}
 		cpit += 1;
 	}
 	// Now, cpit points to the last paragraph that has things that could go in <info>.
-	// bpit is still the beginning of the <info> part.
-
-	return make_tuple(shouldBeInInfo, mustBeInInfo, bpit, cpit);
-}
-
-
-bool hasAbstractBetween(ParagraphList const &paragraphs, pit_type const bpitAbstract, pit_type const epitAbstract)
-{
-	// Hypothesis: the paragraphs between bpitAbstract and epitAbstract can be considered an abstract because they
-	// are just after a document or part title.
-	if (epitAbstract - bpitAbstract <= 0)
-		return false;
-
-	// If there is something between these paragraphs, check if it's compatible with an abstract (i.e. some text).
-	pit_type bpit = bpitAbstract;
-	while (bpit < epitAbstract) {
-		const Paragraph &p = paragraphs.at(bpit);
-
-		if (p.layout().name() == from_ascii("Abstract"))
-			return true;
+	// bpit is the beginning of the <info> part.
+
+	// Go once again through the list of paragraphs to find the abstract. If there is an abstract
+	// layout, only consider it. Otherwise, an abstract is just a sequence of paragraphs with text.
+	if (hasAbstractLayout) {
+		pit_type pit = bpit;
+		while (pit < cpit) { // Don't overshoot the <info> part.
+			if (paragraphs[pit].layout().name() == from_ascii("Abstract"))
+				abstract.emplace(pit);
+			pit++;
+		}
+	} else {
+		pit_type lastAbstract = epit + 1; // A nonsensical value.
+		docstring lastAbstractLayout;
+
+		pit_type pit = bpit;
+		while (pit < cpit) { // Don't overshoot the <info> part.
+			const Paragraph & par = paragraphs.at(pit);
+			if (!par.insetList().empty()) {
+				for (const auto &i : par.insetList()) {
+					if (i.inset->getText(0) != nullptr) {
+						if (lastAbstract == epit + 1) {
+							// First paragraph that matches the heuristic definition of abstract.
+							lastAbstract = pit;
+							lastAbstractLayout = par.layout().name();
+						} else if (pit > lastAbstract + 1 || par.layout().name() != lastAbstractLayout) {
+							// This is either too far from the last abstract paragraph or doesn't
+							// have the right layout name, BUT there has already been an abstract
+							// in this document: done with detecting the abstract.
+							goto done; // Easier to get out of two nested loops.
+						}
 
-		if (!p.insetList().empty()) {
-			for (const auto &i : p.insetList()) {
-				if (i.inset->getText(0) != nullptr) {
-					return true;
+						abstract.emplace(pit);
+						break;
+					}
 				}
 			}
+			pit++;
 		}
-		bpit++;
 	}
-	return false;
+
+	done:
+	return DocBookInfoTag(shouldBeInInfo, mustBeInInfo, abstract, bpit, cpit);
 }
 
 
@@ -947,26 +979,18 @@ void outputDocBookInfo(
 		XMLStream & xs,
 		OutputParams const & runparams,
 		ParagraphList const & paragraphs,
-		DocBookInfoTag const & info,
-		pit_type bpitAbstract,
-		pit_type const epitAbstract)
+		DocBookInfoTag const & info)
 {
-	// Consider everything between bpitAbstract and epitAbstract (excluded) as paragraphs for the abstract.
-	// Use bpitAbstract >= epitAbstract to indicate there is no abstract.
-
-	set<pit_type> shouldBeInInfo;
-	set<pit_type> mustBeInInfo;
-	pit_type bpitInfo;
-	pit_type epitInfo;
-	tie(shouldBeInInfo, mustBeInInfo, bpitInfo, epitInfo) = info;
-
 	// Perform an additional check on the abstract. Sometimes, there are many paragraphs that should go
 	// into the abstract, but none generates actual content. Thus, first generate to a temporary stream,
 	// then only create the <abstract> tag if these paragraphs generate some content.
 	// This check must be performed *before* a decision on whether or not to output <info> is made.
-	bool hasAbstract = hasAbstractBetween(paragraphs, bpitAbstract, epitAbstract);
+	bool hasAbstract = !info.abstract.empty();
 	docstring abstract;
 	if (hasAbstract) {
+		pit_type bpitAbstract = *std::min_element(info.abstract.begin(), info.abstract.end());
+		pit_type epitAbstract = *std::max_element(info.abstract.begin(), info.abstract.end());
+
 		odocstringstream os2;
 		XMLStream xs2(os2);
 		generateDocBookParagraphWithoutSectioning(text, buf, xs2, runparams, paragraphs, bpitAbstract, epitAbstract);
@@ -983,7 +1007,7 @@ void outputDocBookInfo(
 	}
 
 	// The abstract must go in <info>.
-	bool needInfo = !mustBeInInfo.empty() || hasAbstract;
+	bool needInfo = !info.mustBeInInfo.empty() || hasAbstract;
 
 	// Start the <info> tag if required.
 	if (needInfo) {
@@ -993,10 +1017,10 @@ void outputDocBookInfo(
 	}
 
 	// Output the elements that should go in <info>.
-	generateDocBookParagraphWithoutSectioning(text, buf, xs, runparams, paragraphs, bpitInfo, epitInfo);
+	generateDocBookParagraphWithoutSectioning(text, buf, xs, runparams, paragraphs, info.bpit, info.epit);
 
 	if (hasAbstract && !abstract.empty()) { // The second test is probably superfluous.
-		string tag = paragraphs[bpitAbstract].layout().docbookforceabstracttag();
+		string tag = paragraphs[*info.abstract.begin()].layout().docbookforceabstracttag();
 		if (tag == "NONE")
 			tag = "abstract";
 
@@ -1029,7 +1053,7 @@ void docbookFirstParagraphs(
 	ParagraphList const &paragraphs = text.paragraphs();
 	pit_type bpit = runparams.par_begin;
 	DocBookInfoTag info = getParagraphsWithInfo(paragraphs, bpit, epit);
-	outputDocBookInfo(text, buf, xs, runparams, paragraphs, info, get<3>(info), epit);
+	outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
 }
 
 
@@ -1056,8 +1080,8 @@ void docbookSimpleAllParagraphs(
 	pit_type bpit = runparams.par_begin;
 	pit_type const epit = runparams.par_end;
 	DocBookInfoTag info = getParagraphsWithInfo(paragraphs, bpit, epit);
-	outputDocBookInfo(text, buf, xs, runparams, paragraphs, info, 0, 0);
-	bpit = get<3>(info); // Generate the content starting from the end of the <info> part.
+	outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
+	bpit = info.bpit;
 
 	// Then, the content.
 	ParagraphList::const_iterator const pend =

commit b526905159362c7875372cd360df32d0e39797c2
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 2 18:58:36 2020 +0200

    DocBook: use DocBookWrapperMergeWithPrevious in the code.

diff --git a/autotests/export/docbook/bibliography_precooked_aastex.xml b/autotests/export/docbook/bibliography_precooked_aastex.xml
index b663868..2c9f5bd 100644
--- a/autotests/export/docbook/bibliography_precooked_aastex.xml
+++ b/autotests/export/docbook/bibliography_precooked_aastex.xml
@@ -4,23 +4,27 @@
 <article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
 <info>
 <title>Collapsed Cores in Globular Clusters,  Gauge-Boson Couplings, and AASTeX Examples</title>
-<author><personname>S. Djorgovski and Ivan R. King</personname></author>
-<author><affiliation><orgname>Astronomy Department, University of California, Berkeley, CA 94720</orgname></affiliation></author>
-<author><affiliation role="alternate"><orgname>Visiting Astronomer Cerro Tololo Inter-American Observatory.CTIO is operated by AURA Inc. under contract to the National Science Foundation.</orgname></affiliation></author>
-<author><affiliation role="alternate"><orgname>Society of Fellows, Harvard University.</orgname></affiliation></author>
-<author><affiliation role="alternate"><orgname>present address: Center for Astrophysics60 Garden Street, Cambridge, MA 02138</orgname></affiliation></author>
-<author><personname>C. D. Biemesderfer</personname></author>
-<author><affiliation><orgname>National Optical Astronomy Observatories, Tucson, AZ 85719</orgname></affiliation></author>
-<author><affiliation role="alternate"><orgname>Visiting Programmer, Space Telescope Science Institute</orgname></affiliation></author>
-<author><affiliation role="alternate"><orgname>Patron, Alonso's Bar and Grill</orgname></affiliation></author>
-<author><email>aastex-help at aas.org</email></author>
-<author><personname>R. J. Hanisch</personname></author>
-<author><affiliation><orgname>Space Telescope Science Institute, Baltimore, MD 21218</orgname></affiliation></author>
-<author><affiliation role="alternate"><orgname>Patron, Alonso's Bar and Grill</orgname></affiliation></author>
+<author><personname>S. Djorgovski and Ivan R. King</personname>
+<affiliation><orgname>Astronomy Department, University of California, Berkeley, CA 94720</orgname></affiliation>
+<affiliation role="alternate"><orgname>Visiting Astronomer Cerro Tololo Inter-American Observatory.CTIO is operated by AURA Inc. under contract to the National Science Foundation.</orgname></affiliation>
+<affiliation role="alternate"><orgname>Society of Fellows, Harvard University.</orgname></affiliation>
+<affiliation role="alternate"><orgname>present address: Center for Astrophysics60 Garden Street, Cambridge, MA 02138</orgname></affiliation></author>
+<author><personname>C. D. Biemesderfer</personname>
+<affiliation><orgname>National Optical Astronomy Observatories, Tucson, AZ 85719</orgname></affiliation>
+<affiliation role="alternate"><orgname>Visiting Programmer, Space Telescope Science Institute</orgname></affiliation>
+<affiliation role="alternate"><orgname>Patron, Alonso's Bar and Grill</orgname></affiliation>
+<email>aastex-help at aas.org</email></author>
+<author><personname>R. J. Hanisch</personname>
+<affiliation><orgname>Space Telescope Science Institute, Baltimore, MD 21218</orgname></affiliation>
+<affiliation role="alternate"><orgname>Patron, Alonso's Bar and Grill</orgname></affiliation></author>
 <abstract><para>
 <para>This is a preliminary report on surface photometry of the major fraction of known globular clusters, to see which of them show the signs of a collapsed core. We also explore some diversionary mathematics and recreational tables. </para>
-</para></abstract>
-</info>
+<!-- Output Error: Tried to close `Keywords' when tag was not open. Tag discarded. -->
+
+<!-- Output Error: Closing tag `info' when other tags are open, namely: -->
+<!-- Output Error: para -->
+</para><!-- Output Error: abstract -->
+</abstract></info>
 <section>
 <title>Introduction</title>
 <para>A focal problem today in the dynamics of globular clusters is core collapse. It has been predicted by theory for decades <biblioref endterm="hen61" />, <biblioref endterm="lyn68" />, <biblioref endterm="spi85" />, but observation has been less alert to the phenomenon. For many years the central brightness peak in M15 <biblioref endterm="kin75" />, <biblioref endterm="new78" /> seemed a unique anomaly. Then <biblioref endterm="aur82" /> suggested a central peak in NGC 6397, and a limited photographic survey of ours <biblioref endterm="djo84" /> found three more cases, including NGC 6624, whose sharp center had often been remarked on <biblioref endterm="can78" />. </para>
@@ -688,7 +692,8 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mtable>
  </m:math>
 </informalequation>
-</MathLetters>
+<!-- Output Error: Tried to close `title' when tag was not open. Tag discarded. -->
+
 </section>
 </section>
 <section>
@@ -964,8 +969,9 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi
  </m:mrow>
  </m:math>
 </inlineequation> of the electronically submitted abstracts for AAS meetings are error-free. </para>
-<acknowledgement><para>We are grateful to V. Barger, T. Han, and R. J. N. Phillips for doing the math in section&#xA0;<xref linkend="bozomath" />. More information on the AASTeX macros package are available at <link xlink:href="http://www.aas.org/publications/aastex">http://www.aas.org/publications/aastex</link> or the <link xlink:href="ftp://www.aas.org/pubs/AAS ftp site">AAS ftp site</link>.</para></acknowledgement>
-<para><application>IRAF, AIPS, Astropy, ...</application></para>
+<acknowledgement><para>We are grateful to V. Barger, T. Han, and R. J. N. Phillips for doing the math in section&#xA0;<xref linkend="bozomath" />. More information on the AASTeX macros package are available at <link xlink:href="http://www.aas.org/publications/aastex">http://www.aas.org/publications/aastex</link> or the <link xlink:href="ftp://www.aas.org/pubs/AAS ftp site">AAS ftp site</link>.</para>
+<application>IRAF, AIPS, Astropy, ...</application><!-- Output Error: Tried to close `para' when tag was not open. Tag discarded. -->
+
 <Appendix></Appendix>
 <bibliography>
 <bibliomixed xml:id='aur82'>Aurière, M. 1982, <!-- \aap -->, 109, 301 </bibliomixed>
diff --git a/lib/layouts/aastex.layout b/lib/layouts/aastex.layout
index 5db7dee..445d25f 100644
--- a/lib/layouts/aastex.layout
+++ b/lib/layouts/aastex.layout
@@ -175,10 +175,11 @@ Style Affiliation
 	  Family	Roman
 	  Size		Normal
 	EndFont
-	DocBookTag            affiliation
-	DocBookWrapperTag     author
-	DocBookItemTag        orgname
-	DocBookInInfo         always
+	DocBookTag                        affiliation
+	DocBookWrapperTag                 author
+	DocBookWrapperMergeWithPrevious   true
+	DocBookItemTag                    orgname
+	DocBookInInfo                     always
 End
 
 
@@ -201,11 +202,12 @@ Style Altaffilation
 	LabelFont
 	  Color		green
 	EndFont
-	DocBookTag            affiliation
-	DocBookAttr           role="alternate"
-	DocBookItemTag        orgname
-	DocBookWrapperTag     author
-	DocBookInInfo         always
+	DocBookTag                        affiliation
+	DocBookAttr                       role="alternate"
+	DocBookWrapperTag                 author
+	DocBookWrapperMergeWithPrevious   true
+	DocBookItemTag                    orgname
+	DocBookInInfo                     always
 End
 
 
@@ -225,9 +227,10 @@ Style Email
 	  Size		Normal
 	  Shape		Italic
 	EndFont
-	DocBookTag            email
-	DocBookWrapperTag     author
-	DocBookInInfo         always
+	DocBookTag                        email
+	DocBookWrapperTag                 author
+	DocBookWrapperMergeWithPrevious   true
+	DocBookInInfo                     always
 End
 
 
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index a081b2d..d0536ee 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -189,11 +189,30 @@ namespace {
 
 // convenience functions
 
-void openParTag(XMLStream & xs, Paragraph const & par)
+void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar)
 {
-	Layout const & lay = par.layout();
+	Layout const & lay = par->layout();
+
+	if (par == prevpar)
+		prevpar = nullptr;
+
+	// When should the wrapper be opened here? Only if the previous paragraph has the SAME wrapper tag
+	// (usually, they won't have the same layout) and the CURRENT one allows merging.
+	// The main use case is author information in several paragraphs: if the name of the author is the
+	// first paragraph of an author, then merging with the previous tag does not make sense. Say the
+	// next paragraph is the affiliation, then it should be output in the same <author> tag (different
+	// layout, same wrapper tag).
+	bool openWrapper = lay.docbookwrappertag() != "NONE";
+	if (prevpar != nullptr) {
+		Layout const & prevlay = prevpar->layout();
+		if (prevlay.docbookwrappertag() != "NONE") {
+			openWrapper = prevlay.docbookwrappertag() == lay.docbookwrappertag()
+					&& !lay.docbookwrappermergewithprevious();
+		}
+	}
 
-	if (lay.docbookwrappertag() != "NONE")
+	// Main logic.
+	if (openWrapper)
 		xs << xml::StartTag(lay.docbookwrappertag(), lay.docbookwrapperattr());
 
 	string tag = lay.docbooktag();
@@ -207,10 +226,24 @@ void openParTag(XMLStream & xs, Paragraph const & par)
 }
 
 
-void closeTag(XMLStream & xs, Paragraph const & par)
+void closeTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpar)
 {
-	Layout const & lay = par.layout();
+	Layout const & lay = par->layout();
+
+	if (par == nextpar)
+		nextpar = nullptr;
+
+	// See comment in openParTag.
+	bool closeWrapper = lay.docbookwrappertag() != "NONE";
+	if (nextpar != nullptr) {
+		Layout const & nextlay = nextpar->layout();
+		if (nextlay.docbookwrappertag() != "NONE") {
+			closeWrapper = nextlay.docbookwrappertag() == lay.docbookwrappertag()
+					&& !nextlay.docbookwrappermergewithprevious();
+		}
+	}
 
+	// Main logic.
 	if (lay.docbookitemtag() != "NONE")
 		xs << xml::EndTag(lay.docbookitemtag());
 
@@ -219,7 +252,7 @@ void closeTag(XMLStream & xs, Paragraph const & par)
 		tag = "para";
 
 	xs << xml::EndTag(tag);
-	if (lay.docbookwrappertag() != "NONE")
+	if (closeWrapper)
 		xs << xml::EndTag(lay.docbookwrappertag());
 }
 
@@ -399,9 +432,12 @@ ParagraphList::const_iterator makeParagraphs(
 		ParagraphList::const_iterator const & pbegin,
 		ParagraphList::const_iterator const & pend)
 {
-	ParagraphList::const_iterator const begin = text.paragraphs().begin();
+	auto const begin = text.paragraphs().begin();
+	auto const end = text.paragraphs().end();
 	ParagraphList::const_iterator par = pbegin;
-	for (; par != pend; ++par) {
+	ParagraphList::const_iterator prevpar = pbegin;
+
+	for (; par != pend; prevpar = par, ++par) {
 		// We want to open the paragraph tag if:
 		//   (i) the current layout permits multiple paragraphs
 		//  (ii) we are either not already inside a paragraph (HTMLIsBlock) OR
@@ -417,7 +453,7 @@ ParagraphList::const_iterator makeParagraphs(
 		// because of branches, e.g., a branch that contains an entire new section.
 		// We do not really want to wrap that whole thing in a <div>...</div>.
 		bool special_case = false;
-		Inset const *specinset = par->size() == 1 ? par->getInset(0) : 0;
+		Inset const *specinset = par->size() == 1 ? par->getInset(0) : nullptr;
 		if (specinset && !specinset->getLayout().htmlisblock()) { // TODO: Convert htmlisblock to a DocBook parameter?
 			Layout const &style = par->layout();
 			FontInfo const first_font = style.labeltype == LABEL_MANUAL ?
@@ -466,7 +502,7 @@ ParagraphList::const_iterator makeParagraphs(
 		//		or we're not in the last paragraph, anyway.
 		//   (ii) We didn't open it and docbook_in_par is true,
 		//		but we are in the first par, and there is a next par.
-		ParagraphList::const_iterator nextpar = par;
+		auto nextpar = par;
 		++nextpar;
 		bool const close_par =
 				((open_par && (!runparams.docbook_in_par || nextpar != pend))
@@ -484,12 +520,12 @@ ParagraphList::const_iterator makeParagraphs(
 
 		if (!cleaned.empty()) {
 			if (open_par)
-				openParTag(xs, *par);
+				openParTag(xs, &*par, &*prevpar);
 
 			xs << XMLStream::ESCAPE_NONE << os2.str();
 
 			if (close_par) {
-				closeTag(xs, *par);
+				closeTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr);
 				xs << xml::CR();
 			}
 		}
@@ -514,11 +550,24 @@ ParagraphList::const_iterator makeEnvironment(
 		ParagraphList::const_iterator const & pend)
 {
 	auto const begin = text.paragraphs().begin();
+	auto const end = text.paragraphs().end();
 	ParagraphList::const_iterator par = pbegin;
 	depth_type const origdepth = pbegin->params().depth();
 
+	// Find the previous paragraph.
+	auto prevpar = begin;
+	if (prevpar != par) {
+		auto prevpar_next = prevpar;
+		++prevpar_next;
+
+		while (prevpar_next != par) {
+			++prevpar_next;
+			++prevpar;
+		}
+	}
+
 	// open tag for this environment
-	openParTag(xs, *par);
+	openParTag(xs, &*par, &*prevpar);
 	xs << xml::CR();
 
 	// we will on occasion need to remember a layout from before.
@@ -672,7 +721,9 @@ ParagraphList::const_iterator makeEnvironment(
 			xs << xml::CR();
 		}
 	}
-	closeTag(xs, *par);
+	auto nextpar = par;
+	++nextpar;
+	closeTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr);
 	xs << xml::CR();
 	return pend;
 }
@@ -686,14 +737,30 @@ void makeCommand(
 		ParagraphList::const_iterator const & pbegin)
 {
 	// No need for labels, as they are handled by DocBook tags.
+	auto const begin = text.paragraphs().begin();
+	auto const end = text.paragraphs().end();
+	auto nextpar = pbegin;
+	++nextpar;
+
+	// Find the previous paragraph.
+	auto prevpar = begin;
+	if (prevpar != pbegin) {
+		auto prevpar_next = prevpar;
+		++prevpar_next;
+
+		while (prevpar_next != pbegin) {
+			++prevpar_next;
+			++prevpar;
+		}
+	}
 
-	openParTag(xs, *pbegin);
+	// Generate this command.
+	openParTag(xs, &*pbegin, &*prevpar);
 
-	auto const begin = text.paragraphs().begin();
 	pbegin->simpleDocBookOnePar(buf, xs, runparams,
 								text.outerFont(distance(begin, pbegin)));
 
-	closeTag(xs, *pbegin);
+	closeTag(xs, &*pbegin, (nextpar != end) ? &*nextpar : nullptr);
 	xs << xml::CR();
 }
 

commit 5c43790e54d4e7cab9a18f4e0e5a63d36b5dfc36
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 2 18:07:07 2020 +0200

    DocBook: fix for ordering.

diff --git a/src/Layout.cpp b/src/Layout.cpp
index a7e80ea..eeb58d0 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -235,8 +235,8 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 		{ "docbooksectiontag",       LT_DOCBOOKSECTIONTAG },
 		{ "docbooktag",              LT_DOCBOOKTAG },
 		{ "docbookwrapperattr",      LT_DOCBOOKWRAPPERATTR },
-		{ "docbookwrappertag",       LT_DOCBOOKWRAPPERTAG },
 		{ "docbookwrappermergewithprevious", LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS },
+		{ "docbookwrappertag",       LT_DOCBOOKWRAPPERTAG },
 		{ "end",            LT_END },
 		{ "endlabelstring", LT_ENDLABELSTRING },
 		{ "endlabeltype",   LT_ENDLABELTYPE },

commit d5c27037d5c8ae8597ea58e891754e908695fb1a
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 2 17:35:16 2020 +0200

    DocBook: make openParTag/closeTag use paragraphs instead of layouts.
    
    Not useful per se, but will be next with checking whether the wrapper tags should be opened/closed.

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 2e7b637..a081b2d 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -189,8 +189,10 @@ namespace {
 
 // convenience functions
 
-void openParTag(XMLStream & xs, Layout const & lay)
+void openParTag(XMLStream & xs, Paragraph const & par)
 {
+	Layout const & lay = par.layout();
+
 	if (lay.docbookwrappertag() != "NONE")
 		xs << xml::StartTag(lay.docbookwrappertag(), lay.docbookwrapperattr());
 
@@ -205,8 +207,10 @@ void openParTag(XMLStream & xs, Layout const & lay)
 }
 
 
-void closeTag(XMLStream & xs, Layout const & lay)
+void closeTag(XMLStream & xs, Paragraph const & par)
 {
+	Layout const & lay = par.layout();
+
 	if (lay.docbookitemtag() != "NONE")
 		xs << xml::EndTag(lay.docbookitemtag());
 
@@ -294,8 +298,8 @@ ParagraphList::const_iterator findEndOfEnvironment(
 		ParagraphList::const_iterator const & pend)
 {
 	ParagraphList::const_iterator p = pstart;
-	Layout const &bstyle = p->layout();
 	size_t const depth = p->params().depth();
+
 	for (++p; p != pend; ++p) {
 		Layout const &style = p->layout();
 		// It shouldn't happen that e.g. a section command occurs inside
@@ -315,9 +319,10 @@ ParagraphList::const_iterator findEndOfEnvironment(
 		// FIXME I am not sure about the first check.
 		// Surely we *could* have different layouts that count as
 		// LATEX_PARAGRAPH, right?
-		if (style.latextype == LATEX_PARAGRAPH || style != bstyle)
+		if (style.latextype == LATEX_PARAGRAPH || style != p->layout())
 			return p;
 	}
+
 	return pend;
 }
 
@@ -397,8 +402,6 @@ ParagraphList::const_iterator makeParagraphs(
 	ParagraphList::const_iterator const begin = text.paragraphs().begin();
 	ParagraphList::const_iterator par = pbegin;
 	for (; par != pend; ++par) {
-		Layout const &lay = par->layout();
-
 		// We want to open the paragraph tag if:
 		//   (i) the current layout permits multiple paragraphs
 		//  (ii) we are either not already inside a paragraph (HTMLIsBlock) OR
@@ -428,7 +431,7 @@ ParagraphList::const_iterator makeParagraphs(
 		}
 
 		// Plain layouts must be ignored.
-		if (!special_case && buf.params().documentClass().isPlainLayout(lay) && !runparams.docbook_force_pars)
+		if (!special_case && buf.params().documentClass().isPlainLayout(par->layout()) && !runparams.docbook_force_pars)
 			special_case = true;
 		// TODO: Could get rid of this with a DocBook equivalent to htmlisblock?
 		if (!special_case && par->size() == 1 && par->getInset(0)) {
@@ -481,12 +484,12 @@ ParagraphList::const_iterator makeParagraphs(
 
 		if (!cleaned.empty()) {
 			if (open_par)
-				openParTag(xs, lay);
+				openParTag(xs, *par);
 
 			xs << XMLStream::ESCAPE_NONE << os2.str();
 
 			if (close_par) {
-				closeTag(xs, lay);
+				closeTag(xs, *par);
 				xs << xml::CR();
 			}
 		}
@@ -510,13 +513,12 @@ ParagraphList::const_iterator makeEnvironment(
 		ParagraphList::const_iterator const & pbegin,
 		ParagraphList::const_iterator const & pend)
 {
-	ParagraphList::const_iterator const begin = text.paragraphs().begin();
+	auto const begin = text.paragraphs().begin();
 	ParagraphList::const_iterator par = pbegin;
-	Layout const &bstyle = par->layout();
 	depth_type const origdepth = pbegin->params().depth();
 
 	// open tag for this environment
-	openParTag(xs, bstyle);
+	openParTag(xs, *par);
 	xs << xml::CR();
 
 	// we will on occasion need to remember a layout from before.
@@ -535,7 +537,7 @@ ParagraphList::const_iterator makeEnvironment(
 			// One is that we are still in the environment in which we
 			// started---which we will be if the depth is the same.
 			if (par->params().depth() == origdepth) {
-				LATTEST(bstyle == style);
+				LATTEST(par->layout() == style);
 				if (lastlay != nullptr) {
 					closeItemTag(xs, *lastlay);
 					if (lastlay->docbookitemwrappertag() != "NONE") {
@@ -670,7 +672,7 @@ ParagraphList::const_iterator makeEnvironment(
 			xs << xml::CR();
 		}
 	}
-	closeTag(xs, bstyle);
+	closeTag(xs, *par);
 	xs << xml::CR();
 	return pend;
 }
@@ -683,16 +685,15 @@ void makeCommand(
 		Text const & text,
 		ParagraphList::const_iterator const & pbegin)
 {
-	Layout const &style = pbegin->layout();
-
 	// No need for labels, as they are handled by DocBook tags.
 
-	openParTag(xs, style);
+	openParTag(xs, *pbegin);
 
-	ParagraphList::const_iterator const begin = text.paragraphs().begin();
+	auto const begin = text.paragraphs().begin();
 	pbegin->simpleDocBookOnePar(buf, xs, runparams,
 								text.outerFont(distance(begin, pbegin)));
-	closeTag(xs, style);
+
+	closeTag(xs, *pbegin);
 	xs << xml::CR();
 }
 

commit d88222b6673cdaa54329ebc772720b86f4403056
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 2 17:28:50 2020 +0200

    DocBook: use DocBookItemTag within paragraphs.
    
    This is at least helpful for AAS, even though it slightly resembles a repurposition of that parameter.

diff --git a/autotests/export/docbook/bibliography_precooked_aastex.xml b/autotests/export/docbook/bibliography_precooked_aastex.xml
index 37dada8..b663868 100644
--- a/autotests/export/docbook/bibliography_precooked_aastex.xml
+++ b/autotests/export/docbook/bibliography_precooked_aastex.xml
@@ -5,21 +5,21 @@
 <info>
 <title>Collapsed Cores in Globular Clusters,  Gauge-Boson Couplings, and AASTeX Examples</title>
 <author><personname>S. Djorgovski and Ivan R. King</personname></author>
-<author><affiliation>Astronomy Department, University of California, Berkeley, CA 94720</affiliation></author>
-<author><affiliation role="alternate">Visiting Astronomer Cerro Tololo Inter-American Observatory.CTIO is operated by AURA Inc. under contract to the National Science Foundation.</affiliation></author>
-<author><affiliation role="alternate">Society of Fellows, Harvard University.</affiliation></author>
-<author><affiliation role="alternate">present address: Center for Astrophysics60 Garden Street, Cambridge, MA 02138</affiliation></author>
+<author><affiliation><orgname>Astronomy Department, University of California, Berkeley, CA 94720</orgname></affiliation></author>
+<author><affiliation role="alternate"><orgname>Visiting Astronomer Cerro Tololo Inter-American Observatory.CTIO is operated by AURA Inc. under contract to the National Science Foundation.</orgname></affiliation></author>
+<author><affiliation role="alternate"><orgname>Society of Fellows, Harvard University.</orgname></affiliation></author>
+<author><affiliation role="alternate"><orgname>present address: Center for Astrophysics60 Garden Street, Cambridge, MA 02138</orgname></affiliation></author>
 <author><personname>C. D. Biemesderfer</personname></author>
-<author><affiliation>National Optical Astronomy Observatories, Tucson, AZ 85719</affiliation></author>
-<author><affiliation role="alternate">Visiting Programmer, Space Telescope Science Institute</affiliation></author>
-<author><affiliation role="alternate">Patron, Alonso's Bar and Grill</affiliation></author>
+<author><affiliation><orgname>National Optical Astronomy Observatories, Tucson, AZ 85719</orgname></affiliation></author>
+<author><affiliation role="alternate"><orgname>Visiting Programmer, Space Telescope Science Institute</orgname></affiliation></author>
+<author><affiliation role="alternate"><orgname>Patron, Alonso's Bar and Grill</orgname></affiliation></author>
 <author><email>aastex-help at aas.org</email></author>
 <author><personname>R. J. Hanisch</personname></author>
-<author><affiliation>Space Telescope Science Institute, Baltimore, MD 21218</affiliation></author>
-<author><affiliation role="alternate">Patron, Alonso's Bar and Grill</affiliation></author>
-<abstract>
+<author><affiliation><orgname>Space Telescope Science Institute, Baltimore, MD 21218</orgname></affiliation></author>
+<author><affiliation role="alternate"><orgname>Patron, Alonso's Bar and Grill</orgname></affiliation></author>
+<abstract><para>
 <para>This is a preliminary report on surface photometry of the major fraction of known globular clusters, to see which of them show the signs of a collapsed core. We also explore some diversionary mathematics and recreational tables. </para>
-</abstract>
+</para></abstract>
 </info>
 <section>
 <title>Introduction</title>
diff --git a/lib/layouts/aastex.layout b/lib/layouts/aastex.layout
index 275018a..5db7dee 100644
--- a/lib/layouts/aastex.layout
+++ b/lib/layouts/aastex.layout
@@ -155,6 +155,9 @@ Style Author
 	  Series	Medium
 	  Shape		SmallCaps
 	EndFont
+	DocBookTag            personname
+	DocBookWrapperTag     author
+	DocBookInInfo         always
 End
 
 
@@ -172,6 +175,10 @@ Style Affiliation
 	  Family	Roman
 	  Size		Normal
 	EndFont
+	DocBookTag            affiliation
+	DocBookWrapperTag     author
+	DocBookItemTag        orgname
+	DocBookInInfo         always
 End
 
 
@@ -194,6 +201,11 @@ Style Altaffilation
 	LabelFont
 	  Color		green
 	EndFont
+	DocBookTag            affiliation
+	DocBookAttr           role="alternate"
+	DocBookItemTag        orgname
+	DocBookWrapperTag     author
+	DocBookInInfo         always
 End
 
 
@@ -213,6 +225,9 @@ Style Email
 	  Size		Normal
 	  Shape		Italic
 	EndFont
+	DocBookTag            email
+	DocBookWrapperTag     author
+	DocBookInInfo         always
 End
 
 
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 434148b..2e7b637 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -191,20 +191,25 @@ namespace {
 
 void openParTag(XMLStream & xs, Layout const & lay)
 {
-	if (lay.docbookwrappertag() != "NONE") {
+	if (lay.docbookwrappertag() != "NONE")
 		xs << xml::StartTag(lay.docbookwrappertag(), lay.docbookwrapperattr());
-	}
 
 	string tag = lay.docbooktag();
 	if (tag == "Plain Layout")
 		tag = "para";
 
 	xs << xml::ParTag(tag, lay.docbookattr());
+
+	if (lay.docbookitemtag() != "NONE")
+		xs << xml::StartTag(lay.docbookitemtag(), lay.docbookitemattr());
 }
 
 
 void closeTag(XMLStream & xs, Layout const & lay)
 {
+	if (lay.docbookitemtag() != "NONE")
+		xs << xml::EndTag(lay.docbookitemtag());
+
 	string tag = lay.docbooktag();
 	if (tag == "Plain Layout")
 		tag = "para";

commit c7044a444db50dc844b0b69ca1a6c49f295e71ac
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 2 17:23:37 2020 +0200

    Merge findLastParagraph and findLastBibliographyParagraph to lower code duplication.
    
    Maybe these functions should move to ParagraphList.h/cpp?

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 5b788f3..434148b 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -266,10 +266,11 @@ inline void closeItemTag(XMLStream & xs, Layout const & lay)
 
 // end of convenience functions
 
-ParagraphList::const_iterator findLastParagraph(
+ParagraphList::const_iterator findLast(
 		ParagraphList::const_iterator p,
-		ParagraphList::const_iterator const & pend) {
-	for (++p; p != pend && p->layout().latextype == LATEX_PARAGRAPH; ++p);
+		ParagraphList::const_iterator const & pend,
+		LatexType type) {
+	for (++p; p != pend && p->layout().latextype == type; ++p);
 
 	return p;
 }
@@ -644,11 +645,11 @@ ParagraphList::const_iterator makeEnvironment(
 			break;
 		}
 		case LATEX_PARAGRAPH:
-			send = findLastParagraph(par, pend);
+			send = findLast(par, pend, LATEX_PARAGRAPH);
 			par = makeParagraphs(buf, xs, runparams, text, par, send);
 			break;
 		case LATEX_BIB_ENVIRONMENT:
-			send = findLastBibliographyParagraph(par, pend);
+			send = findLast(par, pend, LATEX_BIB_ENVIRONMENT);
 			par = makeParagraphBibliography(buf, xs, runparams, text, par, send);
 			break;
 		case LATEX_COMMAND:
@@ -718,22 +719,19 @@ pair<ParagraphList::const_iterator, ParagraphList::const_iterator> makeAny(
 		}
 		case LATEX_ENVIRONMENT:
 		case LATEX_LIST_ENVIRONMENT:
-		case LATEX_ITEM_ENVIRONMENT: {
+		case LATEX_ITEM_ENVIRONMENT:
 			// FIXME Same fix here.
 			send = findEndOfEnvironment(par, pend);
 			par = makeEnvironment(buf, xs, ourparams, text, par, send);
 			break;
-		}
-		case LATEX_BIB_ENVIRONMENT: {
-			send = findLastBibliographyParagraph(par, pend);
-			par = makeParagraphBibliography(buf, xs, ourparams, text, par, send);
-			break;
-		}
-		case LATEX_PARAGRAPH: {
-			send = findLastParagraph(par, pend);
+		case LATEX_PARAGRAPH:
+			send = findLast(par, pend, LATEX_PARAGRAPH);
 			par = makeParagraphs(buf, xs, ourparams, text, par, send);
 			break;
-		}
+		case LATEX_BIB_ENVIRONMENT:
+			send = findLast(par, pend, LATEX_BIB_ENVIRONMENT);
+			par = makeParagraphBibliography(buf, xs, ourparams, text, par, send);
+			break;
 	}
 
 	return make_pair(par, send);

commit 2e94ad27152ff55bbaf8490d5b0e5795da778459
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 2 17:17:25 2020 +0200

    Slight code-consistency improvements.

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 2199239..5b788f3 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -189,7 +189,7 @@ namespace {
 
 // convenience functions
 
-void openParTag(XMLStream &xs, Layout const &lay)
+void openParTag(XMLStream & xs, Layout const & lay)
 {
 	if (lay.docbookwrappertag() != "NONE") {
 		xs << xml::StartTag(lay.docbookwrappertag(), lay.docbookwrapperattr());
@@ -203,7 +203,7 @@ void openParTag(XMLStream &xs, Layout const &lay)
 }
 
 
-void closeTag(XMLStream &xs, Layout const &lay)
+void closeTag(XMLStream & xs, Layout const & lay)
 {
 	string tag = lay.docbooktag();
 	if (tag == "Plain Layout")
@@ -228,14 +228,14 @@ void closeLabelTag(XMLStream & xs, Layout const & lay)
 }
 
 
-void openItemTag(XMLStream &xs, Layout const &lay)
+void openItemTag(XMLStream & xs, Layout const & lay)
 {
 	xs << xml::StartTag(lay.docbookitemtag(), lay.docbookitemattr());
 }
 
 
 // Return true when new elements are output in a paragraph, false otherwise.
-bool openInnerItemTag(XMLStream &xs, Layout const &lay)
+bool openInnerItemTag(XMLStream & xs, Layout const & lay)
 {
 	if (lay.docbookiteminnertag() != "NONE") {
 		xs << xml::CR();
@@ -249,7 +249,7 @@ bool openInnerItemTag(XMLStream &xs, Layout const &lay)
 }
 
 
-void closeInnerItemTag(XMLStream &xs, Layout const &lay)
+void closeInnerItemTag(XMLStream & xs, Layout const & lay)
 {
 	if (lay.docbookiteminnertag()!= "NONE") {
 		xs << xml::EndTag(lay.docbookiteminnertag());
@@ -258,7 +258,7 @@ void closeInnerItemTag(XMLStream &xs, Layout const &lay)
 }
 
 
-inline void closeItemTag(XMLStream &xs, Layout const &lay)
+inline void closeItemTag(XMLStream & xs, Layout const & lay)
 {
 	xs << xml::EndTag(lay.docbookitemtag());
 	xs << xml::CR();

commit 4d7565328706e5024b98a754c0096271f607f97a
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 2 17:07:38 2020 +0200

    DocBook: add new layout parameter DocBookWrapperMergeWithPrevious.

diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py
index 60d4593..e69deba 100644
--- a/lib/scripts/layout2layout.py
+++ b/lib/scripts/layout2layout.py
@@ -11,7 +11,7 @@
 # This script will update a .layout file to current format
 
 # The latest layout format is also defined in src/TextClass.cpp
-currentFormat = 82
+currentFormat = 83
 
 
 # Incremented to format 4, 6 April 2007, lasgouttes
@@ -281,6 +281,9 @@ currentFormat = 82
 # - Removed tag Header from ClassOptionsClassOptions
 # - Removed tag Element for flex insets
 
+# Incremented to format 83, 2 August 2020 by dourouc05
+# New tag DocBookWrapperMergeWithPrevious
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
diff --git a/src/Layout.cpp b/src/Layout.cpp
index c45fd5c..a7e80ea 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -109,6 +109,7 @@ enum LayoutTags {
 	LT_DOCBOOKININFO,
 	LT_DOCBOOKWRAPPERTAG,
 	LT_DOCBOOKWRAPPERATTR,
+	LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS,
 	LT_DOCBOOKSECTIONTAG,
 	LT_DOCBOOKITEMWRAPPERTAG,
 	LT_DOCBOOKITEMWRAPPERATTR,
@@ -176,6 +177,7 @@ Layout::Layout()
 	htmllabelfirst_ = false;
 	htmlforcecss_ = false;
 	htmltitle_ = false;
+	docbookwrappermergewithprevious_ = false;
 	spellcheck = true;
 	forcelocal = 0;
 	itemcommand_ = "item";
@@ -234,6 +236,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 		{ "docbooktag",              LT_DOCBOOKTAG },
 		{ "docbookwrapperattr",      LT_DOCBOOKWRAPPERATTR },
 		{ "docbookwrappertag",       LT_DOCBOOKWRAPPERTAG },
+		{ "docbookwrappermergewithprevious", LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS },
 		{ "end",            LT_END },
 		{ "endlabelstring", LT_ENDLABELSTRING },
 		{ "endlabeltype",   LT_ENDLABELTYPE },
@@ -743,6 +746,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 			lex >> docbookwrapperattr_;
 			break;
 
+		case LT_DOCBOOKWRAPPERMERGEWITHPREVIOUS:
+			lex >> docbookwrappermergewithprevious_;
+			break;
+
 		case LT_DOCBOOKSECTIONTAG:
 			lex >> docbooksectiontag_;
 			break;
@@ -1610,6 +1617,7 @@ void Layout::write(ostream & os) const
 		os << "\tDocBookItemWrapperTag " << docbookitemwrappertag_ << '\n';
 	if(!docbookitemwrapperattr_.empty())
 		os << "\tDocBookItemWrapperAttr " << docbookitemwrapperattr_ << '\n';
+	os << "\tDocBookItemWrapperMergeWithPrevious " << docbookwrappermergewithprevious_ << '\n';
 	if(!docbookitemlabeltag_.empty())
 		os << "\tDocBookItemLabelTag " << docbookitemlabeltag_ << '\n';
 	if(!docbookitemlabelattr_.empty())
diff --git a/src/Layout.h b/src/Layout.h
index 7e9409a..d9eb893 100644
--- a/src/Layout.h
+++ b/src/Layout.h
@@ -203,6 +203,8 @@ public:
 	///
 	std::string const & docbookwrapperattr() const;
 	///
+	bool docbookwrappermergewithprevious() const { return docbookwrappermergewithprevious_; }
+	///
 	std::string const & docbooksectiontag() const;
 	///
 	std::string const & docbookitemwrappertag() const;
@@ -512,6 +514,8 @@ private:
 	mutable std::string docbookwrappertag_;
 	/// Roles to add to docbookwrappertag_, if any (default: none).
 	mutable std::string docbookwrapperattr_;
+	/// Whether this wrapper tag may be merged with the previously opened wrapper tag.
+	bool docbookwrappermergewithprevious_;
 	/// Outer tag for this section, only if this layout represent a sectionning item, including chapters (default: section).
 	mutable std::string docbooksectiontag_;
 	/// Whether this tag must/can/can't go into an <info> tag (default: never, as it only makes sense for metadata).
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index eb92612..79cdabd 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -62,7 +62,7 @@ namespace lyx {
 // You should also run the development/tools/updatelayouts.py script,
 // to update the format of all of our layout files.
 //
-int const LAYOUT_FORMAT = 82; // dourouc05: DocBook additions.
+int const LAYOUT_FORMAT = 83; // tcuvelier: DocBookWrapperMergeWithPrevious.
 
 
 // Layout format for the current lyx file format. Controls which format is

commit 545fea70b77724e7d5081ae6f65eede5b3bb6ddb
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 2 16:52:33 2020 +0200

    DocBook: allow empty paragraphs before the <info> section.

diff --git a/autotests/export/docbook/bibliography_precooked_aastex.xml b/autotests/export/docbook/bibliography_precooked_aastex.xml
index 89b1714..37dada8 100644
--- a/autotests/export/docbook/bibliography_precooked_aastex.xml
+++ b/autotests/export/docbook/bibliography_precooked_aastex.xml
@@ -3,6 +3,23 @@
   See http://www.lyx.org/ for more information -->
 <article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
 <info>
+<title>Collapsed Cores in Globular Clusters,  Gauge-Boson Couplings, and AASTeX Examples</title>
+<author><personname>S. Djorgovski and Ivan R. King</personname></author>
+<author><affiliation>Astronomy Department, University of California, Berkeley, CA 94720</affiliation></author>
+<author><affiliation role="alternate">Visiting Astronomer Cerro Tololo Inter-American Observatory.CTIO is operated by AURA Inc. under contract to the National Science Foundation.</affiliation></author>
+<author><affiliation role="alternate">Society of Fellows, Harvard University.</affiliation></author>
+<author><affiliation role="alternate">present address: Center for Astrophysics60 Garden Street, Cambridge, MA 02138</affiliation></author>
+<author><personname>C. D. Biemesderfer</personname></author>
+<author><affiliation>National Optical Astronomy Observatories, Tucson, AZ 85719</affiliation></author>
+<author><affiliation role="alternate">Visiting Programmer, Space Telescope Science Institute</affiliation></author>
+<author><affiliation role="alternate">Patron, Alonso's Bar and Grill</affiliation></author>
+<author><email>aastex-help at aas.org</email></author>
+<author><personname>R. J. Hanisch</personname></author>
+<author><affiliation>Space Telescope Science Institute, Baltimore, MD 21218</affiliation></author>
+<author><affiliation role="alternate">Patron, Alonso's Bar and Grill</affiliation></author>
+<abstract>
+<para>This is a preliminary report on surface photometry of the major fraction of known globular clusters, to see which of them show the signs of a collapsed core. We also explore some diversionary mathematics and recreational tables. </para>
+</abstract>
 </info>
 <section>
 <title>Introduction</title>
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 5e15edc..2199239 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -764,15 +764,34 @@ DocBookDocumentSectioning hasDocumentSectioning(ParagraphList const &paragraphs,
 }
 
 
-DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs, pit_type const bpit, pit_type const epit) {
+bool hasOnlyNotes(Paragraph const & par)
+{
+	for (int i = 0; i < par.size(); ++i)
+		if (!par.isInset(i) || !dynamic_cast<InsetNote *>(par.insetList().get(i)))
+			return false;
+	return true;
+}
+
+
+DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs, pit_type bpit, pit_type const epit) {
 	set<pit_type> shouldBeInInfo;
 	set<pit_type> mustBeInInfo;
 
+	// Find the first non empty paragraph by mutating bpit.
+	while (bpit < epit) {
+		Paragraph const &par = paragraphs[bpit];
+		if (par.empty() || hasOnlyNotes(par))
+			bpit += 1;
+		else
+			break;
+	}
+
+	// Find the last info-like paragraph.
 	pit_type cpit = bpit;
 	while (cpit < epit) {
 		// Skip paragraphs only containing one note.
 		Paragraph const &par = paragraphs[cpit];
-		if (par.size() == 1 && dynamic_cast<InsetNote*>(paragraphs[cpit].insetList().get(0))) {
+		if (hasOnlyNotes(par)) {
 			cpit += 1;
 			continue;
 		}

commit 9d8ef32d137245faccc7307dac32b2bbbdba270d
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Wed Sep 2 15:05:20 2020 +0200

    Windows: fix in CMakeLists for warning flags.
    
    /Wp64 was used to debug 64-bit incompatibilities. /W4 is used for warnings.
    
    Don't enable /Wx to turn warnings into errors, as the dependencies won't build.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 62eff71..d3aa192 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1072,9 +1072,9 @@ if(MSVC)
 		# add here warnings which should be disabled /wdXXXX
 		set(MSVC_W_DISABLE "/wd4288 /wd4355 /wd4800 /wd4996 /wd4311 /wd4312 /wd4505 /wd4267 /wd4512 /wd4245 /wd4127 /wd4180 /wd4231")
 
-		set(CMAKE_CXX_FLAGS_DEBUG      "${CMAKE_CXX_FLAGS_DEBUG} /Wp64 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
-		set(CMAKE_CXX_FLAGS_RELEASE    "${CMAKE_CXX_FLAGS_RELEASE} /Wp64 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
-		set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Wp64 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
+		set(CMAKE_CXX_FLAGS_DEBUG      "${CMAKE_CXX_FLAGS_DEBUG} /W4 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
+		set(CMAKE_CXX_FLAGS_RELEASE    "${CMAKE_CXX_FLAGS_RELEASE} /W4 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
+		set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /W4 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
 
 	else()
 		set(CMAKE_CXX_WARNING_LEVEL 3 CACHE STRING "Warning level" FORCE)

commit 8039b34802c9e08809c02bb3682ac50439d97951
Author: Enrico Forestieri <forenr at lyx.org>
Date:   Tue Sep 1 12:12:55 2020 +0200

    Adjust debug output for fonts
    
    This restores the debug output as it was intended before the
    introduction of the LYXERR macro that was unconditionally outputing
    an end of line. This is how this output was appearing until lyx 1.5:
    
    Looking for font family cmr10 ... got: cmr10
     got it normal!
    
    instead of as it was since lyx 1.6 and until now:
    
    Looking for font family cmr10 ...
    got: cmr10
     got it
    normal!

diff --git a/src/frontends/qt/GuiFontLoader.cpp b/src/frontends/qt/GuiFontLoader.cpp
index 6f1de04..82dafbf 100644
--- a/src/frontends/qt/GuiFontLoader.cpp
+++ b/src/frontends/qt/GuiFontLoader.cpp
@@ -185,14 +185,14 @@ static bool isChosenFont(QFont & font, QString const & family,
 	// positions.
 	QFontInfo fi(font);
 
-	LYXERR(Debug::FONT, "got: " << fi.family());
+	LYXERR_NOPOS(Debug::FONT, "got: " << fi.family());
 
 	if (fi.family().contains(family)
 #if QT_VERSION >= 0x040800
 	    && (style.isEmpty() || fi.styleName().contains(style))
 #endif
 	    ) {
-		LYXERR(Debug::FONT, " got it ");
+		LYXERR_NOENDL(Debug::FONT, " got it ");
 		return true;
 	}
 
@@ -202,7 +202,7 @@ static bool isChosenFont(QFont & font, QString const & family,
 
 QFont symbolFont(QString const & family, bool * ok)
 {
-	LYXERR(Debug::FONT, "Looking for font family " << family << " ... ");
+	LYXERR_NOENDL(Debug::FONT, "Looking for font family " << family << " ... ");
 	QString upper = family;
 	upper[0] = family[0].toUpper();
 
@@ -212,26 +212,26 @@ QFont symbolFont(QString const & family, bool * ok)
 	font.setStyleName("LyX");
 
 	if (isChosenFont(font, family, "LyX")) {
-		LYXERR(Debug::FONT, "lyx!");
+		LYXERR_NOPOS(Debug::FONT, "lyx!");
 		*ok = true;
 		return font;
 	}
 
-	LYXERR(Debug::FONT, "Trying normal " << family << " ... ");
+	LYXERR_NOENDL(Debug::FONT, "Trying normal " << family << " ... ");
 	font.setStyleName(QString());
 #endif
 
 	if (isChosenFont(font, family, QString())) {
-		LYXERR(Debug::FONT, "normal!");
+		LYXERR_NOPOS(Debug::FONT, "normal!");
 		*ok = true;
 		return font;
 	}
 
-	LYXERR(Debug::FONT, "Trying " << upper << " ... ");
+	LYXERR_NOENDL(Debug::FONT, "Trying " << upper << " ... ");
 	font.setFamily(upper);
 
 	if (isChosenFont(font, upper, QString())) {
-		LYXERR(Debug::FONT, "upper!");
+		LYXERR_NOPOS(Debug::FONT, "upper!");
 		*ok = true;
 		return font;
 	}
@@ -240,17 +240,17 @@ QFont symbolFont(QString const & family, bool * ok)
 	// A simple setFamily() fails on Qt 2
 
 	QString const raw = rawName(family);
-	LYXERR(Debug::FONT, "Trying " << raw << " ... ");
+	LYXERR_NOENDL(Debug::FONT, "Trying " << raw << " ... ");
 	font.setRawName(raw);
 
 	if (isChosenFont(font, family, QString())) {
-		LYXERR(Debug::FONT, "raw version!");
+		LYXERR_NOPOS(Debug::FONT, "raw version!");
 		*ok = true;
 		return font;
 	}
 #endif
 
-	LYXERR(Debug::FONT, " FAILED :-(");
+	LYXERR_NOPOS(Debug::FONT, " FAILED :-(");
 	*ok = false;
 	return font;
 }
diff --git a/src/support/debug.h b/src/support/debug.h
index 10bb5a7..112b66a 100644
--- a/src/support/debug.h
+++ b/src/support/debug.h
@@ -229,6 +229,18 @@ extern LyXErr lyxerr;
 		else { lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); } \
 	} while (0)
 
+#define LYXERR_NOENDL(type, msg) \
+	do { \
+		if (!lyx::lyxerr.debugging(type)) {} \
+		else { lyx::lyxerr << CURRENT_POSITION << msg; } \
+	} while (0)
+
+#define LYXERR_NOPOS(type, msg) \
+	do { \
+		if (!lyx::lyxerr.debugging(type)) {} \
+		else { lyx::lyxerr << msg; lyx::lyxerr.endl(); } \
+	} while (0)
+
 #define LYXERR0(msg) \
 	do { \
 		lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \

commit 1ba785f2c6ed0c2dc70b4f046571c425d3eb3e49
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date:   Tue Sep 1 01:41:10 2020 -0400

    Localization

diff --git a/src/frontends/qt/GuiInclude.cpp b/src/frontends/qt/GuiInclude.cpp
index 5949d17..61a9a55 100644
--- a/src/frontends/qt/GuiInclude.cpp
+++ b/src/frontends/qt/GuiInclude.cpp
@@ -315,19 +315,19 @@ bool GuiInclude::isValid()
 	int const item = typeCO->currentIndex();
 	// Are we inputting or including a LyX file?
 	if (item != 0 && item != 1) {
-		okbutton->setText("OK");
+		okbutton->setText(qt_("OK"));
 		return true;
 	}
 	// Do we have a LyX filename?
 	if (!isLyXFileName(fromqstr(fname))) {
-		okbutton->setText("OK");
+		okbutton->setText(qt_("OK"));
 		return false;
 	}
 	string const bpath = buffer().filePath();
 	// Path might be relative to current Buffer, so make absolute
 	FileName const absfname = support::makeAbsPath(fromqstr(fname), bpath);
 	// Set OK button text according to whether file already exists
-	okbutton->setText(absfname.exists() ? "OK" : "Create");
+	okbutton->setText(absfname.exists() ? qt_("OK") : qt_("Create"));
 	// enable edit button iff file is open in some Buffer
 	editPB->setEnabled(theBufferList().getBuffer(absfname));
 	return true;

-----------------------------------------------------------------------

Summary of changes:
 CMakeLists.txt                                     |    6 +-
 .../export/docbook}/Linguistics.lyx                |   13 +-
 autotests/export/docbook/Linguistics.xml           |  339 ++++++++++++++++++++
 lib/layouts/linguistics.module                     |    8 +
 src/Floating.cpp                                   |   11 +-
 src/Floating.h                                     |    2 +-
 src/Paragraph.cpp                                  |    4 +-
 src/TextClass.cpp                                  |    2 +-
 src/frontends/qt/GuiFontLoader.cpp                 |   22 +-
 src/frontends/qt/GuiInclude.cpp                    |    6 +-
 src/insets/InsetNewline.cpp                        |    2 +-
 src/output_docbook.cpp                             |   24 ++-
 src/support/debug.h                                |   12 +
 13 files changed, 417 insertions(+), 34 deletions(-)
 copy {lib/examples/de/Modules => autotests/export/docbook}/Linguistics.lyx (99%)
 create mode 100644 autotests/export/docbook/Linguistics.xml


hooks/post-receive
-- 
Repository for new features


More information about the lyx-cvs mailing list