Take the 2-minute tour ×
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.

With texdef it is easy to find definitions for (La)TeX commands. It can show what a definition for a given command is. For instance if I issue texdef -t latex \LaTeX I get the following definitions:

\LaTeX:
macro:->\protect \LaTeX  


\LaTeX :
\long macro:->L\kern -.36em{\sbox \z@ T\vbox to\ht \z@ {\hbox {\check@mathfonts \fontsize \sf@size \z@ \math@fontsfalse \selectfont A}\vss }}\kern -.15em\TeX

A problem is that the latter is very hard to read because it is just one long line. In the source it is easier to read because it is indented. It reads:

\DeclareRobustCommand{\LaTeX}{L\kern-.36em%
        {\sbox\z@ T%
         \vbox to\ht\z@{\hbox{\check@mathfonts
                              \fontsize\sf@size\z@
                              \math@fontsfalse\selectfont
                              A}%
                        \vss}%
        }%
        \kern-.15em%
        \TeX}

Is it possible to make texdef return indented definitions?

Indented definitions are much easier to read. Also, indented definitions are preferable if you want to use them as a base for a redefinition because you do not have to indent them yourself to be able to efficiently work with them.

share|improve this question
    
I think texdef is a simple tool. So the easiest way is to write a new script which uses the functionality of grep, texdef (maybe find). –  Marco Daniel Feb 4 '12 at 10:57
1  
texdef uses \meaning from TeX, not the actual definition text in some file. –  egreg Feb 4 '12 at 10:57
add comment

2 Answers

up vote 7 down vote accepted

Since v1.5 (04/2012) there exists the -s/--source option which will try to locate the (first) original definition of the macro and display it as it is written in the source file. However, this will not work with all macros due to the dynamic nature of TeX. Especially verbatim and similar special macros can't be properly parsed by texdef. If this features fails the definition is printed the "normal" way, so it is save to use this option in any case.

For the example \LaTeX macro this looks as follows:

$ latexdef -s LaTeX
% latex.ltx, line 1328:
\DeclareRobustCommand{\LaTeX}{L\kern-.36em%
        {\sbox\z@ T%
         \vbox to\ht\z@{\hbox{\check@mathfonts
                              \fontsize\sf@size\z@
                              \math@fontsfalse\selectfont
                              A}%
                        \vss}%
        }%
        \kern-.15em%
        \TeX}

If the -F option is used in addition the full file path is displayed, which can be useful if you want to have a closer look at the source.

$ latexdef -Fs LaTeX
% /home/texlive/2012/texmf-dist/tex/latex/base/latex.ltx, line 1328:
\DeclareRobustCommand{\LaTeX}{L\kern-.36em%
...
share|improve this answer
    
I find texdef to be an extremely useful tool for checking \LaTeX2e macros from the kernel or packages. Thanks. –  jfbu Dec 29 '12 at 23:40
add comment

In order to show definitions of commands, texdef runs (La)TeX with an appropriate preamble. Then it uses the primitive \meaning to show on screen the definition. The output of \meaning for a macro is

<token>:
<prefixes> macro:<parameter text>-><replacement text>

In cases of a "robusted command" texdef shows also the internal command, which is why you get two lines from texdef -t latex LaTeX:

\LaTeX:
macro:->\protect \LaTeX  

\LaTeX :
\long macro:->L\kern -.36em{\sbox \z@ T\vbox to\ht \z@ {\hbox {\check@mathfonts \fontsize \sf@size \z@ \math@fontsfalse \selectfont A}\vss }}\kern -.15em\TeX 

texdef does not look into the files, which would be almost meaningless anyway: commands can change their meaning (think to \maketitle, that is defined twice by article.cls depending on the options) or may be defined in ways very different from \def\macro or \newcommand macro.

For example, you would never find \def\mathrm, \newcommand\mathrm or \DeclareRobustCommand\mathrm, as \mathrm is (by default) defined by

\DeclareSymbolFontAlphabet{\mathrm}{operators}

The same holds for many math commands. Thus "finding the exact place where a command is defined" is in general hopeless.

One might think about filtering the output with a "code beautifier", if such a tool were generally available in Perl distributions (this could indeed be a nice feature for texdef).

share|improve this answer
    
Just to clarify: So your answer to the question is that texdef is based on \meaning which does not return indented code and, thus, texdef cannot be made to return indented code? –  N.N. Feb 5 '12 at 11:23
    
Yes, that's the sense. Maybe one can think to filtering the answer through a "code beautifier", but I don't know whether there is such a tool generally available on Perl distributions. –  egreg Feb 5 '12 at 11:26
    
Could you please add such a clarification to your answer to make it clear for future visitors? Yes, sending it to a prettifier that can prettify for a terminal may be a way to solve it. –  N.N. Feb 5 '12 at 11:32
add comment

Your Answer

 
discard

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.