1

I'm a newbie to LaTeX, so sorry if it's a trivial question, but I couldn't find the answer. I'm trying to print code listings inside LaTeX, but when I do so LaTeX doesn't keep code indentation from Java source code. I've found \lstdefineformat snippet for C language, but I don't know how to modify it for Java source code. Here's the snippet:

\lstdefineformat{stand}{
    \{=\newline\string\newline\indent,
    \}=[;]\newline\noindent\string\newline,
    \};=\newline\noindent\string\newline,
    ;=[\ ]\string\space}

And I want to modify this snippet to:

  1. Insert new line only after ending curly brace which I managed to do just by removing the first line
  2. After each starting curly brace the rest of the code should be indented by tab or 4 spaces regarding the code before the starting curly brace.
  3. After each keyword if if there is no curly braces for that conditional like:

    if (err)
        res.send(err);
    

There also should be indentation for the code after if or else statements.

Does anyone know how to do that or have a full command to format Java source code in LaTeX. Thanks for your time.

closed as unclear what you're asking by clemens, Zarko, Stefan Pinnow, user31729, CarLaTeX Mar 2 '17 at 22:28

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Where is \lstdefineformat defined? Can you please extend your code snippet into a minimal working example? – clemens Jan 22 '17 at 15:50