Update latex-server.py
Browse files- latex-server.py +19 -22
latex-server.py
CHANGED
|
@@ -141,20 +141,21 @@ def compile_latex():
|
|
| 141 |
'error': str(exc)
|
| 142 |
}), 400
|
| 143 |
|
| 144 |
-
# Compile LaTeX to PDF using
|
| 145 |
try:
|
| 146 |
-
command = ['
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
| 158 |
|
| 159 |
# Check if PDF was created
|
| 160 |
if result.returncode != 0 or not os.path.exists(pdf_file):
|
|
@@ -177,7 +178,7 @@ def compile_latex():
|
|
| 177 |
except FileNotFoundError:
|
| 178 |
return jsonify({
|
| 179 |
'success': False,
|
| 180 |
-
'error': '
|
| 181 |
}), 500
|
| 182 |
|
| 183 |
except Exception as e:
|
|
@@ -204,19 +205,15 @@ def index():
|
|
| 204 |
})
|
| 205 |
|
| 206 |
if __name__ == '__main__':
|
| 207 |
-
# Check if
|
| 208 |
try:
|
| 209 |
-
subprocess.run(['
|
| 210 |
except (FileNotFoundError, subprocess.CalledProcessError):
|
| 211 |
-
print('ERROR:
|
| 212 |
-
print('Please install TeX Live:')
|
| 213 |
-
print(' macOS: brew install texlive')
|
| 214 |
-
print(' Linux: sudo apt-get install texlive-latex-base texlive-latex-extra')
|
| 215 |
-
print(' Windows: Download from https://tug.org/texlive/')
|
| 216 |
sys.exit(1)
|
| 217 |
|
| 218 |
print('🚀 LaTeX Compiler Server starting on http://localhost:5000')
|
| 219 |
print('📝 Open latex-editor.html in your browser')
|
| 220 |
print('Press Ctrl+C to stop')
|
| 221 |
|
| 222 |
-
app.run(debug=False, host='0.0.0.0', port=
|
|
|
|
| 141 |
'error': str(exc)
|
| 142 |
}), 400
|
| 143 |
|
| 144 |
+
# Compile LaTeX to PDF using xelatex + bibtex
|
| 145 |
try:
|
| 146 |
+
command = ['xelatex', '-interaction=nonstopmode', '-halt-on-error', '-output-directory', tmpdir, tex_file]
|
| 147 |
+
|
| 148 |
+
# Pass 1: Initial xelatex run
|
| 149 |
+
subprocess.run(command, capture_output=True, text=True, timeout=30, cwd=tmpdir)
|
| 150 |
+
|
| 151 |
+
# Pass 2: Run bibtex for citations (like apacite)
|
| 152 |
+
subprocess.run(['bibtex', 'document'], capture_output=True, text=True, timeout=30, cwd=tmpdir)
|
| 153 |
+
|
| 154 |
+
# Pass 3: Second xelatex run (links citations)
|
| 155 |
+
subprocess.run(command, capture_output=True, text=True, timeout=30, cwd=tmpdir)
|
| 156 |
+
|
| 157 |
+
# Pass 4: Final xelatex run (resolves cross-references)
|
| 158 |
+
result = subprocess.run(command, capture_output=True, text=True, timeout=30, cwd=tmpdir)
|
| 159 |
|
| 160 |
# Check if PDF was created
|
| 161 |
if result.returncode != 0 or not os.path.exists(pdf_file):
|
|
|
|
| 178 |
except FileNotFoundError:
|
| 179 |
return jsonify({
|
| 180 |
'success': False,
|
| 181 |
+
'error': 'xelatex not found. Please check your TeX Live installation.'
|
| 182 |
}), 500
|
| 183 |
|
| 184 |
except Exception as e:
|
|
|
|
| 205 |
})
|
| 206 |
|
| 207 |
if __name__ == '__main__':
|
| 208 |
+
# Check if xelatex is available
|
| 209 |
try:
|
| 210 |
+
subprocess.run(['xelatex', '--version'], capture_output=True, check=True)
|
| 211 |
except (FileNotFoundError, subprocess.CalledProcessError):
|
| 212 |
+
print('ERROR: xelatex not found!')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
sys.exit(1)
|
| 214 |
|
| 215 |
print('🚀 LaTeX Compiler Server starting on http://localhost:5000')
|
| 216 |
print('📝 Open latex-editor.html in your browser')
|
| 217 |
print('Press Ctrl+C to stop')
|
| 218 |
|
| 219 |
+
app.run(debug=False, host='0.0.0.0', port=7860)
|