fastai / nbdev

Create delightful software with Jupyter Notebooks
https://nbdev.fast.ai/
Apache License 2.0
4.93k stars 488 forks source link

Carriage returns being inappropriately stripped, ex: LaTeX \right to \night #422

Closed lewtun closed 3 years ago

lewtun commented 3 years ago

Hello,

When running nbdev_clean_nbs all my \right LaTeX commands in Markdown cells are getting converted to \night which breaks the LaTeX syntax and doesn't render in the docs.

Steps to reproduce:

  1. Run nbdev_new to create a new project
  2. Edit the index.ipynb notebook to include a Markdown cell with the following LaTeX equation
    $$\left(a + \frac{b}{c} \right)$$
  3. Run nbdev_clean_nbs
  4. Inspect git diff index.ipynb

Expected behaviour

nbdev_clean_nbs preserves LaTeX parentheses

Actual behaviour

From the git diff:

diff --git a/index.ipynb b/index.ipynb
index 31356b0..dd008d1 100644
--- a/index.ipynb
+++ b/index.ipynb
@@ -74,6 +74,13 @@
     "1+1"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "$$\\left(a + \\frac{b}{c} \\night)$$"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,
@@ -90,5 +97,5 @@
   }
  },
  "nbformat": 4,
- "nbformat_minor": 2
+ "nbformat_minor": 4
 }

System info

hamelsmu commented 3 years ago

@muellerzr mind taking a look at this issue re: my comment in #355 about your CRLF cleaning PR?

hamelsmu commented 3 years ago

@muellerzr fastcore has an in_colab perhaps that may be helpful here?

.... although I suppose someone could also try do LaTex on Colab

muellerzr commented 3 years ago

@hamelsmu I think the solution may be to minimally replace CRLF. IE have the regex match: [\r\n]+ and replace it with \n rather than just all \r.

I just don't know if this can solve CR that's on it's own as well