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.

LaTeX code displays as italic between underscores in Markdown mode

See original GitHub issue

This is a very minor nuisance I have noticed while editing markdown cells in IPython Notebooks. The problem appears to also persist on the MarkDown Demo on CodeMirror’s site.

In Markdown, underscores toggle italics, but in LaTeX they also serve to indicate subscripts. Unfortunately, while editing with CodeMirror, underscores used in LaTeX mode sometimes cause italics to be toggled in the edit view.

Steps to reproduce:

  1. Start editing a markdown cell.
  2. Type the following: $$a_{n+1} = 2a_{n} + b$$
  3. The text will display as a__{n+1} = 2a__{n}+b` where the characters in bold here have been italicized in the editor.

Non-example:

  1. Enter the following into a Markdown cell: $$a_n = 2a_n+b$$

It appears that italics are ignored when there is a single alphanumeric character after the underscore, but the case in which the subscript consists of a bracketed group of characters is not handled correctly.

This is particularly annoying, because in italic monospaced fonts, pipes | look like forward slashes / and backslashes \ look like pipes |.

Thanks!

PS: WIndows 7, 64-bit with Chrome, but I doubt it matters!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
williamsteincommented, Nov 25, 2014

On Mon, Nov 24, 2014 at 2:24 PM, Marijn Haverbeke notifications@github.com wrote:

A multiplexing http://codemirror.net/doc/manual.html#addon_multiplex mode that switches to the stex mode between $$ markers would be very easy to set up, and probably solves your problem

For what it is worth, here’s what I did for SageMathCloud (in coffeescript).

CodeMirror.defineMode "gfm2", (config) ->
    options = []
    for x in [['$$','$$'], ['$','$'], ['\\[','\\]'], ['\\(','\\)']]
        options.push
            open  : x[0]
            close : x[1]
            mode  : CodeMirror.getMode(config, 'stex')
    console.log('gfm2', options)
    return CodeMirror.multiplexingMode(CodeMirror.getMode(config,

“gfm”), options…)

It’s really awesome how easy it is to do things like this using CodeMirror.

William


Professor of Mathematics University of Washington http://wstein.org

1reaction
Mencicommented, Jul 8, 2016

@williamstein A bug in your solution is if I type a $ in a inline code or code block, it’ll be highlighted as TeX.

like

$('#div').html();

See https://github.com/Moeditor/Moeditor/issues/5

Maybe we can find a way to set the “priority” of the marks?

Read more comments on GitHub >

github_iconTop Results From Across the Web

LaTeX code displays as italic between underscores ... - GitHub
In Markdown, underscores toggle italics, but in LaTeX they also serve to indicate subscripts. Unfortunately, while editing with CodeMirror, ...
Read more >
Underscores in words (text) - TeX - LaTeX Stack Exchange
Putting the following at the top of the file seems to work for me. You can then use \_ for underscore. \def\_{{\tt\char95}}.
Read more >
Rmarkdown rendering error in math with underscores
We see that the parts between the underscores are displayed in italic and the formula is not rendered but its source code is...
Read more >
Markdown: Guide for the simple markup language - IONOS
For bold text, use two asterisks – and if you want a text to be both bold and italicized, three asterisks are necessary....
Read more >
Markdown Mode for Emacs - Jason Blevins
For bold and italic text, promotion and demotion means changing the markup from underscores to asterisks. Press C-c C– or C-c LEFT to...
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