Skip to content

Commit

Permalink
Merge branch 'virtualfunction/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Garber authored and Jason Garber committed Jun 27, 2008
2 parents cce37ff + bd07070 commit ae2ac5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions lib/formatters/latex.rb
Expand Up @@ -10,7 +10,7 @@ def escape(text)
end

def escape_pre(text)
latex_esc(text)
text
end

def after_transform(text)
Expand Down Expand Up @@ -59,7 +59,7 @@ def after_transform(text)
:cite => 'quote',
}.each do |m, env|
define_method(m) do |opts|
"\\begin{#{env}}#{opts[:text]}\\end{#{env}}"
begin_chunk(env) + opts[:text] + end_chunk(env)
end
end

Expand Down Expand Up @@ -123,11 +123,11 @@ def table_close(opts)

def bc_open(opts)
opts[:block] = true
"\\begin{verbatim}\n"
begin_chunk("verbatim") + "\n"
end

def bc_close(opts)
"\\end{verbatim}\n"
end_chunk("verbatim") + "\n"
end

def bq_open(opts)
Expand Down Expand Up @@ -210,4 +210,22 @@ def dim(opts)
"#{opts[:x]}#{space}\\texttimes{}#{space}"
end

private

def begin_chunk(type)
chunk_counter[type] += 1
return "\\begin{#{type}}" if 1 == chunk_counter[type]
''
end

def end_chunk(type)
chunk_counter[type] -= 1
raise RuntimeError, "Bad latex #{type} nesting detected" if chunk_counter[type] < 0 # This should never need to happen
return "\\end{#{type}}" if 0 == chunk_counter[type]
''
end

def chunk_counter
@chunk_counter ||= Hash.new 0
end
end
2 changes: 1 addition & 1 deletion test/code.yml
Expand Up @@ -41,7 +41,7 @@ name: escaping of existing entities in blockcode
in: "bc. Math fact: 3 &lt; 5 &amp; 5 &gt; 3 but &pound;5 &#62; $5.
"
html: "<pre><code>Math fact: 3 &amp;lt; 5 &amp;amp; 5 &amp;gt; 3 but &amp;pound;5 &amp;#62; $5.</code></pre>"
latex: "\\begin{verbatim}\n\\begin{verbatim}Math fact: 3 \\&lt; 5 \\&amp; 5 \\&gt; 3 but \\&pound;5 \\&\\#62; \\$5. \\\\\\end{verbatim}\\end{verbatim}\n"
latex: "\\begin{verbatim}\nMath fact: 3 &lt; 5 &amp; 5 &gt; 3 but &pound;5 &#62; $5.\\end{verbatim}\n"
---
name: no formatting within pre
in: |-
Expand Down

0 comments on commit ae2ac5d

Please sign in to comment.