]> git.lyx.org Git - lyx.git/commitdiff
BufferParams: rename formula_indent to math_indent etc. as requested
authorUwe Stöhr <uwestoehr@lyx.org>
Thu, 13 Apr 2017 00:31:26 +0000 (02:31 +0200)
committerUwe Stöhr <uwestoehr@lyx.org>
Thu, 13 Apr 2017 00:31:26 +0000 (02:31 +0200)
- also add flyx2lyx feature to import existing document class option as requested by JMarc
- also don't use a real default indentation length

development/FORMAT
lib/lyx2lyx/lyx_2_3.py
src/Buffer.cpp
src/BufferParams.cpp
src/BufferParams.h
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiDocument.h
src/frontends/qt4/ui/TextLayoutUi.ui
src/tex2lyx/Preamble.cpp
src/tex2lyx/Preamble.h

index 13dad664428ac9cde5528cdb2ac52c5dfda328d1..10cc86e0ea8767526b66eea94324a5eb90a3b15d 100644 (file)
@@ -15,8 +15,8 @@ changes happened in particular if possible. A good example would be
        * Format incremented to 538: support for document class option "fleqn"
          and for length \mathindent.
          New buffer parameters
-         - \is_formula_indent
-         - \formula_indentation
+         - \is_math_indent
+         - \math_indentation
 
 2017-04-04 Uwe Stöhr <uwestoehr@web.de>
        * Format incremented to 537: support for \xout.
index 392f5e5dbcce7cc69a78f89947e9d0beda27de1f..cdb9c29bf7bb0dc3019b95c9339ef98fd01466d9 100644 (file)
@@ -1971,22 +1971,36 @@ def revert_xout(document):
 
 
 def convert_mathindent(document):
-    " add the \\is_formula_indent tag "
+    " add the \\is_math_indent tag "
+    # check if the document uses the class option "fleqn"
     k = find_token(document.header, "\\quotes_style", 0)
-    document.header.insert(k, "\\is_formula_indent 0")
+    regexp = re.compile(r'^.*fleqn.*')
+    i = find_re(document.header, regexp, 0)
+    if i != -1:
+        document.header.insert(k, "\\is_math_indent 1")
+        # delete the found option
+        document.header[i] = document.header[i].replace(",fleqn", "")
+        document.header[i] = document.header[i].replace(", fleqn", "")
+        document.header[i] = document.header[i].replace("fleqn,", "")
+        j = find_re(document.header, regexp, 0)
+        if i == j:
+            # then we have fleqn as the only option 
+            del document.header[i]
+    else:
+        document.header.insert(k, "\\is_math_indent 0")
 
 
 def revert_mathindent(document):
     " Define mathindent if set in the document "
     # first output the length
-    regexp = re.compile(r'(\\formula_indentation)')
+    regexp = re.compile(r'(\\math_indentation)')
     i = find_re(document.header, regexp, 0)
     if i != -1:
-        value = get_value(document.header, "\\formula_indentation" , i).split()[0]
+        value = get_value(document.header, "\\math_indentation" , i).split()[0]
         add_to_preamble(document, ["\\setlength{\\mathindent}{" + value + '}'])
         del document.header[i]
     # now set the document class option
-    regexp = re.compile(r'(\\is_formula_indent)')
+    regexp = re.compile(r'(\\is_math_indent)')
     i = find_re(document.header, regexp, 0)
     value = "1"
     if i == -1:
index 4b2a39fb451cbdd562fd02deda0057392dd0418f..479589217cbf446ca7d3d992009edd8bffa3d0d7 100644 (file)
@@ -916,7 +916,7 @@ int Buffer::readHeader(Lexer & lex)
        params().headheight.erase();
        params().headsep.erase();
        params().footskip.erase();
-       params().formula_indentation.erase();
+       params().math_indentation.erase();
        params().columnsep.erase();
        params().fonts_cjk.erase();
        params().listings_params.clear();
index 35b49d414214b97903f3fec0ec9d63f8b6040f6b..19abefc0dd9706fd872c284aa9f14af470368482 100644 (file)
@@ -342,7 +342,7 @@ public:
         */
        HSpace indentation;
        VSpace defskip;
-       HSpace formula_indentation;
+       HSpace math_indentation;
        PDFOptions pdfoptions;
        LayoutFileIndex baseClass_;
        FormatList exportableFormatList;
@@ -384,8 +384,8 @@ BufferParams::BufferParams()
        cite_engine_type_ = ENGINE_TYPE_DEFAULT;
        makeDocumentClass();
        paragraph_separation = ParagraphIndentSeparation;
-       is_formula_indent = false;
-       formula_indentation = "30pt";
+       is_math_indent = false;
+       math_indentation = "default";
        quotes_style = InsetQuotesParams::EnglishQuotes;
        dynamic_quotes = false;
        fontsize = "default";
@@ -629,15 +629,15 @@ PDFOptions const & BufferParams::pdfoptions() const
 }
 
 
-HSpace const & BufferParams::getFormulaIndentation() const
+HSpace const & BufferParams::getMathIndentation() const
 {
-       return pimpl_->formula_indentation;
+       return pimpl_->math_indentation;
 }
 
 
-void BufferParams::setFormulaIndentation(HSpace const & indent)
+void BufferParams::setMathIndentation(HSpace const & indent)
 {
-       pimpl_->formula_indentation = indent;
+       pimpl_->math_indentation = indent;
 }
 
 
@@ -845,12 +845,12 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                if (pimpl_->defskip.kind() == VSpace::DEFSKIP)
                        // that is invalid
                        pimpl_->defskip = VSpace(VSpace::MEDSKIP);
-       } else if (token == "\\is_formula_indent") {
-               lex >> is_formula_indent;
-       } else if (token == "\\formula_indentation") {
+       } else if (token == "\\is_math_indent") {
+               lex >> is_math_indent;
+       } else if (token == "\\math_indentation") {
                lex.next();
-               string formula_indentation = lex.getString();
-               pimpl_->formula_indentation = HSpace(formula_indentation);
+               string math_indentation = lex.getString();
+               pimpl_->math_indentation = HSpace(math_indentation);
        } else if (token == "\\quotes_style") {
                string qstyle;
                lex >> qstyle;
@@ -1347,9 +1347,9 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
                os << "\n\\paragraph_indentation " << getIndentation().asLyXCommand();
        else
                os << "\n\\defskip " << getDefSkip().asLyXCommand();
-       os << "\n\\is_formula_indent " << is_formula_indent;
-       if (is_formula_indent)
-               os << "\n\\formula_indentation " << getFormulaIndentation().asLyXCommand();
+       os << "\n\\is_math_indent " << is_math_indent;
+       if (is_math_indent)
+               os << "\n\\math_indentation " << getMathIndentation().asLyXCommand();
        os << "\n\\quotes_style "
           << string_quotes_style[quotes_style]
           << "\n\\dynamic_quotes " << dynamic_quotes
@@ -1631,7 +1631,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
            && orientation == ORIENTATION_LANDSCAPE)
                clsoptions << "landscape,";
 
-       if (is_formula_indent)
+       if (is_math_indent)
                clsoptions << "fleqn,";
 
        // language should be a parameter to \documentclass
@@ -1958,12 +1958,12 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                }
        }
 
-       if (is_formula_indent) {
+       if (is_math_indent) {
                // when formula indentation
-               // only output something when it is not the default of 30pt
-               if (getFormulaIndentation().asLyXCommand() != "30pt") {
+               // only output something when it is not the default
+               if (getMathIndentation().asLyXCommand() != "default") {
                        os << "\\setlength{\\mathindent}{"
-                          << from_utf8(getFormulaIndentation().asLatexCommand())
+                          << from_utf8(getMathIndentation().asLatexCommand())
                           << "}\n";
                }
        }
index 0258cc857644b2ab3cf4c64c053b0867f580df8a..3b0b8a79de784a50714906513361368d40f1f379 100644 (file)
@@ -102,15 +102,15 @@ public:
        void setDefSkip(VSpace const & vs);
 
        ///
-       HSpace const & getFormulaIndentation() const;
+       HSpace const & getMathIndentation() const;
        ///
-       void setFormulaIndentation(HSpace const & indent);
+       void setMathIndentation(HSpace const & indent);
 
        /// Whether formulas are indented
-       bool is_formula_indent;
+       bool is_math_indent;
 
        /// the indentation of formulas
-       std::string formula_indentation;
+       std::string math_indentation;
 
        /** Whether paragraphs are separated by using a indent like in
         *  articles or by using a little skip like in letters.
index 433b84c7f1f1a547bfb7cb33e12bba384fe030a6..f02cdebb17d1bf2bf3539950c309d163a246497e 100644 (file)
@@ -725,21 +725,25 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(textLayoutModule->justCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
 
-       connect(textLayoutModule->FormulaIndentCB, SIGNAL(toggled(bool)),
+       connect(textLayoutModule->MathIndentCB, SIGNAL(toggled(bool)),
                this, SLOT(change_adaptor()));
-       connect(textLayoutModule->FormulaIndentLE, SIGNAL(textChanged(const QString &)),
+       connect(textLayoutModule->MathIndentCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
-       connect(textLayoutModule->FormulaIndentCO, SIGNAL(activated(int)),
+       connect(textLayoutModule->MathIndentCO, SIGNAL(activated(int)),
+               this, SLOT(setMathIndent(int)));
+       connect(textLayoutModule->MathIndentLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(textLayoutModule->MathIndentLengthCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
 
-       textLayoutModule->FormulaIndentLE->setValidator(new LengthValidator(
-               textLayoutModule->FormulaIndentLE));
+       
+       textLayoutModule->MathIndentCO->addItem(qt_("Default"));
+       textLayoutModule->MathIndentCO->addItem(qt_("Custom"));
+       textLayoutModule->MathIndentLE->setValidator(new LengthValidator(
+               textLayoutModule->MathIndentLE));
        // initialize the length validator
-       bc().addCheckedLineEdit(textLayoutModule->FormulaIndentLE);
+       bc().addCheckedLineEdit(textLayoutModule->MathIndentLE);
        
-       // LaTeX's default for FormulaIndent is 30pt
-       textLayoutModule->FormulaIndentCO->setCurrentItem(Length::PT);
-
        textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
                textLayoutModule->lspacingLE));
        textLayoutModule->indentLE->setValidator(new LengthValidator(
@@ -1606,6 +1610,14 @@ void GuiDocument::enableSkip(bool skip)
                setSkip(textLayoutModule->skipCO->currentIndex());
 }
 
+void GuiDocument::setMathIndent(int item)
+{
+       bool const enable = (item == 1);
+       textLayoutModule->MathIndentLE->setEnabled(enable);
+       textLayoutModule->MathIndentLengthCO->setEnabled(enable);
+       isValid();
+}
+
 
 void GuiDocument::setMargins()
 {
@@ -2888,17 +2900,14 @@ void GuiDocument::applyView()
                if (rb->isChecked())
                        bp_.use_package(it->first, BufferParams::package_off);
        }
-       bp_.is_formula_indent = textLayoutModule->FormulaIndentCB->isChecked();
-       // if formulas are indented
-       if (bp_.is_formula_indent) {
-               // fill value if empty to avoid LaTeX errors
-               if (textLayoutModule->FormulaIndentLE->text().isEmpty())
-                       textLayoutModule->FormulaIndentLE->setText("0");
-               HSpace FormulaIndentation = HSpace(
-                               widgetsToLength(textLayoutModule->FormulaIndentLE,
-                               textLayoutModule->FormulaIndentCO)
+       bp_.is_math_indent = textLayoutModule->MathIndentCB->isChecked();
+       // if math is indented
+       if (bp_.is_math_indent) {
+               HSpace MathIndentation = HSpace(
+                               widgetsToLength(textLayoutModule->MathIndentLE,
+                               textLayoutModule->MathIndentLengthCO)
                                );
-                       bp_.setFormulaIndentation(FormulaIndentation);
+                       bp_.setMathIndentation(MathIndentation);
        }
 
        // Page Layout
@@ -2988,6 +2997,27 @@ void GuiDocument::applyView()
                }
        }
 
+       if (textLayoutModule->MathIndentCB->isChecked()) {
+               // if formulas are indented
+               switch (textLayoutModule->MathIndentCO->currentIndex()) {
+               case 0:
+                       bp_.setMathIndentation(HSpace(HSpace::DEFAULT));
+                       break;
+               case 1: {
+                       HSpace MathIndent = HSpace(
+                               widgetsToLength(textLayoutModule->MathIndentLE,
+                               textLayoutModule->MathIndentLengthCO)
+                               );
+                       bp_.setMathIndentation(MathIndent);
+                       break;
+                       }
+               default:
+                       // this should never happen
+                       bp_.setMathIndentation(HSpace(HSpace::DEFAULT));
+                       break;
+               }
+       }
+
        bp_.options =
                fromqstr(latexModule->optionsLE->text());
 
@@ -3352,14 +3382,18 @@ void GuiDocument::paramsToDialog()
        updateModuleInfo();
 
        // math
-       if (bp_.is_formula_indent) {
-               textLayoutModule->FormulaIndentCB->setChecked(bp_.is_formula_indent);
-               string FormulaIndentation = bp_.getFormulaIndentation().asLyXCommand();
-               if (!FormulaIndentation.empty()) {
-                       lengthToWidgets(textLayoutModule->FormulaIndentLE,
-                       textLayoutModule->FormulaIndentCO,
-                       FormulaIndentation, default_unit);
+       if (bp_.is_math_indent) {
+               textLayoutModule->MathIndentCB->setChecked(bp_.is_math_indent);
+               string MathIndentation = bp_.getMathIndentation().asLyXCommand();
+               int MathIndent = 0;
+               if (MathIndentation != "default") {
+                       lengthToWidgets(textLayoutModule->MathIndentLE,
+                       textLayoutModule->MathIndentLengthCO,
+                       MathIndentation, default_unit);
+                       MathIndent = 1;
                }
+               textLayoutModule->MathIndentCO->setCurrentIndex(MathIndent);
+               setMathIndent(MathIndent);
        }
 
        map<string, string> const & packages = BufferParams::auto_packages();
index e202bd95e087fbe26f6813ac56712646336cf65d..b33fca95f82ba511acc4334199108366960fc444 100644 (file)
@@ -109,6 +109,7 @@ private Q_SLOTS:
        void enableIndent(bool);
        void setSkip(int);
        void enableSkip(bool);
+       void setMathIndent(int);
        void browseLayout();
        void browseMaster();
        void classChanged();
index 2497099a1727883f81c2f01e9744693efe98ea48..6470939aa0ce8c3a21cc1d2694db925cee167bb1 100644 (file)
     </widget>
    </item>
    <item row="4" column="0">
-    <widget class="QCheckBox" name="FormulaIndentCB">
+    <widget class="QCheckBox" name="MathIndentCB">
      <property name="toolTip">
       <string>Indent displayed formulas instead of centering</string>
      </property>
     </widget>
    </item>
    <item row="4" column="1">
-    <widget class="QLineEdit" name="FormulaIndentLE">
+    <widget class="QComboBox" name="MathIndentCO">
      <property name="enabled">
       <bool>false</bool>
      </property>
+     <property name="toolTip">
+      <string>Size of the indentation</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="2" colspan="2">
+    <spacer name="horizontalSpacer_3">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>203</width>
+       <height>20</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="5" column="1">
+    <widget class="QLineEdit" name="MathIndentLE">
+     <property name="enabled">
+      <bool>false</bool>
+     </property>
+     <property name="toolTip">
+      <string/>
+     </property>
      <property name="text">
-      <string notr="true">30</string>
+      <string notr="true"/>
      </property>
     </widget>
    </item>
-   <item row="4" column="2">
-    <widget class="lyx::frontend::LengthCombo" name="FormulaIndentCO">
+   <item row="5" column="2">
+    <widget class="lyx::frontend::LengthCombo" name="MathIndentLengthCO">
      <property name="enabled">
       <bool>false</bool>
      </property>
      </property>
     </widget>
    </item>
-   <item row="4" column="3">
+   <item row="5" column="3">
     <spacer name="horizontalSpacer_2">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
     </spacer>
    </item>
-   <item row="5" column="0" colspan="4">
+   <item row="6" column="0" colspan="4">
     <spacer>
      <property name="orientation">
       <enum>Qt::Vertical</enum>
  <resources/>
  <connections>
   <connection>
-   <sender>FormulaIndentCB</sender>
-   <signal>toggled(bool)</signal>
-   <receiver>FormulaIndentCO</receiver>
-   <slot>setEnabled(bool)</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>59</x>
-     <y>274</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>289</x>
-     <y>273</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>FormulaIndentCB</sender>
+   <sender>MathIndentCB</sender>
    <signal>toggled(bool)</signal>
-   <receiver>FormulaIndentLE</receiver>
+   <receiver>MathIndentCO</receiver>
    <slot>setEnabled(bool)</slot>
    <hints>
     <hint type="sourcelabel">
     </hint>
     <hint type="destinationlabel">
      <x>182</x>
-     <y>273</y>
+     <y>270</y>
     </hint>
    </hints>
   </connection>
index 894e29e25cd8fb0b944713b6c887c43818087f15..08d019c49e6bf30e3448c981314c3f1eee035c9e 100644 (file)
@@ -493,7 +493,7 @@ Preamble::Preamble() : one_language(true), explicit_babel(false),
        h_font_tt_scale[0]        = "100";
        h_font_tt_scale[1]        = "100";
        //h_font_cjk
-       h_is_formulaindent        = "0";
+       h_is_mathindent           = "0";
        h_graphics                = "default";
        h_default_output_format   = "default";
        h_html_be_strict          = "false";
@@ -1290,9 +1290,9 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc, string const & outfiled
                os << "\\defskip " << h_defskip << "\n";
        else
                os << "\\paragraph_indentation " << h_paragraph_indentation << "\n";
-       os << "\\is_formula_indent " << h_is_formulaindent << "\n";
-       if (!h_formulaindentation.empty())
-               os << "\\formula_indentation " << h_formulaindentation << "\n";
+       os << "\\is_math_indent " << h_is_mathindent << "\n";
+       if (!h_mathindentation.empty())
+               os << "\\math_indentation " << h_mathindentation << "\n";
        os << "\\quotes_style " << h_quotes_style << "\n"
           << "\\dynamic_quotes " << h_dynamic_quotes << "\n"
           << "\\papercolumns " << h_papercolumns << "\n"
@@ -1681,10 +1681,10 @@ void Preamble::parse(Parser & p, string const & forceclass,
                        handle_opt(opts, known_languages, h_language);
                        delete_opt(opts, known_languages);
 
-                       // formula indentation
+                       // math indentation
                        if ((it = find(opts.begin(), opts.end(), "fleqn"))
                                 != opts.end()) {
-                               h_is_formulaindent = "1";
+                               h_is_mathindent = "1";
                                opts.erase(it);
                        }
                        // paper orientation
@@ -1845,7 +1845,7 @@ void Preamble::parse(Parser & p, string const & forceclass,
                                else
                                        h_defskip = translate_len(content);
                        } else if (name == "\\mathindent") {
-                               h_formulaindentation = translate_len(content);
+                               h_mathindentation = translate_len(content);
                        } else
                                h_preamble << "\\setlength{" << name << "}{" << content << "}";
                }
index 567a97df839c2bbe0b745385f9b818b6f3364f95..68842b68b45ed5fbaeb6afc0ae9871b5c8c4e9d9 100644 (file)
@@ -153,8 +153,8 @@ private:
        bool h_font_cjk_set;
        std::string h_font_cjk;
        std::string h_use_microtype;
-       std::string h_is_formulaindent;
-       std::string h_formulaindentation;
+       std::string h_is_mathindent;
+       std::string h_mathindentation;
        std::string h_graphics;
        std::string h_default_output_format;
        std::string h_html_be_strict;