平衡点


2012/08/01

_ tDiary 復旧中です.

VPS を飛ばしてしまった & 設定のバックアップを取っていなかったので, ちまちまと復旧しています. tDiary 本体を弄った所も幾つかあったりしたので, それを思い出しながらです. 日記のデータが飛ばなかったのが救い, ですかねぇ...

_ MathJax 用の plugin を書いてみた.[Computer] [Ruby] [tDiary

数式表示. 以前は mimeTeX 使ったりしていたのですが最近はMathJax使うのが流行りらしいですね.

というわけで tDiary で MathJax を読み込むための plugin を書いてみたりしました.

# source: ruby
#-*- mode: ruby;  coding:utf-8; -*-
#
# load MathJax
#
# Copyright(C) 2012 Youhei SASAKI, All rights reserved.
# $Lastupdate: 2012/08/01 19:39:02$
#
# Author: Youhei SASAKI <uwabami@gfd-dennou.org>
# License: MIT(Expat)
#
# Code:
#
# Options:
mathjax_src = @options['mathjax_src'] || "http://cdn.mathjax.org/mathjax/latest/MathJax.js"
mathjax_config = @options['mathjax_config'] || "TeX-AMS_HTML"
mathjax_uri = "#{mathjax_src}?config=#{mathjax_config}"
x_mathjax_config = @options['x_mathjax_config'] ||
  %q{MathJax.Hub.Config({ tex2jax: { inlineMath: [['$','$']], displayMath: [['$$','$$']], processEscapes: true }});}
#
# Add Header
#
add_header_proc {
  head = ''
  head << %Q{\t<script type="text/x-mathjax-config">\n}
  head << %Q{\t  #{x_mathjax_config}\n}
  head << %Q{\t</script>\n}
  head << %Q{\t<script type="text/javascript" src="#{mathjax_uri}"></script>\n}
  head << %Q{\t<meta http-equiv="X-UA-Compatible" CONTENT="IE=EmulateIE7" />\n}
  head
}
# Add 'tex' notation
def tex(src)
  %Q{  <p>\$#{src}\$</p>\n<p> }
end

最後の部分は, これまでの日記データ内の TeX 記法部分を直すのが面倒だったので微妙にお茶を濁している所だったりして *1. というわけで数式のテストをしてみたり: $\displaystyle{\frac{\partial \mathbf{u}}{\partial t} + \mathbf{u}\cdot\nabla\mathbf{u} = -\frac{1}{\rho}\nabla{p}}$ ...良いみたいですね.

*1 processEscapes: true を processEscape: true と書いていて小一時間嵌ったのは内緒


連絡先など

portrait

最近の日記

一覧

Back to Top ▲