From 7f125f62d2cfeacdb820aee5ef39f86eb82db3ae Mon Sep 17 00:00:00 2001 From: Pavel Sanda Date: Thu, 23 May 2019 15:13:27 +0200 Subject: [PATCH] Introduce doc preference for line numbering. https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg208781.html --- development/FORMAT | 3 +++ lib/lyx2lyx/lyx_2_4.py | 13 +++++++++- src/BufferParams.cpp | 20 +++++++++++++++ src/BufferParams.h | 4 +++ src/frontends/qt4/GuiDocument.cpp | 10 ++++++++ src/frontends/qt4/ui/NumberingUi.ui | 38 +++++++++++++++++++++++++++++ src/tex2lyx/TODO.txt | 1 + src/version.h | 4 +-- 8 files changed, 90 insertions(+), 3 deletions(-) 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 + * Format incremented to 575: add line numbering via lineno package + 2019-04-16 Günter Milde * 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(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 39bed38af5..7927862f2b 100644 --- a/src/frontends/qt4/ui/NumberingUi.ui +++ b/src/frontends/qt4/ui/NumberingUi.ui @@ -90,6 +90,44 @@ + + + + true + + + L&ines numbering + + + true + + + true + + + false + + + + + + Additional O&ptions: + + + linenoLE + + + + + + + lineno package options (e.g. right, modulo, switch, displaymath, mathlines,...) + + + + + + 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 -- 2.39.2