[Fix] Inline latex formula alignment
Fixed an issue of latex inline formulas not aligning correctly with the text. The fix is a ruby translation of the Perl code described in http://tex.stackexchange.com/questions/44486/pixel-perfect-vertical-alignment-of-image-rendered-tex-snippets. This code calculates the alignment of the generated image depending on the image size and the size of the white space between the formula and the margins of the image. The alignment now is nearly perfect, however the new rendering comes with a performance impact because of the increased number of operations. To reduce this impact, the generated images and calculated values for the alignment are now cached in `~/.cache/gollum`. The caching is done per formula and not per page, thus avoiding caching the same formula twice. The Readme and tests have been modified accordingly with the new tool requirements and expected markup.
This commit is contained in:
+16
-1
@@ -146,7 +146,22 @@ module Gollum
|
||||
def process_tex(data)
|
||||
@texmap.each do |id, spec|
|
||||
type, tex = *spec
|
||||
out = %{<img src="#{::File.join(@wiki.base_path, '_tex.png')}?type=#{type}&data=#{Base64.encode64(tex).chomp}" alt="#{CGI.escapeHTML(tex)}">}
|
||||
|
||||
# Obtain the formula with parameters
|
||||
out = nil
|
||||
begin
|
||||
width, height, align, base64 = Gollum::Tex.render_formula(tex, true)
|
||||
|
||||
# TODO: Should we load the binary inside the html?
|
||||
#out = %{<img width="#{width}" height="#{height}" style="vertical-align: #{align}px;" src="data:image/png;base64,\n#{base64}" alt="#{CGI.escapeHTML(tex)}" />}
|
||||
|
||||
# Use the alignment values from the formula rendering but still use the call to '_tex.png'. Although it will call render_formula()
|
||||
# again, it will use the already cached formula and it might have some advantages from the point of view of browser caching (really not sure here).
|
||||
out = %{<img width="#{width}" height="#{height}" style="vertical-align: #{align}px;" src="#{::File.join(@wiki.base_path, '_tex.png')}?type=#{type}&data=#{Base64.encode64(tex).chomp}" alt="#{CGI.escapeHTML(tex)}" />}
|
||||
rescue # In case of error
|
||||
out = CGI.escapeHTML(tex)
|
||||
end
|
||||
|
||||
data.gsub!(id, out)
|
||||
end
|
||||
data
|
||||
|
||||
Reference in New Issue
Block a user