LoginSignup
4
5

More than 5 years have passed since last update.

ターミナルとEmacsのフォントを12ポイントにする。

Posted at

EmacsでASCIIと日本語のフォントの横幅を調整する。

ASCIIのフォントと日本語のフォントは同じ12ポイントでも横幅が違うということがよくあります。これを調整するにはface-font-rescale-alistを使います。

~/.emacs.d/user-start.d/20fontset.el
;;; -*- mode: emacs-lisp; coding: utf-8-emacs; -*-

(if (and (locate-library "fontset")
         (fboundp 'add-to-list)
         (fboundp 'display-graphic-p))
    (progn
      (cond
       ((and (string-match "linux-gnu" system-configuration)
             (display-graphic-p))
        (add-to-list 'default-frame-alist '(font . "TakaoGothic-12"))
        (add-to-list 'initial-frame-alist '(font . "TakaoGothic-12"))
        (add-hook 'after-init-hook
                  (lambda () (set-frame-font "TakaoGothic-12"))))
       ((and (string-match "mingw-nt" system-configuration)
             (display-graphic-p))
        (add-to-list 'default-frame-alist '(font . "MS Gothic-12"))
        (add-to-list 'initial-frame-alist '(font . "MS Gothic-12"))
        (add-hook 'after-init-hook
                  (lambda () (set-frame-font "MS Gothic-12"))))
       ((and (string-match "apple-darwin" system-configuration)
             (display-graphic-p))
        (create-fontset-from-ascii-font
         "Menlo-12:weight=normal:slant=normal"
         nil
         "menlokakugo")
        (set-fontset-font
         "fontset-menlokakugo"
         'unicode
         (font-spec :family "Hiragino Kaku Gothic ProN" :size 12)
         nil
         'append)
        (add-to-list 'default-frame-alist '(font . "fontset-menlokakugo"))
        (add-to-list 'initial-frame-alist '(font . "fontset-menlokakugo"))
        (add-to-list 'face-font-rescale-alist 
                     '(".*Hiragino Kaku Gothic ProN.*" . 1.2))
        (add-hook 'after-init-hook
                  (lambda () (set-frame-font "fontset-menlokakugo")))))))

Menloの12ポイントとHiragino Kaku Gothic ProNの12ポイントでfontset-menlokakugoをつくっているのですが、このままではHiragino Kaku Gothic ProNの横幅がMenloの12ポイント2文字分に比べてやや小さく、「等幅」にならなくなってしまいます。

Emacsでは、フォント名のパターンに対して倍率を指定することでフォントの大きさを微調整することが可能です。そのためのコードが(add-to-list 'face-font-rescale-alist '(".*Hiragino Kaku Gothic ProN.*" . 1.2))で、これによってEmacsでASCIIと日本語のフォントの横幅を調整することが可能というわけです。

ターミナルでフォントを12ポイントにする。

こちらは単純にフォントとして「Menlo Regular 12 pt.」を指定するだけでよいようです。

なお、ターミナルの設定は書き出すことができるので、適当な名前で書き出しておくとよいかもしれません。

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5