#113 ✓resolved
emime

Section numbering option in to_latex

Reported by emime | March 3rd, 2009 @ 11:19 AM

Hello,

Latex supports numbered and unnumbered sections, but to_latex use only unnumbered (that is section* environment).

I would like to add an option to enable section numbering.

What I did to make the thing works...

In textile_doc.rb I added the following attribute:


attr_accessor :latex_numbering

Then in latex.rb I edited the things as follows (starts from line 26):


# headers
  { :h1 => (:latex_numbering) ? 'section' : 'section*',
    :h2 => (:latex_numbering) ? 'subsection' : 'subsection*',
    :h3 => (:latex_numbering) ? 'subsubsection' : 'subsection*',
...

Then, in my test.rb what I need to do is only to set the option as follows:


latex = RedCloth.new(mytextile,[:latex_numbering]).to_latex.to_s

Is it the right way to manage new options? I would like to submit a patch about.

Thanks a lot, Emi

Comments and changes to this ticket

  • emime

    emime March 4th, 2009 @ 02:57 AM

    Hello, I'm sorry...but really the code does not work...

    Actually, with the code above, the to_latex method uses always section (without underscore).

    I tried also this: @@@ doctt = RedCloth.new(mytextile) doctt.latex_numbering = false latex = doctt.to_latex.to_s@@@

    I guess something is wrong ...don't know wath...please help.

    Emi

  • emime

    emime March 4th, 2009 @ 05:29 AM

    Hello, be patient, I told I'm newbie...

    Here a possible solution (that works!!)...I need to check the latex_numbering attribute during the headers definition as follows:

    
    # headers
      { :h1 => 'section*',
        :h2 => 'subsection*',
        :h3 => 'subsubsection*',
        :h4 => 'textbf',
        :h5 => 'textbf',
        :h6 => 'textbf',
      }.each do |m,tag| 
        define_method(m) do |opts|
        #check numbering option
        if latex_numbering then tag=tag.delete('*') end
        "\\#{tag}{#{opts[:text]}}\n\n" 
        end 
      end 
    

    Now the following will work correctly:

    
    latex = RedCloth.new(textile)
    latex.latex_numbering = false
    latex = latex.to_latex.to_s
    

    I don't know if it's the right way...but works

  • Bil Kleb

    Bil Kleb March 6th, 2009 @ 05:49 AM

    I would vote to avoid using the starred versions altogether and let the surrounding LaTeX environment control section numbering via LaTeX's secnumdepth counter, e.g., \setcounter{secnumdepth}{-1} will turn off all section numbering whereas \setcounter{secnumdepth}{2} (LaTeX's default) will only number down to level 2 headings (subsections).

  • Bil Kleb

    Bil Kleb March 6th, 2009 @ 05:50 AM

    • Title changed from “Equation numbering option in to_latex” to “Section numbering option in to_latex”

    To align title with contents, renamed "Equation numbering" to "Section numbering".

  • emime

    emime March 6th, 2009 @ 07:00 AM

    I would vote to avoid using the starred versions altogether

    You are true. \setcounter can be placed in the preamble file and this way numbering is left to a document 'design' decision.

    I complain also about h4, h5 and so....why use \textbf?

    Finally, we can use the following:

    
    # headers
      { :h1 => 'section',
        :h2 => 'subsection',
        :h3 => 'subsubsection',
        :h4 => 'paragraph',
        :h5 => 'subparapgraph',
        :h6 => 'textbf',
      }.each do |m,tag| 
        define_method(m) do |opts|
        "\\#{tag}{#{opts[:text]}}\n\n" 
        end 
      end 
    

    To align title with contents ops...

  • Bil Kleb

    Bil Kleb March 6th, 2009 @ 07:18 AM

    That was actually my first commit to my fork, viz,

    http://github.com/kleb/redcloth/...

    I've sent a pull request to jgarber.

  • Bil Kleb

    Bil Kleb March 7th, 2009 @ 05:47 AM

    • Assigned user changed from “Jason Garber” to “Bil Kleb”
    • State changed from “new” to “resolved”
  • emime

    emime March 9th, 2009 @ 07:13 AM

    I see from the code that "the starred way" was left. Is this compatible with secnumdepth counter? Otherwise please remove the stars.

    Cheers Emi

  • Bil Kleb
  • emime

    emime March 9th, 2009 @ 08:10 AM

    I followed the link before...this latest one shows me the correct code.

    Thanks Emi

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

RedCloth is a Ruby library for converting Textile into HTML

Shared Ticket Bins

People watching this ticket

Tags

Pages