inherance (of bold, italic, etc) not working as expected with LaTeX

Issue #614 on hold
Former user created an issue

Hi, I'm using Pygmentize for LaTeX output but I've got an annoying bug, I can't get italic comments while getting non italic preprocessor directives like a #include, while it works on HTML output. The problem lies in some wrong handling of style inherance for LaTeX. For example, in murphy style we have:

Comment: "#666 italic", Comment.Preproc: "#579 noitalic", Comment.Special: "#c00 bold",

and, even though we have noitalic for Preproc, it keeps italic in LaTeX output (I'm using pdfLatex on TeX Live 2010) while it outputs non italic on html.

Pygmentize is great thanks.

Comments (6)

  1. Anonymous

    Create a directory and inside it create a file named main.cpp with the following contents:

    #include <iostream>
    int main()
    	// Saying hello to the world
    	std::cout << "Hello World!" << std::endl;
    	return 0;

    Navigate to that directory through the command shell and execute the command

    pygmentize -O full,style=murphy -l c++ -f html -o main.html main.cpp

    then execute

    pygmentize -O full,style=murphy -l c++ -f latex -o main.tex main.cpp

    now execute

    pdflatex main.tex

    Now opening both pdf and html output you may see that the #include in the html file isn't italic, which is expected since the murphy style used here doens't inherent italics for the directives (directives are view as subsections of comments in styles), but it keeps italic in the pdf file, while in both, the comments are italic as expected.


  2. Anonymous

    The issue is discussed here and a solution is presented.

    Here's a patch against current pygments tip:

    --- pygments/formatters/	2011-07-22 22:55:29.000000000 +0300
    +++ pygments/formatters/	2011-07-22 22:58:29.000000000 +0300
    @@ -96,11 +96,9 @@
         \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}
    -    \%(cp)s@tok{#1}\expandafter\%(cp)s@toks\fi}
    @@ -340,14 +338,11 @@
                     value = escape_tex(value, self.commandprefix)
                 styles = []
    -            while ttype is not Token:
    -                try:
    -                    styles.append(t2n[ttype])
    -                except KeyError:
    -                    # not in current style
    -                    styles.append(_get_ttype_name(ttype))
    -                ttype = ttype.parent
    -            styleval = '+'.join(reversed(styles))
    +            try:
    +                styleval = t2n[ttype]
    +            except KeyError:
    +                # not in current style
    +                styleval = _get_ttype_name(ttype)
                 if styleval:
                     spl = value.split('\n')
                     for line in spl[:-1]:

    Please, apply this patch.

  3. Log in to comment