commit f2b7f8a089a8117904ccfc6c41074b6938b224bd
Author: Thibaut Cuvelier <[email protected]>
Date:   Thu Oct 22 06:28:46 2020 +0200

    DocBook: generate chapter metadata in <info>, for Springer mono.
---
 autotests/export/docbook/svmono_light.lyx |   45 +++++++-------
 autotests/export/docbook/svmono_light.xml |   25 +++-----
 lib/layouts/svcommon.inc                  |    3 +
 src/output_docbook.cpp                    |   99 ++++++++++++++++++++++-------
 4 files changed, 110 insertions(+), 62 deletions(-)

diff --git a/autotests/export/docbook/svmono_light.lyx 
b/autotests/export/docbook/svmono_light.lyx
index 7f6a67c..36bef6e 100644
--- a/autotests/export/docbook/svmono_light.lyx
+++ b/autotests/export/docbook/svmono_light.lyx
@@ -104,6 +104,10 @@
 
 \begin_body
 
+\begin_layout Standard
+\begin_inset Note Note
+status collapsed
+
 \begin_layout Author
 Author name(s)
 \end_layout
@@ -116,9 +120,9 @@ Book title
 
 \end_layout
 
-\begin_layout Standard
+\begin_layout Plain Layout
 \begin_inset Note Note
-status open
+status collapsed
 
 \begin_layout Preface
 
@@ -154,10 +158,15 @@ author or editor
 
 \end_layout
 
-\begin_layout Standard
+\begin_layout Plain Layout
 
 \end_layout
 
+\begin_layout Plain Layout
+\noindent
+\begin_inset Note Note
+status collapsed
+
 \begin_layout PartBacktext
 \noindent
 \begin_inset Argument 1
@@ -173,6 +182,16 @@ Part Title
  page) on its verso page.
 \end_layout
 
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
 \begin_layout Chapter
 Chapter Heading
 \begin_inset CommandInset label
@@ -186,16 +205,6 @@ name "chap:intro"
 
 \begin_layout Running Chapter
 chapter heading in the running head
-\begin_inset Note Note
-status open
-
-\begin_layout Plain Layout
-optional
-\end_layout
-
-\end_inset
-
-
 \end_layout
 
 \begin_layout Abstract*
@@ -315,16 +324,6 @@ name "sec:Section-Heading"
 
 \begin_layout Running Section
 section heading in the running head
-\begin_inset Note Note
-status open
-
-\begin_layout Plain Layout
-optional
-\end_layout
-
-\end_inset
-
-
 \end_layout
 
 \begin_layout Standard
diff --git a/autotests/export/docbook/svmono_light.xml 
b/autotests/export/docbook/svmono_light.xml
index 8709b0d..6b8b689 100644
--- a/autotests/export/docbook/svmono_light.xml
+++ b/autotests/export/docbook/svmono_light.xml
@@ -2,32 +2,24 @@
 <!-- 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>Book title</title>
-<author>
-<personname>Author name(s)</personname>
-</author>
-</info>
-<part>
-<!-- par --><title>Part Title</title>
- Part title page and, if desired, a short introductory text (maximum one page) 
on its verso page.</part>
+<title>Untitled Document</title>
 <chapter xml:id="chap.intro">
 <title>Chapter Heading</title>
-</chapter>
+<info>
 <titleabbrev>chapter heading in the running head</titleabbrev>
 <abstract role='not-printed'>
-<para>Each chapter should be preceded by an abstract (10–15 lines long) that 
summarizes the content. The abstract will appear <emphasis>online at <link 
xlink:href="www.SpringerLink.com">www.SpringerLink.com</link> and be available 
with unrestricted access. This allows unregistered users to read the abstract 
as a teaser for the complete chapter. As a general rule the abstracts will not 
appear in the printed version of your book unless it is the style of your 
particular book or that of the series to which your book 
belongs.</emphasis><!-- \indent -->
+<para>Each chapter should be preceded by an abstract (10–15 lines long) that 
summarizes the content. The abstract will appear <emphasis>online at  and be 
available with unrestricted access. This allows unregistered users to read the 
abstract as a teaser for the complete chapter. As a general rule the abstracts 
will not appear in the printed version of your book unless it is the style of 
your particular book or that of the series to which your book 
belongs.</emphasis><!-- \indent -->
  Please use the 'starred' version of the <code>abstract</code> environment for 
typesetting the text of the online abstracts. Use the plain 
<code>abstract</code> if the abstract is also to appear in the printed version 
of the book.</para>
 </abstract>
 <abstract>
-<para>Each chapter should be preceded by an abstract (10–15 lines long) that 
summarizes the content. The abstract will appear <emphasis>online at <link 
xlink:href="www.SpringerLink.com">www.SpringerLink.com</link> and be available 
with unrestricted access. This allows unregistered users to read the abstract 
as a teaser for the complete chapter. As a general rule the abstracts will not 
appear in the printed version of your book unless it is the style of your 
particular book or that of the series to which your book 
belongs.</emphasis><!-- \indent -->
+<para>Each chapter should be preceded by an abstract (10–15 lines long) that 
summarizes the content. The abstract will appear <emphasis>online at  and be 
available with unrestricted access. This allows unregistered users to read the 
abstract as a teaser for the complete chapter. As a general rule the abstracts 
will not appear in the printed version of your book unless it is the style of 
your particular book or that of the series to which your book 
belongs.</emphasis><!-- \indent -->
  Please use the 'starred' version of the <code>abstract</code> environment for 
typesetting the text of the online abstracts. Use the plain 
<code>abstract</code> if the abstract is also to appear in the printed version 
of the book.</para>
 </abstract>
+</info>
 <section xml:id="sec.Section-Heading">
 <title>Section Heading</title>
-</section>
 <titleabbrev>section heading in the running head</titleabbrev>
-<para>bla</para>
+</section>
 <section xml:id="sec.Section-Heading-2">
 <title>Section Heading 2</title>
 <para>Instead of simply listing headings of different levels we recommend to 
let every heading be followed by at least a short passage of text.</para>
@@ -42,9 +34,7 @@
  </m:mrow>
  </m:math>
 </informalequation>
- however, for multiline equations we recommend to use the <emphasis 
role='sans'>eqnarray</emphasis> environment<footnote>
-<para>In physics texts please activate the class option <code>vecphys</code> 
to depict your vectors in <emphasis 
role='bold'><emphasis>boldface-italic</emphasis> type - as is customary for a 
wide range of physical subjects.</emphasis></para>
-</footnote>. 
+ however, for multiline equations we recommend to use the <emphasis 
role='sans'>eqnarray</emphasis> environment. 
 <informalequation xml:id="eq.01">
 <alt role='tex'>a\times b &amp; = &amp; c\nonumber \\
 \vec{a}\cdot\vec{b} &amp; = &amp; c\label{eq:01}
@@ -85,4 +75,5 @@
 </informalequation>
 </para>
 </section>
+</chapter>
 </book>
\ No newline at end of file
diff --git a/lib/layouts/svcommon.inc b/lib/layouts/svcommon.inc
index 669361f..0bc1f36 100644
--- a/lib/layouts/svcommon.inc
+++ b/lib/layouts/svcommon.inc
@@ -433,6 +433,7 @@ Style Running_Title
        LabelString     "Running title:"
        DocBookTag            titleabbrev
        DocBookTagType        paragraph
+       DocBookInInfo         maybe
 End
 
 Style Running_Author
@@ -450,6 +451,7 @@ Style Running_Chapter
        LabelString     "Running chapter:"
        DocBookTag            titleabbrev
        DocBookTagType        paragraph
+       DocBookInInfo         maybe
        DocBookSection        false
 End
 
@@ -459,6 +461,7 @@ Style Running_Section
        LabelString     "Running section:"
        DocBookTag            titleabbrev
        DocBookTagType        paragraph
+       DocBookInInfo         maybe
 End
 
 Style Abstract
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 59df193..23d4db8 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -782,8 +782,14 @@ bool hasOnlyNotes(Paragraph const & par)
 
 DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs,
                                                                         
pit_type bpit, pit_type const epit,
-                                                                        // 
Typically, bpit is the beginning of the document and epit the end *or* the 
first section.
-                                                                        bool 
documentHasSections) {
+                                                                        // 
Typically, bpit is the beginning of the document and epit the end of the
+                                                                        // 
document *or* the first section.
+                                                                        bool 
documentHasSections,
+                                                                        bool 
detectUnlayoutedAbstract
+                                                                        // 
Whether paragraphs with no specific layout should be detected as abstracts.
+                                                                        // For 
inner sections, an abstract should only be detected if it has a specific
+                                                                        // 
layout. For others, anything that might look like an abstract should be sought.
+                                                                        ) {
        set<pit_type> shouldBeInInfo;
        set<pit_type> mustBeInInfo;
        set<pit_type> abstractWithLayout;
@@ -804,7 +810,8 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const 
&paragraphs,
        for (; cpit < epit; ++cpit) {
                // Skip paragraphs that don't generate anything in DocBook.
                Paragraph const & par = paragraphs[cpit];
-               if (hasOnlyNotes(par))
+               Layout const &style = par.layout();
+               if (hasOnlyNotes(par) || style.docbookininfo() == "never")
                        continue;
 
                // There should never be any section here. (Just a sanity 
check: if this fails, this function could end up
@@ -815,7 +822,7 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const 
&paragraphs,
                }
 
                // If this is marked as an abstract by the layout, put it in 
the right set.
-               if (par.layout().docbookabstract()) {
+               if (style.docbookabstract()) {
                        hasAbstractLayout = true;
                        abstractWithLayout.emplace(cpit);
                        continue;
@@ -823,13 +830,11 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const 
&paragraphs,
 
                // Based on layout information, store this paragraph in one 
set: should be in <info>, must be,
                // or abstract (either because of layout or of position).
-               Layout const &style = par.layout();
-
                if (style.docbookininfo() == "always")
                        mustBeInInfo.emplace(cpit);
                else if (style.docbookininfo() == "maybe")
                        shouldBeInInfo.emplace(cpit);
-               else if (documentHasSections && !hasAbstractLayout)
+               else if (documentHasSections && !hasAbstractLayout && 
detectUnlayoutedAbstract)
                        abstractNoLayout.emplace(cpit);
                else // This should definitely not be in <info>.
                        break;
@@ -991,7 +996,7 @@ void docbookSimpleAllParagraphs(
        ParagraphList const &paragraphs = text.paragraphs();
 
        // First, the <info> tag.
-       DocBookInfoTag info = getParagraphsWithInfo(paragraphs, bpit, epit, 
false);
+       DocBookInfoTag info = getParagraphsWithInfo(paragraphs, bpit, epit, 
false, true);
        outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
 
        // Then, the content. It starts where the <info> ends.
@@ -1039,7 +1044,7 @@ void docbookParagraphs(Text const &text,
        }
 
        // Output the first <info> tag (or just the title).
-       DocBookInfoTag info = getParagraphsWithInfo(paragraphs, bpit, eppit, 
true);
+       DocBookInfoTag info = getParagraphsWithInfo(paragraphs, bpit, eppit, 
true, true);
        outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
        bpit = info.epit;
 
@@ -1134,27 +1139,77 @@ void docbookParagraphs(Text const &text,
                // Generate this paragraph.
                par = makeAny(text, buf, xs, ourparams, par);
 
-               // Some special sections may require abstracts (mostly parts, 
in books).
+               // Some sections may require abstracts (mostly parts, in books: 
DocBookForceAbstractTag will not be NONE),
+               // others can still have an abstract (it must be detected so 
that it can be output at the right place).
                // TODO: docbookforceabstracttag is a bit contrived here, but 
it does the job. Having another field just for this would be cleaner, but 
that's just for <part> and <partintro>, so it's probably not worth the effort.
-               if (isLayoutSectioning(style) && 
style.docbookforceabstracttag() != "NONE") {
+               if (isLayoutSectioning(style)) {
                        // This abstract may be found between the next 
paragraph and the next title.
                        pit_type cpit = 
std::distance(text.paragraphs().begin(), par);
                        pit_type ppit = 
std::get<1>(hasDocumentSectioning(paragraphs, cpit, epit));
 
                        // Generate this abstract (this code corresponds to 
parts of outputDocBookInfo).
-                       DocBookInfoTag secInfo = 
getParagraphsWithInfo(paragraphs, cpit, ppit, true);
+                       DocBookInfoTag secInfo = 
getParagraphsWithInfo(paragraphs, cpit, ppit, true,
+                                                                               
                  style.docbookforceabstracttag() != "NONE");
+
+                       if (!secInfo.mustBeInInfo.empty() || 
!secInfo.shouldBeInInfo.empty() || !secInfo.abstract.empty()) {
+                               // Generate the <info>, if required. If 
DocBookForceAbstractTag != NONE, this abstract will not be in
+                               // <info>, unlike other ("standard") abstracts.
+                               bool hasStandardAbstract = 
!secInfo.abstract.empty() && style.docbookforceabstracttag() == "NONE";
+                               bool needInfo = !secInfo.mustBeInInfo.empty() 
|| hasStandardAbstract;
+
+                               if (needInfo) {
+                                       xs.startDivision(false);
+                                       xs << xml::StartTag("info");
+                                       xs << xml::CR();
+                               }
 
-                       if (!secInfo.abstract.empty()) {
-                               xs << 
xml::StartTag(style.docbookforceabstracttag());
-                               xs << xml::CR();
-                               for (auto const &p : secInfo.abstract)
-                                       makeAny(text, buf, xs, runparams, 
paragraphs.iterator_at(p));
-                               xs << 
xml::EndTag(style.docbookforceabstracttag());
-                               xs << xml::CR();
-                       }
+                               // Output the elements that should go in 
<info>, before and after the abstract.
+                               for (auto pit : secInfo.shouldBeInInfo) // 
Typically, the title: these elements are so important and ubiquitous
+                                       // that mandating a wrapper like <info> 
would repel users. Thus, generate them first.
+                                       makeAny(text, buf, xs, runparams, 
paragraphs.iterator_at(pit));
+                               for (auto pit : secInfo.mustBeInInfo)
+                                       makeAny(text, buf, xs, runparams, 
paragraphs.iterator_at(pit));
+
+                               // Deal with the abstract in <info> if it is 
standard (i.e. its tag is <abstract>).
+                               if (!secInfo.abstract.empty() && 
hasStandardAbstract) {
+                                       if (!secInfo.abstractLayout) {
+                                               xs << xml::StartTag("abstract");
+                                               xs << xml::CR();
+                                       }
+
+                                       for (auto const &p : secInfo.abstract)
+                                               makeAny(text, buf, xs, 
runparams, paragraphs.iterator_at(p));
+
+                                       if (!secInfo.abstractLayout) {
+                                               xs << xml::EndTag("abstract");
+                                               xs << xml::CR();
+                                       }
+                               }
 
-                       // Skip all the text that just has been generated.
-                       par = paragraphs.iterator_at(ppit);
+                               // End the <info> tag if it was started.
+                               if (needInfo) {
+                                       if (!xs.isLastTagCR())
+                                               xs << xml::CR();
+
+                                       xs << xml::EndTag("info");
+                                       xs << xml::CR();
+                                       xs.endDivision();
+                               }
+
+                               // Deal with the abstract outside <info> if it 
is not standard (i.e. its tag is layout-defined).
+                               if (!secInfo.abstract.empty() && 
!hasStandardAbstract) {
+                                       // Assert: 
style.docbookforceabstracttag() != NONE.
+                                       xs << 
xml::StartTag(style.docbookforceabstracttag());
+                                       xs << xml::CR();
+                                       for (auto const &p : secInfo.abstract)
+                                               makeAny(text, buf, xs, 
runparams, paragraphs.iterator_at(p));
+                                       xs << 
xml::EndTag(style.docbookforceabstracttag());
+                                       xs << xml::CR();
+                               }
+
+                               // Skip all the text that just has been 
generated.
+                               par = paragraphs.iterator_at(ppit);
+                       }
                }
        }
 
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to