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
This commit is contained in:
Uwe Stöhr 2017-04-13 02:31:26 +02:00
parent 031748d9c8
commit fc1c5c6f28
10 changed files with 154 additions and 95 deletions

View 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" * Format incremented to 538: support for document class option "fleqn"
and for length \mathindent. and for length \mathindent.
New buffer parameters New buffer parameters
- \is_formula_indent - \is_math_indent
- \formula_indentation - \math_indentation
2017-04-04 Uwe Stöhr <uwestoehr@web.de> 2017-04-04 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 537: support for \xout. * Format incremented to 537: support for \xout.

View File

@ -1971,22 +1971,36 @@ def revert_xout(document):
def convert_mathindent(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) 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): def revert_mathindent(document):
" Define mathindent if set in the document " " Define mathindent if set in the document "
# first output the length # first output the length
regexp = re.compile(r'(\\formula_indentation)') regexp = re.compile(r'(\\math_indentation)')
i = find_re(document.header, regexp, 0) i = find_re(document.header, regexp, 0)
if i != -1: 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 + '}']) add_to_preamble(document, ["\\setlength{\\mathindent}{" + value + '}'])
del document.header[i] del document.header[i]
# now set the document class option # 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) i = find_re(document.header, regexp, 0)
value = "1" value = "1"
if i == -1: if i == -1:

View File

@ -916,7 +916,7 @@ int Buffer::readHeader(Lexer & lex)
params().headheight.erase(); params().headheight.erase();
params().headsep.erase(); params().headsep.erase();
params().footskip.erase(); params().footskip.erase();
params().formula_indentation.erase(); params().math_indentation.erase();
params().columnsep.erase(); params().columnsep.erase();
params().fonts_cjk.erase(); params().fonts_cjk.erase();
params().listings_params.clear(); params().listings_params.clear();

View File

@ -342,7 +342,7 @@ public:
*/ */
HSpace indentation; HSpace indentation;
VSpace defskip; VSpace defskip;
HSpace formula_indentation; HSpace math_indentation;
PDFOptions pdfoptions; PDFOptions pdfoptions;
LayoutFileIndex baseClass_; LayoutFileIndex baseClass_;
FormatList exportableFormatList; FormatList exportableFormatList;
@ -384,8 +384,8 @@ BufferParams::BufferParams()
cite_engine_type_ = ENGINE_TYPE_DEFAULT; cite_engine_type_ = ENGINE_TYPE_DEFAULT;
makeDocumentClass(); makeDocumentClass();
paragraph_separation = ParagraphIndentSeparation; paragraph_separation = ParagraphIndentSeparation;
is_formula_indent = false; is_math_indent = false;
formula_indentation = "30pt"; math_indentation = "default";
quotes_style = InsetQuotesParams::EnglishQuotes; quotes_style = InsetQuotesParams::EnglishQuotes;
dynamic_quotes = false; dynamic_quotes = false;
fontsize = "default"; 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) if (pimpl_->defskip.kind() == VSpace::DEFSKIP)
// that is invalid // that is invalid
pimpl_->defskip = VSpace(VSpace::MEDSKIP); pimpl_->defskip = VSpace(VSpace::MEDSKIP);
} else if (token == "\\is_formula_indent") { } else if (token == "\\is_math_indent") {
lex >> is_formula_indent; lex >> is_math_indent;
} else if (token == "\\formula_indentation") { } else if (token == "\\math_indentation") {
lex.next(); lex.next();
string formula_indentation = lex.getString(); string math_indentation = lex.getString();
pimpl_->formula_indentation = HSpace(formula_indentation); pimpl_->math_indentation = HSpace(math_indentation);
} else if (token == "\\quotes_style") { } else if (token == "\\quotes_style") {
string qstyle; string qstyle;
lex >> qstyle; lex >> qstyle;
@ -1347,9 +1347,9 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
os << "\n\\paragraph_indentation " << getIndentation().asLyXCommand(); os << "\n\\paragraph_indentation " << getIndentation().asLyXCommand();
else else
os << "\n\\defskip " << getDefSkip().asLyXCommand(); os << "\n\\defskip " << getDefSkip().asLyXCommand();
os << "\n\\is_formula_indent " << is_formula_indent; os << "\n\\is_math_indent " << is_math_indent;
if (is_formula_indent) if (is_math_indent)
os << "\n\\formula_indentation " << getFormulaIndentation().asLyXCommand(); os << "\n\\math_indentation " << getMathIndentation().asLyXCommand();
os << "\n\\quotes_style " os << "\n\\quotes_style "
<< string_quotes_style[quotes_style] << string_quotes_style[quotes_style]
<< "\n\\dynamic_quotes " << dynamic_quotes << "\n\\dynamic_quotes " << dynamic_quotes
@ -1631,7 +1631,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
&& orientation == ORIENTATION_LANDSCAPE) && orientation == ORIENTATION_LANDSCAPE)
clsoptions << "landscape,"; clsoptions << "landscape,";
if (is_formula_indent) if (is_math_indent)
clsoptions << "fleqn,"; clsoptions << "fleqn,";
// language should be a parameter to \documentclass // 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 // when formula indentation
// only output something when it is not the default of 30pt // only output something when it is not the default
if (getFormulaIndentation().asLyXCommand() != "30pt") { if (getMathIndentation().asLyXCommand() != "default") {
os << "\\setlength{\\mathindent}{" os << "\\setlength{\\mathindent}{"
<< from_utf8(getFormulaIndentation().asLatexCommand()) << from_utf8(getMathIndentation().asLatexCommand())
<< "}\n"; << "}\n";
} }
} }

View File

@ -102,15 +102,15 @@ public:
void setDefSkip(VSpace const & vs); 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 /// Whether formulas are indented
bool is_formula_indent; bool is_math_indent;
/// the indentation of formulas /// the indentation of formulas
std::string formula_indentation; std::string math_indentation;
/** Whether paragraphs are separated by using a indent like in /** Whether paragraphs are separated by using a indent like in
* articles or by using a little skip like in letters. * articles or by using a little skip like in letters.

View File

@ -725,20 +725,24 @@ GuiDocument::GuiDocument(GuiView & lv)
connect(textLayoutModule->justCB, SIGNAL(clicked()), connect(textLayoutModule->justCB, SIGNAL(clicked()),
this, SLOT(change_adaptor())); this, SLOT(change_adaptor()));
connect(textLayoutModule->FormulaIndentCB, SIGNAL(toggled(bool)), connect(textLayoutModule->MathIndentCB, SIGNAL(toggled(bool)),
this, SLOT(change_adaptor())); this, SLOT(change_adaptor()));
connect(textLayoutModule->FormulaIndentLE, SIGNAL(textChanged(const QString &)), connect(textLayoutModule->MathIndentCO, SIGNAL(activated(int)),
this, SLOT(change_adaptor())); 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())); 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 // 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->setValidator(new QDoubleValidator(
textLayoutModule->lspacingLE)); textLayoutModule->lspacingLE));
@ -1606,6 +1610,14 @@ void GuiDocument::enableSkip(bool skip)
setSkip(textLayoutModule->skipCO->currentIndex()); 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() void GuiDocument::setMargins()
{ {
@ -2888,17 +2900,14 @@ void GuiDocument::applyView()
if (rb->isChecked()) if (rb->isChecked())
bp_.use_package(it->first, BufferParams::package_off); bp_.use_package(it->first, BufferParams::package_off);
} }
bp_.is_formula_indent = textLayoutModule->FormulaIndentCB->isChecked(); bp_.is_math_indent = textLayoutModule->MathIndentCB->isChecked();
// if formulas are indented // if math is indented
if (bp_.is_formula_indent) { if (bp_.is_math_indent) {
// fill value if empty to avoid LaTeX errors HSpace MathIndentation = HSpace(
if (textLayoutModule->FormulaIndentLE->text().isEmpty()) widgetsToLength(textLayoutModule->MathIndentLE,
textLayoutModule->FormulaIndentLE->setText("0"); textLayoutModule->MathIndentLengthCO)
HSpace FormulaIndentation = HSpace(
widgetsToLength(textLayoutModule->FormulaIndentLE,
textLayoutModule->FormulaIndentCO)
); );
bp_.setFormulaIndentation(FormulaIndentation); bp_.setMathIndentation(MathIndentation);
} }
// Page Layout // 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 = bp_.options =
fromqstr(latexModule->optionsLE->text()); fromqstr(latexModule->optionsLE->text());
@ -3352,14 +3382,18 @@ void GuiDocument::paramsToDialog()
updateModuleInfo(); updateModuleInfo();
// math // math
if (bp_.is_formula_indent) { if (bp_.is_math_indent) {
textLayoutModule->FormulaIndentCB->setChecked(bp_.is_formula_indent); textLayoutModule->MathIndentCB->setChecked(bp_.is_math_indent);
string FormulaIndentation = bp_.getFormulaIndentation().asLyXCommand(); string MathIndentation = bp_.getMathIndentation().asLyXCommand();
if (!FormulaIndentation.empty()) { int MathIndent = 0;
lengthToWidgets(textLayoutModule->FormulaIndentLE, if (MathIndentation != "default") {
textLayoutModule->FormulaIndentCO, lengthToWidgets(textLayoutModule->MathIndentLE,
FormulaIndentation, default_unit); textLayoutModule->MathIndentLengthCO,
MathIndentation, default_unit);
MathIndent = 1;
} }
textLayoutModule->MathIndentCO->setCurrentIndex(MathIndent);
setMathIndent(MathIndent);
} }
map<string, string> const & packages = BufferParams::auto_packages(); map<string, string> const & packages = BufferParams::auto_packages();

View File

@ -109,6 +109,7 @@ private Q_SLOTS:
void enableIndent(bool); void enableIndent(bool);
void setSkip(int); void setSkip(int);
void enableSkip(bool); void enableSkip(bool);
void setMathIndent(int);
void browseLayout(); void browseLayout();
void browseMaster(); void browseMaster();
void classChanged(); void classChanged();

View File

@ -276,7 +276,7 @@
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="4" column="0">
<widget class="QCheckBox" name="FormulaIndentCB"> <widget class="QCheckBox" name="MathIndentCB">
<property name="toolTip"> <property name="toolTip">
<string>Indent displayed formulas instead of centering</string> <string>Indent displayed formulas instead of centering</string>
</property> </property>
@ -286,17 +286,43 @@
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="4" column="1">
<widget class="QLineEdit" name="FormulaIndentLE"> <widget class="QComboBox" name="MathIndentCO">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text"> <property name="toolTip">
<string notr="true">30</string> <string>Size of the indentation</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="2"> <item row="4" column="2" colspan="2">
<widget class="lyx::frontend::LengthCombo" name="FormulaIndentCO"> <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"/>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="lyx::frontend::LengthCombo" name="MathIndentLengthCO">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -305,7 +331,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="3"> <item row="5" column="3">
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -318,7 +344,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="5" column="0" colspan="4"> <item row="6" column="0" colspan="4">
<spacer> <spacer>
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -361,25 +387,9 @@
<resources/> <resources/>
<connections> <connections>
<connection> <connection>
<sender>FormulaIndentCB</sender> <sender>MathIndentCB</sender>
<signal>toggled(bool)</signal> <signal>toggled(bool)</signal>
<receiver>FormulaIndentCO</receiver> <receiver>MathIndentCO</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>
<signal>toggled(bool)</signal>
<receiver>FormulaIndentLE</receiver>
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
@ -388,7 +398,7 @@
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>182</x> <x>182</x>
<y>273</y> <y>270</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>

View File

@ -493,7 +493,7 @@ Preamble::Preamble() : one_language(true), explicit_babel(false),
h_font_tt_scale[0] = "100"; h_font_tt_scale[0] = "100";
h_font_tt_scale[1] = "100"; h_font_tt_scale[1] = "100";
//h_font_cjk //h_font_cjk
h_is_formulaindent = "0"; h_is_mathindent = "0";
h_graphics = "default"; h_graphics = "default";
h_default_output_format = "default"; h_default_output_format = "default";
h_html_be_strict = "false"; h_html_be_strict = "false";
@ -1290,9 +1290,9 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc, string const & outfiled
os << "\\defskip " << h_defskip << "\n"; os << "\\defskip " << h_defskip << "\n";
else else
os << "\\paragraph_indentation " << h_paragraph_indentation << "\n"; os << "\\paragraph_indentation " << h_paragraph_indentation << "\n";
os << "\\is_formula_indent " << h_is_formulaindent << "\n"; os << "\\is_math_indent " << h_is_mathindent << "\n";
if (!h_formulaindentation.empty()) if (!h_mathindentation.empty())
os << "\\formula_indentation " << h_formulaindentation << "\n"; os << "\\math_indentation " << h_mathindentation << "\n";
os << "\\quotes_style " << h_quotes_style << "\n" os << "\\quotes_style " << h_quotes_style << "\n"
<< "\\dynamic_quotes " << h_dynamic_quotes << "\n" << "\\dynamic_quotes " << h_dynamic_quotes << "\n"
<< "\\papercolumns " << h_papercolumns << "\n" << "\\papercolumns " << h_papercolumns << "\n"
@ -1681,10 +1681,10 @@ void Preamble::parse(Parser & p, string const & forceclass,
handle_opt(opts, known_languages, h_language); handle_opt(opts, known_languages, h_language);
delete_opt(opts, known_languages); delete_opt(opts, known_languages);
// formula indentation // math indentation
if ((it = find(opts.begin(), opts.end(), "fleqn")) if ((it = find(opts.begin(), opts.end(), "fleqn"))
!= opts.end()) { != opts.end()) {
h_is_formulaindent = "1"; h_is_mathindent = "1";
opts.erase(it); opts.erase(it);
} }
// paper orientation // paper orientation
@ -1845,7 +1845,7 @@ void Preamble::parse(Parser & p, string const & forceclass,
else else
h_defskip = translate_len(content); h_defskip = translate_len(content);
} else if (name == "\\mathindent") { } else if (name == "\\mathindent") {
h_formulaindentation = translate_len(content); h_mathindentation = translate_len(content);
} else } else
h_preamble << "\\setlength{" << name << "}{" << content << "}"; h_preamble << "\\setlength{" << name << "}{" << content << "}";
} }

View File

@ -153,8 +153,8 @@ private:
bool h_font_cjk_set; bool h_font_cjk_set;
std::string h_font_cjk; std::string h_font_cjk;
std::string h_use_microtype; std::string h_use_microtype;
std::string h_is_formulaindent; std::string h_is_mathindent;
std::string h_formulaindentation; std::string h_mathindentation;
std::string h_graphics; std::string h_graphics;
std::string h_default_output_format; std::string h_default_output_format;
std::string h_html_be_strict; std::string h_html_be_strict;