pandoc-crossrefを使用すればできるらしい。
cabalのインストール
pandoc-crossrefはcabalでインストールできる。 Ubuntu 15.04では、下記のコマンドでcabalをインストールする。
$ sudo apt-get install cabal-install
pandoc-crossrefのインストール
下記のコマンドでsystem wideにpandoc-crossrefをインストールする。 --globalをつけることで/usr/localにインストールされるようになる。
$ sudo cabal install --global pandoc-crossref
推奨はsandboxを使用するようになっているが気にしない。
実行例
test.md
を以下のように作成する。
それぞれの年齢は{@tbl:age_tbl}の様になっている。
name age
----------------- ----------
Taro 18
Jiro 16
Saburo 12
: 年齢表 {#tbl:age_tbl}
これをHTML形式に変換してみる。
$ pandoc -s --filter pandoc-crossref -o test.html test.md
結果は以下のようになる。
それぞれの年齢は{tbl. 1}の様になっている。 Table 1: 年齢表 name age Taro 18 Jiro 16 Saburo 12
HTMLはこちら
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta name="generator" content="pandoc" /> <title></title> <style type="text/css">code{white-space: pre;}</style> </head> <body> <p>それぞれの年齢は{tbl. 1}の様になっている。</p> <table> <caption>Table 1: 年齢表</caption> <thead> <tr class="header"> <th align="center">name</th> <th align="center">age</th> </tr> </thead> <tbody> <tr class="odd"> <td align="center">Taro</td> <td align="center">18</td> </tr> <tr class="even"> <td align="center">Jiro</td> <td align="center">16</td> </tr> <tr class="odd"> <td align="center">Saburo</td> <td align="center">12</td> </tr> </tbody> </table> </body> </html>
設定ファイル
相互参照の表示がデフォルトでは{tbl. 1}
の様になっているが、日本語では表1
のようにしたい。
その場合yaml形式で設定ファイルを作成すると変更することができる。
$HOME/crossref_config.yaml
を以下のように作成する。
figureTitle: "図 " tableTitle: "表 " listingTitle: "コード " figPrefix: "図" eqnPrefix: "式" tblPrefix: "表" lstPrefix: "コード"
先ほどのtest.mdを変換してみる。
$ pandoc -s --filter pandoc-crossref -M "crossrefYaml=$HOME/crossref_config.yaml" -o test.html test.md
実行結果は以下のようになる
それぞれの年齢は 表 1 の様になっている。 表 1: 年齢表 name age Taro 18 Jiro 16 Saburo 12