Win at Emacs A Blog about Emacs

Print a filtered bibliography with biblatex

With biblatex, you can define filters to use in selecting which entries actually get printed. This is perhaps most useful with \nocite{*}, but it could also be used to partition a list of cited works by different criteria, such as by century, by type, and so on.

There are a couple of different ways to do this, depending on what you want to filter on. The command \defbibfilter has a high-level syntax that can be used with predefined segments, entry types and subtypes, keywords, and biblatex categories.

For working with other fields, or more complicated conditions, you can use \defbibcheck to define conditions and actions to take using LaTeX macros.

\defbibcheck{early}{%
  \iffieldint{year}
    {\ifnumless{\thefield{year}}{1940}
      {}
      {\skipentry}}
     {\skipentry}}

This code, based on an example in the biblatex manual, defines a bibliography check called early, which skips anything that doesn’t have an integer in the year field. Moreover, it only prints entries with a year less than 1940.

Using the filter is just a matter of including it as an option to the \printbibliography command:

\printbibliography[check=early]

I use this technique sometimes on a project to pull out an interesting subset of my bibliography to work with. In this case, I wanted to look at the pre-1940 entries without the overhead of formatting a much larger bibliography, so the point was to speed things up.

Go forth and filter your bibliographies!

Python configuration for Emacs 2020

It seems I need to refresh my Python setup almost every time I get back to writing some Python code, so this is the update for 2020.

I built up this configuration by doing basic configuration for python-mode and then adding some things as I felt the need for them. My use for Python at the moment is mostly standalone scripts for my own use, and for that it’s simpler not to bother with virtual environments.

Some background: I am using Python 3 from homebrew, with system-wide installation of Python packages, because I’m the only user on the system. I also have Python 3 installed via XCode command tools, but I try to ignore that as much as possible.

At the moment, I have cut back to just use the python library while I decide if I need more than that for what I do.

Loading python.el for Aquamacs

Aquamacs has traditionally shipped with python-mode, which began before a good mode for python was included with Emacs. At this point, I prefer the now-standard python.el that comes with Emacs. This configuration sets a new autoload for that mode.

The configuration consists of fixing up the autoloads, adding a keybinding for the right function to fill paragraphs, and setting it to use ipython as the interpreter. The interpreter arguments tell ipython to use the simple prompt that works with the Emacs shell.

(use-package python
  :ensure nil
  :init
  (autoload 'python-mode "python")
  :mode ("\\.py\\'" . python-mode)
  :bind (:map python-mode-map
              ("M-q" . python-fill-paragraph))
  :config
  (setq python-shell-interpreter "ipython3"
        python-shell-interpreter-args "-i --simple-prompt"
        python-check-command "/usr/local/bin/flake8")
  (setq python-shell-completion-native-disabled-interpreters
        (remove "ipython"
                python-shell-completion-native-disabled-interpreters)))

Quick reference for things I use in python.el

Here’s a summary of the commands I use from python.el. They are the ones that aren’t obvious from keybindings I am used to.

C-c C-p run-python
C-c C-z python-shell-switch-to-shell (must be running first)

pytest

I’m using pytest for testing my Python code these days.

(use-package python-pytest
  :after python
  :bind (:map python-mode-map ("C-c t" . python-pytest-popup)))