Author: baum
Date: Thu Dec 30 22:56:55 2010
New Revision: 37052
URL: http://www.lyx.org/trac/changeset/37052
Log:
Translate "\LyX{}" and "LyX" correctly in tex2lyx
Modified:
lyx-devel/trunk/src/tex2lyx/Parser.cpp
lyx-devel/trunk/src/tex2lyx/Parser.h
lyx-devel/trunk/src/tex2lyx/test/test-insets.tex
lyx-devel/trunk/src/tex2lyx/text.cpp
Modified: lyx-devel/trunk/src/tex2lyx/Parser.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/Parser.cpp Thu Dec 30 22:03:36 2010
(r37051)
+++ lyx-devel/trunk/src/tex2lyx/Parser.cpp Thu Dec 30 22:56:55 2010
(r37052)
@@ -12,6 +12,7 @@
#include "Encoding.h"
#include "Parser.h"
+#include "support/textutils.h"
#include <iostream>
@@ -120,6 +121,13 @@
}
+bool Token::isAlnumASCII() const
+{
+ return cat_ == catLetter ||
+ (cat_ == catOther && cs_.length() == 1 && isDigitASCII(cs_[0]));
+}
+
+
//
// Parser
//
Modified: lyx-devel/trunk/src/tex2lyx/Parser.h
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/Parser.h Thu Dec 30 22:03:36 2010
(r37051)
+++ lyx-devel/trunk/src/tex2lyx/Parser.h Thu Dec 30 22:56:55 2010
(r37052)
@@ -85,6 +85,8 @@
char character() const { return cs_.empty() ? 0 : cs_[0]; }
/// Returns the token verbatim
std::string asInput() const;
+ /// Is the token an alphanumerical character?
+ bool isAlnumASCII() const;
private:
///
Modified: lyx-devel/trunk/src/tex2lyx/test/test-insets.tex
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/test/test-insets.tex Thu Dec 30 22:03:36
2010 (r37051)
+++ lyx-devel/trunk/src/tex2lyx/test/test-insets.tex Thu Dec 30 22:56:55
2010 (r37052)
@@ -24,6 +24,7 @@
\usepackage{longtable}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
+\providecommand{\lyx}{l\kern-.1667em\lower.25em\hbox{y}\kern-.125e...@}
\newcommand{\lyxline}[1][1pt]{%
\par\noindent%
\rule[.5ex]{\linewidth}{#1}\par}
@@ -292,6 +293,9 @@
ellipsis\ldots, and end-of-senten...@. LyX also supports a menu
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{}.
+
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 Thu Dec 30 22:03:36 2010
(r37051)
+++ lyx-devel/trunk/src/tex2lyx/text.cpp Thu Dec 30 22:56:55 2010
(r37052)
@@ -201,6 +201,11 @@
"negthinspace{}", "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};
+
/// splits "x=z, y=b" into a map and an ordered keyword vector
void split_map(string const & s, map<string, string> & res, vector<string> &
keys)
@@ -1450,8 +1455,21 @@
handle_ert(os, s, context);
}
- else if (t.cat() == catLetter ||
- t.cat() == catOther ||
+ 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();
+ }
+ }
+
+ else if (t.cat() == catOther ||
t.cat() == catAlign ||
t.cat() == catParameter) {
// This translates "&" to "\\&" which may be wrong...
@@ -2103,6 +2121,13 @@
os << "\\lyxline";
}
+ else if (is_known(t.cs(), known_phrases)) {
+ char const * const * where = is_known(t.cs(),
known_phrases);
+ context.check_layout(os);
+ os << known_coded_phrases[where - known_phrases];
+ skip_spaces_braces(p);
+ }
+
else if (is_known(t.cs(), known_ref_commands)) {
context.check_layout(os);
begin_command_inset(os, "ref", t.cs());