claimlink 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- claimlink-1.0.0/.github/workflows/ci.yml +41 -0
- claimlink-1.0.0/.github/workflows/release.yml +72 -0
- claimlink-1.0.0/.gitignore +7 -0
- claimlink-1.0.0/.python-version +1 -0
- claimlink-1.0.0/LICENSE +21 -0
- claimlink-1.0.0/PKG-INFO +127 -0
- claimlink-1.0.0/README.md +115 -0
- claimlink-1.0.0/docs/submission-buildstep/README.md +42 -0
- claimlink-1.0.0/docs/submission-buildstep/latexmkrc +201 -0
- claimlink-1.0.0/pyproject.toml +33 -0
- claimlink-1.0.0/src/claimlink/__init__.py +6 -0
- claimlink-1.0.0/src/claimlink/artifacts.py +191 -0
- claimlink-1.0.0/src/claimlink/cli.py +115 -0
- claimlink-1.0.0/src/claimlink/core.py +127 -0
- claimlink-1.0.0/src/claimlink/errors.py +25 -0
- claimlink-1.0.0/src/claimlink/keys.py +23 -0
- claimlink-1.0.0/src/claimlink/latex.py +622 -0
- claimlink-1.0.0/src/claimlink/location.py +163 -0
- claimlink-1.0.0/src/claimlink/nbconvert.py +43 -0
- claimlink-1.0.0/src/claimlink/serialization.py +104 -0
- claimlink-1.0.0/src/claimlink/storage.py +133 -0
- claimlink-1.0.0/tests/test_artifacts.py +502 -0
- claimlink-1.0.0/tests/test_cli.py +334 -0
- claimlink-1.0.0/tests/test_core.py +451 -0
- claimlink-1.0.0/tests/test_latex.py +621 -0
- claimlink-1.0.0/tests/test_latex_compile.py +1986 -0
- claimlink-1.0.0/tests/test_location.py +524 -0
- claimlink-1.0.0/tests/test_nbconvert.py +137 -0
- claimlink-1.0.0/tests/test_serialization.py +237 -0
- claimlink-1.0.0/tests/test_storage.py +338 -0
- claimlink-1.0.0/uv.lock +1646 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
paths-ignore:
|
|
6
|
+
- 'docs/**'
|
|
7
|
+
- '**.md'
|
|
8
|
+
pull_request:
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build-and-test:
|
|
12
|
+
name: Build & Test
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- name: Checkout code
|
|
16
|
+
uses: actions/checkout@v7
|
|
17
|
+
with:
|
|
18
|
+
fetch-depth: 0
|
|
19
|
+
|
|
20
|
+
- name: Install Python
|
|
21
|
+
uses: actions/setup-python@v7.0.0
|
|
22
|
+
with:
|
|
23
|
+
python-version: "3.13"
|
|
24
|
+
|
|
25
|
+
- name: Install uv
|
|
26
|
+
uses: astral-sh/setup-uv@v10.0.1
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: uv sync
|
|
30
|
+
|
|
31
|
+
- name: Ruff check
|
|
32
|
+
run: uv run ruff check
|
|
33
|
+
|
|
34
|
+
- name: Ruff format check
|
|
35
|
+
run: uv run ruff format --check
|
|
36
|
+
|
|
37
|
+
- name: Build
|
|
38
|
+
run: uv build
|
|
39
|
+
|
|
40
|
+
- name: Run tests
|
|
41
|
+
run: uv run pytest tests
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
name: Create Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
inputs:
|
|
6
|
+
bump:
|
|
7
|
+
description: "Version bump type"
|
|
8
|
+
required: true
|
|
9
|
+
type: choice
|
|
10
|
+
options:
|
|
11
|
+
- major
|
|
12
|
+
- minor
|
|
13
|
+
- patch
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
build-release-publish:
|
|
17
|
+
name: Build, Release, Publish
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
permissions:
|
|
20
|
+
contents: write
|
|
21
|
+
id-token: write
|
|
22
|
+
steps:
|
|
23
|
+
- name: Checkout code
|
|
24
|
+
uses: actions/checkout@v7
|
|
25
|
+
with:
|
|
26
|
+
fetch-depth: 0
|
|
27
|
+
|
|
28
|
+
- name: Install Python
|
|
29
|
+
uses: actions/setup-python@v7.0.0
|
|
30
|
+
with:
|
|
31
|
+
python-version: "3.13"
|
|
32
|
+
|
|
33
|
+
- name: Install uv
|
|
34
|
+
uses: astral-sh/setup-uv@v10.0.1
|
|
35
|
+
|
|
36
|
+
- name: Install dependencies
|
|
37
|
+
run: uv sync
|
|
38
|
+
|
|
39
|
+
- name: Run tests
|
|
40
|
+
run: uv run pytest tests
|
|
41
|
+
|
|
42
|
+
- name: Bump version
|
|
43
|
+
id: bump_version
|
|
44
|
+
env:
|
|
45
|
+
BUMP_TYPE: ${{ github.event.inputs.bump }}
|
|
46
|
+
run: echo "new_version=$(uv version --bump "$BUMP_TYPE" --short --no-sync)" >> "$GITHUB_OUTPUT"
|
|
47
|
+
|
|
48
|
+
- name: Commit, tag, and push
|
|
49
|
+
env:
|
|
50
|
+
NEW_VERSION: ${{ steps.bump_version.outputs.new_version }}
|
|
51
|
+
run: |
|
|
52
|
+
git config user.name "github-actions[bot]"
|
|
53
|
+
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
54
|
+
git add pyproject.toml
|
|
55
|
+
git add uv.lock
|
|
56
|
+
git commit -m "chore: release ${NEW_VERSION} [no ci]"
|
|
57
|
+
git tag "${NEW_VERSION}"
|
|
58
|
+
git push origin HEAD
|
|
59
|
+
git push origin "${NEW_VERSION}"
|
|
60
|
+
|
|
61
|
+
- name: Build
|
|
62
|
+
run: uv build
|
|
63
|
+
|
|
64
|
+
- name: Create GitHub release and upload artifacts
|
|
65
|
+
env:
|
|
66
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
67
|
+
NEW_VERSION: ${{ steps.bump_version.outputs.new_version }}
|
|
68
|
+
run: |
|
|
69
|
+
gh release create "${NEW_VERSION}" dist/* --title "${NEW_VERSION}" --notes "Release ${NEW_VERSION}"
|
|
70
|
+
|
|
71
|
+
- name: Publish package to PyPI
|
|
72
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
claimlink-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Simon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
claimlink-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: claimlink
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Lightweight scientific claim tracking and Python-to-LaTeX integration.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Provides-Extra: nbconvert
|
|
9
|
+
Requires-Dist: ipykernel>=7; extra == 'nbconvert'
|
|
10
|
+
Requires-Dist: nbconvert>=7; extra == 'nbconvert'
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# ClaimLink
|
|
14
|
+
|
|
15
|
+
Ensure scientific claims in Python and LaTeX stay in sync, without copying numbers by hand.
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from claimlink import claim
|
|
19
|
+
|
|
20
|
+
papers = load_papers()
|
|
21
|
+
|
|
22
|
+
claim(
|
|
23
|
+
"number of analyzed papers",
|
|
24
|
+
len(papers),
|
|
25
|
+
unit="papers",
|
|
26
|
+
description="Total number of papers included in the analysis.",
|
|
27
|
+
)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Calling `claim(...)` records the value, optionally the unit and description, the caller's source location and a timestamp in `claim-lock.json`. Re-running with a changed value updates the file and emits a warning.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install claimlink
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Export to LaTeX
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
claimlink export
|
|
42
|
+
claimlink export --input claim-lock.json --output ../Paper
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
ClaimLink writes `claimlink/claims.tex`, `claimlink/figures/` and `claimlink/tables/` into the `--output`-Directory. `claims.tex` is overwritten on every export and defines one `\csname` block per claim plus a small runtime:
|
|
46
|
+
|
|
47
|
+
Commit `claim-lock.json` and treat `claimlink/` as generated.
|
|
48
|
+
|
|
49
|
+
In your paper you can then use the claims like this:
|
|
50
|
+
|
|
51
|
+
```latex
|
|
52
|
+
\input{claimlink/claims.tex}
|
|
53
|
+
|
|
54
|
+
The analysis includes \clv{number-of-analyzed-papers} papers.
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
If your publisher requires a flattened submission with no macros or `\input` in the paper, [`docs/submission-buildstep/`](docs/submission-buildstep/README.md) shows a `latexmkrc` that builds the PDF from a generated single-file copy while the source keeps the claim commands.
|
|
58
|
+
|
|
59
|
+
## Figures and tables
|
|
60
|
+
|
|
61
|
+
Pass figure or table objects to `artifact()`. ClaimLink saves them next to the lock and records their path, description, source location, hash and size.
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from claimlink import artifact
|
|
65
|
+
|
|
66
|
+
fig, ax = plt.subplots()
|
|
67
|
+
ax.plot(epochs, loss)
|
|
68
|
+
artifact("training loss", fig, bbox_inches="tight")
|
|
69
|
+
# artifacts/training-loss.pdf
|
|
70
|
+
|
|
71
|
+
artifact("main results", df, index=False, float_format="%.2f")
|
|
72
|
+
# artifacts/main-results.tex
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Supported payloads are objects with `savefig`, `write_image`, `to_latex` or `save`, plus raw LaTeX strings. `description` is ClaimLink metadata, all other keywords are forwarded to the saver, except `format`, which selects the filename suffix. Use them in LaTeX:
|
|
76
|
+
|
|
77
|
+
```latex
|
|
78
|
+
\clfig[width=\linewidth]{training-loss} % in a figure float
|
|
79
|
+
\cltab{main-results} % in a table float
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Keys and commands
|
|
83
|
+
|
|
84
|
+
Keys are derived from claim names; names that map to the same key abort the export.
|
|
85
|
+
|
|
86
|
+
| Command | Effect |
|
|
87
|
+
| ---------------------------------------------- | --------------------------------------------------------------------- |
|
|
88
|
+
| `\clv{key}`, `\clunit{key}`, `\cldesc{key}` | Print the value, unit, or description and record the use. |
|
|
89
|
+
| `\clv*{key}`, `\clunit*{key}`, `\cldesc*{key}` | Print only: no record, anchor, or usage row. For titles and captions. |
|
|
90
|
+
| `\clcite{key}` | Print nothing and record a `cite` use. |
|
|
91
|
+
| `\clvalue{key}` | Expandable integer/plain-decimal accessor that records nothing. |
|
|
92
|
+
|
|
93
|
+
`\clvalue` handles only integers and plain decimals and records no usage, so pair it with `\clcite` when the occurrence should be recorded:
|
|
94
|
+
|
|
95
|
+
```latex
|
|
96
|
+
\clcite{retained-findings}\num{\clvalue{retained-findings}}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Claims and usage tables
|
|
100
|
+
|
|
101
|
+
```latex
|
|
102
|
+
\cltable % tabular, inside a float
|
|
103
|
+
\cltable* % longtable, spans pages, outside floats
|
|
104
|
+
\clusage % usage table built from the previous pass
|
|
105
|
+
\clusage* % longtable usage table
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Each compile writes `<jobname>.clmdata` in the LaTeX build directory. Print usage tables from any of those files with no extra CLI step (e.g. for both the main paper and the supplement):
|
|
109
|
+
|
|
110
|
+
```latex
|
|
111
|
+
\usepackage{longtable} % required by both commands
|
|
112
|
+
|
|
113
|
+
\claimlinkusagefile{main} % rows written by main.tex
|
|
114
|
+
\claimlinkusageself % rows written by this document
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Notebooks with nbconvert
|
|
118
|
+
|
|
119
|
+
JupyterLab works with no extra setup. A plain `jupyter nbconvert --execute` however does not tell the kernel which notebook or cell it runs, so use our bundled preprocessor instead:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
pip install "claimlink[nbconvert]"
|
|
123
|
+
|
|
124
|
+
jupyter nbconvert --to notebook \
|
|
125
|
+
--Exporter.preprocessors=claimlink.nbconvert.ClaimLinkPreprocessor \
|
|
126
|
+
paper.ipynb
|
|
127
|
+
```
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# ClaimLink
|
|
2
|
+
|
|
3
|
+
Ensure scientific claims in Python and LaTeX stay in sync, without copying numbers by hand.
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
from claimlink import claim
|
|
7
|
+
|
|
8
|
+
papers = load_papers()
|
|
9
|
+
|
|
10
|
+
claim(
|
|
11
|
+
"number of analyzed papers",
|
|
12
|
+
len(papers),
|
|
13
|
+
unit="papers",
|
|
14
|
+
description="Total number of papers included in the analysis.",
|
|
15
|
+
)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Calling `claim(...)` records the value, optionally the unit and description, the caller's source location and a timestamp in `claim-lock.json`. Re-running with a changed value updates the file and emits a warning.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install claimlink
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Export to LaTeX
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
claimlink export
|
|
30
|
+
claimlink export --input claim-lock.json --output ../Paper
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
ClaimLink writes `claimlink/claims.tex`, `claimlink/figures/` and `claimlink/tables/` into the `--output`-Directory. `claims.tex` is overwritten on every export and defines one `\csname` block per claim plus a small runtime:
|
|
34
|
+
|
|
35
|
+
Commit `claim-lock.json` and treat `claimlink/` as generated.
|
|
36
|
+
|
|
37
|
+
In your paper you can then use the claims like this:
|
|
38
|
+
|
|
39
|
+
```latex
|
|
40
|
+
\input{claimlink/claims.tex}
|
|
41
|
+
|
|
42
|
+
The analysis includes \clv{number-of-analyzed-papers} papers.
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
If your publisher requires a flattened submission with no macros or `\input` in the paper, [`docs/submission-buildstep/`](docs/submission-buildstep/README.md) shows a `latexmkrc` that builds the PDF from a generated single-file copy while the source keeps the claim commands.
|
|
46
|
+
|
|
47
|
+
## Figures and tables
|
|
48
|
+
|
|
49
|
+
Pass figure or table objects to `artifact()`. ClaimLink saves them next to the lock and records their path, description, source location, hash and size.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from claimlink import artifact
|
|
53
|
+
|
|
54
|
+
fig, ax = plt.subplots()
|
|
55
|
+
ax.plot(epochs, loss)
|
|
56
|
+
artifact("training loss", fig, bbox_inches="tight")
|
|
57
|
+
# artifacts/training-loss.pdf
|
|
58
|
+
|
|
59
|
+
artifact("main results", df, index=False, float_format="%.2f")
|
|
60
|
+
# artifacts/main-results.tex
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Supported payloads are objects with `savefig`, `write_image`, `to_latex` or `save`, plus raw LaTeX strings. `description` is ClaimLink metadata, all other keywords are forwarded to the saver, except `format`, which selects the filename suffix. Use them in LaTeX:
|
|
64
|
+
|
|
65
|
+
```latex
|
|
66
|
+
\clfig[width=\linewidth]{training-loss} % in a figure float
|
|
67
|
+
\cltab{main-results} % in a table float
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Keys and commands
|
|
71
|
+
|
|
72
|
+
Keys are derived from claim names; names that map to the same key abort the export.
|
|
73
|
+
|
|
74
|
+
| Command | Effect |
|
|
75
|
+
| ---------------------------------------------- | --------------------------------------------------------------------- |
|
|
76
|
+
| `\clv{key}`, `\clunit{key}`, `\cldesc{key}` | Print the value, unit, or description and record the use. |
|
|
77
|
+
| `\clv*{key}`, `\clunit*{key}`, `\cldesc*{key}` | Print only: no record, anchor, or usage row. For titles and captions. |
|
|
78
|
+
| `\clcite{key}` | Print nothing and record a `cite` use. |
|
|
79
|
+
| `\clvalue{key}` | Expandable integer/plain-decimal accessor that records nothing. |
|
|
80
|
+
|
|
81
|
+
`\clvalue` handles only integers and plain decimals and records no usage, so pair it with `\clcite` when the occurrence should be recorded:
|
|
82
|
+
|
|
83
|
+
```latex
|
|
84
|
+
\clcite{retained-findings}\num{\clvalue{retained-findings}}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Claims and usage tables
|
|
88
|
+
|
|
89
|
+
```latex
|
|
90
|
+
\cltable % tabular, inside a float
|
|
91
|
+
\cltable* % longtable, spans pages, outside floats
|
|
92
|
+
\clusage % usage table built from the previous pass
|
|
93
|
+
\clusage* % longtable usage table
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Each compile writes `<jobname>.clmdata` in the LaTeX build directory. Print usage tables from any of those files with no extra CLI step (e.g. for both the main paper and the supplement):
|
|
97
|
+
|
|
98
|
+
```latex
|
|
99
|
+
\usepackage{longtable} % required by both commands
|
|
100
|
+
|
|
101
|
+
\claimlinkusagefile{main} % rows written by main.tex
|
|
102
|
+
\claimlinkusageself % rows written by this document
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Notebooks with nbconvert
|
|
106
|
+
|
|
107
|
+
JupyterLab works with no extra setup. A plain `jupyter nbconvert --execute` however does not tell the kernel which notebook or cell it runs, so use our bundled preprocessor instead:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
pip install "claimlink[nbconvert]"
|
|
111
|
+
|
|
112
|
+
jupyter nbconvert --to notebook \
|
|
113
|
+
--Exporter.preprocessors=claimlink.nbconvert.ClaimLinkPreprocessor \
|
|
114
|
+
paper.ipynb
|
|
115
|
+
```
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Submission buildstep
|
|
2
|
+
|
|
3
|
+
Copy [`latexmkrc`](latexmkrc) into the project root. Then every `latexmk` build of the main file (including Overleaf) compiles the paper from a flattened, submission-ready copy in `build/`. The PDF you see is the PDF built from the source you submit.
|
|
4
|
+
|
|
5
|
+
Adjust `$main` at the top of the hook if your main file is not `paper.tex`; the flat copy is `build/paper.tex` and the root PDF is `<main-stem>.pdf` (`paper.pdf`).
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
claimlink export --input claim-lock.json --output .
|
|
9
|
+
latexmk -pdf paper.tex
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The first command writes `claimlink/claims.tex`, `claimlink/figures/` and `claimlink/tables/`. Those files must be present when you build; commit the generated `claimlink/` tree if you build on Overleaf.
|
|
13
|
+
|
|
14
|
+
## What the hook produces
|
|
15
|
+
|
|
16
|
+
On every main build `build/` is wiped and recreated, so nothing stale survives. It then contains:
|
|
17
|
+
|
|
18
|
+
- the flattened `<main-stem>.tex` with `\includegraphics{<basename>}` calls
|
|
19
|
+
- every figure used by `\clfig`, copied flat as `<basename>`
|
|
20
|
+
- the class from `\documentclass` (if the `.cls` is in the project root)
|
|
21
|
+
- custom `.sty`, `.bst` and `.bib` files from the project root, plus the generated `<main-stem>.bbl`
|
|
22
|
+
- the PDF and aux files, because latexmk compiles inside `build/`
|
|
23
|
+
|
|
24
|
+
The hook copies `build/<main-stem>.pdf` to `<main-stem>.pdf` in the project root after a successful build, so Overleaf shows the PDF even though it hides `build/`. The old root PDF is removed when a main build starts, so a failed build cannot leave a stale PDF visible.
|
|
25
|
+
|
|
26
|
+
## Usage data
|
|
27
|
+
|
|
28
|
+
The ClaimLinks usage table commands (`\cltable`, `\clusage`, `\claimlinkusagefile` and `\claimlinkusageself`) need the runtime and a previous LaTeX pass. Put them into a supplement.
|
|
29
|
+
|
|
30
|
+
When a build includes `supplement.tex`, the hook first builds the source main in a `File::Temp` directory outside `build/` to record `claimusage.clmdata`, copies it to `<main-stem>.clmdata`, and removes the temp directory. There is no `build/usage`. The build fails if that source build, the copy, or a `\claimlinkusagefile{...}` data file referenced by the supplement is missing.
|
|
31
|
+
|
|
32
|
+
The hook touches only ClaimLink commands and `claimlink/` paths:
|
|
33
|
+
|
|
34
|
+
- `\clv`, `\clvalue` become their values; `\clunit`/`\cldesc` add the optional unit or description
|
|
35
|
+
- `\clcite` is removed after checking that the key exists
|
|
36
|
+
- `\clfig[opts]{key}` becomes `\includegraphics[opts]{<basename>}`
|
|
37
|
+
- `\cltab{key}` inlines the flattened table artifact
|
|
38
|
+
- every `\input{claimlink/claims.tex}` is removed
|
|
39
|
+
|
|
40
|
+
Unknown keys and unhandled ClaimLink commands stop the build with an error.
|
|
41
|
+
|
|
42
|
+
Because the main compiles in `build/` and the supplement in the project root, build them in separate `latexmk` invocations, one line per file in your `Makefile`.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# Build the paper from a flattened ClaimLink copy. This runs on every latexmk
|
|
2
|
+
# build, including Overleaf, so the PDF you see is built from the source you
|
|
3
|
+
# submit. Only \cl... commands and claimlink/ paths are touched.
|
|
4
|
+
# The supplement is built from source because it prints runtime usage tables.
|
|
5
|
+
|
|
6
|
+
$pdf_mode = 1; # a bare `latexmk` still uses pdflatex and writes a PDF
|
|
7
|
+
$do_cd = 1; # compile inside build/, where the flat copy lives
|
|
8
|
+
|
|
9
|
+
use File::Basename qw(basename dirname);
|
|
10
|
+
use File::Path qw(make_path remove_tree);
|
|
11
|
+
use File::Copy qw(copy);
|
|
12
|
+
use File::Temp qw(tempdir);
|
|
13
|
+
use Cwd qw(getcwd);
|
|
14
|
+
use File::Spec;
|
|
15
|
+
|
|
16
|
+
my $main = 'paper.tex';
|
|
17
|
+
my $stem = basename($main, '.tex');
|
|
18
|
+
my $claims = 'claimlink/claims.tex';
|
|
19
|
+
my $flat = 'build/paper.tex';
|
|
20
|
+
|
|
21
|
+
my %value; # kind -> key -> value
|
|
22
|
+
my %path; # key -> claimlink path
|
|
23
|
+
my %figure; # every figure key used by \clfig
|
|
24
|
+
|
|
25
|
+
sub strip_comment {
|
|
26
|
+
my ($line) = @_;
|
|
27
|
+
my $pos = 0;
|
|
28
|
+
while (($pos = index($line, '%', $pos)) >= 0) {
|
|
29
|
+
my ($n, $i) = (0, $pos - 1);
|
|
30
|
+
while ($i >= 0 && substr($line, $i, 1) eq '\\') { $n++; $i--; }
|
|
31
|
+
return (substr($line, 0, $pos), substr($line, $pos)) if $n % 2 == 0;
|
|
32
|
+
$pos++;
|
|
33
|
+
}
|
|
34
|
+
return ($line, '');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
sub read_claims {
|
|
38
|
+
open my $cf, '<', $claims or die "flatten: $claims: $!";
|
|
39
|
+
while (<$cf>) {
|
|
40
|
+
$value{$1}{$2} = $3
|
|
41
|
+
if /^\\expandafter\\def\\csname (clv|clunit|cldesc)\@([^\\\s]+)\\endcsname\{(.*)\}\s*$/;
|
|
42
|
+
$path{$1} = $2
|
|
43
|
+
if /^\\expandafter\\def\\csname clpath\@([^\\\s]+)\\endcsname\{(.*)\}\s*$/;
|
|
44
|
+
}
|
|
45
|
+
close $cf;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
sub flatten_table {
|
|
49
|
+
my ($file) = @_;
|
|
50
|
+
open my $tf, '<', $file or die "flatten: $file: $!";
|
|
51
|
+
my $tex = do { local $/; <$tf> };
|
|
52
|
+
close $tf;
|
|
53
|
+
return flatten_text($tex, $file);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
sub flatten_text {
|
|
57
|
+
my ($tex, $src) = @_;
|
|
58
|
+
|
|
59
|
+
$tex =~ s{\\input\{\Q$claims\E\}}{}g;
|
|
60
|
+
|
|
61
|
+
my @lines;
|
|
62
|
+
for my $line (split /(?<=\n)/, $tex) {
|
|
63
|
+
my ($code, $comment) = strip_comment($line);
|
|
64
|
+
$code =~ s/\\clcite\{([^}]*)\}/
|
|
65
|
+
exists $value{clv}{$1} || exists $path{$1}
|
|
66
|
+
? ""
|
|
67
|
+
: die "flatten: unknown key '$1' in \\clcite in $src\n"
|
|
68
|
+
/ge;
|
|
69
|
+
$code =~ s/\\(?:clvalue|clv)\*?\{([^}]*)\}/
|
|
70
|
+
exists $value{clv}{$1}
|
|
71
|
+
? $value{clv}{$1}
|
|
72
|
+
: die "flatten: unknown claim key '$1' in $src\n"
|
|
73
|
+
/ge;
|
|
74
|
+
$code =~ s/\\clunit\*?\{([^}]*)\}/
|
|
75
|
+
exists $value{clv}{$1}
|
|
76
|
+
? (exists $value{clunit}{$1} ? $value{clunit}{$1} : "")
|
|
77
|
+
: die "flatten: unknown claim key '$1' in \\clunit in $src\n"
|
|
78
|
+
/ge;
|
|
79
|
+
$code =~ s/\\cldesc\*?\{([^}]*)\}/
|
|
80
|
+
exists $value{clv}{$1}
|
|
81
|
+
? (exists $value{cldesc}{$1} ? $value{cldesc}{$1} : "")
|
|
82
|
+
: die "flatten: unknown claim key '$1' in \\cldesc in $src\n"
|
|
83
|
+
/ge;
|
|
84
|
+
$code =~ s!\\clfig\*?(?:\[([^\]]*)\])?\{([^}]*)\}!{
|
|
85
|
+
my ($opts, $key) = ($1, $2);
|
|
86
|
+
die "flatten: unknown artifact key '$key' in $src\n"
|
|
87
|
+
unless exists $path{$key};
|
|
88
|
+
$figure{$key} = 1;
|
|
89
|
+
"\\includegraphics" . (defined $opts ? "[$opts]" : "")
|
|
90
|
+
. "{" . basename($path{$key}) . "}"
|
|
91
|
+
}!ge;
|
|
92
|
+
die "flatten: unhandled ClaimLink command \\$1 in $src\n"
|
|
93
|
+
if $code =~ /\\(clv|clvalue|clcite|clunit|cldesc|cltable|clusage|clfig|claimlinkusagefile|claimlinkusageself)\b/;
|
|
94
|
+
# \cltab content is already flattened, so its comments are final text
|
|
95
|
+
# and must not be scanned by the guard above.
|
|
96
|
+
$code =~ s!\\cltab\{([^}]*)\}!{
|
|
97
|
+
my $key = $1;
|
|
98
|
+
exists $path{$key}
|
|
99
|
+
? flatten_table($path{$key})
|
|
100
|
+
: die "flatten: unknown artifact key '$key' in $src\n"
|
|
101
|
+
}!ge;
|
|
102
|
+
push @lines, $code . $comment;
|
|
103
|
+
}
|
|
104
|
+
return join '', @lines;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
sub flatten_claims {
|
|
108
|
+
my ($src, $dst) = @_;
|
|
109
|
+
read_claims();
|
|
110
|
+
|
|
111
|
+
open my $sf, '<', $src or die "flatten: $src: $!";
|
|
112
|
+
my $tex = do { local $/; <$sf> };
|
|
113
|
+
close $sf;
|
|
114
|
+
|
|
115
|
+
$tex = flatten_text($tex, $src);
|
|
116
|
+
|
|
117
|
+
make_path(dirname($dst));
|
|
118
|
+
open my $of, '>', $dst or die "flatten: $dst: $!";
|
|
119
|
+
print $of $tex;
|
|
120
|
+
close $of;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
sub copy_flat {
|
|
124
|
+
my ($src) = @_;
|
|
125
|
+
return unless -f $src;
|
|
126
|
+
copy($src, 'build/' . basename($src))
|
|
127
|
+
or die "latexmkrc: cannot copy $src: $!\n";
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
# Everything the flat copy references must sit next to it in build/.
|
|
131
|
+
sub copy_support {
|
|
132
|
+
my ($src) = @_;
|
|
133
|
+
open my $sf, '<', $src or die "latexmkrc: $src: $!\n";
|
|
134
|
+
my $tex = do { local $/; <$sf> };
|
|
135
|
+
close $sf;
|
|
136
|
+
$tex = join '', map { (strip_comment($_))[0] } split /(?<=\n)/, $tex;
|
|
137
|
+
|
|
138
|
+
if ($tex =~ /\\documentclass(?:\[[^\]]*\])?\{([^}]*)\}/) {
|
|
139
|
+
copy_flat("$1.cls");
|
|
140
|
+
}
|
|
141
|
+
copy_flat($_) for glob('*.sty');
|
|
142
|
+
copy_flat("$1.bst") while $tex =~ /\\bibliographystyle\{([^}]*)\}/g;
|
|
143
|
+
while ($tex =~ /\\bibliography\{([^}]*)\}/g) {
|
|
144
|
+
copy_flat("$_.bib") for split /\s*,\s*/, $1;
|
|
145
|
+
}
|
|
146
|
+
copy_flat($path{$_}) for keys %figure;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
my $clean = grep { /^-[cC]$/ } @ARGV;
|
|
150
|
+
my $main_build = 0;
|
|
151
|
+
|
|
152
|
+
# Clean must work without a generated claimlink/ tree and without the flat copy.
|
|
153
|
+
unless ($ENV{CLAIMLINK_SOURCE_BUILD} || $clean) {
|
|
154
|
+
push @ARGV, $main unless grep { !/^-/ } @ARGV;
|
|
155
|
+
@ARGV = map {
|
|
156
|
+
if (!/^-/ && basename($_) eq $main && $_ ne $flat) {
|
|
157
|
+
$main_build = 1;
|
|
158
|
+
$flat;
|
|
159
|
+
} else {
|
|
160
|
+
$_;
|
|
161
|
+
}
|
|
162
|
+
} @ARGV;
|
|
163
|
+
|
|
164
|
+
if ($main_build) {
|
|
165
|
+
# A failed build must not leave an old root PDF on display.
|
|
166
|
+
remove_tree('build');
|
|
167
|
+
make_path('build');
|
|
168
|
+
unlink "$stem.pdf";
|
|
169
|
+
my $abs_root = getcwd();
|
|
170
|
+
my $abs_build = File::Spec->rel2abs('build');
|
|
171
|
+
$success_cmd = "cp -f '$abs_build/$stem.pdf' '$abs_root/$stem.pdf'";
|
|
172
|
+
flatten_claims($main, $flat);
|
|
173
|
+
copy_support($main);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
# $success_cmd copies the flat PDF to the project root for Overleaf.
|
|
178
|
+
|
|
179
|
+
if (!$clean && grep { m{(^|/)supplement\.tex$} } @ARGV) {
|
|
180
|
+
# The supplement prints the main paper's usage table, which only the source
|
|
181
|
+
# (with the ClaimLink runtime) records. Build it separately for the data.
|
|
182
|
+
my $tmp = tempdir('claimlink-usage-XXXXXX', TMPDIR => 1, CLEANUP => 1);
|
|
183
|
+
local $ENV{CLAIMLINK_SOURCE_BUILD} = 1;
|
|
184
|
+
system('latexmk', '-pdf', '-interaction=nonstopmode', '-halt-on-error',
|
|
185
|
+
'-jobname=claimusage', "-outdir=$tmp", $main)
|
|
186
|
+
and die "latexmkrc: main paper build failed, the supplement needs its usage data\n";
|
|
187
|
+
my $usage = "$stem.clmdata";
|
|
188
|
+
copy("$tmp/claimusage.clmdata", $usage)
|
|
189
|
+
or die "latexmkrc: could not copy claim usage data: $!\n";
|
|
190
|
+
die "latexmkrc: $usage missing after main paper build\n" unless -f $usage;
|
|
191
|
+
|
|
192
|
+
open my $sf, '<', 'supplement.tex' or die "latexmkrc: supplement.tex: $!\n";
|
|
193
|
+
while (<$sf>) {
|
|
194
|
+
my ($code) = strip_comment($_);
|
|
195
|
+
next unless $code =~ /\\claimlinkusagefile\{([^}]*)\}/;
|
|
196
|
+
my $name = $1;
|
|
197
|
+
die "latexmkrc: supplement references \\claimlinkusagefile{$name} but $name.clmdata is missing\n"
|
|
198
|
+
unless -f "$name.clmdata";
|
|
199
|
+
}
|
|
200
|
+
close $sf;
|
|
201
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "claimlink"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "Lightweight scientific claim tracking and Python-to-LaTeX integration."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.10"
|
|
9
|
+
dependencies = []
|
|
10
|
+
|
|
11
|
+
[project.scripts]
|
|
12
|
+
claimlink = "claimlink.cli:main"
|
|
13
|
+
|
|
14
|
+
[project.optional-dependencies]
|
|
15
|
+
nbconvert = ["nbconvert>=7", "ipykernel>=7"]
|
|
16
|
+
|
|
17
|
+
[build-system]
|
|
18
|
+
requires = ["hatchling"]
|
|
19
|
+
build-backend = "hatchling.build"
|
|
20
|
+
|
|
21
|
+
[tool.hatch.build.targets.wheel]
|
|
22
|
+
packages = ["src/claimlink"]
|
|
23
|
+
|
|
24
|
+
[tool.pytest.ini_options]
|
|
25
|
+
testpaths = ["tests"]
|
|
26
|
+
|
|
27
|
+
[dependency-groups]
|
|
28
|
+
dev = [
|
|
29
|
+
"ipykernel>=7.3.0",
|
|
30
|
+
"nbconvert>=7.17.2",
|
|
31
|
+
"pytest>=9.2.0",
|
|
32
|
+
"ruff>=0.17.6",
|
|
33
|
+
]
|