From efca14657124de78e36bd4004a6426556486bf94 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Thu, 26 Jan 2017 18:32:26 +0100 Subject: [PATCH] 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 4bf6333f27..583c90c45f 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) + ""; } + +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 0b24b8e611..65872abe21 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. -- 2.39.5