Emacs 图片支持

新装了最新的官方 Emacs 24.1,一启动发现图片不是光滑的 png 而是 xpm
于是查看 png 支持
M-: (image-type-available-p 'png) RET
返回nil。再看
C-h v libpng-version RET
返回 10403。这才想起来官方 Windows 版里面不带 libpng,原来的版本里面 libpng 版本可能不对。去 bin 目录下面看果然发现 libpng 是 1.2 版本。下载新的 1.4 版本 libpng14-14.dll 替换搞定。
另外实际上 Emacs 显示 png 还需要 zlib1.dll。

补:现在24.4版本里面已经需要10612版。

所有的文件都可以在这里下载。

Wrong type argument error in pst-node style of AUCTeX

Using AUCTeX 11.86 under Emacs 24.0.50.1. Activated pst-node style. Pressed C-c C-e to insert a psmatrix environment, entered nothing on “Options” and encountered the error:
let: Wrong type argument: char-or-string-p, (“”)

The “Options” can auto-complete with psmatrix options such as rowsep, colsep… Still didn’t work even if I entered something. Checked the pst-node.el under /emacs/site-lisp/auctex/style/:

;;; Environments
(defun LaTeX-pstnode-env-psmatrix (env)
  "Return psmatrix environment with arguments."
  (let ((opt (completing-read-multiple "Options: "
                                       LaTeX-pstnode-psmatrix-list)))
    (LaTeX-insert-environment env opt)))

completing-read-multiple comes from crm.el, which enables the multiple auto completion. The return value is a list instead of a string, so LaTeX-insert-environment won’t accept it. Fixed the code as follows to loop over the list and insert the option items with comma and square brackets. It doesn’t look neat but it works anyway.

;;; Environments
;;; Changed by James Lao
(defun LaTeX-pstnode-env-psmatrix (env)
  "Return psmatrix environment with arguments."
  (let ((opt (completing-read-multiple "Options: "
                                       LaTeX-pstnode-psmatrix-list)))
    (setq opto "")
    (while opt
      (if (string= opto "")
	  (setq opto (car opt))
      (setq opto (concat opto ", " (car opt))))
      (setq opt (cdr opt)))
    (LaTeX-insert-environment env (concat "[" opto "]"))))

I’ve never used the mailing list and would appreciate if someone could help me check with the development team…

preview-latex在GS9.00下报错

在emacs下其实很久不用preview-latex了,一直觉得没有必要——但是忽然用一下的时候发现不能用还是很郁闷的。基本上报错是这样的:

"GSWIN32C.EXE" "-dOutputFile=(_region_.prv/tmp5723kvc/pr1-1.png)" "-q""-dSAFER" "-dNOPAUSE" "-DNOPLATFONTS" "-dPrinted" "-dTextAlphaBits=4""-dGraphicsAlphaBits=4" "-sDEVICE=png16m" "-r70.4906x70.6156"
GS>{DELAYSAFER{.setsafe}if}stopped pop/.preview-BPcurrentpagedevice/BeginPage get dup null eq{pop{pop}bind}ifdef<</BeginPage{currentpagedevice/PageSize get dup 0 get 1 ne exch 1get 1 ne or{.preview-BP }{pop}ifelse}bind/PageSize[1 1]>>setpagedevice/preview-do{[count 3 roll save]3 1 roll dup length 0 eq{pop}{setpagedevice}{ifelse .runandhide}stopped{handleerror quit}if aload pop restore}bind def[(_region_.prv/tmp3712kvc/preview.dsc)(r)file]aload exch dup 0 setfileposition 520()/SubFileDecode filter cvx .runandhide aload pop dup dup 623 setfileposition 50()/SubFileDecode filter cvx<<>>preview-do
Error: /invalidfileaccess in --file--

查了一通后来发现有人遇到这个问题之后把GS降级到8.71以下就好了。说明GS在近来做了一些改动。左看右看看到了-dSAFER这个参数——这个参数本意是要加强权限检查防止gs自动打开系统文件权限——但和权限相关的也只有它了。试着在命令行下重新跑着两个命令(用gswin32会容易些,否则后面这个长命令贴都贴不进去),居然跑通了。又大致查了查,貌似可能是一个BUG,不过我升级到了最新的9.02也没有解决这个问题。

既然如此,到site-lisp/auctex/preview.elc(最好还是用.el重新编译一下) 下面找到
(defcustom preview-gs-options '("-q" "-dSAFER" "-dNOPAUSE" "-DNOPLATFONTS" "-dPrinted" "-dTextAlphaBits=4" "-dGraphicsAlphaBits=4")
-dSAFER一项干掉就是了。虽然这似乎是一个“漏洞”,不过就自己跑跑preview来看,应该没太大风险。

一个更为稳妥的办法是在.emacs里面加上'(preview-gs-options (quote ("-q" "-dNOPAUSE" "-DNOPLATFONTS" "-dPrinted" "-dTextAlphaBits=4" "-dGraphicsAlphaBits=4"))),就好了