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

Add LaTeX support for documentation generation #1070

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

adrian052
Copy link

This PR addresses the request for LaTeX support mentioned in #1062. It introduces the following enhancements:

  • Custom LaTeX Markers: Added support for #[ ]# markers to denote LaTeX content in documentation.
  • MathJax Integration: The MathJax library was included to render mathematical formulas directly in the browser.

Example Usage

This documentation from aiken:

/// #[g^{z} = g^{r +c \cdot x} = g^{r} g^{x \cdot c} = g^{r} (g^{x})^{c} = g^{r} u^{c}]#
/// #[\blacksquare]#

will show:

$$ g^{z} = g^{r + c \cdot x} = g^{r} g^{x \cdot c} = g^{r} (g^{x})^{c} = g^{r} u^{c} $$

$$ \blacksquare $$

I'm open to any suggestions about the delimiters or the approach for rendering the formulas. 🚀

@adrian052 adrian052 requested a review from a team as a code owner December 10, 2024 16:59
Comment on lines 292 to 304
fn inject_math_library(html: String) -> String {
let mathjax_script = r#"
<script type="text/javascript" id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
</script>
<script>
MathJax.typeset();
</script>
"#;

html.replace("</head>", &format!("{}\n</head>", mathjax_script))
}

Copy link
Member

Choose a reason for hiding this comment

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

Hey, we probably don't need to inject this from the rust side, but can directly add it to the doc template: https://github.com/aiken-lang/aiken/blob/main/crates/aiken-project/templates/_layout.html#L3-L12

@KtorZ
Copy link
Member

KtorZ commented Dec 10, 2024

Ho, nice! I was looking into it actually the other day after seeing your message in #1062, mostly to see if the underlying markdown generation tool we use would support it out of the box.

And, turns out they do actually have something!

--> pulldown-cmark/pulldown-cmark#734

Though the feature is pretty minimalist, in the sense that it justs isolate the formula in between <span class="math inline">``</span>; and the detection on their end is done using the classic $ and $$$.

So it sounds like perhaps a good mix to include with the PR (enable the math feature, and use their detection as boundary for the MathJax lib ?)

@KtorZ
Copy link
Member

KtorZ commented Dec 10, 2024

Also, someone (@mpizenberg) has been bringing Katex (instead of MathJax) --> https://katex.org/ as a better Math renderer?

@adrian052 adrian052 changed the title Add LaTeX support with custom markers and MathJax integration Add LaTeX support for documentation generation Dec 12, 2024
@adrian052
Copy link
Author

I have switched to Katex and used cmark-pulldown delimiters in a new commit.

@adrian052 adrian052 requested a review from KtorZ December 12, 2024 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants