emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org mode table alignment issue with CJK characters
@ 2023-03-23 14:44 Zelphir Kaltstahl
  2023-03-25 12:56 ` Zelphir Kaltstahl
  2023-03-25 17:55 ` Ihor Radchenko
  0 siblings, 2 replies; 5+ messages in thread
From: Zelphir Kaltstahl @ 2023-03-23 14:44 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 2402 bytes --]

Hello org mode users!

I recently looked into getting org mode tables to properly align cell borders 
and table border, when using Chinese characters in them.

I found out, that there is valign mode [1] and was happy with it for a few days. 
But then I opened a document with lots of tables and some of those tables bigger 
than what I had before in other documents. Scrolling inside that document became 
quite laggy. So teeth-gnashingly I deactivated valign mode, already suspecting 
it to be the culprit. And I was right. After deactivating it, I could scroll 
perfectly fine again.

So I returned to the second alternative I had found out about, when searching 
for a solution: Finding a font, which renders Chinese characters at exactly 
double the width of latin/ASCII characters. I found a font named "Sarasa" [2] 
and experimented a bit with setting the font globally, then setting it only when 
opening an org mode buffer. Now it looks like that font does character widths 
almost correctly (see attached screenshot, see slightly wider 4 ASCII characters 
than 2 Chinese characters).

My settings for org mode regarding fonts/faces are:

~~~~
(add-hook 'org-mode-hook
           (function
            (lambda ()
              ;; Only do the following in graphical mode, as it will
              ;; break when using emacs in terminal mode.
              (when (display-graphic-p)
                ;; Sarasa font is fromhttps://github.com/be5invis/Sarasa-Gothic.
                (setq buffer-face-mode-face
                      '(:family "Sarasa Mono CL"
                        :weight normal
                        :height 110))
                (buffer-face-mode)))))
~~~~

However, it seems, that now org mode does not align tables correctly, even 
though an ASCII character is half the width of a Chinese character in the 
tables. Org mode seems to add too few or too many spaces, which are displayed as 
spaces of various width.—Is that because of the 1 pixel width difference?

Do I need to look for another font, which does things truly exactly, no 1 pixel 
too wide funny business? Maybe someone knows a more exact font?

Ultimately: How can I make tables align correctly?

My Emacs version is: GNU Emacs 28.2

My org mode version is: 9.6.1

[1]: https://github.com/casouri/valign

[2]: https://github.com/be5invis/Sarasa-Gothic

-- 
repositories:https://notabug.org/ZelphirKaltstahl

[-- Attachment #1.2: Type: text/html, Size: 3169 bytes --]

[-- Attachment #2: emacs-font-rendering.png --]
[-- Type: image/png, Size: 91159 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: org mode table alignment issue with CJK characters
  2023-03-23 14:44 org mode table alignment issue with CJK characters Zelphir Kaltstahl
@ 2023-03-25 12:56 ` Zelphir Kaltstahl
  2023-03-25 17:55 ` Ihor Radchenko
  1 sibling, 0 replies; 5+ messages in thread
From: Zelphir Kaltstahl @ 2023-03-25 12:56 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 2857 bytes --]

On 3/23/23 15:44, Zelphir Kaltstahl wrote:
>
> Hello org mode users!
>
> I recently looked into getting org mode tables to properly align cell borders 
> and table border, when using Chinese characters in them.
>
> I found out, that there is valign mode [1] and was happy with it for a few 
> days. But then I opened a document with lots of tables and some of those 
> tables bigger than what I had before in other documents. Scrolling inside that 
> document became quite laggy. So teeth-gnashingly I deactivated valign mode, 
> already suspecting it to be the culprit. And I was right. After deactivating 
> it, I could scroll perfectly fine again.
>
> So I returned to the second alternative I had found out about, when searching 
> for a solution: Finding a font, which renders Chinese characters at exactly 
> double the width of latin/ASCII characters. I found a font named "Sarasa" [2] 
> and experimented a bit with setting the font globally, then setting it only 
> when opening an org mode buffer. Now it looks like that font does character 
> widths almost correctly (see attached screenshot, see slightly wider 4 ASCII 
> characters than 2 Chinese characters).
>
> My settings for org mode regarding fonts/faces are:
>
> ~~~~
> (add-hook 'org-mode-hook
>            (function
>             (lambda ()
>               ;; Only do the following in graphical mode, as it will
>               ;; break when using emacs in terminal mode.
>               (when (display-graphic-p)
>                 ;; Sarasa font is fromhttps://github.com/be5invis/Sarasa-Gothic.
>                 (setq buffer-face-mode-face
>                       '(:family "Sarasa Mono CL"
>                         :weight normal
>                         :height 110))
>                 (buffer-face-mode)))))
> ~~~~
>
> However, it seems, that now org mode does not align tables correctly, even 
> though an ASCII character is half the width of a Chinese character in the 
> tables. Org mode seems to add too few or too many spaces, which are displayed 
> as spaces of various width.—Is that because of the 1 pixel width difference?
>
> Do I need to look for another font, which does things truly exactly, no 1 
> pixel too wide funny business? Maybe someone knows a more exact font?
>
> Ultimately: How can I make tables align correctly?
>
> My Emacs version is: GNU Emacs 28.2
>
> My org mode version is: 9.6.1
>
> [1]: https://github.com/casouri/valign
>
> [2]: https://github.com/be5invis/Sarasa-Gothic
>
I have tried something else today:

I looked at how the font is rendered in Libre Office. There it seems, that the 
characters align perfectly (see attached screenshot). So maybe this is an Emacs 
in general issue of font rendering, which adds a pixel to ASCII characters or 
takes one away from CJK characters?

-- 
repositories:https://notabug.org/ZelphirKaltstahl

[-- Attachment #1.2: Type: text/html, Size: 3987 bytes --]

[-- Attachment #2: libre-office-font-rendering.png --]
[-- Type: image/png, Size: 13183 bytes --]

[-- Attachment #3: emacs-font-rendering-2.png --]
[-- Type: image/png, Size: 24394 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: org mode table alignment issue with CJK characters
  2023-03-23 14:44 org mode table alignment issue with CJK characters Zelphir Kaltstahl
  2023-03-25 12:56 ` Zelphir Kaltstahl
@ 2023-03-25 17:55 ` Ihor Radchenko
  2023-03-25 18:27   ` Zelphir Kaltstahl
  1 sibling, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2023-03-25 17:55 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 396 bytes --]

Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> writes:

> My settings for org mode regarding fonts/faces are:
> ...

It may be tricky to get the scaling right sometimes.
I use the following:

;; Credit for the suggestion about `face-font-rescale-alist': @viz:okash.it (Matrix)
(push `("Sarasa Mono hc" . ,(/ 16.0 13.0)) face-font-rescale-alist)

An example table I created is aligned perfectly.


[-- Attachment #2: table-alignment.png --]
[-- Type: image/png, Size: 12279 bytes --]

[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: org mode table alignment issue with CJK characters
  2023-03-25 17:55 ` Ihor Radchenko
@ 2023-03-25 18:27   ` Zelphir Kaltstahl
  2023-03-25 19:01     ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Zelphir Kaltstahl @ 2023-03-25 18:27 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

On 3/25/23 18:55, Ihor Radchenko wrote:
> Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> writes:
>
>> My settings for org mode regarding fonts/faces are:
>> ...
> It may be tricky to get the scaling right sometimes.
> I use the following:
>
> ;; Credit for the suggestion about `face-font-rescale-alist': @viz:okash.it (Matrix)
> (push `("Sarasa Mono hc" . ,(/ 16.0 13.0)) face-font-rescale-alist)
>
> An example table I created is aligned perfectly.

Ahhh, thank you! That did it!

I saw some font scaling stuff suggested for other fonts, but thought, that it 
was not necessary for Sarasa.

Just in case I want to use other fonts at some point: How did you (or anyone 
else) derive the 16/13 number? Is there a general way, other than "try numbers 
and see what fits"?

-- 
repositories: https://notabug.org/ZelphirKaltstahl



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: org mode table alignment issue with CJK characters
  2023-03-25 18:27   ` Zelphir Kaltstahl
@ 2023-03-25 19:01     ` Ihor Radchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Ihor Radchenko @ 2023-03-25 19:01 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: emacs-orgmode

Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> writes:

> Just in case I want to use other fonts at some point: How did you (or anyone 
> else) derive the 16/13 number? Is there a general way, other than "try numbers 
> and see what fits"?

I did trial and error. AFAIU, it totally depends on the font's
width-to-height ratios. AFAIK, Emacs tries to make all the fonts have
the same height - leading to horizontal misalignment you observed. The
extra custom scaling will make line height vary for latin-only vs.
latin+CJK lines.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-25 19:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-23 14:44 org mode table alignment issue with CJK characters Zelphir Kaltstahl
2023-03-25 12:56 ` Zelphir Kaltstahl
2023-03-25 17:55 ` Ihor Radchenko
2023-03-25 18:27   ` Zelphir Kaltstahl
2023-03-25 19:01     ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).