I have a software product with an public api, which i want to documentate in LaTeX. The output should look like the following

FunctionName(type1 param1, type2 param2 [, type3 param3] ...)

param1: (required) does this
param2: (required) does this with an longer explanation
param3: does that

I currently achive that with lstlistings for the first line and an description Environment for the paramter explanation.

Is there a package that allows me to write something like

    \param[type=type1,required] does this
    \param[type=type2,required] does that

I tried to develop that by myselve but it stuck at writing the CallString to the aux file, because i processed the function environment as an description environment, and wanted to load the first line in the second run from an aux file.

So the question is, whether there is allready a package that can archieve that.


Several languages provide facilities for extracting function signatures and other documentation strings from properly formatted comments in the source code. There is also the doxygen program (http://www.doxygen.nl/), which supports several programming languages that may not provide LaTeX documentation support themselves, and which can apparently be adapted to additional languages, in case yours is not already on the list. If you used such a facility, you could

  1. keep the documentation and the source code together, which makes it easier to keep the docs up to date when the code changes,

  2. generate both offline (LaTeX) and online (HTML) docs from the same source.

I would suggest that you explore this approach.


You can process all of the content within (La)TeX.

The following minimal example processes the function environment twice. In the first cycle it captures all the \params to isolate their type and whether they're required (keys). The second processing of the environment sets the \params in a description environment using the isolated keys. You can define a new name for each parameter as well. Extensions are also possible.

enter image description here



% Setup keys used in \param[<keys>]
% Key: type (defaults to <blank>)
  \expandafter\xdef\csname param@\FunctionName @\theparamcount @type\endcsname
% Key: required (defaults to true)
  \expandafter\xdef\csname param@\FunctionName @\theparamcount @required\endcsname
% Key: name (defaults to param#)
  \expandafter\xdef\csname param@\FunctionName @\theparamcount @name\endcsname

  \def\FunctionName{#1}% Capture function name
    \stepcounter{paramcount}% Count parameters
      type, % Default type is empty
      name,% Default name is param#
      ##1}% Local specifications
  \setbox1=\hbox{\BODY}% process \BODY once to pick up parameters
  \def\paramsep{\def\paramsep{, }}% https://tex.stackexchange.com/a/89187/5764
  \textbf{#1}% Set function name
  (\multido{\i=1+1}{\value{paramcount}}{% Set parameters
    \csname param@\FunctionName @\i @type\endcsname~% Type
    \csname param@\FunctionName @\i @name\endcsname% Name
  % Set parameters using a description environment
      \item[\csname param@\FunctionName @\theparamcount @name\endcsname:]
      \ifnum\pdfstrcmp{\csname param@\FunctionName @\theparamcount @required\endcsname}{true}=0
        (required)% Item is required



  \param[type = typeA, name = stringA] does this
  \param[type = typeB, required] does that


  \param[type = typeC, name = somethingA] does this
  \param[type = typeB, name = somethingB, required] does that


  \param[type = typeD, required] does this
  \param[type = typeE, required] does that


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.