Commit 6494604

HPCesia <me@hpcesia.com>
2026-09-19 08:54:58
style: port math style from typst main
1 parent 86e3de4
Changed files (1)
src
styles
article
src/styles/article/math.scss
@@ -10,24 +10,82 @@ article math {
     margin-block: 1em;
   }
 
-  /* See https://typst.app/docs/reference/math/#alignment */
-  /* In Typst, each alignment point simply alternates between right-aligned/left-aligned. */
-  mtable.aligned,
-  mtable.cases {
-    & > mtr > mtd {
-      &:only-child {
-        text-align: left;
-      }
-      &:not(:only-child) {
-        &:nth-child(odd) {
-          text-align: right;
-          padding-right: 0;
-        }
-        &:nth-child(even) {
-          text-align: left;
-          padding-left: 0;
-        }
-      }
-    }
+  /* Ported from Typst's generated equation CSS. */
+  /* See https://github.com/typst/typst/blob/094b9634d2aa506757d342103411a33a347e3012/crates/typst-html/src/mathml.rs */
+
+  /* Alignment */
+  mtable.right-align > mtr > mtd,
+  mtable > mtr > mtd.right-align,
+  mtable.left-align > mtr > mtd.right-align,
+  mtable.aligned > mtr > mtd:nth-child(odd) {
+    justify-items: end;
+    text-align: right;
+  }
+  mtable.cases > mtr > mtd,
+  mtable.left-align > mtr > mtd,
+  mtable > mtr > mtd.left-align,
+  mtable.aligned > mtr > mtd:nth-child(even),
+  &:is(:not([display])) > mtable.multiline-equation > mtr > mtd {
+    justify-items: start;
+    text-align: left;
+  }
+  mtable.cases > mtr > mtd,
+  mtable.aligned > mtr > mtd,
+  mtable > mtr > mtd.flushed,
+  mtable > mtr > mtd.left-flush {
+    padding-left: 0;
+  }
+  mtable.cases > mtr > mtd,
+  mtable.aligned > mtr > mtd,
+  mtable > mtr > mtd.flushed,
+  mtable > mtr > mtd.right-flush {
+    padding-right: 0;
+  }
+
+  /* Tables */
+  mtable {
+    math-style: inherit;
+  }
+  mtd {
+    math-depth: auto-add;
+    math-style: compact;
+    math-shift: compact;
+  }
+
+  /* Equations */
+  mtable.multiline-equation > mtr > mtd {
+    math-depth: inherit;
+    math-style: inherit;
+    math-shift: inherit;
+    padding: 0;
+  }
+  & > mtable.multiline-equation > mtr:not(:last-child) > mtd {
+    padding-bottom: 0.5em;
+  }
+
+  /* Fractions */
+  mfrac {
+    padding-inline: 0;
+    margin-inline: 0.1em;
+  }
+
+  /* Accents */
+  mover[accent="true" i] > :first-child {
+    font-feature-settings: "dtls";
+  }
+  mover.dotted[accent="true" i] > :first-child {
+    font-feature-settings: "dtls" 0;
+  }
+
+  /* Other rules for scriptlevel, displaystyle and math-shift */
+  munder > :nth-child(2),
+  munderover > :nth-child(2) {
+    math-shift: compact;
+  }
+  munder[accentunder="true" i] > :not(:first-child),
+  mover[accent="true" i] > :not(:first-child) {
+    math-depth: inherit;
+    math-style: inherit;
+    math-shift: inherit;
   }
 }