Skip to content

fix: hwpeq inf 기호(∞) 우선순위 복원 (closes #762)#764

Closed
oksure wants to merge 8 commits into
edwardkim:develfrom
oksure:contrib/fix-inf-symbol-regression
Closed

fix: hwpeq inf 기호(∞) 우선순위 복원 (closes #762)#764
oksure wants to merge 8 commits into
edwardkim:develfrom
oksure:contrib/fix-inf-symbol-regression

Conversation

@oksure

@oksure oksure commented May 9, 2026

Copy link
Copy Markdown
Contributor

문제

PR #729 (LaTeX 명령어 호환 확장)에서 FUNCTIONS HashMap에 ("inf", "inf")을 추가하면서, 기존 hwpeq의 inf 매핑이 함수 텍스트 "inf"로 대체되는 회귀 발생.

samples/exam_math.hwp 페이지 14/16에서 기호가 inf 텍스트로 출력됨.

원인

parser.rs에서 is_function(cmd) (라인 500)이 lookup_symbol(cmd) (라인 511)보다 먼저 점검되므로, inf가 기호()가 아닌 함수 텍스트(inf)로 처리됨.

수정

lookup_symbol (Unicode 기호 매핑)을 is_function (함수명 매칭)보다 먼저 점검하도록 우선순위 조정.

  • inflookup_symbolINF (기존 hwpeq 동작 복원)
  • deglookup_symbolDEG° (기존 hwpeq 동작 복원)
  • sin, cos, log 등 → 기호 테이블에 없으므로 함수로 정상 처리

회귀 가드

테스트 2건 추가:

  • test_hwpeq_inf_remains_symbol: lim _{n→inf} 에서 출력 확인
  • test_hwpeq_deg_remains_symbol: 90 deg 에서 ° 출력 확인

검증

  • cargo test --lib: 1207 passed, 0 failed
  • cargo clippy -- -D warnings: 경고 0건

Closes #762
감사합니다.

oksure and others added 8 commits May 9, 2026 04:54
PR edwardkim#563 (1차: \frac, \sqrt) 이후 추가 LaTeX 명령어 지원:

- \dfrac, \tfrac → Fraction (display/text 스타일 분수)
- \text{...} → FontStyle(Roman) (본문 텍스트)
- \mathrm, \mathit, \mathbf → 기존 FontStyleKind 매핑
- \mathbb, \mathcal, \mathfrak, \mathsf, \mathtt → 신규 FontStyleKind 5종
- \overline, \underline, \not → 소문자 DECORATIONS 별칭 (대소문자 호환)
- \widehat, \widetilde, \overrightarrow → 기존 DecoKind 매핑
- \textbf, \textrm, \textit → FontStyleKind 매핑

Refs edwardkim#143

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
LaTeX 환경(environment) 구문을 기존 수식 AST로 매핑:

- \begin{pmatrix}...\end{pmatrix} → Matrix(Paren)
- \begin{bmatrix}...\end{bmatrix} → Matrix(Bracket)
- \begin{vmatrix}...\end{vmatrix} → Matrix(Vert)
- \begin{matrix}...\end{matrix} → Matrix(Plain)
- \begin{cases}...\end{cases} → Cases
- \begin{aligned}...\end{aligned} → EqAlign
- \begin{align}...\end{align} → EqAlign

토크나이저: \\ (이중 백슬래시) → Whitespace("#") 변환으로 hwpeq의 # (행 구분)과 동일하게 처리.

Refs edwardkim#143

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
native-skia feature 활성화 시 equation_conv.rs의 FontStyleKind 매치에
Blackboard/Calligraphy/Fraktur/SansSerif/Monospace 분기가 누락되어
CI 빌드 실패. svg_render.rs/canvas_render.rs와 동일한 패턴으로 수정.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- FontStyleKind::Bold: 기존 동작 (italic, true) 복원. Blackboard만 upright+bold.
  → bold+italic 중첩 (it {bold {...}}) 정상 동작 보장
- \text{...} 주석에 공백 제한사항 문서화 (토크나이저 skip_spaces)

3개 렌더러 (svg_render, canvas_render, skia/equation_conv) 모두 동일 수정.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
LaTeX 수식 입력 호환성을 넓히기 위한 명령어 추가:

기호 별칭 (~60개):
- 관계/논리: \leq, \geq, \neq, \approx, \equiv, \subset, \forall, \exists 등
- 화살표: \rightarrow, \leftarrow, \implies, \iff, \mapsto, \to, \gets 등
- 연산자: \cdot, \times, \div, \pm, \cup, \cap, \oplus, \otimes 등
- 기호: \infty, \nabla, \partial, \emptyset, \dots, \perp 등
- 큰 연산자: \sum, \prod, \int, \iint, \iiint, \oint, \bigcup, \bigcap 등

구조 명령어 (5개):
- \operatorname{...} → 로만체 연산자명 (hwpeq rm 매핑)
- \phantom{...}, \vphantom, \hphantom → 보이지 않는 공간
- \overbrace, \underbrace → hwpeq arch/under 장식 매핑

간격 명령어 (7개):
- \quad, \qquad → em/2em 공백
- \,  \:  \;  \! → thin/medium/thick/negative 공백
- 토크나이저 레벨에서 \+기호 → THINSPACE 등 명령어 변환

함수명 (6개): \sup, \inf, \lim, \limsup, \liminf, \Pr

테스트: latex_compat_tests 모듈에 11개 추가 (총 29개)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
구조 명령어 추가:
- \overset{over}{base} → Superscript AST (위 첨자로 매핑)
- \underset{under}{base} → Subscript AST (아래 첨자로 매핑)
- \stackrel{over}{base} → Superscript AST

LaTeX 환경 추가:
- \begin{array}...\end{array} → Plain Matrix
- \begin{smallmatrix}...\end{smallmatrix} → Plain Matrix
- \begin{Bvmatrix}...\end{Bvmatrix} → Vert Matrix (이중 세로선)
- \begin{split}, \begin{gather}, \begin{gathered} → EqAlign

테스트 6개 추가 (총 35개 LaTeX 호환 테스트)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
토크나이저:
- \{ → LBrace, \} → RBrace (LaTeX 이스케이프 중괄호)
- \| → Symbol(|), \# → Whitespace(#)

괄호 별칭 추가:
- \langle/\rangle → ⟨/⟩ (각도 괄호)
- \lbrace/\rbrace → {/} (소문자 별칭)
- \lceil/\rceil, \lfloor/\rfloor (소문자 별칭)
- \lvert/\rvert → |, \lVert/\rVert → ‖

테스트 2개 추가 (총 37개 LaTeX 호환 테스트)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
PR #729에서 FUNCTIONS HashMap에 ("inf", "inf")을 추가하면서,
hwpeq의 inf → ∞ 매핑이 함수 텍스트 "inf"로 대체되는 회귀 발생.

수정: parser.rs에서 lookup_symbol (Unicode 기호 매핑)을
is_function (함수명 매칭)보다 먼저 점검하도록 우선순위 조정.

- inf → ∞ (기존 hwpeq 동작 복원)
- deg → ° (기존 hwpeq 동작 복원)
- sin, cos, log 등 → 기호 테이블에 없으므로 함수로 정상 처리

회귀 가드 테스트 2건 추가:
- test_hwpeq_inf_remains_symbol: lim _{n→inf} 에서 ∞ 출력 확인
- test_hwpeq_deg_remains_symbol: 90 deg 에서 ° 출력 확인

Closes edwardkim#762

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 9, 2026 19:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Restores hwpeq command handling so symbol lookups (e.g., inf, deg°) take precedence over function-name rendering, addressing a regression introduced by adding inf to the function table.

Changes:

  • Reordered command resolution in the equation parser to prefer lookup_symbol(cmd) over is_function(cmd).
  • Expanded LaTeX tokenization/parsing support (spacing commands, escaped characters, environments) and added/updated symbol/function/style tables accordingly.
  • Updated SVG/Canvas/Skia equation renderers to handle newly added FontStyleKind variants and added regression/compat tests.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/renderer/skia/equation_conv.rs Updates font-style rendering decisions to cover new FontStyleKind variants.
src/renderer/equation/tokenizer.rs Adds LaTeX-specific tokenization (e.g., \\, spacing commands, escaped characters).
src/renderer/equation/symbols.rs Extends symbol/operator/arrow/bracket/function tables and adds new font style kinds.
src/renderer/equation/svg_render.rs Updates font-style rendering decisions to cover new FontStyleKind variants.
src/renderer/equation/parser.rs Changes symbol-vs-function precedence and adds multiple LaTeX parsing paths + tests.
src/renderer/equation/canvas_render.rs Updates font-style rendering decisions to cover new FontStyleKind variants.
Comments suppressed due to low confidence (1)

src/renderer/equation/symbols.rs:273

  • is_structure_command includes "lim" | "Lim", but call sites (e.g. parser font-style lookahead) pass an uppercased command string. That means lim becomes "LIM" and won’t be recognized as a structure command in that path. Consider normalizing case inside is_structure_command (or adding "LIM") so case handling is consistent with the parser’s usage.
        "CASES" | "PILE" | "LPILE" | "RPILE" |
        "CHOOSE" | "BINOM" |
        "lim" | "Lim" |
        "REL" | "BUILDREL" |

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

'{' => Some(Token::new(TokenType::LBrace, "{", start)),
'}' => Some(Token::new(TokenType::RBrace, "}", start)),
'|' => Some(Token::new(TokenType::Symbol, "|", start)),
'#' => Some(Token::new(TokenType::Whitespace, "#", start)),
Comment on lines +291 to +292
'{' => Some(Token::new(TokenType::LBrace, "{", start)),
'}' => Some(Token::new(TokenType::RBrace, "}", start)),
}

#[test]
#[test]
Comment on lines +223 to 227
// LaTeX 분수: \frac{a}{b}, \dfrac{a}{b}, \tfrac{a}{b}
if matches!(cu, "FRAC" | "DFRAC" | "TFRAC") {
return self.parse_latex_fraction();
}

Comment on lines +248 to +252
// LaTeX \phantom{...} — 보이지 않는 공간 (레이아웃 정렬용)
if matches!(cu, "PHANTOM" | "VPHANTOM" | "HPHANTOM") {
self.parse_single_or_group();
return EqNode::Text(" ".to_string());
}
@edwardkim edwardkim self-requested a review May 10, 2026 17:33
@edwardkim edwardkim added the bug Something isn't working label May 10, 2026
@edwardkim edwardkim added this to the v1.0.0 milestone May 10, 2026
edwardkim added a commit that referenced this pull request May 10, 2026
PR #729 (Task #143 LaTeX 호환 확장 1차, 5/9 머지) 회귀 정정 — FUNCTIONS HashMap 영역 ('inf', 'inf') 추가 영역 기존 hwpeq inf → ∞ 매핑이 함수 텍스트로 대체됨.

정정 (parser.rs +36/-7): lookup_symbol (Unicode 기호) 영역 is_function (함수명) 영역 먼저 점검:
- inf → ∞ (기존 동작 복원)
- deg → ° (기존 동작 복원)
- sin/cos/log 등 → 함수 처리 (정합)

회귀 가드 테스트 2건 추가:
- test_hwpeq_inf_remains_symbol
- test_hwpeq_deg_remains_symbol

본 환경 head commit 만 cherry-pick (옵션 1) — PR 본문 영역 본질 (Issue #762 정정) 만 적용, commit 6~8 (Task #143 추가 LaTeX 확장) 영역 별 본질 영역 별 PR 안내.

검증:
- cargo build/test/clippy --release ALL GREEN (clippy -D warnings)
- 회귀 가드 2건 PASS
- 광범위 sweep 168 same / 2 diff (exam_math_014/016 — 의도된 시각 변경: ∞ 기호 복원, PR 본문 정합)
- WASM 4.66 MB 재빌드
- 작업지시자 시각 판정 ✅ 통과

이전 abandon (Service Worker 캐시 결함) 영역 다시 시도 — 본 환경 영역 정합 진행.

closes #762
@edwardkim

Copy link
Copy Markdown
Owner

@oksure 검토 완료했습니다. 감사합니다.

처리 결과

Merge commit: 4cf08316 (devel)

본질

PR #729 (Task #143 LaTeX 확장 1차) 머지 후 회귀 정정 — inf / deg° 기존 hwpeq 동작 복원. parser.rs 영역 lookup_symbol 영역 is_function 영역 먼저 점검 영역 우선순위 조정.

본 환경 처리 — head commit 만 cherry-pick (옵션 1)

본 PR 영역 8 commits 누적 영역 본 환경 영역 head commit (0eed7a3b) 만 cherry-pick — Issue #762 정정 본질만 적용. 다른 commits 영역:

본질 처리
commits 1~5 (Task #143 LaTeX 확장 1차) PR #729 영역 머지 완료 영역 devel 영역 이미 적용 (skip)
commit 6 (45fdb335 Task #143 명령어 대폭 확장 3차) 별 본질 영역 별 PR 권장
commits 7~8 (d672f954+04187512 overset/underset/stackrel + 이스케이프) 별 본질 영역 별 PR 권장
head commit (0eed7a3b Issue #762 정정) ✅ 본 PR 본질 영역 cherry-pick 적용

PR 본문 영역 Issue #762 정정만 명시되어 있어, commit 68 의 추가 LaTeX 확장 (Task #143 의 2차/3차) 은 별 본질로 분리 권장합니다. 가능하시면 commit 68 영역 별 PR 영역 다시 등록 부탁드립니다.

검증

  • cargo build/test/clippy --release ALL GREEN (clippy -D warnings)
  • 회귀 가드 2건 PASS (inf/deg)
  • 광범위 sweep 168 same / 2 diff (exam_math_014/016 — 의도된 시각 변경: ∞ 기호 복원, PR 본문 정합)
  • WASM 4.66 MB 재빌드
  • 작업지시자 시각 판정 ✅ 통과 (samples/exam_math.hwp 페이지 14/16 영역 ∞ 기호)

Issue #762 close.

5/10 사이클 27번째 PR — 수고하셨습니다.

@edwardkim

Copy link
Copy Markdown
Owner

Merged. Merge commit: 4cf0831

@edwardkim edwardkim closed this May 10, 2026
edwardkim added a commit that referenced this pull request May 10, 2026
PR #764 (closes #762) — 이전 abandon 후 재시도, head commit 만 cherry-pick (옵션 1).
hwpeq inf/deg 기호 우선순위 복원 — PR #729 회귀 정정. samples/exam_math.hwp 페이지 14/16 영역 ∞ 기호 정합.

Merge commit: 4cf0831
Cherry-pick: 0cc3d5c (head commit 0eed7a3)
컨트리뷰터에 commit 6~8 별 PR 안내 완료 (PR comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants