Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
26a52b3
more tweaks in InputForm
mmatera Jan 19, 2026
e67e06f
improve OptionValues InputForm. Adding documentation
mmatera Jan 19, 2026
f843756
improve Definition
mmatera Jan 19, 2026
14ddd30
Fix parenthesized condition in inputform.py
mmatera Jan 19, 2026
d7cdc45
Use new implementation of OutputForm
mmatera Jan 19, 2026
a5a2f09
more explicit logic for parenthesize
mmatera Jan 19, 2026
13c71b9
more explicit parenthesize
mmatera Jan 19, 2026
0f84406
merge
mmatera Jan 19, 2026
dff8acd
group in
mmatera Jan 19, 2026
461f552
group in
mmatera Jan 19, 2026
8e6db2f
Merge branch 'more_on_inputform' into rebase_1d_OutputForm
mmatera Jan 19, 2026
54be619
improve associativity
mmatera Jan 19, 2026
e670635
merge
mmatera Jan 19, 2026
34d5c01
Merge remote-tracking branch 'origin/rebase_1d_OutputForm' into rebas…
mmatera Jan 19, 2026
616c143
Update mathics/format/form/util.py
mmatera Jan 19, 2026
fd095d9
black
mmatera Jan 19, 2026
d9b7184
Merge branch 'more_on_inputform' into rebase_1d_OutputForm
mmatera Jan 19, 2026
f6395c8
Apply suggestions from code review
mmatera Jan 19, 2026
018b5e2
Merge branch 'more_on_inputform' into rebase_1d_OutputForm
mmatera Jan 19, 2026
3a74c9e
fix alternatives
mmatera Jan 19, 2026
dd5ad9e
Merge remote-tracking branch 'origin/master' into rebase_1d_OutputForm
mmatera Jan 20, 2026
bc8826b
move MakeBoxes rules to their right place
mmatera Jan 20, 2026
b591419
fix Optional
mmatera Jan 20, 2026
e597a04
handle `Optional` in OutputForm. Fix PrecedenceForm.
mmatera Jan 20, 2026
e24eac4
Merge branch 'rebase_1d_OutputForm' into move_makeboxes_rules_to_thei…
mmatera Jan 20, 2026
de96e38
add more tests for format_test.yaml
mmatera Jan 20, 2026
45c4445
Merge remote-tracking branch 'origin/move_makeboxes_rules_to_their_sy…
mmatera Jan 20, 2026
95b08a2
merge
mmatera Jan 20, 2026
cc4925d
Merge remote-tracking branch 'origin/master' into move_makeboxes_rule…
mmatera Jan 20, 2026
a718404
makeboxes_overhault
mmatera Jan 21, 2026
a733349
add FormBox
mmatera Jan 21, 2026
2eb1105
Merge branch 'formbox' into makeboxes_overhault
mmatera Jan 21, 2026
a97fa9b
removing trailing code
mmatera Jan 21, 2026
76fac71
interpretationbox tweaks
mmatera Jan 21, 2026
51bb3c9
missing import. Input and FullForm escape quotes in strings
mmatera Jan 21, 2026
02e7c12
Update layout.py
mmatera Jan 23, 2026
eac3119
Implement Format MakeBoxes and Format//OutputFOrm
mmatera Jan 24, 2026
ba922a1
Makeboxes overhault (#1642)
mmatera Jan 24, 2026
7c3b14f
Merge branch 'master' into move_makeboxes_rules_to_their_symbols
mmatera Jan 25, 2026
35f9dc4
Merge branch 'master' into formbox
mmatera Jan 25, 2026
5e9213f
format optional
mmatera Jan 25, 2026
55d5c1e
Merge branch 'Format_Optional' into move_makeboxes_rules_to_their_sym…
mmatera Jan 25, 2026
322be25
Merge remote-tracking branch 'origin/master' into makeboxes_overhault
mmatera Jan 25, 2026
d85b179
new_formbox
mmatera Jan 25, 2026
1004bc9
add FormBox
mmatera Jan 25, 2026
99bb5b6
Merge branch 'formbox' into makeboxes_overhault
mmatera Jan 25, 2026
ab21698
Merge branch 'move_makeboxes_rules_to_their_symbols' into new_formbox
mmatera Jan 25, 2026
a42e744
Merge branch 'master' into new_formbox
mmatera Jan 25, 2026
2e7083b
Merge branch 'new_formbox' into makeboxes_overhault
mmatera Jan 25, 2026
9e8fc07
merge
mmatera Jan 25, 2026
1c6c63c
Merge remote-tracking branch 'origin/master' into makeboxes_overhault
mmatera Jan 25, 2026
e011bda
boxed-> boxes
mmatera Jan 25, 2026
01d23a1
Merge remote-tracking branch 'origin/master' into makeboxes_overhault
mmatera Jan 25, 2026
38f5a18
Merge remote-tracking branch 'origin/master' into Format_Format
mmatera Jan 25, 2026
feea6db
Merge branch 'makeboxes_overhault2' into Format_Format
mmatera Jan 25, 2026
f3140de
Format format update docs (#1657)
rocky Jan 25, 2026
54eabf9
Merge remote-tracking branch 'origin/master' into Format_Format
mmatera Jan 26, 2026
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
2 changes: 2 additions & 0 deletions SYMBOLS_MANIFEST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ImportExport`RegisterExport
ImportExport`RegisterImport
Internal`RealValuedNumberQ
Internal`RealValuedNumericQ
JSON`Import`JSONImport
System`$Aborted
System`$Assumptions
System`$BaseDirectory
Expand Down Expand Up @@ -486,6 +487,7 @@ System`FoldList
System`FontColor
System`For
System`Format
System`FormatType
System`FormatValues
System`FractionBox
System`FractionalPart
Expand Down
13 changes: 11 additions & 2 deletions mathics/builtin/atomic/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,21 @@ class FormatValues(Builtin):
<url>:WMA link:https://reference.wolfram.com/language/tutorial/PatternsAndTransformationRules.html#6025</url>
<dl>
<dt>'FormatValues'[$symbol$]
<dd>gives the list of formatvalues associated with $symbol$.
<dd>gives the list of format rules associated with $symbol$.
</dl>

First, use 'Format' to set a formatting rule for a form:

>> Format[F[x_], OutputForm]:= Subscript[x, F]

Now, to see the rules, we can use 'FormatValues':

>> FormatValues[F]
= {HoldPattern[Format[Subscript[x_, F], OutputForm]] :> Subscript[x, F]}
= {HoldPattern[Subscript[x_, F]] :> Subscript[x, F]}

The replacment pattern on the right in the delayed rule is formatted according to the top-level form. To see the rule input, we can use 'InputForm':
>> FormatValues[F] //InputForm
= {HoldPattern[Format[F[x_], OutputForm]] :> Subscript[x, F]}
"""

summary_text = (
Expand Down
54 changes: 51 additions & 3 deletions mathics/builtin/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ class Format(Builtin):

<dl>
<dt>'Format'[$expr$]
<dd>holds values specifying how $expr$ should be printed.
<dd>used on the left-hand side of an assignment to specify how $expr$ should be printed.
</dl>

Assign values to 'Format' to control how particular expressions
should be formatted when printed to the user.
First, we set up a 'Format' definition for 'f' to display its arguments as if it were equivalent to an infix operator "~":

>> Format[f[x___]] := Infix[{x}, "~"]

Now, to see this format in use:

>> f[1, 2, 3]
= 1 ~ 2 ~ 3
>> f[1]
Expand All @@ -68,12 +71,57 @@ class Format(Builtin):
Formats must be attached to the head of an expression:
>> f /: Format[g[f]] = "my f";
: Tag f not found or too deep for an assigned rule.

Format can be used to specify the request format:
>> Format[Integrate[F[x], x], TeXForm]
= \\int F\\left(x\\right) \\, dx

Format evaluates its first element before applying the format:
>> Format[Integrate[Cos[x], x], TeXForm]
= ...
but the result keeps the structure:
>> % //FullForm
= Format[Sin[x], TeXForm]

If the second parameter is omitted, 'Format' is ignored:
>> Format[F[x]]
= F[x]

If the second argument is not one of '$PrintForms', a message \
is shown, and the argument is discarded:
>> Format[F[x], NoFormat]
: Value of option FormatType -> NoFormat is not valid.
= F[x]

Mathics3 'Format' output can differ slightly from WMA in what we hope \
is a more useful way.

Use 'InputForm' if you want to get a 'Format' definition that can be used as \
Mathics3 input:

>> Format[{a->Integrate[F[x], x]}, StandardForm] //InputForm
= Format[{a -> Integrate[F[x], x]}, StandardForm]

In WMA, you might not get something that can be used as input.

Similarly, use 'Fullform' to get a valid FullForm equivalent expression:

>> Format[{a->Integrate[F[x], x]}, StandardForm] //FullForm
= Format[{Rule[a, Integrate[F[x], x]]}, StandardForm]
"""

messages = {"fttp": "Format type `1` is not a symbol."}
summary_text = (
"settable low-level translator from various forms to evaluatable expressions"
)
rules = {"MakeBoxes[Format[expr_], fmt_]": "MakeBoxes[expr, fmt]"}

def eval_Makeboxes(self, expr, form, evaluation):
"""MakeBoxes[Format[expr_, form_], _]"""
if form not in evaluation.definitions.printforms:
evaluation.message("FormatType", "ftype", form)
return format_element(expr, evaluation)
return format_element(expr, evaluation, form)


class Grid(Builtin):
Expand Down
14 changes: 14 additions & 0 deletions mathics/builtin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ def matched():
return ListExpression(*list(matched()))


class FormatType(Predefined):
"""
<url>:WMA link:https://reference.wolfram.com/language/ref/FormatType.html</url>
<dl>
<dt>'FormatType'
<dd>is an option for output streams, graphics and functions like 'Text' \
that specifies the default format.
</dl>
"""

messages = {"ftype": "Value of option FormatType -> `` is not valid."}
summary_text = "specify the request format"


class None_(Predefined):
"""
<url>:WMA link:https://reference.wolfram.com/language/ref/None.html</url>
Expand Down
15 changes: 15 additions & 0 deletions mathics/format/form/outputform.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,21 @@ def render_output_form(expr: BaseElement, evaluation: Evaluation, **kwargs):
return _default_render_output_form(format_expr, evaluation, **kwargs)


@register_outputform("System`Format")
def format_format(expr, evaluation, **kwargs):
"""Format[expr_, form___]"""
elements = expr.elements
if len(elements) == 1:
return render_output_form(elements[0], evaluation, **kwargs)
if len(elements) == 2:
expr, form = elements
if form not in evaluation.definitions.printforms:
evaluation.message("FormatType", "ftype", form)
return render_output_form(expr, evaluation, **kwargs)
return other_forms(Expression(form, expr), evaluation, **kwargs)
raise _WrongFormattedExpression


@register_outputform("System`Graphics")
def graphics(expr: Expression, evaluation: Evaluation, **kwargs) -> str:
if not isinstance(expr.head, Symbol):
Expand Down
Loading