[LyX/master] DocBook: several missing features for Additional.lyx.

Thibaut Cuvelier tcuvelier at lyx.org
Sat Sep 19 18:18:56 UTC 2020


commit e3da8b65f644df5d7de79c233187144825b9e7f1
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.
---
 autotests/export/docbook/Additional_lyxcode.lyx |  371 +++++++++++++++++++++++
 autotests/export/docbook/Additional_lyxcode.xml |   40 +++
 lib/layouts/logicalmkup.module                  |    9 +
 lib/layouts/stdinsets.inc                       |   36 +++
 src/insets/InsetBox.cpp                         |   18 ++
 src/insets/InsetLayout.cpp                      |   20 ++
 src/insets/InsetLayout.h                        |   16 +
 src/output_docbook.cpp                          |    4 +
 8 files changed, 514 insertions(+), 0 deletions(-)

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..fd2b75e 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
+	DocBookWrapperTag     keycombo
+	DocBookWrapperTagType inline
+	DocBookTag            keycap
+	DocBookTagType        inline
 End
 
 InsetLayout Info:shortcuts
@@ -643,6 +675,10 @@ InsetLayout Info:shortcuts
 	HTMLStyle
 		span.shortcuts { font-family: sans-serif; }
 	EndHTMLStyle
+	DocBookWrapperTag     keycombo
+	DocBookWrapperTagType inline
+	DocBookTag            keycap
+	DocBookTagType        inline
 End
 
 InsetLayout Caption:Standard
diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp
index c61efe6..db76f53 100644
--- a/src/insets/InsetBox.cpp
+++ b/src/insets/InsetBox.cpp
@@ -717,7 +717,25 @@ int InsetBox::plaintext(odocstringstream & os,
 
 void InsetBox::docbook(XMLStream & xs, OutputParams const & runparams) const
 {
+	if (!getLayout().docbookwrappertag().empty()) {
+		if (!xs.isLastTagCR())
+			xs << xml::CR();
+
+		xs << xml::StartTag(getLayout().docbookwrappertag(), getLayout().docbookwrapperattr());
+		xs << xml::CR();
+	} else {
+		LYXERR0("Assertion failed: box layout " + getLayout().name() + " missing DocBookWrapperTag.");
+	}
+
 	InsetText::docbook(xs, runparams);
+
+	if (!getLayout().docbookwrappertag().empty()) {
+		if (!xs.isLastTagCR())
+			xs << xml::CR();
+
+		xs << xml::EndTag(getLayout().docbookwrappertag());
+		xs << xml::CR();
+	}
 }
 
 
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index ce0d25a..d758a1c 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -110,7 +110,11 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
 		IL_HTMLSTYLE,
 		IL_HTMLPREAMBLE,
 		IL_DOCBOOKTAG,
+		IL_DOCBOOKTAGTYPE,
 		IL_DOCBOOKATTR,
+		IL_DOCBOOKWRAPPERTAG,
+		IL_DOCBOOKWRAPPERTAGTYPE,
+		IL_DOCBOOKWRAPPERATTR,
 		IL_INTOC,
 		IL_ISTOCCAPTION,
 		IL_LABELFONT,
@@ -157,6 +161,10 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
 		{ "display", IL_DISPLAY },
 		{ "docbookattr", IL_DOCBOOKATTR },
 		{ "docbooktag", IL_DOCBOOKTAG },
+		{ "docbooktagtype", IL_DOCBOOKTAGTYPE },
+		{ "docbookwrapperattr", IL_DOCBOOKWRAPPERATTR },
+		{ "docbookwrappertag", IL_DOCBOOKWRAPPERTAG },
+		{ "docbookwrappertagtype", IL_DOCBOOKWRAPPERTAGTYPE },
 		{ "editexternal", IL_EDITEXTERNAL },
 		{ "end", IL_END },
 		{ "fixedwidthpreambleencoding", IL_FIXEDWIDTH_PREAMBLE_ENCODING },
@@ -500,9 +508,21 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
 		case IL_DOCBOOKTAG:
 			lex >> docbooktag_;
 			break;
+		case IL_DOCBOOKTAGTYPE:
+			lex >> docbooktagtype_;
+			break;
 		case IL_DOCBOOKATTR:
 			lex >> docbookattr_;
 			break;
+		case IL_DOCBOOKWRAPPERTAG:
+			lex >> docbookwrappertag_;
+			break;
+		case IL_DOCBOOKWRAPPERTAGTYPE:
+			lex >> docbookwrappertagtype_;
+			break;
+		case IL_DOCBOOKWRAPPERATTR:
+			lex >> docbookwrapperattr_;
+			break;
 		case IL_REQUIRES: {
 			lex.eatLine();
 			vector<string> const req
diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h
index 00e3ba6..f11071f 100644
--- a/src/insets/InsetLayout.h
+++ b/src/insets/InsetLayout.h
@@ -150,8 +150,16 @@ public:
 	///
 	std::string docbooktag() const { return docbooktag_; }
 	///
+	std::string docbooktagtype() const { return docbooktagtype_; }
+	///
 	std::string docbookattr() const { return docbookattr_; }
 	///
+	std::string docbookwrappertag() const { return docbookwrappertag_; }
+	///
+	std::string docbookwrappertagtype() const { return docbookwrappertagtype_; }
+	///
+	std::string docbookwrapperattr() const { return docbookwrapperattr_; }
+	///
 	std::set<std::string> required() const { return required_; }
 	///
 	bool isMultiPar() const { return multipar_; }
@@ -281,8 +289,16 @@ private:
 	///
 	std::string docbooktag_;
 	///
+	std::string docbooktagtype_;
+	///
 	std::string docbookattr_;
 	///
+	std::string docbookwrappertag_;
+	///
+	std::string docbookwrappertagtype_;
+	///
+	std::string docbookwrapperattr_;
+	///
 	std::set<std::string> required_;
 	///
 	bool multipar_;
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index cf3873b..1f17351 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -493,6 +493,10 @@ void makeParagraph(
 		// Listings should not get into their own paragraph.
 		if (!special_case && firstInset->lyxCode() == lyx::LISTINGS_CODE)
 			special_case = true;
+
+		// Boxes cannot get into their own paragraph.
+		if (!special_case && firstInset->lyxCode() == lyx::BOX_CODE)
+			special_case = true;
 	}
 
 	bool const open_par = runparams.docbook_make_pars


More information about the lyx-cvs mailing list