# Latex for WordPress

I’ve just installed ‘Jetpack‘ which comes with $\LaTeX$. This post is to provide a quick reference. $\LaTeX$ parses the text in the WordPress post, and lays out the display as a graphic for the viewer. Though someone reading this will see images, there are no images referred to in the edited post.

$\LaTeX$ is a generalised document layout language, but as far as I am concerned, the main use of $\LaTeX$ in WordPress is mathematical.

Note that as the images are generated on the fly, the page will be slower to load than if the page were pre-rendered. Therefore, I think it may still be best for the web to generate the image, save it and then display the result via an <img> tag (keeping the $\LaTeX$ hidden in a comment so that the image can be regenerated if need be). As already mentioned, I have not pre-generated the images for this post, it is all done in code.

It’s a pity that MathML isn’t well supported at the moment.

# Thematic – A problem with php

I am working on a Child Theme based on the ‘Thematic‘ framework for WordPress. For more information, see the ‘Murkymatic‘ pages.

In Thematic there is a clever little script in `functions.php` which goes after every post and displays the tags, categories and so forth. This displays something subtly different on tags pages to category pages and so on. I like it, I want to keep it.

So far, so good. I want to insert into my own function into the child theme after the post but before the post footer.

My function, which is to show related posts if a post is part of a series.

This function works, and works well. Here it is:

```function childtheme_article_series() {     global \$id, \$post;     \$series = get_post_meta(\$post->ID, 'Series', true);     if(\$series) :         \$args = array(             'numberposts' => -1,             'meta_key' => 'Series',             'meta_value' => \$series,         );         \$series_posts = get_posts(\$args);         if(\$series_posts) :             \$class = preg_replace("/[^a-z0-9\\040\\.\\-\\_\\\\]/i", "", \$series);             \$class = strtolower(str_replace(array(' ', ' '), '-', \$class));             if (is_single()) {                 echo '<div class="series series-' . \$class . '"><h4 class="series-title">' . __('Articles in this series') . '</h4><ul>';                 foreach(\$series_posts as \$serial) :                     if(\$serial->ID == \$post->ID)                         echo '<li class="current-post">' . \$serial->post_title . '</li>';                     else                     echo '<li><a href="' . get_permalink(\$serial->ID) . '" title="' . str_replace('"', '"', \$serial->post_title) . '">' . str_replace('"', '"', \$serial->post_title) . '</a></li>';                 endforeach;                 echo '</ul></div>';             } else {                 \$pstlink = get_permalink();                 \$psttitle = get_the_title();                 echo '<div class="series series-' . \$class . '">';                 echo '<h4 class="series-title"><a href="' . \$pstlink . '">' . \$psttitle . '</a>';                 echo ' is part of a series' . '</h4></div>';             }         endif;     endif; }```

The above code goes into the `functions.php` of my Child Theme.

The next step is to tell that function when to run, so I hook it into the Thematic hook which is there for that very purpose.

Into my `functions.php` I add the line: `add_action('thematic_postfooter','childtheme_article_series');`

Unfortunately, this replaces the existing Thematic footer with my footer. This is not what I want.

In short, I can’t work out how to tell WordPress to run my Child Theme function, then to do the Thematic parent theme function.

I’m at a bit of a loss right now.

I could recreate the existing footer in my routine – but that removes one of the advantages of the child theme, should the Thematic code be updated, my replacement footer would not be.

It is important to be able to over-ride the parent theme’s footer, but it’d be nice to be able to supplement it too. What I want is to tell WordPress to run this function before the `thematic_postfooter()` function. I don’t want to have to edit Thematic to do this (as this also removes the parent/Child Theme advantage). Though I did try this, and it caused a server 500 error – I have no clue why.

One solution would be if Thematic had a hook before it called thematic_postfooter() which otherwise did nothing – but it doesn’t.

Another solution is if I could work out how to explicitly pass control to the thematic_postfooter() function at the end of my function.

I tried using the information about priorities giving my function a priority of 5, but this didn’t work at all, it still replaced the thematic footer. It seems that sometimes adding an action over-rides, and sometimes it just adds (as expected).

It’s rather a mystery to me right now. It’s something that I think *should* be possible, but I cannot work out how. I’ve left this message on the thematic forums.

I would really appreciate a pointer here, if anyone has a bright idea. The latest murkymatic code can be found on google code.

# More Theme Modifications

I’ve played with my new theme a little more, and it is roughly where I thought it needed to be for personal modifications.

The first thing I’ve done is to bleed all the colour out – the default is now a white theme, then I’ve added in style definitions which will cease to be relevant on 26th December…. my first test of the date-based tags.

Seems okay…..

Update: Bugger. MSIE….. doing its own thing for CSS….. buggerbuggerbugger…. thankfully there is a javascript fix out there. Come on, Microsoft…. sort out your buggy browser!

Update 2: The problems I had were with MSIE not understanding ‘inherit’ in a class declaration in the way that it should. I’ve made the ‘offending’ CSS explicit in the colour declarations. Not great, but livable. As a result, I’m no longer relying on the javascript above.

# WordPress Theme Style Declarations

As some will know, I’m coding up a WordPress theme from scratch. The idea is to give lots of flexibility so that the theme can be easily modified using stylesheets alone.

Out of the box, it’s fairly gaudy, but this is intentional as it encourages the modification! (Okay, I will ultimately make an ‘okay’ version based on the raw templates).

Anyhow, I thought to myself that it’d be great if css classes could be provided to allow pages to be styled differently depending upon category, tag or date. Lovely to be able to have a ‘Christmas theme’ that pops into being and goes away automatically without special coding and ‘if’ statements.

Therefore, I replaced the <body> tag in header.php with this code:

``` \$today_month = date("m"); \$today_year = date("Y"); echo "<body class=\"today_\$today_year\$today_month\$today_day todaynoyear_\$today_month\$today_day year_\$today_year month_\$today_month day_\$today_day todayyearmonth_\$today_year\$today_month "; if (is_tag()) { \$current_tag = str_replace(" ", "_", single_tag_title("", false)); echo "maintag_\$current_tag"; } elseif (is_category()) { \$current_category = str_replace(" ", "_", single_cat_title("", false)); echo " maincat_\$current_category";} echo "">"; ?> <!-- If a tag page, the tag is listed as a css class declaration in the form maintag_tagname --> <!-- If a category page, the category is listed as a css class declaration in the form maincat_categoryname --> <!-- There are also tags which update daily, letting the site owner have styles which only operate on certain days -->```

On a tag page, it would do something like this: `<body class="today_20081222 todaynoyear_1222 year_2008 month_12 day_22 todayyearmonth_200812 maintag_coding">`

Thus, one could have specific CSS for a particular day (e.g. Christmas), or for a particular tag or category. All specific customisation can then be in the CSS.

# Themes

The observant may have noticed that the look of this site has suddenly got rather gaudy. There is a good reason for this – I’ve been creating a WordPress theme which I want to be as flexible as possible. I.e. a ‘bare’ theme, which can then be styled easily with css.

I know these themes already exist, but I wanted my own, m’kay?

The reason for the gaudy colours? Testing. I wanted the default colours to be fairly obvious, with each main element being distinct so that I could be sure that I had the no typos in the CSS selectors.

I’ll leave the theme running for a little while, I’d be interested to hear about any usability issues (other than the horrible colour scheme).

The theme should be fully widgetised, it should have comment threading, avatars and so on.

The theme should be fluid and resize gracefully, as screen width reduces, the images reduce whilst keeping aspect ratio.

Things I know I want to fix – some of these are purely ‘behind the scenes’:

1. I want, at most, one sticky post on the front page. At the moment, it’ll put any number on.
2. I want to have a tags page which shows the tag cloud.
3. Behind the scenes, the entry formatting uses the same template, called when needed by index.php and archive.php. I need to get the single.php template to use this as well in order to minimise maintenance (requires some ‘if’ statements).
4. Do I *need* single.php and archive.php once I’ve done that?
5. Author pages, ideally automatically pulling in gravatars.
6. Decent 404 page
7. The comment form gets screwed up on a narrow screen and doesn’t resize gracefully. I don’t know why.
8. I want the theme to be accessible. I.e. Good for screen readers and the like. I have no way to test this however, so if you know anyone with a screen reader, please do point them in this direction and ask them to comment (or, pass on their comments should it *really* be unusable).
1. Is the order of elements okay?
2. aural stylesheet hasn’t been done, for me, that’d be coding without testing – I would want a sheet though!
3. The tags/related tags stuff – does there need to be a way to, ideally optionally, skip that for screenreaders…. I wonder how (without introducing new screen cruft)
9. I’ll then package up this rough theme for release, create a duplicate and change the look and feel to customise it. If I find that I have to customise anything other than a stylesheet, I’ll need to amend the ‘raw’ theme.

Things I’m unsure of:

1. I’ve appended categories to tags (with a different class for styling)
2. Do I want to keep the related posts thing? It relies on a plugin, so isn’t essential for the theme (plugin may be disabled as a recent update caused a problem behind the scenes… I hope I remember to remove this sentence when fixed, but I’ve couched it as a conditional just in case)