mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 01:19:31 +08:00
A \circ written as a superscript is the degree sign (90^\circ), but the math verbalizer mapped \circ to "compose" before handling the ^ script, so "$90^\circ$" spoke as " 90 to the c ompose " instead of "90 degrees". Rewrite a superscript \circ to "degrees" before the operator pass; a composition operand (f \circ g) still speaks as "compose". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
29 lines
847 B
Python
29 lines
847 B
Python
"""A ``\\circ`` superscript is the degree sign and must be spoken as "degrees"."""
|
|
|
|
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"$90^\circ$", "90 degrees"),
|
|
(r"$45^\circ$", "45 degrees"),
|
|
(r"$T^{\circ}$", "T degrees"),
|
|
(r"$x = 30^\circ$", "x = 30 degrees"),
|
|
],
|
|
)
|
|
def test_circ_superscript_speaks_as_degrees(latex: str, expected: str) -> None:
|
|
assert _spoken(latex) == expected
|
|
|
|
|
|
def test_circ_as_composition_operator_is_unchanged() -> None:
|
|
# Outside a superscript, ``\circ`` is function composition and must not
|
|
# be rewritten to "degrees".
|
|
assert _spoken(r"$f \circ g$") == "f compose g"
|