}BFjdZddlmZddlZddlZddlZddlZddlmZddl Z ddl m Z ddl m Z mZddlmZddlmZdd lmZmZmZGd d eZ ddefdZddZddZdZdZdZddZdS)zTools for handling LaTeX.)BytesION) encodebytes)Path)find_cmd FindCmdError get_config)SingletonConfigurable)ListBoolUnicodec8eZdZdZdZeeddgddZe dd dZ egd d dZ ed dZ d S) LaTeXToolz3An object to store configuration of the LaTeX tool.ctS)Nr)selfs DC:\PYTHON\_runtimes\venv\Lib\site-packages\IPython/lib/latextools.py_config_defaultzLaTeXTool._config_defaults || matplotlibdvipngaPreferred backend to draw LaTeX math equations. Backends in the list are checked one by one and the first usable one is used. Note that `matplotlib` backend is usable only for inline style equations. To draw display style equations, `dvipng` backend must be specified. )helpT)configzmUse breqn.sty to automatically break long equations. This configuration takes effect only for dvipng backend.)amsmathamsthmamssymbbmziA list of packages to use for dvipng backend. 'breqn' will be automatically appended when use_breqn=True.zKAdditional preamble to use when generating LaTeX source for dvipng backend.N) __name__ __module__ __qualname____doc__rr r tagbackendsr use_breqnpackagespreamblerrrrs==t L(+H     #T#    C    #T#    t...F    #T#    w    #T#   HHrrFBlack?sc t|tsJtj}||d}||vrdS|dkrt }n|dkrt }|drt|dkr d d d tj |d dd D}nz#t$r(}td ||d}~wwxYwtd |n"td ||||||} |r| rt| } | S)alRender a LaTeX string to PNG. Parameters ---------- s : str The raw string containing valid inline LaTeX. encode : bool, optional Should the PNG data base64 encoded to make it JSON'able. backend : {matplotlib, dvipng} Backend for producing PNG data. wrap : bool If true, Automatically wrap `s` as a LaTeX equation. color : string Foreground color name among dvipsnames, e.g. 'Maroon' or on hex RGB format, e.g. '#AA20FA'. scale : float Scale factor for the resulting PNG. None is returned when the backend cannot be used. Nrrr#zRGB {} cHg|]}tt|d S))strint).0xs r z latex_to_png..as86S6S6S!c#a**oo6S6S6SrzInvalid color specification {}.zNo such backend {0}) isinstancer0rinstancer"latex_to_png_mpllatex_to_png_dvipng startswithlenformatjointextwrapwrap ValueErrorr) r)encodebackendr@colorscaleallowed_backendsfebin_datas r latex_to_pngrJ<s. a    ))++4"1%&&&t,  H      C R5zzQ]$OOCHH6S6S6>mE!""Iq6Q6Q6S6S6S-T-TUUEE!]]]$%F%M%Me%T%TUU[\\]!!B!I!I%!P!PQQQ R.55g>>???qD%''H )()x(( Os A C D "#DD c ddlm}m}m}ddlm}ddlm}n#t$rYdSwxYw| dd}|rd |} | d } d |z} t} | d } | |d | \} }}}}|| d z |d z f}|d||z || ||||| | dd| S#t(t*|f$rYdSwxYw)Nr)figure font_managermathtext) backend_agg)ParseFatalExceptionz$$$z${0}$ )sizexpathH)dpiprop)figsize)fontpropertiesrDpngT)rWr= transparent)rrLrMrNmatplotlib.backendsrO pyparsingrP ImportErrorreplacer=FontPropertiesrMathTextParserparseFiguretextFigureCanvasAggsavefiggetvaluerA RuntimeError)r)r@rDrErLrMrNrOrPrXrWbufferparserwidthheightdepth_figs rr9r9os==========3333331111111 tt $A  OOA  ***33Ek((00%+\\!$\%G%G"vuammURZ"$=m>> EFNAd%HHH##C((( FEt DDD    &9 :tts ''CD11EEc tdtdn#t$rYdSwxYwd}tjdkr-t j}|xjtjzc_ ttj }d}d}d}| | dd 5} | t||dddn #1swxYwYt jdd d d |g|tjtj| t#d|z} t jddddt%| ddddd||d|g|tjtj| | | d5} | cdddt)j|S#1swxYwYn*#tj$rYt)j|dSwxYw t)j|dS#t)j|wxYw)Nlatexrntztmp.texztmp.dviztmp.pngwutf8)encodingz-halt-on-errorz -interaction batchmode)cwdstdoutstderr startupinfoz-Ttightz-Dz-z9z-bg Transparentz-oz-fgrb)rrosname subprocess STARTUPINFOdwFlagsSTARTF_USESHOWWINDOWrtempfilemkdtempjoinpathopen writelines genelatex check_callDEVNULLroundr0readshutilrmtreeCalledProcessError) r)r@rDrEr{workdirtmpfiledvifileoutfilerG resolutions rr:r:s ttK w$ ,.. z>>.x'))**   g & & + +C& + A A -Q LL1d++ , , , - - - - - - - - - - - - - - -  & W M%%#     3;'' J  %%#)    .  g & & + +D 1 1 Q6688         g            ( g   g gs! //2AG2$C2& G22C66G29C6:B7G21G& G2&G**G2-G*.G21H32HH3HH33I c tdtjd|gtjtj}|\}}|ddS#t$rYdSwxYw)z5Invoke kpsewhich command with an argument `filename`. kpsewhich)ryrzrur`N)rrPopenPIPE communicatestripdecoder)filenameprocryrzs rrrs  ( #?:?<<< ++--||~~$$VY777      sA:A== B  B c#\Kt}|o|jotd}dV|j}|r|dgz}|D]}d|VdV|jr |jVdV|r dV|VdVn|rd |Vn|Vd Vd S) z+Generate LaTeX document for dvipng backend.z breqn.styz\documentclass{article}breqnz\usepackage{{{0}}}z\pagestyle{empty}z\begin{document}z\begin{dmath*}z \end{dmath*}z$${0}$$z\end{document}N)rr8r#rr$r=r%)bodyr@ltrr$packs rrrs     B  imagecjt|dd}|r t||fzSdS)zRender LaTeX to HTML with embedded PNG data using data URIs. Parameters ---------- s : str The raw string containing valid inline LateX. alt : str The alt text to use for the HTML. T)rBasciiN)rJr_data_uri_template_png)r)alt base64_datas r latex_to_htmlrsFq...55g>>K<%+s);;;<rs   88888888''''''??????))))))))))"""""%"""LJM00 0000f<;;;;|    2N < < < < <