U
    Sh                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ e
eZeeeed	d
ddZedddZeejd	dddZd	S )ab  Overrides to ``sphinx.ext.mathjax``

This fixes two issues:

1. Mathjax should not search for ``$`` delimiters, nor LaTeX amsmath environments,
   since we already achieve this with the dollarmath and amsmath mrakdown-it-py plugins
2. amsmath math blocks should be wrapped in mathjax delimiters (default ``\[...\]``),
   and assigned an equation number

    )nodes)Sphinx)mathjax)_)logging)get_node_equation_number)HTMLTranslatorN)appversioncurrentnewreturnc              	   C   sH   t dd| jjrdS |dkr"dnd}td| d| d	| d
 dS )z8Log a warning if MathJax configuration being overridden.Zmystr   N   z.mathjax3_config['options']['processHtmlClass']z)mathjax_config['tex2jax']['processClass']`z'` is being overridden by myst-parser: 'z' -> 'zz'. Set `suppress_warnings=['myst.mathjax']` to ignore this warning, or `myst_update_mathjax=False` if this is undesirable.)r   Zis_suppressed_warningconfigZsuppress_warningsloggerwarning)r	   r
   r   r   Zconfig_name r   Q/root/rtd-docs/venv/lib/python3.8/site-packages/myst_parser/sphinx_ext/mathjax.pylog_override_warning   s    r   )r	   c                 C   sP  d| j d kr*d| jjkr*tdf| jjd< d| j d kr<dS | jjjsJdS | jjj}d| j kr| j jphi | j _| j j	di  d| j jd kr| j jd d |krt
| d	| j jd d | || j jd d< n~d
| j krL| j jpi | j _| j j	di  d| j jd kr<| j jd d |kr<t
| d| j jd d | || j jd d< dS )a  Override aspects of the mathjax extension.

    MyST-Parser parses dollar and latex math, via markdown-it plugins.
    Therefore, we tell Mathjax to only render these HTML elements.
    This is accompanied by setting the `ignoreClass` on the top-level section of each MyST document.
    amsmathZmyst_enable_extensionsr   NZ
dollarmathmathjax3_configoptionsZprocessHtmlClassr   mathjax_configZtex2jaxZprocessClass   )r   registryZhtml_block_math_renderershtml_visit_displaymathenvZmyst_configZupdate_mathjaxZmathjax_classesr   
setdefaultr   r   )r	   Zmjax_classesr   r   r   override_mathjax'   sT    



r   )selfnoder   c                 C   s   d| dg kr| j| j|ddd |d rft| |}| jd|  | |td | jd	 | jjj	\}}| j| | j| 
|  | j| | jd
 tjt| |S )a`  Override for sphinx.ext.mathjax.html_visit_displaymath to handle amsmath.

    By default displaymath, are normally wrapped in a prefix/suffix,
    defined by mathjax_display, and labelled nodes are numbered.
    However, this is not the case if the math_block is set as 'nowrap', as for amsmath.
    Therefore, we need to override this behaviour.
    r   classesdivz$math notranslate nohighlight amsmath)ZCLASSnumberz<span class="eqno">(%s)zPermalink to this equationz</span>z</div>
)getbodyappendZstarttagr   Zadd_permalink_refr   Zbuilderr   Zmathjax_displayencodeZastextr   ZSkipNoder   r   )r    r!   r$   prefixsuffixr   r   r   r   _   s     
r   )__doc__Zdocutilsr   Zsphinx.applicationr   Z
sphinx.extr   Zsphinx.localer   Zsphinx.utilr   Zsphinx.util.mathr   Zsphinx.writers.htmlr   	getLogger__name__r   intstrr   r   Z
math_blockr   r   r   r   r   <module>   s   
8