Fix printing titles to stdout

This handles non-ascii characters correctly and is based on pull request
8 from Mathieu Leduc-Hamel and Éric Araujo.