
先日のシェル芸勉強会でLaTeX形式のファイルについての処理がテーマだった。 で、sedとかawkで頑張ってたのだが、なんか他に良いツールが無いものかと思い調べてみたところ、とりあえずプレーンテキスト(と言っていいのかわからないけど)に出力してくれるツール『OpenDetex』というものはあるようだったので、試しにインストールしてみる事にした。 検証にはUbuntu Server 16.04 LTSを用いる。
まず、以下のコマンドで前提となるパッケージを導入し、ソースを取得・コンパイルしてインストールする。
bash
sudo apt install make gcc flex
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/opendetex/opendetex-2.8.1.tar.bz2
tar xjvf opendetex-2.8.1.tar.bz2
cd opendetex
make && sudo make install
インストールできたら、後は以下のようにファイルを指定してコマンドを実行してやれば良い。
bashdetex ファイルPATH
(一部うまくテキスト化できてないような気もするが)確かにテキストに変換できている。 利用できるオプションはこんな感じ。
shellblacknon@BS-PUB-UBUNTU-01:~/ShellGeiData/vol.28$ detex --help detex: warning: unknown option ignored - - detex [ -clnstw ] [ -e environment-list ] [ filename[.tex] ... ] -c echo LaTeX \cite, \ref, and \pageref values -e list of LaTeX environments to ignore -l force latex mode -n do not follow \input and \include -s replace control sequences with space -t force tex mode -w word only output