Class: Deplate::Formatter::LaTeX

Inherits:
Object
  • Object
show all
Defined in:
lib/deplate/mod/koma.rb,
lib/deplate/zh_CN.rb,
lib/deplate/mod/endnotes.rb,
lib/deplate/mod/latex-styles.rb,
lib/deplate/mod/lang-zh_CN-autospace.rb,
lib/deplate/mod/latex-verbatim-small.rb,
lib/deplate/mod/latex-emph-table-head.rb

Overview

latex-emph-table-head.rb @Author: Thomas Link (micathom AT gmail com) @Website: deplate.sf.net/ @License: GPL (see www.gnu.org/licenses/gpl.txt) @Created: 26-Nov-2004. @Revision: 0.39

Description:

Usage:

TODO:

CHANGES:

Direct Known Subclasses

LaTeX_Dramatist, LaTeX_Snippet

Defined Under Namespace

Classes: Styles

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.style_classesObject

Returns the value of attribute style_classes.



412
413
414
# File 'lib/deplate/mod/latex-styles.rb', line 412

def style_classes
  @style_classes
end

Instance Method Details



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/deplate/mod/koma.rb', line 83

def format_footer(invoker)
    type = invoker.doc_type(:pre)
    slot = invoker.doc_slot(:body_pre)
    unless @deplate.variables['__pagestyle_initialized']
        add_package("scrpage2")
        type, cslot, slot = format_header_or_footer_slots(type, slot)
        output_at(type, cslot, "", %{\\clearscrheadfoot{}})
        output_at(type, slot, %{\\pagestyle{scrheadings}}, "")
        @deplate.variables['__pagestyle_initialized'] = true
    end
    format_header_or_footer(invoker, "ifoot", "cfoot", "ofoot", "setfootsepline")
end

#format_header(invoker) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/deplate/mod/koma.rb', line 70

def format_header(invoker)
    type = invoker.doc_type(:pre)
    slot = invoker.doc_slot(:body_pre)
    unless @deplate.variables['__pagestyle_initialized']
        add_package("scrpage2")
        type, cslot, slot = format_header_or_footer_slots(type, slot)
        output_at(type, cslot, "", %{\\clearscrheadfoot{}})
        output_at(type, slot, %{\\pagestyle{scrheadings}}, "")
        @deplate.variables['__pagestyle_initialized'] = true
    end
    format_header_or_footer(invoker, "ihead", "chead", "ohead", "setheadsepline")
end

def hook_pre_prepare_koma

push_class_option('tablecaptionabove')

end



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/deplate/mod/koma.rb', line 25

def format_header_or_footer(invoker, left, center, right, linesep=nil)
    args = invoker.args
    elt = invoker.elt
    if elt.size > 1
        format_header_or_footer_error(elt)
    end
    catch :error do
        e = elt[0]
        if e.kind_of?(Deplate::Element::Paragraph)
            l = c = r = nil
            ee = wrap_text(e.elt)
            if args["center"]
                c = ee
            elsif args["right"]
                r = ee
            else
                l = ee
            end
        elsif e.kind_of?(Deplate::Element::Table)
            log("Only the header's first row will be used", :error) if e.elt.size > 1
            l, c, r = e.elt[0].cols.collect {|c| c.cell}
        else
            format_header_or_footer_error(elt)
        end

        output(invoker, "\\%s{%s}" % [left, l])   if l and !l.empty?
        output(invoker, "\\%s{%s}" % [center, c]) if c and !c.empty?
        output(invoker, "\\%s{%s}" % [right, r])  if r and !r.empty?
        ls = args["linesep"] || args["sep"]
        if ls
            if ls == true
                ls = "0.4pt"
            elsif ls =~ /^[0-9.]+$/
                ls = "%dpt" % ls
            end
            output(invoker, "\\%s{%s}" % [linesep, ls])
        end
    end
end


65
66
67
68
# File 'lib/deplate/mod/koma.rb', line 65

def format_header_or_footer_error(elt)
    elts = "%s %s" % [elt.size, elt.collect {|e| e.class}.join(", ")]
    log(["Header must contain only 1 element (a paragraph or a table)", elts], :error)
end


96
97
98
99
100
101
102
# File 'lib/deplate/mod/koma.rb', line 96

def format_header_or_footer_slots(type, slot)
    if slot == :body_pre and type == :pre
        return [type, :prematter_end, slot]
    else
        return [type, slot, slot]
    end
end

#format_list_of_endnotes(invoker) ⇒ Object Also known as: format_list_of_footnotes



26
27
28
29
30
31
# File 'lib/deplate/mod/endnotes.rb', line 26

def format_list_of_endnotes(invoker)
    join_blocks(["\\newpage", "\\begingroup", 
                "\\parindent 0pt", "\\parskip 2ex", 
                "\\def\\enotesize{\\normalsize}", "\\theendnotes", 
                "\\endgroup"])
end

#format_pagenumber(invoker) ⇒ Object



104
105
106
# File 'lib/deplate/mod/koma.rb', line 104

def format_pagenumber(invoker)
    return "\\pagemark{}"
end

#formatter_initialize_latex_emph_table_headObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/deplate/mod/latex-emph-table-head.rb', line 19

def formatter_initialize_latex_emph_table_head
    def_advice("latex-emph-table-head", :table_end_head,
              :wrap => Proc.new do |agent, rv, invoker, nth|
                "#{rv}\n    #{table_horizontal_ruler_from_to(invoker)}"
              end 
             )
    def_advice("latex-emph-table-head", :table_cell,
              :wrap => Proc.new do |agent, rv, invoker, cell, *args|
                hirow = args[0]
                hd = (hirow || cell.head || cell.foot || cell.high)
                if hd
                    format_particle(:format_emphasize, invoker, rv)
                else
                    rv
                end
              end 
             )
end

#formatter_initialize_latex_stylesObject



415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/deplate/mod/latex-styles.rb', line 415

def formatter_initialize_latex_styles
    @style_engines = {
        :default => Deplate::Formatter::LaTeX::Styles.new(@deplate),
    }
    @format_advice_backlist += [:format_table]

    table_agents = [
        :format_table, :table_args, 
        :table_bottom, :table_caption, :table_caption_text, :table_cell, :table_cols, 
        :table_begin_head, :table_end_head, :table_head_row, 
        :table_begin_foot, :table_end_foot, :table_foot_row, 
        :table_begin_body, :table_end_body, :table_high_row, :table_normal_row,
        :table_horizontal_ruler, :table_horizontal_ruler_from_to,
        :table_longtable_top, :table_longtable_bottom, 
        :table_table_bottom, :table_table_top, :table_top,
        :table_tabular_top, :table_tabular_bottom,
        :tabular_col_widths, :tabular_col_justifications, :tabular_vertical_rulers,
        :table_indented_row,
    ]
    for agent in table_agents
        advice = Proc.new do |agent, rv, invoker, *args|
            styles = []
            stylex_arg = invoker.args["stylex"]
            if stylex_arg
                styles += Deplate::Core.split_list(stylex_arg, ',', ';')
            else
                style_arg = invoker.args["style"]
                styles += Deplate::Core.split_list(style_arg, ',', ';') if style_arg
                style_var = @deplate.variables["tableStyle"]
                styles += Deplate::Core.split_list(style_var, ',', ';') if style_var
            end
            styles.compact!
            style_arg = invoker.args["style"]
            for style in styles
                styler = @style_engines[style] || setup_styler(style)
                if styler
                    style_arg.delete(style) if style_arg
                    rv = styler.send(agent, rv, invoker, *args)
                end
            end
            rv
        end
        def_advice("latex-styles", agent, :wrap => advice)
    end
end

#formatter_initialize_latex_verbatim_smallObject



19
20
21
22
23
24
25
26
27
# File 'lib/deplate/mod/latex-verbatim-small.rb', line 19

def formatter_initialize_latex_verbatim_small
    def_advice("latex-verbatim-small", :format_verbatim,
              :wrap => Proc.new do |agent, rv, *rest|
                join_blocks(["{\\" + (@variables["verbSize"] || "footnotesize{}"),
                            rv, 
                            "}"])
              end 
             )
end

#hook_pre_setup_zh_cn_autospaceObject



20
21
22
23
# File 'lib/deplate/mod/lang-zh_CN-autospace.rb', line 20

def hook_pre_setup_zh_cn_autospace
    @cjk_space   = '~'
    @cjk_nospace = ' '
end

#prepare_endnotesObject



17
18
19
20
21
22
23
24
# File 'lib/deplate/mod/endnotes.rb', line 17

def prepare_endnotes
    output_at(:pre, :mod_packages, "\\usepackage{endnotes}")
    notes = plain_text(@deplate.msg("Notes"))
    if notes != "Notes"
        output_at(:pre, :mod_head, "\\renewcommand{\\notesname}{#{notes}}")
    end
    output_at(:pre, :mod_head, "\\let\\footnote=\\endnote")
end

#prepare_zh_cnObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/deplate/zh_CN.rb', line 21

def prepare_zh_cn
    family   = @deplate.variables['cjk_family']   || 'gbsn'
    encoding = @deplate.variables['cjk_encoding'] || 'GB'
    union_at(:pre, :mod_packages, '\\usepackage{CJK}')
    union_at(:pre, :mod_packages, '\\usepackage{CJKnumb}')
    union_at(:pre, :mod_packages, '\\usepackage{indentfirst}')
    output_at(:pre, :body_beg, "\\begin{CJK*}{#{encoding}}{#{family}}", 
                    '\\CJKtilde{}', '\\CJKcaption{GB}', '\\CJKindent{}')
    output_at(:post, :prepend_body_end, '\\end{CJK*}')
end

#set_document_encodingObject



32
33
# File 'lib/deplate/zh_CN.rb', line 32

def set_document_encoding
end

#setup_styler(style) ⇒ Object



461
462
463
464
465
466
467
468
469
470
471
# File 'lib/deplate/mod/latex-styles.rb', line 461

def setup_styler(style)
    # <+TBD+> load module or style definition on-demand
    c = self.class.style_classes[style]
    if c
        @style_engines[style] = styler = c.new(@deplate)
        return styler
    else
        log(["Unknown style", style], :error)
        @style_engines[:default]
    end
end