[LyX/master] Encodings::fromLaTeXCommand: if the command directly maps an entry of unicodesymbols, use it and bypass most of the logic.
Thibaut Cuvelier
tcuvelier at lyx.org
Mon Feb 21 16:51:22 UTC 2022
commit 4cab1a77d20d3db8769862da5afe12879a9f8bb3
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date: Sat Feb 19 02:23:52 2022 +0100
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 deletions(-)
diff --git a/autotests/export/docbook/ert_convert.xml b/autotests/export/docbook/ert_convert.xml
index e21274b..e85efc8 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 -->
<article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
<title>ERT Conversions</title>
-<para>These should be <code>À</code>: À À À </para>
+<para>These should be <code>À</code>: À À À</para>
+<para>This one should be <code>¡</code>: ¡ ¡</para>
</article>
\ No newline at end of file
diff --git a/src/Encoding.cpp b/src/Encoding.cpp
index 988872f..0c8d085 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;
More information about the lyx-cvs
mailing list