Archive for December, 2009

Displaying Math equations using MathML in mediawiki

Monday, December 28th, 2009

Mathematical Markup Language (MathML) describes mathematical notations and capturing both its structure and content. The objective of mathml is to integrate mathematical formulae into World Wide Web documents.
For examples of mathematical expressions and the syntax for writing them within a wiki refer
http://meta.wikimedia.org/wiki/Help:Formula
Example:<math>$ {x}^{2}+4x+4=0$</math> represents the expression

To setup mathml support in mediawiki, we have to install several modules in the server.  Please find the steps to make it work below.

1.Setup Tex proccessing in LocalSettings.php
Open the file LocalSettings.php and enable tex processing. This can be achieved by setting $wgUseTeX = true;

2. Install texvc
The mediawiki application by default comes with the source code for texvc in /mediawiki/math. To install this, we can follow any one of the options below.

  • Download the precompiled binary from http://prdownloads.sourceforge.net/wikipedia/texvc-linux-x86-20040107.tar.gz?download to the math folder.
  • Self compilation and copy to math folder.
    I prefer the (i) method. Also please make sure that the texvc binary file in the math folder has executable permission.

3. Install TeTeX (http://www.tug.org/teTeX/)

4. Install Ghostscript (http://www.ghostscript.com/)

5. Install ImageMagick (http://www.imagemagick.org/)

6. Install AMS fonts (http://www.ams.org)

Please make sure that latex, dvips, convert and gs are installed.
To know whether these modules are installed and the path, use the commands “which latex” , “which dvips” etc in the console.

7. Install libstdc++5(sudo apt-get install libstdc++5)

8. Please make sure the Ghostscript and ImageMagick do not have conflicting versions.

9. PNG files for mathematical expressions are stored in the math directory. Please check the subdirectories math and tmp in the upload subdirectory to see their contents. Sometimes if the
conversion process ceases or has any issue in certain stage, files of that type may remain in the tmp directory only.

  • Share/Save/Bookmark

Seasons Greetings from the team at Cabot Solutions!

Wednesday, December 23rd, 2009

The team at Cabot Solutions would like wish all our clients, well wishers and vendors a very happy holiday season.

  • Share/Save/Bookmark

Generating string combinations for a url shortening service using PHP

Wednesday, December 23rd, 2009

Url shortening is a technique in which a larger URL is made available by accessing a relatively shorter URL.  This is useful for sending links with via email, twitter,  sms etc.  Popular URL shortening services include tinyurl.com and bit.ly.

Usually, the long web page url is mapped to a randomly generated string-numeric combination such that by typing the
url http://shorteningservice.com/randomstring will redirect to the original long url.

I have made the generation of random strings in a uniform way using php by using the characters A to Z.
This is explained below (Usage Examples: 2). This method provides the user a chance to predict the next short url.

Usage Examples:

1. Permutation of strings:

permutations(”ABCDEF”, 3) will return an array of 130 string sequences from ABC to DEF.
This is the permutation of 6 charecters taken 3 at a time. Here ABC and ACB are taken as seperate entities.

2. Permutation with repetation:

That is a sequence of the form AAA, AAB, …., ZZZ, AAAA,AAAB,AAAC,…ZZZZ,…..,ZZZZZZZZZZ…ZZ.
I can show you a function that returns the next element of the above series when the current string is given.

Php Code:

<?php
//function to get the array permutation string sequences
function stringPermute($orgString,$num){
    $last = substr($orgString, 0, $num);
    $result = array();
    while($last != substr($orgString,  -$num)){
        $result[] = $last;
        $last = getNextString($orgString,$last,$num-1);
    }
    $result[] = $last;
    return $result;
}
//Function to get the next string sequence in order
function getNextString($fullString,$string,$char){
    if($string{$char} <> lastElement($fullString)){
        $string{$char} = $fullString{strpos($fullString,$string{$char})+1};
        return $string;
    }else{
        $string = change($string,$fullString{0},$char);
        return getNextString($fullString,$string,$char-1);
    }
}

function lastElement($string){
    return $string{strlen($string)-1};
}

function change($string,$char,$start = 0,$end = 0){
    if($end == 0)
        $end = strlen($string)-1;
    for($i=$start;$i<=$end;$i++){
        $string{$i} = $char;
    }
    return $string;
}
?>
  • Share/Save/Bookmark