m
m
Line 88: Line 88:
 
$$(a+b)^n=\sum_{k=0}^n{n\choose k}a^kb^{n-k}$$
 
$$(a+b)^n=\sum_{k=0}^n{n\choose k}a^kb^{n-k}$$
  
Very pretty. Most of the syntax is straightforward. For instance, Greek letters go $\alpha\neq\beta$ and upcases $\Gamma>\gamma$. Be careful that functions are written in math modes but as functions, e.g., write <nowiki>&#x24;\sin(\pi x)&#x24;</nowiki> not &#x24;sin(\pi x)&#x24; or sin$(\pi x)$, the latter being an abomination. Even if you write sin alone, you have to write <tt>&#x24;\sin&#x24;</tt> alone ($\sin$ alone). The difference of course is that between $\sin(\pi x)$ and $sin(\pi x)$.
+
Very pretty. Most of the syntax is straightforward. For instance, Greek letters go <nowiki>$\alpha\neq\beta$</nowiki> $\alpha\neq\beta$ and upcases <nowiki>$\Gamma>\gamma$</nowiki> $\Gamma>\gamma$. Be careful that functions are written in math modes but as functions, e.g., write <nowiki>$\sin(\pi x)$ not $sin(\pi x)$ or sin$(\pi x)$, the latter being an abomination. Even if you write sin alone, you have to write $\sin$ alone</nowiki> ($\sin$ alone). The difference of course is that between $\sin(\pi x)$ and $sin(\pi x)$. This happens for other symbols, for instance, > is fine for greater (which you can also write as \gt, for "greater than", but use \langle and \rangle for averages, i.e., <nowiki>$\langle x^2\rangle$\neq<x^2>$</nowiki>, can you see it? $\langle x^2\rangle$\neq<x^2>.
 +
 
  
  

Revision as of 11:12, 2 February 2021

$\TeX$ and $\LaTeX$

We have approached how computers display bitmaps on a screen, or store this information on a file. We have seen ASCII and this covers for text, which is already a huge part of what we need to communicate. But Latin alphabet is short of advanced applications. It's good enough for the news, maybe for literature, but how about science? Let's have a look again at one of the oldest equations which humanity has dealt with:

$$x_{1\atop 2}=-{b\pm\sqrt{b^2-4ac}\over 2a}$$

This is the modern notation. It has not always been so neat and structured, being overlayed all over the place with parts of it which extend over others, etc., but it has always required going beyond mere text (and that includes numbers). In particular, in Science, we use a lot Greek letters. We actually also need it without science, for instance because we're Greek and want to read the news on the Internet in our language. For that, technology has developed a new technology, which is the extension of ASCII and is known as unicode. It allows to display characters from other languages, e.g., Greeck, Russian, Chinese, etc. It also covers for a myriad of other characters, from chess ♙♘♗♖♕♔♚♛♜♝♞♟ to road signs ⛔ 🚫 ⚠ ☡ passing by mathematical symbols iħ∂ₜψ(r,t)=[-(∇²/(2m))+V]ψ, and a myriad of things you probably don't need (like a super-asterix ✺ or Groucho Marx's glasses ᅘ). The temptation to encode other fonts has not been resisted. 𝓘𝓼 𝓽𝓱𝓲𝓼 𝓻𝓮𝓪𝓵𝓵𝔂 𝓶𝔂 𝓳𝓸𝓫 𝓽𝓱𝓸𝓾𝓰𝓱? And this remains highly limited for proper math encoding. Compare with the real nice way to write Schrödinger's equation:

$$i\hbar\partial_t\psi(r,t)=\left(-{\nabla^2\over 2m}+V\right)\psi$$

Someone worried about computer's inability to render beautiful math equations when computers started to take up the job of typesetting. Donald Knuth was then working on the Art of Computer programming, an encyclopedia of algorithms and code writing. But when he saw how horrible was the result, he decided to put this on hold and to write a program to typeset text beautifully with a computer. He started the TeX project, which he thought would take him a few months, but turned out to take about 9 years instead![1]. His code became the standard for scientific typesetting, so much so that it is still about the dominant sector as of today, especially for complex documents, either in content (elaborate mathematics) or in size (books, volumes, theses, etc.)

In this lecture, we will learn the bases of this program because as scientists, it is our duty to produce not only nice-looking, but also accurate, intelligible and correct outputs. We will only survey the strict minimum required to produce an output but you are invited to dig in, it's a very powerful and beautiful piece of computer software.

Knuth called his program $\TeX$ which is is the upcase T, E and X of the Greek letters $\tau$, $\epsilon$ and $\chi$. They happen to be the same upcases in Latin or Greek, whence the latin-looking word, which is actually the beginning of τέχνη (ΤΕΧΝΗ – technē), Greek for both "art" and "craft", which is also the root word of technical, so it should be pronounced like "Tech", not like "tex". To demonstrate the power of the program that can assemble glyphs in any way it wants, the name reads $\TeX$ with a displaced E, which would be difficult to do otherwise. In ASCII, Knuth asks that we write TeX to echo that.

It really is a computer language, so we write code, compile it (asks a program, namely, $\TeX$, to process it and turn it into a document. Here's a piece of code:

hello there!

Welcome to \TeX.

\bye

This is simply text and the instructions for the program come with a slash. There are two commands there, one is to typeset $\TeX$ as it should, the other is to signal the end of the document (\bye). We compile this by putting it in a file, say hi.tex, and then from the terminal we run:

tex hi.tex

this will produce

This is TeX, Version 3.14159265 (TeX Live 2019/Debian) (preloaded format=tex)
(./hi.tex [1] )
Output written on hi.dvi (1 page, 268 bytes).
Transcript written on hi.log.

and produce a dvi file which one can either view directly (e.g., with xdvi) or convert into something more popular, like pdf, with dvipdf hi.dvi.

There are two modes in TeX: the text mode and the math mode. We enter the math mode by enclosing its (mathematical) content between $ (dollar sign). So for instance, here is a piece of text combining both:

The number $i$ is special in that $i^2=-1$.

That reads:

Screenshot 20210202 114456.png

It's all written in ASCII, as code, and the program does the formatting. We have just seen superscript. Subscript go with an underscore _. The simpler is to see examples:

If $x_1+x_2=y^2$ then $y=\sqrt{x_1+x_2}$.

gives

If $x_1+x_2=y^2$ then $y=\sqrt{x_1+x_2}$.
The derivative of $\int_a^x f(y)dy=f(x)$ (fundamental theorem of calculus).

gives:

The derivative of $\int_a^x f(y)dy=f(x)$ (fundamental theorem of calculus).

You see that writing the math formula inline squishes it a bit, if it takes a lot of vertical space, as integrals or fractions do. If a formula is very bulky, or if it is important, then we use the displayed mode rather than the inline mode, namely, using two $$ we write something like,

an important number is the golden ratio $$\phi=\frac{1+\sqrt{5}}{2}.$$

gives:

an important number is the golden ratio $$\phi=\frac{1+\sqrt{5}}{2}.$$

There can be a lot of coding involved. Here is the binomial formula:

$$(a+b)^n=\sum_{k=0}^n{n\choose k}a^kb^{n-k}$$

$$(a+b)^n=\sum_{k=0}^n{n\choose k}a^kb^{n-k}$$

Very pretty. Most of the syntax is straightforward. For instance, Greek letters go $\alpha\neq\beta$ $\alpha\neq\beta$ and upcases $\Gamma>\gamma$ $\Gamma>\gamma$. Be careful that functions are written in math modes but as functions, e.g., write $\sin(\pi x)$ not $sin(\pi x)$ or sin$(\pi x)$, the latter being an abomination. Even if you write sin alone, you have to write $\sin$ alone ($\sin$ alone). The difference of course is that between $\sin(\pi x)$ and $sin(\pi x)$. This happens for other symbols, for instance, > is fine for greater (which you can also write as \gt, for "greater than", but use \langle and \rangle for averages, i.e., $\langle x^2\rangle$\neq<x^2>$, can you see it? $\langle x^2\rangle$\neq<x^2>.


As TeX became popular, people started to write "macros", or pieces of code, to

References

  1. Donald Knuth (1997). "Digital Typography (Kyoto Prize Lecture, 1996)" (pdf).