Does pandoc support Synctex?
Asked Answered
D

1

29

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?

Devil answered 1/12, 2014 at 17:39 Comment(4)
Same question here!Leucine
3 years later and I don't think this is supported yet. This would be a great feature!Thiouracil
Another 3 years later, and all I can say: Probably no. Even latex packages rarely intentionally take SyncTeX into account; For instance apxproof doesn't support SyncTeX, and the popular beamer package damages the support to the point of becoming nearly unviable. If the toolchain from source code to PDF contains anything but pdflatex, you are likely looking at significant effort to retain the information during the conversion and modifying the .synctex[.gz] file.Catima
@kdb: It's not trivial, but I have written code to patch the source data in .dvi files as well as Synctex data from pdflatex, when the source file is Sweave preprocessed by R into LaTeX. Six years later I'd still like to do the same when the source is Markdown processed by Pandoc, either into LaTeX or into HTML, but I'm not holding my breath.Devil
D
1

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.

Devil answered 23/10, 2022 at 15:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.