请考虑以下事项:
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. >>
可以看到自动生成的Message
继承了之前打印的Cell
的样式。为什么会这样?以及如何防止这种情况?
答案 0 :(得分:1)
似乎这个错误的一个解决方法是将"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
的结果外观发生了变化:
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
上述解决方法仅适用于第一次新会话。保存并重新打开笔记本电脑后,问题再次出现。
此刻唯一可行的解决方法是不使用样式,而是指定明确的选项集。