Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,12 +4,21 @@ import tempfile
|
|
| 4 |
import base64
|
| 5 |
from pathlib import Path
|
| 6 |
import os
|
|
|
|
| 7 |
|
| 8 |
# Set page configuration
|
| 9 |
st.set_page_config(page_title="LaTeX Editor & Compiler", page_icon="📝", layout="wide")
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Function to convert LaTeX to PDF
|
| 12 |
def latex_to_pdf(latex_code):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
with tempfile.TemporaryDirectory() as temp_dir:
|
| 14 |
temp_path = Path(temp_dir)
|
| 15 |
tex_file = temp_path / "document.tex"
|
|
@@ -20,9 +29,13 @@ def latex_to_pdf(latex_code):
|
|
| 20 |
f.write(latex_code)
|
| 21 |
|
| 22 |
try:
|
| 23 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
process = subprocess.run(
|
| 25 |
-
|
| 26 |
capture_output=True,
|
| 27 |
text=True
|
| 28 |
)
|
|
@@ -35,7 +48,8 @@ def latex_to_pdf(latex_code):
|
|
| 35 |
else:
|
| 36 |
return None, process.stdout, process.stderr
|
| 37 |
except Exception as e:
|
| 38 |
-
return None, "", str(e)
|
|
|
|
| 39 |
|
| 40 |
# Function to display PDF
|
| 41 |
def display_pdf(pdf_data):
|
|
|
|
| 4 |
import base64
|
| 5 |
from pathlib import Path
|
| 6 |
import os
|
| 7 |
+
import shutil
|
| 8 |
|
| 9 |
# Set page configuration
|
| 10 |
st.set_page_config(page_title="LaTeX Editor & Compiler", page_icon="📝", layout="wide")
|
| 11 |
|
| 12 |
+
# Check if pdflatex is available
|
| 13 |
+
def is_pdflatex_installed():
|
| 14 |
+
return shutil.which("pdflatex") is not None
|
| 15 |
+
|
| 16 |
# Function to convert LaTeX to PDF
|
| 17 |
def latex_to_pdf(latex_code):
|
| 18 |
+
# Check if pdflatex is installed
|
| 19 |
+
if not is_pdflatex_installed():
|
| 20 |
+
return None, "", "Error: pdflatex is not installed or not in PATH. Check Dockerfile configuration."
|
| 21 |
+
|
| 22 |
with tempfile.TemporaryDirectory() as temp_dir:
|
| 23 |
temp_path = Path(temp_dir)
|
| 24 |
tex_file = temp_path / "document.tex"
|
|
|
|
| 29 |
f.write(latex_code)
|
| 30 |
|
| 31 |
try:
|
| 32 |
+
# Print the command being run for debugging
|
| 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 |
+
cmd,
|
| 39 |
capture_output=True,
|
| 40 |
text=True
|
| 41 |
)
|
|
|
|
| 48 |
else:
|
| 49 |
return None, process.stdout, process.stderr
|
| 50 |
except Exception as e:
|
| 51 |
+
return None, "", f"Error executing pdflatex: {str(e)}"
|
| 52 |
+
|
| 53 |
|
| 54 |
# Function to display PDF
|
| 55 |
def display_pdf(pdf_data):
|