Discussion:
(**) comments highlighted - newbie
(too old to reply)
Adrian Craciun
2004-06-12 04:04:57 UTC
Permalink
Hello,

I hope my question is not completely silly, but I have been trying to find
an answer for this both in the Mathematica book, in this forum's archive
and elsewhere on the net and I failed.

Since I will be doing quite a bit of programming with Mathematica in the
near future, I would like to have the following (very reasonable, I think)
feature:
comments (* ... *) should (by themselves :) ) change colour (for instance)
so that they are obvious in the code from a distance.

I hope the solution to this is not very complicated, and I'm sure I am not
the first to think about this. Can anyone help?

Thanks in advance,

Adrian
David Park
2004-06-13 03:40:33 UTC
Permalink
Adrian,

You can select a comment and then change the color via the Menu/Format/Text
Color item. I don't think you can have them automatically change color.

Also, in my opinion, there is a flaw in Mathematica's use of comments. If
you select a cell and change it between forms, say from StandardForm to
InputForm or TraditionalForm, the comments are thrown away. So if you ever
do any of that, your careful efforts at commenting will all be lost.

David Park
***@earthlink.net
http://home.earthlink.net/~djmp/

From: Adrian Craciun [mailto:***@risc.uni-linz.ac.at]

Hello,

I hope my question is not completely silly, but I have been trying to find
an answer for this both in the Mathematica book, in this forum's archive
and elsewhere on the net and I failed.

Since I will be doing quite a bit of programming with Mathematica in the
near future, I would like to have the following (very reasonable, I think)
feature:
comments (* ... *) should (by themselves :) ) change colour (for instance)
so that they are obvious in the code from a distance.

I hope the solution to this is not very complicated, and I'm sure I am not
the first to think about this. Can anyone help?

Thanks in advance,

Adrian
AES/newspost
2004-06-14 07:14:45 UTC
Permalink
Post by David Park
You can select a comment and then change the color via the Menu/Format/Text
Color item. I don't think you can have them automatically change color.
Also, in my opinion, there is a flaw in Mathematica's use of comments. If
you select a cell and change it between forms, say from StandardForm to
InputForm or TraditionalForm, the comments are thrown away. So if you ever
do any of that, your careful efforts at commenting will all be lost.
While we're on this topic, it would also be nice if one could Merge a
sequence of Input and text or header cells, starting with an Input cell,
and have all the non-Input cells be auto-converted to comment lines.

I like to develop and test longish routines by coding them as one Input
cell per statement so I can step down through the routine one cell at a
time, together with occasional comment cells in header or text format
interspersed between these input cells to remind me of what I'm doing.

(*--I guess I could put the (* *) labels on the comment cells from the
start -- but why not let Mathematica do the work?--*)
Paul Abbott
2004-06-16 11:56:25 UTC
Permalink
Post by AES/newspost
While we're on this topic, it would also be nice if one could Merge a
sequence of Input and text or header cells, starting with an Input cell,
and have all the non-Input cells be auto-converted to comment lines.
I like to develop and test longish routines by coding them as one Input
cell per statement so I can step down through the routine one cell at a
time, together with occasional comment cells in header or text format
interspersed between these input cells to remind me of what I'm doing.
(*--I guess I could put the (* *) labels on the comment cells from the
start -- but why not let Mathematica do the work?--*)
I think that it is preferable to develop packages as Notebooks, in which
the documentation can be both extensive and nicely formatted, and use
the autogeneration feature to automatically generate the Mathematica
package. This allows you t break your code into understandable chunks,
making your code easier to maintain, test, and understand. Modifying the
Notebook StyleSheet allows you to write comments in any format that you
choose.

For a nice example, see the Notebook

NotationSource.nb

which (automatically) generates the Notation.m package (loaded as
<<Utilities`Notation`), and is included with the standard distribution
in the following directory:

ToFileName[{$TopDirectory, "AddOns", "ExtraPackages","Utilities",
"Documentation","English"}]

Cheers,
Paul
--
Paul Abbott Phone: +61 8 9380 2734
School of Physics, M013 Fax: +61 8 9380 1014
The University of Western Australia (CRICOS Provider No 00126G)
35 Stirling Highway
Crawley WA 6009 mailto:***@physics.uwa.edu.au
AUSTRALIA http://physics.uwa.edu.au/~paul
Adrian Craciun
2004-06-15 06:52:33 UTC
Permalink
Post by David Park
You can select a comment and then change the color via the
Menu/Format/Text
Color item. I don't think you can have them automatically change color.
I already mark the comments by a different colour manually. I was hoping
that someone knows how to do it automatically. I had some attempts to try
something with $Pre, or $PreRead (I think they are called). However I did
not go very far, because these are already used for something else in the
package I am working on, and I'm not too sure I want to mess with that. I
thought that there is some easier solution to this, some option I
overlooked.

My cells are always Input cells. For what is worth.

Thanks for the replies.

Regards,

Adrian
Peltio
2004-06-23 07:20:55 UTC
Permalink
"Adrian Craciun" ha scritto
Post by Adrian Craciun
I already mark the comments by a different colour manually. I was hoping
that someone knows how to do it automatically.
[snip]
Post by Adrian Craciun
My cells are always Input cells. For what is worth.
In this case, wouldn't you be better off with an external editor?
There are freeware editors that are 'syntax-aware' and would let you color
the different keywords (and even comments I infer) as you like it.
The effort of copying and pasting your code from this editor into the
Mathematica front-end would be smaller that that of manually coloring every
single comment, I guess.
You would work with two separated windows: one for coding and one for
running the code.

I wonder if there is any chance to automate te cutting and pasting into the
last selected mathematica notebook. This depends on the editor's capability
to issue external commands of course (no big deal as far as I know), but
also on mathematica's abilty to accept external commands (I never had to
worry about passing a text to a mathematica notebook from outside Mathematica, so I
haven't the slightest idea on how to do that).

My two cents.
Peltio
Invalid address in reply-to. Crafty demunging required to mail me.
Loading...