mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Consider known latex text macros (basically the logos) in convertaTeXCommands()
This commit is contained in:
parent
e1b6ad7980
commit
712600dd6c
@ -614,23 +614,30 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 val = str;
|
||||||
docstring ret;
|
docstring ret;
|
||||||
docstring mret;
|
docstring mret;
|
||||||
|
docstring cret;
|
||||||
|
|
||||||
bool scanning_cmd = false;
|
bool scanning_cmd = false;
|
||||||
bool scanning_math = false;
|
bool scanning_math = false;
|
||||||
bool is_section = false;
|
bool is_section = false;
|
||||||
bool escaped = false; // used to catch \$, etc.
|
bool escaped = false; // used to catch \$, etc.
|
||||||
|
bool skip_space = false;
|
||||||
while (!val.empty()) {
|
while (!val.empty()) {
|
||||||
char_type const ch = val[0];
|
char_type const ch = val[0];
|
||||||
|
|
||||||
// if we're scanning math, we collect everything until we
|
// if we're scanning math, we collect everything until we
|
||||||
// find an unescaped $, and then try to convert this piecewise.
|
// find an unescaped $, and then try to convert this piecewise.
|
||||||
if (scanning_math) {
|
if (scanning_math) {
|
||||||
if (for_xhtml) {
|
if (literal_math) {
|
||||||
// with xhtml, we output everything until we
|
// with xhtml, we output everything until we
|
||||||
// find an unescaped $, at which point we break out.
|
// find an unescaped $, at which point we break out.
|
||||||
if (escaped)
|
if (escaped)
|
||||||
@ -688,6 +695,7 @@ docstring Encodings::convertLaTeXCommands(docstring const & str, bool const for_
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isAlphaASCII(ch)) {
|
if (isAlphaASCII(ch)) {
|
||||||
|
cret += ch;
|
||||||
is_section = false;
|
is_section = false;
|
||||||
val = val.substr(1);
|
val = val.substr(1);
|
||||||
escaped = false;
|
escaped = false;
|
||||||
@ -703,6 +711,17 @@ docstring Encodings::convertLaTeXCommands(docstring const & str, bool const for_
|
|||||||
scanning_cmd = 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:
|
// 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...
|
// \\ or \$, so we'll just output it. That's probably not always right...
|
||||||
if (escaped) {
|
if (escaped) {
|
||||||
@ -728,6 +747,13 @@ docstring Encodings::convertLaTeXCommands(docstring const & str, bool const for_
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isSpace(ch) && skip_space) {
|
||||||
|
val = val.substr(1);
|
||||||
|
skip_space = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
skip_space = false;
|
||||||
|
|
||||||
// Change text mode accents in the form
|
// Change text mode accents in the form
|
||||||
// {\v a} to \v{a} (see #9340).
|
// {\v a} to \v{a} (see #9340).
|
||||||
// FIXME: This is a sort of mini-tex2lyx.
|
// FIXME: This is a sort of mini-tex2lyx.
|
||||||
@ -780,6 +806,14 @@ docstring Encodings::convertLaTeXCommands(docstring const & str, bool const for_
|
|||||||
escaped = true;
|
escaped = true;
|
||||||
val = val.substr(1);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +352,7 @@ public:
|
|||||||
/// converts a string containing LaTeX commands into unicode
|
/// converts a string containing LaTeX commands into unicode
|
||||||
/// for display.
|
/// for display.
|
||||||
static docstring convertLaTeXCommands(docstring const & str,
|
static docstring convertLaTeXCommands(docstring const & str,
|
||||||
bool const for_xhtml = false);
|
bool const literal_math = false);
|
||||||
///
|
///
|
||||||
enum LatexCmd {
|
enum LatexCmd {
|
||||||
///
|
///
|
||||||
|
@ -266,7 +266,11 @@ void InsetIndex::latex(otexstream & ios, OutputParams const & runparams_in) cons
|
|||||||
// We do this on all levels.
|
// We do this on all levels.
|
||||||
// We don't do it if the level already contains a '@', though.
|
// We don't do it if the level already contains a '@', though.
|
||||||
// We use a somewhat "plain" representation for this
|
// 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);
|
processLatexSorting(os, runparams, thislevel, spart, escape_char);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user