Spaces:
Sleeping
Sleeping
Update utils/latex_utils.py
Browse files- utils/latex_utils.py +25 -90
utils/latex_utils.py
CHANGED
|
@@ -2,8 +2,8 @@ import os
|
|
| 2 |
import subprocess
|
| 3 |
from datetime import datetime
|
| 4 |
|
|
|
|
| 5 |
def generate_latex(cv_data):
|
| 6 |
-
"""Generate LaTeX code from structured CV data"""
|
| 7 |
latex_template = r"""\documentclass[12pt]{resume}
|
| 8 |
\usepackage[left=0.5in, right=0.5in, top=0.4in, bottom=0.4in]{geometry}
|
| 9 |
\usepackage[hidelinks]{hyperref}
|
|
@@ -22,110 +22,45 @@ def generate_latex(cv_data):
|
|
| 22 |
\href{mailto:%(email)s}{%(email)s} \textbar{}
|
| 23 |
%(phone)s \textbar{}
|
| 24 |
\href{%(linkedin)s}{LinkedIn} \textbar{}
|
| 25 |
-
\href{https://github.com/}{GitHub}
|
| 26 |
-
\href{}{Portfolio}
|
| 27 |
\end{center}
|
| 28 |
\vspace{-8pt}
|
| 29 |
|
| 30 |
\small
|
| 31 |
|
| 32 |
-
%
|
| 33 |
\begin{rSection}{Professional Summary}
|
| 34 |
%(summary)s
|
| 35 |
\end{rSection}
|
| 36 |
-
\vspace{-8pt}
|
| 37 |
-
|
| 38 |
-
\begin{rSection}{SKILLS}
|
| 39 |
-
\begin{tabular}{ @{} >{\bfseries}l @{\hspace{6ex}} l }
|
| 40 |
-
Technical Skills & %(skills)s \\
|
| 41 |
-
Certifications & %(certifications)s
|
| 42 |
-
\end{tabular}\\
|
| 43 |
-
\end{rSection}
|
| 44 |
-
|
| 45 |
-
% Experience
|
| 46 |
-
\vspace{-8pt}
|
| 47 |
-
\begin{rSection}{Professional Experience}
|
| 48 |
-
%(experience)s
|
| 49 |
-
\end{rSection}
|
| 50 |
-
|
| 51 |
-
% Education
|
| 52 |
-
\vspace{-8pt}
|
| 53 |
-
\begin{rSection}{Education}
|
| 54 |
-
%(education)s
|
| 55 |
-
\end{rSection}
|
| 56 |
-
|
| 57 |
-
% Projects
|
| 58 |
-
\vspace{-8pt}
|
| 59 |
-
\begin{rSection}{Projects}
|
| 60 |
-
%(projects)s
|
| 61 |
-
\end{rSection}
|
| 62 |
|
|
|
|
| 63 |
\end{document}
|
| 64 |
"""
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
exp.get('start_date', ''),
|
| 73 |
-
exp.get('end_date', '') or 'Present'
|
| 74 |
-
) + "\n"
|
| 75 |
-
+ r"\textbf{%s}, %s" % (
|
| 76 |
-
exp.get('company', ''),
|
| 77 |
-
"" # Location could be added if available
|
| 78 |
-
) + "\n"
|
| 79 |
-
+ r"\begin{itemize}[noitemsep, topsep=1pt]" + "\n"
|
| 80 |
-
+ "\n".join([
|
| 81 |
-
r"\item %s" % bullet.strip()
|
| 82 |
-
for bullet in exp.get('description', '').split('\n')
|
| 83 |
-
if bullet.strip()
|
| 84 |
-
]) + "\n"
|
| 85 |
-
+ r"\end{itemize}"
|
| 86 |
-
)
|
| 87 |
|
| 88 |
-
#
|
| 89 |
-
|
| 90 |
-
for
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
) + "\n"
|
| 97 |
-
+ r"\textbf{%s}" % edu.get('institution', '')
|
| 98 |
-
)
|
| 99 |
-
|
| 100 |
-
# Format projects
|
| 101 |
-
project_items = []
|
| 102 |
-
for proj in cv_data.get('projects', []):
|
| 103 |
-
project_items.append(
|
| 104 |
-
r"\textbf{%s}" % proj.get('title', '') + "\n"
|
| 105 |
-
+ r"\begin{itemize}[noitemsep, topsep=1pt]" + "\n"
|
| 106 |
-
+ "\n".join([
|
| 107 |
-
r"\item %s" % bullet.strip()
|
| 108 |
-
for bullet in proj.get('description', '').split('\n')
|
| 109 |
-
if bullet.strip()
|
| 110 |
-
]) + "\n"
|
| 111 |
-
+ r"\end{itemize}"
|
| 112 |
-
)
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
'
|
| 117 |
-
'
|
| 118 |
-
'
|
| 119 |
-
'
|
| 120 |
-
'
|
| 121 |
-
'skills': ', '.join(cv_data.get('skills', [])),
|
| 122 |
-
'certifications': '', # Can be added to CV data if available
|
| 123 |
-
'experience': '\n\n'.join(experience_items),
|
| 124 |
-
'education': '\n\n'.join(education_items),
|
| 125 |
-
'projects': '\n\n'.join(project_items)
|
| 126 |
}
|
| 127 |
-
|
| 128 |
-
return latex_content
|
| 129 |
|
| 130 |
def compile_latex_to_pdf(tex_file, output_dir):
|
| 131 |
"""Compile LaTeX file to PDF using latexmk"""
|
|
|
|
| 2 |
import subprocess
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
+
# In your latex_utils.py
|
| 6 |
def generate_latex(cv_data):
|
|
|
|
| 7 |
latex_template = r"""\documentclass[12pt]{resume}
|
| 8 |
\usepackage[left=0.5in, right=0.5in, top=0.4in, bottom=0.4in]{geometry}
|
| 9 |
\usepackage[hidelinks]{hyperref}
|
|
|
|
| 22 |
\href{mailto:%(email)s}{%(email)s} \textbar{}
|
| 23 |
%(phone)s \textbar{}
|
| 24 |
\href{%(linkedin)s}{LinkedIn} \textbar{}
|
| 25 |
+
\href{https://github.com/}{GitHub}
|
|
|
|
| 26 |
\end{center}
|
| 27 |
\vspace{-8pt}
|
| 28 |
|
| 29 |
\small
|
| 30 |
|
| 31 |
+
% Professional Summary
|
| 32 |
\begin{rSection}{Professional Summary}
|
| 33 |
%(summary)s
|
| 34 |
\end{rSection}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
%(sections)s
|
| 37 |
\end{document}
|
| 38 |
"""
|
| 39 |
|
| 40 |
+
# Ensure all required fields have default values
|
| 41 |
+
cv_data.setdefault('name', '')
|
| 42 |
+
cv_data.setdefault('email', '')
|
| 43 |
+
cv_data.setdefault('phone', '')
|
| 44 |
+
cv_data.setdefault('linkedin', '')
|
| 45 |
+
cv_data.setdefault('summary', '')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
# Generate sections dynamically
|
| 48 |
+
sections = ""
|
| 49 |
+
for section in ['skills', 'experience', 'education', 'projects']:
|
| 50 |
+
if section in cv_data and cv_data[section]:
|
| 51 |
+
sections += f"\\begin{{rSection}}{{{section.capitalize()}}}\n"
|
| 52 |
+
# Add section content here
|
| 53 |
+
sections += "% Add your section content generation logic\n"
|
| 54 |
+
sections += "\\end{rSection}\n\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
return latex_template % {
|
| 57 |
+
'name': cv_data['name'],
|
| 58 |
+
'email': cv_data['email'],
|
| 59 |
+
'phone': cv_data['phone'],
|
| 60 |
+
'linkedin': cv_data['linkedin'],
|
| 61 |
+
'summary': cv_data['summary'],
|
| 62 |
+
'sections': sections
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
}
|
|
|
|
|
|
|
| 64 |
|
| 65 |
def compile_latex_to_pdf(tex_file, output_dir):
|
| 66 |
"""Compile LaTeX file to PDF using latexmk"""
|