Author: baum
Date: Fri Dec 31 12:59:33 2010
New Revision: 37055
URL: http://www.lyx.org/trac/changeset/37055

Log:
Also prevent replacement of LyX => \LyX{} if it is part of a word.
The automatic replacement in LyX is pretty broken (see bug 4752).

Modified:
   lyx-devel/trunk/src/tex2lyx/test/test-insets.tex
   lyx-devel/trunk/src/tex2lyx/text.cpp

Modified: lyx-devel/trunk/src/tex2lyx/test/test-insets.tex
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/test/test-insets.tex    Fri Dec 31 12:57:25 
2010        (r37054)
+++ lyx-devel/trunk/src/tex2lyx/test/test-insets.tex    Fri Dec 31 12:59:33 
2010        (r37055)
@@ -295,6 +295,8 @@
 
 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:

Modified: lyx-devel/trunk/src/tex2lyx/text.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/text.cpp        Fri Dec 31 12:57:25 2010        
(r37054)
+++ lyx-devel/trunk/src/tex2lyx/text.cpp        Fri Dec 31 12:59:33 2010        
(r37055)
@@ -205,6 +205,7 @@
 /// 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 @@
 
                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 @@
                }
 
                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];

Reply via email to