No more LaTeX

I made jokes about this before, but it actually happened: since I no longer use LaTeX, I removed it from my laptop and got rid of the config from my .vimrc. It’s nothing unusual, but I somewhat feel that the departure from LaTeX marks an important (sic!) moment in my life.

LaTeX was my “gateway drug” to programming. I kid you not. Since I was interested in publishing as a teenager (even ran a small but successful magazine for a while), got very disappointed in MS Word’s DTP capabilities, had no money or supported OS to run Adobe or Quark, LaTeX was for me, sadly, the only option to put my magazine together. A Polish magazine called Linux+ published an article about LaTeX, I went through the tutorial, then through lshort2e.pdf, and got hooked. I was of course impressed by the quality of the output, but most importantly I understood the powerful concept of source code and compilation. LaTeX is of course technically markup and not code,1 and it’s not exactly compiled but parsed, but still the process and concepts are easily translatable to programming. So then came going through AWK tutorials, and later came C and Perl. And much later came a lot of other stuff, but it all started with LaTeX.
Continue reading “No more LaTeX”

Stop using LaTeX, switch to MS Word

A hilarious article appeared in PLOS ONE recently (thanks for the link, Pim). StackOverflow already made some good comments, but here’s my two pennies’ worth.

While I find the study methodologically flawed1 and I have a strong dislike for MS Word for numerous (un)sentimental reasons, I cannot disagree with the fact that LaTeX sucks. It has a complex syntax (take a look at Markdown or reStructuredText for comparison), meaningless error messages, it comes as a ginormous zip file full of obsolete stuff and it’s not exactly easy to customize (even installing new fonts is non-trivial). Yes, it has great syntax for mathematical symbols, very good output file quality by default and good default typographical settings, but it doesn’t stop to amaze me that it’s been around for so long and no one has come up with a better alternative.

Well, I guess we should just embrace MS Word and stop wasting taxpayers’ money, as Markus Knauff and Jelica Nejasmic suggest.

update, Dec. 29th: Also, this:

  1. Copying an already written text is waay different than writing it from scratch, tables are notoriously LaTeX’s weakest point, as is customizing anything, the article doesn’t even touch upon the topic of editing long, complex documents, the list goes on… 

LaTeX environment for specifying computational problems

I’m wondering if there’s some standard and neat way of typesetting computational problem definitions in LaTeX. Here’s what I came up with just a moment ago:


and it seems to work pretty well:


But perhaps there’s a better way to typeset it? An obvious problem with mine is that it’s not a theorem-kind of environment, and there’s no way of referencing it with \ref{}, but then again you usually reference computational problems simply by their name. Anyways, suggestions for making it better are welcome.

Previewing LaTeX symbols without preview-latex

This blog’s most popular post is the Emacs howto entry, so I thought I’d share one more LaTeX-related tip for all your Emacs needs. Besides the traditional preview-latex way of generating TeX formulas inside Emacs buffer, there’s a faster and neater way to do this using Emacs’ unicode support. My friends Erik Parmann and Pål Drange made a simple package that turns many math symbols and Greek letters commands into corresponding unicode characters. Here’s a sample of how this looks:


If you’re running Emacs 24, you can get the package from MELPA repository. Otherwise you can get it from Erik’s bitbucket, put it somewhere in your load path and load it with (require 'latex-pretty-symbols). There, happy TeXing!

(also, you can make similar tricks with Haskell mode and have all your lambdas displayed properly).

Pro-LaTeX-tip for today

Pro-LaTeX-tip for today: you can change the size of some big math symbols by putting textstyle or displaystyle in front of them. Example: if you’re using align environment to write a long, case-by-case definition, and you put a sum or prod somewhere in it, LaTeX will render big sigmas and pis, which doesn’t look good.


You can force smaller symbols with textstyle then.


Continuous list enumeration throughout the document with LaTeX

Karolina asked me today to create a macro for having a continuous list enumeration throughout the whole document, i.e.

This is the first list:

1. Item;
2. Another item;

And here goes the second list:

3. Third item;
4. And yet another item.

You can obtain an effect like that by using LaTeX counters and a custom definition of your own enumerate environment. First, we need to \usepackage{enumerate}, and then define the following counter and an environment in the preamble:

{ \begin{enumerate}\setcounter{enumi}{\value{enumi_saved}}}

After that, you can use myenumerate and you’ll have a continuous enumeration in the whole document.

Oh and some credits: I wouldn’t come up with a solution if I haven’t read this post, and this website. Huge thanks to the authors for their tips!

update: There’s a much simpler solution, thanks Jakub.

Emacs as the Ultimate LaTeX Editor

Everyone knows, that GNU Emacs is THE Best Programmer’s Editor. Not everyone knows, though, that when you combine it with AUCTeX macros, it also becomes THE Best Editor for LaTeX.

The biggest problem with Emacs is that it’s not a particularly intuitive piece of software, to say the least, hence many users flee after their first encounter with it. Emacs has its complicated keyboard shortcuts, enormous documentation and config files written in a Lisp dialect (called Emacs lisp), so at first it might seem very unpleasant using it. However, once tamed, it becomes your best friend.

I’d like to present some tips that customize Emacs making it a perfect and very sophisticated editor for LaTeX. Most of these ideas are taken from various config files, howtos and other resources found on the web. Some of them are mine, but I can no longer tell which.

First things first: you need to get Emacs and AUCTeX, and get it running.

Every major linux distro comes with both Emacs and AUCTeX available via package systems. In Ubuntu, you just type sudo apt-get install emacs23 auctex and you’re laughing. Emacs is also available for Windows, and AUCTeX website has instructions on how to set it up with Windows systems. Mac users have a choice of setting up either Carbon Emacs (a version closer to original GNU Emacs) or Aquamacs (an Emacs variant supporting tabs and other nice tweaks; preferred Emacs package by all Mac users I know, Karolina included). Full comparison of Mac Emacs variants is available here, so you can make your own choice. Both Carbon Emacs and Aquamacs come with AUCTeX bundled, so there’s no need to download additional packages.

After running Emacs and loading a TeX file (C-x C-f file_name.tex), AUCTeX should load itself automatically. If it doesn’t happen, you can invoke it with M-x tex-mode, or you can put the following into your $HOME/.emacs file:

(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq TeX-save-query nil)
;(setq TeX-PDF-mode t)

(all the code snippets from this post are available as a Github Gist)

The options above will make sure, that AUCTeX macros are loaded every time a TeX file is opened. The last option, ;(setq TeX-PDF-mode t), is commented (all lines beginning with ; are a comment in Emacs Lisp), but you can uncomment it if you want to have PDFLaTeX mode enabled by default for all documents.

AUCTeX has a number of nice features, the two I use most often are:

  • automatic formatting of a section: C-c C-q C-s;
  • section preview: C-c C-p C-s; (see the screenshot on the right)

Preview function is very nice, because you can see the commands that are behind preview images, edit the code, apply preview again and see the results — no need to parse the whole file too often, and most importantly no need to switch to a PDF/PS viewer to see if your math formula/xypic tree is formatted correctly. Trust me, this saves a lot of time.

(update 27.12.2012: there’s another way of previewing LaTeX symbols inside an Emacs buffer, take a look here)

AUCTeX has many many more features, and you can always consult its documentation if you want to learn more. It’s a little bit overwhelming, but learning it is a very good investment, especially if you work with TeX a lot. But there are more packages that provide features which make your life easier.

Flymake is one of those packages. It enables Emacs to check the syntax of your TeX file on-the-fly. To turn it on, put the following code in your $HOME/.emacs:

(require 'flymake)

(defun flymake-get-tex-args (file-name)
(list "pdflatex"
(list "-file-line-error" "-draftmode" "-interaction=nonstopmode" file-name)))

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

Beware, though — flymake consumes quite a lot of CPU power, especially when used with large files (and paradoxically large files make it most useful).

On the other hand, spell-checking while you type isn’t so cpu consuming, and you can turn it on with:

(setq ispell-program-name "aspell") ; could be ispell as well, depending on your preferences
(setq ispell-dictionary "english") ; this can obviously be set to any language your spell-checking program supports
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
(add-hook 'LaTeX-mode-hook 'flyspell-buffer)

Another nice package is the Outline Mode. It allows the user to hide some parts of the text file, which makes working with large files much easier. To enable it, put the following in $HOME/.emacs:

(defun turn-on-outline-minor-mode ()
(outline-minor-mode 1))
(add-hook 'LaTeX-mode-hook 'turn-on-outline-minor-mode)
(add-hook 'latex-mode-hook 'turn-on-outline-minor-mode)
(setq outline-minor-mode-prefix "\C-c \C-o") ; Or something else

Now you can fold sections, subsections, chapters, or the whole document. To hide all the contents of your current section, use C-c C-o C-l. You can apply it to a chapter, subsection, etc. You can also move to a next unit of your document with C-c C-o C-n, or to a previous one with C-c C-o C-p. If you’re lost and want to see the whole document again, use C-c C-o C-a.

Folding and unfolding parts of the text might be confusing, though, but there’s another way to navigate through a big TeX file, and you can use Reftex mode for it. Reftex is a mode that helps with managing references (full documentation), but it can also be used to create a table of contents for a TeX file and to navigate using it. Here is my configuration for Reftex from my .emacs file:

(require 'tex-site)
(autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
(autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
(autoload 'reftex-citation "reftex-cite" "Make citation" nil)
(autoload 'reftex-index-phrase-mode "reftex-index" "Phrase Mode" t)
(add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
;; (add-hook 'reftex-load-hook 'imenu-add-menubar-index)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq LaTeX-eqnarray-label "eq"
LaTeX-equation-label "eq"
LaTeX-figure-label "fig"
LaTeX-table-label "tab"
LaTeX-myChapter-label "chap"
TeX-auto-save t
TeX-newline-function 'reindent-then-newline-and-indent
TeX-parse-self t
'("style/" "auto/"

Once Reftex is loaded, you can invoke the table of contents buffer with
C-c =


All right, enough. If I mention any more packages, I guess it will scare off those who aren’t already scared. I know that Emacs is a bit peculiar with its complicated keyboard shortcuts, enormous documentation and thousands of modes. It’s not easy to learn, but definitely worth it. I remember that switching from Vim to Emacs for LaTeX editing wasn’t easy, but I never regretted that, and I hope whoever’s going to switch under the influence of this post will not regret it either.