Rainbow + LaTeX

LaTeX support for the Rainbow syntax highlighting engine: craig.is/making/rainbows

HTML

<script src="http://www.seanallred.com/wp-content/plugins/wp-rainbow-hilite/js/dev/rainbow.js"></script>
<pre data-language="latex">
A normal \macro % with comment
\begin {document}
\end {document}
</pre>

CSS

/* ADAPTED FROM */
/**
 * GitHub theme
 *
 * @author Craig Campbell
 * @version 1.0.4
 */

pre .comment {
    color: #998;
}

pre .tag {
    color: navy;
}

pre .entity.function, pre .storage.function {
    font-weight: bold;
}

pre .entity.class {
    color: #458;
}

pre .entity.id, pre .entity.function {
    color: #900;
}

/** other settings for readability; credit: Craig**/

pre {
    border: 1px solid #ccc;
    word-wrap: break-word;
    padding: 6px 10px;
    line-height: 19px;
    margin-bottom: 20px;
}

code {
    border: 1px solid #eaeaea;
    margin: 0px 2px;
    padding: 0px 5px;
    font-size: 12px;
}

pre code {
    border: 0px;
    padding: 0px;
    margin: 0px;
    -moz-border-radius: 0px;
    -webkit-border-radius: 0px;
    border-radius: 0px;
}

pre, code {
    font-family: Consolas, 'Liberation Mono', Courier, monospace;
    color: #333;
    background: #f8f8f8;
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;
    border-radius: 3px;
}

pre, pre code {
    font-size: 13px;
}

JavaScript

/**
 * LaTeX patterns
 *
 * @author Sean Allred <code@seanallred.com>
 * @version 1.0
 */
Rainbow.extend('latex', [
    {
        'name': 'comment',
        'pattern': /%.*$/gm
    },
    {
        'name': 'storage.function',
        'pattern': /\\[A-z@]+/g
    },
    {
        'matches':
        {
            1: 'entity.name.function',
            3: 'entity.class'
        },
        'pattern': /(\\(begin|end))\s*\{(.*?)\}/g
    }
], true)