Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/api/latex_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def build_latex_for_formulas(selected_formulas, columns=2, font_size="10pt", mar
# Escape special LaTeX characters in the formula name
escaped_name = name.replace("\\", "\\textbackslash ").replace("&", "\\&").replace("%", "\\%").replace("#", "\\#").replace("_", "\\_").replace("^", "\\textasciicircum ").replace("{", "\\{").replace("}", "\\}")
body_lines.append("\\textbf{" + escaped_name + "}")
body_lines.append("\\[ \\adjustbox{max width=\\linewidth}{\\displaystyle " + latex + "} \\]")
body_lines.append("\\[ \\adjustbox{max width=\\linewidth}{$\\displaystyle " + latex + "$} \\]")
body_lines.append(f"\\\\[{formula_gap}]")

if in_flushleft:
Expand Down
17 changes: 17 additions & 0 deletions backend/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,23 @@ def test_generate_sheet_10pt_uses_article(self, api_client):
assert "\\documentclass[10pt,fleqn]{article}" in tex
assert "extarticle" not in tex

def test_generate_sheet_formula_uses_displaystyle_in_adjustbox(self, api_client):
"""Non-special-class formulas must be wrapped in $\\displaystyle ...$
inside \\adjustbox to preserve display-style math rendering."""
resp = api_client.post(
"/api/generate-sheet/",
{
"formulas": [
{"class": "ALGEBRA I", "category": "Linear Equations", "name": "Slope Formula"}
]
},
format="json",
)
assert resp.status_code == 200
tex = resp.json()["tex_code"]
assert "\\adjustbox{max width=\\linewidth}" in tex
assert "$\\displaystyle" in tex

def test_generate_sheet_latex_injection_blocked(self, api_client):
"""LaTeX injection attempts in parameters should be sanitized."""
resp = api_client.post(
Expand Down
Loading