showyourwork / showyourwork

A workflow for reproducible and open scientific articles

Home Page:https://show-your.work

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SyncTex references the wrong `ms.tex`

MilesCranmer opened this issue · comments

I was wondering why whenever I try to query synctex from PDF->TeX, it seems to open ms.tex from the directory .showyourwork/compile/ms.tex. Likewise, only when I query synctex from TeX->PDF, it only works if I try on the synctex version.

Lo and behold, if you gunzip ms.synctex.gz and read the first line, it states:

Input:1:<WORKSPACE>/.showyourwork/compile/ms.tex

i.e., it is connected to a file at the incorrect location. So effectively SyncTeX cannot be used with your source code; you have to view the location in the .showyourwork/compile version and then find it in the src/ version manually.


Related, which might already be a known issue: I don't think ms.synctex.gz is being copied to the workspace directory, it is left in /compiled. I am currently using the hack:

watchexec -w .showyourwork/compile/ms.synctex.gz cp .showyourwork/compile/ms.synctex.gz ./

but I thought it was just my system that was buggy. But it looks like the snakefile is not copying the synctex file back?

Update: here's a dirty hack that fixes this. It's probably not robust at all but it seems to work for me.

First, make the file copy_synctex.sh in your workspace directory and make it executable:

#!/bin/zsh
set -e

# Only copy if exists:
TMPDIR=$(mktemp -d)
if [ -f .showyourwork/compile/ms.synctex.gz ]; then
    cp .showyourwork/compile/ms.synctex.gz $TMPDIR/
    pushd $TMPDIR
    gunzip ms.synctex.gz
    sed -i 's/.showyourwork\/compile\///g' ms.synctex
    gzip ms.synctex
    popd
    cp $TMPDIR/ms.synctex.gz ./ms.synctex.gz
fi

then, install watchexec, and run the following command in the background, whenever you are working on your project:

watchexec -w .showyourwork/compile/ms.synctex.gz ./copy_synctex.sh

so whenever there's a new synctex file ready, it will copy it to a temp dir, unzip it, delete all instances of .showyourwork/compile/, zip it, the copy it to your workspace dir.

This could be because the full path to the manuscript is provided when calling tectonic... Could you check if manually running tectonic in the compile directory, but passing the relative filename for ms.tex puts the correct paths in the synctex? Thanks!

I tried this out and passing relative filenames doesn't seem to do the trick. But, interestingly, if ms.pdf and ms.synctex.gz end up in src/tex rather than at the top level, the links do work, even with the incorrect absolute paths in the synctex. I propose that we just put a copy of the pdf in the tex directory! Edit: maybe not - still experimenting!