Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Bug introduced in 10.0.0 and fixed in 10.0.1


In Mathematica version 10, HoldForm no longer produces the same results as in version 8 (edit: I only have versions 10 and 8 installed, so can't compare to version 9 directly). Here are some examples (on Mac OS X):

Formatting of \[ScriptCapitalE]

This symbol is output correctly:

InputForm[ℰ]

But when wrapped as follows, I get gibberish:

HoldForm[InputForm[ℰ]]

â °

Arguments in HoldFormaren't held

Why would I want to use InputForm inside HoldForm in the first place? Here is one example, using the constant E. I would like it to be displayed as E:

HoldForm[InputForm[E]]

E

On the other hand, the constant is formatted differently if I leave out InputForm:

HoldForm[E]

𝕖

So why not use InputForm without HoldForm? Because then I can't write assignments like this:

HoldForm[InputForm[E = 1]]

E = 1

Here, I get no error because of HoldForm. So far, so good. But now things become inconsistent again if I put the same construct into a Plot:

Plot[x^2, {x, -2, 2}, AxesLabel -> {x, HoldForm[InputForm[E = 1]]}]

plot error

This used to work in version 8, but now it throws an error. The resulting plot is still correct, but the messages seem to indicate that HoldForm was ignored at some stage.

Indeed, I then proceeded to do a more basic test:

Clear[x];
Plot[Sin[x], {x, 0, 1}, AxesLabel -> {"x", HoldForm[x = 3]}];
x

3

Yes, that's right. HoldForm was completely ignored.

What can be done to fix this?

Edit

I tried to report the issue, but am currently receiving web form errors at the Wolfram site, so will have to try again later.

share|improve this question
2  
I suggest you report this to WRI tech support. Maybe WRI broke HoldForm when they added the new Inactivate. –  m_goldberg Jul 22 at 0:19
2  
Yes, and it's a nasty one. There is probably a lot of existing code broken by this behavior. And it's worse than even you think. Try substituting Hold[x = 3] for HoldForm[x = 3]. Global x still set to 3 after evaluation. –  m_goldberg Jul 22 at 0:30
2  
Mark I also see your first example failing in V9 as well as V10. –  Mike Honeychurch Jul 22 at 0:51
2  
Mark I meant that the HoldForm[InputForm[ℰ]] renders the same gibberrish for me in V9 as V10 –  Mike Honeychurch Jul 22 at 1:33
2  
In V10 on Windows 8.1 HoldForm[InputForm[ℰ]] works as expected. I don't get the gibberish. –  RunnyKine Jul 22 at 2:01

4 Answers 4

up vote 12 down vote accepted

Regarding the plot issue, I tried using HoldForm[x = Stack[_]] as an axis label to capture the stack at the moment of evaluation inside HoldForm. This revealed a problem in a helper function for dealing with units. The function Visualization`Utilities`OptionsDump`unitFormStringQ is applied to the axis labels (in a pattern test). The definition is this:

unitFormStringQ[s_] := Or @@ (MatchQ[#1, $unitFormString]&) /@ {Sequence @@ s}

The problem is clearly coming from {Sequence @@ s} which removes the HoldForm head.

A simple workaround is thus to define:

Visualization`Utilities`OptionsDump`unitFormStringQ[HoldForm[s_]] = False
share|improve this answer
    
Great analysis and solution for the main issue - it also works for FrameLabel where the same issue appeared. –  Jens Jul 22 at 15:51

I'm not sure what's going on with HoldForm[InputForm[ℰ]], but I think I know what's going on with Plot.

It appears at some point ReleaseHold is called because wrapping HoldForm twice fixes your problem.

Plot[x^2, {x, -2, 2}, AxesLabel -> {x, HoldForm[HoldForm[InputForm[E = 1]]]}]

enter image description here

share|improve this answer
    
That's a valuable observation, thanks! –  Jens Jul 22 at 1:24
    
What you observed also holds for Hold in the same context, so you must have hit the nail on the head. I think this cannot have been done intentionally - it makes no sense. –  Jens Jul 22 at 1:44

I can't comment on exactly why HoldForm has changed but I believe your examples fall under the purview of the new Active/Inactive functionality. For example:

Clear[x];
Plot[Sin[x], {x, 0, 1}, AxesLabel -> {Inactivate[x = 3],
  Inactive[Set][InputForm[E], 3]}]
x

enter image description here

Note, however that Inactivate can't be used with InputForm, since you want InputForm to be applied.

The `[ScriptCapitalE] business has everything to do with your default character encoding. Here are some results on my Mac:

enter image description here

I get the same results in both V9 and V10. If your results are different, you might check the contents of $CharacterEncoding. A list of all possible encodings is contained in $CharacterEncodings.

share|improve this answer
    
comparing the difference in ??Plot between V9 and V10, I noticed only difference is PlotTheme:> was added to V10. I do not know if this has anything to do with this change of behavior or not. This change might break existing code which used HoldForm in labels. –  Nasser Jul 22 at 0:19
    
Thanks, that's definitely a workaround in some cases. But unfortunately it doesn't solve the issue with my first Plot example, where I used the (admittedly contrived) label HoldForm[InputForm[E = 1]] to get E instead of the double-struck letter. –  Jens Jul 22 at 0:21
    
@Jens Does the edit help? I guess that you've got to selectively apply Inactive to Set but not to InputForm. So Inactivate is a bit too coarse. –  Mark McClure Jul 22 at 0:39
    
I suspected that one could find a working character encoding, but of course I would like to keep the default encoding. Anyway, thanks for that find, too! In terms of using Inactive[Set], I would then probably not bother and rewrite everything with FormBoxes. But the fact that Hold has the same issue as HoldForm in AxesLabel really worries me. –  Jens Jul 22 at 1:41

Considering work-arounds, Style and Inactivate seem to work well together.

Plot[x , {x, 0, 1}, 
 AxesLabel -> 
   {Style["M", Italic], 
    Style[Inactivate[InputForm[E] = M c^2, (Set | Times)], "TraditionalForm"]}]

plot

Inactivating Times keeps M c^2 from being rewritten to c^2 M.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.