Skip to content

Commit 40c860a

Browse files
committed
fix mathematical equation
installed kartex
1 parent 5e9c71c commit 40c860a

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

app/blog/posts/now-playing-implementation.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,17 @@ class AudioCNN(nn.Module):
185185
return x
186186
```
187187

188-
# Training with Tiplet Loss
188+
# Training with Triplet Loss
189189

190190
## Triplet Loss
191191

192-
- A tirplet loss ensures that embeddings are learned such that similar sampels are closer in the embedding space and dissimilar samles are farther apart.
192+
- A triplet loss ensures that embeddings are learned such that similar sampels are closer in the embedding space and dissimilar samles are farther apart.
193193
- Formula:
194194

195195
$$
196+
196197
||f(a) - f(p)||_2^2 + margin \leq ||f(a) - f(n)||_2^2
198+
197199
$$
198200

199201
Here, $(f(x))$ is the embedding function (our CNN in this case), and \(a\), \(p\), and \(n\) are the anchor, positive, and negative inputs, respectively.

app/components/mdx.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import Image from 'next/image'
33
import { MDXRemote } from 'next-mdx-remote/rsc'
44
import { highlight } from 'sugar-high'
55
import React from 'react'
6+
import { useEffect } from 'react'
7+
import katex from 'katex'
68

79
function Table({ data }) {
810
let headers = data.headers.map((header, index) => (
@@ -64,6 +66,21 @@ function slugify(str) {
6466
.replace(/\-\-+/g, '-') // Replace multiple - with single -
6567
}
6668

69+
// Math Rendering Component (using KaTeX)
70+
function Math({ children }) {
71+
useEffect(() => {
72+
// Render math equations after the component mounts
73+
const elements = document.querySelectorAll('.math')
74+
elements.forEach((el) => {
75+
katex.render(el.textContent, el, {
76+
throwOnError: false,
77+
})
78+
})
79+
}, [children])
80+
81+
return <span className="math">{children}</span>
82+
}
83+
6784
function createHeading(level) {
6885
const Heading = ({ children }) => {
6986
let slug = slugify(children)
@@ -97,6 +114,7 @@ let components = {
97114
a: CustomLink,
98115
code: Code,
99116
Table,
117+
math: Math, // Add math component for equations
100118
}
101119

102120
export function CustomMDX(props) {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"react-dom": "18.2.0",
2121
"sugar-high": "^0.6.0",
2222
"tailwindcss": "4.0.0-alpha.13",
23-
"typescript": "5.3.3"
23+
"typescript": "5.3.3",
24+
"katex": "^0.16.4"
2425
}
2526
}

0 commit comments

Comments
 (0)