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.

problem with parsing text with mixed $$ and $ delimiters

See original GitHub issue

Before reporting a bug

Describe the bug: In LaTeX source texts it is common to see inline math like $x$$y$ which is equivalent to $xy$ mixed with display math.

However, such math does not render correctly with the autorender extension, when the delimiter option is set to

{delimiters: [
  {left: '$$', right: '$$', display: true},
  {left: '$', right: '$', display: false},
  {left: '\\(', right: '\\)', display: false},
  {left: '\\[', right: '\\]', display: true}
]}

To Reproduce: Steps to reproduce the behavior:

display this file in a supported browser

<!DOCTYPE html>
<!-- KaTeX requires the use of the HTML5 doctype. Without it, KaTeX may not render properly -->
<html>
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFg\
W6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">

    <!-- The loading of KaTeX is deferred to speed up page rendering -->
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4j\
AIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>

    <!-- To automatically render math in text elements, include the auto-render extension: -->
    <script defer
    src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/contrib/auto-render.min.js"
    integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa"
            crossorigin="anonymous" onload="renderMathInElement(document.body, {delimiters: [
  {left: '$$', right: '$$', display: true},
  {left: '$', right: '$', display: false},
  {left: '\\(', right: '\\)', display: false},
  {left: '\\[', right: '\\]', display: true}
]});"></script>
  </head>
  <body>
    <h1>A note on discrete $$\mathcal{R}$$ symmetries in $\mathbb{Z}$$_{6}$-II orbifolds with Wilson lines</h1>

  </body>
</html>

Expected behavior: both the display math and the inline math should be rendered. It is not, but the $$ in the middle of $\mathbb{Z}$$_{6}$ disappears.

Omitting the $$ (which is a NOOP) in the middle results in correct rendering. Introducing a space $\mathbb{Z}$ $_{6}$ also renders the inline math, albeit with a gratuitous space.

Screenshots: katex-autorender

Environment (please complete the following information):

  • KaTeX Version: v0.12.0
  • Device: Linux desktop
  • OS: Fedora 32
  • Browser: Chrome
  • Version: 85.0.4183.102 (Official Build) (64-bit)

Additional Context:

We use KaTeX for rendering in a large repository of scientific papers. We don’t control the TeX source, and hence can’t avoid this mix of delimiters.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
pzinncommented, Dec 12, 2020

I have a fix but I’m not satisfied with it. Let me explain. The way the auto-render works (in splitAtDelimiters.js) is to sequentially try the various delimiters in some order ($ $$ \( \[) and split the text accordingly. To solve the problem above one needs to have $ processed before $$ and add a condition that two $s in a row should be ignored. This is my easy fix. But I think this sequential process is fundamentally flawed. Let’s compare these two expressions

\( \fbox{$a$} \)
$ \fbox{\(a\)} $

which in LaTeX will produce the exact same result. No matter what the ordering is in splitAtDelimiters.js, one of them will fail to be properly processed by auto-render. So I want to rewrite this to have delimiters processed in parallel rather than sequentially.

1reaction
pzinncommented, Dec 11, 2020

I encountered the same problem, and have a fix for it. If anybody cares enough, I’ll submit a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with text reader and set delimiters - MSDN - Microsoft
I am trying to parse a pipe seperated text file using: trName.SetDelimiters("|") arySourceFields = trName.ReadFields().
Read more >
perl - Parsing multiple keyword value pairs in one line
Parsing multiple keyword value pairs in one line - mixed delimiters - Text::Balanced ... e.g. every odd line contain an unique "name", and...
Read more >
Reading a text file and parsing only the text between two ...
import - Reading a text file and parsing only the text between two delimiters - Mathematica Stack Exchange. Stack Overflow for Teams –...
Read more >
IT12595: DFDL PARSER DOES NOT PARSE A DELIMITER ...
The error only occurs if the delimiter contains a mixture of DFDL entities (such as WSP+) and fixed text, and DFDL ignoreCase is...
Read more >
JSON parsing with a mix of single and double quote...
For example: when a text contains one or more single quotes, the delimiters are changed to doubles quotes. And when there are both...
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