### 12.6 The tegcode environment and the directTeg macro

If the package texgraph.sty is called with the server option, it provides the environment:

\begin{tegcode}
<TeXgraph file>
\end{tegcode}

The syntax is the same as a source file without its first line: TeXgraph#, that will be automatically added. The file may contain TEX macros if the backslash $\$ is replaced by # before the commands names, eg: #command{...}. Once declared, the file is read by Texgraph and will remain in memory until the end of the document. The variables and macros defined in that file will then be available for other calls to TeXgraph. Those macros can use the instruction Return(string), only if it is then used by the macro \directTeg.

The macro \directTeg{command} launches the <command> via TeXgraph, that <command> may use the macro Return(string), this one is writing the string in an output file, and that file will be automatically included by the macro \directTeg. Here is an example:

\begin{tegcode}
Mac Gcd = [//Gcd(integers list)
$L:=%1,$N:=Nops(L),
if N<2 then "error !"
else
\$r:=pgcd(L[1],L[2]),
if r=1 then 1
elif N=2 then r
else Gcd( [r,L[3,0]] )
fi
fi
];
\end{tegcode}
\newcommand*{\Gcd}[1]{\directTeg{Return(Gcd([#1]))}}%

Execution of \Gcd{12,68,36} gives 4. Execution of \Gcd{12} gives error !.