I am writing a summary of my methods in c++ where the outputstyle is always the same like that:

TestFunc (Title as subsection)

Method Boolean TestFunc(Integer MyPar) (this should be in a Lstlisting environment)

Description of the Method (as Text)

Parameters: (List of Parameters using itemize like that:)

  • MyPar: followed Description of the parameter

Return values: (List of Return Values like that):

  • True: Description1
  • False Description2

Since I have lots more to go i was thinking about harmonizing it, using my own commands and environments. I thought about something like that:

 Method Boolean TestFunc(Integer MyPar) \end{lstlisting}



while \par should be sth like that: \newcommand{\par}[3]{\item #2: #3}

How can i combine all this? so it would also be possible to include the par-defined stuff in the lstlisting like:

 Method Boolean TestFunc(#1 #2) 

And furthermore: Sometimes the methods have no input arguments, sometimes they have three, so I sort of need numbered parameters. Any idea how to do that?

  • 1
    You can do that but don't call the command \par bad things will happen if you do that (it is the tex primitive to typeset a paragraph) – David Carlisle Jun 28 '13 at 15:15

Here is my suggestion, fancied up a little with colors and formatting.

It doesn't use the listings package, but that's not really necessary here, because you already know pretty well how your output is supposed to be formatted. Additionally, using listings would make things complicated because you can't easily pass verbatim arguments through commands/environments.


  \newcommand\typesetparam[3]{\item[\texttt{\color{blue}##2}] \texttt{##1}: ##3}
    Method \textcolor{blue}{#2} #1(#3)


\begin{method}{TestFunc}{Boolean}{Integer MyPar}


Your Answer

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

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