Does pandoc support Synctex?

1000 views Asked by At

I've spent a week writing an R vignette using knitr, with input in R Markdown, and output in HTML. Previously all vignettes that I wrote were in Sweave with a PDF target.

One of the things I miss is Synctex, which gives the ability to jump from the PDF preview back to the corresponding line in the file. As far as I can see, knitr supports this when producing LaTeX output (using the same scheme as Sweave, I think), but not when producing HTML output.

I know that the R Markdown to HTML process goes through pandoc, so I checked the pandoc docs, but couldn't find any mention of Synctex there.

So my questions are:

  1. Are there any HTML browsers that support something like Synctex for forward and reverse search from an editor? (Since RStudio has its own built-in browser, it could be doing this...)

  2. Does pandoc support any Sweave-like scheme for relating output locations in the HTML file to input locations in the .md input?

1

There are 1 answers

0
user2554330 On BEST ANSWER

As of October, 2022 Pandoc doesn't support Synctex directly, but there are some underpinnings of support described here: https://github.com/jgm/pandoc/issues/4565#issuecomment-749294039. In summary:

  • If the input is Commonmark, use the sourcepos extension and a record is kept internally of the source locations. For example, this option on the command line: --from commonmark+sourcepos.

  • If the output is HTML, the locations will be inserted as data-pos attributes on various components, e.g. <div class="section level2" data-pos="Untitled.knit.md@11:1-12:1"> to indicate that the DIV is based on things from col 1 of line 11 to col 1 of line 12 of the Untitled.knit.md file.

  • If the output is LaTeX, each word in the document will be wrapped in braces, but the source position is not entered in the file. It can be retrieved directly using a separate run of pandoc with --to json replacing --to latex, e.g.

    pandoc --from commonmark+sourcepos --to json -i test.md -o test.json  
    

    This writes a JSON file describing the structure of the output and containing the data-pos attributes. As far as I know, matching this up to the .tex file (or the resulting .pdf file) is a somewhat difficult exercise left for the reader.