On 2009-05-18, Helge Hafting wrote:
> [email protected] wrote:
>> On Friday 15 May 2009, [email protected] wrote:
>>>>>>> I want to have a counter (experiment) that uses roman numerals and
>>>>>>> is sequential throughout the chapters. I figure that a module is the
>>>>>>> right way about this, so I have a module with the following counter:
> Yes. You have to use refstepcounter inside your \experimentSection
> command. This increments the counter for you, and also sets the
> reference string so that the next label will get the experiment number
> instead of the section number. Note that \refstepcounter won't work
> inside a \section command though. (latex limitation)
> The whole module looks like this:
...
It can be slightly simplified:
#\DeclareLyXModule{testexperiment}
#This is a test!
AddToPreamble
\newcounter{experiment}\setcounter{experiment}{1}
\renewcommand{\theexperiment}{\textit{\Roman{experiment}}}
EndPreamble
## A new section style, for the correct printing of the experiment title
that also looks nice on the screen:
Style Experiment
CopyStyle Section
LatexName experimentSection
LabelType Counter
LabelString "\thesection Experiment\theexperiment."
LabelCounter section
OptionalArgs 1
Font
Shape Italic
Size Large
EndFont
Preamble
\newcommand{\experimentSection}[1]{%
\section{\textit{Experiment \theexperiment. #1}}
\refstepcounter{experiment}
}
EndPreamble
End
> And we also have to use \stepcounter _before_ the section,
> so that the printed number won't be one too low.
...
> I know of no way to set the reference string _without_ also incrementing
> the counter. Such a command would make things simpler, but I don't think
> it exists.
I just start the counter wiht 1 instead of 0, so it is correct
*before* \refstepcounter is applied.
...
> if you insert a label in the text following an experiment line, then any
> cross reference to that label will print the roman numeral for the
> experiment.
> If you put a label inside the experiment line itself, then cross
> references to that internal label will print the experiment's section
> number. So be careful how you place your labels!
Günter