aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/LaTeX/Notes.hs
blob: 216a7bfc3c9f69fd8fe17dfd5668c1c6c70d463e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# LANGUAGE LambdaCase        #-}
{-# LANGUAGE OverloadedStrings #-}
{- |
   Module      : Text.Pandoc.Writers.LaTeX.Notes
   Copyright   : Copyright (C) 2006-2020 John MacFarlane
   License     : GNU GPL, version 2 or above

   Maintainer  : John MacFarlane <jgm@berkeley.edu>
   Stability   : alpha
   Portability : portable

Output tables as LaTeX.
-}
module Text.Pandoc.Writers.LaTeX.Notes
  ( notesToLaTeX
  ) where

import Data.List (intersperse)
import Text.DocLayout ( Doc, braces, empty, text, vcat, ($$))
import Data.Text (Text)

notesToLaTeX :: [Doc Text] -> Doc Text
notesToLaTeX = \case
  [] -> empty
  ns -> (case length ns of
            n | n > 1 -> "\\addtocounter" <>
                         braces "footnote" <>
                         braces (text $ show $ 1 - n)
              | otherwise -> empty)
        $$
        vcat (intersperse
               ("\\addtocounter" <> braces "footnote" <> braces "1")
               $ map (\x -> "\\footnotetext" <> braces x)
               $ reverse ns)