출처: https://kevinlanguasco.wordpress.com/2019/04/29/latex-editing-with-emacs-on-manjaro/
A first-timer setup guide to Emacs for LaTeX editing
For four years now, I’ve almost exclusively been using TeXstudio for LaTeX editing. I can’t deny it’s a wonderful IDE, but due to certain inconveniences and the itch of trying new things, I decided to give some other editor a go.
There’s a great thread on StackExchange listing many LaTeX editors (which, incidentally, is where I discovered TeXstudio). As of this writing, the one with the most votes is Emacs with AUCTeX, so why not try that one?
In this post I’ll be explaining my approach as a first-timer to Emacs with the goal of writing LaTeX.
Emacs
The thing with Emacs is that it’s not just a plain old editor. First of all, it’s a family of text editors, being GNU Emacs the most popular one, and the one we’ll be referencing to from now on. It’s very famous in the Unix world because of its extensibility and how powerful it can be: it even includes a real web browser where you can watch YouTube.
Obligatory xkcd referenceTo install it in Manjaro (or Arch Linux variants in general), we simply use pacman (for more information, read the Arch Wiki entry):
sudo pacman -S emacs
I suggest using the GUI version because of some features that might be lost otherwise, in the terminal version. For people who come from vim, there’s Spacemacs and evil-mode, which seem amazing, but I haven’t tried them yet to get a good feeling of vanilla Emacs first.
The basic key notation used for Emacs commands is:
C-x CTRL + x
M-x ALT + x
M-x text ALT + x, then write "text"
For starters, the built-in tutorial is great, and can be accessed from the splash screen or C-h t. It’s a must-read and can be done in around 30 minutes. After that, there’s a vast amount of information both on the Internet and the included documentation.
The default configuration of Emacs is not without its flaws. A first annoyance I had was that scrolling with a trackpad moved 5 lines at a time. There’s more than one approach to solve this: See the Smooth Scrolling article in the Emacs Wiki and this StackOverflow question.
Note that initialization code can be written either in ~/.emacs or ~/.emacs.d/init.el. There are advantages to the latter, see this discussion.
Built-in TeX mode
Emacs works with major and minor modes. You can switch between major modes to select different sets of functionality suited for the current task, and add minor modes for additional features.
Emacs comes with a bare-bones TeX mode. The documentation is very short, so I suggest reading it in its entirety to get a feel of how modes work. One cool feature is the smart insertion of quotes: pressing ‘ ” ‘ will write the opening or closing quotation marks, according to context, removing the mental burden of selecting one character or the other.
Other useful additions include pressing C-c C-o for inserting \begin and \end tags, and, of course, invoking TeX.
There you go! You can start writing LaTeX with Emacs now. But in order to get the bells and whistles, we need to install a package.
Packages in Emacs
Package management is natively supported by Emacs with ELPA. To show all available packages, use
M-x list-packages
There, we can use C-s to search for a particular thing we want to install, press i to select it, and finally x to execute the installation. We do this for the AUCTeX package.
AUCTeX
Refer to the official Quick Start guide for an introduction. For multi-file document structure and LaTeX packages support, put the following in your initialization file:
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
AUCTeX includes various modes, but for now we’ll be using the default LaTeX-mode. This should be active every time you open a .tex file.
There’s a vast amount of shortcuts, better explained here. For example, compiling the document can be done using C-c C-a. In order to view the compiled document, by default we need to have Evince installed. Zathura or Okular can also be configured for this purpose.
preview-latex
Among the coolest features included with AUCTeX is preview-latex, which renders LaTeX math equations in the editor itself. It’s kind of similar to Lyx, but doesn’t give you any abstraction over LaTeX or a graphical equation builder. Instead, you write plain LaTeX as usual, and run the preview command C-c C-p C-d to get a neat-looking images over the code right in the editor window.
An issue I encountered here was that even though the images were being generated, they weren’t displayed. Apparently this is a bug that only occurs in PDF mode, so a fix is to turn this off; but I noticed that doing this caused bibliography with BibLaTeX to not output anything in the DVI file, so another option is to keep it on but first compile the DVI, and then convert it to PDF (Clicking on the LaTeX/P button -> Command -> TeXing options -> PDF from DVI -> dvips + ps2pdf).
The error appearing when using LaTeX/P (PDF mode)If the images are too small, we can modify the preview-scale-functionvariable. See this post.
To clear all the preview images, use
M-x preview-clearout-buffer
Where to go from here?
One killer feature I haven’t touched is the integration with RefTeX, a package for managing citations and references. From what I’ve read, it’s very good. There’s also integration with Zotero for even easier bibliography management. It might also be worth trying out latexmk for compilation.
Org-mode, one of the most well-known Emacs modes, can be used to write LaTeX documents with a simpler syntax. It can be useful for taking class notes, for example.
Finally, it’s up to each of us to find our own preferred workflow. There’s this wonderful guide with suggestions, but of course this can only be done with a lot of practice, experimentation and reading.
'컴퓨터 활용(한글, 오피스 등) > 기타' 카테고리의 다른 글
MiKTEX 구축 VScode Tex (0) | 2025.02.02 |
---|---|
Setting up Emacs, LaTeX for Windows (0) | 2025.02.02 |
[LaTeX] LaTeX 배포판과 에디터 프로그램 (0) | 2025.02.02 |
Latex 편집기 - Texmaker TexLive Texstudio (0) | 2025.02.01 |
Emacs "pdf wasn't produced" (0) | 2025.02.01 |