TextMate2メモ(4) LaTeX Bundleの変更(別バージョン)

TextMateのLaTeX bundleで,LaTeXの実行を指示している箇所が texmate.py にあるので,そこを直接修正することで uplatex での組版ができるようにした。具体的には,pdflatexが選択されているときは,これをptex2pdfで置き換え,また,latexが選択されているときは,これをuplatexで置き換えた。また,latexのあとは,dviをpdfに変換するのだが,dvi2psとps2pdfの組合せの代わりに,dvipdfmxを使うように変更した。具体的は変更は以下の通り。

編集するファイルは,
~/Library/Application Support/TextMate/Managed/Bundles/latex.tmbundle/Support/bin/texmate.py
補助的な関数の定義のあと,914行目からメインのルーティンが始まる。command の種類によって,様々な処理を行うようになっているが,メインは command が latex の場合。そこで,途中の
elif command == 'latex':
以下のブロック(1044行目あたり以降)を次のように書き換えた。

    elif command == 'latex':
        engine_options = construct_engine_options(typesetting_directives,
                                                  tm_engine_options, synctex)
        if engine == 'latex':
            engine = 'uplatex'
            engine_options = "-shell-escape -synctex=1 -interaction=nonstopmode"
        elif engine == 'pdflatex':
            engine = 'ptex2pdf'
            engine_options = "-u -l -ot \"-interaction=nonstopmode -synctex=1 -file-line-error -shell-escape\" "

        command = "{} {}".format(engine, engine_options)
        status = run_latex(command, filename, cache_filename, verbose)
        tex_status, fatal_error, number_errors, number_warnings = status
        number_runs = 1

        if engine == 'latex':
        #    call("dvips {0}.dvi -o '{0}.ps'".format(file_without_suffix),
        #         shell=True)
        #    call("ps2pdf '{}.ps'".format(file_without_suffix), shell=True)
            call("dvipdfmx {0}.dvi", shell=True)
        if tm_autoview and number_errors < 1 and not suppress_viewer:
            viewer_status = run_viewer(
                viewer, filepath, pdffile_path,
                number_errors > 1 or number_warnings > 0 and
                tm_preferences['latexKeepLogWin'],
                'pdfsync' in packages or synctex, line_number)

TextMate2メモ(3) LaTeX Bundleの変更(簡易版)

TextMateのLaTeX bundleは,platex, uplatexをサポートしていない。また,デフォルトはpdflatexとなっている。自分が使いたいのは,uplatexなので,最小限の手間でこれが使えるようにした。実際には,ptex2pdf を使うことにした。これが uplatex, dvipdfmx を順に呼び出してPDFを作るので,pdflatexと同じというわけだ。

~/Library/Application Support/TextMate/Managed/Bundles/latex.tmbundle/Support/lib/Python/tmprefs.py を編集する。36行目からの

        self.default_values = {
            'latexAutoView': True,
            'latexEngine': "pdflatex",
            'latexEngineOptions': "",
            'latexVerbose': False,
            'latexUselatexmk': True,
            'latexViewer': "TextMate",
            'latexKeepLogWin': True,
            'latexDebug': False,
        }

を次のように書き換えた。

        self.default_values = {
            'latexAutoView': True,
            'latexEngine': "ptex2pdf",
            'latexEngineOptions': '-u -l -ot "-synctex=1 -file-line-error -shell-escape"',
            'latexVerbose': True,
            'latexUselatexmk': False,
            'latexViewer': "TextMate",
            'latexKeepLogWin': True,
            'latexDebug': False,
        }

ポイントは,デフォルトのlatexEngineをptex2pdfにして,デフォルトのlatexEngineOptionsを-u -l -ot “-synctex=1 -file-line-error -shell-escape” にしたこと。これで,とりあえずコンパイルできる。ただし,コンソールを見ると,冒頭部分に,
Multiple filename arguments? OK, I’ll take the latter one.
と出力されるので,良きに計らってはくれているものの,パラメーターが正しく渡されていないようだ。

TextMate2メモ(2)

TextMateのLaTeX bundleに変更を施すことにした。これはGitHubで公開されている。GitHubのLaTeX Bundleサイト によれば,TextMateでインストールしたものを一旦アンインストールし,しかるのちに,Git Cloneすべし,とのこと。

そこで,まず,アンインストール。そして,~/Library/Application Support/TextMate/Managed/Bundles/ に行って,ターミナルを開き(あるいは,ターミナルから,

cd ~/Library/Application Support/TextMate/Managed/Bundles/

として) そこで,git clone する。つまり,

git clone https://github.com/textmate/latex.tmbundle.git

とする。拡張子 tmbundleはファインダーから見ると1個のファイルのようだが,実はこれはディレクトリー。ターミナルからls -alするとわかる。そこで,中に入っていくと,いろんなファイルを見ることができる。

ということで,GitHubから落としてきたものに対して変更を加えることにする。

TextMate2メモ(1)

そういえば TextMate というプログラマー御用達のエディターがあったなあ,と検索。以前は日本語が使えなかったと思うが,最新のTextMate2 では普通に日本語が使えるらしい。LaTeX Bundleもあるが,デフォルトがpdflatexで,platex, uplatexは選べない。

ちょっと工夫すれば,uplatex でのコンパイルも出来るようだ。以下,メモ。

一番お手軽なのは,TeX文書の冒頭に,

%!TEX TS-program = ptex2pdf
%!TEX TS-options = -u -l

と,UNIXのshebang的な指示を加えること。ただし,これはエディターによって形式が異なり,TextMateのものは,TeXShopやSublime Textのものとは少し異なっているようだ。できれば,これじゃなく,LaTeX Bundleに手を加えてみたい。