# How do I turn off StandardForm formatting for Piecewise, KroneckerDelta and ConditionalExpression?

I find the StandardForm formatting for Piecewise, KroneckerDelta, and ConditionalExpression to be very annoying.

How do I turn off the formatting for these objects, without changing their TraditionalForm formatting?

• In what form do you want them displayed? InputForm? TraditionalForm? Custom form? – Bob Hanlon Sep 14 at 16:49
• @Bob For example, I am looking for KroneckerDelta[a,b] to format as is without using δ. – QuantumDot Oct 6 at 21:49

When you define a piecewise function, you may wrap InputForm around the definition to force the output to be in input form. E.g. f1 will print in standard form and f2 in input form:

f1[x_] :=
Piecewise[{{1, 0 < x <= 1}, {2, 1 < x <= 2}, {3, 2 < x <= 3}}]
f2[x_] :=
InputForm[
Piecewise[{{1, 0 < x <= 1}, {2, 1 < x <= 2}, {3, 2 < x <= 3}}]]
f1[t]
f2[t]

• If you include InputForm as part of the definition you will have some problems. Look at the result for f2'[t] you end up with an InputForm' factor. As a general rule, wrappers should not be included in definitions. – Bob Hanlon Sep 14 at 17:39
• Well, that's true. But do you have a better idea? – Daniel Huber Sep 15 at 9:53
• If the OP wants all output in a specified form, use $Post. It is more involved if only these functions are to have their StandardForm changed. – Bob Hanlon Sep 15 at 13:56 Following up on Bob Hanlon's comment mentioning $Post I found $PrePrint and its documentation and came up with the following solution: PrePrintFormats=<| KroneckerDelta->FullForm, Piecewise->FullForm, ConditionalExpression->FullForm |>;$PrePrint=If[MemberQ[Keys[PrePrintFormats],Head[#]],PrePrintFormats[Head[#]][#],#]&;


This outputs KroneckerDelta, Piecewise and ConditionalExpression using their respective FullForm. This changes only the OutputForm of attached to those symbols without affecting other forms like TraditionalForm or StandartForm.

I also tried a more direct approach by unprotecting the Symbols and trying to add UpValues on Format[...,OutputForm] but this did not work. I am not sure if this modification to $PrePrint has any nasty side-effects but I think the variable is meant for stuff like this so it might be fine. EDIT: Using InputForm for the output formatting in cells with multiple outputs causes some outputs not to be printed (no real idea why). FullForm seems to work better. But further testing is required. After playing around, I figured the easiest way is to simply define the FormatValues of these symbols manually: Unprotect[Piecewise, KroneckerDelta, ConditionalExpression]; FormatValues[Piecewise] = FormatValues[Piecewise] /. Verbatim[BoxFormfmt_] | BoxFormfmt :> TraditionalForm; FormatValues[ KroneckerDelta] = {HoldPattern[ MakeBoxes[KroneckerDelta[BoxForma$__], TraditionalForm] /;
BoxFormsufficientVersionQ[6.1]] :>
TemplateBox[{RowBox[
Riffle[Function[BoxFormx\$,
MakeBoxes[BoxFormx$$, TraditionalForm], HoldAllComplete] /@ Unevaluated[{BoxForma$$}], ","]]}, "KroneckerDeltaSeq"],
HoldPattern[
SubscriptBox[BoxFormFuncIntBox["δ", KroneckerDelta],
If[Length[Unevaluated[{BoxFormn}]] == 1,
MakeBoxes[BoxFormn, TraditionalForm],
List @@ Function[{BoxFormx},
HoldComplete[BoxFormn]]]]]};

I have placed these lines of code in my init.m file, so they run when the kernel starts up. Now I don't have to deal with their fancy StandardForm typesetting again.
• This method isn't ideal, because it causes Mathematica to generate error messages when it tries to display unrelated things, like SeriesData` etc for the first time. I am still looking for a canonical answer. – QuantumDot Oct 5 at 6:57