
    Mh                        d 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mZ ddl	m
Z
mZmZmZmZmZ ddlmZ ddlmZ  G d	 d
e          Zd Z G d de          ZdS )zExport to PDF via latex    )annotationsN)TemporaryDirectory)BoolInstanceIntegerListUnicodedefault)_contextlib_chdir   )LatexExporterc                  $    e Zd ZdZd Zd Zd ZdS )LatexFailedzRException for failed latex run

    Captured latex output is in error.output.
    c                    || _         dS )zInitialize the error.Noutput)selfr   s     W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbconvert/exporters/pdf.py__init__zLatexFailed.__init__   s        c                    d| j         z  S )zUnicode representation.z.PDF creating failed, captured latex output:
%sr   r   s    r   __unicode__zLatexFailed.__unicode__   s    @4;NNr   c                *    |                                  S )zString representation.)r   r   s    r   __str__zLatexFailed.__str__"   s    !!!r   N)__name__
__module____qualname____doc__r   r   r    r   r   r   r      sN         
  O O O" " " " "r   r   c                `    |sdS |t           j        z   |                    | d          z   || <   dS )zAdd value to the environment variable varname in envdict

    e.g. prepend_to_env_search_path('BIBINPUTS', '/home/sally/foo', os.environ)
    N )ospathsepget)varnamevalueenvdicts      r   prepend_to_env_search_pathr)   '   s;    
  rz)GKK,D,DDGGr   c                      e Zd ZdZdZ edd                              d          Z eg dd	                              d          Z	 ed
dgd                              d          Z
 edd                              d          Z ed          Z eddddi          ZdZ e e                      Z ed          d             Z ed          d             ZddZefdZd dZd fd	Z xZS )!PDFExporterzWriter designed to write to PDF files.

    This inherits from `LatexExporter`. It creates a LaTeX file in
    a temporary directory using the template machinery, and then runs LaTeX
    to create a pdf.
    zPDF via LaTeX   z$How many times latex will be called.)helpT)config)xelatex
{filename}z-quietz$Shell command used to compile latex.bibtexr0   z!Shell command used to run bibtex.Fz0Whether to display the output of latex commands.z.texinputs dir. A notebook's directory is addedznbconvert.writers.FilesWriterr    build_directory.)argskwzapplication/pdffile_extensionc                    dS )N.pdfr    r   s    r   _file_extension_defaultz#PDFExporter._file_extension_defaultO   s    vr   template_extensionc                    dS )Nz.tex.j2r    r   s    r   _template_extension_defaultz'PDFExporter._template_extension_defaultS   s    yr   Nc           
        fd|D             }t          j        |d                   }|(d}|d          d|d          d| d}	t          |	          |dk    rd	nd
}
| j                            d|d         ||
|           t
          j        dk    }|rt          j        |          }t          j
                                        }t          d| j        |           t          d| j        |           t          d| j        |           t          t          j        d          5 }| j        st          j        nd}t%          |          D ]}t          j        ||t          j        |||          }|                                \  }}|j        ri| j        rd}n|                    dd          } |||           | j                            |           |rd| d| }	 ||	           ddd           dS 	 ddd           n# 1 swxY w Y   dS )a  Run command_list count times.

        Parameters
        ----------
        command_list : list
            A list of args to provide to Popen. Each element of this
            list will be interpolated with the filename to convert.
        filename : unicode
            The name of the file to convert.
        count : int
            How many times to run the command.
        raise_on_failure: Exception class (default None)
            If provided, will raise the given exception for if an instead of
            returning False on command failure.

        Returns
        -------
        success : bool
            A boolean indicating if the command was successful (True)
            or failed (False).
        c                <    g | ]}|                                S ))filename)format).0cr?   s     r   
<listcomp>z+PDFExporter.run_command.<locals>.<listcomp>m   s'    EEE1188X8..EEEr   r   NzFhttps://nbconvert.readthedocs.io/en/latest/install.html#installing-texz. not found on PATH, if you have not installed z5 you may need to do so. Find further instructions at r3   r   timetimeszRunning %s %i %s: %swin32	TEXINPUTS	BIBINPUTS	BSTINPUTSrb)stdoutstderrstdinshellenvr"   zutf-8replacezFailed to run "z" command:
FT)shutilwhichOSErrorloginfosysplatform
subprocesslist2cmdliner#   environcopyr)   	texinputsopendevnullverbosePIPErangePopenSTDOUTcommunicate
returncodedecode_captured_outputappend)r   command_listr?   countlog_functionraise_on_failurecommandcmdlinkmsgrE   rN   rO   nullrK   _poutout_strs     `                r   run_commandzPDFExporter.run_commandW   s   , FEEEEEE l<?++;[D?  ?    
 #,,1**',l1oueWUUU' 	7 -g66Gjoo";DDD";DDD";DDD"*d## 	!t,0LBZ__dF5\\ ! !$!%,   Q< !| A #%"%**Wi"@"@ L#...)00999' 4NNNWNN..s333 1	! 	! 	! 	! 	! 	! 	! 	!!!	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!2 ts   "CH4HH	Hc                T      fd}                       j        | j        ||          S )z#Run xelatex self.latex_count times.c                N    j                             d| d         | |           d S )Nz%s failed: %s
%sr   )rT   criticalrm   rt   r   s     r   	log_errorz(PDFExporter.run_latex.<locals>.log_error   s*    H171:wLLLLLr   )rv   latex_commandlatex_countr   r?   rl   r{   s   `   r   	run_latexzPDFExporter.run_latex   sM    	M 	M 	M 	M 	M $*:IGW
 
 	
r   c                     t           j                            |          d         } fd}                      j        |d||          S )zRun bibtex one time.r   c                    j                             d| d                    j                             d| d         | |           d S )Nz<%s had problems, most likely because there were no citationsr   z%s output: %s
%s)rT   warningdebugrz   s     r   r{   z&PDFExporter.run_bib.<locals>.log_error   sP    HNPWXYPZ   HNN.
GSIIIIIr   r   )r#   pathsplitextrv   bib_commandr~   s   `   r   run_bibzPDFExporter.run_bib   s]    7##H--a0	J 	J 	J 	J 	J  0(AyJZ[[[r   c                    t                      j        |fd|i|\  }}|rZ|                    di                               d          r1t          j                            |d         d                   | _        nt          j                    | _        g | _        t                      5 }t          j        |          5  d}d|d<   | j                            |||          }| j                            d           |                     |           |                     |          r|                     |           |d	z   }t          j                            |          s't'          d
                    | j                            | j                            d           t-          |d          5 }	|	                                }
ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   d	|d<   |                    dd           |                    dd           |
|fS )zConvert from notebook node.	resourcesmetadatar   notebookz.texoutput_extension)notebook_namezBuilding PDFr8   
zPDF successfully createdrJ   Noutputsattachments)superfrom_notebook_noder%   r#   r   abspathr\   getcwd_captured_outputsr   r   chdirwriterwriterT   rU   r   r   isfiler   joinrg   r]   readpop)r   nbr   r5   latextdr   tex_filepdf_filefpdf_data	__class__s              r   r   zPDFExporter.from_notebook_node   s   55775bTTITQSTTy 	)z266::6BB 	)W__Yz-B6-JKKDNNY[[DN!#!! 	$R):)@)D)D 	$ 	$&M,2I(){((	(WWHHMM.)))NN8$$$||H%% )x((($v-H7>>(++ D!$))D,A"B"BCCCHMM4555h%% $6688$ $ $ $ $ $ $ $ $ $ $ $ $ $ $	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$$ )/	$% 	i&&&mT***""s[   *H?C3G*2GG*GG*GG*H*G.	.H1G.	2HHH)N)F)r   r   r   r   export_from_notebookr   tagr}   r   r|   r   r   r_   r	   r\   r   r   output_mimetyperg   r
   r9   r<   rv   r   r   r   r   __classcell__)r   s   @r   r+   r+   2   s         +'!"HIIIMMUYMZZKD+++2X  	cc  $,/6YZZZ^^ _  K d5QRRRVV^bVccGMNNNIX5BDUWZC[\\\F'OtGGIIW   W!""  #"G G G GR 4? 
 
 
 

\ 
\ 
\ 
\"# "# "# "# "# "# "# "# "# "#r   r+   )r   
__future__r   r#   rQ   rX   rV   tempfiler   	traitletsr   r   r   r   r	   r
   nbconvert.utilsr   r   r   IOErrorr   r)   r+   r    r   r   <module>r      s&     # " " " " " 				      



 ' ' ' ' ' ' E E E E E E E E E E E E E E E E - - - - - -            " " " " "' " " "&E E Ef# f# f# f# f#- f# f# f# f# f#r   