[LyX features/feature/docbook] DocBook: do a little something for shapepar.

Thibaut Cuvelier tcuvelier at lyx.org
Mon Aug 31 01:02:30 UTC 2020


The branch, feature/docbook, has been updated.
  discards  fb406a93296053fdcc5b4c8f3f089fa0d717566b (commit)
  discards  c4ae476c35eab0421a9e715a01c5be056b20e4cc (commit)
  discards  8f59c384b703daca6f6a10ce8611fe08cbcfccb1 (commit)
  discards  8eb316653848bb270d9aa1fa80d2e221320a8a42 (commit)
  discards  59b2f74c89ca8492ca88b9c1ef697888f4d0788b (commit)
  discards  a2fbd10077ceff7c46d1a4a42b41345135d8a938 (commit)
  discards  f05e96d312730a324e36f894392c4b490a2c5057 (commit)
  discards  a9e2203a9f7acfacf970c989096d1011e7fa1098 (commit)
  discards  864c1cb05db795d79415ce37f80c78c3ac41857b (commit)
  discards  8de9615087eafce2f13117716ce26e4296bc9f8c (commit)
  discards  7975aa61b5de5a29f9a9f82768775d808994ad01 (commit)
  discards  1f55f647c7cca9e17e6af817441726cfb83a5c10 (commit)
  discards  dbdcb4add4c8cbf036491051482c951f00793771 (commit)
  discards  2e41c63d058dcb2ab9d0912daa582ce2094e9124 (commit)
  discards  a92f1c3ac3de30fbcf0c3313346a26557441bd0e (commit)
  discards  628bfae0201e29749a3499b38664c62a1d7da31e (commit)
  discards  3cb5b492371f5b8029eae1a630f3ae811fbccad3 (commit)
  discards  61a0883ed6e24ea051db13fd459375c3fceca2cc (commit)
  discards  cc4667b87051cb88ef571dcbe7c6dccec715284e (commit)
  discards  c7452a539fa1ff5b7c9528e0cbb177e4aad2d1c4 (commit)
  discards  5b8ef9979399e30a2b5b77fec38c2cc2aa3f6153 (commit)
  discards  3ee2640978a7e4ae84455b92c8126fa9d95de3fa (commit)
  discards  ecf93ca5aaf9c087e98a168752855177d808f868 (commit)
  discards  67c1425cba16e55c20e710515691c980b0ac85de (commit)
  discards  a36ebdd3940a69f8dad26fa65b8cc6977624cb4b (commit)
  discards  932bb3fc61419dffa8e25254ebd94e791dca28d5 (commit)
  discards  a2ed7d2ce7eeeda4acb6af231242fd4e3f5f019b (commit)
  discards  2d02d355c16dfb69e58d81019404e88b7085f1fb (commit)
  discards  79950e1824899b711007f32764d21cb803ce4391 (commit)
  discards  7189e5ae41f3c0ddc7ff305b7aee7c882f928e58 (commit)
  discards  ff07a271d0e006e74952863dc8eb167992d4436f (commit)
  discards  d532c106db3b3cd547f143428b965955880522ce (commit)
  discards  ed5ea76328e519f506fa211e6ef8fd49c0cc521a (commit)
  discards  656911f2091957ea7af9fa3787b2df11392496e6 (commit)
  discards  e4a05340b43fa612545d56cfb61f9de207a93ed9 (commit)
  discards  9b98becacc2aec8a37d3904f422e8d35e37b1ade (commit)
  discards  b3a05370c94abf69e7213684dc1ea54a328b0175 (commit)
  discards  e433f1beecd074788c0207cc6e9a96f9b417193d (commit)
  discards  a6d42bca15aad0a52b46dabf0069d0604e8fdacd (commit)
  discards  1c864099d94251ae2b107a8c384de794f9155e38 (commit)
  discards  d2c2ac52bc21cedf2cfc69d147968b5f5634e68e (commit)
  discards  f2af5a1a6b79f18584fc2fc06e05c2ffc59eddfe (commit)
  discards  e878ca5007f06ee48a02035502b5e67424525c75 (commit)
  discards  3af0c7d9d2824ee8f8c2ac340048ac9786ccf506 (commit)
  discards  68a8b750b28fd77eda4d542a325654e5f607e6bc (commit)
  discards  0c464680ee879d867fb140c77a06f40587fd139d (commit)
  discards  49038b7193cf1687c8555be6248fe86334951ffd (commit)
  discards  547e8628db756e6056f34758cc567b7ecbe0396d (commit)
  discards  6b94286316deaec6a84189b952f9acddd61af795 (commit)
  discards  3ec500aa9113cccfc1365c3a0deb966504bcf1ee (commit)
  discards  e83cc36a395d9ee427e30bb8b0a9cb5242b0d395 (commit)
  discards  92a00a7cf5189339e306002f557bca36b889a164 (commit)
  discards  7c67c34dfd133b30f364420e87fc58dee9b6254e (commit)
  discards  94d363c385b6c8bd997d745bb033a08565bc57da (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 (fb406a93296053fdcc5b4c8f3f089fa0d717566b)
            \
             N -- N -- N (f46fb805129940e33faabbf8c280d3eb6b1ec199)

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 f46fb805129940e33faabbf8c280d3eb6b1ec199
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 42b502b71a5149e8c734e3fb74fd71531d69d059
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 ad6783fa26a43a31788a91c2f2ce259f6f800979
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 c0a856e..3c6a2e2 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -491,6 +491,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 4d5d8de9249d23742fd747ffd1bc7f2081bcf0c1
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 af38cf0..c0a856e 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -532,8 +532,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).
@@ -545,65 +556,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 {
@@ -611,8 +582,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 f2008679e3bb92b2302163ad38c17c9cb24611cb
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 ffd16d3..af38cf0 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -47,7 +47,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 1f0b126273a29899253d5e41d835f0ec83b1e019
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 b1d483a7fa3d83171f8901a4d5e7b873647ae6a8
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 e37d563..34fae75 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -1611,6 +1611,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 a0761c3ef54b38f8f2fb4d07b26910892cfa15af
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 e123dab225a3190ae46b78d209e3c16975afadae
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 58752bdf374ea4368ef1e0924455ad6874b1cb01
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 e8dc3af..23c477c 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -2408,13 +2408,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");
 	}
 
@@ -2429,6 +2427,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();
 
@@ -2475,6 +2477,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 f0a300cac68486a22debf0748ab8bb146d69db28
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 0e89381..67d6480 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3320,7 +3320,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;
@@ -3349,33 +3350,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()) {
@@ -3396,7 +3401,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 c0ad33e..ffd16d3 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -511,7 +511,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 ccdf257163d57d83b50b946ef052b847ffec18fc
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 a034e72..0e89381 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3319,7 +3319,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;
@@ -3396,7 +3397,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 5323e57..c0ad33e 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -502,8 +502,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
@@ -511,7 +509,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 7ae9f7760846a79dd5165d5a40a6f9642c2668ff
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 91c8bf3..a034e72 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3345,12 +3345,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 083596602e27649ac8b592e39bffb500cf56cd13
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 5f848a36e7f253822d87a2b3fa3468a8422f9d34
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 d84d2b36c104ed895a7e702aaf5917057cbf374b
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 af836da..5323e57 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -253,6 +253,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)
@@ -690,9 +709,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 7539fee8a397bf844dc4b32e1d4c93488b07e906
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 21c25e2..af836da 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -976,6 +976,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 d8ee569ab311d99fc2e1dd03d72e42e41682323e
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 5ee906f..21c25e2 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -272,8 +272,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;
 		}
 	}
 
@@ -306,8 +308,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;
 		}
 	}
 
@@ -946,8 +950,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 cd0eb6e26f65e3c018e03da87cd310ee0788df42
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 85c440f7860083ec26801afc987cf6595be12b66
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 e56ca3cc61f7a1f0d0bbb5d9aa5f42a6f66396dd
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 fc8a4b03ad0e5185461268c026a3179d4143ece4
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 f584b8b..5ee906f 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -391,12 +391,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");
@@ -1122,7 +1119,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 9b4e47ef285239994116cb711b9675114d6d2f3f
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 609f45c..f584b8b 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -819,7 +819,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;
 }
@@ -849,7 +849,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
@@ -867,14 +867,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;
@@ -991,17 +991,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);
@@ -1038,7 +1038,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;
 	}
@@ -1046,7 +1046,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;
@@ -1139,6 +1139,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 612c2c4b49757c325f19767819b8841f674b4f6a
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 375babb..609f45c 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -1069,18 +1069,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.
@@ -1109,11 +1109,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 21aaebbac906709b5391c29e3dce1c779abd41d3
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 419de20..375babb 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -771,21 +771,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) {}
 };
 
 
@@ -794,7 +801,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;
@@ -818,10 +825,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) {
@@ -832,78 +843,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
@@ -938,17 +919,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.
@@ -972,27 +945,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.
@@ -1004,23 +983,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,
@@ -1034,7 +996,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.
@@ -1069,20 +1031,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);
@@ -1100,8 +1066,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 08e39a521b396c5e1239d615d974d6eda19e39c7
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 27734cc337c92131f805e0b669528b23bcc3c5cc
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 62eff71..3dbf98b 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 b0a48f2..8914cfe 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 35c8a36..e8dc3af 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -2419,7 +2419,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 b7b74a3fa4ea7c640c352567de06dd31d07d525e
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 5ee6171..91c8bf3 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3336,7 +3336,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) {
@@ -3348,7 +3349,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 2cecba9..35c8a36 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -2410,10 +2410,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 6c61dc6..419de20 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -444,10 +444,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);
 
@@ -458,10 +464,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 7f37cd1ed8124894638c4ff9e084acfed6f1a816
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 0c5ae88df5ed2e3002e9e182ea08588675485f59
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 56809d1..6c61dc6 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -223,7 +223,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.
@@ -273,7 +273,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();
 		}
 	}
 
@@ -306,32 +306,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();
 		}
 	}
 
@@ -562,9 +538,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);
@@ -626,7 +600,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();
@@ -660,95 +633,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 ed9e3a162f812f8682d6b7222bafde6dd556f180
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 431079b..56809d1 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -368,12 +368,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(
@@ -662,7 +661,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();
 
@@ -749,6 +747,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;
 }
 
 
@@ -789,10 +789,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;
@@ -800,6 +802,8 @@ ParagraphList::const_iterator makeAny(Text const &text,
 		makeBibliography(text, buf, xs, runparams, par);
 		break;
 	}
+	++par;
+	return par;
 }
 
 
@@ -1206,7 +1210,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 f510a7a5e6189f491216859cc2092b751affeef8
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 625b206..431079b 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -376,11 +376,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.
@@ -431,10 +431,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();
@@ -529,10 +529,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!
@@ -657,10 +657,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.
 {
@@ -753,10 +753,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.
@@ -778,16 +778,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:
@@ -795,10 +794,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 e6ee2abec15e224ef79000e061fcba86a43ae298
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 6668ee7..625b206 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -306,8 +306,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()
+			}
 		}
 	}
 
@@ -505,12 +529,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();
 
@@ -919,12 +1071,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;
 	}
 }
 
@@ -965,21 +1118,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) {
@@ -1056,7 +1208,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 ecd78a1bb39bd3291e2ff1b277e21e8277dcddff
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 51e1ea67675ce616876764998376ceb751c3987d
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 1cc04b5..0b17bdb 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -27347,6 +27347,8 @@ status collapsed
 
 \change_inserted 1075283030 1597698872
 DocBookTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27410,6 +27412,8 @@ status collapsed
 
 \change_inserted 1075283030 1597698987
 DocBook*TagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27431,6 +27435,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699012
 block
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27489,6 +27495,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699113
 paragraph
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27535,6 +27543,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699307
 inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27570,6 +27580,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699585
 block
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28283,8 +28295,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
@@ -28297,6 +28335,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699853
 DocBookItemInnerTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28309,6 +28349,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699866
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28462,6 +28504,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699880
 DocBookItemLabelTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28474,6 +28518,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699874
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28583,6 +28629,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699890
 DocBookItemTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28595,6 +28643,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699890
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28766,6 +28816,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699900
 DocBookItemWrapperTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28778,6 +28830,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699897
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28943,6 +28997,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699904
 DocBookInnerTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28955,6 +29011,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699904
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29106,6 +29164,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699924
 DocBookTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29118,6 +29178,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699924
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29283,6 +29345,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699932
 DocBookWrapperTagType
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29295,6 +29359,8 @@ status collapsed
 
 \change_inserted 1075283030 1597699929
 block, paragraph, inline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29503,6 +29569,8 @@ status collapsed
 
 \change_inserted 1075283030 1597700120
 biblioentry
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -29528,6 +29596,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 e511985..5ee6171 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3316,19 +3316,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;
@@ -3339,15 +3334,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
@@ -3356,12 +3363,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();
@@ -3373,11 +3380,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();
 	}
@@ -3385,11 +3392,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 f642f16..6668ee7 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -380,9 +380,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");
@@ -486,21 +488,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);
+		}
 	}
 }
 
@@ -527,10 +527,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.
@@ -578,9 +576,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);
@@ -610,8 +617,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 60494b331c07154cebb0b53d7dddecda2ffc3a8d
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 6e52eac..f642f16 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -28,8 +28,6 @@
 
 #include "support/lassert.h"
 
-#include "support/regex.h"
-
 #include <stack>
 #include <iostream>
 #include <algorithm>
@@ -164,18 +162,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
@@ -499,13 +485,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)
@@ -656,8 +642,6 @@ void makeAny(
 	}
 }
 
-} // end anonymous namespace
-
 
 using DocBookDocumentSectioning = tuple<bool, pit_type>;
 
@@ -794,6 +778,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,
@@ -827,11 +825,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 bbffa53d3f95d8c96310288c3d2cb148f175d298
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 114fee5..6e52eac 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -384,9 +384,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 36a603b9b927e78af20dff33cc0d6c753c9e6a78
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 a1c3f94..114fee5 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -358,63 +358,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();
 	}
@@ -522,14 +518,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 ecfc877d672d4d3acd295f528838d02a0eb6410a
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..a1c3f94 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -9,15 +9,11 @@
  * Full author contact details are available in file CREDITS.
  */
 
-#include <config.h>
-
 #include "Buffer.h"
 #include "buffer_funcs.h"
 #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 +26,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 +151,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 418ba05928e148ec7239a806c5d99f718a0d3bcf
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 0d0cb214958f8b1708431139c6b30fdf1aac126e
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 97a6cfb..0d3f4c1 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 18c0a8a86438aa894d1eb751cb835719a13006dc
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 1d2a92a536c440c7cd4f998a641361744699745e
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 5be274b016e466f171a7cfd62b254db1bd082dd5
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 c929914ffd0b2d3dd0bc0e3f7dd4400e13c8ba74
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 5992b7f..1cc04b5 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -1,5 +1,5 @@
 #LyX 2.4 created this file. For more info see https://www.lyx.org/
-\lyxformat 596
+\lyxformat 598
 \begin_document
 \begin_header
 \save_transient_properties true
@@ -135,6 +135,7 @@ logicalmkup
 \html_math_output 0
 \html_css_as_file 0
 \html_be_strict true
+\docbook_table_output 0
 \author -970929547 "Thibaut Cuvelier"
 \author -712698321 "Jürgen Spitzmüller"
 \author -495245474 "Jean-Marc Lasgouttes"
@@ -2521,6 +2522,8 @@ status open
 
 \change_inserted -712698321 1524657030
 flavor
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -2534,6 +2537,8 @@ status collapsed
 
 \change_inserted -712698321 1524657047
 .aux
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -2546,6 +2551,8 @@ status open
 
 \change_inserted -712698321 1524657030
 latex, pdflatex, platex, xetex, luatex
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -2559,6 +2566,8 @@ status open
 
 \change_inserted -712698321 1524657030
 latex
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -2650,6 +2659,8 @@ status collapsed
 
 \change_inserted -712698321 1523206193
 hyperref-driver
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -9005,6 +9016,8 @@ status collapsed
 
 \change_inserted -712698321 1526898610
 AddToCiteEngine <engine>
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -9140,6 +9153,8 @@ status collapsed
 
 \change_inserted -712698321 1562592954
 BibInToc
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -9154,6 +9169,8 @@ status collapsed
 
 \emph on
 0
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -9170,6 +9187,8 @@ status collapsed
 
 \change_inserted -712698321 1562592950
 1
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -9664,6 +9683,8 @@ status collapsed
 
 \change_inserted -970929547 1515112782
 DocBookRoot
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -9676,6 +9697,8 @@ status collapsed
 
 \change_inserted -970929547 1515112766
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -9694,6 +9717,8 @@ status collapsed
 
 \change_inserted -970929547 1515112845
 article
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -9720,6 +9745,8 @@ status collapsed
 
 \change_inserted 1075283030 1594226785
 DocBookForceAbstract
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -9732,6 +9759,8 @@ status collapsed
 
 \change_inserted 1075283030 1594226804
 boolean
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -10658,6 +10687,8 @@ status collapsed
 
 \change_inserted -712698321 1565102365
 PageSize
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -10675,6 +10706,8 @@ custom
 \emph default
 , letter, legal, executive, a0, a1, a2, a3, a4, a5, a6, b0, b1, b2, b3,
  b4, b5, b6, c0, c1, c2, c3, c4, c5, c6, b0j, b1j, b2j, b3j, b4j, b5j, b6j
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11276,6 +11309,8 @@ status collapsed
 
 \change_inserted -712698321 1553617809
 TableStyle
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11288,6 +11323,8 @@ status collapsed
 
 \change_inserted -712698321 1553617805
 <name>
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11336,6 +11373,8 @@ status collapsed
 
 \change_inserted -712698321 1554308042
 Formal_without_Footline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11354,6 +11393,8 @@ status collapsed
 
 \change_inserted -712698321 1553618006
 Simple_Grid
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11371,6 +11412,8 @@ status collapsed
 
 \change_inserted -712698321 1553618031
 Grid_with_Head
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11383,6 +11426,8 @@ status collapsed
 
 \change_inserted -712698321 1553618043
 Simple_Grid
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11402,6 +11447,8 @@ status collapsed
 
 \change_inserted -712698321 1553618261
 No_Borders
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11690,6 +11737,8 @@ status collapsed
 
 \change_inserted -712698321 1565110199
 FontSizeFormat
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11702,6 +11751,8 @@ status collapsed
 
 \change_inserted -712698321 1565110196
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11730,6 +11781,8 @@ status collapsed
 
 \change_inserted -712698321 1565110248
 $$s
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11779,6 +11832,8 @@ status collapsed
 
 \change_inserted -712698321 1565101918
 PageSize
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11822,6 +11877,8 @@ b3j|\SpecialChar allowbreak
 b4j|\SpecialChar allowbreak
 b5j|\SpecialChar allowbreak
 b6j"
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11838,6 +11895,8 @@ status collapsed
 
 \change_inserted -712698321 1565101779
 |
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11861,6 +11920,8 @@ status collapsed
 
 \change_inserted -712698321 1565180605
 PageSizeFormat
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11873,6 +11934,8 @@ status collapsed
 
 \change_inserted -712698321 1565180601
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11886,6 +11949,8 @@ status collapsed
 
 \change_inserted -712698321 1565180618
 $$spaper
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -11899,6 +11964,8 @@ status collapsed
 
 \change_inserted -712698321 1565180601
 $$s
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -12479,6 +12546,8 @@ status collapsed
 
 \change_inserted -712698321 1555579780
 NewlineCmd
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -12491,6 +12560,8 @@ status collapsed
 
 \change_inserted -712698321 1555579780
 [string]
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -12507,6 +12578,8 @@ status collapsed
 
 \backslash
 
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -12780,6 +12853,8 @@ status collapsed
 
 \change_inserted -712698321 1559484228
 FreeSpacing
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -12794,6 +12869,8 @@ status collapsed
 
 \emph on
 0
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -12810,6 +12887,8 @@ status collapsed
 
 \change_inserted -712698321 1559484228
 1
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -12922,6 +13001,8 @@ status collapsed
 
 \change_inserted -712698321 1559490711
 InsertOnNewline
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -12934,6 +13015,8 @@ status collapsed
 
 \change_inserted -712698321 1559490703
 [int=0]
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -12946,6 +13029,8 @@ status collapsed
 
 \change_inserted -712698321 1559490703
 1
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -12958,6 +13043,8 @@ status collapsed
 
 \change_inserted -712698321 1559491402
 AutoInsert
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -13278,6 +13365,8 @@ status collapsed
 
 \change_inserted -712698321 1534488412
 Argument listpreamble:1
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -13925,6 +14014,8 @@ status collapsed
 
 \change_inserted -495245474 1550490089
 Passthru 1
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -13943,6 +14034,8 @@ status collapsed
 
 \change_inserted -495245474 1550247736
 FreeSpacing
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -13955,6 +14048,8 @@ status collapsed
 
 \change_inserted -495245474 1550247755
 KeepEmpty
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -15934,6 +16029,8 @@ status collapsed
 
 \change_inserted -712698321 1523696950
 NeedCProtect
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -15948,6 +16045,8 @@ status collapsed
 
 \emph on
 0
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -15964,6 +16063,8 @@ status collapsed
 
 \change_inserted -712698321 1523696950
 1
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -15978,6 +16079,8 @@ status collapsed
 
 \backslash
 cprotect
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -16000,6 +16103,8 @@ status collapsed
 
 \change_inserted -712698321 1552395561
 NeedMBoxProtect
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -16014,6 +16119,8 @@ status collapsed
 
 \emph on
 0
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -16030,6 +16137,8 @@ status collapsed
 
 \change_inserted -712698321 1552395557
 1
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -18564,6 +18673,8 @@ status collapsed
 
 \change_inserted -712698321 1565605014
 Requires
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -18576,6 +18687,8 @@ status collapsed
 
 \change_inserted -712698321 1565605014
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -20955,6 +21068,8 @@ status collapsed
 
 \change_inserted -712698321 1555575740
 MenuString
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -20967,6 +21082,8 @@ status collapsed
 
 \change_inserted -712698321 1555575740
 [string]
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21001,6 +21118,8 @@ status collapsed
 
 \change_inserted -712698321 1555575781
 My Inset|M
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21161,6 +21280,8 @@ status collapsed
 
 \change_inserted -712698321 1523633961
 NeedCProtect
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21175,6 +21296,8 @@ status collapsed
 
 \emph on
 0
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21191,6 +21314,8 @@ status collapsed
 
 \change_inserted -712698321 1523633958
 1
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21230,6 +21355,8 @@ status collapsed
 
 \change_inserted -712698321 1552395787
 NeedMBoxProtect
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21244,6 +21371,8 @@ status collapsed
 
 \emph on
 0
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21260,6 +21389,8 @@ status collapsed
 
 \change_inserted -712698321 1552395787
 1
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21274,6 +21405,8 @@ status collapsed
 
 \backslash
 cite
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21288,6 +21421,8 @@ status collapsed
 
 \backslash
 ref
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21302,6 +21437,8 @@ status collapsed
 
 \backslash
 mbox
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21329,6 +21466,8 @@ status collapsed
 
 \change_inserted -712698321 1555579658
 NewlineCmd
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21341,6 +21480,8 @@ status collapsed
 
 \change_inserted -712698321 1555579651
 [string]
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21468,6 +21609,8 @@ status collapsed
 
 \change_inserted -712698321 1559491854
 ParbreakIgnored
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21482,6 +21625,8 @@ status collapsed
 
 \emph on
 0
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -21498,6 +21643,8 @@ status collapsed
 
 \change_inserted -712698321 1559491850
 1
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -26929,13 +27076,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
 
@@ -26954,6 +27112,8 @@ status collapsed
 \change_inserted -970929547 1496610966
 \SpecialChar LaTeX
 Type
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27068,6 +27228,8 @@ status collapsed
 
 \change_inserted -970929547 1515109656
 DocBookAttr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27080,6 +27242,8 @@ status collapsed
 
 \change_inserted -970929547 1496610966
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27097,6 +27261,8 @@ status collapsed
 
 \change_inserted -970929547 1515110057
 attr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27122,6 +27288,8 @@ status collapsed
 
 \change_inserted -970929547 1496612269
 DocBookTag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27134,6 +27302,8 @@ status collapsed
 
 \change_inserted -970929547 1496610966
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27150,6 +27320,8 @@ status collapsed
 
 \change_inserted -970929547 1496612296
 tag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27161,6 +27333,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
@@ -27428,6 +27846,8 @@ status collapsed
 
 \change_inserted -970929547 1496610966
 MultiPar
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27455,6 +27875,8 @@ status collapsed
 
 \change_inserted -970929547 1515109695
 DocBookAttr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27467,6 +27889,8 @@ status collapsed
 
 \change_inserted -970929547 1496611854
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27484,6 +27908,8 @@ status collapsed
 
 \change_inserted -970929547 1515110044
 attr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27507,6 +27933,8 @@ status collapsed
 
 \change_inserted -970929547 1515110319
 DocBookInInfo
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27519,6 +27947,8 @@ status collapsed
 
 \change_inserted -970929547 1515110384
 never, always, maybe
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27531,6 +27961,8 @@ status collapsed
 
 \change_inserted -970929547 1515110412
 <info>
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27544,6 +27976,8 @@ status collapsed
 
 \change_inserted -970929547 1515110437
 never
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27556,6 +27990,8 @@ status collapsed
 
 \change_inserted -970929547 1515110497
 <info>
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27569,6 +28005,8 @@ status collapsed
 
 \change_inserted -970929547 1515110517
 always
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27581,6 +28019,8 @@ status collapsed
 
 \change_inserted -970929547 1515110514
 <info>
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27593,6 +28033,8 @@ status collapsed
 
 \change_inserted -970929547 1515110550
 <info>
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27610,6 +28052,8 @@ status collapsed
 
 \change_inserted -970929547 1515110540
 maybe
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27622,6 +28066,8 @@ status collapsed
 
 \change_inserted -970929547 1515110538
 <info>
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27634,6 +28080,8 @@ status collapsed
 
 \change_inserted -970929547 1515110585
 <info>
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27656,6 +28104,8 @@ status collapsed
 
 \change_inserted -970929547 1515110974
 DocBookItemAttr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27668,6 +28118,8 @@ status collapsed
 
 \change_inserted -970929547 1515110973
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27685,6 +28137,8 @@ status collapsed
 
 \change_inserted -970929547 1515110984
 itemattr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27708,6 +28162,8 @@ status collapsed
 
 \change_inserted -970929547 1515111465
 DocBookItemInnerAttr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27720,6 +28176,8 @@ status collapsed
 
 \change_inserted -970929547 1515111461
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27737,6 +28195,8 @@ status collapsed
 
 \change_inserted -970929547 1515111476
 iteminnerattr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27760,6 +28220,8 @@ status collapsed
 
 \change_inserted -970929547 1515111467
 DocBookItemInnerTag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27772,6 +28234,8 @@ status collapsed
 
 \change_inserted -970929547 1515111461
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27789,6 +28253,8 @@ status collapsed
 
 \change_inserted -970929547 1515111486
 iteminnertag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27806,6 +28272,8 @@ status collapsed
 
 \change_inserted -970929547 1515111461
 NONE
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27815,6 +28283,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
@@ -27829,6 +28343,8 @@ status collapsed
 
 \change_inserted -970929547 1515111283
 DocBookItemLabelAttr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27841,6 +28357,8 @@ status collapsed
 
 \change_inserted -970929547 1515111279
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27858,6 +28376,8 @@ status collapsed
 
 \change_inserted -970929547 1515111304
 itemlabelattr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27881,6 +28401,8 @@ status collapsed
 
 \change_inserted -970929547 1515111285
 DocBookItemLabelTag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27893,6 +28415,8 @@ status collapsed
 
 \change_inserted -970929547 1515111279
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27910,6 +28434,8 @@ status collapsed
 
 \change_inserted -970929547 1515111311
 itemlabeltag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27922,6 +28448,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
@@ -27936,6 +28508,8 @@ status collapsed
 
 \change_inserted -970929547 1515111060
 DocBookItemTag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27948,6 +28522,8 @@ status collapsed
 
 \change_inserted -970929547 1515111060
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27964,6 +28540,8 @@ status collapsed
 
 \change_inserted -970929547 1515111060
 itemtag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27981,6 +28559,8 @@ status collapsed
 
 \change_inserted -970929547 1515111060
 NONE
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -27989,6 +28569,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
@@ -28001,6 +28629,8 @@ status collapsed
 
 \change_inserted -970929547 1515111124
 DocBookItemWrapperAttr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28013,6 +28643,8 @@ status collapsed
 
 \change_inserted -970929547 1515111124
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28030,6 +28662,8 @@ status collapsed
 
 \change_inserted -970929547 1515111150
 itemwrapperattr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28055,6 +28689,8 @@ status collapsed
 
 \change_inserted -970929547 1515111073
 DocBookItemWrapperTag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28067,6 +28703,8 @@ status collapsed
 
 \change_inserted -970929547 1515111073
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28084,6 +28722,8 @@ status collapsed
 
 \change_inserted -970929547 1515111083
 itemwrappertag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28101,6 +28741,8 @@ status collapsed
 
 \change_inserted -970929547 1515111073
 NONE
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28110,6 +28752,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
@@ -28124,6 +28812,8 @@ status collapsed
 
 \change_inserted -970929547 1515110104
 DocBookInnerAttr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28136,6 +28826,8 @@ status collapsed
 
 \change_inserted -970929547 1515110104
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28153,6 +28845,8 @@ status collapsed
 
 \change_inserted -970929547 1515110104
 innerattr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28176,6 +28870,8 @@ status collapsed
 
 \change_inserted -970929547 1515110104
 DocBookInnerTag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28188,6 +28884,8 @@ status collapsed
 
 \change_inserted -970929547 1515110104
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28204,6 +28902,8 @@ status collapsed
 
 \change_inserted -970929547 1515110104
 innertag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28221,12 +28921,62 @@ status collapsed
 
 \change_inserted -970929547 1515110791
 NONE
+\change_unchanged
+
 \end_layout
 
 \end_inset
 
 , 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
@@ -28239,6 +28989,8 @@ status collapsed
 
 \change_inserted -970929547 1515110665
 DocBookSectionTag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28251,6 +29003,8 @@ status collapsed
 
 \change_inserted -970929547 1515110661
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28266,12 +29020,18 @@ status collapsed
 
 \change_inserted -970929547 1515110721
 section
+\change_unchanged
+
 \end_layout
 
 \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
 
@@ -28287,6 +29047,8 @@ status collapsed
 
 \change_inserted -970929547 1496612023
 DocBookTag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28299,6 +29061,8 @@ status collapsed
 
 \change_inserted -970929547 1496610966
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28315,6 +29079,8 @@ status collapsed
 
 \change_inserted -970929547 1496612033
 tag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28326,6 +29092,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
@@ -28338,6 +29152,8 @@ status collapsed
 
 \change_inserted -970929547 1515110822
 DocBookWrapperAttr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28350,6 +29166,8 @@ status collapsed
 
 \change_inserted -970929547 1515110811
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28367,6 +29185,8 @@ status collapsed
 
 \change_inserted -970929547 1515110845
 wrapperattr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28390,6 +29210,8 @@ status collapsed
 
 \change_inserted -970929547 1515110826
 DocBookWrapperTag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28402,6 +29224,8 @@ status collapsed
 
 \change_inserted -970929547 1515110811
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28418,6 +29242,8 @@ status collapsed
 
 \change_inserted -970929547 1515110842
 wrappertag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28435,13 +29261,61 @@ status collapsed
 
 \change_inserted -970929547 1515110811
 NONE
+\change_unchanged
+
 \end_layout
 
 \end_inset
 
 , 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
 
@@ -28494,6 +29368,8 @@ status collapsed
 
 \change_inserted -970929547 1515109702
 DocBookAttr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28506,6 +29382,8 @@ status collapsed
 
 \change_inserted -970929547 1496610966
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28523,6 +29401,8 @@ status collapsed
 
 \change_inserted -970929547 1515110035
 attr
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28546,6 +29426,8 @@ status collapsed
 
 \change_inserted -970929547 1496611782
 DocBookTag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28558,6 +29440,8 @@ status collapsed
 
 \change_inserted -970929547 1496610966
 string
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28574,6 +29458,8 @@ status collapsed
 
 \change_inserted -970929547 1496610966
 tag
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -28595,9 +29481,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
-The bibliography cannot be formatted: all fields are always output in the
- database-like DocBook format (equivalent to a BibTeX file).
+ 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
+.
+\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 d20dd62b433231d3bfd887dc38603c80f781e07d
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 ec289a6d098311915bd2055448a7a6813e530b69
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 dcba46a..e511985 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3370,12 +3370,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 068854b..2cecba9 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -2461,7 +2461,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 d77d18233f329cd1bd2f2f05778353642863ac6e
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Sun Aug 16 19:22:23 2020 +0200

    Fix compilation

diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
index 26dd55f..48e1993 100644
--- a/src/mathed/InsetMathGrid.cpp
+++ b/src/mathed/InsetMathGrid.cpp
@@ -1634,7 +1634,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
 			for (row_type r = 0; r < numrows; ++r) {
 				for (col_type c = 0; c < numcols; ++c) {
 					idx_type i = index(r + startrow, c + startcol);
-					pos_type ipos = uint(cur.pos()) > cell(i).size()
+					pos_type ipos = pos_type(cur.pos()) > cell(i).size()
 							? cell(i).size()
 							: cur.pos();
 					cell(i).insert(ipos, grid.cell(grid.index(r, c)));

commit 9d68ca3984bff7d41d731a3843b78c563dd90a3f
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 312cafd045a35b55028822008a294a6e3569f5ff
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 b18a6c9f0a25d30523f702aa046ac0b467d937a6
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 73b42d30597ba597be831305292a27587af80767
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();
 }
 

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

Summary of changes:


hooks/post-receive
-- 
Repository for new features


More information about the lyx-cvs mailing list