]> git.lyx.org Git - lyx.git/commitdiff
Encodings::fromLaTeXCommand: if the command directly maps an entry of unicodesymbols...
authorThibaut Cuvelier <tcuvelier@lyx.org>
Sat, 19 Feb 2022 01:23:52 +0000 (02:23 +0100)
committerThibaut Cuvelier <tcuvelier@lyx.org>
Mon, 21 Feb 2022 17:24:26 +0000 (18:24 +0100)
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
src/Encoding.cpp

index e21274b485a22a363b247c5354f9b171fa16ded4..e85efc86a0a2eda3aa2eb15cc3e2a02b8a66a3a0 100644 (file)
@@ -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>&amp;#192;</code>: &#192; &#192; &#192; </para>
+<para>These should be <code>&amp;#192;</code>: &#192; &#192; &#192;</para>
+<para>This one should be <code>&amp;#161;</code>: &#161; &#161;</para>
 </article>
\ No newline at end of file
index 988872f05a32652a42e03581acf84d63266cf49e..0c8d085a19689f51b445da9067ed06849d37e6bc 100644 (file)
@@ -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;