Emacs for Science

on January 7, 2018

I typically cover software packages that do actual calculations toadvance scientific knowledge, but here I'm exploring a slightlystranger tool in the arsenal ofscientific computation.

Emacs is a text editor that has almost allthe functionality of an operating system. A collection ofenhancements and configuration settings are available bundled underthe name ofscimax. Being an Emacs user myself, I was surprised I'd neverheard of it before now. This project has been in development for sometime, but it recently has started to find wider attention.

Before installing it,however, you need to install the latest version of Emacs toget all of the needed functionality. As with most of my articles,I am assuming that you are using a Debian-based distribution. Youcan install Emacs by using the daily snapshot package,available at the official launchpad archive. Install itwith the following commands:

sudo add-apt-repository ppa:ubuntu-elisp/ppasudo updatesudo install emacs-snapshot

This will ensure that you have the latest and greatest version.

Once this isinstalled, go ahead and install the scimax code itself. You canget it from the main GitHub repository with the command:

git clone https://github.com/jkitchin/scimax.git

Start it with the command:

emacs-snapshot -q -l path/to/scimax/init.el

The first time you do this, there will be a lot of activity while Emacsdownloads and installs the full suite of extra packages you needin order for the scimax code to have all of the required dependencies.

When you finally have everything installed and start scimax, you willsee several new menu items in your Emacs session.

Figure 1. You will see several new menu item entries at the top of your Emacs window.

The real driving need behind all of the work that has gone into scimax isto make research more easily reproducible and to handle documentationof your research with minimal extra overhead.

Since you want to workwith organized documents within Emacs, the base of scimax is built ontop oforg-mode. Org-mode, by itself, is probably something you willwant to look into as a potent tool. Scimax takes this powerful coreand makes it easier to use with a series of shortcuts.

Because oforg-mode's power, it would be time well spent if you learned at leastthe basics of how to use the main parts of this package. Org-mode hasa markup syntax of its own, and scimax adds a layer of shortcuts thatmake it easier to write.

Along with the regular org-mode markup syntax,scimax makes it easier to include LaTeX sections for more advanced textuallayout. Many people in scientific fields are familiar with LaTeX. For thosewho aren't, LaTeX is document layout program where you write your textand include layout instructions for the LaTeX engine. The idea is thatyou separate out the text from the formatting of that text.

If you havegraphical images as part of your research, scimax has added some extrafunctionality to make image rescaling and presentation better than theorg-mode defaults by using external programs from the imagemagick package.

Because org-mode is designed to be a document structuring package forEmacs, it allows for exporting your text into a great many otherformats. Also, since it separates out the formatting from the actual text,it can be applied to many different document structures, such as articles,books or web pages.

Scimax uses the ox-manuscript Emacs package to handleexporting to high-quality document formats. This is useful when youneed to produce final versions of your scientific reports or articlesin a format like PDF.

Bibliographic references within your documentare handled through bibtex entries.

So far, I've covered a quickoverview of the document management, organizationand formatting tools that are provided through scimax, but Emacs andorg-mode have much more functionality.You can interact with the outside world in a few different ways. Thefirst is through email. You can grab selections of your text, or an entirebuffer, and issue anorg-mime command within Emacs to tell it to sendan HTML-based email. Depending on your system, you may need additionalconfiguration in order for this to work as expected.

The otherway to interact with the outside world is through Google searches. Assomeone who writes a fair bit myself, I cannot understate the need for aGoogle window to be open to be able to verify some fact or statement as Iam writing. With scimax, thegoogle-this Emacs package gets installedand is available as you are working. This allows you to fire upGoogle searches based on either specific text selections or the contentsof entire buffers immediately from the document that you are working on.

Along with communicating with the outside world, the other powerfulinteraction with external tools is through org-mode's ability to runexternal programs and have their output inserted into sections of yourdocument. This one piece of functionality makes the dream of reproducibleresearch a real possibility. You do need to be diligent and put itinto practice, but you no longer have the excuse of saying that itisn't possible. The idea is that, from within your org-mode document,you can define a block of code that makes some calculation or generatessome graph. You then can have org-mode fire this block so that it canbe run through an external engine and have the results pulled backin and inserted as the displayed text in the original location.

Thedefault engine configured in scimax is Python, which is definitely agood starting point. With more configuration, you can add support forseveral other languages. The powerful idea here is that you alwayscan go back to the original code that generated some result or some graphand re-create it. More and more scientific journals are demanding thislevel of reproducibility, so having it as part of your article contentsdirectly means you never will lose track of it.

The last thing I want to cover is how to organize all of the workthat scimax is helping you do. The highest level of organization isthe ability to set up projects. A project is essentially a directory withall of the associated files for that given project. These projects arehandled by the Emacs projectile package. This package allows you to movebetween projects, find files within projects or do full searches througha given project.

Projectile assumes that these project directories areunder some kind of version control system, such as Git. Luckily, scimaxincludes the magit Emacs package, which adds lots of extra functions thatallow you to interact with the Git repository that the current filebelongs to directly from Emacs. You can create or clone repositories,stage and commit changes, manage diffs between versions, and even handlepushes to and pulls from remote repositories. Along with the explicitcontrol over a Git repository, scimax includes extensions to org-mode tohandle track changes, as well as to insert edit marks withinyour org-mode document.

Putting all of this organizational work together,scimax provides the ability to create and use scientific notebooks.A series of commands starting withnb- allow you to wrap allof the organizational functionality to create, manage and archive thesenotebooks. Now, you have no reason not to start documenting all of yourscientific research in a reproducible way—except maybe the learningcurve. But, as the old saying goes, nothing worth doing is easy, and Ithink this is definitely worth doing, at least for some people.

Load Disqus comments