commit 5c5765061fa1ce1b829c1b1dad05d3fc8d879079
Author: Thibaut Cuvelier <tcuvel...@lyx.org>
Date:   Fri Mar 1 13:45:28 2024 +0100

    DocBook: amend e3020a6b.
    
    Book authorship and authorship can be quite distinct. As far as I know, 
there is no standard way to represent book authorship in DocBook bibliographies.
---
 autotests/export/docbook/basic.xml |  9 ++++++++-
 src/BiblioInfo.cpp                 | 15 ++++++++++++---
 src/BiblioInfo.h                   |  5 ++++-
 src/insets/InsetBibtex.cpp         | 32 +++++++++-----------------------
 4 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/autotests/export/docbook/basic.xml 
b/autotests/export/docbook/basic.xml
index cafbe46547..82bec18b72 100644
--- a/autotests/export/docbook/basic.xml
+++ b/autotests/export/docbook/basic.xml
@@ -424,7 +424,14 @@ I am no more code. </para>
 </personname>
 </author>
 </authorgroup>
-<!-- Several author tags in the reference. Other editor tag: 
fullbynames:bookauthor. Corresponding value: Michel Foucault -->
+<authorgroup>
+<othercredit class="other" otherclass="bookauthor">
+<personname>
+<firstname>Michel</firstname>
+<surname>Foucault</surname>
+</personname>
+</othercredit>
+</authorgroup>
 </biblioentry>
 <biblioentry xml:id="small">
 <title>A small paper</title>
diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
index 0f697ab297..253fb3759c 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -1748,13 +1748,19 @@ string citationStyleToString(const CitationStyle & cs, 
bool const latex)
 }
 
 
-void authorsToDocBookAuthorGroup(docstring const & authorsString, XMLStream & 
xs, Buffer const & buf)
+void authorsToDocBookAuthorGroup(docstring const & authorsString, XMLStream & 
xs, Buffer const & buf,
+                                 const std::string type)
 {
        // This function closely mimics getAuthorList, but produces DocBook 
instead of text.
        // It has been greatly simplified, as the complete list of authors is 
always produced. No separators are required,
        // as the output has a database-like shape.
        // constructName has also been merged within, as it becomes really 
simple and leads to no copy-paste.
 
+       if (! type.empty() && (type != "author" && type != "book")) {
+               LYXERR0("ERROR! Unexpected author contribution `" << type 
<<"'.");
+               return;
+       }
+
        if (authorsString.empty()) {
                return;
        }
@@ -1772,7 +1778,10 @@ void authorsToDocBookAuthorGroup(docstring const & 
authorsString, XMLStream & xs
        auto it = authors.cbegin();
        auto en = authors.cend();
        for (size_t i = 0; it != en; ++it, ++i) {
-               xs << xml::StartTag("author");
+               const std::string tag = (type.empty() || type == "author") ? 
"author" : "othercredit";
+               const std::string attr = (type == "book") ? R"(class="other" 
otherclass="bookauthor")" : "";
+
+               xs << xml::StartTag(tag, attr);
                xs << xml::CR();
                xs << xml::StartTag("personname");
                xs << xml::CR();
@@ -1812,7 +1821,7 @@ void authorsToDocBookAuthorGroup(docstring const & 
authorsString, XMLStream & xs
 
                xs << xml::EndTag("personname");
                xs << xml::CR();
-               xs << xml::EndTag("author");
+               xs << xml::EndTag(tag);
                xs << xml::CR();
 
                // Could add an affiliation after <personname>, but not stored 
in BibTeX.
diff --git a/src/BiblioInfo.h b/src/BiblioInfo.h
index 7a8ffb9081..aeaf0fcecc 100644
--- a/src/BiblioInfo.h
+++ b/src/BiblioInfo.h
@@ -37,7 +37,10 @@ CitationStyle citationStyleFromString(std::string const & 
latex_str,
 std::string citationStyleToString(CitationStyle const &, bool const latex = 
false);
 
 /// Transforms the information about authors into a <authorgroup> (directly 
written to a XMLStream).
-void authorsToDocBookAuthorGroup(docstring const & authorsString, XMLStream & 
xs, Buffer const & buf);
+/// Type: "author" or empty means author of the entry (article, book, etc.); 
"book" means author of the book
+/// (but not necessarily of this entry in particular).
+void authorsToDocBookAuthorGroup(docstring const & authorsString, XMLStream & 
xs, Buffer const & buf,
+                                                                std::string 
type);
 
 
 /// Class to represent information about a BibTeX or
diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index b4bf535014..d452434ab5 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -1402,29 +1402,15 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams 
const &) const
 
                        // <authorgroup>
                        // Example: 
http://tdg.docbook.org/tdg/5.1/authorgroup.html
-                       if (hasTag("fullnames:author") || 
hasTag("fullbynames:bookauthor")) {
-                               // If several author tags are present, only 
output one.
-                               const docstring authorName = getTag(
-                                               hasTag("fullnames:author") ? 
"fullnames:author" : "fullbynames:bookauthor");
-
-                               // Perform full parsing of the BibTeX string, 
dealing with the many corner cases that might
-                               // be encountered.
-                               authorsToDocBookAuthorGroup(authorName, xs, 
buffer());
-
-                               if (hasTag("fullnames:author") && 
hasTag("fullbynames:bookauthor")) {
-                                       xs << XMLStream::ESCAPE_NONE <<
-                                          from_utf8("<!-- Several author tags 
in the reference. Other editor tag: ") +
-                                          from_utf8("fullbynames:bookauthor. 
Corresponding value: ") +
-                                          getTag("fullbynames:bookauthor") + 
from_utf8(" -->\n");
-                               }
-
-                               // Erase all author tags that might be present, 
even if only one is output.
-                               if (hasTag("fullnames:author")) {
-                                       eraseTag("fullnames:author");
-                               }
-                               if (hasTag("fullbynames:bookauthor")) {
-                                       eraseTag("fullbynames:bookauthor");
-                               }
+                       // Perform full parsing of the BibTeX string, dealing 
with the many corner cases that might
+                       // be encountered.
+                       if (hasTag("fullnames:author")) {
+                               
authorsToDocBookAuthorGroup(getTag("fullnames:author"), xs, buffer(), "author");
+                               eraseTag("fullnames:author");
+                       }
+                       if (hasTag("fullbynames:bookauthor")) {
+                               
authorsToDocBookAuthorGroup(getTag("fullbynames:bookauthor"), xs, buffer(), 
"book");
+                               eraseTag("fullbynames:bookauthor");
                        }
 
                        // <editor>
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to