Skip to content

Improve math parsing #118

@xxchan

Description

@xxchan

current situation

types:

  • rendered in display mode: Latex_Environment & Displayed_Math
  • rendered in inline mode: Latex_Fragment Inline/Display

syntax:

  1. $content$, TeX delimiters for inline math -> Latex_Fragment Inline

  2. $$content$$, TeX delimiters for displayed math

  3. \( content \) , LaTeX delimiters for inline math -> Latex_Fragment Inline

    • cannot be multi-line
  4. \[ content \], LaTeX delimiters for displayed math -> Latex_Fragment Display

    • cannot be multi-line
  5. \begin{env} content \end{env}, LaTeX environment-> Latex_Environment

My improvement ideas

  • Allow multi-line for all Latex_Fragment. And allow $ content $

    I'm actually interested why they don't support multi-line now. Is there a design consideration?

    By the way, I don't understand why \(\) and \[\] don't support multi-line text, since they use end_string.
    (Instead, $ use take_while (fun x -> x <> '$' && x <> '\r' && x <> '\n'), which banned \n explicitly

  • Remove Displayed_Math since it's confusing. And in Logseq, let Latex_Fragment Display rendered in display mode.

    For $$, If there's nothing before the starting $$ and nothing after the ending $$, parse it into Latex_Fragment Display. Otherwise Latex_Fragment Inline.

i.e.,

$$a
b$$

and

$$a$$

are displayed math. But

$$a
$$b

and

$$a$$b

is equivalent to $a$b

For reference (and also an aternative), Typora's behavior:

  • $$ and $ can both be multi-line
  • displayed math only when used like codeblocks, i.e.,
$$
a
$$

The first two examples above are both inline math.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions