From: Enrico Forestieri Date: Fri, 12 Jun 2009 14:03:57 +0000 (+0000) Subject: Fix display of BibTeX entries in the info field of the citation X-Git-Tag: 2.0.0~6330 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=411b7a1dec437a8a4416af13f5a8bbb39f2cbd70;p=features.git Fix display of BibTeX entries in the info field of the citation dialog by only converting text mode latex macros to unicode points. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30070 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index c68e18ae4c..92af3b5aba 100644 --- a/src/BiblioInfo.cpp +++ b/src/BiblioInfo.cpp @@ -170,7 +170,8 @@ docstring convertLaTeXCommands(docstring const & str) val.insert(2, from_ascii("{")); } docstring rem; - docstring const cnvtd = Encodings::fromLaTeXCommand(val, rem); + docstring const cnvtd = Encodings::fromLaTeXCommand(val, rem, + Encodings::TEXT_CMD); if (!cnvtd.empty()) { // it did, so we'll take that bit and proceed with what's left ret += cnvtd; diff --git a/src/Encoding.cpp b/src/Encoding.cpp index 9283e55fc8..6a59fe695c 100644 --- a/src/Encoding.cpp +++ b/src/Encoding.cpp @@ -436,8 +436,11 @@ char_type Encodings::fromLaTeXCommand(docstring const & cmd, bool & combining) } -docstring Encodings::fromLaTeXCommand(docstring const & cmd, docstring & rem) +docstring Encodings::fromLaTeXCommand(docstring const & cmd, docstring & rem, + int cmdtype) { + bool const mathmode = cmdtype & MATH_CMD; + bool const textmode = cmdtype & TEXT_CMD; docstring symbols; size_t i = 0; size_t const cmdend = cmd.size(); @@ -468,8 +471,10 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, docstring & rem) size_t unicmd_size = 0; char_type c = 0; for (; it != uniend; ++it) { - docstring const math = it->second.mathcommand; - docstring const text = it->second.textcommand; + docstring const math = mathmode ? it->second.mathcommand + : docstring(); + docstring const text = textmode ? it->second.textcommand + : docstring(); size_t cur_size = max(math.size(), text.size()); // The current math or text unicode command cannot // match, or we already matched a longer one diff --git a/src/Encoding.h b/src/Encoding.h index 6a1e76ce9a..f955fa966a 100644 --- a/src/Encoding.h +++ b/src/Encoding.h @@ -233,13 +233,23 @@ public: * point and set \p combining to true if it is a combining symbol */ static char_type fromLaTeXCommand(docstring const & cmd, bool & combining); + /// + enum LatexCmd { + /// + MATH_CMD = 1, + /// + TEXT_CMD = 2 + }; /** * Convert the LaTeX commands in \p cmd and \return a docstring * of corresponding unicode points. The conversion stops at the * first command which could not be converted, and the remaining - * unconverted commands are returned in \p rem + * unconverted commands are returned in \p rem. + * The \p cmdtype parameter can be used to limit recognized + * commands to math or text mode commands only. */ - static docstring fromLaTeXCommand(docstring const & cmd, docstring & rem); + static docstring fromLaTeXCommand(docstring const & cmd, + docstring & rem, int cmdtype = MATH_CMD | TEXT_CMD); /** * Add the preamble snippet needed for the output of \p c to * \p features.