]> git.lyx.org Git - features.git/commitdiff
Generalize the protection of brackets in citation arguments
authorJuergen Spitzmueller <spitz@lyx.org>
Thu, 26 Jan 2017 17:32:26 +0000 (18:32 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Thu, 26 Jan 2017 17:32:26 +0000 (18:32 +0100)
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
status.22x

index 4bf6333f2791bd4dd56d2b7a1d0efd8a9e64440d..583c90c45fee50d226ed62c749fd599f48500801 100644 (file)
@@ -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
index 0b24b8e611530b085f29e0ee125dab50b10d7637..65872abe215d4aabd4cc99f8380c652253dc2e4f 100644 (file)
@@ -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.