我逐渐意识到,许多软件包文档中宏描述的令人愉悦的风格(斜体参数,用尖括号括起来)实际上是由文档类提供的许多特殊命令(例如\marg
和)生成的。\oarg
ltxdoc
以下屏幕截图取自该listings
包的文档。
如何使用常规包(例如listings
)在article
文档类中产生相同(或类似)的结果?
答案1
掠夺现有代码大有裨益:)
\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}
参考: