Thursday, November 29, 2012

Cygwin package manager and auto updates

I use Cygwin on my Windows machine to get access to all the wonderful Linux tools like grep, wget, etc. One problem with Cygwin is you have to run it's GUI installer again manually each time you want to add tools or update the ones you already have.
apt-cyg provides a command-line package manager that you can use to install tools without using the GUI installer. However, I didn't see a way to update the existing tools. You can write a simple batch script to do the automatic updates for you. You only need the three lines below, assuming you've installed cygwin to C:\cygwin. Then, run the batch file as administrator or create a shortcut to do that for you.
cd C:\cygwin
wget -N http://cygwin.com/setup.exe
setup.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode
If you want to pretty it up so you can scan the results of the commands easier, just add some echo statements:
@ECHO off
cd C:\cygwin
echo ======================================
echo Downloading latest cygwin installer...
echo ======================================
echo.
wget -N http://cygwin.com/setup.exe
echo.
echo ======================================
echo Updating all cygwin packages...
echo ======================================
echo.
setup.exe --no-desktop --no-shortcuts --no-startmenu --quiet-mode
echo.
echo ======================================
echo Update finished.
echo ======================================
echo.
pause

Thursday, January 12, 2012

Suppressing BibTeX fields for specific biblatex entry types

I use LaTeX for writing academic papers and biblatex for handling the citations and references in them. One problem I ran into is that biblatex prints out the location, address, month, and publisher for a lot of entries, which I prefer not to have in my reference list. Rather than editing the BibTeX .bib file and losing that data forever, you can tell biblatex to ignore or suppress specific pieces of it.

Below is my code. It suppresses location, address, month, etc. for all entries, and suppresses the publisher and editor field unless the entry is a book. You may need to modify this for whatever style you're using.

% Loads biblatex with clickable links from citations and the reference list, 
% with back references if the style supports them.
\usepackage[hyperref,doi,url=false,backref,style=alphabetic,maxbibnames=99]{biblatex}
\bibliography{refs.bib}

\AtEveryBibitem{% Clean up the bibtex rather than editing it
 \clearlist{address}
 \clearfield{date}
 \clearfield{eprint}
 \clearfield{isbn}
 \clearfield{issn}
 \clearlist{location}
 \clearfield{month}
 \clearfield{series}
 
 \ifentrytype{book}{}{% Remove publisher and editor except for books
  \clearlist{publisher}
  \clearname{editor}
 }
}

Edit on 2/9/2012: As @siretart helpfully points out in the comments, biblatex makes distinctions between fields, name lists, and literal lists in the source file. To see whether to use \clearfield, \clearname, or \clearlist check the biblatex manual for the data type. For example, date and series are fields, location is a literal list, and editor is a name list. I've updated the code above to reflect this.