I've got an environment CodeScrap that Lyx treats as a list environment. Each list item is a literate programming chunk, and the list item name is the chunk name. I will be using the listings package to format the latex output; so I start like this: (Please don't comment on the needless \startCodeScrap and so forth, it's just till I get it working).

\long\def\startCodeScrap{

\def\nfitem{\item}

\def\item##1[##2]{

\begin{lstlisting}[name=##2]

}

}

\newenvironment{CodeScrap}{\startCodeScrap}{

%\end{lstlisting}

\def\item\nfitem}


So I re-define item during a CodeScrap environment, so that it starts a lstlisting. That works fine; but of course lstlisting is looking for a literal \end{lstlisting} I think and there isn't one... now another \item or \end{CodeScrap}will occur instead.


I think my \def\item might need to be \long\def\item and maybe have a 3rd parameter which ends with \item or \end{CodeScrap} (which will be hard enough, probably I'll have to do the third parameter ending on a \ and then do tail recursion to pull some more if the next symbol isn't \item or \end [won't someone write a yacc for tex?)


But I see that I still need to inject the \end{lstlisting} somewhere. I try to fake it by way of experiment:

\long\def\startCodeScrap{

\def\nfitem{\item}

\def\item##1[##2]##3\end{

{\begin{lstlisting}[name=##2]##3}

{\endlstlisting}

HELLO ##3

\end

}

}


But not only does it not work, it's fetching the tokens not in the same mode as listings works, and eating my { } and so forth.I realise then that if I am going to fetch

ahead to the next item with ##3 and such that I need to mess about with catcodes too...


So before I go too far, any advice for me?


(I also realise that my 2nd \item will have to close the lstlisting of the previous item and so on)

Sam

Reply via email to