Nelse
Table of Contents
When I was growing up in the outskirts of London, my friend and I would take apart any electrical or mechanical mechanism in an attempt to learn how things worked, usually to no success. The resulting pile of bits were called “Nelse”. This is where I store my online Nelse.
LyX, BiBTeX, ADS, astro-ph and hyperref for Astronomers
Keeping a bibtex database and using it to produce dynamic PDF documents through Makefiles and other tools.
Other useful links:
Using BiBTeX entries generated by ADS
Things to fix
- Get the .bst file to elegantly munge the astro-ph URLs
- Add a style file that has the astronomical journals properly included
- Make a more general case to apply to any bst file
Introduction
The goal is to include a bibtex generated from a private library exported from the ADS service into a LyX document as a bibliography, and then to export it as a PDF complete with clickable links to hit back on the astro-ph references and the ADS paper page.
This can be broken down into several parts:
- Generating a list of required papers in ADS
- Exporting the BiBTeX to a local file
- Getting LyX to find and recognise the BiBTeX file
- Setting up how the references and citations look in LyX
- Making LyX recognise the URLs in the BiBTeX file
The bibtex entries have an adsurl entry that contains the link to the ADS web page for a given reference. If you can make that linked in, you’re golden.
Getting a latex file to recognise the abbreviations in an ADS Bibtex download
Normally, you can add the bibtex style fix as listed in the AstroNat link, so that the \apj gets replaced by ApJ, but it turns out that the ADS generates Bibtex items with braces that protect any string replacement that use @STRING [see
here](http://ads.harvard.edu/pubs/bibtex/astronat/doc/html/astronat_3.html#SEC7)
So, I’ve taken the list of journal names from
(http://ads.harvard.edu/pubs/bibtex/astronat/mnras/mn-jour.bib) and
changed them into a long list of \def statements. You can add this into
your latex file as \input{mnras-replacements}. NOTE: I’ve removed a
couple of the more obscure journal names whose \def seems to replace a
latex command or two. They’re fairly obscure journals, so here’s to
never reading “Space” journal.
Getting LyX to find and recognise the BiBTeX file
In Document... => Settings.... => Bibliography, under Citation Style,
select the Natbib radio button, and Natbib-style of Author-year.
In Document... => Settings.... => LaTeX Preample add:
\def\apjl{ApJL }
\def\aj{AJ }
\def\apj{ApJ }
\def\pasp{PASP }
\def\spie{SPIE }
\def\apjs{ApJS }
\def\araa{ARAA }
\def\aap{A\&A }
\def\nat{Nature }
\usepackage{hyperref}
\hypersetup{colorlinks=true,citecolor=blue,linkcolor=black,filecolor=black,runcolor=black}
Optionally addd urlcolor=blue into the \hypersetup line if you want
blue external URL links instead of the rather fetching purple they are
at the moment.
Setting up how the references and citations look in LyX
This is done with the Q and A section of latex makebst.tex…
Making LyX recognise the URLs in the BiBTeX file
Okay, so you should have a Bibtex style file that you can link to in
youe latex file or in your added Biblio section in your lyx file. This
file is called <name>.bst
deep breath So, it turns out that *.bib are your biblio databases,
with the name, publiction date, and so on. Latex spits out an .aux file
which lists all the references it wants to find. Bibtex then taks this
.aux file, reads in your bibtex .bib file, and processes the latex
references according to the style file *.bst.
The bibtex style file is in fact a simple stack-based programming
language, and so you need to hack the .bst file itself to get the proper
behaviour!
I’m sure there is a better method to doing this, but I haven’t found it yet, and anyway, this one works as it stands.
First, the astro-ph links. I’ve decided to keep these as just plain text with no URL link. ADS is now set up so that it links to the astro-ph for any paper that is in its system.
Look for a line in the bst file that looks like this:
"\providecommand{\eprint}[2][]{\texttt{#2}}"
…and change it to:
"\providecommand{\eprint}[2][]{\url{#2}}"
The bst file outputs latex commands for the bibliography section during
processing, and in this section of the bst file, it is writing out a
latex command that will deal with the formatting of any ’eprint’ field
in the bibliography. If you have loaded the hyperref package in the LyX
preamble, it takes the astro-ph:0702.1234 reference and makes it a
clickable link. This is wrong, and instead of hacking through the proper
replacement, we force it to print it out in a typewriter font instead.
Now, the URL links to the ADS website for that given paper.
Change the url to adsurl in the first ENTRY, about 20-60 lines into
the file.
Look for:
FUNCTION {format.url}
{ url empty$
…and change to:
FUNCTION {format.adsurl}
{ adsurl empty$
and then about three/four lines below that, find:
{ "\urlprefix\url{" url * "}" * }
…and change it to…
{ "\href{" adsurl * "}{[ADS]}" * }
Finally, do a ’search and replace’ for format.url and replace with format.adsurl
That’s it! It’s hacky, kludgy, and generally grungy, but for me, it works.
Originally written: 2008 Apr 02
bibtex and texmf
I’ve had several small bibtex files for many years scattered across many directories, and this has led to confusion and madness. To resolve this issue, I’ve gone and decided to use a single bibtex file for all my references, just as Saint Knuth (probably) intended.
But, it’s still wasteful to have all these files duplicated across the directory tree, and soft linking seems a bit nuts to me.
Thankfully the Unix gurus solved this problem many years ago, and there’s a standard directory structure for all your latex files.
Just use `kpsepath tex` to show the current paths that are scanned for files.
On a Mac, create the directory `texmf/` in your `Library/` directory and follow this structure:
./bibtex
/bib
/bst
./tex
/latex
/latex/aastex52
/latex/astronat
/latex/astronat/apj
/latex/astronat/mnras
/latex/emulateapj
This tree must have a prescribed structure. Put BibTeX files (.bib) in `~/texmf/bibtex/bib/` and put macro (.sty) files in `~/texmf/tex/latex/packagename/` (but replace `packagename` with the name of your macro package). Okay, so my big bibtex file lives in `bibtex/bib/kenworthy.bib` and custom style files in `bst`. This is all automatically found with subsequent latex programs, very nice.
NOTE when you add new files, remember to rerun `texhash` in the base directory.
cd texmf/ texhash . texhash: Updating /home/mattk/texmf/./ls-R... texhash: Done.
Links:
Common FLAC Command Line Options
A script to transfer tags from FLAC to MP3 and convert FLAC
#!/bin/bash
# Will convert every flac file in the current directory to mp3's using the highest
# possibly quality setting of the lame encoder. flac should support passing multiple
# files via wildcard, but I have found it to not be trustworthy, plus a loop is needed for
# lame anyways. Intermediate wav's are deleted.
# 6/6/2009
# Use the lame encoder preset
preset=insane
# Find the number of flac files in lower case
lcflac_cnt=`ls | grep -c .flac`
# Find all the flac files
allflac_cnt=`ls | grep -c -i .flac`
# Exit if there are upper case flac's
if [ $lcflac_cnt != $allflac_cnt ]; then
echo "There are some flac's with upper case extensions."
echo "I didn't feel like accounting for them, please fix them and run the script again."
exit
fi
# Exit if there are no files to process
if [ $lcflac_cnt = 0 ]; then
echo "Hey, there isn't anything to do...that was quick."
exit
fi
# Initialize the tag variables so lame won't bomb if they don't exist
tt=""
ta=""
tt=""
ty=""
tc=""
tn=""
tg=""
# Actually do some work
for flac in `ls *.flac`; do
echo "running flac"
flac -d $flac
base=${flac%.flac}
echo "Export metatags"
metaflac $flac --export-tags-to=${base}.tag
tt=`grep -i "^title" ${base}.tag | cut -f 2 -d \=`
ta=`grep -i "^artist" ${base}.tag | cut -f 2 -d \=`
tl=`grep -i "^album" ${base}.tag | cut -f 2 -d \=`
# Some people use album, some use venue.
tl_cnt=`echo $tl | wc -c`
if [ "$tl_cnt" -lt "2" ]; then
tl=`grep -i "^venue" ${base}.tag | cut -f 2 -d \=`
fi
ty=`grep "^DATE" ${base}.tag | cut -f 2 -d \=`
tn=`grep "^TRACKNUMBER" ${base}.tag | cut -f 2 -d \=`
tg=`grep "^GENRE" ${base}.tag | cut -f 2 -d \=`
echo "time for lame"
lame --preset $preset \
--tt "$tt" \
--ta "$ta" \
--tl "$tl" \
--ty "$ty" \
--tn "$tn" \
--tg "$tg" \
--add-id3v2 \
${base}.wav ${base}.mp3
echo "remove wav's"
rm ${base}.wav
echo "remove tag file"
rm ${base}.tag
done
See if everything was processed
mp3_cnt=`ls *.mp3 | wc -l` if [ $mp3_cnt != $lcflac_cnt ]; then echo "There are $lcflac_cnt flacs and $mp3_cnt mp3's, you should check into that." fi
adding art to an mp3 file
Download and install eyeD3 and run from the command line:
eyeD3 --add-image file.jpg:FRONT_COVER music.mp3
FLAC image extraction
CMUS needs specific FLAC tags to group compilation albums. Using metaflac to generate the appropriate tags works very well.
To list a flac files metadata:
metaflac --list 01_intro_tokyo_new.flac | less
To look at the embedded photo (if there is one in there):
metaflac 01-dna_featuring_suzanne_vega__rusted_pipe.flac --export-picture-to=- | xv -
To add the tag for CMUS compilation recognition:
metaflac --set-tag=ALBUMARTIST=COMPILATION *.flac
USE WITH CAUTION as repeated runnings of this command will silently add more of the same VORBIS comment to the file.
Some times adding the ALBUMARTIST tag doesn’t seem to work. Looking through the other tags, I see an ALBUMARTISTSORT tag that is listed before the ALBUMARTIST tag. CMUS apparently does a loose matching of tag text, so it stops on this first (incorrect) tag and use whatever is in that field.
metaflac --show-tag=AlBuMartistsort *.flac metaflac --remove-tag=albumartistsort *.flac metaflac --remove-tag=AlBuM *.flac metaflac --set-tag='album=Innocence and Experience' *.flac
Trying to understand what CMUS tags are read for display:
metaflac carry_on_up_the_charts_2/01-diamonds.flac --list comment[8]: album=Carry on Up the Charts: The Best of The Beautiful South (bonus disc) comment[10]: albumartistsort=Beautiful South, The comment[13]: artist=The Beautiful South comment[14]: title=Diamonds comment[15]: releasetype=compilation comment[20]: albumartist=The Beautiful South comment[23]: tracknumber=1 comment[24]: artistsort=Beautiful South, The
and this displays as:
Beautiful South, The Carry on Up the Charts: The ...‚ 01. The Beautiful South / Diamonds 1994 02:27
But with these set:
metaflac carry_on_up_the_charts_1/01-song_for_whoever.flac --list comment[0]: TITLE=Song For Whoever comment[1]: ARTIST=Beautiful South comment[2]: ALBUM=Carry On Up The Charts comment[3]: DISCNUMBER=1 comment[4]: DATE=1994 comment[5]: TRACKNUMBER=01 comment[6]: GENRE=Rock comment[7]: CDDB=c00bdc0e comment[8]: REPLAYGAIN_TRACK_PEAK=0.94848633 comment[9]: REPLAYGAIN_TRACK_GAIN=-2.08 dB comment[10]: REPLAYGAIN_ALBUM_PEAK=0.94848633 comment[11]: REPLAYGAIN_ALBUM_GAIN=-2.08 dB
Beautiful South ‚ Carry On Up The Charts ‚ 01. Song for Whoever 1994 02:27
So some of the keywords are causing rearrangement of the titles.