I want to showcase in Section Intro, a listing that appears in Section Listings. So I created macro to that effect, \ShowCase, meant to be expanded in both sections. But that causes an error. Looking up ahead, the issue of the counter will also have to be addressed. I know I could override the counter, but perhaps there is a solution that is closer to the notion of duplication (no side effect).
PS: Subsidiary question: how do I list the listings' headers? (see try in the code)
\documentclass[full]{l3doc}
\usepackage{mwe}
\usepackage{tcolorbox}
\usepackage{xparse}
\tcbuselibrary{listings, breakable}
\newtcblisting[auto counter]
{listing}[2][]
{
noparskip,
breakable,
colback=white,
colframe=black,
opacitybacktitle=.8,%
fonttitle=\bfseries,
title=Listing~\thetcbcounter. #1,
arc=0pt,
outer arc=0pt,
boxrule=0pt,
#2
}
%\NewDocumentCommand{\ShowCase}
%{}
\def\ShowCase
{
\begin{listing}[Bar]
% {label=bar,listing only}
{label=bar}
\lipsum[2]
\end{listing}
}
\begin{document}
%\tcblistof{listing}{Listings} % I just want the listings's headers, this show its contents.
\section{Intro}\label{intro}
My favorite Listing has number~\autoref{bar}, here it is:
\ShowCase % ERROR
Youll findit again under \autoref{bar}
\section{Listings}\label{listings}
\begin{listing}[Foo]
% {label=foo,listing only}
{label=foo}
\lipsum[1]
\end{listing}
%\ShowCase % ERROR
\end{document}