Zulip Chat Archive
Stream: lean4
Topic: Notation in namespace not showing in pp
Peter Nelson (May 04 2024 at 12:04):
I'm having an issue since 4.8.0 with notation not showing in the (VScode) pretty-printer when defined in a namespace.
Removing the namespace
fixes the below. Can someone tell me how to make it appear?
import Mathlib.Data.Set.Basic
namespace Set
def MySubset {α : Type} (s t : Set α) : Prop := s ⊆ t
infix:50 " ⊆⊆ " => MySubset
example {α : Type} (s t : Set α) (h : s ⊆⊆ t) : s ⊆ t := by
-- pp shows `h : s.MySubset t` rather than `s ⊆⊆ t`.
exact h
end Set
Yaël Dillies (May 04 2024 at 12:11):
Could this have to do with pp_dot
now being the default?
Peter Nelson (May 04 2024 at 14:22):
On mobile, but guessing that pp_nodot
will fix it. Presumably this isn’t intended behaviour, though.
Kyle Miller (May 04 2024 at 17:02):
Thanks for the report, looking into fixing this. Most notations go through a notation typeclass, which prevents this interaction between the dot notation pretty printer and the unexpander from infix
/etc.
The issue is that the dot notation pretty printer can collapse projections to parent structures, so to prevent any backtracking in pretty printing, once it determines that dot notation is possible it commits to it.
Peter Nelson (May 05 2024 at 12:06):
pp_nodot
does fix it for the time being. Is there any way to (in a local project) add that attribute to a declaration already in mathlib that has been broken by this?
If I try attribute [pp_nodot] Matroid.Restriction
(for example), then I get invalid attribute 'pp_nodot', declaration is in an imported module
.
Kyle Miller (May 05 2024 at 15:48):
Unfortunately no, since pp_nodot
is a TagAttribute.
If this is for fixing pretty printing, then what you could do is make a delaborator (rather than an unexpander) which would be unaffected.
Kyle Miller (May 05 2024 at 15:51):
If you add this chunk of code it'll fix pretty printing locally:
open Lean PrettyPrinter Delaborator SubExpr in
@[delab app.Matroid.Restriction]
private def delabRestriction : Delab :=
whenPPOption getPPNotation <| whenNotPPOption getPPExplicit do
guard <| (← getExpr).getAppNumArgs = 3
let a ← withAppFn <| withAppArg delab
let b ← withAppArg delab
`($a ≤r $b)
Joël Riou (May 05 2024 at 15:56):
Otherwise, in order to fix the pretty printing globally in mathlib, is adding pp_nodot
the recommended solution?
Kyle Miller (May 05 2024 at 16:01):
I'm hoping to fix this in time for the next rc (it seems like there will be one), so I'd hold off on adding pp_nodot
s if that's possible. What notations are affecting you @Joël Riou?
Joël Riou (May 05 2024 at 16:02):
I have observed this behaviour also for docs#CategoryTheory.Functor.comp, but if there is a better fix, I can wait :-)
Kyle Miller (May 05 2024 at 21:17):
Once lean4#4071 finishes building and succeeds in building mathlib, I'll check that these mathlib notations actually pretty print
Last updated: May 02 2025 at 03:31 UTC