sed one-liner for extracting pictures included in a tex file
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:
- draft.tex is the desired tex file from which to extract the list of figures.
- The -n tells sed to suppress printing unless instructed to (which will be effected by the tailing /p.
- 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)
actkbd and screen rotation in archlinux
actkbd is in AUR. I need it so the tablet keys on X220 tablet can serve more use (e.g., differentiate between long and short press, etc.)
In order for the rotation script triggered by actkbd to be able to communicate with X, we need to start actkbd with the DISPLAY=:0 environment variable. The AUR package created the /etc/rc.d/actkbd entry. Just change
[ ! -f $PIDFILE ] && /usr/sbin/actkbd -D -q -p $PIDFILE
to
[ ! -f $PIDFILE ] && DISPLAY=:0 /usr/sbin/actkbd -D -q -p $PIDFILE
dd-wrt ssh port forwarding quirky
I guess it is more of a web-gui quirky. Anyway, here is what I desire: I want to move the ssh port of the router itself to say 9999, and forward port 22 to a workstation connected to the router.
What I did, which is wrong:
1) dd-wrt -> services -> services: change port of ssh to 9999
2) dd-wrt -> NAT/QoS -> port forwarding: add port from 22 to workstation-ip:22
What I now have, which is correct thanks to this post, is:
1) dd-wrt -> services -> services: change port of ssh back to 22
2) dd-wrt -> NAT/QoS -> port forwarding: add port from 22 to workstation-ip:22
3) dd-wrt -> administration -> management: change [ssh remote port] to 9999
Wacom Bamboo Create (CTH670) on linux
Apparently the xf86-input-wacom driver is not enough: one has to manually build the kernel module (for kernel version <= 3.2)
1) get input-wacom driver here: http://sourceforge.net/projects/linuxwacom/files/xf86-input-wacom/input-wacom/
2) unpack and run ./configure. Pay attention to the installation instructions at the end of ./configure output
3) copy kernel modules to /lib/modules/ as instructed.
4) modprobe wacom and enjoy
MKL FATAL ERROR /path/to/libmkl_def.so: undefined symbol: i_free
I started fooling around with python/scipy with the intention of replacing ruby/gsl. Came across this very weird error.
Minimal script to reproduce: invoke ipython -pylab, then in it,
In [1]: from scipy import *
In [2]: a=zeros(1000); a[:100] = 1; b = fft(a)
In [3]: plot(abs(b))
and ipython spits out the titled error.
Found a solution here: before running ipython,
export LD_PRELOAD=/opt/intel/mkl/10.0.5.025/lib/32/libmkl_core.so
apparently, some symbols are defined in libmkl_core.so instead of libmkl_def.so.
stripping url output from bibtex
The bibliographical information as supplied by journals usually includes a URL field, and bibtex styles like \bibliographystyle{apsrev} will export the URL field in the resulting .bbl file, very nagging to some of us. One way to get rid of these URL links is to use a customized .bst file, e.g.,
locate apsrevto find where theapsrev.bstfile is.- cd to the directory, and invoke
grep -v 'format.url output' apsrev.bst > your/manuscript/directory/apsrev-no-url.bstto create a no-url version of the bst file in your manuscript directory (or any other directory in the search path of bibtex). - now, in your manuscript, replace
\bibliographystyle{apsrev}with\bibliographystyle{apsrev-no-url}
pdf to gif conversion and optimization
There have been several occasions that I need to generate some gif animations from a bunch of pdf plots (generated by gnuplot’s tikz terminal), so the following procedure merits documenting. Note that convert is part of ImageMagick, and gifsicle is a gif optimization tool.
- Converting pdfs to png:
for f in *pdf; do convert -verbose -density 150x150 $f `basename $f .pdf`.png; done - combining png to gif (and optimize):
convert -verbose +dither -layers Optimize -colors 32 -delay 5 -loop 0 -dispose previous *png output.gif - if there are too many *png files, it’s probably better to divide and conquerer: assuming png files are frame_000 upto frame_139, then first:
for i in `seq -f "%02g" 0 13`; do convert -verbose +dither -layer Optimize -delay 5 -loop 0 -dispose previous frame_${f}?.png frame_${f}.gif; done
then
convert -verbose frame_??.gif all.gif - notice that I’ve dropped the -color 32, b/c in my case it actually increases the resulting file size.
- further optimization (YMMV) using gifsicle:
gifsicle -O3 output.gif -o output_optimized.gif
cf:
p.s., a related operation is to combine say every 10th of the pdfs for closeup inspection:
pdfjam frame_??0.pdf --papersize '{12in,9in}' --outfile frames.pdf
pdfjam is a frontend to the latex package "pdfpages". The --papersize I used is the same as the one I had used in gnuplot when generating these plots (set term tikz size 12in,9in ...).