The following is a non-exhaustive list of tools that can be used as or combined into a preprocessors to finally generate LaTeX documents. My idea of “preprocessing” here includes converting markuped (reStructuredText, Markdown, MediaWiki, …) documents to LaTeX, custom markup extensions and Unicode character support.
I also include links to resources that look helpful w.r.t working with or extending the itemised tools.
Since I wanted to work with and thereby learn a contemporary scripting/dynamic language, I focused on tools written in Python and Ruby. The list nevertheless also contains tools written in other languages.
In a probability scenario with two possible results per turn (with probabilities p, q = 1 - p) the expected value had to be minimised. This is done in Mathematica with FindMinimum[{f, constraints}, {x, y, ...}], and in my case:
FindMinimum[
{2 p*q + 3 (p^3 + 2 p^2 q + q^2 p + q^3) + 4 (q^2 p^2 + q^3 p), q == 1 - p},
{p, q}
]