5

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:

 \newenvironment{Method}{
 \begin{lstlisting}
 Method Boolean TestFunc(Integer MyPar) \end{lstlisting}
 Parameters:
 \begin{itemize}
 \par{Integer}{MyPar}{Description}
 }

 {
 \end{itemize}

 }

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:

\begin{lstlisting}
 Method Boolean TestFunc(#1 #2) 
\end{lstlisting}

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
1

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.

\documentclass{article}
\usepackage{color}

\newenvironment{method}[3]{%
  \begingroup
  \setlength\parindent{0pt}
  \newcommand\typesetparam[3]{\item[\texttt{\color{blue}##2}] \texttt{##1}: ##3}
  \begingroup\tt
    Method \textcolor{blue}{#2} #1(#3)
    \endgroup\par
  Parameters:
  \begin{description}
}{
  \end{description}
  \endgroup
}

\begin{document}

\begin{method}{TestFunc}{Boolean}{Integer MyPar}
  \typesetparam{MyPar}{Integer}{Description}
\end{method}

\end{document}

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.