Skip to content

Your lightweight open-source personal agent.

fix(webui): prevent equation tags from overlapping formulas

chengyongrubdb6c369d0d3
diff --git a/webui/src/components/DisplayMath.css b/webui/src/components/DisplayMath.css
index f5a295280..fd2e01080 100644
--- a/webui/src/components/DisplayMath.css
+++ b/webui/src/components/DisplayMath.css
@@ -11,6 +11,7 @@
top: 0;
left: 50%;
width: max-content;
+ min-width: 100%;
padding-block: 0.1em;
transform-origin: top center;
}
@@ -23,6 +24,11 @@
font-size: 1.1em;
}
+/* KaTeX tags are out of flow; reserve equal space to keep the formula centered. */
+.math-fit .katex-html:has(> .tag) {
+ padding-inline: calc(var(--math-tag-width) + 1em);
+}
+
/* Math-heavy prose uses a tighter reading rhythm than ordinary chat. */
.markdown-content:has(.math-fit) {
--cjk-line-height: 1.65;
diff --git a/webui/src/components/DisplayMath.tsx b/webui/src/components/DisplayMath.tsx
index 09f613710..704151738 100644
--- a/webui/src/components/DisplayMath.tsx
+++ b/webui/src/components/DisplayMath.tsx
@@ -9,6 +9,8 @@ export function DisplayMath({ children }: { children: ReactNode }) {
useLayoutEffect(() => {
const update = () => {
if (!frame.current || !content.current) return;
+ const tag = content.current.querySelector<HTMLElement>(".katex-html > .tag");
+ content.current.style.setProperty("--math-tag-width", `${tag?.offsetWidth ?? 0}px`);
const width = content.current.offsetWidth;
const scale = width ? Math.min(1, frame.current.clientWidth / width) : 1;
const height = content.current.offsetHeight * scale;