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

LaTeX in markdown #1156

Closed
arguiot opened this issue Jan 30, 2020 · 5 comments
Closed

LaTeX in markdown #1156

arguiot opened this issue Jan 30, 2020 · 5 comments

Comments

@arguiot
Copy link
Contributor

arguiot commented Jan 30, 2020

As Apple works on SwiftNumerics and Google on Tensorflow for Swift, many math libraries will start to appear.

In order to make life easier for developers and newcomers alike, support for LaTex equations would be welcome.

I propose to use the following syntax (as for StackOverflow or others): $<insert equation>$ for inline equations and $$<insert equation>$$ for centered equations.

I think it won't be a challenge to implement since javascript libraries like KaTex and MathJax do that very well.

I'm submitting this issue before working on a PR to discuss about the implementation (so I don't waste my time and your time).

@johnfairh
Copy link
Collaborator

I think it's worth exploring; Xcode quick help doesn't support it so the main use might be in guides rather than API documentation?

Were you thinking render at client or 'server' (jazzy runtime)? Might be easier to do client-side rather than try and express the tooling dependency. Would need an optout flag to avoid adding more JS dependencies.

Brief thought on syntax: I would probably go for hooking the backticks/code generation so you'd write markdown `$equation$`. Implement codespan in the jazzy markdown renderer, spot the dollars and generate some special html tags/attrs to pick up from js at runtime.

@arguiot
Copy link
Contributor Author

arguiot commented Jan 31, 2020

I was thinking of client side rendering (way easier). Rather than having an optout flag, I think it's worth considering an opt-in flag (so it's disabled by default).
Here is an example snippet that we could use if use KaTeX (lighter, but less advanced features than MathJax):

const regex = /^\`\$.*\$\`$/gm; // Check for your syntax
document.querySelectorAll('code').forEach((block) => {
                const content = block.innerHTML
               if (regex.test(content)) {
                            const eq = content.slice(2, -1)
                            katex.render(eq, block)
               }
});

@johnfairh
Copy link
Collaborator

👍 for client-side.

The jazzy change I'm suggesting gives 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 (unless KaTeX deals with that).

@arguiot
Copy link
Contributor Author

arguiot commented Jan 31, 2020

As I'm not a Ruby developer, I have no idea how to do that. For me it seems easier to do all with KaTeX (as I know JavaScript well). I'll probably create a PR later this week, and you'll be able to help me with that

@arguiot
Copy link
Contributor Author

arguiot commented Mar 17, 2020

As the new PR is likely to be merged very soon, I close this issue

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

No branches or pull requests

2 participants