Skip to content

Commit

Permalink
Style display math elements
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanchandra committed Mar 11, 2015
1 parent 099b496 commit 8873c7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 5 additions & 1 deletion _sass/base/_global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ dt {
dd {
margin-left: 2em;
}
p, ol, ul, dl {
p, ol, ul, dl, .math-display {
line-height: 1.5;
margin-bottom: 1em;
}
.math-display {
display: inline-block;
width: 100%;
}
ol, ul {
list-style-position: inside;
}
Expand Down
14 changes: 8 additions & 6 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ Array.prototype.forEach.call(elements, function(element) {
// Extract math markdown
var textToRender = element.innerText || element.textContent;

// Support inline math
// Create span for KaTeX
var katexElement = document.createElement('span');

// Support inline and display math
if (element.type.indexOf('mode=display') != -1){
katexElement.className += "math-display";
textToRender = '\\displaystyle {' + textToRender + '}';
} else {
katexElement.className += "math-inline";
}

// Create span for KaTeX
var katexElement = document.createElement('span');

katex.render(textToRender, katexElement);

// Insert KaTeX span
element.parentNode.insertBefore(katexElement, element);
}
});

0 comments on commit 8873c7a

Please sign in to comment.