# How to execute \LTXexample repeatitively with a looping macro such that its counter value gets rendered in both input/output parts?

The following code is the simplified version of my real scenario. It might look trivial.

I forgot to say that the following code is the Minimal Not Working Example (MNWE):

\documentclass{article}
\usepackage{showexpl}
\usepackage{graphicx}

\begin{document}
\newcount\counter
\counter=-1
\loop
\advance \counter by 1
\ifnum\counter<5
\LTXexample
\scalebox{\counter}{\counter}
\endLTXexample
\newpage
\repeat
\end{document}


When \counter=1, for example, I want the input part (source part) to get rendered as

\scalebox{1}{1}


rather than

\scalebox{\counter}{\counter}


.

Error messages when it is compiled with pdflatex, latex, xelatex:

(c:/texlive/2010/texmf-dist/tex/latex/listings/lstmisc.sty)

Package Listings Warning: Text dropped after begin of listing on input line 21.

(c:/texlive/2010/texmf-dist/tex/latex/base/omscmr.fd))
*
! Emergency stop.
<*> counterlistings

!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on counterlistings.log.


How to execute \LTXexample repeatitively with a looping macro such that its counter value gets rendered in both input/output parts?

-
About the MNWE: Note that all MWE (of questions, not answers) should "not work", so they can show the issue. –  Martin Scharrer Aug 11 '11 at 21:19
add comment

## 1 Answer

The issue here is that \loop reads everything till \repeat as argument and therefore doesn't allow verbatim environments like LTXexample:

\loop:
\long macro:#1\repeat ->\def \iterate {#1\relax \expandafter \iterate \fi }\iterate \let \iterate \relax


You need to look for a different way to loop over it. Note that showexpl uses listings which allows for escape characters. You could use these to escape around the counter value and have \number\counter there. This should write the number to the temp file.

-
Only the first two lines of your answer are understandable. The remaining ones are difficult to understand even I read multiple times. :-) –  xport Aug 11 '11 at 21:43
Simply open the listings manual and search for escape! :-) Anyway, this doesn't work for write-to-file listings. They escape characters are then ignored :-( –  Martin Scharrer Aug 11 '11 at 21:45
OK. I read the manual until page 24 yesterday. I will continue the remaining later. I will decide whether or not I should execute the green mark on this answer later after grasping the knowledge. :-) –  xport Aug 11 '11 at 22:01
add comment