Input and compilation/Text editors/SyncTeX
SyncTeX is a program that puts a lot of anchors in the output file that link to the corresponding position in the source file. This allows you to quickly jump from PDF to source.
Contents
Usage
You can use the --synctex
switch to enable SyncTeX.
context --synctex jobname
Alternatively you can add one of the following commands to your MkIV document:
\setupsynctex[state=start,method=min] % clickable words \setupsynctex[state=start,method=max] % more efficient clickable ranges
This will create a file jobname.synctex
. The command
context --purge
or next run without --synctex
will remove the file again.
Some editors/viewers need a different format, that you can enable by --synctex=repeat
resp. \setupsynctex[state=repeat]
.
To see what became clickable, use one of
\enabletrackers[system.synctex.visualize] \enabletrackers[system.synctex.visualize=real]
This file can be used by your editor and PDF viewer to jump back and forth between the source and the PDF.
Editors & Viewers
TeXshop
Works quite well, but needs “magic lines” like:
% !TEX TS-program = ConTeXt2023 % !TEX useAlternatePath % !TEX useConTeXtSyncParser
Setup see extra page on TeXshop.
TeXWorks
You may need to modify the command for executing ConTeXt first (you need to add --synctex
switch in preferences).
Emacs + auctex
To implement forward search with auctex (i.e., open the viewer at the right page from emacs) creating a shell script called synctex in some directory which precedes one containing the "usual" synctex (if any) in your $PATH with the following contents has been demonstrated to work on at least Slackware64 15.0:
#! /bin/zsh # synctex replacement to allow forward search from emacs+auctex to (at least) evince # Emacs + auctex calls synctex up to three times. # For example, attempting to view the PDF of <FILE>.tex would cause # emacs to run the following commands ($PWD is the path to the # current directory): # synctex view -i <LINE>:<COL>:$PWD/./<FILE>.tex -o <FILE>.pdf # synctex view -i <LINE>:<COL>:<FILE>.tex -o <FILE>.pdf # synctex view -i <LINE>:<COL>:$PWD/<FILE>.tex -o <FILE>.pdf line_number=${3%%:*} tex_file=${3##*:} synctex_file=${tex_file%.tex}.synctex # Transmogrify the output format of mtxrun into something that emacs+auctex # (and maybe other editors?) recognizes: mtxrun --script synctex --find \ --file=$tex_file --line=$line_number $synctex_file \ | sed 's/.*page=/Page:/'
(Note: this has only been tested with simple document structures.)
Evince, Okular & Kile
Okular (the KDE PDF viewer) and Evince (the GNOME one) support SyncTeX (the latter since version 2.32.0).
To forward something from a text editor to Okular, do
okular --unique '${pdffile}#src:${linenumber} ${texfile}'
Kile’s (the KDE TeX IDE’s) ForwardPDF function should support SyncTeX, but it doesn’t seem to work with ConTeXt at the time of writing
Kate & Okular
- You have to compile with --synctex=repeat
context --synctex=repeat myfile.tex
- From Okular to Kate (forward search)
- configuration > Configure Okular > Editor > Kate > kate --line %l --column %c
- the current mode should be "browse" ctrl+1, not "area selection", nor "text selection" etc...
- maj+clic will load the file in kate at the appropriate line
- From Okular to Kate (inverse search)
- no solution yet
Skim.app & TextMate (MacOS X)
In Skim/Preferences/Sync choose TextMate. The key combination
Shift + Apple + MouseClick
will bring you to the corresponding line in text editor.
In TextMate I have created my own command inside the ConTeXt bundle:
- Save: Nothing
- Command(s)
#!/bin/bash pdf=${TM_FILEPATH%tex}pdf /Applications/Skim.app/Contents/SharedSupport/displayline -r "$TM_LINE_NUMBER" "${pdf}"
- Input: None
- Output: Discard
- Activation: Key Equivalent (choose one; I used Ctrl+Alt+Apple+O)
- Scope Selector: text.tex.context
If you use Apple+R
for typesetting that needs to be modified as well (to account for --synctex switch).
Hopefully this functionality will become part of the official ConTeXt bundle one day. (The recipe given above is too specific. The code needs to be written to handle more different viewers and different locations, not only a single viewer at a specified location.)
Pulsar
- Install ConTeXt support from https://codeberg.org/fiee/language-context-lmtx
- Install the
pdfjs-viewer
plugin. There are several plugins for pdf.js, but only this works for me. - SyncTeX support is commented in the plugin’s source code; according to this open ticket, edit
~/.pulsar/packages/pdfjs-viewer/lib/pdfjs-viewer-view.js
:- uncomment line 71+72
- add "var" at the begin of line 217
- Set the path to the
synctex
binary (e.g. from TeX live) in the plugin preferences. - Restart the editor.
- Use
context --synctex=repeat myfile.tex
. - Open myfile.pdf from the editor’s file browser and right-click to find the source location.