Create a gist now

Instantly share code, notes, and snippets.

ruhoh plugin to overload the redcarpet parser with mathjax tags
# place mathjax.rb in _plugins directory of your blog
require 'redcarpet'
class HTMLwithAlbino < Redcarpet::Render::HTML
def block_code(code, language)
if language == 'mathjax'
"<script type=\"math/tex; mode=display\">
#{code}
</script>"
else
"<pre><code class=\"#{language}\">#{code}</code></pre>"
end
end
def codespan(code)
if code[0] == "$" && code[-1] == "$"
code.gsub!(/^\$/,'')
code.gsub!(/\$$/,'')
"<script type=\"math/tex\">#{code}</script>"
else
"<code>#{code}</code>"
end
end
end
class Ruhoh
module Converter
module Markdown
def self.extensions
['.md', '.markdown']
end
def self.convert(page)
markdown = Redcarpet::Markdown.new(HTMLwithAlbino.new(:with_toc_data => true),
:autolink => true,
:fenced_code_blocks => true
)
markdown.render(page.content)
end
end
end
end
---
title: Numerical Differentiation
description:
layout: page
---
## Derivative of a real function
The derivative of `$f(x)$` is
````mathjax
\begin{equation}
f'(x) = \lim_{h \rightarrow 0} \frac{f(x + h) - f(x)}{h} \label{eq:DerivativeDef}
\end{equation}
````
suggest a naive approach to compute a numerical derivative: pick a small value `$h$` and apply \eqref{eq:DerivativeDef}. However, applied uncritically, this procedure is almost guaranteed to produce inaccurate results.
[Ridders](#Ridders) applied Romberg's method to improve the accuracy in the computation of the first and second derivatives of a real function. Using the Taylor expansion in the vicinity of `$x$`:
$$
f'(x) \approx \frac{f(x + h) - f(x - h)}{2h}
$$
with a truncation error of `$e_t \sim h^2 f^{(3)}$`. As a consequence, `$e_t$` decreases quadratically with decreasing `$h$`.
@MartinThoma

Is it possible to use only $e^x$ (without backticks) to trigger MathJax?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment