Skip to content

Commit b1801b3

Browse files
pedritomelenasolexandr-konovalov
authored andcommitted
dealing with macos and linux differences
1 parent 25094c4 commit b1801b3

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

gap/JupyterUtil.gi

+37-21
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ 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, b64file, hasbp, img;
48+
local tmpdir, fn, header, ltx, svgfile, stream, svgdata, tojupyter, hasbp, img, b64file;
4949

5050
hasbp:=PositionSublist(tikz,"begin{tikzpicture}")<>fail;
5151

@@ -77,33 +77,49 @@ function(tikz)
7777

7878
if not( IsExistingFile( Concatenation(fn, ".pdf") ) ) then
7979
tojupyter := rec( json := true, name := "stdout",
80-
data := "No pdf was created; pdflatex is installed in your system?" );
81-
else
82-
svgfile := Concatenation( fn, ".svg" );
83-
b64file := Concatenation( fn, ".b64" );
80+
data := "No pdf was created; pdflatex is installed in your system?",metadata:=rec() );
81+
return JupyterRenderable(tojupyter.data, tojupyter.metadata);
82+
fi;
83+
84+
svgfile := Concatenation( fn, ".svg" );
85+
b64file := Concatenation( fn, ".b64" );
86+
if ARCH_IS_MAC_OS_X() then
87+
ltx := Concatenation( "pdf2svg ", Concatenation( fn, ".pdf" ), " ",
88+
svgfile, "; base64 -i ", svgfile," >> ", b64file );
89+
90+
else
8491
ltx := Concatenation( "pdf2svg ", Concatenation( fn, ".pdf" ), " ",
85-
svgfile, "; base64 -i ", svgfile," >> ", b64file );
86-
Exec( ltx );
87-
if not( IsExistingFile( svgfile ) ) then
92+
svgfile);
93+
fi;
94+
Exec( ltx );
95+
if not( IsExistingFile( svgfile ) ) then
96+
tojupyter := rec( json := true, name := "stdout",
97+
data := "No svg was created; pdf2svg is installed in your system?", metadata := rec());
98+
return JupyterRenderable(tojupyter.data, tojupyter.metadata);
99+
fi;
100+
if ARCH_IS_MAC_OS_X() then
101+
stream := InputTextFile( b64file );
102+
if stream <> fail then
103+
svgdata := ReadLine( stream );
104+
CloseStream( stream );
105+
else
88106
tojupyter := rec( json := true, name := "stdout",
89-
data := "No svg was created; pdf2svg is installed in your system?", metadata := rec());
107+
data := Concatenation( "Unable to render ", tikz ), metadata := rec() );
90108
return JupyterRenderable(tojupyter.data, tojupyter.metadata);
91-
elif not( IsExistingFile( b64file ) ) then
109+
fi;
110+
else
111+
stream := InputTextFile( svgfile );
112+
if stream <> fail then
113+
svgdata := ReadAll( stream );
114+
svgdata:= SubstitutionSublist(Base64String(svgdata),"\n","");
115+
CloseStream( stream );
116+
else
92117
tojupyter := rec( json := true, name := "stdout",
93-
data := "No svg was created; base64 is installed in your system?", metadata := rec());
118+
data := Concatenation( "Unable to render ", tikz ), metadata := rec() );
94119
return JupyterRenderable(tojupyter.data, tojupyter.metadata);
95-
else
96-
stream := InputTextFile( b64file );
97-
if stream <> fail then
98-
svgdata := ReadLine( stream );
99-
CloseStream( stream );
100-
else
101-
tojupyter := rec( json := true, name := "stdout",
102-
data := Concatenation( "Unable to render ", tikz ), metadata := rec() );
103-
return JupyterRenderable(tojupyter.data, tojupyter.metadata);
104-
fi;
105120
fi;
106121
fi;
122+
107123
img:=Concatenation("<img src='data:image/svg+xml;base64,", svgdata,"'>");
108124
return Objectify( JupyterRenderableType, rec( data := rec( ("text/html") := img), metadata:=rec() ));
109125
end);

0 commit comments

Comments
 (0)