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"
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.

View 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:

View 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();

View 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";
}
}

View 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.

View 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));
// initialize the length validator
bc().addCheckedLineEdit(textLayoutModule->FormulaIndentLE);
// LaTeX's default for FormulaIndent is 30pt
textLayoutModule->FormulaIndentCO->setCurrentItem(Length::PT);
textLayoutModule->MathIndentCO->addItem(qt_("Default"));
textLayoutModule->MathIndentCO->addItem(qt_("Custom"));
textLayoutModule->MathIndentLE->setValidator(new LengthValidator(
textLayoutModule->MathIndentLE));
// initialize the length validator
bc().addCheckedLineEdit(textLayoutModule->MathIndentLE);
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();

View 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();

View File

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

View 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;