MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Add syntax highlighting to own command

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101656] Re: Add syntax highlighting to own command
  • From: earthnut at web.de (Bastian Erdnuess)
  • Date: Sun, 12 Jul 2009 06:58:12 -0400 (EDT)
  • References: <h340tk$guu$1@smc.vnet.net> <h390jd$jmo$1@smc.vnet.net>

Peter Breitfeld <phbrf at t-online.de> wrote:

> Bastian,
> 
> you should make a file Bastian.m (or so) to look like this:

I did so.  Now I have a MyToolBox.m.

> Put this file in the Folder $UserBaseDirectory/Applications.
> 
> Look for the file $UserBaseDirectory/Kernel/init.m
> If it doesn't exist, create it.
> Open it with an editor and add the line
> 
> Get["Bastian`"]
> 
> Now, your file will always be loaded on startup.

That was a good tip.  I tried it with $UserBaseDirectory/Autoload first,
but that didn't really worked well.

> To your other questions:
> 
> 1. Yes, it's a bad idea to give your own functions the context System`.
>    Better create your own Bastian.m file and put all your functions in
>    it; they will have the context Bastian`. (Such a file tends to grow
>    over time :-))

Yes, makes sense, and seems to be pretty true.  It already started.  I
wanted to make a usage text with some text formatting.  But since I use
an external editor and Mathematicas

  "\!\(\*RowBox[\"Let\",\"[\",RowBox[\"{\",RowBox[StyleBox[\"x\", ... "

stuff is pretty ugly I started to make some functions for text makeup.

I used the Let construct in them and right now I'm writing the usage
textes to the makeup functions using themseves to do that...

> 2. Syntax Highlighting is done with the line SyntaxInformation above.

That's already nice.  Is there a reason not to use {{__},_} instead of
{_,_}?  However, not exactly what I was looking for.

When you write e.g.

  With[
    {
      a = 1,
      b = 2
    },
    a * b
  ]

Mathematica highlights the symbols a and b green.  But it seems that
this cannot be controlled using SyntaxInformation. :-(

> 3. I can't improve your code.

I found two other versions of the same program (one of them here), and
indeed I must say I like my version best. -- Funnily, I found them while
I was looking for syntax highlighting.  These guys had the same
question: "I wrote this function and now I wonder if I can add syntax
highlighting..."

Bastian


  • Prev by Date: Re: Add syntax highlighting to own command
  • Next by Date: Re: Derivative of a sum.
  • Previous by thread: Re: Add syntax highlighting to own command
  • Next by thread: Re: Add syntax highlighting to own command