CHEVIE enhances the facilities of GAP3 for formatting and displaying objects.
First, it provides some useful string-manipulating functions, such as
Join, Split, Replace, which mimic similar facilities in Perl, Python
or Ruby.
Second, it enforces a general policy on how to format and print objects.
The most basic method which should be provided for an object is the
Format method. This is a method whose second argument is a record of
options to control printing/formatting the object. When the second
argument is absent, or equivalently the empty record, one has the most
basic formatting, which is used to make the Display method of the object.
When the option GAP is set (that is the record second argument has a
field GAP), the output should be a form which can, as far as possible,
read back in GAP. This output is what is used by default in the methods
String and Print.
In addition to the above options, most CHEVIE objects also provide the
formatting options TeX (resp. LaTeX), to output strings suitable for
TeX or LaTeX typesetting. The objects for which this makes sense (like
polynomials) provide a Maple option for formatting to create output
readable by Maple.
Join( list [, delimiter] )
SPrint(s1,...,sn)
PrintToString(s,s1,...,sn)
The function Join is similar to the Perl function of the same name. It
first applies the function String to all elements of the list, then
joins the resulting strings, separated by the given delimiter (if
omitted, "," is used as a delimiter)
gap> Join([1..4]); "1,2,3,4" gap> Join([1..4],"foo"); "1foo2foo3foo4"
SPrint(s1,...,sn) is a synonym for Join([s1,...,sn],""), and
PrintToString(s,s1,...,sn) appends to string s the string
SPrint(s1,...,sn).
These functions require the package "chevie" (see RequirePackage).
Split( s [, delimiter] )
This function is similar to the Perl function of the same name. It splits
the string s at each occurrence of the delimiter (a character).
If delimiter is omitted, ',' is used as a delimiter.
gap> Split("14,2,2,1,");
[ "14", "2", "2", "1", "" ]
This function requires the package "chevie" (see RequirePackage).
Replace( s [, s1, r1 [, s2, r2 [...]]])
Replaces in list s all (non-overlapping) occurrences of sublist s1 by list r1, then all occurrences of s2 by r2, etc...
gap> Replace("aabaabaabbb","aabaa","c","cba","def","bbb","ult");
"default"
This function requires the package "chevie" (see RequirePackage).
IntListToString( part [, brackets] )
part must be a list of positive integers. If all of them are smaller
than 10 then a string of digits corresponding to the entries of part is
returned. If an entry is ≥ 10 then the elements of part are
converted to strings, concatenated with separating commas and the result
surrounded by brackets. By default () brackets are used. This may be
changed by giving as second argument a length two string specifying
another kind of brackets.
gap> IntListToString( [ 4, 2, 2, 1, 1 ] );
"42211"
gap> IntListToString( [ 14, 2, 2, 1, 1 ] );
"(14,2,2,1,1)"
gap> IntListToString( [ 14, 2, 2, 1, 1 ], "{}" );
"{14,2,2,1,1}"
This function requires the package "chevie" (see RequirePackage).
FormatTable( table, options )
This is a general routine to format a table (a rectangular array, that is a list of lists of the same length).
rowLabels:
columnLabels:
rowsLabel:rowLabels).
separators:.separators:=[0].
rows:
columns:
TeX:true, TeX output is generated to format the table.
LaTeX:TeX also should be set if this is used. LaTeX output is
generated using the package longtable, so the output can be split across
several pages.
columnRepartition:columnRepartition
should be a list of integers to specify how many columns to print in each
part. When using plain text output, this is unnecessary as FormatTable
can automatically split the table into parts not exceeding screenColumns
columns, if this option is specified.
screenColumns:SizeScreen()[1], so each
part of the table does not exceed the screen width.
gap> t:=IdentityMat(3);;o:=rec(rowLabels:=[1..3]);;
gap> Print(FormatTable(t,o));
1 |1 0 0
2 |0 1 0
3 |0 0 1
gap> o.columnLabels:=[6..8];;Print(FormatTable(t,o));
|6 7 8
_________
1 |1 0 0
2 |0 1 0
3 |0 0 1
gap> o.rowsLabel:="N";;Print(FormatTable(t,o));
N |6 7 8
_________
1 |1 0 0
2 |0 1 0
3 |0 0 1
gap> o.separators:=[0,2];;Print(FormatTable(t,o));
N |6 7 8
_________
1 |1 0 0
2 |0 1 0
_________
3 |0 0 1
This function requires the package "chevie" (see RequirePackage).
Format( object[, options] )
FormatGAP( object[, options] )
FormatMaple( object[, options] )
FormatTeX( object[, options] )
FormatLaTeX( object[, options] )
Format is a general routine for formatting an object. options is a
record of options; if not given, it is equivalent to options:=rec().
The routines FormatGAP, FormatMaple, FormatTeX and FormatLaTeX add
some options (or setup a record with some options if no second argument is
given); respectively they set up GAP:=true, Maple:=true,
TeX:=true, and for FormatLaTeX both TeX:=true and LaTeX:=true.
If object is a record, Format looks if it has a .operations.Format
method and then calss it. Otherwise, Format knows how to format in
various ways: polynomials, cyclotomics, lists, matrices, booleans.
Here are some examples.
gap> q:=X(Rationals);;q.name:="q";;
gap> Format(q^-3-13*q);
"-13q+q^-3"
gap> FormatGAP(q^-3-13*q);
"-13*q+q^-3"
gap> FormatMaple(q^-3-13*q);
"-13*q+q^(-3)"
gap> FormatTeX(q^-3-13*q);
"-13q+q^{-3}"
By default, Format tries to recognize cyclotomics which are in quadratic
number fields. If the option noQuadrat:=true is given it does not.
gap> Format(E(3)-E(3)^2);
"ER(-3)"
gap> Format(E(3)-E(3)^2,rec(noQuadrat:=true));
"-E3^2+E3"
gap> FormatTeX(E(3)-E(3)^2,rec(noQuadrat:=true));
"-\\zeta_3^2+\\zeta_3"
gap> FormatTeX(E(3)-E(3)^2);
"\\sqrt {-3}"
gap> FormatMaple(E(3)-E(3)^2);
"sqrt(-3)"
Formatting of arrays gives output usable for typesetting if the TeX or
LaTeX options are given.
gap> m:=IdentityMat(3);; gap> Print(Format(m),"\n"); 1 0 0 0 1 0 0 0 1 gap> FormatTeX(m); "1#0#0\\cr\n0#1#0\\cr\n0#0#1\\cr\n" gap> FormatGAP(m); "[[1,0,0],[0,1,0],[0,0,1]]" gap> FormatLaTeX(m); "1#0#0\\\\\n0#1#0\\\\\n0#0#1\\\\\n"
This function requires the package "chevie" (see RequirePackage).
Previous Up Next
Index
GAP 3.4.4