2006-12-20 20:54:23 +00:00
|
|
|
{-
|
2007-07-07 22:51:55 +00:00
|
|
|
Copyright (C) 2006-7 John MacFarlane <jgm@berkeley.edu>
|
2006-12-20 20:54:23 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
-}
|
|
|
|
|
2006-12-20 06:50:14 +00:00
|
|
|
{- |
|
|
|
|
Module : Text.Pandoc.Writers.LaTeX
|
2007-07-07 22:51:55 +00:00
|
|
|
Copyright : Copyright (C) 2006-7 John MacFarlane
|
2006-12-20 06:50:14 +00:00
|
|
|
License : GNU GPL, version 2 or above
|
|
|
|
|
2007-07-07 22:51:55 +00:00
|
|
|
Maintainer : John MacFarlane <jgm@berkeley.edu>
|
2006-12-20 20:20:10 +00:00
|
|
|
Stability : alpha
|
2006-12-20 06:50:14 +00:00
|
|
|
Portability : portable
|
|
|
|
|
|
|
|
Conversion of 'Pandoc' format into LaTeX.
|
|
|
|
-}
|
2006-10-17 14:22:29 +00:00
|
|
|
module Text.Pandoc.Writers.LaTeX (
|
|
|
|
writeLaTeX
|
|
|
|
) where
|
|
|
|
import Text.Pandoc.Definition
|
|
|
|
import Text.Pandoc.Shared
|
2007-01-15 19:52:42 +00:00
|
|
|
import Text.Printf ( printf )
|
2007-07-23 23:14:26 +00:00
|
|
|
import Data.List ( (\\), isInfixOf )
|
2007-07-28 01:10:04 +00:00
|
|
|
import Data.Char ( isAlphaNum )
|
2007-07-22 16:05:38 +00:00
|
|
|
import qualified Data.Set as S
|
|
|
|
import Control.Monad.State
|
|
|
|
|
2007-07-28 01:40:48 +00:00
|
|
|
data WriterState =
|
|
|
|
WriterState { stIncludes :: S.Set String -- strings to include in header
|
|
|
|
, stInNote :: Bool } -- @True@ if we're in a note
|
2007-07-22 16:05:38 +00:00
|
|
|
|
|
|
|
-- | Add line to header.
|
|
|
|
addToHeader :: String -> State WriterState ()
|
2007-07-28 01:40:48 +00:00
|
|
|
addToHeader str = do
|
|
|
|
st <- get
|
|
|
|
let includes = stIncludes st
|
|
|
|
put st {stIncludes = S.insert str includes}
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
-- | Convert Pandoc to LaTeX.
|
|
|
|
writeLaTeX :: WriterOptions -> Pandoc -> String
|
2007-07-22 16:05:38 +00:00
|
|
|
writeLaTeX options document =
|
2007-07-28 01:40:48 +00:00
|
|
|
evalState (pandocToLaTeX options document) $
|
|
|
|
WriterState { stIncludes = S.empty, stInNote = False }
|
2007-07-22 16:05:38 +00:00
|
|
|
|
|
|
|
pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
|
|
|
|
pandocToLaTeX options (Pandoc meta blocks) = do
|
|
|
|
main <- blockListToLaTeX blocks
|
|
|
|
head <- if writerStandalone options
|
|
|
|
then latexHeader options meta
|
|
|
|
else return ""
|
|
|
|
let body = writerIncludeBefore options ++ main ++
|
|
|
|
writerIncludeAfter options
|
|
|
|
let toc = if writerTableOfContents options
|
|
|
|
then "\\tableofcontents\n\n"
|
|
|
|
else ""
|
|
|
|
let foot = if writerStandalone options
|
2007-07-08 03:48:07 +00:00
|
|
|
then "\n\\end{document}\n"
|
|
|
|
else ""
|
2007-07-22 16:05:38 +00:00
|
|
|
return $ head ++ toc ++ body ++ foot
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
-- | Insert bibliographic information into LaTeX header.
|
Extensive changes stemming from a rethinking of the Pandoc data
structure. Key and Note blocks have been removed. Link and image URLs
are now stored directly in Link and Image inlines, and note blocks
are stored in Note inlines. This requires changes in both parsers
and writers. Markdown and RST parsers need to extract data from key
and note blocks and insert them into the relevant inline elements.
Other parsers can be simplified, since there is no longer any need to
construct separate key and note blocks. Markdown, RST, and HTML writers
need to construct lists of notes; Markdown and RST writers need to
construct lists of link references (when the --reference-links option
is specified); and the RST writer needs to construct a list of image
substitution references. All writers have been rewritten to use the
State monad when state is required. This rewrite yields a small speed
boost and considerably cleaner code.
* Text/Pandoc/Definition.hs:
+ blocks: removed Key and Note
+ inlines: removed NoteRef, added Note
+ modified Target: there is no longer a 'Ref' target; all targets
are explicit URL, title pairs
* Text/Pandoc/Shared.hs:
+ Added 'Reference', 'isNoteBlock', 'isKeyBlock', 'isLineClump',
used in some of the readers.
+ Removed 'generateReference', 'keyTable', 'replaceReferenceLinks',
'replaceRefLinksBlockList', along with some auxiliary functions
used only by them. These are no longer needed, since
reference links are resolved in the Markdown and RST readers.
+ Moved 'inTags', 'selfClosingTag', 'inTagsSimple', and 'inTagsIndented'
to the Docbook writer, since that is now the only module that uses
them.
+ Changed name of 'escapeSGMLString' to 'escapeStringForXML'
+ Added KeyTable and NoteTable types
+ Removed fields from ParserState; 'stateKeyBlocks', 'stateKeysUsed',
'stateNoteBlocks', 'stateNoteIdentifiers', 'stateInlineLinks'.
Added 'stateKeys' and 'stateNotes'.
+ Added clause for Note to 'prettyBlock'.
+ Added 'writerNotes', 'writerReferenceLinks' fields to WriterOptions.
* Text/Pandoc/Entities.hs: Renamed 'escapeSGMLChar' and
'escapeSGMLString' to 'escapeCharForXML' and 'escapeStringForXML'
* Text/ParserCombinators/Pandoc.hs: Added lineClump parser: parses a raw
line block up to and including following blank lines.
* Main.hs: Replaced --inline-links with --reference-links.
* README:
+ Documented --reference-links and removed description of --inline-links.
+ Added note that footnotes may occur anywhere in the document, but must
be at the outer level, not embedded in block elements.
* man/man1/pandoc.1, man/man1/html2markdown.1: Removed --inline-links
option, added --reference-links option
* Markdown and RST readers:
+ Rewrote to fit new Pandoc definition. Since there are no longer
Note or Key blocks, all note and key blocks are parsed on a first pass
through the document. Once tables of notes and keys have been constructed,
the remaining parts of the document are reassembled and parsed.
+ Refactored link parsers.
* LaTeX and HTML readers: Rewrote to fit new Pandoc definition. Since
there are no longer Note or Key blocks, notes and references can be
parsed in a single pass through the document.
* RST, Markdown, and HTML writers: Rewrote using state monad new Pandoc
and definition. State is used to hold lists of references footnotes to
and be printed at the end of the document.
* RTF and LaTeX writers: Rewrote using new Pandoc definition. (Because
of the different treatment of footnotes, the "notes" parameter is no
longer needed in the block and inline conversion functions.)
* Docbook writer:
+ Moved the functions 'attributeList', 'inTags', 'selfClosingTag',
'inTagsSimple', 'inTagsIndented' from Text/Pandoc/Shared, since
they are now used only by the Docbook writer.
+ Rewrote using new Pandoc definition. (Because of the different
treatment of footnotes, the "notes" parameter is no longer needed
in the block and inline conversion functions.)
* Updated test suite
* Throughout: old haskell98 module names replaced by hierarchical module
names, e.g. List by Data.List.
* debian/control: Include libghc6-xhtml-dev instead of libghc6-html-dev
in "Build-Depends."
* cabalize:
+ Remove haskell98 from BASE_DEPENDS (since now the new hierarchical
module names are being used throughout)
+ Added mtl to BASE_DEPENDS (needed for state monad)
+ Removed html from GHC66_DEPENDS (not needed since xhtml is now used)
git-svn-id: https://pandoc.googlecode.com/svn/trunk@580 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-04-10 01:56:50 +00:00
|
|
|
latexHeader :: WriterOptions -- ^ Options, including LaTeX header
|
2006-12-20 06:50:14 +00:00
|
|
|
-> Meta -- ^ Meta with bibliographic information
|
2007-07-22 16:05:38 +00:00
|
|
|
-> State WriterState String
|
|
|
|
latexHeader options (Meta title authors date) = do
|
|
|
|
titletext <- if null title
|
|
|
|
then return ""
|
|
|
|
else do title' <- inlineListToLaTeX title
|
|
|
|
return $ "\\title{" ++ title' ++ "}\n"
|
2007-07-28 01:40:48 +00:00
|
|
|
extras <- get >>= (return . unlines . S.toList. stIncludes)
|
|
|
|
let verbatim = if "\\usepackage{fancyvrb}" `isInfixOf` extras
|
|
|
|
then "\\VerbatimFootnotes % allows verbatim text in footnotes\n"
|
|
|
|
else ""
|
2007-07-26 03:49:21 +00:00
|
|
|
let authorstext = "\\author{" ++ (joinWithSep "\\\\"
|
|
|
|
(map stringToLaTeX authors)) ++ "}\n"
|
2007-07-22 16:05:38 +00:00
|
|
|
let datetext = if date == ""
|
|
|
|
then ""
|
|
|
|
else "\\date{" ++ stringToLaTeX date ++ "}\n"
|
2007-07-23 23:14:26 +00:00
|
|
|
let maketitle = if null title then "" else "\\maketitle\n"
|
2007-07-22 16:05:38 +00:00
|
|
|
let secnumline = if (writerNumberSections options)
|
2006-12-20 06:50:14 +00:00
|
|
|
then ""
|
|
|
|
else "\\setcounter{secnumdepth}{0}\n"
|
2007-07-22 16:05:38 +00:00
|
|
|
let baseHeader = writerHeader options
|
2007-07-23 23:14:26 +00:00
|
|
|
let header = baseHeader ++ extras
|
2007-07-28 01:40:48 +00:00
|
|
|
return $ header ++ secnumline ++ verbatim ++ titletext ++ authorstext ++
|
2007-07-26 03:15:35 +00:00
|
|
|
datetext ++ "\\begin{document}\n" ++ maketitle ++ "\n"
|
2006-10-17 14:22:29 +00:00
|
|
|
|
2007-07-14 17:28:26 +00:00
|
|
|
-- escape things as needed for LaTeX
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
stringToLaTeX :: String -> String
|
2007-07-22 16:05:38 +00:00
|
|
|
stringToLaTeX = escapeStringUsing latexEscapes
|
2007-07-22 18:24:34 +00:00
|
|
|
where latexEscapes = backslashEscapes "{}$%&_#" ++
|
|
|
|
[ ('^', "\\^{}")
|
|
|
|
, ('\\', "\\textbackslash{}")
|
|
|
|
, ('~', "\\ensuremath{\\sim}")
|
|
|
|
, ('|', "\\textbar{}")
|
|
|
|
, ('<', "\\textless{}")
|
|
|
|
, ('>', "\\textgreater{}")
|
|
|
|
]
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
-- | Remove all code elements from list of inline elements
|
2007-07-28 01:10:04 +00:00
|
|
|
-- (because it's illegal to have verbatim inside some command arguments)
|
2006-10-17 14:22:29 +00:00
|
|
|
deVerb :: [Inline] -> [Inline]
|
|
|
|
deVerb [] = []
|
2007-07-22 16:05:38 +00:00
|
|
|
deVerb ((Code str):rest) =
|
2007-07-28 01:10:04 +00:00
|
|
|
(TeX $ "\\texttt{" ++ stringToLaTeX str ++ "}"):(deVerb rest)
|
2006-10-17 14:22:29 +00:00
|
|
|
deVerb (other:rest) = other:(deVerb rest)
|
|
|
|
|
|
|
|
-- | Convert Pandoc block element to LaTeX.
|
Extensive changes stemming from a rethinking of the Pandoc data
structure. Key and Note blocks have been removed. Link and image URLs
are now stored directly in Link and Image inlines, and note blocks
are stored in Note inlines. This requires changes in both parsers
and writers. Markdown and RST parsers need to extract data from key
and note blocks and insert them into the relevant inline elements.
Other parsers can be simplified, since there is no longer any need to
construct separate key and note blocks. Markdown, RST, and HTML writers
need to construct lists of notes; Markdown and RST writers need to
construct lists of link references (when the --reference-links option
is specified); and the RST writer needs to construct a list of image
substitution references. All writers have been rewritten to use the
State monad when state is required. This rewrite yields a small speed
boost and considerably cleaner code.
* Text/Pandoc/Definition.hs:
+ blocks: removed Key and Note
+ inlines: removed NoteRef, added Note
+ modified Target: there is no longer a 'Ref' target; all targets
are explicit URL, title pairs
* Text/Pandoc/Shared.hs:
+ Added 'Reference', 'isNoteBlock', 'isKeyBlock', 'isLineClump',
used in some of the readers.
+ Removed 'generateReference', 'keyTable', 'replaceReferenceLinks',
'replaceRefLinksBlockList', along with some auxiliary functions
used only by them. These are no longer needed, since
reference links are resolved in the Markdown and RST readers.
+ Moved 'inTags', 'selfClosingTag', 'inTagsSimple', and 'inTagsIndented'
to the Docbook writer, since that is now the only module that uses
them.
+ Changed name of 'escapeSGMLString' to 'escapeStringForXML'
+ Added KeyTable and NoteTable types
+ Removed fields from ParserState; 'stateKeyBlocks', 'stateKeysUsed',
'stateNoteBlocks', 'stateNoteIdentifiers', 'stateInlineLinks'.
Added 'stateKeys' and 'stateNotes'.
+ Added clause for Note to 'prettyBlock'.
+ Added 'writerNotes', 'writerReferenceLinks' fields to WriterOptions.
* Text/Pandoc/Entities.hs: Renamed 'escapeSGMLChar' and
'escapeSGMLString' to 'escapeCharForXML' and 'escapeStringForXML'
* Text/ParserCombinators/Pandoc.hs: Added lineClump parser: parses a raw
line block up to and including following blank lines.
* Main.hs: Replaced --inline-links with --reference-links.
* README:
+ Documented --reference-links and removed description of --inline-links.
+ Added note that footnotes may occur anywhere in the document, but must
be at the outer level, not embedded in block elements.
* man/man1/pandoc.1, man/man1/html2markdown.1: Removed --inline-links
option, added --reference-links option
* Markdown and RST readers:
+ Rewrote to fit new Pandoc definition. Since there are no longer
Note or Key blocks, all note and key blocks are parsed on a first pass
through the document. Once tables of notes and keys have been constructed,
the remaining parts of the document are reassembled and parsed.
+ Refactored link parsers.
* LaTeX and HTML readers: Rewrote to fit new Pandoc definition. Since
there are no longer Note or Key blocks, notes and references can be
parsed in a single pass through the document.
* RST, Markdown, and HTML writers: Rewrote using state monad new Pandoc
and definition. State is used to hold lists of references footnotes to
and be printed at the end of the document.
* RTF and LaTeX writers: Rewrote using new Pandoc definition. (Because
of the different treatment of footnotes, the "notes" parameter is no
longer needed in the block and inline conversion functions.)
* Docbook writer:
+ Moved the functions 'attributeList', 'inTags', 'selfClosingTag',
'inTagsSimple', 'inTagsIndented' from Text/Pandoc/Shared, since
they are now used only by the Docbook writer.
+ Rewrote using new Pandoc definition. (Because of the different
treatment of footnotes, the "notes" parameter is no longer needed
in the block and inline conversion functions.)
* Updated test suite
* Throughout: old haskell98 module names replaced by hierarchical module
names, e.g. List by Data.List.
* debian/control: Include libghc6-xhtml-dev instead of libghc6-html-dev
in "Build-Depends."
* cabalize:
+ Remove haskell98 from BASE_DEPENDS (since now the new hierarchical
module names are being used throughout)
+ Added mtl to BASE_DEPENDS (needed for state monad)
+ Removed html from GHC66_DEPENDS (not needed since xhtml is now used)
git-svn-id: https://pandoc.googlecode.com/svn/trunk@580 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-04-10 01:56:50 +00:00
|
|
|
blockToLaTeX :: Block -- ^ Block to convert
|
2007-07-22 16:05:38 +00:00
|
|
|
-> State WriterState String
|
|
|
|
blockToLaTeX Null = return ""
|
|
|
|
blockToLaTeX (Plain lst) = (inlineListToLaTeX lst) >>= (return . (++ "\n"))
|
|
|
|
blockToLaTeX (Para lst) = (inlineListToLaTeX lst) >>= (return . (++ "\n\n"))
|
|
|
|
blockToLaTeX (BlockQuote lst) = do
|
|
|
|
contents <- blockListToLaTeX lst
|
|
|
|
return $ "\\begin{quote}\n" ++ contents ++ "\\end{quote}\n"
|
2007-07-28 01:40:48 +00:00
|
|
|
blockToLaTeX (CodeBlock str) = do
|
|
|
|
st <- get
|
|
|
|
let verbEnv = if stInNote st then "Verbatim" else "verbatim"
|
|
|
|
return $ "\\begin{" ++ verbEnv ++ "}\n" ++ str ++
|
|
|
|
"\n\\end{" ++ verbEnv ++ "}\n"
|
2007-07-22 16:05:38 +00:00
|
|
|
blockToLaTeX (RawHtml str) = return ""
|
|
|
|
blockToLaTeX (BulletList lst) = do
|
|
|
|
items <- mapM listItemToLaTeX lst
|
|
|
|
return $ "\\begin{itemize}\n" ++ concat items ++ "\\end{itemize}\n"
|
|
|
|
blockToLaTeX (OrderedList lst) = do
|
|
|
|
items <- mapM listItemToLaTeX lst
|
|
|
|
return $ "\\begin{enumerate}\n" ++ concat items ++ "\\end{enumerate}\n"
|
|
|
|
blockToLaTeX (DefinitionList lst) = do
|
|
|
|
items <- mapM defListItemToLaTeX lst
|
|
|
|
return $ "\\begin{description}\n" ++ concat items ++ "\\end{description}\n"
|
|
|
|
blockToLaTeX HorizontalRule = return $
|
2006-12-20 06:50:14 +00:00
|
|
|
"\\begin{center}\\rule{3in}{0.4pt}\\end{center}\n\n"
|
2007-07-22 16:05:38 +00:00
|
|
|
blockToLaTeX (Header level lst) = do
|
|
|
|
text <- inlineListToLaTeX (deVerb lst)
|
|
|
|
return $ if (level > 0) && (level <= 3)
|
|
|
|
then "\\" ++ (concat (replicate (level - 1) "sub")) ++
|
|
|
|
"section{" ++ text ++ "}\n\n"
|
|
|
|
else text ++ "\n\n"
|
|
|
|
blockToLaTeX (Table caption aligns widths heads rows) = do
|
|
|
|
headers <- tableRowToLaTeX heads
|
|
|
|
captionText <- inlineListToLaTeX caption
|
|
|
|
rows' <- mapM tableRowToLaTeX rows
|
|
|
|
let colWidths = map (printf "%.2f") widths
|
|
|
|
let colDescriptors = concat $ zipWith
|
|
|
|
(\width align -> ">{\\PBS" ++
|
|
|
|
(case align of
|
|
|
|
AlignLeft -> "\\raggedright"
|
|
|
|
AlignRight -> "\\raggedleft"
|
|
|
|
AlignCenter -> "\\centering"
|
|
|
|
AlignDefault -> "\\raggedright") ++
|
|
|
|
"\\hspace{0pt}}p{" ++ width ++
|
2007-07-28 01:10:04 +00:00
|
|
|
"\\columnwidth}")
|
2007-07-22 16:05:38 +00:00
|
|
|
colWidths aligns
|
|
|
|
let tableBody = "\\begin{tabular}{" ++ colDescriptors ++ "}\n" ++
|
|
|
|
headers ++ "\\hline\n" ++ concat rows' ++ "\\end{tabular}\n"
|
|
|
|
let centered str = "\\begin{center}\n" ++ str ++ "\\end{center}\n"
|
|
|
|
addToHeader "\\usepackage{array}\n\
|
2007-07-23 23:14:26 +00:00
|
|
|
\% This is needed because raggedright in table elements redefines \\\\:\n\
|
2007-07-22 16:05:38 +00:00
|
|
|
\\\newcommand{\\PreserveBackslash}[1]{\\let\\temp=\\\\#1\\let\\\\=\\temp}\n\
|
|
|
|
\\\let\\PBS=\\PreserveBackslash"
|
|
|
|
return $ if null captionText
|
|
|
|
then centered tableBody ++ "\n"
|
|
|
|
else "\\begin{table}[h]\n" ++ centered tableBody ++ "\\caption{" ++
|
|
|
|
captionText ++ "}\n" ++ "\\end{table}\n\n"
|
|
|
|
|
|
|
|
blockListToLaTeX lst = mapM blockToLaTeX lst >>= (return . concat)
|
|
|
|
|
|
|
|
tableRowToLaTeX cols =
|
|
|
|
mapM blockListToLaTeX cols >>= (return . (++ "\\\\\n") . (joinWithSep " & "))
|
|
|
|
|
|
|
|
listItemToLaTeX lst = blockListToLaTeX lst >>= (return . ("\\item "++))
|
|
|
|
|
|
|
|
defListItemToLaTeX (term, def) = do
|
2007-07-28 01:10:04 +00:00
|
|
|
term' <- inlineListToLaTeX term
|
2007-07-22 16:05:38 +00:00
|
|
|
def' <- blockListToLaTeX def
|
2007-07-26 03:15:35 +00:00
|
|
|
return $ "\\item[" ++ term' ++ "] " ++ def'
|
2006-10-17 14:22:29 +00:00
|
|
|
|
|
|
|
-- | Convert list of inline elements to LaTeX.
|
Extensive changes stemming from a rethinking of the Pandoc data
structure. Key and Note blocks have been removed. Link and image URLs
are now stored directly in Link and Image inlines, and note blocks
are stored in Note inlines. This requires changes in both parsers
and writers. Markdown and RST parsers need to extract data from key
and note blocks and insert them into the relevant inline elements.
Other parsers can be simplified, since there is no longer any need to
construct separate key and note blocks. Markdown, RST, and HTML writers
need to construct lists of notes; Markdown and RST writers need to
construct lists of link references (when the --reference-links option
is specified); and the RST writer needs to construct a list of image
substitution references. All writers have been rewritten to use the
State monad when state is required. This rewrite yields a small speed
boost and considerably cleaner code.
* Text/Pandoc/Definition.hs:
+ blocks: removed Key and Note
+ inlines: removed NoteRef, added Note
+ modified Target: there is no longer a 'Ref' target; all targets
are explicit URL, title pairs
* Text/Pandoc/Shared.hs:
+ Added 'Reference', 'isNoteBlock', 'isKeyBlock', 'isLineClump',
used in some of the readers.
+ Removed 'generateReference', 'keyTable', 'replaceReferenceLinks',
'replaceRefLinksBlockList', along with some auxiliary functions
used only by them. These are no longer needed, since
reference links are resolved in the Markdown and RST readers.
+ Moved 'inTags', 'selfClosingTag', 'inTagsSimple', and 'inTagsIndented'
to the Docbook writer, since that is now the only module that uses
them.
+ Changed name of 'escapeSGMLString' to 'escapeStringForXML'
+ Added KeyTable and NoteTable types
+ Removed fields from ParserState; 'stateKeyBlocks', 'stateKeysUsed',
'stateNoteBlocks', 'stateNoteIdentifiers', 'stateInlineLinks'.
Added 'stateKeys' and 'stateNotes'.
+ Added clause for Note to 'prettyBlock'.
+ Added 'writerNotes', 'writerReferenceLinks' fields to WriterOptions.
* Text/Pandoc/Entities.hs: Renamed 'escapeSGMLChar' and
'escapeSGMLString' to 'escapeCharForXML' and 'escapeStringForXML'
* Text/ParserCombinators/Pandoc.hs: Added lineClump parser: parses a raw
line block up to and including following blank lines.
* Main.hs: Replaced --inline-links with --reference-links.
* README:
+ Documented --reference-links and removed description of --inline-links.
+ Added note that footnotes may occur anywhere in the document, but must
be at the outer level, not embedded in block elements.
* man/man1/pandoc.1, man/man1/html2markdown.1: Removed --inline-links
option, added --reference-links option
* Markdown and RST readers:
+ Rewrote to fit new Pandoc definition. Since there are no longer
Note or Key blocks, all note and key blocks are parsed on a first pass
through the document. Once tables of notes and keys have been constructed,
the remaining parts of the document are reassembled and parsed.
+ Refactored link parsers.
* LaTeX and HTML readers: Rewrote to fit new Pandoc definition. Since
there are no longer Note or Key blocks, notes and references can be
parsed in a single pass through the document.
* RST, Markdown, and HTML writers: Rewrote using state monad new Pandoc
and definition. State is used to hold lists of references footnotes to
and be printed at the end of the document.
* RTF and LaTeX writers: Rewrote using new Pandoc definition. (Because
of the different treatment of footnotes, the "notes" parameter is no
longer needed in the block and inline conversion functions.)
* Docbook writer:
+ Moved the functions 'attributeList', 'inTags', 'selfClosingTag',
'inTagsSimple', 'inTagsIndented' from Text/Pandoc/Shared, since
they are now used only by the Docbook writer.
+ Rewrote using new Pandoc definition. (Because of the different
treatment of footnotes, the "notes" parameter is no longer needed
in the block and inline conversion functions.)
* Updated test suite
* Throughout: old haskell98 module names replaced by hierarchical module
names, e.g. List by Data.List.
* debian/control: Include libghc6-xhtml-dev instead of libghc6-html-dev
in "Build-Depends."
* cabalize:
+ Remove haskell98 from BASE_DEPENDS (since now the new hierarchical
module names are being used throughout)
+ Added mtl to BASE_DEPENDS (needed for state monad)
+ Removed html from GHC66_DEPENDS (not needed since xhtml is now used)
git-svn-id: https://pandoc.googlecode.com/svn/trunk@580 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-04-10 01:56:50 +00:00
|
|
|
inlineListToLaTeX :: [Inline] -- ^ Inlines to convert
|
2007-07-22 16:05:38 +00:00
|
|
|
-> State WriterState String
|
Extensive changes stemming from a rethinking of the Pandoc data
structure. Key and Note blocks have been removed. Link and image URLs
are now stored directly in Link and Image inlines, and note blocks
are stored in Note inlines. This requires changes in both parsers
and writers. Markdown and RST parsers need to extract data from key
and note blocks and insert them into the relevant inline elements.
Other parsers can be simplified, since there is no longer any need to
construct separate key and note blocks. Markdown, RST, and HTML writers
need to construct lists of notes; Markdown and RST writers need to
construct lists of link references (when the --reference-links option
is specified); and the RST writer needs to construct a list of image
substitution references. All writers have been rewritten to use the
State monad when state is required. This rewrite yields a small speed
boost and considerably cleaner code.
* Text/Pandoc/Definition.hs:
+ blocks: removed Key and Note
+ inlines: removed NoteRef, added Note
+ modified Target: there is no longer a 'Ref' target; all targets
are explicit URL, title pairs
* Text/Pandoc/Shared.hs:
+ Added 'Reference', 'isNoteBlock', 'isKeyBlock', 'isLineClump',
used in some of the readers.
+ Removed 'generateReference', 'keyTable', 'replaceReferenceLinks',
'replaceRefLinksBlockList', along with some auxiliary functions
used only by them. These are no longer needed, since
reference links are resolved in the Markdown and RST readers.
+ Moved 'inTags', 'selfClosingTag', 'inTagsSimple', and 'inTagsIndented'
to the Docbook writer, since that is now the only module that uses
them.
+ Changed name of 'escapeSGMLString' to 'escapeStringForXML'
+ Added KeyTable and NoteTable types
+ Removed fields from ParserState; 'stateKeyBlocks', 'stateKeysUsed',
'stateNoteBlocks', 'stateNoteIdentifiers', 'stateInlineLinks'.
Added 'stateKeys' and 'stateNotes'.
+ Added clause for Note to 'prettyBlock'.
+ Added 'writerNotes', 'writerReferenceLinks' fields to WriterOptions.
* Text/Pandoc/Entities.hs: Renamed 'escapeSGMLChar' and
'escapeSGMLString' to 'escapeCharForXML' and 'escapeStringForXML'
* Text/ParserCombinators/Pandoc.hs: Added lineClump parser: parses a raw
line block up to and including following blank lines.
* Main.hs: Replaced --inline-links with --reference-links.
* README:
+ Documented --reference-links and removed description of --inline-links.
+ Added note that footnotes may occur anywhere in the document, but must
be at the outer level, not embedded in block elements.
* man/man1/pandoc.1, man/man1/html2markdown.1: Removed --inline-links
option, added --reference-links option
* Markdown and RST readers:
+ Rewrote to fit new Pandoc definition. Since there are no longer
Note or Key blocks, all note and key blocks are parsed on a first pass
through the document. Once tables of notes and keys have been constructed,
the remaining parts of the document are reassembled and parsed.
+ Refactored link parsers.
* LaTeX and HTML readers: Rewrote to fit new Pandoc definition. Since
there are no longer Note or Key blocks, notes and references can be
parsed in a single pass through the document.
* RST, Markdown, and HTML writers: Rewrote using state monad new Pandoc
and definition. State is used to hold lists of references footnotes to
and be printed at the end of the document.
* RTF and LaTeX writers: Rewrote using new Pandoc definition. (Because
of the different treatment of footnotes, the "notes" parameter is no
longer needed in the block and inline conversion functions.)
* Docbook writer:
+ Moved the functions 'attributeList', 'inTags', 'selfClosingTag',
'inTagsSimple', 'inTagsIndented' from Text/Pandoc/Shared, since
they are now used only by the Docbook writer.
+ Rewrote using new Pandoc definition. (Because of the different
treatment of footnotes, the "notes" parameter is no longer needed
in the block and inline conversion functions.)
* Updated test suite
* Throughout: old haskell98 module names replaced by hierarchical module
names, e.g. List by Data.List.
* debian/control: Include libghc6-xhtml-dev instead of libghc6-html-dev
in "Build-Depends."
* cabalize:
+ Remove haskell98 from BASE_DEPENDS (since now the new hierarchical
module names are being used throughout)
+ Added mtl to BASE_DEPENDS (needed for state monad)
+ Removed html from GHC66_DEPENDS (not needed since xhtml is now used)
git-svn-id: https://pandoc.googlecode.com/svn/trunk@580 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-04-10 01:56:50 +00:00
|
|
|
inlineListToLaTeX lst =
|
2007-07-22 16:05:38 +00:00
|
|
|
mapM inlineToLaTeX lst >>= (return . concat)
|
2006-10-17 14:22:29 +00:00
|
|
|
|
2007-01-24 08:14:43 +00:00
|
|
|
isQuoted :: Inline -> Bool
|
|
|
|
isQuoted (Quoted _ _) = True
|
|
|
|
isQuoted Apostrophe = True
|
|
|
|
isQuoted _ = False
|
|
|
|
|
2006-10-17 14:22:29 +00:00
|
|
|
-- | Convert inline element to LaTeX
|
Extensive changes stemming from a rethinking of the Pandoc data
structure. Key and Note blocks have been removed. Link and image URLs
are now stored directly in Link and Image inlines, and note blocks
are stored in Note inlines. This requires changes in both parsers
and writers. Markdown and RST parsers need to extract data from key
and note blocks and insert them into the relevant inline elements.
Other parsers can be simplified, since there is no longer any need to
construct separate key and note blocks. Markdown, RST, and HTML writers
need to construct lists of notes; Markdown and RST writers need to
construct lists of link references (when the --reference-links option
is specified); and the RST writer needs to construct a list of image
substitution references. All writers have been rewritten to use the
State monad when state is required. This rewrite yields a small speed
boost and considerably cleaner code.
* Text/Pandoc/Definition.hs:
+ blocks: removed Key and Note
+ inlines: removed NoteRef, added Note
+ modified Target: there is no longer a 'Ref' target; all targets
are explicit URL, title pairs
* Text/Pandoc/Shared.hs:
+ Added 'Reference', 'isNoteBlock', 'isKeyBlock', 'isLineClump',
used in some of the readers.
+ Removed 'generateReference', 'keyTable', 'replaceReferenceLinks',
'replaceRefLinksBlockList', along with some auxiliary functions
used only by them. These are no longer needed, since
reference links are resolved in the Markdown and RST readers.
+ Moved 'inTags', 'selfClosingTag', 'inTagsSimple', and 'inTagsIndented'
to the Docbook writer, since that is now the only module that uses
them.
+ Changed name of 'escapeSGMLString' to 'escapeStringForXML'
+ Added KeyTable and NoteTable types
+ Removed fields from ParserState; 'stateKeyBlocks', 'stateKeysUsed',
'stateNoteBlocks', 'stateNoteIdentifiers', 'stateInlineLinks'.
Added 'stateKeys' and 'stateNotes'.
+ Added clause for Note to 'prettyBlock'.
+ Added 'writerNotes', 'writerReferenceLinks' fields to WriterOptions.
* Text/Pandoc/Entities.hs: Renamed 'escapeSGMLChar' and
'escapeSGMLString' to 'escapeCharForXML' and 'escapeStringForXML'
* Text/ParserCombinators/Pandoc.hs: Added lineClump parser: parses a raw
line block up to and including following blank lines.
* Main.hs: Replaced --inline-links with --reference-links.
* README:
+ Documented --reference-links and removed description of --inline-links.
+ Added note that footnotes may occur anywhere in the document, but must
be at the outer level, not embedded in block elements.
* man/man1/pandoc.1, man/man1/html2markdown.1: Removed --inline-links
option, added --reference-links option
* Markdown and RST readers:
+ Rewrote to fit new Pandoc definition. Since there are no longer
Note or Key blocks, all note and key blocks are parsed on a first pass
through the document. Once tables of notes and keys have been constructed,
the remaining parts of the document are reassembled and parsed.
+ Refactored link parsers.
* LaTeX and HTML readers: Rewrote to fit new Pandoc definition. Since
there are no longer Note or Key blocks, notes and references can be
parsed in a single pass through the document.
* RST, Markdown, and HTML writers: Rewrote using state monad new Pandoc
and definition. State is used to hold lists of references footnotes to
and be printed at the end of the document.
* RTF and LaTeX writers: Rewrote using new Pandoc definition. (Because
of the different treatment of footnotes, the "notes" parameter is no
longer needed in the block and inline conversion functions.)
* Docbook writer:
+ Moved the functions 'attributeList', 'inTags', 'selfClosingTag',
'inTagsSimple', 'inTagsIndented' from Text/Pandoc/Shared, since
they are now used only by the Docbook writer.
+ Rewrote using new Pandoc definition. (Because of the different
treatment of footnotes, the "notes" parameter is no longer needed
in the block and inline conversion functions.)
* Updated test suite
* Throughout: old haskell98 module names replaced by hierarchical module
names, e.g. List by Data.List.
* debian/control: Include libghc6-xhtml-dev instead of libghc6-html-dev
in "Build-Depends."
* cabalize:
+ Remove haskell98 from BASE_DEPENDS (since now the new hierarchical
module names are being used throughout)
+ Added mtl to BASE_DEPENDS (needed for state monad)
+ Removed html from GHC66_DEPENDS (not needed since xhtml is now used)
git-svn-id: https://pandoc.googlecode.com/svn/trunk@580 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-04-10 01:56:50 +00:00
|
|
|
inlineToLaTeX :: Inline -- ^ Inline to convert
|
2007-07-22 16:05:38 +00:00
|
|
|
-> State WriterState String
|
|
|
|
inlineToLaTeX (Emph lst) = do
|
2007-07-28 01:10:04 +00:00
|
|
|
contents <- inlineListToLaTeX lst
|
2007-07-22 16:05:38 +00:00
|
|
|
return $ "\\emph{" ++ contents ++ "}"
|
|
|
|
inlineToLaTeX (Strong lst) = do
|
2007-07-28 01:10:04 +00:00
|
|
|
contents <- inlineListToLaTeX lst
|
2007-07-22 16:05:38 +00:00
|
|
|
return $ "\\textbf{" ++ contents ++ "}"
|
|
|
|
inlineToLaTeX (Strikeout lst) = do
|
2007-07-28 01:10:04 +00:00
|
|
|
contents <- inlineListToLaTeX lst
|
2007-07-22 16:05:38 +00:00
|
|
|
addToHeader "\\usepackage[normalem]{ulem}"
|
|
|
|
return $ "\\sout{" ++ contents ++ "}"
|
|
|
|
inlineToLaTeX (Superscript lst) = do
|
2007-07-28 01:10:04 +00:00
|
|
|
contents <- inlineListToLaTeX lst
|
2007-07-22 16:05:38 +00:00
|
|
|
return $ "\\textsuperscript{" ++ contents ++ "}"
|
|
|
|
inlineToLaTeX (Subscript lst) = do
|
2007-07-28 01:10:04 +00:00
|
|
|
contents <- inlineListToLaTeX lst
|
2007-07-22 16:05:38 +00:00
|
|
|
-- oddly, latex includes \textsuperscript but not \textsubscript
|
|
|
|
-- so we have to define it:
|
|
|
|
addToHeader "\\newcommand{\\textsubscript}[1]{\\ensuremath{_{\\scriptsize\\textrm{#1}}}}"
|
|
|
|
return $ "\\textsubscript{" ++ contents ++ "}"
|
2007-07-28 01:10:04 +00:00
|
|
|
inlineToLaTeX (Code str) = return $ "\\Q{" ++ stuffing ++ "}"
|
|
|
|
where stuffing = concatMap (\c -> if isAlphaNum c
|
|
|
|
then [c]
|
|
|
|
else ['\\',c]) str
|
2007-07-22 16:05:38 +00:00
|
|
|
inlineToLaTeX (Quoted SingleQuote lst) = do
|
|
|
|
contents <- inlineListToLaTeX lst
|
2007-01-24 08:14:43 +00:00
|
|
|
let s1 = if (not (null lst)) && (isQuoted (head lst)) then "\\," else ""
|
2007-07-22 16:05:38 +00:00
|
|
|
let s2 = if (not (null lst)) && (isQuoted (last lst)) then "\\," else ""
|
|
|
|
return $ "`" ++ s1 ++ contents ++ s2 ++ "'"
|
|
|
|
inlineToLaTeX (Quoted DoubleQuote lst) = do
|
|
|
|
contents <- inlineListToLaTeX lst
|
2007-01-24 08:14:43 +00:00
|
|
|
let s1 = if (not (null lst)) && (isQuoted (head lst)) then "\\," else ""
|
2007-07-22 16:05:38 +00:00
|
|
|
let s2 = if (not (null lst)) && (isQuoted (last lst)) then "\\," else ""
|
|
|
|
return $ "``" ++ s1 ++ contents ++ s2 ++ "''"
|
|
|
|
inlineToLaTeX Apostrophe = return "'"
|
|
|
|
inlineToLaTeX EmDash = return "---"
|
|
|
|
inlineToLaTeX EnDash = return "--"
|
|
|
|
inlineToLaTeX Ellipses = return "\\ldots{}"
|
|
|
|
inlineToLaTeX (Str str) = return $ stringToLaTeX str
|
|
|
|
inlineToLaTeX (TeX str) = return str
|
|
|
|
inlineToLaTeX (HtmlInline str) = return ""
|
|
|
|
inlineToLaTeX (LineBreak) = return "\\\\\n"
|
|
|
|
inlineToLaTeX Space = return " "
|
|
|
|
inlineToLaTeX (Link text (src, tit)) = do
|
|
|
|
contents <- inlineListToLaTeX (deVerb text)
|
|
|
|
addToHeader "\\usepackage[breaklinks=true]{hyperref}"
|
|
|
|
return $ "\\href{" ++ src ++ "}{" ++ contents ++ "}"
|
|
|
|
inlineToLaTeX (Image alternate (source, tit)) = do
|
|
|
|
addToHeader "\\usepackage{graphicx}"
|
|
|
|
return $ "\\includegraphics{" ++ source ++ "}"
|
|
|
|
inlineToLaTeX (Note contents) = do
|
2007-07-28 01:40:48 +00:00
|
|
|
st <- get
|
|
|
|
put (st {stInNote = True})
|
2007-07-22 16:05:38 +00:00
|
|
|
contents' <- blockListToLaTeX contents
|
2007-07-28 01:40:48 +00:00
|
|
|
st <- get
|
|
|
|
put (st {stInNote = False})
|
|
|
|
addToHeader "\\usepackage{fancyvrb}"
|
2007-07-22 16:05:38 +00:00
|
|
|
return $ "\\footnote{" ++ stripTrailingNewlines contents' ++ "}"
|