Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use defined System Symbols #204

Merged
merged 1 commit into from
Aug 3, 2024
Merged
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
21 changes: 10 additions & 11 deletions mathics_django/web/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SymbolFullForm,
SymbolGraphics,
SymbolGraphics3D,
SymbolInputForm,
SymbolMathMLForm,
SymbolOutputForm,
SymbolStandardForm,
Expand Down Expand Up @@ -84,31 +85,31 @@ def eval_boxes(result, fn: Callable, obj, **options):
result = expr.elements[0].format(obj, expr_type)
return result.boxes_to_text()
elif expr_head is SymbolGraphics:
result = Expression(SymbolStandardForm, expr).format(obj, "System`MathMLForm")
result = Expression(SymbolStandardForm, expr).format(obj, SymbolMathMLForm)

# This part was derived from and the same as evaluation.py format_output.

use_quotes = get_settings_value(obj.definitions, "Settings`$QuotedStrings")

if format == "text":
result = expr.format(obj, "System`OutputForm")
result = expr.format(obj, SymbolOutputForm)
result = eval_boxes(result, result.boxes_to_text, obj)

if use_quotes:
result = '"' + result + '"'

return result
elif format == "xml":
result = Expression(SymbolStandardForm, expr).format(obj, "System`MathMLForm")
result = Expression(SymbolStandardForm, expr).format(obj, SymbolMathMLForm)
elif format == "tex":
result = Expression(SymbolStandardForm, expr).format(obj, "System`TeXForm")
result = Expression(SymbolStandardForm, expr).format(obj, SymbolTeXForm)
elif format == "unformatted":
if expr_head is PyMathicsGraph and hasattr(expr, "G"):
return format_graph(expr.G)
if expr_head is SymbolCompiledFunction:
result = expr.format(obj, "System`OutputForm")
result = expr.format(obj, SymbolOutputForm)
elif expr_head is SymbolString:
result = expr.format(obj, "System`InputForm")
result = expr.format(obj, SymbolInputForm)
result = result.boxes_to_text()

if not use_quotes:
Expand All @@ -118,16 +119,14 @@ def eval_boxes(result, fn: Callable, obj, **options):
return result
elif expr_head is SymbolGraphics3D:
form_expr = Expression(SymbolStandardForm, expr)
result = form_expr.format(obj, "System`StandardForm")
result = form_expr.format(obj, SymbolStandardForm)
return eval_boxes(result, result.boxes_to_js, obj)
elif expr_head is SymbolGraphics:
form_expr = Expression(SymbolStandardForm, expr)
result = form_expr.format(obj, "System`StandardForm")
result = form_expr.format(obj, SymbolStandardForm)
return eval_boxes(result, result.boxes_to_svg, obj)
else:
result = Expression(SymbolStandardForm, expr).format(
obj, "System`MathMLForm"
)
result = Expression(SymbolStandardForm, expr).format(obj, SymbolMathMLForm)
else:
raise ValueError

Expand Down
Loading