LaTeX3 tutorial (1)-background knowledge

Recap history

As we all know, Donald E. Knuth  couldn't stand the digital typesetting technology at the time when he typeset his masterpiece  The Art of Computer Programming , so he gritted his teeth and spent nearly ten years developing the great typesetting software TeX.

However, this TeX itself is for Knuth's own service, and ordinary people will be more difficult to use. In the 1980s, Professor Leslie Lamport, also a computer scientist, developed LaTeX ( La mport  TeX ), which hides some typographic details and becomes a set of structured document languages. Lamport also  invented LaTeX while preparing his book  The Great American Concurrency Book ; but with LaTeX, this book is too lazy to write ...

In 1992, LaTeX 2.09 was released, and Lamport retired to the second line. The development work was handed over to the LaTeX3 team led by Frank Mittelbach. As the name suggests, this team is meant to represent the development requirements of the LaTeX industry, the direction of the latest technology in the LaTeX industry, and the fundamental interests of the majority of LaTeX users. So they worked hard for two years and made a big news-launched LaTeX 2 ε .

The name "LaTeX 2 ε " comes from the  language of ε - δ in calculus at a glance  . "2 ε " is greater than 2, but as an infinitesimal amount, there are still thousands of miles away from 3. So after more than two decades, the official release of LaTeX3 is still far away.

LaTeX 2 ε  deficiency

To be honest, we are now going to talk about what LaTeX 2 ε  lacks, so that we have to start anew and build a brand new version.

User level

To complete high-quality typesetting, precise format control is required. However, in many cases, format control does not provide a simple and easy-to-use interface, and often requires manual modification of internal definitions. For example, to center the numbered line in a footnote, you need to do this:

\makeatletter
\renewcommand\@makefntext[1]{%
  \hspace*{-2em}%
  \parindent 0em%
  \noindent
  \hb@xt@ 1.8em{\hss
    \@thefnmark. }%
  #1}
\makeatother

A simple example is still the case, a little more complicated requires the use of various patches, hooks, and all kinds of dirty skills, it is very inelegant.

Another way is to borrow wheels made by others and call various macro packages. The consequence is that once the article is long, the introductory area will become a macro package, a pile  \usepackage, plus a variety of tricky settings.

Of course, for this problem, the solution seems to be ready. For example,  KOMA-Script or the  memoir document class (not many people use it in China), they generally group some common functions together, and the user interface is relatively unified.

Programming level

On the other hand, LaTeX 2 ε  lacks a good programming interface, and simple flow control statements are also quite cumbersome and inefficient. Not to mention the unfolding macro of the heartbroken:

\def\CTeX@replacecommand#1#2#3{%
  \expandafter\expandafter\expandafter\let\expandafter
    \csname #1#3\expandafter\endcsname
    \csname #2#3\endcsname
  \expandafter\expandafter\expandafter\def\expandafter
    \csname #2#3\expandafter\endcsname
    {\csname #1#3\endcsname}}

Moreover, many times  the programming in LaTeX 2 ε is a mixture of TeX, annotated LaTeX, and unannotated LaTeX, and weird things can be obtained from weird macro packages. Naming is also often random and coquettish. The end result is poor readability and maintainability. If you fail to do so, you will encounter various conflicts.

Content vs format

A more significant problem is that LaTeX 2 ε  does not implement the principle of separating content from format .

As I mentioned just now, although TeX, which was launched by Knuth in ten years, is known as a "typing artifact", the author must understand all aspects of fonts, font size, alignment, and even line break paging algorithms. Only God can control it. Later, Lamport not only considered the individual struggle of genius, but also considered the historical process of mortals. His LaTeX encapsulated many typographical details with "fool-like" commands, so it became popular all over the world once it was launched.

The so-called "separation of content and format", in the context of LaTeX, is to use semantic commands to mark as much as possible, rather than directly specifying the style of the text. such as:

  • By indicating  \documentclass yes  article, report or  book, it means that this is a shorter article, a medium-length report, or a longer book. LaTeX will define different styles accordingly (including chapter headings, headers, footers, etc.) without the need for the author to worry.

  • Use  \emph rather than  \textit for emphasis, because  \emph that emphasize meaning (emphasize), but  \textit the format is just a statement, although the standard document class both basically the same effect (nested if there will be differences).

  • With  \thanks not  \footnote give additional information about the author (in common  \author in), it will be marked with a special symbol to distinguish the general footnotes.

This advantage, on the one hand, makes the article structure clear and organized; on the other hand, once there is a need to modify the format, it will be easier to operate.

However, things are not always perfect. LaTeX's kernel is very small ( latex.ltx about 8,500 lines, article.cls about 600 lines, size10.clo about 200 lines), either lack of support for related functions, or the format is not written and cannot be changed. In short, unless you completely follow the eight-legged approach, as long as you want to make some formatting changes, only Google will write a long list of long-winded and unintelligible codes for yourself.

Times are always evolving, and Professor Till Tantau prepared beamer document classes to prepare slides when preparing his doctoral thesis defense  (for this reason, he also wrote a drawing package  PGF/TikZ, which is simply breathtaking). In terms of architecture, beamer the design is highly creative. It is divided into 3 levels:

  • Slide author only need to know  frame, theorem, emph those associated with the presentation of a command or environment, simply select the appropriate topic (theme), we can complete the production;

  • Template / theme designers can use the  \setbeamertemplate\setbeamercolor\setbeamerfont and other commands to format the various components, but without regard to the specific content of the presentation;

  • Senior designers (or TeX programmers), for each semantic component, can independently control and directly manipulate specific implementation details.

This hierarchical interface naturally divides users into three categories, so content writing, format design and specific implementation can be completely separated.

If you are familiar with front-end technology, you will find that it is very similar:

  • HTML is responsible for describing webpage content and marking semantic elements;

  • CSS defines styles and specifies how the corresponding HTML elements should be displayed;

  • The browser side is responsible for the final rendering of the web page, that is, the rendering style.

To some extent, the explosive development of front-end technology has given LaTeX3 considerable experience. In the future, we have every reason to believe that HTML / CSS technology and TeX technology can be compatible with each other.

LaTeX3 and expl3

All in all,  although LaTeX 2 ε is currently the most popular TeX format, it also has considerable limitations, and this limitation can not be solved by minor repairs, you must start anew and rebuild a new format-LaTeX3.

The so-called format is to encapsulate the primitives provided by TeX for easy use. Common ones are plain TeX, LaTeX and ConTeXt. LaTeX3 is the next generation LaTeX format. Of course, given the  unshakable position of LaTeX 2 ε , this format will not be abandoned, and the LaTeX3 format will only serve as an additional option. As for when LaTeX3 can really be made into a complete format file ( .fmt), it is still an unknown number.

At present, the main development work of LaTeX3 is concentrated in  expl3 macro packages. expl3 Provides a rich programming interface, what we will introduce later, are all around this macro package. expl3 Not only can it run in LaTeX, but also in plain TeX and ConTeXt.

expl3 It was launched in 1992 and has been around for more than ten years. At present, many macro packages have started  expl3, that is, using LaTeX3 syntax. such as:

  • ctex-kit in the  CTeX, xeCJK, xpinyin, zhnumber and so on, the current mainly developed by Li Qing, Liu Haiyang and Huangchen Cheng et al., maintenance

  • LaTeX3 team members Will Robertson maintenance  fontspec, unicode-mathand maintenance of Joseph Wright siunitx

  • I wrote  fduthesis and zhlipsum

All registered LaTeX3 packages (actually module names) and related information can be  l3prefixes found in.

personal idea

The following are purely personal opinions and do not guarantee their accuracy and objectivity.

  • As a markup language , LaTeX is just right: HTML is slightly redundant and not suitable for writing articles directly (despite Emmet), Markdown is concise and clear but the markup elements are too poor. In contrast, LaTeX tags are much more flexible, with longer being longer and shorter being shorter.

  • As a programming language , (LA) TeX is actually very cumbersome, providing reliable and convenient core syntax and standard libraries, which is probably the main goal of LaTeX3.

  • In fact, LaTeX is equivalent to HTML + CSS + JavaScript, not only to be responsible for markup, but also to manage styles, but also to be able to realize various fantasy needs freely and flexibly. This flexibility certainly prevents the principle of "separation of content and format" from being thoroughly implemented, but imagine that all format changes, even if they only appear once, would require an additional semantic markup, is it really necessary? After all, there are too many edge cases of typesetting.

  • As we all know, the popularity of LaTeX is mainly due to the powerful processing ability of mathematical formulas, so that some people have been confused about the relationship between LaTeX and MathType, MathJax, etc. But in this respect, LaTeX3 itself cannot change much (  unicode-math it is likely to become the future direction).

  • Compared to web publishing, which has been promoted by W3C and a large number of manufacturers, desktop publishing has also invested heavily in Adobe and Microsoft. The TeX community can almost be said to rely solely on the efforts of the community. This is obviously a shortfall, so you do n’t have to expect too much progress. Even if LaTeX3 finally ends up, the current results ( expl3 programming interface) will not be lost.

Published 117 original articles · 69 praises · 10,000+ views

Guess you like

Origin blog.csdn.net/zsd0819qwq/article/details/105378682