Skip to content

Translate symbols once in typst output - #123

Open
soodoku wants to merge 1 commit into
py-econometrics:mainfrom
finite-sample:fix/typst-double-symbol-translation
Open

soodoku wants to merge 1 commit into
py-econometrics:mainfrom
finite-sample:fix/typst-double-symbol-translation

Conversation

@soodoku

@soodoku soodoku commented Nov 8, 2026

Copy link
Copy Markdown

What problem do you want to solve?

import pandas as pd
import maketables as mt

df = pd.DataFrame({"A": ["1"]}, index=["x ≤ 5"])
print(mt.MTable(df, notes="p ≥ 0.1").make(type="typst"))

Observed: [x $$≤$$ 5] and p $$≥$$ 0.1. Expected: $≤$ and $≥$, which is the Typst form in symbols.SYMBOLS.

_output_typst calls _translate_symbols(..., "typst") on the finished table twice, one call straight after the other. The Typst forms of ≤ and ≥ contain the symbol itself, so the second pass wraps them again. The document still compiles: $$ is an empty equation, so the result is two empty equations around a text-mode ≤, not a math-mode symbol. The other symbols (R², ×, Greek letters, ±, °) map to strings without the original character, so the second pass leaves them alone.

Fix

Remove the duplicated call.

Tests

test_typst_translates_each_symbol_once is parametrized over every key in SYMBOLS and checks that the row label renders as exactly SYMBOLS[s]["typst"]. 2 of the 9 cases (≤, ≥) fail on main, and all 9 pass with the fix. The test checks the generated source rather than compiling it, because both the buggy and the fixed output compile. Full suite: 507 passed, and all 135 snapshots are unchanged. pre-commit and ty are clean.

🤖 Generated with Claude Code

Problem: a label or note containing "≤" or "≥" comes out of
make(type="typst") as "$$≤$$" instead of "$≤$": two empty equations
around a text-mode symbol.

Cause: _output_typst applies _translate_symbols to the finished table
twice. The typst forms of ≤ and ≥ ("$≤$", "$≥$") contain the symbol
itself, so the second pass wraps them again; the other symbols map to
strings without the original character and were unaffected.

Fix: drop the duplicated call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant