Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My document MWE:

\documentclass[12pt,a4paper]{mwrep}
\usepackage{minted}
\begin{document}
\inputminted[gobble=4,firstnumber=3,firstline=3,lastline=9,linenos,tabsize=4]{java}{Foo.java}
\end{document}

Content of Foo.java:

public class Foo
{
    public static void main(String[] args)
    {
        for(int i=0; i<10; i++)
        {
            System.out.println(i);
        }
    }
}

Presented TeX document will show and format method main. When I change the code of Foo class (e.g. add a new method above main or expand it), I would need to manually change the range of lines to show. Can it somehow be done automatically? I think of comments as a markers in the java code. Something like in one of the examples below:

public class Foo
{
    //start-main
    public static void main(String[] args)
    {
        for(int i=0; i<10; i++)
        {
            System.out.println(i);
        }
    }
    //end-main
}

or

public class Foo
{
    public static void main(String[] args) //start-main
    {
        for(int i=0; i<10; i++)
        {
            System.out.println(i);
        }
    } //end-main
}

Is it possible to pass this to LaTeX (or Pygments in this case)? I would like to be able to ignore those markers when presenting a larger portion of code (e.g. whole Foo.java file) but this is not as important as the main question. Maybe there is another way without any markers? For example telling Pygments to print main method from Foo class.
Of course I don't want to be limited to methods only. I want to be able to mark any part of the code this way.

share|improve this question
    
I will use listings package instead. –  Please don't touch Nov 24 '11 at 5:08
    
@CounterTerrorist, does listings have this feature? I prefer minted beceuse of better looking output. –  Ichibann Nov 24 '11 at 12:23
    
read my answer please. –  Please don't touch Nov 24 '11 at 12:46
    
@Ichibann: I agree that the default output of minted is somewhat more polished that the default output of listings; however, listings is pretty flexible wrt adapting the typesetting. If you search for the listings tag you will find a couple of "good looking" (well, it's a matter of taste...) examples (such as tex.stackexchange.com/questions/18376/…). –  Daniel Nov 24 '11 at 20:32

1 Answer 1

up vote 4 down vote accepted
+50

The following is taken from listings manual page 51 and 52.

enter image description here

share|improve this answer
    
Yes, this is nice :). If there were something like this in minted... –  Ichibann Nov 24 '11 at 17:47
    
This is not minted, but it works. –  Ichibann Nov 26 '11 at 21:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.