# Can I get the line number for a definition from texdef?

With texdef it is easy to find definitions for (La)TeX commands. It can show what a definition for a given command is and also in what file it is to be found. Sometimes it would be convenient to also learn the line number for the definition it shows. Is this possible with texdef?

Take for instance \section. texdef -t latex -F section returns

\section first defined in "/usr/local/texlive/2011/texmf-dist/tex/latex/base/article.cls".

\section:
\long macro:->\@startsection {section}{1}{\z@ }{-3.5ex \@plus -1ex \@minus -.2ex}{2.3ex \@plus .2ex}{\normalfont \Large \bfseries }


For ease of getting to the definition of \section in article.cls it would be convenient to get the line number to where the definition starts so that I may open the file in an editor and go to that line number instead of having to search the file.

-

With texdef version 1.6 from 2012/05/02 you can use the --source/-s option which makes the script look in the source file for the original definition including line number. Without this it only uses \show inside a (La)TeX call. Note that -s is not compatible with all macro definitions, just normal formatted ones. Verbatim macros etc. might not be found.

$latexdef -s section % article.cls, line 312: \newcommand\section{\@startsection {section}{1}{\z@}% {-3.5ex \@plus -1ex \@minus -.2ex}% {2.3ex \@plus.2ex}% {\normalfont\Large\bfseries}}  If you also use -F option the full path is displayed: $ latexdef -F -s section
% /usr/local/texlive/2011/texmf-dist/tex/latex/base/article.cls, line 312:
\newcommand\section{\@startsection {section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\normalfont\Large\bfseries}}


Here latexdef is equivalent to texdef -t latex. You can also create a symlink from latexdef to texdef as stated in the INSTALL file. Unfortunately TeX Live doesn't include the symlinks.

-
Should I also add an --edit option which opens a text editor at the found line? –  Martin Scharrer May 7 '12 at 13:37
If that is possible it would be fantastic. For cases where texdef is run from within Emacs it might also be possible to write an Emacs function for it. –  N.N. May 7 '12 at 13:40
@N.N.: The problem is to figure out how to call the editor. I know it for Vim +LINENUMBER FILE, but other editor it is different. There need to be a config setting for this. –  Martin Scharrer May 7 '12 at 13:43

As explained in the answer to How can texdef be made to return indented definitions? texdef doesn't read the files, but uses TeX with the appropriate file and does \show\foo when called by

texdef -t latex foo


(possibly with other command line options). Macro definitions are not always performed with \def or \newcommand: many of them are implicitly defined and their definition can't be found in a particular line, even if the program was extended to scan the input files.

-