DocBook: generate chapter metadata in <info>, for Springer mono.

This commit is contained in:
Thibaut Cuvelier 2020-10-22 06:28:46 +02:00
parent b816cb0f3c
commit f2b7f8a089
4 changed files with 110 additions and 62 deletions

View File

@ -104,6 +104,10 @@
\begin_body \begin_body
\begin_layout Standard
\begin_inset Note Note
status collapsed
\begin_layout Author \begin_layout Author
Author name(s) Author name(s)
\end_layout \end_layout
@ -116,9 +120,9 @@ Book title
\end_layout \end_layout
\begin_layout Standard \begin_layout Plain Layout
\begin_inset Note Note \begin_inset Note Note
status open status collapsed
\begin_layout Preface \begin_layout Preface
@ -154,10 +158,15 @@ author or editor
\end_layout \end_layout
\begin_layout Standard \begin_layout Plain Layout
\end_layout \end_layout
\begin_layout Plain Layout
\noindent
\begin_inset Note Note
status collapsed
\begin_layout PartBacktext \begin_layout PartBacktext
\noindent \noindent
\begin_inset Argument 1 \begin_inset Argument 1
@ -173,6 +182,16 @@ Part Title
page) on its verso page. page) on its verso page.
\end_layout \end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Chapter \begin_layout Chapter
Chapter Heading Chapter Heading
\begin_inset CommandInset label \begin_inset CommandInset label
@ -186,16 +205,6 @@ name "chap:intro"
\begin_layout Running Chapter \begin_layout Running Chapter
chapter heading in the running head chapter heading in the running head
\begin_inset Note Note
status open
\begin_layout Plain Layout
optional
\end_layout
\end_inset
\end_layout \end_layout
\begin_layout Abstract* \begin_layout Abstract*
@ -315,16 +324,6 @@ name "sec:Section-Heading"
\begin_layout Running Section \begin_layout Running Section
section heading in the running head section heading in the running head
\begin_inset Note Note
status open
\begin_layout Plain Layout
optional
\end_layout
\end_inset
\end_layout \end_layout
\begin_layout Standard \begin_layout Standard

View File

@ -2,32 +2,24 @@
<!-- This DocBook file was created by LyX 2.4.0dev <!-- This DocBook file was created by LyX 2.4.0dev
See http://www.lyx.org/ for more information --> 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"> <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>Untitled Document</title>
<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>
<chapter xml:id="chap.intro"> <chapter xml:id="chap.intro">
<title>Chapter Heading</title> <title>Chapter Heading</title>
</chapter> <info>
<titleabbrev>chapter heading in the running head</titleabbrev> <titleabbrev>chapter heading in the running head</titleabbrev>
<abstract role='not-printed'> <abstract role='not-printed'>
<para>Each chapter should be preceded by an abstract (1015 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 (1015 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> 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>
<abstract> <abstract>
<para>Each chapter should be preceded by an abstract (1015 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 (1015 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> 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>
</info>
<section xml:id="sec.Section-Heading"> <section xml:id="sec.Section-Heading">
<title>Section Heading</title> <title>Section Heading</title>
</section>
<titleabbrev>section heading in the running head</titleabbrev> <titleabbrev>section heading in the running head</titleabbrev>
<para>bla</para> </section>
<section xml:id="sec.Section-Heading-2"> <section xml:id="sec.Section-Heading-2">
<title>Section Heading 2</title> <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> <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:mrow>
</m:math> </m:math>
</informalequation> </informalequation>
however, for multiline equations we recommend to use the <emphasis role='sans'>eqnarray</emphasis> environment<footnote> however, for multiline equations we recommend to use the <emphasis role='sans'>eqnarray</emphasis> environment.
<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>.
<informalequation xml:id="eq.01"> <informalequation xml:id="eq.01">
<alt role='tex'>a\times b &amp; = &amp; c\nonumber \\ <alt role='tex'>a\times b &amp; = &amp; c\nonumber \\
\vec{a}\cdot\vec{b} &amp; = &amp; c\label{eq:01} \vec{a}\cdot\vec{b} &amp; = &amp; c\label{eq:01}
@ -85,4 +75,5 @@
</informalequation> </informalequation>
</para> </para>
</section> </section>
</chapter>
</book> </book>

View File

@ -433,6 +433,7 @@ Style Running_Title
LabelString "Running title:" LabelString "Running title:"
DocBookTag titleabbrev DocBookTag titleabbrev
DocBookTagType paragraph DocBookTagType paragraph
DocBookInInfo maybe
End End
Style Running_Author Style Running_Author
@ -450,6 +451,7 @@ Style Running_Chapter
LabelString "Running chapter:" LabelString "Running chapter:"
DocBookTag titleabbrev DocBookTag titleabbrev
DocBookTagType paragraph DocBookTagType paragraph
DocBookInInfo maybe
DocBookSection false DocBookSection false
End End
@ -459,6 +461,7 @@ Style Running_Section
LabelString "Running section:" LabelString "Running section:"
DocBookTag titleabbrev DocBookTag titleabbrev
DocBookTagType paragraph DocBookTagType paragraph
DocBookInInfo maybe
End End
Style Abstract Style Abstract

View File

@ -782,8 +782,14 @@ bool hasOnlyNotes(Paragraph const & par)
DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs, DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs,
pit_type bpit, pit_type const epit, pit_type bpit, pit_type const epit,
// Typically, bpit is the beginning of the document and epit the end *or* the first section. // Typically, bpit is the beginning of the document and epit the end of the
bool documentHasSections) { // 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> shouldBeInInfo;
set<pit_type> mustBeInInfo; set<pit_type> mustBeInInfo;
set<pit_type> abstractWithLayout; set<pit_type> abstractWithLayout;
@ -804,7 +810,8 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs,
for (; cpit < epit; ++cpit) { for (; cpit < epit; ++cpit) {
// Skip paragraphs that don't generate anything in DocBook. // Skip paragraphs that don't generate anything in DocBook.
Paragraph const & par = paragraphs[cpit]; Paragraph const & par = paragraphs[cpit];
if (hasOnlyNotes(par)) Layout const &style = par.layout();
if (hasOnlyNotes(par) || style.docbookininfo() == "never")
continue; continue;
// There should never be any section here. (Just a sanity check: if this fails, this function could end up // 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 this is marked as an abstract by the layout, put it in the right set.
if (par.layout().docbookabstract()) { if (style.docbookabstract()) {
hasAbstractLayout = true; hasAbstractLayout = true;
abstractWithLayout.emplace(cpit); abstractWithLayout.emplace(cpit);
continue; 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, // 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). // or abstract (either because of layout or of position).
Layout const &style = par.layout();
if (style.docbookininfo() == "always") if (style.docbookininfo() == "always")
mustBeInInfo.emplace(cpit); mustBeInInfo.emplace(cpit);
else if (style.docbookininfo() == "maybe") else if (style.docbookininfo() == "maybe")
shouldBeInInfo.emplace(cpit); shouldBeInInfo.emplace(cpit);
else if (documentHasSections && !hasAbstractLayout) else if (documentHasSections && !hasAbstractLayout && detectUnlayoutedAbstract)
abstractNoLayout.emplace(cpit); abstractNoLayout.emplace(cpit);
else // This should definitely not be in <info>. else // This should definitely not be in <info>.
break; break;
@ -991,7 +996,7 @@ void docbookSimpleAllParagraphs(
ParagraphList const &paragraphs = text.paragraphs(); ParagraphList const &paragraphs = text.paragraphs();
// First, the <info> tag. // 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); outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
// Then, the content. It starts where the <info> ends. // 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). // 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); outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
bpit = info.epit; bpit = info.epit;
@ -1134,27 +1139,77 @@ void docbookParagraphs(Text const &text,
// Generate this paragraph. // Generate this paragraph.
par = makeAny(text, buf, xs, ourparams, par); 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. // 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. // This abstract may be found between the next paragraph and the next title.
pit_type cpit = std::distance(text.paragraphs().begin(), par); pit_type cpit = std::distance(text.paragraphs().begin(), par);
pit_type ppit = std::get<1>(hasDocumentSectioning(paragraphs, cpit, epit)); pit_type ppit = std::get<1>(hasDocumentSectioning(paragraphs, cpit, epit));
// Generate this abstract (this code corresponds to parts of outputDocBookInfo). // 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.abstract.empty()) { if (!secInfo.mustBeInInfo.empty() || !secInfo.shouldBeInInfo.empty() || !secInfo.abstract.empty()) {
xs << xml::StartTag(style.docbookforceabstracttag()); // Generate the <info>, if required. If DocBookForceAbstractTag != NONE, this abstract will not be in
xs << xml::CR(); // <info>, unlike other ("standard") abstracts.
for (auto const &p : secInfo.abstract) bool hasStandardAbstract = !secInfo.abstract.empty() && style.docbookforceabstracttag() == "NONE";
makeAny(text, buf, xs, runparams, paragraphs.iterator_at(p)); bool needInfo = !secInfo.mustBeInInfo.empty() || hasStandardAbstract;
xs << xml::EndTag(style.docbookforceabstracttag());
xs << xml::CR(); if (needInfo) {
xs.startDivision(false);
xs << xml::StartTag("info");
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();
}
}
// 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);
} }
// Skip all the text that just has been generated.
par = paragraphs.iterator_at(ppit);
} }
} }