diff --git a/apps/android/src/ui/math-formula.tsx b/apps/android/src/ui/math-formula.tsx new file mode 100644 index 0000000..319916f --- /dev/null +++ b/apps/android/src/ui/math-formula.tsx @@ -0,0 +1,19 @@ +import { memo, useMemo } from 'react' +import { ScrollView, Text, useWindowDimensions } from 'react-native' +import { SvgXml } from 'react-native-svg' +import { renderMathSvg } from './math-svg' +import { useTheme } from './theme-context' +import { spacing, typeForDensity } from './theme' + +export const MathFormula = memo(function MathFormula({ source, display = false }: { source: string; display?: boolean }) { + const { colors, density } = useTheme() + const { fontScale, width: screenWidth } = useWindowDimensions() + const result = useMemo(() => renderMathSvg(source, display), [source, display]) + if (!result) return {display ? `\\[${source}\\]` : `\\(${source}\\)`} + const bodySize = typeForDensity(density).body.fontSize + const size = display ? bodySize * fontScale : Math.min(bodySize * fontScale, Math.max(80, screenWidth - 96) / result.width) + const formula = + return display + ? {formula} + : formula +})