fix: KaTeX 통화 가드가 $60\sim80\text{cm}$ 같은 숫자로 시작하는 수식을 죽이던 문제

`$` 다음에 숫자가 오면 무조건 통화로 보고 여는 `$`를 감췄는데, 모델이
`$60\sim80\text{cm}$`처럼 숫자로 시작하는 LaTeX를 내면 수식 전체가 날것으로
남아 `\sim`·`\text{cm}`가 그대로 노출됐다("단위가 이상하게" 신고).

다음 `$`까지의 구간에 백슬래시가 있으면 수식으로 판단해 그 `$`는 건드리지 않는다.
기존 통화 케이스(`$100 절감 … $\rightarrow$`)는 그대로 통화로 처리됨.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rfme1WVEPkpNwnf5oVNXXc
This commit is contained in:
kimandClaude Sonnet 5 committed 2026-09-07 10:23:30 +09:00
1 parent ddd276c15a
commit bf6aae12b3
2 files changed
+24 -2

No files matched your search

+12 -1
View File
@@ -350,11 +350,22 @@ function _walkTextNodes(root, fn) {
for (const n of nodes) fn(n);
}
// `$` 다음에 숫자가 오면 보통 통화지만, `$60\sim80\text{cm}$`처럼 다음 `$`까지의 구간에
// 백슬래시(LaTeX 명령)가 있으면 그건 수식이다 — 그 `$`는 건드리지 않는다.
function _maskCurrencyDollars(s) {
return s.replace(/\$(?=\d)/g, (m, offset) => {
const rest = s.slice(offset + 1);
const end = rest.indexOf('$');
const span = end === -1 ? rest : rest.slice(0, end);
return span.includes('\\') ? m : _KATEX_DOLLAR_SENTINEL;
});
}
function renderKatexIn(container) {
if (!window.renderMathInElement || !container) return;
try {
_walkTextNodes(container, (n) => {
if (n.nodeValue.includes('$')) n.nodeValue = n.nodeValue.replace(/\$(?=\d)/g, _KATEX_DOLLAR_SENTINEL);
if (n.nodeValue.includes('$')) n.nodeValue = _maskCurrencyDollars(n.nodeValue);
});
renderMathInElement(container, {
delimiters: [
+12 -1
View File
@@ -24,11 +24,22 @@
for (var i = 0; i < nodes.length; i++) fn(nodes[i]);
}
// `$` 다음에 숫자가 오면 보통 통화지만, `$60\sim80\text{cm}$`처럼 다음 `$`까지의 구간에
// 백슬래시(LaTeX 명령)가 있으면 그건 수식이다 — 그 `$`는 건드리지 않는다.
function maskCurrencyDollars(s) {
return s.replace(/\$(?=\d)/g, function (m, offset) {
var rest = s.slice(offset + 1);
var end = rest.indexOf('$');
var span = end === -1 ? rest : rest.slice(0, end);
return span.indexOf('\\') !== -1 ? m : SENTINEL;
});
}
window.renderKatexIn = function renderKatexIn(container) {
if (!window.renderMathInElement || !container) return;
try {
walkTextNodes(container, function (n) {
if (n.nodeValue.indexOf('$') !== -1) n.nodeValue = n.nodeValue.replace(/\$(?=\d)/g, SENTINEL);
if (n.nodeValue.indexOf('$') !== -1) n.nodeValue = maskCurrencyDollars(n.nodeValue);
});
window.renderMathInElement(container, {
delimiters: [