Improve math parsing
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 281
- Forks
- 30
- Avg merge
- 5h 30m
- Merged PRs (30d)
- 4
Description
## 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`
- cannot start/end with a space (defined behavior) https://github.com/logseq/logseq/issues/4170
- cannot be multi-line
2. `$$content$$`, TeX delimiters for displayed math
- `$$` appears at the start of a line -> `Displayed_Math`
- can be multi-line
- good cases
- Used like codeblocks
- Only `$$content$$` in one line, no other content later
- bad case: `$$content$$ content` https://github.com/logseq/logseq/issues/4066
- otherwise -> `Latex_Fragment Display`
- cannot be multi-line
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the math parser rules that produce Latex_Environment, Displayed_Math, and Latex_Fragment, then inspect the delimiter branches using take_while and end_string. Resolve the intended multiline and display-versus-inline semantics before changing behavior; done means the selected rules consistently implement one agreed interpretation of the examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- latex, ocaml
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100