Thursday, April 10, 2008

Using Imaxima with Texlive in Gentoo Linux

Imaxima is an Emacs extension to interface with Maxima (see here for a nice tutorial). To use it, one need a LaTeX distribution. However with default Texlive installation in Gentoo, imaxima cannot work. Following is a sample session:

(%i1) integrate(x,x);
LaTex error in: \ifracn{x^{2}}{2}

The problem here is that there is another package breqn needed. Breqn is inlcuded in Texlive package texlive-mathextra, which is not installed when you emerge texlive. The package is also masked by default, therefore you need to unmask it before emerging. Following is a list of commands to install the package (substitute x86 with amd64 for x86-64 systems).

# echo "dev-texlive/texlive-mathextra ~x86" >> /etc/portage/package.keywords
# emerge texlive-mathextra

After installation, fire up your Emacs and enjoy (I)maxima!

Update: if you are not comfortable with the default equation size (as in my case), you can add the following line into your .emacs (adjust the number to suit your own taste):

(setq imaxima-scale-factor 2.0)

Tuesday, April 8, 2008

Copy and Paste between Windows and Linux

Many people use Windows as primary working machine and login to remote Linux/Unix (we will use Linux as shorthand afterwards) boxes. There are times when we need to copy and paste information between Windows and Linux. Below we are going to discuss convenient ways to do so.

Tools

PuTTY and Xming are two popular programs to run in Windows host to facilitate communication to Linux. PuTTY provides console connection while Xming X Window connection. For Xming, Ensure you start Xming with parameter -clipboard (which is enabled by default). Our discussion below is focused on how to copy/paste within PuTTY/Xming. Copy/paste for other Windows applications is quite general (Ctrl+C and Ctrl+V) and should be familiar to the reader, therefore omitted.

Ways

PuTTY

Copy to clipboard: click-and-drag to highlight. Just select, no need to press any key.

Paste from clipboard: right mouse button.

Xming

For Xming applications, copy/paste follows the X window standard as discussed below.

Copy to clipboard: click-and-drag to highlight. Same as PuTTY.

Paste from clipboard: middle mouse button.

Monday, April 7, 2008

Installation of Gentoo Linux 2008.0 Beta 1 with LiveCD

I just started yet another process of installing Gentoo Linux, and following is my record of the installation step by step. Previously I preferred to install from stage 1/3 following this guide. I decided to try LiveCD this time.

1. Boot the machine.

Download the 2008.0 LiveCD from here. Burn the CD and boot the machine with it.

Caveat: in my case, the boot process is stalled. I solved it (according to this article) by appending kernel options during GRUB screen (press e to edit and append all-generic-ide irqpoll pci=nommconf).

2. Installation.

After boot, I click icon "Gentoo Linux Installation (GTK+)" in the desktop.

Partitioning: I selected Recommended Layout.

Local Mounts: accept the defaults without any changes.

Timezone: Asia/Shanghai.

Networking: Dhcp is used. Appropriate host and domain name are provided.

Users: Just add the regular user for daily usage.

Extra Packages: I selected screen and slocate. In my first installation I also selected xorg-x11, gdm, firefox etc. However the installation simply failed when emerging x11-apps/xinit (and I cannot rescue the system since even /etc/fstab is not correctly setup), therefore my second try is quite conservative.

Startup services: I selected sshd.

Other Settings: Although I have not installed X11 or Gnome yet, I selected as following:

  • Display Manager: gdm
  • Clock: local
  • XSession: Gnome

3. Post Installation.

This section is similar as what I have described for coLinux (see here), but is modified specifically for a standalone Gentoo Linux installation.

3.0 Tiny Cleanups.

After rebooting, perform the following steps. Note that if your system was stalled as described before, you can use same trick in GRUB screen and you should add the kernel options to /boot/grub/grub.conf after login.

To avoid some warning, you might need to perform following steps.

# mkdir -p /usr/local/portage

To change host name (according to Gentoo Handbook), edit file /etc/conf.d/hostname, if you call your coLinux machine as tux, then set the following line.

HOSTNAME="tux"

In addition, remove string .\O from file /etc/issue to get rid of the annoying unknown_domain in the welcome message "This is host.unknown_domain ...".

3.1 Network

We have already specified using DHCP. It works but the configuration files is using old syntax. Let's clean it up to avoid future complaints. Edit file /etc/conf.d/net as follows.

config_eth0=( "dhcp" )
3.1.1 Proxy

If you connect to Internet directly, you can skip this section.

To use proxy server, add the following lines into /etc/env.d/99local:

http_proxy="http://proxy.server.com:8080"
ftp_proxy="http://proxy.server.com:8080"

Replace the port and domain name according to your situation. Then run:

env-update && source /etc/profile

3.2 Add additional locales

Modify file /etc/locale.gen, select appropriate locales. For me, the locales are:

en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8

Then run command locale-gen.

3.3 Modify /etc/make.conf

This is specific for your computer type and other factors. Following is my configuration (I'm using a Core 2 Duo CPU). Please refer to Gentoo documentation for your own reference. GENTOO_MIRRORS reflects the fastest mirrors for my connection, as discussed below.

CFLAGS="-march=nocona -O2 -fomit-frame-pointer -pipe -fno-ident"
CXXFLAGS="${CFLAGS}"
CHOST="x86_64-pc-linux-gnu"
LDFLAGS="-Wl,-O1"
MAKEOPTS="-j3"
ACCEPT_KEYWORDS="amd64"
FEATURES="parallel-fetch"
LINGUAS="en zh zh_CN"
INPUT_DEVICES="keyboard mouse"
VIDEO_CARDS="i810"
PORTDIR_OVERLAY="/usr/local/portage"
GENTOO_MIRRORS="http://ftp.iij.ad.jp/pub/linux/gentoo/ http://ftp.kaist.ac.kr/pub/gentoo/"

USE_DEV="bash-completion doc emacs latex ruby sbcl source spell"
USE_HW="cpudetection mmx sse sse2"
USE_LIB="curl gd glibc-omitfp ncurses readline zlib"
USE_MM="aac alsa encode ffmpeg flac midi mp3 ogg pulseaudio quicktime theora xvid"
USE_PIC="gif jpeg png raw svg tiff xpm"
USE_SECURITY="crypt pam ssl tcpd"
USE_SW="bzip2"
USE_SYS="cjk nls nptl nptlonly opengl truetype unicode xinerama xml"
USE_X11="cairo gnome gtk X xft xorg"
USE="-* ${USE_DEV} ${USE_HW} ${USE_LIB} ${USE_MM} \
     ${USE_PIC} ${USE_SECURITY} ${USE_SW} ${USE_SYS} ${USE_X11}"

3.4 Synchronize Portage

Use either emerge --sync or emerge-webrsync -v to update the portage.

3.5 Mirror selection

First run emerge mirrorselect. To select the fastest mirror. I use the following command mirrorselect -D -H -s2 to select the mirror. It means that:

  • -D: actual file will be downloaded from the mirror to test speed.
  • -H: test http mirrors only.
  • -s2: only select 2 mirrors.

After running the command, original /etc/make.conf will be backed up as /etc/make.conf.backup and your selected mirrors will be reflected in make.conf. Type mirrorselect -h for details.

3.6 Update system

Run the following suites of commands (we need the -p argument to check what the commands are supposed to do since they're somehow "dangerous"):

emerge -uDNpv world
emerge -uDNv world
emerge --depclean -pv 
emerge --depclean -v
revdep-rebuild -pv
revdep-rebuild -v

Caveat: if you encounter circular dependency when emerge -uDNv world, try to remove gtk USE flag from /etc/make.conf. After successful emerging, add gtk flag again and run emerge -uDNv world again.

After update, run dispatch-conf to update the configuration files.

3.7 Install X11 and GNOME.

Run command emerge xorg-x11 to install X11. Then use xorgcfg -textmode to configure X server.

I'm using a LCD with resolution of 1680x1050, which is not listed in standard configurations. To use it, first run gtf 1680 1050 60, copy the output to the Monitor section of /etc/X11/xorg.conf, and modify section Screen to the resolution 1680x1050.

For GNOME, I prefer to install gnome-light to avoid the gigantic full GNOME installation. To do so, simply run emerge gnome-light.

If one use startx to run X11, one can simply type echo "exec gnome-session" > ~/.xinitrc to configure so.

To make gdm the default login screen, run the following commands:

# emerge gdm
# rc-update add xdm default

And then edit /etc/conf.d/xdm, changing DISPLAYMANAGER to gdm.

3.8 Install Other programs.

This section is left empty intentionally :-)


Conclusion

It is quite convenient to install with LiveCD. There are some hassles during installation, but I assume the reason is that I'm using a beta version. Since beta version is not stable, my suggestion is to install minimal components therefore you can quickly finish the installation and boot from hard drive.

Although GRP install is not so optimal, the pre-compiled packages should be quite close to optimal ones for 64-bit machines. Also as a Gentoo user, I'm always in the process of customization the OS to suit my needs, therefore a not-so-ideal-initial-setup is not an issue. In summary, livecd approach can save a lot of time, with almost similar end result as installing from stage 1/3.

Ripping CD to FLAC in Gentoo Linux

This post is just a simple note, inspired from here.

First, install cdparanoia and flac:

# emerge cdparanoia flac

Next, issue the following commands (I deleted the original WAV files after conversion). All tracks are extracted and converted to FLAC format.

# cdparanoia -B
# find . -name "*.wav" -print0 | xargs -0 flac
# rm *.wav

Then enjoy the music with your favorite player. Since I'm using mplayer, I call Ruby to generate the playlist and invoke mplayer with it (in the 1st line below, the last track number is 16. Change it according to your own situation).

$ ruby -e '(0..16).map{|i| printf("track%02d.cdda.flac\n", i)}' > pl
$ mplayer -playlist pl

Wednesday, April 2, 2008

Enable Sound for coLinux

In my previous post about installing coLinux with Gentoo, audio part is not touched. Here comes the solution on how to use PulseAudio to bridge coLinux to sound world. This is adapted from here with contents modified for Gentoo Linux.

Windows side

We need to install PulseAudio server on Windows. Frist download binaries for Windows from here. Extract to one directory (c:\bin\pulseaudio in my case).

In the directory of the binaries, create a text config file named default.pa with the content:

load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.0.0/24
load-module module-esound-protocol-tcp auth-ip-acl=127.0.0.1;192.168.0.0/24
load-module module-detect

We start PulseAudio automatically when coLinux starts, by adding the following line to the coLinux configuration file:

exec0=c:\bin\pulseaudio\pulseaudio.exe

Linux side

Install and configure PulseAudio client

Install PulseAudio by emerge pulseaudio. Then edit /etc/pulse/client.conf to set the address of the Windows host that runs the PulseAudio server:

default-server = 192.168.0.1

where 192.168.0.1 is the IP address of the Windows host.

Make sure to add USE flag alsa to /etc/make.conf. If you just add this USE flag, update your system with emerge -uDNv world. ALSA would be automatically emerged.

Install alsa-plugins

In addition, we should install alsa-plugins:

# echo "media-plugins/alsa-plugins pulseaudio" >> /etc/portage/package.use
# emerge alsa-plugins

Edit ~/.asoundrc with the following contents.

pcm.!default {
    type pulse
}

ctl.!default {
    type pulse
}

pcm.pulse {
    type pulse
}

ctl.pulse {
    type pulse
}

Test

As a final step, you can test with an ALSA player:

aplay /usr/share/sounds/alsa/Front_Center.wav

You should hear a voice saying "Front Center". Enjoy!