From: Thibaut Cuvelier Date: Thu, 22 Oct 2020 04:28:46 +0000 (+0200) Subject: DocBook: generate chapter metadata in , for Springer mono. X-Git-Tag: 2.4.0-alpha3~864 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f2b7f8a089a8117904ccfc6c41074b6938b224bd;p=lyx.git DocBook: generate chapter metadata in , for Springer mono. --- diff --git a/autotests/export/docbook/svmono_light.lyx b/autotests/export/docbook/svmono_light.lyx index 7f6a67ccb4..36bef6e0a7 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 8709b0d871..6b8b68979b 100644 --- a/autotests/export/docbook/svmono_light.xml +++ b/autotests/export/docbook/svmono_light.xml @@ -2,32 +2,24 @@ - -Book title - -Author name(s) - - - -Part Title - Part title page and, if desired, a short introductory text (maximum one page) on its verso page. +Untitled Document Chapter Heading - + chapter heading in the running head -Each chapter should be preceded by an abstract (10–15 lines long) that summarizes the content. The abstract will appear online at www.SpringerLink.com 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. +Each chapter should be preceded by an abstract (10–15 lines long) that summarizes the content. The abstract will appear 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. Please use the 'starred' version of the abstract environment for typesetting the text of the online abstracts. Use the plain abstract if the abstract is also to appear in the printed version of the book. -Each chapter should be preceded by an abstract (10–15 lines long) that summarizes the content. The abstract will appear online at www.SpringerLink.com 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. +Each chapter should be preceded by an abstract (10–15 lines long) that summarizes the content. The abstract will appear 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. Please use the 'starred' version of the abstract environment for typesetting the text of the online abstracts. Use the plain abstract if the abstract is also to appear in the printed version of the book. +
Section Heading -
section heading in the running head -bla +
Section Heading 2 Instead of simply listing headings of different levels we recommend to let every heading be followed by at least a short passage of text. @@ -42,9 +34,7 @@ - however, for multiline equations we recommend to use the eqnarray environment -In physics texts please activate the class option vecphys to depict your vectors in boldface-italic type - as is customary for a wide range of physical subjects. -. + however, for multiline equations we recommend to use the eqnarray environment. a\times b & = & c\nonumber \\ \vec{a}\cdot\vec{b} & = & c\label{eq:01} @@ -85,4 +75,5 @@
+
\ No newline at end of file diff --git a/lib/layouts/svcommon.inc b/lib/layouts/svcommon.inc index 669361fa32..0bc1f366a1 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 59df193499..23d4db8281 100644 --- a/src/output_docbook.cpp +++ b/src/output_docbook.cpp @@ -782,8 +782,14 @@ bool hasOnlyNotes(Paragraph const & par) DocBookInfoTag getParagraphsWithInfo(ParagraphList const ¶graphs, 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 shouldBeInInfo; set mustBeInInfo; set abstractWithLayout; @@ -804,7 +810,8 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const ¶graphs, 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 ¶graphs, } // 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 ¶graphs, // Based on layout information, store this paragraph in one set: should be in , 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 . break; @@ -991,7 +996,7 @@ void docbookSimpleAllParagraphs( ParagraphList const ¶graphs = text.paragraphs(); // First, the 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 ends. @@ -1039,7 +1044,7 @@ void docbookParagraphs(Text const &text, } // Output the first 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 and , 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 , if required. If DocBookForceAbstractTag != NONE, this abstract will not be in + // , 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 , 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 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 if it is standard (i.e. its tag is ). + 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 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 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); + } } }