104 CHEVIE String and Formatting functions

CHEVIE enhances the facilities of GAP33 for formatting and displaying objects.

First, it provides some useful string functions, such as Replace, and IntListToString.

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 GAP3. 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.

Subsections

  1. Replace
  2. IntListToString
  3. FormatTable
  4. Format

104.1 Replace

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"

104.2 IntListToString

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}" 

104.3 FormatTable

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).

The option is a record whose fields can be:

rowLabels:
at least this field must be present. It will contain labels for the rows of the table.

columnLabels:
labels for the columns of the table.

rowsLabel:
label for the first column (containing the rowLabels).

separators:
by default, a separating line is put after the line of column labels. This option contains the indices of lines after which to put separating lines, so the default is equivalent to .separators:=[0].

rows:
a list of indices. If given, only the rows specified by these indices are formatted.

columns:
a list of indices. If given, only the columns specified by these indices are formatted.

TeX:
if set to 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:
This is used to specify how to split the table in several parts typeset one after the other. The variable 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:
As explained above, is used to split the table when doing plain text output. A good value to set it is 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

104.4 Format

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 calls 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"

Previous Up Next
Index

gap3-jm
23 Nov 2017