Class: Deplate::Formatter
- Inherits:
-
CommonObject
- Object
- CommonObject
- Deplate::Formatter
- Defined in:
- lib/deplate/mod/utf8.rb,
lib/deplate/zh_CN.rb,
lib/deplate/zh_CN.rb,
lib/deplate/formatter.rb,
lib/deplate/mod/iconv.rb,
lib/deplate/mod/encode.rb,
lib/deplate/mod/recode.rb,
lib/deplate/mod/numpara.rb,
lib/deplate/mod/endnotes.rb,
lib/deplate/mod/pstoedit.rb,
lib/deplate/mod/entities-encode.rb,
lib/deplate/mod/inlatex-compound.rb,
lib/deplate/mod/mark-external-urls.rb,
lib/deplate/mod/lang-zh_CN-autospace.rb,
lib/deplate/mod/html-highstep.rb
Overview
mark-urls.rb @Author: Thomas Link (micathom AT gmail com) @Website: deplate.sf.net/ @License: GPL (see www.gnu.org/licenses/gpl.txt) @Created: 16-Nov-2004. @Revision: 0.43
Description:
Usage:
TODO:
CHANGES:
Defined Under Namespace
Classes: DbkSlides, DbkSnippet, HTML, HTML_Site, HTML_Snippet, LaTeX, LaTeX_Dramatist, LaTeX_Snippet, Sweave, XHTML10transitional, XHTML11m
Constant Summary collapse
- INLATEX_RX =
Regexp.new(rx.join('|'))
- @@custom_particles =
{}
Instance Attribute Summary collapse
-
#advices ⇒ Object
readonly
Returns the value of attribute advices.
-
#bibentries ⇒ Object
Returns the value of attribute bibentries.
-
#cjk_nospace ⇒ Object
readonly
Returns the value of attribute cjk_nospace.
-
#cjk_smart_blanks ⇒ Object
readonly
Returns the value of attribute cjk_smart_blanks.
-
#cjk_space ⇒ Object
readonly
Returns the value of attribute cjk_space.
-
#deplate ⇒ Object
readonly
Returns the value of attribute deplate.
-
#doc_services ⇒ Object
A hash holding all known document services (names => method).
-
#entities_table ⇒ Object
readonly
Returns the value of attribute entities_table.
-
#expander ⇒ Object
readonly
Returns the value of attribute expander.
-
#special_symbols ⇒ Object
Returns the value of attribute special_symbols.
Class Method Summary collapse
-
.def_service(name, &block) ⇒ Object
<
TBD
>Shouldn’t services belong to the formatter?. - .formatter_family_members(args = {}) ⇒ Object
- .formatter_related?(name) ⇒ Boolean
- .hook_post_myname=(name) ⇒ Object
- .noop(context, name) ⇒ Object
- .set_options_for_file(options, file = nil) ⇒ Object
Instance Method Summary collapse
- #bare_latex_formula(text) ⇒ Object
- #bib_entry(key) ⇒ Object
- #canonic_enc_name(enc, table = @encodings) ⇒ Object
-
#canonic_encoding(default = nil, table = {}) ⇒ Object
def canonic_encoding(default=nil, table=@encodings).
- #canonic_image_type(type) ⇒ Object
- #canonic_mime(type) ⇒ Object
- #char_by_name(name) ⇒ Object
- #char_by_number(number) ⇒ Object
- #check_symbol_proxy ⇒ Object
- #close_headings(level, &block) ⇒ Object
- #consumed_ids ⇒ Object
- #consumed_ids=(arg) ⇒ Object
- #consumed_labels ⇒ Object
- #consumed_labels=(arg) ⇒ Object
- #def_advice(applicant, agent, args) ⇒ Object
- #document_encoding(table = @encodings) ⇒ Object
- #doublequote_close(invoker) ⇒ Object
- #doublequote_open(invoker) ⇒ Object
- #dummy(invoker, *args) ⇒ Object
- #dvi2png(invoker, fdvi, fout, other_options = nil) ⇒ Object
- #dvi2ps(invoker, fdvi, fps, other_options = nil) ⇒ Object
- #encode_id(id) ⇒ Object
-
#entities_encode_plain_text ⇒ Object
Properly format
text
as formatter-valid plain text. - #fill_in_template(invoker) ⇒ Object
- #format_ACT(invoker) ⇒ Object
- #format_CAST(invoker) ⇒ Object
- #format_cite(invoker) ⇒ Object
- #format_direct(invoker, text = nil) ⇒ Object
- #format_element(agent, invoker, *args) ⇒ Object
- #format_element_as_string(agent, invoker, *args) ⇒ Object
- #format_GET(invoker) ⇒ Object
- #format_heading_close(invoker) ⇒ Object
- #format_highstep(invoker, txt = nil) ⇒ Object
-
#format_inlatex(invoker) ⇒ Object
Format the Inlatex region.
- #format_LIST(invoker) ⇒ Object
-
#format_ltx(invoker, other_args = {}) ⇒ Object
(also: #format_math)
Format the ltx macro.
- #format_PAGEBREAK(invoker) ⇒ Object
- #format_particle(agent, invoker, *args) ⇒ Object
- #format_particle_as_string(agent, invoker, *args) ⇒ Object
- #format_plain_text(invoker, text = nil, escaped = false) ⇒ Object
- #format_region(invoker) ⇒ Object
-
#format_symbol(invoker, sym) ⇒ Object
def symbol_paragraph(invoker) check_symbol_proxy @symbol_proxy.symbol_paragraph(invoker) end.
- #format_unknown(invoker) ⇒ Object
- #format_unknown_macro(invoker) ⇒ Object
- #format_unknown_particle(invoker) ⇒ Object
- #format_void(invoker, text = nil) ⇒ Object
- #formatted_block(env, text, opts = nil, args = nil, no_id = false, no_indent = false) ⇒ Object
- #formatted_inline(env, text, opts = nil, args = nil, no_id = false) ⇒ Object
- #formatted_single(env, opts = nil, args = nil, no_id = false) ⇒ Object
- #formatter_initialize_mark_urls ⇒ Object
- #formatter_name ⇒ Object
- #formatter_related?(name) ⇒ Boolean
- #formatter_rx ⇒ Object
-
#get_first_char(string, upcase = false) ⇒ Object
Return the first character of string while taking care whether string starts with a multi-byte sequence.
- #get_first_char_re_utf8 ⇒ Object
- #get_first_char_re_zh_cn ⇒ Object
-
#hook_post_go_recode ⇒ Object
def hook_pre_go_recode recode_start end.
- #hook_pre_go_iconv ⇒ Object
- #hook_pre_process_inlatex ⇒ Object
- #hook_pre_setup_zh_cn ⇒ Object
- #hook_pre_setup_zh_cn_autospace ⇒ Object
- #include_image(invoker, file, args, *other_args) ⇒ Object
- #indent_text(text, args = {}) ⇒ Object
-
#initialize(deplate, args = {}) ⇒ Formatter
constructor
A new instance of Formatter.
-
#inlatex(invoker) ⇒ Object
Process inline latex.
- #inlatex_clean(line) ⇒ Object
-
#inlatex_compound ⇒ Object
Process inline latex.
- #inlatex_id(invoker, last = false) ⇒ Object
- #inlatex_process_dvi(invoker, fdvi, fps) ⇒ Object
- #inlatex_process_dvi_png(invoker, fdvi, fout) ⇒ Object
- #inlatex_process_latex(invoker, ftex, faux, flog) ⇒ Object
- #inlatex_process_ps(invoker, device, fps, fout, args) ⇒ Object
-
#inlatex_sfx ⇒ Object
The default suffix/device to be used for inlatex output.
-
#inlatex_split(accum) ⇒ Object
Divert lines in invoker#accum to the preamble or the body.
-
#invoke_service(name, args = {}, text = '') ⇒ Object
Run a “service”, i.e., a small, mostly autonomous function/method that usually yields some formatted output.
- #join_blocks(blocks) ⇒ Object
- #join_inline(strings) ⇒ Object
- #label_delegate ⇒ Object
- #label_mode ⇒ Object
- #label_once ⇒ Object
- #latex2dvi(invoker, ftex, faux, flog) ⇒ Object
- #log(*args) ⇒ Object
- #matches?(text) ⇒ Boolean
- #module_initialize_numpara ⇒ Object
-
#multibyte_leader?(ch) ⇒ Boolean
Check if ch (a number representing a character) is a multi-byte leader.
- #nonbreakingspace(invoker) ⇒ Object
- #numbered_paragraph(text, number) ⇒ Object
- #output(invoker, *body) ⇒ Object
-
#output_at(type, slot, *body) ⇒ Object
def_delegator(:@deplate, :add_at, :output_at).
- #output_destination ⇒ Object
- #output_empty_at?(type, slot) ⇒ Boolean
- #output_preferably_at(invoker, type, slot, *body) ⇒ Object
-
#plain_text(text, escaped = false) ⇒ Object
Properly format
text
as formatter-valid plain text. -
#plain_text_recode(text) ⇒ Object
Recode normal text for #plain_text.
- #pre_process ⇒ Object
- #prelude(name) ⇒ Object
- #prepare ⇒ Object
- #ps2img(invoker, device, fps, fout, args) ⇒ Object
-
#pstoedit_inlatex ⇒ Object
Process inline latex.
- #pstoedit_wrap(invoker, sfx, &block) ⇒ Object
-
#push_class_option(*options) ⇒ Object
push *options to variables.
- #push_linebreak(accum, part, add_blank = true) ⇒ Object
- #read_bib(bibfiles) ⇒ Object
- #recode_start ⇒ Object
- #recode_stop ⇒ Object
- #referenced_bib_entry(invoker, key, text) ⇒ Object
- #reset! ⇒ Object
- #retrieve_particle(id, body = nil, specific = false) ⇒ Object
-
#set_at(type, slot, *body) ⇒ Object
def_delegator(:@deplate, :set_at).
- #setup ⇒ Object
- #setup_endnotes ⇒ Object
- #setup_entities ⇒ Object
- #singlequote_close(invoker) ⇒ Object
- #singlequote_open(invoker) ⇒ Object
-
#sort_index_entries(data) ⇒ Object
Return the alphabethically sorted index data.
- #stepwise_next ⇒ Object
- #stepwise_prepare ⇒ Object
- #store_particle(id, body, particle, specific = false) ⇒ Object
- #suffix ⇒ Object
- #symbol_amp(invoker) ⇒ Object
- #symbol_gt(invoker) ⇒ Object
- #symbol_lt(invoker) ⇒ Object
- #symbol_quote(invoker) ⇒ Object
- #table_empty_cell ⇒ Object
-
#table_row_size(elt) ⇒ Object
Return the maximum row size for the table data in elt.
-
#union_at(type, slot, *body) ⇒ Object
def_delegator(:@deplate, :union_at).
- #with_agent(agent, prototype, invoker, *args) ⇒ Object
-
#wrap_text(text, args = {}) ⇒ Object
Takes an optional block that takes a string as argument and returns true if we shouldn’t wrap the text at this position.
Methods inherited from CommonObject
class_attribute, class_attributes, class_attributes=, class_attributes_ensure, class_meta_attributes, inherited, method_missing, respond_to?
Constructor Details
#initialize(deplate, args = {}) ⇒ Formatter
Returns a new instance of Formatter.
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/deplate/formatter.rb', line 143 def initialize(deplate, args={}) @deplate = deplate @variables = deplate.variables @advices = args[:advices] || {} @doc_services = args[:doc_services] || initialize_services @inlatex_idx = 0 @encodings = {} @symbol_proxy = nil @entities_table = nil @format_advice_backlist = [] reset! end |
Instance Attribute Details
#advices ⇒ Object (readonly)
Returns the value of attribute advices.
135 136 137 |
# File 'lib/deplate/formatter.rb', line 135 def advices @advices end |
#bibentries ⇒ Object
Returns the value of attribute bibentries.
138 139 140 |
# File 'lib/deplate/formatter.rb', line 138 def bibentries @bibentries end |
#cjk_nospace ⇒ Object (readonly)
Returns the value of attribute cjk_nospace.
13 14 15 |
# File 'lib/deplate/mod/lang-zh_CN-autospace.rb', line 13 def cjk_nospace @cjk_nospace end |
#cjk_smart_blanks ⇒ Object (readonly)
Returns the value of attribute cjk_smart_blanks.
13 14 15 |
# File 'lib/deplate/zh_CN.rb', line 13 def cjk_smart_blanks @cjk_smart_blanks end |
#cjk_space ⇒ Object (readonly)
Returns the value of attribute cjk_space.
13 14 15 |
# File 'lib/deplate/mod/lang-zh_CN-autospace.rb', line 13 def cjk_space @cjk_space end |
#deplate ⇒ Object (readonly)
Returns the value of attribute deplate.
134 135 136 |
# File 'lib/deplate/formatter.rb', line 134 def deplate @deplate end |
#doc_services ⇒ Object
A hash holding all known document services (names => method).
140 141 142 |
# File 'lib/deplate/formatter.rb', line 140 def doc_services @doc_services end |
#entities_table ⇒ Object (readonly)
Returns the value of attribute entities_table.
141 142 143 |
# File 'lib/deplate/formatter.rb', line 141 def entities_table @entities_table end |
#expander ⇒ Object (readonly)
Returns the value of attribute expander.
136 137 138 |
# File 'lib/deplate/formatter.rb', line 136 def @expander end |
#special_symbols ⇒ Object
Returns the value of attribute special_symbols.
137 138 139 |
# File 'lib/deplate/formatter.rb', line 137 def special_symbols @special_symbols end |
Class Method Details
.def_service(name, &block) ⇒ Object
<TBD
>Shouldn’t services belong to the formatter?
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/deplate/formatter.rb', line 66 def def_service(name, &block) # prefix = @formatter.class.myname.gsub('\W', '__') # method = ['svc', prefix, name].join('_') method = ['svc', name].join('_') self.class_eval do define_method(method, &block) end init = ['formatter_initialize', method].join('_') sname = name.gsub(/_(.)/) {$1.capitalize} self.class_eval do define_method(init) do @doc_services[name] = method @doc_services[sname] = method end end end |
.formatter_family_members(args = {}) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/deplate/formatter.rb', line 109 def formatter_family_members(args={}) acc = [] formatter_names = args[:names] || [] formatter_class = fmt = self myname = fmt.myname while myname acc << myname yield(myname) if block_given? fmt = fmt.superclass myname = fmt.myname end (formatter_class. + formatter_names).each do |myname| acc << myname yield(myname) if block_given? end acc end |
.formatter_related?(name) ⇒ Boolean
127 128 129 |
# File 'lib/deplate/formatter.rb', line 127 def (name) formatter_family_members.include?(name) end |
.hook_post_myname=(name) ⇒ Object
60 61 62 63 |
# File 'lib/deplate/formatter.rb', line 60 def hook_post_myname=(name) klass = self Deplate::Core.class_eval {declare_formatter(klass)} end |
.noop(context, name) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/deplate/formatter.rb', line 52 def noop(context, name) context.module_eval %{ def #{name}(*args) return "" end } end |
.set_options_for_file(options, file = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/deplate/formatter.rb', line 83 def (, file=nil) case file when '-' .ext = '' .srcdir ||= Dir.pwd .out ||= '-' else .suffix ||= self.suffix unless file.nil? .ext = File.extname(file) .srcdir ||= File.dirname(file) end if .out .out = Deplate::Core.file_join(.dir, .out) # if options.out != '-' # options.out = options.dir ? Deplate::Core.file_join(options.dir, options.out) : options.out # end elsif file.nil? .out = '-' else .out = Deplate::Core.get_out_fullname(file, .suffix, , :raw => true) end end end |
Instance Method Details
#bare_latex_formula(text) ⇒ Object
1073 1074 1075 1076 1077 1078 1079 1080 1081 |
# File 'lib/deplate/formatter.rb', line 1073 def (text) m = /^(\\\[|\$)(.*?)(\\\]|\$)$/.match(text) if m return [m[1] == '\\[', m[2]] else log(['Internal error', text], :error) return nil end end |
#bib_entry(key) ⇒ Object
677 678 679 680 681 682 683 684 685 |
# File 'lib/deplate/formatter.rb', line 677 def bib_entry(key) b = @bibentries[key] || {} crossref = b['crossref'] if crossref cb = @bibentries[crossref] b.update(cb) {|k, o, n| o} if cb end return b end |
#canonic_enc_name(enc, table = @encodings) ⇒ Object
258 259 260 |
# File 'lib/deplate/formatter.rb', line 258 def canonic_enc_name(enc, table=@encodings) Deplate::Encoding.canonic_enc_name(enc, table) end |
#canonic_encoding(default = nil, table = {}) ⇒ Object
def canonic_encoding(default=nil, table=@encodings)
250 251 252 |
# File 'lib/deplate/formatter.rb', line 250 def canonic_encoding(default=nil, table={}) canonic_enc_name(@variables['encoding'] || default || 'latin1', table) end |
#canonic_image_type(type) ⇒ Object
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 |
# File 'lib/deplate/formatter.rb', line 795 def canonic_image_type(type) case type when 'image/cgm' when 'image/g3fax' when 'image/gif', 'gif' return 'gif' when 'image/ief', 'ief' when 'image/jpeg', 'jpeg', 'jpg', 'jpe' return 'jpg' when 'image/naplps' when 'image/pcx', 'pcx' when 'image/png', 'png' return 'png' when 'image/prs.btif' when 'image/prs.pti' when 'image/svg'+'xml', 'svg', 'svgz' return 'svg' when 'image/tiff', 'tiff', 'tif' return 'tif' when 'image/vnd.cns.inf2' when 'image/vnd.djvu', 'djvu', 'djv' when 'image/vnd.dwg' when 'image/vnd.dxf' when 'image/vnd.fastbidsheet' when 'image/vnd.fpx' when 'image/vnd.fst' when 'image/vnd.fujixerox.edmics-mmr' when 'image/vnd.fujixerox.edmics-rlc' when 'image/vnd.mix' when 'image/vnd.net-fpx' when 'image/vnd.svf' when 'image/vnd.wap.wbmp', 'wbmp' when 'image/vnd.xiff' when 'image/x-cmu-raster', 'ras' when 'image/x-coreldraw', 'cdr' when 'image/x-coreldrawpattern', 'pat' when 'image/x-coreldrawtemplate', 'cdt' when 'image/x-corelphotopaint', 'cpt' when 'image/x-icon', 'ico' when 'image/x-jg', 'art' when 'image/x-jng', 'jng' when 'image/x-ms-bmp', 'bmp' return 'bmp' when 'image/x-photoshop', 'psd' when 'image/x-portable-anymap', 'pnm' when 'image/x-portable-bitmap', 'pbm' when 'image/x-portable-graymap', 'pgm' when 'image/x-portable-pixmap', 'ppm' when 'image/x-rgb', 'rgb' when 'image/x-xbitmap', 'xbm' when 'image/x-xpixmap', 'xpm' when 'image/x-xwindowdump', 'xwd' # wmf # ps, eps # pdf end end |
#canonic_mime(type) ⇒ Object
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 |
# File 'lib/deplate/formatter.rb', line 736 def canonic_mime(type) case type when 'image/cgm' when 'image/g3fax' when 'image/gif', 'gif' return 'image/gif' when 'image/ief', 'ief' when 'image/jpeg', 'jpeg', 'jpg', 'jpe' return 'image/jpeg' when 'image/naplps' when 'image/pcx', 'pcx' when 'image/png', 'png' return 'image/png' when 'image/prs.btif' when 'image/prs.pti' when 'image/svg'+'xml', 'svg', 'svgz' return 'image/svg+xml' when 'image/tiff', 'tiff', 'tif' return 'image/tiff' when 'image/vnd.cns.inf2' when 'image/vnd.djvu', 'djvu', 'djv' when 'image/vnd.dwg' when 'image/vnd.dxf' when 'image/vnd.fastbidsheet' when 'image/vnd.fpx' when 'image/vnd.fst' when 'image/vnd.fujixerox.edmics-mmr' when 'image/vnd.fujixerox.edmics-rlc' when 'image/vnd.mix' when 'image/vnd.net-fpx' when 'image/vnd.svf' when 'image/vnd.wap.wbmp', 'wbmp' when 'image/vnd.xiff' when 'image/x-cmu-raster', 'ras' when 'image/x-coreldraw', 'cdr' when 'image/x-coreldrawpattern', 'pat' when 'image/x-coreldrawtemplate', 'cdt' when 'image/x-corelphotopaint', 'cpt' when 'image/x-icon', 'ico' when 'image/x-jg', 'art' when 'image/x-jng', 'jng' when 'image/x-ms-bmp', 'bmp' return 'image/x-ms-bmp' when 'image/x-photoshop', 'psd' when 'image/x-portable-anymap', 'pnm' when 'image/x-portable-bitmap', 'pbm' when 'image/x-portable-graymap', 'pgm' when 'image/x-portable-pixmap', 'ppm' when 'image/x-rgb', 'rgb' when 'image/x-xbitmap', 'xbm' when 'image/x-xpixmap', 'xpm' when 'image/x-xwindowdump', 'xwd' # wmf # ps, eps # pdf end end |
#char_by_name(name) ⇒ Object
481 482 483 484 485 486 487 488 |
# File 'lib/deplate/formatter.rb', line 481 def char_by_name(name) @entities_table.each do |char, named, numbered| if named == name return char end end return name end |
#char_by_number(number) ⇒ Object
472 473 474 475 476 477 478 479 |
# File 'lib/deplate/formatter.rb', line 472 def char_by_number(number) @entities_table.each do |char, named, numbered| if numbered == number return char end end return number end |
#check_symbol_proxy ⇒ Object
490 491 492 493 494 |
# File 'lib/deplate/formatter.rb', line 490 def check_symbol_proxy unless @symbol_proxy pre_process end end |
#close_headings(level, &block) ⇒ Object
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 |
# File 'lib/deplate/formatter.rb', line 711 def close_headings(level, &block) hds = @deplate..headings if hds acc = [] loop do hd = hds.last if hd and level <= hd.level acc << indent_text(format_heading_close(hd), :mult => hd.level - level) if block acc << block.call(hd.level) end hds.pop else break end end if acc.empty? return nil else return join_blocks(acc) end end end |
#consumed_ids ⇒ Object
174 175 176 |
# File 'lib/deplate/formatter.rb', line 174 def consumed_ids @deplate.output.attributes[:consumed_ids] end |
#consumed_ids=(arg) ⇒ Object
177 178 179 |
# File 'lib/deplate/formatter.rb', line 177 def consumed_ids=(arg) @deplate.output.attributes[:consumed_ids] = arg end |
#consumed_labels ⇒ Object
167 168 169 |
# File 'lib/deplate/formatter.rb', line 167 def consumed_labels @deplate.output.attributes[:consumed_labels] end |
#consumed_labels=(arg) ⇒ Object
170 171 172 |
# File 'lib/deplate/formatter.rb', line 170 def consumed_labels=(arg) @deplate.output.attributes[:consumed_labels] = arg end |
#def_advice(applicant, agent, args) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/deplate/formatter.rb', line 199 def def_advice(applicant, agent, args) this = @advices[agent] ||= {} for type in [:wrap] thistype = [] prc = args[type] if prc if prc.kind_of?(Proc) thistype << {:applicant => applicant, :prc => prc} else raise "Not a Proc: %s" % prc end end unless thistype.empty? if this[type] this[type] += thistype else this[type] = thistype end end end for type in [:before, :around, :after] prc = args[type] if prc log(["Unsupported advice type", type, applicant, prc], :error) end end end |
#document_encoding(table = @encodings) ⇒ Object
254 255 256 |
# File 'lib/deplate/formatter.rb', line 254 def document_encoding(table=@encodings) canonic_enc_name(@variables['encoding'] || 'latin1', table) end |
#doublequote_close(invoker) ⇒ Object
521 522 523 524 |
# File 'lib/deplate/formatter.rb', line 521 def doublequote_close(invoker) check_symbol_proxy @symbol_proxy.doublequote_close(invoker) end |
#doublequote_open(invoker) ⇒ Object
516 517 518 519 |
# File 'lib/deplate/formatter.rb', line 516 def doublequote_open(invoker) check_symbol_proxy @symbol_proxy.doublequote_open(invoker) end |
#dummy(invoker, *args) ⇒ Object
376 377 378 |
# File 'lib/deplate/formatter.rb', line 376 def dummy(invoker, *args) args end |
#dvi2png(invoker, fdvi, fout, other_options = nil) ⇒ Object
1259 1260 1261 1262 1263 1264 |
# File 'lib/deplate/formatter.rb', line 1259 def dvi2png(invoker, fdvi, fout, =nil) if Deplate::External.dvi2png(invoker, fdvi, fout, ) and @deplate..clean File.delete(fdvi) if @deplate..clean invoker.log(["Deleting", fdvi]) end end |
#dvi2ps(invoker, fdvi, fps, other_options = nil) ⇒ Object
1251 1252 1253 1254 1255 1256 1257 |
# File 'lib/deplate/formatter.rb', line 1251 def dvi2ps(invoker, fdvi, fps, =nil) # -Pwww if Deplate::External.dvi2ps(invoker, fdvi, fps, ) and @deplate..clean File.delete(fdvi) if @deplate..clean invoker.log(["Deleting", fdvi]) end end |
#encode_id(id) ⇒ Object
566 567 568 |
# File 'lib/deplate/formatter.rb', line 566 def encode_id(id) id ? Deplate::Core.clean_name(id) : id end |
#entities_encode_plain_text ⇒ Object
Properly format text
as formatter-valid plain text.
If escaped
is true, text
appears in a special context and was escaped by a backslash or similar.
If a block is given, convert normal text using this block.
Special characters are translated on the basis of @special_symbols.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/deplate/mod/entities-encode.rb', line 17 def plain_text(text, escaped=false) if defined?(@plain_text_rx) acc = [] text.split(@plain_text_rx).each_with_index do |e, i| if i.modulo(2) == 0 acc << plain_text_recode(e) unless e.empty? else r = @special_symbols[e] case r when :identity acc << e when String acc << r when Proc acc << r.call(escaped) else raise "Internal error: Strange symbol replacement for '#{e}'" end end end acc.join else plain_text_recode(text) end end |
#fill_in_template(invoker) ⇒ Object
670 671 672 |
# File 'lib/deplate/formatter.rb', line 670 def fill_in_template(invoker) invoker.elt end |
#format_ACT(invoker) ⇒ Object
660 661 662 |
# File 'lib/deplate/formatter.rb', line 660 def format_ACT(invoker) return '' end |
#format_CAST(invoker) ⇒ Object
656 657 658 |
# File 'lib/deplate/formatter.rb', line 656 def format_CAST(invoker) return '' end |
#format_cite(invoker) ⇒ Object
895 896 897 |
# File 'lib/deplate/formatter.rb', line 895 def format_cite(invoker) bib_styler.bib_cite(invoker) end |
#format_direct(invoker, text = nil) ⇒ Object
664 665 666 667 668 |
# File 'lib/deplate/formatter.rb', line 664 def format_direct(invoker, text=nil) # invoker.push_styles(['emphasized']) invoker.push_styles(['play-direct']) "(%s)" % (text || invoker.elt || invoker.text) end |
#format_element(agent, invoker, *args) ⇒ Object
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/deplate/formatter.rb', line 295 def format_element(agent, invoker, *args) if @format_advice_backlist.include?(agent) send(agent, invoker, *args) else # rv = with_agent(agent, Array, invoker, *args) # rv.empty? ? format_unknown(invoker) : join_blocks(rv) rv = with_agent(agent, Array, invoker, *args) if rv and !rv.empty? and !self.class.naked_agents.include?(agent) wa = {} wa[:styles] = invoker.styles if invoker.respond_to?(:styles) rv = methods.find_all {|m| m =~ /^wrap_formatted_element_/ }. inject(rv) {|rv, m| send(m, invoker, rv, wa)} end rv end end |
#format_element_as_string(agent, invoker, *args) ⇒ Object
312 313 314 |
# File 'lib/deplate/formatter.rb', line 312 def format_element_as_string(agent, invoker, *args) format_element(agent, invoker, *args) end |
#format_GET(invoker) ⇒ Object
615 616 617 618 619 620 621 622 |
# File 'lib/deplate/formatter.rb', line 615 def format_GET(invoker) elt = invoker.elt if elt elt.format_clip(invoker, Deplate::Element) else invoker.log("Dropped!", :error) end end |
#format_heading_close(invoker) ⇒ Object
708 709 |
# File 'lib/deplate/formatter.rb', line 708 def format_heading_close(invoker) end |
#format_highstep(invoker, txt = nil) ⇒ Object
25 26 27 |
# File 'lib/deplate/mod/html-highstep.rb', line 25 def format_highstep(invoker, txt=nil) format_emphasize(invoker, txt) end |
#format_inlatex(invoker) ⇒ Object
Format the Inlatex region
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 |
# File 'lib/deplate/formatter.rb', line 1035 def format_inlatex(invoker) args = invoker.args inline = args['inline'] args['h'] ||= (args['inlineLatexHeight'] || args['inlatexHeight']) if inline acc = [] elt = invoker.elt if elt elt.each do |i| acc << format_element(:format_figure, invoker, inline, i) end else invoker.log(['Empty element', 'inlatex'], :error) end join_blocks(acc) end |
#format_LIST(invoker) ⇒ Object
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'lib/deplate/formatter.rb', line 624 def format_LIST(invoker) acc = [] elt = invoker.elt case elt when 'contents' elt = 'toc' when 'tables' elt = 'lot' when 'figures' elt = 'lof' end meth = "format_list_of_" + elt args = invoker.args begin if respond_to?(meth) acc << send(meth, invoker) elsif @deplate..listings.is_defined?(elt) acc << format_custom_list(invoker, elt) else log(["Unknown list type", elt.inspect], :error) end acc << format_pagebreak(invoker) if args["page"] rescue StandardError => e log(["Formatting on LIST failed", elt.inspect, e, e.backtrace[0..10]], :error) end join_blocks(acc) end |
#format_ltx(invoker, other_args = {}) ⇒ Object Also known as: format_math
Format the ltx macro
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 |
# File 'lib/deplate/formatter.rb', line 1052 def format_ltx(invoker, other_args={}) args = invoker.args acc = [] args['h'] ||= (args['inlineLatexHeight'] || other_args['h']) args['alt'] ||= invoker.text args['style'] = 'latex' inlatex = invoker.elt if !inlatex or inlatex.empty? acc << invoker.text else for i in inlatex # acc << @deplate.formatter.include_image(invoker, i, args, true) acc << format_element(:format_figure, invoker, true, i) end end return acc.flatten.join("\n") end |
#format_PAGEBREAK(invoker) ⇒ Object
652 653 654 |
# File 'lib/deplate/formatter.rb', line 652 def format_PAGEBREAK(invoker) format_pagebreak(invoker, nil, true) end |
#format_particle(agent, invoker, *args) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/deplate/formatter.rb', line 274 def format_particle(agent, invoker, *args) if @format_advice_backlist.include?(agent) send(agent, invoker, *args) else # rv = with_agent(agent, Array, invoker, *args) # rv.empty? ? format_unknown_particle(invoker) : rv.join rv = with_agent(agent, Array, invoker, *args) if rv and !rv.empty? and !self.class.naked_agents.include?(agent) wa = {} wa[:styles] = invoker.styles if invoker.respond_to?(:styles) rv = methods.find_all {|m| m =~ /^wrap_formatted_particle_/ }. inject(rv) {|rv, m| send(m, invoker, rv, wa)} end rv end end |
#format_particle_as_string(agent, invoker, *args) ⇒ Object
291 292 293 |
# File 'lib/deplate/formatter.rb', line 291 def format_particle_as_string(agent, invoker, *args) join_inline(format_particle(agent, invoker, *args)) end |
#format_plain_text(invoker, text = nil, escaped = false) ⇒ Object
551 552 553 554 555 |
# File 'lib/deplate/formatter.rb', line 551 def format_plain_text(invoker, text=nil, escaped=false) text ||= invoker.match # <+TBD+> escaped plain_text(text, escaped) end |
#format_region(invoker) ⇒ Object
891 892 893 |
# File 'lib/deplate/formatter.rb', line 891 def format_region(invoker) invoker.elt.strip end |
#format_symbol(invoker, sym) ⇒ Object
def symbol_paragraph(invoker)
check_symbol_proxy
@symbol_proxy.symbol_paragraph(invoker)
end
546 547 548 549 |
# File 'lib/deplate/formatter.rb', line 546 def format_symbol(invoker, sym) check_symbol_proxy @symbol_proxy.format_symbol(invoker, sym) end |
#format_unknown(invoker) ⇒ Object
691 692 693 694 695 696 697 698 |
# File 'lib/deplate/formatter.rb', line 691 def format_unknown(invoker) log(["Unknown element", invoker.class], :error, invoker.source) elt = invoker.elt if elt.kind_of?(Array) elt = elt.join("\n") end format_verbatim(invoker, elt) end |
#format_unknown_macro(invoker) ⇒ Object
704 705 706 |
# File 'lib/deplate/formatter.rb', line 704 def format_unknown_macro(invoker) return %{#{plain_text("{")}#{invoker.elt}#{plain_text("}")}} end |
#format_unknown_particle(invoker) ⇒ Object
700 701 702 |
# File 'lib/deplate/formatter.rb', line 700 def format_unknown_particle(invoker) return plain_text(invoker.args[:match][0]) end |
#format_void(invoker, text = nil) ⇒ Object
557 558 559 |
# File 'lib/deplate/formatter.rb', line 557 def format_void(invoker, text=nil) text || invoker.elt end |
#formatted_block(env, text, opts = nil, args = nil, no_id = false, no_indent = false) ⇒ Object
1273 1274 1275 1276 |
# File 'lib/deplate/formatter.rb', line 1273 def formatted_block(env, text, opts=nil, args=nil, no_id=false, no_indent=false) text = indent_text(text) unless no_indent return join_blocks([get_open(env, opts, args, :no_id => no_id), text, get_close(env, args)]) end |
#formatted_inline(env, text, opts = nil, args = nil, no_id = false) ⇒ Object
1280 1281 1282 |
# File 'lib/deplate/formatter.rb', line 1280 def formatted_inline(env, text, opts=nil, args=nil, no_id=false) return join_inline([get_open(env, opts, args, :no_id => no_id), text, get_close(env, args)]) end |
#formatted_single(env, opts = nil, args = nil, no_id = false) ⇒ Object
1284 1285 1286 |
# File 'lib/deplate/formatter.rb', line 1284 def formatted_single(env, opts=nil, args=nil, no_id=false) return get_open(env, opts, args, :single => true, :no_id => no_id) end |
#formatter_initialize_mark_urls ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/deplate/mod/mark-external-urls.rb', line 20 def formatter_initialize_mark_urls def_advice('mark-external-urls', :format_url, :wrap => Proc.new do |agent, rv, invoker, name, dest, *args| if dest =~ Deplate::HyperLink::Url.rx if dest =~ /^mailto:/ icon = @variables['mailtoIcon'] || 'mailto.png' invoker.args['alt'] ||= 'e-mail' else icon = @variables['urlIcon'] || 'url.png' # invoker.args['alt'] ||= 'url' end args = {'style' => 'remote'} img = format_particle(:include_image, invoker, icon, args, true) if @variables['markerInFrontOfURL'] img + rv else rv + img end else rv end end ) end |
#formatter_name ⇒ Object
586 587 588 |
# File 'lib/deplate/formatter.rb', line 586 def formatter_name self.class.myname end |
#formatter_related?(name) ⇒ Boolean
156 157 158 |
# File 'lib/deplate/formatter.rb', line 156 def (name) self.class.(name) end |
#formatter_rx ⇒ Object
590 591 592 |
# File 'lib/deplate/formatter.rb', line 590 def formatter_rx self.class.rx end |
#get_first_char(string, upcase = false) ⇒ Object
Return the first character of string while taking care whether string starts with a multi-byte sequence. Return the character in upper case if upcase is true (this usually doesn’t work for multi-byte characters.
908 909 910 911 912 913 914 |
# File 'lib/deplate/formatter.rb', line 908 def get_first_char(string, upcase=false) if multibyte_leader?(string[0]) string[0..1] else get_first_char_re_zh_cn(string, upcase) end end |
#get_first_char_re_utf8 ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/deplate/mod/utf8.rb', line 18 def get_first_char(string, upcase=false) if multibyte_leader?(string[0]) string[0..1] else get_first_char_re_zh_cn(string, upcase) end end |
#get_first_char_re_zh_cn ⇒ Object
42 |
# File 'lib/deplate/zh_CN.rb', line 42 alias :get_first_char_re_zh_cn :get_first_char |
#hook_post_go_recode ⇒ Object
def hook_pre_go_recode
recode_start
end
24 25 26 |
# File 'lib/deplate/mod/recode.rb', line 24 def hook_post_go_recode recode_stop end |
#hook_pre_go_iconv ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/deplate/mod/iconv.rb', line 18 def hook_pre_go_iconv @iconv_encodings = {} unless defined?(@iconv_enc_source) source = @deplate.variables['encoding'] || "latin1" @iconv_enc_source = canonic_enc_name(source, @iconv_encodings) target = @deplate.variables['recodeEncoding'] || "utf-8" @iconv_enc_target = canonic_enc_name(target, @iconv_encodings) @deplate.variables['encoding'] = target end unless defined?(@iconv_converter) and @iconv_converter @iconv_converter = Iconv.new(@iconv_enc_target, @iconv_enc_source) end end |
#hook_pre_process_inlatex ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/deplate/mod/inlatex-compound.rb', line 35 def hook_pre_process_inlatex pseudo = Deplate::PseudoContainer.new(@deplate, :accum => @inlatex_body, :args => {'sfx' => @inlatex_suffix} ) inlatex_compound(pseudo) fnames = pseudo.elt if fnames.size != @inlatex_container.size log(['Unexpected number of output files', "#{fnames.size} (#{@inlatex_container.size})"], :error) end if @inlatex_container.kind_of?(Array) and fnames.kind_of?(Array) @inlatex_container.each_with_index {|o, i| o.elt = [fnames[i]]} end end |
#hook_pre_setup_zh_cn ⇒ Object
15 16 17 18 |
# File 'lib/deplate/zh_CN.rb', line 15 def hook_pre_setup_zh_cn # @deplate.variables['encoding'] = 'GB2312' @cjk_smart_blanks = !(@deplate.variables['noSmartBlanks'] || false) end |
#hook_pre_setup_zh_cn_autospace ⇒ Object
14 15 16 17 |
# File 'lib/deplate/mod/lang-zh_CN-autospace.rb', line 14 def hook_pre_setup_zh_cn_autospace @cjk_space = ' ' @cjk_nospace = '' end |
#include_image(invoker, file, args, *other_args) ⇒ Object
854 855 856 857 858 859 860 861 862 863 |
# File 'lib/deplate/formatter.rb', line 854 def include_image(invoker, file, args, *other_args) type = args['type'] || File.extname(file).sub(/^\./, '') type = canonic_image_type(type) meth = "include_image_#{type}" if respond_to?(meth) return send(meth, invoker, file, args, *other_args) else include_image_general(invoker, file, args, *other_args) end end |
#indent_text(text, args = {}) ⇒ Object
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 |
# File 'lib/deplate/formatter.rb', line 1288 def indent_text(text, args={}) if text mult = args[:mult] || 1 shift = args[:shift] hanging = args[:hanging] indent = args[:indent] || format_indent(mult, shift) acc = [] text.each_line do |l| rv = '%s%s' % [indent, l.chomp] if hanging indent = args[:indenttail] || \ if args[:indent] args[:indent] + case hanging when Integer ' ' * hanging else ' ' end else format_indent(mult + 1, shift) end hanging = false end acc << rv end return acc.join("\n") end end |
#inlatex(invoker) ⇒ Object
Process inline latex
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 |
# File 'lib/deplate/formatter.rb', line 1085 def inlatex(invoker) pkgs, body = inlatex_split(invoker.accum) id = inlatex_id(invoker) sfx = invoker.args['sfx'] || @deplate.variables['ltxSfx'] || inlatex_sfx currDir = Dir.pwd @deplate.in_working_dir do ftex = id + '.tex' flog = id + '.log' faux = id + '.aux' fdvi = id + '.dvi' fps = id + '.ps' checkOW = true case sfx when 'ps' device = nil fout = fps checkOW = false when 'pdf' device = 'pdfwrite' fout = id + '.*.pdf' when 'jpeg', 'jpg' device = 'jpeg' fout = id + '.*.jpeg' when "png" device = "png" fout = id + ".png" else raise "Unknown device/suffix: #{sfx}" end pointsize = invoker.args['pointsize'] || @deplate.variables['latexPointsize'] || '10' acc = [ "\\documentclass[#{pointsize}pt,a4paper,notitlepage]{article}", "\\usepackage{amsmath}", "\\usepackage{amsfonts}", "\\usepackage{amssymb}", # "\\usepackage{mathabx}", ] acc += pkgs acc << "\\begin{document}" << "\\pagestyle{empty}" acc += body acc << "\\end{document}" if Deplate::Region.check_file(invoker, fout, ftex, acc) invoker.log(['Files exist! Using', fout], :anyway) else if checkOW and !@deplate..force for f in [ftex, flog, faux, fdvi, fout] if !Dir[f].empty? raise "Please delete '#{f}' or change the id before proceeding:\n#{invoker.accum.join("\n")}" end end end acc = acc.join("\n") Deplate::External.write_file(invoker, ftex) {|io| io.puts(acc)} inlatex_process_latex(invoker, ftex, faux, flog) if block_given? yield(invoker, device, fdvi, fps, fout) else case device when "png" inlatex_process_dvi_png(invoker, fdvi, fout) if File.exist?(fdvi) else inlatex_process_dvi(invoker, fdvi, fps) if File.exist?(fdvi) if device inlatex_process_ps(invoker, device, fps, fout, invoker.args) elsif fps != fout File.rename(fps, fout) end end end end invoker.elt = Dir[fout] if invoker.elt.empty? code = invoker.accum.join("\n") invoker.log(["Conversion if Inline LaTeX failed", code], :error) end end end |
#inlatex_clean(line) ⇒ Object
1227 1228 1229 1230 1231 1232 1233 |
# File 'lib/deplate/formatter.rb', line 1227 def inlatex_clean(line) line = line.chomp unless @deplate.is_allowed?('t') line.gsub!(INLATEX_RX, '+++disabled+++') end line end |
#inlatex_compound ⇒ Object
Process inline latex. The file names of the output are saved as an array in invoker.elt
.
17 18 19 20 21 22 23 24 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/deplate/mod/inlatex-compound.rb', line 17 def inlatex(invoker) pkgs, body = inlatex_split(invoker.accum) id = inlatex_id(invoker) sfx = invoker.args['sfx'] || @deplate.variables['ltxSfx'] || inlatex_sfx currDir = Dir.pwd @deplate.in_working_dir do ftex = id + '.tex' flog = id + '.log' faux = id + '.aux' fdvi = id + '.dvi' fps = id + '.ps' checkOW = true case sfx when 'ps' device = nil fout = fps checkOW = false when 'pdf' device = 'pdfwrite' fout = id + '.*.pdf' when 'jpeg', 'jpg' device = 'jpeg' fout = id + '.*.jpeg' when "png" device = "png" fout = id + ".png" else raise "Unknown device/suffix: #{sfx}" end pointsize = invoker.args['pointsize'] || @deplate.variables['latexPointsize'] || '10' acc = [ "\\documentclass[#{pointsize}pt,a4paper,notitlepage]{article}", "\\usepackage{amsmath}", "\\usepackage{amsfonts}", "\\usepackage{amssymb}", # "\\usepackage{mathabx}", ] acc += pkgs acc << "\\begin{document}" << "\\pagestyle{empty}" acc += body acc << "\\end{document}" if Deplate::Region.check_file(invoker, fout, ftex, acc) invoker.log(['Files exist! Using', fout], :anyway) else if checkOW and !@deplate..force for f in [ftex, flog, faux, fdvi, fout] if !Dir[f].empty? raise "Please delete '#{f}' or change the id before proceeding:\n#{invoker.accum.join("\n")}" end end end acc = acc.join("\n") Deplate::External.write_file(invoker, ftex) {|io| io.puts(acc)} inlatex_process_latex(invoker, ftex, faux, flog) if block_given? yield(invoker, device, fdvi, fps, fout) else case device when "png" inlatex_process_dvi_png(invoker, fdvi, fout) if File.exist?(fdvi) else inlatex_process_dvi(invoker, fdvi, fps) if File.exist?(fdvi) if device inlatex_process_ps(invoker, device, fps, fout, invoker.args) elsif fps != fout File.rename(fps, fout) end end end end invoker.elt = Dir[fout] if invoker.elt.empty? code = invoker.accum.join("\n") invoker.log(["Conversion if Inline LaTeX failed", code], :error) end end end |
#inlatex_id(invoker, last = false) ⇒ Object
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 |
# File 'lib/deplate/formatter.rb', line 1170 def inlatex_id(invoker, last=false) id = invoker.args["id"] unless id unless last @inlatex_idx += 1 end id = @deplate.auxiliary_auto_filename('ltx', @inlatex_idx, invoker.accum) invoker.log(["No ID given", invoker.accum]) end id end |
#inlatex_process_dvi(invoker, fdvi, fps) ⇒ Object
1186 1187 1188 |
# File 'lib/deplate/formatter.rb', line 1186 def inlatex_process_dvi(invoker, fdvi, fps) dvi2ps(invoker, fdvi, fps) end |
#inlatex_process_dvi_png(invoker, fdvi, fout) ⇒ Object
1190 1191 1192 |
# File 'lib/deplate/formatter.rb', line 1190 def inlatex_process_dvi_png(invoker, fdvi, fout) dvi2png(invoker, fdvi, fout) end |
#inlatex_process_latex(invoker, ftex, faux, flog) ⇒ Object
1182 1183 1184 |
# File 'lib/deplate/formatter.rb', line 1182 def inlatex_process_latex(invoker, ftex, faux, flog) latex2dvi(invoker, ftex, faux, flog) end |
#inlatex_process_ps(invoker, device, fps, fout, args) ⇒ Object
1194 1195 1196 |
# File 'lib/deplate/formatter.rb', line 1194 def inlatex_process_ps(invoker, device, fps, fout, args) ps2img(invoker, device, fps, fout, args) if File.exist?(fps) end |
#inlatex_sfx ⇒ Object
The default suffix/device to be used for inlatex output.
1236 1237 1238 |
# File 'lib/deplate/formatter.rb', line 1236 def inlatex_sfx 'jpeg' end |
#inlatex_split(accum) ⇒ Object
Divert lines in invoker#accum to the preamble or the body.
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 |
# File 'lib/deplate/formatter.rb', line 1199 def inlatex_split(accum) pkgs = [] body = [] for l in accum.join("\n") l = inlatex_clean(l) if l =~ /^\s*\\(usepackage|input)\s*(\[.*?\])?\s*\{.+?\}\s*$/ pkgs << l.chomp elsif l =~ /%%%\s*$/ pkgs << l.chomp else body << l.chomp end end return pkgs.uniq, body end |
#invoke_service(name, args = {}, text = '') ⇒ Object
Run a “service”, i.e., a small, mostly autonomous function/method that usually yields some formatted output.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/deplate/formatter.rb', line 229 def invoke_service(name, args={}, text='') method = @doc_services[name] if method begin return send(method, args || {}, text || '') rescue Exception => e puts e.backtrace[0..10].join("\n") log(['Calling service failed', name, e], :error) end else # p "DBG" # puts @doc_services.keys.sort.join("\n") log(['Unknown service', name], :error) end end |
#join_blocks(blocks) ⇒ Object
266 267 268 |
# File 'lib/deplate/formatter.rb', line 266 def join_blocks(blocks) blocks.flatten.compact.join("\n") end |
#join_inline(strings) ⇒ Object
270 271 272 |
# File 'lib/deplate/formatter.rb', line 270 def join_inline(strings) strings.flatten.compact.join end |
#label_delegate ⇒ Object
578 579 580 |
# File 'lib/deplate/formatter.rb', line 578 def label_delegate self.class.label_delegate end |
#label_mode ⇒ Object
570 571 572 |
# File 'lib/deplate/formatter.rb', line 570 def label_mode self.class.label_mode end |
#label_once ⇒ Object
574 575 576 |
# File 'lib/deplate/formatter.rb', line 574 def label_once self.class.label_once end |
#latex2dvi(invoker, ftex, faux, flog) ⇒ Object
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 |
# File 'lib/deplate/formatter.rb', line 1240 def latex2dvi(invoker, ftex, faux, flog) if Deplate::External.latex(invoker, ftex) and @deplate..clean for i in [faux, flog] if File.exist?(i) File.delete(i) invoker.log(["Deleting", i]) end end end end |
#log(*args) ⇒ Object
245 246 247 |
# File 'lib/deplate/formatter.rb', line 245 def log(*args) Deplate::Core.log(*args) end |
#matches?(text) ⇒ Boolean
603 604 605 606 607 608 609 610 611 612 613 |
# File 'lib/deplate/formatter.rb', line 603 def matches?(text) self.class.formatter_family_members.any? do |fmtname| fmt = @deplate.get_formatter_class(fmtname) if text[0..0] == '~' rv = (fmt.myname =~ Regexp.new(text[1..-1])) else rv = (text =~ fmt.rx) end return rv ? true : false end end |
#module_initialize_numpara ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/deplate/mod/numpara.rb', line 20 def module_initialize_numpara @numpara_done = [] def_advice("numpara", :format_paragraph, :wrap => Proc.new do |agent, rv, invoker, *rest| unless invoker.args["noNum"] or @numpara_done.include?(invoker) if defined?(@paragraph_number) @paragraph_number += 1 else @paragraph_number = 1 end invoker.elt = numbered_paragraph(invoker.elt, @paragraph_number) @numpara_done << invoker end end ) end |
#multibyte_leader?(ch) ⇒ Boolean
Check if ch (a number representing a character) is a multi-byte leader. This method always returns false unless it is overwritten by some module.
901 902 903 |
# File 'lib/deplate/formatter.rb', line 901 def multibyte_leader?(ch) ch && ch >= 0xA1 && ch <= 0xFE end |
#nonbreakingspace(invoker) ⇒ Object
536 537 538 539 |
# File 'lib/deplate/formatter.rb', line 536 def nonbreakingspace(invoker) check_symbol_proxy @symbol_proxy.nonbreakingspace(invoker) end |
#numbered_paragraph(text, number) ⇒ Object
37 38 39 |
# File 'lib/deplate/mod/numpara.rb', line 37 def numbered_paragraph(text, number) return [text, plain_text("[%d]" % number)].join(" ") end |
#output(invoker, *body) ⇒ Object
380 381 382 |
# File 'lib/deplate/formatter.rb', line 380 def output(invoker, *body) output_at(invoker.doc_type, invoker.doc_slot, *body) end |
#output_at(type, slot, *body) ⇒ Object
def_delegator(:@deplate, :add_at, :output_at)
395 396 397 398 |
# File 'lib/deplate/formatter.rb', line 395 def output_at(type, slot, *body) log(["Output at", "#{type}@#{slot}", body], :debug) @deplate.output.add_at(type, slot, *body) end |
#output_destination ⇒ Object
262 263 264 |
# File 'lib/deplate/formatter.rb', line 262 def output_destination @deplate.output.top_heading.destination || @deplate..out end |
#output_empty_at?(type, slot) ⇒ Boolean
390 391 392 |
# File 'lib/deplate/formatter.rb', line 390 def output_empty_at?(type, slot) @deplate.output.empty_at?(type, slot) end |
#output_preferably_at(invoker, type, slot, *body) ⇒ Object
384 385 386 387 388 |
# File 'lib/deplate/formatter.rb', line 384 def output_preferably_at(invoker, type, slot, *body) type = defined?(invoker.doc_type) ? invoker.doc_type(type) : type slot = defined?(invoker.doc_slot) ? invoker.doc_slot(slot) : slot output_at(type, slot, *body) end |
#plain_text(text, escaped = false) ⇒ Object
Properly format text
as formatter-valid plain text.
If escaped
is true, text
appears in a special context and was escaped by a backslash or similar.
If a block is given, convert normal text using this block.
Special characters are translated on the basis of @special_symbols.
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 |
# File 'lib/deplate/formatter.rb', line 426 def plain_text(text, escaped=false) if defined?(@plain_text_rx) acc = [] text.split(@plain_text_rx).each_with_index do |e, i| if i.modulo(2) == 0 acc << plain_text_recode(e) unless e.empty? else r = @special_symbols[e] case r when :identity acc << e when String acc << r when Proc acc << r.call(escaped) else raise "Internal error: Strange symbol replacement for '#{e}'" end end end acc.join else plain_text_recode(text) end end |
#plain_text_recode(text) ⇒ Object
Recode normal text for #plain_text
562 563 564 |
# File 'lib/deplate/formatter.rb', line 562 def plain_text_recode(text) text end |
#pre_process ⇒ Object
597 598 |
# File 'lib/deplate/formatter.rb', line 597 def pre_process end |
#prelude(name) ⇒ Object
1030 1031 1032 |
# File 'lib/deplate/formatter.rb', line 1030 def prelude(name) @deplate.variables[name] end |
#prepare ⇒ Object
600 601 |
# File 'lib/deplate/formatter.rb', line 600 def prepare end |
#ps2img(invoker, device, fps, fout, args) ⇒ Object
1266 1267 1268 1269 1270 1271 |
# File 'lib/deplate/formatter.rb', line 1266 def ps2img(invoker, device, fps, fout, args) if Deplate::External.ps2img(invoker, device, fps, fout, args) and @deplate..clean File.delete(fps) invoker.log(["Deleting", fps]) end end |
#pstoedit_inlatex ⇒ Object
Process inline latex. The file names of the output are saved as an array in invoker.elt
.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 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 128 129 130 131 132 133 134 135 136 |
# File 'lib/deplate/mod/pstoedit.rb', line 53 def inlatex(invoker) pkgs, body = inlatex_split(invoker.accum) id = inlatex_id(invoker) sfx = invoker.args['sfx'] || @deplate.variables['ltxSfx'] || inlatex_sfx currDir = Dir.pwd @deplate.in_working_dir do ftex = id + '.tex' flog = id + '.log' faux = id + '.aux' fdvi = id + '.dvi' fps = id + '.ps' checkOW = true case sfx when 'ps' device = nil fout = fps checkOW = false when 'pdf' device = 'pdfwrite' fout = id + '.*.pdf' when 'jpeg', 'jpg' device = 'jpeg' fout = id + '.*.jpeg' when "png" device = "png" fout = id + ".png" else raise "Unknown device/suffix: #{sfx}" end pointsize = invoker.args['pointsize'] || @deplate.variables['latexPointsize'] || '10' acc = [ "\\documentclass[#{pointsize}pt,a4paper,notitlepage]{article}", "\\usepackage{amsmath}", "\\usepackage{amsfonts}", "\\usepackage{amssymb}", # "\\usepackage{mathabx}", ] acc += pkgs acc << "\\begin{document}" << "\\pagestyle{empty}" acc += body acc << "\\end{document}" if Deplate::Region.check_file(invoker, fout, ftex, acc) invoker.log(['Files exist! Using', fout], :anyway) else if checkOW and !@deplate..force for f in [ftex, flog, faux, fdvi, fout] if !Dir[f].empty? raise "Please delete '#{f}' or change the id before proceeding:\n#{invoker.accum.join("\n")}" end end end acc = acc.join("\n") Deplate::External.write_file(invoker, ftex) {|io| io.puts(acc)} inlatex_process_latex(invoker, ftex, faux, flog) if block_given? yield(invoker, device, fdvi, fps, fout) else case device when "png" inlatex_process_dvi_png(invoker, fdvi, fout) if File.exist?(fdvi) else inlatex_process_dvi(invoker, fdvi, fps) if File.exist?(fdvi) if device inlatex_process_ps(invoker, device, fps, fout, invoker.args) elsif fps != fout File.rename(fps, fout) end end end end invoker.elt = Dir[fout] if invoker.elt.empty? code = invoker.accum.join("\n") invoker.log(["Conversion if Inline LaTeX failed", code], :error) end end end |
#pstoedit_wrap(invoker, sfx, &block) ⇒ Object
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 |
# File 'lib/deplate/mod/pstoedit.rb', line 26 def pstoedit_wrap(invoker, sfx, &block) case sfx when 'sfx' sfx = nil when 'jpeg' sfx = 'jpg' else log(["Unhandled suffix, let's see how it works", sfx], :anyway) end if sfx begin invoker.args['sfx'] = 'ps' block.call(invoker) id = inlatex_id(invoker, true) fps = id + '.ps' fout = [id, '.', sfx].join args = @deplate.variables['pstoeditArgs'] @deplate.in_working_dir do Deplate::External.pstoedit(invoker, fps, fout, args) end return fout ensure invoker.args['sfx'] = sfx end end end |
#push_class_option(*options) ⇒ Object
push *options to variables
411 412 413 414 415 416 |
# File 'lib/deplate/formatter.rb', line 411 def push_class_option(*) acc = [@deplate.variables["classOptions"]] acc += acc.compact! @deplate.variables["classOptions"] = acc.join(' ') end |
#push_linebreak(accum, part, add_blank = true) ⇒ Object
1023 1024 1025 1026 1027 1028 |
# File 'lib/deplate/formatter.rb', line 1023 def push_linebreak(accum, part, add_blank=true) if part accum << ' ' if add_blank and /\s$/ !~ part accum << "\n" end end |
#read_bib(bibfiles) ⇒ Object
674 675 |
# File 'lib/deplate/formatter.rb', line 674 def read_bib(bibfiles) end |
#recode_start ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/deplate/mod/recode.rb', line 28 def recode_start unless defined?(@recode_encoding_source) @recode_encoding_source = @deplate.variables['encoding'] || "latin-1" @recode_encoding_target = @deplate.variables['recodeEncoding'] || "utf-8" @deplate.variables['encoding'] = @recode_encoding_target end unless @recode_io @recode_io = IO.popen("#{Deplate::External.get_app('recode')} -d #@recode_encoding_source..#@recode_encoding_target", "w+") @recode_io.sync = true end end |
#recode_stop ⇒ Object
40 41 42 43 44 45 |
# File 'lib/deplate/mod/recode.rb', line 40 def recode_stop if @recode_io @recode_io.close @recode_io = nil end end |
#referenced_bib_entry(invoker, key, text) ⇒ Object
687 688 689 |
# File 'lib/deplate/formatter.rb', line 687 def referenced_bib_entry(invoker, key, text) text end |
#reset! ⇒ Object
160 161 162 163 164 165 |
# File 'lib/deplate/formatter.rb', line 160 def reset! @bibentries = {} @open_labels = [] # @consumed_labels = [] # @consumed_ids = [] end |
#retrieve_particle(id, body = nil, specific = false) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/deplate/formatter.rb', line 181 def retrieve_particle(id, body=nil, specific=false) fmt = specific ? formatter_name : '_' particles = @@custom_particles[fmt] ||= {} particle = particles[id] if particle if body.nil? or particle[:body] == body return particle[:class] end end return nil end |
#set_at(type, slot, *body) ⇒ Object
def_delegator(:@deplate, :set_at)
406 407 408 |
# File 'lib/deplate/formatter.rb', line 406 def set_at(type, slot, *body) @deplate.output.set_at(type, slot, *body) end |
#setup ⇒ Object
594 595 |
# File 'lib/deplate/formatter.rb', line 594 def setup end |
#setup_endnotes ⇒ Object
12 13 14 |
# File 'lib/deplate/mod/endnotes.rb', line 12 def setup_endnotes @deplate.set_slot_name(:footnotes, false) end |
#setup_entities ⇒ Object
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/deplate/formatter.rb', line 452 def setup_entities unless @entities_table @entities_table = [] enc = canonic_encoding() ents = Deplate::Core.split_list(@deplate.variables['entities'] || 'general') for d in Deplate::Core.library_directories(@deplate.vanilla, true, ['ents']) for pre in self.class.formatter_family_members << nil for ent in ents f = File.join(d, '%s-%s.entities' % [ent, [pre, enc].compact.join('_')]) if File.readable?(f) @entities_table = File.readlines(f).map do |line| line.chomp.split(/\t/) end end end end end end end |
#singlequote_close(invoker) ⇒ Object
531 532 533 534 |
# File 'lib/deplate/formatter.rb', line 531 def singlequote_close(invoker) check_symbol_proxy @symbol_proxy.singlequote_close(invoker) end |
#singlequote_open(invoker) ⇒ Object
526 527 528 529 |
# File 'lib/deplate/formatter.rb', line 526 def singlequote_open(invoker) check_symbol_proxy @symbol_proxy.singlequote_open(invoker) end |
#sort_index_entries(data) ⇒ Object
Return the alphabethically sorted index data. def sort_index_entries(data)
return data.sort do |a,b|
aa = get_first_char(a, true)
bb = get_first_char(b, true)
aa <=> bb
end
end
921 922 923 |
# File 'lib/deplate/formatter.rb', line 921 def sort_index_entries(data) return data.sort {|a,b| a[0].upcase <=> b[0].upcase} end |
#stepwise_next ⇒ Object
1365 1366 1367 1368 |
# File 'lib/deplate/formatter.rb', line 1365 def stepwise_next stepwise_prepare @deplate.output.attributes[:stepwiseIdx] += 1 end |
#stepwise_prepare ⇒ Object
<TBD
> def_service(‘format’) do |args, text|
id = args['id'] || text
# o = @variables[id]
o = object_by_id(id)
if o
o.format_as_string
end
end
1361 1362 1363 |
# File 'lib/deplate/formatter.rb', line 1361 def stepwise_prepare # @deplate.output.attributes[:stepwiseIdx] ||= 0 end |
#store_particle(id, body, particle, specific = false) ⇒ Object
193 194 195 196 197 |
# File 'lib/deplate/formatter.rb', line 193 def store_particle(id, body, particle, specific=false) fmt = specific ? formatter_name : '_' particles = @@custom_particles[fmt] ||= {} particles[id] = {:body => body, :class => particle} end |
#suffix ⇒ Object
582 583 584 |
# File 'lib/deplate/formatter.rb', line 582 def suffix self.class.suffix end |
#symbol_amp(invoker) ⇒ Object
511 512 513 514 |
# File 'lib/deplate/formatter.rb', line 511 def symbol_amp(invoker) check_symbol_proxy @symbol_proxy.symbol_amp(invoker) end |
#symbol_gt(invoker) ⇒ Object
501 502 503 504 |
# File 'lib/deplate/formatter.rb', line 501 def symbol_gt(invoker) check_symbol_proxy @symbol_proxy.symbol_gt(invoker) end |
#symbol_lt(invoker) ⇒ Object
506 507 508 509 |
# File 'lib/deplate/formatter.rb', line 506 def symbol_lt(invoker) check_symbol_proxy @symbol_proxy.symbol_lt(invoker) end |
#symbol_quote(invoker) ⇒ Object
496 497 498 499 |
# File 'lib/deplate/formatter.rb', line 496 def symbol_quote(invoker) check_symbol_proxy @symbol_proxy.symbol_quote(invoker) end |
#table_empty_cell ⇒ Object
937 938 939 |
# File 'lib/deplate/formatter.rb', line 937 def table_empty_cell '' end |
#table_row_size(elt) ⇒ Object
Return the maximum row size for the table data in elt.
926 927 928 929 930 931 932 933 934 935 |
# File 'lib/deplate/formatter.rb', line 926 def table_row_size(elt) max = 0 for row in elt i = row.cols.size if i > max max = i end end max end |
#union_at(type, slot, *body) ⇒ Object
def_delegator(:@deplate, :union_at)
401 402 403 |
# File 'lib/deplate/formatter.rb', line 401 def union_at(type, slot, *body) @deplate.output.union_at(type, slot, *body) end |
#with_agent(agent, prototype, invoker, *args) ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/deplate/formatter.rb', line 316 def with_agent(agent, prototype, invoker, *args) log(["Call with agent", agent, invoker.class, args], :debug) if respond_to?(agent) before = [] inner = nil after = [] stylish = @advices[agent] if stylish # pre = stylish[:before] # if pre # for advice in pre # before << advice[:prc].call(invoker, *args) # end # end inner = self.send(agent, invoker, *args) prototype ||= inner.class around = stylish[:wrap] if around inner = around.inject(inner) do |acc, advice| advice[:prc].call(agent, acc, invoker, *args) end end # post = stylish[:after] # if post # for advice in post # after << advice[:prc].call(invoker, *args) # end # end else args = args.unshift(invoker) begin inner = self.send(agent, *args) rescue Exception => e log("We shouldn't be here. If you can track down when this happens, please send an example to the author.", :error) puts "DBG: #{agent}: #{e}" puts e.backtrace[0..10].join("\n") # raise e return nil end prototype ||= inner.class end # if prototype == String # rv = [before, inner, after].join # elsif prototype == Integer # rv = [before, inner, after].join.to_i # elsif inner.kind_of?(Array) # rv = before + inner + after # else # rv = before + [inner] + after # end # return rv return inner else invoker.log(['Unknown formatting agent', agent], :error) return nil end end |
#wrap_text(text, args = {}) ⇒ Object
Takes an optional block that takes a string as argument and returns true if we shouldn’t wrap the text at this position
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 |
# File 'lib/deplate/formatter.rb', line 943 def wrap_text(text, args={}) margin = args[:margin] || (wm = @deplate.variables['wrapMargin'] and wm.to_i) || 72 return text if margin == 0 moreIndent = args[:indent] || '' hanging = args[:hanging] || 0 hang_idt = ' ' * hanging block = args[:check] break_at = args[:break_at] acc = [] rx = /(\n|[[:space:]#{break_at}]+)/ text.each_line do |text| # if text.kind_of?(Array) # log("We shouldn't be here. If you can track down when this happens, please send an example to the author.", :error) # puts caller[0..10].join("\n") # return '' # elsif /^\s+$/ =~ text if /^\s*$/ =~ text acc << nil next else m = /^(\s*)(.*)$/.match(text.chomp) accum = [m[1]] idt = m[1] + moreIndent + hang_idt marg = margin - idt.size lmar = 0 pos0 = 0 col0 = 0 line = m[2] scanner = StringScanner.new(line) mpos = scanner.skip_until(rx) while mpos pos = scanner.pos col = pos - lmar part = line[lmar, col - scanner.matched_size] good = !(block and block.call(part)) if col - scanner.matched_size > marg and good accum << idt unless lmar == 0 if pos0 == lmar part = line[lmar, col] accum << part push_linebreak(accum, part) lmar = pos mpos = scanner.skip_until(rx) else part = line[lmar, col0] accum << part push_linebreak(accum, part) lmar = pos0 next end else mpos = scanner.skip_until(rx) end if good pos0 = pos col0 = col end end part = line[lmar, col0] # if /\S/ =~ part accum << idt unless lmar == 0 # p "DBG wrap_text", line # p !(block and block.call(part)) if line.size - lmar - 1 > marg and pos0 != lmar and !(block and block.call(part)) # p "DBG1", part accum << part push_linebreak(accum, part) accum << idt << line[pos0, line.size - pos0] else part = line[lmar, line.size - lmar] # p "DBG2", part accum << part end # end acc << accum.join end end return acc.join("\n") end |