tech log on gentoo, linux, and random stuff

TeX capacity exceeded

leave a comment »

After the discovery of gnuplot’s tikz term, I have been using it for most of the plots I send to my advisor. A very nagging problem though is that when the number of data points is big, pdflatex would complain about “TeX capacity exceeded, sorry [main memory size = xxxx]” and refuse to compile. Today it has just come to a point I can’t stand this any more, so I did some googling and found a solution. Now TeX is a very messy system with fmt, sty, cnf files all over the place, so be sure to backup anything you touch in case something goes wrong.

Here’s a web page from JadeTeX that pointed me in the right direction, http://jadetex.sourceforge.net/#index-div-d18e113. The following solution is based on this.

  1. make changes to texmf.cnf. You may want to use `locate texmf.cnf’ to find where it is. Then in it, change `main_memory’ from 3000000 to say 8000000
  2. now regenerate latex.fmt for plain latex, or pdflatex.fmt for pdflatex. E.g., to recompile pdflatex.fmt:
    1. find where “pdflatex.ini” is
    2. cd to that path, then invoke “pdflatex -ini -progname=pdflatex pdflatex.ini”
      Notice that this is different from what’s in the JadeTeX webpage. You need to invoke “pdflatex” instead of “tex”
    3. now find where the original “pdflatex.fmt” is, back it up, and copy the generated “pdflatex.fmt” to there
  3. to regenerate “latex.fmt”, use “latex -ini -progname=latex latex.ini


In gentoo, the proper way of fixing this once and for all is:

  1. Change the value of the corresponding field in file /etc/texmf/texmf.d/20sizes.cnf. This should persist through all future texliveupgrades.
  2. run texmf-update to regenerate the system-wide texmf.cnf
  3. run fmtutil-sys --all to regenerate the .fmt files


alternatively one can compile with lualatex, which doesn’t seem to have a size limit

Written by zsh

February 23, 2011 at 2:37 pm

firefox segfaults after zlib upgrade

leave a comment »

After some emerging, my firefox suddenly started segfaulting everytime. The worst part of a segfault is you don’t get anything useful out of it, no error message, etc. A backtrace in gdb shows the problem is from a recent upgrade of sys-libs/zlib, and google says it’s an old problem, and as usual, gentoo devs refuse to fix it (maybe for a good reason, but who cares).

Some more googling brought me to this gcc ML post. The solution is simply to add -mstackrealign into your /etc/make.conf. Re-emerge zlib then solves the problem.

Written by zsh

February 5, 2011 at 1:39 pm

quick notes on using gnuplot’s lua terminal

with one comment

In gnuplot,

set term tikz fulldoc color solid createstyle
set output 'tmp.tex'
p x**2 tit '$x^2$'

then in shell,

pdflatex tmp.tex

(1) ‘createstyle’ is crucial, otherwise tex will complain about missing ‘gnuplot-lua-tikz.sty’. This doesn’t seem to be mentioned in the first several google results
(2) I have to comment out the ‘utf8x’ package in the resulting tmp.tex. That may just be a problem with my tex environment

Written by zsh

January 22, 2011 at 12:50 pm

Posted in /usr/bin

Tagged with , , ,

migrating gentoo to a new partition

leave a comment »

quick note to myself, copy with caution..

mkfs.ext4 /dev/sda2
mount /dev/sda2 /mnt/newgentoo
cp -xavv / /mnt/newgentoo/
# -x is used b/c I have some dirs as mount points of fs on other disks
cd /mnt/newgentoo/dev
# need /dev/console and /dev/null for a successful boot
# otherwise will get an error of "unable to open an initial console"
# cf. http://www.gentoo.org/doc/en/udev-guide.xml, 3. Known issues
mknod -m 660 console c 5 1
mknod -m 660 null c 1 3

and finally, don’t forget to change /boot/grub/menu.lst and /mnt/newgentoo/etc/fstab

Written by zsh

December 5, 2010 at 8:28 pm

gnuplot: different color on different segments of a curve

leave a comment »

I’m not sure what’s the proper description, but here’s a task at hand and how it is done in gnuplot:

suppose I have a datafile with 3 columns. I can plot columns 1 and 2 as a curve:

gnuplot> p 'datfile' u 1:2

In my problem, the 3rd column indicates whether the entry is “localized on the left side”, which will have abs($3)>1, or the “right side”, having abs($3)<1. I want the curve to be plotted in one color (say red) for the “left side” segment(s), and another color (say green) for the “right side” segment(s)

somewhere in gnuplot’s manual, it says it will silently drop data if they are unplottable, and gives an example that 1/0 is unplottable (division by zero). so here’s the idea:

define the “above” and “below” function:

gnuplot> above(x,a) = x > a ? 1 : 1/0
gnuplot> below(x,a) = x < a ? 1 : 1/0

then I can use them to pick out the left/right segments:

gnuplot> p '' u 1:($2*above(abs($3),1)) w l lt rgb 'red' lw 2 tit "localized to the right"
gnuplot> rep u 1:($2*below(abs($3),1)) w l lt rgb 'green' lw 2 tit "localized to the left"

there is a minor problem: for data files, the segments with different colors are always separated by a small gap b/c neither above nor below would cover that gap. Haven’t thought about how to solve this yet, probably a clever redef of above and below could do the job.

Attached is some real world example.
colored segments

Written by zsh

November 29, 2010 at 12:41 am

Posted in /usr/bin

Tagged with , ,

network printing on gentoo

leave a comment »

1. emerge cups. leave all conf files as-is

2. emerge foomatic-db-ppds, equivalently just download the ppd file corresponding to your printer (the one in my office is lexmark c543dn)

3. add yourself to the groups lp (for printing) and lpadmin (for using web interface to configure cups)

4. start cupsd (e.g., add it to the default run-level), then visit https://localhost:631

5. add printer from within the web interface. For the lexmark mentioned above, locate the corresponding ppd file installed in step 2. The network address should be socket://ip-address-of-the-printer (I googled and saw on one lexmark official page that the printer should be accessed through the port 9100, which from the cups manual should have socket:// in its URI)

6. I also queried the printer’s default printing options from within cups web interface b/c the default option used by cups doesn’t utilize the duplex feature of the printer.

7. now just use lpr -P&lt printer name &gt to print (e.g., from the gtk printing dialogue box). &lt printer name &gt is the name you used in step 5 when adding the printer.

Written by zsh

November 21, 2010 at 12:43 am

Posted in gentoo

Tagged with , , ,

adding an ssh tunneling account to dd-wrt

with 2 comments

A server I helped to setup recently has its OS re-installed, and I
know that because I can no longer log onto it. I used to have an
ssh-tunneling account set up on that server too for people who need to
reach outside a certain great firewall, and it’s also gone with the
revamp–my father being one of the users. So I decided to add an
ssh-tunneling account to my router (with dd-wrt)

What I need is the public key of whoever is going to use it, in this
case my father’s–alternatively I can also make a pair of
private/public keys and distribute the private key to the target
users, but that kind of defies the purpose of a “private” key.

All I need to do is to put the following snippet into my router’s
startup script, which can be modified from the web interface of
dd-wrt: administration -> commands.

The code goes as

mkdir -p /tmp/tunnel/.ssh
# somehow, /bin/false doesn't work
echo "tunnel:*:401:10:User,,,:/tmp/tunnel:/bin/sh" >> /tmp/etc/passwd
echo "public-key-content" >> /tmp/tunnel/.ssh/authorized_keys

and replace public-key-content with the content of a
desired public key (or several).

And the last thing is to ask the end user to log onto your server once
in case the server’s key fingerprint is not yet in
his/her ~/.ssh/known_hosts

Now conjure up the magical ssh -Nf -D9999

Written by zsh

August 9, 2010 at 5:30 pm

Posted in no cat is good cat

Tagged with ,

Exporting Yamaha YPG-635 recorded songs to wav via AV-710 Line-in jack

leave a comment »

I recently bought myself a Yamaha YPG-635 digital piano. It saves
recordings internally as SMF (Standard Midi Format) files. While
that’s good if you want to do some further midi sequencing, I don’t
yet feel the urge to properly set up a linux midi workstation just to
share some of my amateurish playings with family and friends–a quick
way to export them to wav files would be enough. The built-in speaker
of this DP is crappy, but the headphone out is pretty decent (I’m
using a pair of Sennheiser HD650 cans), so it seems natural to feed it
into the soundcard’s Line-in jack.

Turns out it’s not a simple matter of “plug and record”, so here’s a
mini-Howto. I’m using a Chaintech AV-710 soundcard (already
discontinued for some time now, but among other things has a pretty
decent wolfson DAC on the alt-out jack).

1 Sound card settings:

I’m talking about the settings you can tweak in alsamixer

  1. Playback. Go to the playback tab in alsamixer. To reproduce the
    line-in signal on the wolfson output (the black jack right next
    to the actual S/PDIF jack), set “S/PDIF” from PCM to “H/W In 0”,
    and “S/PDIF 1” to “H/W In 1”. These correspond to the left/right
    channel of the line-in signal (so you get stereo!)

    NB: I didn’t try to reproduce it on the “front out” jack (which
    nobody using AV-710 would use!). The “S/PDIF” and “S/PDIF 1” are
    probably referring to the wolfson device. (“S/PDIF 0” is probably
    the actual S/PDIF jack)

  2. Capture. Go to the capture tab in alsamixer. Press space on the
    “Line” device. There are multiple capture devices on this card
    and they seem mutually exclusive (i.e., pressing space on e.g.
    “Mic” would activate “Mic” and deactivate “Line”).

    Since the DP jack is really a headphone out, better set the
    “Capture” gain to zero–no good can come out of double amping!

2 Recording command:

arecord -D plughw:0,0 -f cd -t wav cavatina.wav

Now hit the Play button on your DP. The song (Cavatina in this case.
Beautiful piece by Stanley Myers btw.) will be recorded to
cavatina.wav as you hear it from your wolfson out. Notice that
plughw is necessary b/c natural format of AV-710 is S32LE instead
of the 16bit cd format (S16LE). The “plughw” ALSA plugin will do
the format converting job.

3 Combining audio with video:

mencoder cavatina.avi -audiofile cavatina.wav -delay -0.55 -oac copy -ovc copy -o cavatina-song5-track4-audio.avi

Written by zsh

June 14, 2010 at 8:32 pm

Posted in /usr/bin

Tagged with , , , , , ,

dumping audio from a video clip using mplayer

leave a comment »

mplayer your-video.mkv -ao pcm:waveheader:file=output.wav

mplayer will suggest you to use -vo null -vc null -ao pcm:fast to achieve faster result, but somehow this doesn’t work for my file at hand

Written by zsh

January 20, 2010 at 1:17 am

Posted in /usr/bin

Tagged with , ,

mounting sansa fuze microsd

leave a comment »

need CONFIG_SCSI_MULTI_LUN, can be found at:
device drivers -> scsi device support -> probe all LUNs on each SCSI device

Written by zsh

September 8, 2009 at 3:43 pm