viernes, 24 de abril de 2009

Fully vim style linux (part 2) - Vim for latex

Writing documents with latex with vim is fairly pleasant because you have your usual maps available, and you can configure most things with scripts but, as always, someone has already done that (don't reinvent the wheel).

latex-suite


Latex-suite is a great and very complete set of plugins for vim that helps writting faster latex with vim. It has lots of options and configuration bits, but you only need to remember a tiny set of shortcuts to use it (at least at a beginner level)

Environment complete (F5) . you're in a document and you want to insert a tabular environment. Just type 'tabular' and press F5. a full tabular environment will be placed right there, with the appropiate number of params and placeholders (you can navigate to the next placeholder with ctrl-j).

Package inserting (F5): in the preamble section, if you press F5 after typing a word, latex-suite will enclose it into a \usepackage{word}
snipMate

Compiling (ll) : to compile a document, just press your leaderkey followed by 'll' (that's two 'els').

View the compiled doc (lv): just type leader lv to open your viewer program with your dvi/pdf file in it.

There are lots of other useful things in latex-suite. you can find further info in its website.

LaTeX::Table

Tabulars can go from the simplest things to fairly complicate structures. Let there be perl.

There's a small module named LaTeX::Table that helps us to make pseudo ascii tables, and put some options embedded in a comment, and it converts them to fully functional tables.

Try cpan:

sudo cpan LaTex::Table
It uses Moose (a great modern OOP system for Perl 5), so if you don't use perl regularly, cpan will probably install a big bunch of perl modules.

If you have any problem installing those modules from cpan, you can always install them (or at least, the one that fails) with the good old method:

perl Makefile.PL, make, make install

Now a usage example.

theme=Berlin;caption_top=1;caption=foo
one & Two & Three
CAN I & haz a & CHEEZBURGER
& OH & KTHX
FOO & bar & Baz
Just visually select it and apply the !ltpretty filter. You're done

Latexhelp

With latexsuite, there is a latex reference in vim help format, so you can access the syntax of latex commands easily in vim. It doesn't need additional configuration, provided you placed the latex reference file in your doc/ directory and ran helptags on it. Probably :helptags ~/.vim/doc will do.

you can find the separate doc files here.

vim config

There are lots of possible configurations depending on your workflow and/or preferences. My configs are just theese lines.

let g:tex_flavor='latex'
let g:Tex_CompileRule_pdf = 'pdflatex -interaction=nonstopmode $*'

More things

As you probably know, learning to use vim effectively has many paths to go, and what is useful for me, can be painful for you. You can combine plenty of other vim plugins to help you writting faster latex.

For example, using snippetsEmu/snipMate/whatever snippets plugin can be useful, using supertab can speed up your (general) writting, or even little maps like the ones explained in my previous post 'Fully vim style linux (part 1)' can enhance your typing experience.

Please post comments about comments/improvements, and I'll make the appropiate updates.

See ya in the next post.

little update

4 days after my first perl6 script. It's already outdated. You see, rakudo is a fast moving target.

Last thursday, parrot 1.1 was out, and it comes with lots of changes compared to parrot 1.0.

One of the strange syntax present in my last script, was a line like:
while my $tat = =$*IN { ... }

In that case, the first = is the well known assignation, and the second = was a prefix operator, that took the next element of the list that was preceeding.

= as a prefix operator has been deprecated in favour of '.get' function .

so that code, now would be like


#!/tmp/rakudo/perl6

sub printa_rusc($f, $c){

my $first = ' - ' x $c ;
$first.chop.say; #chop is non

my $top_line = '/ \_' x $c;
my $bottom_line = '\_/ ' x $c;

for 1..$f {
$top_line.chop.say;
$bottom_line.chop.say;
}
}

while my $tat = $*IN.get {
my @arr=$tat.split(/\s+/);
@arr.perl.say;
if 2==@arr.elems {
printa_rusc(@arr[0], @arr[1]); #not $arr[0]
} else {
"Bad format. Enter only 2 integers".say;
}
}

# vim: set tabstop=4 shiftwidth=4 foldmethod=marker ft=perl: ##
Nothing else for the moment

lunes, 20 de abril de 2009

My first perl6 dabblings

It's been a month since parrot 1.0 and now , rakudo is passing more than 3000 tests than then. It's an amazing progress IMHO.

I just started to write very simple scripts to get the feeling of perl6. This is my first one.

A script that gets 2 integers per row, and then prints a honeycomb of the given size (rows x cols)

it's a really simple script, but at least it gives little hints of how functions are called, strings printed, and STDIO read.


#!/tmp/rakudo/perl6

sub printa_rusc($f, $c){

my $first = ' - ' x $c ;
$first.chop.say; #chop is non destructive

my $top_line = '/ \_' x $c;
my $bottom_line = '\_/ ' x $c;

for 1..$f {
$top_line.chop.say;
$bottom_line.chop.say;
}
}

while my $tat = =$*IN {
my @arr=$tat.split(/\s+/);
@arr.perl.say;
if 2==@arr.elems {
printa_rusc(@arr[0], @arr[1]); #not $arr[0]
} else {
"Bad format. Enter only 2 integers".say;
}
}

# vim: set tabstop=4 shiftwidth=4 foldmethod=marker ft=perl: ##

We can see some strange things if we're used to perl5.

First the @arr[0] thing. In perl6, sigils are part of the symbol, so the @rray @arr will always be acessed as @arr[1], @arr[1..10] ,... it happens the same with %ashes .

chop is not destructive, meaning that returns a copy of what was choped, but it doesn't modify the given argument.

We see something like @arr.perl.say . As you probably know, .say is the method to print things followed by a "\n". print "hi", "\n" ; is the same as say "hi"; or "hi".say; .

For the moment there's not much more to say.

See the rakudo's progress at http://www.rakudo.org/status . today 23/04/09

To get rakudo, it's pretty easy: (from rakudo.org site)

$ git clone git://github.com/rakudo/rakudo.git

If you don't have git installed, you can get a tarball or zip of Rakudo from github by visiting http://github.com/rakudo/rakudo/tree/master and clicking "Download". Then unpack the tarball or zip.

Once you have a copy of Rakudo, build it as follows:

$ cd rakudo
$ perl Configure.pl --gen-parrot
$ make



That's all!

Thanks to parrot and rakudo devs for this new version of our favourite language

miércoles, 8 de abril de 2009

Installing Vectorlinux 6.0 light on Acer Aspire One

In this post I'm going to explain the whole process I followed to install vectorlinux 6.0 light on my AAO. One of the trickiest things is AAO doesn't have CD reader, so you have to manage everything through USB ports unless you have an external cd-reader.

Getting rid of Linpus


So you have a brand new AAO with our sucky linpus or WinXP (huh...). You probably want to have separate partitions for your root and /home directories, so we must have some partitions half ready for the installation. If you have 2 usb's
saf

Partitioning and installing
At the moment, I have vl standard and arch linux with a 1Gb swap partition and a 90Gb partition for home.

I've decided to replace vectorlinux standard for vl light. As I already have the partitioning, the installation will be pretty straight (I hope).
Time now -> 16:50

Getting vectorlinux light iso
To install vl from our archlinux partition we need mainly 2 things, the iso and vinstall-iso script.

To get the iso just open a terminal and type
wget http://vectorlinux.osuosl.org/veclinux-6.0/iso-release/VL6.0-Light-Final.iso
It's the same as browsing to http://vectorlinux.com/downloads and downloading the iso with your favourite browser.

vinstall-iso is the script that will allow us to install vl without any extra media (usb keys, cd...). The script is in the iso. We could mount it as a loop device and extract, but as we still have some time (the iso is just at its 21%) we'll gonna get it from somewhere.

googling for vinstall-iso leads us some results, one being from uelsk8s (vl dev) home directory @ vectorlinux servers. We can trust this file :)

wget http://vectorlinux.osuosl.org/Uelsk8s/iso-test/vinstall-iso
I placed both files in the archlinux partition, because we'll need them accessible from the other partition.

install

Time now -> 17:28

Let's install!
Reboot into the other live system you have. If you are installing from a bootable usb, you may have the iso into another usb key.

In archlinux, log in as root and
chmod +x vinstall-iso
./vinstall-iso VL6.0-Light-Final.iso

I got an error :
     mount: could not find any device /dev/loop#
This got fixed executing (as root)
modprobe loop
Back to the installation.

- In the first menu, I don't need to do any partition change so I choose directly to INSTALL , if you need to repartition that's the moment to select FDISK.

- Select SWAP . I usually bypass checking media (too slow for my impatience)
Usually you only have a swap partition, so chose what's by default

- Root partiton. I only give 5 gb to root partition. I don't need much software.
Filesystem: xfs . I usually choose reiserfs, but heard good things about xfs. Let's try it then ;)

- Optional partitions:
/home . I have a separate partition for /home
DONE

- Optional packages:
Serve yourself

Time now -> 17:48
...

Time now -> 18:02
When Vectorlinux tries to install lilo, it does not see archlinux partition, so I didn't install lilo. (I prefer to touch grubs menu.lst than lilo configs)

Reboot

Configuration

Configuration is pretty straightforward. Just select desired options.

Select 1024x600 resolution

Reboot

Time now -> 18:09 (it's getting fast)

Performance

Now we have a functional vl-light.

Wifi is working great sofar (there's no led, but it works).

Let's look at some numbers.

100Mb ram with a fully functional desktop. It's not bad :D

Booting goes around 30 seconds.