# detex-rs
[](https://github.com/tchajed/detex-rs/actions/workflows/ci.yml)
Port of [opendetex](https://github.com/pkubowicz/opendetex) to Rust using LLMs.
Note that the library and binary are called detex. This Rust port is not 100% compatible with opendetex, but it is close enough to use for counting words written in LaTeX.
Claude Opus 4.5 did the majority of the work with this prompt, along with detex's `detex.l` (written in flex, a lexer generator, but largely C code) and `detex.h`:
> Attached is the source code for detex, written in flex and C. Port this to Rust. First make a careful plan to structure the code, then port everything. Try to write idiomatic Rust code.
The initial tests were generated by Claude, then I supplemented with some small test cases extracted from a larger project that demonstrated bugs (discovered by using `scripts/compare.sh`).
A large bug fix (in handling -s) came from this prompt:
> Read detex.l and lexer.rs and make sure they line up exactly. Add comments to lexer.rs along the way citing the correspondence. Change lexer.rs as needed.
## Building
```
cargo build
```
To run the tests, you need the flex library (`apt install libfl-dev` on Ubuntu) in order to compile opendetex for comparison (the tests will compile it automatically with `make -C opendetex-2.8.11`).
```
cargo test
```