Steven Shaw

$\lambda f. (\lambda x. f (x\;x)) \; (\lambda x. f (x\;x))$

Hello MathJax

MathJax isn’t currently supported out-of-the-box with Octopress. The main reason seems to be that the Markdown processor — rdiscount — doesn’t deal with the MathJax escaping very well. However, since Maruku supports it, I thought I’d try switching over.

I made the following two changes:

switch Markdown processors in _config.yml
1
markdown: maruku
enable MathJax in source/_includes/custom/head.html link
1
2
3
4
5
6
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
      tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
      });
</script>
<script type="text/javascript" src="path-to-mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

This allows for inline $\TeX$ expressions between dollar signs e.g. $\TeX$. MathJax display expressions (i.e. non-inline) are delimited by double dollar signs:

example expression from Paul Snivey’s article link
1
$$\forall x, y : \mathbb{Z}, x > 3 \land y < 2 \Rightarrow x^2 - 2y > 5$$

renders as:

$$\forall x, y : \mathbb{Z}, x > 3 \land y < 2 \Rightarrow x^2 - 2y > 5$$

Right-click issue

There was also a problem with the theme. When right clicking a MathJax expression, the whole page goes blank! Zete has a great fix for this:

fix for right-click link
1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/sass/base/_theme.scss b/sass/base/_theme.scss
index 9a50a8b..fc9dc37 100644
--- a/sass/base/_theme.scss
+++ b/sass/base/_theme.scss
@@ -75,7 +75,7 @@ html {
   background: $page-bg image-url('line-tile.png') top left;
 }
 body {
-  > div {
+  > div#main {
     background: $sidebar-bg $noise-bg;
     border-bottom: 1px solid $page-border-bottom;
     > div {

Futher reading

Rebooting with Octopress

I’m starting with a clean slate and moving to Octopress.

Haskell source code highlighting appears to work out of the box:

Run length encoding link
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import Data.List (group)

-- Datatypes
type Encoded = [(Int, Char)]  -- An encoded String with form [(times, char), ...]
type Decoded = String

-- Takes a decoded string and returns an encoded list of tuples
rlencode :: Decoded -> Encoded
rlencode = map (\g -> (length g, head g)) . group

-- Takes an encoded list of tuples and returns the associated decoded String
rldecode :: Encoded -> Decoded
rldecode = concatMap decodeTuple
    where decodeTuple (n,c) = replicate n c

main :: IO ()
main = do
  -- Get input
  putStr "String to encode: "
  input <- getLine
  -- Output encoded and decoded versions of input
  let encoded = rlencode input
      decoded = rldecode encoded
  putStrLn $ "Encoded: " ++ show encoded ++ "\nDecoded: " ++ show decoded

as does Scala:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import scala.collection.mutable

def countWords(text: String) = {
  val counts = mutable.Map[String, Int]()
  for (word <- text.split("[ ,!.]+")) {
    val lowerWord = word.toLowerCase
    val oldCount = counts.getOrElse(lowerWord, 0)
    counts(lowerWord) = oldCount + 1
  }
  counts
}

val text = "See Spot run. Run, Spot. Run!"

countWords(text) foreach println