diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-11-15 03:11:33 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-11-15 03:11:33 +0000 |
commit | 851c04dfcd21968b157b544c54144fe39e33db38 (patch) | |
tree | 1a5ba6474b6a63cf383fce525cc117e38d37a038 | |
parent | e73c3d3561a743e0687536695e8241e9eaa3f565 (diff) | |
download | pandoc-851c04dfcd21968b157b544c54144fe39e33db38.tar.gz |
Improved footnote handling in LaTeX writer:
+ use wrapTeXIfNeeded instead of wrapIfNeeded
+ make sure footnotes occur on lines by themselves, with a % at the
end of the preceding line to prevent unwanted spaces
+ added writer options to state, so it can be accessed by wrapTeXIfNeeded
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1071 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index f64e06e24..dd290569f 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -38,9 +38,11 @@ import Control.Monad.State import Text.PrettyPrint.HughesPJ hiding ( Str ) data WriterState = - WriterState { stIncludes :: S.Set String -- strings to include in header - , stInNote :: Bool -- @True@ if we're in a note - , stOLLevel :: Int } -- level of ordered list nesting + WriterState { stIncludes :: S.Set String -- strings to include in header + , stInNote :: Bool -- @True@ if we're in a note + , stOLLevel :: Int -- level of ordered list nesting + , stOptions :: WriterOptions -- writer options, so they don't have to be parameter + } -- | Add line to header. addToHeader :: String -> State WriterState () @@ -53,7 +55,7 @@ addToHeader str = do writeLaTeX :: WriterOptions -> Pandoc -> String writeLaTeX options document = render $ evalState (pandocToLaTeX options document) $ - WriterState { stIncludes = S.empty, stInNote = False, stOLLevel = 1 } + WriterState { stIncludes = S.empty, stInNote = False, stOLLevel = 1, stOptions = options } pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState Doc pandocToLaTeX options (Pandoc meta blocks) = do @@ -132,9 +134,15 @@ deVerb (other:rest) = other:(deVerb rest) blockToLaTeX :: Block -- ^ Block to convert -> State WriterState Doc blockToLaTeX Null = return empty -blockToLaTeX (Plain lst) = wrapped inlineListToLaTeX lst >>= return -blockToLaTeX (Para lst) = - wrapped inlineListToLaTeX lst >>= return . (<> char '\n') +blockToLaTeX (Plain lst) = do + st <- get + let opts = stOptions st + wrapTeXIfNeeded opts inlineListToLaTeX lst +blockToLaTeX (Para lst) = do + st <- get + let opts = stOptions st + result <- wrapTeXIfNeeded opts inlineListToLaTeX lst + return $ result <> char '\n' blockToLaTeX (BlockQuote lst) = do contents <- blockListToLaTeX lst return $ text "\\begin{quote}" $$ contents $$ text "\\end{quote}" @@ -306,5 +314,5 @@ inlineToLaTeX (Note contents) = do let rawnote = stripTrailingNewlines $ render contents' -- note: a \n before } is needed when note ends with a Verbatim environment let optNewline = "\\end{Verbatim}" `isSuffixOf` rawnote - return $ text "%\n\\footnote{" <> + return $ text "\\footnote{" <> text rawnote <> (if optNewline then char '\n' else empty) <> char '}' |