### 3.13 User-defined export

Via the MyExport command (or draw, an alias) it is possible to create new graphical elements with a personalized export, different from default’s TeXgraph export.

• MyExport( <"name">, <parameter 1>, ..., <parameter n> )
• Description: The command is used like a graphical command. The user choose a <"name"> and must create two macros:
• The first whose name must concatenate the word Draw and the <"name">. That macro is creating the drawing.
• The second one whose name must concatenate the word Export and <"nom">. That macro is creating the export writing in the export file using the command:WriteFile.

When the graphic is evaluated, the command MyExport calls the drawing macro "Draw"+"name" giving to it the parameters: <parameter 1>, …, <parameter n>.

When exporting, the command MyExport calls the export macro "Export"+"name" giving to it the parameters:<parameter 1>, …, <parameter n>. If the macros returns $0$, then TeXgraph is using the “ classical” export.

• Exemple(s): exporting cartesian curves as pstricks format using the macro \psplot. Let us choose the name pstcartesian, we write then the drawing macro Drawpstcartesian( f(x), [options] ) with options:
• clip := < 0/1 >: to clip or not with the window defined with the option : clipwin (0 by default),
• clipwin := < [xmin+i*ymin, xmax+i*ymax] >: defining the default clipping window, that is the default graphical window,
• x := < [xmin, xmax] >: drawing interval for the function, [tMin, tMax] by default.

Those options must be global variables.

{Drawpstcartesian(f(x),[options])}
[SaveAttr(), clip:=0, clipwin:=[Xmin+i*Ymin, Xmax+i*Ymax], x:=[tMin,tMax],
$aux:=%2, {options evaluation} tMin:=x[1], tMax:=x[2], if clip then SaveWin(),$a:=clipwin[1], $b:=clipwin[2], Fenetre( Re(a)+i*Im(b), Re(b)+i*Im(a)) fi, Cartesienne(%1,0), if clip then RestoreWin() fi, RestoreAttr() ] Then we write the exporting macro:Exportpstcartesian( f(x), [options] ) {Exportpstcartesian(expression,[options])} if ExportMode=pst then {We test the exporting mode} SaveAttr(), clip:=0, clipwin:=[Xmin+i*Ymin, Xmax+i*Ymax], x:=[tMin,tMax],$aux:=%2, {Evaluation des options}
tMin:=x[1], tMax:=x[2],
WriteFile([if clip then
$a:=clipwin[1],$b:=clipwin[2],
"\psclip{",
"\psframe[linestyle=none,fillstyle=none]",
@coord(a),@coord(b),"}%",LF
fi,
"\psplot[algebraic",
if NbPoints<>50 then ",plotpoints=",NbPoints fi,
"]",
"{",Round(tMin,6),"}{",Round(tMax,6),"}{", @cvfunction(String(%1)),"}",
if clip then LF,"\endpsclip" fi
]),
RestoreAttr()
else 0 { <- 0 means normal export}
fi

The macro cvfunction returns the function using pstricks format as a string:

{cvfunction( string ): converting to pstricks’s syntax}
[\$aux:=StrReplace(%1,"cos","COS"),
aux:=StrReplace(aux,"sin","SIN"),
aux:=StrReplace(aux,"tan","TAN"),
aux:=StrReplace(aux,"arccos","ACOS"),
aux:=StrReplace(aux,"arcsin","ASIN"),
aux:=StrReplace(aux,"arctan","ATAN"),
aux:=StrReplace(aux,"ch","COSH"),
aux:=StrReplace(aux,"sh","SINH"),
aux:=StrReplace(aux,"th","TANH"),
aux:=StrReplace(aux,"argch","ACOSH"),
aux:=StrReplace(aux,"argsh","ASINH"),
aux:=StrReplace(aux,"argth","ATANH"),
aux:=StrReplace(aux,"exp","EXP"),
aux]

If we then create a graphical element with the command: MyExport("pstcartesian", x^2, [x:=[-2,2], clip=1] ), then the pstricks export will give the file:

\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(-5.5,-5.5)(5.5,5.5)%
%objet1  (Utilisateur)
\psclip{\psframe[linestyle=none,fillstyle=none](-5,-5)(5,5)}%
\psplot[algebraic]{-4}{4}{x^2*SIN(x)}
\endpsclip
\end{pspicture}%

NB: this example is not complete. Exporting the attributes is not handled: color, thickness, line style,...