mcheema
mcheema

Reputation: 850

How can I get github to display inline math in README.org file

I have tried numerous HTML preambles such as the following minimal example:

  #+TITLE: Some math stuff
  #+BEGIN_HTML
         <script type="text/javascript"
            src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
        </script>
  #+END_HTML
  =(solve a b)= should return $X$, from $AX=B$

The inline math works on my desktop if I export to HTML and view in my browser, but does not seem to be rendered in Github where the dollar signs are just echoed in the output.

Any idea on how to get Github to render inline math? Please note the answer to this question on how to do the same with README.md doesn't help as markdown is dissimilar to the much more featureful org mode.

EDIT: I have now learned how Github processes the .org file using github/markup which in turn uses org-ruby to parse the file. It appears that code blocks with #+BeginSrc etc are parsed very well but not the preamble lines or the inline math---though I have not really confirmed this yet.

@david This is the partial but hopefully relevant source from my webpage:

README.org

    <article class="markdown-body entry-content" itemprop="mainContentOfPage"><h1><a id="user-content-some-math-stuff" class="anchor" href="#some-math-stuff" aria-hidden="true"><span class="octicon octicon-link"></span></a>Some math stuff</h1>
         
<p><code>(solve a b)</code> should return $X$, from $AX=B$</p>
</article>
  </div>

Edit 2: Signal for @VonC in the comments: GitHub supports Latex/MathJax since May 2022

Upvotes: 10

Views: 1704

Answers (2)

Max Nikulin
Max Nikulin

Reputation: 71

There are enough limitations, but you can use LaTeX fragments surrounded by dollars: $f(x)$ or

$$ e^{2\pi i} = 1 $$

Likely you want to add to the document

#+options: ^:nil

GitHub added support of MathJax in 2022, for MarkDown the feature is documented in Writing mathematical expressions. It seems, it is enabled for Org files as well.

Org-ruby does not support LaTeX fragments, but if no other markup is recognized inside a math snippet then it can be handled by MathJax.

The Org manual recommends against usage of dollars as math delimiters, but for GitHub you have to use namely $...$ and $$...$$ instead of more reliable \(...\) and \[...\] since MathJax configuration does not allow the variant with parenthesis.

To avoid interference with Subscripts and Superscripts, you need to disable it using the options keyword.

If you faced an issue with entities (e.g. \int) and you are not going to export the file from Emacs then you may try raw HTML

#+html: \int_a^b f(x)\,dx

Org-ruby does not support disabling of entities, #+options: e:nil has no effect. You have to use multiple #+html: lines since org-ruby is unaware of #+begin_export html blocks (bdewey/org-ruby#73), while Org mode switched from old syntax #+begin_html in version 9.0.

Some limitations for MarkDown described by Nico Schlömer are relevant for Org files as well, see

Upvotes: 0

NickD
NickD

Reputation: 6422

https://github.com/github/markup/issues/274 seems to indicate that it's not currently possible. The issue was closed with no resolution.

Upvotes: 2

Related Questions