2

When I try to make a table that has Korean character (한글) mixed with English words, the table becomes unaligned, and according to an answer about Japanese found here the the same problem with Japanese letters, it seems English letters, and Japanese letters have different base pixel sizes, and thus something needs to be changed at the operating system level.

Table with messed up alignment

Here it is in plain text:

| English word      | Korean word | Memorized? |
|-------------------+-------------+------------|
| friend            | 친구        | yes        |
| to eat            | 먹다        | yes        |
| this row          | is just     | English    |
| to bring with you | 가지고 가다 | no         |

I'm using MacOs Mojave, and actually using spacemacs, any ideas what I can do? Thank you.

eeowaa
  • 342
  • 1
  • 11
Jim Larsen
  • 141
  • 4
  • Have you checked the `string-width` of Korean and Latin characters with your font like suggested in the question you've linked to? Can you add information about your font configuration so people won't have to guess what fonts are you using? –  Mar 26 '19 at 20:33
  • I'm sorry but what do you mean by checking my string-width? Is that within macOS or within spacemacs? – Jim Larsen Mar 27 '19 at 03:21
  • You'll want to call `string-width` from Emacs with strings with Latin and Korean characters, with the easiest way being the scratch buffer. –  Mar 27 '19 at 17:05
  • Could you paste the actual text instead of just a screenshot? I'm interested in digging into this, and being able to copy your example into Emacs would help. – eeowaa Mar 28 '19 at 02:13
  • @DoMiNeLa10 I'm very sorry, but I don't know how to call something like that. I'm very new to spacemacs, emacs, org-mode... everything. I tried typing :string-width to no avail. – Jim Larsen Mar 28 '19 at 03:32
  • @Sam this is my copy and paste from the org file | English word | Korean word | Memorized? | |-------------------+-------------+------------| | friend | 친구 | yes | | to eat | 먹다 | yes | | this row | is just | English | | to bring with you | 가지고 가다 | no | I'm not sure if there is a better way to show this information, please tell me. – Jim Larsen Mar 28 '19 at 03:36
  • @JimLarsen I just edited your question to display the table as preformatted text. Until the edit gets reviewed, however, it will not show to other users. – eeowaa Mar 28 '19 at 03:43
  • @Sam ah! thank you very much! I'm (obviously) new to all of this. If there is anything I can do to edit the original questions to include you block quote, please tell, otherwise, I shall wait for the review – Jim Larsen Mar 28 '19 at 04:16
  • Customize the fonts to ensure the width of one Korean character is twice as one Latin character, and the terminal emulators do this out-of-the-box, thus Emacs insides them doesn't have such issue. – xuchunyang Mar 28 '19 at 04:29
  • Try yanking this into the scratch buffer: `(string-width "y") (string-width "먹")` and typing `C-j` after each expression. You'll probably get `1` and `2` respectively. You should also measure the width of both types of characters in pixels, they should be divisible, and if they aren't, you'll need to tweak your font settings. –  Mar 28 '19 at 07:01
  • @xuchunyang customize the fonts within macOS or within gnumacs? This is where I have some confusion as to the solution. – Jim Larsen Mar 29 '19 at 04:09
  • @DoMiNeLa10 thank you for being very specific with the command I'm supposed to use "C-j" but I'm using spacemacs and hitting C-j both in insert mode and in normal does not tell me anything about the character widths. – Jim Larsen Mar 29 '19 at 04:10
  • @JimLarsen Within Emacs. [Here](https://github.com/xuchunyang/emacs.d/blob/ef5f0e6877026c26fbde53b30a4bd98367bafc3a/init.el#L227-L232) is my configuration for aligning Chinese and English, for example. – xuchunyang Mar 29 '19 at 12:19
  • @JimLarsen You can use `eval-expression` (bound to `M-:` by default to evaluate these expressions one by one). –  Mar 29 '19 at 17:07
  • @DoMiNeLa10 I tried using the eval-expression and when I do it goes like this: eval-expression I put in "t" (without the quotes) and then it just spits back "t" if I put in a Korean symbol, I get the error ``` Debugger entered--Lisp error: (void-variable ㅗ) eval(ㅗ nil) eval-expression(ㅗ nil nil 127) funcall-interactively(eval-expression ㅗ nil nil 127) call-interactively(eval-expression nil nil) command-execute(eval-expression) ``` I guess that command is supposed to show me the width of each symbol? – Jim Larsen Mar 31 '19 at 04:28
  • @xuchunyang this is getting close to what I want, I'm trying to find the proper Korean font that will work, but it's requiring me to search the Korean internet which I'm not especially good at. I shall post the answer to my question if I figure it out... – Jim Larsen Mar 31 '19 at 04:31
  • @JimLarsen Try giving `eval-expression` something like `(string-width "먹")`. –  Mar 31 '19 at 09:32

1 Answers1

1

I'm more than three years late, but it can be fixed using face-font-rescale-alist.

For instance, with JuliaMono 15pt, D2Coding font can be scaled x1.2 to match the width:

(set-frame-font "JuliaMono 15" nil t)
(add-to-list 'default-frame-alist '(font . "JuliaMono 15"))

(defun set-hangul-font (_)
  (set-fontset-font t 'hangul (font-spec :name "D2Coding"))
  (setq face-font-rescale-alist '(("D2Coding" . 1.2))))
(add-to-list 'after-make-frame-functions #'set-hangul-font)

You'll need to fine-tune the size of the Korean font (and/or CJK fonts) of choice with different fonts and sizes.

screenshot

Jay Lee
  • 131
  • 5