gfngfn / SATySFi

A statically-typed, functional typesetting system
GNU Lesser General Public License v3.0
1.16k stars 83 forks source link

How can I write multiple lines under \sum ? #247

Closed TonalidadeHidrica closed 3 years ago

TonalidadeHidrica commented 3 years ago

How can I stack multiple lines in math mode, as in the following image?

\sum_{\substack{i = 1 \\ i \neq k}}^n i^2

\sum_{\substack{i = 1 \\ i \neq k}}^n i^2
TonalidadeHidrica commented 3 years ago

\lower produces smaller text.

monaqa commented 3 years ago

Did you try the following code?

+math(${
  \sum_{i=1}^n i^2 = k^2 + \lower{\sum_{i=1}^n}{i\neq k} i^2
  });

Or, if you don't like that i=1 and i\neq k are written far apart, you can write like this:

% `List` module is required
@require: list

...

+math(
  let-math \stack-lower m msublst =
    msublst |> List.fold-left math-lower m
  in
  ${
  \sum_{i=1}^n i^2
  = k^2 + \lower{\sum_{i=1}^n}{i\neq k} i^2
  = k^2 + \stack-lower{\sum^n}{| i = 1 | i\neq k |} i^2
  = j^2 + k^2 + \stack-lower{\sum^n}{| i = 1 | i\neq j | i\neq k |} i^2
  });

math-example.png

TonalidadeHidrica commented 3 years ago

Thank you. So, I had to apply lower outside the sigma, instead of applying inside _{ }. Now it works, thanks.

image

@require: stdjabook
@require: list
  let-math \stack-lower m msublst =
    msublst |> List.fold-left math-lower m
  in

document (|
  title = {\SATySFi; Playground};
  author = {Your Name};
  show-title = true;
  show-toc = false;
|) '<
    +p {
        \align[
             ${| \sum_{i = 1}^n i^2 |};
             ${| \sum_{\lower{i=1}{i \neq j}}^n i^2 |};
             ${| \lower{\sum_{i=1}^n}{i \neq j} i^2 |};
             ${| \stack-lower{\sum^n}{| i = 1 | i\neq j |} i^2 |};
        ];
    }
>

By the way, isn't it possible to expand the grammar in the future so that we can someday use something like \sum_{| i=1 | i\neq j |}^n ? It'd be more concise and useful.

monaqa commented 3 years ago

It may be technically possible, but I doubt the formula a_{| b | c |} is used often enough to be specified in the SATySFi's grammar. (This is just one user's opinion, and the decision on how to extend SATySFi's grammar should be made by the lead maintainer, @gfngfn .)

na4zagin3 commented 3 years ago

Just my two cents, that could be a use case of ad hoc polymorphism when it is introduced to SATySFi.

TonalidadeHidrica commented 3 years ago

Current SaTySFi system does not accept two different types as an argument right?