Zulip Chat Archive
Stream: lean4
Topic: pretty printed string
Damiano Testa (Jul 12 2024 at 06:43):
Is there a way to get the output of pretty printed syntax as a string?
For example:
import Lean.Elab.Command
open Lean
run_cmd
let stx ← `(variable {$(mkIdent `a) : $(mkIdent `X)})
logInfo stx
-- variable {a : X}
How can I get the string "variable {a : X}"
out of stx
?
Jannis Limperg (Jul 12 2024 at 10:07):
import Lean.Elab.Command
open Lean PrettyPrinter Elab.Command
run_cmd do
let stx ← `(variable {$(mkIdent `a) : $(mkIdent `X)})
logInfo $ ← liftTermElabM $ ppCommand stx
For other syntax categories, see ppCategory
etc.
Jannis Limperg (Jul 12 2024 at 10:09):
Then docs#Std.Format.pretty to convert Format
to String
.
Damiano Testa (Jul 12 2024 at 10:10):
Ah, Std.Format.pretty
looks like it is exactly what I was missing! Thanks a lot!
Last updated: May 02 2025 at 03:31 UTC