Also prevent replacement of LyX => \LyX{} if it is part of a word.

The automatic replacement in LyX is pretty broken (see bug 4752).


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37055 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2010-12-31 11:59:33 +00:00
parent bce18bacfc
commit ef10797f59
2 changed files with 25 additions and 9 deletions

View File

@ -295,6 +295,8 @@ separator\lyxarrow{}and a spif\textcompwordmark{}fy ligature break.
LyX translates the phrases LyX, TeX, LaTeX2e and LaTeX
to the commands \LyX{}, \TeX{}, \LaTeXe{} and \LaTeX{}.
If these phrases occur as part of other words (like 1LyX or aTeX or LaTeX3)
they should not be put into ERT.
Test for whitespace handling of commands: The following lines should
result in identical output:

View File

@ -205,6 +205,7 @@ char const * const known_coded_spaces[] = { "space{}", "space{}",
/// them in ERT. "LaTeXe" must come before "LaTeX"!
char const * const known_phrases[] = {"LyX", "TeX", "LaTeXe", "LaTeX", 0};
char const * const known_coded_phrases[] = {"LyX", "TeX", "LaTeX2e", "LaTeX", 0};
int const known_phrase_lengths[] = {3, 5, 7, 0};
/// splits "x=z, y=b" into a map and an ordered keyword vector
@ -1457,17 +1458,29 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
else if (t.cat() == catLetter) {
context.check_layout(os);
// Workaround for bug 4752.
// FIXME: This whole code block needs to be removed
// when the bug is fixed and tex2lyx produces
// the updated file format.
// The replacement algorithm in LyX is so stupid that
// it even translates a phrase if it is part of a word.
bool handled = false;
for (int const * l = known_phrase_lengths; *l; ++l) {
string phrase = t.cs();
while (p.next_token().isAlnumASCII())
for (int i = 1; i < *l && p.next_token().isAlnumASCII(); ++i)
phrase += p.get_token().cs();
if (is_known(phrase, known_coded_phrases))
if (is_known(phrase, known_coded_phrases)) {
handle_ert(os, phrase, context);
else {
handled = true;
break;
} else {
for (size_t i = 1; i < phrase.length(); ++i)
p.putback();
os << t.cs();
}
}
if (!handled)
os << t.cs();
}
else if (t.cat() == catOther ||
t.cat() == catAlign ||
@ -2122,6 +2135,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
}
else if (is_known(t.cs(), known_phrases)) {
// FIXME: This needs to be changed when bug 4752 is fixed.
char const * const * where = is_known(t.cs(), known_phrases);
context.check_layout(os);
os << known_coded_phrases[where - known_phrases];