2011-04-17 55 views
4

考慮以下幾點:問題的消息造型

printMessage[cellexpr_]:[email protected][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

@Alexey請考慮在發佈代碼的輸入形式,使得它可以被複製播放。日Thnx。 – Sasha 2011-04-17 01:41:51

+0

讓其他人不必重新輸入boxdata,這裏是''BoxData [RowBox [{RowBox [{ 「仙」, 「::」, 「\」 argx \ 「」}], 「:」, 「\」\\!\\(Sin \\)用\\!\\(2 \\)參數調用; 1個參數\ 預期。\ 「」};]'' – Simon 2011-04-17 01:45:53

+0

@Sasha打我吧! – Simon 2011-04-17 01:46:26

回答

1

看來,一個辦法解決這個bug是移動"Message"到另一個地方,在Cell選項:

printMessage[cellexpr_]:[email protected][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]] 

EDIT 2

上述解決辦法只有第一個新的會話過程中起作用。保存並重新打開Notebook後,問題再次出現。

唯一的解決辦法的工作一這一刻是不使用的樣式,但指定明確的選項設置。