[Tex/LaTex] How to understand and write LaTeX code

learningsourcecode

LaTeX is like a language. In order to write LaTeX code I have to understand the "word" and the "sentences structure". I have searched on wiki, some LaTeX books, but they just give the LaTeX command, not how to write a LaTeX code for some specific purpose or to understand the LaTeX code.

Here is one example:

\renewenvironment{svgraybox}%
       {\fboxsep=12pt\relax
        \begin{shaded}%
        \list{}{\leftmargin=12pt\rightmargin=2\leftmargin\leftmargin=\z@\topsep=\z@\relax}%
        \expandafter\item\parindent=\svparindent
        \hskip-\listparindent}%
       {\endlist\end{shaded}}%
%
\renewenvironment{svtintedbox}%
       {\fboxsep=12pt\relax
        \begin{tinted}%
        \list{}{\leftmargin=12pt\rightmargin=2\leftmargin\leftmargin=\z@\topsep=\z@\relax}%
        \expandafter\item\parindent=\svparindent
        \relax}%
       {\endlist\end{tinted}}%
%
}}
%
\let\SVMonoOpt\@empty

I do not know what is \z@, what is \relax, what is \fboxsep … and if I want to design my LaTeX file in my own form, I know that I have to understand many other things.

Note that I can write simple LaTeX enviroment in mathematics (like the matrix, align, enviroment) but it does not help me to understand the above code.

So, what could I do? What book should I read? Or what programming language should I learn?

Best Answer

The TeXbook is the best place to learn about the underlying TeX language, although TeX-by-Topic (texdoc texbytopic) in most distributions is a good free alternative. But much of what you show is not directly using TeX primitives but using constructs such as \list defined in the latex format. The LaTeX Companion has detail for that or the free documented sources of LaTeX texdoc source2e has lots of information.

This site of course can also be used. For example