On Mon, May 20, 2019 at 04:44:12PM +0200, Pavel Sanda wrote:
> Hi,
> 
> I'm not heavy user of lineno package for numbering of the lines
> in the margin, but I regularly need it for submissions and always
> need to google again for preamble two-liner:
> \usepackage{lineno}
> \linenumbers
> 
> What about adding checkbox '[X] Number lines', perhaps with field
> for additional parameters of lineno?

Like the attached.

It occurred to me that lineno might be used for referencing lines
in the document as well (and clickable with hyperref), not sure how
much work would it take to integrate with our label/crossref/hyperref
framework, did anyone used this lineno option before?

Pavel
diff --git a/development/FORMAT b/development/FORMAT
index fd2b6c4f93..31f9ed2e7e 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -7,6 +7,9 @@ changes happened in particular if possible. A good example 
would be
 
 -----------------------
 
+2019-05-21 Pavel Sanda <sa...@lyx.org>
+       * Format incremented to 575: add line numbering via lineno package
+
 2019-04-16  GĂźnter Milde <mi...@lyx.org>
         * Format incremented to 574: Ruby inset, fixes for Japanese.
 
diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py
index 56490855d9..866bbb2b86 100644
--- a/lib/lyx2lyx/lyx_2_4.py
+++ b/lib/lyx2lyx/lyx_2_4.py
@@ -1694,6 +1694,15 @@ def revert_utf8_japanese(document):
     if lang == "japanese-cjk":
         document.set_parameter("inputencoding", "utf8-cjk")
 
+def revert_lineno(document):
+    " Remove lineno package use."
+    i = find_token(document.header, "\\use_lineno", 0)
+    if i != -1:
+        del document.header[i]
+    i = find_token(document.header, "\\lineno_options", 0)
+    if i != -1:
+        del document.header[i]
+
 
 ##
 # Conversion hub
@@ -1731,9 +1740,11 @@ convert = [
            [572, [convert_notoFonts]],  # Added options thin, light, 
extralight for Noto
            [573, [convert_inputencoding_namechange]],
            [574, [convert_ruby_module, convert_utf8_japanese]],
+           [575, []],
           ]
 
-revert =  [[573, [revert_ruby_module, revert_utf8_japanese]],
+revert =  [[574, [revert_lineno]],
+           [573, [revert_ruby_module, revert_utf8_japanese]],
            [572, [revert_inputencoding_namechange]],
            [571, [revert_notoFonts]],
            [570, [revert_cmidruletrimming]],
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 523e5c9a01..dd7d950f54 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -475,6 +475,7 @@ BufferParams::BufferParams()
        output_sync = false;
        use_refstyle = true;
        use_minted = false;
+       use_lineno = false;
 
        // map current author
        author_map_[pimpl_->authorlist.get(0).bufferId()] = 0;
@@ -1118,6 +1119,11 @@ string BufferParams::readToken(Lexer & lex, string const 
& token,
                lex >> use_refstyle;
        } else if (token == "\\use_minted") {
                lex >> use_minted;
+       } else if (token == "\\use_lineno") {
+               lex >> use_lineno;
+       } else if (token == "\\lineno_options") {
+               lex.eatLine();
+               lineno_opts = trim(lex.getString());
        } else {
                lyxerr << "BufferParams::readToken(): Unknown token: " <<
                        token << endl;
@@ -1321,6 +1327,12 @@ void BufferParams::writeFile(ostream & os, Buffer const 
* buf) const
           << "\n\\use_refstyle " << use_refstyle
           << "\n\\use_minted " << use_minted
           << '\n';
+
+       if (use_lineno)
+               os << "\\use_lineno " << use_lineno << '\n';
+       if (!lineno_opts.empty())
+                os << "\\lineno_options " << lineno_opts << '\n';
+
        if (isbackgroundcolor == true)
                os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) 
<< '\n';
        if (isfontcolor == true)
@@ -2132,6 +2144,14 @@ bool BufferParams::writeLaTeX(otexstream & os, 
LaTeXFeatures & features,
                // hyperref loads this automatically
                os << "\\usepackage{nameref}\n";
 
+       if (use_lineno){
+               os << "\\usepackage";
+               if (!lineno_opts.empty())
+                       os << "[" << lineno_opts << "]";
+               os << "{lineno}\n";
+               os << "\\linenumbers\n";
+       }
+
        // bibtopic needs to be loaded after hyperref.
        // the dot provides the aux file naming which LyX can detect.
        if (features.mustProvide("bibtopic"))
diff --git a/src/BufferParams.h b/src/BufferParams.h
index 5c80670a8a..1e8b5b00f1 100644
--- a/src/BufferParams.h
+++ b/src/BufferParams.h
@@ -550,6 +550,10 @@ public:
        bool use_refstyle;
        /// use minted? or listings?
        bool use_minted;
+       //output line numbering
+       bool use_lineno;
+       //optional params for lineno package
+       std::string lineno_opts;
 
        /// Return true if language could be set to lang,
        /// otherwise return false and do not change language
diff --git a/src/frontends/qt4/GuiDocument.cpp 
b/src/frontends/qt4/GuiDocument.cpp
index 23bb35cb87..48bc112a3e 100644
--- a/src/frontends/qt4/GuiDocument.cpp
+++ b/src/frontends/qt4/GuiDocument.cpp
@@ -1253,6 +1253,11 @@ GuiDocument::GuiDocument(GuiView & lv)
        numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
        numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
        setSectionResizeMode(numberingModule->tocTW->header(), 
QHeaderView::ResizeToContents);
+       connect(numberingModule->linenoGB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(numberingModule->linenoLE, SIGNAL(textChanged(QString)),
+               this, SLOT(change_adaptor()));
+
 
        // biblio
        biblioModule = new UiWidget<Ui::BiblioUi>(this);
@@ -3282,6 +3287,8 @@ void GuiDocument::applyView()
                bp_.tocdepth = numberingModule->tocSL->value();
                bp_.secnumdepth = numberingModule->depthSL->value();
        }
+       bp_.use_lineno = numberingModule->linenoGB->isChecked();
+       bp_.lineno_opts = fromqstr(numberingModule->linenoLE->text());
 
        // bullets
        bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
@@ -3806,6 +3813,9 @@ void GuiDocument::paramsToDialog()
                numberingModule->tocTW->clear();
        }
 
+       numberingModule->linenoGB->setChecked(bp_.use_lineno);
+       numberingModule->linenoLE->setText(toqstr(bp_.lineno_opts));
+
        // bullets
        bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
        bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
diff --git a/src/frontends/qt4/ui/NumberingUi.ui 
b/src/frontends/qt4/ui/NumberingUi.ui
index 3cd91a955e..7927862f2b 100644
--- a/src/frontends/qt4/ui/NumberingUi.ui
+++ b/src/frontends/qt4/ui/NumberingUi.ui
@@ -1,7 +1,8 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>NumberingUi</class>
- <widget class="QWidget" name="NumberingUi" >
-  <property name="geometry" >
+ <widget class="QWidget" name="NumberingUi">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
@@ -9,82 +10,134 @@
     <height>323</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string/>
   </property>
-  <layout class="QGridLayout" >
-   <property name="margin" >
+  <layout class="QGridLayout">
+   <property name="leftMargin">
     <number>9</number>
    </property>
-   <property name="spacing" >
+   <property name="topMargin">
+    <number>9</number>
+   </property>
+   <property name="rightMargin">
+    <number>9</number>
+   </property>
+   <property name="bottomMargin">
+    <number>9</number>
+   </property>
+   <property name="spacing">
     <number>6</number>
    </property>
-   <item row="4" column="0" >
-    <widget class="QTreeWidget" name="tocTW" />
+   <item row="4" column="0">
+    <widget class="QTreeWidget" name="tocTW">
+     <column>
+      <property name="text">
+       <string notr="true">1</string>
+      </property>
+     </column>
+    </widget>
    </item>
-   <item row="3" column="0" >
-    <widget class="QSlider" name="tocSL" >
-     <property name="minimum" >
+   <item row="3" column="0">
+    <widget class="QSlider" name="tocSL">
+     <property name="minimum">
       <number>-1</number>
      </property>
-     <property name="maximum" >
+     <property name="maximum">
       <number>5</number>
      </property>
-     <property name="value" >
+     <property name="value">
       <number>3</number>
      </property>
-     <property name="orientation" >
+     <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
     </widget>
    </item>
-   <item row="1" column="0" >
-    <widget class="QSlider" name="depthSL" >
-     <property name="minimum" >
+   <item row="1" column="0">
+    <widget class="QSlider" name="depthSL">
+     <property name="minimum">
       <number>-2</number>
      </property>
-     <property name="maximum" >
+     <property name="maximum">
       <number>5</number>
      </property>
-     <property name="value" >
+     <property name="value">
       <number>3</number>
      </property>
-     <property name="orientation" >
+     <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
     </widget>
    </item>
-   <item row="2" column="0" >
-    <widget class="QLabel" name="TextLabel1" >
-     <property name="text" >
+   <item row="2" column="0">
+    <widget class="QLabel" name="TextLabel1">
+     <property name="text">
       <string>&amp;List in Table of Contents</string>
      </property>
-     <property name="buddy" >
+     <property name="buddy">
       <cstring>tocSL</cstring>
      </property>
     </widget>
    </item>
-   <item row="0" column="0" >
-    <widget class="QLabel" name="TextLabel1_2" >
-     <property name="text" >
+   <item row="0" column="0">
+    <widget class="QLabel" name="TextLabel1_2">
+     <property name="text">
       <string>&amp;Numbering</string>
      </property>
-     <property name="buddy" >
+     <property name="buddy">
       <cstring>depthSL</cstring>
      </property>
     </widget>
    </item>
+   <item row="5" column="0">
+    <widget class="QGroupBox" name="linenoGB">
+     <property name="enabled">
+      <bool>true</bool>
+     </property>
+     <property name="title">
+      <string>L&amp;ines numbering</string>
+     </property>
+     <property name="flat">
+      <bool>true</bool>
+     </property>
+     <property name="checkable">
+      <bool>true</bool>
+     </property>
+     <property name="checked">
+      <bool>false</bool>
+     </property>
+     <layout class="QHBoxLayout" name="horizontalLayout">
+      <item>
+       <widget class="QLabel" name="label">
+        <property name="text">
+         <string>Additional O&amp;ptions:</string>
+        </property>
+        <property name="buddy">
+         <cstring>linenoLE</cstring>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QLineEdit" name="linenoLE">
+        <property name="toolTip">
+         <string>lineno package options (e.g. right, modulo, switch, 
displaymath, mathlines,...)</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
   </layout>
  </widget>
- <pixmapfunction></pixmapfunction>
- <includes>
-  <include location="local" >qt_i18n.h</include>
- </includes>
  <tabstops>
   <tabstop>depthSL</tabstop>
   <tabstop>tocSL</tabstop>
   <tabstop>tocTW</tabstop>
  </tabstops>
+ <includes>
+  <include location="local">qt_i18n.h</include>
+ </includes>
  <resources/>
  <connections/>
 </ui>
diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt
index d1760ace51..c64cdccab0 100644
--- a/src/tex2lyx/TODO.txt
+++ b/src/tex2lyx/TODO.txt
@@ -34,6 +34,7 @@ Format LaTeX feature                        LyX feature
 443    unicode-math.sty                     InsetMath*
 453    automatic stmaryrd loading           \use_package stmaryrd
 457    automatic stackrel loading           \use_package stackrel
+575    numbering of lines (lineno)          \use_lineno, \lineno_options
 
 
 
diff --git a/src/version.h b/src/version.h
index a92854e8a9..496e34b8ee 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 574 // gm: Japanese fixes
-#define LYX_FORMAT_TEX2LYX 574
+#define LYX_FORMAT_LYX 575 // ps: lineno
+#define LYX_FORMAT_TEX2LYX 575
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER

Reply via email to