Skip to content

Commit

Permalink
To enable LaTeX section and paragraph alignments.
Browse files Browse the repository at this point in the history
Note: Not DRY yet. [#137 state:resolved]
  • Loading branch information
kleb committed Apr 26, 2009
1 parent be5d0fa commit 1caa1b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/redcloth/formatters/latex.rb
Expand Up @@ -3,7 +3,7 @@
module RedCloth::Formatters::LATEX
include RedCloth::Formatters::Base

ENTITIES = YAML::load(File.read(File.dirname(__FILE__)+'/latex_entities.yml'))
ENTITIES = YAML::load(File.read(File.dirname(__FILE__)+'/latex_entities.yml'))

module Settings
# Maps CSS style names to latex formatting options
Expand All @@ -23,7 +23,16 @@ def latex_image_styles
:h6 => 'textbf',
}.each do |m,tag|
define_method(m) do |opts|
"\\#{tag}{#{opts[:text]}}\n\n"
case opts[:align]
when 'left' then
"\\begin{flushleft}\\#{tag}{#{opts[:text]}}\\end{flushleft}\n\n"
when 'right' then
"\\begin{flushright}\\#{tag}{#{opts[:text]}}\\end{flushright}\n\n"
when 'center' then
"\\begin{center}\\#{tag}{#{opts[:text]}}\\end{center}\n\n"
else
"\\#{tag}{#{opts[:text]}}\n\n"
end
end
end

Expand Down Expand Up @@ -101,7 +110,16 @@ def li_close(opts=nil)

# paragraphs
def p(opts)
opts[:text] + "\n\n"
case opts[:align]
when 'left' then
"\\begin{flushleft}#{opts[:text]}\\end{flushleft}\n\n"
when 'right' then
"\\begin{flushright}#{opts[:text]}\\end{flushright}\n\n"
when 'center' then
"\\begin{center}#{opts[:text]}\\end{center}\n\n"
else
"#{opts[:text]}\n\n"
end
end

# tables
Expand Down
5 changes: 5 additions & 0 deletions test/textism.yml
Expand Up @@ -163,6 +163,10 @@ html: <p><span lang="fr">rouge</span></p>
in: _(big)red_
html: <p><em class="big">red</em></p>
---
in: p=. A centered paragraph.
html: <p style="text-align:center;">A centered paragraph.</p>
latex: "\\begin{center}A centered paragraph.\\end{center}\n\n"
---
in: p(bob). A paragraph
html: <p class="bob">A paragraph</p>
---
Expand All @@ -177,6 +181,7 @@ html: <h2 style="padding-left:1em;padding-right:1em;text-align:right;">right-ali
---
in: h3=. centered header
html: <h3 style="text-align:center;">centered header</h3>
latex: "\\begin{center}\\subsubsection{centered header}\\end{center}\n\n"
---
in: '!>/image.gif! right-aligned image'
html: <p style="float:right;"><img src="/image.gif" alt="" /> right-aligned image</p>
Expand Down

0 comments on commit 1caa1b2

Please sign in to comment.