git.iko.soy/typeable/pandoc
on master help sign in
Cleaned up LaTeX footnotes:
40fa017fiddlosopher
src/Text/Pandoc/Writers/LaTeX.hs+6−5
@@ -31,7 +31,7 @@ module Text.Pandoc.Writers.LaTeX ( writeLaTeX ) where
31import Text.Pandoc.Definition
31import Text.Pandoc.Definition
32import Text.Pandoc.Shared
32import Text.Pandoc.Shared
33import Text.Printf ( printf )
33import Text.Printf ( printf )
34−import Data.List ( (\\), isInfixOf, intersperse )
34+import Data.List ( (\\), isInfixOf, isSuffixOf, intersperse )
35import Data.Char ( toLower )
35import Data.Char ( toLower )
36import qualified Data.Set as S
36import qualified Data.Set as S
37import Control.Monad.State
37import Control.Monad.State
@@ -303,7 +303,8 @@ inlineToLaTeX (Note contents) = do
303 put (st {stInNote = True})
303 put (st {stInNote = True})
304 contents' <- blockListToLaTeX contents
304 contents' <- blockListToLaTeX contents
305 modify (\st -> st {stInNote = False})
305 modify (\st -> st {stInNote = False})
306− return $ text "\\footnote{" $$
307− (nest 11 $ text (stripTrailingNewlines $ render contents') <> text "\n}")
306+ let rawnote = stripTrailingNewlines $ render contents'
308− -- note: the \n before } is important; removing it causes problems
307+ -- note: a \n before } is needed when note ends with a Verbatim environment
309− -- if a Verbatim environment occurs at the end of the footnote.
308+ let optNewline = "\\end{Verbatim}" `isSuffixOf` rawnote
309+ return $ text "%\n\\footnote{" <>
310+ text rawnote <> (if optNewline then char '\n' else empty) <> char '}'
tests/writer.latex+13−13
@@ -792,11 +792,12 @@ Here is a movie \includegraphics{movie.jpg} icon.
792\section{Footnotes}
792\section{Footnotes}
793
793
794Here is a footnote
794Here is a footnote
795+reference,%
795−reference,\footnote{ Here is the footnote. It can go anywhere after the footnote
796+\footnote{Here is the footnote. It can go anywhere after the footnote
796−reference. It need not be placed at the end of the document.
797+reference. It need not be placed at the end of the document.}
797−}
798and
798and
799+another.%
799−another.\footnote{ Here's the long note. This one contains multiple blocks.
800+\footnote{Here's the long note. This one contains multiple blocks.
800
801
801Subsequent blocks are indented to show that they belong to the
802Subsequent blocks are indented to show that they belong to the
802footnote (as with list items).
803footnote (as with list items).
@@ -805,24 +806,23 @@ footnote (as with list items).
805 { <code> }
806 { <code> }
806\end{Verbatim}
807\end{Verbatim}
807If you want, you can indent every line, but you can also be lazy
808If you want, you can indent every line, but you can also be lazy
808−and just indent the first line of each block.
809+and just indent the first line of each block.}
809−}
810This should \emph{not} be a footnote reference, because it contains
810This should \emph{not} be a footnote reference, because it contains
811a space.[\^{}my note] Here is an inline
811a space.[\^{}my note] Here is an inline
812+note.%
812−note.\footnote{ This is \emph{easier} to type. Inline notes may contain
813+\footnote{This is \emph{easier} to type. Inline notes may contain
813\href{http://google.com}{links} and \verb!]! verbatim characters,
814\href{http://google.com}{links} and \verb!]! verbatim characters,
814−as well as [bracketed text].
815+as well as [bracketed text].}
815−}
816
816
817\begin{quote}
817\begin{quote}
818−Notes can go in quotes.\footnote{ In quote.
818+Notes can go in quotes.%
819−}
819+\footnote{In quote.}
820
820
821\end{quote}
821\end{quote}
822\begin{enumerate}[1.]
822\begin{enumerate}[1.]
823\item
823\item
824− And in list items.\footnote{ In list.
824+ And in list items.%
825−}
825+\footnote{In list.}
826\end{enumerate}
826\end{enumerate}
827This paragraph should not be part of the note, as it is not
827This paragraph should not be part of the note, as it is not
828indented.
828indented.