Progress Report
Four months on, I thought it a good idea to "report back" here, and I wrote something. Then, I had better thoughts and turned it into a blog post.
You can read it on the TeX.sx blog.
Prompted by a recent conversation in the chat room, I am thinking of revisiting emacs as my source editor. In order to give it a good chance (I have failed with four or five previous attempts over the past ten years or so), I'd like to ask for useful tips, or pointers to larger works, to make this transition from TeXWorks as smooth as possible.
Key features of my modus operandi are:
- heavy use of
memoir
,beamer
, andtikz
- structured documents with
\input
andstandalone
- lualatex (with occasional ventures needed into xelatex or pdflatex), driven by latexmk
biblatex
(using bibtex rather than biber, but only through inertia)- unicode, with no exceptions
- Windows 7
- Ouside TeXWorks, general-purpose PDF viewer: PDF XChange
Among the questions and uncertainties I should like to see addressed (some of which, I accept, may not be directly on-topic — links may be more suitable in these cases) are these:
- Initial setup of emacs, including (…)TeX-workflow-specific add-ons
- Compilation and preview direct from the emacs environment
- Synchronisation of source and preview
- Auto-completion
- Spelling (EN-GB, PT-BR, ES, and FR)
- Any other hints, bear-traps, and so forth
- A good tutorial
Best Answer
I have never used Emacs in Windows but I started to learn and use Emacs only eight or nine months ago and I now use it for most of my work.
Learning
First you need to get comfortable with the basics of Emacs and probably this is what will be your main frustration. For a new user the commands for basic usage can be a pain to learn because they are unlike other editors. Let the learning process take time and you will eventually be very efficient. Know that once you get past the culture shock and learn the basics you will enjoy Emacs.
A good way to start learning the basics of Emacs is by its built-in tutorial which you can access via C-h t. Take your time and follow the tutorial from beginning to end. Make sure you learn how to navigate in buffers, edit buffers, open new buffers and switch between buffers. You do not need to learn it all at once. You can always go back to the tutorial.
Once you can handle the basics you should try to do some of your work in Emacs. Use your old editor in parallel to begin with. The first month or two you mighta switch back and forth before you spend most time in Emacs. The important thing is that you take time to get used to Emacs and try to learn new things every now and then. Even long-time users learn new things once in a while. It is a never-ending learning process.
You may have habits and ways of doing things that conflict with the way of Emacs. Sometimes it is best to adapt Emacs to how you are used to work and sometimes Emacs has a better way and then you are better off adapting. As an example, when I started to use Emacs I thought its way of opening files and switching between buffers was complicated and awkward so I tended to use menus and the toolbar for these tasks. But as I understood and got used to the commands for handling buffers, such as C-x b for switching between buffers, I was impressed by its efficiency. Something you might want to learn for further efficiency of switching between files is the bookmarks feature.
For learning more about Emacs its internal help is good. You can see the help options by doing C-h ?. As usual the web is great for help. A particular site is EmacsWiki. On the Stack Exchange network this site is good for TeX related Emacs issues but sometimes you are better off asking at Stack Overflow where more Emacs gurus are hanging out. For general and non-programming question about Emacs you can try Super User. Finally, the chat might be a good place for venting your Emacs related frustration (or euphoria).
Modes and tools
What you want to use for LaTeX is the Emacs mode AUCTeX for which http://emacswiki.org/emacs/AUCTeX is a good resource, see also Useful shortcuts or key bindings or predefined commands for emacs+AUCTeX. The best way to get started with and learn AUCTeX is probably to read the quick start. I have included some configuration that is good to start with when using AUCTeX in the setup below. AUCTeX can handle
\input
andstandalone
.I have never used
memoir
so I do not know if there is some particular Emacs gadget to help with it. Generally YASnippet is a great way to make it easier to insert structures you often insert and for making templates, so it should be helpful formemoir
too. The same goes forbeamer
. Another way to create beamer slides is via another Emacs mode called Org-mode which is a mode for keeping notes, maintaining TODO lists, doing project planning, and authoring. What you do is to write an org file and export it to beamer. Finally, for TikZ checkout AucTeX extension for TikZ.You can setup Emacs to work with latexmk (my preferred way is https://stackoverflow.com/a/8026921/789593). Then, since you use latexmk you can set up biblatex with bibtex and compilation with lualatex, xelatex and pdflatex via latexmk's own configuration.
For inserting
biblatex
citation macros and cross-references you use RefTeX which comes with AUCTeX. Check out Setting up RefTeX with biblatex citation commands for configuration. In the configuration below I already included such lines.Emacs has full support for unicode and it has auto-completion for most commands. AUCTeX also provides auto-completion for TeX commands.
Emacs has good tools for spelling. I use Flyspell when I need to check spelling but I keep it off while writing to avoid distraction. With AUCTeX it knows the difference between code and text. To use Flyspell do M-x flyspell-buffer to spell check the whole buffer or M-x flyspell-region to spell check the marked region. If you want to integrate spell checking with LaTeX language packages the following questions might be interesting for you:
Workflow
I have already written about workflow in Everyday LaTeX and workflow? It includes a general description of a workflow for LaTeX but without a particular editor in mind and a short description on how to implement it via Org-mode and AUCTeX. I think outlining and drafting is best done in Org-mode. AUCTeX is best later in the process. Since your question is about Emacs and LaTeX in particular I will not say more about Org-mode but focus on AUCTeX.
What is the best workflow may vary between tasks and persons. The following is just some general notes on how you can work with LaTeX files in Emacs. When you edit LaTeX files in Emacs you will probably spend most time using AUCTeX but since you use use biblatex you will also edit .bib files. Roughly, work with LaTeX files can be classified as either writing or compiling.
When it comes to writing you should use the all the basic commands in Emacs to navigate in text and to edit text. These you learn by practice. AUCTeX provides some LaTeX specific commands which you should learn, make sure to checkout the commands for creating macros, C-c Enter, and environments, C-c C-e, LaTeX-math-mode and the RefTeX commands for inserting citations and cross-references, see the AUCTeX resources above for details. To speed up and make creation of LaTeX files easier you can use templates via YASnippet as described in Working with templates. Also, there is a special mode for .bib files which can ease editing such files.
When it comes to compiling you can use latexmk as described above but you can also use AUCTeX built-in compiling method which is quite good (C-c C-c). To view the output of the current buffer simply do C-c C-v. If the compilation fails AUCTeX can take you to the line where the error occurred.
Another aspect of workflow is to track changes. This can be done via revision control, see What are the advantages of using version control (git, etc.) in LaTeX documents and What are good working practices for VCS with LaTeX documents? for details. Emacs has built-in support for many revision control systems. If you use git magit is superior to the built-in git support.
Setup
Your Emacs configuration is based in your .emacs file which is a text file consisting of Lisp code. You do not have to know Lisp to configure Emacs (although you will benefit from knowing some). Often you proceed by finding snippets on the net which you paste into your .emacs.
Configuring Emacs is a never-ending process. There is nothing wrong with this. You adapt it to your needs as you go. However, it is good to have something to start with. Below you find an .emacs to start with. I took my .emacs and removed most things except some minor display configuration, some general AUCTeX and RefTeX configuration and some configuration for proper syntax highlighting of macros from popular packages such as
enumitem
,biblatex
andcsquotes
macros. I have commented it heavily so that it is easier to understand what it does. If there is some configuration you do not like you can just remove the relevant lines or comment them to deactivate them. Make sure to keep backups of your .emacs so that you do not lose your configuration.