feat: add public Pgn_to_tex entry point

Move parsing and rendering internals into the private
pgn_to_tex_internal library and rename pgn2tex to converter. Expose only
Pgn_to_tex with default to_tex arguments, abstract diagram_data,
empty_diagrams, and parse_diagrams_json. Update tests, JS bridge, and
README to the new names.
This commit is contained in:
2026-10-23 16:38:24 +02:00
committed by owenrees
parent 8df30f1746
commit 548f98f303
22 changed files with 111 additions and 48 deletions
+3 -8
View File
@@ -1,10 +1,5 @@
(library
(name pgn_logic)
(name pgn_to_tex)
(public_name pgn_to_tex)
(libraries sedlex menhirLib yojson)
(modules ast parser lexer parsing latex latex_helpers pgn2tex nag)
(preprocess
(pps sedlex.ppx)))
(menhir
(modules parser))
(modules pgn_to_tex)
(libraries pgn_to_tex_internal))
View File
+10
View File
@@ -0,0 +1,10 @@
(library
(name pgn_to_tex_internal)
(package pgn_to_tex)
(libraries sedlex menhirLib yojson)
(modules ast parser lexer parsing latex latex_helpers converter nag)
(preprocess
(pps sedlex.ppx)))
(menhir
(modules parser))
View File
+8
View File
@@ -0,0 +1,8 @@
type diagram_data = Pgn_to_tex_internal.Ast.diagram_data
let empty_diagrams = Pgn_to_tex_internal.Ast.empty_diagrams
let parse_diagrams_json = Pgn_to_tex_internal.Converter.parse_diagrams_json
let to_tex ?(diagram_data = empty_diagrams) ?(clock = false) pgn =
Pgn_to_tex_internal.Converter.to_tex pgn ~diagram_data ~clock
+39
View File
@@ -0,0 +1,39 @@
(** Convert chess PGN games to LaTeX.
[Pgn_to_tex] is the public entry point for the library. Open it to convert
a PGN string without referring to any internal parsing or rendering
modules:
{[
let tex = Pgn_to_tex.to_tex pgn
]}
Diagrams are optional and selected by passing {!diagram_data} built with
{!empty_diagrams} or {!parse_diagrams_json}. *)
(** Diagram selection data.
The representation is intentionally abstract; construct values with
{!empty_diagrams} or {!parse_diagrams_json}. *)
type diagram_data
val empty_diagrams : diagram_data
(** [empty_diagrams] selects no diagrams. It is the default used by
{!to_tex}. *)
val parse_diagrams_json : string -> diagram_data
(** [parse_diagrams_json json] parses diagram selections from a JSON string.
The input is expected to be a JSON array of objects. Each object contains
a [fen] string and may contain a [ply] number and a [path] array of SAN
moves. Malformed JSON yields {!empty_diagrams} rather than raising. *)
val to_tex : ?diagram_data:diagram_data -> ?clock:bool -> string -> string
(** [to_tex pgn] converts the PGN game in [pgn] to a LaTeX fragment.
@param diagram_data
diagram selections to render; defaults to {!empty_diagrams}.
@param clock
when [true], render clock times alongside diagrams; defaults to [false].
@raise Failure "Parse error" if [pgn] is not a valid PGN game. *)