@@ -237,3 +237,132 @@ def add_math(n):
237
237
dash_dcc .wait_for_element ("#md2 svg" )
238
238
assert gravity not in dash_dcc ._get_element ("#md2" ).text
239
239
assert dash_dcc .driver .execute_script ("return !!window.MathJax" )
240
+
241
+
242
+ def test_mkdw008_mathjax_visual (dash_dcc ):
243
+ app = Dash (__name__ , eager_loading = True , assets_folder = "../../assets" )
244
+
245
+ false = False
246
+
247
+ # json
248
+ fig = {
249
+ "data" : [
250
+ {"x" : [0 , 1 ], "y" : [0 , 1.414 ], "name" : "$E^2=m^2c^4+p^2c^2$" },
251
+ {
252
+ "x" : [0 , 1 ],
253
+ "y" : [1.4 , 0.1 ],
254
+ "type" : "bar" ,
255
+ "name" : "$x=\\ frac{-b \\ pm \\ sqrt{b^2-4ac}}{2a}$" ,
256
+ },
257
+ {
258
+ "type" : "pie" ,
259
+ "values" : [1 , 9 ],
260
+ "labels" : ["$\\ frac{1}{10}=10\\ %$" , "$\\ frac{9}{10}=90\\ %$" ],
261
+ "domain" : {"x" : [0.3 , 0.75 ], "y" : [0.55 , 1 ]},
262
+ },
263
+ {
264
+ "type" : "heatmap" ,
265
+ "z" : [[1 , 2 ], [3 , 4 ]],
266
+ "xaxis" : "x2" ,
267
+ "yaxis" : "y2" ,
268
+ "colorbar" : {"y" : 0.225 , "len" : 0.45 },
269
+ },
270
+ ],
271
+ "layout" : {
272
+ "yaxis" : {"domain" : [0 , 0.45 ], "title" : {"text" : "$y=\\ sin{2 \\ theta}$" }},
273
+ "xaxis" : {
274
+ "domain" : [0 , 0.45 ],
275
+ "title" : {"text" : "$x=\\ int_0^a a^2+1$" },
276
+ "tickvals" : [0 , 1 ],
277
+ "ticktext" : ["$\\ frac{0}{100}$" , "$\\ frac{100}{100}$" ],
278
+ },
279
+ "xaxis2" : {"domain" : [0.85 , 1 ], "anchor" : "y2" },
280
+ "yaxis2" : {
281
+ "domain" : [0 , 0.45 ],
282
+ "anchor" : "x2" ,
283
+ "title" : {"text" : "$(||01\\ rangle+|10\\ rangle)/\\ sqrt2$" },
284
+ },
285
+ "height" : 500 ,
286
+ "width" : 800 ,
287
+ "margin" : {"r" : 250 },
288
+ "title" : {
289
+ "text" : "$i\\ hbar\\ frac{d\\ Psi}{dt}=-[V-\\ frac{-\\ hbar^2}{2m}\\ nabla^2]\\ Psi$"
290
+ },
291
+ "annotations" : [
292
+ {
293
+ "text" : "$(top,left)$" ,
294
+ "showarrow" : false ,
295
+ "xref" : "paper" ,
296
+ "yref" : "paper" ,
297
+ "xanchor" : "left" ,
298
+ "yanchor" : "top" ,
299
+ "x" : 0 ,
300
+ "y" : 1 ,
301
+ "textangle" : 10 ,
302
+ "bordercolor" : "#0c0" ,
303
+ "borderpad" : 3 ,
304
+ "bgcolor" : "#dfd" ,
305
+ },
306
+ {
307
+ "text" : "$(right,bottom)$" ,
308
+ "xref" : "paper" ,
309
+ "yref" : "paper" ,
310
+ "xanchor" : "right" ,
311
+ "yanchor" : "bottom" ,
312
+ "x" : 0.2 ,
313
+ "y" : 0.7 ,
314
+ "ax" : - 20 ,
315
+ "ay" : - 20 ,
316
+ "textangle" : - 30 ,
317
+ "bordercolor" : "#0c0" ,
318
+ "borderpad" : 3 ,
319
+ "bgcolor" : "#dfd" ,
320
+ "opacity" : 0.5 ,
321
+ },
322
+ {"text" : "$not-visible$" , "visible" : false },
323
+ {
324
+ "text" : "$^{29}Si$" ,
325
+ "x" : 0.7 ,
326
+ "y" : 0.7 ,
327
+ "showarrow" : false ,
328
+ "xanchor" : "right" ,
329
+ "yanchor" : "top" ,
330
+ },
331
+ {
332
+ "text" : "$^{17}O$" ,
333
+ "x" : 0.7 ,
334
+ "y" : 0.7 ,
335
+ "ax" : 15 ,
336
+ "ay" : - 15 ,
337
+ "xanchor" : "left" ,
338
+ "yanchor" : "bottom" ,
339
+ },
340
+ ],
341
+ },
342
+ }
343
+
344
+ app .layout = html .Div (
345
+ children = [
346
+ dcc .Markdown ("# h1 tag with inline MathJax: $E=mc^2$" , mathjax = True ),
347
+ dcc .Markdown (
348
+ """
349
+ ## h2 tag with MathJax block:
350
+ $$
351
+ \\ frac{1}{(\\ sqrt{\\ phi \\ sqrt{5}}-\\ phi) e^{\\ frac25 \\ pi}} =
352
+ 1+\\ frac{e^{-2\\ pi}} {1+\\ frac{e^{-4\\ pi}} {1+\\ frac{e^{-6\\ pi}}
353
+ {1+\\ frac{e^{-8\\ pi}} {1+\\ ldots} } } }
354
+ $$
355
+ ## Next line.
356
+ """ ,
357
+ mathjax = True ,
358
+ ),
359
+ dcc .Graph (mathjax = True , id = "graph-with-math" , figure = fig ),
360
+ dcc .Markdown ("### No MathJax: Apple: $2, Orange: $3" ),
361
+ dcc .Graph (id = "graph-without-math" , figure = fig ),
362
+ ]
363
+ )
364
+
365
+ dash_dcc .start_server (app )
366
+ dash_dcc .percy_snapshot ("mkdw008 - markdown and graph with/without mathjax" )
367
+
368
+ assert dash_dcc .get_logs () == []
0 commit comments