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.
This commit is contained in:
Juergen Spitzmueller 2017-01-26 18:32:26 +01:00
parent 1265ed2a68
commit efca146571
2 changed files with 18 additions and 4 deletions

View 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

View 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.