Spaces:
Sleeping
Sleeping
Siyuan Hu
commited on
Commit
·
fb75b9f
1
Parent(s):
20a552d
fix(fonts): add font fallbacks in template; patch theme file inside uploaded/repo zip during debug compile when needed
Browse files- app.py +14 -1
- template/beamerthemegemini.sty +31 -9
app.py
CHANGED
|
@@ -736,7 +736,7 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 736 |
logs.append("❌ No .tex file found in uploaded zip")
|
| 737 |
_write_logs(LOG_PATH, logs)
|
| 738 |
return "<div style='color:#b00'>No .tex found in uploaded zip</div>"
|
| 739 |
-
# Disable logoleft if missing
|
| 740 |
try:
|
| 741 |
logos_dir = tex_path.parent / "logos"
|
| 742 |
has_left = False
|
|
@@ -753,6 +753,19 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 753 |
if new_txt != txt:
|
| 754 |
tex_path.write_text(new_txt, encoding="utf-8")
|
| 755 |
logs.append("ℹ️ No left_logo found; disabled \\logoleft in uploaded project.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 756 |
except Exception as e:
|
| 757 |
logs.append(f"⚠️ left_logo adjust failed: {e}")
|
| 758 |
# Compile
|
|
|
|
| 736 |
logs.append("❌ No .tex file found in uploaded zip")
|
| 737 |
_write_logs(LOG_PATH, logs)
|
| 738 |
return "<div style='color:#b00'>No .tex found in uploaded zip</div>"
|
| 739 |
+
# Disable logoleft if missing; also patch local theme fonts if present
|
| 740 |
try:
|
| 741 |
logos_dir = tex_path.parent / "logos"
|
| 742 |
has_left = False
|
|
|
|
| 753 |
if new_txt != txt:
|
| 754 |
tex_path.write_text(new_txt, encoding="utf-8")
|
| 755 |
logs.append("ℹ️ No left_logo found; disabled \\logoleft in uploaded project.")
|
| 756 |
+
# Patch theme font fallbacks if the zip includes the theme file
|
| 757 |
+
for sty in work_zip_dir.rglob("beamerthemegemini.sty"):
|
| 758 |
+
try:
|
| 759 |
+
s = sty.read_text(encoding="utf-8")
|
| 760 |
+
if "\\newfontfamily\\Raleway" in s or "\\newfontfamily\\Lato" in s:
|
| 761 |
+
import re as _re
|
| 762 |
+
s = _re.sub(r"\\newfontfamily\\Raleway\[[^\]]*\]\{Raleway\}", r"\\IfFontExistsTF{Raleway}{\\newfontfamily\\Raleway[Ligatures=TeX]{Raleway}}{\\newfontfamily\\Raleway[Ligatures=TeX]{DejaVu Sans}}", s)
|
| 763 |
+
s = _re.sub(r"\\newfontfamily\\Lato\[[^\]]*\]\{Lato\}", r"\\IfFontExistsTF{Lato}{\\newfontfamily\\Lato[Ligatures=TeX]{Lato}}{\\newfontfamily\\Lato[Ligatures=TeX]{DejaVu Sans}}", s)
|
| 764 |
+
s = _re.sub(r"\\setsansfont\{Lato\}\[[^\]]*\]", r"\\IfFontExistsTF{Lato}{\\setsansfont{Lato}[UprightFont=*-Light,ItalicFont=*-LightItalic,BoldFont=*-Regular,BoldItalicFont=*-Italic]}{\\IfFontExistsTF{DejaVu Sans}{\\setsansfont{DejaVu Sans}[BoldFont=*-Bold,ItalicFont=*-Oblique,BoldItalicFont=*-BoldOblique]}{\\setsansfont{Latin Modern Sans}}}", s)
|
| 765 |
+
sty.write_text(s, encoding="utf-8")
|
| 766 |
+
logs.append(f"🛠️ Patched fonts in {sty.relative_to(work_zip_dir)}")
|
| 767 |
+
except Exception as e:
|
| 768 |
+
logs.append(f"⚠️ Font patch failed for {sty}: {e}")
|
| 769 |
except Exception as e:
|
| 770 |
logs.append(f"⚠️ left_logo adjust failed: {e}")
|
| 771 |
# Compile
|
template/beamerthemegemini.sty
CHANGED
|
@@ -15,17 +15,39 @@
|
|
| 15 |
% Fonts
|
| 16 |
% ====================
|
| 17 |
|
| 18 |
-
|
| 19 |
-
\newfontfamily\Lato[Ligatures=TeX]{Lato}
|
| 20 |
-
|
| 21 |
\usefonttheme{professionalfonts}
|
| 22 |
|
| 23 |
-
\
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
\setbeamerfont{headline}{family=\Raleway}
|
| 31 |
\setbeamerfont{headline title}{size=\Huge,series=\bfseries}
|
|
|
|
| 15 |
% Fonts
|
| 16 |
% ====================
|
| 17 |
|
| 18 |
+
% Prefer Raleway/Lato if available; otherwise fall back to DejaVu or Latin Modern Sans
|
|
|
|
|
|
|
| 19 |
\usefonttheme{professionalfonts}
|
| 20 |
|
| 21 |
+
\IfFontExistsTF{Raleway}{
|
| 22 |
+
\newfontfamily\Raleway[Ligatures=TeX]{Raleway}
|
| 23 |
+
}{
|
| 24 |
+
\newfontfamily\Raleway[Ligatures=TeX]{DejaVu Sans}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
\IfFontExistsTF{Lato}{
|
| 28 |
+
\newfontfamily\Lato[Ligatures=TeX]{Lato}
|
| 29 |
+
}{
|
| 30 |
+
\newfontfamily\Lato[Ligatures=TeX]{DejaVu Sans}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
\IfFontExistsTF{Lato}{
|
| 34 |
+
\setsansfont{Lato}[
|
| 35 |
+
UprightFont=*-Light,
|
| 36 |
+
ItalicFont=*-LightItalic,
|
| 37 |
+
BoldFont=*-Regular,
|
| 38 |
+
BoldItalicFont=*-Italic
|
| 39 |
+
]
|
| 40 |
+
}{
|
| 41 |
+
\IfFontExistsTF{DejaVu Sans}{
|
| 42 |
+
\setsansfont{DejaVu Sans}[
|
| 43 |
+
BoldFont=*-Bold,
|
| 44 |
+
ItalicFont=*-Oblique,
|
| 45 |
+
BoldItalicFont=*-BoldOblique
|
| 46 |
+
]
|
| 47 |
+
}{
|
| 48 |
+
\setsansfont{Latin Modern Sans}
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
|
| 52 |
\setbeamerfont{headline}{family=\Raleway}
|
| 53 |
\setbeamerfont{headline title}{size=\Huge,series=\bfseries}
|