From ef10797f594d37780766ed3d402b0a6fe299f4e5 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 31 Dec 2010 11:59:33 +0000 Subject: [PATCH] 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 --- src/tex2lyx/test/test-insets.tex | 2 ++ src/tex2lyx/text.cpp | 32 +++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/tex2lyx/test/test-insets.tex b/src/tex2lyx/test/test-insets.tex index c606c96b60..5f6ef3739d 100644 --- a/src/tex2lyx/test/test-insets.tex +++ b/src/tex2lyx/test/test-insets.tex @@ -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: diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 350dde9482..122aa3c074 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -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,16 +1458,28 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cat() == catLetter) { context.check_layout(os); - string phrase = t.cs(); - while (p.next_token().isAlnumASCII()) - phrase += p.get_token().cs(); - if (is_known(phrase, known_coded_phrases)) - handle_ert(os, phrase, context); - else { - for (size_t i = 1; i < phrase.length(); ++i) - p.putback(); - os << t.cs(); + // 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(); + for (int i = 1; i < *l && p.next_token().isAlnumASCII(); ++i) + phrase += p.get_token().cs(); + if (is_known(phrase, known_coded_phrases)) { + handle_ert(os, phrase, context); + handled = true; + break; + } else { + for (size_t i = 1; i < phrase.length(); ++i) + p.putback(); + } } + if (!handled) + os << t.cs(); } else if (t.cat() == catOther || @@ -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]; -- 2.39.5