-
Notifications
You must be signed in to change notification settings - Fork 414
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
Rendering LaTeX in markdown #1159
Conversation
Using JSDeliver & deferred loading, load time isn't impacted (or very little)
Using JSDeliver & deferred loading, load time isn't impacted (or very little)
Using JSDeliver & deferred loading, load time isn't impacted (or very little)
*Total -- 375.98kb -> 302.06kb (19.66%) /lib/jazzy/themes/fullwidth/assets/img/dash.png -- 1.31kb -> 0.54kb (58.74%) /lib/jazzy/themes/jony/assets/img/dash.png -- 1.31kb -> 0.54kb (58.74%) /lib/jazzy/themes/apple/assets/img/dash.png -- 1.31kb -> 0.54kb (58.74%) /lib/jazzy/themes/fullwidth/assets/img/gh.png -- 1.53kb -> 0.78kb (48.95%) /lib/jazzy/themes/jony/assets/img/gh.png -- 1.53kb -> 0.78kb (48.95%) /lib/jazzy/themes/apple/assets/img/gh.png -- 1.53kb -> 0.78kb (48.95%) /images/realm.png -- 18.82kb -> 12.25kb (34.91%) /images/screenshot.jpg -- 233.45kb -> 190.30kb (18.48%) /images/logo.jpg -- 115.20kb -> 95.55kb (17.06%) Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>
[ImgBot] Optimize images
Also, I'm not sure, but maybe we also should consider passing |
The build is failing because it's comparing the output to a prebuilt version, so if you guys could update that so it succeed |
const eq = content.slice(2, -2) | ||
katex.render(eq, block) | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regexps: g
flag is not required and will confuse with its lastIndex
behaviour. Look at the s
flag for the \n|.
pattern? Missing ^$
anchors in the bigBlockRegex
pattern?
Needs to not match in <pre><code>
elements -- that is supposed to be verbatim.
Should test the bigBlockRegex
first otherwise small will match (the accidental g
flag sometimes saves it!)
Might be better to write a single regexp and use a capture group to pull out the equation to render: what's here gets confused by trailing newlines.
If katex fails then it would be good to fall back to what the user wrote - when I tried I just got blank content.
Style: looks to me as though this file uses semicolons, 2-space indent, and jQuery?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking at this! Added some javascript nits.
Jazzy docs are supposed to be offline which is how come they ship jQuery and so on.
KaTeX is heavy compared to what we have already, even if we don't ship any of the fonts, so I think to deploy this we'd have to make it opt-in and only copy the js/css/fonts into the docs if the flag is set.
Do you see what I mean about the <code>
style? The gray background and h-padding are inherited from there:
I'll try a ruby patch in a bit to generate a span instead -- or a div for the $$
version, that way it'll naturally be a block and easy to style. I agree the $$
should be block & centered like mathoverflow.
Leave out the imagebot stuff - may be worthwhile but should be a different PR, just confusing this one.
To add some tests / make CI happier you need to:
- fork jazzy_integration_specs (in the specs/integration_specs) directory
- add your tests/demos to the misc_jazzy_features project
- do
bundle exec rake rebuild_integration_fixtures
to update things, check they look right - commit those changes & set up a PR in the jazzy_integration_specs repo
git add spec/integration_specs
to this PR and commit it -- this links the new version of the submodule to your PR.
Ok that came out easily enough -- https://gist.github.com/johnfairh/a82dc7cfc927491f31a3d213f8a4a52b |
@johnfairh the regex looks good to me, I will test with my project and tell you if it works |
This reverts commit 6f68e46.
@johnfairh I'm having trouble running So, I runned I fixed a few things on the project:
|
Gemfile.lock
Outdated
@@ -191,4 +191,4 @@ DEPENDENCIES | |||
webmock | |||
|
|||
BUNDLED WITH | |||
1.17.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I might broke the build with that!
Hi @arguiot, the Ruby code is removing the $, and CSS class names need a dot in selectors. So the js should be something like: // KaTeX rendering
document.querySelectorAll('.math').forEach((block) => {
const content = block.innerHTML
katex.render(content, block)
}); ...which works for me on your fork, html: <p>How about <span class='math m-inline'>\Gamma(n) = (n-1)!\quad\forall n\in\mathbb N</span> ?</p> Yes, undo the Gemfile.lock change.
What is the trouble you are having with If you can add the tests, fix the styling (center/displaymode, anything else?), tweak error handling if possible, then I'll look after the "add a flag to avoid bloating every jazzy site with katex" part. |
@johnfairh Alright, I fixed the problem with |
@arguiot -- just to let you know I'm not ignoring this, slowly working through the pieces. |
No problem |
Continued in #1164. |
As discussed in #1156 , LaTeX rendering inside a code block like:
Or
$Equation$
would be an interesting feature to add, as Apple works on SwiftNumerics and Google on Tensorflow for Swift, many math libraries will start to appear.This PR focuses on front end rendering, @johnfairh suggested to give control over generating the
code
element - so instead of<code>$equation$</code>
it could give, for example,<span class="math">equation</span>
. Then the selector is easier and the styling will be easier because there's no<code>
element to fight with.