Make InsetSpecialChar names more consistent

This is the rersult of a discussion on the list. Now all special characters
have meaningful names, and it is clear that the LyX file syntax is not LaTeX.
This commit is contained in:
Georg Baum 2015-03-23 21:28:04 +01:00
parent 9e8ebce2bd
commit 49ac79100b
21 changed files with 131 additions and 68 deletions

View File

@ -11,6 +11,21 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
-----------------------
2015-03-23 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* Format incremented to 483
Make InsetSpecialChar names more consistent:
\- => softhyphen
\textcompwordmark{} => ligaturebreak
\@. => endofsentence
\ldots{} => ldots
\menuseparator => menuseparator
\slash{} => breakableslash
\nobreakdash- => nobreakdash
\LyX => LyX
\TeX => TeX
\LaTeX2e => LaTeX2e
\LaTeX => LaTeX
2015-03-01 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* Format incremented to 482
"LyX", "TeX", "LaTeX2e" and "LaTeX" are not automatically converted

View File

@ -85,7 +85,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)),
("1_6", list(range(277,346)), minor_versions("1.6" , 10)),
("2_0", list(range(346,414)), minor_versions("2.0", 8)),
("2_1", list(range(414,475)), minor_versions("2.1", 0)),
("2_2", list(range(475,483)), minor_versions("2.2", 0))
("2_2", list(range(475,484)), minor_versions("2.2", 0))
]
####################################################################

View File

@ -645,6 +645,49 @@ def revert_phrases(document):
i += 1
def convert_specialchar_internal(document, forward):
specialchars = {"\\-":"softhyphen", "\\textcompwordmark{}":"ligaturebreak", \
"\\@.":"endofsentence", "\\ldots{}":"ldots", \
"\\menuseparator":"menuseparator", "\\slash{}":"breakableslash", \
"\\nobreakdash-":"nobreakdash", "\\LyX":"LyX", \
"\\TeX":"TeX", "\\LaTeX2e":"LaTeX2e", \
"\\LaTeX":"LaTeX" # must be after LaTeX2e
}
i = 0
while i < len(document.body):
words = document.body[i].split()
if len(words) > 1 and words[0] == "\\begin_inset" and \
words[1] in ["CommandInset", "External", "Formula", "Graphics", "listings"]:
# see convert_phrases
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
for key, value in specialchars.iteritems():
if forward:
document.body[i] = document.body[i].replace("\\SpecialChar " + key, "\\SpecialChar " + value)
document.body[i] = document.body[i].replace("\\SpecialCharNoPassThru " + key, "\\SpecialCharNoPassThru " + value)
else:
document.body[i] = document.body[i].replace("\\SpecialChar " + value, "\\SpecialChar " + key)
document.body[i] = document.body[i].replace("\\SpecialCharNoPassThru " + value, "\\SpecialCharNoPassThru " + key)
i += 1
def convert_specialchar(document):
"convert special characters to new syntax"
convert_specialchar_internal(document, True)
def revert_specialchar(document):
"convert special characters to old syntax"
convert_specialchar_internal(document, False)
##
# Conversion hub
#
@ -661,10 +704,12 @@ convert = [
[479, []],
[480, []],
[481, [convert_dashes]],
[482, [convert_phrases]]
[482, [convert_phrases]],
[483, [convert_specialchar]]
]
revert = [
[482, [revert_specialchar]],
[481, [revert_phrases]],
[480, [revert_dashes]],
[479, [revert_question_env]],

View File

@ -283,37 +283,37 @@ void InsetSpecialChar::write(ostream & os) const
string command;
switch (kind_) {
case HYPHENATION:
command = "\\-";
command = "softhyphen";
break;
case LIGATURE_BREAK:
command = "\\textcompwordmark{}";
command = "ligaturebreak";
break;
case END_OF_SENTENCE:
command = "\\@.";
command = "endofsentence";
break;
case LDOTS:
command = "\\ldots{}";
command = "ldots";
break;
case MENU_SEPARATOR:
command = "\\menuseparator";
command = "menuseparator";
break;
case SLASH:
command = "\\slash{}";
command = "breakableslash";
break;
case NOBREAKDASH:
command = "\\nobreakdash-";
command = "nobreakdash";
break;
case PHRASE_LYX:
command = "\\LyX";
command = "LyX";
break;
case PHRASE_TEX:
command = "\\TeX";
command = "TeX";
break;
case PHRASE_LATEX2E:
command = "\\LaTeX2e";
command = "LaTeX2e";
break;
case PHRASE_LATEX:
command = "\\LaTeX";
command = "LaTeX";
break;
}
os << "\\SpecialChar " << command << "\n";
@ -326,27 +326,27 @@ void InsetSpecialChar::read(Lexer & lex)
lex.next();
string const command = lex.getString();
if (command == "\\-")
if (command == "softhyphen")
kind_ = HYPHENATION;
else if (command == "\\textcompwordmark{}")
else if (command == "ligaturebreak")
kind_ = LIGATURE_BREAK;
else if (command == "\\@.")
else if (command == "endofsentence")
kind_ = END_OF_SENTENCE;
else if (command == "\\ldots{}")
else if (command == "ldots")
kind_ = LDOTS;
else if (command == "\\menuseparator")
else if (command == "menuseparator")
kind_ = MENU_SEPARATOR;
else if (command == "\\slash{}")
else if (command == "breakableslash")
kind_ = SLASH;
else if (command == "\\nobreakdash-")
else if (command == "nobreakdash")
kind_ = NOBREAKDASH;
else if (command == "\\LyX")
else if (command == "LyX")
kind_ = PHRASE_LYX;
else if (command == "\\TeX")
else if (command == "TeX")
kind_ = PHRASE_TEX;
else if (command == "\\LaTeX2e")
else if (command == "LaTeX2e")
kind_ = PHRASE_LATEX2E;
else if (command == "\\LaTeX")
else if (command == "LaTeX")
kind_ = PHRASE_LATEX;
else
lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass article

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass article

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass article

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass article

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass article

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass article

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass article

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass article
@ -3120,7 +3120,7 @@ row
\begin_inset Quotes erd
\end_inset
of the table can take up several lines. Note however that \SpecialChar \TeX
of the table can take up several lines. Note however that \SpecialChar TeX
\begin_inset space \space{}
@ -6685,17 +6685,17 @@ Special characters
\begin_layout Standard
Then one has those macros with a long name for a short meaning, like ~, ^ or
\backslash
, \SpecialChar \slash{}
, \SpecialChar \nobreakdash-
, \SpecialChar breakableslash
, \SpecialChar nobreakdash
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 \@.
LyX also supports a menu separator\SpecialChar \menuseparator
and a spif\SpecialChar \textcompwordmark{}
And what about special characters like hyphe\SpecialChar softhyphen
nation mark, ellipsis\SpecialChar ldots
, and end-of-sentence\SpecialChar endofsentence
LyX also supports a menu separator\SpecialChar menuseparator
and a spif\SpecialChar ligaturebreak
fy ligature break.
\end_layout
@ -6764,10 +6764,10 @@ status collapsed
\end_layout
\begin_layout Standard
LyX translates the phrases LyX, TeX, LaTeX2e and LaTeX to the commands \SpecialChar \LyX
, \SpecialChar \TeX
, \SpecialChar \LaTeX2e
and \SpecialChar \LaTeX
LyX translates the phrases LyX, TeX, LaTeX2e and LaTeX to the commands \SpecialChar LyX
, \SpecialChar TeX
, \SpecialChar LaTeX2e
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

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass memoir

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass amsart

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass book

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass scrbook

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass article
@ -446,7 +446,7 @@ test1
\end_layout
\begin_layout Standard
\SpecialChar \LyX
\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
@ -484,7 +484,7 @@ test2
\end_layout
\begin_layout Standard
\SpecialChar \LyX
\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
@ -543,7 +543,7 @@ dfgd
\end_layout
\begin_layout Standard
\SpecialChar \LyX
\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

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass article
@ -137,7 +137,7 @@ status open
\begin_layout Standard
What are you doing \SpecialChar \ldots{}
What are you doing \SpecialChar ldots
Dave
\end_layout
@ -242,17 +242,17 @@ status collapsed
\end_inset
is text in a new par\SpecialChar \-
is text in a new par\SpecialChar softhyphen
agraph.
\begin_inset Newline newline
\end_inset
It has \SpecialChar \ldots{}
It has \SpecialChar ldots
an
\begin_inset Formula $ \alpha $
\end_inset
in it, which is OK\SpecialChar \@.
in it, which is OK\SpecialChar endofsentence
I can type special characters
\begin_inset Foot
status collapsed

View File

@ -1,5 +1,5 @@
#LyX file created by tex2lyx 2.2
\lyxformat 482
\lyxformat 483
\begin_document
\begin_header
\textclass article

View File

@ -258,11 +258,11 @@ 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",
"\\SpecialChar \\LyX\n", "\\SpecialChar \\TeX\n", "\\SpecialChar \\LaTeX2e\n",
"\\SpecialChar \\LaTeX\n", 0};
char const * const known_coded_special_chars[] = {"\\SpecialChar ldots\n",
"\\SpecialChar menuseparator\n", "\\SpecialChar ligaturebreak\n",
"\\SpecialChar breakableslash\n", "~", "^", "\n\\backslash\n",
"\\SpecialChar LyX\n", "\\SpecialChar TeX\n", "\\SpecialChar LaTeX2e\n",
"\\SpecialChar LaTeX\n", 0};
/*!
* Graphics file extensions known by the dvips driver of the graphics package.
@ -3800,8 +3800,11 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
if (t.cs() == "protect")
p.get_token();
context.check_layout(os);
os << "\\SpecialChar \\" << t.cs()
<< p.get_token().asInput() << '\n';
if (t.cs() == "nobreakdash")
os << "\\SpecialChar nobreakdash\n";
else
os << "\\SpecialChar endofsentence\n";
p.get_token();
}
else if (t.cs() == "textquotedbl") {
@ -3815,7 +3818,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|| t.cs() == "%" || t.cs() == "-") {
context.check_layout(os);
if (t.cs() == "-")
os << "\\SpecialChar \\-\n";
os << "\\SpecialChar softhyphen\n";
else
os << t.cs();
}

View File

@ -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 482 // gb: special phrases
#define LYX_FORMAT_TEX2LYX 482
#define LYX_FORMAT_LYX 483 // gb: sanitize SpecialChar format
#define LYX_FORMAT_TEX2LYX 483
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER