Translate "\LyX{}" and "LyX" correctly in tex2lyx

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37052 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2010-12-30 21:56:55 +00:00
parent 05bd78904a
commit 3403727940
4 changed files with 41 additions and 2 deletions

View File

@ -12,6 +12,7 @@
#include "Encoding.h"
#include "Parser.h"
#include "support/textutils.h"
#include <iostream>
@ -120,6 +121,13 @@ string Token::asInput() const
}
bool Token::isAlnumASCII() const
{
return cat_ == catLetter ||
(cat_ == catOther && cs_.length() == 1 && isDigitASCII(cs_[0]));
}
//
// Parser
//

View File

@ -85,6 +85,8 @@ public:
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:
///

View File

@ -24,6 +24,7 @@
\usepackage{longtable}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\providecommand{\LyX}{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@}
\newcommand{\lyxline}[1][1pt]{%
\par\noindent%
\rule[.5ex]{\linewidth}{#1}\par}
@ -292,6 +293,9 @@ And what about special characters like hyphe\-nation mark,
ellipsis\ldots, and end-of-sentence\@. 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:

View File

@ -201,6 +201,11 @@ char const * const known_coded_spaces[] = { "space{}", "space{}",
"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 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
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 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
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());