Bento MathML
<head>
<meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> <script type="module" async src="https://cdn.ampproject.org/bento.mjs" ></script> <script nomodule src="https://cdn.ampproject.org/bento.js"></script> <script type="module" async src="https://cdn.ampproject.org/v0/bento-mathml-1.0.mjs" ></script> <script nomodule async src="https://cdn.ampproject.org/v0/bento-mathml-1.0.js" ></script> <link rel="stylesheet" type="text/css" href="https://cdn.ampproject.org/v0/bento-mathml-1.0.css" /> <style> body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background: #ecf1f3; } </style>
</head>
<body>
<h2>The Quadratic Formula</h2> <bento-mathml style="height: 40px" data-formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]" ></bento-mathml> <h2>Inline formula</h2> <p> This is an example of a formula, <bento-mathml style="height: 40px; width: 147px" inline data-formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]" ></bento-mathml> placed inline in the middle of a block of text. </p>
</body>
Renders a MathML formula in an iframe.
Use bento-mathml as a web component or a React functional component:
↓ Web Component ↓ React / PreactWeb Component
You must include each Bento component's required CSS library to guarantee proper loading and before adding custom styles. Or use the light-weight pre-upgrade styles available inline. See Layout and style.
Import via npm
npm install @bentoproject/mathml
import {defineElement as defineBentoMathml} from '@bentoproject/mathml';
defineBentoMathml();
Include via <script>
<script type="module" src="https://cdn.ampproject.org/bento.mjs" crossorigin="anonymous"></script>
<script nomodule src="https://cdn.ampproject.org/bento.js" crossorigin="anonymous"></script>
<script type="module" src="https://cdn.ampproject.org/v0/bento-mathml-1.0.mjs" crossorigin="anonymous"></script>
<script nomodule src="https://cdn.ampproject.org/v0/bento-mathml-1.0.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.ampproject.org/v0/bento-mathml-1.0.css" crossorigin="anonymous">
Example
<head>
<script type="module" async src="https://cdn.ampproject.org/bento.mjs" ></script> <script nomodule src="https://cdn.ampproject.org/bento.js"></script> <script type="module" async src="https://cdn.ampproject.org/v0/bento-mathml-1.0.mjs" ></script> <script nomodule async src="https://cdn.ampproject.org/v0/bento-mathml-1.0.js" ></script> <link rel="stylesheet" type="text/css" href="https://cdn.ampproject.org/v0/bento-mathml-1.0.css" />
</head>
<body>
<h2>The Quadratic Formula</h2> <bento-mathml style="height: 40px;" data-formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]" ></bento-mathml> <h2>Inline formula</h2> <p> This is an example of a formula, <bento-mathml style="height: 40px; width: 147px" inline data-formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]" ></bento-mathml> placed inline in the middle of a block of text. </p>
</body>
Layout and style
Each Bento component has a small CSS library you must include to guarantee proper loading without content shifts. Because of order-based specificity, you must manually ensure that stylesheets are included before any custom styles.
<link
rel="stylesheet"
type="text/css"
href="https://cdn.ampproject.org/v0/bento-mathml-1.0.css"
/>
Alternatively, you may also make the light-weight pre-upgrade styles available inline:
<style>
bento-mathml {
display: block;
overflow: hidden;
position: relative;
}
</style>
Attributes
data-formula
(required)
Specifies the formula to render.
inline
(optional)
If specified, the component renders inline (inline-block
in CSS).
title
(optional)
Define a title
attribute for the component to propagate to the underlying <iframe>
element. The default value is "MathML formula"
.
Styling
You may use the bento-mathml
element selector to style the accordion freely.
Preact/React Component
Import via npm
npm install @bentoproject/mathml
import React from 'react';
import {BentoMathml} from '@bentoproject/mathml/react';
import '@bentoproject/mathml/styles.css';
function App() {
return (
<>
<h2>The Quadratic Formula</h2>
<BentoMathml
style={{height: 40}}
formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]"
></BentoMathml>
<h2>Inline formula</h2>
<p>
This is an example of a formula,{' '}
<BentoMathml
style={{height: 40, width: 147}}
inline
formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]"
></BentoMathml>
, placed inline in the middle of a block of text. This shows how the formula will fit inside a block of text and can be styled with CSS.
</p>
</>
);
}
Layout and style
Container type
The BentoMathml
component has a defined layout size type. To ensure the component renders correctly, be sure to apply a size to the component and its immediate children via a desired CSS layout (such as one defined with height
, width
, aspect-ratio
, or other such properties). These can be applied inline:
<BentoMathml style={{width: 300, height: 100}}>...</BentoMathml>
Or via className
:
<BentoMathml className="custom-styles">...</BentoMathml>
.custom-styles {
height: 40px;
width: 147px;
}
Props
formula
(required)
Specifies the formula to render.
inline
(optional)
If specified, the component renders inline (inline-block
in CSS).
title
(optional)
Define a title
attribute for the component to propagate to the underlying <iframe>
element. The default value is "MathML formula"
.