16
$\begingroup$

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.

$\endgroup$
12
  • 2
    $\begingroup$ I suggest you report this to WRI tech support. Maybe WRI broke HoldForm when they added the new Inactivate. $\endgroup$
    – m_goldberg
    Jul 22, 2014 at 0:19
  • 2
    $\begingroup$ 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. $\endgroup$
    – m_goldberg
    Jul 22, 2014 at 0:30
  • 2
    $\begingroup$ Mark I also see your first example failing in V9 as well as V10. $\endgroup$ Jul 22, 2014 at 0:51
  • 2
    $\begingroup$ Mark I meant that the HoldForm[InputForm[ℰ]] renders the same gibberrish for me in V9 as V10 $\endgroup$ Jul 22, 2014 at 1:33
  • 2
    $\begingroup$ In V10 on Windows 8.1 HoldForm[InputForm[ℰ]] works as expected. I don't get the gibberish. $\endgroup$
    – RunnyKine
    Jul 22, 2014 at 2:01

4 Answers 4

12
$\begingroup$

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
$\endgroup$
1
  • $\begingroup$ Great analysis and solution for the main issue - it also works for FrameLabel where the same issue appeared. $\endgroup$
    – Jens
    Jul 22, 2014 at 15:51
12
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ That's a valuable observation, thanks! $\endgroup$
    – Jens
    Jul 22, 2014 at 1:24
  • $\begingroup$ 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. $\endgroup$
    – Jens
    Jul 22, 2014 at 1:44
8
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$
    – Nasser
    Jul 22, 2014 at 0:19
  • $\begingroup$ 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. $\endgroup$
    – Jens
    Jul 22, 2014 at 0:21
  • $\begingroup$ @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. $\endgroup$ Jul 22, 2014 at 0:39
  • $\begingroup$ 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. $\endgroup$
    – Jens
    Jul 22, 2014 at 1:41
1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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