B
    öÀ„\j  ã               @   sh   d Z ddlZddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 dd„ Zd	d
„ Zdd„ Zdd„ ZdS )aT  
    sphinx.ext.mathjax
    ~~~~~~~~~~~~~~~~~~

    Allow `MathJax <https://www.mathjax.org/>`_ to be used to display math in
    Sphinx's HTML writer -- requires the MathJax JavaScript library on your
    webserver/computer.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
é    N)Únodes)ÚExtensionError)Ú_)Úget_node_equation_numberc             C   sZ   | j  | j|dddd¡ | j  | jjjd |  | ¡ ¡ | jjjd  d ¡ tj	‚d S )NÚspanÚ zmath notranslate nohighlight)ÚCLASSr   é   z</span>)
ÚbodyÚappendÚstarttagÚbuilderÚconfigÚmathjax_inlineÚencodeÚastextr   ÚSkipNode)ÚselfÚnode© r   ú1lib/python3.7/site-packages/sphinx/ext/mathjax.pyÚhtml_visit_math   s    0r   c             C   sz  | j  | j|ddd¡ |d rH| j  |  | ¡ ¡¡ | j  d¡ tj‚|d r†t| |ƒ}| j  d| ¡ |  |t	dƒ¡ | j  d	¡ | j  | j
jjd
 ¡ dd„ | ¡  d¡D ƒ}t|ƒdkrÌ| j  d¡ xft|ƒD ]Z\}}|  |¡}d|kr| j  d| d ¡ n| j  |¡ |t|ƒd k rÖ| j  d¡ qÖW t|ƒdkrN| j  d¡ | j  | j
jjd ¡ | j  d¡ tj‚d S )NZdivzmath notranslate nohighlight)r   Znowrapz</div>Únumberz<span class="eqno">(%s)zPermalink to this equationz</span>r   c             S   s   g | ]}|  ¡ r|‘qS r   )Ústrip)Ú.0Zprtr   r   r   ú
<listcomp>6   s    z*html_visit_displaymath.<locals>.<listcomp>z

r	   z \begin{align}\begin{aligned}z\\z\begin{split}z\end{split}z\end{aligned}\end{align} z</div>
)r
   r   r   r   r   r   r   r   Zadd_permalink_refr   r   r   Úmathjax_displayÚsplitÚlenÚ	enumerate)r   r   r   ÚpartsÚiÚpartr   r   r   Úhtml_visit_displaymath'   s4    


r#   c             C   sœ   | j jdks| j jdkrd S | jjs,tdƒ‚| d¡ ¡ r˜ddi}| jjrX| 	| jj¡ | j j
| jjf|Ž | jjr˜dt | jj¡ }| j j
d d|d d S )	NÚhtmlÚmathjaxzGmathjax_path config value must be set for the mathjax extension to workZmathÚasynczMathJax.Hub.Config(%s)ztext/x-mathjax-config)Útyper
   )r   ÚformatZmath_renderer_namer   Úmathjax_pathr   Z
get_domainZhas_equationsÚmathjax_optionsÚupdateZadd_js_fileÚmathjax_configÚjsonÚdumps)ÚappÚenvZoptionsr
   r   r   r   Úinstall_mathjaxH   s    r1   c             C   s|   |   dtd ftd f¡ |  ddd¡ |  di d¡ |  dddgd¡ |  d	d
dgd¡ |  dd d¡ |  dt¡ tjddœS )Nr%   r)   z[https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMMLr$   r*   r   z\(z\)r   z\[z\]r,   zenv-check-consistencyT)ÚversionZparallel_read_safe)Zadd_html_math_rendererr   r#   Zadd_config_valueZconnectr1   ÚsphinxZ__display_version__)r/   r   r   r   Úsetup\   s    
r4   )Ú__doc__r-   Zdocutilsr   r3   Zsphinx.errorsr   Zsphinx.localer   Zsphinx.util.mathr   r   r#   r1   r4   r   r   r   r   Ú<module>   s   		!