# luacoolprop 1.2.0

`luacoolprop` is a format-generic LuaTeX interface to the CoolProp shared library. It computes thermodynamic states in Lua and emits PGFPlots code for PH (pressure-enthalpy), log-log PV (pressure-specific-volume), linear TS (temperature-entropy), linear HS (enthalpy-entropy), and PT (pressure-temperature, logarithmic in pressure) diagrams of pure fluids. It requires PGFPlots 1.18 or later but never changes the document's selected PGFPlots compatibility level.

The package supports saturation curves, quality lines, diagram-specific
background families, thermodynamic process paths, stable curve names,
per-curve overrides, and automatic label placement delegated to
`pgfplots-autonode`.

The independent `pgfplots-autonode` package is a required dependency. It also
labels ordinary PGFPlots curves without loading LuaCoolProp or CoolProp. Its
source, documentation, and issue tracker live in the separate
[pgfplots-autonode repository](https://github.com/cjorssen/pgfplots-autonode).

![Methane Linde-process solution with a fully constructed PH cycle](doc/luatex/luacoolprop/images/methane-linde-cycle.png)

*The final stage of the [methane Linde-process tutorial](tutorial/methane-linde-solution.tex): a computed PH diagram, coupled flows, state readings, and energy balances.*

![Butane pressure-specific-volume diagram with ideal-gas comparison](doc/luatex/luacoolprop/images/butane-pv-ideal-gas.png)

*An [intermediate butane PV tutorial stage](tutorial/butane-pv.tex), comparing a real-fluid isotherm with its dilute-gas approximation.*

Both previews are cropped directly from the figures in the
[reference manual](doc/luatex/luacoolprop/luacoolprop-manual.pdf). The corresponding figure sources
are included; no external exercise artwork is bundled.

This package was **vibe-coded with OpenAI Codex and the Astra-6 model** under the direction of
Christophe Jorssen.

> [!WARNING]
> CTAN publication is not a correctness or safety certification. Inspect the
> source and independently validate thermodynamic results before industrial,
> regulated, safety-critical, or other high-consequence use.

Author and Current Maintainer: Christophe Jorssen
<christophe.jorssen@gmail.com>. Version 1.2.0 is dated 2026-11-20; version
1.0.0 was distributed to a small group on 2026-09-05. The work is
maintained and distributed under the LaTeX Project Public License 1.3c or
later. The public project repository is
[github.com/cjorssen/luacoolprop](https://github.com/cjorssen/luacoolprop).

## Upgrading from CTAN 1.1.1

Read the [compatibility and migration notes](CHANGELOG.md#compatibility-and-migration-from-ctan-111)
before updating. In particular, install all Lua components, select a reviewed
CoolProp binary, correct formerly ignored unknown keys, and initialize a single
HEOS reference convention before using any alias of a fluid. The notes identify
changes in loading, native errors, internal extension points and file paths.
Existing public TeX command names and diagram defaults are retained.

## Citing CoolProp

If you publish work based on thermodynamic results produced with LuaCoolProp,
please cite the underlying CoolProp project as its authors request:
Ian H. Bell, Jorrit Wronski, Sylvain Quoilin, and Vincent Lemort,
“Pure and Pseudo-pure Fluid Thermophysical Property Evaluation and the
Open-Source Thermophysical Property Library CoolProp,” *Industrial &
Engineering Chemistry Research* **53**(6), 2498–2508 (2014),
[doi:10.1021/ie4033999](https://doi.org/10.1021/ie4033999), and
[coolprop.org](https://coolprop.org/). The [official citation page](https://coolprop.org/citation.html)
also provides BibTeX. Record the CoolProp version used for reproducibility.

## Files

The runtime names below live in `tex/luatex/luacoolprop/`; all Lua files
live in its `lua/` subdirectory. The manual source and PDF live in
`doc/luatex/luacoolprop/`.

- `luacoolprop.tex`: generic TeX interface based on `pgfkeys`.
- `luacoolprop.lua`: stable public Lua facade and component loader.
- `luacoolprop-*.lua`: internal modules for the CoolProp ABI, input validation,
  thermodynamic models, sampling, projections, and PGFPlots serialization.
  Install all these files alongside the facade; they are runtime dependencies,
  not optional development files.
- `luacoolprop.sty`: LaTeX wrapper.
- `t-luacoolprop.tex`: ConTeXt wrapper.
- `p-luacoolprop.tex`: plain TeX wrapper.
- [luacoolprop-manual.pdf](doc/luatex/luacoolprop/luacoolprop-manual.pdf): complete reference manual,
  included in both the GitHub tree and the CTAN distribution.
- `luacoolprop-manual.tex`: English user manual, exhaustive TeX reference,
  command/key indexes, and developer reference.
- `doc/luatex/luacoolprop/luacoolprop-getting-started.tex`: first figures, local
  styles, key-family map and routes to advanced control.
- `doc/luatex/luacoolprop/luacoolprop-tex-reference.tex`: command-by-command and key-by-key TeX
  reference with executable source/result examples.
- `doc/luatex/luacoolprop/r717-teaching-tutorial.tex`: instructor-oriented tutorial producing a
  blank R717 worksheet diagram and its annotated model-solution diagram.
- `doc/luatex/luacoolprop/r134a-air-conditioner-tutorial.tex`: advanced six-stage R134a tutorial
  progressing from phase regions to a fully quantified air-conditioning cycle.
- `doc/luatex/luacoolprop/butane-pv-tutorial.tex`: five-stage butane PV tutorial covering phase
  regions, the ideal-gas limit, intersection-defined states, a rigid-tank
  isochore, and numerical process exports.
- `doc/luatex/luacoolprop/r1234yf-heat-pump-tutorial.tex`: worksheet/model-solution tutorial for
  an R1234yf swimming-pool heat pump, including saturation-derived pressures,
  a four-device PH cycle, and automated condenser-power calculation.
- `doc/luatex/luacoolprop/methane-linde-tutorial.tex`: expert worksheet/progressive-solution
  tutorial for methane liquefaction by the Linde process, including coupled
  separator, regenerator, mixer, three-stage compression, and live power
  balances.
- `doc/luatex/luacoolprop/luacoolprop-lua-api.md`: detailed Lua API, ownership, units, error,
  extension, and contribution reference.
- `examples/`: compilable LaTeX, plain TeX, ConTeXt, and Lua API examples with
  reproducible compilation logs.

## Choose your path

The [reference manual](doc/luatex/luacoolprop/luacoolprop-manual.pdf) opens with
three ways to work:

- **First figure:** choose a fluid and one of PH, PV, TS, HS or PT with
  `\LCPDiagram{TYPE}[fluid=...]`. Complete programs cover LaTeX, plain TeX and
  ConTeXt MkIV, including loading and compilation.
- **Everyday customization:** select a legible curve network, units and labels.
  Copy the transparent worksheet, solution or monochrome PGF styles into your
  document and override individual keys. These are document-owned recipes,
  not additional installed presets.
- **Complete control:** own the PGFPlots axis, add families and processes
  individually, export numerical tables or call the Lua API directly.

A key-family map and task recipes lead to the exhaustive command/key reference
and the worked scientific tutorials. All projections use the same generic API;
choose coordinates for the physical question.

## Quick start: automatic PH diagram

The LaTeX wrapper uses `siunitx` for generated numbers and units. If `siunitx`
was loaded first, LuaCoolProp preserves its package options and `\sisetup`
configuration. Otherwise the wrapper loads it with the standard defaults.
Plain TeX and ConTeXt do not acquire this LaTeX dependency.

Numeric input is locale independent: always use `.` as the decimal separator,
even if `siunitx` displays decimal commas. Decimal scientific notation and an
attached recognized process unit are accepted, for example `1.2E5Pa`.
Unknown package keys and malformed numbers, units, booleans, lists, modes,
presets, and bounds raise errors instead of silently selecting a fallback.
Use the documented style keys to pass ordinary PGFPlots or TikZ options.

```tex
\documentclass[border=3mm]{standalone}
\usepackage{luacoolprop}
\pgfplotsset{compat=1.18}

\begin{document}
\LCPPHDiagram[
  fluid=R134a,
  quality step=0.2,
  isotherm=true,
  temperature values={-20,0,20,40,60},
  labels=true
]
\end{document}
```

Compile with `lualatex --shell-escape` after selecting the external CoolProp
shared library as described below. The source is also available as
[`examples/ph-readme-automatic.tex`](examples/ph-readme-automatic.tex).

## Quick start: choose the curves in a PGFPlots axis

Use a normal PGFPlots `axis` when you want to choose each family and control
the axes yourself. `auto node placement` enables the required external
`pgfplots-autonode` solver; it does not take control of unrelated axes.

```tex
\documentclass[border=3mm]{standalone}
\usepackage{luacoolprop}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
  lcp fluid=R134a,
  width=12cm,height=8cm,
  ymode=log,grid=both,
  xlabel={$h/(\mathrm{kJ\,kg^{-1}})$},
  ylabel={$p/\mathrm{bar}$},
  auto node placement
]
  \LCPAddPHQuality[quality values={0,0.5,1},labels=true]
  \LCPAddPHIsotherms[temperature values={-20,0,20,40,60},labels=true]
\end{axis}
\end{tikzpicture}
\end{document}
```

This exact source is [`examples/ph-readme-selected.tex`](examples/ph-readme-selected.tex).

## Pressure-specific-volume diagrams

PV is a registered diagram type with a log-log default axis. Quality curves,
isotherms, and isentropes use the shared option vocabulary; the abscissa is
mass-specific volume in m³/kg by default.

```tex
\LCPPVDiagram[
  fluid=R134a,
  isotherm=true,
  isentrope=true,
  quality values={0,0.25,0.5,0.75,1},
  temperature values={-20,0,20,40,60},
  entropy values={1.6,1.8,2.0},
  labels=true
]
```

The low-level commands `\LCPAddPVQuality`, `\LCPAddPVIsotherms`,
`\LCPAddPVIsentropes`, `\LCPAddPVPlots`, and `\LCPAddPVProcess` work inside an
existing `loglogaxis`. PV process coordinate exports use scaled specific volume
for X while retaining raw SI volume in the `...SpecificVolumeSI` macros.

## Temperature-entropy diagrams

TS is a registered diagram type with linear axes. Mass-specific entropy is
shown in kJ/(kg K) and absolute temperature in K by default. Quality curves and
constant mass-specific enthalpy curves use the shared selection, styling,
label, and autonode vocabulary.

```tex
\LCPTSDiagram[
  fluid=R134a,
  isenthalp=true,
  quality values={0,0.25,0.5,0.75,1},
  enthalpy values={200,250,300,350,400,450},
  labels=true
]
```

The low-level commands `\LCPAddTSQuality`, `\LCPAddTSIsenthalps`,
`\LCPAddTSPlots`, and `\LCPAddTSProcess` work inside an existing linear
`axis`. TS process coordinate exports use scaled entropy for X and the selected
scaled/offset temperature coordinate for Y while retaining absolute
temperature and every other resolved property in SI.

## Enthalpy-entropy diagrams

HS is a registered linear diagram type with mass-specific entropy on the
horizontal axis and mass-specific enthalpy on the vertical axis. It supports
qualities, isochores, isotherms, and isobars, including a common critical-limit
endpoint
and continuous two-phase isotherm/isobar segments.

```tex
\LCPHSDiagram[
  fluid=Water,
  quality step=0.2,
  isochore=true,
  specific volume values={0.01,0.1,1},
  isotherm=true,
  temperature values={100,200,300,400},
  isobar=true,
  isobar values={0.1,1,10,100},
  labels=true
]
```

The low-level commands `\LCPAddHSQuality`, `\LCPAddHSIsochores`,
`\LCPAddHSIsotherms`, `\LCPAddHSIsobars`, `\LCPAddHSPlots`, and
`\LCPAddHSProcess` work inside an existing linear `axis`. HS process exports
use scaled entropy for X and scaled enthalpy for Y, with all resolved
thermodynamic properties retained in SI.

## Pressure-temperature diagrams

PT uses temperature on the horizontal axis and a logarithmic pressure axis.
Its default background is the single liquid-vapour coexistence curve from the
triple point to the critical point. Saturated liquid and saturated vapour have
the same `(T,p)` coordinates, so this locus is intentionally not represented
as separate `Q=0` and `Q=1` curves. Isentropes, isenthalps, and isochores are
optional.

```tex
\LCPPTDiagram[
  fluid=R134a,
  temperature axis unit=celsius,
  pressure axis unit=bar,
  isentrope=true, entropy values={1.4,1.7,2.0},
  isenthalp=true, enthalpy values={200,300,400},
  isochore=true, specific volume values={0.001,0.01,0.1}
]
```

The low-level commands are `\LCPAddPTPhaseEnvelope` (also
`\LCPAddPTSaturation`), `\LCPAddPTIsentropes`, `\LCPAddPTIsenthalps`,
`\LCPAddPTIsochores`, `\LCPAddPTPlots`, and `\LCPAddPTProcess`.

## Scientific and coordinate contracts

PH, PV, TS, HS, and PT are peers in one registry. Their background capabilities
are validated: PH provides quality/isotherm/isentrope/isochore, PV provides
quality/isotherm/isentrope, TS provides quality/isenthalp, and HS provides
quality/isochore/isotherm/isobar, while PT provides one phase envelope plus
isentrope/isenthalp/isochore. An unsupported family switch is an error;
all six conserved-property process types remain projectable in every diagram.

Diagram construction accepts only CoolProp fluids reported as pure. Mixtures
and predefined blends are rejected because this release does not implement
mixture phase envelopes. The low-level Lua wrappers remain mixture-capable.

At the critical state, vapor quality is undefined. When a quality curve reaches
the critical pressure, its final graphical record is a quality-independent
limiting endpoint, not a state carrying the curve's subcritical quality value.

Use semantic coordinate keys such as `pressure axis unit=mpa`,
`enthalpy axis unit=jkg`, `specific volume axis unit=lkg`,
`entropy axis unit=jkgk`, and `temperature axis unit=celsius`. Each changes the
numeric coordinate and generated label together. Raw scale keys are retained
for advanced use and produce an explicit scaled-SI label.

Enthalpy and entropy reference origins are selected at initialization with
`\LCPSetReferenceState{DEF|IIR|ASHRAE|NBP}` or `reference state=...`. The first
diagram calculation locks the convention for that native fluid, including all
its CoolProp aliases (for example `R134a`, `R134A` and `HEOS::R134a`). Managed
references and diagrams require the HEOS backend; other backends remain
available through the low-level Lua interface. Use the same
convention for every compared state and use enthalpy differences in energy
balances.

Adaptive curves retain disconnected valid components instead of drawing
across rejected CoolProp states. `domain policy=ignore|warning|error` controls
the diagnostic; PGFPlots serialization always uses explicit jumps.

## Process path example

```tex
\LCPAddPHProcess[
  fluid=R134a,
  type=isentrope,
  from={pressure=1bar,quality=1},
  to={pressure=10bar},
  style={very thick,-Latex},
  label={$1\to2$},
  mark endpoints=true
]
```

## Define a cycle once, draw several views

Named thermodynamic models keep resolved SI states independent of a diagram.
For example, define an ideal compressor once:

```tex
\LCPDeclareModel[fluid=R134a]{fridge}
\LCPDefineState{fridge}{A}{T=0C,q=1}
\LCPDefineProcess{fridge}{compress}[
  type=isentropic,from=A,to=B,to state={p=10bar}]
```

Inside a suitable PGFPlots axis, draw it with
`\LCPAddModelProcess{PH}{fridge}{compress}` or
`\LCPAddModelProcess{TS}{fridge}{compress}`. Retrieve the same enthalpy in J/kg
with `\LCPStateValue{fridge}{B}{h}`. Add processes and register a closed ordered
cycle with `\LCPDefineCycle`; `\LCPAddCycle` draws it in any built-in projection.
The manual's “Named states and reusable cycles” reference supplies a complete
refrigerator, coordinate labels, grouping rules and explicit table exports.
These model values come from CoolProp, not from a graphical intersection.
Existing explicit process commands remain available.

## Diagram API

Diagram identifiers are uppercase coordinate pairs. `\LCPPHDiagram[<options>]`,
`\LCPPVDiagram[<options>]`, `\LCPTSDiagram[<options>]`, and
`\LCPHSDiagram[<options>]`, and `\LCPPTDiagram[<options>]` are the convenience spellings;
`\LCPDiagram{PH}[<options>]`, `\LCPDiagram{PV}[<options>]`, and
`\LCPDiagram{TS}[<options>]`, `\LCPDiagram{HS}[<options>]`, and
`\LCPDiagram{PT}[<options>]` are their generic
equivalents. The same dispatch API is available for plots, families, and
processes:

```tex
\LCPAddDiagramPlots{PH}[<options>]
\LCPAddDiagramFamily{PH}{isotherm}[<options>]
\LCPAddDiagramProcess{PH}[<options>]
```

Additional implementations can register further identifiers behind the same
interface. Mixed-case commands and abbreviated keys are accepted aliases;
the canonical interface uses uppercase diagram codes and
full property names such as `quality`, `temperature`, and `pressure`.

The developer-facing Lua API is documented in
[`doc/luatex/luacoolprop/luacoolprop-lua-api.md`](doc/luatex/luacoolprop/luacoolprop-lua-api.md). It covers the
CoolProp FFI wrappers, deterministic `AbstractState` cleanup, SI-unit contracts,
PH, PV, TS, HS, and PT point/process records, renderer options, error handling, and the
stable registration shape for custom diagram implementations.

## Automatic-label dependency

`pgfplots-autonode` is an independent CTAN and TeX Live package and a required
LuaCoolProp runtime dependency. LuaCoolProp loads its PGFPlots library
automatically; it does not embed or maintain a private copy. The label package
can also be used independently after loading the PGFPlots frontend:

```tex
\usepgfplotslibrary{autonode}
```

The frontend is `\usepackage{pgfplots}` in LaTeX, `\input pgfplots.tex` in
plain TeX, and `\usemodule[t][pgfplots]` in ConTeXt. A labelled plot uses
`\pgfplotsautonode` as a trailing path command:

```tex
\begin{axis}[auto node placement,auto node algorithm=repair]
  \addplot[domain=0:4] {x}
    \pgfplotsautonode[preferred pos=0.65,sloped=true]{$y=x$};
\end{axis}
```

`auto node placement` is the lifecycle switch which runs the joint solver at
the end of the axis. It is mandatory for standalone use and for LuaCoolProp
family commands inside a manually written axis; omitting it produces a clear
warning. High-level commands such as `\LCPPHDiagram` install it on the axis
they create without changing unrelated PGFPlots axes.

The standalone `pgfplots-autonode` distribution provides its own manual,
affine-network tutorial, examples for all three formats, numerical tests, and
installed-tree independence tests. It requires neither CoolProp nor shell
escape.

## CoolProp installation and runtime

CoolProp is an external native dependency. It is never included in the
LuaCoolProp package or its CTAN archive. Obtain a binary from the [official
shared-library page](https://coolprop.org/coolprop/wrappers/SharedLibrary/) or
build a reviewed revision from the [official CoolProp
repository](https://github.com/CoolProp/CoolProp). The library is normally
named `libCoolProp.dylib` on macOS, `libCoolProp.so` on Linux, and
`CoolProp.dll` on Windows.

The CoolProp library and the TeX engine process must have matching
architectures. Use an absolute `LUACOOLPROP_LIB` path, and record the CoolProp
tag or commit used to produce reproducible documents. Loading a shared library
executes native code, so use only an official binary or one built from source
you trust.

### Native version detection

LuaCoolProp automatically detects the file actually loaded and selects a reviewed
interface. No `compat` key is needed. The tested native identities are CoolProp
`8.0.0b1` (`322000f4ddab`), released `8.0.0` (`ae81610e7d23`), and the additional
`8.0.1dev` snapshot (`6de0bf8c5164`). “8.0-dev” denotes the first of these exact
commits, not every development build. The [Lua API reference](doc/luatex/luacoolprop/luacoolprop-lua-api.md#tested-native-identities-and-adaptation)
lists full identities and the supported-version policy. Unreviewed versions
produce an actionable error before property calculations.

Select a library with `\LCPsetup{library={/absolute/path/to/libCoolProp.dylib}}`
before the first calculation, or set `LUACOOLPROP_LIB`. An explicit selection is
authoritative: failure never silently selects another installation. In `texlua`,
`require("luacoolprop").library_info()` reports the actual path, version, commit,
adapter, ABI and capabilities. Changing the library requires a fresh compiler
process. Cache entries and exported tables include its identity.

Validation covers all five diagrams, critical tails, domain
gaps, processes, caches and table exports against the same package runtime, with
isolated LaTeX, plain TeX and ConTeXt MkIV builds on macOS arm64. Linux and Windows
installation instructions below describe supported build methods; those native
platforms have not been tested for this version.

### Security warning: `--shell-escape`

> [!CAUTION]
> LuaCoolProp requires full `--shell-escape` because TeX Live exposes the
> LuaTeX FFI module only in a shell-escape-enabled typesetting process. This
> option lets the document and every loaded class, package, module, and input
> file run external programs with your user permissions. Compile only trusted
> sources, preferably in a sandbox or isolated account without secrets or
> elevated privileges. Never run the TeX engine as `root` or Administrator.
> Restricted shell escape is not sufficient for this FFI mechanism.

LuaCoolProp uses FFI to load the CoolProp C API. It does not download or compile
CoolProp and does not issue shell commands while typesetting, but that does not
reduce the authority granted to the rest of the document by
`--shell-escape`.

### Install the TeX package

Once the package is available through a TeX distribution, install it with that
distribution's package manager (`tlmgr install luacoolprop
pgfplots-autonode` for TeX Live, or the MiKTeX Console on MiKTeX). TeX Live
normally installs the declared `pgfplots-autonode` dependency automatically.
CoolProp must still be installed separately.

For a manual TDS installation, unpack both independent TDS archives at the
root of a personal TEXMF tree. On TeX Live this is normally:

```sh
texmf_home=$(kpsewhich -var-value=TEXMFHOME)
mkdir -p "$texmf_home"
unzip luacoolprop.tds.zip -d "$texmf_home"
unzip pgfplots-autonode.tds.zip -d "$texmf_home"
mktexlsr "$texmf_home"
```

Do not unpack the browsing archive `luacoolprop.zip` directly into a TEXMF
tree: it contains documentation and source files in CTAN's browsing layout.

### Reproducible source checkout

Building from source requires Git, CMake, Ninja, Python, a C++ compiler, and
CoolProp's submodule prerequisites. Keep the checkout beside, never inside,
this repository. This example pins the reviewed `v8.0.0` tag; replace it deliberately
when adopting another reviewed release.

```sh
git clone https://github.com/CoolProp/CoolProp.git ../coolprop-src
git -C ../coolprop-src fetch --tags
git -C ../coolprop-src checkout --detach v8.0.0
git -C ../coolprop-src submodule update --init --recursive
```

### macOS

Install Apple's command-line developer tools plus Git, CMake, and Ninja. For a
reproducible build, perform the pinned common checkout above first. The bundled
helper then reuses `../coolprop-src`, updates submodules, and puts the build in
a sibling directory. If no checkout exists, it clones the reviewed `v8.0.0` tag:

```sh
./scripts/build-coolprop-macos.sh
```

It defaults to `arm64` on Apple Silicon and prints the final absolute library
path. Match an Intel TeX engine or request a universal binary with:

```sh
COOLPROP_MACOS_ARCH=x86_64 ./scripts/build-coolprop-macos.sh
COOLPROP_MACOS_ARCH='arm64;x86_64' ./scripts/build-coolprop-macos.sh
```

To run CMake directly, use:

```sh
cmake -S ../coolprop-src -B ../coolprop-build-macos-arm64 -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_OSX_ARCHITECTURES=arm64 \
  -DCOOLPROP_SHARED_LIBRARY=ON \
  -DCOOLPROP_STATIC_LIBRARY=OFF \
  -DCOOLPROP_OBJECT_LIBRARY=OFF
cmake --build ../coolprop-build-macos-arm64 --target CoolProp
export LUACOOLPROP_LIB="$PWD/../coolprop-build-macos-arm64/libCoolProp.dylib"
```

### Linux

Install Git, CMake, Ninja, Python, a C++ toolchain, and 7-Zip with the system
package manager. For Debian or Ubuntu, the usual package names are `git`,
`cmake`, `ninja-build`, `build-essential`, `python3`, and `p7zip-full`. After
the pinned checkout above:

```sh
cmake -S ../coolprop-src -B ../coolprop-build-linux -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DCOOLPROP_SHARED_LIBRARY=ON \
  -DCOOLPROP_STATIC_LIBRARY=OFF \
  -DCOOLPROP_OBJECT_LIBRARY=OFF
cmake --build ../coolprop-build-linux --target CoolProp
export LUACOOLPROP_LIB="$PWD/../coolprop-build-linux/libCoolProp.so"
```

A system-wide install and `sudo` are not required. Keeping the versioned build
outside the package and selecting it with an absolute path is easier to audit.

### Windows

The simplest setup is to extract an official precompiled x64 DLL to a stable
directory outside the LuaCoolProp tree. For a source build, install Git, CMake,
Python, and either Ninja with a compatible C++ compiler or Visual Studio. In
PowerShell, a Ninja build is:

```powershell
git clone https://github.com/CoolProp/CoolProp.git ..\coolprop-src
git -C ..\coolprop-src fetch --tags
git -C ..\coolprop-src checkout --detach v8.0.0
git -C ..\coolprop-src submodule update --init --recursive
cmake -S ..\coolprop-src -B ..\coolprop-build-windows -G Ninja `
  -DCMAKE_BUILD_TYPE=Release `
  -DCOOLPROP_SHARED_LIBRARY=ON `
  -DCOOLPROP_STATIC_LIBRARY=OFF `
  -DCOOLPROP_OBJECT_LIBRARY=OFF
cmake --build ..\coolprop-build-windows --target CoolProp
$env:LUACOOLPROP_LIB =
  (Resolve-Path ..\coolprop-build-windows\CoolProp.dll).Path
```

With Visual Studio 2022, use the matching x64 multi-configuration build:

```powershell
cmake -S ..\coolprop-src -B ..\coolprop-build-vs `
  -G "Visual Studio 17 2022" -A x64 `
  -DCOOLPROP_SHARED_LIBRARY=ON `
  -DCOOLPROP_STATIC_LIBRARY=OFF `
  -DCOOLPROP_OBJECT_LIBRARY=OFF
cmake --build ..\coolprop-build-vs --config Release --target CoolProp
$env:LUACOOLPROP_LIB =
  (Resolve-Path ..\coolprop-build-vs\Release\CoolProp.dll).Path
```

Some CMake versions place the DLL in a different configuration subdirectory;
locate the newly built `CoolProp.dll` under the selected build directory if
needed. In `cmd.exe`, use `set "LUACOOLPROP_LIB=C:\absolute\path\CoolProp.dll"`.

### Compile a document

Set `LUACOOLPROP_LIB` in the terminal that launches TeX, then use the engine
belonging to the document format.

LaTeX:

```sh
export LUACOOLPROP_LIB=/absolute/path/to/libCoolProp.dylib
lualatex --shell-escape myfile.tex
```

Plain TeX documents load `p-luacoolprop.tex` and use LuaTeX:

```tex
\input p-luacoolprop.tex
\pgfplotsset{compat=1.18}
\LCPPHDiagram[fluid=R134a]
\bye
```

```sh
luatex --shell-escape myfile.tex
```

ConTeXt documents select the `t-` module explicitly, because this repository
also contains the plain-TeX `p-` wrapper:

```tex
\usemodule[t][luacoolprop]
\pgfplotsset{compat=1.18}
\starttext
\LCPPHDiagram[fluid=R134a]
\stoptext
```

```sh
context --luatex --shell-escape myfile.tex
```

The `--luatex` switch selects ConTeXt MkIV. It is required because LuaCoolProp
uses the LuaTeX FFI module, which is not available in LuaMetaTeX/LMTX. Full
installation, loader diagnostics, and security guidance are in
`luacoolprop-manual.pdf`.

## Reproducible document build

The repository build exercises all three wrappers. Files named `plain-*.tex`
are built with `luatex`, files named `context-*.tex` with ConTeXt MkIV, and all
other examples plus the manual with `lualatex`. The manual build also regenerates
its separate command and key/value indexes with `makeindex`:

```sh
LUACOOLPROP_LIB=/path/to/libCoolProp.dylib ./scripts/build-examples.sh
```

Console logs are stored in `examples/logs/` and `build-logs/`; PDFs are placed
next to their sources. Sandboxed builds may set `LUACOOLPROP_TEX_CACHE` to a
writable directory for the LaTeX and plain-TeX font cache.

The manual uses the native PGF manual reference and source/result facilities.
Its diagrams execute directly during compilation; it does not import
precompiled example PDFs. Shared, input-safe definitions in `tutorial/source/`
also serve the independent teaching drivers, whose logs are stored in
`tutorial/logs/`. The complete tutorial definitions are printed in the manual.
Complete plain-TeX, ConTeXt MkIV, and Lua listings are extracted from the
manual sources and executed by `scripts/build-manual-programs.py`.
The teaching drivers include the R717 and R1234yf worksheet/solution pairs, the six-page
advanced R134a air-conditioner construction, the five-page butane PV
construction, and the six-page expert methane Linde-process correction.

To rebuild only the indexed manual and its displayed non-LaTeX programs, use
`scripts/build-examples.sh --manual-only` with the same library environment.
This mode does not require the standalone example or tutorial PDFs.
See [the documentation build guide](doc/luatex/luacoolprop/documentation-build.md) for the
validation commands, log locations, and observed engine/dependency versions.

## Distribution contents

The GitHub tree and CTAN browsing archive contain the files listed in
`MANIFEST.txt`: runtime libraries, the PDF manual and its complete sources,
usable examples and tutorial documents, README images, license notices, and
user build tools. `scripts/build-coolprop-macos.sh` builds the external native
library; `scripts/build-examples.sh` and its `build-manual-programs.py` helper
rebuild the documentation. Internal regression tests, submission tools, and
release tooling are not part of the public distribution.

The optional `luacoolprop.tds.zip` supplies the runtime, user documentation
and public build tools in their TDS locations. To rebuild the documentation,
extract the browsing archive into a writable directory; its tools use the
repository layout. Neither archive embeds CoolProp or pgfplots-autonode.
Install the independent label library separately.

Copyright (C) 2026 Christophe Jorssen. LuaCoolProp is distributed under LPPL 1.3c or later with maintenance status `maintained`.
`pgfplots-autonode` is a separate LPPL 1.3c-or-later package. CoolProp is a
separate MIT-licensed native dependency and is not included.

## Numerical cache

Numerical curves and process states can optionally be reused between builds:

```latex
\LCPSetup{cache=read-write, cache directory={build/luacoolprop-cache}}
```

The default is `cache=off`; `refresh` recomputes entries, while `read-only`
requires compatible saved data. Caching supports pure HEOS fluids and still
requires CoolProp. It preserves numerical data and process exports; PGFPlots
and the independent autonode library render each figure normally. The manual
documents invalidation, supported configuration changes and the distinction
from TikZ PDF externalization.

For reusable data, `\LCPExportDiagramTable{TS}[fluid=Water]{build/water-ts.dat}`
and `\LCPExportProcessTable{HS}[...]{build/process.dat}` write explicit PGFPlots
tables with units and provenance. Read them with `\addplot table[x=x,y=y]` and
`unbounded coords=jump`; an independent table consumer does not need CoolProp.
The manual also explains TikZ externalization for reusing complete LaTeX figures
and when native-library or preamble changes require an explicit PDF rebuild.

## Installation layout

LuaTeX is required; the shared implementation supports plain LuaTeX, LuaLaTeX
and ConTeXt MkIV (LuaTeX). Runtime files and format loaders are installed in
`tex/luatex/luacoolprop/`, with Lua modules in its `lua/` subdirectory. Copy the `tex/`
tree into a TEXMF tree; refresh the filename database / MkIV resolver cache
as required. Public documentation lives in `doc/luatex/luacoolprop/`.

The recommended CTAN archive category is `/macros/luatex/generic/luacoolprop`. TeX Live's
installation layout is separate and is controlled by its package import rules.

The source browsing archive includes complete examples and user build helpers.
See `doc/luatex/luacoolprop/documentation-build.md` for reproducible documentation builds.
Maintainer tests and release tools are kept out of the public distribution.


## Explicit components and balances

Named models also support steady-flow compressors, liquid pumps, turbines, isenthalpic valves,
heat exchange, passive pressure losses and custom components between known states. Heat and
shaft work received by the fluid are positive. Specify each machine's isentropic efficiency
and, when powers are needed, the mass flow explicitly:

```latex
\LCPDeclareModel[fluid=R134a]{machine}
\LCPDefineState{machine}{A}{T=0C,q=1}
\LCPDefineComponent{machine}{compress}[
  type=compressor,from=A,to=B,to state={p=10bar},efficiency=0.75]
\LCPBalanceSetup{mass flow=0.1} % kg/s
\edef\CompressorPower{\LCPComponentValue{machine}{compress}{work_rate}}
% \CompressorPower is in W; use \num{\CompressorPower} for display in LaTeX.
```

Use the same named-process/cycle drawing commands in any supported projection.
A nonideal compressor, pump or turbine has a dashed schematic connector: efficiency determines
its endpoints, not an interior thermodynamic path. The
[manual](doc/luatex/luacoolprop/luacoolprop-manual.pdf) includes a complete
refrigerator and a steam Rankine cycle in PH and TS, signed energy balances,
explicit exports, and the assumptions
needed to interpret entropy generation and coefficients of performance.
Heat exchangers remain isobaric by default. Use `pressure drop=0.5bar` or
`pressure ratio=0.95` to impose a loss, with either an outlet thermal property
or signed specific `heat`. A `type=pressure loss` element requires an explicit
pressure route and `thermal model=adiabatic` or `thermal model=specified heat`.
Combined heat/loss endpoints have dashed schematic connectors; no internal
pressure profile, heat-transfer law or entropy transfer is inferred.

Pumps require liquid states; turbines admit equilibrium wet outlets. These
models do not predict cavitation or wet-stage losses. Turbine work received is
negative; net delivered power subtracts pump consumption from turbine output.
