mirror of
https://github.com/TheRealOwenRees/pgn_to_tex.git
synced 2026-11-18 12:52:06 +00:00
Compare commits
20
Commits
v0.0.1-alpha.2
...
v0.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dfa7d5bc7e | ||
|
|
c654beb5a8 | ||
|
|
4d20084f7e | ||
|
|
16fcaa3b13 | ||
|
|
4f50ff020e | ||
|
|
2bf11e92a8 | ||
|
|
786bad8956 | ||
|
|
135491e915 | ||
|
|
9cd7878ad8 | ||
|
|
548f98f303 | ||
|
|
8df30f1746 | ||
|
|
79eda1beab
|
||
|
|
c500b1625d
|
||
|
|
fe9eb8ba45 | ||
|
|
5831ddfb5e
|
||
|
|
5f0521430d
|
||
|
|
a58a6504b4 | ||
|
|
b4816553c7
|
||
|
|
b6534537ff
|
||
|
|
47ab11f1c1
|
@@ -0,0 +1,52 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ci-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Format, build, test, and document
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out the repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up OCaml
|
||||
uses: ocaml/setup-ocaml@v3
|
||||
with:
|
||||
ocaml-compiler: 5.4.x
|
||||
cache: false
|
||||
|
||||
- name: Install dependencies
|
||||
run: opam install . --deps-only --with-test --with-doc --with-dev-setup
|
||||
|
||||
- name: Check formatting
|
||||
run: opam exec -- dune build @fmt
|
||||
|
||||
- name: Build
|
||||
run: opam exec -- dune build @install
|
||||
|
||||
- name: Run tests
|
||||
run: opam exec -- dune runtest
|
||||
|
||||
- name: Build documentation
|
||||
run: opam exec -- dune build @doc
|
||||
|
||||
- name: Build the JavaScript artifact
|
||||
run: opam exec -- dune build bin/pgn_to_tex_js.bc.js
|
||||
|
||||
- name: Run the Node smoke test
|
||||
run: node test/js/smoke.js
|
||||
|
||||
- name: Lint the opam metadata
|
||||
run: opam lint pgn_to_tex.opam
|
||||
@@ -0,0 +1,59 @@
|
||||
name: Documentation
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
concurrency:
|
||||
group: pages
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build odoc
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out the repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up OCaml
|
||||
uses: ocaml/setup-ocaml@v3
|
||||
with:
|
||||
ocaml-compiler: 5.4.x
|
||||
cache: false
|
||||
|
||||
- name: Install documentation dependencies
|
||||
run: opam install . --deps-only --with-doc
|
||||
|
||||
- name: Build documentation
|
||||
run: opam exec -- dune build @doc
|
||||
|
||||
- name: Disable Jekyll processing
|
||||
run: touch _build/default/_doc/_html/.nojekyll
|
||||
|
||||
- name: Configure GitHub Pages
|
||||
uses: actions/configure-pages@v5
|
||||
|
||||
- name: Upload the documentation artifact
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: _build/default/_doc/_html
|
||||
|
||||
deploy:
|
||||
name: Deploy to GitHub Pages
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
steps:
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
profile = default
|
||||
version = 0.28.1
|
||||
version = 0.29.0
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
## Agent skills
|
||||
|
||||
### Issue tracker
|
||||
|
||||
Issues live in GitHub Issues for TheRealOwenRees/pgn_to_tex and are managed with `gh`. See `docs/agents/issue-tracker.md`.
|
||||
|
||||
### Triage labels
|
||||
|
||||
The five canonical triage roles map directly to `needs-triage`, `needs-info`, `ready-for-agent`, `ready-for-human`, and `wontfix`. See `docs/agents/triage-labels.md`.
|
||||
|
||||
### Domain docs
|
||||
|
||||
Single-context: `GLOSSARY.md` and `docs/adr/` at the repo root. See `docs/agents/domain.md`.
|
||||
@@ -1,3 +1,89 @@
|
||||
## 0.1.0
|
||||
|
||||
### Breaking changes
|
||||
|
||||
- Renamed the public entry point from `Pgn_logic` / `Pgn2tex` to
|
||||
`Pgn_to_tex`. The old modules are removed with no compatibility aliases.
|
||||
- `Pgn_to_tex.to_tex` takes optional `~diagram_data` and `~clock` arguments
|
||||
before the PGN string, and defaults to no diagrams and no clock output.
|
||||
- Removed the internal parser, AST, LaTeX, and NAG modules from the public
|
||||
surface. `diagram_data` is now an abstract type.
|
||||
- Renamed the optional JavaScript artifact from `main.bc.js` to
|
||||
`pgn_to_tex_js.bc.js`.
|
||||
|
||||
### Added
|
||||
|
||||
- New public API: `Pgn_to_tex.to_tex`, `Pgn_to_tex.parse_diagrams_json`,
|
||||
`Pgn_to_tex.empty_diagrams`, and the abstract `diagram_data` type.
|
||||
- Diagram JSON accepts `path`, `ply`, or both. Paths identify mainline and
|
||||
variation positions; path lookup takes precedence over the legacy ply
|
||||
fallback, and path-only variation entries are supported.
|
||||
- Diagrams inside variations render inline at the smaller `smallboard` size.
|
||||
- Generated odoc API documentation, a package landing page, and a GitHub Pages
|
||||
deployment workflow.
|
||||
- GitHub Actions CI covering formatting, build, tests, docs, the JavaScript
|
||||
build, the Node smoke test, and opam lint.
|
||||
- A self-contained README covering installation, the API, diagram JSON,
|
||||
clocks, variations, headers, NAGs, errors, the LaTeX preamble, and JavaScript
|
||||
usage.
|
||||
- `js_of_ocaml` and `js_of_ocaml-ppx` are declared as test-only dependencies.
|
||||
|
||||
### Fixed
|
||||
|
||||
- A mixed `Author` and player header no longer produces an empty author line.
|
||||
- A `Title` without a `Subtitle` no longer emits an empty subtitle block.
|
||||
|
||||
### Changed
|
||||
|
||||
- The package version is now `0.1.0`.
|
||||
- Documentation now points at
|
||||
<https://therealowenrees.github.io/pgn_to_tex/>.
|
||||
- Removed stale CI-acceptance metadata for unsupported OCaml versions.
|
||||
|
||||
### Migration from 0.0.x
|
||||
|
||||
Replace the old import and module prefix:
|
||||
|
||||
```ocaml
|
||||
(* 0.0.x *)
|
||||
open Pgn_logic
|
||||
|
||||
let diagrams = Pgn2tex.parse_diagrams_json json
|
||||
let tex = Pgn2tex.to_tex pgn ~diagram_data:diagrams ~clock:false
|
||||
|
||||
(* 0.1.0 *)
|
||||
let diagrams = Pgn_to_tex.parse_diagrams_json json
|
||||
let tex = Pgn_to_tex.to_tex ~diagram_data:diagrams ~clock:false pgn
|
||||
```
|
||||
|
||||
Use `Pgn_to_tex.empty_diagrams` when a game has no diagrams. Diagram data is
|
||||
now abstract, so replace any hand-built `MoveMap.t` with
|
||||
`Pgn_to_tex.parse_diagrams_json`. The JavaScript `to_tex` function keeps the
|
||||
same three arguments; only the artifact name changed.
|
||||
|
||||
## 0.0.2
|
||||
|
||||
- support diagrams in variations. Diagram data now carries an optional `path` (the SAN move sequence from the root) alongside the legacy `ply`; diagrams whose `path` resolves inside a variation are rendered inline within the variation. `parse_diagrams_json` returns a `diagram_data` record with `by_ply` and `by_path` maps.
|
||||
|
||||
- make variation board diagrams slightly smaller than mainline board diagrams
|
||||
|
||||
## v0.0.1
|
||||
|
||||
- fix bug whereby a `subtitle` custom PGN header was rendering on a separate page. It now appears under the title
|
||||
- remove old tests and commented out code
|
||||
|
||||
## v0.0.1-rc.2
|
||||
|
||||
- add correct versioning metadata
|
||||
|
||||
## v0.0.1-rc.1
|
||||
|
||||
- Update readme and add license file
|
||||
|
||||
## v0.0.1-alpha.2
|
||||
|
||||
- Expose function `parse_diagrams_json` to convert stringified JSON to a MoveMap, allowing for parsing of the diagram data with `to_tex`
|
||||
|
||||
## v0.0.1-alpha.1
|
||||
|
||||
- Initial release
|
||||
|
||||
+59
-4
@@ -1,13 +1,68 @@
|
||||
# Contributing
|
||||
|
||||
When contributing to this repository, please first discuss the change you wish to make via the repository's issues.
|
||||
When contributing to this repository, please first discuss the change you wish
|
||||
to make via the repository's issues.
|
||||
|
||||
If you are wanting to tackle one of the pre-existing issues, please comment on that issue so that you can be assigned to it.
|
||||
If you are wanting to tackle one of the pre-existing issues, please comment on
|
||||
that issue so that you can be assigned to it.
|
||||
|
||||
Alternatively, just send a PR and I will check it asap. Please bear in mind that I may not be reactive if I was not expecting a PR.
|
||||
Alternatively, just send a PR and I will check it asap. Please bear in mind that
|
||||
I may not be reactive if I was not expecting a PR.
|
||||
|
||||
## Guidelines
|
||||
|
||||
- We use the [GitHub Flow](https://www.gitkraken.com/learn/git/best-practices/git-branch-strategy#github-flow-considerations) branching strategy. Add your code into a feature branch such as `feature/feature-name`.
|
||||
- Write good commit messages. 'Fix bug' is not a good commit message. 'Fix bug with comments before moves' is a good commit message.
|
||||
- Explain the changes in the PR comments
|
||||
- Explain the changes in the PR comments.
|
||||
|
||||
## Development setup
|
||||
|
||||
The package requires OCaml 5.4 or newer. From a checkout, install all build,
|
||||
test, documentation, and development dependencies:
|
||||
|
||||
```sh
|
||||
opam install . --deps-only --with-test --with-doc --with-dev-setup
|
||||
```
|
||||
|
||||
The JavaScript build is an optional target. Its dependencies are part of the
|
||||
`--with-test` set (`js_of_ocaml` and `js_of_ocaml-ppx`), so the command above
|
||||
also prepares the Node smoke test.
|
||||
|
||||
## Verification commands
|
||||
|
||||
Run these before opening or updating a pull request.
|
||||
|
||||
Check formatting, build the package, run the test suite, and build the API
|
||||
documentation:
|
||||
|
||||
```sh
|
||||
dune build @fmt @install @runtest @doc
|
||||
```
|
||||
|
||||
`@fmt` checks formatting with `ocamlformat` 0.29.0. If it reports a diff, apply
|
||||
the formatting with `dune fmt` (or `dune build @fmt --auto-promote`).
|
||||
|
||||
Build the optional JavaScript artifact:
|
||||
|
||||
```sh
|
||||
dune build bin/pgn_to_tex_js.bc.js
|
||||
```
|
||||
|
||||
Run the Node smoke test against that artifact:
|
||||
|
||||
```sh
|
||||
node test/js/smoke.js
|
||||
```
|
||||
|
||||
Lint the generated opam metadata:
|
||||
|
||||
```sh
|
||||
opam lint pgn_to_tex.opam
|
||||
```
|
||||
|
||||
The opam file is generated from `dune-project`, so change dependencies and
|
||||
package metadata there rather than editing `pgn_to_tex.opam` by hand.
|
||||
|
||||
The test suite has one OUnit runner, `test/test_suite.ml`. Add a suite to that
|
||||
runner instead of starting a second test executable. Bundled PGN fixtures live
|
||||
in `test/pgn_examples/` and are exercised by the real-world tests.
|
||||
|
||||
@@ -0,0 +1,650 @@
|
||||
# GNU Affero General Public License
|
||||
|
||||
_Version 3, 19 November 2007_
|
||||
_Copyright © 2007 Free Software Foundation, Inc. <<http://fsf.org/>>_
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
## Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: **(1)** assert copyright on the software, and **(2)** offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
## TERMS AND CONDITIONS
|
||||
|
||||
### 0. Definitions
|
||||
|
||||
“This License” refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
“Copyright” also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
“The Program” refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as “you”. “Licensees” and
|
||||
“recipients” may be individuals or organizations.
|
||||
|
||||
To “modify” a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a “modified version” of the
|
||||
earlier work or a work “based on” the earlier work.
|
||||
|
||||
A “covered work” means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To “propagate” a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To “convey” a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays “Appropriate Legal Notices”
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that **(1)** displays an appropriate copyright notice, and **(2)**
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
### 1. Source Code
|
||||
|
||||
The “source code” for a work means the preferred form of the work
|
||||
for making modifications to it. “Object code” means any non-source
|
||||
form of a work.
|
||||
|
||||
A “Standard Interface” means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The “System Libraries” of an executable work include anything, other
|
||||
than the work as a whole, that **(a)** is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and **(b)** serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
“Major Component”, in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The “Corresponding Source” for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
### 2. Basic Permissions
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
### 3. Protecting Users' Legal Rights From Anti-Circumvention Law
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
### 4. Conveying Verbatim Copies
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
### 5. Conveying Modified Source Versions
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
- **a)** The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
- **b)** The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section 7.
|
||||
This requirement modifies the requirement in section 4 to
|
||||
“keep intact all notices”.
|
||||
- **c)** You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
- **d)** If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
“aggregate” if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
### 6. Conveying Non-Source Forms
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
- **a)** Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
- **b)** Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either **(1)** a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or **(2)** access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
- **c)** Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
- **d)** Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
- **e)** Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A “User Product” is either **(1)** a “consumer product”, which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or **(2)** anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, “normally used” refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
“Installation Information” for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
### 7. Additional Terms
|
||||
|
||||
“Additional permissions” are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
- **a)** Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
- **b)** Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
- **c)** Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
- **d)** Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
- **e)** Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
- **f)** Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered “further
|
||||
restrictions” within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
### 8. Termination
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated **(a)**
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and **(b)** permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
### 9. Acceptance Not Required for Having Copies
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
### 10. Automatic Licensing of Downstream Recipients
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An “entity transaction” is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
### 11. Patents
|
||||
|
||||
A “contributor” is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's “contributor version”.
|
||||
|
||||
A contributor's “essential patent claims” are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, “control” includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a “patent license” is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To “grant” such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either **(1)** cause the Corresponding Source to be so
|
||||
available, or **(2)** arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or **(3)** arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. “Knowingly relying” means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is “discriminatory” if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license **(a)** in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or **(b)** primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
### 12. No Surrender of Others' Freedom
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
### 13. Remote Network Interaction; Use with the GNU General Public License
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
### 14. Revised Versions of this License
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License “or any later version” applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
### 15. Disclaimer of Warranty
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
### 16. Limitation of Liability
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
### 17. Interpretation of Sections 15 and 16
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
_END OF TERMS AND CONDITIONS_
|
||||
|
||||
## How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the “copyright” line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a “Source” link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a “copyright disclaimer” for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<<http://www.gnu.org/licenses/>>.
|
||||
@@ -1,9 +1,316 @@
|
||||
# Pgn_to_tex
|
||||
|
||||
`Pgn_to_tex` converts chess games written in PGN to LaTeX. It renders move
|
||||
numbers, moves, comments, variations, NAG annotations, clock times, and
|
||||
optional chessboard diagrams of selected positions.
|
||||
|
||||
- [API documentation](https://therealowenrees.github.io/pgn_to_tex/)
|
||||
- [Changelog](CHANGELOG.md)
|
||||
- [Contributing](CONTRIBUTING.md)
|
||||
|
||||
## Requirements
|
||||
|
||||
- OCaml 5.4 or newer
|
||||
- dune
|
||||
- A LaTeX installation with `xskak` and `multicol` (see
|
||||
[LaTeX setup](#latex-setup))
|
||||
|
||||
## Installation
|
||||
|
||||
Install the released package with opam:
|
||||
|
||||
```sh
|
||||
opam install pgn_to_tex
|
||||
```
|
||||
|
||||
To use the current repository instead, clone it and pin the checkout:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/TheRealOwenRees/pgn_to_tex.git
|
||||
cd pgn_to_tex
|
||||
opam install .
|
||||
```
|
||||
|
||||
Then add the library to the relevant `dune` file:
|
||||
|
||||
```lisp
|
||||
(libraries pgn_to_tex)
|
||||
```
|
||||
|
||||
## Quick start
|
||||
|
||||
Open `Pgn_to_tex` and call `to_tex` with a PGN string:
|
||||
|
||||
```ocaml
|
||||
let pgn = "1. e4 e5 2. Nf3 Nc6 3. Bb5"
|
||||
|
||||
let tex = Pgn_to_tex.to_tex pgn
|
||||
```
|
||||
|
||||
`to_tex` returns a LaTeX fragment without a preamble or `\begin{document}`.
|
||||
`~diagram_data` defaults to no diagrams and `~clock` defaults to `false`, so
|
||||
this basic call needs no other arguments.
|
||||
|
||||
To render diagrams, describe the selected positions as JSON and parse it with
|
||||
`parse_diagrams_json`:
|
||||
|
||||
```ocaml
|
||||
let diagrams =
|
||||
Pgn_to_tex.parse_diagrams_json
|
||||
{| [
|
||||
{"fen": "rnbqkbnr/pppppppp/8/8/3P4/8/PPP1PPPP/RNBQKBNR b KQkq - 0 1",
|
||||
"path": ["d4"]},
|
||||
{"fen": "rnbqkbnr/ppp1pppp/8/3p4/3P4/8/PPP1PPPP/RNBQKBNR w KQkq - 0 2",
|
||||
"ply": 2}
|
||||
] |}
|
||||
|
||||
let tex = Pgn_to_tex.to_tex ~diagram_data:diagrams pgn
|
||||
```
|
||||
|
||||
To explicitly request a game with no diagrams, pass
|
||||
`~diagram_data:Pgn_to_tex.empty_diagrams`.
|
||||
|
||||
`diagram_data` is abstract. Construct it with `parse_diagrams_json` or
|
||||
`empty_diagrams` instead of building the internal representation directly.
|
||||
|
||||
## Diagram JSON schema
|
||||
|
||||
`parse_diagrams_json` accepts a JSON array. Each entry is an object:
|
||||
|
||||
```json
|
||||
[
|
||||
{"fen": "8/8/8/8/8/8/4K3/7k w - - 0 1", "path": ["d4", "d5", "e4", "d6"]},
|
||||
{"fen": "8/8/8/8/8/8/4K3/7k w - - 0 1", "ply": 5},
|
||||
{"fen": "8/8/8/8/8/8/4K3/7k w - - 0 1", "ply": 9, "path": ["e4", "e5", "Nf3", "Nc6"]}
|
||||
]
|
||||
```
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| ------ | --------------- | --------------- | ----------- |
|
||||
| `fen` | string | yes | The board position to render. |
|
||||
| `path` | array of string | one of path/ply | The SAN move sequence from the start of the game, including moves inside a variation (for example `["d4","d5","e4","d6"]`). It uniquely identifies mainline and variation positions. |
|
||||
| `ply` | integer | one of path/ply | Legacy half-move count from the start of the game: 1 after White's first move. It is used for mainline positions. |
|
||||
|
||||
Resolution rules:
|
||||
|
||||
- An entry may carry `path`, `ply`, or both.
|
||||
- A matching `path` takes precedence over a matching `ply`.
|
||||
- If no `path` matches, mainline positions fall back to a matching legacy `ply`.
|
||||
- Variation diagrams require `path`; a `ply`-only entry only matches mainline
|
||||
positions.
|
||||
- Missing both `path` and `ply` leaves the entry with no position to match.
|
||||
|
||||
Diagrams on the mainline use the default board size. Diagrams inside a
|
||||
variation are rendered inline and use the smaller `smallboard` size.
|
||||
|
||||
### Malformed diagram JSON
|
||||
|
||||
If the JSON is invalid, or any entry is malformed, `parse_diagrams_json`
|
||||
returns empty diagram data instead of raising. Conversion then proceeds
|
||||
without diagrams.
|
||||
|
||||
## Clocks
|
||||
|
||||
Clock annotations are opt-in:
|
||||
|
||||
```ocaml
|
||||
let tex = Pgn_to_tex.to_tex ~clock:true ~diagram_data:diagrams pgn
|
||||
```
|
||||
|
||||
With `~clock:true`, the most recent clock values for both players are shown
|
||||
above and below each rendered diagram. Clock values come from PGN clock
|
||||
annotations such as `{[%clk 0:10:00]}` or an inline `[%clk 0:10:00]`.
|
||||
|
||||
Clocks are displayed as part of diagram output. When no diagram is selected
|
||||
for a position, its clock values are not emitted.
|
||||
|
||||
## Variations
|
||||
|
||||
Parenthesised variations are rendered inline inside the mainline, for example
|
||||
`( 2... d6 )`. Mainline moves and move numbers are bold; variation moves are
|
||||
not. Comments and NAGs inside a variation are rendered there too. Variation
|
||||
diagrams are looked up by their full `path` and use `smallboard` so they do not
|
||||
dominate the subline.
|
||||
|
||||
## Supported headers
|
||||
|
||||
The following PGN headers are rendered:
|
||||
|
||||
- `Event` is used as the title when `Title` is absent.
|
||||
- `Title` is the document title. When `Subtitle` is also present, the subtitle
|
||||
is rendered below the title. A title without a subtitle renders no subtitle
|
||||
block.
|
||||
- `Author` is the author line when present. Otherwise the author line is built
|
||||
from `White` and `Black`, including `WhiteElo` and `BlackElo` when supplied.
|
||||
- `Date` and `Site` are combined into the date line. An empty date with a site
|
||||
renders the site; an empty date and site render an empty date.
|
||||
- `Result` is rendered in bold at the end of the game.
|
||||
|
||||
All other headers are ignored.
|
||||
|
||||
## NAG annotations
|
||||
|
||||
The following Numeric Annotation Glyphs are rendered:
|
||||
|
||||
| NAG | LaTeX |
|
||||
| ------ | ----------------------- |
|
||||
| `$1` | `!` |
|
||||
| `$2` | `?` |
|
||||
| `$3` | `!!` |
|
||||
| `$4` | `??` |
|
||||
| `$5` | `!?` |
|
||||
| `$6` | `?!` |
|
||||
| `$10` | `=` |
|
||||
| `$13` | `\infty` |
|
||||
| `$14` | `\wbetter` |
|
||||
| `$15` | `\bbetter` |
|
||||
| `$16` | `\ensuremath{\pm}` |
|
||||
| `$17` | `\ensuremath{\mp}` |
|
||||
| `$18` | `+-` |
|
||||
| `$19` | `-+` |
|
||||
| `$22` | `\zugzwang` |
|
||||
| `$32` | `\development` |
|
||||
| `$36` | `\initiative` |
|
||||
| `$40` | `\attack` |
|
||||
| `$44` | `\compensation` |
|
||||
| `$132` | `\counterplay` |
|
||||
|
||||
Unmapped NAGs are ignored.
|
||||
|
||||
## Error behavior
|
||||
|
||||
- `to_tex` raises `Failure "Parse error"` when the PGN cannot be parsed.
|
||||
- `parse_diagrams_json` never raises for malformed JSON; it returns empty
|
||||
diagram data, as described above.
|
||||
|
||||
## LaTeX setup
|
||||
|
||||
The generated string is a fragment: it does not include a document class,
|
||||
preamble, or `\begin{document}`. A complete document using `xskak` (which
|
||||
loads `chessboard`, `skak`, and the chess symbol fonts), `multicol` for the
|
||||
column layout, and the default diagram commands looks like this:
|
||||
|
||||
```latex
|
||||
\documentclass{article}
|
||||
\usepackage{xskak}
|
||||
\usepackage{multicol}
|
||||
\usepackage{amsmath,amssymb}
|
||||
|
||||
% NAG $13 renders \infty, a math-mode symbol, in text mode.
|
||||
\let\pgninfinity\infty
|
||||
\renewcommand{\infty}{\ensuremath{\pgninfinity}}
|
||||
|
||||
\begin{document}
|
||||
\begin{multicols}{2}
|
||||
% Paste the string returned by Pgn_to_tex.to_tex here.
|
||||
\end{multicols}
|
||||
\end{document}
|
||||
```
|
||||
|
||||
The relevant packages are:
|
||||
|
||||
- `xskak` for `\newchessgame`, `\chessboard`, and the NAG symbol commands.
|
||||
- `multicol` for the two-column environment shown above.
|
||||
- `amsmath` and `amssymb` for math symbols.
|
||||
|
||||
## JavaScript build
|
||||
|
||||
The JavaScript target is optional. Dune skips it when the JavaScript
|
||||
dependencies are not installed. Install them with:
|
||||
|
||||
```sh
|
||||
opam install js_of_ocaml js_of_ocaml-ppx
|
||||
```
|
||||
|
||||
Build the artifact with:
|
||||
|
||||
```sh
|
||||
dune build bin/pgn_to_tex_js.bc.js
|
||||
```
|
||||
|
||||
The generated CommonJS file is
|
||||
`_build/default/bin/pgn_to_tex_js.bc.js`. It works in Node and in the browser.
|
||||
|
||||
The build exposes a single global function with the same three inputs as the
|
||||
JavaScript entry point:
|
||||
|
||||
```js
|
||||
to_tex(pgnString, diagramJsonString, displayClock);
|
||||
```
|
||||
|
||||
- `pgnString` is the PGN text.
|
||||
- `diagramJsonString` is the diagram JSON. Pass `""` or `"{}"` when there are
|
||||
no diagrams.
|
||||
- `displayClock` is a boolean controlling clock rendering.
|
||||
- The return value is the LaTeX fragment as a string.
|
||||
|
||||
Node example:
|
||||
|
||||
```js
|
||||
require("./_build/default/bin/pgn_to_tex_js.bc.js");
|
||||
|
||||
const gameTex = globalThis.to_tex("1. e4 e5 2. Nf3", "{}", false);
|
||||
```
|
||||
|
||||
In the browser, the function is available as `window.to_tex` after the
|
||||
artifact is loaded.
|
||||
|
||||
Run the Node smoke test after building the artifact:
|
||||
|
||||
```sh
|
||||
node test/js/smoke.js
|
||||
```
|
||||
|
||||
## Migration from 0.0.x
|
||||
|
||||
Version `0.1.0` is a breaking release. The old `Pgn_logic` library name and the
|
||||
`Pgn2tex` module are gone.
|
||||
|
||||
| 0.0.x | 0.1.0 |
|
||||
| ----- | ----- |
|
||||
| `open Pgn_logic` | `open Pgn_to_tex` or use `Pgn_to_tex.` |
|
||||
| `Pgn2tex.to_tex` | `Pgn_to_tex.to_tex` |
|
||||
| `Pgn2tex.parse_diagrams_json` | `Pgn_to_tex.parse_diagrams_json` |
|
||||
| Exposed `MoveMap.t` diagram data | Abstract `Pgn_to_tex.diagram_data` |
|
||||
| `_build/default/bin/main.bc.js` | `_build/default/bin/pgn_to_tex_js.bc.js` |
|
||||
|
||||
The optional arguments now come before the PGN string:
|
||||
|
||||
```ocaml
|
||||
(* 0.0.x *)
|
||||
let tex = Pgn2tex.to_tex pgn ~diagram_data ~clock:false
|
||||
|
||||
(* 0.1.0 *)
|
||||
let tex = Pgn_to_tex.to_tex ~diagram_data ~clock:false pgn
|
||||
```
|
||||
|
||||
Replace a hand-built diagram map with `parse_diagrams_json`, or use
|
||||
`empty_diagrams` for a game without diagrams. Path-only diagram entries are
|
||||
supported; see [Diagram JSON schema](#diagram-json-schema). The JavaScript
|
||||
`to_tex(pgn, diagramJson, displayClock)` contract is unchanged apart from the
|
||||
artifact name.
|
||||
|
||||
## Dependencies
|
||||
|
||||
- dune
|
||||
- sedlex
|
||||
- menhir
|
||||
- js_of_ocaml-compiler
|
||||
- ocamlformat
|
||||
- ocaml-lsp-server
|
||||
- ounit2
|
||||
Runtime and build dependencies:
|
||||
|
||||
- `ocaml` >= 5.4
|
||||
- `dune` >= 3.21
|
||||
- `sedlex` >= 3.7
|
||||
- `menhir` >= 20260209
|
||||
- `yojson` >= 3.0
|
||||
|
||||
Test-only dependencies:
|
||||
|
||||
- `ounit2` >= 2.2.7
|
||||
- `js_of_ocaml`
|
||||
- `js_of_ocaml-ppx`
|
||||
|
||||
Development and documentation dependencies:
|
||||
|
||||
- `ocamlformat` 0.29.0 (development setup)
|
||||
- `odoc` (documentation build)
|
||||
|
||||
## License
|
||||
|
||||
AGPL-3.0-or-later. See [LICENSE](LICENSE).
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
(executable
|
||||
(name main)
|
||||
(name pgn_to_tex_js)
|
||||
(modes js)
|
||||
(optional)
|
||||
(libraries pgn_to_tex js_of_ocaml yojson)
|
||||
(preprocess
|
||||
(pps js_of_ocaml-ppx))
|
||||
(enabled_if
|
||||
(= %{env:CI=false} "false")))
|
||||
(pps js_of_ocaml-ppx)))
|
||||
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
open Js_of_ocaml
|
||||
open Pgn_logic
|
||||
open Ast
|
||||
|
||||
let parse_diagram_json json_str =
|
||||
let json = Yojson.Basic.from_string json_str in
|
||||
let json_list = Yojson.Basic.Util.to_list json in
|
||||
|
||||
List.fold_left
|
||||
(fun acc item ->
|
||||
let move_int =
|
||||
item |> Yojson.Basic.Util.member "ply" |> Yojson.Basic.Util.to_int
|
||||
in
|
||||
let fen_str =
|
||||
item |> Yojson.Basic.Util.member "fen" |> Yojson.Basic.Util.to_string
|
||||
in
|
||||
Pgn2tex.MoveMap.add move_int fen_str acc)
|
||||
Pgn2tex.MoveMap.empty json_list
|
||||
|
||||
let convert_js pgn_js diagram_json_js display_clock =
|
||||
let pgn = Js.to_string pgn_js in
|
||||
|
||||
(* convert JS string into OCaml string *)
|
||||
let json_str = Js.to_string diagram_json_js in
|
||||
|
||||
let diagram_data =
|
||||
if json_str = "" || json_str = "{}" then Pgn2tex.MoveMap.empty
|
||||
else parse_diagram_json json_str
|
||||
in
|
||||
|
||||
let result = Pgn2tex.to_tex pgn ~diagram_data ~clock:display_clock in
|
||||
Js.string result
|
||||
|
||||
(* Exporting the module to the global JavaScript scope *)
|
||||
let () = Js.export "to_tex" (Js.wrap_callback convert_js)
|
||||
@@ -0,0 +1,20 @@
|
||||
open Js_of_ocaml
|
||||
open Pgn_to_tex
|
||||
|
||||
let convert_js pgn_js diagram_json_js display_clock =
|
||||
let pgn = Js.to_string pgn_js in
|
||||
|
||||
(* convert JS string into OCaml string *)
|
||||
let json_str = Js.to_string diagram_json_js in
|
||||
|
||||
let diagram_data =
|
||||
if json_str = "" || json_str = "{}" then Pgn_to_tex.empty_diagrams
|
||||
else Pgn_to_tex.parse_diagrams_json json_str
|
||||
in
|
||||
|
||||
let result = Pgn_to_tex.to_tex ~diagram_data ~clock:display_clock pgn in
|
||||
Js.string result
|
||||
|
||||
(* The documented Node and browser contract is a single global [to_tex]
|
||||
function, so setting it on the global object is the only export needed. *)
|
||||
let () = Js.Unsafe.set Js.Unsafe.global "to_tex" (Js.wrap_callback convert_js)
|
||||
@@ -0,0 +1,21 @@
|
||||
{0 Pgn_to_tex}
|
||||
|
||||
[Pgn_to_tex] converts chess games written in PGN to LaTeX fragments. Move
|
||||
numbers, moves, comments, variations, NAGs, and optional diagrams of selected
|
||||
positions are rendered into text suitable for inclusion in a larger LaTeX
|
||||
document.
|
||||
|
||||
{1 Quick start}
|
||||
|
||||
{[
|
||||
let tex = Pgn_to_tex.to_tex "1. e4 e5 2. Nf3"
|
||||
]}
|
||||
|
||||
Pass [~clock:true] to render clock annotations. Pass [~diagram_data] to select
|
||||
positions for diagrams; build a selection with
|
||||
{!Pgn_to_tex.parse_diagrams_json} or use {!Pgn_to_tex.empty_diagrams} to
|
||||
explicitly request a game with no diagrams.
|
||||
|
||||
{1 API}
|
||||
|
||||
{!modules:Pgn_to_tex}
|
||||
@@ -0,0 +1,35 @@
|
||||
# Domain Docs
|
||||
|
||||
How the engineering skills should consume this repo's domain documentation when exploring the codebase.
|
||||
|
||||
## Before exploring, read these
|
||||
|
||||
- **`GLOSSARY.md`** at the repo root.
|
||||
- **`docs/adr/`**: read ADRs that touch the area you're about to work in.
|
||||
|
||||
If any of these files don't exist, **proceed silently**. Don't flag their absence; don't suggest creating them upfront. The `/domain-modeling` skill (reached via `/grill-with-docs` and `/improve-codebase-architecture`) creates them lazily when terms or decisions actually get resolved.
|
||||
|
||||
## File structure
|
||||
|
||||
Single-context repo (most repos):
|
||||
|
||||
```
|
||||
/
|
||||
├── GLOSSARY.md
|
||||
├── docs/adr/
|
||||
│ ├── 0001-event-sourced-orders.md
|
||||
│ └── 0002-postgres-for-write-model.md
|
||||
└── src/
|
||||
```
|
||||
|
||||
## Use the glossary's vocabulary
|
||||
|
||||
When your output names a domain concept (in an issue title, a refactor proposal, a hypothesis, a test name), use the term as defined in `GLOSSARY.md`. Don't drift to synonyms the glossary explicitly avoids.
|
||||
|
||||
If the concept you need isn't in the glossary yet, that's a signal: either you're inventing language the project doesn't use (reconsider) or there's a real gap (note it for `/domain-modeling`).
|
||||
|
||||
## Flag ADR conflicts
|
||||
|
||||
If your output contradicts an existing ADR, surface it explicitly rather than silently overriding:
|
||||
|
||||
> _Contradicts ADR-0007 (event-sourced orders), but worth reopening because…_
|
||||
@@ -0,0 +1,46 @@
|
||||
# Issue tracker: GitHub
|
||||
|
||||
Issues and specs for this repo live as GitHub issues. Use the `gh` CLI for all operations.
|
||||
|
||||
## Conventions
|
||||
|
||||
- **Create an issue**: `gh issue create --title "..." --body "..."`. Use a heredoc for multi-line bodies.
|
||||
- **Read an issue**: `gh issue view <number> --json number,title,body,labels,comments`.
|
||||
- **List issues**: `gh issue list --state open --json number,title,body,labels,comments --jq '[.[] | {number, title, body, labels: [.labels[].name], comments: [.comments[].body]}]'` with appropriate `--label` and `--state` filters.
|
||||
- **Make an issue a sub-issue of a parent**: `gh issue create --parent <parent> ...`, or `gh issue edit <parent> --add-sub-issue <child>` afterwards (`gh` 2.94+). Older `gh`: `gh api --method POST repos/<owner>/<repo>/issues/<parent>/sub_issues -F sub_issue_id=<child-db-id>` (database id, as in **Blocking** below). Without sub-issues, put `Part of #<parent>` at the top of the child body.
|
||||
- **Comment on an issue**: `gh issue comment <number> --body "..."`
|
||||
- **Apply / remove labels**: `gh issue edit <number> --add-label "..."` / `--remove-label "..."`
|
||||
- **Close**: `gh issue close <number> --comment "..."`
|
||||
|
||||
Infer the repo from `git remote -v`; `gh` does this automatically when run inside a clone.
|
||||
|
||||
## Pull requests as a triage surface
|
||||
|
||||
**PRs as a request surface: no.** _(Set to `yes` if this repo treats external PRs as feature requests; `/triage` reads this flag.)_
|
||||
|
||||
When set to `yes`, PRs run through the same labels and states as issues, using the `gh pr` equivalents:
|
||||
|
||||
- **Read a PR**: `gh pr view <number> --comments` and `gh pr diff <number>` for the diff.
|
||||
- **List external PRs for triage**: `gh api --paginate 'repos/{owner}/{repo}/pulls?state=open' --jq '.[] | select(.author_association | IN("OWNER","MEMBER","COLLABORATOR") | not) | {number, title, author: .user.login, author_association, labels: [.labels[].name]}'`.
|
||||
- **Comment / label / close**: `gh pr comment`, `gh pr edit --add-label`/`--remove-label`, `gh pr close`.
|
||||
|
||||
GitHub shares one number space across issues and PRs, so a bare `#42` may be either: resolve with `gh pr view 42` and fall back to `gh issue view 42`.
|
||||
|
||||
## When a skill says "publish to the issue tracker"
|
||||
|
||||
Create a GitHub issue.
|
||||
|
||||
## When a skill says "fetch the relevant ticket"
|
||||
|
||||
Read it as in **Read an issue** above.
|
||||
|
||||
## Wayfinding operations
|
||||
|
||||
Used by `/wayfinder`. The **map** is a single issue with **child** issues as tickets.
|
||||
|
||||
- **Map**: a single issue labelled `wayfinder:map`, holding the Notes / Decisions-so-far / Fog body. `gh issue create --label wayfinder:map`.
|
||||
- **Child ticket**: an issue linked to the map as a GitHub sub-issue (see **Make an issue a sub-issue of a parent**). Where sub-issues aren't enabled, add the child to a task list in the map body and put `Part of #<map>` at the top of the child body. Labels: `wayfinder:<type>` (`research`/`prototype`/`grilling`/`task`). Once claimed, the ticket is assigned to the driving dev.
|
||||
- **Blocking**: GitHub's **native issue dependencies**, the canonical, UI-visible representation. Add an edge with `gh api --method POST repos/<owner>/<repo>/issues/<child>/dependencies/blocked_by -F issue_id=<blocker-db-id>`, where `<blocker-db-id>` is the blocker's numeric **database id** (`gh api repos/<owner>/<repo>/issues/<n> --jq .id`, _not_ the `#number` or `node_id`). GitHub reports `issue_dependencies_summary.blocked_by` (open blockers only, the live gate). Where dependencies aren't available, fall back to a `Blocked by: #<n>, #<n>` line at the top of the child body. A ticket is unblocked when every blocker is closed.
|
||||
- **Frontier query**: list the map's open children (`gh issue list --state open`, scoped to the map's sub-issues / task list), drop any with an open blocker (`issue_dependencies_summary.blocked_by > 0`, or an open issue in the `Blocked by` line) or an assignee; first in map order wins.
|
||||
- **Claim**: `gh issue edit <n> --add-assignee @me`, the session's first write.
|
||||
- **Resolve**: `gh issue comment <n> --body "<answer>"`, then `gh issue close <n>`, then append a context pointer (gist + link) to the map's Decisions-so-far.
|
||||
@@ -0,0 +1,15 @@
|
||||
# Triage Labels
|
||||
|
||||
The skills speak in terms of five canonical triage roles. This file maps those roles to the actual label strings used in this repo's issue tracker.
|
||||
|
||||
| Label in mattpocock/skills | Label in our tracker | Meaning |
|
||||
| -------------------------- | -------------------- | ---------------------------------------- |
|
||||
| `needs-triage` | `needs-triage` | Maintainer needs to evaluate this issue |
|
||||
| `needs-info` | `needs-info` | Waiting on reporter for more information |
|
||||
| `ready-for-agent` | `ready-for-agent` | Fully specified, ready for an AFK agent |
|
||||
| `ready-for-human` | `ready-for-human` | Requires human implementation |
|
||||
| `wontfix` | `wontfix` | Will not be actioned |
|
||||
|
||||
When a skill mentions a role (e.g. "apply the AFK-ready triage label"), use the corresponding label string from this table.
|
||||
|
||||
Edit the "Label in our tracker" column to match whatever vocabulary you actually use.
|
||||
+12
-3
@@ -15,9 +15,10 @@
|
||||
|
||||
(license AGPL-3.0-or-later)
|
||||
|
||||
(documentation https://github.com/TheRealOwenRees/pgn_to_tex/README.md)
|
||||
(documentation
|
||||
https://therealowenrees.github.io/pgn_to_tex/)
|
||||
|
||||
(version 0.0.1)
|
||||
(version 0.1.0)
|
||||
|
||||
(package
|
||||
(name pgn_to_tex)
|
||||
@@ -37,8 +38,16 @@
|
||||
(and
|
||||
:with-test
|
||||
(>= 2.2.7)))
|
||||
(js_of_ocaml
|
||||
(and
|
||||
:with-test))
|
||||
(js_of_ocaml-ppx
|
||||
(and
|
||||
:with-test))
|
||||
("ocamlformat"
|
||||
(and :with-dev-setup)))
|
||||
(and
|
||||
:with-dev-setup
|
||||
(= 0.29.0))))
|
||||
(tags
|
||||
("pgn" "latex" "chess" "parser")))
|
||||
|
||||
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
module MoveMap = Map.Make (Int)
|
||||
|
||||
type tag = { key : string; value : string }
|
||||
|
||||
type item =
|
||||
| Move of string
|
||||
| Number of string
|
||||
| Clock of string
|
||||
| Nag of string
|
||||
| Comment of string
|
||||
| Result of string
|
||||
| Variation of item list
|
||||
|
||||
type game = { tags : tag list; content : item list; result : string option }
|
||||
@@ -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))
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
module MoveMap = Map.Make (Int)
|
||||
module PathMap = Map.Make (String)
|
||||
|
||||
type tag = { key : string; value : string }
|
||||
|
||||
(* Diagrams selected by the client. [by_ply] keeps the legacy mainline lookup
|
||||
keyed on the ply number; [by_path] keys on the SAN move sequence from the
|
||||
root (space separated), which uniquely identifies mainline and variation
|
||||
positions alike. *)
|
||||
type diagram_data = { by_ply : string MoveMap.t; by_path : string PathMap.t }
|
||||
|
||||
let empty_diagrams = { by_ply = MoveMap.empty; by_path = PathMap.empty }
|
||||
|
||||
type item =
|
||||
| Move of string
|
||||
| Number of string
|
||||
| Clock of string
|
||||
| Nag of string
|
||||
| Comment of string
|
||||
| Result of string
|
||||
| Variation of item list
|
||||
|
||||
type game = { tags : tag list; content : item list; result : string option }
|
||||
@@ -0,0 +1,38 @@
|
||||
module MoveMap = Ast.MoveMap
|
||||
module PathMap = Ast.PathMap
|
||||
open Yojson.Safe.Util
|
||||
|
||||
let path_key path_moves = String.concat " " path_moves
|
||||
|
||||
let parse_diagrams_json diagrams_json_str =
|
||||
let fail () = raise Exit in
|
||||
try
|
||||
let json = Yojson.Safe.from_string diagrams_json_str in
|
||||
let diagrams_list = to_list json in
|
||||
List.fold_left
|
||||
(fun acc item ->
|
||||
let fields = match item with `Assoc fields -> fields | _ -> fail () in
|
||||
let fen =
|
||||
match List.assoc_opt "fen" fields with
|
||||
| Some (`String fen) -> fen
|
||||
| _ -> fail ()
|
||||
in
|
||||
let acc =
|
||||
match List.assoc_opt "ply" fields with
|
||||
| None -> acc
|
||||
| Some (`Int ply) ->
|
||||
{ acc with Ast.by_ply = MoveMap.add ply fen acc.Ast.by_ply }
|
||||
| Some _ -> fail ()
|
||||
in
|
||||
match List.assoc_opt "path" fields with
|
||||
| None -> acc
|
||||
| Some (`List path_items) ->
|
||||
let key = path_items |> List.map to_string |> path_key in
|
||||
{ acc with Ast.by_path = PathMap.add key fen acc.Ast.by_path }
|
||||
| Some _ -> fail ())
|
||||
Ast.empty_diagrams diagrams_list
|
||||
with _ -> Ast.empty_diagrams
|
||||
|
||||
let to_tex pgn ~diagram_data ~clock =
|
||||
let game = Parsing.parse_pgn pgn in
|
||||
Latex.game_to_tex game ~diagram_data ~clock
|
||||
@@ -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))
|
||||
@@ -27,7 +27,10 @@ let tags_to_tex tags =
|
||||
^ build_date_site_string date site
|
||||
^ "\\maketitle\n\\newchessgame"
|
||||
|
||||
let rec item_to_tex is_mainline ply ?(diagram_data = MoveMap.empty) = function
|
||||
let path_key path_moves = String.concat " " path_moves
|
||||
|
||||
let rec item_to_tex is_mainline ply ?(diagram_data = Ast.empty_diagrams)
|
||||
?(branch_path = []) = function
|
||||
| Number n -> if is_mainline then "\\textbf{" ^ n ^ "}" else n
|
||||
| Move m ->
|
||||
if is_mainline then "\\textbf{" ^ escape_tex m ^ "}" else escape_tex m
|
||||
@@ -35,40 +38,53 @@ let rec item_to_tex is_mainline ply ?(diagram_data = MoveMap.empty) = function
|
||||
if is_mainline then "\\newline " ^ escape_tex c ^ "\\par"
|
||||
else escape_tex c
|
||||
| Result r -> "\\textbf{" ^ r ^ "}"
|
||||
| Variation v -> "( " ^ render_game false ~diagram_data v ^ " )"
|
||||
| Variation v ->
|
||||
"( " ^ render_game false ~diagram_data ~path:branch_path v ^ " )"
|
||||
| Nag g -> " " ^ Nag.nag_to_tex g ^ "{}"
|
||||
| Clock c -> c
|
||||
|
||||
and render_game is_mainline ?(diagram_data = MoveMap.empty) ?(clock = false)
|
||||
items =
|
||||
let rec aux ply interrupted ?(white_time = "0:00") ?(black_time = "0:00") =
|
||||
and render_game is_mainline ?(diagram_data = Ast.empty_diagrams)
|
||||
?(clock = false) ?(path = []) items =
|
||||
let rec aux ply interrupted ~white_time ~black_time ~path ~branch_path =
|
||||
function
|
||||
| [] -> ""
|
||||
| Comment c :: Move m :: tail when is_mainline && ply mod 2 != 0 ->
|
||||
let next_ply = ply + 1 in
|
||||
let next_path = path @ [ m ] in
|
||||
let rendered_comment = "\\newline " ^ escape_tex c ^ "\\par" in
|
||||
let rendered_move = "\\textbf{\\ldots{}" ^ escape_tex m ^ "}" in
|
||||
let diag_str =
|
||||
match get_diagram next_ply diagram_data with
|
||||
match
|
||||
get_diagram ~path:(path_key next_path) ~ply:next_ply diagram_data
|
||||
with
|
||||
| Some s -> s
|
||||
| None -> ""
|
||||
in
|
||||
let has_diag = diag_str <> "" in
|
||||
rendered_comment ^ " " ^ rendered_move ^ diag_str ^ " "
|
||||
^ aux next_ply has_diag tail
|
||||
^ aux next_ply has_diag ~white_time ~black_time ~path:next_path
|
||||
~branch_path:path tail
|
||||
| head :: tail -> (
|
||||
match head with
|
||||
| Clock c ->
|
||||
if ply mod 2 = 0 then
|
||||
aux ply interrupted ~white_time ~black_time:c tail
|
||||
else aux ply interrupted ~white_time:c ~black_time tail
|
||||
aux ply interrupted ~white_time ~black_time:c ~path ~branch_path
|
||||
tail
|
||||
else
|
||||
aux ply interrupted ~white_time:c ~black_time ~path ~branch_path
|
||||
tail
|
||||
| _ ->
|
||||
let is_move = match head with Move _ -> true | _ -> false in
|
||||
let move_san = match head with Move m -> Some m | _ -> None in
|
||||
let is_move = Option.is_some move_san in
|
||||
|
||||
let next_ply =
|
||||
match head with Move _ when is_mainline -> ply + 1 | _ -> ply
|
||||
in
|
||||
|
||||
let next_path =
|
||||
match move_san with Some m -> path @ [ m ] | None -> path
|
||||
in
|
||||
|
||||
let prefix =
|
||||
if is_move && is_mainline && next_ply mod 2 == 0 && interrupted
|
||||
then "\\ldots{}"
|
||||
@@ -77,7 +93,7 @@ and render_game is_mainline ?(diagram_data = MoveMap.empty) ?(clock = false)
|
||||
|
||||
let rendered_head =
|
||||
let raw_head =
|
||||
item_to_tex is_mainline next_ply ~diagram_data head
|
||||
item_to_tex is_mainline next_ply ~diagram_data ~branch_path head
|
||||
in
|
||||
if prefix <> "" && raw_head <> "" then
|
||||
"\\textbf{" ^ prefix ^ "}" ^ raw_head
|
||||
@@ -85,16 +101,23 @@ and render_game is_mainline ?(diagram_data = MoveMap.empty) ?(clock = false)
|
||||
in
|
||||
|
||||
let diag_str =
|
||||
if is_move && is_mainline then
|
||||
get_diagram next_ply diagram_data ~clock ~white_time ~black_time
|
||||
if is_move then
|
||||
if is_mainline then
|
||||
get_diagram ~path:(path_key next_path) ~ply:next_ply ~clock
|
||||
~white_time ~black_time diagram_data
|
||||
else
|
||||
get_diagram_by_path ~path:(path_key next_path) ~small:true
|
||||
diagram_data
|
||||
else None
|
||||
in
|
||||
|
||||
let diag_output = match diag_str with Some s -> s | None -> "" in
|
||||
let is_comment = match head with Comment _ -> true | _ -> false in
|
||||
let next_interrupted = diag_output <> "" || is_comment in
|
||||
let next_branch_path = if is_move then path else branch_path in
|
||||
let rest =
|
||||
aux next_ply next_interrupted ~white_time ~black_time tail
|
||||
aux next_ply next_interrupted ~white_time ~black_time
|
||||
~path:next_path ~branch_path:next_branch_path tail
|
||||
in
|
||||
|
||||
if rendered_head = "" then rest
|
||||
@@ -102,7 +125,9 @@ and render_game is_mainline ?(diagram_data = MoveMap.empty) ?(clock = false)
|
||||
rendered_head ^ diag_output ^ if rest = "" then "" else " " ^ rest
|
||||
)
|
||||
in
|
||||
String.trim (aux 0 false items)
|
||||
String.trim
|
||||
(aux 0 false ~white_time:"0:00" ~black_time:"0:00" ~path ~branch_path:path
|
||||
items)
|
||||
|
||||
let game_to_tex game ~diagram_data ~clock =
|
||||
let header_tex = tags_to_tex game.tags in
|
||||
@@ -0,0 +1,94 @@
|
||||
module MoveMap = Ast.MoveMap
|
||||
module PathMap = Ast.PathMap
|
||||
|
||||
(* escape strings for LaTeX *)
|
||||
let escape_tex s =
|
||||
let b = Buffer.create (String.length s) in
|
||||
String.iter
|
||||
(fun c ->
|
||||
match c with
|
||||
| '#' -> Buffer.add_string b "\\#"
|
||||
| '%' -> Buffer.add_string b "\\%"
|
||||
| '{' -> Buffer.add_string b "\\{"
|
||||
| '}' -> Buffer.add_string b "\\}"
|
||||
| '_' -> Buffer.add_string b "\\_"
|
||||
| '&' -> Buffer.add_string b "\\&"
|
||||
| _ -> Buffer.add_char b c)
|
||||
s;
|
||||
Buffer.contents b
|
||||
|
||||
(* ELO string builder *)
|
||||
let build_elo_string elo = if String.length elo > 0 then "(" ^ elo ^ ")" else ""
|
||||
|
||||
(* Author string builder *)
|
||||
let build_author_string author white black white_elo black_elo =
|
||||
if author <> "" then "\\author{" ^ escape_tex author ^ "}"
|
||||
else
|
||||
match (white, black) with
|
||||
| "", "" -> "\\author{}"
|
||||
| white, black ->
|
||||
"\\author{" ^ escape_tex white ^ " " ^ build_elo_string white_elo
|
||||
^ "\\\\" ^ escape_tex black ^ " " ^ build_elo_string black_elo ^ "}"
|
||||
|
||||
(* Title string builder *)
|
||||
let build_title_string event title subtitle =
|
||||
match (event, title, subtitle) with
|
||||
| event, "", "" -> "\\title{" ^ event ^ "}"
|
||||
| _event, "", subtitle -> "\\title{" ^ subtitle ^ "}"
|
||||
| _event, title, "" -> "\\title{" ^ title ^ "}"
|
||||
| _event, title, subtitle ->
|
||||
"\\title{" ^ title ^ "\\\\[2ex]\\large{" ^ subtitle ^ "}}"
|
||||
|
||||
(* Date and Site string builder *)
|
||||
let build_date_site_string date site =
|
||||
match (date, site) with
|
||||
| "", "" -> "\\date{}"
|
||||
| "", s -> "\\date{" ^ s ^ "}"
|
||||
| d, "" -> "\\date{" ^ d ^ "}"
|
||||
| d, s -> "\\date{" ^ d ^ ", " ^ s ^ "}"
|
||||
|
||||
(* board size options: mainline diagrams use the default size, variation
|
||||
diagrams use the smaller "smallboard" so they don't dominate the subline *)
|
||||
let board_options small = if small then ", smallboard" else ""
|
||||
|
||||
(* emit a diagram with or without clock times *)
|
||||
let diagram_tex ?(clock = false) ?(white_time = "0:00") ?(black_time = "0:00")
|
||||
?(small = false) fen =
|
||||
let size = board_options small in
|
||||
if not clock then
|
||||
"\n\\par\\nobreak\\medskip\\chessboard[setfen=" ^ fen ^ ", vmargin=false"
|
||||
^ size ^ "]\\par\\medskip\n"
|
||||
else
|
||||
"\\par\\medskip\\noindent" ^ "\\begin{minipage}{\\linewidth}" ^ black_time
|
||||
^ "\\par\\nopagebreak\\smallskip\n" ^ "\\chessboard[setfen=" ^ fen
|
||||
^ ", vmargin=false" ^ size ^ "]\\par\\nopagebreak\\vspace{1em}\n"
|
||||
^ white_time ^ "\\end{minipage}\\par\\medskip"
|
||||
|
||||
(* look up a diagram by its SAN path (root -> position, space separated) *)
|
||||
let get_diagram_by_path ?(clock = false) ?(white_time = "0:00")
|
||||
?(black_time = "0:00") ?(small = false) ~path diagram_data =
|
||||
match PathMap.find_opt path diagram_data.Ast.by_path with
|
||||
| None -> None
|
||||
| Some fen -> Some (diagram_tex ~clock ~white_time ~black_time ~small fen)
|
||||
|
||||
(* look up a diagram by ply (legacy mainline keying) *)
|
||||
let get_diagram_by_ply ?(clock = false) ?(white_time = "0:00")
|
||||
?(black_time = "0:00") ply diagram_data =
|
||||
match MoveMap.find_opt ply diagram_data.Ast.by_ply with
|
||||
| None -> None
|
||||
| Some fen -> Some (diagram_tex ~clock ~white_time ~black_time fen)
|
||||
|
||||
(* Prefer the path lookup, falling back to ply for older payloads that only
|
||||
carry a mainline ply. *)
|
||||
let get_diagram ?(clock = false) ?(white_time = "0:00") ?(black_time = "0:00")
|
||||
?(small = false) ?path ~ply diagram_data =
|
||||
let by_path =
|
||||
match path with
|
||||
| Some path ->
|
||||
get_diagram_by_path ~clock ~white_time ~black_time ~small ~path
|
||||
diagram_data
|
||||
| None -> None
|
||||
in
|
||||
match by_path with
|
||||
| Some _ as diagram -> diagram
|
||||
| None -> get_diagram_by_ply ~clock ~white_time ~black_time ply diagram_data
|
||||
@@ -76,8 +76,8 @@ and read_comment_clock buf =
|
||||
| clock_val ->
|
||||
let time = Utf8.lexeme buf in
|
||||
begin match%sedlex buf with
|
||||
| ']' -> begin
|
||||
match%sedlex buf with
|
||||
| ']' ->
|
||||
begin match%sedlex buf with
|
||||
| Star white_space, '}' -> CLOCK time
|
||||
| _ -> failwith "Expected closing '}' after clock comment"
|
||||
end
|
||||
@@ -28,15 +28,3 @@ let parse_pgn s =
|
||||
in
|
||||
try MenhirLib.Convert.Simplified.traditional2revised Parser.main provider
|
||||
with _ -> failwith "Parse error"
|
||||
|
||||
(* let parse_diagram_json json_str =
|
||||
let json = Yojson.Basic.from_string json_str in
|
||||
let json_assoc = Yojson.Basic.Util.to_assoc json in
|
||||
|
||||
List.fold_left
|
||||
(fun acc (key_str, json_value) ->
|
||||
let value_string = Yojson.Basic.Util.to_string json_value in
|
||||
match int_of_string_opt key_str with
|
||||
| Some k -> Pgn2tex.MoveMap.add k value_string acc
|
||||
| None -> acc)
|
||||
Pgn2tex.MoveMap.empty json_assoc *)
|
||||
@@ -1,63 +0,0 @@
|
||||
module MoveMap = Ast.MoveMap
|
||||
|
||||
(* escape strings for LaTeX *)
|
||||
let escape_tex s =
|
||||
let b = Buffer.create (String.length s) in
|
||||
String.iter
|
||||
(fun c ->
|
||||
match c with
|
||||
| '#' -> Buffer.add_string b "\\#"
|
||||
| '%' -> Buffer.add_string b "\\%"
|
||||
| '{' -> Buffer.add_string b "\\{"
|
||||
| '}' -> Buffer.add_string b "\\}"
|
||||
| '_' -> Buffer.add_string b "\\_"
|
||||
| '&' -> Buffer.add_string b "\\&"
|
||||
| _ -> Buffer.add_char b c)
|
||||
s;
|
||||
Buffer.contents b
|
||||
|
||||
(* ELO string builder *)
|
||||
let build_elo_string elo = if String.length elo > 0 then "(" ^ elo ^ ")" else ""
|
||||
|
||||
(* Author string builder *)
|
||||
let build_author_string author white black white_elo black_elo =
|
||||
match (author, white, black) with
|
||||
| "", "", "" -> "\\author{}"
|
||||
| "", white, black ->
|
||||
"\\author{" ^ escape_tex white ^ " " ^ build_elo_string white_elo ^ "\\\\"
|
||||
^ escape_tex black ^ " " ^ build_elo_string black_elo ^ "}"
|
||||
| author, "", "" -> "\\author{" ^ escape_tex author ^ "}"
|
||||
| _ -> ""
|
||||
|
||||
(* Title string builder *)
|
||||
let build_title_string event title subtitle =
|
||||
match (event, title, subtitle) with
|
||||
| event, "", "" -> "\\title{" ^ escape_tex event ^ "}"
|
||||
| _event, title, subtitle ->
|
||||
"\\title{" ^ title ^ "}\\\\[2ex]\\large{" ^ subtitle ^ "}"
|
||||
|
||||
(* Date and Site string builder *)
|
||||
let build_date_site_string date site =
|
||||
match (date, site) with
|
||||
| "", "" -> "\\date{}"
|
||||
| "", s -> "\\date{" ^ s ^ "}"
|
||||
| d, "" -> "\\date{" ^ d ^ "}"
|
||||
| d, s -> "\\date{" ^ d ^ ", " ^ s ^ "}"
|
||||
|
||||
(* generate a diagram with or without clock times from the passed in Map (JSON in JS) *)
|
||||
let get_diagram ?(clock = false) ?(white_time = "0:00") ?(black_time = "0:00")
|
||||
ply diagram_data =
|
||||
match MoveMap.find_opt ply diagram_data with
|
||||
| None -> None
|
||||
| Some fen ->
|
||||
if not clock then
|
||||
Some
|
||||
("\n\\par\\nobreak\\medskip\\chessboard[setfen=" ^ fen
|
||||
^ ", vmargin=false]\\par\\medskip\n")
|
||||
else
|
||||
Some
|
||||
("\\par\\medskip\\noindent" ^ "\\begin{minipage}{\\linewidth}"
|
||||
^ black_time ^ "\\par\\nopagebreak\\smallskip\n"
|
||||
^ "\\chessboard[setfen=" ^ fen
|
||||
^ ", vmargin=false]\\par\\nopagebreak\\vspace{1em}\n" ^ white_time
|
||||
^ "\\end{minipage}\\par\\medskip")
|
||||
@@ -1,18 +0,0 @@
|
||||
module MoveMap = Ast.MoveMap
|
||||
open Yojson.Safe.Util
|
||||
|
||||
let parse_diagrams_json diagrams_json_str =
|
||||
try
|
||||
let json = Yojson.Safe.from_string diagrams_json_str in
|
||||
let diagrams_list = to_list json in
|
||||
List.fold_left
|
||||
(fun acc_map item ->
|
||||
let ply = item |> member "ply" |> to_int in
|
||||
let fen = item |> member "fen" |> to_string in
|
||||
MoveMap.add ply fen acc_map)
|
||||
MoveMap.empty diagrams_list
|
||||
with _ -> MoveMap.empty
|
||||
|
||||
let to_tex pgn ~diagram_data ~clock =
|
||||
let game = Parsing.parse_pgn pgn in
|
||||
Latex.game_to_tex game ~diagram_data ~clock
|
||||
@@ -0,0 +1,7 @@
|
||||
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
|
||||
@@ -0,0 +1,40 @@
|
||||
(** 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}. *)
|
||||
|
||||
type diagram_data
|
||||
(** Diagram selection data.
|
||||
|
||||
The representation is intentionally abstract; construct values with
|
||||
{!empty_diagrams} or {!parse_diagrams_json}. *)
|
||||
|
||||
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 either a legacy [ply] number, a [path] array of SAN moves,
|
||||
or both. A matching [path] takes precedence; [ply] is the fallback for
|
||||
mainline positions. 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].
|
||||
|
||||
Raises [Failure "Parse error"] if [pgn] is not a valid PGN game. *)
|
||||
+5
-3
@@ -1,6 +1,6 @@
|
||||
# This file is generated by dune, edit dune-project instead
|
||||
opam-version: "2.0"
|
||||
version: "0.0.1"
|
||||
version: "0.1.0"
|
||||
synopsis: "A chess PGN to TeX conversion tool"
|
||||
description:
|
||||
"Convert PGN files to LaTeX markdown, including rendered images of selected positions"
|
||||
@@ -9,7 +9,7 @@ authors: ["Owen Rees <owenrees.dev@gmail.com>"]
|
||||
license: "AGPL-3.0-or-later"
|
||||
tags: ["pgn" "latex" "chess" "parser"]
|
||||
homepage: "https://github.com/therealowenrees/pgn_to_tex"
|
||||
doc: "https://github.com/TheRealOwenRees/pgn_to_tex/README.md"
|
||||
doc: "https://therealowenrees.github.io/pgn_to_tex/"
|
||||
bug-reports: "https://github.com/therealowenrees/pgn_to_tex/issues"
|
||||
depends: [
|
||||
"dune" {>= "3.21"}
|
||||
@@ -18,7 +18,9 @@ depends: [
|
||||
"menhir" {>= "20260209"}
|
||||
"yojson" {>= "3.0"}
|
||||
"ounit2" {with-test & >= "2.2.7"}
|
||||
"ocamlformat" {with-dev-setup}
|
||||
"js_of_ocaml" {with-test}
|
||||
"js_of_ocaml-ppx" {with-test}
|
||||
"ocamlformat" {with-dev-setup & = "0.29.0"}
|
||||
"odoc" {with-doc}
|
||||
]
|
||||
build: [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(test
|
||||
(name test_suite)
|
||||
(modules (:standard))
|
||||
(libraries ounit2 sedlex sedlex.ppx pgn_to_tex helpers)
|
||||
(libraries ounit2 sedlex sedlex.ppx pgn_to_tex pgn_to_tex_internal helpers)
|
||||
(deps
|
||||
(source_tree pgn_examples)))
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
(library
|
||||
(name helpers)
|
||||
(modules latex_helper))
|
||||
(modules latex_helper text_helper)
|
||||
(libraries pgn_to_tex_internal))
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
module MoveMap = Map.Make (Int)
|
||||
open Pgn_to_tex_internal
|
||||
open Ast
|
||||
|
||||
let diagram_data =
|
||||
{
|
||||
by_ply =
|
||||
MoveMap.empty
|
||||
|> MoveMap.add 5
|
||||
"rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3"
|
||||
@@ -9,4 +12,6 @@ let diagram_data =
|
||||
|> MoveMap.add 10
|
||||
"r1bqkbnr/pp1ppppp/2n5/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 3 5"
|
||||
|> MoveMap.add 15
|
||||
"r1bqkb1r/pp1ppppp/2n5/2p5/4P3/2N2N2/PPPP1PPP/R1BQKB1R b KQkq - 5 7"
|
||||
"r1bqkb1r/pp1ppppp/2n5/2p5/4P3/2N2N2/PPPP1PPP/R1BQKB1R b KQkq - 5 7";
|
||||
by_path = PathMap.empty;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
let contains ~needle haystack =
|
||||
let n = String.length needle and h = String.length haystack in
|
||||
let rec loop i =
|
||||
if i + n > h then false
|
||||
else if String.sub haystack i n = needle then true
|
||||
else loop (i + 1)
|
||||
in
|
||||
n = 0 || loop 0
|
||||
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("node:assert");
|
||||
const path = require("node:path");
|
||||
|
||||
const artifact = path.resolve(
|
||||
__dirname,
|
||||
"../../_build/default/bin/pgn_to_tex_js.bc.js",
|
||||
);
|
||||
|
||||
require(artifact);
|
||||
|
||||
const toTex = globalThis.to_tex;
|
||||
assert.strictEqual(
|
||||
typeof toTex,
|
||||
"function",
|
||||
"the generated artifact should export a global to_tex function",
|
||||
);
|
||||
|
||||
const latex = toTex("1. e4 e5 2. Nf3", "{}", false);
|
||||
|
||||
assert.strictEqual(typeof latex, "string", "to_tex should return a string");
|
||||
assert.ok(
|
||||
latex.includes("\\textbf{1.}"),
|
||||
"rendered LaTeX should contain the first move number",
|
||||
);
|
||||
assert.ok(
|
||||
latex.includes("\\textbf{e4}"),
|
||||
"rendered LaTeX should contain the first move",
|
||||
);
|
||||
assert.ok(
|
||||
latex.includes("\\textbf{Nf3}"),
|
||||
"rendered LaTeX should contain the third move",
|
||||
);
|
||||
|
||||
console.log("js smoke test passed");
|
||||
@@ -0,0 +1,7 @@
|
||||
[Result "*"]
|
||||
[Title "Some Title"]
|
||||
[Subtitle "Some Subtitle"]
|
||||
[Date "2025.12.23"]
|
||||
[Author "Some Author"]
|
||||
|
||||
1. d4 d5 2. c4 dxc4 3. e4 Nf6 4. e5 Nd5 5. Bxc4 Nb6 6. Bb3 e6 (6... Nc6) 7. Nf3 c5 8. Be3 N8d7 9. O-O c4 10. Bc2 Nd5 11. Nc3 N7b6 12. Be4 Bb4 13. Bxd5 Nxd5? (13... Bxc3) 14. Nxd5 exd5 15. Qa4+ Bd7 16. Qxb4 Qb6 17. Qxb6 axb6 18. Rfc1 O-O 19. Nd2 Bf5 20. b3 b5 21. a4 cxb3 22. Nxb3 bxa4 23. Nc5 b5 24. Bd2 Rfe8 25. Bb4 Rac8 26. Nb7 Rxc1+ 27. Rxc1 Rc8 28. Rxc8+ Bxc8 29. Nd6 Bd7 30. f4 g6 31. Kf2 Kg7 32. h3 *
|
||||
@@ -0,0 +1,132 @@
|
||||
open OUnit2
|
||||
|
||||
let contains = Helpers.Text_helper.contains
|
||||
|
||||
let path_only_variation_json =
|
||||
{| [{"fen":"8/8/8/8/8/8/4K3/7k w - - 0 1","path":["e4","e5","Nf3","d6"]}] |}
|
||||
|
||||
let test_path_only_variation_diagram _ctxt =
|
||||
let pgn = "1. e4 e5 2. Nf3 Nc6 (2... d6) 3. Bb5" in
|
||||
let diagrams = Pgn_to_tex.parse_diagrams_json path_only_variation_json in
|
||||
let rendered = Pgn_to_tex.to_tex ~diagram_data:diagrams pgn in
|
||||
assert_bool
|
||||
(Printf.sprintf "path-only variation diagram missing from:\n%s" rendered)
|
||||
(contains ~needle:"setfen=8/8/8/8/8/8/4K3/7k w - - 0 1" rendered);
|
||||
assert_bool "path-only variation diagram should use smallboard"
|
||||
(contains ~needle:"smallboard" rendered)
|
||||
|
||||
let path_only_mainline_json =
|
||||
{| [{"fen":"8/8/8/8/8/8/4K3/7k w - - 0 1","path":["e4","e5"]}] |}
|
||||
|
||||
let test_path_only_mainline_diagram _ctxt =
|
||||
let pgn = "1. e4 e5 2. Nf3" in
|
||||
let diagrams = Pgn_to_tex.parse_diagrams_json path_only_mainline_json in
|
||||
let rendered = Pgn_to_tex.to_tex ~diagram_data:diagrams pgn in
|
||||
assert_bool
|
||||
(Printf.sprintf "path-only mainline diagram missing from:\n%s" rendered)
|
||||
(contains ~needle:"setfen=8/8/8/8/8/8/4K3/7k w - - 0 1" rendered)
|
||||
|
||||
let test_path_takes_precedence_over_ply _ctxt =
|
||||
let pgn = "1. e4 e5 2. Nf3" in
|
||||
let path_fen = "8/8/8/8/8/8/4K3/7k w - - 0 1" in
|
||||
let ply_fen = "7k/8/8/8/8/8/8/4K3 b - - 0 1" in
|
||||
let json =
|
||||
Printf.sprintf {| [{"fen":"%s","path":["e4","e5"]},{"ply":2,"fen":"%s"}] |}
|
||||
path_fen ply_fen
|
||||
in
|
||||
let diagrams = Pgn_to_tex.parse_diagrams_json json in
|
||||
let rendered = Pgn_to_tex.to_tex ~diagram_data:diagrams pgn in
|
||||
assert_bool "path diagram should win over the ply fallback"
|
||||
(contains ~needle:("setfen=" ^ path_fen) rendered);
|
||||
assert_bool "ply diagram should not replace the matching path diagram"
|
||||
(not (contains ~needle:("setfen=" ^ ply_fen) rendered))
|
||||
|
||||
let test_entry_with_path_and_ply _ctxt =
|
||||
let pgn = "1. e4 e5" in
|
||||
let both_fen = "8/8/8/8/8/8/4K3/7k w - - 0 1" in
|
||||
let path_fen = "7k/8/8/8/8/8/8/4K3 b - - 0 1" in
|
||||
let json =
|
||||
Printf.sprintf
|
||||
{| [{"ply":9,"fen":"%s","path":["e4"]},{"fen":"%s","path":["e4","e5"]}] |}
|
||||
both_fen path_fen
|
||||
in
|
||||
let diagrams = Pgn_to_tex.parse_diagrams_json json in
|
||||
let rendered = Pgn_to_tex.to_tex ~diagram_data:diagrams pgn in
|
||||
assert_bool "entry carrying both path and ply should still resolve by path"
|
||||
(contains ~needle:("setfen=" ^ both_fen) rendered);
|
||||
assert_bool "second path-only entry should resolve by path"
|
||||
(contains ~needle:("setfen=" ^ path_fen) rendered)
|
||||
|
||||
let test_ply_only_entry_falls_back _ctxt =
|
||||
let pgn = "1. e4 e5 2. Nf3" in
|
||||
let ply_fen = "7k/8/8/8/8/8/8/4K3 b - - 0 1" in
|
||||
let json = Printf.sprintf {| [{"ply":2,"fen":"%s"}] |} ply_fen in
|
||||
let diagrams = Pgn_to_tex.parse_diagrams_json json in
|
||||
let rendered = Pgn_to_tex.to_tex ~diagram_data:diagrams pgn in
|
||||
assert_bool "legacy ply-only diagram should still resolve by ply"
|
||||
(contains ~needle:("setfen=" ^ ply_fen) rendered)
|
||||
|
||||
let test_malformed_json_yields_empty_diagrams _ctxt =
|
||||
let pgn = "1. e4 e5" in
|
||||
let expected = Pgn_to_tex.to_tex pgn in
|
||||
let malformed =
|
||||
[
|
||||
"not json at all";
|
||||
{| {"ply":1} |};
|
||||
{| [{"path":["e4"]}] |};
|
||||
{| [{"fen":"8/8/8/8/8/8/4K3/7k w - - 0 1","ply":"not-a-number"}] |};
|
||||
]
|
||||
in
|
||||
List.iter
|
||||
(fun json ->
|
||||
let actual =
|
||||
Pgn_to_tex.to_tex
|
||||
~diagram_data:(Pgn_to_tex.parse_diagrams_json json)
|
||||
pgn
|
||||
in
|
||||
assert_equal
|
||||
~printer:(fun x -> x)
|
||||
~msg:("malformed JSON: " ^ json)
|
||||
expected actual)
|
||||
malformed
|
||||
|
||||
let test_mixed_valid_and_invalid_entries_yield_empty _ctxt =
|
||||
let pgn = "1. e4 e5 2. Nf3" in
|
||||
let expected = Pgn_to_tex.to_tex pgn in
|
||||
let valid = {|{"ply":2,"fen":"8/8/8/8/8/8/4K3/7k w - - 0 1"}|} in
|
||||
let invalid_entries =
|
||||
[
|
||||
{|{"ply":3}|};
|
||||
{|{"ply":"not-a-number","fen":"8/8/8/8/8/8/4K3/7k w - - 0 1"}|};
|
||||
{|{"fen":"8/8/8/8/8/8/4K3/7k w - - 0 1","path":[1,2]}|};
|
||||
{|{"fen":42}|};
|
||||
]
|
||||
in
|
||||
List.iter
|
||||
(fun invalid ->
|
||||
let json = Printf.sprintf "[%s,%s]" valid invalid in
|
||||
let actual =
|
||||
Pgn_to_tex.to_tex
|
||||
~diagram_data:(Pgn_to_tex.parse_diagrams_json json)
|
||||
pgn
|
||||
in
|
||||
assert_equal
|
||||
~printer:(fun x -> x)
|
||||
~msg:("mixed valid/invalid JSON: " ^ json)
|
||||
expected actual)
|
||||
invalid_entries
|
||||
|
||||
let suite =
|
||||
"diagram resolution tests"
|
||||
>::: [
|
||||
"path_only_variation_diagram" >:: test_path_only_variation_diagram;
|
||||
"path_only_mainline_diagram" >:: test_path_only_mainline_diagram;
|
||||
"path_takes_precedence_over_ply"
|
||||
>:: test_path_takes_precedence_over_ply;
|
||||
"entry_with_path_and_ply" >:: test_entry_with_path_and_ply;
|
||||
"ply_only_entry_falls_back" >:: test_ply_only_entry_falls_back;
|
||||
"malformed_json_yields_empty_diagrams"
|
||||
>:: test_malformed_json_yields_empty_diagrams;
|
||||
"mixed_valid_and_invalid_entries_yield_empty"
|
||||
>:: test_mixed_valid_and_invalid_entries_yield_empty;
|
||||
]
|
||||
+25
-8
@@ -1,5 +1,5 @@
|
||||
open OUnit2
|
||||
open Pgn_logic
|
||||
open Pgn_to_tex_internal
|
||||
open Ast
|
||||
open Helpers
|
||||
|
||||
@@ -105,15 +105,28 @@ let test_date_site =
|
||||
ae "\\date{}" (Latex_helpers.build_date_site_string "" "") );
|
||||
]
|
||||
|
||||
let test_escape_tex _ctxt =
|
||||
ae "\\#\\%\\{\\}\\_\\&" (Latex_helpers.escape_tex "#%{}_&");
|
||||
ae "plain text" (Latex_helpers.escape_tex "plain text")
|
||||
|
||||
let test_title =
|
||||
[
|
||||
( "Event only" >:: fun _ ->
|
||||
ae "\\title{some event}"
|
||||
(Latex_helpers.build_title_string "some event" "" "") );
|
||||
( "Title and subtitle" >:: fun _ ->
|
||||
ae "\\title{Some title}\\\\[2ex]\\large{Some subtitle}"
|
||||
ae "\\title{Some title\\\\[2ex]\\large{Some subtitle}}"
|
||||
(Latex_helpers.build_title_string "irrelevant" "Some title"
|
||||
"Some subtitle") );
|
||||
( "Title without subtitle" >:: fun _ ->
|
||||
ae "\\title{Some title}"
|
||||
(Latex_helpers.build_title_string "irrelevant" "Some title" "") );
|
||||
( "Subtitle without title" >:: fun _ ->
|
||||
ae "\\title{Some subtitle}"
|
||||
(Latex_helpers.build_title_string "irrelevant" "" "Some subtitle") );
|
||||
( "Title is not escaped" >:: fun _ ->
|
||||
ae "\\title{100% & more}"
|
||||
(Latex_helpers.build_title_string "" "100% & more" "") );
|
||||
]
|
||||
|
||||
let test_author =
|
||||
@@ -121,12 +134,15 @@ let test_author =
|
||||
( "Author only" >:: fun _ ->
|
||||
ae "\\author{Some author}"
|
||||
(Latex_helpers.build_author_string "Some author" "" "" "" "") );
|
||||
( "Author wins over players" >:: fun _ ->
|
||||
ae "\\author{Carol}"
|
||||
(Latex_helpers.build_author_string "Carol" "Alice" "Bob" "1" "2") );
|
||||
( "Nothing" >:: fun _ ->
|
||||
ae "\\author{}" (Latex_helpers.build_author_string "" "" "" "" "") );
|
||||
]
|
||||
|
||||
let test_diagram _ctxt =
|
||||
match Latex_helpers.get_diagram 5 Helpers.Latex_helper.diagram_data with
|
||||
match Latex_helpers.get_diagram ~ply:5 Helpers.Latex_helper.diagram_data with
|
||||
| Some actual ->
|
||||
let expected =
|
||||
"\n\\par\\nobreak\\medskip\\chessboard[setfen="
|
||||
@@ -138,8 +154,8 @@ let test_diagram _ctxt =
|
||||
|
||||
let test_diagram_clock _ctxt =
|
||||
match
|
||||
Latex_helpers.get_diagram 5 Helpers.Latex_helper.diagram_data ~clock:true
|
||||
~white_time:"1:00" ~black_time:"0:21"
|
||||
Latex_helpers.get_diagram ~ply:5 Helpers.Latex_helper.diagram_data
|
||||
~clock:true ~white_time:"1:00" ~black_time:"0:21"
|
||||
with
|
||||
| Some actual ->
|
||||
let expected =
|
||||
@@ -151,7 +167,9 @@ let test_diagram_clock _ctxt =
|
||||
| None -> assert_failure "Diagram for ply 5 was not found"
|
||||
|
||||
let test_no_diagram _ctxt =
|
||||
let result = Latex_helpers.get_diagram 99 Helpers.Latex_helper.diagram_data in
|
||||
let result =
|
||||
Latex_helpers.get_diagram ~ply:99 Helpers.Latex_helper.diagram_data
|
||||
in
|
||||
|
||||
match result with
|
||||
| None -> ()
|
||||
@@ -172,11 +190,10 @@ let suite =
|
||||
"diagram_placement" >:: test_diagram_placement;
|
||||
"elo tests" >::: test_player_elo;
|
||||
"date & site tests" >::: test_date_site;
|
||||
"escape tex" >:: test_escape_tex;
|
||||
"title tests" >::: test_title;
|
||||
"author tests" >::: test_author;
|
||||
"diagram_test" >:: test_diagram;
|
||||
"diagram_clock" >:: test_diagram_clock;
|
||||
"no_diagram" >:: test_no_diagram;
|
||||
]
|
||||
|
||||
let () = run_test_tt_main suite
|
||||
|
||||
+25
-3
@@ -1,5 +1,5 @@
|
||||
open OUnit2
|
||||
open Pgn_logic
|
||||
open Pgn_to_tex_internal
|
||||
open Parser
|
||||
|
||||
let lex_all ?(is_header = false) s =
|
||||
@@ -170,9 +170,33 @@ let test_clock_in_comment _ctxt =
|
||||
in
|
||||
assert_tokens ~ctxt:_ctxt ~input ~is_header:false ~expected
|
||||
|
||||
let test_header_unterminated_string_raises _ctxt =
|
||||
let input = {|Event "oops|} in
|
||||
let lexbuf = Sedlexing.Utf8.from_string input in
|
||||
ignore (Lexer.tokenize_header lexbuf);
|
||||
let exn_opt =
|
||||
try
|
||||
ignore (Lexer.tokenize_header lexbuf);
|
||||
None
|
||||
with exn -> Some exn
|
||||
in
|
||||
assert_bool "Expected exception on unterminated header string"
|
||||
(Option.is_some exn_opt)
|
||||
|
||||
let test_unknown_characters_are_skipped _ctxt =
|
||||
let input = "1. e4 ?! e5 @ 2. Nf3" in
|
||||
let expected =
|
||||
[ NUMBER "1."; MOVE "e4"; MOVE "e5"; NUMBER "2."; MOVE "Nf3"; EOF ]
|
||||
in
|
||||
assert_tokens ~ctxt:_ctxt ~input ~is_header:false ~expected
|
||||
|
||||
let suite =
|
||||
"lexer tests"
|
||||
>::: [
|
||||
"header_unterminated_string_raises"
|
||||
>:: test_header_unterminated_string_raises;
|
||||
"unknown_characters_are_skipped"
|
||||
>:: test_unknown_characters_are_skipped;
|
||||
"header_simple" >:: test_header_simple;
|
||||
"header_escaped_string" >:: test_header_escaped_string;
|
||||
"numbers_and_moves" >:: test_numbers_and_moves;
|
||||
@@ -187,5 +211,3 @@ let suite =
|
||||
"clock_inline" >:: test_clock_inline;
|
||||
"clock_in_comment" >:: test_clock_in_comment;
|
||||
]
|
||||
|
||||
let () = run_test_tt_main suite
|
||||
|
||||
+4
-1
@@ -1,5 +1,5 @@
|
||||
open OUnit2
|
||||
open Pgn_logic
|
||||
open Pgn_to_tex_internal
|
||||
open Ast
|
||||
open Nag
|
||||
|
||||
@@ -19,12 +19,15 @@ let test_direct_nags =
|
||||
("$15" >:: fun _ -> ae "\\bbetter" (nag_to_tex "$15"));
|
||||
("$16" >:: fun _ -> ae "\\ensuremath{\\pm}" (nag_to_tex "$16"));
|
||||
("$17" >:: fun _ -> ae "\\ensuremath{\\mp}" (nag_to_tex "$17"));
|
||||
("$18" >:: fun _ -> ae "+-" (nag_to_tex "$18"));
|
||||
("$19" >:: fun _ -> ae "-+" (nag_to_tex "$19"));
|
||||
("$22" >:: fun _ -> ae "\\zugzwang" (nag_to_tex "$22"));
|
||||
("$32" >:: fun _ -> ae "\\development" (nag_to_tex "$32"));
|
||||
("$36" >:: fun _ -> ae "\\initiative" (nag_to_tex "$36"));
|
||||
("$40" >:: fun _ -> ae "\\attack" (nag_to_tex "$40"));
|
||||
("$44" >:: fun _ -> ae "\\compensation" (nag_to_tex "$44"));
|
||||
("$132" >:: fun _ -> ae "\\counterplay" (nag_to_tex "$132"));
|
||||
("unknown fallback" >:: fun _ -> ae "" (nag_to_tex "$999"));
|
||||
]
|
||||
|
||||
let suite = "nag test" >::: [ "direct nags" >::: test_direct_nags ]
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
open OUnit2
|
||||
open Pgn_to_tex_internal
|
||||
open Ast
|
||||
|
||||
let ae expected actual = assert_equal expected actual
|
||||
|
||||
let test_empty_input _ctxt =
|
||||
ae { tags = []; content = []; result = None } (Parsing.parse_pgn "")
|
||||
|
||||
let test_result_only_game _ctxt =
|
||||
ae
|
||||
{ tags = []; content = [ Result "1-0" ]; result = None }
|
||||
(Parsing.parse_pgn "1-0")
|
||||
|
||||
let test_nested_variations _ctxt =
|
||||
let pgn = "1. e4 (1. d4 (1... d5) 1... e5) 1... c5" in
|
||||
let expected =
|
||||
{
|
||||
tags = [];
|
||||
content =
|
||||
[
|
||||
Number "1.";
|
||||
Move "e4";
|
||||
Variation
|
||||
[
|
||||
Number "1.";
|
||||
Move "d4";
|
||||
Variation [ Number "1..."; Move "d5" ];
|
||||
Number "1...";
|
||||
Move "e5";
|
||||
];
|
||||
Number "1...";
|
||||
Move "c5";
|
||||
];
|
||||
result = None;
|
||||
}
|
||||
in
|
||||
ae expected (Parsing.parse_pgn pgn)
|
||||
|
||||
let test_malformed_input_raises _ctxt =
|
||||
assert_raises (Failure "Parse error") (fun () ->
|
||||
ignore (Parsing.parse_pgn "1. e4 e5 (2. Nf3"))
|
||||
|
||||
let suite =
|
||||
"parser tests"
|
||||
>::: [
|
||||
"empty_input" >:: test_empty_input;
|
||||
"result_only_game" >:: test_result_only_game;
|
||||
"nested_variations" >:: test_nested_variations;
|
||||
"malformed_input_raises" >:: test_malformed_input_raises;
|
||||
]
|
||||
@@ -1,143 +0,0 @@
|
||||
open OUnit2
|
||||
open Pgn_logic
|
||||
open Ast
|
||||
module MoveMap = Pgn2tex.MoveMap
|
||||
|
||||
let ae expected actual = assert_equal ~printer:(fun x -> x) expected actual
|
||||
|
||||
let diagram_json_str =
|
||||
{| [{"ply":1,"fen":"rnbqkbnr/pppppppp/8/8/3P4/8/PPP1PPPP/RNBQKBNR b KQkq - 0 1"},{"ply":2,"fen":"rnbqkbnr/ppp1pppp/8/3p4/3P4/8/PPP1PPPP/RNBQKBNR w KQkq - 0 2"}] |}
|
||||
|
||||
let diagram_data =
|
||||
MoveMap.empty
|
||||
|> MoveMap.add 5
|
||||
"rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3"
|
||||
|> MoveMap.add 6
|
||||
"rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 3"
|
||||
|> MoveMap.add 10
|
||||
"r1bqkbnr/pp1ppppp/2n5/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 3 5"
|
||||
|> MoveMap.add 15
|
||||
"r1bqkb1r/pp1ppppp/2n5/2p5/4P3/2N2N2/PPPP1PPP/R1BQKB1R b KQkq - 5 7"
|
||||
|
||||
let test_json_str_to_map _ctxt =
|
||||
let result = Pgn2tex.parse_diagrams_json diagram_json_str in
|
||||
let actual_bindings = MoveMap.bindings result in
|
||||
|
||||
let expected_bindings =
|
||||
[
|
||||
(1, "rnbqkbnr/pppppppp/8/8/3P4/8/PPP1PPPP/RNBQKBNR b KQkq - 0 1");
|
||||
(2, "rnbqkbnr/ppp1pppp/8/3p4/3P4/8/PPP1PPPP/RNBQKBNR w KQkq - 0 2");
|
||||
]
|
||||
in
|
||||
|
||||
let string_of_bindings pairs =
|
||||
let string_of_pair (ply, fen) = Printf.sprintf "(%d, %S)" ply fen in
|
||||
"[" ^ String.concat "; " (List.map string_of_pair pairs) ^ "]"
|
||||
in
|
||||
|
||||
assert_equal expected_bindings actual_bindings ~printer:string_of_bindings
|
||||
|
||||
let test_basic_pgn_to_tex _ctxt =
|
||||
let filename = "pgn_examples/1.pgn" in
|
||||
let ic = In_channel.open_text filename in
|
||||
let input_string = In_channel.input_all ic in
|
||||
let actual = Pgn2tex.to_tex input_string ~diagram_data ~clock:false in
|
||||
let expected =
|
||||
{|\title{URS-chJ}
|
||||
\author{Ibragimov, Ildar (2455)\\Kramnik, Vladimir (2480)}
|
||||
\date{1991.??.??, Kherson}\maketitle
|
||||
\newchessgame
|
||||
\textbf{1.} \textbf{d4} \newline A88: Dutch Defence: Leningrad System: 5 Nf3 0-0 6 0-0 d6 7 Nc3 c6\par \textbf{\ldots{}d6} \textbf{2.} \textbf{c4} \textbf{f5} \textbf{3.} \textbf{Nf3}
|
||||
\par\nobreak\medskip\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip
|
||||
\textbf{\ldots{}}\textbf{Nf6}
|
||||
\par\nobreak\medskip\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 3, vmargin=false]\par\medskip
|
||||
\textbf{4.} \textbf{g3} \textbf{g6} \textbf{5.} \textbf{Bg2} \textbf{Bg7}
|
||||
\par\nobreak\medskip\chessboard[setfen=r1bqkbnr/pp1ppppp/2n5/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 3 5, vmargin=false]\par\medskip
|
||||
\textbf{6.} \textbf{O-O} \textbf{O-O} \textbf{7.} \textbf{Nc3} \textbf{Qe8} \textbf{8.} \textbf{b3}
|
||||
\par\nobreak\medskip\chessboard[setfen=r1bqkb1r/pp1ppppp/2n5/2p5/4P3/2N2N2/PPPP1PPP/R1BQKB1R b KQkq - 5 7, vmargin=false]\par\medskip
|
||||
\textbf{\ldots{}}\textbf{Na6} \textbf{9.} \textbf{Ba3} \textbf{c6} \textbf{10.} \textbf{Qd3} \textbf{Rb8} \textbf{11.} \textbf{e4} \textbf{fxe4} \textbf{12.} \textbf{Nxe4} \textbf{Bf5} \textbf{13.} \textbf{Nxf6+} \textbf{Bxf6} \textbf{14.} \textbf{Qd2} \textbf{Nc7} \textbf{15.} \textbf{Rae1} \textbf{Qd7} \textbf{16.} \textbf{h4} \textbf{b5} \textbf{17.} \textbf{Re3} \textbf{bxc4} \textbf{18.} \textbf{bxc4} \textbf{Bh3} \textbf{19.} \textbf{Rfe1} \textbf{Bxg2} \newline last book move\par \textbf{20.} \textbf{Kxg2} \textbf{Qf5} \textbf{21.} \textbf{Re4} \textbf{Rbe8} \textbf{22.} \textbf{Rf4} \textbf{Qc8} \textbf{23.} \textbf{Qa5} \textbf{d5} \textbf{24.} \textbf{cxd5} \textbf{Nxd5} \textbf{25.} \textbf{Rfe4} \newline e7 seems the pivot of the position\par \textbf{\ldots{}Qf5} \textbf{26.} \textbf{Qd2} ( 26. Qxa7 ??{} taking the pawn is naive Qxf3+ Annihilates a defender: f3 27. Kxf3 Bxd4+ 28. Kg4 Bxa7 29. Bxe7 Rxf2 -+{} ( 29... Rxe7 30. Rxe7 Bxf2 31. a4 -+{} ) ( 29... Nxe7 ?!{} 30. Rxe7 Rxe7 31. Rxe7 Bxf2 32. a4 -+{} ) ) \textbf{Bg7} \textbf{27.} \textbf{Nh2} \textbf{Rf7} \textbf{28.} \textbf{Bc5} \newline The white bishop on an outpost\par \textbf{\ldots{}Qd7} \textbf{29.} \textbf{a4} \textbf{Nf6} \textbf{30.} \textbf{Re5} \textbf{Nd5} \textbf{31.} \textbf{R5e4} ( 31. R5e2 Rb8 \wbetter{} ) \textbf{Nf6} {} \textbf{32.} \textbf{Re5} \textbf{Kh8} ( 32... Nd5 33. R5e2 \wbetter{} ) \textbf{33.} \textbf{Kg1} \textbf{Nd5} \newline A valuable piece\par \textbf{34.} \textbf{R5e2} \textbf{a6} \textbf{35.} \textbf{Qd3} \textbf{Qh3} ( 35... Ra8 \wbetter{} ) \textbf{36.} \textbf{Nf3} ( 36. Qxa6 Ref8 37. Qa5 \wbetter{} ( 37. Qxc6 Rxf2 38. Rxf2 Qxg3+ 39. Kh1 Rxf2 ( 39... Qxf2 ?!{} 40. Rf1 Qa2 41. Rxf8+ Bxf8 42. Kg1 {} ) 40. Qa8+ Bf8 41. Qxf8+ Rxf8 42. Re2 Rf2 43. Rxf2 Qxf2 44. Ng4 Qf1+ 45. Kh2 Nf4 46. Ne3 Qf2+ 47. Kh1 Qxh4+ 48. Kg1 Qg3+ 49. Kf1 Qxe3 50. Bb6 Qe2+ 51. Kg1 Qg2\# ) ( 37. Bxe7 ??{} White will choke on that pawn Rxf2 ( 37... Nxe7 ?!{} 38. Rd1 -+{} ) 38. Rxf2 Qxg3+ 39. Kh1 Rxf2 ( 39... Qxf2 40. Re2 Qxd4 41. Bxf8 Qd1+ 42. Kg2 Nf4+ 43. Kf3 {} ) 40. Qc8+ Bf8 41. Bf6+ Nxf6 42. Qxf8+ Ng8 43. Qxf2 Qxf2 -+{} ) ) \textbf{Nf4} \bbetter{} \newline Do you see the mate threat?\par \textbf{37.} \textbf{gxf4} \textbf{Rxf4} \newline The mate threat is Rg4\par \textbf{38.} \textbf{Ne5} ( 38. Re4 !?{} is worthy of consideration Qg4+ 39. Kf1 Rxf3 40. Rxg4 Rxd3 41. Re6 \bbetter{} ) \textbf{Rg4+} !{} \ensuremath{\mp}{} \newline keeping the advantage\par \textbf{39.} \textbf{Nxg4} \newline Theme: Deflection from d3\par \textbf{\ldots{}Qxd3} \textbf{40.} \textbf{Re4} \textbf{Qf3} \textbf{41.} \textbf{Nh2} \textbf{Qf5} \textbf{42.} \textbf{Bxe7} ( 42. Kg2 Rf8 43. f3 Bf6 -+{} ) \textbf{Kg8} \textbf{43.} \textbf{f3} ( 43. R1e3 Qd5 -+{} ) \textbf{Qh3} -+{} \textbf{44.} \textbf{R1e2} ( 44. Kh1 -+{} ) \textbf{Qg3+} \textbf{45.} \textbf{Rg2} \textbf{Bxd4+} !{} \newline a devastating blow\par \textbf{46.} \textbf{Kh1} ( 46. Rxd4 A deflection Qe1+ Theme: Double Attack ) \textbf{Qh3} \textbf{47.} \textbf{Rgg4} ( 47. a5 Bc3 -+{} ) \textbf{c5} \textbf{48.} \textbf{h5} ( 48. Re1 does not improve anything Bf6 49. Rge4 Bxe7 50. Rxe7 Rxe7 51. Rxe7 Qxh4 -+{} ) \textbf{Rb8} \textbf{49.} \textbf{Re1} \textbf{Be5} \textbf{50.} \textbf{Rh4} \textbf{Qf5} \textbf{51.} \textbf{hxg6} \textbf{hxg6} \textbf{52.} \textbf{Re2} ( 52. Bxc5 doesn't change the outcome of the game Bg3 53. Rb4 Rc8 -+{} ( 53... Bxe1 ?!{} is clearly worse 54. Rxb8+ Kh7 55. Rb7+ Kh8 56. Rb8+ Kg7 57. Rb7+ Kf6 58. Ng4+ Kg5 59. Be3+ Kh4 60. Kg2 Qc2+ 61. Nf2 \bbetter{} ) ( 53... Qxc5 ?!{} is much worse 54. Rxb8+ Bxb8 55. Re8+ Kf7 56. Rxb8 -+{} ) ) \textbf{Rb1+} ( 52... Qb1+ !?{} keeps an even firmer grip 53. Kg2 Rb2 54. Rxb2 Qxb2+ 55. Kg1 -+{} ) \textbf{53.} \textbf{Kg2} \textbf{Bd4} \textbf{54.} \textbf{Ng4} ( 54. Rxd4 no good, but what else? cxd4 55. Ng4 -+{} ) \textbf{Rg1+} \textbf{55.} \textbf{Kh2} ( 55. Kh3 doesn't do any good Qxf3+ 56. Kh2 Rh1\# ) \textbf{Qf4+} ( 55... Qf4+ 56. Kh3 Qg3\# ) \textbf{0-1}|}
|
||||
in
|
||||
ae expected actual;
|
||||
close_in ic
|
||||
|
||||
let test_pgn_with_clock_to_tex _ctxt =
|
||||
let filename = "pgn_examples/2.pgn" in
|
||||
let ic = In_channel.open_text filename in
|
||||
let input_string = In_channel.input_all ic in
|
||||
let actual = Pgn2tex.to_tex input_string ~diagram_data ~clock:true in
|
||||
let expected =
|
||||
{|\title{Casual Rapid game}
|
||||
\author{montillo2015 (1919)\\reassessyourchess (1869)}
|
||||
\date{2023.12.03, https://lichess.org/9Z0taHcG}\maketitle
|
||||
\newchessgame
|
||||
\textbf{1.} \textbf{d4} \textbf{1...} \textbf{Nf6} \textbf{2.} \textbf{Nf3} \textbf{2...} \textbf{d5} \textbf{3.} \textbf{e3}\par\medskip\noindent\begin{minipage}{\linewidth}0:10:01\par\nopagebreak\smallskip
|
||||
\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\nopagebreak\vspace{1em}
|
||||
0:10:00\end{minipage}\par\medskip \textbf{3...} \textbf{e6}\par\medskip\noindent\begin{minipage}{\linewidth}0:10:01\par\nopagebreak\smallskip
|
||||
\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 3, vmargin=false]\par\nopagebreak\vspace{1em}
|
||||
0:10:01\end{minipage}\par\medskip \newline D05 Queen's Pawn Game: Colle System\par \textbf{4.} \textbf{a3} \textbf{4...} \textbf{c5} \textbf{5.} \textbf{c4} \textbf{5...} \textbf{Nc6}\par\medskip\noindent\begin{minipage}{\linewidth}0:10:02\par\nopagebreak\smallskip
|
||||
\chessboard[setfen=r1bqkbnr/pp1ppppp/2n5/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 3 5, vmargin=false]\par\nopagebreak\vspace{1em}
|
||||
0:10:02\end{minipage}\par\medskip \textbf{6.} \textbf{dxc5} \textbf{6...} \textbf{Bxc5} \textbf{7.} \textbf{b4} \textbf{7...} \textbf{Be7} \textbf{8.} \textbf{Bb2}\par\medskip\noindent\begin{minipage}{\linewidth}0:10:00\par\nopagebreak\smallskip
|
||||
\chessboard[setfen=r1bqkb1r/pp1ppppp/2n5/2p5/4P3/2N2N2/PPPP1PPP/R1BQKB1R b KQkq - 5 7, vmargin=false]\par\nopagebreak\vspace{1em}
|
||||
0:10:03\end{minipage}\par\medskip \textbf{8...} \textbf{dxc4} \textbf{9.} \textbf{Qxd8+} \textbf{9...} \textbf{Nxd8} \textbf{10.} \textbf{Bxc4} \textbf{10...} \textbf{O-O} \textbf{11.} \textbf{O-O} \textbf{11...} \textbf{a6} \textbf{12.} \textbf{Nc3} \textbf{12...} \textbf{b5} \textbf{13.} \textbf{Be2} \textbf{13...} \textbf{Bb7} \textbf{14.} \textbf{Nd4} \textbf{14...} \textbf{Ne4} \textbf{15.} \textbf{Nxe4} \textbf{15...} \textbf{Bxe4} \textbf{16.} \textbf{Bf3} \textbf{16...} \textbf{Bxf3} \textbf{17.} \textbf{Nxf3} \textbf{17...} \textbf{Nc6} \textbf{18.} \textbf{Rac1} \textbf{18...} \textbf{Rac8} \textbf{19.} \textbf{Rfd1} \textbf{19...} \textbf{Rfd8} \textbf{20.} \textbf{Rxd8+} \textbf{20...} \textbf{Rxd8} \textbf{21.} \textbf{g3} \textbf{21...} \textbf{Nb8} \textbf{22.} \textbf{Rc7} \textbf{22...} \textbf{Bd6} \textbf{23.} \textbf{Rc2} \textbf{23...} \textbf{f6} \textbf{24.} \textbf{Kg2} \textbf{24...} \textbf{e5} \textbf{25.} \textbf{h4} \textbf{25...} \textbf{e4} \textbf{26.} \textbf{Nd4} \textbf{26...} \textbf{Kf7} \textbf{27.} \textbf{Nf5} \textbf{27...} \textbf{Nd7} \textbf{28.} \textbf{Nxd6+} \newline Black resigns.\par \textbf{1-0}|}
|
||||
in
|
||||
ae expected actual;
|
||||
close_in ic
|
||||
|
||||
let test_pgn_with_unsupported_text _ctxt =
|
||||
let filename = "pgn_examples/4.pgn" in
|
||||
let ic = In_channel.open_text filename in
|
||||
let input_string = In_channel.input_all ic in
|
||||
let actual = Pgn2tex.to_tex input_string ~diagram_data ~clock:true in
|
||||
let expected =
|
||||
{|\title{Casual Rapid game}
|
||||
\author{montillo2015 (1919) vs. reassessyourchess (1869)}
|
||||
\date{2023.12.03, https://lichess.org/9Z0taHcG}\maketitle
|
||||
\newchessgame
|
||||
\textbf{1.} \textbf{d4} \textbf{1...} \textbf{Nf6} \textbf{2.} \textbf{Nf3} \textbf{2...} \textbf{d5} \textbf{3.} \textbf{e3}\par\nobreak 0:10:01\par\nobreak\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip\nobreak\ 0:10:00\par \textbf{3...} \textbf{e6}\par\nobreak 0:10:01\par\nobreak\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip\nobreak\ 0:10:01\par \newline D05 Queen's Pawn Game: Colle System\par \textbf{4.} \textbf{a3} \textbf{4...} \textbf{c5} \textbf{5.} \textbf{c4} \textbf{5...} \textbf{Nc6}\par\nobreak 0:10:02\par\nobreak\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip\nobreak\ 0:10:02\par \textbf{6.} \textbf{dxc5} \textbf{6...} \textbf{Bxc5} \textbf{7.} \textbf{b4} \textbf{7...} \textbf{Be7} \textbf{8.} \textbf{Bb2}\par\nobreak 0:10:00\par\nobreak\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip\nobreak\ 0:10:03\par \textbf{8...} \textbf{dxc4} \textbf{9.} \textbf{Qxd8+} \textbf{9...} \textbf{Nxd8} \textbf{10.} \textbf{Bxc4} \textbf{10...} \textbf{O-O} \textbf{11.} \textbf{O-O} \textbf{11...} \textbf{a6} \textbf{12.} \textbf{Nc3} \textbf{12...} \textbf{b5} \textbf{13.} \textbf{Be2} \textbf{13...} \textbf{Bb7} \textbf{14.} \textbf{Nd4} \textbf{14...} \textbf{Ne4} \textbf{15.} \textbf{Nxe4} \textbf{15...} \textbf{Bxe4} \textbf{16.} \textbf{Bf3} \textbf{16...} \textbf{Bxf3} \textbf{17.} \textbf{Nxf3} \textbf{17...} \textbf{Nc6} \textbf{18.} \textbf{Rac1} \textbf{18...} \textbf{Rac8} \textbf{19.} \textbf{Rfd1} \textbf{19...} \textbf{Rfd8} \textbf{20.} \textbf{Rxd8+} \textbf{20...} \textbf{Rxd8} \textbf{21.} \textbf{g3} \textbf{21...} \textbf{Nb8} \textbf{22.} \textbf{Rc7} \textbf{22...} \textbf{Bd6} \textbf{23.} \textbf{Rc2} \textbf{23...} \textbf{f6} \textbf{24.} \textbf{Kg2} \textbf{24...} \textbf{e5} \textbf{25.} \textbf{h4} \textbf{25...} \textbf{e4} \textbf{26.} \textbf{Nd4} \textbf{26...} \textbf{Kf7} \textbf{27.} \textbf{Nf5} \textbf{27...} \textbf{Nd7} \textbf{28.} \textbf{Nxd6+} \newline Black resigns.\par \textbf{1-0}|}
|
||||
in
|
||||
ae expected actual;
|
||||
close_in ic
|
||||
|
||||
let test_pgn_with_custom_headers _ctxt =
|
||||
let filename = "pgn_examples/7.pgn" in
|
||||
let ic = In_channel.open_text filename in
|
||||
let input_string = In_channel.input_all ic in
|
||||
let actual = Pgn2tex.to_tex input_string ~diagram_data ~clock:false in
|
||||
let expected =
|
||||
{|\title{Casual Rapid game}
|
||||
\author{montillo2015 (1919) vs. reassessyourchess (1869)}
|
||||
\date{2023.12.03, https://lichess.org/9Z0taHcG}\maketitle
|
||||
\newchessgame
|
||||
\textbf{1.} \textbf{d4} \textbf{1...} \textbf{Nf6} \textbf{2.} \textbf{Nf3} \textbf{2...} \textbf{d5} \textbf{3.} \textbf{e3}\par\nobreak 0:10:01\par\nobreak\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip\nobreak\ 0:10:00\par \textbf{3...} \textbf{e6}\par\nobreak 0:10:01\par\nobreak\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip\nobreak\ 0:10:01\par \newline D05 Queen's Pawn Game: Colle System\par \textbf{4.} \textbf{a3} \textbf{4...} \textbf{c5} \textbf{5.} \textbf{c4} \textbf{5...} \textbf{Nc6}\par\nobreak 0:10:02\par\nobreak\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip\nobreak\ 0:10:02\par \textbf{6.} \textbf{dxc5} \textbf{6...} \textbf{Bxc5} \textbf{7.} \textbf{b4} \textbf{7...} \textbf{Be7} \textbf{8.} \textbf{Bb2}\par\nobreak 0:10:00\par\nobreak\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip\nobreak\ 0:10:03\par \textbf{8...} \textbf{dxc4} \textbf{9.} \textbf{Qxd8+} \textbf{9...} \textbf{Nxd8} \textbf{10.} \textbf{Bxc4} \textbf{10...} \textbf{O-O} \textbf{11.} \textbf{O-O} \textbf{11...} \textbf{a6} \textbf{12.} \textbf{Nc3} \textbf{12...} \textbf{b5} \textbf{13.} \textbf{Be2} \textbf{13...} \textbf{Bb7} \textbf{14.} \textbf{Nd4} \textbf{14...} \textbf{Ne4} \textbf{15.} \textbf{Nxe4} \textbf{15...} \textbf{Bxe4} \textbf{16.} \textbf{Bf3} \textbf{16...} \textbf{Bxf3} \textbf{17.} \textbf{Nxf3} \textbf{17...} \textbf{Nc6} \textbf{18.} \textbf{Rac1} \textbf{18...} \textbf{Rac8} \textbf{19.} \textbf{Rfd1} \textbf{19...} \textbf{Rfd8} \textbf{20.} \textbf{Rxd8+} \textbf{20...} \textbf{Rxd8} \textbf{21.} \textbf{g3} \textbf{21...} \textbf{Nb8} \textbf{22.} \textbf{Rc7} \textbf{22...} \textbf{Bd6} \textbf{23.} \textbf{Rc2} \textbf{23...} \textbf{f6} \textbf{24.} \textbf{Kg2} \textbf{24...} \textbf{e5} \textbf{25.} \textbf{h4} \textbf{25...} \textbf{e4} \textbf{26.} \textbf{Nd4} \textbf{26...} \textbf{Kf7} \textbf{27.} \textbf{Nf5} \textbf{27...} \textbf{Nd7} \textbf{28.} \textbf{Nxd6+} \newline Black resigns.\par \textbf{1-0}|}
|
||||
in
|
||||
ae expected actual;
|
||||
close_in ic
|
||||
|
||||
let test_pgn_with_different_unsupported_text _ctxt =
|
||||
let filename = "pgn_examples/10.pgn" in
|
||||
let ic = In_channel.open_text filename in
|
||||
let input_string = In_channel.input_all ic in
|
||||
let actual = Pgn2tex.to_tex input_string ~diagram_data ~clock:false in
|
||||
let expected =
|
||||
{|\title{Casual Rapid game}
|
||||
\author{montillo2015 (1919) vs. reassessyourchess (1869)}
|
||||
\date{2023.12.03, https://lichess.org/9Z0taHcG}\maketitle
|
||||
\newchessgame
|
||||
\textbf{1.} \textbf{d4} \textbf{1...} \textbf{Nf6} \textbf{2.} \textbf{Nf3} \textbf{2...} \textbf{d5} \textbf{3.} \textbf{e3}\par\nobreak 0:10:01\par\nobreak\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip\nobreak\ 0:10:00\par \textbf{3...} \textbf{e6}\par\nobreak 0:10:01\par\nobreak\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip\nobreak\ 0:10:01\par \newline D05 Queen's Pawn Game: Colle System\par \textbf{4.} \textbf{a3} \textbf{4...} \textbf{c5} \textbf{5.} \textbf{c4} \textbf{5...} \textbf{Nc6}\par\nobreak 0:10:02\par\nobreak\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip\nobreak\ 0:10:02\par \textbf{6.} \textbf{dxc5} \textbf{6...} \textbf{Bxc5} \textbf{7.} \textbf{b4} \textbf{7...} \textbf{Be7} \textbf{8.} \textbf{Bb2}\par\nobreak 0:10:00\par\nobreak\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip\nobreak\ 0:10:03\par \textbf{8...} \textbf{dxc4} \textbf{9.} \textbf{Qxd8+} \textbf{9...} \textbf{Nxd8} \textbf{10.} \textbf{Bxc4} \textbf{10...} \textbf{O-O} \textbf{11.} \textbf{O-O} \textbf{11...} \textbf{a6} \textbf{12.} \textbf{Nc3} \textbf{12...} \textbf{b5} \textbf{13.} \textbf{Be2} \textbf{13...} \textbf{Bb7} \textbf{14.} \textbf{Nd4} \textbf{14...} \textbf{Ne4} \textbf{15.} \textbf{Nxe4} \textbf{15...} \textbf{Bxe4} \textbf{16.} \textbf{Bf3} \textbf{16...} \textbf{Bxf3} \textbf{17.} \textbf{Nxf3} \textbf{17...} \textbf{Nc6} \textbf{18.} \textbf{Rac1} \textbf{18...} \textbf{Rac8} \textbf{19.} \textbf{Rfd1} \textbf{19...} \textbf{Rfd8} \textbf{20.} \textbf{Rxd8+} \textbf{20...} \textbf{Rxd8} \textbf{21.} \textbf{g3} \textbf{21...} \textbf{Nb8} \textbf{22.} \textbf{Rc7} \textbf{22...} \textbf{Bd6} \textbf{23.} \textbf{Rc2} \textbf{23...} \textbf{f6} \textbf{24.} \textbf{Kg2} \textbf{24...} \textbf{e5} \textbf{25.} \textbf{h4} \textbf{25...} \textbf{e4} \textbf{26.} \textbf{Nd4} \textbf{26...} \textbf{Kf7} \textbf{27.} \textbf{Nf5} \textbf{27...} \textbf{Nd7} \textbf{28.} \textbf{Nxd6+} \newline Black resigns.\par \textbf{1-0}|}
|
||||
in
|
||||
ae expected actual;
|
||||
close_in ic
|
||||
|
||||
let suite =
|
||||
"pgn2tex tests"
|
||||
>::: [
|
||||
"json_str_to_map" >:: test_json_str_to_map;
|
||||
"basic_pgn_to_tex" >:: test_basic_pgn_to_tex;
|
||||
"pgn_with_clock_to_tex" >:: test_pgn_with_clock_to_tex;
|
||||
(* "pgn_with_unsupported_text" >:: test_pgn_with_unsupported_text; *)
|
||||
(* "pgn_with_custom_headers" >:: test_pgn_with_custom_headers; *)
|
||||
(* "pgn_with_different_unsupported_text"
|
||||
>:: test_pgn_with_different_unsupported_text; *)
|
||||
]
|
||||
|
||||
let () = run_test_tt_main suite
|
||||
@@ -0,0 +1,101 @@
|
||||
open OUnit2
|
||||
|
||||
let ae expected actual = assert_equal ~printer:(fun x -> x) expected actual
|
||||
let contains = Helpers.Text_helper.contains
|
||||
|
||||
let game_diagram_json_str =
|
||||
{| [
|
||||
{"ply":5,"fen":"rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3"},
|
||||
{"ply":6,"fen":"rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 3"},
|
||||
{"ply":10,"fen":"r1bqkbnr/pp1ppppp/2n5/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 3 5"},
|
||||
{"ply":15,"fen":"r1bqkb1r/pp1ppppp/2n5/2p5/4P3/2N2N2/PPPP1PPP/R1BQKB1R b KQkq - 5 7"}
|
||||
] |}
|
||||
|
||||
let diagram_data = Pgn_to_tex.parse_diagrams_json game_diagram_json_str
|
||||
|
||||
let variation_diagram_json_str =
|
||||
{| [{"ply":4,"fen":"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1","path":["e4","e5","Nf3","d6"]}] |}
|
||||
|
||||
let test_variation_diagram_to_tex _ctxt =
|
||||
let pgn = "1. e4 e5 2. Nf3 Nc6 (2... d6) 3. Bb5" in
|
||||
let diagrams = Pgn_to_tex.parse_diagrams_json variation_diagram_json_str in
|
||||
let rendered = Pgn_to_tex.to_tex ~diagram_data:diagrams ~clock:false pgn in
|
||||
let fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" in
|
||||
assert_bool
|
||||
(Printf.sprintf "variation diagram misplaced in:\n%s" rendered)
|
||||
(contains
|
||||
~needle:("2... d6\n\\par\\nobreak\\medskip\\chessboard[setfen=" ^ fen)
|
||||
rendered);
|
||||
assert_bool "variation diagram should use smallboard"
|
||||
(contains ~needle:"smallboard" rendered)
|
||||
|
||||
let test_basic_pgn_to_tex _ctxt =
|
||||
let filename = "pgn_examples/1.pgn" in
|
||||
let ic = In_channel.open_text filename in
|
||||
let input_string = In_channel.input_all ic in
|
||||
let actual = Pgn_to_tex.to_tex ~diagram_data ~clock:false input_string in
|
||||
let expected =
|
||||
{|\title{URS-chJ}
|
||||
\author{Ibragimov, Ildar (2455)\\Kramnik, Vladimir (2480)}
|
||||
\date{1991.??.??, Kherson}\maketitle
|
||||
\newchessgame
|
||||
\textbf{1.} \textbf{d4} \newline A88: Dutch Defence: Leningrad System: 5 Nf3 0-0 6 0-0 d6 7 Nc3 c6\par \textbf{\ldots{}d6} \textbf{2.} \textbf{c4} \textbf{f5} \textbf{3.} \textbf{Nf3}
|
||||
\par\nobreak\medskip\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\medskip
|
||||
\textbf{\ldots{}}\textbf{Nf6}
|
||||
\par\nobreak\medskip\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 3, vmargin=false]\par\medskip
|
||||
\textbf{4.} \textbf{g3} \textbf{g6} \textbf{5.} \textbf{Bg2} \textbf{Bg7}
|
||||
\par\nobreak\medskip\chessboard[setfen=r1bqkbnr/pp1ppppp/2n5/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 3 5, vmargin=false]\par\medskip
|
||||
\textbf{6.} \textbf{O-O} \textbf{O-O} \textbf{7.} \textbf{Nc3} \textbf{Qe8} \textbf{8.} \textbf{b3}
|
||||
\par\nobreak\medskip\chessboard[setfen=r1bqkb1r/pp1ppppp/2n5/2p5/4P3/2N2N2/PPPP1PPP/R1BQKB1R b KQkq - 5 7, vmargin=false]\par\medskip
|
||||
\textbf{\ldots{}}\textbf{Na6} \textbf{9.} \textbf{Ba3} \textbf{c6} \textbf{10.} \textbf{Qd3} \textbf{Rb8} \textbf{11.} \textbf{e4} \textbf{fxe4} \textbf{12.} \textbf{Nxe4} \textbf{Bf5} \textbf{13.} \textbf{Nxf6+} \textbf{Bxf6} \textbf{14.} \textbf{Qd2} \textbf{Nc7} \textbf{15.} \textbf{Rae1} \textbf{Qd7} \textbf{16.} \textbf{h4} \textbf{b5} \textbf{17.} \textbf{Re3} \textbf{bxc4} \textbf{18.} \textbf{bxc4} \textbf{Bh3} \textbf{19.} \textbf{Rfe1} \textbf{Bxg2} \newline last book move\par \textbf{20.} \textbf{Kxg2} \textbf{Qf5} \textbf{21.} \textbf{Re4} \textbf{Rbe8} \textbf{22.} \textbf{Rf4} \textbf{Qc8} \textbf{23.} \textbf{Qa5} \textbf{d5} \textbf{24.} \textbf{cxd5} \textbf{Nxd5} \textbf{25.} \textbf{Rfe4} \newline e7 seems the pivot of the position\par \textbf{\ldots{}Qf5} \textbf{26.} \textbf{Qd2} ( 26. Qxa7 ??{} taking the pawn is naive Qxf3+ Annihilates a defender: f3 27. Kxf3 Bxd4+ 28. Kg4 Bxa7 29. Bxe7 Rxf2 -+{} ( 29... Rxe7 30. Rxe7 Bxf2 31. a4 -+{} ) ( 29... Nxe7 ?!{} 30. Rxe7 Rxe7 31. Rxe7 Bxf2 32. a4 -+{} ) ) \textbf{Bg7} \textbf{27.} \textbf{Nh2} \textbf{Rf7} \textbf{28.} \textbf{Bc5} \newline The white bishop on an outpost\par \textbf{\ldots{}Qd7} \textbf{29.} \textbf{a4} \textbf{Nf6} \textbf{30.} \textbf{Re5} \textbf{Nd5} \textbf{31.} \textbf{R5e4} ( 31. R5e2 Rb8 \wbetter{} ) \textbf{Nf6} {} \textbf{32.} \textbf{Re5} \textbf{Kh8} ( 32... Nd5 33. R5e2 \wbetter{} ) \textbf{33.} \textbf{Kg1} \textbf{Nd5} \newline A valuable piece\par \textbf{34.} \textbf{R5e2} \textbf{a6} \textbf{35.} \textbf{Qd3} \textbf{Qh3} ( 35... Ra8 \wbetter{} ) \textbf{36.} \textbf{Nf3} ( 36. Qxa6 Ref8 37. Qa5 \wbetter{} ( 37. Qxc6 Rxf2 38. Rxf2 Qxg3+ 39. Kh1 Rxf2 ( 39... Qxf2 ?!{} 40. Rf1 Qa2 41. Rxf8+ Bxf8 42. Kg1 {} ) 40. Qa8+ Bf8 41. Qxf8+ Rxf8 42. Re2 Rf2 43. Rxf2 Qxf2 44. Ng4 Qf1+ 45. Kh2 Nf4 46. Ne3 Qf2+ 47. Kh1 Qxh4+ 48. Kg1 Qg3+ 49. Kf1 Qxe3 50. Bb6 Qe2+ 51. Kg1 Qg2\# ) ( 37. Bxe7 ??{} White will choke on that pawn Rxf2 ( 37... Nxe7 ?!{} 38. Rd1 -+{} ) 38. Rxf2 Qxg3+ 39. Kh1 Rxf2 ( 39... Qxf2 40. Re2 Qxd4 41. Bxf8 Qd1+ 42. Kg2 Nf4+ 43. Kf3 {} ) 40. Qc8+ Bf8 41. Bf6+ Nxf6 42. Qxf8+ Ng8 43. Qxf2 Qxf2 -+{} ) ) \textbf{Nf4} \bbetter{} \newline Do you see the mate threat?\par \textbf{37.} \textbf{gxf4} \textbf{Rxf4} \newline The mate threat is Rg4\par \textbf{38.} \textbf{Ne5} ( 38. Re4 !?{} is worthy of consideration Qg4+ 39. Kf1 Rxf3 40. Rxg4 Rxd3 41. Re6 \bbetter{} ) \textbf{Rg4+} !{} \ensuremath{\mp}{} \newline keeping the advantage\par \textbf{39.} \textbf{Nxg4} \newline Theme: Deflection from d3\par \textbf{\ldots{}Qxd3} \textbf{40.} \textbf{Re4} \textbf{Qf3} \textbf{41.} \textbf{Nh2} \textbf{Qf5} \textbf{42.} \textbf{Bxe7} ( 42. Kg2 Rf8 43. f3 Bf6 -+{} ) \textbf{Kg8} \textbf{43.} \textbf{f3} ( 43. R1e3 Qd5 -+{} ) \textbf{Qh3} -+{} \textbf{44.} \textbf{R1e2} ( 44. Kh1 -+{} ) \textbf{Qg3+} \textbf{45.} \textbf{Rg2} \textbf{Bxd4+} !{} \newline a devastating blow\par \textbf{46.} \textbf{Kh1} ( 46. Rxd4 A deflection Qe1+ Theme: Double Attack ) \textbf{Qh3} \textbf{47.} \textbf{Rgg4} ( 47. a5 Bc3 -+{} ) \textbf{c5} \textbf{48.} \textbf{h5} ( 48. Re1 does not improve anything Bf6 49. Rge4 Bxe7 50. Rxe7 Rxe7 51. Rxe7 Qxh4 -+{} ) \textbf{Rb8} \textbf{49.} \textbf{Re1} \textbf{Be5} \textbf{50.} \textbf{Rh4} \textbf{Qf5} \textbf{51.} \textbf{hxg6} \textbf{hxg6} \textbf{52.} \textbf{Re2} ( 52. Bxc5 doesn't change the outcome of the game Bg3 53. Rb4 Rc8 -+{} ( 53... Bxe1 ?!{} is clearly worse 54. Rxb8+ Kh7 55. Rb7+ Kh8 56. Rb8+ Kg7 57. Rb7+ Kf6 58. Ng4+ Kg5 59. Be3+ Kh4 60. Kg2 Qc2+ 61. Nf2 \bbetter{} ) ( 53... Qxc5 ?!{} is much worse 54. Rxb8+ Bxb8 55. Re8+ Kf7 56. Rxb8 -+{} ) ) \textbf{Rb1+} ( 52... Qb1+ !?{} keeps an even firmer grip 53. Kg2 Rb2 54. Rxb2 Qxb2+ 55. Kg1 -+{} ) \textbf{53.} \textbf{Kg2} \textbf{Bd4} \textbf{54.} \textbf{Ng4} ( 54. Rxd4 no good, but what else? cxd4 55. Ng4 -+{} ) \textbf{Rg1+} \textbf{55.} \textbf{Kh2} ( 55. Kh3 doesn't do any good Qxf3+ 56. Kh2 Rh1\# ) \textbf{Qf4+} ( 55... Qf4+ 56. Kh3 Qg3\# ) \textbf{0-1}|}
|
||||
in
|
||||
ae expected actual;
|
||||
close_in ic
|
||||
|
||||
let test_pgn_with_clock_to_tex _ctxt =
|
||||
let filename = "pgn_examples/2.pgn" in
|
||||
let ic = In_channel.open_text filename in
|
||||
let input_string = In_channel.input_all ic in
|
||||
let actual = Pgn_to_tex.to_tex ~diagram_data ~clock:true input_string in
|
||||
let expected =
|
||||
{|\title{Casual Rapid game}
|
||||
\author{montillo2015 (1919)\\reassessyourchess (1869)}
|
||||
\date{2023.12.03, https://lichess.org/9Z0taHcG}\maketitle
|
||||
\newchessgame
|
||||
\textbf{1.} \textbf{d4} \textbf{1...} \textbf{Nf6} \textbf{2.} \textbf{Nf3} \textbf{2...} \textbf{d5} \textbf{3.} \textbf{e3}\par\medskip\noindent\begin{minipage}{\linewidth}0:10:01\par\nopagebreak\smallskip
|
||||
\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 3, vmargin=false]\par\nopagebreak\vspace{1em}
|
||||
0:10:00\end{minipage}\par\medskip \textbf{3...} \textbf{e6}\par\medskip\noindent\begin{minipage}{\linewidth}0:10:01\par\nopagebreak\smallskip
|
||||
\chessboard[setfen=rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 3, vmargin=false]\par\nopagebreak\vspace{1em}
|
||||
0:10:01\end{minipage}\par\medskip \newline D05 Queen's Pawn Game: Colle System\par \textbf{4.} \textbf{a3} \textbf{4...} \textbf{c5} \textbf{5.} \textbf{c4} \textbf{5...} \textbf{Nc6}\par\medskip\noindent\begin{minipage}{\linewidth}0:10:02\par\nopagebreak\smallskip
|
||||
\chessboard[setfen=r1bqkbnr/pp1ppppp/2n5/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 3 5, vmargin=false]\par\nopagebreak\vspace{1em}
|
||||
0:10:02\end{minipage}\par\medskip \textbf{6.} \textbf{dxc5} \textbf{6...} \textbf{Bxc5} \textbf{7.} \textbf{b4} \textbf{7...} \textbf{Be7} \textbf{8.} \textbf{Bb2}\par\medskip\noindent\begin{minipage}{\linewidth}0:10:00\par\nopagebreak\smallskip
|
||||
\chessboard[setfen=r1bqkb1r/pp1ppppp/2n5/2p5/4P3/2N2N2/PPPP1PPP/R1BQKB1R b KQkq - 5 7, vmargin=false]\par\nopagebreak\vspace{1em}
|
||||
0:10:03\end{minipage}\par\medskip \textbf{8...} \textbf{dxc4} \textbf{9.} \textbf{Qxd8+} \textbf{9...} \textbf{Nxd8} \textbf{10.} \textbf{Bxc4} \textbf{10...} \textbf{O-O} \textbf{11.} \textbf{O-O} \textbf{11...} \textbf{a6} \textbf{12.} \textbf{Nc3} \textbf{12...} \textbf{b5} \textbf{13.} \textbf{Be2} \textbf{13...} \textbf{Bb7} \textbf{14.} \textbf{Nd4} \textbf{14...} \textbf{Ne4} \textbf{15.} \textbf{Nxe4} \textbf{15...} \textbf{Bxe4} \textbf{16.} \textbf{Bf3} \textbf{16...} \textbf{Bxf3} \textbf{17.} \textbf{Nxf3} \textbf{17...} \textbf{Nc6} \textbf{18.} \textbf{Rac1} \textbf{18...} \textbf{Rac8} \textbf{19.} \textbf{Rfd1} \textbf{19...} \textbf{Rfd8} \textbf{20.} \textbf{Rxd8+} \textbf{20...} \textbf{Rxd8} \textbf{21.} \textbf{g3} \textbf{21...} \textbf{Nb8} \textbf{22.} \textbf{Rc7} \textbf{22...} \textbf{Bd6} \textbf{23.} \textbf{Rc2} \textbf{23...} \textbf{f6} \textbf{24.} \textbf{Kg2} \textbf{24...} \textbf{e5} \textbf{25.} \textbf{h4} \textbf{25...} \textbf{e4} \textbf{26.} \textbf{Nd4} \textbf{26...} \textbf{Kf7} \textbf{27.} \textbf{Nf5} \textbf{27...} \textbf{Nd7} \textbf{28.} \textbf{Nxd6+} \newline Black resigns.\par \textbf{1-0}|}
|
||||
in
|
||||
ae expected actual;
|
||||
close_in ic
|
||||
|
||||
let test_default_arguments _ctxt =
|
||||
let actual = Pgn_to_tex.to_tex "1. e4 e5" in
|
||||
let expected =
|
||||
"\\title{}\n\
|
||||
\\author{}\n\
|
||||
\\date{}\\maketitle\n\
|
||||
\\newchessgame\n\
|
||||
\\textbf{1.} \\textbf{e4} \\textbf{e5}"
|
||||
in
|
||||
ae expected actual
|
||||
|
||||
let test_invalid_pgn_raises _ctxt =
|
||||
assert_raises (Failure "Parse error") (fun () ->
|
||||
ignore (Pgn_to_tex.to_tex "1. e4 e5 (2. Nf3"))
|
||||
|
||||
let suite =
|
||||
"pgn_to_tex tests"
|
||||
>::: [
|
||||
"variation_diagram_to_tex" >:: test_variation_diagram_to_tex;
|
||||
"basic_pgn_to_tex" >:: test_basic_pgn_to_tex;
|
||||
"pgn_with_clock_to_tex" >:: test_pgn_with_clock_to_tex;
|
||||
"default_arguments" >:: test_default_arguments;
|
||||
"invalid_pgn_raises" >:: test_invalid_pgn_raises;
|
||||
]
|
||||
@@ -0,0 +1,119 @@
|
||||
open OUnit2
|
||||
|
||||
let contains = Helpers.Text_helper.contains
|
||||
|
||||
let read_file path =
|
||||
let ic = In_channel.open_text path in
|
||||
Fun.protect
|
||||
~finally:(fun () -> In_channel.close ic)
|
||||
(fun () -> In_channel.input_all ic)
|
||||
|
||||
let render_fixture filename =
|
||||
Pgn_to_tex.to_tex (read_file @@ "pgn_examples/" ^ filename)
|
||||
|
||||
let all_percents_escaped text =
|
||||
let rec loop i =
|
||||
if i >= String.length text then true
|
||||
else if text.[i] = '%' then i > 0 && text.[i - 1] = '\\' && loop (i + 1)
|
||||
else loop (i + 1)
|
||||
in
|
||||
loop 0
|
||||
|
||||
let test_author_with_players _ctxt =
|
||||
let pgn =
|
||||
{|[Event "Club Night"]
|
||||
[White "Alice"]
|
||||
[Black "Bob"]
|
||||
[Author "Carol"]
|
||||
[Date "2024.01.02"]
|
||||
|
||||
1. e4 e5 1-0
|
||||
|}
|
||||
in
|
||||
let tex = Pgn_to_tex.to_tex pgn in
|
||||
assert_bool "author header should be present"
|
||||
(contains ~needle:"\\author{Carol}" tex);
|
||||
assert_bool "author header should not be empty"
|
||||
(not (contains ~needle:"\\author{}" tex));
|
||||
assert_bool "player names should not replace the author"
|
||||
(not (contains ~needle:"Alice" tex))
|
||||
|
||||
let test_title_without_subtitle _ctxt =
|
||||
let pgn =
|
||||
{|[Event "Club Night"]
|
||||
[Title "Club Championship"]
|
||||
[Date "2024.01.02"]
|
||||
|
||||
1. e4 e5 1-0
|
||||
|}
|
||||
in
|
||||
let tex = Pgn_to_tex.to_tex pgn in
|
||||
assert_bool "title should be rendered"
|
||||
(contains ~needle:"\\title{Club Championship}" tex);
|
||||
assert_bool "empty subtitle block should be omitted"
|
||||
(not (contains ~needle:"\\large{}" tex));
|
||||
assert_bool "subtitle separator should be omitted"
|
||||
(not (contains ~needle:"\\\\[2ex]" tex))
|
||||
|
||||
let test_title_subtitle_author_fixture _ctxt =
|
||||
let expected =
|
||||
{|\title{Some Title\\[2ex]\large{Some Subtitle}}
|
||||
\author{Some Author}
|
||||
\date{2025.12.23}\maketitle
|
||||
\newchessgame
|
||||
\textbf{1.} \textbf{d4} \textbf{d5} \textbf{2.} \textbf{c4} \textbf{dxc4} \textbf{3.} \textbf{e4} \textbf{Nf6} \textbf{4.} \textbf{e5} \textbf{Nd5} \textbf{5.} \textbf{Bxc4} \textbf{Nb6} \textbf{6.} \textbf{Bb3} \textbf{e6} ( 6... Nc6 ) \textbf{7.} \textbf{Nf3} \textbf{c5} \textbf{8.} \textbf{Be3} \textbf{N8d7} \textbf{9.} \textbf{O-O} \textbf{c4} \textbf{10.} \textbf{Bc2} \textbf{Nd5} \textbf{11.} \textbf{Nc3} \textbf{N7b6} \textbf{12.} \textbf{Be4} \textbf{Bb4} \textbf{13.} \textbf{Bxd5} \textbf{Nxd5} ( 13... Bxc3 ) \textbf{14.} \textbf{Nxd5} \textbf{exd5} \textbf{15.} \textbf{Qa4+} \textbf{Bd7} \textbf{16.} \textbf{Qxb4} \textbf{Qb6} \textbf{17.} \textbf{Qxb6} \textbf{axb6} \textbf{18.} \textbf{Rfc1} \textbf{O-O} \textbf{19.} \textbf{Nd2} \textbf{Bf5} \textbf{20.} \textbf{b3} \textbf{b5} \textbf{21.} \textbf{a4} \textbf{cxb3} \textbf{22.} \textbf{Nxb3} \textbf{bxa4} \textbf{23.} \textbf{Nc5} \textbf{b5} \textbf{24.} \textbf{Bd2} \textbf{Rfe8} \textbf{25.} \textbf{Bb4} \textbf{Rac8} \textbf{26.} \textbf{Nb7} \textbf{Rxc1+} \textbf{27.} \textbf{Rxc1} \textbf{Rc8} \textbf{28.} \textbf{Rxc8+} \textbf{Bxc8} \textbf{29.} \textbf{Nd6} \textbf{Bd7} \textbf{30.} \textbf{f4} \textbf{g6} \textbf{31.} \textbf{Kf2} \textbf{Kg7} \textbf{32.} \textbf{h3} \textbf{*}|}
|
||||
in
|
||||
assert_equal ~printer:(fun x -> x) expected (render_fixture "12.pgn")
|
||||
|
||||
let test_empty_date_and_site_fixture_5 _ctxt =
|
||||
let tex = render_fixture "5.pgn" in
|
||||
assert_bool "event title should be rendered"
|
||||
(contains ~needle:"\\title{Obert Barad 2024}" tex);
|
||||
assert_bool "players should be rendered when no author is present"
|
||||
(contains ~needle:"\\author{Alejandro Fernandez Cardenete (1873)" tex);
|
||||
assert_bool "empty date and site should render an empty date"
|
||||
(contains ~needle:"\\date{}\\maketitle" tex)
|
||||
|
||||
let test_empty_date_fixture_6 _ctxt =
|
||||
let tex = render_fixture "6.pgn" in
|
||||
assert_bool "empty date should fall back to the site"
|
||||
(contains ~needle:"\\date{Terrassa}\\maketitle" tex);
|
||||
assert_bool "a missing date must not render a comma-only date"
|
||||
(not (contains ~needle:"\\date{,}" tex))
|
||||
|
||||
let test_percent_escaping_fixture_8 _ctxt =
|
||||
let tex = render_fixture "8.pgn" in
|
||||
assert_bool "percent in a comment should be LaTeX-escaped"
|
||||
(contains ~needle:"\\%" tex);
|
||||
assert_bool "every percent in the output should be escaped"
|
||||
(all_percents_escaped tex)
|
||||
|
||||
let fixture_names () =
|
||||
Sys.readdir "pgn_examples" |> Array.to_list
|
||||
|> List.filter (fun name -> Filename.check_suffix name ".pgn")
|
||||
|> List.sort String.compare
|
||||
|
||||
let test_fixture_smoke =
|
||||
List.map
|
||||
(fun filename ->
|
||||
filename >:: fun _ctxt ->
|
||||
let tex = render_fixture filename in
|
||||
assert_bool
|
||||
(filename ^ " should render non-empty LaTeX")
|
||||
(String.length tex > 0);
|
||||
assert_bool
|
||||
(filename ^ " should contain document setup")
|
||||
(contains ~needle:"\\newchessgame" tex))
|
||||
(fixture_names ())
|
||||
|
||||
let suite =
|
||||
"real-world header and fixture tests"
|
||||
>::: [
|
||||
"author with players" >:: test_author_with_players;
|
||||
"title without subtitle" >:: test_title_without_subtitle;
|
||||
"title/subtitle/author fixture" >:: test_title_subtitle_author_fixture;
|
||||
"empty date/site fixture 5" >:: test_empty_date_and_site_fixture_5;
|
||||
"empty date fixture 6" >:: test_empty_date_fixture_6;
|
||||
"percent escaping fixture 8" >:: test_percent_escaping_fixture_8;
|
||||
"all fixtures" >::: test_fixture_smoke;
|
||||
]
|
||||
+4
-1
@@ -6,8 +6,11 @@ let () =
|
||||
>::: [
|
||||
Test_lexer.suite;
|
||||
Test_latex.suite;
|
||||
Test_pgn2tex.suite;
|
||||
Test_pgn_to_tex.suite;
|
||||
Test_parser.suite;
|
||||
Test_diagram_resolution.suite;
|
||||
Test_nag.suite;
|
||||
Test_real_world.suite;
|
||||
]
|
||||
in
|
||||
run_test_tt_main all
|
||||
|
||||
Reference in New Issue
Block a user