]> git.lyx.org Git - features.git/commitdiff
Add support for medspace and thickspace (in text) (#11893)
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 26 Jun 2020 09:12:35 +0000 (11:12 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 26 Jun 2020 09:12:35 +0000 (11:12 +0200)
File format change.

lib/lyx2lyx/lyx_2_1.py
lib/lyx2lyx/lyx_2_4.py
lib/ui/stdcontext.inc
src/frontends/qt/GuiHSpace.cpp
src/insets/InsetSpace.cpp
src/tex2lyx/text.cpp
src/version.h

index 133d500f9ff31a26142586f6d8a6435504219c39..d370112aa5d71c3446a7d461a2fb48639a4993b1 100644 (file)
@@ -353,7 +353,7 @@ def revert_undertilde(document):
 
 
 def revert_negative_space(document):
-    "Revert InsetSpace negmedspace and negthickspace into its TeX-code counterpart"
+    "Revert InsetSpace negmedspace and negthickspace into their TeX-code counterparts"
     i = 0
     j = 0
     reverted = False
@@ -366,7 +366,7 @@ def revert_negative_space(document):
           if reverted == True:
             i = find_token(document.header, "\\use_amsmath 2", 0)
             if i == -1:
-              add_to_preamble(document, ["\\@ifundefined{negthickspace}{\\usepackage{amsmath}}"])
+              add_to_preamble(document, ["\\@ifundefined{negthickspace}{\\usepackage{amsmath}}{}"])
           return
       if i == -1:
         return
index 206365185e937a63eb97ceb96f008d1227613dce..f778b4aea764cd721a309935a6706e95e48309d3 100644 (file)
@@ -3753,6 +3753,28 @@ def revert_counter_inset(document):
     if pretext:
         add_to_preamble(document, pretext)
 
+
+def revert_ams_spaces(document):
+    "Revert InsetSpace medspace and thickspace into their TeX-code counterparts"
+    Found = False
+    insets = ["\\medspace{}", "\\thickspace{}"]
+    for inset in insets:
+        i = 0
+        j = 0
+        i = find_token(document.body, "\\begin_inset space " + inset, i)
+        if i == -1:
+            continue
+        end = find_end_of_inset(document.body, i)
+        subst = put_cmd_in_ert(inset)
+        document.body[i : end + 1] = subst
+        Found = True
+      
+    if Found == True:
+        # load amsmath in the preamble if not already loaded
+        i = find_token(document.header, "\\use_package amsmath 2", 0)
+        if i == -1:
+            add_to_preamble(document, ["\\@ifundefined{thickspace}{\\usepackage{amsmath}}{}"])
+            return
         
 ##
 # Conversion hub
@@ -3809,10 +3831,12 @@ convert = [
            [591, [convert_postpone_fragile]],
            [592, []],
            [593, [convert_counter_maintenance]],
-           [594, []]
+           [594, []],
+           [595, []]
           ]
 
-revert =  [[593, [revert_counter_inset]],
+revert =  [[594, [revert_ams_spaces]],
+           [593, [revert_counter_inset]],
            [592, [revert_counter_maintenance]],
            [591, [revert_colrow_tracking]],
            [590, [revert_postpone_fragile]],
index 120aac4dd94f2d32d89aaa8d32a3a168fafa85d8..2c28a85606b908019d6bc6d1b7fe86171ae0ad99 100644 (file)
@@ -244,6 +244,8 @@ Menuset
                Item "Protected Space|o" "inset-modify space ~"
                Item "Visible Space|a" "inset-modify space \textvisiblespace{}"
                Item "Thin Space|T" "inset-modify space \thinspace{}"
+               Item "Medium Space|M" "inset-modify space \medspace{}"
+               Item "Thick Space|i" "inset-modify space \thickspace{}"
                Item "Negative Thin Space|N" "inset-modify space \negthinspace{}"
                Item "Negative Medium Space|v" "inset-modify space \negmedspace{}"
                Item "Negative Thick Space|h" "inset-modify space \negthickspace{}"
@@ -252,7 +254,7 @@ Menuset
                Item "Quad Space|Q" "inset-modify space \quad{}"
                Item "Double Quad Space|u" "inset-modify space \qquad{}"
                Item "Horizontal Fill|F" "inset-modify space \hfill{}"
-               Item "Protected Horizontal Fill|i" "inset-modify space \hspace*{\fill}"
+               Item "Protected Horizontal Fill|z" "inset-modify space \hspace*{\fill}"
                Item "Horizontal Fill (Dots)|D" "inset-modify space \dotfill{}"
                Item "Horizontal Fill (Rule)|R" "inset-modify space \hrulefill{}"
                Item "Horizontal Fill (Left Arrow)|L" "inset-modify space \leftarrowfill{}"
index 4307ae0e0f35ec1f659719dc5f85ab542705ee63..9a1437009b9d2f79c258b694bf3469933f0cc9e1 100644 (file)
@@ -41,32 +41,20 @@ GuiHSpace::GuiHSpace(bool math_mode, QWidget * parent)
        setupUi(this);
 
        spacingCO->clear();
-       if (math_mode_) {
-               spacingCO->addItem(qt_("Interword Space"), "normal");
-               spacingCO->addItem(qt_("Thin Space"), "thinspace");
-               spacingCO->addItem(qt_("Medium Space"), "medspace");
-               spacingCO->addItem(qt_("Thick Space"), "thickspace");
-               spacingCO->addItem(qt_("Negative Thin Space"), "negthinspace");
-               spacingCO->addItem(qt_("Negative Medium Space"), "negmedspace");
-               spacingCO->addItem(qt_("Negative Thick Space"), "negthickspace");
-               spacingCO->addItem(qt_("Half Quad (0.5 em)"), "halfquad");
-               spacingCO->addItem(qt_("Quad (1 em)"), "quad");
-               spacingCO->addItem(qt_("Double Quad (2 em)"), "qquad");
-               spacingCO->addItem(qt_("Horizontal Fill"), "hfill");
-               spacingCO->addItem(qt_("Custom"), "custom");
-       } else {
-               spacingCO->addItem(qt_("Interword Space"), "normal");
-               spacingCO->addItem(qt_("Thin Space"), "thinspace");
-               spacingCO->addItem(qt_("Negative Thin Space"), "negthinspace");
-               spacingCO->addItem(qt_("Negative Medium Space"), "negmedspace");
-               spacingCO->addItem(qt_("Negative Thick Space"), "negthickspace");
-               spacingCO->addItem(qt_("Half Quad (0.5 em)"), "halfquad");
-               spacingCO->addItem(qt_("Quad (1 em)"), "quad");
-               spacingCO->addItem(qt_("Double Quad (2 em)"), "qquad");
-               spacingCO->addItem(qt_("Horizontal Fill"), "hfill");
-               spacingCO->addItem(qt_("Custom"), "custom");
+       spacingCO->addItem(qt_("Interword Space"), "normal");
+       spacingCO->addItem(qt_("Thin Space"), "thinspace");
+       spacingCO->addItem(qt_("Medium Space"), "medspace");
+       spacingCO->addItem(qt_("Thick Space"), "thickspace");
+       spacingCO->addItem(qt_("Negative Thin Space"), "negthinspace");
+       spacingCO->addItem(qt_("Negative Medium Space"), "negmedspace");
+       spacingCO->addItem(qt_("Negative Thick Space"), "negthickspace");
+       spacingCO->addItem(qt_("Half Quad (0.5 em)"), "halfquad");
+       spacingCO->addItem(qt_("Quad (1 em)"), "quad");
+       spacingCO->addItem(qt_("Double Quad (2 em)"), "qquad");
+       spacingCO->addItem(qt_("Horizontal Fill"), "hfill");
+       if (!math_mode_)
                spacingCO->addItem(qt_("Visible Space"), "visible");
-       }
+       spacingCO->addItem(qt_("Custom"), "custom");
 
        connect(spacingCO, SIGNAL(highlighted(QString)),
                this, SLOT(changedSlot()));
index 799568eadd0ca0165d4df6c50b423541c591e59b..84c6a2599c60ba163927bdc4b5f8e9a860a0788d 100644 (file)
@@ -516,9 +516,9 @@ void InsetSpaceParams::read(Lexer & lex)
                kind = InsetSpaceParams::VISIBLE;
        else if (command == "\\thinspace{}")
                kind = InsetSpaceParams::THIN;
-       else if (math && command == "\\medspace{}")
+       else if (command == "\\medspace{}")
                kind = InsetSpaceParams::MEDIUM;
-       else if (math && command == "\\thickspace{}")
+       else if (command == "\\thickspace{}")
                kind = InsetSpaceParams::THICK;
        else if (command == "\\quad{}")
                kind = InsetSpaceParams::QUAD;
@@ -597,10 +597,16 @@ void InsetSpace::latex(otexstream & os, OutputParams const & runparams) const
                os << (runparams.free_spacing ? " " : "\\,");
                break;
        case InsetSpaceParams::MEDIUM:
-               os << (runparams.free_spacing ? " " : "\\:");
+               if (params_.math)
+                       os << (runparams.free_spacing ? " " : "\\:");
+               else
+                       os << (runparams.free_spacing ? " " : "\\medspace{}");
                break;
        case InsetSpaceParams::THICK:
-               os << (runparams.free_spacing ? " " : "\\;");
+               if (params_.math)
+                       os << (runparams.free_spacing ? " " : "\\;");
+               else
+                       os << (runparams.free_spacing ? " " : "\\thickspace{}");
                break;
        case InsetSpaceParams::QUAD:
                os << (runparams.free_spacing ? " " : "\\quad{}");
@@ -867,8 +873,11 @@ docstring InsetSpace::xhtml(XMLStream & xs, OutputParams const &) const
 
 void InsetSpace::validate(LaTeXFeatures & features) const
 {
-       if (params_.kind == InsetSpaceParams::NEGMEDIUM ||
-           params_.kind == InsetSpaceParams::NEGTHICK)
+       if ((params_.kind == InsetSpaceParams::NEGMEDIUM
+            || params_.kind == InsetSpaceParams::NEGTHICK)
+           || (!params_.math
+               && (params_.kind == InsetSpaceParams::MEDIUM
+                   || params_.kind == InsetSpaceParams::THICK)))
                features.require("amsmath");
 }
 
index d1b35c431ebc37b0c11829026a1282f3dfb8c641..4053ddbfe928123d9cb1a5ea82955ff825058ba9 100644 (file)
@@ -318,16 +318,16 @@ char const * const known_tex_extensions[] = {"tex", 0};
 /// spaces known by InsetSpace
 char const * const known_spaces[] = { " ", "space", ",",
 "thinspace", "quad", "qquad", "enspace", "enskip",
-"negthinspace", "negmedspace", "negthickspace", "textvisiblespace",
-"hfill", "dotfill", "hrulefill", "leftarrowfill", "rightarrowfill",
-"upbracefill", "downbracefill", 0};
+"medspace", "thickspace", "negthinspace", "negmedspace", "negthickspace",
+"textvisiblespace", "hfill", "dotfill", "hrulefill", "leftarrowfill",
+"rightarrowfill", "upbracefill", "downbracefill", 0};
 
 /// the same as known_spaces with .lyx names
 char const * const known_coded_spaces[] = { "space{}", "space{}",
 "thinspace{}", "thinspace{}", "quad{}", "qquad{}", "enspace{}", "enskip{}",
-"negthinspace{}", "negmedspace{}", "negthickspace{}", "textvisiblespace{}",
-"hfill{}", "dotfill{}", "hrulefill{}", "leftarrowfill{}", "rightarrowfill{}",
-"upbracefill{}", "downbracefill{}", 0};
+"medspace{}", "thickspace{}", "negthinspace{}", "negmedspace{}", "negthickspace{}",
+"textvisiblespace{}", "hfill{}", "dotfill{}", "hrulefill{}", "leftarrowfill{}",
+"rightarrowfill{}", "upbracefill{}", "downbracefill{}", 0};
 
 /// known TIPA combining diacritical marks
 char const * const known_tipa_marks[] = {"textsubwedge", "textsubumlaut",
index 866fe10e95ba1287c1629bfcebc203f67ee218d4..fd40047cf46bb0468cd273a731ce3085876efe6d 100644 (file)
@@ -32,8 +32,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 594 // rikiheck: counter insets
-#define LYX_FORMAT_TEX2LYX 594
+#define LYX_FORMAT_LYX 595 // spitz: medspace and thickspace
+#define LYX_FORMAT_TEX2LYX 595
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER