Class: Deplate::Formatter::LaTeX_Dramatist

Inherits:
LaTeX
  • Object
show all
Defined in:
lib/deplate/fmt/latex-dramatist.rb

Instance Method Summary collapse

Methods inherited from LaTeX

#format_footer, #format_header, #format_header_or_footer, #format_header_or_footer_error, #format_header_or_footer_slots, #format_list_of_endnotes, #format_pagenumber, #formatter_initialize_latex_emph_table_head, #formatter_initialize_latex_styles, #formatter_initialize_latex_verbatim_small, #hook_pre_setup_zh_cn_autospace, #prepare_endnotes, #prepare_zh_cn, #set_document_encoding, #setup_styler

Instance Method Details

#format_ACT(invoker) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/deplate/fmt/latex-dramatist.rb', line 71

def format_ACT(invoker)
    elt = invoker.elt
    if elt.empty?
        return '\\act{}'
    else
        return '\\Act{%s}' % elt
    end
end

#format_CAST(invoker) ⇒ Object



66
67
68
# File 'lib/deplate/fmt/latex-dramatist.rb', line 66

def format_CAST(invoker)
    return '\\DramPer{}'
end

#format_direct(invoker, text = nil) ⇒ Object

Stage direction direct…



171
172
173
# File 'lib/deplate/fmt/latex-dramatist.rb', line 171

def format_direct(invoker, text=nil)
    "\\direct{%s}" % (text || invoker.elt || invoker.text)
end

#format_heading(invoker, level = nil, elt = nil, args = nil) ⇒ Object

+++



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/deplate/fmt/latex-dramatist.rb', line 39

def format_heading(invoker, level=nil, elt=nil, args=nil)
    # elt ||= invoker.elt
    # if elt.empty?
        args  ||= invoker.args
        level ||= invoker.level
        hd     = @headings0[level - 1]
        mod    = heading_mod(args)
        cap    = heading_caption(invoker)
        labels = invoker && format_label(invoker, :string)
        join_blocks(["\n\\#{hd}#{mod}#{cap}{}", labels])
    # else
    #     super
    # end
end

#format_list_env(invoker, type, level, what, subtype = nil) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/deplate/fmt/latex-dramatist.rb', line 140

def format_list_env(invoker, type, level, what, subtype=nil)
    indent = format_indent(level)
    if is_cast?(invoker)
        return ''
    else
        case what
        when :open
            w    = "begin"
            if list_wide?
                pre  = "\n#{indent}"
                post = "\n"
            else
                pre  = indent
                post = ""
            end
        when :close
            w    = "end"
            pre  = indent
            post = ""
        end
        if level == 0 and type == 'Description' and !invoker.args['plain']
            "#{pre}\\#{w}{drama}#{post}"
        else
            ''
        end
    end
end

#format_list_item(invoker, type, level, item, args = {}) ⇒ Object

  • Unordered -> stage directions or cast group

  • Descriptions -> dialog or cast

Cast list: CharacterNamename beginCharacterGroupNAME GCharacterNamename … endCharacterGroup DramPer

Dialog: namespeaks direct… …



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/deplate/fmt/latex-dramatist.rb', line 93

def format_list_item(invoker, type, level, item, args={})
    indent = format_indent(level, true)
    ctag   = list_wide? ? '' : :empty
    explv  = list_item_explicit_value(item)
    if explv
        explv = %{[#{explv}]}
    end
    case type
    when 'Itemize'
        if is_cast?(invoker)
            return wrap_text("#{indent}\\begin{CharacterGroup}{#{item.body}}", :indent => "  "), "#{indent}\\end{CharacterGroup}"
        else
            return wrap_text("#{indent}\\StageDir{#{item.body}}", :indent => "  "), ctag
        end
    when 'Description'
        if is_cast?(invoker)
            full_name    = [item.item.upcase, item.body].compact.join(', ')
            display_name = item.item
            tex_name     = speaker(item.item)
            if level > 1
                char = '%s\\GCharacter{%s}{%s}{%s}'
                full_name << ','
            else
                char = '%s\\Character[%s]{%s}{%s}'
                full_name << '.'
            end
            return wrap_text(char % [indent, full_name, display_name, tex_name], :indent => "  "), ctag
        else
            speaker = item.item.sub(/^(\S+)/) {|t| speaker($1) + 'speaks'}
            return wrap_text("#{indent}\\#{speaker} #{item.body}", :indent => "  "), ctag
        end
    else
        super
    end
end

#format_paragraph(invoker) ⇒ Object

Open stage directions. StageDir…



57
58
59
60
61
62
63
# File 'lib/deplate/fmt/latex-dramatist.rb', line 57

def format_paragraph(invoker)
    if invoker.args['plain']
        super
    else
        join_blocks([wrap_text("\\StageDir{%s}" % invoker.elt), ""])
    end
end

#formatter_initialize_dramatistObject



24
25
26
# File 'lib/deplate/fmt/latex-dramatist.rb', line 24

def formatter_initialize_dramatist
    @ignored_styles << /^play/
end

#is_cast?(invoker) ⇒ Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/deplate/fmt/latex-dramatist.rb', line 130

def is_cast?(invoker)
    return invoker.args['cast'] || invoker.tagged_as?('cast')
end

#prepare_dramatistObject



33
34
35
36
# File 'lib/deplate/fmt/latex-dramatist.rb', line 33

def prepare_dramatist
    add_package('dramatist')
    # output_at(:pre, :body_beg, %{\\pagestyle{myheadings}})
end

#prepare_headingsObject



28
29
30
31
# File 'lib/deplate/fmt/latex-dramatist.rb', line 28

def prepare_headings
    @headings  = ['Scene']
    @headings0 = ['scene']
end

#speaker(name) ⇒ Object



135
136
137
# File 'lib/deplate/fmt/latex-dramatist.rb', line 135

def speaker(name)
    name.downcase
end