Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode Art #18357

Closed
vbraun opened this issue May 3, 2015 · 77 comments
Closed

Unicode Art #18357

vbraun opened this issue May 3, 2015 · 77 comments

Comments

@vbraun
Copy link
Member

vbraun commented May 3, 2015

There should be a variant of ascii art using unicode. It should share code with ascii art as appropriate.

Also, there are various typesetting-related modules in sage.misc: ascii art, latex, mathjax, .... They should be moved into a common package. I propose sage.typeset

CC: @sagetrac-elixyre

Component: user interface

Author: Volker Braun, Vincent Delecroix

Branch/Commit: a6cf84f

Reviewer: Vincent Delecroix, Volker Braun

Issue created by migration from https://trac.sagemath.org/ticket/18357

@vbraun vbraun added this to the sage-6.7 milestone May 3, 2015
@vbraun

This comment has been minimized.

@videlec
Copy link
Contributor

videlec commented May 3, 2015

comment:2

What would be your strategy here? A method _unicode_art_ on objects?

@vbraun
Copy link
Member Author

vbraun commented May 3, 2015

comment:3

Yes, objects should use _unicode_art_ to hook into unicode art generation.

@vbraun
Copy link
Member Author

vbraun commented May 4, 2015

Branch: u/vbraun/unicode_art

@novoselt
Copy link
Member

Commit: c8317b2

@novoselt
Copy link
Member

comment:5

Is it feasible to have generation of such art from _latex_ methods when no special one is provided? Is anyone aware of good converters? MathJax 2.5 has that "fast HTML preview" that appears before the formula is properly rendered, but it does not support \hline and other frame parts of arrays, for example.


New commits:

c8317b2initial implementation of unicode art

@vbraun
Copy link
Member Author

vbraun commented May 14, 2015

comment:6

The closest I know is http://asciitex.sourceforge.net, though really I don't think its feasible for complicated equations...

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 16, 2015

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

de3440ainitial implementation of unicode art
a73beeeAdd a OutputUnicodeArt rich output type

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 16, 2015

Changed commit from c8317b2 to a73beee

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 16, 2015

Changed commit from a73beee to 3ed994d

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 16, 2015

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

3ed994dAdd a OutputUnicodeArt rich output type

@vbraun
Copy link
Member Author

vbraun commented May 16, 2015

comment:9

Analogous to ascii art, the following works now:

sage: %display unicode_art
sage: identity_matrix(ZZ, 2)
⎛1 0⎞
⎝0 1⎠

@videlec
Copy link
Contributor

videlec commented May 16, 2015

comment:10

Replying to @vbraun:

Analogous to ascii art, the following works now:

Nice!

Though, on 6.7.rc0 I got

sage: %display unicode_art
value must be unset (None) or one of ('plain', 'ascii_art', 'latex'), got unicode_art

Vincent

@videlec
Copy link
Contributor

videlec commented May 16, 2015

comment:11

Replying to @videlec:

Replying to @vbraun:

Analogous to ascii art, the following works now:

Nice!

Though, on 6.7.rc0 I got...

It works perfectly fine after applying the branch! Sorry for the noise.

@videlec
Copy link
Contributor

videlec commented May 16, 2015

comment:12

Argh, the Dyck paths looks ugly. I am trying to do something but the BOX DIAGONALS do not match very well...

Do you know why in the ipython notebook we got a failure

sage: unicode_art(matrix([[2,2],[1,1]]))
Traceback (most recent call last):
...
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1: ordinal not in range(128)

Vincent

@videlec
Copy link
Contributor

videlec commented May 16, 2015

comment:13

A commit with unicode art for Dyck paths and Tableaux at u/vdelecroix/18357.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 16, 2015

Changed commit from 3ed994d to e41f4f6

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 16, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

e41f4f6Always use unicode for IPython backend

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 16, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

7616a94Trac 18357: unicode art for Dyck words and Tableaux
26e6221Merge branch 'u/vdelecroix/18357' #18357

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 16, 2015

Changed commit from e41f4f6 to 26e6221

@vbraun
Copy link
Member Author

vbraun commented May 16, 2015

comment:16

Fixed the IPython issue, it wants unicode instead of utf-8 encoded bytes.

I merged your branch

@videlec
Copy link
Contributor

videlec commented May 17, 2015

comment:17

Thanks for the inclusion.

I got other troubles with the Ipython notebook:

  • with %display unicode it can not export in pdf because latex failed
...
    ! Package ucs Error: Unknown Unicode character 9115 = U+239B,
    (ucs)                possibly declared in uni-35.def.
    (ucs)                Type H to see if it is available with options.
...
    l.225 ...lor}Out[{\color{outcolor}15}]:} ⎛2 2⎞
                                                      
    ? 
    ! Emergency stop.
     ...                                              
                                                      
    l.225 ...lor}Out[{\color{outcolor}15}]:} ⎛2 2⎞
                                                      
    !  ==> Fatal error occurred, no output PDF file produced!
    Transcript written on notebook.log.
  • if %display latex then it works fine in the browser for matrices but not for tableaux or Dyck paths. More precisely, I see the latex code.
  • if %display latex then after an export pdf, the output which is exported is not the latex one but the plain text! I thought that latex would be the ideal mode for notebooks for both the display and the export...

Vincent

@vbraun
Copy link
Member Author

vbraun commented May 17, 2015

comment:18

%display latex uses Sage's mathjax/latex. In particular, matrices are typeset by mathjax and not by this branch. Sage's latex also has problems with unicode that are unrelated to this ticket:

sage: latex(u'Motörhead')
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-4-0cfcb5f9dc0d> in <module>()
----> 1 latex(u'Motörhead')

/home/vbraun/Sage/git-develop/local/lib/python2.7/site-packages/sage/misc/latex.pyc in __call__(self, x, combine_all)
    925             return LatexExpr(f(x))
    926         except KeyError:
--> 927             return LatexExpr(str_function(str(x)))
    928 
    929 

UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 3: ordinal not in range(128)

@vbraun
Copy link
Member Author

vbraun commented May 17, 2015

comment:19

Upstream bug for PDF export with unicode ipython/ipython#7150 (closed as wontfix)

@videlec
Copy link
Contributor

videlec commented May 17, 2015

comment:20

Replying to @vbraun:

Upstream bug for PDF export with unicode ipython/ipython#7150 (closed as wontfix)

It is the author of the request who closes the issue... not sure it is a won't fix but he did not say how he fixed it for himself. Anyway, it looks like a Ipython notebook issue and not a Sage one. Would be nice to have this "export to pdf" feature using the latex output!

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 17, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

9a2405ause named constants instead of literals for matrix unicode art

@vbraun
Copy link
Member Author

vbraun commented May 26, 2015

comment:49

There are a number of doctest failures due to different baselines because of your changes, like:

File "src/sage/combinat/binary_tree.py", line 2511, in sage.combinat.binary_tree.BinaryTree.under
Failed example:
    ascii_art((b1, b2, b1 \ b2))
Expected:
    (   o    o        _o_   )
    (  / \    \      /   \  )
    ( o   o,   o,   o     o )
    (              / \      )
    (             o   o     )
Got:
    (   o  , o  ,     _o_   )
    (  / \    \      /   \  )
    ( o   o    o    o     o )
    (              / \      )
    (             o   o     )

IMHO the previous baseline was better.

@videlec
Copy link
Contributor

videlec commented May 27, 2015

comment:50

Right. Sorry. With a one line modification I get the previous behavior. But do you really think that we should keep this behavior

            [                                       ]
            [ , o, ,   _o_        o      o      o   ]
            [         /   \             / \         ]
            [        o     o           o   o        ]
            [             / \                       ]
            [            o   o, ,  , ,      , ,  ,  ]

Would be better with all commas at the same position, isn't it?

Vincent

@vbraun
Copy link
Member Author

vbraun commented May 27, 2015

comment:51

I think ideally the boxes are vertically aligned along their baseline (=bottom of the box in this case):

            [                                       ]
            [          _o_                          ]
            [         /   \                         ]
            [        o     o             o          ]
            [             / \           / \         ]
            [ , o, ,     o   o, , o, , o   o, , o,  ]

though we don't necessarily have to do it on this ticket.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 27, 2015

Changed commit from 2b0207c to a27bfe5

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 27, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

a27bfe5Trac #18357: fix the position of the separator for lists

@videlec
Copy link
Contributor

videlec commented May 27, 2015

comment:53

Replying to @vbraun:

I think ideally the boxes are vertically aligned along their baseline (=bottom of the box in this case):

though we don't necessarily have to do it on this ticket.

I hope it implies "you can do it". I did a test all and it went smoothly.

Vincent

@vbraun
Copy link
Member Author

vbraun commented May 27, 2015

comment:54

The commas are now on the common base line, but the constituent object is still top-aligned instead of aligned on the baseline:

[ o    o   ]     
[     / \  ]     
[  , o   o ]

instead of

[      o   ]     
[     / \  ]     
[ o, o   o ]

@videlec
Copy link
Contributor

videlec commented May 27, 2015

comment:55

I am not responsible for that (with current develop version)

sage: b3 = BinaryTrees(3).an_element()
sage: b1 = BinaryTrees(1).an_element()
sage: ascii_art(b1) + ascii_art(b3) + ascii_art(b1)
oo    o
  \   
   o  
    \ 
     o

You would like to change the semantic of __add__? Of course it would make sense that the objects get aligned on their baseline (I thought it was precisely the purpose of baseline).

That way, I could remove the current hack for the separator as it will naturally appear on the baseline.

@vbraun
Copy link
Member Author

vbraun commented May 27, 2015

comment:56

I think that we should follow the usual glyph layout convention, which always aligns on the baseline as you said. Right now its pretty confusing to have such a huge space between the top-aligned object and the comma at the bottom.

@videlec
Copy link
Contributor

videlec commented May 30, 2015

comment:57

Actually, this is the expected behavior. Baselines are computed from the bottom, not from the top (this is crazy to me). In particular, the baseline of a tree is at its root (which is comprehensible).

@vbraun
Copy link
Member Author

vbraun commented May 30, 2015

comment:58

Ok, I wasn't aware that the trees have their baseline at the top. Thats a valid design choice for trees I guess. Then we should revert the last commit (but fix the doctests) to display as

    (   o  , o  ,     _o_   )
    (  / \    \      /   \  )
    ( o   o    o    o     o )
    (              / \      )
    (             o   o     )

@vbraun
Copy link
Member Author

vbraun commented May 30, 2015

comment:59

PS: In an ideal world we would have kerning to move the commas in:

    (   o,   o,       _o_   )
    (  / \    \      /   \  )
    ( o   o    o    o     o )
    (              / \      )
    (             o   o     )

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 31, 2015

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

7378e2fTrac #18357: merge sage-6.8.beta2
a6cf84fTrac #18357: fix doctests

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 31, 2015

Changed commit from a27bfe5 to a6cf84f

@vbraun
Copy link
Member Author

vbraun commented Jun 2, 2015

Changed branch from u/vdelecroix/18357 to a6cf84f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants