[Bug] Single Dollar Sign in Text Breaks LaTeX Rendering #5

Open
opened 2025-10-14 15:38:54 -06:00 by navan · 0 comments
Owner

Originally created by @resetsix on 4/17/2025

Issue Description

When using LaTeXSwiftUI, a single dollar sign ($) in text content (especially in code blocks) breaks the LaTeX rendering of all subsequent content. This happens because the parser seems to interpret the standalone dollar sign as the beginning of a math expression but doesn't find a matching closing delimiter.

Steps to Reproduce

  1. Create a LaTeX view with content that contains a code block including a dollar sign, followed by actual LaTeX expressions
  2. For example:

Here, \ is used to ensure proper rendering on GitHub.


let content = #"""
\```bash
$ pnpm install
\```

Some text followed by a LaTeX expression: $E=mc^2$
"""#

LaTeX(content)

Current Behavior

The LaTeX content after the standalone dollar sign is not properly rendered. The parser appears to be confused by the single dollar sign in the code block, treating it as the beginning of a math expression.

Expected Behavior

The parser should be smart enough to recognize that a dollar sign within a code block (```bash) or other non-LaTeX contexts should not be treated as a math delimiter. Alternatively, it should provide a mechanism to handle these cases without requiring manual escaping by users.

Workarounds

Currently, we need to manually handle this by:

  1. Removing the dollar sign: pnpm install
  2. Escaping the dollar sign: \$ pnpm install
  3. Adding a matching dollar sign: $ pnpm install $

However, these workarounds require users to modify their content, which is not ideal.

Proposed Solution

The library should be enhanced to:

  1. Ignore dollar signs inside code blocks automatically
  2. Only interpret dollar signs as LaTeX delimiters when they conform to proper LaTeX syntax
  3. Add a configuration option to specify contexts where LaTeX parsing should be disabled

Environment

  • iOS version: iOS 18.1
  • Swift version: 6.0
  • LaTeXSwiftUI version: 1.5.0

Additional Context

This issue is particularly problematic when trying to render Markdown content that contains both code examples with shell commands (which often use $ as a prompt) and mathematical formulas.

Image Image
*Originally created by @resetsix on 4/17/2025* ## Issue Description When using LaTeXSwiftUI, a single dollar sign (`$`) in text content (especially in code blocks) breaks the LaTeX rendering of all subsequent content. This happens because the parser seems to interpret the standalone dollar sign as the beginning of a math expression but doesn't find a matching closing delimiter. ## Steps to Reproduce 1. Create a LaTeX view with content that contains a code block including a dollar sign, followed by actual LaTeX expressions 2. For example: > Here, \ is used to ensure proper rendering on GitHub. ```swift let content = #""" \```bash $ pnpm install \``` Some text followed by a LaTeX expression: $E=mc^2$ """# LaTeX(content) ``` ## Current Behavior The LaTeX content after the standalone dollar sign is not properly rendered. The parser appears to be confused by the single dollar sign in the code block, treating it as the beginning of a math expression. ## Expected Behavior The parser should be smart enough to recognize that a dollar sign within a code block (```bash) or other non-LaTeX contexts should not be treated as a math delimiter. Alternatively, it should provide a mechanism to handle these cases without requiring manual escaping by users. ## Workarounds Currently, we need to manually handle this by: 1. Removing the dollar sign: `pnpm install` 2. Escaping the dollar sign: `\$ pnpm install` 3. Adding a matching dollar sign: `$ pnpm install $` However, these workarounds require users to modify their content, which is not ideal. ## Proposed Solution The library should be enhanced to: 1. Ignore dollar signs inside code blocks automatically 2. Only interpret dollar signs as LaTeX delimiters when they conform to proper LaTeX syntax 3. Add a configuration option to specify contexts where LaTeX parsing should be disabled ## Environment - iOS version: iOS 18.1 - Swift version: 6.0 - LaTeXSwiftUI version: 1.5.0 ## Additional Context This issue is particularly problematic when trying to render Markdown content that contains both code examples with shell commands (which often use `$` as a prompt) and mathematical formulas. <img width="413" alt="Image" src="https://github.com/user-attachments/assets/f010f156-1595-4544-a02c-6c1236297ccb" /> <img width="411" alt="Image" src="https://github.com/user-attachments/assets/91bd6528-83e1-4da3-861f-2d19de1cee05" />
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github/LaTeXSwiftUI#5
No description provided.