[Tex/LaTex] Which editors can autocomplete any word from document

auto-completioneditors

Of course, any LaTeX editor will autocomplete common LaTeX commands and environments. Many (most?) let user add new commands to be autocompleted. However, in technical documents there will usually be specific terms, which are encountered often enough (and may be quite long) to be worth autocompleting, but aren't commands and are different from one document to another. So it's quite nice to be able to autocomplete any word which exists in the document (or any of the open documents).

I know Emacs, Vim, Kile and TeXstudio support this; do any others?

Best Answer

Any LaTeX editor can accommodate this style of auto-completion by means of macro definitions. It is probably the fastest way to perform this without having to switch from your existing editor to a new/different one. In my opinion, it is flexible, transferable and accommodates a host of variability that you may require based on (say) conditional support from LaTeX packages.

Since the replacement text is typically used inside regular text, the xspace package is of great help. It inserts a space after a command sequence only if it is followed by a space. This is a common issue with using command sequences in regular text. For example, A \TeX command sequence. will expand to A TeXcommand sequence. since the space represents the end of \TeX and is therefore gobbled. xspace is the way around this:

\documentclass{article}
\usepackage{xspace}% http://ctan.org/pkg/xspace
% Definitions for words to auto-complete
\newcommand{\sync}{synchrocyclotrons\xspace}%
%...
\begin{document}
What mighty \sync you have, sir! Get me one of those \sync.
\end{document}

enter image description here

If you change your mind (to quote ABBA), you can just change the macro definition. It would probably be the same amount of effort to do this than it would to modify the auto-completion segment provided by such an editor.

To go one step further, you can even define your macros to have (say) starred version * which expand to the plural form if use, otherwise it uses the singular form:

\documentclass{article}
\usepackage{xparse}% http://ctan.org/pkg/xprase
\usepackage{xspace}% http://ctan.org/pkg/xspace
% Definitions for words to auto-complete
\NewDocumentCommand{\sync}{s}{%
  synchrocyclotron\IfBooleanTF{#1}{s}{}\xspace
}
%...
\begin{document}
That's a huge \sync! There are plenty more \sync* over there.
\end{document}

enter image description here

The xparse package provides an easy interface for working with starred versions of commands/environments.