Sunday, July 10, 2011

Postscript Syntax Highlighting

In this blog post I will outline the GtkSourceView language definition for Postscript.

Postscript is best know as a page description language. I found myself using it to produce a set of pictures, but was disappointed that no syntax highlighting was available. Luckily I had prior experience

Just like the the blog post about MAGMA syntax highlighting I used GtkSourceView to create a language definition file for Postscript. The language definition file can be found on github. For instructions about installing the language definition file I refer to the post about MAGMA. (Or you can find instructions in the README file.)

Have fun with Postscript!

Tuesday, June 21, 2011

Graphviz: dot

In this blog post I will discuss the programming language dot.

Dot is a graph description language. I will dive right in and show you an example. The following code:

graph example {
    a [label="root"]
    b [shape="box"]
    c [color="red"]
 
    a -- b -- d
    a -- c -- e
    c -- f [label="indirect"]
}
produces this output:

This clearly shows the capabilities of dot. For more information about dot, and it companion programs visit the Graphviz website.

Thursday, June 16, 2011

MathJax: the gory details

In this blog post I will outline the steps needed to display LaTeX on blogger via MathJax.

In this post I announced the use of a new LaTeX rendering engine that I started to use. A comment asked for more information how I achieved this. Unfortunately it took me a while before I noticed the comment. In this blog post I will provide the steps I performed to start using MathJax in blogger.

Step 1: Hosting
This is by far the hardest step in the configuration of MathJax. MathJax relies on a server which provides all the resources MathJax needs. So you need a host which you can control. I looked around for a hosting service and picked a local hosting service.

Step 2: Installing MathJax
There are various ways of installing MathJax depending on your host. For various reason I opted for a local installation.
Get a copy of the latest MathJax distribution of the download page of MathJax. Place the distribution on the host and follow the installation instructions. Other options are described as well.

Step 3: Add reference to your MathJax in blogger
In order to use MathJax in blogger you have to refer to the MathJax installation. Go to the design section of blogger and edit the html. In the head section of the html add the following section of code.

<html>
  <head>
     ...
     <script src='http://[yourhost/your-installation/]MathJax.js' type='text/javascript'/>
     ...
  </head>
  <body>
    ...
  </body>
</html>

Step 4: Start using LaTeX
Now you can use LaTeX in blogger.
\[
e^{i\pi} + 1 = 0
\]

Above I outlined the steps I performed to start using MathJax in blogger. Since the time that I started using MathJax some things changed. For example, It is now possible to use MathJax directly from their Content Distribution Network (CDN). In effect making steps 1 and 2 unnecessary.

Before you can use the CDN you will have to read the terms of service. After that use the alternate step 3 to reference Mathjax in blogger as outlined below and on the documentation page.

Step 3': Add reference to the CDN Mathjax in blogger
Go to the design section of blogger and edit the html. In the head section of the html add the following section of code.

<html>
  <head>
     ...
     <script src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' type='text/javascript'/>
     ...
  </head>
  <body>
    ...
  </body>
</html>

This wraps up the explanation of the use of MathJax in Blogger.

Friday, June 3, 2011

MAGMA Syntax Highlighting

This blog post points out how to add syntax highlighting for MAGMA in gedit.

MAGMA is a very good computer algebra system, but not very well known outside a select mathematical circle. So it is not very surprising that gedit does not know how to syntax highlight MAGMA code out of the box.

Gedit uses GtkSourceView as its syntax highlighting engine. GtkSourceView can be extended by providing a language definition file.

So I set out to create a language definition file for MAGMA. The results can be found at github. In order to use is, you have to place the magma.lang file in the following directory:


~/.local/share/gtksourceview-2.0/language-specs

Below you can find a screenshot of a snippet of MAGMA code highlighted by gedit.

Tuesday, May 10, 2011

Unity: adding items to the dock

In this blog post I will outline a way to add new items to the dock in Unity.

Unity is a new graphic shell for the latest Ubuntu; Nauty Narwal. One of the more prominent features is a docking area.

In this docking area icons for running applications appear. You can decide to keep the icon as a launcher for the application. This feature is nicely integrated with the software center. Whenever new software is installed it will write a desktop file to /usr/share/applications/. This file describes how the menu-item will appear on the dock.

The only downside is that not all software is installed via the software center. One of the reasons is that the software center repositories hold older versions. For example the version of eclipse found in the repository is 3.5.2 (Galileo). At this moment the latest version of eclipse is 3.6 (Helios).
Software which is not installed via the software center does not readily appear on the dock. The reason is the missing desktop file. The rest of the blog post describes how to provide a custom desktop file.

I found the following site helpful. There is a more formal specification of the Desktop Entry Specification. A quick overview is given at anatomy-of-a-desktop-file.

The following steps create a launcher for an application which is not installed via the software center.

  1. Create a desktop file for the application
  2. Place the desktop file in ~/.local/share/applications/
  3. [Optionally] Drag the desktop file onto the dock

Create a desktop file for the application
There are various routes to creating a desktop file. One can create a desktop file from scratch, or copy and modify an existing one. A great place for inspiration are the desktop files in /usr/share/applications.
Below is an example of a desktop file. I created it to launch Eclipse. Paths mentioned are specific for my system and can be changed. The shortcut groups defined at lines 13, 15 and 20 appear when you right-click the icon.

[Desktop Entry]
Name=Eclipse Helios
GenericName=Eclipse
Comment=Start the awesome Eclipse IDE
Exec=/home/dvberkel/bin/eclipse/eclipse
Terminal=false
Type=Application
Icon=/home/dvberkel/bin/eclipse/icon.xpm
Categories=IDE;
StartupNotify=true
OnlyShowIn=GNOME;Unity;

X-Ayatana-Desktop-Shortcuts=Choose;Workspace;

[Choose Shortcut Group]
Name=Choose workspace
Exec=/home/dvberkel/bin/eclipse/eclipse
TargetEnvironment=Unity

[Workspace Shortcut Group]
Name=Workspace
Exec=/home/dvberkel/bin/eclipse/eclipse -data /home/dvberkel/workspace
TargetEnvironment=Unity

Place the desktop file in ~/.local/share/applications/
Unity is looking for custom desktop files in the ~/.local/share.applications directory. It could be that Unity should be restarted before changes are picked up. This can be accomplished by issuing the following command: unity --replace.

[Optionally] Drag the desktop file onto the dock
By dragging the desktop file onto the dock it immediately can be used as a launcher. This option really worked well for me.

This concludes this blog post. In it I explained a means to provide a custom desktop file which gets picked up by Unity.

Monday, May 2, 2011

Learning Language Categories

In this blog post I will advocate to learn new language categories instead of new languages.

Every once in a while you find a post on a forum addressing the question which new language should one learn. Notable examples can be found by googling. Here is a sample:

In my opinion, growing as a developer is not about specific languages. If this was the case then why does nobody suggest C# if one knows Java or vice versa? Seldom is such an advice given. But if it is all about learning languages then this advice should surface as often as any other advice.

I think that language categories are more important then languages. One reason to learn a new language is to broaden your horizon. By seeing new solution to old problems your problem solving toolbox grows. Even if it is not possible to apply the language directly it often is possible to adopt the idea. By going beyond a language category barrier, the novelty and creativity with which problems can be solved grow enormously.

So the next time the question "Which language should I learn next" is asked, go ahead and advice to learn a new language category.

Using proper tags

while reviewing all my old posts in order to use the new Mathjax rendering engine (as mentioned here), I noticed that these posts do not always use proper html tags. I would rather rely on the basic blog layout to work for me.

Frankly it is unreliable. So I went back and redid them using proper tags. The most prominent change was the introduction of the humble <p> tag.

So you can expect a more consistent look and feel for my blog post of way back.