Research and Programming

Right now my research and programming go hand in hand. Saving all sources and notes in a database proved to be a very good idea. Adding new sources to the database is easy in Adminer.

Whenever new additions are made to the database, it’s a matter of seconds to compile a new bibliography file via my Python script.

Now I write, and write. Texts, notes, ideas, chapters, structures … poor out. The database is a major tool in the creative work. Quotations are made via the ID in the database. Since the value is unique there are no conflicts in the bibtex file.

In the actual texts its a matter of adding @wp_81 – or whatever the id of the relevant source may be.

All my texts are written in markdown. I can compile the texts to .pdf, .epub, .docx etc. via a Pandoc script i bash.

With this “toolbox” it’s easy to write the academic dissertation.

Right now the writing process is in a phase of “write-out”. I don’t care to finish anything. It’s like drawing a sketch on paper. But when the chapters are compiled – it turns into a report, with all the academic features: lists of content, notes, and a very precise academic bibliography.

I never thought, that writing and programming were related in this way. But it’s a fact: programming and (academic) creative writing are related.

Pandoc, Markdown and eBook-production

Why don’t you save the long pandoc command lines as a bash script?

In this project I write in Markdown most of the time. I may need the same text in many formats:

  • .docx for the boss
  • .pdf for nice presentations
  • .tex for serious work
  • .epub for ebooks
  • .mobi for Kindle

I have chosen to write most of my texts in Markdown. Pandoc can transform Markdown to all the formats above. Except perhaps .mobi. Here you need Amazon’s kindlegen.

In order to create an Ebook and a Kindle version, you need to:

pandoc -o myText.epub
kindlegen myText.epub

Kindlegen will create a file with the .mobi extension: That’s it. Your book is ready for Kindle.

Here’s a list of pages, that I tend to use over and over again:

Let’s try a conversion from Markdown to an eBook. The –ebook-cover will ad a frontpage. So you’ll have an eBook with a nice cover. The –toc means Table of Content.

pandoc -s --epub-cover-image=owl.jpg --toc meta.txt -o x.epub

As you progress the pandoc commandline tends to become very long indeed. I save such lines i as a bash script. Here’s a sample:

# Create the eBook and a Kindle version of the same
pandoc -S --epub-cover-image=owl.jpg --toc -o yourBook.epub meta.txt
kindlegen yourBook.epub

Save the file as Then run this command: chmod a+x Now you can run the entire command like this:


in a terminal. As soon as your pandoc command works you can save it for future use. You could even save the script in


Then you can use your script as a Linux command.

I’m sure that you can do something similar in Windows or OSX. In the heyday of MS DOS I might have saved the pandoc command in a .bat file. But in the end I prefer a Linux solution.

By thine own ingenium create your solution …


Better PDF support

In this blogpost by Mike Schroder you can see, that WordPress will have better PDF support from WP 4.7.

Mike Schroder: better PDF support from WP 4.7
Mike Schroder: better PDF support from WP 4.7 (image from Mike Schroder’s blog post).

However, the PDF support needs several dependencies:

Core support is provided through WP_Image_Editor_Imagick and requires Imagick, ImageMagick, and Ghostscript support. When not supported, or if the generation fails, WordPress falls back to previous behavior and saves the attachment without adding image previews to meta. (Quote: Mike Schroder Nov. 15th. 2016)

Create aBibtex file via MySQL and Python

My sources are saved in a MySQL database. I’d like to write my text in LaTeX via LyX. I cannot use the database directly in my reports. So I need a compiler, that will convert my data to a format, that LyX & friends can handle.

Therefore I have made a little compiler in Python. I’ll use the Python mysql.connector. Ubuntu has the relevant packages in the repos.

The compiler will format an ascii-file according to the Bibtex format:

author=”Raielo, Eike J.”,
publisher=”Hovedopgave, EAAA”,
title=”Development of WordPress plugin Dreamgrow Scroll Triggered Box”,

Here is the bibtex compiler:

# kompile to the bibtex format
for row in cursor:
print "@book{wp_" + str(row[3]) + ","
print "author=\"" + row[0] + "\","
print "publisher=\"" + row[4] + "\","
print "title=\"" + row[1] + "\","
print "year=" + str(row[2])
print "}"
print ""

A book should have a unique name. The unique id from the table could be used here. The book will get an id like wp_123 in the line:

print “@book{wp_” + str(row[3]) + “,”

Save the Pyhon file as Create the bibliography as below:

# python > bibliography.bib

The complete code is available on Githup.

International characters may look odd. A workaround is to open the .bib file in KBibTex and save it again. Perhaps it’s not elegant, but it works all right. KBibTex will add special characters. My name will demonstrate what happens to Scandinavian characters:

author = “Jensen, Per Thykj{\ae}r”,
publisher = “Per Thykj{\ae}r Jensen”,
title = “{}”,
year = 2016