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.

Double-escaped dollar signs different to Jupyter Notebook

See original GitHub issue

Describe the bug When escaping the $ in Jupyter notebooks, you need to double-escape \\$ so that it doesn’t try to render LaTeX. When the notebook is run through Sphinx to be converted to HTML, however, these now appear as “\$”, not “$”.

To Reproduce Steps to reproduce the behavior:

  1. clone https://github.com/ds-connectors/econ-models-textbook/tree/jb-0.7
  2. run jupyter-book build ./
  3. open _build/content/07-game-theory/utility.html
  4. See error in 1st paragraph (image below)

Expected behavior The double-escaped dollar signs \\$ should be rendered as “$” not “$”

https://github.com/ds-connectors/econ-models-textbook/tree/jb-0.7

Here is the MD in the cell in the notebook:

# Expected Utility Theory

Imagine you're offered a choice between \\$1 guaranteed or \\$100 with probability $\frac{1}{80}$ (i.e. with probability $\frac{79}{80}$, you get \\$0). Which would you choose? Most people would be probably say the \\$1 because it's guaranteed that you'll get a positive outcome. But is that the rational choice?

In game theory, we consider rationality by examining the utility of different outcomes to individuals. To do so, we calculate the **expected utility** of a set of outcomes, which is the average of the utilities of those outcomes weighted by their probabilities. In the example above, there are two outcomes:

* \\$1 guaranteed. This occurs with probability $p_1=1$ and we'll say has utility $u_1 = 1$.
* \\$100 with probability $p_2 = \frac{1}{80}$. We'll say this has utility $u_2 = 100$.

The expected utility of the first choice would be $p_1 \cdot u_1 = 1$ because there is only one possible outcome and it has utility 1. The expected utility of the second choice would be $p_2 \cdot u_2 + (1 - p_2) \cdot 0 = 1.25$ because we obtain utility $u_2$ with probability $p_2$ and utility 0 with probability $1-p_2$. Notice that the expected utility of the second choice is higher! This means that, had you chosen the \\$1 guaranteed, you would have made the irrational choice, because it is _expected_ that you would get \\$1.25 as opposed to \\$1 with the second choice.

The idea that individuals, when making a gamble, will choose the option that maximizes the expected utility based on their preferences is called the **expected utility hypothesis**.

Here is the output screenshot:

Screen Shot 2020-07-03 at 8 43 28 PM

Environment (please complete the following information):

  • Python Version 3.6.5
  • Output of jupyter-book --version:
Jupyter Book: 0.7.1
MyST-NB: 0.8.3
Sphinx Book Theme: 0.0.23dev0
MyST-Parser: 0.9.0
Jupyter-Cache: 0.2.2

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
chrispylescommented, Jul 20, 2020

Another thing that I’ve noticed related to this issue: dollar signs inside LaTeX equations need to be double-escaped to render correctly, but this only works in display math. In inline equations, you can’t have dollar signs at all or else the equation doesn’t render.

0reactions
choldgrafcommented, Feb 5, 2021

I’m a fan of treating pandoc as a “source of truth” for the “expected” pattern here, unless somebody in the JupyterLab/Notebook communities comes back saying that there was a specific reason to require two backslashes, it feels like a bug (or at least, a break from common implementations of this feature, that I suspect may be due to an implementation limitation).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Escaping dollar sign in ipython notebook - Stack Overflow
Put two backslashes in front of dollar signs. For example: Some prices: \\$3.10, \\$4.25, \\$8.50. (running Jupyter notebook server 5.7.0).
Read more >
How To Write Dollar Signs In Jupyter Notebook
With MathJax, you can use double backslash and a dollar sign to show the amount, range, or other combination of dollars in a...
Read more >
Markdown for Jupyter notebooks cheatsheet - IBM
Here's how to format Markdown cells in Jupyter notebooks: ... Mathematical symbols: Surround mathematical symbols with a dollar sign ($), for example:
Read more >
Jupyter Notebook Users Manual.ipynb - Bryn Mawr College
Raw Cells, unlike all other Jupyter Notebook cells, have no input-output ... interpret your text as LaTex, surround your input with dollar signs...
Read more >
Running and Quitting – Plotting and Programming in Python
Understand the difference between a Python script and a Jupyter notebook. ... What do you think the underscore, _ , circumflex, ^ ,...
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