SST Lab Dokuwiki Header header picture

ユーザ用ツール

サイト用ツール


linux:mathtex_install

MathTeXのインストール

今となってはMathJaxがあれば全て幸せということなのだが、不幸せの種は尽きないわけでMathTeXやらmimeTeXはいつでも有効。というわけでここではMathTeXをインストールしてみよう。 http://www.forkosh.com/mathtex.htmlを読め、ということなのだが

  1. $\TeX$ ($\LaTeX$)のタイプセッタとdvipngのインストール
    $ sudo apt install texlive-full

    こんな感じでインストールできる。dvipngも同時にインストールされるはずだが、もしインストールされない場合は

    $ sudo apt install dvipng

    どちらも

    $ latex --version
    pdfTeX 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian)
    kpathsea version 6.2.1
    Copyright 2015 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
    There is NO warranty.  Redistribution of this software is
    covered by the terms of both the pdfTeX copyright and
    the Lesser GNU General Public License.
    For more information about these matters, see the file
    named COPYING and the pdfTeX source.
    Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
    Compiled with libpng 1.6.17; using libpng 1.6.17
    Compiled with zlib 1.2.8; using zlib 1.2.8
    Compiled with poppler version 0.41.0
    $ dvipng --version
    This is dvipng 1.15 Copyright 2002-2015 Jan-Ake Larsson
    dvipng 1.15
    kpathsea version 6.2.1
    Compiled with Freetype 2.5.2
    Using libft 2.6.1
    Copyright (C) 2002-2015 Jan-Ake Larsson.
    There is NO warranty.  You may redistribute this software
    under the terms of the GNU Lesser General Public License
    version 3, see the COPYING file in the dvipng distribution
    or <http://www.gnu.org/licenses/>.
    $ 

    みたいにすればチェックできる。

  2. MathTeXのダウンロード
    $ wget http://www.forkosh.com/mathtex.zip
  3. MathTeXの展開
    $ mkdir mathtex
    $ cp mathtex.zip mathtex/
    $ cd mathtex
    $ unzip mathtex.zip

    配布されているzipファイルはディレクトリごとアーカイブしたものではないのでディレクトリを切ってからそこで解凍すること。

  4. MathTeXのコンパイル
    $ cc mathtex.c -DLATEX=\"$(which latex)\" \
                   -DDVIPNG=\"$(which dvipng)\" \
                   -o   mathtex.cgi 
    $

    素のままのubuntu serverだとgccも入っていないのでgcc入れるとこからやる必要あり。

  5. mathtex.cgiのテスト
    $ ./mathtex.cgi "x^2+y^2" -m9 -o test
    +-----------------------------------------------------------------------+
    |mathTeX vers 1.06 , Copyright(c) 2007-2017, John Forkosh Associates, Inc|
    +-----------------------------------------------------------------------+
    | mathTeX is free software, licensed to you under terms of the GNU/GPL  |
    |           and comes with absolutely no warranty whatsoever.           |
    |     See http://www.forkosh.com/mathtex.html for complete details.     |
    +-----------------------------------------------------------------------+
     
    mathTeX> running image: ./mathtex.cgi
     
    mathTeX> home directory: /home/kimi/mathtex/
     
    mathTeX> input expression: x^2+y^2
     
    mathTeX> Built-in timelimit: warn/killtime=-1/10, path=none
     
    mathTeX> working directory: 8dfaf8281769c217b7e78b27a4747285
     
    mathTeX> latex command executed:
             /usr/bin/latex latex.tex < reply.txt >latex.out 2>latex.err
     
    mathTeX> system() return status: 0
     
    mathTeX> output image file: test.gif
     
    mathTeX> dvipng command executed:
             /usr/bin/dvipng --gif -D 120 --gamma 2.5 -bg Transparent -T
             tight -v -o ../test.gif latex.dvi >dvipng.out 2>dvipng.err
    $

    test.gifという名前のこんなのができていればOK

  6. mathTeX(mathtex.cgi)のインストール
    $ sudo cp mathtex.cgi /usr/lib/cgi-bin/
    $ sudo chown www-data.www-data /usr/lib/cgi-bin/mathtex.cgi
    $ sudo mkdir /usr/lib/cgi-bin/mathtex
    $ sudo chown -R www-data.www-data /usr/lib/cgi-bin/mathtex
    $ sudo a2enmod cgid
    $ sudo service apache2 restart

    ubuntu server 16.XX.XXのapache2の場合CGIスクリプトは/usr/lib/cgi-binに置かれる。そこで出来上がったmathtex.cgiをコピーし、MathTeXのキャッシュディレクトリや作業用ディレクトリに適切なパーミッションを設定する。その後CGIスクリプトを有効化しapache2を再起動する。上記作業手順にはCGIスクリプトが作業用ディレクトリを作成できるようにする作業を意図的に記載していない。この部分をセキュアにする自信のない者はそもそもこういったことをしようと思ってはいけない。

  7. CGIスクリプトのテスト
    sample.html
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>MathTeX動作テスト</title>
    </head>
    <body>
    <img src="http://ip_address_or_FQDN/cgi-bin/mathtex.cgi?{f(x)=\int_{-\infty}^xe^{-t^2}dt}" alt="eq" />
    </body>
    </html>

    Webブラウザに上記のようなファイルを表示させてみて意図通りに表示されていればOK。

linux/mathtex_install.txt · 最終更新: 2022/08/23 13:34 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki