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