You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Doesn't tabulate correctly with zero-width characters (Devanagari) #68
I tried your example (copy-pasting Devangari text, on Windows, tabulate 0.8.8), at it seems to work just fine:
In [28]: tbl = [["रषटर परकषण", 19.25],["123456789A", 0]]
In [29]: print(tabulate(tbl, headers=["Name","Score"]))
Name Score
---------- -------
रषटर परकषण 19.25
123456789A 0
In [30]: wcwidth.__version__
Out[30]: '0.2.5'
Maybe some zero-width characters were lost in copy-and-paste operation? Just in case, this is the hex dump of the string:
In [41]: [ "0x%04x"%ord(c) for c in tbl[0][0] ]
Out[41]:
['0x0930',
'0x0937',
'0x091f',
'0x0930',
'0x0020',
'0x092a',
'0x0930',
'0x0915',
'0x0937',
'0x0923']
And the length of the first column is calculated to be 10:
Unfortunately the Devanagari you copied was wrong. Even in that, you can see that the 0 in the second column is more to the right, or equivalently the Devanagari entry is to the left. Here's another test with the same string as yours on v0.8.9:
Name Points
---------- --------
रषटर परकषण 20
123456789A 0
The previous example:
Name Points
------------ --------
राष्ट्र परीक्षण 19.25
Test 0
Another example:
Name Points
-------------- --------
एक उत्तम उदाहरण 0.00
A nice example 0.00
There are also scripts like Devanagari that just don't seem to have a monospace representation. I was unable to get Windows to display Devanagari characters in console. They do display in Notepad, but they don't obey any kind of monospace font rules, at all.
If this is still true, then tabulate won't be able to format Devanagari tables as plain text.
As a workaround I suggest to use an output format which does not assume that all letters are the same width, like HTML.
I think it's just the problem of calculating visible length and formatting properly, probably the wcwidth devs would look into it better. HTML is not an option for me, so I use codeblocks to format it on the UX side (and also internally for docs).
Activity
Delta456 commentedon Jul 8, 2020
wcwidthdoesn't supports Devangari yet.astanin commentedon Feb 20, 2021
I tried your example (copy-pasting Devangari text, on Windows, tabulate 0.8.8), at it seems to work just fine:
Maybe some zero-width characters were lost in copy-and-paste operation? Just in case, this is the hex dump of the string:
And the length of the first column is calculated to be 10:
I don't read Devangari, and cannot tell if it is correct. If it's not, then you should report a bug to https://github.com/jquast/wcwidth/issues
If the issue is resolved, please let me know. There was a bug with the alignment of the wide characters fixed in 0.8.8.
siddhpant commentedon Feb 26, 2021
Unfortunately the Devanagari you copied was wrong. Even in that, you can see that the
0in the second column is more to the right, or equivalently the Devanagari entry is to the left. Here's another test with the same string as yours on v0.8.9:The previous example:
Another example:
astanin commentedon Feb 26, 2021
I took a look at https://docs.microsoft.com/en-us/typography/script-development/devanagari The writing system is complicated. And this begs a question, do monospaced Devanagari fonts even exist?
According to a random blog post from 2015:
If this is still true, then tabulate won't be able to format Devanagari tables as plain text.
As a workaround I suggest to use an output format which does not assume that all letters are the same width, like HTML.
siddhpant commentedon Mar 1, 2021
I think it's just the problem of calculating visible length and formatting properly, probably the wcwidth devs would look into it better. HTML is not an option for me, so I use codeblocks to format it on the UX side (and also internally for docs).
Thank you for taking out your time!
jquast commentedon Nov 13, 2023
This is resolved in the latest releases of wcwidth, thanks.