After only 7 years ;-) I found time to finish a patch to support \baselineskip, see attached. The patch is a fileformat change.

\baselineskip is the distance between the baseline of 2 subsequent text lines in a paragraph. Therefore \vspace{\baselineskip} is a useful spacing.

I implemented the support so that \baselineskip is only available for vertical spacings. a horizontal \baselineskip makes not much sense, but is allowed by LaTeX. So if you say \baselineskip should also be available for \hspace, I will do so.

Concerning lyx2lyx I did purposely nothing for tables and graphics. We don't know the exact amount of pt of a \baselineskip because this is defined in the used document class. Therefore one cannot replace it with a pt value. To be super correct one would have to convert all tables and graphics to ERT that contains a \baselineskip unit. This is in my opinion overkill. No software I know is able to provide exactly the same functionality also for older version. With my patch the spacing is simply removed and users of older LyX versions can manually choose another spacing, see that attached LyX testfile.

regards Uwe

Attachment: baselineskip-test.lyx
Description: application/lyx

 development/FORMAT                              |  4 +++
 lib/lyx2lyx/lyx_2_3.py                          | 45 +++++++++++++++++++++++--
 src/Length.cpp                                  |  8 +++++
 src/Length.h                                    |  1 +
 src/frontends/qt4/GuiGraphics.cpp               |  3 ++
 src/frontends/qt4/GuiHSpace.cpp                 |  3 ++
 src/frontends/qt4/GuiTabular.cpp                |  4 +++
 src/insets/InsetGraphics.cpp                    |  1 +
 src/lengthcommon.cpp                            |  4 +--
 src/tex2lyx/test/box-color-size-space-align.tex |  1 +
 src/tex2lyx/text.cpp                            | 12 +++++--
 src/version.h                                   |  4 +--
 12 files changed, 80 insertions(+), 10 deletions(-)

diff --git a/development/FORMAT b/development/FORMAT
index c601311c83..43c5fc2e89 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -7,6 +7,10 @@ changes happened in particular if possible. A good example 
would be
 
 -----------------------
 
+2017-04-02 Uwe Stöhr <[email protected]>
+       * Format incremented to 536: support for \baselineskip.
+         - new length unit BLS
+
 2017-03-19 Enrico Forestieri <[email protected]>
        * Format incremented to 535: support for en/em-dash as ligatures.
          The en- and em-dashes (U+2013 and U+2014) are now exported as
diff --git a/lib/lyx2lyx/lyx_2_3.py b/lib/lyx2lyx/lyx_2_3.py
index ddf7822fb9..d8e0cece59 100644
--- a/lib/lyx2lyx/lyx_2_3.py
+++ b/lib/lyx2lyx/lyx_2_3.py
@@ -26,7 +26,7 @@ import sys, os
 
 from parser_tools import find_end_of, find_token_backwards, 
find_end_of_layout, \
     find_token, find_end_of_inset, get_value,  get_bool_value, \
-    get_containing_layout, get_quoted_value, del_token
+    get_containing_layout, get_quoted_value, del_token, find_re
 #  find_tokens, find_token_exact, is_in_inset, \
 #  check_token, get_option_value
 
@@ -1941,6 +1941,43 @@ def revert_dashligatures(document):
         i += 1
 
 
+def revert_baselineskip(document):
+  " Revert baselineskips to TeX code "
+  i = 0
+  vspaceLine = 0
+  hspaceLine = 0
+  while True:
+    regexp = re.compile(r'^.*baselineskip%.*$')
+    i = find_re(document.body, regexp, i)
+    if i == -1:
+      return
+    vspaceLine = find_token(document.body, "\\begin_inset VSpace", i - 1)
+    if  vspaceLine == i:
+      # output VSpace inset as TeX code
+      # first read out the values
+      beg = document.body[i].rfind("VSpace ");
+      end = document.body[i].rfind("baselineskip%");
+      baselineskip = float(document.body[i][beg + 7:end]);
+      # we store the value in percent, thus divide by 100
+      baselineskip = baselineskip/100;
+      baselineskip = str(baselineskip);
+      # check if it is the starred version
+      if document.body[i].find('*') != -1:
+        star = '*'
+      else:
+        star = ''
+      # now output TeX code
+      endInset = find_end_of_inset(document.body, i)
+      if endInset == -1:
+        document.warning("Malformed LyX document: Missing '\\end_inset' of 
VSpace inset.")
+        return
+      else:
+        document.body[vspaceLine: endInset + 1] = put_cmd_in_ert("\\vspace" + 
star + '{' + baselineskip + "\\baselineskip}")
+    hspaceLine = find_token(document.body, "\\begin_inset space \\hspace", i - 
1)
+          
+    i = i + 1
+
+
 ##
 # Conversion hub
 #
@@ -1973,11 +2010,13 @@ convert = [
            [532, [convert_literalparam]],
            [533, []],
            [534, []],
-           [535, [convert_dashligatures]]
+           [535, [convert_dashligatures]],
+           [536, []]
           ]
 
 revert =  [
-           [534, [revert_dashligatures]],
+           [535, [revert_baselineskip]],
+           [534, [revert_dashligatures, revert_baselineskip]],
            [533, [revert_chapterbib]],
            [532, [revert_multibib]],
            [531, [revert_literalparam]],
diff --git a/src/Length.cpp b/src/Length.cpp
index 3aa610f659..366d4eeea8 100644
--- a/src/Length.cpp
+++ b/src/Length.cpp
@@ -107,6 +107,9 @@ string const Length::asLatexString() const
        case PPH:
                os << formatFPNumber(val_ / 100.0) << "\\paperheight";
                break;
+       case BLS:
+               os << formatFPNumber(val_ / 100.0) << "\\baselineskip";
+               break;
        case UNIT_NONE:
                break;
        default:
@@ -147,6 +150,7 @@ string const Length::asHTMLString() const
        case PCW:
        case PTH:
        case PPH:
+       case BLS:
                // what it's a percentage of probably won't make sense for HTML,
                // so we'll assume people have chosen these appropriately
                os << formatFPNumber(val_) << '%';
@@ -291,6 +295,10 @@ double Length::inInch(double text_width, double em_width) 
const
        case Length::PPH:
                result = val_ * text_width * 2.2 / 100;
                break;
+       case Length::BLS:
+               // baselineskip is approx. 1.2 times the font size for the cmr 
fonts
+               result = val_ * em_width * 1.2 / 100;
+               break;
        case Length::UNIT_NONE:
                result = 0;  // this cannot happen
                break;
diff --git a/src/Length.h b/src/Length.h
index 2a8f064210..c04a41f394 100644
--- a/src/Length.h
+++ b/src/Length.h
@@ -58,6 +58,7 @@ public:
                PLW, //< Percent of LineWidth
                PTH, //< Percent of TextHeight          // Herbert 2002-05-16
                PPH, //< Percent of PaperHeight         // Herbert 2002-05-16
+               BLS, //< Percent of BaselineSkip        // uwestoehr 2017-04-01
                UNIT_NONE ///< no unit
        };
 
diff --git a/src/frontends/qt4/GuiGraphics.cpp 
b/src/frontends/qt4/GuiGraphics.cpp
index 7e4f9ef37b..f05e2846cf 100644
--- a/src/frontends/qt4/GuiGraphics.cpp
+++ b/src/frontends/qt4/GuiGraphics.cpp
@@ -152,6 +152,9 @@ GuiGraphics::GuiGraphics(GuiView & lv)
        connect(rotateOrderCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
 
+       // remove baselineskip from width units
+       widthUnit->removeUnit(Length::BLS);
+
        filename->setValidator(new PathValidator(true, filename));
        setFocusProxy(filename);
 
diff --git a/src/frontends/qt4/GuiHSpace.cpp b/src/frontends/qt4/GuiHSpace.cpp
index ad829ecd81..4e7d995fcd 100644
--- a/src/frontends/qt4/GuiHSpace.cpp
+++ b/src/frontends/qt4/GuiHSpace.cpp
@@ -92,6 +92,9 @@ GuiHSpace::GuiHSpace(bool math_mode, QWidget * parent)
        // initialize the length validator
        addCheckedWidget(valueLE, valueL);
        enableWidgets();
+
+       // remove baselineskip from units
+       unitCO->removeUnit(Length::BLS);
 }
 
 
diff --git a/src/frontends/qt4/GuiTabular.cpp b/src/frontends/qt4/GuiTabular.cpp
index b021836ac0..4d5f683b38 100644
--- a/src/frontends/qt4/GuiTabular.cpp
+++ b/src/frontends/qt4/GuiTabular.cpp
@@ -167,6 +167,10 @@ GuiTabular::GuiTabular(QWidget * parent)
        decimalPointED->setInputMask("X; ");
        decimalPointED->setMaxLength(1);
 
+       // remove baselineskip from width units
+       columnWidthUnitLC->removeUnit(Length::BLS);
+       tabularWidthUnitLC->removeUnit(Length::BLS);
+
        // initialize the length validator
        addCheckedWidget(columnWidthED, columnWidthLA);
        addCheckedWidget(multirowOffsetED, multirowOffsetLA);
diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp
index 1582874211..04ed735f68 100644
--- a/src/insets/InsetGraphics.cpp
+++ b/src/insets/InsetGraphics.cpp
@@ -413,6 +413,7 @@ docstring InsetGraphics::toDocbookLength(Length const & 
len) const
                case Length::PLW: // Percent of LineWidth
                case Length::PTH: // Percent of TextHeight
                case Length::PPH: // Percent of PaperHeight
+               case Length::BLS: // Percent of BaselineSkip
                        // Sigh, this will go wrong.
                        result << len.value() << "%";
                        break;
diff --git a/src/lengthcommon.cpp b/src/lengthcommon.cpp
index c4fe515e09..9665e09fe2 100644
--- a/src/lengthcommon.cpp
+++ b/src/lengthcommon.cpp
@@ -32,7 +32,7 @@ char const * const unit_name[] = {
        "bp", "cc", "cm", "dd", "em", "ex", "in", "mm", "mu",
        "pc", "pt", "sp",
        "text%",  "col%", "page%", "line%",
-       "theight%", "pheight%", "" };
+       "theight%", "pheight%", "baselineskip%", "" };
 
 int const num_units = int(sizeof(unit_name) / sizeof(unit_name[0]) - 1);
 
@@ -42,7 +42,7 @@ char const * const unit_name_gui[] = {
        N_("ex"), N_("in[[unit of measure]]"), N_("mm"), N_("mu[[unit of 
measure]]"), N_("pc"),
        N_("pt"), N_("sp"), N_("Text Width %"),
        N_("Column Width %"), N_("Page Width %"), N_("Line Width %"),
-       N_("Text Height %"), N_("Page Height %"), "" };
+       N_("Text Height %"), N_("Page Height %"), N_("Line Distance %"), "" };
 
 
 Length::UNIT unitFromString(string const & data)
diff --git a/src/tex2lyx/test/box-color-size-space-align.tex 
b/src/tex2lyx/test/box-color-size-space-align.tex
index 72d4b9de80..3518c88375 100644
--- a/src/tex2lyx/test/box-color-size-space-align.tex
+++ b/src/tex2lyx/test/box-color-size-space-align.tex
@@ -492,6 +492,7 @@ Lines can have a vfill \vfill in the middle.
 Lines can have a vfill \vspace{\fill} in the middle.
 Lines can have a protected vfill \vspace*{\fill} in the middle.
 Lines can have a vertical absolute space \vspace{2cm} in the middle.
+Lines can have a baselineskip \vspace{1.2\baselineskip} in the middle.
 Lines can have a vertical relative space \vspace{0.09\columnwidth} in the 
middle.
 Lines can have a vertical glue-length space \vspace{2cm minus 2bp plus 1cc} in 
the middle.
 Lines can have protected vertical space \vspace*{2cm} in the middle.
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index b3cbc46c66..986daf49fb 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -413,6 +413,9 @@ bool translate_len(string const & length, string & 
valstring, string & unit)
        } else if (unit == "\\textheight") {
                valstring = percentval;
                unit = "theight%" + endlen;
+       } else if (unit == "\\baselineskip") {
+               valstring = percentval;
+               unit = "baselineskip%" + endlen;
        }
        return true;
 }
@@ -4517,7 +4520,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, 
bool outer,
                                                // therefore handle them 
separately
                                                if (unit == "\\paperwidth" || 
unit == "\\columnwidth"
                                                        || unit == 
"\\textwidth" || unit == "\\linewidth"
-                                                       || unit == 
"\\textheight" || unit == "\\paperheight")
+                                                       || unit == 
"\\textheight" || unit == "\\paperheight"
+                                                       || unit == 
"\\baselineskip")
                                                        known_unit = true;
                                                break;
                                                         }
@@ -4546,7 +4550,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, 
bool outer,
                                        gluelength.replace(i, 6, "+");
                        }
 
-                       if (t.cs()[0] == 'h' && (known_unit || known_hspace || 
is_gluelength)) {
+                       if (t.cs()[0] == 'h' && (known_unit || known_hspace || 
is_gluelength)
+                               && unit != "\\baselineskip") {
+                               // because \baselineskip is only supported for 
\vspace
                                // Literal horizontal length or known variable
                                context.check_layout(os);
                                begin_inset(os, "space ");
@@ -4562,7 +4568,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, 
bool outer,
                                if (is_gluelength)
                                        os << "\n\\length " << gluelength;
                                end_inset(os);
-                       } else if (known_unit || known_vspace || is_gluelength) 
{
+                       } else if (t.cs()[0] == 'v' && (known_unit || 
known_vspace || is_gluelength)) {
                                // Literal vertical length or known variable
                                context.check_layout(os);
                                begin_inset(os, "VSpace ");
diff --git a/src/version.h b/src/version.h
index 5a03e0d312..c1fda54e62 100644
--- a/src/version.h
+++ b/src/version.h
@@ -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 535 // ef: support for en/em-dash as ligatures
-#define LYX_FORMAT_TEX2LYX 535
+#define LYX_FORMAT_LYX 536 // uwestoehr: support for \baselineskip
+#define LYX_FORMAT_TEX2LYX 536
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER

Reply via email to