arxiv-to-prompt 0.4.1__py3-none-any.whl → 0.5.1__py3-none-any.whl
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.
- arxiv_to_prompt/__init__.py +3 -1
- arxiv_to_prompt/cli.py +31 -3
- arxiv_to_prompt/core.py +68 -25
- {arxiv_to_prompt-0.4.1.dist-info → arxiv_to_prompt-0.5.1.dist-info}/METADATA +7 -1
- arxiv_to_prompt-0.5.1.dist-info/RECORD +9 -0
- arxiv_to_prompt-0.4.1.dist-info/RECORD +0 -9
- {arxiv_to_prompt-0.4.1.dist-info → arxiv_to_prompt-0.5.1.dist-info}/WHEEL +0 -0
- {arxiv_to_prompt-0.4.1.dist-info → arxiv_to_prompt-0.5.1.dist-info}/entry_points.txt +0 -0
- {arxiv_to_prompt-0.4.1.dist-info → arxiv_to_prompt-0.5.1.dist-info}/licenses/LICENSE +0 -0
- {arxiv_to_prompt-0.4.1.dist-info → arxiv_to_prompt-0.5.1.dist-info}/top_level.txt +0 -0
arxiv_to_prompt/__init__.py
CHANGED
|
@@ -15,7 +15,7 @@ Example:
|
|
|
15
15
|
>>> latex_source = process_latex_source(local_folder="/path/to/tex/files")
|
|
16
16
|
"""
|
|
17
17
|
|
|
18
|
-
from .core import process_latex_source, download_arxiv_source, get_default_cache_dir
|
|
18
|
+
from .core import process_latex_source, download_arxiv_source, get_default_cache_dir, list_sections, extract_section
|
|
19
19
|
|
|
20
20
|
# Import version from package metadata
|
|
21
21
|
try:
|
|
@@ -32,5 +32,7 @@ __all__ = [
|
|
|
32
32
|
"process_latex_source",
|
|
33
33
|
"download_arxiv_source",
|
|
34
34
|
"get_default_cache_dir",
|
|
35
|
+
"list_sections",
|
|
36
|
+
"extract_section",
|
|
35
37
|
"__version__",
|
|
36
38
|
]
|
arxiv_to_prompt/cli.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import argparse
|
|
2
2
|
import re
|
|
3
|
-
from .core import process_latex_source, get_default_cache_dir
|
|
3
|
+
from .core import process_latex_source, get_default_cache_dir, list_sections, extract_section
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
def extract_arxiv_id(input_str: str) -> str:
|
|
@@ -45,7 +45,18 @@ def main():
|
|
|
45
45
|
help="Path to a local folder containing TeX files (alternative to arxiv_id)",
|
|
46
46
|
default=None
|
|
47
47
|
)
|
|
48
|
-
|
|
48
|
+
parser.add_argument(
|
|
49
|
+
"--list-sections",
|
|
50
|
+
action="store_true",
|
|
51
|
+
help="List all section names in the document"
|
|
52
|
+
)
|
|
53
|
+
parser.add_argument(
|
|
54
|
+
"--section",
|
|
55
|
+
type=str,
|
|
56
|
+
action="append",
|
|
57
|
+
help="Extract only the specified section(s). Can be used multiple times."
|
|
58
|
+
)
|
|
59
|
+
|
|
49
60
|
args = parser.parse_args()
|
|
50
61
|
|
|
51
62
|
# Validate that either arxiv_id or local_folder is provided
|
|
@@ -64,7 +75,24 @@ def main():
|
|
|
64
75
|
remove_appendix_section=args.no_appendix,
|
|
65
76
|
local_folder=args.local_folder
|
|
66
77
|
)
|
|
67
|
-
if content:
|
|
78
|
+
if not content:
|
|
79
|
+
return
|
|
80
|
+
|
|
81
|
+
if args.list_sections:
|
|
82
|
+
sections = list_sections(content)
|
|
83
|
+
for section in sections:
|
|
84
|
+
print(section)
|
|
85
|
+
elif args.section:
|
|
86
|
+
extracted = []
|
|
87
|
+
for section_name in args.section:
|
|
88
|
+
section_content = extract_section(content, section_name)
|
|
89
|
+
if section_content:
|
|
90
|
+
extracted.append(section_content)
|
|
91
|
+
else:
|
|
92
|
+
print(f"Warning: Section '{section_name}' not found", file=__import__('sys').stderr)
|
|
93
|
+
if extracted:
|
|
94
|
+
print("\n\n".join(extracted))
|
|
95
|
+
else:
|
|
68
96
|
print(content)
|
|
69
97
|
|
|
70
98
|
if __name__ == "__main__":
|
arxiv_to_prompt/core.py
CHANGED
|
@@ -92,40 +92,55 @@ def download_arxiv_source(arxiv_id: str, cache_dir: Optional[str] = None, use_ca
|
|
|
92
92
|
|
|
93
93
|
def find_main_tex(directory: str) -> Optional[str]:
|
|
94
94
|
"""
|
|
95
|
-
Find the main .tex file containing documentclass.
|
|
95
|
+
Find the main .tex file containing documentclass.
|
|
96
|
+
Searches recursively through subdirectories.
|
|
96
97
|
First checks for common naming conventions (main.tex, paper.tex, index.tex).
|
|
97
|
-
If none found, returns the
|
|
98
|
-
since shorter files are typically conference templates or supplementary documents
|
|
98
|
+
If none found, returns the path of the longest .tex file containing documentclass,
|
|
99
|
+
since shorter files are typically conference templates or supplementary documents
|
|
99
100
|
rather than the main manuscript.
|
|
100
101
|
"""
|
|
101
102
|
common_names = ['main.tex', 'paper.tex', 'index.tex']
|
|
102
103
|
main_tex_file = None
|
|
103
104
|
max_line_count = 0
|
|
104
105
|
|
|
105
|
-
#
|
|
106
|
-
for
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
106
|
+
# Walk through directory and subdirectories
|
|
107
|
+
for root, dirs, files in os.walk(directory):
|
|
108
|
+
rel_root = os.path.relpath(root, directory)
|
|
109
|
+
|
|
110
|
+
# First pass: check for common naming conventions
|
|
111
|
+
for file_name in files:
|
|
112
|
+
if file_name in common_names:
|
|
113
|
+
file_path = os.path.join(root, file_name)
|
|
114
|
+
try:
|
|
115
|
+
with open(file_path, 'r', encoding='utf-8') as file:
|
|
116
|
+
lines = file.readlines()
|
|
117
|
+
if any('\\documentclass' in line for line in lines):
|
|
118
|
+
if rel_root == '.':
|
|
119
|
+
return file_name
|
|
120
|
+
return os.path.join(rel_root, file_name)
|
|
121
|
+
except Exception as e:
|
|
122
|
+
logging.warning(f"Could not read file {file_path}: {e}")
|
|
115
123
|
|
|
116
124
|
# Second pass: find the longest .tex file containing documentclass
|
|
117
|
-
for
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
for root, dirs, files in os.walk(directory):
|
|
126
|
+
rel_root = os.path.relpath(root, directory)
|
|
127
|
+
|
|
128
|
+
for file_name in files:
|
|
129
|
+
if file_name.endswith('.tex'):
|
|
130
|
+
file_path = os.path.join(root, file_name)
|
|
131
|
+
try:
|
|
132
|
+
with open(file_path, 'r', encoding='utf-8') as file:
|
|
133
|
+
lines = file.readlines()
|
|
134
|
+
if any('\\documentclass' in line for line in lines):
|
|
135
|
+
line_count = len(lines)
|
|
136
|
+
if line_count > max_line_count:
|
|
137
|
+
if rel_root == '.':
|
|
138
|
+
main_tex_file = file_name
|
|
139
|
+
else:
|
|
140
|
+
main_tex_file = os.path.join(rel_root, file_name)
|
|
141
|
+
max_line_count = line_count
|
|
142
|
+
except Exception as e:
|
|
143
|
+
logging.warning(f"Could not read file {file_path}: {e}")
|
|
129
144
|
|
|
130
145
|
return main_tex_file
|
|
131
146
|
|
|
@@ -164,6 +179,34 @@ def remove_appendix(text: str) -> str:
|
|
|
164
179
|
return text[:appendix_match.start()].rstrip()
|
|
165
180
|
return text
|
|
166
181
|
|
|
182
|
+
|
|
183
|
+
def list_sections(text: str) -> list:
|
|
184
|
+
"""Extract all section names from LaTeX content."""
|
|
185
|
+
pattern = r'\\section\*?\{([^}]+)\}'
|
|
186
|
+
return re.findall(pattern, text)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def extract_section(text: str, section_name: str) -> Optional[str]:
|
|
190
|
+
"""Extract content of a specific section (including its subsections)."""
|
|
191
|
+
# Find the start of the requested section
|
|
192
|
+
pattern = rf'\\section\*?\{{{re.escape(section_name)}\}}'
|
|
193
|
+
start_match = re.search(pattern, text)
|
|
194
|
+
if not start_match:
|
|
195
|
+
return None
|
|
196
|
+
|
|
197
|
+
start_pos = start_match.start()
|
|
198
|
+
|
|
199
|
+
# Find the next \section (not subsection) or end of document
|
|
200
|
+
remaining = text[start_match.end():]
|
|
201
|
+
end_match = re.search(r'\\section\*?\{', remaining)
|
|
202
|
+
|
|
203
|
+
if end_match:
|
|
204
|
+
end_pos = start_match.end() + end_match.start()
|
|
205
|
+
return text[start_pos:end_pos].rstrip()
|
|
206
|
+
else:
|
|
207
|
+
return text[start_pos:].rstrip()
|
|
208
|
+
|
|
209
|
+
|
|
167
210
|
def flatten_tex(directory: str, main_file: str) -> str:
|
|
168
211
|
"""Combine all tex files into one, resolving inputs."""
|
|
169
212
|
def process_file(file_path: str, processed_files: set) -> str:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: arxiv-to-prompt
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: transform arXiv papers into a single latex prompt for LLMs
|
|
5
5
|
Author: Takashi Ishida
|
|
6
6
|
License: MIT
|
|
@@ -54,6 +54,12 @@ arxiv-to-prompt 2303.08774 --no-comments --no-appendix
|
|
|
54
54
|
# Process a local folder containing TeX files (instead of downloading from arXiv)
|
|
55
55
|
arxiv-to-prompt --local-folder /path/to/tex/files
|
|
56
56
|
|
|
57
|
+
# List all section names in the paper
|
|
58
|
+
arxiv-to-prompt 2303.08774 --list-sections
|
|
59
|
+
|
|
60
|
+
# Extract only specific sections
|
|
61
|
+
arxiv-to-prompt 2303.08774 --section "Introduction" --section "Methods"
|
|
62
|
+
|
|
57
63
|
# Copy to clipboard
|
|
58
64
|
arxiv-to-prompt 2303.08774 | pbcopy
|
|
59
65
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
arxiv_to_prompt/__init__.py,sha256=LbfYhirPwhaMpwV4-YgMwW6hA0GOQDHVCPYCPKabjw0,1169
|
|
2
|
+
arxiv_to_prompt/cli.py,sha256=IwT64A-lf5PrxCxs2e1adN09USkf7ji31uzO8YAegpU,3203
|
|
3
|
+
arxiv_to_prompt/core.py,sha256=ln67k1MT-l8PalwGsszU6IwCZ15GAOiX0yfLgyKvySA,13837
|
|
4
|
+
arxiv_to_prompt-0.5.1.dist-info/licenses/LICENSE,sha256=np8L3--VyxwVJa_8D_mfK4RYrtnRMM_eeYN3rM4PMHo,1071
|
|
5
|
+
arxiv_to_prompt-0.5.1.dist-info/METADATA,sha256=VKK7my5pxFuVLTejMV3vS8BLhk_kV62HHPWxC84_80Q,4786
|
|
6
|
+
arxiv_to_prompt-0.5.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
7
|
+
arxiv_to_prompt-0.5.1.dist-info/entry_points.txt,sha256=iYEEn8xZ_5OkhNIs5HCyHSQBpDRJkbD5h0tlAb16lL0,61
|
|
8
|
+
arxiv_to_prompt-0.5.1.dist-info/top_level.txt,sha256=JClbu_lGGWu3RaTHZlNqTKB1-DUSbYXQNIYmJ9_F7fY,16
|
|
9
|
+
arxiv_to_prompt-0.5.1.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
arxiv_to_prompt/__init__.py,sha256=riK7TcTaKDleP5g5rjf2jkmLtXZu7irNZDujyAVDnKM,1093
|
|
2
|
-
arxiv_to_prompt/cli.py,sha256=np6mv2iCkLiVLawyix1vXP4bVFzRmZlkfjxb07ee89Q,2276
|
|
3
|
-
arxiv_to_prompt/core.py,sha256=6tl6IZh5BlBENKa3QMHG0ekqhhLLmh82oUQpgfYrz2o,12228
|
|
4
|
-
arxiv_to_prompt-0.4.1.dist-info/licenses/LICENSE,sha256=np8L3--VyxwVJa_8D_mfK4RYrtnRMM_eeYN3rM4PMHo,1071
|
|
5
|
-
arxiv_to_prompt-0.4.1.dist-info/METADATA,sha256=p5DIa1t9ik8_Mdn-7qxvfm8j0k--kAMn689-a3WocNM,4598
|
|
6
|
-
arxiv_to_prompt-0.4.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
7
|
-
arxiv_to_prompt-0.4.1.dist-info/entry_points.txt,sha256=iYEEn8xZ_5OkhNIs5HCyHSQBpDRJkbD5h0tlAb16lL0,61
|
|
8
|
-
arxiv_to_prompt-0.4.1.dist-info/top_level.txt,sha256=JClbu_lGGWu3RaTHZlNqTKB1-DUSbYXQNIYmJ9_F7fY,16
|
|
9
|
-
arxiv_to_prompt-0.4.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|