4

Consider the following:

printMessage[cellexpr_]:=CellPrint@Cell[cellexpr,"Message",
                         CellLabel->"(slave Kernel)",ShowCellLabel->True,
                         CellFrameMargins->0,Background->LightBrown,
                         CellLabelAutoDelete->False];
printMessage[BoxData[RowBox[{RowBox[{"Sin", "::", "\"argx\""}], ": ",
  "\"\\!\\(Sin\\) called with \\!\\(2\\) arguments; 1 argument is expected.\""}],
  StandardForm]]
Sin[1,1];

-->

(slave Kernel) Sin::argx: Sin called with 2 arguments; 1 argument is expected.
During evaluation of In[1]:= Sin::argx: Sin called with 2 arguments;
1 argument is expected. >>

enter image description here

One can see that the auto-generated Message inherits the style of the previous printed Cell. Why this happens? And how to prevent this?

Alexey Popkov
  • 9,355
  • 4
  • 42
  • 93
  • 1
    @Alexey Please consider posting the input form of the code so that it can be copied for playing. Thnx. – Sasha Apr 17 '11 at 01:41
  • So that other people don't have to retype the boxdata, here it is ``BoxData[RowBox[{RowBox[{"Sin", "::", "\"argx\""}], ": ", "\"\\!\\(Sin\\) called with \\!\\(2\\) arguments; 1 argument is \ expected.\""}]];`` – Simon Apr 17 '11 at 01:45
  • and ``printMessage[cellexpr_] :> CellPrint@Cell[cellexpr, "Message", CellLabel -> "(slave Kernel)", ShowCellLabel -> True, CellFrameLabelMargins -> 0, Background -> LightBrown, CellLabelAutoDelete -> False]`` – Simon Apr 17 '11 at 01:47
  • 2
    I think it should be noted that it only happens when `printMessage[BoxData[...]]` and `Sin[1,1]` are within the same cell separated by new lines. If there are entered on new cells, the reported effect can not be observed. – Sasha Apr 17 '11 at 01:54
  • 2
    It's also a little inconsistent - the styles sometimes take a while to propagate. I've been play a bit, and sometimes I think I found a solution, but when it's run again it reverts to the behaviour that Alexey doesn't want... It also happens with `FontSize` and other options. – Simon Apr 17 '11 at 02:19
  • @Simon And it is not related to Cell Options – Dr. belisarius Apr 17 '11 at 02:21
  • Sorry for the absence of the original code. It was removed by [rcollyer](http://stackoverflow.com/users/198315/rcollyer) "in favor of image". I have rolled back this edit. – Alexey Popkov Apr 17 '11 at 02:22
  • Does everyone else think that this must be a bug and not a feature? – Simon Apr 17 '11 at 02:23
  • @Simon I think the format propagation is related to the "During evaluation of In..." msg. – Dr. belisarius Apr 17 '11 at 02:29
  • @belisarius "During evaluation of In..." is just the result of inherited `ShowCellLabel->True` option. You can see that other options are also inherited. – Alexey Popkov Apr 17 '11 at 02:32
  • @Alexey Yep. Overlooked that. Thanks – Dr. belisarius Apr 17 '11 at 02:37
  • @Simon What could be the purpose of such a "feature"? – Dr. belisarius Apr 17 '11 at 02:39
  • @Simon I have not seen anywhere in the Documentation any clue on such behavior. And I have carefully browsed all `Cell` options and have not found any option related to this behavior: `Information[#, LongForm -> False] & /@ Options[Cell][[All, 1]];`. I think this behavior is probably a bug. – Alexey Popkov Apr 17 '11 at 02:41
  • I just found that this problem persist not only for `"Message"` style but also for `"Print"` style and probably for any other style. The only workaround I have found is not to use named styles at all. – Alexey Popkov Apr 17 '11 at 03:12
  • @belisarius: No obvious purpose as a feature... that's why I suggested a bug... – Simon Apr 17 '11 at 06:04
  • @Alexey, my apologies, I had removed the code block because the picture was much more readable, even after formatting. I wasn't thinking about the need to actually copy the code ... – rcollyer Apr 18 '11 at 12:25

1 Answers1

1

It seems that one workaround for this bug is to move "Message" to another place in the Cell options:

printMessage[cellexpr_]:=CellPrint@Cell[cellexpr,CellLabel->"(slave Kernel)",
                         "Message", ShowCellLabel->True,
                         CellFrameMargins->0,Background->LightBrown,
                         CellLabelAutoDelete->False];
printMessage[BoxData[RowBox[{RowBox[{"Sin", "::", "\"argx\""}], ": ",
  "\"\\!\\(Sin\\) called with \\!\\(2\\) arguments; 1 argument is expected.\""}],
  StandardForm]]
Sin[1,1];

EDIT

But as the result appearance of the printed Cell is changed:

ScreenShot

print := printMessage[
  BoxData[RowBox[{RowBox[{"NIntegrate", "::", "\"slwcon\""}], ": ", 
     "\"Numerical integration converging too slowly; suspect one of \
the following: singularity, value of the integration being 0, \
oscillatory integrand, or insufficient WorkingPrecision. If your \
integrand is oscillatory try using the option Method->Oscillatory in \
NIntegrate.\""}], StandardForm]]

EDIT 2

The above workaround works only during the first fresh session. After saving and reopening of the Notebook the problem appears again.

The only working workaround a this moment is do not use Styles but to specify explicit set of options.

Alexey Popkov
  • 9,355
  • 4
  • 42
  • 93