function [] =latexdraw(x,y,opt,aks)
%Tekee vektorikuvasta latex-koodin
%
%latexdraw(x,y,opt,aks)
%
%Example of use:
%x=linspace(-2,2,30);
%y=sin(x);
%z=cos(x);
%figure, hold on
%plot(x,y)
%plot(x,z)
%g=ginput(2);
%latexdraw(x,y,2,1)
%latexdraw(x,z,1,0)
%latexdraw(x,g,3,0)
%

x=round(10000*x)/10000;
y=round(10000*y)/10000;

if aks==1,
xmin=min(x);xmax=max(x);
ymin=min(y);ymax=max(y);

lev=xmax-xmin;
kork=ymax-ymin;
lev=round(100*lev)/100;
kork=round(100*kork)/100;

disp('\vspace{1cm}')
disp('\begin{center}')
disp('\setlength{\unitlength}{1cm}')
%eval(['disp(''\begin{picture}(' num2str(lev) ',' num2str(kork) ')'')'])
disp('\begin{picture}(0,0)')
end

l=length(x);
if opt==1,
    prompt='anna symboli:';
    str=inputdlg(prompt,'s');
    str=str{1};
    %str=input(prompt,'s');
for k=1:l
    eval(['disp(''\put(' num2str(x(k)) ',' num2str(y(k)) '){$' str '$}'')'])
end
elseif opt==2,
for k=1:l-1
    eval(['disp(''\qbezier(' num2str(x(k)) ',' num2str(y(k)) ')(' num2str(x(k)) ',' num2str(y(k)) ')(' num2str(x(k+1)) ',' num2str(y(k+1)) ')'')'])
end
elseif opt==3,
    pit=length(y);
    for k=1:pit
    prompt='kerro ilmaus:';
    str=inputdlg(prompt,'s');
    str=str{1};
    eval(['disp(''\put(' num2str(y(1,k)) ',' num2str(y(2,k)) ') {' str '}'')'])
    end
end



if aks==1,
eval(['disp(''\put(' num2str(xmin) ',0){\vector(1,0){' num2str(xmax-xmin) '}}'')'])
eval(['disp(''\put(0,' num2str(ymin) '){\vector(0,1){' num2str(ymax-ymin) '}}'')'])

eval(['disp(''\put(' num2str(xmax-0.2) ',-0.3) {$x$}'')'])
eval(['disp(''\put(-0.3,' num2str(ymax-0.2) ') {$y$}'')'])

disp('\end{picture}')
disp('\end{center}')
eval(['disp(''\label{apukuva2' num2str(now) '}'')'])
disp('\vspace{1cm}')
end

end

