Reputation: 44897
As described here, Pandoc records Synctex-like information when the source is commonmark+sourcepos
. For example, with this commonmark input,
---
title: "Sample"
---
This is a sample document.
the output in native format starts like this:
Pandoc
Meta
{ unMeta =
fromList [ ( "title" , MetaInlines [ Str "Sample" ] ) ]
}
[ Div
( "" , [] , [ ( "data-pos" , "Sample.knit.md@5:1-6:1" ) ] )
[ Para
[ Span
( ""
, []
, [ ( "data-pos" , "Sample.knit.md@5:1-5:5" ) ]
)
[ Str "This" ]
, Span
( ""
, []
, [ ( "data-pos" , "Sample.knit.md@5:5-5:6" ) ]
)
[ Space ]
, Span
( ""
, []
, [ ( "data-pos" , "Sample.knit.md@5:6-5:8" ) ]
)
[ Str "is" ]
but all that appears in the .tex file is this:
{This}{ }{is}...
As a step towards Synctex support, I'd like to insert the data-pos information as LaTeX markup, i.e. change the .tex output to look like this:
{This\datapos{Sample.knit.md@5:1-5:5}}{ \datapos{Sample.knit.md@5:5-5:6}}{is\datapos{Sample.knit.md@5:6-5:8}}...
This looks like something a Lua filter could accomplish pretty easily: look for the data-pos
records, copy the location information into the Str
record. However, I don't know Lua or Pandoc native language. Could someone help with this? Doing it for the Span
records would be enough for my purposes. I'm using Pandoc 2.18 and Lua 5.4.
Upvotes: 3
Views: 99
Reputation: 44897
Here is an attempt that appears to work. Comments or corrections would still be welcome!
Span = function(span)
local datapos = span.attributes['data-pos']
if datapos then
table.insert(span.content, pandoc.RawInline('tex', "\\datapos{" .. datapos .. "}"))
end
return span
end
Upvotes: 2