括弧の前後/カンマの後に空白を置いて、句読点を統一する ruby スクリプト

半角英数字の開き括弧の前、閉じ括弧の後、カンマの後には空白が必要。それを忘れてしまったときに使うスクリプト
日曜日に必要に迫られて書いてみた。ついでに句読点も統一する。

$KCODE="SJIS"

ARGV.each do |file|
  File.rename(file,file+".bak")
  src =open(file+".bak")
  dest = open(file,"w")
  src.each do |line|
    # append space after closing parenthesis
    line = line.gsub(/\)([^(」|}|、|。|,|.|\]|\}|\{|'|,|\.|\s)])/,') \1' )
    # append space befor opening parenthesis
    line = line.gsub(/([^(「|{|、|。|,|.|\[|\}|\{|'|,|\.|\s)])\(/,'\1 (' )
    # replace Japanese punctuation characters
    line = line.gsub( //, '')
    line = line.gsub( //, '')
    dest.print(line)
  end
  dest.close
  src.close
end

今見ると、コロン・セミコロンも例外にしないといけない気がする。

my blog pages have been moved / ひっそりとお引っ越し


My blog pages are moved from cocolog to Hatena diary (here).


cocologはメンテ落ちがひどいし、編集画面が変なリッチテキストで使いにくいので、こっちに引っ越します。
こっちは pukiwiki 記法そっくりの「はてな記法」が使えるので、気軽にメモできそう。

Describe a file path in a tex document / TeX でファイルパスを記述する方法

English

The url.sty package is very useful to describe URL or URL-like strings such as file path, but a path which contains space characters cannot be acceptable for the url package because the default behavior of url package trims any space characters. The solution for the problem is "obeyspaces" option.

\usepackage[obeyspaces]{url}

This option forces url package not to trim any space characters.

Another useful command is "\path" command. This command is also declared in the url package, which can describe a path containing back slash (a path separator in Windows) without escaping back slash.

\path{C:\Documents and Settings\tmishina}

Japanese

url.sty パッケージを使うと、URLもしくはそれに類する文字列を整形して表示してくれる。しかしファイルパスのように、スペース文字を含んでいる文字列を表示しようとするとうまくいかない。なぜならurl.styパッケージはデフォルトであらゆるスペース文字を削除するよう設定されているから。解決方法は "obeyspaces" オプションを付けること。

\usepackage[obeyspaces]{url}

これでスペース文字を削除しなくなる。

もうひとつ便利なコマンドが "\path"。これは url.sty で定義されているコマンドで、バックスラッシュ(円記号)をエスケープなしで使えるようになる。つまりWindowsのパスを簡単に書ける。

\path{C:\Documents and Settings\tmishina}

OpenOffice.org の SDK を使う

非常に有用なこちらのサイトが本日は 403 Forbidden で、ちょっと困ってしまいました…。

OOo SDK 2.1 を Eclipse 3.2 で使う(日本語)

細かなステップは下記の英語を参考にしてください。要は

  • types.rdb もバージョン管理に入れる
  • SDK インストール後にバッチファイルを走らせる必要はない。手動で IDL をコンパイルしたければ、OOoOOo SDK の exe/dll にパスを張る

ということです。

How to use OOo SDK 2.1 with Eclipse 3.2 (en)
Although there are some online tutorials (English, Japanese), they contains some old information. Followings are a simple direction to create a new UNO-IDL project with Eclipse IDE.

  1. get the installation packages of OpenOffice.org 2.1 and OpenOffice 2.1 SDK from openoffice.org, and install them into your computer. Paths that do not contain white space are better to install them (e.g., "C:/opt/ooo" is better than "C:/Program Files/OpenOffice.org 2.1")
  2. install Eclipse plugin. Use Eclipse Update Manager (start Eclipse, select Help -> Software Update -> Find and Install) with this site.
  3. Create a new UNO-IDL project.
  4. Be sure that "types.rdb" should not be ignored if you manage source code and materials under some version control system (other files such as ".urd" files do not be needed to manage by it). "types.rdb" can be retrieved as the output of IDL compiration and regmerge, but it's not so easy.

No more installation processes are needed. Some tutorials say that a batch file should be run, but current SDK does not require it. If you want to run some tool such as UNO-IDL compiler (idlc.exe), add paths of the OpenOffice.org program directory (default: C:/Program Files/OpenOffice.org 2.1/program) and the OpenOffice.org SDK bin directory (default C:/Program Files/OpenOffice.org 2.1 SDK/windows/bin) to the Windows environmental variable.

dvipdfmx で \CID{} でしか出ない字体を出力する

(Japanese only; this topic talks about the problem that the dvipdfmx
causes an error if a target tex source contains characters which cannot
be coded as MS932 (a.k.a. Shift_JIS) )

前回の設定だけでは、UnicodeBMP から外れた異体字(土口の「吉」など)は PDF に変換できません(Adobe-Japan1-6 の CMap がない、と言われる)。


対処方法は 「CMap を別途入手する」です。またまた奥村先生のページを参考にします。O'reilly の ftp サイトにある Adobe-Japan1-6 の CMap を get して、 .tar.Z を解凍してできたディレクトリの中身をC:\usr\local\share\texmf-local\fonts\cmap に上書きコピーします。


こうしておけば土口の「吉」も出力できます。


ただし、Windows 付属の MS 明朝には土口の「吉」のグリフ(字体)がないらしく、dvipdfmx での変換時にMS明朝を埋め込むような cid-x-local.map を指定するとエラーになってしまいます(ヒラギノ明朝なら問題ないはず)。小塚明朝にはちゃんとグリフが存在するので、フォントを埋め込んでなければ Adobe Reader で正しく表示できます。よって Windows ではフォントを埋め込まないほうがよいでしょう。

TeX: utf/otf package and dvipdfmx

(Japanese only; this topic talks about the problem that the dvipdfmx causes an error if a target tex source contains characters which cannot be coded as MS932 (a.k.a. Shift_JIS) )

年末に書店へ行ったら、奥村晴彦著「[改訂第4版]LaTeX2e美文書作成入門」が並べてあったので、買ってきました。第2版から買い続けているものの、未だに細かいところでアップデートが行われているので、買っておいて損はないと思います。

今回の改版は、私の感じたところでは、PDF関係やUnicode関係が主な変更点だと思います。
(大学院時代に Macヒラギノを埋め込んで「すげーきれいだー」とか悦に入ってたのを思い出す)

残念ながら、今現在でも「utf/otf パッケージとdvipdfm(x) を使って、 Unicode でしか表現できない文字を PDF 出力する」のは簡単ではないようです。少なくともこの「美文書作成入門」のCD-ROMから単純にインストールしただけでは PDF 出力できません(dvipdfmxがエラーを吐く)。以下の問題があります。
(「美文書作成入門」から Windows XP 環境にインストールした場合)

  1. dvipdfmxに、Unicode 用のフォントエンコーディングファイルがない
  2. dvipdfmxのフォントマップ(map)には、Unicode 文字列を表現するためのフォントが "KozMinPro-Regular-Acro.otf" と指定されているが、このフォントは TEXMF ディレクトリにインストールされない

まず (1) の問題に対処します。
(以下の例は、すべてのソフトウェアをデフォルト位置にインストールした場合の例です。インストール位置を変更している場合は読み替えてください)

対処方法 (1)

Adobe Reader 付属の CMap ファイルは再配布可能ということなので、コピーしてもライセンス上の問題は発生しないと思います。

続いて (2) ですが、こちらは二つの対処法があります。おすすめは「フォントを埋め込まない方法」です。理由はライセンス上の問題が発生しにくいことと、できあがった PDF ファイルが軽くなることです。

対処方法 (2a) フォントを埋め込まないように map ファイルを作る

  • リュウミンライトと中ゴシックBBB を指定した map ファイル(TeX Wiki の dvipdfm 向けフォント埋め込みなしサンプル)を c:\usr\local\share\texmf-local\fonts\map\dvipdfm\local\cid-x-local.map として保存する。
  • 以下のいずれかの方法をとる

    • dvipdfmx 実行時に、毎回 dvipdfmx -f cid-x-local.map foo.tex と指定する
    • C:\usr\local\share\texmf\dvipdfm\config\dvipdfmx.cfg の最後に "f cid-x-local.map" という行を追加する

対処方法 (2b) フォントを texmf ディレクトリに用意する

  1. Adobe Reader 8をインストールする。(脆弱性が発見されているので Adobe Reader 7 はダメ!
  2. C:\Program Files\Adobe\Acrobat 7.0\Resource\CIDFont の中身を C:\usr\local\share\texmf-local\fonts\opentype 以下にコピー(もしくはシンボリックリンク)する。

    • fonts ディレクトリ以下はデフォルトでは存在しないので、ディレクトリを作っておく。
    • そのときファイル名は"KozMinPro-Regular-Acro.otf" のように指定する(このファイル名は dvipdfmx を動かしたときに出るエラーから見つけてもよいし、C:\usr\local\share\texmf\fonts\map\dvipdfm\base\cid-x.map の記述を直接見てもよい)。

これで小塚明朝を埋め込んだ PDF を dvipdfmx を使って生成できます。ただし、Adobe Reader 付属のフォントは埋め込み用途を想定していないとのことなので(参考)、実用上は、ライセンス的に問題のないフォント(Mac OS X にプリインストールのヒラギノなど)を埋め込み用に使う必要がありそうです。