]> git.lyx.org Git - lyx.git/commitdiff
BiblioInfo: Ability to distinguish '&' and 'and' author separation
authorJuergen Spitzmueller <spitz@lyx.org>
Thu, 11 Jul 2024 07:13:43 +0000 (09:13 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Thu, 11 Jul 2024 07:13:43 +0000 (09:13 +0200)
Finicky styles such as APA use both in different context, and we need
to represent this to make style choice differentiatable

lib/layouts/stdciteformats.inc
src/BiblioInfo.cpp
src/BiblioInfo.h

index d88218d76b424abf91a70b515c6a24a22ccd445c..78fe8706cd4ad10a664d61274b65716b07cd2ec5 100644 (file)
@@ -29,6 +29,8 @@ CiteFormat default
        B_namesep , [[separate author names in citation, except for last name]]
        B_lastnamesep , and [[separate name of last author in citation]]
        B_pairnamesep  and [[separate two authors in citation]]
+       B_lastampnamesep , & [[separate name of last author in citation w/ ampersand]]
+       B_amppairnamesep  & [[separate two authors in citation w/ ampersand]]
 
        #
        # Macros
index 5d4ded999689b38ced58d115705b667306dfa24c..04235e424a4b11a8c0b445fbd32337dcb71d8ad8 100644 (file)
@@ -524,19 +524,19 @@ BibTeXInfo::BibTeXInfo(docstring const & key, docstring const & type)
 
 docstring const BibTeXInfo::getAuthorOrEditorList(Buffer const * buf,
                                                  size_t const max_key_size,
-                                                 bool full, bool forceshort) const
+                                                 bool amp, bool full, bool forceshort) const
 {
        docstring author = operator[]("author");
        if (author.empty())
                author = operator[]("editor");
 
-       return getAuthorList(buf, author, max_key_size, full, forceshort);
+       return getAuthorList(buf, author, max_key_size, amp, full, forceshort);
 }
 
 
 docstring const BibTeXInfo::getAuthorList(Buffer const * buf,
                docstring const & author, size_t const max_key_size,
-               bool const full, bool const forceshort,
+               bool const amp, bool const full, bool const forceshort,
                bool const allnames, bool const beginning) const
 {
        // Maxnames treshold depend on engine
@@ -582,12 +582,14 @@ docstring const BibTeXInfo::getAuthorList(Buffer const * buf,
        string const namesep =
                buf ? buf->params().documentClass().getCiteMacro(engine_type, "B_namesep")
                   : ", ";
-       string const lastnamesep =
-               buf ? buf->params().documentClass().getCiteMacro(engine_type, "B_lastnamesep")
-                   : ", and ";
-       string const pairnamesep =
-               buf ? buf->params().documentClass().getCiteMacro(engine_type, "B_pairnamesep")
-                    : " and ";
+       string lastnamesep = ", and ";
+       if (buf)
+               lastnamesep = amp ? buf->params().documentClass().getCiteMacro(engine_type, "B_lastampnamesep")
+                                 : buf->params().documentClass().getCiteMacro(engine_type, "B_lastnamesep");
+       string pairnamesep = " and ";
+       if (buf)
+               pairnamesep = amp ? buf->params().documentClass().getCiteMacro(engine_type, "B_amppairnamesep")
+                                 : buf->params().documentClass().getCiteMacro(engine_type, "B_pairnamesep");
        string firstnameform =
                        buf ? buf->params().documentClass().getCiteMacro(engine_type, "!firstnameform")
                             : "{%prefix%[[%prefix% ]]}%surname%{%suffix%[[, %suffix%]]}{%prename%[[, %prename%]]}";
@@ -1192,65 +1194,86 @@ docstring BibTeXInfo::getValueForKey(string const & oldkey, Buffer const & buf,
                        // Special key to provide abbreviated name list,
                        // with respect to maxcitenames. Suitable for Bibliography
                        // beginnings.
+                       bool const amp = prefixIs(subtype, '&');
+                       if (amp)
+                               subtype = subtype.substr(1);
                        docstring const kind = operator[](subtype);
-                       ret = getAuthorList(&buf, kind, ci.max_key_size, false, false, true);
+                       ret = getAuthorList(&buf, kind, ci.max_key_size, amp, false, false, true);
                        if (ci.forceUpperCase && isLowerCase(ret[0]))
                                ret[0] = uppercase(ret[0]);
                } else if (prefixIs(key, "fullnames:")) {
                        // Return a full name list. Suitable for Bibliography
                        // beginnings.
+                       bool const amp = prefixIs(subtype, '&');
+                       if (amp)
+                               subtype = subtype.substr(1);
                        docstring const kind = operator[](subtype);
-                       ret = getAuthorList(&buf, kind, ci.max_key_size, true, false, true);
+                       ret = getAuthorList(&buf, kind, ci.max_key_size, amp, true, false, true);
                        if (ci.forceUpperCase && isLowerCase(ret[0]))
                                ret[0] = uppercase(ret[0]);
                } else if (prefixIs(key, "forceabbrvnames:")) {
                        // Special key to provide abbreviated name lists,
                        // irrespective of maxcitenames. Suitable for Bibliography
                        // beginnings.
+                       bool const amp = prefixIs(subtype, '&');
+                       if (amp)
+                               subtype = subtype.substr(1);
                        docstring const kind = operator[](subtype);
-                       ret = getAuthorList(&buf, kind, ci.max_key_size, false, true, true);
+                       ret = getAuthorList(&buf, kind, ci.max_key_size, amp, false, true, true);
                        if (ci.forceUpperCase && isLowerCase(ret[0]))
                                ret[0] = uppercase(ret[0]);
                } else if (prefixIs(key, "abbrvbynames:")) {
                        // Special key to provide abbreviated name list,
                        // with respect to maxcitenames. Suitable for further names inside a
                        // bibliography item // (such as "ed. by ...")
+                       bool const amp = prefixIs(subtype, '&');
+                       if (amp)
+                               subtype = subtype.substr(1);
                        docstring const kind = operator[](subtype);
-                       ret = getAuthorList(&buf, kind, ci.max_key_size, false, false, true, false);
+                       ret = getAuthorList(&buf, kind, ci.max_key_size, amp, false, false, true, false);
                        if (ci.forceUpperCase && isLowerCase(ret[0]))
                                ret[0] = uppercase(ret[0]);
                } else if (prefixIs(key, "fullbynames:")) {
                        // Return a full name list. Suitable for further names inside a
                        // bibliography item // (such as "ed. by ...")
+                       bool const amp = prefixIs(subtype, '&');
+                       if (amp)
+                               subtype = subtype.substr(1);
                        docstring const kind = operator[](subtype);
-                       ret = getAuthorList(&buf, kind, ci.max_key_size, true, false, true, false);
+                       ret = getAuthorList(&buf, kind, ci.max_key_size, amp, true, false, true, false);
                        if (ci.forceUpperCase && isLowerCase(ret[0]))
                                ret[0] = uppercase(ret[0]);
                } else if (prefixIs(key, "forceabbrvbynames:")) {
                        // Special key to provide abbreviated name lists,
                        // irrespective of maxcitenames. Suitable for further names inside a
                        // bibliography item // (such as "ed. by ...")
+                       bool const amp = prefixIs(subtype, '&');
+                       if (amp)
+                               subtype = subtype.substr(1);
                        docstring const kind = operator[](subtype);
-                       ret = getAuthorList(&buf, kind, ci.max_key_size, false, true, true, false);
+                       ret = getAuthorList(&buf, kind, ci.max_key_size, amp, false, true, true, false);
                        if (ci.forceUpperCase && isLowerCase(ret[0]))
                                ret[0] = uppercase(ret[0]);
-               } else if (key == "abbrvciteauthor") {
+               } else if (prefixIs(key, "abbrvciteauthor")) {
                        // Special key to provide abbreviated author or
                        // editor names (suitable for citation labels),
                        // with respect to maxcitenames.
-                       ret = getAuthorOrEditorList(&buf, ci.max_key_size, false, false);
+                       bool const amp = suffixIs(key, "&");
+                       ret = getAuthorOrEditorList(&buf, ci.max_key_size, amp, false, false);
                        if (ci.forceUpperCase && isLowerCase(ret[0]))
                                ret[0] = uppercase(ret[0]);
-               } else if (key == "fullciteauthor") {
+               } else if (prefixIs(key, "fullciteauthor")) {
                        // Return a full author or editor list (for citation labels)
-                       ret = getAuthorOrEditorList(&buf, ci.max_key_size, true, false);
+                       bool const amp = suffixIs(key, "&");
+                       ret = getAuthorOrEditorList(&buf, ci.max_key_size, amp, true, false);
                        if (ci.forceUpperCase && isLowerCase(ret[0]))
                                ret[0] = uppercase(ret[0]);
-               } else if (key == "forceabbrvciteauthor") {
+               } else if (prefixIs(key, "forceabbrvciteauthor")) {
                        // Special key to provide abbreviated author or
                        // editor names (suitable for citation labels),
                        // irrespective of maxcitenames.
-                       ret = getAuthorOrEditorList(&buf, ci.max_key_size, false, true);
+                       bool const amp = suffixIs(key, "&");
+                       ret = getAuthorOrEditorList(&buf, ci.max_key_size, amp, false, true);
                        if (ci.forceUpperCase && isLowerCase(ret[0]))
                                ret[0] = uppercase(ret[0]);
                } else if (key == "bibentry") {
@@ -1425,7 +1448,7 @@ docstring const BiblioInfo::getAuthorOrEditorList(docstring const & key, Buffer
        if (it == end())
                return docstring();
        BibTeXInfo const & data = it->second;
-       return data.getAuthorOrEditorList(&buf, max_key_size, false);
+       return data.getAuthorOrEditorList(&buf, max_key_size, false, false);
 }
 
 
index d1f1a8ed8dfcbcbac7ffce6e89d5c0154769c4a7..6092894b40bc45b71e54e6dc15b783db9de6f38a 100644 (file)
@@ -68,10 +68,10 @@ public:
        /// otherwise, it will be translated to the buffer language.
        docstring const getAuthorOrEditorList(Buffer const * buf = nullptr,
                                              size_t const max_key_size = 128,
-                                             bool full = false, bool forceshort = false) const;
+                                             bool amp = false, bool full = false, bool forceshort = false) const;
        /// Same for a specific author role (editor, author etc.)
        docstring const getAuthorList(Buffer const * buf, docstring const & author, size_t const max_key_size,
-                                     bool const full = false, bool const forceshort = false,
+                                     bool const amp = false, bool const full = false, bool const forceshort = false,
                                      bool const allnames = false, bool const beginning = true) const;
        ///
        docstring const getYear() const;