Проблема со стилем сообщений - PullRequest
4 голосов
/ 17 апреля 2011

Рассмотрим следующее:

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

Видно, что автоматически сгенерированный Message наследует стиль предыдущего напечатанного Cell. Почему это происходит? И как это предотвратить?

1 Ответ

1 голос
/ 17 апреля 2011

Кажется, что один из обходных путей для этой ошибки - переместить "Message" в другое место в опциях Cell:

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];

РЕДАКТИРОВАТЬ

Нов результате внешний вид напечатанного Cell изменяется:

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]]

РЕДАКТИРОВАТЬ 2

Обходное решение работает тольково время первого свежего сеанса.После сохранения и повторного открытия Ноутбука проблема снова появляется.

Единственный работающий обходной путь в этот момент - не используйте Стили, а укажите явный набор параметров.

...