From 065b09a002e04a542625e64a9e62f223e204265b Mon Sep 17 00:00:00 2001 From: Kamisato Date: Thu, 9 Apr 2026 11:55:01 -0700 Subject: [PATCH 1/2] Fix LaTeX math mode in adjustbox - wrap formula in $...$ --- backend/api/latex_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/api/latex_utils.py b/backend/api/latex_utils.py index 80614f5..bcaa961 100644 --- a/backend/api/latex_utils.py +++ b/backend/api/latex_utils.py @@ -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}{$" + latex + "$} \\]") body_lines.append(f"\\\\[{formula_gap}]") if in_flushleft: From ebd0868ac10ebf6a837018475c393de68d5e0bd1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Apr 2026 19:06:21 +0000 Subject: [PATCH 2/2] Use $\displaystyle$ in adjustbox and add regression test Agent-Logs-Url: https://github.com/ChicoState/cheat-sheet/sessions/6cf938c1-4164-4c40-b003-4cd063d56458 Co-authored-by: bdtran2002 <19805162+bdtran2002@users.noreply.github.com> --- backend/api/latex_utils.py | 2 +- backend/api/tests.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/api/latex_utils.py b/backend/api/latex_utils.py index bcaa961..c77fce9 100644 --- a/backend/api/latex_utils.py +++ b/backend/api/latex_utils.py @@ -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}{$" + latex + "$} \\]") + body_lines.append("\\[ \\adjustbox{max width=\\linewidth}{$\\displaystyle " + latex + "$} \\]") body_lines.append(f"\\\\[{formula_gap}]") if in_flushleft: diff --git a/backend/api/tests.py b/backend/api/tests.py index 84cf7db..e14d63a 100644 --- a/backend/api/tests.py +++ b/backend/api/tests.py @@ -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(