Skip to content

Commit ef76a2e

Browse files
authored
Merge pull request #945 from KaranAhlawat/master
Update the book to have a guide on setup with `AucTeX`
2 parents 34afff0 + e63b5e1 commit ef76a2e

2 files changed

Lines changed: 124 additions & 0 deletions

File tree

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
- [Building Tectonic](howto/build-tectonic/index.md)
3434
- [Install Dependencies Externally](howto/build-tectonic/external-dep-install.md)
3535
- [Install Dependencies With cargo-vcpkg](howto/build-tectonic/cargo-vcpkg-dep-install.md)
36+
- [Use Tectonic with AucTeX](howto/auctex-setup/index.md)
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# How To: Use Tectonic with AucTeX
2+
3+
This section is a guide aimed at [GNU
4+
Emacs](https://www.gnu.org/software/emacs/) users for setting up
5+
[AucTeX](https://www.gnu.org/software/auctex/) with Tectonic as the TeX/LaTeX
6+
distribution.
7+
8+
## Basic Prerequisites
9+
10+
To follow this section you will need Tectonic and GNU Emacs installed on your
11+
system. Additionally, you will require the AucTeX emacs package to be installed
12+
before following along.
13+
14+
> Note: This section makes use of the [V2 tectonic CLI](../../ref/v2cli.md),
15+
> invoked using the `tectonic -X` flag or `nextonic` command alias.
16+
17+
## Setup
18+
19+
All the code displayed in this section should go into your `init.el` file (or
20+
equivalent, such as `config.el` if you are using
21+
[Doomemacs](https://github.com/doomemacs/)).
22+
23+
First, load the AucTeX package.
24+
25+
```lisp
26+
(require 'latex)
27+
```
28+
29+
You will need to set the default TeX engine AucTeX uses to figure out the build
30+
commands to use Tectonic instead of traditional TeX distributions. Therefore we
31+
have to modify the `TeX-engine-alist` varible.
32+
* The first element of the list is the symbol that AucTeX recognizes.
33+
* The second element is a string with the name of the TeX distribution.
34+
* The third element is the shell command for compiling plain TeX documents.
35+
* The fourth element is the shell command for compiling LaTeX documents. Here we
36+
are assuming the user is using a Tectonic project (generated using `tectonic -X
37+
new <proj-name>`).
38+
* The last element is the shell command for compiling ConTeXt documents, left
39+
unconfigured for now.
40+
41+
```lisp
42+
(setq TeX-engine-alist '((default
43+
"Tectonic"
44+
"tectonic -X compile -f plain %T"
45+
"tectonic -X watch"
46+
nil)))
47+
```
48+
49+
Next, modify the `LaTeX-command-style` so that AucTex doesn't add extra options
50+
to it that Tectonic does not recognize. We simply set it to the `%(latex)`
51+
expansion (from `TeX-expand-list-builtin`), removing any other extra options.
52+
53+
```lisp
54+
(setq LaTeX-command-style '(("" "%(latex)")))
55+
```
56+
57+
We need to set the `TeX-check-TeX` variable to `nil` since AucTeX will try to
58+
find a traditional distibution like `TeXLive` or others, and will fail since
59+
Tectonic doesn't meet it's criteria.
60+
61+
Additionally, we should also set `TeX-process-asynchronous` to `t`, so that
62+
running Tectonic in watch mode doesn't hang up Emacs.
63+
64+
We'll also just ensure that the `TeX-engine` is set to `default`.
65+
66+
```lisp
67+
(setq TeX-process-asynchronous t
68+
TeX-check-TeX nil
69+
TeX-engine 'default)
70+
```
71+
72+
Finally, modify the `TeX-command-list` to use the appropriate commands, and not
73+
pass in extra metadata and options to Tectonic which cause it to error out. This
74+
needs to be done in place.
75+
76+
```lisp
77+
(let ((tex-list (assoc "TeX" TeX-command-list))
78+
(latex-list (assoc "LaTeX" TeX-command-list)))
79+
(setf (cadr tex-list) "%(tex)"
80+
(cadr latex-list) "%l"))
81+
```
82+
83+
And that is all! You should now be able to
84+
1. Compile plain TeX files.
85+
2. Build Tectonic LaTeX projects in watch mode.
86+
87+
## Additional Configuration and Usage Suggestions
88+
89+
### Compile LaTeX outside a Tectonic project
90+
91+
To do this, you can simply invoke `M-x TeX-command-master`, and the select the
92+
`Other` option, passing in the compile command `tectonic -X compile -f latex <name
93+
of file>`.
94+
95+
> **Caution**: Compiling a document with multiple LaTeX files in this manner
96+
> isn't extensively tested, as using a Tectonic project is the better way in
97+
> that case. Any bug reports are welcome.
98+
99+
### Live PDF Preview in Tectonic projects
100+
101+
AucTeX expects the output PDF after compiling to be in the same directory as the
102+
input file. So it will error out when that is not the case, since Tectonic
103+
places the output in a build directory.
104+
105+
This behavior can be controlled by using the `TeX-output-dir` variable on a per
106+
project basis.
107+
108+
This configuration assumes you are using `project.el`, although porting this
109+
code to `projectile.el` should be trivial.
110+
111+
```lisp
112+
(add-hook 'after-change-major-mode-hook
113+
(lambda ()
114+
(when-let ((project (project-current))
115+
(proot (project-root project)))
116+
(when (file-exists-p (expand-file-name "Tectonic.toml" proot))
117+
(setq-local TeX-output-dir (expand-file-name "build/index" proot))))))
118+
```
119+
120+
We are basically looking for `Tectonic.toml` file in the project root, and if it
121+
exists, setting the `TeX-output-dir` to the appropriate path to the build
122+
directory. You may replace the `"build/index"` path to wherever your PDF file is
123+
placed after it is generated by Tectonic.

0 commit comments

Comments
 (0)