From 95a483c2de588e66c783ce42321ade33052218db Mon Sep 17 00:00:00 2001 From: Florian Lercher <florian.lercher@tum.de> Date: Fri, 4 Aug 2023 17:19:21 +0200 Subject: [PATCH 1/3] Ignore commented cites --- bibliography_cleaner/prepare_bib_for_publication.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bibliography_cleaner/prepare_bib_for_publication.py b/bibliography_cleaner/prepare_bib_for_publication.py index 2024dbe..f6431f9 100644 --- a/bibliography_cleaner/prepare_bib_for_publication.py +++ b/bibliography_cleaner/prepare_bib_for_publication.py @@ -290,7 +290,8 @@ def get_cite_keys_from_tex(tex_src: Path) -> Tuple[str]: cite_keys = set() for fl in files: with fl.open('r') as f: - content = f.read() + # regex r'(?<!\\)%' matches % not preceded by a backslash + content = '\n'.join(re.split(r'(?<!\\)%', line)[0] for line in f) cite_keys.update(re.findall(r'\\cite\{([^}]+)}', content)) for cite_key in tuple(cite_keys): -- GitLab From 3858f18fb79a0ae38a62d492944df3286c42f4c9 Mon Sep 17 00:00:00 2001 From: Florian Lercher <florian.lercher@tum.de> Date: Fri, 4 Aug 2023 17:19:35 +0200 Subject: [PATCH 2/3] Match cites with optional parameter --- bibliography_cleaner/prepare_bib_for_publication.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bibliography_cleaner/prepare_bib_for_publication.py b/bibliography_cleaner/prepare_bib_for_publication.py index f6431f9..006bdc4 100644 --- a/bibliography_cleaner/prepare_bib_for_publication.py +++ b/bibliography_cleaner/prepare_bib_for_publication.py @@ -293,6 +293,7 @@ def get_cite_keys_from_tex(tex_src: Path) -> Tuple[str]: # regex r'(?<!\\)%' matches % not preceded by a backslash content = '\n'.join(re.split(r'(?<!\\)%', line)[0] for line in f) cite_keys.update(re.findall(r'\\cite\{([^}]+)}', content)) + cite_keys.update(re.findall(r'\\cite(?:\[[^]]*])?\{([^}]+)}', content)) for cite_key in tuple(cite_keys): if ',' in cite_key: -- GitLab From fee15809fc8cbf2732211716d7aa7c72e926d628 Mon Sep 17 00:00:00 2001 From: Florian Lercher <florian.lercher@tum.de> Date: Mon, 7 Aug 2023 10:56:24 +0200 Subject: [PATCH 3/3] Add contribution to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4e08b6b..8d95df2 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ For questions, reach out to [Jonathan](mailto:jonathan.kuelz@tum.de). ## Contributors - [Jakob Thumm](mailto:jakob.thumm@tum.de): Proceeding abbreviations - [Luis Gressenbuch](mailto:luis.gressenbuch@tum.de): Pip packaging +- [Florian Lercher](mailto:florian.lercher@tum.de): Improved cite key extraction ## How to use The CLI help should be sufficient: `python prepare_bib_for_publication.py -h` -- GitLab