Mathematica 中的语法着色 [英] Syntax Coloring In Mathematica
问题描述
如何在
f[x_] = 2 x
或可变符号,例如
lotto = Table[2, {10}];
自动着色?
在 M8 的语法着色中,没有为此提供选项.
In Syntax coloring on M8 no option is offered for this.
只有没有赋值的局部变量或全局符号.
Only Local Variables or Global symbols that have no values assigned.
推荐答案
这不是您所要求的,但可能对您有用.
This is not exactly what you asked for, but it may be useful to you.
您可以使用以下方法按上下文突出显示符号:
You can highlight symbols by context, using this method:
SetOptions[$FrontEndSession,
AutoStyleOptions -> {"SymbolContextStyles" -> {"highlight`" -> Green}}
]
AppendTo[$ContextPath, "highlight`"];
现在,当你在上下文 highlight`
中创建一个符号时,它会自动变成绿色:
Now, when you create a symbol in the context highlight`
it will automatically be colored green:
highlight`lotto ;
并且由于 highlight`
被附加到 $ContextPath
之后,该符号可以简单地使用:
and since highlight`
was appended to $ContextPath
, after that the symbol can be used plainly:
lotto
如果您希望自动突出显示您创建的所有符号,请设置:
If you want all the symbols you create to automatically be highlighted, then set:
$Context = "highlight`"
之后,您创建的所有 新 符号都将属于上下文 highlight`
并接收颜色.
After that, all new symbols you create will belong to the context highlight`
and will receive the color.
新的意思是以前没有在会话中使用过的,或者已经被删除
d.
New means ones that have not been previously used in the session, or have been Remove
d.
在我看来,实现此目的的更好方法(避免可能的阴影"问题)可能是为 Global`
上下文本身设置突出显示.我没有考虑过这样做的后果,但可以单独使用它:
It occurs to me that a better way to accomplish this, that avoids a possible "shadowing" problem, may be to set highlighting for the Global`
context itself. I have not considered the ramifications of this, but it can be done with this alone:
SetOptions[$FrontEndSession,
AutoStyleOptions -> {"SymbolContextStyles" -> {"Global`" -> Green}}
]
<小时>
使用提示
上下文
highlight`
是完全任意的,你可以用不同的颜色突出显示多个上下文.
Tips on usage
The context
highlight`
is completely arbitrary, and you can have multiple contexts highlighted with different colors.您可以为包的上下文(例如
Units`
)着色,以区分哪些符号属于该包.You can color the contexts of packages such as
Units`
to distinguish which symbols belong to that package.这篇关于Mathematica 中的语法着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!