- You edit
.texfiles locally in DocWriter. - The PDF rebuilds on every save and a preview window stays in sync.
- Double-clicking the PDF jumps to the source line.
- Accepted edits flow back to Overleaf as git commits after each agent turn.
Prerequisites
- DocWriter installed.
- A TeX distribution with
pdflatex,bibtex, andsynctexon yourPATH. On macOS, MacTeX is the easiest install. On Linux, installtexlive-full. giton yourPATH.- An Overleaf project. The free tier supports git integration; for older free accounts you may need the paid plan.
1. Get the project locally
Overleaf offers two ways to sync a project to your machine. Either works with DocWriter; pick whichever fits your existing workflow.Option A: Sync to GitHub (recommended)
If you use GitHub already, this is the cleaner path. In Overleaf, open the project’s Menu (top-left), find the Sync section, and click GitHub. Authorize Overleaf to access your GitHub account, then pick a repository (or let Overleaf create one). Overleaf will keep the two sides in sync going forward. Then on your machine:Option B: Clone Overleaf’s git endpoint directly
Overleaf also exposes a direct git remote atgit.overleaf.com. In the
project’s Menu, Sync section, click Git to find the clone
URL:
2. Open the project in DocWriter
main.tex or whatever your entry file is named, plus chapter files, a
.bib, and figures).
Click main.tex. It opens as a tab in the editor. .tex source is shown
as plain text. DocWriter does not try to render LaTeX in the editor; the
preview window does that.
3. Wire up the LaTeX build hook
In the menu bar, open Settings and click Hooks. In the template chip row, click the pdflatex chip. The add-form fills in:- Event:
PostToolUse - Matcher:
Edit|Write - Command:
- Output:
main.pdf
main.tex, edit the command (replace
both main.tex and main) and the output (replace main.pdf) to match.
The three pdflatex passes and the bibtex call resolve cross-references
and citations in one go. The -synctex=1 flag is what makes
double-clicking the PDF jump to source later.
Click + to save.
4. First build
Click Run now on the new hook. The first run takes a few seconds and the history pane shows the progress. On success, the hook producesmain.pdf in the project root.
If the build fails, the history pane shows the stderr. Common first-run
issues:
- Missing packages. Install via
tlmgr install <package>if you are on TeX Live, or run the build once outside DocWriter so MacTeX can auto-install. - Wrong entry file name. Edit the hook’s command and output.
5. Open the preview
A Preview button now appears in the top-right of the editor (because the active tab’s stem matches the hook’s output). Click it. A popup window opens with the PDF. Drag it to a second monitor or arrange it side-by-side with DocWriter.![A .tex file open in the editor with a [[ ... ]] directive asking for a TikZ figure](https://mintcdn.com/ucberkeley-8d9be701/pOA9wX63uxLFsbqp/images/overleaf-tex-open.png?fit=max&auto=format&n=pOA9wX63uxLFsbqp&q=85&s=6bd33ce9ec179821aa7bbaccf03056f3)
\section{Introduction} add a single commented
line:
% keeps pdflatex happy if it builds before the agent
handles the directive; the agent still picks the directive up. A few
seconds after you stop typing, the agent reads the file, adds the
necessary \usepackage{tikz} to the preamble, replaces the commented
line with a real \begin{figure} block, and proposes both as pending
reviews.
You can keep editing the document while this is happening. The
screenshot below was captured mid-flight: the agent’s proposed TikZ
block sits as a pending review on the right, the directive is struck
through in the editor, and a sentence typed by the user at line 114
(in the abstract body) is already in the document, plain prose, no
conflict. The two streams are concurrent edits on the same file.



6. Test the loop
Edit something inmain.tex. The hook fires on every save, pdflatex
rebuilds, and the preview window reloads with the new PDF. Scroll
position is preserved across reloads.
Double-click any text in the PDF preview. DocWriter resolves the click
to a source line via synctex, switches to that file in the editor, and
scrolls to the line.
7. Add the auto-push hook
To send your work back to Overleaf as you go, add a git hook: In the hooks panel, click the Git auto-commit & push on Stop chip. The form fills in:- Event:
Stop - Command:
+ to save.
The hook fires after every agent turn ends. It commits any pending
changes (your typing and any accepted agent edits) and pushes to the
current branch’s upstream.
If
git push ever prompts for credentials, run it once manually in a
terminal so your git credential helper caches the Overleaf token.
DocWriter cannot answer a credential prompt.8. Drive the agent
Click Send in the top-right of the editor. Type a prompt:Tighten the abstract.After three seconds, the agent submits. It calls
read_doc on
main.tex, then edit_doc with the proposed change. The change appears
as a pending review in the right pane.
Click Accept. The accepted edit:
- Counts as an
Edittool call, so your pdflatex hook fires. - The preview window reloads with the rebuilt PDF.
- The turn ends,
Stopfires, the git hook commits and pushes.
9. Pull collaborator changes
DocWriter does not auto-pull. If you have collaborators working in Overleaf’s web editor (or via GitHub if you chose Option A in step 1), periodically run:SessionStart hook if you want it to run every
time DocWriter starts:
- Event:
SessionStart - Command:
git pull --rebase --autostash || true
--autostash and || true ensure the hook does not fail if you have
uncommitted local changes.)
With the GitHub sync path (Option A), pushes from DocWriter land in your
GitHub repo; Overleaf picks them up on its next sync. Pulls happen in
the other direction. The latency between Overleaf and GitHub is
usually a few seconds.
Troubleshooting
Preview button doesn’t appear. The active tab’s stem does not match any hook’s output. Check that the hook has anoutput field set and that
it matches your entry file (e.g. main.pdf, not paper.pdf).
Double-click PDF does nothing. Make sure pdflatex ran with
-synctex=1 (the template includes it) and that the synctex binary is
on your PATH. Run which synctex to verify.
Auto-push hook silently fails. Check the hook’s history-pane card
for stderr. Most commonly: no upstream set on the branch, or the credential
prompt is asking for a token DocWriter cannot answer. Push once from a
terminal to seed credentials.
Brackets in agent edits fail to apply. The markdown serializer
escapes [ as \[. This rarely matters for .tex files but can come
up. If an agent edit fails with “old_string not found”, look for an
escaped bracket in the source.
Where to go next
- Hooks. Write your own hooks for other toolchains.
- Live preview. Synctex, themes, and HTML/image previews.
- Delegating tasks. Longer-running agent work (multi-file rewrites, build-fix loops).