One of the youth sins of LyX is that it replaces some special phrases 
automatically with a typeset version. This is not wanted in most cases (the 
LyX documentation being an exception) and filed as bug 4752. The replacement 
algorithm is rather limited, i.e. it converts these phrases even if they are 
part of a word like aLyXb into a\LyX{}b, which is most certainly never 
wanted.

The attached patch follows the same line of thought as the previous work on 
dashes. Since lyx2lyx misses the information about passThru I had to 
introduce special tokens again. It was suggested in trac to use a flex 
inset, but I could not make it work, since flex insets do require arguments 
currently. Therefore I invented new kinds of InsetSpecialChar. As a side 
effect of the patch the export of the LaTeX2e logo to formats other than 
LaTeX is slightly improved. What I also like is the amount of code which is 
no longer needed. The inset solution is much cleaner and more robust.

If nobody complains I'll put this in soon.


Georg
diff --git a/development/FORMAT b/development/FORMAT
index 0809060..b369453 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -11,6 +11,12 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
 
 -----------------------
 
+2015-02-27 Georg Baum  <georg.b...@post.rwth-aachen.de>
+	* Format incremented to 482
+	  "LyX", "TeX", "LaTeX2e" and "LaTeX" are not automatically converted
+	  to LaTeX macros anymore.
+	  Instead, these are new flavours of InsetSpecialChar (bug 4752).
+
 2015-02-24 Georg Baum  <georg.b...@post.rwth-aachen.de>
 	* Format incremented to 481
 	  "--" and "---" are not treated as endash and emdash anymore, since
diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py
index eef9220..fdfa34d 100644
--- a/lib/lyx2lyx/LyX.py
+++ b/lib/lyx2lyx/LyX.py
@@ -85,7 +85,7 @@ format_relation = [("0_06",    [200], minor_versions("0.6" , 4)),
                    ("1_6", range(277,346), minor_versions("1.6" , 10)),
                    ("2_0", range(346,414), minor_versions("2.0", 8)),
                    ("2_1", range(414,475), minor_versions("2.1", 0)),
-                   ("2_2", range(475,482), minor_versions("2.2", 0))
+                   ("2_2", range(475,483), minor_versions("2.2", 0))
                   ]
 
 ####################################################################
diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py
index 1036ae9..ba9ea7f 100644
--- a/lib/lyx2lyx/lyx_2_2.py
+++ b/lib/lyx2lyx/lyx_2_2.py
@@ -557,6 +557,92 @@ def revert_dashes(document):
             i += 1
 
   
+# order is important for the last three!
+phrases = ["LyX", "LaTeX2e", "LaTeX", "TeX"]
+
+def is_part_of_converted_phrase(line, j, phrase):
+    "is phrase part of an already converted phrase?"
+    for p in phrases:
+        converted = "\\SpecialCharNoPassThru \\" + p
+        pos = j + len(phrase) - len(converted)
+        if pos >= 0:
+            if line[pos:pos+len(converted)] == converted:
+                return True
+    return False
+
+
+def convert_phrases(document):
+    "convert special phrases from plain text to \\SpecialCharNoPassThru"
+
+    if document.backend != "latex":
+        return
+
+    for phrase in phrases:
+        i = 0
+        while i < len(document.body):
+            if find_token(document.body, "\\begin_Inset Formula", i) == i:
+                # must not replace anything in math
+                j = find_end_of_inset(document.body, i)
+                if j == -1:
+                    document.warning("Malformed LyX document: Can't find end of Formula inset at line " + str(i))
+                    i += 1
+                else:
+                    i = j
+                continue
+            if document.body[i].find("\\") == 0:
+                i += 1
+                continue
+            j = document.body[i].find(phrase)
+            if j == -1:
+                i += 1
+                continue
+            if not is_part_of_converted_phrase(document.body[i], j, phrase):
+                front = document.body[i][:j]
+                back = document.body[i][j+len(phrase):]
+                if len(back) > 0:
+                    document.body.insert(i+1, back)
+                # We cannot use SpecialChar since we do not know whether we are outside passThru 
+                document.body[i] = front + "\\SpecialCharNoPassThru \\" + phrase
+            i += 1
+
+
+def revert_phrases(document):
+    "convert special phrases to plain text"
+
+    lyx_found = False
+    i = 0
+    while i < len(document.body):
+        if find_token(document.body, "\\begin_Inset Formula", i) == i:
+            # must not replace anything in math
+            j = find_end_of_inset(document.body, i)
+            if j == -1:
+                document.warning("Malformed LyX document: Can't find end of Formula inset at line " + str(i))
+                i += 1
+            else:
+                i = j
+            continue
+        replaced = False
+        for phrase in phrases:
+            # we can replace SpecialChar since LyX ensures that it cannot be inserted into passThru parts
+            if document.body[i].find("\\SpecialChar \\" + phrase) >= 0:
+                document.body[i] = document.body[i].replace("\\SpecialChar \\" + phrase, phrase)
+                replaced = True
+            if document.body[i].find("\\SpecialCharNoPassThru \\" + phrase) >= 0:
+                document.body[i] = document.body[i].replace("\\SpecialCharNoPassThru \\" + phrase, phrase)
+                replaced = True
+        if replaced and i+1 < len(document.body) and \
+           (document.body[i+1].find("\\") != 0 or \
+            document.body[i+1].find("\\SpecialChar") == 0) and \
+           len(document.body[i]) + len(document.body[i+1]) <= 80:
+            document.body[i] = document.body[i] + document.body[i+1]
+            document.body[i+1:i+2] = []
+            i -= 1
+        i += 1
+
+    if lyx_found:
+        add_to_preamble(document, ["\\providecommand{\\LyX}{L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}"])
+
+
 ##
 # Conversion hub
 #
@@ -572,10 +658,12 @@ convert = [
            [478, []],
            [479, []],
            [480, []],
-           [481, [convert_dashes]]
+           [481, [convert_dashes]],
+           [482, [convert_phrases]]
           ]
 
 revert =  [
+           [481, [revert_phrases]],
            [480, [revert_dashes]],
            [479, [revert_question_env]],
            [478, [revert_beamer_lemma]],
diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc
index db890d1..a21420a 100644
--- a/lib/ui/stdmenus.inc
+++ b/lib/ui/stdmenus.inc
@@ -399,6 +399,10 @@ Menuset
 		Item "Visible Space|V" "space-insert visible"
 		Item "Menu Separator|M" "specialchar-insert menu-separator"
 		Item "Phonetic Symbols|P" "ipa-insert"
+		Item "LyX Logo" "specialchar-insert lyx"
+		Item "TeX Logo" "specialchar-insert tex"
+		Item "LaTeX Logo" "specialchar-insert latex"
+		Item "LaTeX2e Logo" "specialchar-insert latex2e"
 	End
 
 	Menu "insert_formatting"
diff --git a/src/FontList.cpp b/src/FontList.cpp
index ba6b79a..1c763e1 100644
--- a/src/FontList.cpp
+++ b/src/FontList.cpp
@@ -207,13 +207,6 @@ FontSize FontList::highestInRange(pos_type startpos, pos_type endpos,
 }
 
 
-bool FontList::hasChangeInRange(pos_type pos, int len) const
-{
-	List::const_iterator cit = fontIterator(pos);
-	return cit == list_.end() || pos + len - 1 <= cit->pos();
-}
-
-
 void FontList::validate(LaTeXFeatures & features) const
 {
 	const_iterator fcit = list_.begin();
diff --git a/src/FontList.h b/src/FontList.h
index fed99fe..9dfd527 100644
--- a/src/FontList.h
+++ b/src/FontList.h
@@ -112,12 +112,6 @@ public:
 		FontSize def_size
 		) const;
 
-	/// is there a font change in middle of the word?
-	bool hasChangeInRange(
-		pos_type pos, ///< position in the paragraph.
-		int len ///< length of the range to check.
-		) const;
-
 	///
 	void validate(LaTeXFeatures & features) const;
 
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 01ddb19..2a6c598 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -499,7 +499,7 @@ void LyXAction::init()
  * \li Action: Inserts various characters into the document.
  * \li Syntax: specialchar-insert <CHAR>
  * \li Params: <CHAR>: hyphenation, ligature-break, slash, nobreakdash, dots,
-                       end-of-sentence, menu-separator.
+                       end-of-sentence, menu-separator, lyx, tex, latex, latex2e.
  * \li Origin: JSpitzm, 6 Dec 2007
  * \endvar
  */
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index b0fd796..3ce354c 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -363,13 +363,6 @@ public:
 		otexstream & os,
 		pos_type i,
 		unsigned int & column);
-	///
-	bool latexSpecialPhrase(
-		otexstream & os,
-		pos_type & i,
-		pos_type end_pos,
-		unsigned int & column,
-		OutputParams const & runparams);
 
 	///
 	void validate(LaTeXFeatures & features) const;
@@ -378,9 +371,6 @@ public:
 	bool onlyText(Buffer const & buf, Font const & outerfont,
 		      pos_type initial) const;
 
-	/// match a string against a particular point in the paragraph
-	bool isTextAt(string const & str, pos_type pos) const;
-
 	/// a vector of speller skip positions
 	typedef vector<FontSpan> SkipPositions;
 	typedef SkipPositions::const_iterator SkipPositionsIterator;
@@ -508,26 +498,6 @@ public:
 };
 
 
-namespace {
-
-struct special_phrase {
-	string phrase;
-	docstring macro;
-	bool builtin;
-};
-
-special_phrase const special_phrases[] = {
-	{ "LyX", from_ascii("\\LyX{}"), false },
-	{ "TeX", from_ascii("\\TeX{}"), true },
-	{ "LaTeX2e", from_ascii("\\LaTeXe{}"), true },
-	{ "LaTeX", from_ascii("\\LaTeX{}"), true },
-};
-
-size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase);
-
-} // namespace anon
-
-
 Paragraph::Private::Private(Paragraph * owner, Layout const & layout)
 	: owner_(owner), inset_owner_(0), id_(-1), begin_of_body_(0), layout_(&layout)
 {
@@ -1010,26 +980,6 @@ int Paragraph::Private::writeScriptChars(otexstream & os,
 }
 
 
-bool Paragraph::Private::isTextAt(string const & str, pos_type pos) const
-{
-	pos_type const len = str.length();
-
-	// is the paragraph large enough?
-	if (pos + len > int(text_.size()))
-		return false;
-
-	// does the wanted text start at point?
-	for (string::size_type i = 0; i < str.length(); ++i) {
-		// Caution: direct comparison of characters works only
-		// because str is pure ASCII.
-		if (str[i] != text_[pos + i])
-			return false;
-	}
-
-	return fontlist_.hasChangeInRange(pos, len);
-}
-
-
 void Paragraph::Private::latexInset(BufferParams const & bparams,
 				    otexstream & os,
 				    OutputParams & runparams,
@@ -1281,10 +1231,6 @@ void Paragraph::Private::latexSpecialChar(otexstream & os,
 		break;
 
 	default:
-		// LyX, LaTeX etc.
-		if (latexSpecialPhrase(os, i, end_pos, column, runparams))
-			return;
-
 		if (c == '\0')
 			return;
 
@@ -1397,33 +1343,6 @@ bool Paragraph::Private::latexSpecialT3(char_type const c, otexstream & os,
 }
 
 
-/// \param end_pos
-///   If [start_pos, end_pos) does not include entirely the special phrase, then
-///   do not apply the macro transformation.
-bool Paragraph::Private::latexSpecialPhrase(otexstream & os, pos_type & i, pos_type end_pos,
-	unsigned int & column, OutputParams const & runparams)
-{
-	// FIXME: if we have "LaTeX" with a font
-	// change in the middle (before the 'T', then
-	// the "TeX" part is still special cased.
-	// Really we should only operate this on
-	// "words" for some definition of word
-
-	for (size_t pnr = 0; pnr < phrases_nr; ++pnr) {
-		if (!isTextAt(special_phrases[pnr].phrase, i)
-		    || (end_pos != -1 && i + int(special_phrases[pnr].phrase.size()) > end_pos))
-			continue;
-		if (runparams.moving_arg)
-			os << "\\protect";
-		os << special_phrases[pnr].macro;
-		i += special_phrases[pnr].phrase.length() - 1;
-		column += special_phrases[pnr].macro.length() - 1;
-		return true;
-	}
-	return false;
-}
-
-
 void Paragraph::Private::validate(LaTeXFeatures & features) const
 {
 	if (layout_->inpreamble && inset_owner_) {
@@ -1501,13 +1420,6 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
 
 	// then the contents
 	for (pos_type i = 0; i < int(text_.size()) ; ++i) {
-		for (size_t pnr = 0; pnr < phrases_nr; ++pnr) {
-			if (!special_phrases[pnr].builtin
-			    && isTextAt(special_phrases[pnr].phrase, i)) {
-				features.require(special_phrases[pnr].phrase);
-				break;
-			}
-		}
 		BufferEncodings::validate(text_[i], features);
 	}
 }
diff --git a/src/Text.cpp b/src/Text.cpp
index 526a1b5..2b19a72 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -486,12 +486,18 @@ void Text::readParToken(Paragraph & par, Lexer & lex,
 	} else if (token == "\\color") {
 		lex.next();
 		setLyXColor(lex.getString(), font.fontInfo());
-	} else if (token == "\\SpecialChar") {
+	} else if (token == "\\SpecialChar" ||
+	           (token == "\\SpecialCharNoPassThru" &&
+	            !par.layout().pass_thru && !inset().isPassThru())) {
 		auto_ptr<Inset> inset;
 		inset.reset(new InsetSpecialChar);
 		inset->read(lex);
 		inset->setBuffer(*buf);
 		par.insertInset(par.size(), inset.release(), font, change);
+	} else if (token == "\\SpecialCharNoPassThru") {
+		lex.next();
+		docstring const s = ltrim(lex.getDocString(), "\\");
+		par.insert(par.size(), s, font, change);
 	} else if (token == "\\IPAChar") {
 		auto_ptr<Inset> inset;
 		inset.reset(new InsetIPAChar);
diff --git a/src/Text3.cpp b/src/Text3.cpp
index a6e1334..9d6815e 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -1188,6 +1188,14 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 			specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
 		else if (name == "menu-separator")
 			specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
+		else if (name == "lyx")
+			specialChar(cur, InsetSpecialChar::PHRASE_LYX);
+		else if (name == "tex")
+			specialChar(cur, InsetSpecialChar::PHRASE_TEX);
+		else if (name == "latex")
+			specialChar(cur, InsetSpecialChar::PHRASE_LATEX);
+		else if (name == "latex2e")
+			specialChar(cur, InsetSpecialChar::PHRASE_LATEX2E);
 		else if (name.empty())
 			lyxerr << "LyX function 'specialchar-insert' needs an argument." << endl;
 		else
diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp
index 59ce69a..77792b9 100644
--- a/src/insets/InsetSpecialChar.cpp
+++ b/src/insets/InsetSpecialChar.cpp
@@ -50,32 +50,43 @@ void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
 	dim.asc = fm.maxAscent();
 	dim.des = fm.maxDescent();
 
-	string s;
+	docstring s;
 	switch (kind_) {
 		case LIGATURE_BREAK:
-			s = "|";
+			s = from_ascii("|");
 			break;
 		case END_OF_SENTENCE:
-			s = ".";
+			s = from_ascii(".");
 			break;
 		case LDOTS:
-			s = ". . .";
+			s = from_ascii(". . .");
 			break;
 		case MENU_SEPARATOR:
-			s = " x ";
+			s = from_ascii(" x ");
 			break;
 		case HYPHENATION:
-			s = "-";
+			s = from_ascii("-");
 			break;
 		case SLASH:
-			s = "/";
+			s = from_ascii("/");
 			break;
 		case NOBREAKDASH:
-			s = "-";
+			s = from_ascii("-");
+			break;
+		case PHRASE_LYX:
+			s = from_ascii("LyX");
+			break;
+		case PHRASE_TEX:
+			s = from_ascii("TeX");
+			break;
+		case PHRASE_LATEX2E:
+			s = from_ascii("LaTeX2") + char_type(0x03b5);
+			break;
+		case PHRASE_LATEX:
+			s = from_ascii("LaTeX");
 			break;
 	}
-	docstring ds(s.begin(), s.end());
-	dim.wid = fm.width(ds);
+	dim.wid = fm.width(s);
 	if (kind_ == HYPHENATION && dim.wid > 5)
 		dim.wid -= 2; // to make it look shorter
 	
@@ -145,6 +156,22 @@ void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
 		pi.pain.text(x, y, char_type('-'), font);
 		break;
 	}
+	case PHRASE_LYX:
+		font.setColor(Color_special);
+		pi.pain.text(x, y, from_ascii("LyX"), font);
+		break;
+	case PHRASE_TEX:
+		font.setColor(Color_special);
+		pi.pain.text(x, y, from_ascii("TeX"), font);
+		break;
+	case PHRASE_LATEX2E:
+		font.setColor(Color_special);
+		pi.pain.text(x, y, from_ascii("LaTeX2") + char_type(0x03b5), font);
+		break;
+	case PHRASE_LATEX:
+		font.setColor(Color_special);
+		pi.pain.text(x, y, from_ascii("LaTeX"), font);
+		break;
 	}
 }
 
@@ -175,6 +202,18 @@ void InsetSpecialChar::write(ostream & os) const
 	case NOBREAKDASH:
 		command = "\\nobreakdash-";
 		break;
+	case PHRASE_LYX:
+		command = "\\LyX";
+		break;
+	case PHRASE_TEX:
+		command = "\\TeX";
+		break;
+	case PHRASE_LATEX2E:
+		command = "\\LaTeX2e";
+		break;
+	case PHRASE_LATEX:
+		command = "\\LaTeX";
+		break;
 	}
 	os << "\\SpecialChar " << command << "\n";
 }
@@ -200,6 +239,14 @@ void InsetSpecialChar::read(Lexer & lex)
 		kind_ = SLASH;
 	else if (command == "\\nobreakdash-")
 		kind_ = NOBREAKDASH;
+	else if (command == "\\LyX")
+		kind_ = PHRASE_LYX;
+	else if (command == "\\TeX")
+		kind_ = PHRASE_TEX;
+	else if (command == "\\LaTeX2e")
+		kind_ = PHRASE_LATEX2E;
+	else if (command == "\\LaTeX")
+		kind_ = PHRASE_LATEX;
 	else
 		lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
 }
@@ -235,6 +282,26 @@ void InsetSpecialChar::latex(otexstream & os,
 			os << "\\protect";
 		os << "\\nobreakdash-";
 		break;
+	case PHRASE_LYX:
+		if (rp.moving_arg)
+			os << "\\protect";
+		os << "\\LyX{}";
+		break;
+	case PHRASE_TEX:
+		if (rp.moving_arg)
+			os << "\\protect";
+		os << "\\TeX{}";
+		break;
+	case PHRASE_LATEX2E:
+		if (rp.moving_arg)
+			os << "\\protect";
+		os << "\\LaTeX2e{}";
+		break;
+	case PHRASE_LATEX:
+		if (rp.moving_arg)
+			os << "\\protect";
+		os << "\\LaTeX{}";
+		break;
 	}
 }
 
@@ -263,6 +330,19 @@ int InsetSpecialChar::plaintext(odocstringstream & os,
 	case NOBREAKDASH:
 		os.put(0x2011);
 		return 1;
+	case PHRASE_LYX:
+		os << "LyX";
+		return 3;
+	case PHRASE_TEX:
+		os << "TeX";
+		return 3;
+	case PHRASE_LATEX2E:
+		os << "LaTeX2";
+		os.put(0x03b5);
+		return 7;
+	case PHRASE_LATEX:
+		os << "LaTeX";
+		return 5;
 	}
 	return 0;
 }
@@ -289,6 +369,19 @@ int InsetSpecialChar::docbook(odocstream & os, OutputParams const &) const
 	case NOBREAKDASH:
 		os << '-';
 		break;
+	case PHRASE_LYX:
+		os << "LyX";
+		break;
+	case PHRASE_TEX:
+		os << "TeX";
+		break;
+	case PHRASE_LATEX2E:
+		os << "LaTeX2";
+		os.put(0x03b5);
+		break;
+	case PHRASE_LATEX:
+		os << "LaTeX";
+		break;
 	}
 	return 0;
 }
@@ -317,6 +410,18 @@ docstring InsetSpecialChar::xhtml(XHTMLStream & xs, OutputParams const &) const
 	case NOBREAKDASH:
 		xs << XHTMLStream::ESCAPE_NONE << "&#8209;";
 		break;
+	case PHRASE_LYX:
+		xs << "LyX";
+		break;
+	case PHRASE_TEX:
+		xs << "TeX";
+		break;
+	case PHRASE_LATEX2E:
+		xs << "LaTeX2" << XHTMLStream::ESCAPE_NONE << "&#x3b5;";
+		break;
+	case PHRASE_LATEX:
+		xs << "LaTeX";
+		break;
 	}
 	return docstring();
 }
@@ -352,6 +457,8 @@ void InsetSpecialChar::validate(LaTeXFeatures & features) const
 		features.require("lyxarrow");
 	if (kind_ == NOBREAKDASH)
 		features.require("amsmath");
+	if (kind_ == PHRASE_LYX)
+		features.require("LyX");
 }
 
 
diff --git a/src/insets/InsetSpecialChar.h b/src/insets/InsetSpecialChar.h
index 5ce620c..b1121dd 100644
--- a/src/insets/InsetSpecialChar.h
+++ b/src/insets/InsetSpecialChar.h
@@ -41,7 +41,15 @@ public:
 		/// breakable slash
 		SLASH,
 		/// protected dash
-		NOBREAKDASH
+		NOBREAKDASH,
+		/// LyX logo
+		PHRASE_LYX,
+		/// TeX logo
+		PHRASE_TEX,
+		/// LaTeX2e logo
+		PHRASE_LATEX2E,
+		/// LaTeX logo
+		PHRASE_LATEX
 	};
 
 	///
diff --git a/src/tex2lyx/test/CJK.lyx.lyx b/src/tex2lyx/test/CJK.lyx.lyx
index 8db24ed..f5b84a4 100644
--- a/src/tex2lyx/test/CJK.lyx.lyx
+++ b/src/tex2lyx/test/CJK.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass article
diff --git a/src/tex2lyx/test/CJKutf8.lyx.lyx b/src/tex2lyx/test/CJKutf8.lyx.lyx
index 1e98d78..e8a6b37 100644
--- a/src/tex2lyx/test/CJKutf8.lyx.lyx
+++ b/src/tex2lyx/test/CJKutf8.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass article
diff --git a/src/tex2lyx/test/DummyDocument.lyx.lyx b/src/tex2lyx/test/DummyDocument.lyx.lyx
index 0d9fd27..9727ed2 100644
--- a/src/tex2lyx/test/DummyDocument.lyx.lyx
+++ b/src/tex2lyx/test/DummyDocument.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass article
diff --git a/src/tex2lyx/test/Dummy~Document.lyx.lyx b/src/tex2lyx/test/Dummy~Document.lyx.lyx
index c92cfb5..d5f27bd 100644
--- a/src/tex2lyx/test/Dummy~Document.lyx.lyx
+++ b/src/tex2lyx/test/Dummy~Document.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass article
diff --git a/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx b/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
index fdabbdc..23580b3 100644
--- a/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
+++ b/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass article
diff --git a/src/tex2lyx/test/algo2e.lyx.lyx b/src/tex2lyx/test/algo2e.lyx.lyx
index 0f81d3b..e88af88 100644
--- a/src/tex2lyx/test/algo2e.lyx.lyx
+++ b/src/tex2lyx/test/algo2e.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass article
diff --git a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
index b83dfee..1b590c8 100644
--- a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
+++ b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass article
@@ -908,17 +908,7 @@ doublebox
 \end_layout
 
 \begin_layout Subsection
-
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LyX
-\end_layout
-
-\end_inset
-
- Boxes
+LyX Boxes
 \end_layout
 
 \begin_layout Standard
diff --git a/src/tex2lyx/test/test-insets.lyx.lyx b/src/tex2lyx/test/test-insets.lyx.lyx
index 9a80d48..1468d17 100644
--- a/src/tex2lyx/test/test-insets.lyx.lyx
+++ b/src/tex2lyx/test/test-insets.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass article
@@ -296,17 +296,7 @@ status collapsed
 
 \end_inset
 
- will be parsed in ERT, since 
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LyX
-\end_layout
-
-\end_inset
-
- does not support refstyle and prettyref natively at the same time.
+ will be parsed in ERT, since LyX does not support refstyle and prettyref natively at the same time.
 \end_layout
 
 \begin_layout Section
@@ -3130,7 +3120,8 @@ row
 \begin_inset Quotes erd
 \end_inset
 
- of the table can take up several lines. Note however that TeX
+ of the table can take up several lines. Note however that \SpecialChar \TeX
+
 \begin_inset space \space{}
 
 \end_inset
@@ -3457,17 +3448,7 @@ like this.
 \end_layout
 
 \begin_layout Standard
-From bug 7412 another example with more captions (can currently not produced in 
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LyX
-\end_layout
-
-\end_inset
-
-): 
+From bug 7412 another example with more captions (can currently not produced in LyX): 
 \begin_inset Tabular 
 <lyxtabular version="3" rows="45" columns="2">
 <features rotate="0" islongtable="true" lastFootEmpty="true">
@@ -5324,17 +5305,7 @@ Macros
 \end_layout
 
 \begin_layout Standard
-
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LyX
-\end_layout
-
-\end_inset
-
- supports several kinds of macros: def 
+LyX supports several kinds of macros: def 
 \begin_inset FormulaMacro
 \def\macroa #1{a #1 a}
 \end_inset
@@ -5904,17 +5875,7 @@ Special formattings
 \end_layout
 
 \begin_layout Subsection
-
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LyX
-\end_layout
-
-\end_inset
-
- line
+LyX line
 \end_layout
 
 \begin_layout Standard
@@ -6652,17 +6613,7 @@ linebreak[4]
 \end_layout
 
 \begin_layout Standard
-There are even newlines with weird arguments, but these are not handled by 
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LyX
-\end_layout
-
-\end_inset
-
-
+There are even newlines with weird arguments, but these are not handled by LyX
 \begin_inset ERT
 status collapsed
 
@@ -6736,34 +6687,14 @@ Then one has those macros with a long name for a short meaning, like ~, ^ or
 \backslash
 , \SpecialChar \slash{}
 , \SpecialChar \nobreakdash-
- and the characters that 
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LaTeX
-\end_layout
-
-\end_inset
-
- wants to espace because they are active, like _&#${}%.
+ and the characters that LaTeX wants to espace because they are active, like _&#${}%.
 \end_layout
 
 \begin_layout Standard
 And what about special characters like hyphe\SpecialChar \-
 nation mark, ellipsis\SpecialChar \ldots{}
 , and end-of-sentence\SpecialChar \@.
- 
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LyX
-\end_layout
-
-\end_inset
-
- also supports a menu separator\SpecialChar \menuseparator
+ LyX also supports a menu separator\SpecialChar \menuseparator
 and a spif\SpecialChar \textcompwordmark{}
 fy ligature break.
 \end_layout
@@ -6833,87 +6764,11 @@ status collapsed
 \end_layout
 
 \begin_layout Standard
-
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LyX
-\end_layout
-
-\end_inset
-
- translates the phrases 
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LyX
-\end_layout
-
-\end_inset
-
-, 
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-TeX
-\end_layout
-
-\end_inset
-
-, 
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LaTeX
-\end_layout
-
-\end_inset
-
-2e and 
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LaTeX
-\end_layout
-
-\end_inset
-
- to the commands LyX, TeX, LaTeX2e and LaTeX. If these phrases occur as part of other words (like 1
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LyX
-\end_layout
-
-\end_inset
-
- or a
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-TeX
-\end_layout
-
-\end_inset
-
- or 
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LaTeX
-\end_layout
-
-\end_inset
-
-3) they should not be put into ERT.
+LyX translates the phrases LyX, TeX, LaTeX2e and LaTeX to the commands \SpecialChar \LyX
+, \SpecialChar \TeX
+, \SpecialChar \LaTeXe
+ and \SpecialChar \LaTeX
+. If these phrases occur as part of other words (like 1LyX or aTeX or LaTeX3) they should not be put into ERT.
 \end_layout
 
 \begin_layout Standard
diff --git a/src/tex2lyx/test/test-memoir.lyx.lyx b/src/tex2lyx/test/test-memoir.lyx.lyx
index a072761..38e6f8d 100644
--- a/src/tex2lyx/test/test-memoir.lyx.lyx
+++ b/src/tex2lyx/test/test-memoir.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass memoir
diff --git a/src/tex2lyx/test/test-modules.lyx.lyx b/src/tex2lyx/test/test-modules.lyx.lyx
index 4bde71a..7070d36 100644
--- a/src/tex2lyx/test/test-modules.lyx.lyx
+++ b/src/tex2lyx/test/test-modules.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass amsart
@@ -89,17 +89,7 @@ The theorem is recognized is a style provided by the module theorems-ams, since
 \end_layout
 
 \begin_layout Standard
-The lemma is not recognized as a command provided by a module, since the preamble code is from an older version of 
-\begin_inset ERT
-status collapsed
-
-\begin_layout Plain Layout
-LyX
-\end_layout
-
-\end_inset
-
-, and modules are only loaded if the preamble code matches (otherwise you could easily get completely different output for some often used names like 
+The lemma is not recognized as a command provided by a module, since the preamble code is from an older version of LyX, and modules are only loaded if the preamble code matches (otherwise you could easily get completely different output for some often used names like 
 \backslash
 theorem.
 \end_layout
diff --git a/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx b/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx
index 07654f9..46beaea 100644
--- a/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx
+++ b/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass book
diff --git a/src/tex2lyx/test/test-scr.lyx.lyx b/src/tex2lyx/test/test-scr.lyx.lyx
index 31bd868..1e91df9 100644
--- a/src/tex2lyx/test/test-scr.lyx.lyx
+++ b/src/tex2lyx/test/test-scr.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass scrbook
diff --git a/src/tex2lyx/test/test-structure.lyx.lyx b/src/tex2lyx/test/test-structure.lyx.lyx
index 7cb176d..596f230 100644
--- a/src/tex2lyx/test/test-structure.lyx.lyx
+++ b/src/tex2lyx/test/test-structure.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass article
@@ -446,7 +446,8 @@ test1
 \end_layout
 
 \begin_layout Standard
-LyX is a document preparation system. It excels at letting you create complex technical and scientific articles with mathematics, cross-references, bibliographies, indices, etc. It is very good at documents of any length in which the usual processing abilities are required: automatic sectioning and pagination, spell checking, and so forth. It can also be used to write a letter to your mom, though granted, there are probably simpler programs available for that. It is definitely not the best tool for creating banners, flyers, or advertisements (we'll explain why later), though with some effort all these can be done, too.
+\SpecialChar \LyX
+ is a document preparation system. It excels at letting you create complex technical and scientific articles with mathematics, cross-references, bibliographies, indices, etc. It is very good at documents of any length in which the usual processing abilities are required: automatic sectioning and pagination, spell checking, and so forth. It can also be used to write a letter to your mom, though granted, there are probably simpler programs available for that. It is definitely not the best tool for creating banners, flyers, or advertisements (we'll explain why later), though with some effort all these can be done, too.
 \end_layout
 
 \begin_layout Standard
@@ -483,7 +484,8 @@ test2
 \end_layout
 
 \begin_layout Standard
-LyX is a document preparation system. It excels at letting you create complex technical and scientific articles with mathematics, cross-references, bibliographies, indices, etc. It is very good at documents of any length in which the usual processing abilities are required: automatic sectioning and pagination, spell checking, and so forth. It can also be used to write a letter to your mom, though granted, there are probably simpler programs available for that. It is definitely not the best tool for creating banners, flyers, or advertisements (we'll explain why later), though with some effort all these can be done, too.
+\SpecialChar \LyX
+ is a document preparation system. It excels at letting you create complex technical and scientific articles with mathematics, cross-references, bibliographies, indices, etc. It is very good at documents of any length in which the usual processing abilities are required: automatic sectioning and pagination, spell checking, and so forth. It can also be used to write a letter to your mom, though granted, there are probably simpler programs available for that. It is definitely not the best tool for creating banners, flyers, or advertisements (we'll explain why later), though with some effort all these can be done, too.
 \end_layout
 
 \begin_layout Standard
@@ -541,7 +543,8 @@ dfgd
 \end_layout
 
 \begin_layout Standard
-LyX is a document preparation system. It excels at letting you create complex technical and scientific articles with mathematics, cross-references, bibliographies, indices, etc. It is very good at documents of any length in which the usual processing abilities are required: automatic sectioning and pagination, spell checking, and so forth. It can also be used to write a letter to your mom, though granted, there are probably simpler programs available for that. It is definitely not the best tool for creating banners, flyers, or advertisements (we'll explain why later), though with some effort all these can be done, too.
+\SpecialChar \LyX
+ is a document preparation system. It excels at letting you create complex technical and scientific articles with mathematics, cross-references, bibliographies, indices, etc. It is very good at documents of any length in which the usual processing abilities are required: automatic sectioning and pagination, spell checking, and so forth. It can also be used to write a letter to your mom, though granted, there are probably simpler programs available for that. It is definitely not the best tool for creating banners, flyers, or advertisements (we'll explain why later), though with some effort all these can be done, too.
 \end_layout
 
 \begin_layout Standard
diff --git a/src/tex2lyx/test/test.lyx.lyx b/src/tex2lyx/test/test.lyx.lyx
index 08c0097..115209f 100644
--- a/src/tex2lyx/test/test.lyx.lyx
+++ b/src/tex2lyx/test/test.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass article
diff --git a/src/tex2lyx/test/verbatim.lyx.lyx b/src/tex2lyx/test/verbatim.lyx.lyx
index 94dca02..e16487d 100644
--- a/src/tex2lyx/test/verbatim.lyx.lyx
+++ b/src/tex2lyx/test/verbatim.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 481
+\lyxformat 482
 \begin_document
 \begin_header
 \textclass article
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 869fac9..5a55b87 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -249,12 +249,20 @@ char const * const known_coded_font_shapes[] = { "italic", "slanted",
 /// Known special characters which need skip_spaces_braces() afterwards
 char const * const known_special_chars[] = {"ldots",
 "lyxarrow", "textcompwordmark",
-"slash", "textasciitilde", "textasciicircum", "textbackslash", 0};
+"slash", "textasciitilde", "textasciicircum", "textbackslash",
+"LyX", "TeX", "LaTeXe",
+"LaTeX", 0};
+
+/// special characters from known_special_chars which may have a \\protect before
+char const * const known_special_protect_chars[] = {"LyX", "TeX",
+"LaTeXe", "LaTeX", 0};
 
 /// the same as known_special_chars with .lyx names
 char const * const known_coded_special_chars[] = {"\\SpecialChar \\ldots{}\n",
 "\\SpecialChar \\menuseparator\n", "\\SpecialChar \\textcompwordmark{}\n",
-"\\SpecialChar \\slash{}\n", "~", "^", "\n\\backslash\n", 0};
+"\\SpecialChar \\slash{}\n", "~", "^", "\n\\backslash\n",
+"\\SpecialChar \\LyX\n", "\\SpecialChar \\TeX\n", "\\SpecialChar \\LaTeXe\n",
+"\\SpecialChar \\LaTeX\n", 0};
 
 /*!
  * Graphics file extensions known by the dvips driver of the graphics package.
@@ -295,12 +303,6 @@ char const * const known_coded_spaces[] = { "space{}", "space{}",
 "hfill{}", "dotfill{}", "hrulefill{}", "leftarrowfill{}", "rightarrowfill{}",
 "upbracefill{}", "downbracefill{}", 0};
 
-/// These are translated by LyX to commands like "\\LyX{}", so we have to put
-/// 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};
-
 /// known TIPA combining diacritical marks
 char const * const known_tipa_marks[] = {"textsubwedge", "textsubumlaut",
 "textsubtilde", "textseagull", "textsubbridge", "textinvsubbridge",
@@ -2360,28 +2362,7 @@ 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();
-				for (int i = 1; i < *l && p.next_token().isAlnumASCII(); ++i)
-					phrase += p.get_token().cs();
-				if (is_known(phrase, known_coded_phrases)) {
-					output_ert_inset(os, phrase, context);
-					handled = true;
-					break;
-				} else {
-					for (size_t i = 1; i < phrase.length(); ++i)
-						p.putback();
-				}
-			}
-			if (!handled)
-				os << t.cs();
+			os << t.cs();
 		}
 
 		else if (t.cat() == catOther ||
@@ -3387,20 +3368,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 			end_inset(os);
 		}
 
-		else if (is_known(t.cs(), known_phrases) ||
-		         (t.cs() == "protect" &&
-		          p.next_token().cat() == catEscape &&
-		          is_known(p.next_token().cs(), known_phrases))) {
-			// LyX sometimes puts a \protect in front, so we have to ignore it
-			// FIXME: This needs to be changed when bug 4752 is fixed.
-			where = is_known(
-				t.cs() == "protect" ? p.get_token().cs() : t.cs(),
-				known_phrases);
-			context.check_layout(os);
-			os << known_coded_phrases[where - known_phrases];
-			skip_spaces_braces(p);
-		}
-
 		// handle refstyle first to catch \eqref which can also occur
 		// without refstyle. Only recognize these commands if
 		// refstyle.sty was found in the preamble (otherwise \eqref
@@ -3811,7 +3778,14 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 			p.setEncoding(enc, Encoding::inputenc);
 		}
 
-		else if ((where = is_known(t.cs(), known_special_chars))) {
+		else if (is_known(t.cs(), known_special_chars) ||
+		         (t.cs() == "protect" &&
+		          p.next_token().cat() == catEscape &&
+		          is_known(p.next_token().cs(), known_special_protect_chars))) {
+			// LyX sometimes puts a \protect in front, so we have to ignore it
+			where = is_known(
+				t.cs() == "protect" ? p.get_token().cs() : t.cs(),
+				known_special_chars);
 			context.check_layout(os);
 			os << known_coded_special_chars[where - known_special_chars];
 			skip_spaces_braces(p);
diff --git a/src/version.h b/src/version.h
index d1c7476..124a404 100644
--- a/src/version.h
+++ b/src/version.h
@@ -36,8 +36,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 481 // gb: endash and emdash
-#define LYX_FORMAT_TEX2LYX 481
+#define LYX_FORMAT_LYX 482 // gb: special phrases
+#define LYX_FORMAT_TEX2LYX 482
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER

Reply via email to