I have a function that returns equalities, which I want to print, for example, x==y, or 2x+5==10. These usually have no meaning for mathematica, it cannot simplify it furhter.
However, sometimes the both sides are equal, but I want to be able to print the equality in unevaluated form: that is, I want Mathematica to print x==x, and not True.
A very simple example:
Print[printableEqual[x,y]]
should print x==y, while
Print[printableEqual[x,x]]
should print x==x
Edit: The reason is that I have a relation among graphs. I would like to return things like
G1 == t*G2 + s*G3
where t,s are integers, and Gi are Graphics objects in Mathematica. Just returning this works great, (Since Mathematica cannot simplify such things) EXCEPT G1 == G1 which will be True.
The trouble is that using Defer, or HoldForm gives
Private`lhs$714 == Private`rhs$714
as output, that is, the private variables in my package is not evaluated as my Graphics.
Usually one uses
HoldForm
for this sort of thing.HoldForm
is a head that works likeHold
, in that it doesn't evaluate its contents, but it's not displayed when it's printed as output, like so:As with
Hold
, you can interpolate things into aHoldForm
usingWith
or function argument substitution, like so:However, this will mean that the arguments are evaluated before substitution, like so:
If you don't want this to happen, you can use
SetAttributes
andHoldAll
:Note that
HoldForm
is always there, it's just not displayed in output form:If you want to evaluate things, use
ReleaseHold
:Another trick is to just use
Unevaluated
:Another thing you can do is to is use
Grid[]
to align all of your equalities - the added advantage is that since you don't actually create expressions withEqual[]
, you don't have to prevent their evaluation.On a similar vein, you could manually typeset using
or more generally
By the way, the output from the
printableEqual[]
defined above can be converted back to a real Expression usingToExpression[ToString[#]]&
or something likeYou can use
Defer
to do this: