@@ -161,14 +161,14 @@ blockToLaTeX (Plain lst) = inlineListToLaTeX lst
161blockToLaTeX (Para [Image txt (src,tit)]) = do
161blockToLaTeX (Para [Image txt (src,tit)]) = do
162 capt <- inlineListToLaTeX txt
162 capt <- inlineListToLaTeX txt
163 img <- inlineToLaTeX (Image txt (src,tit))
163 img <- inlineToLaTeX (Image txt (src,tit))
164− return $ text "\\begin{figure}[htb]" $$ text "\\centering" $$ img $$
164+ return $ "\\begin{figure}[htb]" $$ "\\centering" $$ img $$
165− (text "\\caption{" <> capt <> char '}') $$ text "\\end{figure}" $$ blankline
165+ ("\\caption{" <> capt <> char '}') $$ "\\end{figure}" $$ blankline
166blockToLaTeX (Para lst) = do
166blockToLaTeX (Para lst) = do
167 result <- inlineListToLaTeX lst
167 result <- inlineListToLaTeX lst
168 return $ result <> blankline
168 return $ result <> blankline
169blockToLaTeX (BlockQuote lst) = do
169blockToLaTeX (BlockQuote lst) = do
170 contents <- blockListToLaTeX lst
170 contents <- blockListToLaTeX lst
171− return $ text "\\begin{quote}" $$ contents $$ text "\\end{quote}"
171+ return $ "\\begin{quote}" $$ contents $$ "\\end{quote}"
172blockToLaTeX (CodeBlock (_,classes,_) str) = do
172blockToLaTeX (CodeBlock (_,classes,_) str) = do
173 st <- get
173 st <- get
174 env <- if writerLiterateHaskell (stOptions st) && "haskell" `elem` classes &&
174 env <- if writerLiterateHaskell (stOptions st) && "haskell" `elem` classes &&
@@ -186,7 +186,7 @@ blockToLaTeX (CodeBlock (_,classes,_) str) = do
186blockToLaTeX (RawHtml _) = return empty
186blockToLaTeX (RawHtml _) = return empty
187blockToLaTeX (BulletList lst) = do
187blockToLaTeX (BulletList lst) = do
188 items <- mapM listItemToLaTeX lst
188 items <- mapM listItemToLaTeX lst
189− return $ text "\\begin{itemize}" $$ vcat items $$ text "\\end{itemize}"
189+ return $ "\\begin{itemize}" $$ vcat items $$ "\\end{itemize}"
190blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
190blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
191 st <- get
191 st <- get
192 let oldlevel = stOLLevel st
192 let oldlevel = stOLLevel st
@@ -205,12 +205,11 @@ blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do
205 map toLower (toRomanNumeral oldlevel) ++
205 map toLower (toRomanNumeral oldlevel) ++
206 "}{" ++ show (start - 1) ++ "}"
206 "}{" ++ show (start - 1) ++ "}"
207 else empty
207 else empty
208− return $ text "\\begin{enumerate}" <> exemplar $$ resetcounter $$
208+ return $ "\\begin{enumerate}" <> exemplar $$ resetcounter $$
209− vcat items $$ text "\\end{enumerate}"
209+ vcat items $$ "\\end{enumerate}"
210blockToLaTeX (DefinitionList lst) = do
210blockToLaTeX (DefinitionList lst) = do
211 items <- mapM defListItemToLaTeX lst
211 items <- mapM defListItemToLaTeX lst
212− return $ text "\\begin{description}" $$ vcat items $$
212+ return $ "\\begin{description}" $$ vcat items $$ "\\end{description}"
213− text "\\end{description}"
214blockToLaTeX HorizontalRule = return $
213blockToLaTeX HorizontalRule = return $
215 "\\begin{center}\\rule{3in}{0.4pt}\\end{center}" $$ blankline
214 "\\begin{center}\\rule{3in}{0.4pt}\\end{center}" $$ blankline
216blockToLaTeX (Header level lst) = do
215blockToLaTeX (Header level lst) = do
@@ -241,18 +240,18 @@ blockToLaTeX (Header level lst) = do
241blockToLaTeX (Table caption aligns widths heads rows) = do
240blockToLaTeX (Table caption aligns widths heads rows) = do
242 headers <- if all null heads
241 headers <- if all null heads
243 then return empty
242 then return empty
244− else liftM ($$ text "\\hline") $ tableRowToLaTeX heads
243+ else liftM ($$ "\\hline") $ tableRowToLaTeX heads
245 captionText <- inlineListToLaTeX caption
244 captionText <- inlineListToLaTeX caption
246 rows' <- mapM tableRowToLaTeX rows
245 rows' <- mapM tableRowToLaTeX rows
247 let colDescriptors = concat $ zipWith toColDescriptor widths aligns
246 let colDescriptors = concat $ zipWith toColDescriptor widths aligns
248 let tableBody = text ("\\begin{tabular}{" ++ colDescriptors ++ "}") $$
247 let tableBody = text ("\\begin{tabular}{" ++ colDescriptors ++ "}") $$
249− headers $$ vcat rows' $$ text "\\end{tabular}"
248+ headers $$ vcat rows' $$ "\\end{tabular}"
250− let centered txt = text "\\begin{center}" $$ txt $$ text "\\end{center}"
249+ let centered txt = "\\begin{center}" $$ txt $$ "\\end{center}"
251 modify $ \s -> s{ stTable = True }
250 modify $ \s -> s{ stTable = True }
252 return $ if isEmpty captionText
251 return $ if isEmpty captionText
253 then centered tableBody $$ blankline
252 then centered tableBody $$ blankline
254− else text "\\begin{table}[h]" $$ centered tableBody $$
253+ else "\\begin{table}[h]" $$ centered tableBody $$
255− inCmd "caption" captionText $$ text "\\end{table}" $$ blankline
254+ inCmd "caption" captionText $$ "\\end{table}" $$ blankline
257toColDescriptor :: Double -> Alignment -> String
256toColDescriptor :: Double -> Alignment -> String
258toColDescriptor 0 align =
257toColDescriptor 0 align =
@@ -286,7 +285,7 @@ defListItemToLaTeX :: ([Inline], [[Block]]) -> State WriterState Doc
286defListItemToLaTeX (term, defs) = do
285defListItemToLaTeX (term, defs) = do
287 term' <- inlineListToLaTeX $ deVerb term
286 term' <- inlineListToLaTeX $ deVerb term
288 def' <- liftM vsep $ mapM blockListToLaTeX defs
287 def' <- liftM vsep $ mapM blockListToLaTeX defs
289− return $ text "\\item[" <> term' <> text "]" $$ def'
288+ return $ "\\item" <> brackets term' $$ def'
291-- | Convert list of inline elements to LaTeX.
290-- | Convert list of inline elements to LaTeX.
292inlineListToLaTeX :: [Inline] -- ^ Inlines to convert
291inlineListToLaTeX :: [Inline] -- ^ Inlines to convert
@@ -335,31 +334,31 @@ inlineToLaTeX (Code str) = do
335inlineToLaTeX (Quoted SingleQuote lst) = do
334inlineToLaTeX (Quoted SingleQuote lst) = do
336 contents <- inlineListToLaTeX lst
335 contents <- inlineListToLaTeX lst
337 let s1 = if (not (null lst)) && (isQuoted (head lst))
336 let s1 = if (not (null lst)) && (isQuoted (head lst))
338− then text "\\,"
337+ then "\\,"
339− else empty
338+ else empty
340 let s2 = if (not (null lst)) && (isQuoted (last lst))
339 let s2 = if (not (null lst)) && (isQuoted (last lst))
341− then text "\\,"
340+ then "\\,"
342 else empty
341 else empty
343 return $ char '`' <> s1 <> contents <> s2 <> char '\''
342 return $ char '`' <> s1 <> contents <> s2 <> char '\''
344inlineToLaTeX (Quoted DoubleQuote lst) = do
343inlineToLaTeX (Quoted DoubleQuote lst) = do
345 contents <- inlineListToLaTeX lst
344 contents <- inlineListToLaTeX lst
346 let s1 = if (not (null lst)) && (isQuoted (head lst))
345 let s1 = if (not (null lst)) && (isQuoted (head lst))
347− then text "\\,"
346+ then "\\,"
348− else empty
347+ else empty
349 let s2 = if (not (null lst)) && (isQuoted (last lst))
348 let s2 = if (not (null lst)) && (isQuoted (last lst))
350− then text "\\,"
349+ then "\\,"
351 else empty
350 else empty
352− return $ text "``" <> s1 <> contents <> s2 <> text "''"
351+ return $ "``" <> s1 <> contents <> s2 <> "''"
353inlineToLaTeX Apostrophe = return $ char '\''
352inlineToLaTeX Apostrophe = return $ char '\''
354−inlineToLaTeX EmDash = return $ text "---"
353+inlineToLaTeX EmDash = return "---"
355−inlineToLaTeX EnDash = return $ text "--"
354+inlineToLaTeX EnDash = return "--"
356−inlineToLaTeX Ellipses = return $ text "\\ldots{}"
355+inlineToLaTeX Ellipses = return "\\ldots{}"
357inlineToLaTeX (Str str) = return $ text $ stringToLaTeX str
356inlineToLaTeX (Str str) = return $ text $ stringToLaTeX str
358inlineToLaTeX (Math InlineMath str) = return $ char '$' <> text str <> char '$'
357inlineToLaTeX (Math InlineMath str) = return $ char '$' <> text str <> char '$'
359−inlineToLaTeX (Math DisplayMath str) = return $ text "\\[" <> text str <> text "\\]"
358+inlineToLaTeX (Math DisplayMath str) = return $ "\\[" <> text str <> "\\]"
360inlineToLaTeX (TeX str) = return $ text str
359inlineToLaTeX (TeX str) = return $ text str
361inlineToLaTeX (HtmlInline _) = return empty
360inlineToLaTeX (HtmlInline _) = return empty
362−inlineToLaTeX (LineBreak) = return $ text "\\\\"
361+inlineToLaTeX (LineBreak) = return "\\\\"
363inlineToLaTeX Space = return space
362inlineToLaTeX Space = return space
364inlineToLaTeX (Link txt (src, _)) =
363inlineToLaTeX (Link txt (src, _)) =
365 case txt of
364 case txt of
@@ -367,17 +366,17 @@ inlineToLaTeX (Link txt (src, _)) =
367 do modify $ \s -> s{ stUrl = True }
366 do modify $ \s -> s{ stUrl = True }
368 return $ text $ "\\url{" ++ x ++ "}"
367 return $ text $ "\\url{" ++ x ++ "}"
369 _ -> do contents <- inlineListToLaTeX $ deVerb txt
368 _ -> do contents <- inlineListToLaTeX $ deVerb txt
370− return $ text ("\\href{" ++ src ++ "}{") <> contents <>
369+ return $ text ("\\href{" ++ src ++ "}{") <> contents <>
372inlineToLaTeX (Image _ (source, _)) = do
371inlineToLaTeX (Image _ (source, _)) = do
373 modify $ \s -> s{ stGraphics = True }
372 modify $ \s -> s{ stGraphics = True }
374− return $ text $ "\\includegraphics{" ++ source ++ "}"
373+ return $ "\\includegraphics" <> braces (text source)
375inlineToLaTeX (Note contents) = do
374inlineToLaTeX (Note contents) = do
376 modify (\s -> s{stInNote = True})
375 modify (\s -> s{stInNote = True})
377 contents' <- blockListToLaTeX contents
376 contents' <- blockListToLaTeX contents
378 modify (\s -> s {stInNote = False})
377 modify (\s -> s {stInNote = False})
379 -- note: a \n before } is needed when note ends with a Verbatim environment
378 -- note: a \n before } is needed when note ends with a Verbatim environment
380− return $ text "\\footnote{" <> nest 2 contents' <> char '}'
379+ return $ "\\footnote" <> braces (nest 2 contents')
383citationsToNatbib :: [Citation] -> State WriterState Doc
382citationsToNatbib :: [Citation] -> State WriterState Doc