From: Thibaut Cuvelier Date: Sat, 19 Feb 2022 01:23:52 +0000 (+0100) Subject: Encodings::fromLaTeXCommand: if the command directly maps an entry of unicodesymbols... X-Git-Tag: 2.4-beta2~822 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=4cab1a77d20d3db8769862da5afe12879a9f8bb3;hp=0cde3dce12cd2be875f700ae3c1a175db595a2b7;p=lyx.git Encodings::fromLaTeXCommand: if the command directly maps an entry of unicodesymbols, use it and bypass most of the logic. This is important for commands like !`, that are equivalent to \textexclamdown. However, ! is matched earlier, because the logic works with prefixes, hence the output doesn't make sense. --- diff --git a/autotests/export/docbook/ert_convert.xml b/autotests/export/docbook/ert_convert.xml index e21274b485..e85efc86a0 100644 --- a/autotests/export/docbook/ert_convert.xml +++ b/autotests/export/docbook/ert_convert.xml @@ -3,5 +3,6 @@ See https://www.lyx.org/ for more information -->
ERT Conversions -These should be À: À À À +These should be À: À À À +This one should be ¡: ¡ ¡
\ No newline at end of file diff --git a/src/Encoding.cpp b/src/Encoding.cpp index 988872f05a..0c8d085a19 100644 --- a/src/Encoding.cpp +++ b/src/Encoding.cpp @@ -381,6 +381,30 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype, rem = empty_docstring(); bool const mathmode = cmdtype & MATH_CMD; bool const textmode = cmdtype & TEXT_CMD; + + // Easy case: the command is a complete entry of unicodesymbols. + for (const auto & unicodeSymbol : unicodesymbols) { + if (mathmode) { + for (const auto & command : unicodeSymbol.second.mathCommands()) { + if (command == cmd) { + docstring value; + value += unicodeSymbol.first; + return value; + } + } + } + if (textmode) { + for (const auto & command : unicodeSymbol.second.textCommands()) { + if (command == cmd) { + docstring value; + value += unicodeSymbol.first; + return value; + } + } + } + } + + // Otherwise, try to map as many commands as possible, matching prefixes of the command. docstring symbols; size_t const cmdend = cmd.size(); size_t prefix = 0;