Emacs LaTeX mode quick start guide

We are trying use AUCTEX. Apparently AUCTEX mode is given by):

LaTeX-mode

and shows as LaTeX\P in when we do C-h m.

Emacs hooks are based on commands like this:

(add-hook 'LaTeX-mode-hook 'linum-mode)

Run emacs

C-c C-c and then followed by typing *mk so that it “compiles” with LaTeXmk. C-c C-a does everything without any prompt.

Folding

Tab does folding.

Keybindings

C-c C-e –> add environment

C-c ret –> add macros such as \item etc…

Error fontspec cannot use pdf-tex engine

ERROR: Fatal fontspec error: "cannot-use-pdftex"

--- TeX said ---
! 
! The fontspec package requires either XeTeX or LuaTeX.
! 
! You must change your typesetting engine to, e.g., "xelatex" or
! "lualatex"instead of plain "latex" or "pdflatex".
! 
! See the fontspec documentation for further information.
! 
! For immediate help type H <return>.

Please add the following to the end of the file and reopen it.

MUST REOPEN THE FILE, THESE THINGS ARE READ ONCE AT THE BEGINNING C-x C-v.

From here.

%%% Local Variables: 
%%% coding: utf-8
%%% mode: latex
%%% TeX-engine: xetex
%%% End: 

Check version of auctex by

C-h v AUCTEx-version

Another possibility

https://tex.stackexchange.com/a/26387/97901

(setq-default TeX-engine 'xetex)
(setq-default TeX-PDF-mode t)

in the init file. NOT TESTED!

Goal

I would like to write my resume and cover letter in Emacs. With this post I want to log what all I did to setup Emacs and how to get Latex working.

I would I ideally want a pdf on the right (within or not within Emacs), and left side to have the text.

How to easily install auctex?

How to manage packages within auctex?

How to display the pdf output?

how do make a simple document with hello world.

Info

The AUCTeX package provides more advanced features for editing TeX and its related formats, including the ability to preview TeX equations within Emacs buffers. Unlike BibTeX mode and the RefTeX package, AUCTeX is not distributed with Emacs by default.

AUCTeX also provides auto-completion for TeX commands.

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

Apprently there is this thing called YASnippet as described in Working with templates.

Compiling

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.

Latex for linux

I started with this simpletons guide, which was not really simple.

If you’re using a distro which packages LaTeX (almost all will do) then look for texlive or tetex. TeX Live is the newer of the two, and is replacing tetex on most distributions now. -stack

Latex for linux stack website suggests the use of texlive package. This allows for the use of latex in all its glory. There are different packages/types of installations such as:

texlive-full texlive-latex-base texlive-latex-extra texlive-latex-recommended texlive-generic-extra

texlive-full probably has everything. texlive-latex-base contains essential packages and so on.

You can always just start with texlive-latex-base and then just install the collections you need. (To find a collection with a package in use apt-cache search pacakge) There is no good way yet to install individual packages in Ubuntu, as tlmgr will run in user mode (installing packages only for one user). - stack

Point being that I might run into problems later if I need this for more than one user. Unlikely to be my case. If that is what happens then I can always remove and install the full thing. For now I see this as an opportunity to understand and install what I need, to get knowledge regarding this.

So I think I did

sudo apt-get install texlive-latex-base

To check if a package is installed use

apt list --installed texlive-latex-base

output:

texlive-latex-base/xenial-updates,xenial-updates,xenial-security,xenial-security,now 2015.20160320-1ubuntu0.1 all [installed]
N: There is 1 additional version. Please use the '-a' switch to see it

Configuring emacs to work with AUCTeX

How this whole thing will look is shown as in the video here, it is a good start to get a feel of what is happening!

Apparently you need latexmk

sudo apt-get install latexmk

But it is a package in emacs? I thought and I removed it along with dependencies using

sudo apt-get purge latexmk
sudo apt-get purge --auto-remove latexmk

But it turns out you need latexmk (latex make)

LatexMk is a Perl script for running LaTeX the correct number of times to resolve cross references, etc; it also runs auxiliary programs (bibtex, makeindex if necessary, and dvips and/or a previewer as requested) — emacswiki on latexmk

So I don’t know any more about it other than that it is needed for something and everyone seems to be using it. In case I had bib or something, it would take care of running Latex the necessary number of times.

So

sudo apt-get install latexmk

Add to init file based on the git repo. Install auctex-latexmk and then

(require 'auctex-latexmk)
(auctex-latexmk-setup)

In the case of my init file this is accomplished by adding auctex-latexmk to the list of packages to be installed and then adding (auctex-latexmk-setup) to the packages-init.el.

Running emacs

This seems to be the basic setup that you need to type C-c C-c and start with latexmk to make all the necessary files. And then C-c C-c with View to display PDF. Viewing is only done once to open a PDF.

TeX-evince-sync-view

souce

Hooks

  • Line number

      (add-hook 'LaTeX-mode-hook 'linum-mode)
    
  • folding

      (add-hook 'TeX-mode-hook
        (lambda () (TeX-fold-mode 1))); Automatically activate
                  ; TeX-fold-mode.
    

There are a lot of hot keys to remember if you want to fold using TeX-mode-hook as mentioned here

  • folding like org-mode with outline-minor-mode or Latex-extra as explained here

    (add-hook ‘LaTeX-mode-hook #’latex-extra-mode) (add-hook ‘LaTeX-mode-hook #’outline-minor-mode)

The keybinds it defines are a little hard to use for outline-minor-mode, so you might want to change some of them.

C-c @ C-a       show-all
C-c @ C-c       hide-entry

For Latex-extra

Similar to how org-mode hides and displays of subtrees, if you hit TAB on a section header latex-extra will hide the contents of that section for you. Hitting tab twice will expand it again. This will not interfere with whatever with other keybinds you have set for TAB, such as yasnippet or auto-completion. Shift-TAB will do the same for the entire buffer. Of course, the same goes for chapters, subsections, etc.

This is what I want!

preview-latex

AUCTeX already comes with preview-LaTeX apparently. The power of it can be seen in this video. It apprently can preview within the editor how say equations will acutally look, how plots will actually look.

Info- engines/ compilers

Engines: TeX, pdfTeX, XeTeX, LuaTeX, … These are the actual executable binaries which implement the different TeX dialects. The LaTeX format is implemented with both the pdfTeX (pdflatex) and XeTeX (xelatex) engines, for example. When someone says “TeX can’t find my fonts”, they usually mean an engine.

Formats: LaTeX, plain TeX, pdfLaTeX, … These are the TeX-based languages in which you actually write documents. When someone says “TeX is giving me this mysterious error”, they usually mean a format.

At a high level, the output format that gets used depends on the program you invoke. If you run latex (which implements the LaTeX format), you will get DVI; if you run pdflatex (which also implements the LaTeX format), you will get PDF.

pdflatex is a terminal command that tells the pdfTeX engine to use the LaTeX format. — stack

According to the source mentioned below, you can choose engine by

M-x customize-variable RET
TeX-engine RET

Also you can check which engine is being used now:

C-h v TeX-engine

Source

Diff type of engines and meanings and usage in emacs

Source

How to choose other engines/compilers

Resume

1 page academic CV’s

https://www.quora.com/What-are-some-elegant-serious-LaTeX-templates-for-an-academic-CV

Widely known 1 column CV 1 page

http://www.tjansson.dk/2009/03/writing-a-cv-in-latex/

MIT format

https://github.com/sb2nov/resume

Error handling with latexmk

Dealt with as and when the need arises! After a compile if you get errors.

C-c `

Look for error online and then go

finding things in a package

On http://packages.ubuntu.com/ you can search for packages containing some file.

Source

Instead of using the website it is also possible to do it in the terminal

apt-file find kpfonts.sty

Check if the suggested package is already installed

apt list --installed texlive-fonts-extra

If not install it.

sudo apt-get install texlive-fonts-extra

Package missing

  • marvosym missing,

    sudo apt-get install texlive-fonts-recommended

Source

  • fonstpec.sty not found

    Found that it was in texlive-latex-recommended from http://packages.ubuntu.com/. and installed it.

      apt list --installed texlive-latex-recommended
      sudo apt-get install texlive-latex-recommended
    
  • At this point I get an error : “Latex: problems after [0] pages”

No use searching online. So I changed to luatex with C-h v TeX-engine and then I got these and followed the same way as above.

  • luaotfload.sty is missing

    installed texlive-luatex

  • xunicode.sty is missing

    install texlive-xetex??? but it works

    Source

No PDF display

So usually when you hit C-c C-c the second time you will see the View: TeX-evince-sync-view or something very similar. But I saw some .dvi stuff written. PDF did not get updated except that it got created the first time. but that is that. What helped–and I don’t know why– is this stack answer. Jesus man I don’t know WTF if happening but it helped.

With the latest version of AUCTeX, if should be sufficient to customize the variable TeX-PDF-from-DVI as described in the manual. Try M-x customize-variable RET TeX-PDF-from-DVI RET , click on Value Menu and choose dvips - ps2pdf sequence, hit Apply and Save and you should be done.

\documentclass[10pt,a4paper]{article}
\begin{document}
foobar
\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% TeX-PDF-mode: t
%%% TeX-PDF-from-DVI: "Dvipdfmx"
%%% End:

There is some explanation but the thing is if you do C-c C-c repeatedly all is good, PDF works and everything displays as expected. Or just to C-c C-a.

Peace

bib

Currently I have nothing setup for it. Read here for more info: https://tex.stackexchange.com/questions/25701/bibtex-vs-biber-and-biblatex-vs-natbib

*.bib file is what we need with the bib info which is then converted by Latex appropriately with the appropriate commands!

Reflection

I probably spend too much time just trying to understand things too well (parkinsons law). I am making notes, if I have to do this again. I suspect I might have to do this every 5 years once I loose the LTS of ubuntu. I am trying to understand on a high level what exactly I am doing. I suspect it to be useful in debugging and keeping track of what I have done to my pc, adding packages and removing them in case of conflicts as and when necessary. Learning in some sense, just-enough and possibly also more than just-enough.

I look at these notes after 3 months and I feel like I am on track, all knowledge is saved in a seemingly clear format to pick up from. Although maybe I could regain this knowledge, but also I think it is painful to search your ass off and start again.

References

Emacs-wiki Guide to emacs, as stack question auctex key-bindings quick start to Auctex by GNU AucTeX extension for TikZ my init file / config

Appendix: What is memoir, beamer and tix

I see this word appearing now and then in the Guide to emacs, as stack question, “memoir”. A quick investigation shows that it is a document class which is more flexible in terms of chapter styles, than ‘report’ or ‘book’.

Beamer is for creating powerful presentations.

Tikz is for creating graphics elements. Such as adding plot details legends etc.. with data points or, even just creating and drawing lines as necessary.