Class: RDocF95::Markup::ToLaTeX
- Defined in:
- lib/rdoc-f95/markup/to_latex.rb
Overview
Convert SimpleMarkup to basic LaTeX report format.
Defined Under Namespace
Classes: InlineTag
Constant Summary collapse
- BS =
\
"\020"
- OB =
{
"\021"
- CB =
}
"\022"
- DL =
Dollar
"\023"
- BACKSLASH =
"#{BS}symbol#{OB}92#{CB}"
- HAT =
"#{BS}symbol#{OB}94#{CB}"
- BACKQUOTE =
"#{BS}symbol#{OB}0#{CB}"
- TILDE =
"#{DL}#{BS}sim#{DL}"
- LESSTHAN =
"#{DL}<#{DL}"
- GREATERTHAN =
"#{DL}>#{DL}"
- LIST_TYPE_TO_LATEX =
{ :BULLET => [ l("\\begin{itemize}"), l("\\end{itemize}") ], :NUMBER => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\arabic" ], :UPPERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\Alph" ], :LOWERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\alph" ], :LABELED => [ l("\\begin{description}"), l("\\end{description}") ], :NOTE => [ l("\\begin{tabularx}{\\linewidth}{@{} l X @{}}"), l("\\end{tabularx}") ], }
Class Method Summary collapse
Instance Method Summary collapse
- #accept_blank_line(am, fragment) ⇒ Object
- #accept_heading(am, fragment) ⇒ Object
- #accept_list_end(am, fragment) ⇒ Object
- #accept_list_item(am, fragment) ⇒ Object
- #accept_list_start(am, fragment) ⇒ Object
- #accept_paragraph(am, fragment) ⇒ Object
- #accept_rule(am, fragment) ⇒ Object
- #accept_verbatim(am, fragment) ⇒ Object
-
#add_tag(name, start, stop) ⇒ Object
Add a new set of LaTeX tags for an attribute.
- #end_accepting ⇒ Object
-
#escape(str) ⇒ Object
Escape a LaTeX string.
-
#init_tags ⇒ Object
Set up the standard mapping of attributes to LaTeX.
-
#initialize ⇒ ToLaTeX
constructor
A new instance of ToLaTeX.
- #l(arg) ⇒ Object
-
#start_accepting ⇒ Object
Here’s the client side of the visitor pattern.
-
#wrap(txt, line_len = 76) ⇒ Object
This is a higher speed (if messier) version of wrap.
Methods inherited from Formatter
Constructor Details
#initialize ⇒ ToLaTeX
Returns a new instance of ToLaTeX.
45 46 47 48 49 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 45 def initialize @list_depth = 0 @prev_list_types = [] end |
Class Method Details
Instance Method Details
#accept_blank_line(am, fragment) ⇒ Object
139 140 141 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 139 def accept_blank_line(am, fragment) # @res << "\n" end |
#accept_heading(am, fragment) ⇒ Object
143 144 145 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 143 def accept_heading(am, fragment) @res << convert_heading(fragment.head_level, am.flow(fragment.txt)) end |
#accept_list_end(am, fragment) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 123 def accept_list_end(am, fragment) if tag = @in_list_entry.pop @res << tag << "\n" end @res << list_name(fragment.type, false) << "\n" end |
#accept_list_item(am, fragment) ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 130 def accept_list_item(am, fragment) if tag = @in_list_entry.last @res << tag << "\n" end @res << list_item_start(am, fragment) @res << wrap(convert_flow(am.flow(fragment.txt))) << "\n" @in_list_entry[-1] = list_end_for(fragment.type) end |
#accept_list_start(am, fragment) ⇒ Object
118 119 120 121 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 118 def accept_list_start(am, fragment) @res << list_name(fragment.type, true) << "\n" @in_list_entry.push false end |
#accept_paragraph(am, fragment) ⇒ Object
101 102 103 104 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 101 def accept_paragraph(am, fragment) @res << wrap(convert_flow(am.flow(fragment.txt))) @res << "\n" end |
#accept_rule(am, fragment) ⇒ Object
112 113 114 115 116 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 112 def accept_rule(am, fragment) size = fragment.param size = 10 if size > 10 @res << "\n\n\\rule{\\linewidth}{#{size}pt}\n\n" end |
#accept_verbatim(am, fragment) ⇒ Object
106 107 108 109 110 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 106 def accept_verbatim(am, fragment) @res << "\n\\begin{code}\n" @res << fragment.txt.sub(/[\n\s]+\Z/, '') @res << "\n\\end{code}\n\n" end |
#add_tag(name, start, stop) ⇒ Object
Add a new set of LaTeX tags for an attribute. We allow separate start and end tags for flexibility
85 86 87 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 85 def add_tag(name, start, stop) @attr_tags << InlineTag.new(RDocF95::Markup::Attribute.bitmap_for(name), start, stop) end |
#end_accepting ⇒ Object
97 98 99 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 97 def end_accepting @res.tr(BS, '\\').tr(OB, '{').tr(CB, '}').tr(DL, '$') end |
#escape(str) ⇒ Object
Escape a LaTeX string
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 65 def escape(str) $stderr.print "FE: ", str if $DEBUG_RDOC s = str. sub(/\s+$/, ''). gsub(/([_\${}&%#])/, "#{BS}\\1"). gsub(/\\/, BACKSLASH). gsub(/\^/, HAT). gsub(/~/, TILDE). gsub(/</, LESSTHAN). gsub(/>/, GREATERTHAN). gsub(/,,/, ",{},"). gsub(/\`/, BACKQUOTE) $stderr.print "-> ", s, "\n" if $DEBUG_RDOC s end |
#init_tags ⇒ Object
Set up the standard mapping of attributes to LaTeX
54 55 56 57 58 59 60 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 54 def @attr_tags = [ InlineTag.new(RDocF95::Markup::Attribute.bitmap_for(:BOLD), l("\\textbf{"), l("}")), InlineTag.new(RDocF95::Markup::Attribute.bitmap_for(:TT), l("\\texttt{"), l("}")), InlineTag.new(RDocF95::Markup::Attribute.bitmap_for(:EM), l("\\emph{"), l("}")), ] end |
#l(arg) ⇒ Object
28 29 30 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 28 def l(arg) RDocF95::Markup::ToLaTeX.l(arg) end |
#start_accepting ⇒ Object
Here’s the client side of the visitor pattern
92 93 94 95 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 92 def start_accepting @res = "" @in_list_entry = [] end |
#wrap(txt, line_len = 76) ⇒ Object
This is a higher speed (if messier) version of wrap
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/rdoc-f95/markup/to_latex.rb', line 150 def wrap(txt, line_len = 76) res = "" sp = 0 ep = txt.length while sp < ep # scan back for a space p = sp + line_len - 1 if p >= ep p = ep else while p > sp and txt[p] != ?\s p -= 1 end if p <= sp p = sp + line_len while p < ep and txt[p] != ?\s p += 1 end end end res << txt[sp...p] << "\n" sp = p sp += 1 while sp < ep and txt[sp] == ?\s end res end |