B
    Åû_Á(  ã               @   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ej	Z	ej
Z
ejZejZ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û(?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 k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< d|j| dd¡f |d< d}tjdkr®d}t ¡ }tj	 |d¡}|d| 7 }tj d¡}|d tjd< t |¡}|rj|tjd< ntjd= t|dd ¡ }|dkr˜ttdƒƒ t |¡ t |¡ nBtj |||dtj!tj!d}| "¡ \}}|j#dkrðttdƒ| ƒ t $|¡ tj	 %|	¡rt $|	¡ tj	 %|
¡r:t|
dd ¡ }t $|
¡ d}t  d|¡}|r^t&| 'd¡ƒ}d}t  d|¡}|r‚t(| 'd¡ƒ}t  d|¡}|r¤t(| '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   Úpreamblez.texé   z.auxz.logÚwz;Running `%s' on file `%s' to detect default page settings.
z%s %szExecuting: %s
ÚCÚLC_ALLz%s:%sZ	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ÚwarningÚ_ÚstartÚLATEX_INSPECTION_DOCUMENTÚtempfileZmkstempÚosÚpathÚsplitextÚsplitÚfdopenÚwriteÚcloseÚprogressZlatex_programÚdebugÚenvironÚcopyZ	input_dirÚgetÚsysÚplatformZmkdtempÚjoinÚ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;   úl/home/gub/NewGub/gub/target/mingw/src/lilypond-git.sv.gnu.org--lilypond.git-stable-2.22/python/book_latex.pyÚget_latex_textwidthº   sš    







r=   c             C   s8   |   ¡ }t d|¡r4t d|¡s4t dd|¡}|| _d S )Nz\\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    rB   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| _dddg| _	d| _
d| _d S )NZlatexz.texz.latexz.lytexZ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<   rF   ,  s    zBookLatexOutputFormat.__init__c             C   s   |   |¡ d S )N)Zprocess_options_pdfnotdefault)rK   r5   r;   r;   r<   Úprocess_options6  s    z%BookLatexOutputFormat.process_optionsc             C   s   t || jƒ}d| S )Nz%.0f\pt)r=   r5   )rK   r4   r6   r;   r;   r<   Úget_line_width9  s    z$BookLatexOutputFormat.get_line_widthc             C   sJ   y$t jd|gdt jdj}|r"|S W n t jk
r:   Y nX tj | |¡S )NZ	kpsewhichT)Zcheckr   )r+   Úrunr-   r   ZCalledProcessErrorrD   rE   Úinput_fullname)rK   Zinput_filenameZtrialr;   r;   r<   rO   =  s    
z$BookLatexOutputFormat.input_fullnamec             C   s4   x.|D ]&}|  ¡ rt d| ¡ ¡rt|ƒ P qW |S )Nz\\begin *{document})Zis_plainr   r   r>   rB   )rK   ZchunksÚcr;   r;   r<   Úprocess_chunksI  s    
z$BookLatexOutputFormat.process_chunksc             C   sÄ   d}|  ¡ }| dd¡|d< tj |j¡ dd¡|d< |j|d< tj|j	kr`|| j
tj | 7 }tj|j	krŒ| ¡ |d< || j
tj | 7 }|| j
tj | 7 }tj|j	krÀ| j
tj d|i }|S )	Nr   ú\ú/ÚbaseÚfilenameÚextr   Ústr)Zget_replacementsÚreplacer   r   ÚbasenamerU   rV   Úbook_snippetsÚPRINTFILENAMEZoption_dictrJ   ÚVERBATIMZverb_lyÚOUTPUTÚQUOTE)rK   rY   ZsnippetrA   Zrepr;   r;   r<   Úsnippet_outputQ  s    
z$BookLatexOutputFormat.snippet_outputN)	Ú__name__Ú
__module__Ú__qualname__rF   rL   rM   rO   rQ   r_   r;   r;   r;   r<   rC   +  s   
rC   )r   r   r+   r#   r   rD   rZ   ZlilylibZlyr   r   ÚerrorZdebug_outputr   rH   ZFILTERr]   r[   r^   r\   ZVERSIONrI   r   r=   rB   rE   rC   Zregister_formatr;   r;   r;   r<   Ú<module>   sH   		
f?