@@ -45,25 +45,26 @@ import Text.Pandoc.Highlighting (highlight, styleToLaTeX,
4545 formatLaTeXInline, formatLaTeXBlock)
4646
4747data WriterState =
48− WriterState { stInNote :: Bool -- true if we're in a note
49− , stInTable :: Bool -- true if we're in a table
50− , stTableNotes :: [(Char, Doc)] -- List of markers, notes
51− -- in current table
52− , stOLLevel :: Int -- level of ordered list nesting
53− , stOptions :: WriterOptions -- writer options, so they don't have to be parameter
54− , stVerbInNote :: Bool -- true if document has verbatim text in note
55− , stEnumerate :: Bool -- true if document needs fancy enumerated lists
56− , stTable :: Bool -- true if document has a table
57− , stStrikeout :: Bool -- true if document has strikeout
58− , stSubscript :: Bool -- true if document has subscript
59− , stUrl :: Bool -- true if document has visible URL link
60− , stGraphics :: Bool -- true if document contains images
61− , stLHS :: Bool -- true if document has literate haskell code
62− , stBook :: Bool -- true if document uses book or memoir class
63− , stCsquotes :: Bool -- true if document uses csquotes
64− , stHighlighting :: Bool -- true if document has highlighted code
65− , stFirstFrame :: Bool -- true til we've written first beamer frame
66− , stIncremental :: Bool -- true if beamer lists should be displayed bit by bit
48+ WriterState { stInNote :: Bool -- true if we're in a note
49+ , stInTable :: Bool -- true if we're in a table
50+ , stTableNotes :: [(Char, Doc)] -- List of markers, notes
51+ -- in current table
52+ , stOLLevel :: Int -- level of ordered list nesting
53+ , stOptions :: WriterOptions -- writer options, so they don't have to be parameter
54+ , stVerbInNote :: Bool -- true if document has verbatim text in note
55+ , stEnumerate :: Bool -- true if document needs fancy enumerated lists
56+ , stTable :: Bool -- true if document has a table
57+ , stStrikeout :: Bool -- true if document has strikeout
58+ , stSubscript :: Bool -- true if document has subscript
59+ , stUrl :: Bool -- true if document has visible URL link
60+ , stGraphics :: Bool -- true if document contains images
61+ , stLHS :: Bool -- true if document has literate haskell code
62+ , stBook :: Bool -- true if document uses book or memoir class
63+ , stCsquotes :: Bool -- true if document uses csquotes
64+ , stHighlighting :: Bool -- true if document has highlighted code
65+ , stFirstFrame :: Bool -- true til we've written first beamer frame
66+ , stIncremental :: Bool -- true if beamer lists should be displayed bit by bit
67+ , stInternalLinks :: [String] -- list of internal link targets
6768 }
6869
6970-- | Convert Pandoc to LaTeX.
@@ -77,10 +78,15 @@ writeLaTeX options document =
7778 stUrl = False, stGraphics = False,
7879 stLHS = False, stBook = writerChapters options,
7980 stCsquotes = False, stHighlighting = False,
80− stFirstFrame = True, stIncremental = writerIncremental options }
81+ stFirstFrame = True, stIncremental = writerIncremental options,
82+ stInternalLinks = [] }
8183
8284pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
8385pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
86+ -- see if there are internal links
87+ let isInternalLink (Link _ ('#':xs,_)) = [xs]
88+ isInternalLink _ = []
89+ modify $ \s -> s{ stInternalLinks = queryWith isInternalLink blocks }
8490 let template = writerTemplate options
8591 -- set stBook depending on documentclass
8692 let bookClasses = ["memoir","book","report","scrreprt","scrbook"]
@@ -430,13 +436,14 @@ sectionHeader ref level lst = do
430436 let stuffing = optional <> char '{' <> txt <> char '}'
431437 book <- liftM stBook get
432438 let level' = if book then level - 1 else level
433− let refLabel lab = (if (not . null) ref
434− then text "\\hyperdef"
435− <> braces empty
436− <> braces (text ref)
437− <> braces (lab <> text "\\label"
438− <> braces (text ref))
439− else lab)
439+ internalLinks <- gets stInternalLinks
440+ let refLabel lab = (if ref `elem` internalLinks
441+ then text "\\hyperdef"
442+ <> braces empty
443+ <> braces (text ref)
444+ <> braces (lab <> text "\\label"
445+ <> braces (text ref))
446+ else lab)
440447 $$ blankline
441448 let headerWith x y = refLabel $ text x <> y
442449 return $ case level' of