
\c           @   s  d  Z  d d l Z d d l m Z d d l m Z d d l m Z d d l m Z m	 Z	 m
 Z
 d d l m Z d d l m Z m Z m Z m Z m Z m Z m Z m Z m Z d d	 l m Z m Z d d
 l m Z d d l m Z d d l m Z m  Z  d d l! m" Z" m# Z# d d l$ m% Z% d d l& m' Z' m( Z( m) Z) d d l* m+ Z+ m, Z, d d l- m. Z. m/ Z/ d d l0 m1 Z1 d d l2 m3 Z3 d d l4 m5 Z5 m6 Z6 d d l7 m8 Z8 m9 Z9 m: Z: e; r!d d l< m= Z= d d l> m? Z? m@ Z@ mA ZA mB ZB mC ZC mD ZD d d lE mF ZF d d l mG ZG n  i* d d 6d d 6d d 6d  d! 6d" d# 6d$ d% 6d& d' 6d( d) 6d* d+ 6d, d- 6d. d/ 6d0 d1 6d2 d3 6d4 d5 6d6 d7 6d8 d9 6d: d; 6d: d< 6d= d> 6d= d? 6d@ dA 6dB dC 6dD dE 6dF dG 6dH dI 6dJ dK 6dL dM 6dN dO 6dP dQ 6dP dR 6dS dT 6dU dV 6dW dX 6dY dZ 6d[ d\ 6d] d^ 6d_ d` 6d_ da 6d_ db 6dc dd 6de df 6dg dh 6ZH dV dX dZ d\ d^ d` db dd g ZI e( jJ eK  ZL di e f dj     YZM dk   ZN dl   ZO dm   ZP dn   ZQ do   ZR d S(p   s   
    sphinx.builders.latex
    ~~~~~~~~~~~~~~~~~~~~~

    LaTeX builder.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iN(   t   path(   t   OptionParser(   t	   text_type(   t   package_dirt   addnodest   highlighting(   t   Builder(	   t   BibliographyTransformt   CitationReferenceTransformt   MathReferenceTransformt   FootnoteDocnameUpdatert   LaTeXFootnoteTransformt   LiteralBlockTransformt   ShowUrlsTransformt   DocumentTargetTransformt   IndexInSectionTitleTransform(   t   string_classest   ENUM(   t   NoUri(   t   ImageAdapter(   t   SphinxErrort   ConfigError(   t   _t   __(   t   SphinxTransformer(   t	   texescapet   loggingt   status_iterator(   t   boldt	   darkgreen(   t   SphinxFileOutputt   new_document(   t   copy_asset_file(   t   inline_all_toctrees(   t   SEPt   make_filename(   t   DEFAULT_SETTINGSt   LaTeXWritert   LaTeXTranslator(   t   nodes(   t   Anyt   Dictt   Iterablet   Listt   Tuplet   Union(   t   Sphinx(   t   Configs   -L albanian -C utf8 t   sqs   -L croatian -C utf8 t   hrs   -L czech -C utf8 t   css   -L danish -C utf8 t   das   -L dutch -C ij-as-ij-utf8 t   nls   -L english -C utf8 t   ens   -L esperanto -C utf8 t   eos   -L estonian -C utf8 t   ets   -L finnish -C utf8 t   fis   -L french -C utf8 t   frs   -L german -C din5007-utf8 t   des   -L icelandic -C utf8 t   iss   -L italian -C utf8 t   its   -L latin -C utf8 t   las   -L latvian -C utf8 t   lvs   -L lithuanian -C utf8 t   lts   -L lower-sorbian -C utf8 t   dsbt   dss   -L norwegian -C utf8 t   nbt   nos   -L polish -C utf8 t   pls   -L portuguese -C utf8 t   pts   -L romanian -C utf8 t   ros   -L slovak -C small-utf8 t   sks   -L slovenian -C utf8 t   sls   -L spanish -C modern-utf8 t   ess   -L swedish -C utf8 t   svs   -L turkish -C utf8 t   trs   -L upper-sorbian -C utf8 t   hsbt   hss   -L vietnamese -C utf8 t   vis   -L belarusian -C utf8 t   bes   -L bulgarian -C utf8 t   bgs   -L macedonian -C utf8 t   mks   -L mongolian -C cyrillic-utf8 t   mns   -L russian -C utf8 t   rus   -L serbian -C utf8 t   srs   sh-cyrlt   shs   -L ukrainian -C utf8 t   uks   -L greek -C utf8 t   els   -L greek -C polytonic-utf8 s
   el-polytont   LaTeXBuilderc           B   s   e  Z d  Z d Z d Z e d  Z e j d k rF e e d  7Z n  d d d g Z e	 Z
 e Z d   Z d	   Z d d
  Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s,   
    Builds LaTeX output to create PDF.
    t   latexs"   The LaTeX files are in %(outdir)s.t   posixsr   
Run 'make' in that directory to run these through (pdf)latex
(use `make latexpdf' here to do that automatically).s   application/pdfs	   image/pngs
   image/jpegc         C   s2   g  |  _  g  |  _ |  j j j |  _ t j   d  S(   N(   t   docnamest   document_datat   appt   registryt   latex_packagest   usepackagesR   t   init(   t   self(    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyRa      s    		c         C   s   d S(   Ns   all documents(    (   Rb   (    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyt   get_outdated_docs   s    c         C   s$   | |  j  k r t  n d | Sd  S(   Nt   %(   R[   R   (   Rb   t   docnamet   typ(    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyt   get_target_uri   s    	c         C   s   |  j  | |  S(   N(   Rg   (   Rb   t   from_t   toRf   (    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyt   get_relative_uri   s    c         C   s   g  |  j  j D] } t |  ^ q } | sB t j t d   d  Sg  |  _ x | D] } | d } | |  j j k r t j t d  |  qR n  |  j	 j
 |  | j t d  r | d  } n  |  j j
 | | d f  qR Wd  S(   NsE   no "latex_documents" config value found; no documents will be writteni    s=   "latex_documents" config value references unknown document %st   indexii   (   t   configt   latex_documentst   listt   loggert   warningR   t   titlest   envt   all_docsR\   t   appendt   endswithR"   (   Rb   t   xt   preliminary_document_datat   entryRe   (    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyt   init_document_data   s    %	
c         C   sv   t  j d |  j j  } t j |  j d  } t | d  4 } | j d  | j d  | j | j	    Wd  QXd  S(   NRY   s   sphinxhighlight.styt   ws%   \NeedsTeXFormat{LaTeX2e}[1995/12/01]
sY   \ProvidesPackage{sphinxhighlight}[2016/05/29 stylesheet for highlighting with pygments]

(
   R   t   PygmentsBridgeRl   t   pygments_styleR    t   joint   outdirt   opent   writet   get_stylesheet(   Rb   t   highlightert
   stylesheett   f(    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyt   write_stylesheet   s    c         G   s   t  |   } t d |  j j d | f d t  j   } |  j   |  j   x|  j D]} | d  \ } } } } }	 t	 }
 t
 |  d k r | d }
 n  t d t j |  j |  d d d t  } t j t d	  | d
 d |  j j |  j t j  } | r:| d j d  d k r1| d j d  } q@d  } n d  } |  j | |
 d |	 d k rg|  j j pjg  } | | d <|  j |  |  j |  t j t d  d
 d | | _ | | j _ | | j _ |  j |  | j _  | | j _! |	 | j _" | j# | |  t j d  qT Wd  S(   Nt   defaultst
   componentst   read_config_filesi   t   destination_patht   encodings   utf-8t   overwrite_if_changeds   processing %s...t   nonli   i    t   maxdeptht
   appendicest   howtot   tocdepths   writing... t   done($   R%   R   Rr   t   settingst   Truet   get_default_valuesRy   R   R\   t   Falset   lenR   R    R}   R~   Ro   t   infoR   t   get_doctreet   traverseR   t   toctreet   gett   Nonet   assemble_doctreeRl   t   latex_appendicest   apply_transformst   post_process_imagest   authort   titlet   get_contentsnamet   contentsnameRe   t   docclassR   (   Rb   t   ignoredt	   docwritert   docsettingsRx   Re   t
   targetnameR   R   R   t   toctree_onlyt   destinationt   toctreesR   t   doctree(    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyR      sH    	

		!
	c         C   sS   |  j  j |  } d  } x4 | j t j  D]  } d | k r+ | d } Pq+ q+ W| S(   Nt   caption(   Rr   R   R   R   R   R   (   Rb   t	   indexfilet   treeR   R   (    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyR      s    
c         C   sC  d d l  m } t | g |  |  _ t j t |  d d d |  j j |  } | | d <| r t	 d  } | j
   } | | j d d  7} | | 7} x$ | j t j  D] } | | 7} q W| } n  t |  |  j | | t | g  }	 | |	 d <x7 | D]/ }
 |  j j |
  } |
 | d <|	 j |  q Wt j d	  t j t d
   |  j j |	 | |   x |	 j t j  D] } | d }
 | d } | j | |  g } x |  j D]v \ } } |
 j |  r| j | j t d  t d    | j | j | |   | j | j d d   PqqW| j |  q{W|	 S(   Ni(   R'   t    R   i   Re   s   <latex output>u   <Set title in conf.py>t    s   resolving references...t
   refdocnamet   refsectnames    (in t   )(   t   docutilsR'   t   setR[   Ro   R   R   Rr   R   R   t   sectionR   R   R   R   R!   Rt   R   t   resolve_referencest   pending_xreft   emphasisRq   t
   startswitht   TextR   t   replace_self(   Rb   R   R   R   R'   R   t   new_treet   new_sectt   nodet	   largetreeRe   t   appendixt   pendingnodet   sectnamet   newnodest   subdirR   (    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyR      sH    


	



%c         C   sI   t  |  } | j |  j  | j t t t t t t	 g  | j
   d  S(   N(   R   t   set_environmentRr   t   add_transformsR   R   R   R   R   R   R   (   Rb   R   t   transformer(    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyR     s    	
c         C   sZ  |  j    |  j j rK t j |  j j d  d  } |  j j d  t k } n d } t } i |  j j d 6|  j j d 6| d 6| d 6} t	 j
 t t d    t j t d	  } xK t j |  D]: } | j d
  s t t j | |  |  j d | q q Wt j d k rDt j t d  } t t j | d  |  j d | n  |  j j rt	 j
 t t d   d d xJ |  j j D]< } t	 j
 d | d d t t j |  j |  |  j  q|Wt	 j
 d  n  |  j j rCt j t j |  j |  j j   st t d  |  j j   qCt t j |  j |  j j  |  j  n  t	 j
 t d   d  S(   Ni   s   -L general -C utf8 s   -L english -C utf8 t   latex_enginet	   xindy_uset   xindy_lang_optiont   xindy_cyrillics   copying TeX support files...t	   texinputst   .t   contextt   ntt   texinputs_wint
   Makefile_ts   copying additional files...R   i   R   R   s   logo file %r does not existR   (   t   copy_image_filesRl   t   languaget   XINDY_LANG_OPTIONSR   t   XINDY_CYRILLIC_SCRIPTSR   R   t   latex_use_xindyRo   R   R   R   R    R}   R   t   ost   listdirR   R    R~   t   namet   latex_additional_filest   confdirt
   latex_logot   isfileR   (   Rb   R   R   R   t   staticdirnamet   filename(    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyt   finish#  sB    
	
#$(c         C   s   |  j  r t |  j j  j } x t |  j  t d  d t |  j   |  j j d | D] } |  j  | } y/ t	 t
 j |  j |  t
 j |  j |   WqU t k
 r } t j t d  t
 j |  j |  |  qU XqU Wn  d  S(   Ns   copying images... t   brownt   stringify_funcs   cannot copy image file %r: %s(   t   imagesR   R]   Rr   t   get_original_image_uriR   R   R   t	   verbosityR    R    R}   t   srcdirR~   t	   ExceptionRo   Rp   (   Rb   R   t   srct   destt   err(    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyR   V  s    	N(   t   __name__t
   __module__t   __doc__R   t   formatR   t   epilogR   t   supported_image_typesR   t   supported_remote_imagesR&   t   default_translator_classRa   Rc   R   Rg   Rj   Ry   R   R   R   R   R   R   R   (    (    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyRX   o   s*   				
	+		-		3c         C   s   x | j  D] } y t | d  Wn* t k
 rN t t d  | f   n Xy t | d  Wq
 t k
 r t t d  | f   q
 Xq
 WxV t | j  D]E } | t k r t d  } t j	 | | f  | j j
 |  q q Wd  S(   Ni   sk   Invalid latex_documents.title found (might contain non-ASCII chars. Please use u"..." notation instead): %ri   sl   Invalid latex_documents.author found (might contain non-ASCII chars. Please use u"..." notation instead): %rs3   Unknown configure key: latex_elements[%r]. ignored.(   Rm   R   t   UnicodeDecodeErrorR   R   Rn   t   latex_elementsR$   Ro   Rp   t   pop(   R]   Rl   t   documentt   keyt   msg(    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyt   validate_config_valuesf  s$    		c         C   s   |  j  d k r d Sd Sd S(   s>    Better default latex_engine settings for specific languages. t   jat   platext   pdflatexN(   R   (   Rl   (    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyt   default_latex_engine  s    c         C   s)   |  j  d k r! i d d 6d d 6Si  Sd S(   s@    Better default latex_docclass settings for specific languages. R   t   jsbookt   manualt   jreportR   N(   R   (   Rl   (    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyt   default_latex_docclass  s    
c         C   s   |  j  d d h k S(   s?    Better default latex_use_xindy settings for specific engines. t   xelatext   lualatex(   R   (   Rl   (    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyt   default_latex_use_xindy  s    c      	   C   s  |  j  t  |  j t  |  j t  |  j d t  |  j t  |  j	 d t
 d  t d d d d   |  j	 d d   d   |  j	 d	 d  d  t  |  j	 d
 g  d   |  j	 d t d   |  j	 d t d   |  j	 d d  d  t d  d d d   |  j	 d t d  t g  |  j	 d d d   |  j	 d t d   |  j	 d i  d   |  j	 d g  d   |  j	 d t d   i d d 6t d 6t d 6S(   Ns   config-initedR   R   R  R  R   Rm   c         S   s)   |  j  t |  j  d |  j d d f g S(   Ns   .texR   R  (   t
   master_docR#   t   project(   Rb   (    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyt   <lambda>  s   R   R   t   latex_use_latex_multicolumnR   t   latex_toplevel_sectioningt   partt   chapterR   t   latex_domain_indicest   latex_show_urlsRC   t   latex_show_pagerefsR   R   t   latex_docclasst   builtint   versiont   parallel_read_safet   parallel_write_safe(   t   add_builderRX   t   add_post_transformR   R	   t   connectR   t   add_transformR
   t   add_config_valueR   R   R   R   R   R  R   Rn   R  (   R]   (    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyt   setup  s4    	(S   R   R   R    t   docutils.frontendR   t   sixR   t   sphinxR   R   R   t   sphinx.buildersR   t    sphinx.builders.latex.transformsR   R   R	   R
   R   R   R   R   R   t   sphinx.configR   R   t   sphinx.environmentR   t!   sphinx.environment.adapters.assetR   t   sphinx.errorsR   R   t   sphinx.localeR   R   t   sphinx.transformsR   t   sphinx.utilR   R   R   t   sphinx.util.consoleR   R   t   sphinx.util.docutilsR   R   t   sphinx.util.fileutilR    t   sphinx.util.nodesR!   t   sphinx.util.osutilR"   R#   t   sphinx.writers.latexR$   R%   R&   R   R   R'   t   typingR(   R)   R*   R+   R,   R-   t   sphinx.applicationR.   R/   R   R   t	   getLoggerR   Ro   RX   R   R   R  R  R  (    (    (    s=   lib/python2.7/site-packages/sphinx/builders/latex/__init__.pyt   <module>
   s   @.
				
	