From 0f145c3ef0828dc7e06ff839a3ececf66edf5be6 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sun, 2 Aug 2020 18:58:36 +0200 Subject: [PATCH] DocBook: use DocBookWrapperMergeWithPrevious in the code. --- .../docbook/bibliography_precooked_aastex.xml | 42 ++++---- lib/layouts/aastex.layout | 27 ++--- src/output_docbook.cpp | 101 +++++++++++++++--- 3 files changed, 123 insertions(+), 47 deletions(-) diff --git a/autotests/export/docbook/bibliography_precooked_aastex.xml b/autotests/export/docbook/bibliography_precooked_aastex.xml index b6638686ac..2c9f5bd32a 100644 --- a/autotests/export/docbook/bibliography_precooked_aastex.xml +++ b/autotests/export/docbook/bibliography_precooked_aastex.xml @@ -4,23 +4,27 @@
Collapsed Cores in Globular Clusters, Gauge-Boson Couplings, and AASTeX Examples -S. Djorgovski and Ivan R. King -Astronomy Department, University of California, Berkeley, CA 94720 -Visiting Astronomer Cerro Tololo Inter-American Observatory.CTIO is operated by AURA Inc. under contract to the National Science Foundation. -Society of Fellows, Harvard University. -present address: Center for Astrophysics60 Garden Street, Cambridge, MA 02138 -C. D. Biemesderfer -National Optical Astronomy Observatories, Tucson, AZ 85719 -Visiting Programmer, Space Telescope Science Institute -Patron, Alonso's Bar and Grill -aastex-help@aas.org -R. J. Hanisch -Space Telescope Science Institute, Baltimore, MD 21218 -Patron, Alonso's Bar and Grill +S. Djorgovski and Ivan R. King +Astronomy Department, University of California, Berkeley, CA 94720 +Visiting Astronomer Cerro Tololo Inter-American Observatory.CTIO is operated by AURA Inc. under contract to the National Science Foundation. +Society of Fellows, Harvard University. +present address: Center for Astrophysics60 Garden Street, Cambridge, MA 02138 +C. D. Biemesderfer +National Optical Astronomy Observatories, Tucson, AZ 85719 +Visiting Programmer, Space Telescope Science Institute +Patron, Alonso's Bar and Grill +aastex-help@aas.org +R. J. Hanisch +Space Telescope Science Institute, Baltimore, MD 21218 +Patron, Alonso's Bar and Grill This is a preliminary report on surface photometry of the major fraction of known globular clusters, to see which of them show the signs of a collapsed core. We also explore some diversionary mathematics and recreational tables. - - + + + + + +
Introduction A focal problem today in the dynamics of globular clusters is core collapse. It has been predicted by theory for decades , , , but observation has been less alert to the phenomenon. For many years the central brightness peak in M15 , seemed a unique anomaly. Then suggested a central peak in NGC 6397, and a limited photographic survey of ours found three more cases, including NGC 6624, whose sharp center had often been remarked on . @@ -688,7 +692,8 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi - + +
@@ -964,8 +969,9 @@ v(p,\lambda)_{\pm} & = & \pm\lambda(E\mp\lambda|{\textbf{p}}|)^{1/2}\chi of the electronically submitted abstracts for AAS meetings are error-free. -We are grateful to V. Barger, T. Han, and R. J. N. Phillips for doing the math in section . More information on the AASTeX macros package are available at http://www.aas.org/publications/aastex or the AAS ftp site. -IRAF, AIPS, Astropy, ... +We are grateful to V. Barger, T. Han, and R. J. N. Phillips for doing the math in section . More information on the AASTeX macros package are available at http://www.aas.org/publications/aastex or the AAS ftp site. +IRAF, AIPS, Astropy, ... + Aurière, M. 1982, , 109, 301 diff --git a/lib/layouts/aastex.layout b/lib/layouts/aastex.layout index 5db7deea01..445d25f536 100644 --- a/lib/layouts/aastex.layout +++ b/lib/layouts/aastex.layout @@ -175,10 +175,11 @@ Style Affiliation Family Roman Size Normal EndFont - DocBookTag affiliation - DocBookWrapperTag author - DocBookItemTag orgname - DocBookInInfo always + DocBookTag affiliation + DocBookWrapperTag author + DocBookWrapperMergeWithPrevious true + DocBookItemTag orgname + DocBookInInfo always End @@ -201,11 +202,12 @@ Style Altaffilation LabelFont Color green EndFont - DocBookTag affiliation - DocBookAttr role="alternate" - DocBookItemTag orgname - DocBookWrapperTag author - DocBookInInfo always + DocBookTag affiliation + DocBookAttr role="alternate" + DocBookWrapperTag author + DocBookWrapperMergeWithPrevious true + DocBookItemTag orgname + DocBookInInfo always End @@ -225,9 +227,10 @@ Style Email Size Normal Shape Italic EndFont - DocBookTag email - DocBookWrapperTag author - DocBookInInfo always + DocBookTag email + DocBookWrapperTag author + DocBookWrapperMergeWithPrevious true + DocBookInInfo always End diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp index a081b2db79..d0536eee3a 100644 --- a/src/output_docbook.cpp +++ b/src/output_docbook.cpp @@ -189,11 +189,30 @@ namespace { // convenience functions -void openParTag(XMLStream & xs, Paragraph const & par) +void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar) { - Layout const & lay = par.layout(); + Layout const & lay = par->layout(); + + if (par == prevpar) + prevpar = nullptr; + + // When should the wrapper be opened here? Only if the previous paragraph has the SAME wrapper tag + // (usually, they won't have the same layout) and the CURRENT one allows merging. + // The main use case is author information in several paragraphs: if the name of the author is the + // first paragraph of an author, then merging with the previous tag does not make sense. Say the + // next paragraph is the affiliation, then it should be output in the same tag (different + // layout, same wrapper tag). + bool openWrapper = lay.docbookwrappertag() != "NONE"; + if (prevpar != nullptr) { + Layout const & prevlay = prevpar->layout(); + if (prevlay.docbookwrappertag() != "NONE") { + openWrapper = prevlay.docbookwrappertag() == lay.docbookwrappertag() + && !lay.docbookwrappermergewithprevious(); + } + } - if (lay.docbookwrappertag() != "NONE") + // Main logic. + if (openWrapper) xs << xml::StartTag(lay.docbookwrappertag(), lay.docbookwrapperattr()); string tag = lay.docbooktag(); @@ -207,10 +226,24 @@ void openParTag(XMLStream & xs, Paragraph const & par) } -void closeTag(XMLStream & xs, Paragraph const & par) +void closeTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpar) { - Layout const & lay = par.layout(); + Layout const & lay = par->layout(); + + if (par == nextpar) + nextpar = nullptr; + + // See comment in openParTag. + bool closeWrapper = lay.docbookwrappertag() != "NONE"; + if (nextpar != nullptr) { + Layout const & nextlay = nextpar->layout(); + if (nextlay.docbookwrappertag() != "NONE") { + closeWrapper = nextlay.docbookwrappertag() == lay.docbookwrappertag() + && !nextlay.docbookwrappermergewithprevious(); + } + } + // Main logic. if (lay.docbookitemtag() != "NONE") xs << xml::EndTag(lay.docbookitemtag()); @@ -219,7 +252,7 @@ void closeTag(XMLStream & xs, Paragraph const & par) tag = "para"; xs << xml::EndTag(tag); - if (lay.docbookwrappertag() != "NONE") + if (closeWrapper) xs << xml::EndTag(lay.docbookwrappertag()); } @@ -399,9 +432,12 @@ ParagraphList::const_iterator makeParagraphs( ParagraphList::const_iterator const & pbegin, ParagraphList::const_iterator const & pend) { - ParagraphList::const_iterator const begin = text.paragraphs().begin(); + auto const begin = text.paragraphs().begin(); + auto const end = text.paragraphs().end(); ParagraphList::const_iterator par = pbegin; - for (; par != pend; ++par) { + ParagraphList::const_iterator prevpar = pbegin; + + for (; par != pend; prevpar = par, ++par) { // We want to open the paragraph tag if: // (i) the current layout permits multiple paragraphs // (ii) we are either not already inside a paragraph (HTMLIsBlock) OR @@ -417,7 +453,7 @@ ParagraphList::const_iterator makeParagraphs( // because of branches, e.g., a branch that contains an entire new section. // We do not really want to wrap that whole thing in a
...
. bool special_case = false; - Inset const *specinset = par->size() == 1 ? par->getInset(0) : 0; + Inset const *specinset = par->size() == 1 ? par->getInset(0) : nullptr; if (specinset && !specinset->getLayout().htmlisblock()) { // TODO: Convert htmlisblock to a DocBook parameter? Layout const &style = par->layout(); FontInfo const first_font = style.labeltype == LABEL_MANUAL ? @@ -466,7 +502,7 @@ ParagraphList::const_iterator makeParagraphs( // or we're not in the last paragraph, anyway. // (ii) We didn't open it and docbook_in_par is true, // but we are in the first par, and there is a next par. - ParagraphList::const_iterator nextpar = par; + auto nextpar = par; ++nextpar; bool const close_par = ((open_par && (!runparams.docbook_in_par || nextpar != pend)) @@ -484,12 +520,12 @@ ParagraphList::const_iterator makeParagraphs( if (!cleaned.empty()) { if (open_par) - openParTag(xs, *par); + openParTag(xs, &*par, &*prevpar); xs << XMLStream::ESCAPE_NONE << os2.str(); if (close_par) { - closeTag(xs, *par); + closeTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr); xs << xml::CR(); } } @@ -514,11 +550,24 @@ ParagraphList::const_iterator makeEnvironment( ParagraphList::const_iterator const & pend) { auto const begin = text.paragraphs().begin(); + auto const end = text.paragraphs().end(); ParagraphList::const_iterator par = pbegin; depth_type const origdepth = pbegin->params().depth(); + // Find the previous paragraph. + auto prevpar = begin; + if (prevpar != par) { + auto prevpar_next = prevpar; + ++prevpar_next; + + while (prevpar_next != par) { + ++prevpar_next; + ++prevpar; + } + } + // open tag for this environment - openParTag(xs, *par); + openParTag(xs, &*par, &*prevpar); xs << xml::CR(); // we will on occasion need to remember a layout from before. @@ -672,7 +721,9 @@ ParagraphList::const_iterator makeEnvironment( xs << xml::CR(); } } - closeTag(xs, *par); + auto nextpar = par; + ++nextpar; + closeTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr); xs << xml::CR(); return pend; } @@ -686,14 +737,30 @@ void makeCommand( ParagraphList::const_iterator const & pbegin) { // No need for labels, as they are handled by DocBook tags. + auto const begin = text.paragraphs().begin(); + auto const end = text.paragraphs().end(); + auto nextpar = pbegin; + ++nextpar; + + // Find the previous paragraph. + auto prevpar = begin; + if (prevpar != pbegin) { + auto prevpar_next = prevpar; + ++prevpar_next; + + while (prevpar_next != pbegin) { + ++prevpar_next; + ++prevpar; + } + } - openParTag(xs, *pbegin); + // Generate this command. + openParTag(xs, &*pbegin, &*prevpar); - auto const begin = text.paragraphs().begin(); pbegin->simpleDocBookOnePar(buf, xs, runparams, text.outerFont(distance(begin, pbegin))); - closeTag(xs, *pbegin); + closeTag(xs, &*pbegin, (nextpar != end) ? &*nextpar : nullptr); xs << xml::CR(); } -- 2.39.2