将内联格式添加到使用情况消息的便捷方法 [英] Convenient way to add inline formatting to usage Messages

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

问题描述

用法Messages具有嵌入式嵌入式格式.例如:

Usage Messages of built-in functions have embedded in-line formatting. For example:

In[1]:= ActionMenu::usage // FullForm

Out[1]//FullForm= 
"\!\(\*RowBox[{\"ActionMenu\", \"[\", RowBox[{StyleBox[\"name\", \"TI\
\"], \",\", RowBox[{\"{\", \
RowBox[{RowBox[{SubscriptBox[StyleBox[\"lbl\", \"TI\"], \
StyleBox[\"1\", \"TR\"]], \":>\", SubscriptBox[StyleBox[\"act\", \"TI\
\"], StyleBox[\"1\", \"TR\"]]}], \",\", \
RowBox[{SubscriptBox[StyleBox[\"lbl\", \"TI\"], StyleBox[\"2\", \
\"TR\"]], \":>\", SubscriptBox[StyleBox[\"act\", \"TI\"], \
StyleBox[\"2\", \"TR\"]]}], \",\", StyleBox[\"\[Ellipsis]\", \
\"TR\"]}], \"}\"}]}], \"]\"}]\) represents an action menu with label \
\!\(\*StyleBox[\"name\", \"TI\"]\), and with items labeled \
\!\(\*SubscriptBox[StyleBox[\"lbl\", \"TI\"], StyleBox[\"i\", \
\"TI\"]]\), that evaluates the expression \
\!\(\*SubscriptBox[StyleBox[\"act\", \"TI\"], StyleBox[\"i\", \
\"TI\"]]\) if the corresponding item is chosen."

可以看到这种内联格式基于Core.nb样式表的内联格式样式"部分中定义的样式集.但是我没有找到有关这些样式的任何文档,也没有找到对usage Message s添加格式的便捷算法的任何描述.

One can see that this in-line formatting is based on the set of styles defined in "Styles for Inline Formatting" section of the Core.nb stylesheet. But I have not found any documentation for these styles as well as any description of the convenient algorithm of adding formatting to usage Messages.

在Mathematica 中的用户定义的usage Message s中添加内联格式的便捷方法是什么? Core.nb样式表中定义的内联格式默认样式的使用规则是什么?我想仅使用 Mathematica 将行内格式化添加到我包中的usage Message中,而无需安装诸如Workbench等的其他组件.

What is the convenient way to add in-line formatting to user-defined usage Messages in Mathematica? What are the usage rules of default styles for in-line formatting defined in the Core.nb stylesheet? I would like to add in-line formatting to the usage Messages in my package just with Mathematica, without installing additional components like Workbench etc.

P.S.教程页"String中嵌入式嵌入式格式的语法. >框的字符串表示形式."官方新闻组中有关此语法的相关问题:" (有关线性语法的任何文档?? "在FrontEnd中显示此类字符串是由CellShowStringCharacters->False选项控制的.

P.S. The syntax of the embedded in-line formatting in Strings is partially documented on the tutorial page "String Representation of Boxes." Related question in the official newsgroup on this syntax: "(any documentation for) linear syntax?" Displaying of such strings in the FrontEnd is controlled by the option ShowStringCharacters->False of Cell.

推荐答案

处理字符串的问题之一是Mathematica中大多数使用字符串的操作都会自动将反斜杠(\)替换为转义的反斜杠().

One of the problems of handling strings like that is that most operations with strings in Mathematica automatically replace the backslash (\) with the escaped backslash (\\).

如果您尝试这样做:

您可能会认为您正在寻找的字符串(减去\!使其成为表达式),但实际上它是:"\\(x\\_\\(1, 2\\) \[Equal] \\(\\(-b\\) \[PlusMinus] \\@\\(b\\^2 -\\(4\\ a\\ c\\)\\)\\)\\/\\(2\\ a\\)\\)"

you may think you have the string you're looking for (minus the \! to make it an expression), but in fact it is: "\\(x\\_\\(1, 2\\) \[Equal] \\(\\(-b\\) \[PlusMinus] \\@\\(b\\^2 -\\(4\\ a\\ c\\)\\)\\)\\/\\(2\\ a\\)\\)"

我的解决方案远非优雅,但可行.

My solution is far from elegant, but it works.

  1. 从格式化的表达式生成框:
  2. 选择输出,然后转到菜单项Cell > Convert to > InputForm.结果:
  3. 您现在可以编辑字符串,在其前面加上\!并用引号引起来: "\!\(x \_ \(1, 2\) == \(\(-b\) \[PlusMinus] \@\(b \^2 - \(4\ a\ c\)\)\) \/ \(2\ a\)\)"
  1. Generate boxes from your formatted expression:
  2. Select the output, and go to menu item Cell > Convert to > InputForm. Result:
  3. You can now edit the string, putting \! in front of it and quotes around it: "\!\(x \_ \(1, 2\) == \(\(-b\) \[PlusMinus] \@\(b \^2 - \(4\ a\ c\)\)\) \/ \(2\ a\)\)"

如果您在外部编辑器中执行第3步,则不要使用引号,而只需在前面加上\!并将结果粘贴回MMA中即可直接将其转换为格式表达式

If you perform step 3 in an external editor, leave away the quotes and just have \! in front and paste back the result in MMA it is directly converted to the formatted expression

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

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