@@ -12,6 +12,7 @@ import React, { useContext, useEffect, useRef, useState } from 'react';
1212import ApiContext from '../api/ApiContext' ;
1313import EventSystem from '../EventSystem' ;
1414import Pane from './Pane' ;
15+ import { typesetMathJax } from './utils/mathjaxHelpers' ;
1516
1617const DEFAULT_HEIGHT = 400 ;
1718const DEFAULT_WIDTH = 300 ;
@@ -25,6 +26,7 @@ function ImagePane(props) {
2526 // --------------
2627 const paneRef = useRef ( ) ;
2728 const imgRef = useRef ( ) ;
29+ const captionRef = useRef ( ) ;
2830 const mouseLocationRef = useRef ( { x : null , y : null } ) ;
2931 const [ view , setView ] = useState ( { scale : 1 , tx : 0 , ty : 0 } ) ;
3032 const [ imgDim , setImgDim ] = useState ( { width : null , height : 0 } ) ;
@@ -147,7 +149,11 @@ function ImagePane(props) {
147149 const commitSliderSelection = ( value ) => {
148150 const idx = parseInt ( value , 10 ) ;
149151 if ( Number . isNaN ( idx ) ) return ;
150- sendPaneMessage ( { event_type : 'SliderMoved' , index : idx , pane_data : false } , id , envID ) ;
152+ sendPaneMessage (
153+ { event_type : 'SliderMoved' , index : idx , pane_data : false } ,
154+ id ,
155+ envID
156+ ) ;
151157 } ;
152158
153159 const finalizeSlider = ( evt ) => {
@@ -307,12 +313,20 @@ function ImagePane(props) {
307313 content = content [ actualSelected ] ;
308314 }
309315
316+ useEffect ( ( ) => {
317+ let cancelled = false ;
318+ typesetMathJax ( captionRef . current , ( ) => cancelled ) ;
319+ return ( ) => {
320+ cancelled = true ;
321+ } ;
322+ } , [ content . caption ] ) ;
323+
310324 // add caption as widget
311325 if ( content . caption ) {
312326 widgets . splice (
313327 0 ,
314328 0 ,
315- < span className = "widget" key = "img_caption" >
329+ < span className = "widget" key = "img_caption" ref = { captionRef } >
316330 { content . caption }
317331 </ span >
318332 ) ;
0 commit comments