mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 18:00:11 +08:00
_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>
22 lines
562 B
Python
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
|