Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have come to realize that the pleasant style (argument in italics, enclosed by angle brackets) of macro descriptions in numerous package documentations is actually produced by a number of special commands, such as \marg and \oarg, provided by the ltxdoc document class.

The following screenshot is taken from documentation of the listings package.

enter image description here

How can I produce the same (or similar) result with normal packages (e.g. listings) in, say, the article document class?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Plundering existing code goes a long way :)

enter image description here

\documentclass{article}

\usepackage[T1]{fontenc} % for typewriter braces 
\usepackage{textcomp}    % for ``text'' angle brackets
\usepackage{xcolor}

% adapted from doc.dtx    
\providecommand\meta[1]{\textlangle{\itshape #1\/}\textrangle}

% directly taken from ltxdoc.dtx
\providecommand\marg[1]{%
  {\ttfamily\char`\{}\meta{#1}{\ttfamily\char`\}}}
\providecommand\oarg[1]{%
  {\ttfamily[}\meta{#1}{\ttfamily]}}

% directly taken from listings.dtx (lstdoc.sty)
\definecolor{darkgreen}{rgb}{0,0.5,0}
\def\rstyle{\color{darkgreen}}

% adapted from listings.dtx (lstdoc.sty)
\providecommand\rcmdname[1]{\texttt{\rstyle\string#1}}

\begin{document}
\rcmdname\lstset\marg{key=value list}
\par
\rcmdname\lstinputlisting\oarg{key=value list}\marg{file name}
\end{document}

References:

share|improve this answer
    
Thanks, :-) This works just fine. Although I cannot completely understand the code. But I will firstly search for what I do not know by myself. Moreover, I have found an easier solution provided by @LeoLiu (but not on SE site): Use listings package, and set \lstset{basicstyle=\ttfamily,moredelim=[s][\normalfont\itshape]{<}{>}}. –  Naitree May 3 at 14:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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