o
    f+                     @   s   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Zd dlZdde	d d dddd	d
ddd	Z
ejdejdejdejdejdejdiZdZdd Zdd ZG dd dejZee  dS )    Nzp(?smx)
          ^[^%\n]*?
          (?P<match>
          \\input\s*{
           (?P<filename>\S+?)
          })z(?smx)
          ^ [^%\n]*?
          (?P<match>
            \\lilypond
            \s*
            ( \[ \s* (?P<options> [^\[\]]*? ) \s* \] )?
            \s*
            { (?P<code>
   z) }
          )a:  (?smx)
          ^ [^%\n]*?
          (?P<match>
            \\begin
            \s*
            (?P<env> {lilypond} \s* )?
            ( \[ \s* (?P<options> [^\[\]]*? ) \s* \] )?
            (?(env) | \s* {lilypond} )
            (?P<code> .*? )
            ^ [^%\n]*?
            \\end \s* {lilypond}
          )z(?smx)
          ^ [^%\n]*?
          (?P<match>
            \\lilypondfile
            \s*
            ( \[ \s* (?P<options> [^\[\]]*? ) \s* \] )?
            \s*
            { (?P<filename> \S+? ) }
          )z(?smx)
          ^ [^%\n]*?
          (?P<match>
            \\musicxmlfile
            \s*
            ( \[ \s* (?P<options> [^\[\]]*? ) \s* \] )?
            \s*
            { (?P<filename> \S+? ) }
          )zS(?mx)
          ^.*?
          (?P<match>
           (?P<code>
           %.*$\n+))z(?mx)
          ^[^%\n]*?
          (?P<match>
           (?P<code>
           \\verb(?P<del>.)
            .*?
           (?P=del)))z(?msx)
          ^[^%\n]*?
          (?P<match>
           (?P<code>
           \\begin\s*{verbatim}
            .*?
           \\end\s*{verbatim}))zA(?smx)
          (?P<match>
          \\lilypondversion)[^a-zA-Z])	ZincludeZlilypondZlilypond_blockZlilypond_fileZmusicxml_fileZsingleline_commentverbZverbatimZlilypondversionz5\begin{lilypond}[%(options)s]
%(code)s
\end{lilypond}z{%%
\parindent 0pt
\noindent
\ifx\preLilyPondExample \undefined
\else
  \expandafter\preLilyPondExample
\fi
\def\lilypondbook{}%%
\input{%(base)s-systems.tex}%%
\ifx\postLilyPondExample \undefined
\else
  \expandafter\postLilyPondExample
\fi
}z!\texttt{%(filename)s}
\linebreak
z!\begin{quote}
%(str)s
\end{quote}z1\noindent
\begin{verbatim}%(verb)s\end{verbatim}
z%(program_version)sz
\nonstopmode
%(preamble)s
\begin{document}
\typeout{textwidth=\the\textwidth}
\typeout{columnsep=\the\columnsep}
\makeatletter\if@twocolumn\typeout{columns=2}\fi\makeatother
\end{document}
c                 C   s&  d}t d| }|d u rttd |S | d |d }td|i }td\}}t	j
|d }t	j
|d }|d }	|d	 }
t	|d
}|| |  ttd|j|f  d|j|f }td|  t	j }d|d< t	j
j|j|ddf|d< d}tjdkrd}t }t	j
|d}|d| 7 }t	jd}|d t	jd< t	|}|r|t	jd< nt	jd= t|dd }|dkrttd t	| t	 | n!t!j"|||dt!j#t!j#d}|$ \}}|j%dkrttd|  t	&| t	j
'|	rt	&|	 t	j
'|
r!t|
dd }t	&|
 d}t d|}|r3t(|)d}d}t d|}|rEt*|)d}t d|}|rVt*|)d}n	ttd |S td  td!|  td"|  td#|  |r|r|| | }td$ td#|  |S )%Ng     0@z"(?P<preamble>\\begin\s*{document})z.cannot find \begin{document} in LaTeX documentr   preamble.tex   z.auxz.logwz;Running `%s' on file `%s' to detect default page settings.
z%s %szExecuting: %s
CLC_ALLZ	TEXINPUTS TZmingw32Fz
output.txtz > %sutf8)encodingz(Unable to auto-detect default settings:
)envuniversal_newlinesshellstdoutstderrz*Unable to auto-detect default settings:
%szcolumns=([0-9.]+)zcolumnsep=([0-9.]+)ptztextwidth=([0-9.]+)ptz"cannot detect textwidth from LaTeXzDetected values:z  columns = %sz  columnsep = %sz  textwidth = %szAdjusted value:)+researchlyZwarning_startLATEX_INSPECTION_DOCUMENTtempfileZmkstempospathsplitextsplitfdopenwritecloseZprogressZlatex_programZdebug_outputenvironcopypathsepjoinZ	input_dirgetsysplatformZmkdtempsystemopenreadremovermdir
subprocessPopenPIPEZcommunicate
returncodeunlinkexistsintgroupfloat)sourceglobal_options	textwidthmr   Zlatex_documentZhandleZtmpfileZtmpfilerootZauxfileZlogfileZ
tmp_handlecmdZrun_envr   Z
output_dirZoutput_filenameZoldtexinputsr/   Zparameter_stringprocZerror_stringcolumnsZ	columnsep r<   _/home/lily/lilypond-2.24.4/release/binaries/mingw/lilypond/lilypond-2.24.4/python/book_latex.pyget_latex_textwidth   s   













r>   c                 C   s@   |   }td|rtd|stdd|}|| _d S d S d S )N\\begin *{document}z{graphic[sx]z\\begin{document}z(\\usepackage{graphics}
\\begin{document})replacement_textr   r   subZoverride_text)chunksr<   r<   r=   modify_preamble%  s   

rD   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )BookLatexOutputFormatc                 C   s>   t j|  d| _d| _t| _t| _g d| _	d| _
d| _d S )NZlatexr   )z.latexz.lytexr   Zpsz\s*,\s*)	book_baseBookOutputFormat__init__formatZdefault_extensionLatex_snippet_resZsnippet_resLatex_outputoutputZhandled_extensionsZimage_formatsZsnippet_option_separator)selfr<   r<   r=   rH   1  s   

zBookLatexOutputFormat.__init__c                 C   s   |  | d S )N)Zprocess_options_pdfnotdefault)rM   r6   r<   r<   r=   process_options;  s   z%BookLatexOutputFormat.process_optionsc                 C   s   t || j}d| S )Nz%.0f\pt)r>   r6   )rM   r5   r7   r<   r<   r=   get_line_width>  s   z$BookLatexOutputFormat.get_line_widthc              	   C   sV   zt jd|gddt jddj}|d}W |S  t jtfy*   tj	| |}Y |S w )NZ	kpsewhichTzutf-8)Zcheckr   r   r   
)
r,   runr.   r   stripZCalledProcessErrorFileNotFoundErrorrF   rG   input_fullname)rM   Zinput_filenamerT   r<   r<   r=   rT   B  s$   
z$BookLatexOutputFormat.input_fullnamec                 C   s4   |D ]}|  rtd| rt|  |S q|S )Nr?   )Zis_plainr   r   r@   rD   )rM   Zchunkscr<   r<   r=   process_chunksT  s    z$BookLatexOutputFormat.process_chunksc                 C   s   d}|  }|dd|d< tj|jdd|d< |j|d< tj|j	v r0|| j
tj | 7 }tj|j	v rF| |d< || j
tj | 7 }|| j
tj | 7 }	 tj|j	v ra| j
tj d|i }|S )Nr
   \/basefilenameextr   r   rP   z%
str)Zget_replacementsreplacer   r   basenamerZ   r[   book_snippetsPRINTFILENAMEZoption_dictrL   VERBATIMZverb_lyOUTPUTr   countljustQUOTE)rM   r^   ZsnippetrC   ZrepZbreaksr<   r<   r=   snippet_output\  s   
z$BookLatexOutputFormat.snippet_outputN)	__name__
__module____qualname__rH   rN   rO   rT   rV   rf   r<   r<   r<   r=   rE   0  s    
rE   )r   r   r,   r%   r   rF   r_   Zlilylibr   Zbrace_matcherrJ   ZFILTERrb   r`   re   ra   ZVERSIONrK   r   r>   rD   rG   rE   Zregister_formatr<   r<   r<   r=   <module>   sD   		\&gE