git.iko.soy/typeable/pandoc
on master help sign in
Adjusted formatting of LaTeX and ConTeXt footnotes:
09b57fcfiddlosopher
src/Text/Pandoc/Shared.hs+19−9
@@ -227,8 +227,12 @@ isNote _ = False
227
227
228-- | Wrap inlines to line length, treating footnotes in a way that
228-- | Wrap inlines to line length, treating footnotes in a way that
229-- makes sense in LaTeX and ConTeXt.
229-- makes sense in LaTeX and ConTeXt.
230−wrappedTeX :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc
230+wrappedTeX :: Monad m
231+ => Bool -- | Include % on line before notes.
232+ -> ([Inline] -> m Doc) -- | Inline list writer.
233+ -> [Inline]
234+ -> m Doc
231−wrappedTeX listWriter sect = do
235+wrappedTeX includePercent listWriter sect = do
232 let (firstpart, rest) = break isNote sect
236 let (firstpart, rest) = break isNote sect
233 firstpartWrapped <- wrapped listWriter firstpart
237 firstpartWrapped <- wrapped listWriter firstpart
234 if null rest
238 if null rest
@@ -236,17 +240,23 @@ wrappedTeX listWriter sect = do
236 else do let (note:rest') = rest
240 else do let (note:rest') = rest
237 restWrapped <- if null rest'
241 restWrapped <- if null rest'
238 then return empty
242 then return empty
239− else wrappedTeX listWriter rest'
243+ else wrappedTeX includePercent listWriter rest'
240 noteText <- listWriter [note]
244 noteText <- listWriter [note]
241− return $ firstpartWrapped <> PP.char '%' $$ noteText $$ restWrapped
245+ return $ firstpartWrapped <>
246+ (if includePercent then PP.char '%' else empty) $$
247+ noteText $$ restWrapped
242
248
243-- | Wrap inlines if the text wrap option is selected, specialized
249-- | Wrap inlines if the text wrap option is selected, specialized
244-- for LaTeX and ConTeXt.
250-- for LaTeX and ConTeXt.
245−wrapTeXIfNeeded :: Monad m => WriterOptions -> ([Inline] -> m Doc) ->
251+wrapTeXIfNeeded :: Monad m
252+ => WriterOptions
253+ -> Bool -- | Include % on line before notes.
254+ -> ([Inline] -> m Doc) -- | Inline list writer.
246− [Inline] -> m Doc
255+ -> [Inline]
256+ -> m Doc
247−wrapTeXIfNeeded opts = if writerWrapText opts
257+wrapTeXIfNeeded opts includePercent = if writerWrapText opts
248− then wrappedTeX
258+ then wrappedTeX includePercent
249− else ($)
259+ else ($)
250
260
251--
261--
252-- Parsing
262-- Parsing
src/Text/Pandoc/Writers/ConTeXt.hs+3−3
@@ -116,9 +116,9 @@ blockToConTeXt :: WriterOptions
116 -> State WriterState Doc
116 -> State WriterState Doc
117blockToConTeXt opts Null = return empty
117blockToConTeXt opts Null = return empty
118blockToConTeXt opts (Plain lst) =
118blockToConTeXt opts (Plain lst) =
119− wrapTeXIfNeeded opts (inlineListToConTeXt opts) lst >>= return
119+ wrapTeXIfNeeded opts False (inlineListToConTeXt opts) lst >>= return
120blockToConTeXt opts (Para lst) =
120blockToConTeXt opts (Para lst) =
121− wrapTeXIfNeeded opts (inlineListToConTeXt opts) lst >>= return . (<> char '\n')
121+ wrapTeXIfNeeded opts False (inlineListToConTeXt opts) lst >>= return . (<> char '\n')
122blockToConTeXt opts (BlockQuote lst) = do
122blockToConTeXt opts (BlockQuote lst) = do
123 contents <- blockListToConTeXt opts lst
123 contents <- blockListToConTeXt opts lst
124 return $ text "\\startblockquote\n" $$ contents $$ text "\\stopblockquote"
124 return $ text "\\startblockquote\n" $$ contents $$ text "\\stopblockquote"
@@ -270,7 +270,7 @@ inlineToConTeXt opts (Image alternate (src, tit)) = do
270 text tit <> text "}\n{\\externalfigure[" <> text src <> text "]}"
270 text tit <> text "}\n{\\externalfigure[" <> text src <> text "]}"
271inlineToConTeXt opts (Note contents) = do
271inlineToConTeXt opts (Note contents) = do
272 contents' <- blockListToConTeXt opts contents
272 contents' <- blockListToConTeXt opts contents
273− return $ text "\\footnote{" <>
273+ return $ text " \\footnote{" <>
274 text (stripTrailingNewlines $ render contents') <>
274 text (stripTrailingNewlines $ render contents') <>
275 char '}'
275 char '}'
276
276
src/Text/Pandoc/Writers/LaTeX.hs+3−3
@@ -137,11 +137,11 @@ blockToLaTeX Null = return empty
137blockToLaTeX (Plain lst) = do
137blockToLaTeX (Plain lst) = do
138 st <- get
138 st <- get
139 let opts = stOptions st
139 let opts = stOptions st
140− wrapTeXIfNeeded opts inlineListToLaTeX lst
140+ wrapTeXIfNeeded opts True inlineListToLaTeX lst
141blockToLaTeX (Para lst) = do
141blockToLaTeX (Para lst) = do
142 st <- get
142 st <- get
143 let opts = stOptions st
143 let opts = stOptions st
144− result <- wrapTeXIfNeeded opts inlineListToLaTeX lst
144+ result <- wrapTeXIfNeeded opts True inlineListToLaTeX lst
145 return $ result <> char '\n'
145 return $ result <> char '\n'
146blockToLaTeX (BlockQuote lst) = do
146blockToLaTeX (BlockQuote lst) = do
147 contents <- blockListToLaTeX lst
147 contents <- blockListToLaTeX lst
@@ -314,5 +314,5 @@ inlineToLaTeX (Note contents) = do
314 let rawnote = stripTrailingNewlines $ render contents'
314 let rawnote = stripTrailingNewlines $ render contents'
315 -- note: a \n before } is needed when note ends with a Verbatim environment
315 -- note: a \n before } is needed when note ends with a Verbatim environment
316 let optNewline = "\\end{Verbatim}" `isSuffixOf` rawnote
316 let optNewline = "\\end{Verbatim}" `isSuffixOf` rawnote
317− return $ text "\\footnote{" <>
317+ return $ text " \\footnote{" <>
318 text rawnote <> (if optNewline then char '\n' else empty) <> char '}'
318 text rawnote <> (if optNewline then char '\n' else empty) <> char '}'
tests/writer.context+10−10
@@ -821,11 +821,11 @@ Here is a movie
821
821
822\subject{Footnotes}
822\subject{Footnotes}
823
823
824−Here is a footnote reference,%
824+Here is a footnote reference,
825−\footnote{Here is the footnote. It can go anywhere after the footnote
825+ \footnote{Here is the footnote. It can go anywhere after the footnote
826reference. It need not be placed at the end of the document.}
826reference. It need not be placed at the end of the document.}
827−and another.%
827+and another.
828−\footnote{Here's the long note. This one contains multiple blocks.
828+ \footnote{Here's the long note. This one contains multiple blocks.
829
829
830Subsequent blocks are indented to show that they belong to the
830Subsequent blocks are indented to show that they belong to the
831footnote (as with list items).
831footnote (as with list items).
@@ -837,20 +837,20 @@ footnote (as with list items).
837If you want, you can indent every line, but you can also be lazy
837If you want, you can indent every line, but you can also be lazy
838and just indent the first line of each block.}
838and just indent the first line of each block.}
839This should {\em not} be a footnote reference, because it contains
839This should {\em not} be a footnote reference, because it contains
840−a space.[\letterhat{}my note] Here is an inline note.%
840+a space.[\letterhat{}my note] Here is an inline note.
841−\footnote{This is {\em easier} to type. Inline notes may contain
841+ \footnote{This is {\em easier} to type. Inline notes may contain
842\useurl[31][http://google.com][][links]\from[31] and \type{]}
842\useurl[31][http://google.com][][links]\from[31] and \type{]}
843verbatim characters, as well as [bracketed text].}
843verbatim characters, as well as [bracketed text].}
844
844
845\startblockquote
845\startblockquote
846−Notes can go in quotes.%
846+Notes can go in quotes.
847−\footnote{In quote.}
847+ \footnote{In quote.}
848
848
849\stopblockquote
849\stopblockquote
850\startitemize
850\startitemize
851\sym{1.}
851\sym{1.}
852− And in list items.%
852+ And in list items.
853− \footnote{In list.}
853+ \footnote{In list.}
854\stopitemize
854\stopitemize
855This paragraph should not be part of the note, as it is not
855This paragraph should not be part of the note, as it is not
856indented.
856indented.
tests/writer.latex+5−5
@@ -792,10 +792,10 @@ Here is a movie \includegraphics{movie.jpg} icon.
792\section{Footnotes}
792\section{Footnotes}
793
793
794Here is a footnote reference,%
794Here is a footnote reference,%
795−\footnote{Here is the footnote. It can go anywhere after the footnote
795+ \footnote{Here is the footnote. It can go anywhere after the footnote
796reference. It need not be placed at the end of the document.}
796reference. It need not be placed at the end of the document.}
797and another.%
797and another.%
798−\footnote{Here's the long note. This one contains multiple blocks.
798+ \footnote{Here's the long note. This one contains multiple blocks.
799
799
800Subsequent blocks are indented to show that they belong to the
800Subsequent blocks are indented to show that they belong to the
801footnote (as with list items).
801footnote (as with list items).
@@ -807,19 +807,19 @@ If you want, you can indent every line, but you can also be lazy
807and just indent the first line of each block.}
807and just indent the first line of each block.}
808This should \emph{not} be a footnote reference, because it contains
808This should \emph{not} be a footnote reference, because it contains
809a space.[\^{}my note] Here is an inline note.%
809a space.[\^{}my note] Here is an inline note.%
810−\footnote{This is \emph{easier} to type. Inline notes may contain
810+ \footnote{This is \emph{easier} to type. Inline notes may contain
811\href{http://google.com}{links} and \verb!]! verbatim characters,
811\href{http://google.com}{links} and \verb!]! verbatim characters,
812as well as [bracketed text].}
812as well as [bracketed text].}
813
813
814\begin{quote}
814\begin{quote}
815Notes can go in quotes.%
815Notes can go in quotes.%
816−\footnote{In quote.}
816+ \footnote{In quote.}
817
817
818\end{quote}
818\end{quote}
819\begin{enumerate}[1.]
819\begin{enumerate}[1.]
820\item
820\item
821 And in list items.%
821 And in list items.%
822− \footnote{In list.}
822+ \footnote{In list.}
823\end{enumerate}
823\end{enumerate}
824This paragraph should not be part of the note, as it is not
824This paragraph should not be part of the note, as it is not
825indented.
825indented.