Repository: pypi/warehouse

Issue:
Support for mathematical expressions in Markdown
**What's the problem this feature will solve?**
GitHub has [started supporting mathematical expressions in Markdown](https://github.blog/2022-05-19-math-support-in-markdown/).
It would be nice to have the same possibility in PyPi, since oftentimes the `README.md` on GitHub is used as `long_description` in `setup.py`. 
<!-- A clear and concise description of what the problem is. -->

**Describe the solution you'd like**
Implement the same syntax used by GitHub, described [here](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/writing-mathematical-expressions).
<!-- A clear and concise description of what you want to happen. -->

**Additional context**
Example PyPi package for which math expressions are not rendered: https://pypi.org/project/sourcespec/ (section: "Theoretical background").
The original `README.md` on GitHub: https://github.com/SeismicSource/sourcespec/blob/master/README.md 
<!-- Add any other context, links, etc. about the feature here. -->



Discussion:
Related: https://github.com/pypa/readme_renderer/issues/214
This is blocked on https://github.com/pypa/readme_renderer/issues/214 (but this does work for reStructuredText now since https://github.com/pypi/warehouse/pull/12062)
🥳 I'm very excited to report that the work done to enable MathJax on the frontend now automatically detects the `$$` delimiters that have been added in the Markdown, so no changes to either readme_renderer or warehouse code are necessary!

Using the [provided project](https://pypi.org/project/sourcespec/), we can now see that the previously submitted content renders as Math (that I don't fully understand, but who cares?! 😆 ):
<img width="836" alt="Screen Shot 2022-08-26 at 18 12 00" src="https://user-images.githubusercontent.com/529516/186997238-fb4172ed-cbf3-45f4-812c-810f2577f100.png">

> Note in particular that the $...$ in-line delimiters are not used by default. That is because dollar signs appear too often in non-mathematical settings, which could cause some text to be treated as mathematics unexpectedly. For example, with single-dollar delimiters, “… the cost is $2.50 for the first one, and $2.00 for each additional one …” would cause the phrase “2.50 for the first one, and” to be treated as mathematics since it falls between dollar signs.

We could add them as configuration, if we want: https://docs.mathjax.org/en/latest/input/tex/delimiters.html#tex-delimiters

but should consider the potential downsides of a sentence like:

```
To split $100 in half, we calculate $100/2$
```

[GitHub docs](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/writing-mathematical-expressions#writing-dollar-signs-in-line-with-and-within-mathematical-expressions) recommend using html to split and make it work like so:

```html
To split <span>$</span>100 in half, we calculate $100/2$
```

We'd have to ask ourselves what's the likelihood of an equation being inline with an expected dollar sign.
Wow, that's great! Thank you!

For the inline dollar sign problem, I think that the benefits of having inline LaTeX outweigh the corner case of a dollar sign in the same sentence. 

I would say that people who chose to use LaTeX math in their README.md will probably detect this problem when rendering locally or on GitHub/GitLab their markdown file, which will push them to try and find a solution on their own. 

Moreover, it would be nice, from my point of view, if we match the GitHub syntax, and thus allow inline LaTeX. 

Great work, anyway! Thanks again!

Resolving patch:
diff --git a/warehouse/csp.py b/warehouse/csp.py
--- a/warehouse/csp.py
+++ b/warehouse/csp.py
@@ -115,6 +115,9 @@ def includeme(config):
                     "https://cdn.jsdelivr.net/npm/mathjax@3.2.2/",
                     # Hash for v3.2.2 of MathJax tex-svg.js
                     "'sha256-1CldwzdEg2k1wTmf7s5RWVd7NMXI/7nxxjJM2C4DqII='",
+                    # Hash for MathJax inline config
+                    # See warehouse/templates/packaging/detail.html
+                    "'sha256-0POaN8stWYQxhzjKS+/eOfbbJ/u4YHO5ZagJvLpMypo='",
                 ],
                 "style-src": [
                     SELF,


Test patch:
diff --git a/tests/unit/test_csp.py b/tests/unit/test_csp.py
--- a/tests/unit/test_csp.py
+++ b/tests/unit/test_csp.py
@@ -229,6 +229,7 @@ def test_includeme():
                         "'sha256-U3hKDidudIaxBDEzwGJApJgPEf2mWk6cfMWghrAa6i0='",
                         "https://cdn.jsdelivr.net/npm/mathjax@3.2.2/",
                         "'sha256-1CldwzdEg2k1wTmf7s5RWVd7NMXI/7nxxjJM2C4DqII='",
+                        "'sha256-0POaN8stWYQxhzjKS+/eOfbbJ/u4YHO5ZagJvLpMypo='",
                     ],
                     "style-src": [
                         "'self'",