Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,13 @@ def is_pdflatex_installed():
|
|
17 |
def latex_to_pdf(latex_code):
|
18 |
# Check if pdflatex is installed
|
19 |
if not is_pdflatex_installed():
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
with tempfile.TemporaryDirectory() as temp_dir:
|
23 |
temp_path = Path(temp_dir)
|
@@ -29,13 +35,9 @@ def latex_to_pdf(latex_code):
|
|
29 |
f.write(latex_code)
|
30 |
|
31 |
try:
|
32 |
-
#
|
33 |
-
cmd = ["pdflatex", "-interaction=nonstopmode", "-output-directory", temp_dir, str(tex_file)]
|
34 |
-
st.write(f"Running command: {' '.join(cmd)}")
|
35 |
-
|
36 |
-
# Run pdflatex with full path if needed
|
37 |
process = subprocess.run(
|
38 |
-
|
39 |
capture_output=True,
|
40 |
text=True
|
41 |
)
|
@@ -48,8 +50,7 @@ def latex_to_pdf(latex_code):
|
|
48 |
else:
|
49 |
return None, process.stdout, process.stderr
|
50 |
except Exception as e:
|
51 |
-
return None, "",
|
52 |
-
|
53 |
|
54 |
# Function to display PDF
|
55 |
def display_pdf(pdf_data):
|
@@ -301,28 +302,17 @@ st.markdown("""
|
|
301 |
</style>
|
302 |
""", unsafe_allow_html=True)
|
303 |
|
304 |
-
# JavaScript for copying commands to editor
|
305 |
-
st.markdown("""
|
306 |
-
<script>
|
307 |
-
function copyToEditor(text) {
|
308 |
-
const textareas = document.getElementsByTagName('textarea');
|
309 |
-
if (textareas.length > 0) {
|
310 |
-
const editor = textareas[0];
|
311 |
-
const start = editor.selectionStart;
|
312 |
-
const end = editor.selectionEnd;
|
313 |
-
const value = editor.value;
|
314 |
-
editor.value = value.substring(0, start) + text + value.substring(end);
|
315 |
-
editor.selectionStart = editor.selectionEnd = start + text.length;
|
316 |
-
editor.focus();
|
317 |
-
}
|
318 |
-
}
|
319 |
-
</script>
|
320 |
-
""", unsafe_allow_html=True)
|
321 |
-
|
322 |
# Main application
|
323 |
def main():
|
324 |
st.title("LaTeX Editor & PDF Compiler")
|
325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
326 |
# Create layout with sidebar
|
327 |
col1, col2 = st.columns([3, 2])
|
328 |
|
@@ -431,13 +421,13 @@ def main():
|
|
431 |
for category, commands in latex_commands.items():
|
432 |
with st.expander(category):
|
433 |
for cmd, desc in commands.items():
|
434 |
-
st.markdown(f"<div class='latex-command'
|
435 |
|
436 |
with tabs[1]:
|
437 |
for category, packages in latex_packages.items():
|
438 |
with st.expander(category):
|
439 |
for pkg, desc in packages.items():
|
440 |
-
st.markdown(f"<div class='latex-command'
|
441 |
|
442 |
if __name__ == "__main__":
|
443 |
main()
|
|
|
17 |
def latex_to_pdf(latex_code):
|
18 |
# Check if pdflatex is installed
|
19 |
if not is_pdflatex_installed():
|
20 |
+
st.error("pdflatex not found. Debug info:")
|
21 |
+
st.code(f"PATH: {os.environ.get('PATH')}")
|
22 |
+
result = subprocess.run(["which", "pdflatex"], capture_output=True, text=True)
|
23 |
+
st.code(f"which pdflatex: {result.stdout} {result.stderr}")
|
24 |
+
result = subprocess.run(["ls", "-la", "/usr/bin/pdflatex"], capture_output=True, text=True)
|
25 |
+
st.code(f"ls -la /usr/bin/pdflatex: {result.stdout} {result.stderr}")
|
26 |
+
return None, "", "Error: pdflatex is not installed or not in PATH."
|
27 |
|
28 |
with tempfile.TemporaryDirectory() as temp_dir:
|
29 |
temp_path = Path(temp_dir)
|
|
|
35 |
f.write(latex_code)
|
36 |
|
37 |
try:
|
38 |
+
# Run pdflatex to compile the LaTeX file
|
|
|
|
|
|
|
|
|
39 |
process = subprocess.run(
|
40 |
+
["pdflatex", "-interaction=nonstopmode", "-output-directory", temp_dir, str(tex_file)],
|
41 |
capture_output=True,
|
42 |
text=True
|
43 |
)
|
|
|
50 |
else:
|
51 |
return None, process.stdout, process.stderr
|
52 |
except Exception as e:
|
53 |
+
return None, "", str(e)
|
|
|
54 |
|
55 |
# Function to display PDF
|
56 |
def display_pdf(pdf_data):
|
|
|
302 |
</style>
|
303 |
""", unsafe_allow_html=True)
|
304 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
# Main application
|
306 |
def main():
|
307 |
st.title("LaTeX Editor & PDF Compiler")
|
308 |
|
309 |
+
# Display installation status
|
310 |
+
if not is_pdflatex_installed():
|
311 |
+
st.warning("⚠️ LaTeX is not installed correctly. The PDF compilation feature will not work.")
|
312 |
+
st.info("For Hugging Face Spaces, make sure you have a packages.txt file with the necessary LaTeX packages.")
|
313 |
+
else:
|
314 |
+
st.success("✅ LaTeX is installed and ready to use!")
|
315 |
+
|
316 |
# Create layout with sidebar
|
317 |
col1, col2 = st.columns([3, 2])
|
318 |
|
|
|
421 |
for category, commands in latex_commands.items():
|
422 |
with st.expander(category):
|
423 |
for cmd, desc in commands.items():
|
424 |
+
st.markdown(f"<div class='latex-command'>{cmd}</div> - {desc}", unsafe_allow_html=True)
|
425 |
|
426 |
with tabs[1]:
|
427 |
for category, packages in latex_packages.items():
|
428 |
with st.expander(category):
|
429 |
for pkg, desc in packages.items():
|
430 |
+
st.markdown(f"<div class='latex-command'>{pkg}</div> - {desc}", unsafe_allow_html=True)
|
431 |
|
432 |
if __name__ == "__main__":
|
433 |
main()
|