Files
DeepTutor/tests/services/test_speech_escaped_percent.py
Rudy Celekli 604c835cc3 fix(voice): read an escaped percent in math as "percent"
_drop_unknown_commands discarded both characters of "\%" because no
branch matched "%", so "$10\%$" spoke as " 10 " and dropped the percent.
Since a bare % starts a TeX comment, \% is the normal spelling of a
percentage; read it as "percent" instead of dropping it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-01 23:50:24 -05:00

22 lines
562 B
Python

"""An escaped percent (``\\%``) inside math must survive as spoken "percent"."""
import pytest
from deeptutor.services.voice.speech_text import verbalize_latex_for_speech
def _spoken(text: str) -> str:
return " ".join(verbalize_latex_for_speech(text).split())
@pytest.mark.parametrize(
("latex", "expected"),
[
(r"$10\%$", "10 percent"),
(r"$x = 50\%$", "x = 50 percent"),
(r"$3.5\%$", "3.5 percent"),
],
)
def test_escaped_percent_is_spoken(latex: str, expected: str) -> None:
assert _spoken(latex) == expected