-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Render mathematical expressions in Markdown #15433
Comments
I am not sure whether this is in scope. Generally, we try to minimize external dependencies. @pikinier20 WDYT? |
I don't know if external dependencies added as the scripts in the HTML hurt us that much. However, there's also the other side of the coin that we probably don't want to spam dependencies inside HTML to have all possible features. I have a thought that maybe we should add an entry point in Scaladoc (setting or sth like that) to allow users to add scripts to their docs? @odersky The above opinion is not exactly related to the Mathjax. It sounds interesting and I don't have anything against adding that. The libraries implementing FP concepts might also find it useful and describe theoretical stuff using it. Also, I can help you with the configuration part (you're right, we should generate that in Scala). |
@odersky I understand the need to minimize external dependencies, but I'd like to argue that it's worth it for a few reasons: MathJax is widely used by many websites and large organizations. See its Wikipedia page for instance. It is well supported, well documented and compatible with all browsers and even screenreaders. Python supports math notation inside docstrings as well (via the reST math directive in this case). Sphinx, the de-facto Python doc tool can use MathJax as renderer. Libraries like Numpy use it to render math expression from their docstrings (example). For creating similar libraries in Scala, or porting things over, rendering support for these kinds of expressions would be really helpful. |
Thanks @pikinier20 that'd be great! I could just start with a fork until we have a clearer picture if/how scripts should be included in general. |
So, basically I think that the simplest way to add this config would be to generate a small file with script. You can see an example in file
So, you need to generate the |
Do you think scaladoc should or could be extensible so that third parties could provide support for various features (e.g., mermaid diagrams, etc.)? |
Just my 2 cents here, I'd go with KaTeX instead of MathJax. See discussion in my PR for Scala 2 PDF: scala/scala#7432 |
I'd also like to see this feature baked-in; as a stop-gap, I am using the following to update the .html files to add-in MathJax before publishing to a static site:
The above requires GNU sed. (Macs may need to install it.) Here's how an inline math formula looks in the scaladoc:
|
Many tools like vscode support rendering math expressions in LaTeX style inside Markdown. Since a few weeks this is also supported here on GitHub.
I.e. we can put our expression into two $$$y = xA^T + b$$ $y = xA^T + b$ by using a single $:
$$y = xA^T + b$$
and get a nicely rendered expression:Or alternatively we can get inline rendering
$y = xA^T + b$
Rendering is done with MathJax, an apache-licenced JavaScript rendering library that can be included in any webpage.
I think this is quite useful for documentation inside of i.e. numeric and scientific libraries or just anything with math operations so I'd like to propose to add support for MathJax in Scaladoc.
I did a small POC by including the necessary JS and config manually into a Scaladoc generated html file, and it seems to work well:
I guess the MathJax script URL using a CDN should be added here:
https://github.com/lampepfl/dotty/blob/6635929a036ac8d340cd17eaea0c2a89bbc497b2/scaladoc/src/dotty/tools/scaladoc/renderers/Resources.scala#L111-L117
I'm less sure about configuration script. Should that be generated from Scala? If someone more familiar with the codebase could point me in the right direction I'd be grateful.
The text was updated successfully, but these errors were encountered: