
%Jenik Hollan's attempt to aproximate emlines by standard LaTeX lines
%  -- what is inconvenient, the resulting integer length of lines
%  as I don't know how to make a real number in TeX.

\newcount\xlen
\newcount\ylen
\newcount\xo
\newcount\yo
\newcount\xm
\newcount\ym

%\newcommand{\emline}[6]{\relax}

\newcommand{\emline}[6]
{
\begingroup

\dimen0 = #4pt
\advance \dimen0 by -#1pt

\dimen1 = #5pt
\advance \dimen1 by -#2pt

\dimen2 = 1pt

\xlen = \dimen0
\divide \xlen by \dimen2

\ylen = \dimen1
\divide \ylen by \dimen2

\ifnum \xlen > 0
 \xo=1
\else
 \xo=-1
 \xlen =-\xlen
\fi

\ifnum \ylen > 0
 \yo=1
\else
 \yo=-1
 \ylen =-\ylen
\fi

\ifnum \ylen = 0    %horizontal
 \yo=0
\else
 \ifnum \xlen = 0  %vertical
  \xo=0
  \xlen=\ylen
 \else          %45degrees
  \ifnum \xlen = \ylen
   \relax
  \else
   \ifnum \ylen > \xlen  %reversing y and x lengths 
    \dimen2 = \dimen0
    \dimen0 = \dimen1
    \dimen1 = \dimen2
    \ylen = 0            %used just like a boolean, no true length here
   \fi    

   \dimen2 = \dimen0
   \dimen3 = 6pt
   \divide \dimen2 by \dimen3 %becomes xlen div 6
   \xm = \dimen2
   \advance \xm by 1
   \dimen2 = 32768 \xm
   \dimen3 = \dimen1
   \advance \dimen3 by \dimen2    
   \dimen2 = 6 \dimen3   %the above 7 lines are an attempt to round off
   \divide \dimen2 by \dimen0

   \ifcase \dimen2   %uses just multiples of 1/6
    \ym=0 \xm=1  % almost horizontal
                \or 
    \ym=1 \xm=6          % 5,1 and 4,1 slopes are tested as well: 
     \dimen3 = 6 \dimen1 
     \advance \dimen3 by -\dimen0
     \ifnum \dimen3 < 0 \dimen3 = -\dimen3 \fi
     \dimen4 = 5 \dimen1 
     \advance \dimen4 by -\dimen0
     \ifnum \dimen4 < 0 \dimen4 = -\dimen4 \fi
     \ifnum \dimen4 < \dimen3 
      \xm=5 
      \dimen3 = 4 \dimen1 
      \advance \dimen3 by -\dimen0
      \ifnum \dimen3 < 0 \dimen3 = -\dimen3 \fi
      \ifnum \dimen3 < \dimen4 
       \xm=4
      \fi
     \fi  
                \or
    \ym=1 \xm=3 
     \dimen3 = 6 \dimen1 
     \dimen5 = 2 \dimen0
     \advance \dimen3 by -\dimen5
     \ifnum \dimen3 < 0 \dimen3 = -\dimen3 \fi
     \dimen4 = 5 \dimen1 
     \advance \dimen4 by -\dimen5
     \ifnum \dimen4 < 0 \dimen4 = -\dimen4 \fi
     \ifnum \dimen4 < \dimen3 
      \xm=5 \ym=2
     \else 
      \dimen4 = 8 \dimen1 
      \advance \dimen4 by -\dimen5
      \ifnum \dimen4 < 0 \dimen4 = -\dimen3 \fi
      \ifnum \dimen4 < \dimen3 
       \xm=4 \ym=1
      \fi
     \fi  
                \or
    \ym=1 \xm=2 
     \dimen3 = 4 \dimen1 
     \dimen5 = 2 \dimen0
     \advance \dimen3 by -\dimen5
     \ifnum \dimen3 < 0 \dimen3 = -\dimen3 \fi
     \dimen4 = 5 \dimen1 
     \advance \dimen4 by -\dimen5
     \ifnum \dimen4 < 0 \dimen4 = -\dimen4 \fi
     \ifnum \dimen4 < \dimen3 
      \xm=5 \ym=2
     \fi  
                \or
    \ym=2 \xm=3 
                \or
    \ym=5 \xm=6 
     \dimen3 = 72 \dimen1 
     \dimen5 = 60 \dimen0
     \advance \dimen3 by -\dimen5
     \ifnum \dimen3 < 0 \dimen3 = -\dimen3 \fi
     \dimen4 = 75 \dimen1 
     \advance \dimen4 by -\dimen5
     \ifnum \dimen4 < 0 \dimen4 = -\dimen4 \fi
     \ifnum \dimen4 < \dimen3 
      \xm=5 \ym=4
      \dimen3 = 80 \dimen1 
      \advance \dimen3 by -\dimen5
      \ifnum \dimen3 < 0 \dimen3 = -\dimen3 \fi
      \ifnum \dimen3 < \dimen4 
       \xm=4 \ym=3
      \fi
     \fi  
                \or
    \ym=1 \xm=1 \else 
    \ym=1 \xm=1 
   \fi     
   \ifnum \ylen = 0 \ylen=\xm \xm=\ym \ym=\ylen \fi
   \multiply \xo by \xm \multiply \yo by \ym      
  \fi 
 \fi
\fi

\put(#1,#2){\line(\xo,\yo){\xlen}}

\endgroup
}      
