let rec env_to_string (e:Stack.environment) =
let spr = Printf.sprintf in
match e with
| `cmd_end -> spr "cmd_end"
| `cmd_inside environment -> spr "begin %s" (env_to_string environment)
| `cmd_begin (s, l) -> spr "cmd_begin %s" s
| `unknown (s, l) -> spr "unknown %s" s
| `italic -> spr "italic"
| `bold -> spr "bold"
| `mono_space -> spr "mono_space (t)"
| `superscript -> spr "superscript (sup)"
| `subscript -> spr "subscript (sub)"
| `paragraph -> spr "paragraph (p)"
| `new_line -> spr "new_line (br)"
| `quotation (s) -> spr "quotation (q)"
| `non_break_space -> spr "non_break_space (~)"
| `horizontal_ellipsis -> spr "horizontal_ellipsis (...)"
| `en_dash -> "en dash"
| `em_dash -> "em dash"
| `open_brace -> spr "open_brace ({)"
| `close_brace -> spr "close_brace (})"
| `sharp -> spr "sharp (#)"
| `utf8_char i -> spr "utf8_char 0x%x" i
| `code l -> spr "code"
| `bypass -> spr "bypass"
| `text -> "text"
| `ignore -> "ignore"
| `list l -> spr "list"
| `item -> spr "item (*)"
| `section (n, l) -> spr "section %d" n
| `link l -> spr "link"
| `image (src, _,_) -> spr "image %s" src
| `header -> spr "header"
| `title -> spr "title"
| `authors -> spr "authors"
| `subtitle -> spr "subtitle"
| `table _ -> "table"
| `cell _ -> "cell"
| `note -> "note"
| `quote -> "quote"