Monday, January 17, 2011

getting Skype to work on opensuse as a user

Skype is still only provided as a 32 bit binary and that is rather upsetting, because opensuse doesn't ship libXv as a 32 bit build by default. So if it fails because of that install xorg-x11-libXv-32bit (and any other stuff it wants).

If however you aren't root, then you are a little on your own. I got it working with the following
  1. Grab a 32 bit libXv from somwehere, e.g. here
  2. Unpack it. In my case like this: rpm2cpio xorg-x11-libXv-32bit-7.5-1.8.x86_64.rpm | cpio -idmv
  3. Now push that libXv.so.1 some place sensible (I recommend ~/.local/lib)
  4. Export LD_LIBRARY_PATH="$HOME/.local/lib/" or appropriate
  5. Start skype from within the reach of that export e.g. the same shell
Steps 4 and 5 have to be redone every time, so you might as well make a script out of it
All of this can be automated of course and is just a pointer for poor souls like me that take longer than 10 minutes to figure this out.

Thursday, January 13, 2011

Tex Font Catalogue

This is a most excellent find:

http://www.tug.dk/FontCatalogue/

Saturday, January 8, 2011

Latex Wrapperclass

When you define a new class in latex you most unlikely want to start from scratch. This is of course not a problem, you can easily inherit another documentclass. Problems tend to start if you also need to react on an option of the class as well. The example shows the easiest way i know of:

\NeedsTeXFormat{LaTeX2e} 
\ProvidesClass{myartcl}[2010/01/06 This is so 2010!]
\RequirePackage[unknownkeysallowed]{keyval} 
%set up the function for finding doublesided as an argument 
\define@key{keygroup}{doublesided}[true]{% 
  % Do whatever you need to here 
  \PackageWarning{myartcl}{Found doublesided #1}% 
} 
% and we pass it on to the keyval parsing algo 
\DeclareOption*{% 
  \edef\act{\noexpand\setkeys{keygroup}{\CurrentOption}}\act% 
  \PassOptionsToClass{\CurrentOption}{article}% 
} 
\ProcessOptions\relax 
\LoadClass{article} 

Saturday, January 1, 2011

Optional Arguments in Latex Functions, Style and Class Files

I just wrote my first own latex package and as usual i was rather aiming for the stars than KISS.
The last big issue was finding out how to have optional package arguments that take a value (think geometry's left).

First: 
How to have functions with more than one optional argument or named optional arguments: Turns out not to be too complicated in the end. First you need the package keyval which enables you to parse key=value style arguments and then you need to understand how it works (the doc is aweful imho). Set up your parsing functions with something like

\define@key{keygroup}{keyname}{\dostuff{#1}}

this defines an option keyname that takes an argument, that has to be provided if the key is used.
Example: 
\define@key{keygroup}{color}{\domorestuff{#1}}

You can also define an optional argument that has an optional value that gets used when none is provided with the following syntax

\define@key{keygroup}{keyname}[default]{\dostuff{#1}}

 This lets you for example define a length type argument like follows:

\define@key{head}{width}[\textwidth]{\def\@bannerwidth{#1}}

This would set \@bannerwidth to 5cm for width=5cm and to the width of the text otherwise.
 Now to parse an optionstring you need to pass it to \setkeys like this:

\setkeys{keygroup}{optstring}

So now in order to have a command with more than one optional argument (beware syntax is different though!)

\newcommand{\printbanner}[2][]{
    \setkeys{keygroup}{#1} 
    ....
}
and call it like so: 

\printbanner[width=18cm,color = red]{Other Arg}
 
Second:
I think keyval was written with functions in mind but that shan't stop us from abusing it for package options. Declare all your options that don't need keyval syntax first (it's easier than going through keyval). Afterwards set up the catchall handler with 

\DeclareOption*{\edef\@act{\noexpand\setkeys{keygroup}{\CurrentOption}}\@act}

The reason you need this is so you can delay the expansion of the arguments. This should be enough so you can 

\includepackage[width=18cm]{package}

Further Notes:
If you want a switch case like option have a look at the package ifthen.
A complete, minimal, working example is available here.