support to indent formulas

- adds support for the general document class option fleqn
- adds support to specify the formula indentation
- fileformat change
This commit is contained in:
Uwe Stöhr 2017-04-05 22:22:47 +02:00
parent 60810e0ae2
commit 808339790c
9 changed files with 299 additions and 62 deletions

View File

@ -7,6 +7,13 @@ changes happened in particular if possible. A good example would be
-----------------------
2017-04-05 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 538: support for document class option "fleqn"
and for length \mathindent.
New buffer parameters
- \is_formula_indent
- \formula_indentation
2017-04-04 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 537: support for \xout.
Character style via ulem's \xout. New

View File

@ -1970,6 +1970,38 @@ def revert_xout(document):
'\\usepackage{ulem}'])
def convert_mathindent(document):
" add the \\is_formula_indent tag "
k = find_token(document.header, "\\quotes_style", 0)
document.header.insert(k, "\\is_formula_indent 0")
def revert_mathindent(document):
" Define mathindent if set in the document "
# first output the length
regexp = re.compile(r'(\\formula_indentation)')
i = find_re(document.header, regexp, 0)
if i != -1:
value = get_value(document.header, "\\formula_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)')
i = find_re(document.header, regexp, 0)
value = "1"
if i == -1:
return
else:
k = find_token(document.header, "\\options", 0)
if k != -1:
document.header[k] = document.header[k].replace("\\options", "\\options fleqn,")
del document.header[i]
else:
l = find_token(document.header, "\\use_default_options", 0)
document.header.insert(l, "\\options fleqn")
del document.header[i + 1]
##
# Conversion hub
#
@ -2004,10 +2036,12 @@ convert = [
[534, []],
[535, [convert_dashligatures]],
[536, []],
[537, []]
[537, []],
[538, [convert_mathindent]]
]
revert = [
[537, [revert_mathindent]],
[536, [revert_xout]],
[535, [revert_noto]],
[534, [revert_dashligatures]],

View File

@ -342,6 +342,7 @@ public:
*/
HSpace indentation;
VSpace defskip;
HSpace formula_indentation;
PDFOptions pdfoptions;
LayoutFileIndex baseClass_;
FormatList exportableFormatList;
@ -383,6 +384,8 @@ BufferParams::BufferParams()
cite_engine_type_ = ENGINE_TYPE_DEFAULT;
makeDocumentClass();
paragraph_separation = ParagraphIndentSeparation;
is_formula_indent = false;
formula_indentation = string();
quotes_style = InsetQuotesParams::EnglishQuotes;
dynamic_quotes = false;
fontsize = "default";
@ -626,6 +629,18 @@ PDFOptions const & BufferParams::pdfoptions() const
}
HSpace const & BufferParams::getFormulaIndentation() const
{
return pimpl_->formula_indentation;
}
void BufferParams::setFormulaIndentation(HSpace const & indent)
{
pimpl_->formula_indentation = indent;
}
HSpace const & BufferParams::getIndentation() const
{
return pimpl_->indentation;
@ -830,6 +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") {
lex.next();
string formula_indentation = lex.getString();
pimpl_->formula_indentation = HSpace(formula_indentation);
} else if (token == "\\quotes_style") {
string qstyle;
lex >> qstyle;
@ -1326,6 +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\\quotes_style "
<< string_quotes_style[quotes_style]
<< "\n\\dynamic_quotes " << dynamic_quotes
@ -1607,6 +1631,9 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
&& orientation == ORIENTATION_LANDSCAPE)
clsoptions << "landscape,";
if (is_formula_indent)
clsoptions << "fleqn,";
// language should be a parameter to \documentclass
if (language->babel() == "hebrew"
&& default_language->babel() != "hebrew")
@ -1931,6 +1958,16 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
}
}
if (is_formula_indent) {
// when formula indentation
// only output something when it is not the default of 30pt
if (getFormulaIndentation().asLyXCommand() != "30pt") {
os << "\\setlength{\\mathindent}{"
<< from_utf8(getFormulaIndentation().asLatexCommand())
<< "}\n";
}
}
// Now insert the LyX specific LaTeX commands...
features.resolveAlternatives();
features.expandMultiples();

View File

@ -101,6 +101,17 @@ public:
///
void setDefSkip(VSpace const & vs);
///
HSpace const & getFormulaIndentation() const;
///
void setFormulaIndentation(HSpace const & indent);
/// Whether formulas are indented
bool is_formula_indent;
/// the indentation of formulas
std::string formula_indentation;
/** Whether paragraphs are separated by using a indent like in
* articles or by using a little skip like in letters.
*/

View File

@ -1259,6 +1259,20 @@ GuiDocument::GuiDocument(GuiView & lv)
this, SLOT(change_adaptor()));
connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
this, SLOT(change_adaptor()));
connect(mathsModule->FormulaIndentGB, SIGNAL(toggled(bool)),
this, SLOT(change_adaptor()));
connect(mathsModule->FormulaIndentLE, SIGNAL(textChanged(const QString &)),
this, SLOT(change_adaptor()));
connect(mathsModule->FormulaIndentCO, SIGNAL(activated(int)),
this, SLOT(change_adaptor()));
mathsModule->FormulaIndentLE->setValidator(new LengthValidator(
mathsModule->FormulaIndentLE));
// initialize the length validator
bc().addCheckedLineEdit(mathsModule->FormulaIndentLE);
// LaTeX's default for FormulaIndent is 30pt
mathsModule->FormulaIndentCO->setCurrentItem(Length::PT);
// latex class
@ -2873,6 +2887,18 @@ void GuiDocument::applyView()
if (rb->isChecked())
bp_.use_package(it->first, BufferParams::package_off);
}
bp_.is_formula_indent = mathsModule->FormulaIndentGB->isChecked();
// if formulas are indented
if (bp_.is_formula_indent) {
// fill value if empty to avoid LaTeX errors
if (mathsModule->FormulaIndentLE->text().isEmpty())
mathsModule->FormulaIndentLE->setText("0");
HSpace FormulaIndentation = HSpace(
widgetsToLength(mathsModule->FormulaIndentLE,
mathsModule->FormulaIndentCO)
);
bp_.setFormulaIndentation(FormulaIndentation);
}
// Page Layout
if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
@ -3324,6 +3350,17 @@ void GuiDocument::paramsToDialog()
latexModule->psdriverCO->setCurrentIndex(nitem);
updateModuleInfo();
// math
if (bp_.is_formula_indent) {
mathsModule->FormulaIndentGB->setChecked(bp_.is_formula_indent);
string FormulaIndentation = bp_.getFormulaIndentation().asLyXCommand();
if (!FormulaIndentation.empty()) {
lengthToWidgets(mathsModule->FormulaIndentLE,
mathsModule->FormulaIndentCO,
FormulaIndentation, default_unit);
}
}
map<string, string> const & packages = BufferParams::auto_packages();
for (map<string, string>::const_iterator it = packages.begin();
it != packages.end(); ++it) {

View File

@ -13,8 +13,17 @@
<property name="windowTitle">
<string/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>11</y>
<width>411</width>
<height>271</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableWidget" name="packagesTW">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -37,7 +46,7 @@
<column/>
</widget>
</item>
<item row="1" column="0">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="allPakcagesLA">
@ -69,11 +78,100 @@
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="FormulaIndentGB">
<property name="title">
<string>Indent Formulas</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLineEdit" name="FormulaIndentLE">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>30</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="lyx::frontend::LengthCombo" name="FormulaIndentCO">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>lyx::frontend::LengthCombo</class>
<extends>QComboBox</extends>
<header>LengthCombo.h</header>
</customwidget>
</customwidgets>
<includes>
<include location="local">qt_i18n.h</include>
</includes>
<resources/>
<connections/>
<connections>
<connection>
<sender>FormulaIndentGB</sender>
<signal>toggled(bool)</signal>
<receiver>FormulaIndentCO</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>215</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>194</x>
<y>260</y>
</hint>
</hints>
</connection>
<connection>
<sender>FormulaIndentGB</sender>
<signal>toggled(bool)</signal>
<receiver>FormulaIndentLE</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>215</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>97</x>
<y>260</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -492,6 +492,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_graphics = "default";
h_default_output_format = "default";
h_html_be_strict = "false";
@ -1286,7 +1287,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 << "\\quotes_style " << h_quotes_style << "\n"
os << "\\is_formula_indent " << h_is_formulaindent << "\n"
<< "\\formula_indentation " << h_formulaindentation << "\n"
<< "\\quotes_style " << h_quotes_style << "\n"
<< "\\papercolumns " << h_papercolumns << "\n"
<< "\\papersides " << h_papersides << "\n"
<< "\\paperpagestyle " << h_paperpagestyle << "\n";
@ -1673,6 +1676,12 @@ void Preamble::parse(Parser & p, string const & forceclass,
handle_opt(opts, known_languages, h_language);
delete_opt(opts, known_languages);
// formula indentation
if ((it = find(opts.begin(), opts.end(), "fleqn"))
!= opts.end()) {
h_is_formulaindent = "1";
opts.erase(it);
}
// paper orientation
if ((it = find(opts.begin(), opts.end(), "landscape")) != opts.end()) {
h_paperorientation = "landscape";
@ -1830,6 +1839,8 @@ void Preamble::parse(Parser & p, string const & forceclass,
h_defskip = "bigskip";
else
h_defskip = translate_len(content);
} else if (name == "\\mathindent") {
h_formulaindentation = translate_len(content);
} else
h_preamble << "\\setlength{" << name << "}{" << content << "}";
}

View File

@ -152,6 +152,8 @@ private:
bool h_font_cjk_set;
std::string h_font_cjk;
bool h_use_microtype;
std::string h_is_formulaindent;
std::string h_formulaindentation;
std::string h_graphics;
std::string h_default_output_format;
std::string h_html_be_strict;

View File

@ -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 537 // uwestoehr: support for \\xout
#define LYX_FORMAT_TEX2LYX 537
#define LYX_FORMAT_LYX 538 // uwestoehr: support for formula indentation
#define LYX_FORMAT_TEX2LYX 538
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER