Latex brush for Syntax Highlighter Plus Wordpress plugin

I post source code snippets quite often and I use this plugin for syntax highlighting. It works great but it doesn’t support every programming language. For example it lacks Latex support. On the other hand you can define coloring rules for unsupported languages by creating new “brushes”.

Taking advantage of this feature, I’ve defined an extremely simple Latex brush which highlights:

  • Latex comments beginning with a percent symbol ‘%’.
  • Latex commands beginning with a backslash “\”.
  • Some keywords such as ‘if’, ‘else’, etc.

You can download the brush from here.

If you want to see Latex coloring in action, you can take a look at the Latex section of my blog.

Note: I also had to add this line:

'Latex'     => array('latex', 'tex'),

…to the SetVariables() function in syntaxhighlighter.php for the new brush to work.

Setting up a Public Key Infrastructure (PKI) on Linux: Theory and Practice

This article highlights the most important concepts regarding Public Key Infrastructure (PKI). It also includes a practical step-by-step guide explaining how to set up a PKI on Linux using the OpenSSL package.

Wrap text around float figures in Latex

The wrapfig package enables text wrapping around figures.

\usepackage{wrapfig}

To include a wrapped figure we can use the \begin{wrapfigure} command. You have to specify the alignment (l, r) and the figure’s width. Here is an example:

\begin{wrapfigure}{r}{60mm}
\begin{center}
\includegraphics[scale=0.5]{images/nature_photography.jpg}
\end{center}
\caption{Wrapped image.}
\end{wrapfigure}

And the final result.

picture 11 Wrap text around float figures in Latex

Placing subfigures in Latex documents

Sometimes you need to place two or more figures side by side or you just need to include a figure composed of many subfigures. To place the images in your Latex document this way, you can use the subfig package.

\usepackage{subfig}

The command subfloat is used to specify the subfigures.

\begin{figure}[!h]
\centering
\subfloat[NP Server's certificate]{label{fig:gull} \includegraphics[width=0.4\textwidth] {images/npservercert.png}} \qquad
\subfloat[SP Server's certificate]{label{fig:gull} \includegraphics[width=0.4\textwidth] {images/spservercert.png}}
\caption{}
\label{fig:}
\end{figure}

And this is the final result.

subfig Placing subfigures in Latex documents

Source code snippets in Latex

In this post I’m going to show you how to include source code snippets in your Latex documents. To perform the task we’re going to use the listings package.

\usepackage{listings}

First we’re going to define the source code’s layout. We’ll define two different styles to show the capabilities of the package. The first style comes in handy for including source code. The second one is better for including, for instance, console commands. Of course you can define different styles to suit your own needs.

\definecolor{gray92}{gray}{.92}
\definecolor{gray75}{gray}{.75}
\definecolor{gray45}{gray}{.45}
 
\lstdefinestyle{source_code}
{
numbers=left,
stepnumber=5, 
basicstyle=\normalsize, 
captionpos = b, %bottom 
keywordstyle=\color[rgb]{0,0,1}, 
commentstyle=\color[rgb]{0.133,0.545,0.133}, 
stringstyle=\color[rgb]{0.627,0.126,0.941}, 
backgroundcolor=\color{gray92}, 
frame=lrtb, 
framerule=0.5pt, 
linewidth = \textwidth 
}
 
\lstdefinestyle{console} 
{ 
numbers=none, 
basicstyle=\bf\ttfamily, 
backgroundcolor=\color{gray92}, 
frame= lrtb, 
framerule=0.5pt, 
linewidth=\textwidth, 
}

Once the styles are defined there are two ways to include the snippets in the document:

  • Writing the source code directly in the Latex document.
  • Importing the source code file.
\begin{lstlisting}[style=console, caption=A command] 
# gcc -o hello hello.c 
\end{lstlisting}

Note how we can specify the source code’s programming language as well as the listing’s caption:

\lstinputlisting[style=source_code, label = some label, caption=A shell script, language=bash]{example.bash}

The final result looks like this:

picture162 Source code snippets in Latex

You can get the full Latex source code here.

DynDNS or how to host Internet services with a dynamic IP address

Sometimes you need to set up some service at home (e.g., a Web Server or a Mail Server). In my case, my IP address is dynamic and likely to change. You can always pay for a static IP address but there other valid solutions. For instance you can use a dynamic DNS service such as DynDNS. Service setup is easy; you have to follow these steps:

  • Register an account at dyndns.org and configure a hostname (e.g., myhost.dyndns.org).
  • Download the DynDNS client and configure it with your registered hostname. There are versions for Windows, Linux and Mac.

Now every time your IP address changes, the DynDNS client updates the corresponding DNS records and your services are accessible again. This mode of operation has a drawback related to DNS catching. All records in DNS have a Time to Live (TTL) value. This value dictates how long a record should be stored locally before a new copy of the record must be retrieved from DNS. Sometimes the information in DNS changes, but the old information is still stored in the DNS caches. When the cached record is different from the newest information in DNS, it is called a caching error.
DynDNS allows you to set the TTL value to 60s or 4h. If your IP is dynamic you should use the 60s value.
picture12 DynDNS or how to host Internet services with a dynamic IP address
In summary, if availability and grade of service are key aspects for you, pay for a static IP. Otherwise you can always use services like DynDNS.

Panorámica sobre el sector TIC y consejos para los nuevos graduados

Hace unas semanas Aitor Ibañez (Responsable Técnico de la Zona Norte de Oracle) ofreció una charla muy interesante en la Escuela de Ingenieros de Bilbao. En ella realizó una panorámica sobre diferentes empresas TIC tanto nacionales como internacionales, y ofreció una serie de consejos muy útiles para el desarrollo profesional.

Desde luego una presentación muy útil para todos aquellos que vamos a entrar en el mercado laboral en breve.

Adding Subversion support to Visual Studio 2008

Control versioning systems are an essential tool for every programmer and provide very useful options such as keeping different branches of the same project or reverting the source code to a previous version.

In this post I’m going to show you how to set up and integrate Subversion with VS2008. Continue reading ‘Adding Subversion support to Visual Studio 2008’ »

Beautiful tables in Latex

Producing tables is latex is not an easy task. Fortunately I found a very handy macro that transforms Excel tables into Latex code. It is written by Joachim Marder and can be obtained here. If you use OpenOffice you can take a look at calc2latex. With the table creation problem solved, now we can focus on improving the style. We are going to need the following packages:

\usepackage[dvipsnames,usenames]{color} 
\usepackage{array} 
\usepackage{colortbl} 
\usepackage{booktabs}

Next we specify some formatting commands:

%increase the column separation and the cell height 
\renewcommand{tabcolsep}{0.25cm} 
\renewcommand{arraystretch}{2} 
%We can define our custom colors in RGB format 
\definecolor{tableheading}{rgb}{0.82,0.82,0.82} 
\definecolor{softblue}{rgb}{0.8,0.8,1} %Change the bar color 
\arrayrulecolor{ForestGreen}

… and voila! Latex has produced a very stylish table.

picture14 Beautiful tables in Latex

This is the full latex source code:

\documentclass[12pt,a4paper]{report} 
\usepackage[utf8x]{inputenc} 
\usepackage{ucs} 
\usepackage{amsmath} 
\usepackage{amsfonts} 
\usepackage{amssymb} 
\usepackage{makeidx} 
\usepackage[dvipsnames,usenames]{color} 
\usepackage{array} \usepackage{colortbl} 
\usepackage{booktabs} 
\renewcommand{tabcolsep}{0.25cm} 
\renewcommand{arraystretch}{2} 
\definecolor{tableheading}{rgb}{0.82,0.82,0.82} 
%definecolor{totalcolor}{rgb}{1,0.7,0.7} 
%definecolor{firstcolumncolor}{rgb}{0.7,1,0.7} 
\definecolor{softblue}{rgb}{0.8,0.8,1} 
\arrayrulecolor{ForestGreen} 
 
\begin{document} 
% Table generated by Excel2LaTeX from sheet 'material' 
\begin{table}[!h] 
\centering 
\begin{tabular}{ccccc} 
\toprule 
\rowcolor{tableheading} {bf ID} & {bf Description} & {bf Price} & {bf Redeem period} & {bf Redeemed cost} \ 
\midrule 
M1 & PC 1 & 500,00 & 9,00 & 150,00 \ 
\midrule 
M2 & PC 2 & 500,00 & 9,00 & 150,00 \ 
\midrule 
M3 & Server 1 & 1.000,00 & 9,00 & 250,00 \ 
\midrule \textit{Total} &  &  & & multicolumn{1}{>{columncolor{softblue}}c}{550,00} \ 
\bottomrule 
\label{tab:test} 
\end{tabular} 
\caption{Test table} 
\end{table} 
\end{document}

Web services in Python with soaplib (1)

Surprisingly, there aren’t too many web services libraries in Python. On the one hand, we have ZSI, allegedly the most powerful one. However its documentation is outdated and the beginnings aren’t easy. Keeping my search I discovered soaplib. Soaplib is an easy to use python library for writing and calling soap web services. To install it follow these steps:

svn co https://svn.optio.webfactional.com/soaplib/trunk soaplib 
cd soaplib python setup.py install

Creating web services with soaplib is quite easy. This is the server:

from soaplib.wsgi_soap import SimpleWSGISoapApp
from soaplib.service import soapmethod
from soaplib.serializers.primitive import String, Integer, Array
 
class HelloWorldService(SimpleWSGISoapApp):
 
    @soapmethod(String,Integer,_returns=Array(String))
    def say_hello(self,name,times):
        results = []
        for i in range(0,times):
            results.append('Hello, %s'%name)
        return results
 
if __name__=='__main__':
    from cherrypy._cpwsgiserver import CherryPyWSGIServer
    # this example uses CherryPy2.2, use cherrypy.wsgiserver.CherryPyWSGIServer for CherryPy 3.0
    server = CherryPyWSGIServer(('localhost',7789),HelloWorldService())
    server.start()

And this is the client:

from soaplib.client import make_service_client
from helloworld import HelloWorldService
client = make_service_client('http://localhost:7789/',HelloWorldService())
print client.say_hello("Dave",5)

As you can see writing a simple web service just takes a few seconds. This example passes primitive data types (String, integer …) to the remote method. We’ll see how to pass complex data another time.