TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Encouraged by a super response to my previous question on a similar topic, I shall persevere with a similar line of inquiry. I think it would be super if, in my LaTeX editor, I could click on a macro name:


and the cursor would jump to the corresponding definition:


Do any LaTeX editors have this feature? I mainly use Aquamacs/AucTeX myself, but am interested in other editors too. I reckon it would be quite challenging to implement, because \blob might not just be defined in the current document - it might be:

  • in a master file that includes the current document,
  • in a slave file that the current document includes, or
  • in a package that the document uses.
share|improve this question
... or defined in the latex format ... or be a tex primitive. depends how much you want to thrash your disk. Recently to answer a less than complete question on this site we had to do find . -name *.sty -exec grep zzzz \{\}\; to search every file in the input tree for a command to find out where it came from. You probably don't want to hide that behind a single keystroke. – David Carlisle May 9 '13 at 14:56
What is easier of course is to show the definition as that just means executing \show\blob – David Carlisle May 9 '13 at 14:58
You could collect all the package names and then execute something like this in the shell texdef -t latex -p longtable -p tabularx longtable which returns the definition, texdef has options to return instead the filename at which the definition was found (it has lots of options:-) – David Carlisle May 9 '13 at 15:33
Just yesterday I examined \bar as redefined by amsmath; would you believe me when I say that the redefinition by amsmath is performed by \@tempa{\bar}? Really, apart from very simple cases, this is impossible. – egreg May 13 '13 at 8:36
This feature would be awesome. – Nicholas Hamilton May 15 '13 at 7:48

The general problem of finding where a command is defined has no viable solution. Macros can and do change their meaning; a typical example is \\. This simple document





gives the following output in the terminal window:

> \\=macro:
->\x@protect \\\protect \\  .
l.4 \show\\

> \\=macro:
->\ifhmode \unskip \else \@nolnerr \fi \par \@ifstar {\nobreak \@xcentercr }\@xcentercr .
l.6 {\centering\show\\
> \\=macro:
->{\ifnum 0=`}\fi \@ifstar \@xtabularcr \@xtabularcr .
l.9 \show\\

Thus, besides caching your entire preamble, a safe routine should also compile your document in order to get the actual meaning of a macro.

Another example. Suppose you load siunitx and do \show\SI; the output is

> \SI=\protected macro:
->\int_zero:N \l__xparse_processor_int \tl_set:Nn \l__xparse_args_tl {\SI code }\tl_set:Nn \l__xparse_fn_tl {\SI  }\__xparse_grab_D:w []{-NoValue-}\__xparse_grab_m_1:w \__xparse_grab_D:w []{-NoValue-}\__xparse_grab_m_1:w \l__xparse_args_tl .

the usefulness of which is very dubious.

Another example. Suppose you're using amsmath and want to access the definition of \bar; a \show command would print

> \bar=macro:
->\protect \mathaccentV {bar}016.

but you'll never find where this definition is performed, because there's no \def, \newcommand or any other similar command that does it: indeed in amsmath.sty you find (line numbers for convenience)

574 \def\set@mathaccent#1#2#3#4{%
575   \xdef#2{\@nx\protect\@nx\mathaccentV
576     {\@xp\@gobble\string#2}\hexnumber@#1#4}%
577 }
578 \def\@tempa#1{\@xp\@tempb\meaning#1\@nil#1}
579 \def\@tempb#1>#2#3 #4\@nil#5{%
580   \@xp\ifx\csname#3\endcsname\mathaccent
581     \@tempc#4?"7777\@nil#5%
582   \else
583     \PackageWarningNoLine{amsmath}{%
584       Unable to redefine math accent \string#5}%
585   \fi
586 }
587 \def\@tempc#1"#2#3#4#5#6\@nil#7{%
588   \chardef\@tempd="#3\relax\set@mathaccent\@tempd{#7}{#2}{#4#5}}
589 \@tempa{\hat}
590 \@tempa{\check}
591 \@tempa{\tilde}
592 \@tempa{\acute}
593 \@tempa{\grave}
594 \@tempa{\dot}
595 \@tempa{\ddot}
596 \@tempa{\breve}
597 \@tempa{\bar}
598 \@tempa{\vec}

and it's line 597 that performs the redefinition from the kernel's meaning

\mathaccent "7016\relax

that's assigned in fontmath.ltx by the high level instruction


Final example. You can't even guess the syntax of a command from its definition: here's the output of \show\makebox

> \makebox=macro:
->\leavevmode \@ifnextchar (\@makepicbox {\@ifnextchar [\@makebox \mbox }.
share|improve this answer

I'll mention TeXlipse, which includes this feature, though only partially. You can press F3 when the cursor is on a macro name, to jump to its definition. But...

  • TeXlipse does not take redefinitions via \renewcommand into account.

  • It does not understand macros defined by \def. Only \newcommand seems to work.


  • It does work if the macro is defined outside of the current file, in a package that you include via \usepackage.
share|improve this answer

You could try a regex (PCRE) similar to /(\\def|\\renewcommand|\\newkeycommand).*$cmdname/.

Hope this helps, I can't write any lisp for it right now, but it should be trivial to implement.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.