Formula Rendering
CalculusCalculator presents expressions as mathematical formulas in several places, mainly relying on LaTeX.
Result Formula Rendering
Computation results from modules such as differentiation, integration, function properties, transformation, and equation solving are converted to SVG via core/render.py and rendered in a QGraphicsView, supporting light / dark backgrounds.
- Light theme: view background is white
- Dark theme: view background is black
- After switching themes, displayed formulas automatically refresh with the new color scheme
LaTeX Output in the Compute Tab
The "Compute" tab provides three computation engines, among which:
- SymPy symbolic engine: performs symbolic computation based on SymPy; results are displayed both as LaTeX code and as plain text.
- LaTeX code generation engine: directly generates corresponding LaTeX code from the input Python expression, convenient for copying into papers and notes.
Help Document Rendering
The built-in "Help" page uses QTextBrowser to display static documentation (changed from QWebEngineView to QTextBrowser since v1.6.1), significantly improving load performance and adapting to main window scaling.
Input as LaTeX
In any expression input box, LaTeX code starting with $ is automatically parsed into a SymPy expression before rendering; see String Parsing.
Python API
The rendering logic lives in core/render.py; the public functions are:
| Function | Description |
|---|---|
setGraphicsView(n, l, g) |
Render LaTeX expression l (with name prefix n) into the QGraphicsView g. Automatically applies text / background colors from the parent window's theme and caches it for refresh after theme switches. |
refreshGraphicsView() |
After a theme switch, re-render all cached graphics views. |
setGraphicsViewTheme(main_class, parent_class) |
Set the background color of all QGraphicsViews in a window (white for light, black for dark). |
clearGraphicsView(g) |
Clear the rendered content of the QGraphicsView g and remove its cache, used to wipe previous output before a new solve. (QGraphicsView has no setHtml method, so this function should be used instead.) |
applyPlotTheme(fig, ax, theme) |
Adapt a matplotlib Figure / Axes (2D or 3D) to light / dark theme colors, returning (bg, fg, grid_color, axis_color) for further styling of grid lines and axes. Function plotting and plane / solid geometry plotting use it for dark mode. |
Note
Rendering uses Matplotlib's Agg backend to generate SVG, then displays it via QGraphicsSvgItem. Chinese text is rendered as plain text with a CJK font while formulas use mathtext, avoiding tofu (boxes) for Chinese characters.