BIL101, Introduction to Computers and Information Systems Chapter 8 TeX: The Stradivarius Language...

41
BIL101, Introduction to Computers and BIL101, Introduction to Computers and Information Systems Information Systems Chapter 8 Chapter 8 TeX: The Stradivarius Language TeX: The Stradivarius Language of Word Processing of Word Processing and Document Preparation and Document Preparation Partially Based on the some chapters of the books entitled Partially Based on the some chapters of the books entitled A Gentle Introduction to TEX, A Manual for Self-study A Gentle Introduction to TEX, A Manual for Self-study by by Michael Doob Michael Doob and and TeX book by TeX book by Donald E. Knuth Donald E. Knuth Written by Written by Metin Demiralp Metin Demiralp Istanbul Technical University, Informatics Institute, Istanbul Technical University, Informatics Institute, Maslak - 80626, İstanbul, TÜRKİYE Maslak - 80626, İstanbul, TÜRKİYE Version 0.60 Version 0.60
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    215
  • download

    0

Transcript of BIL101, Introduction to Computers and Information Systems Chapter 8 TeX: The Stradivarius Language...

BIL101, Introduction to Computers and BIL101, Introduction to Computers and Information SystemsInformation Systems

Chapter 8Chapter 8•TeX: The Stradivarius Language TeX: The Stradivarius Language

of Word Processingof Word Processingand Document Preparationand Document Preparation

Partially Based on the some chapters of the books entitledPartially Based on the some chapters of the books entitledA Gentle Introduction to TEX, A Manual for Self-studyA Gentle Introduction to TEX, A Manual for Self-study by by

Michael DoobMichael Doobandand

TeX book byTeX book byDonald E. KnuthDonald E. Knuth

Written byWritten byMetin DemiralpMetin Demiralp

Istanbul Technical University, Informatics Institute, Maslak - Istanbul Technical University, Informatics Institute, Maslak - 80626, İstanbul, TÜRKİYE80626, İstanbul, TÜRKİYE

Version 0.60 Version 0.60

TEX: Stradivarius Language TEX: Stradivarius Language of Word Processing and of Word Processing and Document PreparationDocument Preparation

•TEX is a programming language TEX is a programming language like HTML. Hence, this is the like HTML. Hence, this is the second time to encounter the second time to encounter the programming technologies. This programming technologies. This will be very helpfull when we will be very helpfull when we deal with SQL, GnuPlot and deal with SQL, GnuPlot and Mahtematica ...Mahtematica ...

The Name, a Short History, The Name, a Short History, and Identificationand Identification

•The words like The words like technologytechnology find find their roots in the Greek originated their roots in the Greek originated term starting with the letters τterm starting with the letters τ which means art as well as which means art as well as technology. We imply that this technology. We imply that this facility, that is, TEX is a master tool facility, that is, TEX is a master tool which is equipped with both which is equipped with both technology and art.technology and art.

•TEX was developed by Donald E. Knuth TEX was developed by Donald E. Knuth who was a Computer Science guru at who was a Computer Science guru at Stanford University, through a major Stanford University, through a major project of the same University in 1970’s. project of the same University in 1970’s. The purpose was to create a software The purpose was to create a software package which removes or diminishes all package which removes or diminishes all difficulties in the document preparation difficulties in the document preparation into a very minor level. After TEX was into a very minor level. After TEX was born there had been a lot of efforts to born there had been a lot of efforts to create new macro packages to facilitate create new macro packages to facilitate its utilization.its utilization.

•The reason why we pronounce TEX like The reason why we pronounce TEX like tech or more precisely tech or more precisely teckstecks is to remind is to remind the user TEX is essentially concerned the user TEX is essentially concerned with high-quality technical manuscripts. with high-quality technical manuscripts. It emphasizes on the art and technology It emphasizes on the art and technology and reminds that it the only thing you and reminds that it the only thing you can use if you want to produce a high can use if you want to produce a high fidelity document. If you merely, want to fidelity document. If you merely, want to obtain a document which is passably obtain a document which is passably good enough, a simpler system which is good enough, a simpler system which is called just called just word processorword processor (like Word) (like Word) is sufficient.is sufficient.

•The main goal of TEX is not just to The main goal of TEX is not just to obtain a readable document but to obtain a readable document but to produce finest quality.produce finest quality.

•The TEX’s main site in the Internet The TEX’s main site in the Internet locates at the URL (Unified Resource locates at the URL (Unified Resource Location) http://www.ctan.org. You can Location) http://www.ctan.org. You can find its versions for all major operating find its versions for all major operating systems there. The site has an systems there. The site has an amazing abundance of programs and amazing abundance of programs and utilities about TEX and related things.utilities about TEX and related things.

•The Structure and Running of TEXThe Structure and Running of TEX TEX is in fact a programming language TEX is in fact a programming language since in contains most of the necessary since in contains most of the necessary features to be so. You can use variables, features to be so. You can use variables, constants, input and output variables, constants, input and output variables, logical statements, loops, an arithmetical logical statements, loops, an arithmetical operation capability which suffices for operation capability which suffices for the necessary calculation in printing, and the necessary calculation in printing, and macros. It has a modular structure so macros. It has a modular structure so you can extend or build a new structure you can extend or build a new structure which is oriented to a more specific task, which is oriented to a more specific task, on it. on it.

•These capabilities give of course a lot of These capabilities give of course a lot of superiorities to TEX over the other softwares superiorities to TEX over the other softwares and many computer wizards think that it is and many computer wizards think that it is at a ultimate point where there is no more at a ultimate point where there is no more road to go. This point of TEX is emphasized road to go. This point of TEX is emphasized by giving TEX a version number which is by giving TEX a version number which is composed of the first few decimal digits of composed of the first few decimal digits of the transcendental number the transcendental number ..

•TEX works like an interpreter.TEX works like an interpreter.

•When it is invoked it waits line by line input to When it is invoked it waits line by line input to process and creates an output file whose type process and creates an output file whose type is called is called DVI DVI which is an acronym for the which is an acronym for the statement statement DeVice IndependentDeVice Independent..

•TEX needs a bundle of lines as input to TEX needs a bundle of lines as input to produce the desired output. These lines can produce the desired output. These lines can be composed of commands and text material be composed of commands and text material to be appearing in the output.Each TEX to be appearing in the output.Each TEX command must start by a backslash character command must start by a backslash character \ and can be composed of lower or upper case \ and can be composed of lower or upper case letters.letters.

• It is possible to define new commands by It is possible to define new commands by combining the TEX primitive commands. combining the TEX primitive commands. The entirity of the lines which forms the The entirity of the lines which forms the input a document preparation session is input a document preparation session is defined as a TEX input file. All TEX files defined as a TEX input file. All TEX files are assumed to have a four letter are assumed to have a four letter suffix suffix .tex..tex. The files can be created by The files can be created by means of any editor or editing facility means of any editor or editing facility existing in your system.existing in your system.

•The creation of the DVI file form a TEX input The creation of the DVI file form a TEX input file can be realized in two ways, either file can be realized in two ways, either interactiveinteractive or or batch modebatch mode. In the . In the interactive mode each line of the input is interactive mode each line of the input is given separetely but cosecutively. To invoke given separetely but cosecutively. To invoke an interactive mode under SuSE Linux you an interactive mode under SuSE Linux you can give the command can give the command textex at the at the commandline interpreter prompt by facing commandline interpreter prompt by facing with the following display. with the following display. demiralp@jaguar:~/bil101 > tex This is demiralp@jaguar:~/bil101 > tex This is TeX, Version 3.14159 (Web2C 7.3.1)TeX, Version 3.14159 (Web2C 7.3.1)

•** **** ** is the global TEX prompt and, to is the global TEX prompt and, to proceed, you must give either a TEX proceed, you must give either a TEX command or a filename for the TEX input command or a filename for the TEX input file to be pocessed. If you give the correct file to be pocessed. If you give the correct filename for the TEX input file, say filename for the TEX input file, say sample.texsample.tex then the filename of the file between the then the filename of the file between the parentheses is returned in the next line and parentheses is returned in the next line and a single star prompt appears in the a single star prompt appears in the following line like the following display.following line like the following display.

• demiralp@jaguar:~/bil101 > tex This is demiralp@jaguar:~/bil101 > tex This is TeX, Version 3.14159 (Web2C 7.3.1) **sample.tex TeX, Version 3.14159 (Web2C 7.3.1) **sample.tex (sample.tex) (sample.tex) ** This happens when the file This happens when the file sample.texsample.tex does not contain any terminating does not contain any terminating command. So what we are going to do for command. So what we are going to do for the finalization of the session is to give either the finalization of the session is to give either endend or maybe more securely or maybe more securely bye bye command at command at this prompt.this prompt.

• If the file If the file sample.texsample.tex would contain one of would contain one of the commands the commands endend or or byebye then the above then the above display would replace with the following display would replace with the following one. one. demiralp@jaguar:~/bil101 > tex demiralp@jaguar:~/bil101 > tex This is TeX, Version 3.14159 (Web2C This is TeX, Version 3.14159 (Web2C 7.3.1) **sample.tex 7.3.1) **sample.tex (sample.tex [1] ) (sample.tex [1] ) Output written on sample.dvi (1page,220bytes). Output written on sample.dvi (1page,220bytes). Transcript written on sample.log.Transcript written on sample.log.

• In the case of termination via In the case of termination via endend or or byebye commands an output file created under commands an output file created under the name the name texput.dvitexput.dvi and the text format and the text format display of the session is collected into a display of the session is collected into a file whose name is a file whose name is a texput.logtexput.log. However, in . However, in the case where the session is terminated the case where the session is terminated by entering Ctrl d no dvi file is created by entering Ctrl d no dvi file is created although all the next format display of the although all the next format display of the session is saved into the file session is saved into the file texput.logtexput.log..

•The batch mode is quite straight forward. The batch mode is quite straight forward. We write all necessary TEX commands and We write all necessary TEX commands and the text material to create what we want in the text material to create what we want in the output display into a file whose name the output display into a file whose name contains a four letter contains a four letter suffix.texsuffix.tex. This file is . This file is the TEX input file. We run TEX by specifying the TEX input file. We run TEX by specifying the name of the input file after tex the name of the input file after tex command followed by at least one space command followed by at least one space character at the commandline interpreter of character at the commandline interpreter of the system.the system.

•For example, in our SuSE system we can For example, in our SuSE system we can give the display of an attempt to run a give the display of an attempt to run a TEX file TEX file sample.texsample.tex and its result as and its result as follows. follows. demiralp@jaguar:~/bil101 > tex demiralp@jaguar:~/bil101 > tex sample This is TeX, Version 3.14159 sample This is TeX, Version 3.14159 (Web2C 7.3.1) (sample.tex [1] ) (Web2C 7.3.1) (sample.tex [1] ) Output written sample.dvi (1 page,216 Output written sample.dvi (1 page,216 bytes). Transcript written on sample.log. bytes). Transcript written on sample.log. The interactiveThe interactive mode is more mode is more pedagogical because of the instant pedagogical because of the instant reaction of TEX after entering each line.reaction of TEX after entering each line.

•The batch mode can also be in the The batch mode can also be in the same way but this time the errors can same way but this time the errors can be seen and removed after the run of be seen and removed after the run of the commands in the given input file the commands in the given input file a single entity. a single entity.

• A successful running stage always A successful running stage always creates a DVI and LOG files unless a creates a DVI and LOG files unless a special structure is given to the input special structure is given to the input file not to produce any output page. file not to produce any output page. DVI and LOG files are created under DVI and LOG files are created under the names same as the the names same as the .tex.tex suffixed suffixed input filename and suffixesinput filename and suffixes.dvi.dvi and and .log.log..

•Displaying the DVI FilesDisplaying the DVI Files After the successful After the successful editing and running stages the editing and running stages the next step is the displying of the next step is the displying of the output included in the DVI file in output included in the DVI file in binary form. For this task we need binary form. For this task we need a GUI (Graphical User Interface) a GUI (Graphical User Interface) specific software which is called specific software which is called DriverDriver. Most common driver for X . Most common driver for X window system is called window system is called xdvixdvi..

•There are some recently developed There are some recently developed environments like KDE or Gnome environments like KDE or Gnome where some other drivers are under where some other drivers are under development. For example, SuSE development. For example, SuSE Linux KDE contains a driver for DVI Linux KDE contains a driver for DVI files under the name files under the name kdvikdvi..

•The Microsoft Windows series or NT The Microsoft Windows series or NT use some other type of drivers like use some other type of drivers like dvi2scrdvi2scr although there are some although there are some efforts to develop the version efforts to develop the version xdvixdvi for for these systems.these systems.

Document Preparation With Document Preparation With TEXTEX

•Plain Text, Text Alignment and Plain Text, Text Alignment and Blocks, Glues, FontsBlocks, Glues, Fonts

•Plain TextPlain Text Now we can start to learn how a Now we can start to learn how a TEX input file can be prepared in the TEX input file can be prepared in the editing step by opening a file whose editing step by opening a file whose name is name is sample1.texsample1.tex. You can use any . You can use any editor for this purpose and it is quite editor for this purpose and it is quite natural to use your favorite editor. natural to use your favorite editor.

•Text Alignment and BlocksText Alignment and Blocks TEX reads all lines of the TEX reads all lines of the input file and makes a single strip input file and makes a single strip by changing each character with its by changing each character with its roman counterpart and deleting all roman counterpart and deleting all newline characters without caring newline characters without caring how long the final strip is. TEX can how long the final strip is. TEX can use many different fonts and the use many different fonts and the default font type is called default font type is called RomanRoman. . The dafault size of the font is ten The dafault size of the font is ten points where 72.22 points are points where 72.22 points are equivalent to one inch.equivalent to one inch.

•Each character has a display in a Each character has a display in a rectangular frame which has three rectangular frame which has three dimensions: width, height and depth. dimensions: width, height and depth. The frame is divided into two vertical The frame is divided into two vertical segments separated by a horizontal segments separated by a horizontal line which is called line which is called baselinebaseline. The . The distance between the top edge and distance between the top edge and the baseline is the baseline is heightheight. The distance . The distance from the baseline to the bottom edge from the baseline to the bottom edge is called is called depthdepth. The dept of a . The dept of a character may be zero depending on character may be zero depending on its shape. The its shape. The widthwidth is the length of is the length of the baseline.the baseline.

•TEX assumes that the display will TEX assumes that the display will be locate on a standard sheet of be locate on a standard sheet of paper which is either paper which is either letter letter or or A4 A4 which is a standard mostly used in which is a standard mostly used in Europe. The default size of the Europe. The default size of the display can be changed by using display can be changed by using the TEX commands \the TEX commands \hsize, \vsize, \hsize, \vsize, \hoffset, \voffsethoffset, \voffset..

•A single line can be left or right A single line can be left or right justified or centered in the output justified or centered in the output display. This can be accomplished display. This can be accomplished by using the TEX commands \by using the TEX commands \leftline, leftline, \rightline, and \centerline\rightline, and \centerline..

•All these commands need a single All these commands need a single argument which may involve any argument which may involve any space or tab characters. The text space or tab characters. The text material to be left or right justified or material to be left or right justified or centered must be given in blocks centered must be given in blocks structure. A block in TEX is a group of structure. A block in TEX is a group of commands and text material which commands and text material which are encompassed by the left and right are encompassed by the left and right braces {,}.braces {,}.

•One more facility about the alignment One more facility about the alignment is the deliberately breaking of the is the deliberately breaking of the lines within a predefined tolerance. lines within a predefined tolerance.

•We can mention two TEX commands We can mention two TEX commands to this end: \to this end: \break,break, and \ and \goodbreakgoodbreak. \. \breakbreak breaks the line at the point it is breaks the line at the point it is given and increases the given and increases the intermediate spaces such that the intermediate spaces such that the new formed line is terminated by the new formed line is terminated by the last word before the command. \last word before the command. \goodbreakgoodbreak breaks the line at the point breaks the line at the point it is issued such that some it is issued such that some reasonable amount and size of reasonable amount and size of spaces are used and then the spaces are used and then the remaining portion of the line is filled remaining portion of the line is filled by the sufficient spaces.by the sufficient spaces.

•Glues Glues You can create spaces You can create spaces between the words or lines. The between the words or lines. The spaces can be divided into two spaces can be divided into two categories: categories: skips skips and and gluesglues. . skipskip is a is a vertical or horizontal space such that vertical or horizontal space such that it can be divided into pieces if it it can be divided into pieces if it exceeds the borders of line or page. exceeds the borders of line or page. glueglue is an indivisible space. is an indivisible space. skipskip needs a reference material to be needs a reference material to be activated. activated. glueglue does not behave so. does not behave so.

•To create a vertical space /vskip or To create a vertical space /vskip or /vglue commands are used. These /vglue commands are used. These commands must be followed some commands must be followed some lengths like pt (point- 72.22 point = 1 lengths like pt (point- 72.22 point = 1 inch), mm, cm.inch), mm, cm.

•There are some special purpose There are some special purpose skipsskips or or gluesglues like \ like \baselineskipbaselineskip, or \, or \parskipparskip, \, \topskiptopskip. . In TEX each line has a baseline where In TEX each line has a baseline where the bases of the characters are located. the bases of the characters are located. Each character of TEX has three Each character of TEX has three dimensions: width, height and depth.dimensions: width, height and depth.

•When two separate characters are When two separate characters are joined by matching their rectangles joined by matching their rectangles horizontally such that these horizontally such that these hypothetical horizontal lines match hypothetical horizontal lines match on the same horizontal direction. on the same horizontal direction. This line is called This line is called baselinebaseline. .

•The command \The command \parskipparskip is used to is used to make spaces between the make spaces between the paragraphs. If you leave a blank line paragraphs. If you leave a blank line or use the command \or use the command \parpar in the TEX in the TEX file then TEX inserts a default space file then TEX inserts a default space between two consecutive lines. between two consecutive lines.

•The command \The command \topskiptopskip is used to is used to make spaces between the headline make spaces between the headline and the first line of the page. If not and the first line of the page. If not given then TEX uses the default given then TEX uses the default value. The command must be value. The command must be followed by the desired skip value.followed by the desired skip value.

•Fonts Fonts As all typographical utilities As all typographical utilities do TEX uses fonts. Font is a do TEX uses fonts. Font is a collection of characters. For TEX the collection of characters. For TEX the numbers of the characters in a font numbers of the characters in a font is limited by 256. is limited by 256.

•There are two major ways for calling a There are two major ways for calling a font inside a TEX document. One and font inside a TEX document. One and easiest way is to give a calling-by-easiest way is to give a calling-by-acronym-command. For example, acronym-command. For example, rmrm, , is used to call roman font of the is used to call roman font of the current size in the document. \current size in the document. \it, \sl, \it, \sl, \bf, \ttbf, \tt commands are used to call commands are used to call italicitalic, , slantedslanted, , extended boldfaceextended boldface, , typewritertypewriter fonts fonts respectively. Therefore, one of these respectively. Therefore, one of these commands can be given at any place commands can be given at any place of the document source file.of the document source file.

•The other way for font calling is to use The other way for font calling is to use the command \the command \fontfont. This command . This command must be followed by a name which is must be followed by a name which is at our disposal for the font, an equal at our disposal for the font, an equal sign, and the real name of the font in sign, and the real name of the font in the TEX package.the TEX package.

•Mathematical and Display Modes, Mathematical and Display Modes, Formulae TypesettingFormulae Typesetting

•Mathematical ModeMathematical Mode You can write mathematical You can write mathematical formulae by using TEX.formulae by using TEX.

•There are two available modes for this There are two available modes for this purpose. The Mathematical Mode can purpose. The Mathematical Mode can be created by encompassing the TEX be created by encompassing the TEX commands and related material by $ commands and related material by $ signs. Anything given between these signs. Anything given between these signs are considered mathematical signs are considered mathematical objects to be inserted into lines by objects to be inserted into lines by TEX. So this mode enables us to TEX. So this mode enables us to combine text material and combine text material and mathematical formulae at the same mathematical formulae at the same line.line.

•Display ModeDisplay Mode The Display Mode can be The Display Mode can be created by encompassing the TEX created by encompassing the TEX commands and related material by commands and related material by $$ signs. Anything given between $$ signs. Anything given between these signs are considered these signs are considered mathematical objects to be mathematical objects to be inserted between lines by TEX. So inserted between lines by TEX. So this mode enables us to typeset this mode enables us to typeset mathematical formulae separately.mathematical formulae separately.

Formulae TypesettingFormulae Typesetting This task can be done by This task can be done by combining the convenient TEX combining the convenient TEX commands by obeying some rules.commands by obeying some rules.

•Does \AE schylus understand \OE dipus? Does \AE schylus understand \OE dipus?

Does Æ schylus understand dipus? Does Æ schylus understand dipus?

•The smallest internal unit of \TeX{} is The smallest internal unit of \TeX{} is about 53.63\AA. about 53.63\AA.

$(\forall x\in \Re)(\exists y\in\Re)$ $y>x$.

${a+b\over c}\quad {a\over b+c}\quad {1\over a+b+c} \not= {1\over a}+ {1\over b}+{1\over c}$.

What are the points where ${\partial \What are the points where ${\partial \over \partial x} f(x,y) = {\partial \over \partial x} f(x,y) = {\partial \over \partial y} f(x,y) = 0$? over \partial y} f(x,y) = 0$?

$e^x \quad e^{-x} \quad e^{i\pi}+1=0 \quad x_0 \$e^x \quad e^{-x} \quad e^{i\pi}+1=0 \quad x_0 \quad x_0^2 \quad {x_0}^2 \quad 2^{x^x}$. quad x_0^2 \quad {x_0}^2 \quad 2^{x^x}$.

$\nabla^2 f(x,y) = {\partial^2 f \over\$\nabla^2 f(x,y) = {\partial^2 f \over\partial x^2}+ {\partial^2 f \over \partial x^2}+ {\partial^2 f \over \partial y^2}$. partial y^2}$.

$$\int \csc^2x\, dx = -\cot x+ C \qquad $$\int \csc^2x\, dx = -\cot x+ C \qquad \lim_{\alpha\to 0} {\sin\alpha \over \\lim_{\alpha\to 0} {\sin\alpha \over \alpha} = 1 \qquad \lim_{\alpha\to \alpha} = 1 \qquad \lim_{\alpha\to \infty} {\sin\alpha \over \alpha} = 0.$$ infty} {\sin\alpha \over \alpha} = 0.$$

• $$ I_4 = \pmatrix{ 1 $$ I_4 = \pmatrix{ 1 &0 &0 &0 \cr&0 &0 &0 \cr0 &1 &0 &0 \cr0 &1 &0 &0 \cr0 &0 &1 &0 \cr0 &0 &1 &0 \cr0 &0 &0 &1 \cr}$$ 0 &0 &0 &1 \cr}$$

\def\boxtext#1{%\def\boxtext#1{%\vbox{%\vbox{%\hrule\hrule\hbox{\strut \vrule{} #1 \vrule}%\hbox{\strut \vrule{} #1 \vrule}%\hrule\hrule}%}%}}\moveright 2 in \vbox{\offinterlineskip\moveright 2 in \vbox{\offinterlineskip\hbox{\boxtext{6}\boxtext{1}\boxtext \hbox{\boxtext{6}\boxtext{1}\boxtext {8}}{8}}\hbox{\boxtext{7}\boxtext{5}\\hbox{\boxtext{7}\boxtext{5}\boxtext{3}}boxtext{3}}\hbox{\boxtext{2}\boxtext{9}\\hbox{\boxtext{2}\boxtext{9}\boxtext{4}}boxtext{4}}}}