aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-03-16 06:45:57 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-03-16 06:45:57 +0000
commitbe344321227a33c9a3f3e2031b88045f5159d1ff (patch)
treeaf8244fb71e7f73b411b49e3f7b479f33b57bd7e /src/Text/Pandoc
parent26b41ce7ba2944f312a54b555baeba2351c1c025 (diff)
downloadpandoc-be344321227a33c9a3f3e2031b88045f5159d1ff.tar.gz
LaTeX writer: Add unique labels to figures.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1895 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 02fbf4add..a3e6b9364 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -40,6 +40,7 @@ import Text.PrettyPrint.HughesPJ hiding ( Str )
data WriterState =
WriterState { stInNote :: Bool -- @True@ if we're in a note
, stOLLevel :: Int -- level of ordered list nesting
+ , stUsedIdents :: [String] -- identifiers used already
, stOptions :: WriterOptions -- writer options, so they don't have to be parameter
, stVerbInNote :: Bool -- true if document has verbatim text in note
, stEnumerate :: Bool -- true if document needs fancy enumerated lists
@@ -56,8 +57,8 @@ data WriterState =
writeLaTeX :: WriterOptions -> Pandoc -> String
writeLaTeX options document =
evalState (pandocToLaTeX options document) $
- WriterState { stInNote = False, stOLLevel = 1, stOptions = options,
- stVerbInNote = False, stEnumerate = False,
+ WriterState { stInNote = False, stOLLevel = 1, stUsedIdents = [],
+ stOptions = options, stVerbInNote = False, stEnumerate = False,
stTable = False, stStrikeout = False, stSubscript = False,
stUrl = False, stGraphics = False,
stLHS = False, stBook = False }
@@ -133,8 +134,14 @@ blockToLaTeX (Plain lst) = do
blockToLaTeX (Para [Image txt (src,tit)]) = do
capt <- inlineListToLaTeX txt
img <- inlineToLaTeX (Image txt (src,tit))
- return $ text "\\begin{figure}[htb]" $$ text "\\centering" $$ img $$
- (text "\\caption{" <> capt <> char '}') $$ text "\\end{figure}\n"
+ st <- get
+ let usedIdents = stUsedIdents st
+ let lab = uniqueIdent txt usedIdents
+ put $ st{ stUsedIdents = lab : usedIdents }
+ return $ text "\\begin{figure}[htb]" $$
+ text "\\centering" $$ img $$
+ (text "\\caption{" <> capt <> text ("}\\label{" ++ lab ++ "}")) $$
+ text "\\end{figure}\n"
blockToLaTeX (Para lst) = do
st <- get
let opts = stOptions st