|egKdZddlmZddlmZddlmZmZddlm Z m Z ddl m Z m Z dgZdZd Zd Zd ZGd deZGd deZy)z pygments.formatters.latex ~~~~~~~~~~~~~~~~~~~~~~~~~ Formatter for LaTeX fancyvrb output. :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. )StringIO) Formatter)Lexer do_insertions)TokenSTANDARD_TYPES) get_bool_opt get_int_optLatexFormatterc|jddjddjddjdd|zjdd|zjdd |zjd d |zjd d |zjdd|zjdd|zjdd|zjdd|zjdd|zjdd|zjdd|zjdd|zjdd|zjd d!|zS)"N\{}z\%sZbs{}z\%sZob{}z\%sZcb{}^z\%sZca{}_z\%sZus{}&z\%sZam{}z\%sZgt{}#z\%sZsh{}%z\%sZpc{}$z\%sZdl{}-z\%sZhy{}'z\%sZsq{}"z\%sZdq{}~z\%sZti{})replace)text commandprefixs ;/usr/lib/python3/dist-packages/pygments/formatters/latex.py escape_texr#s, <<f %V$V$ m ;< m ;< m ;<[=89[=89[=89[=89[=89[=89[=89[=89[=89[=89[=89[=89#:z \documentclass{%(docclass)s} \usepackage{fancyvrb} \usepackage{color} \usepackage[%(encoding)s]{inputenc} %(preamble)s %(styledefs)s \begin{document} \section*{%(title)s} %(code)s \end{document} a \makeatletter \def\%(cp)s@reset{\let\%(cp)s@it=\relax \let\%(cp)s@bf=\relax%% \let\%(cp)s@ul=\relax \let\%(cp)s@tc=\relax%% \let\%(cp)s@bc=\relax \let\%(cp)s@ff=\relax} \def\%(cp)s@tok#1{\csname %(cp)s@tok@#1\endcsname} \def\%(cp)s@toks#1+{\ifx\relax#1\empty\else%% \%(cp)s@tok{#1}\expandafter\%(cp)s@toks\fi} \def\%(cp)s@do#1{\%(cp)s@bc{\%(cp)s@tc{\%(cp)s@ul{%% \%(cp)s@it{\%(cp)s@bf{\%(cp)s@ff{#1}}}}}}} \def\%(cp)s#1#2{\%(cp)s@reset\%(cp)s@toks#1+\relax+\%(cp)s@do{#2}} %(styles)s \def\%(cp)sZbs{\char`\\} \def\%(cp)sZus{\char`\_} \def\%(cp)sZob{\char`\{} \def\%(cp)sZcb{\char`\}} \def\%(cp)sZca{\char`\^} \def\%(cp)sZam{\char`\&} \def\%(cp)sZlt{\char`\<} \def\%(cp)sZgt{\char`\>} \def\%(cp)sZsh{\char`\#} \def\%(cp)sZpc{\char`\%%} \def\%(cp)sZdl{\char`\$} \def\%(cp)sZhy{\char`\-} \def\%(cp)sZsq{\char`\'} \def\%(cp)sZdq{\char`\"} \def\%(cp)sZti{\char`\~} %% for compatibility with earlier versions \def\%(cp)sZat{@} \def\%(cp)sZlb{[} \def\%(cp)sZrb{]} \makeatother ctj|}|r|Sd}|,|d|z}|j}tj|}|,||zS)N)rgetparent)ttypefnameanames r"_get_ttype_namer-s^   u %E  E -b E! ""5) - 5=r$c<eZdZdZdZddgZdgZdZdZd dZ d Z y ) r a Format tokens as LaTeX code. This needs the `fancyvrb` and `color` standard packages. Without the `full` option, code is formatted as one ``Verbatim`` environment, like this: .. sourcecode:: latex \begin{Verbatim}[commandchars=\\\{\}] \PY{k}{def }\PY{n+nf}{foo}(\PY{n}{bar}): \PY{k}{pass} \end{Verbatim} Wrapping can be disabled using the `nowrap` option. The special command used here (``\PY``) and all the other macros it needs are output by the `get_style_defs` method. With the `full` option, a complete LaTeX document is output, including the command definitions in the preamble. The `get_style_defs()` method of a `LatexFormatter` returns a string containing ``\def`` commands defining the macros needed inside the ``Verbatim`` environments. Additional options accepted: `nowrap` If set to ``True``, don't wrap the tokens at all, not even inside a ``\begin{Verbatim}`` environment. This disables most other options (default: ``False``). `style` The style to use, can be a string or a Style subclass (default: ``'default'``). `full` Tells the formatter to output a "full" document, i.e. a complete self-contained document (default: ``False``). `title` If `full` is true, the title that should be used to caption the document (default: ``''``). `docclass` If the `full` option is enabled, this is the document class to use (default: ``'article'``). `preamble` If the `full` option is enabled, this can be further preamble commands, e.g. ``\usepackage`` (default: ``''``). `linenos` If set to ``True``, output line numbers (default: ``False``). `linenostart` The line number for the first line (default: ``1``). `linenostep` If set to a number n > 1, only every nth line number is printed. `verboptions` Additional options given to the Verbatim environment (see the *fancyvrb* docs for possible values) (default: ``''``). `commandprefix` The LaTeX commands used to produce colored output are constructed using this prefix and some letters (default: ``'PY'``). .. versionadded:: 0.7 .. versionchanged:: 0.10 The default is now ``'PY'`` instead of ``'C'``. `texcomments` If set to ``True``, enables LaTeX comment lines. That is, LaTex markup in comment tokens is not escaped so that LaTeX can render it (default: ``False``). .. versionadded:: 1.2 `mathescape` If set to ``True``, enables LaTeX math mode escape in comments. That is, ``'$...$'`` inside a comment will trigger math mode (default: ``False``). .. versionadded:: 1.2 `escapeinside` If set to a string of length 2, enables escaping to LaTeX. Text delimited by these 2 characters is read as LaTeX code and typeset accordingly. It has no effect in string literals. It has no effect in comments if `texcomments` or `mathescape` is set. (default: ``''``). .. versionadded:: 2.0 `envname` Allows you to pick an alternative environment name replacing Verbatim. The alternate environment still has to support Verbatim's option syntax. (default: ``'Verbatim'``). .. versionadded:: 2.0 LaTeXlatextexz*.texc tj|fi|t|dd|_|j dd|_|j dd|_t|dd|_tt|dd |_ tt|d d |_ |j d d|_ t|d d|_ |j d d|_t|dd|_t|dd|_|j dd|_t%|j"dk(r)|j"d|_|j"d |_nd|_|j dd|_|j-y)NnowrapFdocclassarticlepreambler&linenos linenostart linenostep verboptions nobackgroundr!PY texcomments mathescape escapeinsiderenvnameVerbatim)r__init__r r3r(r4r6r7absr r8r:r;r<r!r>r?r@lenleftrightrB_create_stylesheet)selfoptionss r"rDzLatexFormatter.__init__sL4+7+"7He<  J :  J3 #GY> {7M1EFk'<CD";;}b9(.%H$[[$?'F&w eD#KK; t  !Q &))!,DI**1-DJ "D {{9j9  !r$c tdix}|_ix}|_|j}d}|jD]\}}t |}d}|dr|dz }|dr|dz }|dr|dz }|d r|d z }|d r|d z }|d r|d z }|dr|d||dzz }|dr|d||dd||ddz }n|dr|d||dzz }|dk(r|j d|}|||<|||<y)Nr&c |r;djdDcgc] }dt||||dzzddz z"c}Sycc}w)N,)rrAz%.2fr9go@z1,1,1)joinint)colis r"rgbcolorz3LatexFormatter._create_stylesheet..rgbcolorsXxx*3!5%&"(3s1vAE /BB+G%+O!P!566!5s%?boldz\let\$$@bf=\textbfitalicz\let\$$@it=\textit underlinez\let\$$@ul=\underlineromanz\let\$$@ff=\textrmsansz\let\$$@ff=\textsfmonocolorz'\def\$$@tc##1{\textcolor[rgb]{%s}{##1}}borderzG\def\$$@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{}{bgcolorz}{\strut ##1}}}zH\def\$$@bc##1{{\setlength{\fboxsep}{0pt}\colorbox[rgb]{%s}{\strut ##1}}}z$$)r ttype2namecmd2defr!styler-r) rJt2nc2dcprUr*ndefnamecmndefs r"rIz!LatexFormatter._create_stylesheetsm!& +dodl     :: KE4"5)DFF|//H~//K 22G}//F|//F|//G}E#DM234H~$T(^4$T)_578i?#DO456|^^D"-FCJCI? r$c |j}g}|jjD] \}}|jd|d|d|d"t|jdj |dzS)z Return the command sequences needed to define the commands used to format text in the verbatim environment. ``arg`` is ignored. z \@namedef{z@tok@r^r )restyles)r!raitemsappendSTYLE_TEMPLATErQ)rJargrerkrg definitions r"get_style_defszLatexFormatter.get_style_defsDsp    $ 2 2 4 P D* MMT:N O Pt'9'9+/99V+<!>> >r$c |j}|j}|jr |}t}|js|j d|j zdz|jrE|j|j}}|j d|xrd|zxsdz|xrd|zxsdz|js|js |jr|j d|jr|j d|jz|j d |D]^\}} |tjvrV|jrU| d d }t!d t#| D]} |d | | k7rn || | z }| t#|d} t%||}|| z} n|jrL| j'd } d } t)| D]\} } | st%| || | <| } d j+| } n|jr| }d} |r|j-|j.\}}}|rJ|j-|j0\}}}|r| t%|||zz } n%| t%||z|z|z } n| t%||z } |r}n+t%| |} n|tj2vr t%| |} g}|tur* |j5|||j:}|tur*dj+t=|}|rp| j'd}|ddD]0}|r|j d|d|d|d|j d2|ds.|j d|d|d|ddN|j | a|js!|j d|j zdz|jr|j>xsd}ddddjA|jCdd|}j tDtG|jH|jJ|jL||jO|jQzyy#t6$r|j5t9|YwxYw)Nz\begin{z}[commandchars=\\\{\}z ,numbers=leftz,firstnumber=%dr&z,stepnumber=%dz6,codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}rNz] rr9rF+rjr'r rr^rz\end{z} utf8latin1)utf_8latin_1 iso_8859_1rr)r4r6titleencoding styledefscode))r`r!fullrr3writerBr7r8r:r?r>r@r;rCommentrangerFr#split enumeraterQ partitionrGrHEscapermKeyErrorr-r)reversedrzr(r DOC_TEMPLATEdictr4r6ryrqgetvalue)rJ tokensourceoutfilercre realoutfilestartstepr*valuerTpartsin_mathpartr asep1bsep2rkstylevalspllinerzs r"format_unencodedzLatexFormatter.format_unencodedPsDoo    99!KjG{{ MM*t||36QQ R||"..t o$B):U)BHbJ#?(84(?E2GH$"2"2d6G6G 89 cD$4$445 MM% '; %LE5 %##!!AJE"1c%j1* 8uQx/!q)* "#e*+.E&ub1E"EME__!KK,E#G#,U#3.4&'1$';E!H&-+. HHUOE&& DE(,tyy(A 4,0NN4::,FMAtT# %Ar):Q)> > %AHqL")E E!Z2%66E'ub1Eell*"5"-Fu$:MM#e*-  u$xx 01Hkk$'H(D Hd&KLMM$'(r7MMB#b'"JK e$w; %z{{ MM(T\\1E9 : 99}}.H #&c(""3,h7    l!%!%!)!%!4!4!6!(!1!1!3 55 6 ' :MM/%"89:s:Q#Q<;Q<N)r&) __name__ __module__ __qualname____doc__rgaliases filenamesrDrIrqrr$r"r r s7gP DG I".+Z >e6r$c.eZdZdZdZdZdZdZdZy)LatexEmbeddedLexera This lexer takes one lexer as argument, the lexer for the language being formatted, and the left and right delimiters for escaped text. First everything is scanned using the language lexer to obtain strings and comments. All other consecutive tokens are merged and the resulting text is scanned for escaped segments, which are given the Token.Escape type. Finally text that is not escaped is scanned again with the language lexer. c Z||_||_||_tj|fi|yN)rGrHlangrrD)rJrGrHrrKs r"rDzLatexEmbeddedLexer.__init__s(    t'w'r$c@d}g}g}|j|D]B\}}}|&|r|jt||fg}||z }/|j|||fD|r|jt||ft||jj |S)Nr&)_find_safe_escape_tokensrmrFrrget_tokens_unprocessed)rJr buffered insertions insertion_bufrTtvs r"rz)LatexEmbeddedLexer.get_tokens_unprocesseds  44T: 0GAq!y %%s8}m&DE$&MA $$aAY/ 0    s8}m< =Z!YY==hGI Ir$c#K|j|jj|dD]4\}}}|%|j|D]\}}}||z||f.|d|f6yw)z8 find escape tokens that are not in strings or comments cN|tjvxs|tjvSr)rrString)rs r"z=LatexEmbeddedLexer._find_safe_escape_tokens..sa5==(=A,=r$N) _filter_torr_find_escape_tokens)rJr rTrri2t2v2s r"rz+LatexEmbeddedLexer._find_safe_escape_tokenss~ II , ,T 2 =  !GAq!y"&":":1"=)JBBb&"b.()qj  !sA%A'c#Kd}d}|D]*\}}}||r|r |d|fd}|||f"|s|}||z },|r|d|fyyw)zC Keep only the tokens that match `pred`, merge the others together r&rNr)rJitpredbufidxrTrrs r"rzLatexEmbeddedLexer._filter_tosr GAq!AwtS.(CAg Cq  tS.  s?Ac#Kd}|r|j|j\}}}|r|d|f|t|z }|r|j|j\}}}|rH|t|ztj |f|t|t|zt|zz }n%|tj |f|t|z }|}|ryyw)z; Find escape tokens within text, give token=None otherwise rN)rrGrFrHrrError)rJr indexrrrrs r"rz&LatexEmbeddedLexer._find_escape_tokenss NN4995MAtTT1n$Q $tzz : 4#d)+U\\1<<SYQ/#d);;Ed22SY&EDs C CCN) rrrrrDrrrrrr$r"rrs! ( I& !!"r$rN)riorpygments.formatterrpygments.lexerrrpygments.tokenrr pygments.utilr r __all__r#rrnr-r rrr$r"rs\(/03  :* n"J b6Yb6J QQr$