Tag Info

Hot answers tagged

61

What you want is SyntaxInformation. With this, you can use every highlighting which already exists for things like Table, Solve, etc. for your own functions. You can specify the pattern of the arguments. With this you get the typical red commas if you use too many parameters. Or you can highlight locally used variables inside the function-arguments: ...


31

The colors used by the syntax highlighter can be set by changing the styles for StandardForm. The following is a how-to that explains how I styled the input cell in the screenshot in the question. This should be a starting point to get your own custom highlighting scheme up and running. Note that you can also do the same by choosing the colours in ...


30

As a part of a larger sets of development tools which I am working on currently, I have developed a general syntax highlighter generator which does just that (not yet with styles though, this is coming). I wanted to put in on GitHub and do a bit more polishing / development, but since you asked the question, here goes. Features From a simple lexical ...


28

The default style sheets set ShowSyntaxStyles -> False for the "Printout" environment. You could change the notebook to use a style sheet that doesn't set this. Probably the easiest way is to copy the definition from Default.nb, and modify it: Cell[StyleData[All, "Printout"], ShowSyntaxStyles->True]


24

The red colouring indicates shadowing — i.e., when a symbol originally in a particular context, is exposed to the current context path, thereby clashing with another symbol of the same name in a different context, also on the context path. Example of shadowing: Here is a short example that demonstrates this. Try it out in a fresh kernel (call Quit[] ...


13

This is because Mathematica exports to PDF in the Printout screen environment. If you change this to the working environment, it'll keep the syntax highlighting, but will also make everything a bit bigger: SetOptions[$FrontEnd, PrintingStyleEnvironment -> "Working"] You can also change this setting from the GUI using Format -> Option Inspector... ...


12

You can get the syntax highlighting that you desire by modifying your UnicodeCharacters.tr file, though I don't know how advisable this practice is. For example, adding: 0x20B0 \[PennyOp] ($penny$) Infix 155 None 5 5 I can use EscpennyEsc to enter: I am not aware of documentation of the format of this file but as ...


11

Available messages The message ::argx is one of the general messages intended for use with any function. These have the special property of being called for any symbol used (placed left of ::): Message[foo::"argx", "foo", 2, 3] foo::argx: foo called with 2 arguments; 1 argument is expected. >> Use Messages[General] to see a list of these messages. ...


10

When you're writing a blog, then I assume you take some content management system like Joomla because otherwise a blog is maybe to hard to keep up-to-date in pure html. I have personal experience with Joomla and know, that code-highlighting as described below works great. As mentioned by J.M. we have worked and tested hard to get a highlighter running for ...


9

This is because you are using = (the assignment operator) in the condition (not the body) of While. It is a typical beginner mistake to use = where == is meant, so Mathematica warns about this. Since you also use several ; in the condition, it gets a little confused and only highlights one of the = signs, not all of them.


9

I don't know what is causing your problem, but presumably you can still specially color the symbols in those contexts as I do. For example: SetOptions[$FrontEnd, AutoStyleOptions -> {"SymbolContextStyles" -> {"Units`" -> Brown, "PhysicalConstants`" -> Orange} } ] Since the above suggestion doesn't have effect on your machine even ...


9

As @R.M. explained, the styling rules are stored in the AutoStyleOptions setting. There is already a built-in editor for the code highlighting style, that can be accessed through Edit -> Preferences... -> Apperance -> Syntax Coloring. This changes the styles globally though. My suggestion is to first edit the global styling (because the built-in ...


9

As acl points out, this post shows you how to setup error highlighting for invalid number of arguments. Coming to the actual error messages used, there are three built-in messages attached to General, that can be used for your own functions as well. These are argx, argrx and argt: General::argx (* "`1` called with `2` arguments; 1 argument is expected." *) ...


8

You can do this using the following code: CurrentValue[EvaluationNotebook[], {AutoStyleOptions, "UndefinedSymbolStyle"}] = {FontColor -> RGBColor[0.5`, 0.173`, 0.765`]} More style options (other than "UndefinedSymbolStyle") that can be set are: {"CommentStyle", "EmphasizedSyntaxErrorStyle", "ExcessArgumentStyle", "FormattingErrorStyle", ...


8

I don't know whether I interpret your question correctly but have you checked Preferences->Appearance? There you see what the colors of the syntax highlighter mean:


7

Instead of using the Notation package, you can achieve the translation by doing the following: MakeExpression[RowBox[{x_, "⟗", y_}], StandardForm] := MakeExpression[ RowBox[{"FlatJoin", "[", x, ",", y, "]"}], StandardForm ] This takes care of the input translation. Now it's possible to enter expressions like 1 ⟗ (3 + 4 ⟗ 2) and have ...


7

The difference in color depends on whether or not it is a recognized symbol: black indicates it is recognized, blue indicates that it is not. For a symbol to be recognized, it has had to have been input to the kernel, i.e. it has to have been included in an executed cell. I have had problems in the past when quitting and restarting the kernel where the ...


6

I think it's just a warning that you have a symbol inside a localization scope that contains a symbol of the same (base) name. Compare With[{max = 2}, {With[{max = 3}, max], max}] Module[{max}, max = 2; {Module[{max}, max = 3], max}] Block[{max}, max = 2; {Module[{max}, max = 3], max}] and so on. The outputs above are each {3,2} and no messages are ...


6

I hope you don't mind if I answer this in a larger context and you have to read a bit. What you observe here is one disadvantage of the otherwise very nice Mathematica language. Since Mathematica follows the paradigm everything is an expression and code-is-data it is a mess when it comes to features that help programmers to write correct code or make ...


6

I remember being confused by this when I first started out. As rcollyer notes, black means that it is either a command or a variable that contains information, blue means that it is not recognized at all. Try this: testVariable="5" When you execute it, testVariable will turn from blue to black. Now, if you're coding and need to call on testVariable, it ...


5

I don't know if this is possible for the Input - style cells, but it is certainly possible for the Program-style cells with the syntax highlighter generator I exposed in a recent answer. The work in that direction is underway, but I don't have a complete package at the moment. In fact, apart from code highlighting for languages like C, Java, etc, a strong ...


5

Personally I'm always disappointed by the quality of the conversion done when one simply saves a notebook as a TeX file--it never looks like what I want or expected. But perhaps this isn't too surprising, as the two file types are very different, and therefore many choices need to be made about the conversion. I think a good general approach for solving ...


4

I find the difference to be helpful and provides "good to know" syntax information. In the case of using it in a "function" as you did*, naming a pattern (i.e. the : term) allows you to create much more complicated pattern matches for that element. So, while for your example, the full form of each statement evaluates the same: In[17]:= FullForm[foo[x_List]] ...


4

This seems to be a minor bug that shouldn't affect the functionality of PetersenGraph. The symbol has an incorrect SyntaxInformation. If it bothers you, you can (mostly) fix it by putting the following in your Kernel init.m: If[$Version == 9.0, PetersenGraph; (* load symbol *) Unprotect[PetersenGraph]; SyntaxInformation[PetersenGraph] = ...


3

As far as I know, you cannot change this. I cannot exactly say how it works in Eclipse, but usually the highlighting process consists of several steps. Basic highlighting can be provided after the lexical analysis. For a context sensitive highlighting like the one for local variables inside Module, Block, Function or in your case Compile, you need to parse ...


2

I don't think it's possible, but I hope for an answer proving me wrong. I don't think you can do anything about how the front-end interprets what you type as boxes. If you could do that, you could make something like x_Integer parse into a certain StyleBox. However, it's interpreted as a single word. Try it, and in the cell expression you'll see ...


2

I can reproduce this on OSX, but it is not specific to Plot. There are many other functions showing the same behavior. Try for instance Integrate[a___] /; True := blub When you delete the last e of Integrate, you see that the pattern a___ is highlighted in green again. All this happens in the front end where you cannot get much insight. A possible ...


2

The coloring is there to tell you of a possible conflict. Your function will be replacing var in both the Block and RuleDelayed with whatever you use as the second term of the first argument. It's possible that this is exactly what you intend, but it is usually not, hence the highlighting to warn. If you give an example of the use of your function I can ...


1

Crazyness! Ok so this behaviour relies on something like x = s_; f[x] := s behaving like you how you want it to. I must say I am guilty of making crazy definitions myself. Personally I don't like leaving any evaluation on the left hand side up to SetDelayed in cases like these. Anyway, you can do the following, but really it becomes only more crazy ...


1

This is a intended feature. It is explained by J. Fultz (Wolfram) in http://forums.wolfram.com/mathgroup/archive/2011/Sep/msg00198.html At that time the last mathematica version was version 8 and the feature didn't exist.



Only top voted, non community-wiki answers of a minimum length are eligible