4

I have to make list environment based on description that should be used to describe C functions.

For example:

% !TeX program = lualatex

\documentclass[11pt]{report}
\usepackage{enumitem}
\usepackage{minted}

\NewDocumentCommand{\code}{m}{\texttt{#1}}

\newlist{funcDescription}{description}{1}
\setlist[funcDescription, 1]{style=nextline, font=\mdseries\ttfamily, align=left}

\begin{document}

    \begin{funcDescription}
        \item[int printf(const char * format, ...)]
            Writes the \code{C} string pointed by format to the standard output
            (stdout). If format includes format specifiers (subsequences
            beginning with \code{\%}), the additional arguments following
            format are formatted and inserted in the resulting string replacing
            their respective specifiers.
    \end{funcDescription}
    
\end{document}

It produces the

enter image description here

But I want to apply \mintinline command to the \item[] argument. Also, I would like to pass verb text to the \item[] and \code{} argument.

So there is the questions:

  1. How to apply some command to funcDescription items from the \setlist?
  2. How to pass verb text to the \code{} command in latex with \NewDocumentCommand{}{}{}?
  3. How to pass verb text to the argument of \item[]?

(texdoc research didn't help)

1 Answer 1

4

This uses \funcitem instead of \item, which doesn't seem too big a nuisance.

\documentclass[11pt]{report}
\usepackage{enumitem}
\usepackage{minted}

\newmintinline[code]{C}{}

\newlist{funcDescription}{description}{1}
\setlist[funcDescription, 1]{
  style=nextline,
  font=\mdseries\ttfamily,
  align=left,
}
\NewDocumentCommand{\funcitem}{v}{\item[\code|#1|]}

\begin{document}

\begin{funcDescription}
  \funcitem{int printf(const char * format, ...)}
    Writes the \code{C} string pointed by format to the standard output
    (stdout). If format includes format specifiers (subsequences
    beginning with \code|%|), the additional arguments following
    format are formatted and inserted in the resulting string replacing
    their respective specifiers.
  \funcitem|printf(%d,argument_list)|
    This is just to show how to do with \code|%|
\end{funcDescription}
    
\end{document}

In case of need, also the argument to \funcitem can be enclosed in |...| (or any other pair of equal characters, as usual for \verb) as shown in the example. The same for \code.

enter image description here

1
  • Dang. This is that easy. Actually, about \funcitem, I thought there is some LaTeX way to do so, but if expert says that wrapper command is good enough I will take it. Thank You! Commented Jan 2 at 23:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .