Fix/sum preview#261
Open
m-messer wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
Custom symbols defined with big-operator LaTeX (e.g.
infsumwith\sum_{n=1}^{\infty}) were treated as plain SymPy Symbol objects. This meantinfsum((-1)^n / n^2)parsed as multiplication (Symbol("infsum") * ((-1)^n / n^2)), causing the sum symbol to appear in fraction numerators or with spurious\cdotmultiply dots in the preview. For example, from JF's course:infsum((-1)^n / n^2)rendered with the sum symbol inside the fraction numerator instead of wrapping the expressionpi^2/3 + infsum((-1)^n*cos(n*x)*(4/n^2)rendered with a \cdot immediately after the sum symbolSolution:
Detect prefix operator symbols automatically from their existing
latexdefinition: if a symbol's LaTeX starts with a big operator command (\sum, \int, \prod, \lim, \bigcup, \bigcap), create a SymPy Function subclass for it instead of a Symbol. No changes to teacher-facing configuration are required.A SymPy Function subclass is necessary because of how SymPy's parser handles callable objects in
local_dict. Wheninfsumis a Symbol, SymPy's auto-multiplication transformation convertsinfsum(x)intoSymbol("infsum") * x.By placing a Function subclass in
local_dictinstead, SymPy's parser treatsinfsum(x)as a genuine function applicationInfSum(x), the subclass carries a_latex()method that the SymPy printer calls when it encounters
InfSum(x), returning{symbol_latex} {arg_latex} directly.Changes:
app/utility/expression_utilities.py- added BIG_OPERATOR_PREFIXES constant; modifiedsympy_symbols()to create a dynamic Function subclass (with custom_latex()) for any symbol whose LaTeX begins with a big operator prefix, falling back to Symbol otherwise.app/preview_test.py- added test_sum_previewTo test please use the sandbox here