On 2009-05-15, obregonma...@gmail.com wrote:
> On Friday 15 May 2009, Helge Hafting wrote:
>> obregonma...@gmail.com 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:
>> > 
>> > Counter experimentCounter
>> >    LabelString      "\Roman{experimentCounter}"
>> >    Within           ""     
>> > End
>> > 
>> > Now, what I want is a section heading  that would look like:
>> > 
>> > 3.2    <label expt:reading-ability> Experiment I: Effect of reading ability
>> > 
>> > and then later on:
>> > 
>> > 3.6   <label expt:age-predictor> Experiment II: Age as a predictor
>> > 
>> > and then ...
>> > 
>> > 4.2   <label expt:reading-aids> Experiment III: Reading aids
>> > 
>> > 
>> > 
>> > How can I use my "experimentCounter" in a section title, as well as
>> > assign a label to this experiment item (NOT the section number)? I
>> > imagine that it would require an ERT ... but with what LaTeX
>> > command? 


>> Basically, you create a new "experiment-section" [...] And then you add
>> the necessary latex code, once. Instead of having to add it as ERT to
>> every experiment in your text.

> I can get LyX to display a modified section very nicely, but I cannot
> get latex to show me a modified experiment-section.

...

> I am at a loss for the latex commands. I don't want to start learning
> the complexities of LaTeX macro writings just to modify a section
> title. 

In this case you might consider typing the Experiment number by hand...

> I simply want something like this, so that I have both the normal
> section counter and my special experimentCounter counter:

> Counter experimentCounter
>       LabelString      "\Roman{experimentCounter}"
>       Within           ""     
> End

This sets up the Counter for LyX only, you need to set up a LaTex
counter as well.

AddToPreamble
        \newcounter{experiment}
        \setcounter{experiment}{0}
EndPreamble


> Style Experiment
>         CopyStyle             Section
>       LatexName             experiment-section
>         LabelType             Counter
>         LabelString           "Experiment \theexperimentCounter."
>         LabelCounter        section, experimentCounter
>       Font
>               Series  Italic
>               Size    Large
>       EndFont
>         Preamble
>               \newcommand{\experiment-section}[1]{%
>                       \section{Experiment \theexperimentCounter. #1}}
>       EndPreamble
> End

> But, latex gives errors that I don't understand.

But only if you post them here, we can help!

1. LaTeX macro names with hyphens are not strictly forbidden but only
   accessible with the \csname ... \endcsname construct.
   
   Use e.g. \experimentSection
   
2. As already said, you need to set up the counter for LaTeX as well.

3. You need to increment the counter in LaTeX
   
4. You need to convert the counter to Roman in LaTeX

Maybe this works, but it is untested:
 
 \newcommand{\experimentSection}[1]{%
    \stepcounter{experiment}
    \section{Experiment \Roman{experiment}. #1}%
 }
   
Günter

Reply via email to