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.
This commit is contained in:
Thibaut Cuvelier 2022-02-19 02:23:52 +01:00
parent 0cde3dce12
commit 4cab1a77d2
2 changed files with 26 additions and 1 deletions

View File

@ -3,5 +3,6 @@
See https://www.lyx.org/ for more information --> 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"> <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> <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> </article>

View File

@ -381,6 +381,30 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
rem = empty_docstring(); rem = empty_docstring();
bool const mathmode = cmdtype & MATH_CMD; bool const mathmode = cmdtype & MATH_CMD;
bool const textmode = cmdtype & TEXT_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; docstring symbols;
size_t const cmdend = cmd.size(); size_t const cmdend = cmd.size();
size_t prefix = 0; size_t prefix = 0;