idyll icon indicating copy to clipboard operation
idyll copied to clipboard

Add equation syntax

Open mathisonian opened this issue 6 years ago • 7 comments

It would be great to write $...$ or $$...$$ instead of [equation]...[/equation] [equation display:true]...[/equation]

mathisonian avatar May 14 '18 04:05 mathisonian

Don't know enough about lexing + parsing to understand what is considered the cleaner approach / best practice. Let's say we have both of these inputs:

[Equation]
  y = \int x^2 dx
[/Equation]
$$
  y = \int x^2 dx
$$

Is it better practice to:

  1. Handle this at lexer level, i.e. in lexer.js so that they both output identical tokens and are indistinguishable for parser.
  2. Handle this at parser level. So maybe lexer converts "$$" into some new token, let's say EQUATION, that we handle with equation token specific definition in grammar.ne, kind of like how there are currently defintions for ImageInline and LinkInline, so that the final ast is indistinguishable for both.
  3. Handle at some other level I don't know about

hemu avatar Oct 14 '18 15:10 hemu

@hemu it would be best to add an additional rule in the lexer, similar for how we special case equation tags here: https://github.com/idyll-lang/idyll/blob/master/packages/idyll-compiler/src/lexer.js#L53-L66.

The regex is a little hairy, but the same logic should be applicable to the new $$ tokens.

mathisonian avatar Nov 08 '18 03:11 mathisonian

@mathisonian I've started working on this here https://github.com/idyll-lang/idyll/pull/573, tests pass but so far haven't succeeded in testing this manually inside new idyll project/document - adding $$y=0$$ somewhere in text does nothing.

Edit: found the problem, it was regex.

michaltakac avatar Jul 30 '19 15:07 michaltakac

Wouldn't [$...$] and [$$...$$] be better instead of $...$ and $$...$$? That way it works beautifully :) but it's just me battling with the regex :D.

Inline equation [$ y = x^{\frac{\pi}{2}} $], or centered: [$$ y = 0 $$]

Or with some whitespaces for nicer formatting:

[$$
  y = \int x^2 dx
$$]

Screen Shot 2019-07-30 at 14 37 27

michaltakac avatar Jul 30 '19 18:07 michaltakac

Thanks for the work on this @michaltakac! Also saw your comment on #314, I think that would be awesome to add - we should discuss syntax for that as well. I'm totally in favor of getting changes in to improve the equation/latex experience, but it will probably will be a couple days before I can do a close review.

Edit: found the problem, it was regex.

A tale as old as time.

Arguments for [$$...$$] vs [$$]... [/$$] to keep things more consistent with the existing syntax?

mathisonian avatar Jul 30 '19 19:07 mathisonian

Feeling that [$]...[/$] and [$$]...[/$$] would suit Idyll better - basically it would be a syntactic sugar for [equation /].

michaltakac avatar Jul 30 '19 19:07 michaltakac

[$ $] is easier to type than [$][/$]. Both are surely better than $ $, because it won't accidentally parse something as an equation.

Note that there's also other latex syntax: \( \) for inline equations and \[ \] for block equations.

suhr avatar Aug 03 '19 12:08 suhr