# Background

I have seen beautiful manuals with commands and descriptions of what they do. I have a shared preamble (edited by multiple people and used for multiple documents) that has a multitude of custom commands created with

• \newcommand
• \DeclareRobustCommand
• \DeclareDocumentCommand (xparse package)
• \renewcommand
• etc.

and a multitude of environments

• \newenvironment
• \NewEnviron (environ package)
• etc.

Recently, I asked the question: Is there a way to iterate over all defined colors without mentioning them again?

It turned out to be great! I was wondering whether I can do something similar with commands and their environments despite all of their complexities. All of my commands and environments have a three letter prefix, e.g. mbm (for "made by me").

# Goal

I would use this to create a template list of left-aligned commands/environments, followed by an aesthetically-pleasing space followed by a description of that command or environment.

# Example with Pseudocode

\documentclass{article}
\usepackage{fontspec}
\usepackage{listings}
\usepackage{tikz}
\usepackage{pgffor}

% Commands
\newcommand\mbmA{elephants}
\newcommand\mbmB[1]{#1}
\newif\ifcolormodules
\DeclareRobustCommand{\mbmmodule}[1]{%
\textbf{\textit{{\ifcolormodules\color{green}\fi #1}}}%
}%
\newcommand{\dq}[1]{\char"201C{}#1\char"201D{}} % Exception to mbm prefix rule
\newcommand{\sq}[1]{\char"2018{}#1\char"2019{}} % Exception to mbm prefix rule
% Environments
\lstnewenvironment{mbmlstcode}{\lstset{basicstyle=\ttfamily\small,columns=fullflexible,keepspaces=true,basewidth=0.5em}}{}
\NewEnviron{mbmerrors}{%
\BODY
}

\begin{document}

\section{Commands}
\foreach \definedcommand in {defined commands} % pseudo-code
\begin{tikzpicture}
\node [minimum width=3cm, minimum height=1cm,text=red] {\string\definedcommand}; % pseudo-code
\end{tikzpicture}

\section{Environments}
\foreach \definedenvironment in {defined environment} % pseudo-code
\begin{tikzpicture}
\node [minimum width=3cm, minimum height=1cm,text=orange] {\string\definedenvironment}; % pseudo-code
\end{tikzpicture}

\end{document}

• may be help tex.stackexchange.com/questions/222861/… – touhami Apr 10 '15 at 7:36
• It seems definitely possible to use this approach to do what he whishes, but I guess if you want to create a documentation of this piece of code, it would be better suited to make use of the package documentation tools already existing. You might want to have a look at the CTAN list of documentation creation packages or more specifically the dox package. – Samuel Albert Apr 10 '15 at 8:39
• @Jonathan Komar I just come upon a similar problem working on a larger document with several people. Different commands for basically the same thing were defined and mixed up. It would have been very convinient to have such a list of commands automatically provided to every author. Did you find a proper solution for this question by now? If so, would you mind sharing this solution as answer to your own question? – Dave Jan 25 at 12:35
• @Dave, I ended up just using grep and searching for patterns. The only way to do that would be to redefine each command to include a writeout to some list that could be printed later. It was not worth the effort...for color definitions, however, I did create such a command where I defined groups of colors called palettes (accent colors, main colors) whose list I could easily print. – Jonathan Komar Jan 25 at 13:32
• @Dave That approach would work but has issues. The foremost reason is one of sheer complexity: not every def is alike (but finite set, so possible). You have the preexpanded ones and non-expanded (def/edef). You have protected ones too. The viability of your approach depends on how much time you are willing to spend. I determined it was not worth my time. Learn C or something, it would be easier ;) Anyway, I will post an answer of my half-solution. – Jonathan Komar Jan 26 at 7:08