28

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?

user2554330
  • 37,248
  • 4
  • 43
  • 90
  • Same question here! – Farid Cheraghi Dec 27 '16 at 23:19
  • 3
    3 years later and I don't think this is supported yet. This would be a great feature! – tmastny Oct 01 '17 at 15:29
  • 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. – kdb Apr 29 '20 at 13:43
  • @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. – user2554330 Apr 29 '20 at 16:49

1 Answers1

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.

user2554330
  • 37,248
  • 4
  • 43
  • 90