とある事情で、Ubuntu上ではUTF-8およびShift_JISの2種類のTeX文書を処理している。一々 platex -kanji=utf8 とか platex -kanji=sjis とか、したくないので、文字コードを判別してから組版し、ついでにPDFに変換して文書ビューアで表示させる Perl スクリプトを作ってみた。
ユーザーは自分だけなので、思いっきり手抜きだが、まずまず役立っている。
#! /usr/bin/perl -w # # [usage] myplatex hoge # hoge.tex の文字コードを判別して、platex -kanji=KANJICODE とコンパイル # 引き続いて dvipdfmx で PDF を作り、文書ビューアー evince を起動する # とりあえず,普段使っている UTF-8 と Shift_JIS のみサポート use strict; my $basename; # hoge my $texfile; # hoge.tex my $dvifile; # hoge.dvi my $pdffile; # hoge.pdf my $kanjicode; # UTF-8, Shift_JIS $basename = $ARGV[0]; $texfile = $basename."\.tex"; $dvifile = $basename."\.dvi"; $pdffile = $basename."\.pdf"; open (INFILE, "<$texfile") || die "File Not Found\n"; close INFILE; $kanjicode = `nkf -g $texfile`; chomp($kanjicode); if ($kanjicode eq "UTF-8") { system("platex -kanji=utf8 -interaction=nonstopmode $texfile"); } elsif ($kanjicode eq "Shift_JIS") { system("platex -kanji=sjis -interaction=nonstopmode $texfile"); } else { die "Not supported\n"; } system("dvipdfmx $dvifile"); system("evince $pdffile");
It’s always pleasant to find a new website this excellent. I’ll be back here for certain!