---
name: "Format_doc"
section: "3o"
platform: "linux"
package: "ocaml"
version: "5.5.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/Format_doc"
---

# Format\_doc(3o)

Composable document for the Format formatting engine.

## NAME

Format\_doc - Composable document for the Format formatting engine.

## Module

Module   Format\_doc

## Documentation

Module **Format\_doc**\
  :  **sig end**

Composable document for the  **Format** formatting engine.

This module introduces a pure and immutable document type which represents a sequence of formatting instructions to be printed by a formatting engine at later point. At the same time, it also provides format string interpreter which produces this document type from format string and their associated printers.

The module is designed to be source compatible with code defining format printers: replacing \`Format\` by \`Format\_doc\` in your code will convert \`Format\` printers to \`Format\_doc\` printers.

*module Doc :* **sig end**

Definitions and immutable API for composing documents

### Compatibility API

The functions and types below provides source compatibility with format printers and conversion function from  **Format\_doc** printers to  **Format** printers. The reverse direction is implemented using an escape hatch in the formatting instruction and should only be used to preserve backward compatibility.

*type doc* =  **Doc.t**

*type t* =  **doc**

*type formatter*

*type* **'a** *printer* =  **formatter -\> 'a -\> unit**

*val formatter* :  **doc ref -\> formatter**

**formatter rdoc** creates a  **Format\_doc.formatter** that updates the  **rdoc** reference

*type* **'a** *format\_printer* =  **Format.formatter -\> 'a -\> unit**

Translate a  **Format\_doc** printer to a  **Format** one.

*val compat* :  **'a printer -\> 'a format\_printer**

*val compat1* :  **('p1 -\> 'a printer) -\> 'p1 -\> 'a format\_printer**

*val compat2* :  **('p1 -\> 'p2 -\> 'a printer) -\>** **'p1 -\> 'p2 -\> 'a format\_printer**

*val deprecated\_printer* :  **(Format.formatter -\> unit) -\> formatter -\> unit**

If necessary, embed a  **Format** printer inside a formatting instruction stream. This breaks every guarantees provided by  **Format\_doc** .

*val deprecated* :  **'a format\_printer -\> 'a printer**

*val deprecated1* :  **('p1 -\> 'a format\_printer) -\> 'p1 -\> 'a printer**

### Format string interpreters

*val fprintf* :  **formatter -\> ('a, formatter, unit) format -\> 'a**

*val kfprintf* :  **(formatter -\> 'a) -\>** **formatter -\>** **('b, formatter, unit, 'a) format4 -\> 'b**

*val asprintf* :  **('a, formatter, unit, string) format4 -\> 'a**

*val kasprintf* :  **(string -\> 'a) -\> ('b, formatter, unit, 'a) format4 -\> 'b**

*val dprintf* :  **('a, formatter, unit, formatter -\> unit) format4 -\>** **'a**

*val kdprintf* :  **((formatter -\> unit) -\> 'a) -\>** **('b, formatter, unit, 'a) format4 -\> 'b**

*val doc\_printf* :  **('a, formatter, unit, doc) format4 -\> 'a**

**Format\_doc.doc\_printf** and  **Format\_doc.kdoc\_printf** creates a document directly

*val kdoc\_printf* :  **(doc -\> 'r) -\>** **('a, formatter, unit, 'r) format4 -\> 'a**

### Compatibility with Format\_doc.Doc

*val doc\_printer* :  **'a printer -\> 'a Doc.printer**

*val pp\_doc* :  **doc printer**

### Source compatibility with Format

### String printers

*val pp\_print\_string* :  **string printer**

*val pp\_print\_substring* :  **pos:int -\> len:int -\> string printer**

*val pp\_print\_text* :  **string printer**

*val pp\_print\_bytes* :  **bytes printer**

*val pp\_print\_as* :  **formatter -\> int -\> string -\> unit**

*val pp\_print\_substring\_as* :  **pos:int -\> len:int -\> formatter -\> int -\> string -\> unit**

### Primitive type printers

*val pp\_print\_char* :  **char printer**

*val pp\_print\_int* :  **int printer**

*val pp\_print\_float* :  **float printer**

*val pp\_print\_bool* :  **bool printer**

*val pp\_print\_nothing* :  **unit printer**

### Printer combinators

*val pp\_print\_iter* :  **?pp\_sep:unit printer -\>** **(('a -\> unit) -\> 'b -\> unit) -\>** **'a printer -\> 'b printer**

*val pp\_print\_list* :  **?pp\_sep:unit printer -\>** **'a printer -\> 'a list printer**

*val pp\_print\_array* :  **?pp\_sep:unit printer -\>** **'a printer -\> 'a array printer**

*val pp\_print\_seq* :  **?pp\_sep:unit printer -\>** **'a printer -\> 'a Seq.t printer**

*val pp\_print\_option* :  **?none:unit printer -\>** **'a printer -\> 'a option printer**

*val pp\_print\_result* :  **ok:'a printer -\>** **error:'e printer -\> ('a, 'e) result printer**

*val pp\_print\_either* :  **left:'a printer -\>** **right:'b printer -\> ('a, 'b) Either.t printer**

### Boxes and tags

*val pp\_open\_stag* :  **Format.stag printer**

*val pp\_close\_stag* :  **unit printer**

*val pp\_open\_box* :  **int printer**

*val pp\_close\_box* :  **unit printer**

### Break hints

*val pp\_print\_space* :  **unit printer**

*val pp\_print\_cut* :  **unit printer**

*val pp\_print\_break* :  **formatter -\> int -\> int -\> unit**

*val pp\_print\_custom\_break* :  **formatter -\>** **fits:string \* int \* string -\> breaks:string \* int \* string -\> unit**

### Tabulations

*val pp\_open\_tbox* :  **unit printer**

*val pp\_close\_tbox* :  **unit printer**

*val pp\_set\_tab* :  **unit printer**

*val pp\_print\_tab* :  **unit printer**

*val pp\_print\_tbreak* :  **formatter -\> int -\> int -\> unit**

### Newlines and flushing

*val pp\_print\_if\_newline* :  **unit printer**

*val pp\_force\_newline* :  **unit printer**

*val pp\_print\_flush* :  **unit printer**

*val pp\_print\_newline* :  **unit printer**

### Compiler specific functions

### Separators

*val comma* :  **unit printer**

*val semicolon* :  **unit printer**

### Compiler output

*val pp\_two\_columns* :  **?sep:string -\>** **?max\_lines:int -\> formatter -\> (string \* string) list -\> unit**

**pp\_two\_columns ?sep ?max\_lines ppf l** prints the lines in  **l** as two columns separated by  **sep** ("\|" by default).  **max\_lines** can be used to indicate a maximum number of lines to print -- an ellipsis gets inserted at the middle if the input has too many lines.

Example:

pp\_two\_columns ~max\_lines:3 Format.std\_formatter \[ "abc", "hello"; "def", "zzz"; "a"  , "bllbl"; "bb" , "dddddd"; \]

prints

abc \| hello ... bb  \| dddddd
