Friday, December 31, 2010

Using Unicode in Latex/Tex

To use Hindi Unicode, do the following -

In the .tex file include the line -
\font\texthi="Lohit Hindi:script=deva,mapping=tex-text" at 11pt.
(Remember to exclude the full stop at the end!)
Enter Hindi unicode text in the document as -
Some English text {\texthi हिन्दी...} more English text...
Compile the document using Xetex or XeLatex.

More information -

"texthi" is the name of the command we just defined to indicate Unicode text. You can give any other name, e.g. \font\abcd="...".

"Lohit Hindi" (remember the space between Lohit and Hindi) is the name of an Open Truetype Font (OTF) installed in the system. You can specify any other font that is installed. In Ubuntu, you can see what fonts are installed as follows -
Goto Main Taskbar -> System -> Preferences -> Appearance -> (Popup opens) -> Click 'Fonts' tab -> Try to change any of the fonts e.g. Application font. You get another popup where the fonts are listed under 'Family'. You can use any of these fonts instead of "Lohit Hindi".

"deva" is a tag that specifies which script (and hence which unicode range) should be used. Hindi uses the devanagari script. For other scripts, find out which script tag to use.

"mapping=tex-text" - I don't know what this. If you do, please tell me.

Linux command for listing files with complete paths

List all files (recursively) with complete paths (e.g. to use in shell scripts)
E.g. to get all .txt files, use find -type f -name "*.txt".

Tuesday, December 28, 2010

Linux shell script loop to process files in a directory

To process .txt files in a directory, but skipping the first few and the last few -

ls | grep -E "\.txt" | while read line; do
    count=`expr $count + 1`
    if [ $count -le 10 ] ; then

    echo $line

    if [ $line = "xyz.txt" ]; then

Wednesday, December 22, 2010

Using screen command in linux

The 'screen' command creates in a console session, the equivalent of windows in a GUI-based desktop. These 'screen's persist even after logout. You can ssh into a remote machine, open a 'screen', start your job, detach the screen, and logout. You can ssh back later, reattach the screen and check how the job is going.

screen -R myjob1 - opens a new screen myjob1 (like opening a new window)
Ctrl+a followed by d - detaches screen, and goes back to main session (like minimizing all windows and going to the desktop)
screen -R myjob1 - reopens the screen myjob1 (since it already exists)
Ctrl+a followed by d - detaches screen
screen -R myjob2 - opens a second screen myjob2
Ctrl+a followed by d - detaches the second screen
screen -R - lists screens available (in this case - myjob1 and myjob2)
screen -R myjob1 - attaches that screen
Ctrl+d - terminates the screen

Monday, December 20, 2010

Packages for generating figures (esp. plate diagrams)

- Inkscape
- latex
    - pstricks
    - tikz (,
    - TikZ and PGF
- xfig
- jPicEdt
- lpe (
- omnigraffle (not free) (

Friday, October 22, 2010

Mesh plot in MATLAB

To create a mesh plot in MATLAB similar to this -

do the following.

  • Initialize vectors X and Y with the x- and y-coordinates.
  • For each pair of (x,y) values, compute the function value f(x,y), and store in matrix Z having the form -
Z(1,:) = [ f(y1,x1) f(y1,x2) ... f(y1,xn) ]
Z(2,:) = [ f(y2,x1) f(y2,x2) ... f(y2,xn) ]
and so on.
  • Run mesh(X,Y,Z) to the mesh plot.

E.g. Plot f(x,y) = 2x^2 + 12 xy + 7y^2 (shown in plot)
The code will look something like this -

X = -1:.1:1;


% x's along columns
Xsq = X.*X;
for n=1:size(Y,2)
XsqM(n,:) = Xsq;
% y's along rows
Ysq = Y.*Y;
for n=1:size(X,2)
YsqM(:,n) = Ysq';

% x's change along a row (y fixed)
% y's change along a col (x fixed)
XY = Y'*X;

Z = 2.*XsqM + 12.*XY - 1.*YsqM;

Wednesday, July 7, 2010

Tech talk - slides - tips

Here are some tips for tech talks, that I got from some website (I forgot which one) -

1) As a technical paper presenter at AAAI-10, you have a special
obligation to help maintain the high quality of the conference. It is
your responsibility to take great care in preparing both the content
and presentation of your talk, including any visual aids. You should
be sure to make your talk accessible to the broadest possible
audience, giving relevant background, etc., and wherever possible
providing connections to related areas. Your goal is to ensure that
your audience grasps your main points.
2) The meeting room will be equipped with an LCD projector and screen.
laptop, please be sure to bring a MAC to VGA adapter. This adapter is
proprietary and almost every MAC has a different type. Therefore, the
audio/visual company may not be able to assist you onsite.
3) In preparing your slides, please follow these guidelines as
closely as possible. Material should be placed sparingly on each
slide, so as to be visible to a large audience.
* Landscape format is preferred
* Text should be centered on the page with at least a 1" margin
all around the page.
* There should be no more than 5 to 6 lines per page.
* There should be no more than 20 to 25 characters and spaces per line.
* Minimum title font size is 30 point.
* Text must be readable to the naked eye from 6 feet away (we
suggest no less than 20 point type for text and preferably 24).
4) The most effective slides contain diagrams and illustrations, with
relatively little text. Do not use slides merely to summarize the
talk or the paper; they should illustrate the research rather than
provide formal detail. Any text should be highlighted by bullets.
5) We strongly recommend that you go through a practice run of your
presentation with your colleagues. This will greatly enhance the
final presentation.
6) Remember that your talk is allotted a 20-minute time slot. We
encourage you to limit your talk to 17 minutes to leave at least 3
minutes for questions. Please time your practice talk carefully.
There will be 3 presentations per session.
7) Please go to the meeting room at least 10 minutes before the
session begins and introduce yourself to the session chair. Please
make sure you are on time to your talk.
8) Please start promptly (people will straggle in throughout the
talk, so don't wait).
9) Please observe the schedule very strictly and cooperate with the

Sunday, May 16, 2010

Sort command in Linux

To do a descending numeric sort on the 4th column of a tab-separated file qwe.txt, do
sort -t$'\t' -rn -k4,4 qwe.txt > sorted.qwe.txt

Note the grouping: sort [separator] [options] [fields to sort on]
Here I have used the options: -r (descending order) and -n (numeric sort).

The trick for specifying tab as a field separator is borrowed from here. Also see this.

Friday, April 9, 2010

Using Perl modules

  • Let the first line in the .pm file be package Red::Green::Blue;.
  • The .pm file should be named
  • The .pm file must be stored at dir/Red/Green/
  • In the perl program where you want to use this module, include use lib "dir";. This tells Perl to also look in dir when searching for modules. (this basically adds an entry to @INC).
  • In the same program, after the previous line, include use Red::Green::Blue;. This tells Perl to find path/Red/Green/ for all paths in @INC, including dir.
When this will not work -
  • If you get the error Can't locate loadable object for module qwe, then the module is a non-pure Perl module and uses external code (e.g. C code), which should come in a .so file.
  • The easy way is to do sudo cpan Red::Green::Blue and install the module.
  • If you do this, sure to remove the file dir/Red/Green/ so that Perl does not use it instead of the installed module.

    Thursday, February 4, 2010

    Perl tips - Unicode

    First, use Encode;

    • $string = Encode::decode('UTF-8',$text); (assuming the input file (or STDIN) is encoded in UTF-8).
    • You can now handle $string as you would normal strings (e.g. split(//) will split it at character boundaries)
    • Do $text = Encode::encode('UTF-8', $string); before writing it out to file (assuming you want the output file (or STDOUT) in that encoding).
    • \p{L} - full glyph (e.g. the letter 'A')
    • \p{M} - partial glyph (e.g. the accent ` on the letter 'A', giving 'À')
    • \p{N} - digit
    • \p{P} - punctuation
    • \p{kannada} - any Kannada character
    • \P{} - invert the condition
    E.g. to match a line if it contains no numerals and no punctuation do
    $line ~= m/\p{N}|\p{P}/

    Backup and restore using SimpleBackup

    I am using SimpleBackup for backing up my home directory. Download the utility and extract into some directory. Then do the following -

    • First, cd to that the SimpleBackup directory.
    • Run simplebackupconfig. You get a dialog where you can configure some stuff - mainly, the directories to be backed up, and the directories to be excluded from backup, and the directory where the backup files (which will be in .tar.gz form) should be stored.
    • Change the script bkup at line if [ $intdayofwk = 1 -o ! -e "$timestampfile" -o $lastfullbkage -gt 7 ]; to e.g. if [ ! -e "$timestampfile" -o $lastfullbkage -gt 30 ]; to do incremental backup unless it has been 30 days since the last full backup.
    • Decide on the directory or file to restore. cd to /. Run tar -xzf bkupfile.tar.gz --anchored "home/gtholpadi/Desktop/Files/some/dir".
    • This will create the directories home, gtholpadi etc. till dir, and also the directories in dir, if they don't already exist.
    • If extracted files already exist, they are overwritten.
    • Other files are kept intact.
    • Replace dir with file to extract file.

    Update: I have now moved to rsync.

    Wednesday, February 3, 2010

    Perl tips - array of records, command line params, STDIN/STDOUT handles

    set of records or 2D array
    • To store a set of records, use  my @data; $data[i]->[j] = $someval; (ith record, jth field). This basically works similar to a 2-D array except that each row can have different size.
    • To sort the records based on column j, do @sorteddata = sort {$a->[j] <=> $b->[j]} @data;.
    Command line parameters
    • The format for specifying parameters is cmd OPT1=sth OPT2=sth ...
    • Use while(@ARGV){ if(m{OPT1=}){ use $'; }elsif(m{OPT2}){...}}.
    • Use $opstream = *STDOUT; (note the '*') to pass (both read and write) file handles around and use them via variables (e.g. print $opstream "qwe";).
    • To get floor of a number, do use POSIX; $val = POSIX::floor($num);.

    Perl tips - creating your own utility library using classes

    - Creating your own library of utility functions
    • Create a file
    • For each new class in it, start with package MyUtils::MyClass.
    • Create static class attributes using our $attr.
    • Create methods using sub meth1{ my @args = @_; ... }. If this will be used as an object method (not static), remember to treat first entry of @_ as reference to object.
    • Object is nothing but a normal data type (like hash or list) and is allocated in the new method (that you must define) and returned.
    • The new method should be like sub new {my ($class, $otherargs) = @_; my ;...; my $ref_to_somedata; bless , $class; return $ref_to_somedata;}.
    • Start with package MyUtils::MyClass::MySubClass to create a subclass.
    Accessing your library
    • First include use lib "path/to/dir/containing/"; use MyUtils; in the beginning of the .pl file.
    • Use MyUtils::MyClass::meth1 to access static methods.
    • Use $MyUtils::MyClass::attr to access static attribute $attr of the class (note the $).
    • Use MyUtils::MyClass->new(...) to create an object.
    • Use MyUtils::MyClass::MySubClass wherever you are using MyUtils::MyClass for subclasses.
    Other useful stuff
    • Use $ENV{env_variable} to access the value of environment variable $env_variable in Perl code, (useful for specifying "path/to/dir/" of .pm file).

    Some LaTeX tips

    - Useful commands
    • \footnote{} for adding footnotes in text (numbered)
    • \titlenote{} for adding footnotes to titles, subtitles etc. (*, dagger etc.)
    • \bibliographystyle{abbrv} to get short author names in the References
    • \bibliography{<.bib file>}
    • \fbox{} for enclosing text within a box 
    • To get a new line/line break after the paragraph title, use \paragraph{}\<space>\\
    • To hyperlink text, use \href{}{link text} (uses thepackage hyperref)
    - About \begin{figure}
    • \begin{figure/table}[h] - the [h] will try to force the figure/table to appear at that place in the text
    • \epsfig{file=sth.eps, scale=0.25} - quick way to include .eps image.
    • Ensure that label comes immediately after caption, i.e. stick to the order: \caption{}\label{}\end{figure} when including figure. [Updated]
    - Numbering parts of figures
    • Add \usepackage{subfig}
    • Put \subfloat[]{ \label{} \epsfig{}} \subfloat{...} ... within \begin{figure} ... \end{figure}
    - About table/tabular
    • Use \begin{center}\begin{tabular}... if u dont need full-fledged table
    • If u have \begin{tabular}{|c|c||c|c|c|}, use \multicolumn{2}{|c||}{text} & \multicolumn{3}{|c|}to merge the first 2 and the next 3 columns.
    • Use longtable instead of tabular to allow the table to be split over two pages.
    - For multiple authors, use this -
    auth1 \and auth2 \and auth3 \and auth4 \and

    \email{\texttt{\{auth1,auth2, auth3, auth4\}}}
    -To spell check TeX files, use command ispell <.tex file>.

    Some things I learnt about paper writing

    Start writing sections with Experiments, work backwards till intro, then write conclusion, and then abstract and title.

    - make it crisp!
    - Abstract, Contributions, Conclusion.
    • State the exact work done in these sections. All three must be in sync.
    • Contributions: only what we have done, what is new (not how good it is); at the end, add a paragraph about paper organization.
    - Experiments
    • First describe data, then the method, then the results.
    - Highlighting
    • give names for systems you have built
    • make sure you highlight the good stuff (in boxes, by putting them in headings, etc.)
    • section headings should be informative; reader shoud be able to flip thru the paper and zero in on the crux of the paper
    - Checks
    • double check notation - should be introduced properly, be simple, and consistent
    • Diagrams should stand on their own (reader should not have to go through the text to understand
    • give the right keywords and categories (will determine who will review the paper)
    • for categories, refer to ACM’S COMPUTING CLASSIFICATION SYSTEM
    - Others
    • inline equations to save space
    • take the reader smoothly thru the paper; she should never get confused.
    • the first page is very important