diff --git a/autotests/export/docbook/subfigures_EmbeddedObjects.lyx b/autotests/export/docbook/subfigures_EmbeddedObjects.lyx
new file mode 100644
index 0000000000..0154d2119d
--- /dev/null
+++ b/autotests/export/docbook/subfigures_EmbeddedObjects.lyx
@@ -0,0 +1,444 @@
+#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
+% that links to image floats jumps
+% to the beginning of the float and
+% not to its caption
+\usepackage[figure]{hypcap}
+
+% the pages of the TOC are numbered roman
+% and a PDF-bookmark for the TOC is added
+\let\myTOC\tableofcontents
+\renewcommand\tableofcontents{%
+ \frontmatter
+ \pdfbookmark[1]{\contentsname}{}
+ \myTOC
+ \mainmatter }
+
+% provides caption formatting
+\usepackage[labelfont={bf,sf}]{caption}[2004/07/16]
+
+% provides commands to set caption
+% beside tables/images
+\newcommand{\TabBesBeg}[1][1.0]{%
+ \let\MyTable\table
+ \let\MyEndtable\endtable
+ \renewenvironment{table}[1]{\begin{SCtable}[#1]##1}{\end{SCtable}}}
+
+\newcommand{\TabBesEnd}{%
+ \let\table\MyTable
+ \let\endtable\MyEndtable}
+
+\newcommand{\FigBesBeg}[1][1.0]{%
+ \let\MyFigure\figure
+ \let\MyEndfigure\endfigure
+ \renewenvironment{figure}[1]{\begin{SCfigure}[#1]##1}{\end{SCfigure}}}
+
+\newcommand{\FigBesEnd}{%
+ \let\figure\MyFigure
+ \let\endfigure\MyEndfigure}
+
+% enables calculation of values,
+\usepackage{calc}
+
+% increase the bottom float placement fraction
+\renewcommand{\bottomfraction}{0.5}
+
+% avoids that floats are placed before their
+% corresponding section starts
+\let\mySection\section\renewcommand{\section}{\suppressfloats[t]\mySection}
+
+% speed up the longtable calculation
+\setcounter{LTchunksize}{100}
+
+% used for colored tables
+\@ifundefined{textcolor}
+ {\usepackage{color}}{}
+\definecolor{darkgreen}{cmyk}{0.5, 0, 1, 0.5}
+\definecolor{lightgrey}{gray}{0.8}
+
+% check for package colortbl
+% used for colored table cells
+\newboolean{colortbl}
+\IfFileExists{colortbl.sty}
+ {\usepackage{colortbl}
+ \setboolean{colortbl}{true}}
+ {\setboolean{colortbl}{false}}
+
+% used to have extra space in table cells
+\@ifundefined{extrarowheight}
+ {\usepackage{array}}{}
+\setlength{\extrarowheight}{2pt}
+
+% used for customized tables
+% ---
+\newcolumntype{M}[1]
+ {>{\centering\hspace{0pt}}m{#1}}
+
+\newcolumntype{S}[2]
+ {>{\centering\hspace{0pt}}m{(#1+(2\tabcolsep+\arrayrulewidth)*(1-#2))/#2}}
+
+\newcolumntype{K}[1]
+ {>{\columncolor{#1}\hspace{0pt}}c}
+
+\newcolumntype{V}{!{\vrule width 1.5pt}}
+
+\newcolumntype{W}{!{\color{green}\vline}}
+% ---
+
+% insert additional vertical space of
+% 1.5 mm between footnotes
+\let\myFoot\footnote
+\renewcommand{\footnote}[1]{\myFoot{#1\vspace{1.5mm}}}
+
+% number algorithm floats within chapters
+\numberwithin{algorithm}{chapter}
+
+% ------------------------------------
+% used to check for needed LaTeX packages
+\usepackage{ifthen}
+
+% check for package arydshln
+% used for tables with dashed lines
+\newboolean{arydshln}
+\IfFileExists{arydshln.sty}
+ {\usepackage{arydshln}
+ \setboolean{arydshln}{true}}
+ {\setboolean{arydshln}{false}}
+
+% check for package marginnote
+% used for margin notes
+\newboolean{marginnote}
+\IfFileExists{marginnote.sty}
+ {\usepackage{marginnote}
+ \let\marginpar\marginnote
+ \setboolean{marginnote}{true}}
+ {\setboolean{marginnote}{false}}
+
+% check for package sidecap
+% used for captions on the side
+\newboolean{sidecap}
+\IfFileExists{sidecap.sty}
+ {\usepackage{sidecap}
+ \setboolean{sidecap}{true}}
+ {\setboolean{sidecap}{false}}
+
+% check for picinpar
+% used for surrounded fixed objects
+\newboolean{picinpar}
+\IfFileExists{picinpar.sty}
+ {\usepackage{picinpar}
+ \setboolean{picinpar}{true}}
+ {\setboolean{picinpar}{false}}
+
+% check for lettrine
+\newboolean{lettrine}
+\IfFileExists{lettrine.sty}
+ {\usepackage{lettrine}
+ \setboolean{lettrine}{true}}
+ {\setboolean{lettrine}{false}}
+
+% check for diagbox
+\newboolean{diagbox}
+\IfFileExists{diagbox.sty}
+ {\usepackage{diagbox}
+ \setboolean{diagbox}{true}}
+ {\setboolean{diagbox}{false}}
+% Added by lyx2lyx
+\setlength{\parskip}{\medskipamount}
+\setlength{\parindent}{0pt}
+\end_preamble
+\options bibliography=totoc,index=totoc,BCOR7.5mm,titlepage,captions=tableheading,dvipsnames,table
+\use_default_options false
+\begin_modules
+initials
+graphicboxes
+varwidth
+\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 makeindex
+\paperfontsize 12
+\spacing single
+\use_hyperref true
+\pdf_title "LyX's Figure, Table, Floats, Notes, and Boxes manual"
+\pdf_author "LyX Team, Uwe Stöhr"
+\pdf_subject "LyX-documentation about figures, tables, floats, notes, and boxes"
+\pdf_keywords "LyX, Tables, Figures, Floats, Boxes, Notes"
+\pdf_bookmarks true
+\pdf_bookmarksnumbered true
+\pdf_bookmarksopen true
+\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 default
+\use_geometry false
+\use_package amsmath 1
+\use_package amssymb 1
+\use_package cancel 1
+\use_package esint 1
+\use_package mathdots 1
+\use_package mathtools 1
+\use_package mhchem 1
+\use_package stackrel 1
+\use_package stmaryrd 1
+\use_package undertilde 1
+\cite_engine basic
+\cite_engine_type default
+\biblio_style plain
+\use_bibtopic false
+\use_indices false
+\paperorientation portrait
+\suppress_date false
+\justification true
+\use_refstyle 0
+\use_minted 0
+\use_lineno 0
+\notefontcolor #0000ff
+\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 2
+\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
+\SpecialChar LyX
+'s detailed Figure, Table, Floats, Notes, Boxes and External Material manual
+\end_layout
+
+\begin_layout Chapter
+Figures
+\end_layout
+
+\begin_layout Section
+Figure Floats
+\end_layout
+
+\begin_layout Standard
+Normally only one image is inserted to a figure float, but sometimes you
+ might want to use two images with separate subcaptions.
+ This can be done by inserting image floats into existing image floats.
+ Note that only the main caption of the float is added to the List of Figures.
+ Figure
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "fig:Two-distorted-images"
+
+\end_inset
+
+ is an example of a figure float with two images set side by side.
+ You can also set the images one below the other.
+ Figure
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "fig:Pink-object"
+
+\end_inset
+
+ and
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "fig:A-star"
+
+\end_inset
+
+ are the subfigures.
+\end_layout
+
+\begin_layout Standard
+\begin_inset Float figure
+placement document
+alignment document
+wide false
+sideways false
+status open
+
+\begin_layout Plain Layout
+\begin_inset space \hfill{}
+\end_inset
+
+
+\begin_inset Float figure
+placement document
+alignment document
+wide false
+sideways false
+status open
+
+\begin_layout Plain Layout
+\begin_inset Caption Standard
+
+\begin_layout Plain Layout
+\begin_inset CommandInset label
+LatexCommand label
+name "fig:Pink-object"
+
+\end_inset
+
+Pink object.
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Graphics
+ filename ../../../lib/doc/clipart/3D-structure-distort.pdf
+ width 45col%
+ scaleBeforeRotation
+ groupId distorted
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\begin_inset space \hfill{}
+\end_inset
+
+
+\begin_inset Float figure
+placement document
+alignment document
+wide false
+sideways false
+status open
+
+\begin_layout Plain Layout
+\begin_inset Caption Standard
+
+\begin_layout Plain Layout
+\begin_inset CommandInset label
+LatexCommand label
+name "fig:A-star"
+
+\end_inset
+
+A star.
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Graphics
+ filename ../../../lib/doc/clipart/Star-structure.pdf
+ width 45col%
+ scaleBeforeRotation
+ groupId distorted
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\begin_inset space \hfill{}
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Caption Standard
+
+\begin_layout Plain Layout
+\begin_inset CommandInset label
+LatexCommand label
+name "fig:Two-distorted-images"
+
+\end_inset
+
+Two distorted images.
+ Both images are in the image settings group named
+\begin_inset Quotes eld
+\end_inset
+
+distorted
+\begin_inset Quotes erd
+\end_inset
+
+.
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_body
+\end_document
diff --git a/autotests/export/docbook/subfigures_EmbeddedObjects.xml b/autotests/export/docbook/subfigures_EmbeddedObjects.xml
new file mode 100644
index 0000000000..08fda0446d
--- /dev/null
+++ b/autotests/export/docbook/subfigures_EmbeddedObjects.xml
@@ -0,0 +1,32 @@
+
+
+
+LyX's detailed Figure, Table, Floats, Notes, Boxes and External Material manual
+
+Figures
+
+Figure Floats
+Normally only one image is inserted to a figure float, but sometimes you might want to use two images with separate subcaptions. This can be done by inserting image floats into existing image floats. Note that only the main caption of the float is added to the List of Figures. Figure is an example of a figure float with two images set side by side. You can also set the images one below the other. Figure and are the subfigures.
+
+Two distorted images. Both images are in the image settings group named “distorted”.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/autotests/export/docbook/subfigures_boxes_EmbeddedObjects.lyx b/autotests/export/docbook/subfigures_boxes_EmbeddedObjects.lyx
new file mode 100644
index 0000000000..da41aa331d
--- /dev/null
+++ b/autotests/export/docbook/subfigures_boxes_EmbeddedObjects.lyx
@@ -0,0 +1,420 @@
+#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
+% that links to image floats jumps
+% to the beginning of the float and
+% not to its caption
+\usepackage[figure]{hypcap}
+
+% the pages of the TOC are numbered roman
+% and a PDF-bookmark for the TOC is added
+\let\myTOC\tableofcontents
+\renewcommand\tableofcontents{%
+ \frontmatter
+ \pdfbookmark[1]{\contentsname}{}
+ \myTOC
+ \mainmatter }
+
+% provides caption formatting
+\usepackage[labelfont={bf,sf}]{caption}[2004/07/16]
+
+% provides commands to set caption
+% beside tables/images
+\newcommand{\TabBesBeg}[1][1.0]{%
+ \let\MyTable\table
+ \let\MyEndtable\endtable
+ \renewenvironment{table}[1]{\begin{SCtable}[#1]##1}{\end{SCtable}}}
+
+\newcommand{\TabBesEnd}{%
+ \let\table\MyTable
+ \let\endtable\MyEndtable}
+
+\newcommand{\FigBesBeg}[1][1.0]{%
+ \let\MyFigure\figure
+ \let\MyEndfigure\endfigure
+ \renewenvironment{figure}[1]{\begin{SCfigure}[#1]##1}{\end{SCfigure}}}
+
+\newcommand{\FigBesEnd}{%
+ \let\figure\MyFigure
+ \let\endfigure\MyEndfigure}
+
+% enables calculation of values,
+\usepackage{calc}
+
+% increase the bottom float placement fraction
+\renewcommand{\bottomfraction}{0.5}
+
+% avoids that floats are placed before their
+% corresponding section starts
+\let\mySection\section\renewcommand{\section}{\suppressfloats[t]\mySection}
+
+% speed up the longtable calculation
+\setcounter{LTchunksize}{100}
+
+% used for colored tables
+\@ifundefined{textcolor}
+ {\usepackage{color}}{}
+\definecolor{darkgreen}{cmyk}{0.5, 0, 1, 0.5}
+\definecolor{lightgrey}{gray}{0.8}
+
+% check for package colortbl
+% used for colored table cells
+\newboolean{colortbl}
+\IfFileExists{colortbl.sty}
+ {\usepackage{colortbl}
+ \setboolean{colortbl}{true}}
+ {\setboolean{colortbl}{false}}
+
+% used to have extra space in table cells
+\@ifundefined{extrarowheight}
+ {\usepackage{array}}{}
+\setlength{\extrarowheight}{2pt}
+
+% used for customized tables
+% ---
+\newcolumntype{M}[1]
+ {>{\centering\hspace{0pt}}m{#1}}
+
+\newcolumntype{S}[2]
+ {>{\centering\hspace{0pt}}m{(#1+(2\tabcolsep+\arrayrulewidth)*(1-#2))/#2}}
+
+\newcolumntype{K}[1]
+ {>{\columncolor{#1}\hspace{0pt}}c}
+
+\newcolumntype{V}{!{\vrule width 1.5pt}}
+
+\newcolumntype{W}{!{\color{green}\vline}}
+% ---
+
+% insert additional vertical space of
+% 1.5 mm between footnotes
+\let\myFoot\footnote
+\renewcommand{\footnote}[1]{\myFoot{#1\vspace{1.5mm}}}
+
+% number algorithm floats within chapters
+\numberwithin{algorithm}{chapter}
+
+% ------------------------------------
+% used to check for needed LaTeX packages
+\usepackage{ifthen}
+
+% check for package arydshln
+% used for tables with dashed lines
+\newboolean{arydshln}
+\IfFileExists{arydshln.sty}
+ {\usepackage{arydshln}
+ \setboolean{arydshln}{true}}
+ {\setboolean{arydshln}{false}}
+
+% check for package marginnote
+% used for margin notes
+\newboolean{marginnote}
+\IfFileExists{marginnote.sty}
+ {\usepackage{marginnote}
+ \let\marginpar\marginnote
+ \setboolean{marginnote}{true}}
+ {\setboolean{marginnote}{false}}
+
+% check for package sidecap
+% used for captions on the side
+\newboolean{sidecap}
+\IfFileExists{sidecap.sty}
+ {\usepackage{sidecap}
+ \setboolean{sidecap}{true}}
+ {\setboolean{sidecap}{false}}
+
+% check for picinpar
+% used for surrounded fixed objects
+\newboolean{picinpar}
+\IfFileExists{picinpar.sty}
+ {\usepackage{picinpar}
+ \setboolean{picinpar}{true}}
+ {\setboolean{picinpar}{false}}
+
+% check for lettrine
+\newboolean{lettrine}
+\IfFileExists{lettrine.sty}
+ {\usepackage{lettrine}
+ \setboolean{lettrine}{true}}
+ {\setboolean{lettrine}{false}}
+
+% check for diagbox
+\newboolean{diagbox}
+\IfFileExists{diagbox.sty}
+ {\usepackage{diagbox}
+ \setboolean{diagbox}{true}}
+ {\setboolean{diagbox}{false}}
+% Added by lyx2lyx
+\setlength{\parskip}{\medskipamount}
+\setlength{\parindent}{0pt}
+\end_preamble
+\options bibliography=totoc,index=totoc,BCOR7.5mm,titlepage,captions=tableheading,dvipsnames,table
+\use_default_options false
+\begin_modules
+initials
+graphicboxes
+varwidth
+\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 makeindex
+\paperfontsize 12
+\spacing single
+\use_hyperref true
+\pdf_title "LyX's Figure, Table, Floats, Notes, and Boxes manual"
+\pdf_author "LyX Team, Uwe Stöhr"
+\pdf_subject "LyX-documentation about figures, tables, floats, notes, and boxes"
+\pdf_keywords "LyX, Tables, Figures, Floats, Boxes, Notes"
+\pdf_bookmarks true
+\pdf_bookmarksnumbered true
+\pdf_bookmarksopen true
+\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 default
+\use_geometry false
+\use_package amsmath 1
+\use_package amssymb 1
+\use_package cancel 1
+\use_package esint 1
+\use_package mathdots 1
+\use_package mathtools 1
+\use_package mhchem 1
+\use_package stackrel 1
+\use_package stmaryrd 1
+\use_package undertilde 1
+\cite_engine basic
+\cite_engine_type default
+\biblio_style plain
+\use_bibtopic false
+\use_indices false
+\paperorientation portrait
+\suppress_date false
+\justification true
+\use_refstyle 0
+\use_minted 0
+\use_lineno 0
+\notefontcolor #0000ff
+\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 2
+\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
+\SpecialChar LyX
+'s detailed Figure, Table, Floats, Notes, Boxes and External Material manual
+\end_layout
+
+\begin_layout Chapter
+Floats
+\end_layout
+
+\begin_layout Section
+Floats Side by Side
+\end_layout
+
+\begin_layout Standard
+To place floats side by side, as in Figures
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "fig:Float-left"
+
+\end_inset
+
+ and
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "fig:Float-right"
+
+\end_inset
+
+, only
+\emph on
+one
+\emph default
+ float is used.
+ In it two minipage boxes are inserted.
+
+\end_layout
+
+\begin_layout Standard
+\begin_inset Float figure
+placement document
+alignment document
+wide false
+sideways false
+status open
+
+\begin_layout Plain Layout
+\begin_inset Box Frameless
+position "b"
+hor_pos "c"
+has_inner_box 1
+inner_pos "t"
+use_parbox 0
+use_makebox 0
+width "45col%"
+special "none"
+height "1in"
+height_special "totalheight"
+thickness "0.4pt"
+separation "3pt"
+shadowsize "4pt"
+framecolor "black"
+backgroundcolor "none"
+status open
+
+\begin_layout Plain Layout
+\align center
+\begin_inset Graphics
+ filename ../../../lib/doc/clipart/2D-intensity-plot.pdf
+ width 100col%
+ scaleBeforeRotation
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Caption Standard
+
+\begin_layout Plain Layout
+\begin_inset CommandInset label
+LatexCommand label
+name "fig:Float-left"
+
+\end_inset
+
+Float on the left side.
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\begin_inset space \hfill{}
+\end_inset
+
+
+\begin_inset Box Frameless
+position "b"
+hor_pos "c"
+has_inner_box 1
+inner_pos "t"
+use_parbox 0
+use_makebox 0
+width "45col%"
+special "none"
+height "1in"
+height_special "totalheight"
+thickness "0.4pt"
+separation "3pt"
+shadowsize "4pt"
+framecolor "black"
+backgroundcolor "none"
+status open
+
+\begin_layout Plain Layout
+\align center
+\begin_inset Graphics
+ filename ../../../lib/doc/clipart/Star-structure.pdf
+ width 100col%
+ scaleBeforeRotation
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Plain Layout
+\begin_inset Caption Standard
+
+\begin_layout Plain Layout
+\begin_inset CommandInset label
+LatexCommand label
+name "fig:Float-right"
+
+\end_inset
+
+Float on the right side.
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_body
+\end_document
diff --git a/autotests/export/docbook/subfigures_boxes_EmbeddedObjects.xml b/autotests/export/docbook/subfigures_boxes_EmbeddedObjects.xml
new file mode 100644
index 0000000000..7f010cf47d
--- /dev/null
+++ b/autotests/export/docbook/subfigures_boxes_EmbeddedObjects.xml
@@ -0,0 +1,32 @@
+
+
+
+LyX's detailed Figure, Table, Floats, Notes, Boxes and External Material manual
+
+Floats
+
+Floats Side by Side
+To place floats side by side, as in Figures and , only one float is used. In it two minipage boxes are inserted.
+
+No caption
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp
index eaa24cb5bd..4e7db11901 100644
--- a/src/insets/InsetFloat.cpp
+++ b/src/insets/InsetFloat.cpp
@@ -566,6 +566,66 @@ const InsetCaption* findCaptionInParagraph(const Paragraph &par)
}
+/// Takes an unstructured subfigure container (typically, an InsetBox) and find the elements within:
+/// actual content (image or table), maybe a caption, maybe a label.
+std::tuple docbookParseHopelessSubfigure(const InsetText * subfigure)
+{
+ InsetCode type = NO_CODE;
+ const Inset * content = nullptr;
+ const InsetCaption * caption = nullptr;
+ const InsetLabel * label = nullptr;
+
+ for (const auto & it : subfigure->paragraphs()) {
+ for (pos_type posIn = 0; posIn < it.size(); ++posIn) {
+ const Inset * inset = it.getInset(posIn);
+ if (inset) {
+ switch (inset->lyxCode()) {
+ case GRAPHICS_CODE:
+ case TABULAR_CODE:
+ if (!content) {
+ content = inset;
+ type = inset->lyxCode();
+ }
+ break;
+ case CAPTION_CODE:
+ if (!caption) {
+ caption = dynamic_cast(inset);
+
+ // A label often hides in a caption. Make a simplified version of the main loop.
+ if (!label) {
+ for (const auto &cit : caption->paragraphs()) {
+ for (pos_type cposIn = 0; cposIn < cit.size(); ++cposIn) {
+ const Inset *cinset = cit.getInset(posIn);
+ if (cinset && cinset->lyxCode() == LABEL_CODE) {
+ label = dynamic_cast(cinset);
+ break;
+ }
+ }
+
+ if (label)
+ break;
+ }
+ }
+ }
+ break;
+ case LABEL_CODE:
+ if (!label)
+ label = dynamic_cast(inset);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ if (content && caption && label)
+ break;
+ }
+
+ return std::make_tuple(type, content, caption, label);
+}
+
+
void docbookSubfigures(XMLStream & xs, OutputParams const & runparams, const InsetCaption * caption,
const InsetLabel * label, std::vector & subfigures)
{
@@ -595,22 +655,27 @@ void docbookSubfigures(XMLStream & xs, OutputParams const & runparams, const Ins
// Deal with each subfigure individually. This should also deal with their caption and their label.
// This should be a recursive call to InsetFloat.
- // An item in subfigure should either be an InsetBox containing an InsetFloat or directly an InsetFloat.
- for (const InsetCollapsible *subfigure: subfigures) {
- // If there is no InsetFloat in the paragraphs, output a warning.
- bool foundInsetFloat = false;
+ // An item in subfigure should either be an InsetBox containing an InsetFloat, or an InsetBox directly containing
+ // an image or a table, or directly an InsetFloat.
+ for (const InsetCollapsible * subfigure: subfigures) {
+ if (subfigure == nullptr)
+ continue;
// The collapsible may already be a float (InsetFloat).
- if (subfigure && dynamic_cast(subfigure))
- foundInsetFloat = true;
+ if (dynamic_cast(subfigure)) {
+ subfigure->docbook(xs, runparams);
+ continue;
+ }
- // Subfigures are in boxes.
- if (!foundInsetFloat) {
+ // Subfigures are in boxes, then in InsetFloat.
+ {
+ bool foundInsetFloat = false;
for (const auto &it : subfigure->paragraphs()) {
for (pos_type posIn = 0; posIn < it.size(); ++posIn) {
const Inset *inset = it.getInset(posIn);
- if (inset && dynamic_cast(inset)) {
+ if (inset && inset->lyxCode() == FLOAT_CODE) {
foundInsetFloat = true;
+ inset->docbook(xs, runparams);
break;
}
}
@@ -618,15 +683,79 @@ void docbookSubfigures(XMLStream & xs, OutputParams const & runparams, const Ins
if (foundInsetFloat)
break;
}
+ if (foundInsetFloat)
+ continue;
}
- if (!foundInsetFloat)
- xs << XMLStream::ESCAPE_NONE << "Error: no float found in the box. "
- "To use subfigures in DocBook, elements must be wrapped in a float "
- "inset and have a title/caption.";
+ // Subfigures are in boxes, then directly an image or a table. In that case, generate the whole content of the
+ // InsetBox, but not the box container.
+ // Impose some model on the subfigure: at most a caption, at most a label, exactly one figure or one table.
+ {
+ InsetCode stype = NO_CODE;
+ const Inset * scontent = nullptr;
+ const InsetCaption * scaption = nullptr;
+ const InsetLabel * slabel = nullptr;
+
+ std::tie(stype, scontent, scaption, slabel) = docbookParseHopelessSubfigure(subfigure);
+
+ // If there is something, generate it. This is very much like docbookNoSubfigures, but many things
+ // must be coded differently because there is no float.
+ // TODO: some code is identical to Floating, like Floating::docbookTag or Floating::docbookCaption. How to reuse that code?
+ if (scontent) {
+ // Floating::docbookCaption()
+ string docbook_caption = "caption"; // This is already correct for tables.
+ if (stype == GRAPHICS_CODE)
+ docbook_caption = "title";
+
+ // Floating::docbookTag() with hasTitle = true, as we are in formalgroup.
+ string stag = "float";
+ if (stype == GRAPHICS_CODE)
+ stag = "figure";
+ else if (stype == TABULAR_CODE)
+ stag = "table";
+
+ // Ensure there is no label output, it is supposed to be handled as xml:id.
+ if (slabel)
+ rpNoLabel.docbook_anchors_to_ignore.emplace(slabel->screenLabel());
+
+ // Ensure the float does not output its caption, as it is handled here (DocBook mandates a specific place for
+ // captions, they cannot appear at the end of the float, albeit LyX is happy with that).
+ OutputParams rpNoTitle = runparams;
+ rpNoTitle.docbook_in_float = true;
+ if (stype == TABULAR_CODE)
+ rpNoTitle.docbook_in_table = true;
+
+ // Organisation: .
+ docstring sattr = docstring();
+ if (slabel)
+ sattr += "xml:id=\"" + xml::cleanID(slabel->screenLabel()) + "\"";
+ // No layout way of adding attributes, unlike the normal code path.
+
+ xs << xml::StartTag(stag, sattr);
+ xs << xml::CR();
+ xs << xml::StartTag(docbook_caption);
+ if (scaption)
+ scaption->getCaptionAsDocBook(xs, rpNoLabel);
+ else // Mandatory in formalgroup.
+ xs << "No caption detected";
+ xs << xml::EndTag(docbook_caption);
+ xs << xml::CR();
+ scontent->docbook(xs, rpNoTitle);
+ xs << xml::EndTag(stag);
+ xs << xml::CR();
+
+ // This subfigure could be generated.
+ continue;
+ }
+ }
+
+ // If there is no InsetFloat in the inset, output a warning.
+ xs << XMLStream::ESCAPE_NONE << "Error: no float found in the box. "
+ "To use subfigures in DocBook, elements must be wrapped in a float "
+ "inset and have a title/caption.";
// TODO: could also output a table, that would ensure that the document is correct and *displays* correctly (but without the right semantics), instead of just an error.
- // Finally, recurse.
+ // Recurse to generate as much content as possible (avoid any loss).
subfigure->docbook(xs, runparams);
}