
    ^h                        S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
JrJrJrJrJr  SSKJr  SSKJr   " S	 S
\5      rS r " S S\5      rg)zExport to PDF via latex    )annotationsN)TemporaryDirectory)BoolInstanceIntegerListUnicodedefault)_contextlib_chdir   )LatexExporterc                  *    \ rS rSrSrS rS rS rSrg)LatexFailed   zJException for failed latex run

Captured latex output is in error.output.
c                    Xl         g)zInitialize the error.Noutput)selfr   s     Q/home/james-whalen/.local/lib/python3.13/site-packages/nbconvert/exporters/pdf.py__init__LatexFailed.__init__   s        c                     SU R                   -  $ )zUnicode representation.z.PDF creating failed, captured latex output:
%sr   r   s    r   __unicode__LatexFailed.__unicode__   s    @4;;NNr   c                "    U R                  5       $ )zString representation.)r   r   s    r   __str__LatexFailed.__str__"   s    !!r   r   N)	__name__
__module____qualname____firstlineno____doc__r   r   r   __static_attributes__ r   r   r   r      s    
O"r   r   c                d    U(       d  gU[         R                  -   UR                  U S5      -   X '   g)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+    
 rzz)GKK,DDGr   c                  r  ^  \ rS rSrSrSr\" SSS9R                  SS9r\	" / S	QS
S9R                  SS9r
\	" SS/SS9R                  SS9r\" SSS9R                  SS9r\" SS9r\" SSSS0S9rSr\	" \" 5       5      r\" S5      S 5       r\" S5      S 5       rS S jr\4S jrS!S jrS U 4S jjrSrU =r$ )"PDFExporter2   zWriter 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.bibtexr7   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                    g)N.pdfr&   r   s    r   _file_extension_default#PDFExporter._file_extension_defaultO   s    r   template_extensionc                    g)Nz.tex.j2r&   r   s    r   _template_extension_default'PDFExporter._template_extension_defaultS   s    r   c                x   U Vs/ s H  ofR                  US9PM     nn[        R                  " US   5      nUc  Sn	US    SUS    SU	 S3n
[        U
5      eUS:X  a  S	OS
nU R                  R                  SUS   X;U5        [        R                  S:H  nU(       a  [        R                  " U5      n[        R                  R                  5       n[        SU R                  U5        [        SU R                  U5        [        SU R                  U5        [        [        R                   S5       nU R"                  (       d  [        R$                  OSn['        U5       H  n[        R(                  " UU[        R*                  UUUS9nUR-                  5       u  nnUR.                  (       d  MP  U R"                  (       a  SnOUR1                  SS5      nU" UU5        U R2                  R5                  U5        U(       a  SU SU 3n
U" U
5      e  SSS5        g   SSS5        gs  snf ! , (       d  f       g= f)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).
)filenamer   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 r:   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)format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_listrG   countlog_functionraise_on_failureccommandcmdlinkmsgrI   rR   rS   nullrO   _poutout_strs                       r   run_commandPDFExporter.run_commandW   s   , 9EE188X8.E ll<?+;[D?##Q?# $V1 
 #,1*',l1ouWU' --g6Gjjoo";D";D";D"**d#t,0LLZ__dF5\$$!%,, Q<<<|| #%"%**Wi"@ #.))009' /yWIN.s33 1 $#! $2 c F0 $#2 s   H&1A;H+0A"H+H++
H9c                `   ^  U 4S jnT R                  T R                  UT R                  X25      $ )z#Run xelatex self.latex_count times.c                F   > TR                   R                  SU S   X5        g )Nz%s failed: %s
%sr   )rY   criticalrs   rz   r   s     r   	log_error(PDFExporter.run_latex.<locals>.log_error   s    HH171:wLr   )r|   latex_commandlatex_countr   rG   rq   r   s   `   r   	run_latexPDFExporter.run_latex   s3    	M $*:*:I
 	
r   c                   ^  [         R                  R                  U5      S   nU 4S jnT R                  T R                  USX25      $ )zRun bibtex one time.r   c                   > TR                   R                  SU S   5        TR                   R                  SU S   X5        g )Nz<%s had problems, most likely because there were no citationsr   z%s output: %s
%s)rY   warningdebugr   s     r   r   &PDFExporter.run_bib.<locals>.log_error   s<    HHNPWXYPZ HHNN.
GIr   r   )r)   pathsplitextr|   bib_commandr   s   `   r   run_bibPDFExporter.run_bib   sA    77##H-a0	J  0 0(Ay[[r   c                F  > [         TU ]  " U4SU0UD6u  pBU(       aQ  UR                  S0 5      R                  S5      (       a+  [        R                  R                  US   S   5      U l        O[        R                  " 5       U l        / U l        [        5        n[        R                  " U5         SnSUS'   U R                  R                  XBUS9nU R                  R                  S5        U R!                  U5        U R#                  U5      (       a  U R!                  U5        US	-   n[        R                  R%                  U5      (       d$  ['        S
R)                  U R*                  5      5      eU R                  R                  S5        [-        US5       n	U	R/                  5       n
SSS5        SSS5        SSS5        S	US'   UR1                  SS5        UR1                  SS5        W
U4$ ! , (       d  f       NK= f! , (       d  f       NT= f! , (       d  f       N]= f)zConvert from notebook node.	resourcesmetadatar   notebookz.texoutput_extension)notebook_namezBuilding PDFr?   
zPDF successfully createdrN   Noutputsattachments)superfrom_notebook_noder+   r)   r   abspathra   getcwd_captured_outputsr   r   chdirwriterwriterY   rZ   r   r   isfiler   joinrl   rb   readpop)r   nbr   r<   latextdr   tex_filepdf_filefpdf_data	__class__s              r   r   PDFExporter.from_notebook_node   s    75bTITQSTz26::6BBWW__Yz-B6-JKDNYY[DN!#!R):)@)@)D&M,2I(){{(((WHHHMM.)NN8$||H%%x($v-H77>>(++!$))D,A,A"BCCHHMM45h%668 & *E!$ )/	$% 	i&mT*"" &% *E)D!!s=   H1C)HG0+H3H0
G>:H
H	H
H )r   ra   )N)F)r    r!   r"   r#   r$   export_from_notebookr   tagr   r   r   r   r   rd   r	   ra   r   r   output_mimetyperl   r
   r@   rD   r|   r   r   r   r   r%   __classcell__)r   s   @r   r1   r1   2   s    +!"HIMMUYMZK+2X	cc  ,/6YZ^^ _ K 5QRVV^bVcGMNI5BDUWZC[\F'OGI  !" #GR 4? 

\"# "#r   r1   )r$   
__future__r   r)   rV   r]   r[   tempfiler   	traitletsr   r   r   r   r	   r
   nbconvert.utilsr   r   r   IOErrorr   r/   r1   r&   r   r   <module>r      sH     # 	   
 ' E E -  "' "&Ef#- f#r   