deepagents-printshop 0.1.0__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.
- agents/content_editor/__init__.py +1 -0
- agents/content_editor/agent.py +279 -0
- agents/content_editor/content_reviewer.py +327 -0
- agents/content_editor/versioned_agent.py +455 -0
- agents/latex_specialist/__init__.py +1 -0
- agents/latex_specialist/agent.py +531 -0
- agents/latex_specialist/latex_analyzer.py +510 -0
- agents/latex_specialist/latex_optimizer.py +1192 -0
- agents/qa_orchestrator/__init__.py +1 -0
- agents/qa_orchestrator/agent.py +603 -0
- agents/qa_orchestrator/langgraph_workflow.py +733 -0
- agents/qa_orchestrator/pipeline_types.py +72 -0
- agents/qa_orchestrator/quality_gates.py +495 -0
- agents/qa_orchestrator/workflow_coordinator.py +139 -0
- agents/research_agent/__init__.py +1 -0
- agents/research_agent/agent.py +258 -0
- agents/research_agent/llm_report_generator.py +1023 -0
- agents/research_agent/report_generator.py +536 -0
- agents/visual_qa/__init__.py +1 -0
- agents/visual_qa/agent.py +410 -0
- deepagents_printshop-0.1.0.dist-info/METADATA +744 -0
- deepagents_printshop-0.1.0.dist-info/RECORD +37 -0
- deepagents_printshop-0.1.0.dist-info/WHEEL +4 -0
- deepagents_printshop-0.1.0.dist-info/entry_points.txt +2 -0
- deepagents_printshop-0.1.0.dist-info/licenses/LICENSE +86 -0
- tools/__init__.py +1 -0
- tools/change_tracker.py +419 -0
- tools/content_type_loader.py +171 -0
- tools/graph_generator.py +281 -0
- tools/latex_generator.py +374 -0
- tools/llm_latex_generator.py +678 -0
- tools/magazine_layout.py +462 -0
- tools/pattern_injector.py +250 -0
- tools/pattern_learner.py +477 -0
- tools/pdf_compiler.py +386 -0
- tools/version_manager.py +346 -0
- tools/visual_qa.py +799 -0
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
"""
|
|
2
|
+
LaTeX Specialist Agent - Milestone 3
|
|
3
|
+
|
|
4
|
+
Specialized agent for optimizing LaTeX formatting, typography, and document structure.
|
|
5
|
+
Integrates with version management system to create v2_latex_optimized versions.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Dict, List, Optional
|
|
12
|
+
import json
|
|
13
|
+
from datetime import datetime
|
|
14
|
+
|
|
15
|
+
# Add project root to path
|
|
16
|
+
project_root = Path(__file__).parent.parent.parent
|
|
17
|
+
sys.path.insert(0, str(project_root))
|
|
18
|
+
|
|
19
|
+
from agents.latex_specialist.latex_analyzer import LaTeXAnalyzer, LaTeXAnalysisResult
|
|
20
|
+
from agents.latex_specialist.latex_optimizer import LaTeXOptimizer
|
|
21
|
+
from tools.version_manager import VersionManager
|
|
22
|
+
from tools.change_tracker import ChangeTracker
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class LaTeXSpecialistAgent:
|
|
26
|
+
"""
|
|
27
|
+
LaTeX Specialist Agent with version management and quality optimization.
|
|
28
|
+
|
|
29
|
+
Features:
|
|
30
|
+
- LaTeX document analysis and optimization
|
|
31
|
+
- Professional typography and formatting
|
|
32
|
+
- Version management integration
|
|
33
|
+
- Quality progression tracking
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(self, memory_dir: str = ".deepagents/latex_specialist/memories",
|
|
37
|
+
content_source: str = "research_report"):
|
|
38
|
+
"""
|
|
39
|
+
Initialize the LaTeX specialist agent.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
memory_dir: Directory for storing agent memories
|
|
43
|
+
content_source: Content source folder (e.g., 'research_report', 'magazine')
|
|
44
|
+
"""
|
|
45
|
+
self.memory_dir = Path(memory_dir)
|
|
46
|
+
self.memory_dir.mkdir(parents=True, exist_ok=True)
|
|
47
|
+
self.content_source = content_source
|
|
48
|
+
|
|
49
|
+
# Initialize components
|
|
50
|
+
self.latex_analyzer = LaTeXAnalyzer()
|
|
51
|
+
self.latex_optimizer = LaTeXOptimizer(content_source=content_source)
|
|
52
|
+
self.version_manager = VersionManager()
|
|
53
|
+
self.change_tracker = ChangeTracker()
|
|
54
|
+
|
|
55
|
+
# Paths
|
|
56
|
+
self.reports_dir = Path("artifacts/agent_reports/quality")
|
|
57
|
+
self.reports_dir.mkdir(parents=True, exist_ok=True)
|
|
58
|
+
self.output_filename = content_source # e.g., 'magazine' or 'research_report'
|
|
59
|
+
|
|
60
|
+
# Initialize memory
|
|
61
|
+
self.init_memory()
|
|
62
|
+
|
|
63
|
+
def init_memory(self):
|
|
64
|
+
"""Initialize agent memory files."""
|
|
65
|
+
memory_files = {
|
|
66
|
+
"latex_best_practices.md": """# LaTeX Best Practices and Standards
|
|
67
|
+
|
|
68
|
+
## Document Structure
|
|
69
|
+
- Use appropriate document class (article, report, book)
|
|
70
|
+
- Maintain consistent section hierarchy
|
|
71
|
+
- Include title, author, and date
|
|
72
|
+
- Add table of contents for longer documents
|
|
73
|
+
|
|
74
|
+
## Typography Excellence
|
|
75
|
+
- Use T1 font encoding for better output
|
|
76
|
+
- Enable microtype for improved typography
|
|
77
|
+
- Set appropriate line spacing (1.5 for academic)
|
|
78
|
+
- Maintain consistent font usage throughout
|
|
79
|
+
|
|
80
|
+
## Professional Packages
|
|
81
|
+
- booktabs: Professional table formatting
|
|
82
|
+
- geometry: Proper page margins and layout
|
|
83
|
+
- hyperref: Navigation and cross-references
|
|
84
|
+
- graphicx + float: Figure management
|
|
85
|
+
- caption: Professional figure captions
|
|
86
|
+
|
|
87
|
+
## Table Formatting
|
|
88
|
+
- Use booktabs package for professional tables
|
|
89
|
+
- Replace \\hline with \\toprule, \\midrule, \\bottomrule
|
|
90
|
+
- Align numbers in columns appropriately
|
|
91
|
+
- Use clear, descriptive table captions
|
|
92
|
+
|
|
93
|
+
## Figure Management
|
|
94
|
+
- Use [htbp] placement options
|
|
95
|
+
- Include descriptive captions
|
|
96
|
+
- Ensure proper figure sizing
|
|
97
|
+
- Reference all figures in text
|
|
98
|
+
""",
|
|
99
|
+
"typography_rules.md": """# Typography and Formatting Rules
|
|
100
|
+
|
|
101
|
+
## Font and Encoding
|
|
102
|
+
- Always use T1 font encoding: \\usepackage[T1]{fontenc}
|
|
103
|
+
- UTF-8 input encoding: \\usepackage[utf8]{inputenc}
|
|
104
|
+
- Modern fonts: \\usepackage{lmodern}
|
|
105
|
+
- Microtypography: \\usepackage{microtype}
|
|
106
|
+
|
|
107
|
+
## Spacing Guidelines
|
|
108
|
+
- Line spacing: 1.5 for academic papers (\\onehalfspacing)
|
|
109
|
+
- Paragraph indentation: Default LaTeX (no manual spacing)
|
|
110
|
+
- Section spacing: Let LaTeX handle automatically
|
|
111
|
+
- Margin settings: 1 inch margins for most documents
|
|
112
|
+
|
|
113
|
+
## Text Formatting
|
|
114
|
+
- Bold: \\textbf{text} (not \\bf)
|
|
115
|
+
- Italic: \\textit{text} (not \\it)
|
|
116
|
+
- Typewriter: \\texttt{text} (not \\tt)
|
|
117
|
+
- Avoid nested emphasis commands
|
|
118
|
+
|
|
119
|
+
## Document Flow
|
|
120
|
+
- Use proper sectioning commands
|
|
121
|
+
- Include page breaks where appropriate
|
|
122
|
+
- Maintain consistent formatting throughout
|
|
123
|
+
- Use proper cross-referencing with \\ref{}
|
|
124
|
+
""",
|
|
125
|
+
"table_figure_standards.md": """# Table and Figure Formatting Standards
|
|
126
|
+
|
|
127
|
+
## Professional Tables with Booktabs
|
|
128
|
+
```latex
|
|
129
|
+
\\usepackage{booktabs}
|
|
130
|
+
\\begin{table}[htbp]
|
|
131
|
+
\\centering
|
|
132
|
+
\\caption{Descriptive table caption}
|
|
133
|
+
\\label{tab:example}
|
|
134
|
+
\\begin{tabular}{lcc}
|
|
135
|
+
\\toprule
|
|
136
|
+
Column 1 & Column 2 & Column 3 \\\\
|
|
137
|
+
\\midrule
|
|
138
|
+
Data 1 & Data 2 & Data 3 \\\\
|
|
139
|
+
Data 4 & Data 5 & Data 6 \\\\
|
|
140
|
+
\\bottomrule
|
|
141
|
+
\\end{tabular}
|
|
142
|
+
\\end{table}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Figure Best Practices
|
|
146
|
+
```latex
|
|
147
|
+
\\usepackage{graphicx}
|
|
148
|
+
\\usepackage{float}
|
|
149
|
+
\\begin{figure}[htbp]
|
|
150
|
+
\\centering
|
|
151
|
+
\\includegraphics[width=0.8\\textwidth]{figure.png}
|
|
152
|
+
\\caption{Clear, descriptive figure caption}
|
|
153
|
+
\\label{fig:example}
|
|
154
|
+
\\end{figure}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Caption Guidelines
|
|
158
|
+
- Tables: Caption above the table
|
|
159
|
+
- Figures: Caption below the figure
|
|
160
|
+
- Use descriptive, self-contained captions
|
|
161
|
+
- Reference all tables and figures in text
|
|
162
|
+
- Use consistent numbering and labeling
|
|
163
|
+
""",
|
|
164
|
+
"optimization_patterns.md": """# LaTeX Optimization Patterns
|
|
165
|
+
|
|
166
|
+
## Common Issues and Fixes
|
|
167
|
+
1. **Poor Typography**
|
|
168
|
+
- Issue: Missing font encoding packages
|
|
169
|
+
- Fix: Add fontenc, inputenc, microtype packages
|
|
170
|
+
|
|
171
|
+
2. **Unprofessional Tables**
|
|
172
|
+
- Issue: Using \\hline for table rules
|
|
173
|
+
- Fix: Replace with booktabs package rules
|
|
174
|
+
|
|
175
|
+
3. **Poor Figure Placement**
|
|
176
|
+
- Issue: Using only [h] placement
|
|
177
|
+
- Fix: Use [htbp] for better flexibility
|
|
178
|
+
|
|
179
|
+
4. **Inconsistent Spacing**
|
|
180
|
+
- Issue: Manual spacing commands
|
|
181
|
+
- Fix: Use proper LaTeX spacing mechanisms
|
|
182
|
+
|
|
183
|
+
## Quality Improvement Strategies
|
|
184
|
+
- Analyze document structure first
|
|
185
|
+
- Fix typography issues early
|
|
186
|
+
- Optimize tables and figures
|
|
187
|
+
- Apply consistent formatting
|
|
188
|
+
- Validate compilation success
|
|
189
|
+
|
|
190
|
+
## Optimization Levels
|
|
191
|
+
- Conservative: Essential fixes only
|
|
192
|
+
- Moderate: Professional improvements
|
|
193
|
+
- Aggressive: Maximum optimization with style changes
|
|
194
|
+
"""
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
for filename, content in memory_files.items():
|
|
198
|
+
file_path = self.memory_dir / filename
|
|
199
|
+
if not file_path.exists():
|
|
200
|
+
with open(file_path, 'w', encoding='utf-8') as f:
|
|
201
|
+
f.write(content)
|
|
202
|
+
|
|
203
|
+
def analyze_latex_quality(self, content: str) -> LaTeXAnalysisResult:
|
|
204
|
+
"""
|
|
205
|
+
Analyze LaTeX content quality.
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
content: LaTeX content to analyze
|
|
209
|
+
|
|
210
|
+
Returns:
|
|
211
|
+
Detailed analysis results
|
|
212
|
+
"""
|
|
213
|
+
print("š Analyzing LaTeX quality...")
|
|
214
|
+
return self.latex_analyzer.analyze_document(content)
|
|
215
|
+
|
|
216
|
+
def optimize_latex_content(self,
|
|
217
|
+
content: str,
|
|
218
|
+
markdown_content: Optional[Dict[str, str]] = None,
|
|
219
|
+
optimization_level: str = 'moderate') -> Dict:
|
|
220
|
+
"""
|
|
221
|
+
Optimize LaTeX content for professional quality.
|
|
222
|
+
|
|
223
|
+
Args:
|
|
224
|
+
content: Original LaTeX content (if any)
|
|
225
|
+
markdown_content: Markdown content to convert and optimize
|
|
226
|
+
optimization_level: Level of optimization to apply
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
Optimization results
|
|
230
|
+
"""
|
|
231
|
+
print(f"š§ Optimizing LaTeX content (level: {optimization_level})")
|
|
232
|
+
|
|
233
|
+
if markdown_content:
|
|
234
|
+
print(f"š Converting {len(markdown_content)} markdown files to LaTeX")
|
|
235
|
+
|
|
236
|
+
return self.latex_optimizer.optimize_document(
|
|
237
|
+
content=content,
|
|
238
|
+
markdown_content=markdown_content,
|
|
239
|
+
optimization_level=optimization_level
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
def process_with_versioning(self,
|
|
243
|
+
parent_version: str = "v1_content_edited",
|
|
244
|
+
target_version: str = "v2_latex_optimized",
|
|
245
|
+
optimization_level: str = 'moderate') -> Dict:
|
|
246
|
+
"""
|
|
247
|
+
Process content with full LaTeX optimization and version management.
|
|
248
|
+
|
|
249
|
+
Args:
|
|
250
|
+
parent_version: Source version to optimize from
|
|
251
|
+
target_version: Target version name for optimized content
|
|
252
|
+
optimization_level: Level of optimization to apply
|
|
253
|
+
|
|
254
|
+
Returns:
|
|
255
|
+
Processing results with version information
|
|
256
|
+
"""
|
|
257
|
+
print(f"š LaTeX Specialist Processing: {parent_version} ā {target_version}")
|
|
258
|
+
print("=" * 60)
|
|
259
|
+
|
|
260
|
+
# Load parent version content
|
|
261
|
+
try:
|
|
262
|
+
parent_content_dict = self.version_manager.get_version_content(parent_version)
|
|
263
|
+
print(f"ā
Loaded {parent_version} with {len(parent_content_dict)} files")
|
|
264
|
+
except Exception as e:
|
|
265
|
+
print(f"ā Failed to load {parent_version}: {e}")
|
|
266
|
+
raise
|
|
267
|
+
|
|
268
|
+
# Analyze parent version LaTeX quality (if it's already LaTeX)
|
|
269
|
+
parent_latex_content = ""
|
|
270
|
+
parent_quality_scores = {}
|
|
271
|
+
|
|
272
|
+
# Convert markdown content to LaTeX and optimize
|
|
273
|
+
print("\nš Converting and optimizing content...")
|
|
274
|
+
optimization_result = self.optimize_latex_content(
|
|
275
|
+
content=parent_latex_content,
|
|
276
|
+
markdown_content=parent_content_dict,
|
|
277
|
+
optimization_level=optimization_level
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
optimized_latex = optimization_result['optimized_content']
|
|
281
|
+
optimizations_applied = optimization_result['optimizations_applied']
|
|
282
|
+
|
|
283
|
+
print(f"ā
Applied {len(optimizations_applied)} optimizations")
|
|
284
|
+
|
|
285
|
+
# Analyze optimized LaTeX quality
|
|
286
|
+
print("\nš Analyzing optimized LaTeX quality...")
|
|
287
|
+
latex_analysis = self.analyze_latex_quality(optimized_latex)
|
|
288
|
+
|
|
289
|
+
print(f"š LaTeX Quality Scores:")
|
|
290
|
+
print(f" ⢠Structure: {latex_analysis.structure_score}/25")
|
|
291
|
+
print(f" ⢠Typography: {latex_analysis.typography_score}/25")
|
|
292
|
+
print(f" ⢠Tables/Figures: {latex_analysis.tables_figures_score}/25")
|
|
293
|
+
print(f" ⢠Best Practices: {latex_analysis.best_practices_score}/25")
|
|
294
|
+
print(f" ⢠Overall: {latex_analysis.overall_score}/100")
|
|
295
|
+
|
|
296
|
+
# Create LaTeX file for the version
|
|
297
|
+
latex_content_dict = {
|
|
298
|
+
f"{self.output_filename}.tex": optimized_latex
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
# Create version metadata
|
|
302
|
+
version_metadata = {
|
|
303
|
+
"description": f"LaTeX formatting and typography optimized",
|
|
304
|
+
"purpose": "latex_optimization",
|
|
305
|
+
"optimization_level": optimization_level,
|
|
306
|
+
"latex_quality_score": latex_analysis.overall_score,
|
|
307
|
+
"optimizations_applied": len(optimizations_applied),
|
|
308
|
+
"structure_score": latex_analysis.structure_score,
|
|
309
|
+
"typography_score": latex_analysis.typography_score,
|
|
310
|
+
"tables_figures_score": latex_analysis.tables_figures_score,
|
|
311
|
+
"best_practices_score": latex_analysis.best_practices_score,
|
|
312
|
+
"processing_timestamp": datetime.now().isoformat()
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
# Create new version
|
|
316
|
+
print(f"\nš¦ Creating version: {target_version}")
|
|
317
|
+
version_info = self.version_manager.create_version(
|
|
318
|
+
content_dict=latex_content_dict,
|
|
319
|
+
version_name=target_version,
|
|
320
|
+
agent_name="latex_specialist",
|
|
321
|
+
parent_version=parent_version,
|
|
322
|
+
metadata=version_metadata
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
# Generate change comparison (markdown to LaTeX)
|
|
326
|
+
print(f"\nš Generating change analysis...")
|
|
327
|
+
change_report = self.change_tracker.create_change_report(
|
|
328
|
+
old_version=parent_version,
|
|
329
|
+
new_version=target_version,
|
|
330
|
+
old_content=parent_content_dict,
|
|
331
|
+
new_content=latex_content_dict,
|
|
332
|
+
old_quality=None, # Would need to calculate markdown quality
|
|
333
|
+
new_quality=latex_analysis.overall_score
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
# Create comprehensive processing report
|
|
337
|
+
processing_results = {
|
|
338
|
+
"version_created": version_info,
|
|
339
|
+
"parent_version": parent_version,
|
|
340
|
+
"target_version": target_version,
|
|
341
|
+
"optimization_results": optimization_result,
|
|
342
|
+
"latex_analysis": {
|
|
343
|
+
"overall_score": latex_analysis.overall_score,
|
|
344
|
+
"structure_score": latex_analysis.structure_score,
|
|
345
|
+
"typography_score": latex_analysis.typography_score,
|
|
346
|
+
"tables_figures_score": latex_analysis.tables_figures_score,
|
|
347
|
+
"best_practices_score": latex_analysis.best_practices_score,
|
|
348
|
+
"issues_found": len(latex_analysis.issues),
|
|
349
|
+
"suggestions": latex_analysis.suggestions
|
|
350
|
+
},
|
|
351
|
+
"optimizations_applied": optimizations_applied,
|
|
352
|
+
"change_report_path": change_report,
|
|
353
|
+
"processing_timestamp": datetime.now().isoformat()
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
# Save processing report
|
|
357
|
+
self.save_processing_report(processing_results, target_version)
|
|
358
|
+
|
|
359
|
+
print(f"\nā
LaTeX optimization complete!")
|
|
360
|
+
print(f" Version created: {target_version}")
|
|
361
|
+
print(f" LaTeX quality score: {latex_analysis.overall_score}/100")
|
|
362
|
+
print(f" Optimizations applied: {len(optimizations_applied)}")
|
|
363
|
+
print(f" Change report: {change_report}")
|
|
364
|
+
|
|
365
|
+
return processing_results
|
|
366
|
+
|
|
367
|
+
def save_processing_report(self, results: Dict, version_name: str):
|
|
368
|
+
"""Save processing results to quality reports directory."""
|
|
369
|
+
# JSON report
|
|
370
|
+
json_path = self.reports_dir / f"{version_name}_latex_processing_report.json"
|
|
371
|
+
with open(json_path, 'w', encoding='utf-8') as f:
|
|
372
|
+
json.dump(results, f, indent=2, ensure_ascii=False, default=str)
|
|
373
|
+
|
|
374
|
+
# Markdown report
|
|
375
|
+
md_path = self.reports_dir / f"{version_name}_latex_processing_report.md"
|
|
376
|
+
self.create_processing_markdown(results, md_path)
|
|
377
|
+
|
|
378
|
+
def create_processing_markdown(self, results: Dict, output_path: Path):
|
|
379
|
+
"""Create human-readable markdown processing report."""
|
|
380
|
+
version_info = results["version_created"]
|
|
381
|
+
latex_analysis = results["latex_analysis"]
|
|
382
|
+
optimizations = results["optimizations_applied"]
|
|
383
|
+
parent_version = results["parent_version"]
|
|
384
|
+
target_version = results["target_version"]
|
|
385
|
+
|
|
386
|
+
content = f"""# LaTeX Processing Report: {target_version}
|
|
387
|
+
|
|
388
|
+
**Generated:** {results["processing_timestamp"]}
|
|
389
|
+
**Parent Version:** {parent_version}
|
|
390
|
+
**Agent:** latex_specialist
|
|
391
|
+
**Optimization Level:** {results["optimization_results"]["optimization_level"]}
|
|
392
|
+
|
|
393
|
+
## LaTeX Quality Analysis
|
|
394
|
+
|
|
395
|
+
| Metric | Score | Max |
|
|
396
|
+
|--------|-------|-----|
|
|
397
|
+
| Document Structure | {latex_analysis["structure_score"]} | 25 |
|
|
398
|
+
| Typography | {latex_analysis["typography_score"]} | 25 |
|
|
399
|
+
| Tables & Figures | {latex_analysis["tables_figures_score"]} | 25 |
|
|
400
|
+
| Best Practices | {latex_analysis["best_practices_score"]} | 25 |
|
|
401
|
+
| **Overall Score** | **{latex_analysis["overall_score"]}** | **100** |
|
|
402
|
+
|
|
403
|
+
## Optimizations Applied ({len(optimizations)} total)
|
|
404
|
+
|
|
405
|
+
"""
|
|
406
|
+
|
|
407
|
+
for i, optimization in enumerate(optimizations, 1):
|
|
408
|
+
content += f"{i}. {optimization}\n"
|
|
409
|
+
|
|
410
|
+
content += f"""
|
|
411
|
+
|
|
412
|
+
## Quality Improvements
|
|
413
|
+
|
|
414
|
+
- **Issues Found:** {latex_analysis["issues_found"]} LaTeX issues detected
|
|
415
|
+
- **Optimizations Applied:** {len(optimizations)} improvements made
|
|
416
|
+
- **Final Quality Score:** {latex_analysis["overall_score"]}/100
|
|
417
|
+
|
|
418
|
+
## Recommendations
|
|
419
|
+
|
|
420
|
+
"""
|
|
421
|
+
|
|
422
|
+
for suggestion in latex_analysis["suggestions"]:
|
|
423
|
+
content += f"- {suggestion}\n"
|
|
424
|
+
|
|
425
|
+
content += f"""
|
|
426
|
+
|
|
427
|
+
## Version Information
|
|
428
|
+
|
|
429
|
+
- **Version Name:** {version_info["name"]}
|
|
430
|
+
- **Created:** {version_info["created_at"]}
|
|
431
|
+
- **Parent Version:** {version_info["parent_version"]}
|
|
432
|
+
- **Content Hash:** {version_info["content_hash"]}
|
|
433
|
+
- **Files:** {", ".join(version_info["files"])}
|
|
434
|
+
|
|
435
|
+
## Change Analysis
|
|
436
|
+
|
|
437
|
+
Detailed change comparison available at: `{results["change_report_path"]}`
|
|
438
|
+
|
|
439
|
+
## LaTeX Output
|
|
440
|
+
|
|
441
|
+
The optimized LaTeX document includes:
|
|
442
|
+
- Professional document structure
|
|
443
|
+
- Enhanced typography with proper packages
|
|
444
|
+
- Optimized table and figure formatting
|
|
445
|
+
- Best practices implementation
|
|
446
|
+
- Publication-ready formatting
|
|
447
|
+
"""
|
|
448
|
+
|
|
449
|
+
with open(output_path, 'w', encoding='utf-8') as f:
|
|
450
|
+
f.write(content)
|
|
451
|
+
|
|
452
|
+
def validate_latex_compilation(self, latex_content: str) -> Dict:
|
|
453
|
+
"""
|
|
454
|
+
Validate that LaTeX content can be compiled (mock implementation).
|
|
455
|
+
|
|
456
|
+
Args:
|
|
457
|
+
latex_content: LaTeX content to validate
|
|
458
|
+
|
|
459
|
+
Returns:
|
|
460
|
+
Validation results
|
|
461
|
+
"""
|
|
462
|
+
# This would use pdflatex in a real implementation
|
|
463
|
+
# For now, we'll do basic syntax checking
|
|
464
|
+
|
|
465
|
+
validation_result = {
|
|
466
|
+
"compilation_successful": True,
|
|
467
|
+
"warnings": [],
|
|
468
|
+
"errors": [],
|
|
469
|
+
"pdf_generated": True # Mock
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
# Basic syntax checks
|
|
473
|
+
if not re.search(r'\\begin\{document\}', latex_content):
|
|
474
|
+
validation_result["errors"].append("Missing \\begin{document}")
|
|
475
|
+
validation_result["compilation_successful"] = False
|
|
476
|
+
|
|
477
|
+
if not re.search(r'\\end\{document\}', latex_content):
|
|
478
|
+
validation_result["errors"].append("Missing \\end{document}")
|
|
479
|
+
validation_result["compilation_successful"] = False
|
|
480
|
+
|
|
481
|
+
# Check for unmatched braces (simplified)
|
|
482
|
+
open_braces = latex_content.count('{')
|
|
483
|
+
close_braces = latex_content.count('}')
|
|
484
|
+
if open_braces != close_braces:
|
|
485
|
+
validation_result["warnings"].append(f"Unmatched braces: {open_braces} open, {close_braces} close")
|
|
486
|
+
|
|
487
|
+
return validation_result
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
def main():
|
|
491
|
+
"""Run the LaTeX specialist agent."""
|
|
492
|
+
print("š Starting LaTeX Specialist Agent - Milestone 3")
|
|
493
|
+
print("=" * 60)
|
|
494
|
+
|
|
495
|
+
# Initialize agent
|
|
496
|
+
agent = LaTeXSpecialistAgent()
|
|
497
|
+
|
|
498
|
+
try:
|
|
499
|
+
# Process content with versioning
|
|
500
|
+
results = agent.process_with_versioning(
|
|
501
|
+
parent_version="v1_content_edited",
|
|
502
|
+
target_version="v2_latex_optimized",
|
|
503
|
+
optimization_level="moderate"
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
# Show version history
|
|
507
|
+
print("\nš Updated Version History:")
|
|
508
|
+
history = agent.version_manager.list_versions()
|
|
509
|
+
for entry in history:
|
|
510
|
+
quality = entry.get('metadata', {}).get('latex_quality_score')
|
|
511
|
+
quality_str = f" (LaTeX: {quality})" if quality else ""
|
|
512
|
+
print(f" {entry['name']}: {entry.get('metadata', {}).get('description', 'No description')}{quality_str}")
|
|
513
|
+
|
|
514
|
+
# Show version statistics
|
|
515
|
+
stats = agent.version_manager.get_version_stats()
|
|
516
|
+
print(f"\nš Version Statistics:")
|
|
517
|
+
print(f" Total versions: {stats['total_versions']}")
|
|
518
|
+
print(f" Agents used: {', '.join(stats['agents_used'])}")
|
|
519
|
+
print(f" Latest version: {stats['latest_version']}")
|
|
520
|
+
|
|
521
|
+
print("\n" + "=" * 60)
|
|
522
|
+
print("ā
MILESTONE 3: LaTeX optimization complete!")
|
|
523
|
+
|
|
524
|
+
except Exception as e:
|
|
525
|
+
print(f"ā Error: {e}")
|
|
526
|
+
import traceback
|
|
527
|
+
traceback.print_exc()
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
if __name__ == "__main__":
|
|
531
|
+
main()
|