]> git.lyx.org Git - lyx.git/commitdiff
DocBook: amend e3020a6b.
authorThibaut Cuvelier <tcuvelier@lyx.org>
Fri, 1 Mar 2024 12:45:28 +0000 (13:45 +0100)
committerThibaut Cuvelier <tcuvelier@lyx.org>
Fri, 1 Mar 2024 12:45:28 +0000 (13:45 +0100)
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
src/BiblioInfo.cpp
src/BiblioInfo.h
src/insets/InsetBibtex.cpp

index cafbe46547df2bb9542e49a9410548e51a5e17f7..82bec18b726905d3c3db1a36584354be7f6d9300 100644 (file)
@@ -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>
index 0f697ab297beb80717b70d8b00cc09d937fe8b32..253fb3759cbb7d50a30d9d6c701dd62330c18530 100644 (file)
@@ -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.
index 7a8ffb90813eb260f2cbca30f1c543cd476e986f..aeaf0fcecc5bc2d13e7c1336b876423e7e746315 100644 (file)
@@ -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
index b4bf53501474642f7e40eb24c6b3f6e0d9d64414..d452434ab5fe8b26810d9544b578fd852d880715 100644 (file)
@@ -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>