Computer Class 12 GSEB Solutions Chapter 12 Publishing Documents using LaTeX

Students frequently turn to Computer Class 12 GSEB Solutions and GSEB Computer Textbook Solutions Class 12 Chapter 12 Publishing Documents using LaTeX for practice and self-assessment.

GSEB Computer Textbook Solutions Class 12 Chapter 12 Publishing Documents using LaTeX

Question 1.
Compare LaTeX with word processors. List the strengths and weaknesses of both.
Answer:
Using LaTeX

  • To use LaTeX, there is a requirement of LaTeX distribution (software).
  •  Most include TeX and some additional software in them.
  • TeX Live is a very popular LaTeX distribution software which is available in the standard Ubuntu repositories.
  • There is also a need for plain text editor and software to view the output file.
  • LaTeX can produce output in different file formats and depending on the output file format, corresponding viewer software is needed.
  • LaTeX documents are typically created using any plain text editor (like gedit or SciTE).
  • The different parts of the text are marked using LaTeX commands that associate a meaning to them.
  • For example, \title is used to define the document’s title, \author to specify the author(s) of the document and \date to indicate the date the document was created.
  • Similarly, \chapter, \section, \subsection, \paragraph can be used to explicitly specify the logical structure of the document.
  • LaTeX comes with built-in ways to format these document elements in a pleasant-looking professional style.
  • However, when typing the document, one can see it as plain unformatted text with these commands written as part of the text.
  • The document is then compiled (processed) using the LaTeX system and an output file is produced.
  • LaTeX may also produce some additional files.
  • In most cases, these additional files can be deleted safely without losing any information.
  • When the output file is viewed using appropriate software or print it on a printer, one can see the formatted document.
  • If the looks of the document are not satisfactory, it can be further customized with the help of built-in styles or own styles can be defined.
  • Every time a modification is made in the source text, there will be a need to compile it again for seeing the effect of the change in the output document.
  • Both TeX and LaTeX use the file extension .tex.
  • LaTeX now has a command called pdflatex that produces the popular PDF (Portable Document format) format files.
  • PDF files can be viewed on screen as well as printed to printers and the printout looks exactly same as the monitor display.
  • PDF files are very popular for sharing printable documents on the Web.
  • PDF documents can be viewed in Ubuntu’s default viewer, evince.
  • Hence the edit-compile-view cycle is as given below :
    1. Edit the document using any plain text editor like gedit.
    2. Compile the document by issuing the command pdflatex filename at the command prompt (in the directory where the tex file is saved).
    3. View the generated PDF file by either opening ‘ it from the GUI or by issuing the command evince pdffilename at the command prompt (the terminal will display the next prompt only when the PDF file is closed).
  • SciTE editor can also be used for editing LaTeX files.
  • While both gedit and SciTE have syntax highlighting (displaying different language elements in different colours for easy identification and readability), SciTE has one advantage over gedit – one can compile and view the document from within the SciTE program itself.
  • To use SciTE with pdflatex, there is a need to make changes in its configuration file.
  • It has to be performed only once, after installing the required software.

The LaTeX Language

  • LaTeX is essentially a markup language.
  • The LaTeX source consists of plain text, with some parts of the text marked up using markers known as commands.
  • Some commands are independent commands – they do not mark any specific part of the text.
  • These commands can perform a variety of tasks when the document is processed by the LaTeX system.
  • They provide information about the text or the document.
  • They indicate the role of the marked text in the overall structure of the document (and hence cause LaTeX to format the text in certain way).
  • They directly specify formatting. They instruct LaTeX to process the document in a certain way (for example, use a certain page size, start a new chapter only on an odd-numbered page, etc.).
  • LaTeX commands start with a \ (backslash) character followed by the command name.
  • The command name can be a string of alphabetic letters only or it can be a single non-letter.
  • LaTeX commands are case-sensitive (capital and small letters are treated as being different).
  • Some commands accept additional information (for example, the \text\color command expects the color in which the text is to be displayed).
  • This additional information is called arguments.
  • There are two types of arguments, Optional and compulsory arguments.
  • Optional arguments are not mandatory.
  • The user may provide them or may not.
  • If one or more optional arguments are to be provided, they have to be written after the command name, enclosed in[ ] (square brackets) and separated by comma.
  • These are followed by mandatory arguments (if there are any) in { } (curly braces) with each mandatory argument written in its own set of curly braces.
  • For example, if a command\documentclass[12pt] {article} is given, then the documentclass is the name of the command, 12pt is an optional argument while article is a compulsory argument.
  • LaTeX treats all whitespace characters (the space, tab and newline characters) as the same.
  • It converts all occurrences of multiple consecutive whitespace into a single space character.
  • The white spaces at the beginning of a line are generally ignored and one or more consecutive blank lines are considered to mark the beginning of a new paragraph.
  • This means that even if the text has several lines, it will appear in the output as a continuous flow unless there is a blank line in it.
  • To insert a break in lines use V (the line break command) at the end of each line except the last line in the paragraph.
  • Ligure shows an example of continuous text as well as how to insert explicit line breaks.
    Figure shows the output of the LaTeX file.
\documentclass [ 12pt] {article}
\title{Line handling in \LaTeX}
\date{May 2013}
\begin{document}
\maketitle
\section{Continuous Text} \textsf{
We have no wings, we cannot fly 
But we have legs to sail and climb 
By slow degrees and by and by 
The cloudy summits of our time}
\section{Text with Separate Lines} \textf{ 
Heights by great men reached and kept \\ 
Were not attained by a sudden flight \\
But they, while their companions slept, \\ 
Were toiling upwards in the night} 
\end{document}

Figure : Line Handling Example Source File

(1) Continuous Text
We have no wings, we cannot fly But we have legs to sail and climb By slow degrees and by and by The cloudy summits of our time.
(2) Text with Separate Lines
Heights by great men reached and kept 
Were not attained by a sudden flight 
But they, while their companions slept,
Were toiling upwards in the night.

Figure : Line Handling Example Output

  • The following characters are reserved characters in LaTeX;
    # $ % & _ (underscore) { } ∧ ~ \
  • They have a special meaning in LaTeX.
  • These characters cannot be used directly in the text in LaTeX. If they are to be used in any text, then the following forms have to be used.
    \# \$ \% \& \_ \{ \}
    \∧{} \~{} \textbackslash{}
  • Note the special cases of the last three characters.
  • The symbols < and > print very differently by default (except in math mode).
  • Hence they must be written as \textless and \textgreater.
  • The ‘(grave accent or backquote) and’ (apostrophe or straight quote) are used around text to put it in single
    quotos, like ‘Book Code’
  • Double quotes are produced by repeating them twice, like “Book Code” (these are two straight quotes, not a single double quote).
  • These look odd in the source file, but are typeset properly in the output file.
  • LaTeX uses groups to mark portions of text.
  • A group ¡s enclosed between curly braces {and}.
  • Any command in a group applies only to text following the command within that group.
  • Also, some commands are followed by a group and apply to the whole group.
  • Groups are useful for applying few commands to a small amount of text such as a part of a line, few lines or a paragraph.
  • For the cases where a multitude of commands piust be applied (for example, for formatting a table or mathematical equation properly) or where some command (s) have to be applied to large portions of the text (like several paragraphs, whole sections), LaTeX provides a facility called environments.
  • An environment begins with a \begin {environment-name} command and ends with a \end{environment-name} command.
  • All the formatting characteristics of the environment are applied to the entire text inside the environment.
  • Environments can be nested. One environment can be nested inside another.
  • There are several standard environments meant for specific types of content, like equation, quotation, table and list that come with nice ready-made formatting commands for these specific content types.
  • While LaTeX documents are meant to be displayed and printed, LaTeX has several
    advanced features, including programming and automatically generating parts of the documents or multiple documents (mail merge).
  • Often a complicated LaTeX template or package developed by one person or team is used by many others.
  • Sometimes such people also need to tweak the LaTeX code.
  • In such cases, providing explanation for the complicated parts makes it easy for others to understand the code.
  • Such explanation is provided in the form of comment.
  • In LaTeX, the % character marks the beginning of a comment and everything from the % character up to the end of the line is treated as a comment.
  • Comments are meant for the humans who read the LaTeX source code in a text editor for understanding and modifying it.
  • Comments are completely ignored by the compilation process and hence never make it into the output.

Computer Class 12 GSEB Solutions Chapter 12 Publishing Documents using LaTeX

Question 2.
List key reasons for the popularity of LaTeX.
Answer:
Advantages of LaTeX

  • LaTeX has several benefits.
  • Just as TeX was extended to LaTeX, LaTeX itself also can be extended.
  • Anyone can create additional packages to enhance the features provided in LaTeX to add new features or to provide alternate implementations.
  • Thousands of such packages have been created by LaTeX users around the world to cater to different needs.
  • Most of them are free.
  • They are hosted on the CTAN
    (The Comprehensive TeX Archive Network)
    website at www.ctan.org.
  • LaTeX is extremely good at laying out complex mathematical formulae in nice looking and appropriate way.
  • Because of this, it is quite popular among authors and publishers in mathematics, engineering, computer science and other technical areas.
  • Because it is open source, it is highly systematic and is developed in the academic spirit of knowledge sharing and collaboration.
  • It is getting popular among academicians and scholars.
  • People in these fields use LaTeX, share their views and experiences, help one another and share new packages and drive the further development of LaTeX.
  • LaTeX has built-in facilities to automatically update numbering and references and to automatically create table of contents, indexes, and other such needs, taking a major burden off the mind of the author.

Question 3.
List the reserved characters and characters that cannot be used directly in LaTeX.
Answer:
The LaTeX Language

  • LaTeX is essentially a markup language.
  • The LaTeX source consists of plain text, with some parts of the text marked up using markers known as commands.
  • Some commands are independent commands – they do not mark any specific part of the text.
  • These commands can perform a variety of tasks when the document is processed by the LaTeX system.
  • They provide information about the text or the document.
  • They indicate the role of the marked text in the overall structure of the document (and hence cause LaTeX to format the text in certain way).
  • They directly specify formatting. They instruct LaTeX to process the document in a certain way (for example, use a certain page size, start a new chapter only on an odd-numbered page, etc.).
  • LaTeX commands start with a \ (backslash) character followed by the command name.
  • The command name can be a string of alphabetic letters only or it can be a single non-letter.
  • LaTeX commands are case-sensitive (capital and small letters are treated as being different).
  • Some commands accept additional information (for example, the \text\color command expects the color in which the text is to be displayed).
  • This additional information is called arguments.
  • There are two types of arguments, Optional and compulsory arguments.
  • Optional arguments are not mandatory.
  • The user may provide them or may not.
  •  If one or more optional arguments are to be provided, they have to be written after the command name, enclosed in[ ] (square brackets) and separated by comma.
  • These are followed by mandatory arguments (if there are any) in { } (curly braces) with each mandatory argument written in its own set of curly braces.
  • For example, if a command\documentclass[12pt] {article} is given, then the documentclass is the name of the command, 12pt is an optional argument while article is a compulsory argument.
  • LaTeX treats all whitespace characters (the space, tab and newline characters) as the same.
  • It converts all occurrences of multiple consecutive whitespace into a single space character.
  • The white spaces at the beginning of a line are generally ignored and one or more consecutive blank lines are considered to mark the beginning of a new paragraph.
  • This means that even if the text has several lines, it will appear in the output as a continuous flow unless there is a blank line in it.
  • To insert a break in lines use V (the line break command) at the end of each line except the last line in the paragraph.
  • Ligure shows an example of continuous text as well as how to insert explicit line breaks.
    Figure shows the output of the LaTeX file.
\documentclass [ 12pt] {article}
\title{Line handling in \LaTeX}
\date{May 2013}
\begin{document}
\maketitle
\section{Continuous Text} \textsf{
We have no wings, we cannot fly 
But we have legs to sail and climb 
By slow degrees and by and by 
The cloudy summits of our time}
\section{Text with Separate Lines} \textf{ 
Heights by great men reached and kept \\ 
Were not attained by a sudden flight \\
But they, while their companions slept, \\ 
Were toiling upwards in the night} 
\end{document}

Figure : Line Handling Example Source File

(1) Continuous Text
We have no wings, we cannot fly But we have legs to sail and climb By slow degrees and by and by The cloudy summits of our time

(2) Text with Separate Lines
Heights by great men reached and kept 
Were not attained by a sudden flight 
But they, while their companions slept,
Were toiling upwards in the night.

Figure : Line Handling Example Output

  • The following characters are reserved characters in LaTeX;
    # $ % & _ (underscore) { } ∧ ~ \
  • They have a special meaning in LaTeX.
  • These characters cannot be used directly in the text in LaTeX. If they are to be used in any text, then the following forms have to be used.
    \# \$ \% \& \_ \{ \}
    \∧{} \~{} \textbackslash{}
  • Note the special cases of the last three characters.
  • The symbols < and > print very differently by default (except in math mode).
  • Hence they must be written as \textless and \textgreater.
  • The ‘(grave accent or backquote) and’ (apostrophe or straight quote) are used around text to put it in single
    quotos, like ‘Book Code’
  • Double quotes are produced by repeating them twice, like “Book Code” (these are two straight quotes, not a single double quote).
  • These look odd in the source file, but are typeset properly in the output file.
  • LaTeX uses groups to mark portions of text.
  • A group ¡s enclosed between curly braces {and}.
  • Any command in a group applies only to text following the command within that group.
  • Also, some commands are followed by a group and apply to the whole group.
  • Groups are useful for applying few commands to a small amount of text such as a part of a line, few lines or a paragraph.
  • For the cases where a multitude of commands piust be applied (for example, for formatting a table or mathematical equation properly) or where some command (s) have to be applied to large portions of the text (like several paragraphs, whole sections), LaTeX provides a facility called environments.
  • An environment begins with a \begin {environment-name} command and ends with a \end{environment-name} command.
  • All the formatting characteristics of the environment are applied to the entire text inside the environment.
  • Environments can be nested. One environment can be nested inside another.
  • There are several standard environments meant for specific types of content, like equation, quotation, table and list that come with nice ready-made formatting commands for these specific content types.
  • While LaTeX documents are meant to be displayed and printed, LaTeX has several
    advanced features, including programming and automatically generating parts of the documents or multiple documents (mail merge).
  • Often a complicated LaTeX template or package developed by one person or team is used by many others.
  • Sometimes such people also need to tweak the LaTeX code.
  • In such cases, providing explanation for the complicated parts makes it easy for others to understand the code.
  • Such explanation is provided in the form of comment.
  • In LaTeX, the % character marks the beginning of a comment and everything from the % character up to the end of the line is treated as a comment.
  • Comments are meant for the humans who read the LaTeX source code in a text editor for understanding and modifying it.
  • Comments are completely ignored by the compilation process and hence never make it into the output.

Computer Class 12 GSEB Solutions Chapter 12 Publishing Documents using LaTeX

Question 4.
Explain the structure of a LaTeX document.
Answer:
The Structure of a LaTeX Document

  • A LaTeX document has two parts namely preamble and content.
  • The preamble contains metadata (data about data).
  • In this case, the metadata is information about the document (for example, what kind of document it is, who is the author, when it was created.) and instructions on how LaTeX should process the document.
  • The actual content is always inside the environment document, written between.

Question 5.
Explain the \frac command and its nesting inside another \frac command with an example.
Answer:

  • LaTeX supports a large number of mathematical operators. The power (x2) and the index operator (x1) are not provided separately, but are implemented using the generic superscript operator ∧ (the caret character) and the generic subscript operator _(the underscore character) respectively.
  • The superscript operator raises the text that follows it, while the subscript operator lowers it.
  • Both reduce the size of the text as well.
  • Absolute values can be denoted by enclosing the expression between two | (vertical bar) symbols.
  • Fractions are created using the command \frac{numerator}{denominator}, while square root of a number x is denoted using the command \sqrt{x}.
  • These operators can be nested one inside another.
  • That means one can have a fraction in the denominator of another fraction, whose square root is in the numerator of yet another fraction and so on.
  • There is no practical limit on this, and LaTeX takes care of sizing and placing the elements appropriately.
  • Round brackets work normally.
  • An example usage of mathematical operators is given in listing.
    • Create a new file in SciTE using the File → New menu option
    • Type the content shown in Listing in a SciTE editor.

Computer Class 12 GSEB Solutions Chapter 12 Publishing Documents using LaTeX 1Computer Class 12 GSEB Solutions Chapter 12 Publishing Documents using LaTeX 2

    • Save the file using File → Save menu option.
    • Now Select the Tools → Build menu option
      (shortcut key : F7) to compile your LaTeX file.
    • If the compilation is successful, select the tools → Go menu option (shortcut key : F5) to view the file in the default document viewer.
    • Figure shows the output of the file when viewed in the document viewer.

Computer Class 12 GSEB Solutions Chapter 12 Publishing Documents using LaTeX 3

Question 6.
Choose the most appropriate option from those given below :

1) Modern word processing software operates in which of the following mode ?
(A) WIGIW1S
(B) WISYWIG
(C) WYSIWYG
(D) WISYWYG
Answer:
(C) WYSIWYG

2) Which of the following is not a reserved character in LaTeX ?
(A) @
(B) %
(C) $
(D) A
Answer:
(A) @

Computer Class 12 GSEB Solutions Chapter 12 Publishing Documents using LaTeX

3) Which of the following begins with \begin{name} and ends with end{name}?
(A) group
(B) section
(C) environment
(D) preamble
Answer:
(C) environment

4) Which of the following character is used to mark a comment in LaTeX ?
(A) $
(B) %
(C) #
(D) &
Answer:
(B) %

5) Which of the following part of the LaTeX document contains the metadata ?
(A) preface
(B) TOC
(C) preamble
(D) environment
Answer:
(C) preamble

6) Which of the following web site hosts the LaTeX packages ?
(A) CTAN
(B) CLAN
(C) CTEN
(D) CLEN
Answer:
(A) CTAN

7) Which of the following will not be automatically numbered ?
(A) \section
(B) \subsection
(C) \chapter*
(D) \part
Answer:
(C) \chapter*

8) Which of these environments displays mathematical content inline with the text ?
(A) displaymath
(B) math
(C) equation
(D) text
Answer:
(B) math

9) Which of the following commands generate the set union symbol ?
(A) \cup
(B) \setunion
(C) \cap
(D) \union
Answer:
(A) \cup

Computer Class 12 GSEB Solutions Chapter 12 Publishing Documents using LaTeX

10) Which of the following operator is used to denote a subscript or an index ?
(A) _ (underscore)
(B) ∧ (caret)
(C) – (minus)
(D) < (less than)
Answer:
(A) _ (underscore)

11) Which of the following refer to the very first line in the preamble ?
(A) \usepackage
(B) \title
(C) \maketitle
(D) \documentclass
Answer:
(D) \documentclass

Computer Class 12 GSEB Notes Chapter 12 Publishing Documents using LaTeX

The Preamble

  • As LaTeX supports creation of a wide variety of documents, each with different characteristics and format, LaTeX needs to know what type of a document used as a source file is.
  • The very first element in the preamble must be \ documentclass{document-class-name} specifying the type of the document.
  • Some common document classes are as shown in Table .
  • Many document classes have options.
  • Table lists some common options.
Document Class Purpose
article For writing individual articles.
book For writing entire books.
slides For creating presentations slides. It automatically sets larger font size.
letter For writing letters.
beamer For generating presentations similar to office suites using the beamer package.

Table : Some Common Document Classes

Options Function
10pt, 11pt, 12pt Sets the size of the main font in the document to 10 points (the default), 11 points and 12 points respectively.
a4paper, letterpaper, legalpaper Defines the paper size. These are several international standard paper sizes.
The most common paper sizes in regular office use are A4, letter and legal.
fleqn Displayed formulas and equations are flushed left (left- aligned) rather than centered (the default)
landscape Changes the layout of the document to print in landscape mode.

Table : Some Common Opetions of Document Classes

  • The document class declaration is followed by optional package declaration.
  • While the LaTeX system itself provides for many common typesetting requirements, it also recognizes that it cannot provide everything that users may need.
  • Hence LaTeX allows users to write packages that provide additional functionality.
  • There is a large community of LaTeX users who develop new LaTeX packages or enhance existing ones to cater to their own needs and then share them with others over the Comprehensive TeX Archive Network (CTAN).
  • LaTeX distributions themselves usually come with a large number of such packages preinstalled.
  • To use one or more packages in our document, there is a need to declare them in the preamble as \usepackage{package-name}.
  • Some packages can also have options to customize their behaviour.
  • If the user is not using options for any packages, multiple package names can be declared in a single \usepackage command, separated by commas.
  • Table shows only a few of the commonly used packages.
Package Description
amsmath It contains the advanced math extensions for LaTeX originally developed for the American Mathematical Society.
color It adds support for colored text.
easylist Adds support for multilevel lists.
geometry For page layout tasks like setting paper size, orientation, margins, etc.
listings Has special features for including programming code within the document
Setspace Lets you change line spacing

Table : Some Commonly Used Packages.

  • Three more pieces of information are typically supplied. They are mentioned below :
    \title{the-title-of-the-document}
    \author{author(s) of the document}
    \date{date of creation / last update of the document, in any format}
  • It is necessaiy to provide the title and the author if LaTeX has to create an automatic title.
  • Providing date is optional, if it is omitted then the date of compilation is used in the title.
  • These pieces of information can be supplied in the preamble or as the first thing in the document environment also.

Computer Class 12 GSEB Solutions Chapter 12 Publishing Documents using LaTeX

The Document Environment

  • The document environments for articles and slides will only have a title followed by the main content of the document.
  • A title is automatically generated by LaTeX when it sees that \maketitle command.
  • The \title, \author and \date commands must precede the \maketitle command because their information is used in creating the title.
  • A book can have a far more elaborate structure, though most elements are optional.
  • The document environment of a book is divided into three main parts :
    1. The front matter
    2. The main matter
    3. Back matter
  • These three parts are denoted by the following commands respectively :
    1. \frontmatter
    2. \mainmatter
    3. \backmatter
  • This structure as things like the title, the table of contents and the preface in the front matter, the bibliography, index and references in the back matter and the primary content in the form of chapters, sections and subsections in the main matter.
  • The main contents of a book has a hierarchical structure, where a book is divided into parts, parts are divided into chapters, chapters are divided into sections which are divided into subsections which are divided into sub subsections which are divided into paragraphs which are divided into subparagraphs.
  • These are marked with the commands \part, \chapter, \section, \subsection, \subsubsection, \paragraph and \ subparagraph respectively.
  • Each accepts one compulsory argument, the title; and one optional argument. The title has to be displayed in the table of contents.
  • They start a new part, chapter or section respectively.
  • The title to be displayed in the main text can be longer and can have internal formatting (like boldface or italics applied to a part of the title).
  • The title to be displayed in the table of contents is expected to be short and devoid of any special formatting to maintain consistency in looks.
  • These 7 elements nest inside one another and have an integer level assigned to them, with part having a level of 1, chapter a level of 0, section a level of 1 and so on.
  • The parts, chapters, sections are numbered automatically by LaTeX.
  • The author can also move chapters, sections and subsections without having to bother about remembering.
  • The parts are numbered in Roman numerals (I, II, III, and so on), while the chapters, sections, subsections, etc. are numbered in Arabic numerals (1, 2, 3, and so on).
  • All chapters after the special \appendix command (to be used only once) are treated as appendices and get uppercase alphabetic numbering (A, B, C, and so on).
  • Pages in the front matter are numbered using Roman numerals, while the pages in the main matter and back matter are numbered in Arabic numerals with the numbering restarting from 1. While both the front matter and back matter can have chapters (like preface, acknowledgements, bibliography), those chapters usually do not have sections or other sub-elements.
  • The commands defining different elements of the document also have their starred equivalents that are not numbered.
  • For example, \section* can be used to create a section that is not automatically numbered.
  • By default elements are assigned number up to level 2 that is up to subsections. Sub subsections and further divisions are not assigned numbers.
  • This can be changed by modifying one of the built-in counters of LaTeX in the preamble.
  • For example, the command
    \setcounter{secnumdepth} {3}
    Ensures that elements up to level 3 (subsubsection) are assigned numbers.
  • Elements are assigned a number formed by appending a period (.) and the element number to the number of the parent element.
  • Chapters are an exception as their assigned number does not have a part number and period in front of them.
  • Chapters are assigned simple Arabic numeral numbers.
  • If part II of a book has chapter 5 in it, which, in turn has section 4 in it that has subsection 1 in it, the subsection would be numbered 5.4.1.
  • A well-formatted table of contents (TOC) is generated automatically from the elements titles by LaTeX when it encounters the command Uableofcontents.
  • Again, by default a TOC has entries up to level 2 (subsection), but this can be changed by altering the value of another built-in counter tocdepth.
  • There is one important point to be noted. LaTeX processes the source file sequentially from the beginning to end in a single pass.
  • It produces the output file also sequentially.
  • It cannot move back and forth in either of the file. This poses a problem.
  • The TOC comes early in the document and must output the entries for chapters or sections along with their page numbers.
  • However, at that point LaTeX has no knowledge about chapters or sections that would follow.
  • In this kind of situation, LaTeX must be run multiple times.
  • In the first run LaTeX collects information about the document structure and stores it in supplementary files.
  • The TOC in the output files would empty at this point or may have information from old supplementary files.
  • In the second run, it will pick up the correct information from the supplementary files in the beginning to produce the correct TOC.
  • Just like the TOC, LaTeX can also maintain list of , figures, list of tables, cross references, bibliography, and glossary or index automatically.
  • This offloads a great burden from the author’s back and is major reason for the popularity of LaTeX.
    Example :
  • To have an idea of how LaTeX typesets books, one source file can be created and see its output.
  • Use SciTE editor with LaTeX to work on the example.
    • Create a new file in SciTE using the File → New menu option.
    • Type the content shown in Listing in a SciTE editor.
\documentclass[12pt] {book}
\usepackage {amsmath}
\title {\huge Mathematics \\[3\baselineskip]
\Large Standard 12}
\author {Gujarat State Board of School Textbooks}
\date{2013}
\setcounter{secnumdepth} {2}
\setcounter {tocdepth}{1}
\begin{document}
\frontmatter
\maketitle
\chapter {\MakeUppercase{Fundamental Duties}}
\tableofcontents
\chapter{\MakeUppercase{About This Textbook...}}
\mainmatter
\part{Semester I}
\chapter{Set Operations}
\section{Introduction}
\section*{Exercise 1.1}
\section{Properties of the Union Operation}
\subsection{Union is a Binary Operation}
\section{Properties of the Intersection Operation}
\subsection{Intersection is a Binary Operation} \
subsection{Associative Law}
\chapter{Number Systems}
\section{Introduction}
\section*{Exercise 2.1}
\section{Irrational Numbers}
\chapter{Polynomials}
\chapter{Coordinate Geometry}
\chapter{Some Primary Concepts in Geometry : 1}
\chapter*{answers}
\markboth{\Make Uppercase{Answers}}{}
\addcontentsline{toc}{chapter}{Answers}
\part{Semester II}
\chapter{Quadrilaterals}
\section{Introduction}
\section{Plane Quadrilateral}
\chapter{Areas of Parallelograms and Triangles}
\section{Introduction}
\section{Interior of a Triangle}
\chapter{Circle}
\chapter{Surface Area and Volume}
\chapter* {Answers}
\markboth{\MakeUppercase{Answers}}{}
\addcontentsline{toc}{chapter}{Answers}
\appendix
\chapter {Terminology}
\backmatter \end{document}

Listing : A Sample Book in LaTeX

    • Save the file using File → Save menu option. Note that the extension of the file should be .tex.
    • Now select Tools → Build menu option (shortcut key: F7) to compile the LaTeX file.
    • The output window will show several messages. If the last line (in blue color) reads Exit code: 0 then compilation was successful. Otherwise the error messages may point the error(s), but often they are difficult to interpret.
    • If the compilation is successful, then select Tools → Go menu option (shortcut key: F5) to view the file in the default document viewer.
    • Close the document viewer before returning to SciTE.

Computer Class 12 GSEB Solutions Chapter 12 Publishing Documents using LaTeX

Text Formatting

  • In LaTeX documents, a paragraph is typed in a continuous flow without pressing ENTER key.
  • LaTeX then adjusts the text automatically.
  • It decides how much text should go in the first line, how much text should go in the second line, and so on according to the page width, font size, alignment option used.
  • LaTeX usually avoids breaking a word in two parts.
  • It has a hyphenation algorithm to decide the most appropriate way of breaking the word with a hyphen (-).
  • For example, if the word formatting cannot be accommodated on a single line, the first line may end with formatt- and the next line may begin withing.
  • On the other hand, there are some situations where some text, even though technically forming multiple words, should not be split into multiple lines.
  • For example, up to are two words, and yet, it is not desirable to have one line ending in up and next line beginning with to because up is an independent word with different meaning.
  • So the reader is surprised for a moment on seeing to on the next line.
  • This is an obstacle to smooth reading experience.
  • To avoid it, both up and to should be on the same line, either the first line or the second.
  • In LaTeX, this can be taken care of by inserting a non-breaking space between up and to.
  • LaTeX uses the ~ (tilde) character to denote a non-breaking space.
  • LaTeX divides font families into three categories.
    1. Roman (also called serif) font have a tiny line or curve called serif at the end of the strokes (lines). ‘
    2. Sans serif fonts do not have serifs while monospace fonts use equal width for all characters.
    3. Monospace fonts are typically used for computer code listings.
  • The default fonts are Roman.
  • These three types of fonts can be used for any text by employing the commands \textrm{text}, \textsf{text} and \texttt{text} respectively.
  • The difference between serif and sans serif fonts can be seen in figure where the section titles are in the default serif fonts while the body text is in sans serif.
  • The font size can be changed using the commands \tiny, \scriptsize, \footnotesize, \small, \normalsize, Marge, MARGE, \huge and \Huge.
  • Notice that the commands are case-sensitive.
  • The commands \textbf, textit and \emph can be used to add the bold, italic and emphasis (generally same as italics) effect to the text.
    – \textsc provides small capital letters.
  • Superscripts and subscripts can be created in text mode using the commands \textsuperscript and \textsubscript respectively from the package fixltx2e.

Paragraph Formatting

  • In LaTeX, the setspace package provides the singlespace, onehalfspace, doublespace and spacing {amount-of-spacing} environments for setting the line spacing.
  • By default, body text is fully justified in LaTeX.
  • To achieve left alignment, right alignment or center alignment, one has to use the environments flushhleft, flushright and center respectively.
  • The first line of a paragraph is indented, except for the paragraphs immediately following a heading.
  • The Mndent and \noindent commands can be used immediately before a paragraph to explicitly make the first line indented and unindented respectively.
  • The verbatim environment outputs everything inside it (including special characters, spaces, newlines and LaTeX commands) as it is without any processing.
  • The moreverb package provides a listing environment with one mandatory argument line- number-of-first-line for program code listing with line numbers.

Computer Class 12 GSEB Solutions Chapter 12 Publishing Documents using LaTeX

Page Layout

  • In LaTeX, the geometry can be used for page layout.
  • The paper size and margins can be passed as optional arguments with the \usepackage command itself. Example the command given below :
    \usepackage[a4paper, top=lin, bottom=2in,
    left=1.5in, right=l in] {geometry}
  • sets the page size to A4, top margin to 1″, bottom margin to 2″, left margin to 1.5″ and right margin to 1″.
  • Page sizes have been standardized internationally.
  • The page sizes commonly used with regular printers are A4, letter and legal.
  • These can be specified by a4paper, letterpaper and legalpaper respectively.
  • The page orientation can also be specified using the portrait (default) and landscape options.
  • Documents can be either one-sided or two-sided.
  • Articles are by default one-sided while books are two-sided.
  • Two-sided documents differentiate between the left (even) and right(odd) pages and can have different margins for both, to take care of amount of page space used up by the binding.
  • There can also be rules like all chapters must start on an odd page.

Typesetting Mathematical Content in LaTeX

  • Ability of automatically laying out complex mathematical content is a major strength of LaTeX.
  • The most common way of laying out mathematical content in LaTeX is using the packages amsmath, amssymb and amsfonts created by the American Mathematical Society.
  • he amsmath package defines several environments for mathematical content.
  • There are two ways of typesetting formulas and equations.
  • One can have them printed as part of the running text (inline) or they can be printed independently on their own lines (called display in LaTeX parlance).
  • The former form can be obtained using the math environment, while the latter can be obtained using the displaymath environment,
  • The equation environment is a display environment that automatically numbers equations.
  • A convenient way of embedding math environment in running text is to enclose the mathematical content between $…$.
  • In mathematical environments, each letter is treated as a mathematical variable.
  • Hence they are different from the text environments.
  • To understand these environments, create a text file by using code in listing.
    • Create a new file in SciTE using File → New menu option
    • Type the content shown in Listing in a SciTE editor
\documentclass [12pt] {article}
\usepackage{amsmath}
\title{ Introduction to \LaTeX}
\date{May 2013}
\begin{document}
\section*{math environment}
The quadratic equation, in its general form, is
\begin{math}
axA2 + bx + c = 0
\end{math}.
You learnt about them in class X.
The quadratic equation, in its general form, is $ax∧2 + bx + c = 0$. You learnt about them in class X.
\section* {displaymath environment}
The quadratic equation, in its general form, is
\begin{displaymath}
ax∧2 + bx + c = 0
\end{displaymath}. You learnt about them in class X
\end{ document}

Listing : Demonstration of the math environments

    • Save the file using File → Save menu option
    • Select the Tools Build menu option (shortcut key : F7) to compile the LaTeX file.
    • If the compilation is successful, select the Tools → Go option (shortcut key : F5) to view the file in the default document viewer.
    • Figure shows the output of the file when viewed in document viewer.

math environment
The quadratic equation, in its general form, is ax2 + bx + c = 0. You leamt about them in class X.
The quadratic equation, in its general form, is ax2 + bx + c = 0. You leamt about them in class X.

displaymath environment
The quadratic equation, in its general form, is ax2 + bx + c = 0
You learnt about them in class X.
Figure : Part output of the TeX code in Listing

Computer Class 12 GSEB Solutions Chapter 12 Publishing Documents using LaTeX

Using Mathematical Symbols

  • Mathematics uses a large number of symbols.
  • Letters of the Greek alphabet have their corresponding commands, like \alpha, \beta, \gamma, \pi that produce the lower case letters.
  • The same commands, when used with the first letter in the uppercase, for example \Alpha produce capital Greek letters. There are commands for other mathematical symbols as well.
  • Figure and Figure show some LaTeX commands and the mathematical symbols produced by them using the AMS packages.
  • The reason for providing commands for the trigonometric functions sin, cos and others are that they need to be recognized as functions rather than as individual variables.

Computer Class 12 GSEB Solutions Chapter 12 Publishing Documents using LaTeX 4

Using Equations

  • LaTeX provides a special equation environment for typesetting equations.
  • Each equation is to be enclosed in the equation environment, which cannot be embedded in a math environment.
  • Equations are numbered automatically and center-aligned.
  • Listing shows an example of using the equation environment, while figure shows a part of the output.
\documentclass [12pt] {article}
\setlength{\parindent}{Opt}
\userpackage{amsmath}
\title{Introduction to \LaTeX}
\date{May 2013}
]begin{document}
\begin{equation}
\sin∧2\theta + \cos∧2\theta=1
\end{equation}
\begin{equation}
\sec∧2\theta -\tan∧2\theta=1
\end{equation}
\begin{equation}
\csc∧2\theta -\cot∧2\theta=1
\end{equation}
\end{document}

Listing : Using the Equation Environment

sin2θ + cos2θ = 1 (1)
sec2θ – tan2θ = 1 (2)
csc2θ – cot2θ = 1 (3)

Figure : Output of the TeX code in Listing

Leave a Comment

Your email address will not be published. Required fields are marked *