Skip to content

Commit 62de7e7

Browse files
JupyterSplashTikZ now checks if the string tikz contains "begin{tikzpicture}" (#134)
JupyterSplashTikZ now checks if the string tikz contains "begin{tikzpicture}"; in this way it becomes compatible with the TikZ code generated by IntPic
1 parent e97a4d6 commit 62de7e7

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

gap/JupyterUtil.gi

+13-6
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,25 @@ end);
4545
# To show TikZ in a GAP jupyter notebook
4646
BindGlobal("JupyterSplashTikZ",
4747
function(tikz)
48-
local tmpdir, fn, header, ltx, svgfile, stream, svgdata, tojupyter;
48+
local tmpdir, fn, header, ltx, svgfile, stream, svgdata, tojupyter,hasbp;
49+
50+
hasbp:=PositionSublist(tikz,"begin{tikzpicture}")<>fail;
4951

5052
header:=Concatenation( "\\documentclass[crop,tikz]{standalone}\n",
5153
"\\usepackage{pgfplots}",
5254
"\\makeatletter\n",
5355
"\\batchmode\n",
5456
"\\nonstopmode\n",
55-
"\\begin{document}",
56-
"\\begin{tikzpicture}");
57+
"\\begin{document}\n");
58+
if not(hasbp) then
59+
Concatenation(header, "\\begin{tikzpicture}\n");
60+
fi;
5761
header:=Concatenation(header, tikz);
58-
header:=Concatenation(header,"\\end{tikzpicture}\n\\end{document}");
59-
62+
if hasbp then
63+
header:=Concatenation(header,"\\end{document}");
64+
else
65+
header:=Concatenation(header,"\\end{tikzpicture}\n\\end{document}");
66+
fi;
6067
tmpdir := DirectoryTemporary();
6168
fn := Filename( tmpdir, "svg_get" );
6269

@@ -85,7 +92,7 @@ function(tikz)
8592
svgdata := ReadAll( stream );
8693
tojupyter := rec( json := true, source := "gap",
8794
data := rec( ( "image/svg+xml" ) := svgdata ),
88-
metadata := rec( ( "image/svg+xml" ) := rec( width := 500, height := 500 ) ) );
95+
metadata := rec( ( "image/svg+xml" ) := rec( width := "100%", height := "100%" ) ) );
8996
CloseStream( stream );
9097
else
9198
tojupyter := rec( json := true, name := "stdout",

0 commit comments

Comments
 (0)