ó
7ÊƒRc           @À  sñ   d  d l  m Z d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d d l	 m
 Z
 m Z d  d l m Z m Z m Z d  d l m Z d e f d	 „  ƒ  YZ d Z d Z d Z e j d ƒ Z d d „ Z d S(   i    (   t   absolute_import(   t   with_statementNi   (   t   utilt   custom(   t   translatorst
   conversiont	   structure(   t   url_to_patht   TeXFailedErrorc           BÀ  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sB   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/bazki/latex.pyR      s   t   xelatexs   -interactiont   nonstopmodet   latext   dvipss   -ot    s3   ^Missing character: There is no (.) in font (.+)\n$s   .pdfc   "   
   À  s  |  j  ƒ  } | j d ƒ s! t ‚ t j d ƒ } t j j | t j j | ƒ d  ƒ } d |  j	 ƒ  k rF|  j	 ƒ  d } xÌ| D]Á} | d k rŸ d' } d( } n d) } d* } | j
 d
 d ƒ \ }	 }
 d d l m } i  } t j |
 | ƒ } d | k rt | ƒ } | d =n  y t j |	 | | | ƒ } WnD t j k
 rot | ƒ d k rit j |	 | | | ƒ } qp‚  n X|  j | j ƒ  ƒ | j  ƒ  } | j ƒ  } | d d
 k s±t ‚ t j |	 ƒ } | j | |
 ƒ } t j j | t | ƒ | ƒ } t j j | ƒ } t j j | ƒ s%t j | ƒ n  t j | | ƒ | j ƒ  q~ Wn  | d k r[t  } n% | d k rpt! } n t" d | ƒ ‚ i d j t# j$ ƒ d 6t j% d ƒ d 6t j% d ƒ d 6} t& j' | | f d | d | d t& j( d t& j( ƒ} | j) ƒ  \ } } | j* d k r1t+ | j* | d t, | ƒ ƒ ‚ n  i  ‰  t- | d ƒ } d" } xý | D]õ } | r«| j d ƒ sxt ‚ | | d  7} ˆ  j/ | t0 ƒ  ƒ j1 | ƒ d" } qW| j2 d ƒ rWt3 j4 t5 | d ƒ ƒ } | d" k	 sðt t6 | ƒ ƒ ‚ | j7 d ƒ } | j d  ƒ r:ˆ  j/ | d!  t0 ƒ  ƒ j1 | j7 d ƒ ƒ qL| j7 d ƒ } qWqWWWd" QXˆ  rd# } | d$ j ‡  f d% †  ˆ  Dƒ ƒ 7} t8 | j9 d ƒ ƒ ‚ n  | d k rÆt& j: t; | f d | ƒn  t j< d& | ƒ \ }  }! t j= |  ƒ t j> | | |! ƒ |  j? |! ƒ d" S(+   si   Latex the latex code referred to by im, then return an im for the resulting file in the specified format.s   .texs   .bazkilatexiüÿÿÿt   imagess   .pdfs   .epdfs   .jpgs   .pngs   .epst   .i   (   t   gettingt   di    s   .pss   Unknown typeset format '%s'!t   :t	   TEXINPUTSt   HOMEt   PATHt   cwdt   envt   stdoutt   stderrs   

Environment: s   .logs   !
iþÿÿÿs   Missing characters   utf-8i   t   !iÿÿÿÿNs   Missing characters: s   ; c         3À  s6   |  ], } d  | d j  d „  ˆ  | Dƒ ƒ f Vq d S(   s   font '%s' doesn't contain %ss   , c         sÀ  s%   |  ] } d  | t  | ƒ f Vq d S(   s   %s (%s)N(   t   repr(   t   .0t   c(    (    sB   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/bazki/latex.pys	   <genexpr>t   s   N(   t   join(   R   t   fontname(   t   missing(    sB   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/bazki/latex.pys	   <genexpr>r   s   t   suffix(   s   .epdf(   s   .jpgs   .png(   s   .eps(    (@   t   asPatht   endswitht   AssertionErrort   tempfilet   mkdtempt   ost   pathR    t   basenamet   metadatat   splitR   R   R   t   extract_filterst   dictt   convert_anyt   ConversionFailedExceptiont   lent   addDepst   getDepst   getExtensionR   t   get_elementt   attachment_url_forR   t   dirnamet   existst   makedirst   shutilt   copyt   nixt   PDFLATEX_COMMAND_LINEt   DVILATEX_COMMAND_LINEt	   TypeErrorR   t   LATEX_SEARCH_PATHSt   getenvt
   subprocesst   Popent   PIPEt   communicatet
   returncodeR   t   strt   opent   Nonet
   setdefaultt   sett   addt
   startswitht   MISSING_CHARACTER_PATt   matcht   unicodeR   t   groupt   UnicodeErrort   encodet
   check_callt   DVIPS_COMMAND_LINEt   mkstempt   closet   renamet   setPath("   t   imt   formatt   texfpatht   temp_dirt   baseoutpathR   t   it   formatst   backup_formatst   enamet   pname_w_filtersR   t   filterst   pnamet   imgimt   imgpatht   extt   elmt   urlt   imgloct   imgdirt   clineR   t   text   texoutt   texerrt   logt   contt   lR!   t   mt   messaget   fdesct   retpath(    (   R"   sB   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/bazki/latex.pyt   typeset   s¨    %	
					,
(   R   s   -interactionR   (   s   latexs   -interactionR   (   R   s   -oR   (   t
   __future__R    R   t   sysR)   RC   R;   t   reR'   R   R   R   t   bazbaseR   R   R   t   redbeans.latexR   t   IOErrorR   R>   R?   RV   t   compileRO   Ry   (    (    (    sB   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/bazki/latex.pyt   <module>   s   <	