How would I best go about creating a custom directory similar to the Table of Contents, List of Figures, or List of Tables. For the sake of this example, I will call it a "List of Examples".
Let's say I have a custom environment that utilizes the convenience and readability of xparse of the environment definition and the beauty/robustness of tcolorbox for multiple-page support. A known issue is that I implement the optional argument incorrectly in that it does not support automatic line breaking. Also, perhaps the colon after Example would cause a funny-looking list of examples when no optional argument is provided.
\NewDocumentEnvironment{qikexample}{ O{} } % Optional Title, appears in List of Examples
{
\colorlet{colexam}{gray}
\newtcolorbox[use counter=qikexample,]{qikexamplebox}{%
% Example Frame Start
empty,% Empty previously set parameters
title={Example: #1},% use \thetcbcounter to access the qikexample counter text
% Attaching a box requires an overlay
attach boxed title to top left,
% (boxed title style requires an overlay)
boxed title style={empty,size=minimal,toprule=0pt,top=4pt,overlay={}},
coltitle=colexam,fonttitle=\bfseries,
before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=0pt,right=3mm,top=2pt,breakable,pad at break=0mm,
before upper=\csname @totalleftmargin\endcsname0pt, % Use instead of parbox=true. This ensures parskip is inherited by box.
% Handles box when it exists on one page only
overlay unbroken={\draw[colexam,line width=.5pt] ([xshift=-10pt]title.north west) -- ([xshift=-10pt]frame.south west); },
% Handles multipage box: first page
overlay first={\draw[colexam,line width=.5pt] ([xshift=-10pt]title.north west) -- ([xshift=-10pt]frame.south west); },
% Handles multipage box: middle page
overlay middle={\draw[colexam,line width=.5pt] ([xshift=-10pt]frame.north west) -- ([xshift=-10pt]frame.south west); },
% Handles multipage box: last page
overlay last={\draw[colexam,line width=.5pt] ([xshift=-10pt]frame.north west) -- ([xshift=-10pt]frame.south west); },%
}
\begin{qikexamplebox}}
{\end{qikexamplebox}\endlist}
I would implement this in a document like this:
\begin{qikexample}[List Contents of Directory in Unix]
ls
\end{qikexample}
I would like to add logic that lists their names and page numbers.
After running a command like \listofexamples, the output might look something like:
List of Examples
Example: List Contents of Directory in Unix .................. 23
Example: List Contents of Directory in Windows .................. 23
Code
\documentclass{article}
\usepackage{fontspec}
\usepackage[most]{tcolorbox}
\usepackage{xparse}
% Counters
\newcounter{qikexample}
\NewDocumentEnvironment{qikexample}{ O{} } % Optional Title, appears in List of Examples
{
\colorlet{colexam}{gray}
\newtcolorbox[use counter=qikexample,]{qikexamplebox}{%
% Example Frame Start
empty,% Empty previously set parameters
title={Example: #1},% use \thetcbcounter to access the qikexample counter text
% Attaching a box requires an overlay
attach boxed title to top left,
% (boxed title style requires an overlay)
boxed title style={empty,size=minimal,toprule=0pt,top=4pt,overlay={}},
coltitle=colexam,fonttitle=\bfseries,
before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=0pt,right=3mm,top=2pt,breakable,pad at break=0mm,
before upper=\csname @totalleftmargin\endcsname0pt, % Use instead of parbox=true. This ensures parskip is inherited by box.
% Handles box when it exists on one page only
overlay unbroken={\draw[colexam,line width=.5pt] ([xshift=-10pt]title.north west) -- ([xshift=-10pt]frame.south west); },
% Handles multipage box: first page
overlay first={\draw[colexam,line width=.5pt] ([xshift=-10pt]title.north west) -- ([xshift=-10pt]frame.south west); },
% Handles multipage box: middle page
overlay middle={\draw[colexam,line width=.5pt] ([xshift=-10pt]frame.north west) -- ([xshift=-10pt]frame.south west); },
% Handles multipage box: last page
overlay last={\draw[colexam,line width=.5pt] ([xshift=-10pt]frame.north west) -- ([xshift=-10pt]frame.south west); },%
}
\begin{qikexamplebox}}
{\end{qikexamplebox}\endlist}
\begin{document}
%\listofexamples
\begin{qikexample}[List Contents of Directory in Unix]
ls
\end{qikexample}
\end{document}

\usepackage[most]{tcolorbox}would help – Nov 03 '15 at 11:45\newtcolorbox: You might use\DeclareTColorBoxand benefit from thexparsesyntax there too! – Nov 03 '15 at 12:06\DeclareTColorBox. – Jonathan Komar Nov 12 '15 at 09:18