]> git.lyx.org Git - features.git/commitdiff
Make InsetSpecialChar names more consistent
authorGeorg Baum <baum@lyx.org>
Mon, 23 Mar 2015 20:28:04 +0000 (21:28 +0100)
committerGeorg Baum <baum@lyx.org>
Mon, 23 Mar 2015 20:28:04 +0000 (21:28 +0100)
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.

21 files changed:
development/FORMAT
lib/lyx2lyx/LyX.py
lib/lyx2lyx/lyx_2_2.py
src/insets/InsetSpecialChar.cpp
src/tex2lyx/test/CJK.lyx.lyx
src/tex2lyx/test/CJKutf8.lyx.lyx
src/tex2lyx/test/DummyDocument.lyx.lyx
src/tex2lyx/test/Dummy~Document.lyx.lyx
src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
src/tex2lyx/test/algo2e.lyx.lyx
src/tex2lyx/test/box-color-size-space-align.lyx.lyx
src/tex2lyx/test/test-insets.lyx.lyx
src/tex2lyx/test/test-memoir.lyx.lyx
src/tex2lyx/test/test-modules.lyx.lyx
src/tex2lyx/test/test-refstyle-theorems.lyx.lyx
src/tex2lyx/test/test-scr.lyx.lyx
src/tex2lyx/test/test-structure.lyx.lyx
src/tex2lyx/test/test.lyx.lyx
src/tex2lyx/test/verbatim.lyx.lyx
src/tex2lyx/text.cpp
src/version.h

index bd51661f7538d852c91cc84e25651c2ab046bd73..dbdb1ad8b04f0db4e98ebf2607a3fd895b82f6f0 100644 (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
index 89b08c8d289228e3a2c45bbe42ea8c46185ab46c..d96b7b465ec0abae0340406facdb8c85b5447f4f 100644 (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))
                   ]
 
 ####################################################################
index b4ce71e53524726c61d6942891f1244375bd3625..94aa1e3415103903dbae541480032e3aaa3d553d 100644 (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]],
index 6d967bfada0a984ab43dacf1b035d452509bcf1c..8a52f166fc011cac31b0f2c34324c572cc23df76 100644 (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'");
index f5b84a4dfde17ac167c38299f2aa6cfcb0ea79c4..600b7a790fdb952bdc370b1c67e187a08ebcdb1c 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 482
+\lyxformat 483
 \begin_document
 \begin_header
 \textclass article
index e8a6b37d0419be5f6ffae46c596db2317c56d1c7..d44a7e0420d93415d56a34b7eb38a408a1f5aca5 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 482
+\lyxformat 483
 \begin_document
 \begin_header
 \textclass article
index 9727ed2f22c3cb4bcfc23fa7fd65d61477928899..6f69e69190918328c692db18fbb9db4f44b98f73 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 482
+\lyxformat 483
 \begin_document
 \begin_header
 \textclass article
index d5f27bd312a941ae4781734a610e1dc9c552fed9..5e47998e7a1b8a0709881250eb45cd33aa21d146 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 482
+\lyxformat 483
 \begin_document
 \begin_header
 \textclass article
index 23580b30dbde6844c6837cf0738bfa22561c9bae..6e17f477c216ee25494232890d3eeff7fa1e0414 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 482
+\lyxformat 483
 \begin_document
 \begin_header
 \textclass article
index dfb6c7adc26b757836cade18b553d0d17ae9350a..976b2127e8bd61c0fbf7d0ee032ed3c92bb94a4e 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 482
+\lyxformat 483
 \begin_document
 \begin_header
 \textclass article
index b08a0bfc41cecfe649b42f8ad1642fb154487c1c..776736a612e50c02657eb530123c6c2f74aa920d 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 482
+\lyxformat 483
 \begin_document
 \begin_header
 \textclass article
index 422775d890e95b41a624ba7c8d3f54df93ba274f..169ac5203b1175826d2540134eca24b70ff463c0 100644 (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
 
index 38e6f8d42f44f6ca00e0f1b6d9dab4d146af2a29..e294b206b7507ccb21da1bcf636d062a3b147b7c 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 482
+\lyxformat 483
 \begin_document
 \begin_header
 \textclass memoir
index 7070d3644d54be80755db59085a4e9aefd795841..3b7f8abd5002cbbcbf951a38731f7ba6ec09714c 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 482
+\lyxformat 483
 \begin_document
 \begin_header
 \textclass amsart
index 4ae6755b873764ddda44a660907cc442183d3cd9..eab4b599f00e9b905cd4557cc8c441b8e68071d5 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 482
+\lyxformat 483
 \begin_document
 \begin_header
 \textclass book
index 96589428d54eb99485ebb78746cf865e960a803a..91d502ece8aecce885a81170520f2b8b64b8b86e 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 482
+\lyxformat 483
 \begin_document
 \begin_header
 \textclass scrbook
index 1082c4546dfa31be69e78755a9a0bb27b37c248d..9fe5f1de0025dcc87debd3c4c55cc533dd01505b 100644 (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
 
index 115209f96ece1254c12beb1a298ee4b7801300c3..7c8ae41544beb61344839abc76cbc6d21c91ad42 100644 (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
index e16487dcf3efc1287d7190bcfb8bf2f1c3d88b3b..f756637ebdca88cf160528e1a586a7d01a54a6a2 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 482
+\lyxformat 483
 \begin_document
 \begin_header
 \textclass article
index 6a67b58f0be26dac52da06d5ff65e5d4d52937ef..33c389ba5f4bdb3115cf3eda260bae44fd99e40c 100644 (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();
                }
index 124a404c12f3674f959828a070ba717851d3dcf6..a112664fbf53d4d56de7b022780ed49e31d35771 100644 (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