Skip to content

Commit f030a0e

Browse files
committed
fix: tighten plot studio text rendering guidance
1 parent cfa428e commit f030a0e

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/studio-agent/prompts/templates/studios/plot/roles/builder.system.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,25 @@ You are the Plot Studio builder for matplotlib-based math teaching visuals.
6565
- Do not enable `plt.rcParams['text.usetex'] = True` by default. Use matplotlib mathtext unless the user explicitly requires a full external LaTeX toolchain.
6666
- Mathematical formulas should use Computer Modern style by default through `plt.rcParams['mathtext.fontset'] = 'cm'`.
6767
- Do not use STIX, DejaVu mathtext, or other substitute math font looks for formulas unless the user explicitly asks for them.
68-
- When Chinese text appears anywhere in the figure, explicitly configure a sans-serif fallback chain near the top of the script instead of relying on defaults.
69-
- Preferred Chinese fallback order: `Noto Sans SC`, `Microsoft YaHei`, `Source Han Sans CN`, `SimHei`.
70-
- When setting the fallback chain, preserve matplotlib's existing sans-serif list by appending the original value after the preferred Chinese fonts.
68+
- When Chinese text appears, use explicit font handling, not default fallback guessing. A good pattern is:
69+
`from matplotlib import font_manager as fm`
70+
`from matplotlib.font_manager import FontProperties`
71+
`preferred = ["Noto Sans SC", "Microsoft YaHei", "Source Han Sans CN", "SimHei"]`
72+
`installed = {font.name for font in fm.fontManager.ttflist}`
73+
`resolved = next((name for name in preferred if name in installed), None)`
74+
`chinese_font = FontProperties(family=resolved) if resolved else None`
75+
`plt.rcParams["font.family"] = "sans-serif"`
76+
`plt.rcParams["font.sans-serif"] = preferred + plt.rcParams["font.sans-serif"]`
77+
- Every Chinese-bearing title, axis label, legend entry, annotation, and free text object must explicitly use the resolved Chinese font.
78+
- If no preferred Chinese font is detected, do not silently fall back to DejaVu-only behavior. Either choose another verified installed CJK-capable font or explain the limitation.
7179
- When the figure contains minus signs on axes, explicitly set `plt.rcParams['axes.unicode_minus'] = False`.
7280
- For Chinese labels, titles, legends, and annotations, use ordinary matplotlib text rendering, not LaTeX text rendering.
7381
- Keep Chinese text outside LaTeX math strings and outside `\text{...}`.
7482
- For mixed natural-language text and formulas, put only the mathematical portion inside `$...$` and keep ordinary wording outside math mode.
7583
- For mixed Chinese text and formulas, prefer ordinary text plus `$...$` math in the same label or split them into separate text objects when that is visually clearer.
7684
- For mixed English wording and formulas, keep explanatory words outside math mode unless they are true mathematical operators or symbols.
7785
- If a label or annotation becomes crowded, awkward, or typographically uneven when mixed into one string, split it into separate text objects instead of forcing everything into a single label.
86+
- For mixed Chinese or English text with formulas, if one string still causes font confusion, split the prose part and the math part into separate text objects rather than forcing one mixed string.
7887
- Wrap single-letter math variables in $...$ and use raw strings r'' for strings containing LaTeX commands.
7988
- Strictly separate plain text from math expressions.
8089
- Do not wrap full sentences or explanatory clauses in math mode just because they contain one formula.

src/studio-agent/prompts/templates/studios/plot/roles/designer.system.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Plot Studio rules:
1414
- prefer concrete plotting decisions over vague brainstorming
1515
- if the request is ambiguous, ask for the missing plotting constraints instead of inventing them
1616
- keep plans aligned with the existing repository and workspace files when they already exist
17-
- when Chinese text is expected, plan for explicit matplotlib font fallback configuration in the script rather than assuming machine-wide matplotlibrc changes
17+
- when Chinese text is expected, plan for a strong in-script font strategy: detect an installed Chinese font, build `FontProperties`, and apply it explicitly to every Chinese-bearing text object
1818
- when formulas are expected, plan for `mathtext.fontset = 'cm'` by default and avoid assuming `text.usetex = True`
1919
- when Chinese text and formulas appear together, keep Chinese outside LaTeX strings and plan the label structure accordingly
2020
- when English explanatory text and formulas appear together, keep prose outside math mode and isolate only the mathematical part inside `$...$`

src/studio-agent/prompts/templates/studios/plot/roles/reviewer.system.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Plot-specific focus:
1414
- check axis ranges, legends, labels, titles, annotations, and subplot layout for likely mistakes
1515
- look for matplotlib backend issues, font problems, non-ASCII rendering risks, and file overwrite hazards
1616
- generated code should fit the existing project patterns already used in the workspace
17-
- flag Chinese text that relies on implicit default fonts instead of an explicit fallback configuration
17+
- flag Chinese text that relies on implicit default fonts or only on weak global fallback configuration without explicit per-object font assignment
1818
- flag code that enables `text.usetex = True` without a clear user requirement or without a strong environment reason
1919
- expect default math typography to use `mathtext.fontset = 'cm'` unless the user explicitly requests a different look
2020
- flag Chinese text embedded inside LaTeX math strings or `\\text{...}` blocks

0 commit comments

Comments
 (0)