2

I stumbeled over a way of formatting sourcecode in a book I am currently reading. It looks like this: example

So basically we have a following structure:

  • There are two columns. Left column contains the code, right contains the comments
  • A comment can be assigned to a line or a block of code
  • The background color is adjusted to the box of associated parts (gray box in the example)
  • Line numbers for each line of code

Does anybody at least know a template which looks like this? So I would have a point where I could start of.

Currently I am using verbatim lstlisting. But if there are any other packages, which are more suitable for that kind of formatting code, I would not mind using them either.

  • Thank you for the reference. Though there are some issues with given examples. I liked the structure of writing (*@comment@*) code in the latter example. What I did not like is the fact, that I could not put code in separate file e.g. code.cpp: begin{beautifulcode} some code here end{beautifulcode}} and including it via include{code.cpp}. And I also have no idea on how to put a background on a group of comment + code. – zunder Dec 27 '14 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.