OCamlDoc is the standard documentation generator for the OCaml programming language. It parses OCaml source files and generates documentation in various formats, most commonly HTML. This tool is essential for creating readable and navigable documentation for your OCaml libraries and projects.
Below are common command-line examples for using OCamlDoc to generate documentation for your OCaml code.
This is the most common use case, creating browsable HTML documentation for your OCaml modules.
# Generate documentation in HTML format for an OCaml file
ocamldoc -html myfile.ml
For generating printable documentation, LaTeX output is a good option.
# Generate documentation in LaTeX format
ocamldoc -latex myfile.ml
Control where the generated documentation files are placed.
# Specify the output directory for the generated documentation
ocamldoc -d output_directory -html myfile.ml
Enhance your documentation by using custom tags and including package information.
# Generate documentation with custom tags
ocamldoc -tags custom_tag1,custom_tag2 -html myfile.ml
# Pass specific package options to improve generated documentation
ocamldoc -package pkg_name -html myfile.ml
By default, OCamlDoc hides private elements. You can choose to include them.
# Generate documentation including private elements (by default it hides them)
ocamldoc -html -hide private myfile.ml
OCamlDoc can also generate documentation in the traditional Unix man page format.
# Generate documentation in man page format
ocamldoc -man myfile.ml
Pass specific options to the underlying OCaml compiler when generating documentation.
# Use a specific ocamlc command
ocamldoc -copts "ocamlc options" -html myfile.ml
For simpler projects or quick sharing, a single HTML file can be useful.
# Generate a one-page HTML file
ocamldoc -html -one-page myfile.ml
Add a navigation bar to your HTML documentation for better user experience.
# Include the navigation bar in the documentation
ocamldoc -html -with-index -d output_directory myfile.ml
For more in-depth information on OCamlDoc and OCaml programming, refer to the official documentation: