Posts Tagged ‘wordpress’

Category-specifc RSS feeds from WordPress

Friday, October 24th, 2008

I subscribe to some topic-specific blog aggregation feeds, and I get mildly annoyed when posts appear on those things that actually don’t have anything to do with the aggregation’s topic.  I found this off-topic spamming surprising because blogs always have these categories and tags on every message, so what’s the point of all that if you can’t subscribe to a specific category?

It’s not exactly obvious, but it turns out that at least with WordPress blogs (like this one) you can subscribe to a particular category.

First you have to figure out the category number for the topic you’re interested in.  You can usually do that by clicking on the link for the category you’re interested in an looking at the url.  It’ll have part that says something like “cat=4″.   Then you append that onto the regular feed url.  Now you append that onto the base RSS url for the blog.  Like for this blog the base is:

http://www.billbaxter.com/techblog/wp-rss2.php

Use a “?” to tack on the category string and voila!

http://www.billbaxter.com/techblog/wp-rss2.php?cat=4

you have a category-specific feed url (in the case above, for my “code” topic, which current includes D, C++ and Python sub-categories.

Update: It seems WordPress folks changed the URL format they use at some point.  For the version I’m currently using (2.9.2), the format is now:

http://www.billbaxter.com/techblog/?feed=rss2&cat=4

The .php script referencing the type of feed is no longer explicit, and instead both feed type and category are just parameters.

So here are some category-links for my blog here (updated for my WP 2.9.2):

LaTex in WordPress with PHP5.x

Thursday, July 31st, 2008

I’ve been using the wp-latexrender plugin on my WordPress blogs on DreamHost here for a while now.  The other day something prompted me to switch my DreamHost account to use PHP5 instead of the default PHP4.  Today I come to work and find equations in new posts are all full of garbage text with words like “ormulabox” and “ormulawidth” and “ormulaheight”.

Turns out PHP5.2 added “\f” as a special escape sequence.  So the php code that was working fine with LaTeX commands like “\formulabox” in double quoted strings, suddenly started breaking.  The \f’s became formfeeds, and what’s left (“ormulabox”, etc.)  was being interpreted by LaTeX as just regular words to put in the output.

So you could fix it by just turning those \f’s into \\f’s, but that would break latexrender on PHP4 installs.

So the fix to keep things working with both PHP4 or 5 is to put the bulk of those strings in single quotes.   So replace the wrap_formula function in wp-content/plugins/latexrender/class.latexrender.php with the following:

    function wrap_formula($latex_formula) {
        $string  = "\documentclass[".$this->_font_size."pt]{".$this->_latexclass."}\n";
        $string .= '\usepackage[latin1]{inputenc}' ."\n";
        $string .= '\usepackage{amsmath}' ."\n";
        $string .= '\usepackage{amsfonts}'."\n";
        $string .= '\usepackage{amssymb}'."\n";
        $string .= '\pagestyle{empty}' ."\n";
        $string .= '\newsavebox{\formulabox}' ."\n";
        $string .= '\newlength{\formulawidth}' ."\n";
        $string .= '\newlength{\formulaheight}' ."\n";
        $string .= '\newlength{\formuladepth}' ."\n";
        $string .= '\setlength{\topskip}{0pt}' ."\n";
        $string .= '\setlength{\parindent}{0pt}' ."\n";
        $string .= '\setlength{\abovedisplayskip}{0pt}' ."\n";
        $string .= '\setlength{\belowdisplayskip}{0pt}' ."\n";
        $string .= '\begin{lrbox}{\formulabox}' ."\n";
        $string .= "$\\ ".$latex_formula."$\n";
        $string .= '\end{lrbox}' ."\n";
        $string .= '\settowidth {\formulawidth}  {\usebox{\formulabox}}' ."\n";
        $string .= '\settoheight{\formulaheight} {\usebox{\formulabox}}' ."\n";
        $string .= '\settodepth {\formuladepth}  {\usebox{\formulabox}}' ."\n";
        $string .= '\newwrite\foo' ."\n";
        $string .= '\immediate\openout\foo=\jobname.depth' ."\n";
        $string .= '    \addtolength{\formuladepth} {1pt}' ."\n";
        $string .= '    \immediate\write\foo{\the\formuladepth}' ."\n";
        $string .= '\closeout\foo' ."\n";
        $string .= '\begin{document}' ."\n";
        $string .= '\usebox{\formulabox}' ."\n";
        $string .= '\end{document}' ."\n";

        return $string;
    }

And that does the trick.  This was a problem as of Aug 1, 2008, with version v0.8 of class.latexrender.php.