z·eeki·sh

tech log on gentoo, linux, and random stuff

Archive for the ‘/usr/bin’ Category

sed one-liner for extracting pictures included in a tex file

leave a comment »

When writing up tex manuscripts, I usually put related data/function plots under the same directory as the tex file, or some sub-dir like ‘figs/’. Often times though, many of them are never actually used in the tex file. while I have no problem with cluttering up my folders with unused plots, it is quite painful when you need to pick out those used plots, for example when tar-balling them to share with a colleague or submit it to some journal. Here is a one-liner to extract a list of used plots in a tex file:

sed -n 's/[^%]*includegraphics[^{]*{\([^}]*\)}.*/\1/p' draft.tex

NB:

  1. draft.tex is the desired tex file from which to extract the list of figures.
  2. The -n tells sed to suppress printing unless instructed to (which will be effected by the tailing /p.
  3. The [^%] will skip plots commented out.

Here is the shell command to generate a tarball containing all necessary files:
tar -cvvzf draft.tgz draft.tex *bbl *bst $(for f in `sed -n 's/[^%]*includegraphics[^{]*{\([^}]*\)}.*/\1/p' draft.tex`; do echo `basename $f .pdf`.pdf; done)

Written by zsh

January 20, 2013 at 11:42 am

Posted in /usr/bin

Tagged with , , ,

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

NB:
(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 , , ,

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 , ,

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 , ,

automatically (un)compress files with arbitrary suffix in emacs

leave a comment »

Xournal, the note-taking app I’m using on my tablet, has the nice feature of gzipping its xml-format files. The following snippet in ~/.emacs will allow emacs to automatically compress/uncompress it during writing/reading.

(add-to-list 'jka-compr-compression-info-list 
  ["\\.xoj" 
   "compressing" "gzip" ("-c" "-q") 
   "uncompressing" "gzip" ("-c" "-q" "-d") 
   t nil 
   "\213"]
 )
(jka-compr-update)
  

Written by zsh

April 20, 2009 at 4:17 pm

Posted in /usr/bin, emacs

Tagged with , , ,

playing .nrg format dts cd with mplayer

leave a comment »

Well, I was about to write about using cdemu to simulate a cd-device from an .nrg file, and then use mplayer to play the simulated device. It turns out you don’t even need cdemu if it’s a media cd/dvd image. Here’s the cli:

mplayer cdda:// -cdrom-device yourfile.nrg -rawaudio format=0x2001

the only mysterious part is the magic number 0x2001, telling mplayer the disc has dts rawaudio. Apparently you can find this number by man mplayer and search for dts.

Written by zsh

March 15, 2009 at 3:39 pm

Posted in /usr/bin

Tagged with , , ,