Alex Pearce

A Blog

Ruby developer @ aTech Media.

Freelance developer @ quantum bits.

Physics undergraduate @ University of Southampton.

Contact me.

The source for this site is available on GitHub

The Spectrum of Quarkonium

Friday 18, May 2012 in Physics

As part of my degree I'm taking a computing course which requires two project reports. The second was on finding the roots of the first Airy function in order to find the charm and beauty quark masses. The first one is in a previous post.

The report is written in LaTeX, the problem solving was done in Python, and the plotting was done with Mathematica. The entire project is open source on GitHub.

Compiling

The LaTeX document has a few dependencies.

  1. atlasphysics which is bundled in the repository.
  2. siunitx is found here. It's a nice package which simplifies typesetting units.
  3. Standard packages such as amsmath, graphicx, subfigure and float. I use the MacTex distribution for OS X, which ships with these packages by default (and ships with siunitx too).

You can view the final compiled PDF on GitHub.

Scattering Cross Sections in the Standard Model

Saturday 28, April 2012 in Physics

As part of my degree I'm taking a computing course which requires two project reports. The first was on e+eāˆ’ → μ+μāˆ’ scattering, mediated via the photon and the Z boson.

I wrote the report in LaTeX, with the main program being written in Python. As an extension, I rewrote the bulk of the Python script in C in order to compare the relative performance of the two languages.

I've open-sourced the entire project, which you can view on GitHub.

Compiling

The C script should compile on just about any system with gcc using

$ gcc -Wall cross_section.c -o cross_section

The LaTeX document has a few dependencies.

  1. atlasphysics which is bundled in the repository.
  2. feynmp is found here. There's a nice guide to installing feynmp on OS X here.
  3. Standard packages such as amsmath, graphicx, subfig and float. I use the MacTex distribution for OS X, which ships with these packages by default.

You can view the final compiled report on GitHub.

Escaping Liquid Tags in Jekyll

Monday 23, April 2012 in Tips

Writing the previous post brought about a problem: How can I write posts about Liquid tags?

By default, any Jekyll file containing YAML front matter will be churned through the Liquid processor. This means that any blog posts, which require YAML front matter, that contain Liquid tags will have them processed producing unwanted results.

The few solutions to this problem I've seen monkey-patch Jekyll. This works but was a little messy for me, so I went with a JavaScript approach.

Instead of writing my posts with Liquid tags , I simply substitute in ERB-style brackets.

<% for post in site.posts %>
  <%= post.title %>
  <% include post.json %>
<% endfor %>

The above will be transformed in to

<% for post in site.posts %>
  <%= post.title %>
  <% include post.json %>
<% endfor %>

The replacement is done with JavaScript via replaceERBTags($el), where $el is a jQuery object of the element containing the tags to be replaced. The function itself is nothing complex, in fact it's so simple I can't show it because it can't escape itself! So you'll have to be content with viewing it on GitHub.

Syntax Highlighting

Pygments, the syntax highlighter used by Jekyll, doesn't support Liquid so we can't get pretty markup. The syntax highlighting above is due to me using a <% highlight erb %> block. Because I target $('code.text') elements for tag replacements, i.e. <% highlight text %> blocks, I needed to use a different lexer to show the ERB tags.

You could target code.erb elements instead, but then you lose the use of ERB tags! I'm not a fan of Liquid, so I plan on doing as few posts on it as possible, hence I'm happier with ERB support. (Plus, any syntax highlighting you did get would only be approximate, and I expect would break down if you had anything but raw Liquid.)