Le 05/04/2017 à 22:22, Uwe Stöhr a écrit :
commit 808339790c94b0bffa316efddc7e913bd83c91c7
Author: Uwe Stöhr <uwesto...@lyx.org>
Date:   Wed Apr 5 22:22:47 2017 +0200

    support to indent formulas

    - adds support for the general document class option fleqn
    - adds support to specify the formula indentation
    - fileformat change

Dear Uwe,

Once again, I am too slow for you. Here are my comments after the battle:

+2017-04-05 Uwe Stöhr <uwesto...@web.de>
+       * Format incremented to 538: support for document class option "fleqn"
+         and for length \mathindent.
+         New buffer parameters
+         - \is_formula_indent

The question is not whether the equation is indented, it is whether it is flushed left. The paramter (and all it incarantion in the code) should be \fleqn or \flush_equation or \flush_math

+         - \formula_indentation

- (minor) although the term formula is used in the file format, it is a remnant of old times (like Style/Layout) that we should not encourage. In this case \math_indent is a much better choice, especially since this is the LaTeX term.

- I am really not sure that we need to expose a way to change the value of the indentation: this is something that is decided by the class author, and it is trivial to change in preamble for people who know what they are doing. The idea is "if you do not know how to change it, you probably do not need to change it. If you do know how to do it, think twice before doing it". Moreover, it makes the dialog scroll, as Scott pointed out.


> +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")

How come that you do not need to add your formula_indentation parameter?

A nice touch here would be to detect fleqn in the document options, and change it to brand new support.

        HSpace formula_indentation;

Should be named mathindent

> +  formula_indentation = string();

Please do not initialize a HSpace object with a string.

+HSpace const & BufferParams::getFormulaIndentation() const
+{
+       return pimpl_->formula_indentation;
+}

getMathIndent() (OK, I stop here, you see what I mean by now)

+               // only output something when it is not the default of 30pt
+               if (getFormulaIndentation().asLyXCommand() != "30pt") {
+                       os << "\\setlength{\\mathindent}{"
+                          << 
from_utf8(getFormulaIndentation().asLatexCommand())
+                          << "}\n";

Where does this magic number of 30pt come from???

I have two issues with it:
- the default should be an empty length (remember I coded that to avoid ugly hardcoding)
  that lets the textclass do what it wants
- when trying to set such default length, please try to see what the length actually is, or ask for help

In such case, I follow the "Use the source, Luke" mantra. Let's see... We are looking for \mathindent. If I search this in LaTeX sources, I see (for example in fleqn.clo) that the consensus is
  \mathindent\leftmargini
which means that the margin is equal to the margin used for first-level itemize.

But what is this value, I hear you ask? Well, grep is my friend again, and I see in main class something like
\if@twocolumn
  \setlength\leftmargini  {2em}
\else
  \setlength\leftmargini  {2.5em}
\fi

Here we have our answer: the left margin is 2.5em in general, but not always. As you can imagine, document class authors are creative.

A good default value would also be to use
TL;DR: my advice is to use an empty value for default indentation (my real advice is to drop it, remember), and to use 2.5em (or the same as what we use for the itemize environment) if you need this default value for screen display uses (more on this at the end).

+       if (bp_.is_formula_indent) {
+               // fill value if empty to avoid LaTeX errors
+               if (mathsModule->FormulaIndentLE->text().isEmpty())
+                       mathsModule->FormulaIndentLE->setText("0");

Don't we have length validator for this kind of things? (anyway you should allow empty values, see above).


Finally, I will comment on what I do not see: there is no code to show to the user what the result is. So long for WYSIWYM. The math displayed equations should be flushed left (with the correct indentation) on screen. It is more work, but without it, the patch is just taking dialog screen real-estate for something that is just a few lines in a preamble.

Hope this helps (really)
JMarc

Reply via email to