commit dbbefcd321d477eb87b5ad3a611a642fd3e9983b
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Sat Jan 7 17:55:38 2017 +0100

    Dynamically set final punctuation of bib entries
    
    Fullcite does not need the punct.
---
 lib/layouts/stdciteformats.inc |   14 ++++++++------
 src/BiblioInfo.cpp             |    4 ++--
 src/TextClass.cpp              |   10 +++++++---
 src/TextClass.h                |    5 +++--
 4 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/lib/layouts/stdciteformats.inc b/lib/layouts/stdciteformats.inc
index 9ef2b78..86f24a2 100644
--- a/lib/layouts/stdciteformats.inc
+++ b/lib/layouts/stdciteformats.inc
@@ -2,7 +2,7 @@
 #
 # Author: Richard Heck <rgh...@comcast.net>
 
-Format 62
+Format 63
 
 CiteFormat default
        # translatable bits
@@ -12,7 +12,7 @@ CiteFormat default
        _numtext no.
        _in in
 
-       # macros
+       # Macros
        !pages {%pages%[[, %_pptext% %pages%]]}
        !authoredit {%author%[[%author%, ]][[{%editor%[[%editor%, %_edtext%, 
]]}]]}
        !volnum {%volume%[[ %_voltext% %volume%, {%number%[[%_numtext% 
%number%]]}]]}
@@ -21,11 +21,13 @@ CiteFormat default
        !emphjournal 
{!<i>!}{%journal%[[%journal%]][[{%journaltitle%[[%journaltitle%]]}]]}{!</i>!}
        !location {%address%[[%address%: ]][[{%location%[[%location%: ]]}]]}
 
-       !insomething %author%, %!quotetitle%, %_in%{%editor%[[ %editor%, 
%_edtext%,]]} {!<i>!}%booktitle%{!</i>!}%!volnum%{%edition%[[ %edition%]]} 
(%!location%%publisher%, %year%)%!pages%.{%note%[[ %note%]]}
+       # Entry types. Note that final punctuation will be added later, if 
needed.
 
-       article %author%, %!quotetitle%, %!emphjournal% {%volume%[[ 
%volume%{%number%[[, %number%]]}]]} (%year%)%!pages%.{%note%[[ %note%]]}
+       !insomething %author%, %!quotetitle%, %_in%{%editor%[[ %editor%, 
%_edtext%,]]} {!<i>!}%booktitle%{!</i>!}%!volnum%{%edition%[[ %edition%]]} 
(%!location%%publisher%, %year%)%!pages%{%note%[[. %note%]]}
 
-       !booklike %!authoredit%%!emphtitle%%!volnum%{%edition%[[ %edition%]]} 
(%!location%%publisher%, %year%).{%note%[[ %note%]]}
+       article %author%, %!quotetitle%, %!emphjournal% {%volume%[[ 
%volume%{%number%[[, %number%]]}]]} (%year%)%!pages%{%note%[[. %note%]]}
+
+       !booklike %!authoredit%%!emphtitle%%!volnum%{%edition%[[ %edition%]]} 
(%!location%%publisher%, %year%){%note%[[. %note%]]}
        book %!booklike%
        collection %!booklike%
        proceedings %!booklike%
@@ -33,7 +35,7 @@ CiteFormat default
        incollection %!insomething%
        inproceedings %!insomething%
 
-       !theses %author%, %title% 
(%!location%{%school%[[%school%]][[%institution%]]}, %year%).{%note%[[ %note%]]}
+       !theses %author%, %title% 
(%!location%{%school%[[%school%]][[%institution%]]}, %year%){%note%[[. %note%]]}
        thesis %!theses%
        phdthesis %!theses%
        mastersthesis %!theses%
diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
index 025679f..67da85a 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -788,7 +788,7 @@ docstring BibTeXInfo::getValueForKey(string const & oldkey, 
Buffer const & buf,
                        CiteEngineType const engine_type = 
buf.params().citeEngineType();
                        DocumentClass const & dc = buf.params().documentClass();
                        docstring const & format =
-                               from_utf8(dc.getCiteFormat(engine_type, 
to_utf8(entry_type_)));
+                               from_utf8(dc.getCiteFormat(engine_type, 
to_utf8(entry_type_), false));
                        int counter = 0;
                        ret = expandFormat(format, xrefs, counter, buf, ci, 
false, false);
                } else if (key == "textbefore")
@@ -1000,7 +1000,7 @@ docstring const BiblioInfo::getLabel(vector<docstring> 
keys,
 
        CiteEngineType const engine_type = buf.params().citeEngineType();
        DocumentClass const & dc = buf.params().documentClass();
-       docstring const & format = from_utf8(dc.getCiteFormat(engine_type, 
style, "cite"));
+       docstring const & format = from_utf8(dc.getCiteFormat(engine_type, 
style, true, "cite"));
        docstring ret = format;
        vector<docstring>::const_iterator key = keys.begin();
        vector<docstring>::const_iterator ken = keys.end();
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index 9a51fb0..6157348 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -1815,10 +1815,12 @@ Layout const & DocumentClass::htmlTOCLayout() const
 }
 
 
-string const & DocumentClass::getCiteFormat(CiteEngineType const & type,
-       string const & entry, string const & fallback) const
+string const DocumentClass::getCiteFormat(CiteEngineType const & type,
+       string const & entry, bool const punct, string const & fallback) const
 {
-       static string default_format = "{%author%[[%author%, 
]][[{%editor%[[%editor%, ed., ]]}]]}\"%title%\"{%journal%[[, 
{!<i>!}%journal%{!</i>!}]][[{%publisher%[[, %publisher%]][[{%institution%[[, 
%institution%]]}]]}]]}{%year%[[ (%year%)]]}{%pages%[[, %pages%]]}.";
+       string default_format = "{%author%[[%author%, ]][[{%editor%[[%editor%, 
ed., ]]}]]}\"%title%\"{%journal%[[, {!<i>!}%journal%{!</i>!}]][[{%publisher%[[, 
%publisher%]][[{%institution%[[, %institution%]]}]]}]]}{%year%[[ 
(%year%)]]}{%pages%[[, %pages%]]}";
+       if (punct)
+               default_format += ".";
 
        map<CiteEngineType, map<string, string> >::const_iterator itype = 
cite_formats_.find(type);
        if (itype == cite_formats_.end())
@@ -1828,6 +1830,8 @@ string const & 
DocumentClass::getCiteFormat(CiteEngineType const & type,
                it = itype->second.find(fallback);
        if (it == itype->second.end())
                return default_format;
+       if (punct)
+               return it->second + ".";
        return it->second;
 }
 
diff --git a/src/TextClass.h b/src/TextClass.h
index dbfb974..da217a5 100644
--- a/src/TextClass.h
+++ b/src/TextClass.h
@@ -485,8 +485,9 @@ public:
        /// returns true if the class has a ToC structure
        bool hasTocLevels() const;
        ///
-       std::string const & getCiteFormat(CiteEngineType const & type,
-               std::string const & entry, std::string const & fallback = "") 
const;
+       std::string const getCiteFormat(CiteEngineType const & type,
+               std::string const & entry, bool const punct = true,
+               std::string const & fallback = "") const;
        ///
        std::string const & getCiteMacro(CiteEngineType const & type,
                std::string const & macro) const;

Reply via email to