2007-11-03 23:27:58 +00:00
|
|
|
{-
|
2010-03-23 13:31:09 -07:00
|
|
|
Copyright (C) 2006-2010 John MacFarlane <jgm@berkeley.edu>
|
2007-11-03 23:27:58 +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
|
|
|
|
-}
|
|
|
|
|
|
|
|
{- |
|
|
|
|
Module : Text.Pandoc.Writers.LaTeX
|
2010-03-23 13:31:09 -07:00
|
|
|
Copyright : Copyright (C) 2006-2010 John MacFarlane
|
2007-11-03 23:27:58 +00:00
|
|
|
License : GNU GPL, version 2 or above
|
|
|
|
|
|
|
|
Maintainer : John MacFarlane <jgm@berkeley.edu>
|
|
|
|
Stability : alpha
|
|
|
|
Portability : portable
|
|
|
|
|
|
|
|
Conversion of 'Pandoc' format into LaTeX.
|
|
|
|
-}
|
|
|
|
module Text.Pandoc.Writers.LaTeX ( writeLaTeX ) where
|
|
|
|
import Text.Pandoc.Definition
|
|
|
|
import Text.Pandoc.Shared
|
2009-12-31 01:08:56 +00:00
|
|
|
import Text.Pandoc.Templates
|
2007-11-03 23:27:58 +00:00
|
|
|
import Text.Printf ( printf )
|
2010-01-03 08:47:54 +00:00
|
|
|
import Data.List ( (\\), isSuffixOf, isPrefixOf, intersperse )
|
2007-11-03 23:27:58 +00:00
|
|
|
import Data.Char ( toLower )
|
|
|
|
import Control.Monad.State
|
|
|
|
import Text.PrettyPrint.HughesPJ hiding ( Str )
|
|
|
|
|
|
|
|
data WriterState =
|
2009-12-31 01:18:14 +00:00
|
|
|
WriterState { 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
|
|
|
|
, stVerbInNote :: Bool -- true if document has verbatim text in note
|
|
|
|
, stEnumerate :: Bool -- true if document needs fancy enumerated lists
|
|
|
|
, stTable :: Bool -- true if document has a table
|
|
|
|
, stStrikeout :: Bool -- true if document has strikeout
|
|
|
|
, stSubscript :: Bool -- true if document has subscript
|
|
|
|
, stUrl :: Bool -- true if document has visible URL link
|
|
|
|
, stGraphics :: Bool -- true if document contains images
|
2009-12-31 21:18:36 +00:00
|
|
|
, stLHS :: Bool -- true if document has literate haskell code
|
2010-01-03 08:47:54 +00:00
|
|
|
, stBook :: Bool -- true if document uses book or memoir class
|
2007-11-15 03:11:33 +00:00
|
|
|
}
|
2007-11-03 23:27:58 +00:00
|
|
|
|
|
|
|
-- | Convert Pandoc to LaTeX.
|
|
|
|
writeLaTeX :: WriterOptions -> Pandoc -> String
|
|
|
|
writeLaTeX options document =
|
2009-12-31 01:08:56 +00:00
|
|
|
evalState (pandocToLaTeX options document) $
|
2010-03-17 06:53:38 +00:00
|
|
|
WriterState { stInNote = False, stOLLevel = 1, stOptions = options,
|
|
|
|
stVerbInNote = False, stEnumerate = False,
|
2009-12-31 01:18:14 +00:00
|
|
|
stTable = False, stStrikeout = False, stSubscript = False,
|
2010-01-05 08:36:02 +00:00
|
|
|
stUrl = False, stGraphics = False,
|
2010-01-03 08:47:54 +00:00
|
|
|
stLHS = False, stBook = False }
|
2007-11-03 23:27:58 +00:00
|
|
|
|
2009-12-31 01:08:56 +00:00
|
|
|
pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
|
|
|
|
pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
|
2010-01-03 08:47:54 +00:00
|
|
|
let template = writerTemplate options
|
|
|
|
let usesBookClass x = "\\documentclass" `isPrefixOf` x &&
|
|
|
|
("{memoir}" `isSuffixOf` x || "{book}" `isSuffixOf` x ||
|
|
|
|
"{report}" `isSuffixOf` x)
|
|
|
|
when (any usesBookClass (lines template)) $
|
|
|
|
modify $ \s -> s{stBook = True}
|
2009-12-31 01:16:55 +00:00
|
|
|
titletext <- liftM render $ inlineListToLaTeX title
|
|
|
|
authorsText <- mapM (liftM render . inlineListToLaTeX) authors
|
|
|
|
dateText <- liftM render $ inlineListToLaTeX date
|
2009-12-31 01:12:59 +00:00
|
|
|
body <- blockListToLaTeX blocks
|
2010-03-13 04:11:24 +00:00
|
|
|
let main = render body
|
2009-12-31 01:18:14 +00:00
|
|
|
st <- get
|
2009-12-31 01:09:50 +00:00
|
|
|
let context = writerVariables options ++
|
2009-12-31 01:10:17 +00:00
|
|
|
[ ("toc", if writerTableOfContents options then "yes" else "")
|
2009-12-31 01:08:56 +00:00
|
|
|
, ("body", main)
|
|
|
|
, ("title", titletext)
|
2009-12-31 01:16:00 +00:00
|
|
|
, ("date", dateText) ] ++
|
2009-12-31 01:18:14 +00:00
|
|
|
[ ("author", a) | a <- authorsText ] ++
|
|
|
|
[ ("xetex", "yes") | writerXeTeX options ] ++
|
|
|
|
[ ("verbatim-in-note", "yes") | stVerbInNote st ] ++
|
|
|
|
[ ("fancy-enums", "yes") | stEnumerate st ] ++
|
|
|
|
[ ("tables", "yes") | stTable st ] ++
|
|
|
|
[ ("strikeout", "yes") | stStrikeout st ] ++
|
|
|
|
[ ("subscript", "yes") | stSubscript st ] ++
|
|
|
|
[ ("url", "yes") | stUrl st ] ++
|
2010-01-31 01:07:58 +00:00
|
|
|
[ ("numbersections", "yes") | writerNumberSections options ] ++
|
2009-12-31 21:18:36 +00:00
|
|
|
[ ("lhs", "yes") | stLHS st ] ++
|
2009-12-31 01:18:14 +00:00
|
|
|
[ ("graphics", "yes") | stGraphics st ]
|
2009-12-31 01:12:59 +00:00
|
|
|
return $ if writerStandalone options
|
2010-01-03 08:47:54 +00:00
|
|
|
then renderTemplate context template
|
2009-12-31 01:12:59 +00:00
|
|
|
else main
|
2007-11-03 23:27:58 +00:00
|
|
|
|
|
|
|
-- escape things as needed for LaTeX
|
|
|
|
|
|
|
|
stringToLaTeX :: String -> String
|
|
|
|
stringToLaTeX = escapeStringUsing latexEscapes
|
|
|
|
where latexEscapes = backslashEscapes "{}$%&_#" ++
|
|
|
|
[ ('^', "\\^{}")
|
|
|
|
, ('\\', "\\textbackslash{}")
|
|
|
|
, ('~', "\\ensuremath{\\sim}")
|
|
|
|
, ('|', "\\textbar{}")
|
|
|
|
, ('<', "\\textless{}")
|
|
|
|
, ('>', "\\textgreater{}")
|
2010-10-24 19:31:06 -07:00
|
|
|
, ('[', "{[}") -- to avoid interpretation as
|
|
|
|
, (']', "{]}") -- optional arguments
|
2008-07-11 01:24:15 +00:00
|
|
|
, ('\160', "~")
|
2010-11-27 11:53:30 -08:00
|
|
|
, ('\x2018', "`")
|
|
|
|
, ('\x2019', "'")
|
|
|
|
, ('\x201C', "``")
|
|
|
|
, ('\x201D', "''")
|
2007-11-03 23:27:58 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
-- | Puts contents into LaTeX command.
|
|
|
|
inCmd :: String -> Doc -> Doc
|
|
|
|
inCmd cmd contents = char '\\' <> text cmd <> braces contents
|
|
|
|
|
|
|
|
-- | Remove all code elements from list of inline elements
|
|
|
|
-- (because it's illegal to have verbatim inside some command arguments)
|
|
|
|
deVerb :: [Inline] -> [Inline]
|
|
|
|
deVerb [] = []
|
|
|
|
deVerb ((Code str):rest) =
|
|
|
|
(TeX $ "\\texttt{" ++ stringToLaTeX str ++ "}"):(deVerb rest)
|
|
|
|
deVerb (other:rest) = other:(deVerb rest)
|
|
|
|
|
|
|
|
-- | Convert Pandoc block element to LaTeX.
|
|
|
|
blockToLaTeX :: Block -- ^ Block to convert
|
|
|
|
-> State WriterState Doc
|
|
|
|
blockToLaTeX Null = return empty
|
2007-11-15 03:11:33 +00:00
|
|
|
blockToLaTeX (Plain lst) = do
|
|
|
|
st <- get
|
|
|
|
let opts = stOptions st
|
2007-11-17 18:42:11 +00:00
|
|
|
wrapTeXIfNeeded opts True inlineListToLaTeX lst
|
2010-03-16 04:06:33 +00:00
|
|
|
blockToLaTeX (Para [Image txt (src,tit)]) = do
|
|
|
|
capt <- inlineListToLaTeX txt
|
|
|
|
img <- inlineToLaTeX (Image txt (src,tit))
|
2010-03-17 06:53:38 +00:00
|
|
|
return $ text "\\begin{figure}[htb]" $$ text "\\centering" $$ img $$
|
|
|
|
(text "\\caption{" <> capt <> char '}') $$ text "\\end{figure}\n"
|
2007-11-15 03:11:33 +00:00
|
|
|
blockToLaTeX (Para lst) = do
|
|
|
|
st <- get
|
|
|
|
let opts = stOptions st
|
2007-11-17 18:42:11 +00:00
|
|
|
result <- wrapTeXIfNeeded opts True inlineListToLaTeX lst
|
2007-11-15 03:11:33 +00:00
|
|
|
return $ result <> char '\n'
|
2007-11-03 23:27:58 +00:00
|
|
|
blockToLaTeX (BlockQuote lst) = do
|
|
|
|
contents <- blockListToLaTeX lst
|
|
|
|
return $ text "\\begin{quote}" $$ contents $$ text "\\end{quote}"
|
2008-12-02 22:42:29 +00:00
|
|
|
blockToLaTeX (CodeBlock (_,classes,_) str) = do
|
2007-11-03 23:27:58 +00:00
|
|
|
st <- get
|
2009-12-31 01:18:14 +00:00
|
|
|
env <- if writerLiterateHaskell (stOptions st) && "haskell" `elem` classes &&
|
2009-11-03 06:50:17 +00:00
|
|
|
"literate" `elem` classes
|
2009-12-31 21:18:36 +00:00
|
|
|
then do
|
|
|
|
modify $ \s -> s{ stLHS = True }
|
|
|
|
return "code"
|
2009-12-31 01:18:14 +00:00
|
|
|
else if stInNote st
|
|
|
|
then do
|
|
|
|
modify $ \s -> s{ stVerbInNote = True }
|
|
|
|
return "Verbatim"
|
|
|
|
else return "verbatim"
|
2007-11-03 23:27:58 +00:00
|
|
|
return $ text ("\\begin{" ++ env ++ "}\n") <> text str <>
|
|
|
|
text ("\n\\end{" ++ env ++ "}")
|
2008-07-13 16:53:06 +00:00
|
|
|
blockToLaTeX (RawHtml _) = return empty
|
2007-11-03 23:27:58 +00:00
|
|
|
blockToLaTeX (BulletList lst) = do
|
|
|
|
items <- mapM listItemToLaTeX lst
|
|
|
|
return $ text "\\begin{itemize}" $$ vcat items $$ text "\\end{itemize}"
|
|
|
|
blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
|
|
|
|
st <- get
|
|
|
|
let oldlevel = stOLLevel st
|
|
|
|
put $ st {stOLLevel = oldlevel + 1}
|
|
|
|
items <- mapM listItemToLaTeX lst
|
2008-07-13 16:53:06 +00:00
|
|
|
modify (\s -> s {stOLLevel = oldlevel})
|
2009-12-31 01:18:14 +00:00
|
|
|
exemplar <- if numstyle /= DefaultStyle || numdelim /= DefaultDelim
|
|
|
|
then do
|
|
|
|
modify $ \s -> s{ stEnumerate = True }
|
|
|
|
return $ char '[' <>
|
|
|
|
text (head (orderedListMarkers (1, numstyle,
|
|
|
|
numdelim))) <> char ']'
|
|
|
|
else return empty
|
2007-11-03 23:27:58 +00:00
|
|
|
let resetcounter = if start /= 1 && oldlevel <= 4
|
|
|
|
then text $ "\\setcounter{enum" ++
|
|
|
|
map toLower (toRomanNumeral oldlevel) ++
|
|
|
|
"}{" ++ show (start - 1) ++ "}"
|
|
|
|
else empty
|
|
|
|
return $ text "\\begin{enumerate}" <> exemplar $$ resetcounter $$
|
|
|
|
vcat items $$ text "\\end{enumerate}"
|
|
|
|
blockToLaTeX (DefinitionList lst) = do
|
|
|
|
items <- mapM defListItemToLaTeX lst
|
|
|
|
return $ text "\\begin{description}" $$ vcat items $$
|
|
|
|
text "\\end{description}"
|
|
|
|
blockToLaTeX HorizontalRule = return $ text $
|
|
|
|
"\\begin{center}\\rule{3in}{0.4pt}\\end{center}\n"
|
|
|
|
blockToLaTeX (Header level lst) = do
|
2009-12-05 07:28:50 +00:00
|
|
|
let lst' = deVerb lst
|
|
|
|
txt <- inlineListToLaTeX lst'
|
|
|
|
let noNote (Note _) = Str ""
|
|
|
|
noNote x = x
|
|
|
|
let lstNoNotes = processWith noNote lst'
|
|
|
|
-- footnotes in sections don't work unless you specify an optional
|
|
|
|
-- argument: \section[mysec]{mysec\footnote{blah}}
|
|
|
|
optional <- if lstNoNotes == lst'
|
|
|
|
then return empty
|
|
|
|
else do
|
|
|
|
res <- inlineListToLaTeX lstNoNotes
|
|
|
|
return $ char '[' <> res <> char ']'
|
2010-01-03 08:47:54 +00:00
|
|
|
let stuffing = optional <> char '{' <> txt <> char '}'
|
|
|
|
book <- liftM stBook get
|
|
|
|
return $ case (book, level) of
|
|
|
|
(True, 1) -> text "\\chapter" <> stuffing <> char '\n'
|
|
|
|
(True, 2) -> text "\\section" <> stuffing <> char '\n'
|
|
|
|
(True, 3) -> text "\\subsection" <> stuffing <> char '\n'
|
|
|
|
(True, 4) -> text "\\subsubsection" <> stuffing <> char '\n'
|
|
|
|
(False, 1) -> text "\\section" <> stuffing <> char '\n'
|
|
|
|
(False, 2) -> text "\\subsection" <> stuffing <> char '\n'
|
|
|
|
(False, 3) -> text "\\subsubsection" <> stuffing <> char '\n'
|
|
|
|
_ -> txt <> char '\n'
|
2007-11-03 23:27:58 +00:00
|
|
|
blockToLaTeX (Table caption aligns widths heads rows) = do
|
2010-03-01 02:28:03 +00:00
|
|
|
headers <- if all null heads
|
|
|
|
then return empty
|
|
|
|
else liftM ($$ text "\\hline") $ tableRowToLaTeX heads
|
2007-11-03 23:27:58 +00:00
|
|
|
captionText <- inlineListToLaTeX caption
|
|
|
|
rows' <- mapM tableRowToLaTeX rows
|
2009-11-28 03:22:33 +00:00
|
|
|
let colDescriptors = concat $ zipWith toColDescriptor widths aligns
|
2007-11-03 23:27:58 +00:00
|
|
|
let tableBody = text ("\\begin{tabular}{" ++ colDescriptors ++ "}") $$
|
2010-03-01 02:28:03 +00:00
|
|
|
headers $$ vcat rows' $$ text "\\end{tabular}"
|
2007-11-03 23:27:58 +00:00
|
|
|
let centered txt = text "\\begin{center}" $$ txt $$ text "\\end{center}"
|
2009-12-31 01:18:14 +00:00
|
|
|
modify $ \s -> s{ stTable = True }
|
2007-11-03 23:27:58 +00:00
|
|
|
return $ if isEmpty captionText
|
|
|
|
then centered tableBody <> char '\n'
|
|
|
|
else text "\\begin{table}[h]" $$ centered tableBody $$
|
|
|
|
inCmd "caption" captionText $$ text "\\end{table}\n"
|
|
|
|
|
2009-11-28 03:22:33 +00:00
|
|
|
toColDescriptor :: Double -> Alignment -> String
|
|
|
|
toColDescriptor 0 align =
|
|
|
|
case align of
|
|
|
|
AlignLeft -> "l"
|
|
|
|
AlignRight -> "r"
|
|
|
|
AlignCenter -> "c"
|
|
|
|
AlignDefault -> "l"
|
|
|
|
toColDescriptor width align = ">{\\PBS" ++
|
|
|
|
(case align of
|
|
|
|
AlignLeft -> "\\raggedright"
|
|
|
|
AlignRight -> "\\raggedleft"
|
|
|
|
AlignCenter -> "\\centering"
|
|
|
|
AlignDefault -> "\\raggedright") ++
|
|
|
|
"\\hspace{0pt}}p{" ++ printf "%.2f" width ++
|
|
|
|
"\\columnwidth}"
|
|
|
|
|
2008-07-13 16:53:06 +00:00
|
|
|
blockListToLaTeX :: [Block] -> State WriterState Doc
|
2007-11-03 23:27:58 +00:00
|
|
|
blockListToLaTeX lst = mapM blockToLaTeX lst >>= return . vcat
|
|
|
|
|
2008-07-13 16:53:06 +00:00
|
|
|
tableRowToLaTeX :: [[Block]] -> State WriterState Doc
|
2007-11-03 23:27:58 +00:00
|
|
|
tableRowToLaTeX cols = mapM blockListToLaTeX cols >>=
|
|
|
|
return . ($$ text "\\\\") . foldl (\row item -> row $$
|
2008-11-11 03:02:56 +00:00
|
|
|
(if isEmpty row then text "" else text " & ") <> item) empty
|
2007-11-03 23:27:58 +00:00
|
|
|
|
2008-07-13 16:53:06 +00:00
|
|
|
listItemToLaTeX :: [Block] -> State WriterState Doc
|
2008-08-09 16:50:46 +00:00
|
|
|
listItemToLaTeX lst = blockListToLaTeX lst >>= return . (text "\\item" $$) .
|
2007-11-03 23:27:58 +00:00
|
|
|
(nest 2)
|
|
|
|
|
2009-12-07 08:26:53 +00:00
|
|
|
defListItemToLaTeX :: ([Inline], [[Block]]) -> State WriterState Doc
|
|
|
|
defListItemToLaTeX (term, defs) = do
|
2007-11-03 23:27:58 +00:00
|
|
|
term' <- inlineListToLaTeX $ deVerb term
|
2009-12-07 08:26:53 +00:00
|
|
|
def' <- liftM (vcat . intersperse (text "")) $ mapM blockListToLaTeX defs
|
2007-11-03 23:27:58 +00:00
|
|
|
return $ text "\\item[" <> term' <> text "]" $$ def'
|
|
|
|
|
|
|
|
-- | Convert list of inline elements to LaTeX.
|
|
|
|
inlineListToLaTeX :: [Inline] -- ^ Inlines to convert
|
|
|
|
-> State WriterState Doc
|
|
|
|
inlineListToLaTeX lst = mapM inlineToLaTeX lst >>= return . hcat
|
|
|
|
|
|
|
|
isQuoted :: Inline -> Bool
|
|
|
|
isQuoted (Quoted _ _) = True
|
|
|
|
isQuoted Apostrophe = True
|
|
|
|
isQuoted _ = False
|
|
|
|
|
|
|
|
-- | Convert inline element to LaTeX
|
|
|
|
inlineToLaTeX :: Inline -- ^ Inline to convert
|
|
|
|
-> State WriterState Doc
|
|
|
|
inlineToLaTeX (Emph lst) =
|
|
|
|
inlineListToLaTeX (deVerb lst) >>= return . inCmd "emph"
|
|
|
|
inlineToLaTeX (Strong lst) =
|
|
|
|
inlineListToLaTeX (deVerb lst) >>= return . inCmd "textbf"
|
|
|
|
inlineToLaTeX (Strikeout lst) = do
|
|
|
|
contents <- inlineListToLaTeX $ deVerb lst
|
2009-12-31 01:18:14 +00:00
|
|
|
modify $ \s -> s{ stStrikeout = True }
|
2007-11-03 23:27:58 +00:00
|
|
|
return $ inCmd "sout" contents
|
2009-12-31 01:18:14 +00:00
|
|
|
inlineToLaTeX (Superscript lst) =
|
2007-11-03 23:27:58 +00:00
|
|
|
inlineListToLaTeX (deVerb lst) >>= return . inCmd "textsuperscript"
|
|
|
|
inlineToLaTeX (Subscript lst) = do
|
2009-12-31 01:18:14 +00:00
|
|
|
modify $ \s -> s{ stSubscript = True }
|
2007-11-03 23:27:58 +00:00
|
|
|
contents <- inlineListToLaTeX $ deVerb lst
|
|
|
|
-- oddly, latex includes \textsuperscript but not \textsubscript
|
2008-06-08 03:29:09 +00:00
|
|
|
-- so we have to define it (using a different name so as not to conflict with memoir class):
|
|
|
|
return $ inCmd "textsubscr" contents
|
2008-07-15 23:26:06 +00:00
|
|
|
inlineToLaTeX (SmallCaps lst) =
|
|
|
|
inlineListToLaTeX (deVerb lst) >>= return . inCmd "textsc"
|
2008-08-04 03:15:12 +00:00
|
|
|
inlineToLaTeX (Cite _ lst) =
|
|
|
|
inlineListToLaTeX lst
|
2007-11-03 23:27:58 +00:00
|
|
|
inlineToLaTeX (Code str) = do
|
2009-12-31 01:18:14 +00:00
|
|
|
st <- get
|
|
|
|
when (stInNote st) $ modify $ \s -> s{ stVerbInNote = True }
|
2007-11-03 23:27:58 +00:00
|
|
|
let chr = ((enumFromTo '!' '~') \\ str) !! 0
|
|
|
|
return $ text $ "\\verb" ++ [chr] ++ str ++ [chr]
|
|
|
|
inlineToLaTeX (Quoted SingleQuote lst) = do
|
|
|
|
contents <- inlineListToLaTeX lst
|
|
|
|
let s1 = if (not (null lst)) && (isQuoted (head lst))
|
|
|
|
then text "\\,"
|
|
|
|
else empty
|
|
|
|
let s2 = if (not (null lst)) && (isQuoted (last lst))
|
|
|
|
then text "\\,"
|
|
|
|
else empty
|
|
|
|
return $ char '`' <> s1 <> contents <> s2 <> char '\''
|
|
|
|
inlineToLaTeX (Quoted DoubleQuote lst) = do
|
|
|
|
contents <- inlineListToLaTeX lst
|
|
|
|
let s1 = if (not (null lst)) && (isQuoted (head lst))
|
|
|
|
then text "\\,"
|
|
|
|
else empty
|
|
|
|
let s2 = if (not (null lst)) && (isQuoted (last lst))
|
|
|
|
then text "\\,"
|
|
|
|
else empty
|
|
|
|
return $ text "``" <> s1 <> contents <> s2 <> text "''"
|
|
|
|
inlineToLaTeX Apostrophe = return $ char '\''
|
|
|
|
inlineToLaTeX EmDash = return $ text "---"
|
|
|
|
inlineToLaTeX EnDash = return $ text "--"
|
|
|
|
inlineToLaTeX Ellipses = return $ text "\\ldots{}"
|
|
|
|
inlineToLaTeX (Str str) = return $ text $ stringToLaTeX str
|
2008-08-13 03:02:42 +00:00
|
|
|
inlineToLaTeX (Math InlineMath str) = return $ char '$' <> text str <> char '$'
|
|
|
|
inlineToLaTeX (Math DisplayMath str) = return $ text "\\[" <> text str <> text "\\]"
|
2007-11-03 23:27:58 +00:00
|
|
|
inlineToLaTeX (TeX str) = return $ text str
|
2008-07-13 16:53:06 +00:00
|
|
|
inlineToLaTeX (HtmlInline _) = return empty
|
2007-11-03 23:27:58 +00:00
|
|
|
inlineToLaTeX (LineBreak) = return $ text "\\\\"
|
|
|
|
inlineToLaTeX Space = return $ char ' '
|
2010-01-05 08:36:02 +00:00
|
|
|
inlineToLaTeX (Link txt (src, _)) =
|
2007-11-03 23:27:58 +00:00
|
|
|
case txt of
|
|
|
|
[Code x] | x == src -> -- autolink
|
2009-12-31 01:18:14 +00:00
|
|
|
do modify $ \s -> s{ stUrl = True }
|
|
|
|
return $ text $ "\\url{" ++ x ++ "}"
|
2007-11-03 23:27:58 +00:00
|
|
|
_ -> do contents <- inlineListToLaTeX $ deVerb txt
|
|
|
|
return $ text ("\\href{" ++ src ++ "}{") <> contents <>
|
|
|
|
char '}'
|
2009-12-31 01:18:14 +00:00
|
|
|
inlineToLaTeX (Image _ (source, _)) = do
|
|
|
|
modify $ \s -> s{ stGraphics = True }
|
2010-04-04 16:36:37 +08:00
|
|
|
return $ text $ "\\includegraphics{" ++ source ++ "}"
|
2007-11-03 23:27:58 +00:00
|
|
|
inlineToLaTeX (Note contents) = do
|
|
|
|
st <- get
|
|
|
|
put (st {stInNote = True})
|
|
|
|
contents' <- blockListToLaTeX contents
|
2008-07-13 16:53:06 +00:00
|
|
|
modify (\s -> s {stInNote = False})
|
2007-11-03 23:27:58 +00:00
|
|
|
let rawnote = stripTrailingNewlines $ render contents'
|
|
|
|
-- note: a \n before } is needed when note ends with a Verbatim environment
|
|
|
|
let optNewline = "\\end{Verbatim}" `isSuffixOf` rawnote
|
2007-12-04 04:14:16 +00:00
|
|
|
return $ text "\\footnote{" <>
|
2007-11-03 23:27:58 +00:00
|
|
|
text rawnote <> (if optNewline then char '\n' else empty) <> char '}'
|