From 4cab1a77d20d3db8769862da5afe12879a9f8bb3 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sat, 19 Feb 2022 02:23:52 +0100 Subject: [PATCH 1/1] 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. --- autotests/export/docbook/ert_convert.xml | 3 ++- src/Encoding.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) 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; -- 2.39.2