Skip to content

🐛 fix(latex): keep digit-led inline formulas out of the currency escape - #10

Open
alaasumrain wants to merge 1 commit into
lobehub:mainfrom
alaasumrain:fix/digit-led-formulas
Open

alaasumrain wants to merge 1 commit into
lobehub:mainfrom
alaasumrain:fix/digit-led-formulas

Conversation

@alaasumrain

Copy link
Copy Markdown

Problem

escapeCurrencyDollars reads any $ followed by a digit as a price, unless the whole span is a bare integer ($1$) or a comma list ($1,2,3$). So inline formulas that happen to start with a digit lose their opening $ and render as raw text, and the leftover $ then pairs with the next one in the line:

Input Today Expected
so $2n$ is even so \$2n$ is even unchanged
then $3x+1$ grows then \$3x+1$ grows unchanged
half is $0.5$ here half is \$0.5$ here unchanged
step $10 + 7 = 17$ done step \$10 + 7 = 17$ done unchanged

This is common in worked maths answers (coefficients, decimals, arithmetic steps).

Fix

One more protection pass before the currency escape. A $…$ span whose body starts with a digit is kept as math when:

  • its body ends on a non-space character right before the closing $, so pay $5 and $10 still reads as two prices, and
  • the body holds a letter or TeX syntax (\ ^ _ { }), is a decimal, puts an operator between two numbers, or lists numbers.

Plain amounts ($20, $1,000, $19.99, $20-$50) are escaped exactly as before.

Tests

Two cases in src/latex.test.ts: digit-led formulas stay math, and two prices in one line are still escaped. The latex tests pass (145), and the new case fails without the change.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant