1

For example, I'm trying to execute \textsuperscript in the raw (from its definition).

I don't even know where to start looking for the source!

Granted, I have discovered \show. I also can do \expandafter\show\csname textsuperscript \endcsname for protected macros, which then leads me to \makeatletter\show\@textsuperscript\makeatother.

And yes, kpsewhich finds the source file, if I even know the name of the source file.

But is that the best way? Any really updated documentation so that me and my team doesn't have to plough through the source codes?

  • 8
    This is really too broad a question as posed. To learn about packages, use texdoc <packagename> to find its documentation. To learn about TeX the language, you should read the TeXbook (a real book) and the online TeX by Topic. (texdoc texbytopic). The documented source of the latex kernel is in source2e.pdf (texdoc source2e). – Alan Munn Apr 25 '18 at 03:09
  • @AlanMunn Not too broad, although it has been (indirectly) asked before. The problem is that you cannot bother looking for package documentation, if you do not know which package provides the macro! Worse, some packages re-define. Looking through docs is only useful if you add a package with new macros. –  Apr 25 '18 at 03:16
  • Possibly related: https://tex.stackexchange.com/questions/35878/do-any-of-the-latex-variants-support-namespaces –  Apr 25 '18 at 04:15
  • 2
    The latexdef command, and friends may be of interest. For example, latexdef textsuperscript returns \textsuperscript: macro:->\protect \textsuperscript, which it then expands further to \textsuperscript : macro:#1->\@textsuperscript {\selectfont #1}. –  Apr 25 '18 at 04:24
  • 2
    Unfortunately I think going through the source code (at least of relevant packages, if not of LaTeX and of TeX itself) is ultimately the only real way to truly learn LaTeX/TeX “inside out”. – ShreevatsaR Apr 25 '18 at 04:42

1 Answers1

14

Taking the question literally, how to learn (La)TeX inside out. To start at the bottom:

  • [Skipping Boolean logic, transistors, computer architecture, operating systems, etc…]

  • There is a program called TeX, written by D. E. Knuth, for which you can read the (documented) source code with texdoc tex (also published as Volume B of Computers and Typesetting), and the user manual (The TeXbook = Volume A). (Another independent documentation is TeX By Topic.) If you decide to read the source code, you'll also have to know (a subset of) the Pascal programming language, and Knuth's WEB literate programming system.

  • Next there is a program (collection of TeX macros) called LaTeX, originally written by Leslie Lamport and then by others, for which you can read the (documented) source code with texdoc source2e and the user manual in the (printed, real) book LaTeX: A Document Preparation System, and other books (The LaTeX Companion, lshort, etc; see questions on this site).

  • Next there are thousands of programs (aka packages, collections of macros that build on TeX, LaTeX, and other packages), written by various people, for use with TeX/LaTeX. They have varying quality of documentation in their user manuals, and varying quality of documentation in their source code.

  • [Omitting extensions to TeX like eTeX, pdfTeX, XeTeX, LuaTeX, etc.]

  • [Also omitting what happens before or after the core work of TeX is done: input encodings, fonts (OpenType and otherwise), DVI drivers or PDF viewers, etc.]

So when faced with a particular macro or behaviour you'd like to know more about, it could come from any of these sources. You can start at the top:

  • First, see if the definition is in any of the packages. To know which package's source code to look at, first you can get a list of all the package files that were opened by the TeX program: this you can do with pdflatex -recorder and looking in the <jobname>.fls file, or with mkjobtexmf, or a bunch of other solutions. Use a crude grep or whatever, to search for your macro in those files.

  • Next, check whether it is part of LaTeX itself: you can grep in latex.ltx.

  • Finally, check whether it is part of TeX itself: you can look in the index to the TeXbook, say.

Unfortunately, there isn't a better solution, such as TeX recording where it encountered the definitions of macros.


Example: For \textsuperscript, you can first check that it's not defined in any of the packages (as might happen, depending on the set of packages you've included), then find its definition in texdoc source2e:

textsuperscript

And you can repeat the procedure for the definition you find, namely here \DeclareRobustCommand, \selectfont, \m@th, \ensuremath, \mbox, \fontsize, \sf@size, \z@. And repeat for things you find in their definitions, etc. Of course, many of these definitions (such as the one for \sf@size) only make sense in light of other definitions or what is being expected in certain contexts, so you need to understand them as well.

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
  • Wow. Just, wow. Yes, you read my question right. It may sound broad, but that's what I do (reverse-engineering). You just did my job for me. –  Apr 25 '18 at 07:24
  • er, \mbox is latex lingo. plain tex has \hbox and \vbox. (\mbox uses \hbox in its definition.) – barbara beeton Apr 25 '18 at 17:35
  • @barbarabeeton Oops :-) The one thing I didn't bother to look for, and got wrong. Will fix. – ShreevatsaR Apr 25 '18 at 17:37