
    \h	7                         S SK r S SKJr  S SKrS SKrS SKJr   S SKJrJ	r	J
r
  S SKJr  S SKJr  SSKJr  S	S
/0rS rS rS rSSSSSS.S jr\" SSSS9   SS j5       rg! \ a     NGf = f)    N)join)Path)STDOUTCalledProcessErrorcheck_output)doctest_depends_on)debug   )latex)previewpygletc                  N    [         R                  S:X  a  SnOSn[        U SU0UD6$ )Nnti   r   creationflags)osnamer   )argskwargscreation_flags      N/var/www/auris/envauris/lib/python3.13/site-packages/sympy/printing/preview.py_check_output_no_windowr      s.     
ww$"E]EfEE    c                 <   [         R                  " S[        R                  R	                  U 5      S   SS9 n[        U S5       n[        R                  " X25        SSS5        SSS5        SSKnUR                  5       S:X  a"  SSK
nUR                  S	WR                  45        gUR                  5       S
:X  a!  [        R                  " WR                  5        gSSK
nUR                  SWR                  45        g! , (       d  f       N= f! , (       d  f       N= f)zOpen fname with the default system viewer.

In practice, it is impossible for python to know when the system viewer is
done. For this reason, we ensure the passed file will not be deleted under
it, and this function does not attempt to block.
zsympy-preview-r
   F)prefixsuffixdeleterbNr   DarwinopenWindowszxdg-open)tempfileNamedTemporaryFiler   pathsplitextr   shutilcopyfileobjplatformsystem
subprocesscallr   	startfile)fnamefmttemp_ffr'   r)   s         r   system_default_viewerr0      s     
	$	$,<,.GG,<,<U,CA,F,1
36<%!q) 
3 H$-.		i	'
V[[!V[[12 
3 
3s#   DC<D<
D
	D
Dc                   ^	^
^^^  SSK JnJnJm	  SSKJm  SSKJn   UR                  U 5      m
SnT	R                  SS	9nUR                  T
R                  S
U-  -   T
R                  S
U-  -   SSUS9mTR!                  S5         U4S jmTTl        UU4S jnUTl        U	U
U4S jnUTl        TR(                  (       d3  TR+                  5         TR-                  5         TR(                  (       d  M3  TR1                  5         g ! [         a    [        S5      ef = f! U a    [        SR                  U5      5      ef = f! [.         a     NZf = f)Nr   )windowimagegl)key)ImageDecodeExceptionz:pyglet is required for preview.
 visit https://pyglet.org/z,pyglet preview does not work for '{}' files.   F)double_buffer   SymPy)widthheightcaption	resizableconfigc                     > ST l         g )NT)has_exit)wins   r   on_closepyglet_viewer.<locals>.on_closeQ   s
    CLr   c                 N   > U TR                   TR                  4;   a  T" 5         g g )N)QESCAPE)symbol	modifiersr5   rC   s     r   on_key_press#pyglet_viewer.<locals>.on_key_pressV   s"    #%%,,
 -r   c                     > T R                  SSSS5        T R                  T R                  5        TR                  TR                  TR                  -
  S-  TR
                  TR
                  -
  S-  5        g )Ng      ?r9   )glClearColorglClearGL_COLOR_BUFFER_BITblitr;   r<   )r4   imgrB   s   r   	on_expose pyglet_viewer.<locals>.on_expose\   s]    OOCc3/JJr--.HHSYY&!+cjj(A-r   )r   r2   r3   r4   pyglet.windowr5   pyglet.image.codecsr6   ImportErrorload
ValueErrorformatConfigWindowr;   r<   	set_vsyncrC   rJ   rR   rA   dispatch_eventsflipKeyboardInterruptclose)r,   r-   r2   r3   r6   offsetr?   rJ   rR   r4   rQ   r5   rC   rB   s            @@@@@r   pyglet_viewerrb   6   sI   Y,,%<Ujj FYYUY+F
--ii!F("zzAfH$  C MM%	   	 (	 ",,!HHJ ,,, IIKe  YWXXY
   UGNNsSTTUT  s)   D D A,E D!D>
EE T)preamblepackagesextra_preambleeulerfontsizec                   Uc  US-   nU(       a  US-  nSSR                  U Vs/ s H  nSU-  PM
     sn5      -   n	U(       a  X-  n	U(       d  SnO&[        U[        5      (       a  SR                  U5      nSU< SU	< S	3nOU(       d  U(       a  [	        S
5      e[        U [
        5      (       a  U n
OS[        U 4SS0UD6-   S-   n
US-   U
-   S-   S-   $ s  snf )z9
Generate string of a LaTeX document rendering ``expr``.
)amsmathamsfonts)rg   
z\usepackage{%s}12ptz{}ptz\documentclass[varwidth,z]{standalone}
z

\begin{document}
zcThe "packages" or "extra_preamble" keywordsmust not be set if a custom LaTeX preamble was specifiedz$\displaystyle modeplain$z

z\end{document})r   
isinstanceintrY   rX   strr   )exprrd   re   rf   rg   rh   latex_settingsactual_packagesppackage_includeslatex_strings              r   _get_latex_mainrz   p   s   
 "%<<z)O$))6E-G6E .@!-C6E-G #H H.H#&&}}X.H
 !	# ~ C D D $*dCCNCD d?\)F25FFF7-Gs   C
)r   dvipng)r   )evincegimpzsuperior-dvi-viewer)exemodulesdisable_viewersc           
         Uc  US:X  a   SSK n[        nUcB  / SQ/ SQ/ SQS.nUR                  U/ 5       H   n[        R
                  " U5      nUc  M  Un  O   Uc  [        nUS:X  a  Uc  [        S	5      eONUS
:X  a  Uc  [        S5      eO9[        U5      (       d)  [        R
                  " U5      (       d  [        SU-  5      e[        U 4XtX:US.UD6n[        S5        [        U5        [        R                  " 5        n[        [        US5      5      R!                  USS9  U	b!  [        R"                  " [        US5      U	5        [        R
                  " S5      (       d  [%        S5      e ['        / SQU[(        S9  SU-  nUS:w  a  S// SQS/S/S.n UU   nU H%  n[        R
                  " U5      nU(       d  M"  U/n  O?   [1        U5      S:  a  [%        S S!R                  U5      -  5      e[%        S"US   -  5      e/ S#QS$/S%.nS&US'/S'U/S&US'/S&US'/S&US'/S&US'/S(.nUb  UR3                  U5        O!UR3                  UR                  U/ 5      5        UR3                  UU   5         ['        UU[(        S9  US:X  a"  [        R4                  " [        UU5      U5        OoUS
:X  a5  [        [        UU5      5      R7                  5       nUR9                  U5        O4[        U5      (       a  U" [        UU5      US,9  O ['        UU/U[(        S9  SSS5        g! [         a     GNf = f! [*         a  n[%        SUR,                  -  5      eSnAff = f! [.         a    [        SU-  5      Sef = f! [*         a1  n[%        S)S*R                  U5      < S+UR,                  < 35      eSnAff = f! [*         a&  n[%        S)U< S*U< S+UR,                  < 35      eSnAff = f! , (       d  f       g= f)-a~  
View expression or LaTeX markup in PNG, DVI, PostScript or PDF form.

If the expr argument is an expression, it will be exported to LaTeX and
then compiled using the available TeX distribution.  The first argument,
'expr', may also be a LaTeX string.  The function will then run the
appropriate viewer for the given output format or use the user defined
one. By default png output is generated.

By default pretty Euler fonts are used for typesetting (they were used to
typeset the well known "Concrete Mathematics" book). For that to work, you
need the 'eulervm.sty' LaTeX style (in Debian/Ubuntu, install the
texlive-fonts-extra package). If you prefer default AMS fonts or your
system lacks 'eulervm' LaTeX package then unset the 'euler' keyword
argument.

To use viewer auto-detection, lets say for 'png' output, issue

>>> from sympy import symbols, preview, Symbol
>>> x, y = symbols("x,y")

>>> preview(x + y, output='png')

This will choose 'pyglet' by default. To select a different one, do

>>> preview(x + y, output='png', viewer='gimp')

The 'png' format is considered special. For all other formats the rules
are slightly different. As an example we will take 'dvi' output format. If
you would run

>>> preview(x + y, output='dvi')

then 'view' will look for available 'dvi' viewers on your system
(predefined in the function, so it will try evince, first, then kdvi and
xdvi). If nothing is found, it will fall back to using a system file
association (via ``open`` and ``xdg-open``). To always use your system file
association without searching for the above readers, use

>>> from sympy.printing.preview import system_default_viewer
>>> preview(x + y, output='dvi', viewer=system_default_viewer)

If this still does not find the viewer you want, it can be set explicitly.

>>> preview(x + y, output='dvi', viewer='superior-dvi-viewer')

This will skip auto-detection and will run user specified
'superior-dvi-viewer'. If ``view`` fails to find it on your system it will
gracefully raise an exception.

You may also enter ``'file'`` for the viewer argument. Doing so will cause
this function to return a file object in read-only mode, if ``filename``
is unset. However, if it was set, then 'preview' writes the generated
file to this filename instead.

There is also support for writing to a ``io.BytesIO`` like object, which
needs to be passed to the ``outputbuffer`` argument.

>>> from io import BytesIO
>>> obj = BytesIO()
>>> preview(x + y, output='png', viewer='BytesIO',
...         outputbuffer=obj)

The LaTeX preamble can be customized by setting the 'preamble' keyword
argument. This can be used, e.g., to set a different font size, use a
custom documentclass or import certain set of LaTeX packages.

>>> preamble = "\\documentclass[10pt]{article}\n" \
...            "\\usepackage{amsmath,amsfonts}\\begin{document}"
>>> preview(x + y, output='png', preamble=preamble)

It is also possible to use the standard preamble and provide additional
information to the preamble using the ``extra_preamble`` keyword argument.

>>> from sympy import sin
>>> extra_preamble = "\\renewcommand{\\sin}{\\cos}"
>>> preview(sin(x), output='png', extra_preamble=extra_preamble)

If the value of 'output' is different from 'dvi' then command line
options can be set ('dvioptions' argument) for the execution of the
'dvi'+output conversion tool. These options have to be in the form of a
list of strings (see ``subprocess.Popen``).

Additional keyword args will be passed to the :func:`~sympy.printing.latex.latex` call,
e.g., the ``symbol_names`` flag.

>>> phidd = Symbol('phidd')
>>> preview(phidd, symbol_names={phidd: r'\ddot{\varphi}'})

For post-processing the generated TeX File can be written to a file by
passing the desired filename to the 'outputTexFile' keyword
argument. To write the TeX code to a file named
``"sample.tex"`` and run the default png viewer to display the resulting
bitmap, do

>>> preview(x + y, outputTexFile="sample.tex")


Npngr   )r|   okularkdvixdvi)r|   r   gsviewgv)r|   r   kpdfacroreadxpdfr   )dvipspdffilez-filename has to be specified if viewer="file"BytesIOzFoutputbuffer has to be a BytesIO compatible object if viewer="BytesIO"zUnrecognized viewer: %s)rd   re   rg   rf   rh   zLatex code:
texput.texzutf-8)encodingr   zlatex program is not installed)r   z-halt-on-errorz-interaction=nonstopmoder   )cwdstderrz7'latex' exited abnormally with the following output:
%sz	texput.%sr   dvips)dvipdfmxdvipdfmdvipdfr{   dvisvgm)r   r   r   svgzInvalid output format: %sr
   zNone of %s are installedz, z%s is not installed)z-Ttightz-z9z--truecolorz
--no-fonts)r{   r   z-oz
texput.dvi)r   r   r   r   r{   r   ' z/' exited abnormally with the following output:
)r-   )r   rb   rV   getr%   whichr0   rX   callableOSErrorrz   r	   r!   TemporaryDirectoryr   r   
write_textcopyfileRuntimeErrorr   r   r   outputKeyErrorlenextendmove
read_byteswrite)rt   r   viewerrg   re   filenameoutputbufferrd   
dvioptionsoutputTexFilerf   rh   ru   r   
candidates	candidater#   
latex_mainworkdiresrccommandnamescmd_variantscmd_variantcmd_pathcmddefaultoptions
commandendss                                r   r   r      sE   T ~&E/	# #F ~ :8K

 $3I<<	*D	 4 ~&NOO 	9	 G H H   ffll6&:&:/&899  F',*2F6DFJ 
-	*		$	$	&'T'<()44Z'4R$OOD,7G||G$$?@@		#	 V$U? i8 z!{	LQ+F3
  ,!<<48#*C	  , |$q(&'ADIIlD['[\\&'<|A'NOO D(>N \2'- #|4!35l3 #|4J %

:&

>--k2>?JJz+.//'H VKKWc*H5y T'3'(335Aq!f4%62-'SMwv?i 
'	&S  		p " 	J 	"  Q !<v!EFDPQJ & /"XXc]AHH./ //" & -"S!((,- --m 
'	&s   L" A.O+0L3O+M O+B0O+3M:BO+N8"
L0/L03
M=MMO+M77O+:
N5,N00N55O+8
O(!O##O((O++
O9)r   NTrc   NNNNNNN)r   os.pathr   r%   r!   pathlibr   r)   r   r   r   rV   sympy.utilities.decoratorr   sympy.utilities.miscr	   r   __doctest_requires__r   r0   rb   rz   r   rc   r   r   <module>r      s    	    	CC 9 & $xj1 F327t '+R$GN +[EGBDHL>Bm-Gm-a  		s   
A# #A,+A,