KBibtex in Ubuntu Oneiric 11.10

KBibtex is a useful bibtex bibliography management tool for the KDE desktop.
However, it seems that the package is missing in the Ubuntu 11.10 repositories.

A quick remedy (as tweeted here) is to install the package from the Debian Sid distribution: kbibtex.
To install on the command line (check the exact name of the .deb file)
sudo dpkg -i kbibtex_0.4-1_amd64.deb

Alternatively .deb packages can be installed in the GUI (e.g. by opening the file in Dolphin).

The package should be compatible with Ubuntu 11.10, and seems to work fine.

The 0.4 version has improved a lot and has a very useful online search tool for acquiring bibtex files. Google scholar and other data bases can be used.
Other tools include a reference preview (though bibtex2html) and a PDF preview.

Autocrop images with imagemagick

Often one has to crop excess margins from an raster image. Common image graphical editors have autocrop tool, but if many files need to be processed, opening and saving files one by one quickly becomes tedious.

A better solution is to use convert tool that is a part of the powerful Imagemagick toolkit:

convert image.jpg -trim -bordercolor White -border 20x10 +repage cropped_image.jpg
This command reads the original file, removes (trims, crops) white borders, adds 20 pixel white borders horizontally and 10px vertically, and stores the file as cropped_image.jpg.

It is also possible to process all image files in the current directory with the following one line command:
for i in `ls *.jpg`; do convert $i -trim -bordercolor White -border 20x10 +repage cropped_`basename $i`; done

If you want to convert to another image format, it can be done conveniently at the same time (-quality option controls the jpg quality):
for i in `ls *.gif`; do convert $i -trim -bordercolor White -border 20x10 -quality 92 +repage cropped_`basename $i gif`jpg; done
Above basename utility is used for trimming suffix from the file name.

Extract images from a pdf file

In Linux pdfimages utility extracts raster images from a pdf file.

Extract all raster images from pdf file, save in jpg format (creates bar-000.jpg, bar-001.jpg, etc.):
pdfimages -j file.pdf image

The -j option is to convert the images to jpeg format if possible.
Other options can be found in the manual.

Using wget to download multiple files from a website

The following command downloads all files pdf files from http://www.host.com/some/path/ to currenct directory
wget -r -l1 -nd -nc -A.pdf http://www.host.com/some/path/

The options are:
-r Makes it recursive for subfolders
-l1 set maximum recursion, 1 levels of subfolders
-nd no directories — copies all matching files to current directory, discards directory information
-nc Do not download it file already exists
-A.pdf Accept only certain files (with pdf suffix in this case). Specify comma-separated lists of file name suffixes or patterns.

Script for downloading bibtex file using DOI

Digital Object Identifier (DOI) and bibtex files are common for anyone citing scientific articles. The DOI is used to uniquely identify any object, such as an electronic document, while bibtex is used to cite an article in Latex environment.

An article can be found on the internet via the address dx.doi.org/ followed by the DOI, e.g. http://dx.doi.org/10.1016/j.ocemod.2004.08.002. However, it takes a while to browse the publishers website, locate the appropriate bibtex file and save it to disk.

Here is a very handy Python script that fetches a bibtex file from NASA’s Astrophysics Data System using the article’s DOI.

It requires Python Beautiful Soup XML/HTML parser.
In Ubuntu-like linux distributions it can be installed easily:
sudo apt-get install python-beautifulsoup

Example:

>>doi2bibtex.py 10.1016/j.ocemod.2004.08.002
@ARTICLE{2005OcMod...9..347S,
author = {{Shchepetkin}, A.~F. and {McWilliams}, J.~C.},
title = "{The regional oceanic modeling system (ROMS): a split-explicit, free-surface, topography-following-coordinate oceanic model}",
journal = {Ocean Modelling},
year = 2005,
volume = 9,
pages = {347-404},
doi = {10.1016/j.ocemod.2004.08.002},
adsurl = {http://adsabs.harvard.edu/abs/2005OcMod...9..347S},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}

Fixing screen brightness keys in MacBook + Ubuntu 10.10

After upgrading to Ubuntu 10.10 natty, the keyboard backlight keys and screen brightness keys did not work in macbook pro.

Solution:
Make sure that Mactel-support PPA repository in enabled. It is usually deactivated during the upgrade process.
Install nvidia-bl-dkms package:
sudo apt-get update 
sudo apt-get install nvidia-bl-dkms

Installing 32-bit MATLAB on 64-bit Linux (Ubuntu)

Currently 64-bit Linux distributions are stable and well established so there are virtually no problems in opting for a 64-bit system.
However, some MATLAB Linux versions, notably the student version, only exists in 32-bit and it is not so obvious to get it installed in 64-bit Linux environment.

Here’s how I got it done (MATLAB R2009a in Ubuntu 10.04 Lucid):
1) Install some 32-bit libraries:
sudo apt-get install ia32-libs lib32ncurses5
2) Mount the CD (e.g. open the content in a file manager)
3) Install MATLAB, force to use the 32-bit executable:
sudo /media/cdrom0/install_unix.sh -glnx86
Install matlab to some convenient place, typically /usr/local/matlab (assumed here).
The installation will fail, complaining about 64-bit java.
4) Fix the java problem (change the path according to your installation):
sudo ln -s /usr/local/matlab/sys/java/jre/glnx86/ /usr/local/matlab/sys/java/jre/glnxa64
5) Register your matlab
sudo /usr/local/matlab/bin/activate_matlab.sh
6) You can now run MATLAB:
matlab -glnx86

KDE touchpad configuration disabled in Kubuntu Maverick

After upgrade from Kubuntu Lucid 10.04 to Maverick 10.10 the touchpad configuration was disabled in KDE system settings (System settings -> Input devices -> Touchpad). All the controls were disabled, the “Informations” section reading “Touchpad Name: Device not found”.

I have Apple Macbook Pro (macbook5,5) which uses bcm5974 driver. Apparently the driver is included in the recent linux kernels, but it can also be installed from the Mactel Support repository. First thing to do is to check if the drive is loaded in the kernel:
lsmod | grep bcm5974
If the command doesn’t print anything, you need to install the driver.

If the driver is installed, like in my case, but the KDE configuration is still disabled, check if xserver synaptics package is installed:
sudo apt-get install xserver-xorg-input-synaptics

The KDE touchpad configuration module is provided by the package kde-config-touchpad.

Linux audio: Device or resource busy

Usually audio playback causes no problems in Linux, but sometimes audio vanishes suddenly and you cannot get playback until you logout/restart the system. Here’s how you can restore audio playback without restarting.

Usually the problem is caused by a crashed program that is still using the audio device preventing other processes accessing it. If you run a playback software from the command line (e.g. vlc foo.mp3) you typically see an error like:
/dev/dsp: Device or resource busy

The solution is simple, you just need to identify the runaway process and kill it. Command
lsof | grep snd
gives a list of candidates that might be occupying the audio device. These can be terminated by
killall program_name or kill PID, where PID is the process ID shown in the second column of lsof output.

Linking shared libraries: overcoming runtime errors

Say you’re developing a program in C++ and you need to use some exotic library called libAAA.
You have been able to download the sources and build the package ( by adding -I/path/to/the/library/include to the compilation options, for example) and linking it ( by adding something like -L/path/to/the/library/lib -lAAA to the linker options, for example).

But running the program raises an error:
>>./program_a
./program_a: error while loading shared libraries: libAAA.so: cannot open shared object file: No such file or directory

This is due to the fact that although you have informed the compiler and the linker about the location of your libAAA files, the system cannot find them at runtime. In fact, the program_a would call a dynamic linker that searches for shared libraries in the system. It, however, searches only in default locations where libraries are commonly installed (such as /usr/lib).

You can check the dynamic libraries by invoking ldd command on the executable:
>>ldd program_a
linux-gate.so.1 => (0xb7f48000)
liblapack.so.3gf => /usr/lib/liblapack.so.3gf (0xb7836000)
libAAA.so => not found
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb76c4000)
/lib/ld-linux.so.2 (0xb7f49000)

Here it is clearly seen that the linker cannot find the library. A remedy is to add the custom library path to the LD_LIBRARY_PATH environment variable (this example is for bash shell):
>>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/the/library/lib

Now the library can be located at runtime:
>>ldd program_a
linux-gate.so.1 => (0xb7f48000)
liblapack.so.3gf => /usr/lib/liblapack.so.3gf (0xb7836000)
libAAA.so => /path/to/the/library/lib/libAAA.so (0xb77da000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb76c4000)
/lib/ld-linux.so.2 (0xb7f49000)

Another option is to do a manual system-wide install by copying the library to /usr/lib, for example, or modifying the dynamic linker look-up path (in file /etc/ld.so.conf). Naturally such problems should not appear if the library is well-built so that make install will do a system-wide installation automatically.

More information can be found in here for instance.

Follow

Get every new post delivered to your Inbox.