@@ -57,6 +57,8 @@ import Dexie from 'dexie'
5757import JSZip from 'jszip'
5858import QrScanner from 'qr-scanner'
5959import { JupyterEdit } from '@fails-components/jupyter-react-edit'
60+ import katex from 'katex'
61+ import 'katex/dist/katex.min.css'
6062
6163QrScanner . WORKER_PATH = new URL (
6264 '../node_modules/qr-scanner/qr-scanner-worker.min.js' ,
@@ -1324,7 +1326,7 @@ class App extends Component {
13241326 < span className = 'p-buttonset' >
13251327 { ! this . state . ispolledit [ node . id ] ? (
13261328 < Button
1327- label = { node . name }
1329+ label = { this . maybeUseLatex ( node . name ) }
13281330 className = 'p-button-text p-button-secondary fails-tree'
13291331 tooltip = { 'Question text' }
13301332 tooltipOptions = { ttopts }
@@ -1437,7 +1439,7 @@ class App extends Component {
14371439 < span className = 'p-buttonset' >
14381440 { ! this . state . ispolledit [ node . id ] ? (
14391441 < Button
1440- label = { node . name }
1442+ label = { this . maybeUseLatex ( node . name ) }
14411443 className = 'p-button-text p-button-secondary fails-tree'
14421444 tooltip = { 'Answer text' }
14431445 tooltipOptions = { ttopts }
@@ -1995,6 +1997,56 @@ class App extends Component {
19951997 }
19961998 }
19971999
2000+ // latex duplicate to lecture app, maybe move to other package
2001+ maybeUseLatex ( item ) {
2002+ return this . detectLatex ( item ) ? this . convertToLatex ( item ) : item
2003+ }
2004+
2005+ detectLatex ( string ) {
2006+ return string . indexOf ( '$' ) !== - 1
2007+ }
2008+
2009+ convertToLatex ( string ) {
2010+ const retarray = [ ]
2011+ let secstart = 0
2012+ let seclatex = false
2013+ for ( let curpos = 0 ; curpos < string . length ; curpos ++ ) {
2014+ const curchar = string . charAt ( curpos )
2015+ if ( curchar === '$' ) {
2016+ if ( seclatex ) {
2017+ const html = katex . renderToString (
2018+ string . substring ( secstart , curpos ) ,
2019+ {
2020+ throwOnError : false ,
2021+ displayMode : false
2022+ }
2023+ )
2024+ retarray . push (
2025+ < span dangerouslySetInnerHTML = { { __html : html } } > </ span >
2026+ )
2027+ secstart = curpos + 1
2028+ seclatex = false
2029+ } else {
2030+ retarray . push (
2031+ < React . Fragment >
2032+ { string . substring ( secstart , curpos - 1 ) } { ' ' }
2033+ </ React . Fragment >
2034+ )
2035+ secstart = curpos + 1
2036+ seclatex = true
2037+ }
2038+ }
2039+ }
2040+
2041+ retarray . push (
2042+ < React . Fragment >
2043+ { string . substring ( secstart , string . length ) } { ' ' }
2044+ </ React . Fragment >
2045+ )
2046+
2047+ return retarray
2048+ }
2049+
19982050 render ( ) {
19992051 let polldata = [ ]
20002052 let jupyterdata = [
0 commit comments