@@ -50,6 +50,8 @@ import Text.Pandoc.Highlighting (highlight, styleToLaTeX,
5050
5151data WriterState =
5252 WriterState { stInNote :: Bool -- true if we're in a note
53+ , stInMinipage :: Bool -- true if in minipage
54+ , stNotes :: [Doc] -- notes in a minipage
5355 , stOLLevel :: Int -- level of ordered list nesting
5456 , stOptions :: WriterOptions -- writer options, so they don't have to be parameter
5557 , stVerbInNote :: Bool -- true if document has verbatim text in note
@@ -70,7 +72,7 @@ data WriterState =
7072writeLaTeX :: WriterOptions -> Pandoc -> String
7173writeLaTeX options document =
7274 evalState (pandocToLaTeX options document) $
73− WriterState { stInNote = False,
75+ WriterState { stInNote = False, stInMinipage = False, stNotes = [],
7476 stOLLevel = 1, stOptions = options,
7577 stVerbInNote = False,
7678 stTable = False, stStrikeout = False,
@@ -501,16 +503,31 @@ tableCellToLaTeX :: Bool -> (Double, Alignment, [Block])
501503 -> State WriterState Doc
502504tableCellToLaTeX _ (0, _, blocks) = blockListToLaTeX blocks
503505tableCellToLaTeX header (width, align, blocks) = do
506+ modify $ \st -> st{ stInMinipage = True, stNotes = [] }
504507 cellContents <- blockListToLaTeX blocks
508+ notes <- gets stNotes
509+ modify $ \st -> st{ stInMinipage = False, stNotes = [] }
505510 let valign = text $ if header then "[b]" else "[t]"
506511 let halign = case align of
507512 AlignLeft -> "\\raggedright"
508513 AlignRight -> "\\raggedleft"
509514 AlignCenter -> "\\centering"
510515 AlignDefault -> "\\raggedright"
511− return $ "\\begin{minipage}" <> valign <>
512− braces (text (printf "%.2f\\columnwidth" width)) <>
513− (halign <> cr <> cellContents <> cr) <> "\\end{minipage}"
516+ return $ ("\\begin{minipage}" <> valign <>
517+ braces (text (printf "%.2f\\columnwidth" width)) <>
518+ (halign <> cr <> cellContents <> cr) <> "\\end{minipage}")
519+ $$ case notes of
520+ [] -> empty
521+ ns -> (case length ns of
522+ n | n > 1 -> "\\addtocounter" <>
523+ braces "footnote" <>
524+ braces (text $ show $ 1 - n)
525+ | otherwise -> empty)
526+ $$
527+ vcat (intersperse
528+ ("\\addtocounter" <> braces "footnote" <> braces "1")
529+ $ map (\x -> "\\footnotetext" <> braces x)
530+ $ reverse ns)
514531
515532listItemToLaTeX :: [Block] -> State WriterState Doc
516533listItemToLaTeX lst = blockListToLaTeX lst >>= return . (text "\\item" $$) .
@@ -713,14 +730,20 @@ inlineToLaTeX (Image _ (source, _)) = do
713730 source'' <- stringToLaTeX URLString source'
714731 return $ "\\includegraphics" <> braces (text source'')
715732inlineToLaTeX (Note contents) = do
733+ inMinipage <- gets stInMinipage
716734 modify (\s -> s{stInNote = True})
717735 contents' <- blockListToLaTeX contents
718736 modify (\s -> s {stInNote = False})
719737 let optnl = case reverse contents of
720738 (CodeBlock _ _ : _) -> cr
721739 _ -> empty
722− return $ "\\footnote" <> braces (nest 2 contents' <> optnl)
723− -- note: a \n before } needed when note ends with a Verbatim environment
740+ let noteContents = nest 2 contents' <> optnl
741+ modify $ \st -> st{ stNotes = noteContents : stNotes st }
742+ return $
743+ if inMinipage
744+ then "\\footnotemark{}"
745+ -- note: a \n before } needed when note ends with a Verbatim environment
746+ else "\\footnote" <> braces noteContents
724747
725748citationsToNatbib :: [Citation] -> State WriterState Doc
726749citationsToNatbib (one:[])