m***@hio.no
2007-07-03 07:38:46 UTC
Hello
The problem pointed at below is actually a LaTeX issue, not a Listings
one.
Still, I meet it within a Listings lstenvironment context, and choose
to describe it this way, as maybe a workaround can be found through
Listings.
I am building some lstenvironments, for which I would like the
captions to be augmented and formatted automatically, by a macro,
\eksempel.
\eksempel is defined with \newcommand{\eksempel}{....} (See below).
Here is an example environment: (see line with %!!!! below)
--------------------------------------------------------------------------
\lstnewenvironment{barephp}[2]{%
\lstset{
label=#1,
language=php,
caption=\eksempel{#2}, %!!!!
float=h,
}
} {}
----------------------------------------------------------------------------
Here is the definition of \eksempel (\eksempel works fine on its
own):
---------------------------------------------------------------
% define a counter first
\newcounter{eksemp}[chapter]
\renewcommand{\theeksemp}{\thechapter.\Alph{eksemp}}
\newcommand{\eksempel}[1]{
\refstepcounter{eksemp}
\emph{\textbf{Eksempel \theeksemp:} #1}
}
----------------------------------------------------------------
\eksempel works fine when called on its own. \eksempel{some text}.
So does
\begin{barephp}{some label}{some text}
when
caption=#2.
But when
caption=\eksempel{#2},
as in %!!!!! above, I get the error message:
--------------------------------------------------------------------
! Missing \endcsname inserted.
<to be read again>
\csname\endcsname
l.172 \begin{barephp}{some label}{some text}
----------------------------------------------------------------------
Is there any workaround
here?
Thanks
...
Michael
The problem pointed at below is actually a LaTeX issue, not a Listings
one.
Still, I meet it within a Listings lstenvironment context, and choose
to describe it this way, as maybe a workaround can be found through
Listings.
I am building some lstenvironments, for which I would like the
captions to be augmented and formatted automatically, by a macro,
\eksempel.
\eksempel is defined with \newcommand{\eksempel}{....} (See below).
Here is an example environment: (see line with %!!!! below)
--------------------------------------------------------------------------
\lstnewenvironment{barephp}[2]{%
\lstset{
label=#1,
language=php,
caption=\eksempel{#2}, %!!!!
float=h,
}
} {}
----------------------------------------------------------------------------
Here is the definition of \eksempel (\eksempel works fine on its
own):
---------------------------------------------------------------
% define a counter first
\newcounter{eksemp}[chapter]
\renewcommand{\theeksemp}{\thechapter.\Alph{eksemp}}
\newcommand{\eksempel}[1]{
\refstepcounter{eksemp}
\emph{\textbf{Eksempel \theeksemp:} #1}
}
----------------------------------------------------------------
\eksempel works fine when called on its own. \eksempel{some text}.
So does
\begin{barephp}{some label}{some text}
when
caption=#2.
But when
caption=\eksempel{#2},
as in %!!!!! above, I get the error message:
--------------------------------------------------------------------
! Missing \endcsname inserted.
<to be read again>
\csname\endcsname
l.172 \begin{barephp}{some label}{some text}
----------------------------------------------------------------------
Is there any workaround
here?
Thanks
...
Michael