Wednesday, 24 June 2009

Basic LaTeX

I have indicated there are good reasons to use LaTeX, the markup language developed by Lamport to run on top of Knuth's Tex. If you have read my earlier post and installed LaTeX here is an annotated file you can use as a building block for a simple project. I developed it on an Apple powerbook using MacTex


% File to show basic usage of Latex

% © Alex Kashko 2009


% a "%" sign is a comment

\documentclass[11pt]{article} % This tells LaTeX what type of document to produce


% This is the prolog to the document. MOST things here apply to the whole

% Document and any documents read in using \include{filename}

% Font size changes made here seem to have no effect


\usepackage{hyperref} % package (stylesheet) used to convert

%every \ref to a link

\pagestyle{myheadings} % Define how headers and page

%numbering are handled

\parskip 0.3 cm % Gap between paragraphs

% \newfont{\helvetica}{cmss12} % Define a reference to a font.

\textheight 9 in % Depth of printed matter on page.

% start of document

\begin{document}

\section{in the beginning \label{math}} % Define a label for the section

\Huge %change fontsize till further notice

%(\normalsize for example)

% Case sensitive

\bf{HELLO WORLD} \rm %\rm returns font style to normal

\begin{equation}

x=3\alpha \label{magnify} % label the equation

% refer to the equation with %\ref{magnify}

\end{equation}

\begin{equation}

2^{\aleph_0} = C \label{continuum}

\end{equation}

Equation \ref{magnify} deals with scaling and \ref{continuum} is to do with logic


\section{next}

And now for something totally different from \ref{math}

\end{document}

\end



The structure of the file is


\documentclass[11pt]{article}

% Document prologue goes here

\begin{document}

% Latex commands go here

\end{document}

\end


The prologue defines global formatting and this can be over-ridden in the document.


Cut and paste the document (bold text above) into a file beginlatex.tex

From the command line type


latex beginlatex.text

dvipdf beginlatex.dvi


Ignore the other files produced. They are fun to look at though


You should get a PDF file you can open in any reader and see the formatting. On my powerbook the links are highlighted.


In future posts I will look at top down document structuring basing the presentation on the maths textbook I had published a few years ago.


Enjoy


Saturday, 20 June 2009

Why your enterprise should use LaTex

Digital text production today is dominated by the word processor and the word processor universe is dominated by Microsoft Word, though free open source products such as Open Office are, as of 2009 challenging that dominance. While word processors have a lot of advantages they also have some disadvantages ad tend to be a middle ground between text processing and desktop publishing.

A word processor formats the text on screen in real time to give a close approximation to the format the user intends. The user can then save their work or print it.

An alternative approach, no longer in fashion, is the markup language. When working with a markup language the textual content is produced in a text editor, embellished with markup tags, and sent to a preprocessor which formats the text the way the author intended.

Advantages of markup languages

These include freedom from macro viruses, voiding vendor lock-in - the preprocessor is given a plain ascii text file to to work on, zero risk of data loss from corruption of the source file, ability to enforce standards, ability to divide work on a document within a team, and easier programmatic generation and manipulation of documents.

Disadvantages of markup languages

Disadvantages of markup languages such as HTML, SGML, XML, and the early languages such as nroff and troff include a perceived learning curve and the possible obscuration of the content by the markup tags. It is true that a beginner will initially be more productive with a word processor than with a markup language but the learning curve for real mastery of Word or Open Office is probably greater than with a markup language such as LaTeX. When it comes to programmatic manipulation of a document a markup language can reduce development time and cost dramatically. One major issue with a markup language if you are seeking work is that almost all recruiters require a CV in Word Format.


Which to use?

Horses for courses. If you are seeking work or need to get a short document out quickly use a Word processor. Using a word processor becomes unpleasant for long documents and it is hard, if not impossible, to create a word processor document on which many people can work at the same time.
If you need to produce a flyer or a brochure a full desktop publishing program is more appropriate. If you need to produce a book or a long report where adherence to in-house or legal standards is needed a markup Language such as LaTeX can enforce the standards without the user noticing. If you are producing mission critical documents a markup language will eliminate the risk of your source data becoming unreadable.

What can you do with LaTeX

LaTeX is a text markup language now under continuous improvement by a group of experts. It has a moderate learning curve and allows the user to do just about everything a word processor user would want to do – but not writing macro viruses – though some features like embedding a spreadsheet in a document may require non trivial skills. It is possible to produce indexes, lists of figures and tables, a table of contents and embed pictures and animations using LaTeX, and CJK (Chinese, Japanese Korean) writing is possible. Output can be to a printer or to a PDF HTML or postscript file. In principle LaTeX could be used to generate web pages though PHP is probably more suitable for this, at the cost of a higher learning curve. It is easy however to create a document in such a way that more than one person can work on it at a time. This has obvious advantages for internal corporate security. Technical people can work on tech ical sections and work on sensitive portions of the document can be confined to those authorised to handle such data.

Resources

Hopefully the discussion so far has established that there may be a place for LaTeX in the enterprise along with Word Processors and Desktop Publishing Systems.

There are many distributions of LaTeX on the internet, either free or commercial. MikeTex for Windows, MacTex for OS X and various varieties for Linux and other forms of UNIX. Resources for learning are easy to find and there is a thriving user community.

The Latex project should be a good place to start and
the latex community site has a useful forum.


The next part of this series will demonstrate basic LaTex Usage

Wednesday, 17 June 2009

Graphical user interface for passphrase generator in c#

**
* This class is the code for the user interface of an application to generate random
* but memorable and generally pronounceable passwords and phrases.
* The user specifies password length using a slider and may generate as many
* phrases as they wish till they find one they like.
* Minimum length is 8 characters and maximum length is 50 characters
* The resulting passphrase is all lower case
* The passphrase generation algorithm is not supplied at this time.
* I have produced several such algorithms and am not yet totally satisfied
*
* The code is intended to illustrate key features of some commonly used
* Winforms components. It is not intended to be a complete and slick application.
* That will come later.
*
* I posted this as a generally accessible note to myself. If you find it helpful
* I will be pleased.
*
* I wrote the code by hand ( i.e in a text editor outside an IDE) on a Power PC Macintosh
* using the Mono .NET framework. If Monodevelop OS X ever beomes truly usable
* there are many cosmetic improvements to be made
*
*
* Disclaimer: This code is supplied as is and you use it at your own risk
* All rights reserved.
*
* © Alex Kashko November 2008
*
*
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace passwordgenerator
{
public class passwordgenerator : Form
{

// Form variables. All we need is a button, a slider and a couple of labels.


TrackBar passwordLengthTrackBar;
Label passwordLengthLabel;
Label generatedPasswordLabel = new Label();
Button generateButton = new Button();

// Constructor. In the Sharpdev IDE the component formatting is hidden in
// a generated routine called initializeComponent()


public passwordgenerator()
{
this.Text = “Password Generator”;


// initialise controls


passwordLengthLabel= createPasswordLengthLabel();
generatedPasswordLabel = createGeneratedPasswordLabel();


// The trackbar is the most complex component in terms of the initialisation needed.


// X and Y positions


int trackbarx= 20;
int trackbary=40;


// Width and height


int trackbarwidth =48;
int trackbarheight = 200;


// Minimum and maximum passphrase length


int minlength=8;
int maxlength=50;
passwordLengthTrackBar = createPasswordLengthTrackBar(
trackbarx,trackbary,
trackbarwidth,trackbarheight,
minlength,maxlength);

generateButton = createGeneratorButton();

// Add the controls to the form
Controls.Add(generatedPasswordLabel );
Controls.Add(passwordLengthTrackBar );
Controls.Add(passwordLengthLabel);
Controls.Add(generateButton);
}

// ========== EventHandlers ===================

void generateButtonClick(object sender, EventArgs e)
{
// this.generatePassword(); // to be written
generatedPasswordLabel.Text= “Passphrase generator not supplied”;
}

void trackbarScroll(object sender, System.EventArgs e)
{
int value = this.passwordLengthTrackBar.Value;
this.passwordLengthLabel.Text = value.ToString();
}

// ========== Methods to hide initialisation of controls

private Button createGeneratorButton()
{
Button theButton = new Button();
theButton.Location = new System.Drawing.Point(100, 150);
theButton.Text=”GENERATE”;

theButton.Click += new System.EventHandler(generateButtonClick);

return theButton;
}

private Label createGeneratedPasswordLabel()
{
Label theLabel = new Label();
theLabel.Location =new System.Drawing.Point(100, 100) ;
theLabel.BackColor = System.Drawing.Color.LightSalmon;
theLabel.Text = “GENERATED PASSWORD”;
return theLabel;
}

private Label createPasswordLengthLabel()
{
Label theLabel = new Label();
theLabel.Text = “PASSWORD LENGTH”;
theLabel.Location = new System.Drawing.Point(60, 10);
return theLabel;
}

// Creates a trackbar at the specified location with given height and width and sets
// minimum and maximum passphrase length;


private TrackBar createPasswordLengthTrackBar(
int xpos, int ypos,
int width, int height,
int minlength, int maxlength
)
{
// Attributes


TrackBar trackbar = new TrackBar();
trackbar.Location = new System.Drawing.Point(xpos, ypos);
trackbar.Orientation = System.Windows.Forms.Orientation.Vertical;
trackbar.Size = new System.Drawing.Size(width, height);
trackbar.BackColor = System.Drawing.Color.LightSalmon;

trackbar.Minimum = minlength;
trackbar.Maximum=maxlength;
// Event handlers
trackbar.Scroll += new System.EventHandler(this.trackbarScroll);

return trackbar;
}

// Main method
public static void Main()
{
Application.Run(new passwordgenerator());
}
}

}

Friday, 12 June 2009

CV Writing Service for IT specialists and others

A CV writing service specialising in the IT market.

We will:

discuss your needs

Rework your CV

Where appropriate recommend where you can place your CV

Monday, 8 June 2009

Swing versus Winforms

As I write it seems Swing programmers are hard to find and the demand for c# is rising. This means it is a good time to compare Swing and the ,NET Winforms framework.

Note that I am NOT comparing the two languages, but, for the record I think C# a much nicer language than Java ( and I am a senior Java developer!!) but there is much more one can do rapidly with Java and are far less c# open source software around. Even if I were as expert in c# as in Java ( and I consider myself only one or two pegs down, as the languages are very similar) I would probably be less productive because of the relative lack of APIs, online documentation (Sun do a good job there) and open source software. Your mileage may vary and so may mine after a good c# contract.

I picked a relatively simple project, a pass-phrase generator. The goal was to develop memorable random passphrases, To do this I used the universal pattern of alternating consonants and vowels.

Step one was to develop the model. This took about two hours in each framework. The first cut was passwords only (pass phrase without spaces) I used the free Sharp develop IDE on a Windows PC to produce the .NET version and Eclipse for OS X on a G4 Powerbook to produce the Java version. The details of the algorithms ( Beyond the scope of this article) were slightly different in each case, but this did not seem to affect the end result much.

Next stage was to develop the interface. In each case all I needed was a button, a label and a slider. Developing the interface took one hour in Winforms and two in Swing, including testing and tweaking. The main reason for the difference was having to work round Swing's layout managers. The Swing GUI did not behave exactly as I would like while the Winforms GUI behaved perfectly right away, and I recall experimenting with Swing a few years ago and finding a strange bug that seemed to be in the framework.

I later repeated the parallel development exercise on an Apple power book using Mono.NET. The comparison was not fair since currently the only free C# IDE for OS X I know of is monodevelop and that is currently useless, as far as I can tell, for developing a GUI. However the framework itself supports command line development of a GUI provided you know which dll holds the desired classes. It took me a few minutes to find where the installer had hidden them after which all was plain sailing.

My tentative conclusion is that since it took me longer to develop a Swing Gui than a Winforms GUI, Winforms enables faster productivity -though this may simply because I do not have a drag and drop swing editor installed in Eclipse, - but Swing, being to my mind more like a form of Assembler for GUI. may allow more control and be deployable on a wider range of platforms. On the other hand Winforms seems to have overcome the problems that arise in Swing from leaving threading control to the developer.

I am happy to use Winforms for private c# projects and Swing for private Java projects. The lack of Winforms support in Monodevelop will slow down the speed with which I move to C#. Swing however is showing its age, something evidenced by the number of Swing toolkits designed to simplify development

Wednesday, 6 May 2009

Memorable random passphrase generator in c#

Not the most sophisticated algorithm and a different RNG could give more satisfactory performance. I seem to recall better results from a Java version of this algorithm.

/**
* this is a first pass at the algorithm for generating suggestions for pronounceable
* and hence memorable passphrases. There is some work to be done to
* give the user the power to choose things like mean "word" length and some
* decision needed as to whether to include numbers or not.
*
* the resulting passphrases are all lower case and this means a phrase
* of about 37 characters will be equivalent to 128 bit encryption. If you allow Uppercase
* A sequence of about 18 characters seems to be enough.
*
* The algorithm is based on the near universal alternation of vowels and consonants in almost all languages
* First a pattern comprising a series of alternating consonant and vowel ,markers is generated and then
* some of these are replaced by space markers.
*
* After that each marker is replaced by a random vowel consonant or space as appropriate.
*
* At present the sort of random 'words' generated seem to me to have an African flavour.
* This is interesting but I do not think it has implications for theories of the origin of language.
*
* A more sophisticated algorithm would mimic vowel and consonant or even digram
* frequencies in different languages allowing users to choose languages they know.
*
* At the date of writing I do not intend spending a lot of time on more sophisticated algorithms
* as I have other projects competing for priority.
* However this project can lead me into the interesting area of synthetic language generation
*
* I posted this as a generally accessible note to myself. If you find it helpful
* I will be pleased. Plase acknowledge me as the originator.
*
* I wrote the code by hand ( i.e in a text editor outside an IDE) on a Power PC Macintosh
* using the Mono .NET framework.
*
* Disclaimer: This code is supplied as is and you use it at your own risk
* All rights reserved.
*
* © Alex Kashko November 2008
*
*
*/
using System;
using System.Collections;
using System.ComponentModel;

namespace passwordgeneratormodel
{
public class passwordgeneratormodel
{
private static double probabilityOfSpace = 0.2;
private static Random rng = new Random();

// Passphrase generation routine
public static String generatePassWord( int length)
{
String pattern = generatePattern(length);
String result =transformPattern(pattern);
return result;
}

// Given a pattern generate the pass phrase
// Using Strings not chars would have resulted in much more complex code.
private static String transformPattern(string pattern)
{
char[] vowels = {'a', 'e','i', 'o', 'u'};
char[] consonants = {'b', 'c', 'd', 'f', 'g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z'};
// char[] numbers = {'1','2','3','4','5','6','7','8','9'};

char[] res = new char[pattern.Length];
for( int i =0; i<>

return new String(res);
}

// select random member of array
private static char pickany(char[] array)
{
int index = rng.Next(array.Length);
return array[index];
}

// Generates a pattern of CVCV or VCVC with occasional S
// C = consonant, V = vowel, S = space
private static String generatePattern (int length)
{
// choose consonant or vowel randomly
// Reuse the RNG rather than creating a new one

Char[] pattern = new Char[length];
pattern[0] = 'V';
if(rng.NextDouble() < i ="1;">

}
else
{
pattern[i] = 'V';
}

}
// Step through the array again and change
// Some elements to space (S) with fixed probability. Make sure you have no leading or
// trailing spaces and never get two spaces in a row.
for( int i =1; i < i =" i+1;">

Words about me

Photographer, Writer, Expert Software developer, Translator, patent writer. Mathematician, Physicist, IT contractor and lots more.