-
Notifications
You must be signed in to change notification settings - Fork 13
TikZ splash now uses png; demos and documentation added #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
872555c
4772806
d56f85a
78d20b6
0a9f235
9d67cde
773752e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <!-- This is an automatically generated file. --> | ||
| <Chapter Label="Chapter_Jupyter_Kernel"> | ||
| <Heading>Jupyter Kernel</Heading> | ||
|
|
||
| <P/> | ||
| A <C>Jupyter Kernel</C> is an object that can handles the Jupyter Protocol. | ||
| <P/> | ||
| <Section Label="Chapter_Jupyter_Kernel_Section_Functions"> | ||
| <Heading>Functions</Heading> | ||
|
|
||
| <P/> | ||
| <ManSection> | ||
| <Func Arg="filename" Name="JUPYTER_LogProtocol" /> | ||
| <Description> | ||
| Opens a file that is used to log all jupyter protocol | ||
| messages. | ||
| </Description> | ||
| </ManSection> | ||
|
|
||
|
|
||
| <ManSection> | ||
| <Func Arg="arg" Name="JUPYTER_UnlogProtocol" /> | ||
| <Description> | ||
| Closes the protocol log. | ||
| </Description> | ||
| </ManSection> | ||
|
|
||
|
|
||
| </Section> | ||
|
|
||
|
|
||
| </Chapter> | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <!ENTITY crypting '<Package>crypting</Package>'> | ||
| <!ENTITY json '<Package>json</Package>'> | ||
| <!ENTITY uuid '<Package>uuid</Package>'> | ||
| <!ENTITY Jupyter '<URL Text="Jupyter">https://jupyter.org</URL>'> | ||
| <!ENTITY ZeroMQ '<URL Text="ZeroMQ">https://zeromq.org</URL>'> | ||
| <!ENTITY IO '<Package>IO</Package>'> | ||
| <!ENTITY ZeroMQInterface '<Package>ZeroMQInterface</Package>'> | ||
| <!ENTITY JupyterKernel '<Package>JupyterKernel</Package>'> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,5 @@ | ||
| InstallMethod( JupyterRender, [ IsRecord ], | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was moved to JupyterRenderable.gi |
||
| r -> Objectify( JupyterRenderableType | ||
| , rec( data := rec( text\/plain := String(r) ) | ||
| , metadata := rec() ) ) ); | ||
|
|
||
| # This is still an ugly hack, but its already much better than before! | ||
| BindGlobal("JupyterSplashDot", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used |
||
| InstallGlobalFunction("JupyterSplashDot", | ||
| function(dot) | ||
| local fn, fd, r; | ||
|
|
||
|
|
@@ -43,13 +38,13 @@ function(group) | |
| end); | ||
|
|
||
| # To show TikZ in a GAP jupyter notebook | ||
| BindGlobal("JupyterSplashTikZ", | ||
| InstallGlobalFunction("JupyterSplashTikZ", | ||
| function(tikz) | ||
| local tmpdir, fn, header, ltx, svgfile, stream, svgdata, tojupyter, hasbp, img, b64file; | ||
| local tmpdir, fn, header, ltx, pngfile, stream, pngdata, tojupyter, hasbp, img, b64file, b64cmd, dims, dimsfile, pdffile, dimx; | ||
|
|
||
| hasbp:=PositionSublist(tikz,"begin{tikzpicture}")<>fail; | ||
| hasbp:=PositionSublist(tikz,"begin[border=2pt]{tikzpicture}")<>fail; | ||
|
|
||
| header:=Concatenation( "\\documentclass[crop,tikz]{standalone}\n", | ||
| header:=Concatenation( "\\documentclass[crop,tikz,border=2pt]{standalone}\n", | ||
| "\\usepackage{pgfplots}", | ||
| "\\makeatletter\n", | ||
| "\\batchmode\n", | ||
|
|
@@ -75,40 +70,58 @@ function(tikz) | |
| Concatenation( fn, ".tex" ), " > ", Concatenation( fn, ".log2" ) ); | ||
| Exec( ltx ); | ||
|
|
||
| if not( IsExistingFile( Concatenation(fn, ".pdf") ) ) then | ||
| pdffile:=Concatenation(fn, ".pdf"); | ||
| if not( IsExistingFile( pdffile ) ) then | ||
| tojupyter := rec( json := true, name := "stdout", | ||
| data := "No pdf was created; pdflatex is installed in your system?",metadata:=rec() ); | ||
| Info(InfoWarning,1,"No pdf was created; pdflatex is installed in your system?"); | ||
| return JupyterRenderable(tojupyter.data, tojupyter.metadata); | ||
| fi; | ||
|
|
||
| svgfile := Concatenation( fn, ".svg" ); | ||
| b64file := Concatenation( fn, ".b64" ); | ||
| if ARCH_IS_MAC_OS_X() then | ||
| ltx := Concatenation( "pdf2svg ", Concatenation( fn, ".pdf" ), " ", | ||
| svgfile, "; base64 -i ", svgfile," >> ", b64file ); | ||
|
|
||
| else | ||
| ltx := Concatenation( "pdf2svg ", Concatenation( fn, ".pdf" ), " ", | ||
| svgfile, "; base64 ", svgfile," >> ", b64file ); | ||
| fi; | ||
| Exec( ltx ); | ||
| if not( IsExistingFile( svgfile ) ) then | ||
| dimsfile:=Concatenation(fn, "-dims.txt"); | ||
| ltx:=Concatenation("pdfinfo ",pdffile," | grep \"Page size\" > ",dimsfile); | ||
| Exec(ltx); | ||
| if not( IsExistingFile( dimsfile ) ) then | ||
| tojupyter := rec( json := true, name := "stdout", | ||
| data := "No svg was created; pdf2svg is installed in your system?", metadata := rec()); | ||
| data := "pdfinfo missing in your system",metadata:=rec() ); | ||
| Info(InfoWarning,1,"No pdf was created; pdflatex is installed in your system?"); | ||
| return JupyterRenderable(tojupyter.data, tojupyter.metadata); | ||
| fi; | ||
| stream := InputTextFile( b64file ); | ||
| if stream <> fail then | ||
| svgdata := ReadAll( stream ); | ||
| CloseStream( stream ); | ||
| else | ||
|
|
||
| stream := InputTextFile( dimsfile ); | ||
| dims:= ReadAll( stream ); | ||
| NormalizeWhitespace(dims); | ||
| CloseStream( stream ); | ||
| dimx:=Float(NormalizedWhitespace(dims{[PositionSublist(dims,": ")+2..PositionSublist(dims," x")]})); | ||
|
|
||
| pngfile := Concatenation( fn, ".png" ); | ||
| ltx := Concatenation( "pdftoppm -r 300 -png ", pdffile, " > ", pngfile); | ||
| Exec( ltx ); | ||
|
|
||
| if not( IsExistingFile( pngfile ) ) then | ||
| tojupyter := rec( json := true, name := "stdout", | ||
| data := Concatenation( "Unable to render ", tikz ), metadata := rec() ); | ||
| data := "No png was created; pdftoppm is installed in your system?",metadata:=rec() ); | ||
| Info(InfoWarning,1,"No png was created; are convert and pdftoppm installed in your system?"); | ||
| return JupyterRenderable(tojupyter.data, tojupyter.metadata); | ||
| fi; | ||
|
|
||
| img:=Concatenation("<img src='data:image/svg+xml;base64,", svgdata,"'>"); | ||
| return Objectify( JupyterRenderableType, rec( data := rec( ("text/html") := img), metadata:=rec() )); | ||
| b64file := Concatenation( fn, ".b64" ); | ||
| if ARCH_IS_MAC_OS_X() then | ||
| b64cmd:="base64 -i "; | ||
| else | ||
| b64cmd:="base64 "; | ||
| fi; | ||
|
|
||
| ltx := Concatenation( b64cmd, pngfile," > ", b64file ); | ||
| Exec( ltx ); | ||
| stream := InputTextFile( b64file ); | ||
| pngdata:= ReadAll( stream ); | ||
| CloseStream( stream ); | ||
|
|
||
|
|
||
| img:=Concatenation("\n <img src='data:image/png;base64,",pngdata,"' style=\"width:",String(dimx),"px;\" >"); | ||
|
|
||
| return Objectify( JupyterRenderableType, rec( data := rec( ("text/html") := img), metadata:=rec( ) )); | ||
| end); | ||
|
|
||
| # This is really not what I should be doing here... | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more descritptive title for the section