Date Tags LaTeX

I use LaTeX for my academic work. For some time Atom has been my editor of choice. Over the years, I've migrated through a variety of workflows, including using dedicated editors like LyX to write my S.M. thesis.

Atom is not a dedicated LaTeX editor, but it is immensely popular. Consequently it has many useful features and packages that I've found improve my productivity for writing code (LaTeX documents are, after all, code).1 Some of these are LaTeX-specific, but many are not.

See previous writing on this use-case by Matteo Merola and others.

TeX environment & packages

I write on Ubuntu, but most of the following are available for Mac OS or—with more difficulty—Windows.

TeX Live
This is the LaTeX distribution available with Ubuntu. By default it contains most of the packages listed below. I work with the default versions, with a small number of exceptions for “fast-moving” packages.2
beamer

For slides and posters. See the LaTeX Wikibook for an introduction.

  1. Metropolis is an attractive, simple, modern theme for beamer. Because it uses more common TrueType (instead of TeX) fonts, it must be compiled with XeLaTeX—pass the -xelatex option to latexmk.

  2. My TeX repository contains a derived MIT IDSS theme.

biblatex

BibLaTeX is a much-advanced, highly-configurable version of the old, BibTeX reference management software.

  1. I keep my BibTeX database in a separate directory and Git repository from my publications. My ~/.profile file sets the $BIBINPUTS environment variable so that any LaTeX compilation can find it:

    export BIBINPUTS=$HOME/Documents/reference:$BIBINPUTS

  2. The LaTeX Wikibook has a handy table of entry and field types in BibLaTeX files.

  3. KBibTeX is a useful GUI for editing my BibTeX database, when I need to. If the localfile key is defined for an entry, it has a pane that shows an embedded view of the PDF.

pgfplots

Generate figures and tables. Installed manually from version control:

git clone git://git.code.sf.net/p/pgfplots/code pgfplots
cd pgfplots
git checkout 1.14  # or latest version

Use \pgfplotsset{compat=1.14} to disable compatibility features.

gitinfo2
Installed manually. Watermark documents according to the revision information of the Git repository that contains them.

Own scripts, mini-packages & snippets

My scripts repository contains command-line tools I use to help writing LaTeX documents:

bib
Some collected utilities in Python for managing a BibTeX database.
Commands:
  check_files  Check files listed with the 'localfiles'...
  import       (DEV) Read new entries into the database.
  kw_list      List all keywords appearing in entries.
  queue        Display a reading queue.
install-latexmk
Install an up-to-date latexmk on Ubuntu. Version 4.41 (in Ubuntu 16.10) fails to properly recompile BibLaTeX files in some instances.

My TeX repository also contains some ‘mini’ packages and snippets of code:

unicode-extra
Define Unicode characters like →γ₂ so they can be used directly in equations—much more concise than \rightarrow\gamma_2.
zh
A command \zh{北京} for short Chinese texts in non-CJK documents.

Atom features & built-in packages

For Mac OS X keyboard shortcuts, substitute Cmd for Ctrl, or search in the Atom settings for the list of key bindings. The Atom documentation contains descriptions of other features.

Toggle line comments (Ctrl+/)
This is one of the default editor features. To debug LaTeX errors, isolate lines (or Beamer frames) that may contain the problem: select large chunks of your document, Ctrl+/ to comment them out, and recompile. Once you've found and spotted the errors, use Ctrl+/ to reverse.
Multiple cursors

Use Shift+Alt+{Up,Down} to add cursors above and below the current cursor(s), or use Ctrl + click to put a cursor anywhere. Any new characters typed, backspaces, or deletions will happen at every cursor simultaneously. This lets you quickly make changes that may be harder to find-and-replace.3

To make this feature more useful, keep your code indented and aligned so you can easily, for instance, add a decimal point to all the numbers in a table:

\begin{tabular}{lc}
  Foo & Bar \\
   12 &  10 \\
    1 & 100 \\
\end{tabular}

…or prepend \ttfamily to the description of each list entry:

\begin{description}
  \item [First] list entry.
  \item [Second] list entry.
\end{description}
Bracket matching

Leaving off a trailing } in LaTeX can lead to immense headaches in debugging. Use Ctrl+M (go to matching bracket) at any { to find its partner—if the cursor doesn't move, there isn't one, and you've made a mistake.

This package also lets you select all text inside the current brackets, jump to the nearest enclosing bracket, and remove all brackets inside a selection. Use the command palette (Ctrl+P) or set a shortcut for each of these commands.

Snippets
When starting a new LaTeX environment, such as \begin{itemize}, type the first few letters of the name, and press Tab. A complete environment is inserted, with a closing tag, so you don't forget it later. Snippets are customizable.
Git line diffs
Easily identify which parts of source files have changed since the last commit. The file tree also colours changed or new files.

Community Atom packages

language-latex
Syntax highlighting for LaTeX.
linter-chktex

Linter plugin for LaTeX using chktex, requires linter. A linter searches your code for ‘lint’; not errors, but little mistakes in comparison to proper style or syntax. I write with this package disabled, and only turn it on briefly when I'm finalizing a document or debugging, since it's very opinionated.

For instance, chktex will complain about The time since 1900 A.D. has been… because the final . would be misintepreted as ending a sentence, when in fact it should be followed by an interword space (.\ ).

build-makeGNU makelatexmk

Depends on build. make looks for a Makefile in the root of your project, and executes commands based on rules in this file. I use it in concert with latexmk, a program which understands how to run pdflatex, biblatex, and other programs repeatedly to compile a document (and ships with TeX Live). For this, it is sufficient to have a Makefile with the following:

all: paper.pdf

paper.pdf: paper.tex
    latexmk -pdf $<

In this setup, Atom (build-make) invokes make, and make in turn invokes latexmk, which decides whether paper.tex (or any the other files on which it depends) has changed and recompiles as needed.

  1. build-make can be configured to either invoke make every time a file is saved, or only when a command (default: F9) is given. The former is fine for simple documents, but for complex documents that take some time to compile it usually results in my laptop sounding like a jet engine, distracting me from writing.

  2. To avoid a messy command line, put options to latexmk in a file .latexmkrc:

    # Generate PDFs by default
    $pdf_mode = 1;
    # -file-line-error: more readable output on errors
    # -shell-escape %O %S: allow pdflatex to invoke programs like pygmentize
    $pdflatex = "pdflatex -file-line-error -shell-escape %O %S";
    # Suppress most output from pdflatex etc.; check the .log file
    $silent = 1;
    
    and give latexmk -r /path/to/.latexmkrc on the command-line.

wordcount
Counts words!
zen
Full-screen the editor and hide everything but the text.

Other packages

Some other LaTeX-specific packages for Atom that I haven't found a need for or don't use, with reasons:

latexer
Certain LaTeX-specific autocompletions.
autocomplete-bibtex
Autocompletion for BibTeX citations. I either am referring to a small number of papers which I've read (exhaustively) and for which I know the citation keys; or am working on a literature review, in which case I have KBibTeX open.
latex-plus
Appears to be unmaintained.
latex
A package for running latexmk with some options. The build and build-make packages, being more general, are better maintained; also I use make to do things besides compile LaTeX documents.4
pdf-view
I use Evince, the default document viewer on Ubuntu.5

  1. My work often involves switching back and forth between a document, and code to support what I'm writing: primary analysis; post-processing code that produces figures and tables; and Hydrogen for quick calculations. Using a general-purpose editor, I can have these as different tabs in the same application, rather than different applications. 

  2. TeX Live comes out with a new release every year, and Ubuntu releases every six months, so this entails any feature that I really need within a year of its being developed. Most popular LaTeX packages are fairly static, and new features cover use-cases that don't apply to my work. 

  3. However, find and replace using regular expressions is an immensely powerful skill that rewards invested time, especially when changes have to be made to similar, but not identical, text throughout a document. Atom has both file- (Ctrl+F) and project-level (Ctrl+Shift+F) find and replace. 

  4. A subject for another post. 

  5. My greatest complaint about Atom is performance. Atom is built on the Electron framework that includes the open-source version of Google Chrome. This is highly optimized for running JavaScript, but is not always as fast as native code. I have an old (ca. 2013) Dell XPS 13 laptop, and I also run Gitkraken client for Github & friends—another Electron program; so I am running three browsers, which can bog down my system considerably. pdf-view makes this problem worse. 



Comments

comments powered by Disqus