# ==================================== # Demonstration of HTML output in GAP # ==================================== # Version history # May 2018: Initial release # Jul 2018: Added HTMLGraphList function to demo # A word on how to develop output like this: # I wrote most of this in a friendly html editor, and tested by # copying and pasting an html preview to TextEdit. # To get into GAP, I ran it through an html minifier, with tr to # fix up strings for GAP format. The command line for my minifier was # minify html_demo.html | tr \"\\n \'\ # A utility function to easily send an html string to output WcHtmlOut:=function(str) return WindowCmd(["HTM", str]); end; # Code to create a 'graph' of a list (requires fig2dev) HTMLGraphList:=function(L) local figstr, i; if not IsList(L) then Print("Argument must be a list"); return fail; fi; figstr:= "#FIG 3.2 Produced GAP code\nLandscape\nCenter\nInches\nLetter \n100.00\nSingle\n-2\n1200 2\n"; for i in [1..Size(L)] do figstr:=Concatenation(figstr, "2 2 0 2 4 17 50 -1 20 0.000 0 0 -1 0 0 5\n\t"); figstr:=Concatenation(figstr, " ", String(i*300), " ", String(0)); figstr:=Concatenation(figstr, " ", String(i*300), " ", String(L[i]*400)); figstr:=Concatenation(figstr, " ", String((i+1)*300), " ", String(L[i]*400)); figstr:=Concatenation(figstr, " ", String((i+1)*300), " ", String(0)); figstr:=Concatenation(figstr, " ", String(i*300), " ", String(0)); figstr:=Concatenation(figstr, "\n"); od; PrintTo("/tmp/gap_figgraph.fig", figstr); Exec("bash -l -c 'fig2dev -L png /tmp/gap_figgraph.fig /tmp/gap_figgraph.png'"); WcHtmlOut("a graphic from my webpage
"); RemoveFile("/tmp/gap_figgraph.fig"); RemoveFile("/tmp/gap_figgraph.png"); end; # code to pretty-print a matrix using html tables HTMLPrintMatrix:=function(mat) local htmlstr, m, n, i, j; if not IsMatrix(mat) then return fail; fi; htmlstr:=""; Append(htmlstr, ""); m:=DimensionsMat(mat)[1]; n:=DimensionsMat(mat)[2]; for i in [1..m] do Append(htmlstr, ""); for j in [1..n] do Append(htmlstr, ""); od; Append(htmlstr, ""); od; Append(htmlstr, "
"); Append(htmlstr, String(mat[i][j])); Append(htmlstr, "
"); WcHtmlOut(htmlstr); return htmlstr; end; BigBlueString:=function(text) WcHtmlOut(Concatenation("

", text, "

")); end; # put a nicely styled header up Demo_Html_Heading:=function(text) WcHtmlOut(Concatenation("

",text,"

")); end; Demo_Html_Help:=function(helptext, moreinfourl) local htmlstr; # set up (partial) css as in GAPDoc htmlstr:="
"; Append(htmlstr, helptext); Append(htmlstr, "
"); WcHtmlOut(htmlstr); # put out a "more info" link, with less styling WcHtmlOut(Concatenation("

Refer to the Full GAP help for more information.

")); end; # Output a nice header # ======================== WcHtmlOut("
A demonstration/test of HTML output for GAPRuss Woodroofe

"); # Give an overview # ======================== WcHtmlOut("

GAP currently uses VT100 terminal commands to support some limited styling of output. The purpose of this demonstration is to propose using (a subset of) HTML as a more modern way to solve similar problems.

Essentially all modern operating systems support a control to display simple HTML. For example, Gap.app currently uses an NSTextView and NSAttributedString's to display HTML. The subset of HTML and CSS supported is limited, but this demonstration will already show the potential for this. It would be also possible to use a WebKit view to display a richer HTML dialect.

Although the following examples are for now limited to recent versions of Gap.app, I envision that either Gap.app could be ported to Windows/Linux, or else that similar support could easily be given from another frontend."); # Demonstrate graphics # ======================== Demo_Html_Heading("Use case: graphics"); WcHtmlOut("

One obvious use case is that it is easy to use HTML to insert graphical elements into a GAP command session. For example, GAP code could call GraphViz to display a graph, and insert the output inline into the output.

The following example figure is loaded from my webpage (requires internet).

"); WcHtmlOut("a graphic from my webpage
"); WcHtmlOut("

The following example is generated with the
HTMLGraphList([3,1,2]);
command (requires fig2dev to be installed, which should come with xfig)

"); HTMLGraphList([3,1,2]); WcHtmlOut("

Try it yourself! For example:

HTMLGraphList(RandomMat(1,6,Integers)[1]);

"); # Demonstrate html math notation # ======================== Demo_Html_Heading("Use case: mathematical notation and equations"); WcHtmlOut("

Although basic HTML is certainly short of LaTeX or MathJax, it is already possible to express a rich subset of mathematical notations (superscripts, subscripts, italics, greek letters, special symbols, etc). Some examples follow:

"); WcHtmlOut("

  Sn = ⟨ gh

  ∀ εδ ∋ |x - x0| < δ ⇒ |f(x) - f(x0)| < ε

"); # Demonstrate inline-help # ======================== Demo_Html_Heading("Use case: inline help"); WcHtmlOut("

It would require only limited support from GAPDoc for Gap.app to be able to output the results of a help search inline to the GAP command session, with a link to the full article in GAP help.

An example follows. The links are set to point to gap-system.org to avoid file location problems, but could also easily refer to a location on the local disk.

"); # The html help is taken straight from the GAP documentation files, with # the only adjustment being adjusting the URLs to point to a universal location, # and some minification Demo_Html_Help("
50.1-10 SymmetricGroup
‣ SymmetricGroup( [filt, ]deg )( function )
‣ SymmetricGroup( [filt, ]dom )( function )

constructs the symmetric group of degree deg in the category given by the filter filt. If filt is not given it defaults to IsPermGroup (43.1-1). For more information on possible values of filt see section (50.1). In the second version, the function constructs the symmetric group on the points given in the set dom which must be a set of positive integers.

 gap> SymmetricGroup(10); Sym( [ 1 .. 10 ] ) 

Note that permutation groups provide special treatment of symmetric and alternating groups, see 43.4.", "https://www.gap-system.org/Manuals/doc/ref/chap50.html#X858666F97BD85ABB"); # Demonstrate matrices # ======================== Demo_Html_Heading("Use case: display of matrices"); WcHtmlOut("

It is simple to output pretty matrices using HTML tables with a little CSS styling.

"); HTMLPrintMatrix(IdentityMat(3,Integers)); WcHtmlOut("

The demonstration has installed a function HTMLPrintMatrix, which will pretty-print an arbitrary matrix in a similar manner. For example, the following command will pretty-print a random 4x5 matrix:

HTMLPrintMatrix(RandomMat(4,5,Integers));;

");