Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ repos:
- id: no-space-in-cite
- id: tilde-cite
- id: unique-labels
# args:
# [
# # If present only check for uniqueness within each file.
# # Can be useful if a repository contains multiple main files.
# "--individual",
# ]
- id: cleveref-instead-of-autoref
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
Expand Down
10 changes: 9 additions & 1 deletion latexhooks/unique_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ def search(files: t.List[t.IO[str]]) -> bool:

def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
"--individual",
action="store_true",
help="Allow duplicate labels if they are in different files",
)
parser.add_argument(
"files",
metavar="FILE",
Expand All @@ -90,7 +95,10 @@ def main() -> None:
args = parser.parse_args()

files = sorted(args.files, key=lambda f: f.name)
found_multiple_definitions = search(files)
if args.individual:
found_multiple_definitions = any(search([f]) for f in files)
else:
found_multiple_definitions = search(files)
if found_multiple_definitions:
sys.exit("Found multiple definitions of the same label")

Expand Down