Zulip Chat Archive
Stream: metaprogramming / tactics
Topic: Extra spaces in prettyprinted term
Leni Aniva (Jul 22 2025 at 05:56):
What causes the extra spacing in this example?
#eval do
let z ← Elab.Term.elabTerm (← `(term|λ (x : Nat) => x + 1)) .none
let stx ← PrettyPrinter.delab z
logInfo s!"{stx.raw.prettyPrint}"
which shows
fun x => x + 1
Robin Arnez (Jul 22 2025 at 07:30):
Syntax.prettyPrint just prints the raw text contained in stx, including all trailing whitespace which might've been caused by certain syntax quotations in the delaborator containing them. You probably want ← PrettyPrinter.formatTerm stx instead.
Leni Aniva (Jul 22 2025 at 15:53):
Robin Arnez said:
Syntax.prettyPrintjust prints the raw text contained instx, including all trailing whitespace which might've been caused by certain syntax quotations in the delaborator containing them. You probably want← PrettyPrinter.formatTerm stxinstead.
sometimes PrettyPrinter.format functions throw "format: uncaught backtrack exception". Is there a way to diagnose it?
Eric Wieser (Jul 22 2025 at 15:57):
Leni Aniva (Jul 23 2025 at 21:19):
Eric Wieser said:
In this case I'm not using custom syntax, but I figured it out and it was because of malformed objects going into the prettyprinter.
Eric Wieser (Jul 23 2025 at 21:29):
The issue there is about a syntax defined in mathlib, minimized to not mention it
Leni Aniva (Jul 23 2025 at 21:35):
Eric Wieser said:
The issue there is about a syntax defined in mathlib, minimized to not mention it
Ah I see, there doesn't seem to be a conclusive solution
Last updated: Dec 20 2025 at 21:32 UTC