From fc1c5c6f28f375a86d6a17e94cbbe074093cea86 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Thu, 13 Apr 2017 02:31:26 +0200 Subject: [PATCH] BufferParams: rename formula_indent to math_indent etc. as requested - 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 | 4 +- lib/lyx2lyx/lyx_2_3.py | 24 ++++++-- src/Buffer.cpp | 2 +- src/BufferParams.cpp | 40 ++++++------- src/BufferParams.h | 8 +-- src/frontends/qt4/GuiDocument.cpp | 86 +++++++++++++++++++--------- src/frontends/qt4/GuiDocument.h | 1 + src/frontends/qt4/ui/TextLayoutUi.ui | 62 +++++++++++--------- src/tex2lyx/Preamble.cpp | 14 ++--- src/tex2lyx/Preamble.h | 4 +- 10 files changed, 152 insertions(+), 93 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 13dad66442..10cc86e0ea 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -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 * Format incremented to 537: support for \xout. diff --git a/lib/lyx2lyx/lyx_2_3.py b/lib/lyx2lyx/lyx_2_3.py index 392f5e5dbc..cdb9c29bf7 100644 --- a/lib/lyx2lyx/lyx_2_3.py +++ b/lib/lyx2lyx/lyx_2_3.py @@ -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: diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 4b2a39fb45..479589217c 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -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(); diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 35b49d4142..19abefc0dd 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -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"; } } diff --git a/src/BufferParams.h b/src/BufferParams.h index 0258cc8576..3b0b8a79de 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -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. diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 433b84c7f1..f02cdebb17 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -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 const & packages = BufferParams::auto_packages(); diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index e202bd95e0..b33fca95f8 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -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(); diff --git a/src/frontends/qt4/ui/TextLayoutUi.ui b/src/frontends/qt4/ui/TextLayoutUi.ui index 2497099a17..6470939aa0 100644 --- a/src/frontends/qt4/ui/TextLayoutUi.ui +++ b/src/frontends/qt4/ui/TextLayoutUi.ui @@ -276,7 +276,7 @@ - + Indent displayed formulas instead of centering @@ -286,17 +286,43 @@ - + false + + Size of the indentation + + + + + + + Qt::Horizontal + + + + 203 + 20 + + + + + + + + false + + + + - 30 + - - + + false @@ -305,7 +331,7 @@ - + Qt::Horizontal @@ -318,7 +344,7 @@ - + Qt::Vertical @@ -361,25 +387,9 @@ - FormulaIndentCB - toggled(bool) - FormulaIndentCO - setEnabled(bool) - - - 59 - 274 - - - 289 - 273 - - - - - FormulaIndentCB + MathIndentCB toggled(bool) - FormulaIndentLE + MathIndentCO setEnabled(bool) @@ -388,7 +398,7 @@ 182 - 273 + 270 diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 894e29e25c..08d019c49e 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -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 << "}"; } diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h index 567a97df83..68842b68b4 100644 --- a/src/tex2lyx/Preamble.h +++ b/src/tex2lyx/Preamble.h @@ -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; -- 2.39.2