question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Render mathematical expressions in Markdown

See original GitHub issue

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$$ and get a nicely rendered expression: $$y = xA^T + b$$ Or alternatively we can get inline rendering $y = xA^T + b$ by using a single $: $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:

<script>
    MathJax = {
        tex: {
            inlineMath: [['$', '$']]
        }
    };
</script>
<script type="text/javascript" id="MathJax-script" defer="true" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

grafik

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.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
julienrfcommented, Jun 14, 2022

Do you think scaladoc should or could be extensible so that third parties could provide support for various features (e.g., mermaid diagrams, etc.)?

1reaction
pikinier20commented, Jun 14, 2022

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 Resources.scala :

private def dynamicJsData =
    val str = jsonObject("filterDefaults" -> jsonObject(
      FilterAttributes.defaultValues.toSeq.map { case  (n, v) => n -> jsonString(v) }:_*
    ))
    Resource.Text("scripts/data.js", s"var scaladocData = $str")

So, you need to generate the Resource.Text object and then append it to commonResources. First param describe the path in which the file will be rendered, second param is the body of file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Render mathematical expressions in Markdown | GitHub ...
You can now use LaTeX style syntax to render math expressions within Markdown inline (using $ delimiters) or in blocks (using $$ delimiters) ......
Read more >
Writing mathematical expressions - GitHub Docs
Use Markdown to display mathematical expressions on GitHub. ... GitHub's math rendering capability uses MathJax; an open source, JavaScript-based display ...
Read more >
Mathematical expressions - markdown-memo example ...
Mathematical expressions. Contents ... When doing md → tex → pdf, LaTeX takes care of the math, but to render the math in...
Read more >
How to show math equations in general github's markdown ...
Equations do not render directly on Markdown files. The equations would pretty much have to be images to be on the readme.md ....
Read more >
Using math expressions in github markdown
This blog explores using and creating some standard mathematical expressions using github markdown. I was motivated to try this out after ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found