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.

Backslash sometimes inserted when using $ in text

See original GitHub issue

I noticed that on some parts of my portfolio site (made with gatsby and gatsby-mdx), there are extra backslashes being inserted in some places where dollar signs are used. For example:

  • Go to https://descioli.design/grove and Find for \$ — there are 6 occurrences on the page. There are 12 usages of $, though — not every $ is preceded by a backslash.
  • The MDX source for that page is here. Note: no backslashes.
  • The rendering of the page is here. Pretty standard AFAIK.

It only started happening when I switched from Remark to MDX. I didn’t notice it when I did the initial switch.

Environment

  • macOS and ubuntu, latest version
  • @mdx-js/mdx@1.0.20, gatsby-mdx@0.6.3
  • node@10.1.0, yarn@1.13.0

Steps to reproduce

Clone my portfolio repo, https://github.com/lourd/descioli-design, and run it. No additional configuration needed.

Expected behaviour

No extra backslashes.

Actual behaviour

Extra backslashes

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
adamwathancommented, May 13, 2020

Sorry to comment on a closed issue but I’m still seeing MDX render \$ in the HTML if the dollar sign is escaped in the MDX. It’s a Next.js project, and here are my dependencies:

{
  "name": "tailwind-jobs",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "@mdx-js/loader": "^1.6.1",
    "@next/mdx": "^9.4.0",
    "@tailwindcss/ui": "^0.3.0",
    "autoprefixer": "^9.7.6",
    "next": "9.4.0",
    "postcss-nesting": "^7.0.1",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "tailwindcss": "^1.4.6"
  }
}

Is there a dependency I need to explicitly add that I’m missing, to make sure I’m actually grabbing a recent enough version to get this fix?

2reactions
flores8commented, Apr 7, 2021

If anyone else runs into this problem like I did today, here’s how I fixed it. I needed prettier to stop adding in the backslash. I first started looking in the prettier settings to see if I could turn off the math portion but that ended up being a dead end. I realized that I needed to tell prettier to simply ignore it.

I first tried to my prettier ignore file: https://media.lauraleeflores.com/llu5D48j that works however it will ignore the page completely and that was not ideal for me.

The solution that worked was to simply ignore a portion of the file. You can learn more about that here: https://prettier.io/docs/en/ignore.html

Mine is an mdx file so this is how I ignored it: https://media.lauraleeflores.com/YEuR1dYj

I hope that helps someone who runs into the same problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Slash Symbols in Writing: When to Use a Backslash vs. a ...
The forward slash should be placed directly between two words when used ... Forwards slashes are often used when an abbreviation involves shortening...
Read more >
Backslash inserted when pressing o, u, h at the same time
When I press the letters o, u, and h at the same time, a backslash \ ends up being inserted before the h....
Read more >
How does one insert a backslash or a tilde (~) into LaTeX? - TeX
I believe \backslash may be used in math formulae, but not into text itself. Lamport's, Kopka's, and Mittelbach's texts have said as much...
Read more >
JavaScript backslash (\) in variables is causing an error
The backslash ( \ ) is an escape character in Javascript (along with a lot of other C-like languages). This means that when...
Read more >
Punctuation Tips: The Backslash and Forward Slash - Proofed
The backslash (\) is mostly used in computing and isn't a punctuation mark. · The forward slash (/) can be used in place...
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