格式化使用情况消息 [英] Formatting usage messages

查看:87
本文介绍了格式化使用情况消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您查看(mathematicapath)/AddOns/LegacyPackages/DiscreteMath/Combinatorica.m Mathematica8 中的Combinatorica包,则会发现函数的定义.我想知道的是Mathematica如何知道如何格式化用法消息.某些信息告诉我,我没有查看正确的文件.无论如何,请尝试以下操作:

If you take a look at the Combinatorica package in Mathematica8 in (mathematicapath)/AddOns/LegacyPackages/DiscreteMath/Combinatorica.m you will find the definitions of functions. What I'm interested to know is how Mathematica knows how to format the usage messages. Something tells me that I'm not looking at the right file. In any case, lets try the following:

Cofactor::usage = "Cofactor[m, {i, j}] calculates the (i, j)th cofactor of matrix m."

此行是上述文件中的682行.现在,如果我们在mathematica笔记本中运行它并使用?Cofactor,我们将看到完全相同的消息.但是,如果我们得到该软件包,则消息将被格式化.这是屏幕截图:

This line is the 682 line in the file mentioned above. Now if we run it in a mathematica notebook and we use ?Cofactor we will see the exact same message. But if we get the package then the message is formatted. Here is a screenshot:

请注意函数中的m,i和j如何更改,并在消息中添加了双箭头.我认为箭头已添加到消息中,因为存在它的文档.有人可以解释这种行为吗?

Notice how the m, i and j inside the function changed and a double arrow was added to the message. I think the arrow was added to the message because there exists documentation for it. Can someone explain this behavior?

这是我的笔记本文件的屏幕截图,该文件自动保存为m文件.

This is a screenshot of my notebook file that autosaves to an m file.

如您所见,LM的斜体字为新罗马字.现在,我将加载程序包并查看用法.

As you can see, the L and M are in italic times new roman. Now I will load the package and see the usage.

到目前为止,一切都很好.现在,让我们看一下文档中心.我将寻找功能LineDistance.

So far so good. Now lets look at the Documentation center. I will look for the function LineDistance.

如您所见,它显示了一条奇怪的消息.在这种情况下,我们只想显示没有任何样式的消息.我仍然不知道Combinatorica包是如何做到这一点的. 我按照进行了索引,以便文档中心可以显示摘要.摘要本质上是用法显示.让我知道是否需要更具体.

As you can see, it shows a weird message. In this case we only want to display the message without any styles. I still can't figure out how the Combinatorica package does this. I followed this to make the index so that the doc center can display the summary. The summary is essentially the usage display. Let me know if I need to be more specific.

推荐答案

好的,这是解释.

在Combinatorica来源中进行挖掘可以发现这一点:

Digging in the Combinatorica source reveals this:

(* get formatted Combinatorica messages, except for special cases *)
If[FileType[ToFileName[{System`Private`$MessagesDir,$Language},"Usage.m"]]===File,
Select[FindList[ToFileName[{System`Private`$MessagesDir,$Language},"Usage.m"],"Combinatorica`"],
StringMatchQ[#,StartOfString~~"Combinatorica`*"]&&
!StringMatchQ[#,"Combinatorica`"~~("EdgeColor"|"Path"|"Thin"|"Thick"|"Star"|"RandomInteger")~~__]&]//ToExpression;
]

它正在从ToFileName[{System`Private`$MessagesDir,$Language},"Usage.m"](在我的计算机上为SystemFiles\Kernel\TextResources\English\Usage.m)加载消息.这就是为什么所有使用情况消息都在Combinatorica.m中有条件创建的原因(仅当它们尚不存在时).如果您查看Usage.m,您会发现它具有@ragfield提到的所有丑陋的东西.

It is loading messages from ToFileName[{System`Private`$MessagesDir,$Language},"Usage.m"], which on my machine is SystemFiles\Kernel\TextResources\English\Usage.m. This is why all usage messages are created conditionally in Combinatorica.m (only if they don't exist yet). If you look in Usage.m you'll see it has all the ugly boxes stuff that @ragfield mentioned.

我想格式化消息的最简单方法是在笔记本的前端对其进行编辑,然后创建一个自动保存程序包.这样,您可以使用所有前端的格式化工具,而无需处理盒子.

I guess the simplest way to have formatted messages is to edit them in the front end in a notebook, and create an auto-save package. This way you can use all the front end's formatting tools, and won't need to deal with boxes.

这篇关于格式化使用情况消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆