4

次の点を考慮してください。

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ます。なぜこれが起こるのですか?そして、これを防ぐ方法は?

4

1 に答える 1

1

このバグの回避策の 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

上記の回避策は、最初の新しいセッション中にのみ機能します。ノートブックを保存して再度開くと、問題が再び発生します。

現時点での唯一の回避策は、スタイルを使用せず、オプションの明示的なセットを指定することです。

于 2011-04-17T03:26:12.017 に答える