aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-03-19 13:56:14 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2016-03-19 13:56:14 -0700
commit3af753de477c79a06dd40839f5fb2c9da299c20a (patch)
tree1886cd9a56586dce78af15c7320c748e5be768d4 /src/Text/Pandoc
parent3aa7bd1b7c8b0cc9782cc942d7f3d03e8baf5663 (diff)
parent1fde92053fb1763c6af913aa9628827dff9ef899 (diff)
downloadpandoc-3af753de477c79a06dd40839f5fb2c9da299c20a.tar.gz
Merge pull request #2637 from mb21/latex-figure-label
LaTeX writer: figure label
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 52f525fe7..0f47132b3 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -403,7 +403,7 @@ blockToLaTeX (Div (identifier,classes,kvs) bs) = do
blockToLaTeX (Plain lst) =
inlineListToLaTeX $ dropWhile isLineBreakOrSpace lst
-- title beginning with fig: indicates that the image is a figure
-blockToLaTeX (Para [Image attr txt (src,'f':'i':'g':':':tit)]) = do
+blockToLaTeX (Para [Image attr@(ident, _, _) txt (src,'f':'i':'g':':':tit)]) = do
inNote <- gets stInNote
modify $ \st -> st{ stInMinipage = True, stNotes = [] }
capt <- inlineListToLaTeX txt
@@ -415,13 +415,14 @@ blockToLaTeX (Para [Image attr txt (src,'f':'i':'g':':':tit)]) = do
else brackets <$> inlineListToLaTeX (walk deNote txt)
img <- inlineToLaTeX (Image attr txt (src,tit))
let footnotes = notesToLaTeX notes
+ figure <- refLabel ident $ cr <>
+ "\\begin{figure}[htbp]" $$ "\\centering" $$ img $$
+ ("\\caption" <> captForLof <> braces capt) $$
+ "\\end{figure}" <> cr
return $ if inNote
-- can't have figures in notes
then "\\begin{center}" $$ img $+$ capt $$ "\\end{center}"
- else "\\begin{figure}[htbp]" $$ "\\centering" $$ img $$
- ("\\caption" <> captForLof <> braces capt) $$
- "\\end{figure}" $$
- footnotes
+ else figure $$ footnotes
-- . . . indicates pause in beamer slides
blockToLaTeX (Para [Str ".",Space,Str ".",Space,Str "."]) = do
beamer <- writerBeamer `fmap` gets stOptions
@@ -715,9 +716,8 @@ sectionHeader :: Bool -- True for unnumbered
-> Int
-> [Inline]
-> State WriterState Doc
-sectionHeader unnumbered ref level lst = do
+sectionHeader unnumbered ident level lst = do
txt <- inlineListToLaTeX lst
- lab <- text `fmap` toLabel ref
plain <- stringToLaTeX TextString $ foldl (++) "" $ map stringify lst
let noNote (Note _) = Str ""
noNote x = x
@@ -740,16 +740,6 @@ sectionHeader unnumbered ref level lst = do
book <- gets stBook
opts <- gets stOptions
let level' = if book || writerChapters opts then level - 1 else level
- internalLinks <- gets stInternalLinks
- let refLabel x = (if ref `elem` internalLinks
- then text "\\hypertarget"
- <> braces lab
- <> braces x
- else x)
- let headerWith x y = refLabel $ text x <> y <>
- if null ref
- then empty
- else text "\\label" <> braces lab
let sectionType = case level' of
0 | writerBeamer opts -> "part"
| otherwise -> "chapter"
@@ -765,16 +755,31 @@ sectionHeader unnumbered ref level lst = do
-- needed for \paragraph, \subparagraph in quote environment
-- see http://tex.stackexchange.com/questions/169830/
else empty
+ stuffing' <- refLabel ident $ text ('\\':sectionType) <> stuffing
return $ if level' > 5
then txt
- else prefix $$
- headerWith ('\\':sectionType) stuffing
+ else prefix $$ stuffing'
$$ if unnumbered
then "\\addcontentsline{toc}" <>
braces (text sectionType) <>
braces txtNoNotes
else empty
+-- | Append label to x and wrap in hypertarget
+refLabel :: String -> Doc -> State WriterState Doc
+refLabel ident x = do
+ ref <- text `fmap` toLabel ident
+ internalLinks <- gets stInternalLinks
+ let hypertarget y = if ident `elem` internalLinks
+ then text "\\hypertarget"
+ <> braces ref
+ <> braces y
+ else y
+ label = if null ident
+ then empty
+ else text "\\label" <> braces ref
+ return $ hypertarget $ x <> label
+
-- | Convert list of inline elements to LaTeX.
inlineListToLaTeX :: [Inline] -- ^ Inlines to convert
-> State WriterState Doc