From: Georg Baum Date: Mon, 23 Mar 2015 20:28:04 +0000 (+0100) Subject: Make InsetSpecialChar names more consistent X-Git-Tag: 2.2.0alpha1~1114 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=49ac79100bc36bcd8e54c0224596ae36af9c3c77;p=features.git 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. --- diff --git a/development/FORMAT b/development/FORMAT index bd51661f75..dbdb1ad8b0 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -11,6 +11,21 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx. ----------------------- +2015-03-23 Georg Baum + * 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 * Format incremented to 482 "LyX", "TeX", "LaTeX2e" and "LaTeX" are not automatically converted diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index 89b08c8d28..d96b7b465e 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", 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)) ] #################################################################### diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py index b4ce71e535..94aa1e3415 100644 --- a/lib/lyx2lyx/lyx_2_2.py +++ b/lib/lyx2lyx/lyx_2_2.py @@ -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]], diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp index 6d967bfada..8a52f166fc 100644 --- a/src/insets/InsetSpecialChar.cpp +++ b/src/insets/InsetSpecialChar.cpp @@ -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'"); diff --git a/src/tex2lyx/test/CJK.lyx.lyx b/src/tex2lyx/test/CJK.lyx.lyx index f5b84a4dfd..600b7a790f 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 482 +\lyxformat 483 \begin_document \begin_header \textclass article diff --git a/src/tex2lyx/test/CJKutf8.lyx.lyx b/src/tex2lyx/test/CJKutf8.lyx.lyx index e8a6b37d04..d44a7e0420 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 482 +\lyxformat 483 \begin_document \begin_header \textclass article diff --git a/src/tex2lyx/test/DummyDocument.lyx.lyx b/src/tex2lyx/test/DummyDocument.lyx.lyx index 9727ed2f22..6f69e69190 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 482 +\lyxformat 483 \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 d5f27bd312..5e47998e7a 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 482 +\lyxformat 483 \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 23580b30db..6e17f477c2 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 482 +\lyxformat 483 \begin_document \begin_header \textclass article diff --git a/src/tex2lyx/test/algo2e.lyx.lyx b/src/tex2lyx/test/algo2e.lyx.lyx index dfb6c7adc2..976b2127e8 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 482 +\lyxformat 483 \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 b08a0bfc41..776736a612 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 482 +\lyxformat 483 \begin_document \begin_header \textclass article diff --git a/src/tex2lyx/test/test-insets.lyx.lyx b/src/tex2lyx/test/test-insets.lyx.lyx index 422775d890..169ac5203b 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 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 diff --git a/src/tex2lyx/test/test-memoir.lyx.lyx b/src/tex2lyx/test/test-memoir.lyx.lyx index 38e6f8d42f..e294b206b7 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 482 +\lyxformat 483 \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 7070d3644d..3b7f8abd50 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 482 +\lyxformat 483 \begin_document \begin_header \textclass amsart diff --git a/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx b/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx index 4ae6755b87..eab4b599f0 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 482 +\lyxformat 483 \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 96589428d5..91d502ece8 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 482 +\lyxformat 483 \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 1082c4546d..9fe5f1de00 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 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 diff --git a/src/tex2lyx/test/test.lyx.lyx b/src/tex2lyx/test/test.lyx.lyx index 115209f96e..7c8ae41544 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 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 diff --git a/src/tex2lyx/test/verbatim.lyx.lyx b/src/tex2lyx/test/verbatim.lyx.lyx index e16487dcf3..f756637ebd 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 482 +\lyxformat 483 \begin_document \begin_header \textclass article diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 6a67b58f0b..33c389ba5f 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -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(); } diff --git a/src/version.h b/src/version.h index 124a404c12..a112664fbf 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 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