From: Juergen Spitzmueller Date: Sat, 10 Mar 2018 13:58:55 +0000 (+0100) Subject: tex2lyx: make nested CJK parsing slightly less dumb. X-Git-Tag: lyx-2.4.0dev-acb2ca7b~3721 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=0f4c9027056a6f4f771382e9ebfc7940274bf5c0;p=features.git tex2lyx: make nested CJK parsing slightly less dumb. Fixes: #9562 --- diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index cd7d0a92bd..e12e4eeb42 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -343,6 +343,10 @@ bool minted_float_has_caption = false; // The caption for non-floating minted listings string minted_nonfloat_caption = ""; +// Characters that have to be escaped by \\ in LaTeX +char const * const known_escaped_chars[] = { + "&", "_", "$", "%", "#", "^", "{", "}"}; + /// splits "x=z, y=b" into a map and an ordered keyword vector void split_map(string const & s, map & res, vector & keys) @@ -521,9 +525,6 @@ bool skip_braces(Parser & p) pair convert_unicodesymbols(docstring s) { bool res = true; - int const nchars_escape = 8; - static char_type const chars_escape[nchars_escape] = { - '&', '_', '$', '%', '#', '^', '{', '}'}; odocstringstream os; for (size_t i = 0; i < s.size();) { if (s[i] != '\\') { @@ -546,8 +547,8 @@ pair convert_unicodesymbols(docstring s) i = 0; else { res = false; - for (int k = 0; k < nchars_escape; k++) - if (prefixIs(s, from_ascii("\\") + chars_escape[k])) + for (auto const & c : known_escaped_chars) + if (prefixIs(s, from_ascii("\\") + c)) res = true; i = 1; } @@ -1719,10 +1720,10 @@ void parse_environment(Parser & p, ostream & os, bool outer, // things like comments are completely wrong. string const s = p.plainEnvironment("CJK"); for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) { - if (*it == '\\') - output_ert_inset(os, "\\", parent_context); - else if (*it == '$') - output_ert_inset(os, "$", parent_context); + string snip; + snip += *it; + if (snip == "\\" || is_known(snip, known_escaped_chars)) + output_ert_inset(os, snip, parent_context); else if (*it == '\n' && it + 1 != et && s.begin() + 1 != it) os << "\n "; else