Next: , Previous: , Up: Directory Index   [Contents][Index]


2.20 text-handling

Function File: tex = buildTeXTable ( spec, opt, val, … )

Build a TeX table from a cell array specification.

Arguments

tex

TeX table as a string

spec

table specification

Options

numfmt

num2TeX() format for formatting numbers [default: "g"]

tblwidth

TeX command specifying table width [optional]

fillcols

space-filling columns: "first", "all", "byrow" or "none" [default]

fillcolrow

which row to use when setting space-filling columns with "byrow"

defcolsep

default non-space-filling column separation [default: 1]

The table specification spec is a 1-D cell array of rows, the elements of which are 1-D cell arrays of columns. Further nesting of cell arrays may be used to set up elements which span multiple columns. TeX numbers containing periods are split into 2 columns to align numbers at the period.

Run demo buildTeXTable for some examples.

Examples

buildTeXTable({{1, 2, 3}, {4, 5, 6}})
buildTeXTable({"\\hline", {1, 2.2, 3}, {4, 5, 6}, "\\hline"})
buildTeXTable({"\\hline", {[], "A", "B"}, {[], {"A1", "A2"}, "B"}, "\\hline", {"x", {1, 2.2}, 3}, {"y", {4, 5}, 6}, "\\hline"})
Function File: tex = num2TeX ( num, fmt, opt, val, … )

Format a number in TeX format.

Arguments

tex

cell array of TeX strings (or string if numel(num) == 1)

num

any-dimensional array of numbers

fmt

printf()-style format string, without the leading %

Options

prefix

": string to add at start of TeX string (default: "")

suffix

": string to add at end of TeX string (default: "")

dollar

symbol to wrap TeX string with (default: "$")

times

TeX symbol to use for times (default: "{\times}")

infstr

TeX string to use for infinity (default: "\infty")

nanstr

TeX string to use for not-a-number (default: "\mathrm{NaN}")

dbslash

double backslash characters, i.e. replace "\" with "\\"

Examples

assert(num2TeX([1.234, 5.67e-8], "g"), {"$1.234$", "$5.67{\\times}10^{-8}$"})
Function File: json = object2json ( object )

This function returns a valid json string that will describe object The string will be in a compact form (i.e. no spaces or line breaks)

It will map simple octave values this way:

function handles

String with the name of the function.

double (numbers)

depends: if it’s real it will map to a string representing that number. if it’s complex it will map to an object with the next properties:

real

real part of the number

imag

imaginary part of the number

char

A string enclosed by double quotes representing that character

And will map more complex octave values this other way:

struct

an object with properties equal to the struct’s field names and value equal to the json counterpart of that field

cell

it will be mapped depending on the value of the cell (for example {i} will be mapped to an object with real=0 and imag=1)

vectors or cell arrays

it will map them to a corresponding js array (same size) with the values transformed to their json counterpart (Note: that in javascript all arrays are like octave’s cells ,i.e. they can store different type and size variables) strings or char vectors: they will be mapped to the same string enclosed by double quotes

Other octave values will be mapped to a string enclosed by double quuotes with the value that the class() function returns It can handle escape sequences and special chars automatically. If they’re valid in JSON it will keep them if not they’ll be escaped so they can become valid

Examples

assert(object2json({1.234, 2.345}), '[1.234,2.345]')
assert(object2json({1.234, 2.345, "abcd"}), '[1.234,2.345,"abcd"]')
assert(object2json(struct("abcd", 1.234)), '{"abcd":1.234}')
Function File: s = stringify ( x )

Convert an Octave value x into a string expression, which can be re-used as input, i.e. eval(stringify(x)) should re-create x.

Examples

x = [1 2 3.4; 5.67 8.9 0];
assert(isequal(x, eval(stringify(x))));
x = int32([1 2 3 7]);
assert(isequal(x, eval(stringify(x))));
x = [true; false];
assert(isequal(x, eval(stringify(x))));
x = "A string";
assert(isequal(x, eval(stringify(x))));
x = @(y) y*2;
assert(x(7) == eval(stringify(x))(7));
x = {1, 2, "three"; 4, 5, {6}};
assert(isequal(x, eval(stringify(x))));
x = {1, 2, "three", {4, 5, {6}, true}, 7, false, int16(9)};
assert(isequal(x, eval(stringify(x))));
x = struct("Hi","there","where", 2,"cell",{1,2,3,{4*5,6,{7,true}}});
assert(isequal(x, eval(stringify(x))));
Function File: s = strjoin ( cstr, sep )

Join the cell array of strings cstr using the separator sep and return the joined string.

Examples

assert(strcmp(strjoin({"a"},","), "a"))
assert(strcmp(strjoin({"a","b","c"},","), "a,b,c"))
assert(strcmp(strjoin({" a","b "," c "},","), " a,b , c "))

Next: , Previous: , Up: Directory Index   [Contents][Index]