TraditionalForm¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
TraditionalForm[expr]
displays expr in textbook notation: sin(x), log(x), |x|, e^x, x = 1.
Notes
TraditionalForm is a display wrapper: the notebook typesets its argument in that notation (in the math font); as text it prints as expr itself. TraditionalForm can be nested to switch notation for one subexpression.Examples (10)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (3)¶
The wrapper survives arithmetic
Not a ToString form
Applications (7)¶
The terminal prints the expression; the notebook typesets it as ln(x) + sin²(x)
The argument is evaluated before display
The wrapper stays in the expression and in any later arithmetic
InputForm keeps it
Nested, it changes only that part (cos(x) in the notebook)
Not supported as a ToString form
Only Protected
Implementation notes¶
Semantics. TraditionalForm shares builtin_display_form with StandardForm. The builtin always returns NULL, so the argument is evaluated and the wrapper is kept (attribute Protected). Because the head survives, it stays inside later arithmetic: TraditionalForm[x^2] + 1 is Plus[1, TraditionalForm[x^2]].
Rendering. The text printer (print_standard) skips the wrapper and prints its argument, except under InputForm, where it is kept. The typeset renderer src/print_latex.c (expr_to_latex_form) clears the LBuf.std flag for the wrapped subtree. That gives textbook notation: \sin(x), \ln(x), |x|, e^{x}, x = 1, a \land b, n-th roots as surds, Greek-named symbols as letters, and C[1] as c₁. Nesting switches notation for that subtree only, and a StandardForm[...] inside switches it back. In the notebook protocol (src/repl.c) a result whose outermost head is TraditionalForm is sent with slatex alone, typeset in that notation. The notebook's Convert To menu and its View › Output Format setting choose between the forms on the client side, without re-evaluating.
Limits. The terminal REPL has no typeset output, so TraditionalForm prints like the bare expression there. TeXForm uses a separate renderer (print_tex in src/print.c) and does not read the notation flag. ToString[expr, TraditionalForm] is not supported and stays unevaluated. There is no box layer, so TraditionalForm output cannot be parsed back.
Attributes: Protected.
References¶
See also: StandardForm, InputForm
- Source:
src/print.c - Specification:
docs/spec/builtins/expression-information.md - Tests:
tests/test_print.c
Notes & additional examples¶
Notes¶
- A display wrapper for textbook notation:
sin(x),ln(x),|x|,e^x,x = 1,a ∧ b, surds for n-th roots, Greek letters for Greek-named symbols,c₁forC[1]. In the notebook, an outermostTraditionalForm[...]sets how the whole result is shown, and a nested one sets it for that part. - The terminal REPL has no typeset output, so it prints the wrapped expression as plain text. Only
InputFormandFullFormshow the head. - The head is kept, so wrap a result only for display.
TraditionalForm[x^2] + 1isPlus[1, TraditionalForm[x^2]]. - There is no box layer: TraditionalForm output cannot be parsed back, and
ToString[expr, TraditionalForm]stays unevaluated. UseTeXFormfor LaTeX text. - Attributes
{Protected}. - See also:
StandardForm,TeXForm,InputForm,FullForm.