Dear list,

To solve https://www.lyx.org/trac/ticket/12612, I needed a new layout
parameter for DocBook to generate some content based on paragraph labels.
It draws heavily from LyXHTML code: makeEnvironment in output_xhtml.cpp,
case on environments, label generation (currently, lines 499 to 511).

As I'm still not very confident with layout changes, and especially as LyX
master is maturing, I'm requesting some feedback/review before pushing. I
believe everything is there (code changes, layout version update, changes
in the layout to use the new feature, documentation), with the exception of
updating the version number of all layouts (to avoid cluttering the patch).

By the way, I noticed that the documentation on the new DocBook parameters
for the layouts is truly lacking. I'll try to do something about it.

Thanks in advance!

Thibaut Cuvelier
From f6d49430e08c732dc3f5bb76a80f572f957fce48 Mon Sep 17 00:00:00 2001
From: Thibaut Cuvelier <tcuvelier@lyx.org>
Date: Thu, 22 Dec 2022 04:38:36 +0100
Subject: [PATCH] DocBook: add support for DocBookGenerateTitle.

The new parameter allows more flexibility when encoding some elements that have a poor mapping in DocBook, like theorems. The major use is to wrap the environment in a generic container, figure, which requires a title (but none is available).
---
 autotests/export/docbook/theorems-mathml.lyx | 148 +++++++++++++++++++
 autotests/export/docbook/theorems-mathml.xml |  85 +++++++++++
 lib/doc/Customization.lyx                    |  68 ++++++++-
 lib/layouts/elsart.layout                    |  62 ++++++--
 lib/layouts/theorems-ams-bytype.inc          |  53 +++++--
 lib/layouts/theorems-ams-chap-bytype.inc     |  53 +++++--
 lib/layouts/theorems-ams.inc                 |  51 +++++--
 lib/layouts/theorems-bytype.inc              |  53 +++++--
 lib/layouts/theorems-starred.inc             |  56 +++++--
 lib/layouts/theorems-without-preamble.inc    |  83 ++++++++---
 lib/layouts/theorems.inc                     |  51 +++++--
 src/Layout.cpp                               |   6 +
 src/Layout.h                                 |   8 +-
 src/TextClass.cpp                            |   2 +-
 src/output_docbook.cpp                       |  15 +-
 15 files changed, 662 insertions(+), 132 deletions(-)
 create mode 100644 autotests/export/docbook/theorems-mathml.lyx
 create mode 100644 autotests/export/docbook/theorems-mathml.xml

diff --git a/autotests/export/docbook/theorems-mathml.lyx b/autotests/export/docbook/theorems-mathml.lyx
new file mode 100644
index 0000000000..89281f8332
--- /dev/null
+++ b/autotests/export/docbook/theorems-mathml.lyx
@@ -0,0 +1,148 @@
+#LyX 2.4 created this file. For more info see https://www.lyx.org/
+\lyxformat 613
+\begin_document
+\begin_header
+\save_transient_properties true
+\origin unavailable
+\textclass article
+\use_default_options true
+\begin_modules
+theorems-std
+\end_modules
+\maintain_unincluded_children no
+\language american
+\language_package default
+\inputencoding utf8
+\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
+\float_placement class
+\float_alignment class
+\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 false
+\paperorientation portrait
+\suppress_date false
+\justification true
+\use_refstyle 1
+\use_minted 0
+\use_lineno 0
+\index Index
+\shortcut idx
+\color #008000
+\end_index
+\secnumdepth 3
+\tocdepth 3
+\paragraph_separation indent
+\paragraph_indentation default
+\is_math_indent 0
+\math_numbering_side default
+\quotes_style english
+\dynamic_quotes 0
+\papercolumns 1
+\papersides 1
+\paperpagestyle default
+\tablestyle default
+\tracking_changes false
+\output_changes false
+\change_bars false
+\postpone_fragile_content true
+\html_math_output 0
+\html_css_as_file 0
+\html_be_strict false
+\docbook_table_output 0
+\docbook_mathml_prefix 1
+\end_header
+
+\begin_body
+
+\begin_layout Title
+Ensure that maths are properly converted in theorems
+\end_layout
+
+\begin_layout Standard
+Equation outside environments:
+ 
+\begin_inset Formula $\pi\,r^{2}$
+\end_inset
+
+.
+\begin_inset Formula 
+\[
+\pi\,\rho^{3}
+\]
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Theorem
+This is a theorem:
+ hypothesis 
+\begin_inset Formula $a=b$
+\end_inset
+
+,
+ thesis 
+\begin_inset Formula 
+\[
+a\neq b.
+\]
+
+\end_inset
+
+Clear,
+ don't you think?
+\end_layout
+
+\begin_layout Proof
+Left as exercise for the reader.
+\end_layout
+
+\begin_layout Remark
+This is real math,
+ you know.
+ 
+\begin_inset Formula $a=b=a$
+\end_inset
+
+.
+\end_layout
+
+\end_body
+\end_document
diff --git a/autotests/export/docbook/theorems-mathml.xml b/autotests/export/docbook/theorems-mathml.xml
new file mode 100644
index 0000000000..46865fa059
--- /dev/null
+++ b/autotests/export/docbook/theorems-mathml.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This DocBook file was created by LyX 2.4.0-beta2
+  See https://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>Ensure that maths are properly converted in theorems</title>
+<para>Equation outside environments: <inlineequation>
+<alt role='tex'>\pi\,r^{2}</alt>
+<m:math display="inline">
+ 
+<m:mrow>
+ <m:mrow><m:mi>&#x3C0;</m:mi>
+  <m:mspace width="6px"/>
+  <m:msup>
+   <m:mi>r</m:mi>
+   <m:mn>2</m:mn>
+  </m:msup>
+ </m:mrow>
+</m:mrow>
+</m:math>
+</inlineequation>.
+<informalequation>
+<alt role='tex'>\pi\,\rho^{3}</alt>
+<m:math display="block">
+ 
+<m:mrow>
+ <m:mrow><m:mi>&#x3C0;</m:mi>
+  <m:mspace width="6px"/>
+  <m:msup><m:mi>&#x3C1;</m:mi>
+   <m:mn>3</m:mn>
+  </m:msup>
+ </m:mrow>
+</m:mrow>
+</m:math>
+</informalequation>
+</para>
+<figure role='theorem'>
+<title>Theorem 1.</title>
+<para>This is a theorem: hypothesis <inlineequation>
+<alt role='tex'>a=b</alt>
+<m:math display="inline">
+ 
+<m:mrow>
+ <m:mrow>
+  <m:mi>a</m:mi>
+  <m:mo>=</m:mo>
+  <m:mi>b</m:mi>
+ </m:mrow>
+</m:mrow>
+</m:math>
+</inlineequation>, thesis 
+<informalequation>
+<alt role='tex'>a\neq b.</alt>
+<m:math display="block">
+ 
+<m:mrow>
+ <m:mrow>
+  <m:mi>a</m:mi><m:mo>&#x2260;</m:mo>
+  <m:mi>b</m:mi>
+  <m:mn>.</m:mn>
+ </m:mrow>
+</m:mrow>
+</m:math>
+</informalequation>
+Clear, don&#8217;t you think?</para>
+</figure>
+<para role='proof'>Left as exercise for the reader.</para>
+<figure role='remark'>
+<title>Remark 2.</title>
+<para>This is real math, you know. <inlineequation>
+<alt role='tex'>a=b=a</alt>
+<m:math display="inline">
+ 
+<m:mrow>
+ <m:mrow>
+  <m:mi>a</m:mi>
+  <m:mo>=</m:mo>
+  <m:mi>b</m:mi>
+  <m:mo>=</m:mo>
+  <m:mi>a</m:mi>
+ </m:mrow>
+</m:mrow>
+</m:math>
+</inlineequation>.</para>
+</figure>
+</article>
\ No newline at end of file
diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index bad5484e05..82a58ca7dd 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 612
+\lyxformat 613
 \begin_document
 \begin_header
 \save_transient_properties true
@@ -14662,7 +14662,73 @@ string
 \end_inset
 
 ] Copies all the features of an existing style into the current one.
+
+\change_deleted 1075283030 1671679775
  
+\change_inserted 1075283030 1671679774
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted 1075283030 1671680255
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1671679781
+DocBookGenerateTitle
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1671679785
+bool
+\end_layout
+
+\end_inset
+
+] Generates a 
+\family typewriter
+title
+\family default
+ tag after the wrapper tag.
+ This parameter should only be used with 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted 1075283030 1671679828
+DocBookWrapperTag
+\end_layout
+
+\end_inset
+
+,
+ otherwise the title will be output 
+\emph on
+before
+\emph default
+ the contents of the environment.
+ The generated title is the same as the LyXHTML label:
+ a combination of the environment type and its number.
+ A major use is when DocBook has no close mapping for LaTeX environments and users must fallback to using a generic container such as 
+\family typewriter
+figure
+\family default
+,
+ which requires a title although there is none in LaTeX.
+ This feature is heavily used for theorem-like environments.
+\change_unchanged
+
 \end_layout
 
 \begin_layout Description
diff --git a/lib/layouts/elsart.layout b/lib/layouts/elsart.layout
index 63a529f675..c64aaf98b1 100644
--- a/lib/layouts/elsart.layout
+++ b/lib/layouts/elsart.layout
@@ -333,8 +333,10 @@ Style Theorem
 	  Shape               Up
 	  Series              Bold
 	EndFont
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='theorem'
 	DocBookTag            para
-	DocBookAttr           role='theorem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -364,8 +366,10 @@ Style Proof
 	LabelFont
 	  Series              Bold
 	EndFont
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='proof'
 	DocBookTag            para
-	DocBookAttr           role='proof'
+	DocBookGenerateTitle  true
 End
 
 
@@ -373,8 +377,10 @@ Style Lemma
 	CopyStyle             Theorem
 	LatexName             lem
 	LabelString           "Lemma \arabic{theorem}"
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='lemma'
 	DocBookTag            para
-	DocBookAttr           role='lemma'
+	DocBookGenerateTitle  true
 End
 
 
@@ -382,8 +388,10 @@ Style Corollary
 	CopyStyle             Theorem
 	LatexName             cor
 	LabelString           "Corollary \arabic{theorem}"
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='corollary'
 	DocBookTag            para
-	DocBookAttr           role='corollary'
+	DocBookGenerateTitle  true
 End
 
 
@@ -391,8 +399,10 @@ Style Proposition
 	CopyStyle             Theorem
 	LatexName             prop
 	LabelString           "Proposition \arabic{theorem}"
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='proposition'
 	DocBookTag            para
-	DocBookAttr           role='proposition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -400,8 +410,10 @@ Style Criterion
 	CopyStyle             Theorem
 	LatexName             crit
 	LabelString           "Criterion \arabic{theorem}"
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='criterion'
 	DocBookTag            para
-	DocBookAttr           role='criterion'
+	DocBookGenerateTitle  true
 End
 
 
@@ -409,8 +421,10 @@ Style Algorithm
 	CopyStyle             Theorem
 	LatexName             alg
 	LabelString           "Algorithm \arabic{theorem}"
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='algorithm'
 	DocBookTag            para
-	DocBookAttr           role='algorithm'
+	DocBookGenerateTitle  true
 End
 
 
@@ -425,8 +439,10 @@ Style Definition
 	  Shape               Up
 	  Series              Bold
 	EndFont
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='definition'
 	DocBookTag            para
-	DocBookAttr           role='definition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -434,8 +450,10 @@ Style Conjecture
 	CopyStyle             Theorem
 	LatexName             conj
 	LabelString           "Conjecture \arabic{theorem}"
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='conjecture'
 	DocBookTag            para
-	DocBookAttr           role='conjecture'
+	DocBookGenerateTitle  true
 End
 
 
@@ -453,8 +471,10 @@ Style Problem
 	CopyStyle             Theorem
 	LatexName             prob
 	LabelString           "Problem \arabic{theorem}"
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='problem'
 	DocBookTag            para
-	DocBookAttr           role='problem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -462,8 +482,10 @@ Style Remark
 	CopyStyle             Theorem
 	LatexName             rem
 	LabelString           "Remark \arabic{theorem}"
-	DocBookTag            note
-	DocBookItemTag        para
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='remark'
+	DocBookTag            para
+	DocBookGenerateTitle  true
 End
 
 
@@ -471,8 +493,10 @@ Style Note
 	CopyStyle             Theorem
 	LatexName             note
 	LabelString           "Note \arabic{theorem}"
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='note'
 	DocBookTag            para
-	DocBookAttr           role='note'
+	DocBookGenerateTitle  true
 End
 
 
@@ -480,8 +504,10 @@ Style Claim
 	CopyStyle             Theorem
 	LatexName             claim
 	LabelString           "Claim \arabic{theorem}"
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='claim'
 	DocBookTag            para
-	DocBookAttr           role='claim'
+	DocBookGenerateTitle  true
 End
 
 
@@ -490,8 +516,10 @@ Style Summary
 	LatexName             summ
 	LabelCounter          summ
 	LabelString           "Summary \arabic{summ}"
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='summary'
 	DocBookTag            para
-	DocBookAttr           role='summary'
+	DocBookGenerateTitle  true
 End
 
 
@@ -500,8 +528,10 @@ Style Case
 	LatexName             case
 	LabelCounter          case
 	LabelString           "Case \arabic{case}"
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='case'
 	DocBookTag            para
-	DocBookAttr           role='case'
+	DocBookGenerateTitle  true
 End
 
 
diff --git a/lib/layouts/theorems-ams-bytype.inc b/lib/layouts/theorems-ams-bytype.inc
index 7ff26b522f..b60ab3c361 100644
--- a/lib/layouts/theorems-ams-bytype.inc
+++ b/lib/layouts/theorems-ams-bytype.inc
@@ -72,8 +72,10 @@ Style Theorem
 		\addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
 	Requires              amsthm
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='theorem'
 	DocBookTag            para
-	DocBookAttr           role='theorem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -92,8 +94,10 @@ Style Corollary
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='corollary'
 	DocBookTag            para
-	DocBookAttr           role='corollary'
+	DocBookGenerateTitle  true
 End
 
 
@@ -112,8 +116,10 @@ Style Lemma
 	  \addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
 	LabelCounter          lemma
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='lemma'
 	DocBookTag            para
-	DocBookAttr           role='lemma'
+	DocBookGenerateTitle  true
 End
 
 
@@ -132,8 +138,10 @@ Style Proposition
 	  \addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
 	LabelCounter          proposition
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='proposition'
 	DocBookTag            para
-	DocBookAttr           role='proposition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -152,8 +160,10 @@ Style Conjecture
 	  \addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
 	LabelCounter          conjecture
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='conjecture'
 	DocBookTag            para
-	DocBookAttr           role='conjecture'
+	DocBookGenerateTitle  true
 End
 
 
@@ -172,8 +182,10 @@ Style Fact
 	  \addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
 	LabelCounter          fact
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='fact'
 	DocBookTag            para
-	DocBookAttr           role='fact'
+	DocBookGenerateTitle  true
 End
 
 
@@ -199,8 +211,10 @@ Style Definition
 	  \addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
 	LabelCounter          definition
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='definition'
 	DocBookTag            para
-	DocBookAttr           role='definition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -222,7 +236,7 @@ Style Example
 	LabelCounter          example
 	DocBookWrapperTag     informalexample
 	DocBookTag            para
-	DocBookAttr        ""
+	DocBookAttr           ""
 End
 
 
@@ -242,8 +256,10 @@ Style Problem
 	  \addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
 	LabelCounter          problem
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='problem'
 	DocBookTag            para
-	DocBookAttr           role='problem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -263,8 +279,10 @@ Style Exercise
 	  \addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
 	LabelCounter          exercise
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='exercise'
 	DocBookTag            para
-	DocBookAttr           role='exercise'
+	DocBookGenerateTitle  true
 End
 
 
@@ -284,8 +302,10 @@ Style Solution
 		\addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
 	LabelCounter          solution
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='solution'
 	DocBookTag            para
-	DocBookAttr           role='solution'
+	DocBookGenerateTitle  true
 End
 
 
@@ -312,8 +332,10 @@ Style Remark
 	  \addto\captions$$lang{\renewcommand{\remarkname}{_(Remark)}}
 	EndBabelPreamble
 	LabelCounter          remark
-	DocBookTag            note
-	DocBookItemTag        para
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='remark'
+	DocBookTag            para
+	DocBookGenerateTitle  true
 End
 
 
@@ -333,9 +355,10 @@ Style Claim
 	  \addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
 	LabelCounter          claim
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='claim'
 	DocBookTag            para
-	DocBookAttr           role='claim'
-	DocBookItemTag        ""
+	DocBookGenerateTitle  true
 End
 
 Input theorems-case.inc
diff --git a/lib/layouts/theorems-ams-chap-bytype.inc b/lib/layouts/theorems-ams-chap-bytype.inc
index 8ef60a5260..854588078e 100644
--- a/lib/layouts/theorems-ams-chap-bytype.inc
+++ b/lib/layouts/theorems-ams-chap-bytype.inc
@@ -118,8 +118,10 @@ Style Theorem
 		\addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
 	Requires              amsthm
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='theorem'
 	DocBookTag            para
-	DocBookAttr           role='theorem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -142,8 +144,10 @@ Style Corollary
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='corollary'
 	DocBookTag            para
-	DocBookAttr           role='corollary'
+	DocBookGenerateTitle  true
 End
 
 
@@ -166,8 +170,10 @@ Style Lemma
 	  \addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
 	LabelCounter          lemma
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='lemma'
 	DocBookTag            para
-	DocBookAttr           role='lemma'
+	DocBookGenerateTitle  true
 End
 
 
@@ -190,8 +196,10 @@ Style Proposition
 	  \addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
 	LabelCounter          proposition
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='proposition'
 	DocBookTag            para
-	DocBookAttr           role='proposition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -214,8 +222,10 @@ Style Conjecture
 	  \addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
 	LabelCounter          conjecture
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='conjecture'
 	DocBookTag            para
-	DocBookAttr           role='conjecture'
+	DocBookGenerateTitle  true
 End
 
 
@@ -238,8 +248,10 @@ Style Fact
 	  \addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
 	LabelCounter          fact
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='fact'
 	DocBookTag            para
-	DocBookAttr           role='fact'
+	DocBookGenerateTitle  true
 End
 
 
@@ -269,8 +281,10 @@ Style Definition
 	  \addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
 	LabelCounter          definition
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='definition'
 	DocBookTag            para
-	DocBookAttr           role='definition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -296,7 +310,7 @@ Style Example
 	LabelCounter          example
 	DocBookWrapperTag     informalexample
 	DocBookTag            para
-	DocBookAttr        ""
+	DocBookAttr           ""
 End
 
 
@@ -320,8 +334,10 @@ Style Problem
 	  \addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
 	LabelCounter          problem
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='problem'
 	DocBookTag            para
-	DocBookAttr           role='problem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -345,8 +361,10 @@ Style Exercise
 	  \addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
 	LabelCounter          exercise
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='exercise'
 	DocBookTag            para
-	DocBookAttr           role='exercise'
+	DocBookGenerateTitle  true
 End
 
 
@@ -370,8 +388,10 @@ Style Solution
 		\addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
 	LabelCounter          solution
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='solution'
 	DocBookTag            para
-	DocBookAttr           role='solution'
+	DocBookGenerateTitle  true
 End
 
 
@@ -402,8 +422,10 @@ Style Remark
 	  \addto\captions$$lang{\renewcommand{\remarkname}{_(Remark)}}
 	EndBabelPreamble
 	LabelCounter          remark
-	DocBookTag            note
-	DocBookItemTag        para
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='remark'
+	DocBookTag            para
+	DocBookGenerateTitle  true
 End
 
 
@@ -427,9 +449,10 @@ Style Claim
 	  \addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
 	LabelCounter          claim
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='claim'
 	DocBookTag            para
-	DocBookAttr           role='claim'
-	DocBookItemTag        ""
+	DocBookGenerateTitle  true
 End
 
 
diff --git a/lib/layouts/theorems-ams.inc b/lib/layouts/theorems-ams.inc
index 5e265e551c..90ea48f3d4 100644
--- a/lib/layouts/theorems-ams.inc
+++ b/lib/layouts/theorems-ams.inc
@@ -69,8 +69,10 @@ Style Theorem
 	  \addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
 	Requires              amsthm
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='theorem'
 	DocBookTag            para
-	DocBookAttr           role='theorem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -89,8 +91,10 @@ Style Corollary
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='corollary'
 	DocBookTag            para
-	DocBookAttr           role='corollary'
+	DocBookGenerateTitle  true
 End
 
 
@@ -109,8 +113,10 @@ Style Lemma
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='lemma'
 	DocBookTag            para
-	DocBookAttr           role='lemma'
+	DocBookGenerateTitle  true
 End
 
 
@@ -129,8 +135,10 @@ Style Proposition
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='proposition'
 	DocBookTag            para
-	DocBookAttr           role='proposition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -149,8 +157,10 @@ Style Conjecture
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='conjecture'
 	DocBookTag            para
-	DocBookAttr           role='conjecture'
+	DocBookGenerateTitle  true
 End
 
 
@@ -169,8 +179,10 @@ Style Fact
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='fact'
 	DocBookTag            para
-	DocBookAttr           role='fact'
+	DocBookGenerateTitle  true
 End
 
 
@@ -196,8 +208,10 @@ Style Definition
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='definition'
 	DocBookTag            para
-	DocBookAttr           role='definition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -235,8 +249,10 @@ Style Problem
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='problem'
 	DocBookTag            para
-	DocBookAttr           role='problem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -254,8 +270,10 @@ Style Exercise
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='exercise'
 	DocBookTag            para
-	DocBookAttr           role='exercise'
+	DocBookGenerateTitle  true
 End
 
 
@@ -273,8 +291,10 @@ Style Solution
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='solution'
 	DocBookTag            para
-	DocBookAttr           role='solution'
+	DocBookGenerateTitle  true
 End
 
 
@@ -301,8 +321,10 @@ Style Remark
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\remarkname}{_(Remark)}}
 	EndBabelPreamble
-	DocBookTag            note
-	DocBookItemTag        para
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='remark'
+	DocBookTag            para
+	DocBookGenerateTitle  true
 End
 
 
@@ -320,9 +342,10 @@ Style Claim
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='claim'
 	DocBookTag            para
-	DocBookAttr           role='claim'
-	DocBookItemTag        ""
+	DocBookGenerateTitle  true
 End
 
 Input theorems-case.inc
diff --git a/lib/layouts/theorems-bytype.inc b/lib/layouts/theorems-bytype.inc
index 1967eebb0f..316812883b 100644
--- a/lib/layouts/theorems-bytype.inc
+++ b/lib/layouts/theorems-bytype.inc
@@ -66,8 +66,10 @@ Style Theorem
 		\addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
 	Requires              amsthm
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='theorem'
 	DocBookTag            para
-	DocBookAttr           role='theorem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -86,8 +88,10 @@ Style Corollary
 		\addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
 	LabelCounter          corollary
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='corollary'
 	DocBookTag            para
-	DocBookAttr           role='corollary'
+	DocBookGenerateTitle  true
 End
 
 
@@ -106,8 +110,10 @@ Style Lemma
 		\addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
 	LabelCounter          lemma
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='lemma'
 	DocBookTag            para
-	DocBookAttr           role='lemma'
+	DocBookGenerateTitle  true
 End
 
 
@@ -126,8 +132,10 @@ Style Proposition
 		\addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
 	LabelCounter          proposition
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='proposition'
 	DocBookTag            para
-	DocBookAttr           role='proposition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -146,8 +154,10 @@ Style Conjecture
 		\addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
 	LabelCounter          conjecture
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='conjecture'
 	DocBookTag            para
-	DocBookAttr           role='conjecture'
+	DocBookGenerateTitle  true
 End
 
 
@@ -166,8 +176,10 @@ Style Fact
 		\addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
 	LabelCounter          fact
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='fact'
 	DocBookTag            para
-	DocBookAttr           role='fact'
+	DocBookGenerateTitle  true
 End
 
 
@@ -193,8 +205,10 @@ Style Definition
 		\addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
 	LabelCounter          definition  
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='definition'
 	DocBookTag            para
-	DocBookAttr           role='definition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -216,7 +230,7 @@ Style Example
 	LabelCounter          example
 	DocBookWrapperTag     informalexample
 	DocBookTag            para
-	DocBookAttr        ""
+	DocBookAttr           ""
 End
 
 
@@ -236,8 +250,10 @@ Style Problem
 		\addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
 	LabelCounter          problem
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='problem'
 	DocBookTag            para
-	DocBookAttr           role='problem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -257,8 +273,10 @@ Style Exercise
 		\addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
 	LabelCounter          exercise
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='exercise'
 	DocBookTag            para
-	DocBookAttr           role='exercise'
+	DocBookGenerateTitle  true
 End
 
 
@@ -278,8 +296,10 @@ Style Solution
 		\addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
 	LabelCounter          solution
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='solution'
 	DocBookTag            para
-	DocBookAttr           role='solution'
+	DocBookGenerateTitle  true
 End
 
 
@@ -306,8 +326,10 @@ Style Remark
 		\addto\captions$$lang{\renewcommand{\remarkname}{_(Remark)}}
 	EndBabelPreamble
 	LabelCounter          remark
-	DocBookTag            note
-	DocBookItemTag        para
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='remark'
+	DocBookTag            para
+	DocBookGenerateTitle  true
 End
 
 
@@ -327,9 +349,10 @@ Style Claim
 		\addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
 	LabelCounter          claim
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='claim'
 	DocBookTag            para
-	DocBookAttr           role='claim'
-	DocBookItemTag        ""
+	DocBookGenerateTitle  true
 End
 
 Input theorems-case.inc
diff --git a/lib/layouts/theorems-starred.inc b/lib/layouts/theorems-starred.inc
index 704e88a1c8..003b07d267 100644
--- a/lib/layouts/theorems-starred.inc
+++ b/lib/layouts/theorems-starred.inc
@@ -19,6 +19,9 @@
 # - Claim
 # - Proof
 
+# TODO: for DocBook, there is no difference with standard (not starred) environments.
+# How to encode the subtlety?
+
 Format 98
 
 OutlinerName thm "Definitions & Theorems"
@@ -67,8 +70,10 @@ Style Theorem*
 	  \addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
 	Requires              amsthm
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='theorem'
 	DocBookTag            para
-	DocBookAttr           role='theorem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -86,8 +91,10 @@ Style Corollary*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='corollary'
 	DocBookTag            para
-	DocBookAttr           role='corollary'
+	DocBookGenerateTitle  true
 End
 
 
@@ -105,8 +112,10 @@ Style Lemma*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='lemma'
 	DocBookTag            para
-	DocBookAttr           role='lemma'
+	DocBookGenerateTitle  true
 End
 
 
@@ -124,8 +133,10 @@ Style Proposition*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='proposition'
 	DocBookTag            para
-	DocBookAttr           role='proposition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -143,8 +154,10 @@ Style Conjecture*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='conjecture'
 	DocBookTag            para
-	DocBookAttr           role='conjecture'
+	DocBookGenerateTitle  true
 End
 
 
@@ -162,8 +175,10 @@ Style Fact*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='fact'
 	DocBookTag            para
-	DocBookAttr           role='fact'
+	DocBookGenerateTitle  true
 End
 
 
@@ -189,8 +204,10 @@ Style Definition*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='definition'
 	DocBookTag            para
-	DocBookAttr           role='definition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -210,7 +227,7 @@ Style Example*
 	EndBabelPreamble
 	DocBookWrapperTag     informalexample
 	DocBookTag            para
-	DocBookAttr        ""
+	DocBookAttr           ""
 End
 
 
@@ -228,8 +245,10 @@ Style Problem*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='problem'
 	DocBookTag            para
-	DocBookAttr           role='problem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -247,8 +266,10 @@ Style Exercise*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='exercise'
 	DocBookTag            para
-	DocBookAttr           role='exercise'
+	DocBookGenerateTitle  true
 End
 
 
@@ -266,8 +287,10 @@ Style Solution*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='solution'
 	DocBookTag            para
-	DocBookAttr           role='solution'
+	DocBookGenerateTitle  true
 End
 
 
@@ -293,8 +316,10 @@ Style Remark*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\remarkname}{_(Remark)}}
 	EndBabelPreamble
-	DocBookTag            note
-	DocBookItemTag        para
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='remark'
+	DocBookTag            para
+	DocBookGenerateTitle  true
 End
 
 
@@ -312,8 +337,9 @@ Style Claim*
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='claim'
 	DocBookTag            para
-	DocBookAttr           role='claim'
-	DocBookItemTag        ""
+	DocBookGenerateTitle  true
 End
 
diff --git a/lib/layouts/theorems-without-preamble.inc b/lib/layouts/theorems-without-preamble.inc
index 13021ab654..26fba7c61f 100644
--- a/lib/layouts/theorems-without-preamble.inc
+++ b/lib/layouts/theorems-without-preamble.inc
@@ -74,8 +74,10 @@ Style Theorem
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='theorem'
 	DocBookTag            para
-	DocBookAttr           role='theorem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -93,8 +95,10 @@ Style Corollary
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='corollary'
 	DocBookTag            para
-	DocBookAttr           role='corollary'
+	DocBookGenerateTitle  true
 End
 
 
@@ -112,8 +116,10 @@ Style Lemma
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='lemma'
 	DocBookTag            para
-	DocBookAttr           role='lemma'
+	DocBookGenerateTitle  true
 End
 
 
@@ -131,8 +137,10 @@ Style Proposition
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='proposition'
 	DocBookTag            para
-	DocBookAttr           role='proposition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -150,8 +158,10 @@ Style Prop
 	LabelFont
 	  Series	Medium
 	EndFont
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='proposition'
 	DocBookTag            para
-	DocBookAttr           role='proposition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -176,8 +186,10 @@ Style Conjecture
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='conjecture'
 	DocBookTag            para
-	DocBookAttr           role='conjecture'
+	DocBookGenerateTitle  true
 End
 
 
@@ -195,8 +207,10 @@ Style Fact
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='fact'
 	DocBookTag            para
-	DocBookAttr           role='fact'
+	DocBookGenerateTitle  true
 End
 
 
@@ -222,8 +236,10 @@ Style Definition
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='definition'
 	DocBookTag            para
-	DocBookAttr           role='definition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -244,7 +260,7 @@ Style Example
 	EndBabelPreamble
 	DocBookWrapperTag     informalexample
 	DocBookTag            para
-	DocBookAttr        ""
+	DocBookAttr           ""
 End
 
 
@@ -264,8 +280,10 @@ Style Problem
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='problem'
 	DocBookTag            para
-	DocBookAttr           role='problem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -299,8 +317,10 @@ Style Prob
 	EndFont
 	AddToToc	thm
 	IsTocCaption	true
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='problem'
 	DocBookTag            para
-	DocBookAttr           role='problem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -319,8 +339,10 @@ Style Solution
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='solution'
 	DocBookTag            para
-	DocBookAttr           role='solution'
+	DocBookGenerateTitle  true
 End
 
 
@@ -335,8 +357,10 @@ Style Sol
 	  Tooltip	"Label of the corresponding problem"
 	  IsTocCaption true
 	EndArgument
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='solution'
 	DocBookTag            para
-	DocBookAttr           role='solution'
+	DocBookGenerateTitle  true
 End
 
 
@@ -355,8 +379,10 @@ Style Exercise
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='exercise'
 	DocBookTag            para
-	DocBookAttr           role='exercise'
+	DocBookGenerateTitle  true
 End
 
 
@@ -375,8 +401,10 @@ Style Remark
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\remarkname}{_(Remark)}}
 	EndBabelPreamble
-	DocBookTag            note
-	DocBookItemTag        para
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='remark'
+	DocBookTag            para
+	DocBookGenerateTitle  true
 End
 
 
@@ -390,9 +418,10 @@ Style		Claim
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='claim'
 	DocBookTag            para
-	DocBookAttr           role='claim'
-	DocBookItemTag        ""
+	DocBookGenerateTitle  true
 End
 
 
@@ -411,8 +440,10 @@ Style Case
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\casename}{_(Case)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='case'
 	DocBookTag            para
-	DocBookAttr           role='case'
+	DocBookGenerateTitle  true
 End
 
 
@@ -431,8 +462,10 @@ Style Property
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\propertyname}{_(Property)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='property'
 	DocBookTag            para
-	DocBookAttr           role='property'
+	DocBookGenerateTitle  true
 End
 
 
@@ -451,8 +484,10 @@ Style Question
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\questionname}{_(Question)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='question'
 	DocBookTag            para
-	DocBookAttr           role='question'
+	DocBookGenerateTitle  true
 End
 
 
@@ -471,7 +506,9 @@ Style Note
 	BabelPreamble
 	  \addto\captions$$lang{\renewcommand{\notename}{_(Note)}}
 	EndBabelPreamble
-	DocBookTag            note
-	DocBookItemTag        para
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='note'
+	DocBookTag            para
+	DocBookGenerateTitle  true
 End
 
diff --git a/lib/layouts/theorems.inc b/lib/layouts/theorems.inc
index 3310b2c4f3..0d7696dd13 100644
--- a/lib/layouts/theorems.inc
+++ b/lib/layouts/theorems.inc
@@ -69,8 +69,10 @@ Style Theorem
 		\addto\captions$$lang{\renewcommand{\theoremname}{_(Theorem)}}
 	EndBabelPreamble
 	Requires              amsthm
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='theorem'
 	DocBookTag            para
-	DocBookAttr           role='theorem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -89,8 +91,10 @@ Style Corollary
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\corollaryname}{_(Corollary)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='corollary'
 	DocBookTag            para
-	DocBookAttr           role='corollary'
+	DocBookGenerateTitle  true
 End
 
 
@@ -109,8 +113,10 @@ Style Lemma
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\lemmaname}{_(Lemma)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='lemma'
 	DocBookTag            para
-	DocBookAttr           role='lemma'
+	DocBookGenerateTitle  true
 End
 
 
@@ -129,8 +135,10 @@ Style Proposition
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\propositionname}{_(Proposition)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='proposition'
 	DocBookTag            para
-	DocBookAttr           role='proposition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -149,8 +157,10 @@ Style Conjecture
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\conjecturename}{_(Conjecture)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='conjecture'
 	DocBookTag            para
-	DocBookAttr           role='conjecture'
+	DocBookGenerateTitle  true
 End
 
 
@@ -169,8 +179,10 @@ Style Fact
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\factname}{_(Fact)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='fact'
 	DocBookTag            para
-	DocBookAttr           role='fact'
+	DocBookGenerateTitle  true
 End
 
 
@@ -196,8 +208,10 @@ Style Definition
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\definitionname}{_(Definition)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='definition'
 	DocBookTag            para
-	DocBookAttr           role='definition'
+	DocBookGenerateTitle  true
 End
 
 
@@ -235,8 +249,10 @@ Style Problem
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\problemname}{_(Problem)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='problem'
 	DocBookTag            para
-	DocBookAttr           role='problem'
+	DocBookGenerateTitle  true
 End
 
 
@@ -254,8 +270,10 @@ Style Exercise
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\exercisename}{_(Exercise)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='exercise'
 	DocBookTag            para
-	DocBookAttr           role='exercise'
+	DocBookGenerateTitle  true
 End
 
 
@@ -273,8 +291,10 @@ Style Solution
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\solutionname}{_(Solution)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='solution'
 	DocBookTag            para
-	DocBookAttr           role='solution'
+	DocBookGenerateTitle  true
 End
 
 
@@ -301,8 +321,10 @@ Style Remark
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\remarkname}{_(Remark)}}
 	EndBabelPreamble
-	DocBookTag            note
-	DocBookItemTag        para
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='remark'
+	DocBookTag            para
+	DocBookGenerateTitle  true
 End
 
 
@@ -320,9 +342,10 @@ Style Claim
 	BabelPreamble
 		\addto\captions$$lang{\renewcommand{\claimname}{_(Claim)}}
 	EndBabelPreamble
+	DocBookWrapperTag     figure
+	DocBookWrapperAttr    role='claim'
 	DocBookTag            para
-	DocBookAttr           role='claim'
-	DocBookItemTag        ""
+	DocBookGenerateTitle  true
 End
 
 Input theorems-case.inc
diff --git a/src/Layout.cpp b/src/Layout.cpp
index 515226da3e..3e2a5fe101 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -111,6 +111,7 @@ enum LayoutTags {
 	LT_DOCBOOKINNERTAGTYPE,
 	LT_DOCBOOKININFO,
 	LT_DOCBOOKABSTRACT,
+	LT_DOCBOOKGENERATETITLE,
 	LT_DOCBOOKWRAPPERTAG,
 	LT_DOCBOOKWRAPPERATTR,
 	LT_DOCBOOKWRAPPERTAGTYPE,
@@ -240,6 +241,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass,
 		{ "docbookabstract",           LT_DOCBOOKABSTRACT },
 		{ "docbookattr",               LT_DOCBOOKATTR },
 		{ "docbookforceabstracttag",   LT_DOCBOOKFORCEABSTRACTTAG },
+		{ "docbookgeneratetitle",      LT_DOCBOOKGENERATETITLE },
 		{ "docbookininfo",             LT_DOCBOOKININFO },
 		{ "docbookinnerattr",          LT_DOCBOOKINNERATTR },
 		{ "docbookinnertag",           LT_DOCBOOKINNERTAG },
@@ -872,6 +874,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass,
             lex >> docbooknofontinside_;
             break;
 
+        case LT_DOCBOOKGENERATETITLE:
+            lex >> docbookgeneratetitle_;
+            break;
+
 		case LT_SPELLCHECK:
 			lex >> spellcheck;
 			break;
diff --git a/src/Layout.h b/src/Layout.h
index 7fc8a7c777..6efc5129f9 100644
--- a/src/Layout.h
+++ b/src/Layout.h
@@ -265,6 +265,8 @@ public:
 	///
 	bool docbooknofontinside() const { return docbooknofontinside_; }
 	///
+	bool docbookgeneratetitle() const { return docbookgeneratetitle_; }
+	///
 	bool isParagraph() const { return latextype == LATEX_PARAGRAPH; }
 	///
 	bool isCommand() const { return latextype == LATEX_COMMAND; }
@@ -587,10 +589,14 @@ private:
 	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
+	/// held by this attribute.
 	mutable std::string docbookforceabstracttag_;
 	/// Whether font tags are allowed inside this tag.
 	bool docbooknofontinside_ = false;
+	/// Whether LyX should create a title on its own, just after the wrapper tag. Typically, this parameter is required
+	/// because the wrapper tag requires a title (like a figure). The generated title will be similar to a LyXHTML label
+	/// (environment type and a number).
+	bool docbookgeneratetitle_ = false;
 	/// Should we generate the default CSS for this layout, even if HTMLStyle
 	/// has been given? Default is false.
 	/// Note that the default CSS is output first, then the user CSS, so it is
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index 8973eb0643..56054180a0 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -59,7 +59,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 = 98; // rikiheck: HTMLClass for InsetLayout
+int const LAYOUT_FORMAT = 99; // tcuvelier: add docbookgeneratetitle
 
 
 // Layout format for the current lyx file format. Controls which format is
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 5e1f6d12cf..c80a7cdb91 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -200,9 +200,18 @@ void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar
 	}
 
 	// Main logic.
-	if (openWrapper)
+	if (openWrapper) {
 		xml::openTag(xs, lay.docbookwrappertag(), lay.docbookwrapperattr(), lay.docbookwrappertagtype());
 
+		if (lay.docbookgeneratetitle()) {
+			docstring const label = par->params().labelString();
+
+			xml::openTag(xs, "title", "", "paragraph");
+			xs << (!label.empty() ? label : from_ascii("No title"));
+			xml::closeTag(xs, "title", "paragraph");
+		}
+	}
+
 	const string & tag = lay.docbooktag();
 	if (tag != "NONE") {
 		auto xmltag = xml::ParTag(tag, lay.docbookattr());
@@ -508,7 +517,9 @@ void makeEnvironment(Text const &text,
 		std::vector<docstring> pars_prepend;
         std::vector<docstring> pars;
         std::vector<docstring> pars_append;
-        tie(pars_prepend, pars, pars_append) = par->simpleDocBookOnePar(buf, runparams, text.outerFont(std::distance(text.paragraphs().begin(), par)), 0, false, ignoreFonts);
+        tie(pars_prepend, pars, pars_append) =
+				par->simpleDocBookOnePar(buf, runparams, text.outerFont(std::distance(text.paragraphs().begin(), par)),
+										 0, false, ignoreFonts);
 
         for (docstring const & parXML : pars_prepend)
             xs << XMLStream::ESCAPE_NONE << parXML;
-- 
2.30.1.windows.1

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to