@@ -2777,10 +2777,95 @@ export abstract class JupyterActions extends Actions<JupyterStoreState> {
2777
2777
const { tag, id } = labels [ label ] ;
2778
2778
return `[${ tag } ](#id=${ id } )` ;
2779
2779
} ) ;
2780
- return noRefs ;
2780
+
2781
+ const figures = transformFigures ( noRefs ) ;
2782
+
2783
+ return figures ;
2781
2784
} ;
2782
2785
}
2783
2786
2787
+ /*
2788
+ Turn this:
2789
+
2790
+ ---
2791
+
2792
+ ...
2793
+
2794
+ \begin{figure}
2795
+ \centering
2796
+ \centerline{\includegraphics[width=WIDTH]{URL}}
2797
+ \caption{CAPTION}
2798
+ \end{figure}
2799
+
2800
+ ...
2801
+
2802
+ ---
2803
+
2804
+ into this:
2805
+
2806
+ ---
2807
+
2808
+ ...
2809
+
2810
+ <div style="text-align:center"><img src="URL" style="width:WIDTH"/></div>
2811
+ \begin{equation}
2812
+ \text{CAPTION}
2813
+ \end{equation}
2814
+
2815
+ ...
2816
+
2817
+ ---
2818
+
2819
+ There can be lots of figures.
2820
+
2821
+ */
2822
+
2823
+ function transformFigures ( content : string ) : string {
2824
+ while ( true ) {
2825
+ const i = content . indexOf ( "\\begin{figure}" ) ;
2826
+ if ( i == - 1 ) {
2827
+ return content ;
2828
+ }
2829
+ const j = content . indexOf ( "\\end{figure}" ) ;
2830
+ if ( j == - 1 ) {
2831
+ return content ;
2832
+ }
2833
+ const k = content . indexOf ( "\\includegraphics" ) ;
2834
+ if ( k == - 1 ) {
2835
+ return content ;
2836
+ }
2837
+ const c = content . indexOf ( "\\caption{" ) ;
2838
+ if ( c == - 1 ) {
2839
+ return content ;
2840
+ }
2841
+ const c2 = content . lastIndexOf ( "}" , j ) ;
2842
+ if ( c2 == - 1 ) {
2843
+ return content ;
2844
+ }
2845
+
2846
+ const w = content . indexOf ( "width=" ) ;
2847
+ const w2 = content . indexOf ( "{" , k ) ;
2848
+ const w3 = content . indexOf ( "}" , k ) ;
2849
+ if ( w2 == - 1 || w3 == - 1 ) {
2850
+ return content ;
2851
+ }
2852
+ let style = "" ;
2853
+ if ( w != - 1 ) {
2854
+ style = `width:${ content . slice ( w + "width=" . length , w2 - 1 ) } ` ;
2855
+ }
2856
+ const url = content . slice ( w2 + 1 , w3 ) ;
2857
+ const caption = content . slice ( c + "\\caption{" . length , c2 ) ;
2858
+
2859
+ const md = `\n\n<div style="text-align:center"><img src="${ url } " style="${ style } "/></div>\n\n
2860
+ \\begin{equation}
2861
+ \\text{${ caption } }
2862
+ \\end{equation}\n\n` ;
2863
+
2864
+ content =
2865
+ content . slice ( 0 , i ) + md + content . slice ( j + "\\end{figure}" . length ) ;
2866
+ }
2867
+ }
2868
+
2784
2869
function extractLabel ( content : string ) : string {
2785
2870
const i = content . indexOf ( "{" ) ;
2786
2871
const j = content . lastIndexOf ( "}" ) ;
0 commit comments