}
-docstring Encodings::convertLaTeXCommands(docstring const & str, bool const for_xhtml)
+/// text macros we can convert beyond unicodesymbols
+char const * const known_text_macros[] = {"LyX", "TeX", "LaTeXe", "LaTeX", ""};
+char const * const known_text_macros_out[] = {"LyX", "TeX", "LaTeX2e", "LaTeX", ""};
+
+
+docstring Encodings::convertLaTeXCommands(docstring const & str, bool const literal_math)
{
docstring val = str;
docstring ret;
docstring mret;
+ docstring cret;
bool scanning_cmd = false;
bool scanning_math = false;
bool is_section = false;
bool escaped = false; // used to catch \$, etc.
+ bool skip_space = false;
while (!val.empty()) {
char_type const ch = val[0];
// if we're scanning math, we collect everything until we
// find an unescaped $, and then try to convert this piecewise.
if (scanning_math) {
- if (for_xhtml) {
+ if (literal_math) {
// with xhtml, we output everything until we
// find an unescaped $, at which point we break out.
if (escaped)
continue;
}
if (isAlphaASCII(ch)) {
+ cret += ch;
is_section = false;
val = val.substr(1);
escaped = false;
scanning_cmd = false;
}
+ // check if it's a know text macro
+ // If so, output and skip the following space
+ if (!cret.empty()) {
+ int const n = findToken(known_text_macros, to_ascii(cret));
+ if (n != -1) {
+ ret += known_text_macros_out[n];
+ skip_space = true;
+ }
+ cret.clear();
+ }
+
// was the last character a \? If so, then this is something like:
// \\ or \$, so we'll just output it. That's probably not always right...
if (escaped) {
continue;
}
+ if (isSpace(ch) && skip_space) {
+ val = val.substr(1);
+ skip_space = false;
+ continue;
+ }
+ skip_space = false;
+
// Change text mode accents in the form
// {\v a} to \v{a} (see #9340).
// FIXME: This is a sort of mini-tex2lyx.
escaped = true;
val = val.substr(1);
}
+ // check if it's a know text macro
+ // If so, output and skip the following space
+ if (!cret.empty()) {
+ int const n = findToken(known_text_macros, to_ascii(cret));
+ if (n != -1)
+ ret += known_text_macros_out[n];
+ }
+
return ret;
}
// We do this on all levels.
// We don't do it if the level already contains a '@', though.
// We use a somewhat "plain" representation for this
- docstring const spart = Encodings::convertLaTeXCommands(thislevel);
+ docstring spart = Encodings::convertLaTeXCommands(thislevel);
+ // if convertLaTeXCommands() returns nothing, we fall back
+ // to the command name without backslash
+ if (trim(spart).empty())
+ spart = ltrim(thislevel, "\\");
processLatexSorting(os, runparams, thislevel, spart, escape_char);
}
} else {