Skip to content

Commit

Permalink
To add \centering to LaTeX float environments.
Browse files Browse the repository at this point in the history
  • Loading branch information
kleb committed Mar 7, 2009
1 parent 4b6bae2 commit 9715b8e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/redcloth/formatters/latex.rb
Expand Up @@ -136,12 +136,16 @@ def table_open(opts)
return ""
end

# FIXME: need caption and label elements similar to image -> figure
def table_close(opts)
output = "\\begin{table}\n \\begin{tabular}{ #{"l " * @table[0].size }}\n"
output = "\\begin{table}\n"
output << " \\centering\n"
output << " \\begin{tabular}{ #{"l " * @table[0].size }}\n"
@table.each do |row|
output << " #{row.join(" & ")} \\\\\n"
end
output << " \\end{tabular}\n\\end{table}\n"
output << " \\end{tabular}\n"
output << "\\end{table}\n"
output
end

Expand Down Expand Up @@ -180,6 +184,7 @@ def image(opts)
styling = opts[:class].to_s.split(/\s+/).collect { |style| latex_image_styles[style] }.compact.join ','
# Build latex code
[ "\\begin{figure}",
" \\centering",
" \\includegraphics[#{styling}]{#{opts[:src]}}",
(" \\caption{#{escape opts[:title]}}" if opts[:title]),
(" \\label{#{escape opts[:alt]}}" if opts[:alt]),
Expand Down
5 changes: 5 additions & 0 deletions test/images.yml
Expand Up @@ -3,6 +3,7 @@ in: This is an !image.jpg!
html: <p>This is an <img src="image.jpg" alt="" /></p>
latex: |+
This is an \begin{figure}
\centering
\includegraphics[]{image.jpg}
\end{figure}
Expand All @@ -11,6 +12,7 @@ in: This is an !image.jpg(with alt text)!
html: <p>This is an <img src="image.jpg" title="with alt text" alt="with alt text" /></p>
latex: |+
This is an \begin{figure}
\centering
\includegraphics[]{image.jpg}
\caption{with alt text}
\end{figure}
Expand Down Expand Up @@ -193,6 +195,7 @@ in: "!../../image.jpg!"
html: <p><img src="../../image.jpg" alt="" /></p>
latex: |+
\begin{figure}
\centering
\includegraphics[]{../../image.jpg}
\end{figure}
Expand Down Expand Up @@ -226,6 +229,7 @@ in: "!/pictures/cat_and_fox.jpg(Trady Blix & The cartoon fox)!"
html: '<p><img src="/pictures/cat_and_fox.jpg" title="Trady Blix &amp; The cartoon fox" alt="Trady Blix &amp; The cartoon fox" /></p>'
latex: |+
\begin{figure}
\centering
\includegraphics[]{/pictures/cat_and_fox.jpg}
\caption{Trady Blix \& The cartoon fox}
\end{figure}
Expand All @@ -236,6 +240,7 @@ in: '!/pictures/bacon.jpg(The fox said: "Have some chunky bacon")!'
html: '<p><img src="/pictures/bacon.jpg" title="The fox said: &quot;Have some chunky bacon&quot;" alt="The fox said: &quot;Have some chunky bacon&quot;" /></p>'
latex: |+
\begin{figure}
\centering
\includegraphics[]{/pictures/bacon.jpg}
\caption{The fox said: "Have some chunky bacon"}
\end{figure}
Expand Down
4 changes: 4 additions & 0 deletions test/table.yml
Expand Up @@ -20,6 +20,7 @@ html: |-
<h3>A header after the table</h3>
latex: |+
\begin{table}
\centering
\begin{tabular}{ l l l }
a & b & c \\
1 & 2 & 3 \\
Expand Down Expand Up @@ -67,6 +68,7 @@ html: |-
</table>
latex: |+
\begin{table}
\centering
\begin{tabular}{ l l l l l }
This & is & a & simple & table \\
This & is & a & simple & row \\
Expand Down Expand Up @@ -188,6 +190,7 @@ html: |-
</table>
latex: |+
\begin{table}
\centering
\begin{tabular}{ l l }
Cell with gray background & Normal cell \\
\multicolumn{2}{ l l }{Cell spanning 2 columns} \\
Expand Down Expand Up @@ -232,6 +235,7 @@ html: |-
</table>
latex: |+
\begin{table}
\centering
\begin{tabular}{ l l l }
1 & 2 & 3 \\
1 & \multirow{3}{*}{2} & 3 \\
Expand Down
1 change: 1 addition & 0 deletions test/textism.yml
Expand Up @@ -205,6 +205,7 @@ html: |-
</table>
latex: |
\begin{table}
\centering
\begin{tabular}{ l l l l l }
This & is & a & simple & table \\
This & is & a & simple & row \\
Expand Down

0 comments on commit 9715b8e

Please sign in to comment.