commit efca14657124de78e36bd4004a6426556486bf94
Author: Juergen Spitzmueller <[email protected]>
Date:   Thu Jan 26 18:32:26 2017 +0100

    Generalize the protection of brackets in citation arguments
    
    Whenever an argument delimiter is used inside the argument, the argument
    needs to be grouped, that is
    
    \cites({text (text) text})
    
    or
    
    \cite[{text [text] text}]
    
    This fixes the original case reported in #2751 which is independent
    from the general issue that the pre- and postnote field take literal
    code.
---
 src/insets/InsetCitation.cpp |   18 ++++++++++++++----
 status.22x                   |    4 ++++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index 4bf6333..583c90c 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -226,6 +226,15 @@ inline docstring wrapCitation(docstring const & key,
                        html::htmlize(content, XHTMLStream::ESCAPE_ALL) + 
"</a>";
 }
 
+
+docstring protectArgument(docstring & arg)
+{
+       if (contains(arg, '[') || contains(arg, ']'))
+               // protect brackets
+               arg = '{' + arg + '}';
+       return arg;
+}
+
 } // anonymous namespace
 
 docstring InsetCitation::generateLabel(bool for_xhtml) const
@@ -422,12 +431,13 @@ void InsetCitation::latex(otexstream & os, OutputParams 
const & runparams) const
 
        os << "\\" << cite_str;
 
-       docstring const & before = getParam("before");
-       docstring const & after  = getParam("after");
+       docstring before = getParam("before");
+       docstring after  = getParam("after");
        if (!before.empty() && cs.textBefore)
-               os << '[' << before << "][" << after << ']';
+               os << '[' << protectArgument(before)
+                  << "][" << protectArgument(after) << ']';
        else if (!after.empty() && cs.textAfter)
-               os << '[' << after << ']';
+               os << '[' << protectArgument(after) << ']';
 
        if (!bi.isBibtex(getParam("key")))
                // escape chars with bibitems
diff --git a/status.22x b/status.22x
index 0b24b8e..65872ab 100644
--- a/status.22x
+++ b/status.22x
@@ -122,6 +122,10 @@ What's new
 - Fix mathtools, amsmath and amssymb not loading automatically for some
   symbols (bug 10467)
 
+- Protect citation arguments (pre and post text) which contain brackets
+  (part of bug 2751).
+
+
 * LYX2LYX
 
 - Do not convert "--" to "\twohyphens" in formula macros.

Reply via email to