Zulip Chat Archive

Stream: general

Topic: pretty printer + brackets


Eric Rodriguez (Apr 30 2021 at 21:43):

image.png

is this considered a bug or a feature?

Eric Wieser (Apr 30 2021 at 22:41):

Bug

Eric Wieser (Apr 30 2021 at 22:42):

But I think it's a font rendering bug in webkit / blink

Eric Wieser (Apr 30 2021 at 22:42):

I've seen it in doc-gen too

Floris van Doorn (Apr 30 2021 at 22:43):

I've also seen this sometimes. I think it usually only happens when coercion arrows are present.

Kevin Buzzard (Apr 30 2021 at 22:47):

This is the "random close-bracket in the wrong place" bug I think?

Patrick Massot (May 03 2021 at 10:11):

Some of my students see this bug everywhere and it's driving me crazy, especially since I can't reproduce it on any computer I can access to. I think fixing this should be very high priority but I don't see how to help without being able to reproduce.

Mario Carneiro (May 03 2021 at 10:13):

is the second close bracket considered a bug?

Mario Carneiro (May 03 2021 at 10:13):

because I see that all the time

Eric Wieser (May 03 2021 at 10:14):

I think only the ) in the blue box is the bug

Eric Wieser (May 03 2021 at 10:14):

Because the reading order has to backtrack vertically which isn't how reading is supposed to work

Eric Wieser (May 03 2021 at 10:16):

I see this bug a lot for , but it seems not to happen for for me

Eric Wieser (May 03 2021 at 10:16):

Putting the cursor at the beginning of this line does it for me:
https://github.com/leanprover-community/mathlib/blob/0cc3cd54efb97332e973e0ff1ca94dbd486899eb/src/algebra/direct_sum_graded.lean#L584

Eric Wieser (May 03 2021 at 10:16):

image.png

Eric Wieser (May 03 2021 at 10:19):

This also reproduces it for me:

import algebra.pointwise

example (S : set ) : (S + S) = (S + S) := sorry  -- goal view is wonky at the sorry

Patrick Massot (May 03 2021 at 10:41):

I see no issue at all

Patrick Massot (May 03 2021 at 10:42):

in Eric's two examples

Eric Wieser (May 03 2021 at 11:01):

With what font?

Eric Wieser (May 03 2021 at 11:02):

This is a font / CSS issue I think

Patrick Massot (May 03 2021 at 11:03):

DevaVu sans mono

Eric Wieser (May 03 2021 at 11:04):

I see it with Consolas on Windows

Eric Wieser (May 03 2021 at 11:07):

The CSS specifies the indents in terms of "ch", the width of an 0. In consolas, that character is considerably narrower than an 0:
image.png

Eric Rodriguez (May 03 2021 at 11:07):

it's a font thing for sure; just installed dejavu sans mono and it's fixed itself
image.png

Patrick Massot (May 03 2021 at 11:10):

@Edward Ayers do you think you could fix this issue now that we understood where it comes from?

Patrick Massot (May 03 2021 at 11:12):

Does anyone know a simple way to explain how to install DejaVu sans mono on Windows or Mac? I mean simple enough that students could understand.

Eric Rodriguez (May 03 2021 at 11:13):

its super easy on windows, just get the files, double click them and there's an install button

Eric Rodriguez (May 03 2021 at 11:13):

image.png

Eric Wieser (May 03 2021 at 11:16):

Here's a #mwe: bad.html edit: i messed that up

Scott Morrison (May 03 2021 at 11:17):

Similarly on a mac. Download the zip file, unzip it, double click on a font file, and click "install font":
Screen-Shot-2021-05-03-at-9.16.38-pm.png

Patrick Massot (May 03 2021 at 11:20):

Thanks Eric and Scott, I'll try to tell my students to try this.

Eric Wieser (May 03 2021 at 11:23):

If I change ch to ex in the CSS the problem goes away

Eric Wieser (May 03 2021 at 11:24):

Actual mwe copied out of vscode: bad.html

Eric Wieser (May 03 2021 at 11:24):

Which is weird, because ch is supposedly the width of a 0, and ex the width of an x... Which are the same in a monospace font

Patrick Massot (May 03 2021 at 11:27):

Your bad example displays fine here. Maybe I don't have that font and my browser falls back to a good one.

Eric Rodriguez (May 03 2021 at 11:27):

i also thought ex was width, but just googled and it seems ex is height of x (which is the same, but not the same as height of 0? unsure)

Eric Rodriguez (May 03 2021 at 11:27):

not sure if Linux has consolas Patrick

Eric Wieser (May 03 2021 at 11:53):

Ah, in that case my proposed fix is not a justified one

Edward Ayers (May 06 2021 at 20:04):

The autoindenting CSS strikes again

Edward Ayers (May 06 2021 at 20:08):

The problem is that get getting the pretty indenting in CSS to work is a little hacky. I think that the correct approach would be to take full control of newlines and so on based on the width of the view, but I think that would be quite a lot of work.

Eric Wieser (May 06 2021 at 20:08):

Presumably the text reflowing would be a JavaScript job within the view window

Eric Wieser (May 06 2021 at 20:09):

But I agree, that sounds like a lot of work

Edward Ayers (May 06 2021 at 20:09):

Ideally no. Because it breaks the abstraction of Lean sending widgety HTML.

Edward Ayers (May 06 2021 at 20:09):

But practically yes do it with javascript

Eric Wieser (May 06 2021 at 20:10):

Oh, I assumed the goal view was special-cased

Edward Ayers (May 06 2021 at 20:10):

No it's all done by lean

Eric Wieser (May 06 2021 at 20:11):

Alternatively: output every character in the goal view in its own span with min-width set to 1ch

Eric Wieser (May 06 2021 at 20:11):

But that increases the textual size of the html by an order of magnitude

Edward Ayers (May 06 2021 at 20:11):

The dream of widgets was that absolutely all of the presentation code would be in Lean, so you wouldn't have to ever worry about javascript. But there are lots of places where that breaks so I don't think it's worth holding on to that abstraction in the cases where it is clearly awkward.

Edward Ayers (May 06 2021 at 20:13):

Eric Wieser said:

But that increases the textual size of the html by an order of magnitude

I suspect this would actually have ok performance.

Eric Wieser (May 06 2021 at 20:14):

Maybe it's sufficient to put a span around every word with min-width proportional to its number of characters

Edward Ayers (May 06 2021 at 20:14):

yeah that might work

Edward Ayers (May 06 2021 at 20:14):

might get some clipping

Eric Wieser (May 06 2021 at 20:15):

Assuming we don't wrap within words right now

Eric Wieser (May 06 2021 at 20:15):

Min-width shouldn't clip

Eric Wieser (May 06 2021 at 20:15):

It should just insert extra space sometimes

Edward Ayers (May 06 2021 at 20:16):

yeah an alternative might be to just add some extra space whenever there is a grouping in the pretty-printed sexpr

Edward Ayers (May 06 2021 at 20:21):

The styles to fiddle with are in https://github.com/leanprover-community/mathlib/blob/9c86e38141b94bcd23665717f26c1da1622c59a7/src/tactic/interactive_expr.lean#L157

Patrick Massot (May 06 2021 at 20:26):

Isn't there at least a temporary fix swapping ex and ch or whatever?

Edward Ayers (May 06 2021 at 20:29):

@Eric Wieser sorry why did setting it as ex work?

Edward Ayers (May 06 2021 at 20:30):

Eric Wieser said:

If I change ch to ex in the CSS the problem goes away

Why was this crossed out sorry?

Eric Wieser (May 06 2021 at 20:32):

Because it is a bad idea

Eric Wieser (May 06 2021 at 20:32):

ex is for vertical spacing

Edward Ayers (May 06 2021 at 20:32):

So for context, @Daniel Fabian spotted a trick where you can emulate Wadler-style pretty printing in CSS by setting the text indentation to be a negative number and padding to be minus that number, then if that block can't fit on one line, it will linebreak with an apparent indent. But what is happening here (which I unfortunately didn't observe because I have a all-unicode monospaced font) is some width calculating maths in the browser is messing up and it is linebreaking because of the different-width characters.

Edward Ayers (May 06 2021 at 20:33):

Eric Wieser said:

ex is for vertical spacing

But did it actually fix the problem?

Edward Ayers (May 06 2021 at 20:33):

Maybe we could use px

Edward Ayers (May 06 2021 at 20:35):

@Eric Wieser how do I use your bad.html mwe?

Edward Ayers (May 06 2021 at 20:36):

should it just render bad or do I need to change the width of the viewport?

Eric Wieser (May 06 2021 at 20:36):

It should just render badly

Edward Ayers (May 06 2021 at 20:36):

In chrome?

Eric Wieser (May 06 2021 at 20:37):

Anything other than 1ch will not indent right when it's actually supposed to wrap

Eric Wieser (May 06 2021 at 20:37):

Chrome on windows

Edward Ayers (May 06 2021 at 20:44):

Do you know if there are any linux fonts where this bug happens?

Edward Ayers (May 06 2021 at 20:45):

got it

Edward Ayers (May 06 2021 at 20:48):

@Eric Wieser please could you have a go at changing the exem?

Edward Ayers (May 06 2021 at 20:49):

never mind it breaks for me

Edward Ayers (May 06 2021 at 20:49):

wow

Edward Ayers (May 06 2021 at 21:45):

This bug is mad

Edward Ayers (May 06 2021 at 21:47):

@Eric Wieser please could you try the bad example with 0.9ch?

Eric Wieser (May 06 2021 at 21:49):

The bug is easier to reproduce another way

Eric Wieser (May 06 2021 at 21:49):

Change 1ch to 2ch

Edward Ayers (May 06 2021 at 21:50):

where?

Eric Wieser (May 06 2021 at 21:50):

And instead of using the weird arrow character that is too narrow, compare a one char prefix with a two char prefix

Eric Wieser (May 06 2021 at 21:50):

Everywhere

Eric Wieser (May 06 2021 at 21:50):

The cause is that \u-| is less than 1ch wide

Eric Wieser (May 06 2021 at 21:53):

I can give you a better repro tomorrow

Edward Ayers (May 06 2021 at 21:55):

no need I've found a small one

Eric Wieser (May 06 2021 at 21:58):

Did you find the ascii-only repro?

Edward Ayers (May 06 2021 at 21:59):

Yeah you get it whenever the text-indent minus text-indent is lower greater than the minwidth char

Edward Ayers (May 06 2021 at 21:59):

so if you use a non-monospace font then you get it p quickly

Eric Wieser (May 06 2021 at 21:59):

Right, but you can get it for monospace ascii too

Edward Ayers (May 06 2021 at 21:59):

Yes by setting it to 2ch

Edward Ayers (May 06 2021 at 22:00):

since that is a greater width than the narrowest char

Eric Wieser (May 06 2021 at 22:01):

That sounds like the reverse of what you said above

Edward Ayers (May 06 2021 at 22:01):

text indent is negative

Edward Ayers (May 06 2021 at 22:01):

ygwim

Edward Ayers (May 06 2021 at 22:02):

So the quick-and-dirty solution is to set it to use 0.9ch or whatever width these offending chars are

Edward Ayers (May 06 2021 at 22:03):

maybe just set it as 0.5ch

Edward Ayers (May 06 2021 at 22:03):

and then the quest begins to find a way of indenting stuff that doesn't require this hack

Edward Ayers (May 06 2021 at 22:03):

in the first place

Eric Wieser (May 06 2021 at 22:06):

0.5 makes the line wrapping look a little weird though

Edward Ayers (May 06 2021 at 22:06):

what is the biggest number you can get away with?

Edward Ayers (May 06 2021 at 22:07):

I think that the main pain point is windows users with consolas

Eric Wieser (May 06 2021 at 22:07):

\_l is pretty darn narrow

Eric Wieser (May 06 2021 at 22:08):

Frankly just putting coe_sort in a 1ch box would fix all the problems I actually see often

Edward Ayers (May 06 2021 at 22:09):

Ok maybe let's do that for now, and a few other common killers

Edward Ayers (May 06 2021 at 22:19):

I'll have another go tomorrow

Eric Rodriguez (May 12 2021 at 00:50):

just to make everything even more annoying, this can even happen with DejaVu Sans Mono depending on the screen resolution and stuff (if I make the widget screen-wide, it goes away but that's clearly undesirable :b there's some other wider element way above in the goal view, and for some reason it doesn't allow this to be wider because of it)

image.png

(polynomial_galois_group.lean:243)

Alex J. Best (May 12 2021 at 01:22):

I actually put my info view as a horizontal split instead, so below my code rather than beside it, for this sort of reason, I find it far easier to read that way even if having less lines of the source code visible is occasionally annoying.

Eric Wieser (May 12 2021 at 07:56):

Eric, that image doesn't seem to show the same bug

Eric Wieser (May 12 2021 at 07:57):

I think that's working as intended, or at least could be construed to be; unlike the original report, it's not actively breaking the reading order


Last updated: Dec 20 2023 at 11:08 UTC