Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Math support #23

Merged
merged 3 commits into from
Jan 1, 2023
Merged

feat: Math support #23

merged 3 commits into from
Jan 1, 2023

Conversation

Omikhleia
Copy link
Owner

@Omikhleia Omikhleia commented Nov 13, 2022

Close #20

-- and must not be followed immediately by a digit.
-- NOTE: For display math, "there can be no blank lines between the opening and closing $$ delimiters",
-- Does this implies blank lines are acceptable in inline math? For now, assume it's not the case,
-- and not even a line break (which would be allowed in $$ per the above)
Copy link
Owner Author

@Omikhleia Omikhleia Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I got it wrong, Github doesn't accept a line break in inline math... So $e^{i\pi}$ is $e^{i\pi}$, but

$e^{i\pi}
= -1$

Is not parsed as math:
$e^{i\pi}
= -1$
Pandoc seems to differ here: accepts a line break, but seems to have the same restriction as display math (= no blank lines). Really, folks? This does not seem in line with what the manual says...

larsers.displaymathdelim = parsers.dollar * parsers.dollar
larsers.displaymath = larsers.displaymathdelim
-- There can be no blank lines between the opening and closing $$ delimiters.
* C((parsers.any -parsers.blankline^2 -parsers.dollar -larsers.displaymathdelim)^1)
Copy link
Owner Author

@Omikhleia Omikhleia Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pandoc accept a single $ in display math: $$ e = $x $$ is $$ e = $x $$
So my -parsers.dollar is probably wrong here.

But GitHub doesn't $$ e = $x $$ is:
$$ e = $x $$

(And some say Markdown is simple. Folks you got mad at one point ;)

Copy link
Owner Author

@Omikhleia Omikhleia Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scrap that. Both Pandoc and Github do not seem to accept a single $ in display math (or behave badly, but differently however ! Oh my...)

specials = specials .. "'\""
end
if options.tex_math_dollars then
specials = specials .. "$"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether we should make $ escapable is another thing that is unclear to me...

@@ -890,11 +891,14 @@ function M.new(writer, options)
-- Basic parsers (local)
------------------------------------------------------------------------------

local specials = "*_~`&[]<!\\-@^"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Aside node) If going this route, we should perhaps fix the changes made for superscripts and subscripts the same way, to avoid having the added characters being interpreted as "specials" when the corresponding extensions are disabled.

There is an important constraint, though: you have to restrict yourself to the syntax subset supported
by SILE. This being said, some nice fomulas may be achieved:

$$\pi=\sum_{k=0}^\infty\frac{1}{16^k}(\frac{4}{8k+1} \minus \frac{2}{8k+4} \minus \frac{1}{8k+5} \minus \frac{1}{8k+6})$$
Copy link
Owner Author

@Omikhleia Omikhleia Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Aside note) Check the example... GitHub accepts it, but complains - \minus doesn't seem legit:
$$\pi=\sum_{k=0}^\infty\frac{1}{16^k}(\frac{4}{8k+1} \minus \frac{2}{8k+4} \minus \frac{1}{8k+5} \minus \frac{1}{8k+6})$$

I'm bad at TeX math :p Pandoc to HTML complains ("Could not convert TeX math"), even with - instead of that \minus (which SILE accepts, it but might be by mere chance lol)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N.B. Also relates to sile-typesetter/sile#1642 on the SILE side...

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub accepts the minus sign (−):
$$\pi=\sum_{k=0}^\infty\frac{1}{16^k}(\frac{4}{8k+1} − \frac{2}{8k+4} − \frac{1}{8k+5} − \frac{1}{8k+6})$$

Due to the above-mentioned SILE behavior with unary/binary operators, I'll stick to it for now (I don't think it will be fixed in a decent time-frame)

@Omikhleia Omikhleia self-assigned this Dec 4, 2022
@Witiko
Copy link
Contributor

Witiko commented Dec 28, 2022

I will review this in February as part of Witiko/markdown#216 if that's OK.

@Omikhleia
Copy link
Owner Author

Just rebased and conflicts fixed, for now.

@Witiko

I will review this in February as part of Witiko/markdown#216 if that's OK.

No problem at all, you are welcome.
I might merge it here "as-is" in this "vendored" copy of the lunamark reader later this month, so as to move forward with my 1.1 planned release of the SILE-Markdown tooling and to tickle SILE a bit on its Math support, but there's no urge as far as lunamark is concerned (that the advantage of using a vendored copy at this early point... with all the drawbacks too, though!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Math support (a.k.a. tex_math_dollars)
2 participants