Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -286,7 +286,7 @@ Your conclusion here.
|
|
286 |
\end{document}
|
287 |
"""
|
288 |
|
289 |
-
# Enhanced VSCode-like
|
290 |
st.markdown("""
|
291 |
<style>
|
292 |
/* Base theming - VS Code inspired */
|
@@ -309,8 +309,23 @@ st.markdown("""
|
|
309 |
background-color: #1177bb;
|
310 |
}
|
311 |
|
312 |
-
/*
|
313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
font-family: 'Consolas', 'Monaco', 'Courier New', monospace !important;
|
315 |
font-size: 14px !important;
|
316 |
line-height: 1.5 !important;
|
@@ -321,43 +336,9 @@ st.markdown("""
|
|
321 |
border: 1px solid #252526 !important;
|
322 |
}
|
323 |
|
324 |
-
/*
|
325 |
-
.
|
326 |
-
background-color: #
|
327 |
-
color: #d4d4d4;
|
328 |
-
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
329 |
-
font-size: 14px;
|
330 |
-
padding: 10px;
|
331 |
-
border-radius: 4px;
|
332 |
-
border: 1px solid #252526;
|
333 |
-
white-space: pre-wrap;
|
334 |
-
margin-top: 10px;
|
335 |
-
overflow-x: auto;
|
336 |
-
}
|
337 |
-
|
338 |
-
/* Syntax highlighting for different LaTeX elements */
|
339 |
-
.syntax-highlight .command {
|
340 |
-
color: #569cd6; /* Blue for commands */
|
341 |
-
}
|
342 |
-
|
343 |
-
.syntax-highlight .environment {
|
344 |
-
color: #4ec9b0; /* Teal for environments */
|
345 |
-
}
|
346 |
-
|
347 |
-
.syntax-highlight .bracket {
|
348 |
-
color: #d4d4d4; /* White for brackets */
|
349 |
-
}
|
350 |
-
|
351 |
-
.syntax-highlight .math {
|
352 |
-
color: #c586c0; /* Purple for math */
|
353 |
-
}
|
354 |
-
|
355 |
-
.syntax-highlight .comment {
|
356 |
-
color: #6a9955; /* Green for comments */
|
357 |
-
}
|
358 |
-
|
359 |
-
.syntax-highlight .package {
|
360 |
-
color: #dcdcaa; /* Yellow for package imports */
|
361 |
}
|
362 |
|
363 |
/* VS Code-like editor container */
|
@@ -691,60 +672,84 @@ st.markdown("""
|
|
691 |
font-weight: bold;
|
692 |
}
|
693 |
|
694 |
-
/*
|
695 |
-
.
|
696 |
-
background-color: #1e1e1e;
|
697 |
-
border: 1px solid #2d2d2d;
|
698 |
-
border-radius: 4px;
|
699 |
-
margin-top: 10px;
|
700 |
-
padding: 10px;
|
701 |
-
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
702 |
-
font-size: 14px;
|
703 |
-
line-height: 1.5;
|
704 |
-
overflow-x: auto;
|
705 |
-
white-space: pre-wrap;
|
706 |
-
}
|
707 |
-
|
708 |
-
/* Custom select styling */
|
709 |
-
.stSelectbox [data-baseweb="select"] {
|
710 |
-
background-color: #3c3c3c;
|
711 |
-
border-color: #3c3c3c;
|
712 |
-
}
|
713 |
-
|
714 |
-
.stSelectbox [data-baseweb="select"] > div {
|
715 |
-
color: #cccccc;
|
716 |
-
}
|
717 |
-
|
718 |
-
/* Keyboard shortcuts display */
|
719 |
-
.shortcuts-container {
|
720 |
background-color: #252526;
|
721 |
border: 1px solid #2d2d2d;
|
722 |
border-radius: 4px;
|
|
|
723 |
margin-top: 10px;
|
724 |
-
|
725 |
-
}
|
726 |
-
|
727 |
-
.shortcut-row {
|
728 |
display: flex;
|
729 |
-
|
730 |
-
margin-bottom: 8px;
|
731 |
-
border-bottom: 1px solid #333;
|
732 |
-
padding-bottom: 8px;
|
733 |
}
|
734 |
|
735 |
-
.shortcut-
|
736 |
background-color: #3c3c3c;
|
737 |
padding: 2px 8px;
|
738 |
border-radius: 3px;
|
739 |
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
740 |
font-size: 12px;
|
|
|
741 |
}
|
742 |
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
}
|
747 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
748 |
""", unsafe_allow_html=True)
|
749 |
|
750 |
# Function to create a functional VS Code-like toolbar
|
@@ -875,42 +880,6 @@ def render_status_bar():
|
|
875 |
"""
|
876 |
st.markdown(status_html, unsafe_allow_html=True)
|
877 |
|
878 |
-
# Create syntax highlighting for the code preview
|
879 |
-
def syntax_highlight_latex(latex_code):
|
880 |
-
if not isinstance(latex_code, str):
|
881 |
-
try:
|
882 |
-
latex_code = str(latex_code)
|
883 |
-
except:
|
884 |
-
return "<pre>Invalid code</pre>"
|
885 |
-
|
886 |
-
# Replace special HTML characters
|
887 |
-
latex_code = latex_code.replace("&", "&").replace("<", "<").replace(">", ">")
|
888 |
-
|
889 |
-
# Highlight LaTeX commands (starting with \)
|
890 |
-
latex_code = re.sub(r'(\\[a-zA-Z]+)(\{|\[|\s|$)', r'<span class="command">\1</span>\2', latex_code)
|
891 |
-
|
892 |
-
# Highlight environment tags
|
893 |
-
latex_code = re.sub(r'(\\begin\{[^}]+\}|\\end\{[^}]+\})', r'<span class="environment">\1</span>', latex_code)
|
894 |
-
|
895 |
-
# Highlight math modes
|
896 |
-
latex_code = re.sub(r'(\$\$.*?\$\$|\$.*?\$)', r'<span class="math">\1</span>', latex_code)
|
897 |
-
|
898 |
-
# Highlight comments
|
899 |
-
latex_code = re.sub(r'(%.*$)', r'<span class="comment">\1</span>', latex_code)
|
900 |
-
|
901 |
-
# Highlight package imports
|
902 |
-
latex_code = re.sub(r'(\\usepackage(\[.*?\])?\{[^}]+\})', r'<span class="package">\1</span>', latex_code)
|
903 |
-
|
904 |
-
# Highlight brackets
|
905 |
-
latex_code = re.sub(r'(\{|\}|\[|\])', r'<span class="bracket">\1</span>', latex_code)
|
906 |
-
|
907 |
-
return f'<div class="syntax-highlight">{latex_code}</div>'
|
908 |
-
|
909 |
-
# Function to display the code with syntax highlighting
|
910 |
-
def display_code_with_syntax_highlighting(latex_code):
|
911 |
-
highlighted_code = syntax_highlight_latex(latex_code)
|
912 |
-
st.markdown(highlighted_code, unsafe_allow_html=True)
|
913 |
-
|
914 |
# Render a document outline based on section hierarchy
|
915 |
def render_document_outline(structure):
|
916 |
if not structure:
|
@@ -1083,34 +1052,15 @@ def render_environments_panel(environments):
|
|
1083 |
|
1084 |
st.markdown('</div>', unsafe_allow_html=True)
|
1085 |
|
1086 |
-
# Display keyboard
|
1087 |
-
def
|
1088 |
-
st.markdown(
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
("Ctrl+E", "Insert equation"),
|
1096 |
-
("Ctrl+L", "Insert list"),
|
1097 |
-
("Ctrl+F", "Insert fraction"),
|
1098 |
-
("F5", "Compile document"),
|
1099 |
-
("Ctrl+S", "Save document"),
|
1100 |
-
("Ctrl+/", "Toggle comment"),
|
1101 |
-
("Tab", "Indent")
|
1102 |
-
]
|
1103 |
-
|
1104 |
-
for key, description in shortcuts:
|
1105 |
-
st.markdown(
|
1106 |
-
f'<div class="shortcut-row">'
|
1107 |
-
f'<span class="shortcut-keys">{key}</span>'
|
1108 |
-
f'<span class="shortcut-description">{description}</span>'
|
1109 |
-
f'</div>',
|
1110 |
-
unsafe_allow_html=True
|
1111 |
-
)
|
1112 |
-
|
1113 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
1114 |
|
1115 |
# Main application
|
1116 |
def main():
|
@@ -1125,8 +1075,6 @@ def main():
|
|
1125 |
st.session_state.errors = []
|
1126 |
if 'warnings' not in st.session_state:
|
1127 |
st.session_state.warnings = []
|
1128 |
-
if 'show_syntax_highlight' not in st.session_state:
|
1129 |
-
st.session_state.show_syntax_highlight = False
|
1130 |
|
1131 |
# Check installation status
|
1132 |
if not is_pdflatex_installed():
|
@@ -1137,7 +1085,7 @@ def main():
|
|
1137 |
|
1138 |
with col1:
|
1139 |
# Create tabs for main editing area with VS Code style
|
1140 |
-
editor_tabs = st.tabs(["Editor", "
|
1141 |
|
1142 |
with editor_tabs[0]:
|
1143 |
# VS Code-like editor interface
|
@@ -1149,8 +1097,8 @@ def main():
|
|
1149 |
# Toolbar with functional buttons
|
1150 |
render_functional_toolbar()
|
1151 |
|
1152 |
-
# Editor with VS Code styling
|
1153 |
-
st.markdown('<div
|
1154 |
latex_code = st.text_area(
|
1155 |
"",
|
1156 |
value=st.session_state.latex_code,
|
@@ -1166,9 +1114,12 @@ def main():
|
|
1166 |
|
1167 |
st.markdown('</div>', unsafe_allow_html=True)
|
1168 |
|
|
|
|
|
|
|
1169 |
# Control buttons with VS Code styling
|
1170 |
st.markdown('<div class="button-group">', unsafe_allow_html=True)
|
1171 |
-
compile_btn = st.button("Compile", help="Compile LaTeX to PDF")
|
1172 |
load_template_btn = st.button("Load Template", help="Load default template")
|
1173 |
clear_btn = st.button("Clear", help="Clear editor content")
|
1174 |
st.markdown('</div>', unsafe_allow_html=True)
|
@@ -1187,14 +1138,6 @@ def main():
|
|
1187 |
st.rerun()
|
1188 |
|
1189 |
with editor_tabs[1]:
|
1190 |
-
# Show syntax highlighted preview
|
1191 |
-
st.markdown("<h3>Syntax Highlighted Preview</h3>", unsafe_allow_html=True)
|
1192 |
-
st.markdown("<p>This shows your LaTeX code with syntax highlighting</p>", unsafe_allow_html=True)
|
1193 |
-
|
1194 |
-
# Display code with syntax highlighting
|
1195 |
-
display_code_with_syntax_highlighting(st.session_state.latex_code)
|
1196 |
-
|
1197 |
-
with editor_tabs[2]:
|
1198 |
st.markdown("<h3>LaTeX Settings</h3>", unsafe_allow_html=True)
|
1199 |
|
1200 |
st.markdown('<div class="control-panel">', unsafe_allow_html=True)
|
@@ -1218,9 +1161,6 @@ def main():
|
|
1218 |
index=0, key="editor_theme")
|
1219 |
|
1220 |
st.markdown('</div>', unsafe_allow_html=True)
|
1221 |
-
|
1222 |
-
# Display keyboard shortcuts
|
1223 |
-
render_keyboard_shortcuts()
|
1224 |
|
1225 |
with col2:
|
1226 |
# Output tabs with VS Code style
|
@@ -1310,7 +1250,7 @@ def main():
|
|
1310 |
output_format="PNG")
|
1311 |
st.markdown('</div>', unsafe_allow_html=True)
|
1312 |
else:
|
1313 |
-
st.info("Click 'Compile' to generate PDF output")
|
1314 |
|
1315 |
with output_tabs[1]:
|
1316 |
# Document structure/outline view (with type check)
|
|
|
286 |
\end{document}
|
287 |
"""
|
288 |
|
289 |
+
# Enhanced VSCode-like styling with inline syntax highlighting
|
290 |
st.markdown("""
|
291 |
<style>
|
292 |
/* Base theming - VS Code inspired */
|
|
|
309 |
background-color: #1177bb;
|
310 |
}
|
311 |
|
312 |
+
/* Custom editor with built-in syntax highlighting */
|
313 |
+
#latex-editor-container {
|
314 |
+
position: relative;
|
315 |
+
width: 100%;
|
316 |
+
height: 600px;
|
317 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
318 |
+
font-size: 14px;
|
319 |
+
line-height: 1.5;
|
320 |
+
background-color: #1e1e1e;
|
321 |
+
color: #d4d4d4;
|
322 |
+
border-radius: 4px;
|
323 |
+
border: 1px solid #252526;
|
324 |
+
padding: 10px;
|
325 |
+
}
|
326 |
+
|
327 |
+
/* Default coloring for textarea */
|
328 |
+
.stTextArea textarea {
|
329 |
font-family: 'Consolas', 'Monaco', 'Courier New', monospace !important;
|
330 |
font-size: 14px !important;
|
331 |
line-height: 1.5 !important;
|
|
|
336 |
border: 1px solid #252526 !important;
|
337 |
}
|
338 |
|
339 |
+
/* Highlight LaTeX specific elements */
|
340 |
+
.stTextArea textarea::selection {
|
341 |
+
background-color: #264f78;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
342 |
}
|
343 |
|
344 |
/* VS Code-like editor container */
|
|
|
672 |
font-weight: bold;
|
673 |
}
|
674 |
|
675 |
+
/* Simple keyboard shortcut */
|
676 |
+
.shortcut-item {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
677 |
background-color: #252526;
|
678 |
border: 1px solid #2d2d2d;
|
679 |
border-radius: 4px;
|
680 |
+
padding: 5px 10px;
|
681 |
margin-top: 10px;
|
682 |
+
font-size: 13px;
|
|
|
|
|
|
|
683 |
display: flex;
|
684 |
+
align-items: center;
|
|
|
|
|
|
|
685 |
}
|
686 |
|
687 |
+
.shortcut-key {
|
688 |
background-color: #3c3c3c;
|
689 |
padding: 2px 8px;
|
690 |
border-radius: 3px;
|
691 |
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
692 |
font-size: 12px;
|
693 |
+
margin-right: 10px;
|
694 |
}
|
695 |
|
696 |
+
/* Inline syntax highlighting for LaTeX - applied via JavaScript */
|
697 |
+
#syntax-styles {
|
698 |
+
display: none;
|
699 |
}
|
700 |
</style>
|
701 |
+
|
702 |
+
<div id="syntax-styles">
|
703 |
+
<style>
|
704 |
+
.latex-command { color: #569cd6; }
|
705 |
+
.latex-environment { color: #4ec9b0; }
|
706 |
+
.latex-bracket { color: #d4d4d4; }
|
707 |
+
.latex-math { color: #c586c0; }
|
708 |
+
.latex-comment { color: #6a9955; }
|
709 |
+
.latex-package { color: #dcdcaa; }
|
710 |
+
</style>
|
711 |
+
</div>
|
712 |
+
|
713 |
+
<script>
|
714 |
+
// Add inline syntax highlighting support for the editor
|
715 |
+
document.addEventListener('DOMContentLoaded', function() {
|
716 |
+
// Function to apply syntax highlighting to the textarea
|
717 |
+
function applySyntaxHighlighting() {
|
718 |
+
const textarea = document.querySelector('textarea');
|
719 |
+
if (!textarea) return;
|
720 |
+
|
721 |
+
// Find text matches and colorize them
|
722 |
+
const text = textarea.value;
|
723 |
+
|
724 |
+
// Color LaTeX commands
|
725 |
+
textarea.style.color = '#d4d4d4'; // Default text color
|
726 |
+
|
727 |
+
// Apply specific colors for different LaTeX constructs
|
728 |
+
// We can't do this directly in the textarea, but we indicate the presence of these elements
|
729 |
+
if (text.match(/\\usepackage/g)) {
|
730 |
+
const packageButtons = document.querySelectorAll('.toolbar-button[title="Add Package"]');
|
731 |
+
packageButtons.forEach(button => button.style.color = '#dcdcaa');
|
732 |
+
}
|
733 |
+
|
734 |
+
if (text.match(/\\begin\{align\}/g)) {
|
735 |
+
const alignButtons = document.querySelectorAll('.toolbar-button[title="Align"]');
|
736 |
+
alignButtons.forEach(button => button.style.color = '#4ec9b0');
|
737 |
+
}
|
738 |
+
|
739 |
+
if (text.match(/\\\w+/g)) {
|
740 |
+
// Commands are present
|
741 |
+
}
|
742 |
+
|
743 |
+
if (text.match(/\$/g)) {
|
744 |
+
const mathButtons = document.querySelectorAll('.toolbar-button[title="Inline Math"]');
|
745 |
+
mathButtons.forEach(button => button.style.color = '#c586c0');
|
746 |
+
}
|
747 |
+
}
|
748 |
+
|
749 |
+
// Set up an interval to periodically check and update highlighting
|
750 |
+
setInterval(applySyntaxHighlighting, 1000);
|
751 |
+
});
|
752 |
+
</script>
|
753 |
""", unsafe_allow_html=True)
|
754 |
|
755 |
# Function to create a functional VS Code-like toolbar
|
|
|
880 |
"""
|
881 |
st.markdown(status_html, unsafe_allow_html=True)
|
882 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
883 |
# Render a document outline based on section hierarchy
|
884 |
def render_document_outline(structure):
|
885 |
if not structure:
|
|
|
1052 |
|
1053 |
st.markdown('</div>', unsafe_allow_html=True)
|
1054 |
|
1055 |
+
# Display a simple F5 keyboard shortcut reminder
|
1056 |
+
def render_f5_shortcut():
|
1057 |
+
st.markdown(
|
1058 |
+
'<div class="shortcut-item">'
|
1059 |
+
'<span class="shortcut-key">F5</span>'
|
1060 |
+
'<span>Press F5 to compile the document</span>'
|
1061 |
+
'</div>',
|
1062 |
+
unsafe_allow_html=True
|
1063 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1064 |
|
1065 |
# Main application
|
1066 |
def main():
|
|
|
1075 |
st.session_state.errors = []
|
1076 |
if 'warnings' not in st.session_state:
|
1077 |
st.session_state.warnings = []
|
|
|
|
|
1078 |
|
1079 |
# Check installation status
|
1080 |
if not is_pdflatex_installed():
|
|
|
1085 |
|
1086 |
with col1:
|
1087 |
# Create tabs for main editing area with VS Code style
|
1088 |
+
editor_tabs = st.tabs(["Editor", "Settings"])
|
1089 |
|
1090 |
with editor_tabs[0]:
|
1091 |
# VS Code-like editor interface
|
|
|
1097 |
# Toolbar with functional buttons
|
1098 |
render_functional_toolbar()
|
1099 |
|
1100 |
+
# Editor with VS Code styling and syntax highlighting
|
1101 |
+
st.markdown('<div id="syntax-highlighting-editor">', unsafe_allow_html=True)
|
1102 |
latex_code = st.text_area(
|
1103 |
"",
|
1104 |
value=st.session_state.latex_code,
|
|
|
1114 |
|
1115 |
st.markdown('</div>', unsafe_allow_html=True)
|
1116 |
|
1117 |
+
# F5 shortcut reminder
|
1118 |
+
render_f5_shortcut()
|
1119 |
+
|
1120 |
# Control buttons with VS Code styling
|
1121 |
st.markdown('<div class="button-group">', unsafe_allow_html=True)
|
1122 |
+
compile_btn = st.button("Compile", help="Compile LaTeX to PDF (F5)")
|
1123 |
load_template_btn = st.button("Load Template", help="Load default template")
|
1124 |
clear_btn = st.button("Clear", help="Clear editor content")
|
1125 |
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
1138 |
st.rerun()
|
1139 |
|
1140 |
with editor_tabs[1]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1141 |
st.markdown("<h3>LaTeX Settings</h3>", unsafe_allow_html=True)
|
1142 |
|
1143 |
st.markdown('<div class="control-panel">', unsafe_allow_html=True)
|
|
|
1161 |
index=0, key="editor_theme")
|
1162 |
|
1163 |
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
1164 |
|
1165 |
with col2:
|
1166 |
# Output tabs with VS Code style
|
|
|
1250 |
output_format="PNG")
|
1251 |
st.markdown('</div>', unsafe_allow_html=True)
|
1252 |
else:
|
1253 |
+
st.info("Click 'Compile' to generate PDF output or press F5")
|
1254 |
|
1255 |
with output_tabs[1]:
|
1256 |
# Document structure/outline view (with type check)
|