Skip to main content

Overview

Giac provides functions to export mathematical expressions and plots to various formats including LaTeX, MathML, SVG, Maple, and TI-89 formats.

LaTeX Export

gen2tex

std::string gen2tex(const gen & e, GIAC_CONTEXT);
Converts a Giac expression to LaTeX format.
e
gen
The expression to convert
return
std::string
LaTeX representation of the expression
Example:
gen expr = symbolic(at_plus, makesequence(x, 2));
std::string latex = gen2tex(expr, context0);
// Returns: "x+2"

graph2tex

int graph2tex(const std::string & s, const vecteur & v,
              double X1, double X2, double Y1, double Y2,
              double xunit, double yunit, bool logo,
              GIAC_CONTEXT);
Exports a 2D graphic object to LaTeX (TikZ/PSTricks).
s
std::string
Output filename
v
vecteur
Vector of graphic objects to export
X1
double
Minimum x coordinate
X2
double
Maximum x coordinate
Y1
double
Minimum y coordinate
Y2
double
Maximum y coordinate
xunit
double
Horizontal scaling unit
yunit
double
Vertical scaling unit
Whether to include Giac logo

spread2tex

std::string spread2tex(const matrice & m, int formule, GIAC_CONTEXT);
Converts a spreadsheet matrix to LaTeX table format.
m
matrice
The matrix/spreadsheet data
formule
int
Formula display mode
return
std::string
LaTeX table representation

LaTeX Global Variables

extern double horiz_latex;  // Horizontal dimension (default 12 cm)
extern double vert_latex;   // Vertical dimension (default 12 cm)
extern const char tex_preamble[];
extern const char tex_end[];
Control the dimensions of LaTeX output figures.

MathML Export

gen2mathml

std::string gen2mathml(const gen & e, GIAC_CONTEXT);
std::string gen2mathml(const gen & e, std::string & svg, GIAC_CONTEXT);
Converts a Giac expression to MathML format.
e
gen
The expression to convert
svg
std::string &
Optional SVG output for graphics
return
std::string
MathML representation of the expression

spread2mathml

std::string spread2mathml(const matrice & m, int formule, GIAC_CONTEXT);
Converts a spreadsheet matrix to MathML table format.
m
matrice
The matrix/spreadsheet data
formule
int
Formula display mode
return
std::string
MathML table representation

matrix2mathml

std::string matrix2mathml(const matrice & m, GIAC_CONTEXT);
Converts a matrix to MathML format.
m
matrice
The matrix to convert
return
std::string
MathML matrix representation

SVG Export

gen2svg

std::string gen2svg(const gen & e, GIAC_CONTEXT, bool withpreamble = false);

std::string gen2svg(const gen & e,
                    double xmin, double xmax,
                    double ymin, double ymax,
                    double ysurx, GIAC_CONTEXT,
                    bool withpreamble = false);
Converts a graphic object to SVG format.
e
gen
The graphic object to export
xmin
double
Minimum x coordinate
xmax
double
Maximum x coordinate
ymin
double
Minimum y coordinate
ymax
double
Maximum y coordinate
ysurx
double
Aspect ratio (y/x)
withpreamble
bool
Whether to include SVG XML preamble
return
std::string
SVG representation

svg_preamble

std::string svg_preamble(double width_cm, double height_cm,
                         bool xml, int color);

std::string svg_preamble(double svg_width_cm, double svg_height_cm,
                         double xmin, double xmax,
                         double ymin, double ymax,
                         bool ortho, bool xml, int color);
Generates SVG preamble with specified dimensions.
width_cm
double
Width in centimeters
height_cm
double
Height in centimeters
xml
bool
Whether to include XML declaration
color
int
Background color
ortho
bool
Whether to use orthonormal axes

svg_grid

std::string svg_grid(double xmin, double xmax,
                     double ymin, double ymax, int color);
Generates SVG grid lines.
xmin
double
Minimum x coordinate
xmax
double
Maximum x coordinate
ymin
double
Minimum y coordinate
ymax
double
Maximum y coordinate
color
int
Grid color
return
std::string
SVG grid markup

Maple Format

The maple.h header provides compatibility functions for Maple-style operations.

Time Measurement

struct cpureal_t {
  double cpu;   // CPU time
  double real;  // Real (wall-clock) time
};

cpureal_t clock_realtime();
double realtime();
Functions for measuring execution time.
cpu
double
CPU time in seconds
real
double
Wall-clock time in seconds

TI-89 Format

The ti89.h header provides TI-89 calculator compatibility functions for importing and exporting expressions.

ti2gen

gen ti2gen(octet * ptr, GIAC_CONTEXT);
Converts TI-89 binary format to Giac expression.
ptr
octet *
Pointer to TI-89 binary data
return
gen
Giac expression

exact

gen exact(const gen & g, GIAC_CONTEXT);
Converts floating-point values to exact representations.
g
gen
Expression with floating-point values
return
gen
Expression with exact values (fractions, radicals, etc.)

Utility Functions

translate_underscore

std::string translate_underscore(const std::string & s);
Escapes special LaTeX characters (underscore, ampersand, braces).
s
std::string
Input string
return
std::string
String with escaped characters

greek2tex

int greek2tex(const std::string & s, std::string & texs, bool mathmode);
Converts Greek letter names to LaTeX commands.
s
std::string
Greek letter name (e.g., “alpha”)
texs
std::string &
Output LaTeX command (e.g., “\alpha”)
mathmode
bool
Whether output is for math mode
return
int
Status code

arc_en_ciel

void arc_en_ciel(int k, int & r, int & g, int & b);
Generates rainbow colors for visualization.
k
int
Color index (reduced modulo 126)
r
int &
Red component (0-255)
g
int &
Green component (0-255)
b
int &
Blue component (0-255)

See Also

Build docs developers (and LLMs) love