Wolfram mathematica 消息中的数字格式很好

Wolfram mathematica 消息中的数字格式很好,wolfram-mathematica,Wolfram Mathematica,当使用样式框打印字符串时,默认情况下,我们会在字符串中获得格式良好的数字: StyleBox["some text 1000000"] // DisplayForm 我的意思是,这些数字似乎会有额外的小空间:“1 000 000” 但是在消息中s显示的所有数字都没有格式: f::NoMoreMemory = "There are less than `1` bytes of free physical memory (`2` bytes \ is free). $Failed is re

当使用
样式框打印字符串时,默认情况下,我们会在字符串中获得格式良好的数字:

StyleBox["some text 1000000"] // DisplayForm
我的意思是,这些数字似乎会有额外的小空间:“1 000 000”

但是在
消息中
s显示的所有数字都没有格式:

f::NoMoreMemory = 
  "There are less than `1` bytes of free physical memory (`2` bytes \
is free). $Failed is returned.";
Message[f::NoMoreMemory, 1000000, 98000000]

有没有办法将
消息中的数字格式化?

我想您需要
$MessagePrePrint

$MessagePrePrint = 
   NumberForm[#, DigitBlock -> 3, NumberSeparator -> " "] &;
或者,结合Sjoerd的建议:

With[
  {opts =
    AbsoluteOptions[EvaluationNotebook[],
     {DigitBlock, NumberSeparator}]},
  $MessagePrePrint = NumberForm[#, Sequence @@ opts] &];
采用Brett Champion的方法,我相信这可以按照您的要求进行复制和粘贴:

$MessagePrePrint = StyleForm[#, AutoNumberFormatting -> True] &;

我将使用Style应用AutoNumberFormatting选项:

您可以使用它来定位特定的消息:

f::NoMoreMemory = 
 "There are less than `1` bytes of free physical memory (`2` bytes is free). $Failed is returned.";

Message[f::NoMoreMemory, 
 Style[1000000, AutoNumberFormatting -> True], 
 Style[98000000, AutoNumberFormatting -> True]]
$MessagePrePrint = Style[#, AutoNumberFormatting -> True] &;

Message[f::NoMoreMemory, 1000000, 98000000]
或者,您可以将其与$MessagePrePrint一起使用,以将其应用于所有邮件:

f::NoMoreMemory = 
 "There are less than `1` bytes of free physical memory (`2` bytes is free). $Failed is returned.";

Message[f::NoMoreMemory, 
 Style[1000000, AutoNumberFormatting -> True], 
 Style[98000000, AutoNumberFormatting -> True]]
$MessagePrePrint = Style[#, AutoNumberFormatting -> True] &;

Message[f::NoMoreMemory, 1000000, 98000000]

最好在代码中使用
NumberSeparator->“\[ThinSpace]”
。但是,我不希望在数字中使用任何附加字符。通过
StyleBox[“1000000”]//DisplayForm
我们可以获得外观美观的可复制数字。我想在
消息
s中获取此信息。如果您从评估笔记本中获取格式选项,将非常有用,以使内容更加统一。因此,您可以使用
绝对选项[EvaluationNotebook[],{DigitBlock,DigitBlockMinimum,NumberPoint,NumberParator,NumberMultiplier}]
@Sjoerd C.de Vries我应该如何准确地使用问题中的示例代码?我的意思是
消息[f::nomoremory,1000000,98000000]
。如果答案有效,请将其单独张贴。@Alexey人们提出的问题和用法很有趣。我从不尝试从邮件中复制和粘贴。我得看看是否能找到解决办法。将这些数字存储在其他地方以供参考,而不是复制和粘贴会有任何用处吗?@Alexey Popkov Wizard先生已经这样做了。关键是使用Sequence来摆脱AbsoluteOptions返回的列表结构。+1您的方法,但使用
StyleForm
代替
Style
,实现了Alexey的要求。@Brett Champion有没有办法通过在我的系统上修改
Message
Style
?@Mr.Wizard来做到这一点(适用于Windows的Mathematica 7.01)
Style
StyleForm
在这种情况下也一样。你使用的是什么版本的Mathematica?@Alexey这里的设置相同。尝试复制并粘贴
1000000
,然后将
+5
放在旁边,并进行计算。对于我来说,使用
Style
我得到
5+1000000
,但使用
StyleForm
我得到
1000005
@Alexey我认为应该有一种通过样式表实现的方法,但我还没有找到。