OCamlDoc - OCaml Documentation Generator

OCamlDoc is a powerful documentation generator for OCaml. Learn how to use OCamlDoc to create HTML, LaTeX, and man page documentation for your OCaml projects.

OCamlDoc - OCaml Documentation Generator

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.

OCamlDoc Usage Examples

Below are common command-line examples for using OCamlDoc to generate documentation for your OCaml code.

Generate HTML Documentation

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

Generate LaTeX Documentation

For generating printable documentation, LaTeX output is a good option.

# Generate documentation in LaTeX format
ocamldoc -latex myfile.ml

Specify Output Directory

Control where the generated documentation files are placed.

# Specify the output directory for the generated documentation
ocamldoc -d output_directory -html myfile.ml

Custom Tags and Packages

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

Include Private Elements

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

Generate Man Pages

OCamlDoc can also generate documentation in the traditional Unix man page format.

# Generate documentation in man page format
ocamldoc -man myfile.ml

Using Specific OCaml Compiler Options

Pass specific options to the underlying OCaml compiler when generating documentation.

# Use a specific ocamlc command
ocamldoc -copts "ocamlc options" -html myfile.ml

One-Page HTML Output

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

Include Navigation Bar

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

Further Resources

For more in-depth information on OCamlDoc and OCaml programming, refer to the official documentation: