Format\_doc.Doc(3) OCaml library Format\_doc.Doc(3)

# [NAME](#NAME)

Format\_doc.Doc - Definitions and immutable API for composing documents

# [Module](#Module)

Module Format\_doc.Doc

# [Documentation](#Documentation)

Module **Doc**  
: **sig end**

Definitions and immutable API for composing documents

## [Type definitions and core functions](#Type_definitions_and_core_functions)

*type box\_type* =  
| H  
| V  
| HV  
| HoV  
| B

Format box types

*type stag* = **Format.stag**

*type element* =  
| Text **of** **string**  
| With\_size **of** **int**  
| Open\_box **of {**  
kind : **box\_type** ;  
indent : **int** ;  
}  
| Close\_box  
| Open\_tag **of** **Format.stag**  
| Close\_tag  
| Open\_tbox  
| Tab\_break **of {**  
width : **int** ;  
offset : **int** ;  
}  
| Set\_tab  
| Close\_tbox  
| Simple\_break **of {**  
spaces : **int** ;  
indent : **int** ;  
}  
| Break **of {**  
fits : **string * int * string** ;  
breaks : **string * int * string** ;  
}  
| Flush **of {**  
newline : **bool** ;  
}  
| Newline  
| If\_newline  
| Deprecated **of** **(Format.formatter -&gt; unit)**  
(* Escape hatch: a **Format** printer used to provide backward-compatibility for user-defined printer (from the **#install\_printer** toplevel directive for instance).  
\*)

Base formatting instruction recognized by **Format**

*type t*

Immutable document type

*type* **('a, 'b)** *fmt* = **('a, t, t, 'b) format4**

*type printer0* = **t -&gt; t**

*type* **'a** *printer* = **'a -&gt; printer0**

*val empty* : **t**

Empty document

*val format* : **Format.formatter -&gt; t -&gt; unit**

**format ppf doc** sends the format instruction of **doc** to the Format's formatter **doc** .

*val fold* : **('acc -&gt; element -&gt; 'acc) -&gt; 'acc -&gt; t -&gt; 'acc**

Fold over a document as a sequence of instructions

*val msg* : **('a, t) fmt -&gt; 'a**

**Format\_doc.Doc.msg** and **Format\_doc.Doc.kmsg** produce a document from a format string and its argument

*val kmsg* : **(t -&gt; 'b) -&gt; ('a, 'b) fmt -&gt; 'a**

*val printf* : **('a, printer0) fmt -&gt; 'a**

**Format\_doc.Doc.printf** and **Format\_doc.Doc.kprintf** produce a printer from a format string and its argument

*val kprintf* : **(t -&gt; 'b) -&gt;** **('a, t -&gt; 'b) fmt -&gt; 'a**

*val open\_box* : **box\_type -&gt; int -&gt; printer0**

The functions below mirror **Format** printers, without the **pp\_print\_** prefix naming convention

*val close\_box* : **printer0**

*val text* : **string printer**

*val string* : **string printer**

*val bytes* : **bytes printer**

*val with\_size* : **int printer**

*val int* : **int printer**

*val float* : **float printer**

*val char* : **char printer**

*val bool* : **bool printer**

*val space* : **printer0**

*val cut* : **printer0**

*val break* : **spaces:int -&gt; indent:int -&gt; printer0**

*val custom\_break* : **fits:string * int * string -&gt;** **breaks:string * int * string -&gt; printer0**

*val force\_newline* : **printer0**

*val if\_newline* : **printer0**

*val flush* : **printer0**

*val force\_stop* : **printer0**

*val open\_tbox* : **printer0**

*val set\_tab* : **printer0**

*val tab* : **printer0**

*val tab\_break* : **width:int -&gt; offset:int -&gt; printer0**

*val close\_tbox* : **printer0**

*val open\_tag* : **stag printer**

*val close\_tag* : **printer0**

*val list* : **?sep:printer0 -&gt;** **'a printer -&gt; 'a list printer**

*val iter* : **?sep:printer0 -&gt;** **iter:(('a -&gt; unit) -&gt; 'b -&gt; unit) -&gt;** **'a printer -&gt; 'b printer**

*val array* : **?sep:printer0 -&gt;** **'a printer -&gt; 'a array printer**

*val seq* : **?sep:printer0 -&gt;** **'a printer -&gt; 'a Seq.t printer**

*val option* : **?none:printer0 -&gt;** **'a printer -&gt; 'a option printer**

*val result* : **ok:'a printer -&gt;** **error:'e printer -&gt;** **('a, 'e) result printer**

*val either* : **left:'a printer -&gt;** **right:'b printer -&gt;** **('a, 'b) Either.t printer**

## [Alignment functions](#Alignment_functions)

*val align\_prefix* : **(t * int) list -&gt; t list**

Align the right side of one **"@{&lt;ralign&gt;...@}"** tag box by inserting spaces at the beginning of boxes. Those function do nothing if the tag box appears after a break hint.

*val align\_prefix2* : **t * int -&gt;** **t * int -&gt; t * t**

2026-09-04 OCamldoc

---

Document: Format_doc.Doc(3o) from ocaml 5.5.1-r0 (Chainguard OS)
Source: https://github.com/ocaml/ocaml
