Skip to content

Fix unescaped backslash in theta label in model_variables.json - #1193

Open
arihantlodha-cmd wants to merge 1 commit into
PSLmodels:masterfrom
arihantlodha-cmd:fix-theta-label-escape
Open

Fix unescaped backslash in theta label in model_variables.json#1193
arihantlodha-cmd wants to merge 1 commit into
PSLmodels:masterfrom
arihantlodha-cmd:fix-theta-label-escape

Conversation

@arihantlodha-cmd

Copy link
Copy Markdown

Closes #1015.

The theta label in model_variables.json was written with a single backslash:

"label": "Replacement rate ($\theta_j$)",

JSON interprets \t as a tab character, so \theta parsed to <TAB>heta and the label failed to render as LaTeX in plots. This escapes the backslash so it parses to a literal \theta:

"label": "Replacement rate ($\\theta_j$)",

This matches the convention already used by the other LaTeX labels in the file — the \\tilde labels for c and p_tilde were already written with escaped backslashes and render correctly. I went with escaping the JSON source (rather than casting to raw strings at read time, as the issue floated) because it's consistent with those existing labels and doesn't require any change to how constants.py loads the file. theta was the only remaining label with an unescaped backslash.

Also adds tests/test_constants.py::test_labels_have_no_control_characters, which asserts that no VAR_LABELS/ToGDP_LABELS entry contains a control character — guarding against this class of bug being reintroduced.

Testing

  • pytest tests/test_constants.py passes; confirmed the test fails on the pre-fix JSON.
  • Verified VAR_LABELS["theta"] == "Replacement rate ($\\theta_j$)" (literal backslash, no tab) and no other labels contain control characters.
  • ruff format --check ., ruff check ., and linecheck clean.

Closes PSLmodels#1015. The 'theta' label in model_variables.json used a single
backslash ($\theta_j$), which JSON parses into a tab character, so the
label failed to render properly in plots. Escape it ($\\theta_j$) to match
the already-corrected \\tilde labels. Adds test_constants.py guarding against
control characters in any VAR_LABELS/ToGDP_LABELS entry.
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.

Label strings in model_variables.json not rendering properly

1 participant