Showing posts with label Math. Show all posts
Showing posts with label Math. Show all posts

Sunday, 27 May 2012

Math in LaTeX


LaTeX is a widely used document markup language and a document preparation system for high-quality typesetting. Based on Donald E. Kruth’s TeX typesetting, it is used for producing scientific and mathematical documents of high typographic quality. However it is quite different from the word processors such as MS Word or LibreOffice etc. which uses the WYSIWYG approach. 

Getting to the basics of it, every LaTeX document must contain the following 3 components (every thing else being optional):

\documentclass{article}
\begin{document}
\end{document}

Here the 1st line tells LaTeX the type of document (article, report, book, letter), and the body of the document must occur between \begin{document} & \end{document} commands. Any text after \end{document} is ignored. 

Few commonly used commands: \pagestyle (controls page numbering and headings), \title, \author, \date, \section (creating separate sections) \tableofcontents etc. 

Math Mode: LaTeX uses a special math mode to display mathematics, as LaTeX typesets math notations differently than the normal text. Special environments have been declared for this purpose, 3 commonly used environments in math mode :

1. math environment : text formulae are displayed inline (within the body of the text) [ TeX shorthand $....$ ]
2. displaymath environment – displayed formulae are separate from the main text [ TeX shorthand $$....$$ ]
3. equation environment

An example:

\documentclass{article}
\begin{document}
$$ \frac{d}{dx}\left( \int\limits_{0}^{x} f(u)\,du\right)=f(x)$$
\end{document}

will produce :
 

Math symbols : the symbols in Math formula fall into different classes : Ord (simple/ordinary), Op (prefix operator), Bin (binary operator), Rel (relation/comparison), Open (left/opening delimiter), Close (right/closing delimiter), Pun (postfix/punctuation). It comprises of

Latin Letters, Arabic numerals (0-9), Greek letters are simple symbols. Example of Greek letters in LaTeX are \Gamma, \alpha, \beta etc. 
Other alphabetic symbols: \complement, \partial, \daleth etc
Misc. Simple Symbols: \#, \&,  \angle, \infty, \exists, \forall etc.
Binary Operator Symbols: *, +, -, \cdot, \div, \pm, etc.
Relational Symbols: <, =, >, \approx, \gg,  \ll, \prec etc.
Relation Symbols (arrows): \leftarrow, \Leftrightarrow, \rightarrow, \curvearrowleft, \curvearrowright etc.
Relation Symbols (Misc): \parallel, \backepsilon, \because, \in, \mid, \nparallel, \sqsubset, \subset etc.
Cumulative Operators: \int, \oint, \prod, \sum, \bigcap, \bigup, \bigsqup, \bigvee, etc.
Punctuation: . ; / | , ; \colon : ! ?
Pairing delimiters: (, ), [, ], \lbrace, \rbrace, \langle, \rangle, \lceil, \rceil, \lfloor, \rfloor etc.
Non-Pairing Extensible Symbols: \backlash, /, \vert etc.
Extensible vertical arrows: \uparrow, \Uparrow, \downarrow etc.
Accents: \bar{x}, \vec{x}, \dot{x}, \hat{x}, \acute{x}, etc.
Named Operators: \cos, \cot, \det, \lg, \lim, \ln, \log, \inf, \dim, \max, \min, \sin, \sup, \tan,

Another Example:

\documentclass{article}
\begin{document}
$$ \left(1+x\right)^n = 1 + nx + \frac{n\left(n-1\right)}{2!}x^2 + \frac{n\left(n-1\right)\left(n-2\right)}{3!}x^3 + \frac{n\left(n-1\right)\left(n-2\right)\left(n-3\right)}{4!}x^4 + \ldots $$
\end{document}

will produce:





Saturday, 19 May 2012

iTeX vs LaTeX

LaTeX is a widely used document markup language and a document preparation system for the TeX typesetting program. Whereas iTeX can be seen as a downgraded LaTeX. The differences arising because of the way we write a research paper (long and technical) and the way we put stuff on the web (short and snappier). Essentially iTeX is a pure converter whereas LaTeX is a mixture of a converter and renderer (technically LaTeX is the rules to convert the input to TeX which is then rendered by TeX).

iTeX is very similar to the Standard LaTeX but with a few differences keeping in mind that iTeX produces MathML.

There are quite a bit of differences between iTeX and TeX :

1. In iTeX $abc$ would be a single token which when converted to MathML would be <mi>abc</abc>

However $a b c$ would be three tokens which when converted to MathML will be <mi>a</mi><mi>b</mi><mi>c</mi>

but it is important to note that the TeX considers both the above to be the same.

2. Numbers: $10^20$ will be 10^(20)  in iTeX whereas it will be 10^(2)0 in LaTeX , hence it is always safe to use curly brackets to be consistent across like $10^{20}$

3. Whitespace : $a \textrm{ and } b$ will be x and y in LaTeX whereas in iTeX it will be xandy. The reason behind this being the fact that mtext elements in MathMl doesn’t have fore and aft whitespaces.

4. As MathML doesn’t know the difference between unary operators and binary relations it is inconvenient for iTeX to do so.

5. iTeX doesn’t parse math if it includes non-ascii characters

6. It is possible to insert MathML markup inside iTeX equations making “<” and “>” pretty significant. \lt and \gt are used to get less-than and greater-than signs.

A much more detailed look into LaTeX will follow up in the next post.

References:

1. http://www.latex-project.org/guides/

2. http://golem.ph.utexas.edu/~distler/blog/itex2MML.html

Wednesday, 9 May 2012

A look into MathML


Mathematical Markup Language is an application of Extensible Markup Language (XML) for describing mathematical notation and capturing both its structure and content. The main aim of MathML is to integrate math with the World Wide Web. Essentially MathML is for math what HTML is for text. 

As mentioned before MathML deals with both the structure and the content of a mathematical notation. The structure part is called Presentation MathML and as the name suggests it deals with the display of the notation, equation or formula. Whereas the content part is called Content MathML and it focuses on the semantics. 
An example of a Presentation MathML for  is :

 <math>
  <mrow>
    <mi>x</mi>
    <mo>=</mo>
    <mfrac>
      <mrow>
        <mrow>
          <mo>-</mo>
          <mi>b</mi>
        </mrow>
        <mo>
          &#xB1;<!--PLUS-MINUS SIGN-->
        </mo>
        <msqrt>
          <mrow>
            <msup>
              <mi>b</mi>
              <mn>2</mn>
            </msup>
            <mo>-</mo>
            <mrow>
              <mn>4</mn>
              <mo>
                &#x2062;<!--INVISIBLE TIMES-->
              </mo>
              <mi>a</mi>
              <mo>
                &#x2062;<!--INVISIBLE TIMES-->
              </mo>
              <mi>c</mi>
            </mrow>
          </mrow>
        </msqrt>
      </mrow>
      <mrow>
        <mn>2</mn>
        <mo>
          &#x2062;<!--INVISIBLE TIMES-->
        </mo>
        <mi>a</mi>
      </mrow>
    </mfrac>
  </mrow>
</math>

As seen above every valid MathML expression is wrapped in outer <math> tags which shows each instance of MathML markup within a document. 

The presentation elements have 2 classes – Token Elements (symbols, numbers, names etc.) and Layout Schemata (which builds expressions out of the parts and have only elements as its content). Here we are using various token elements such as mi – identifier, mo – operator, mn – number. And general layout schemata elements such as mrow (groups any numbers of sub-expressions horizontally), mfrac (fraction of 2 sub-expressions), msqrt (square root)

Also above we can see that we write b^2 using superscript and two letters written side by side will mean two variables multiplied together which shows that the presentation markup just holds the structure and we need content markup to put in meaning into the formula. 

Content MathML for the same formula would be:

<math>
  <apply>
    <eq/>
    <ci>x</ci>
    <apply>
      <divide/>
      <apply>
        <plus/>
        <apply>
          <minus/>
          <ci>b</ci>
        </apply>
        <apply>
          <root/>
          <apply>
            <minus/>
            <apply>
              <power/>
              <ci>b</ci>
              <cn>2</cn>
            </apply>
            <apply>
              <times/>
              <cn>4</cn>
              <ci>a</ci>
              <ci>c</ci>
            </apply>
          </apply>
        </apply>
      </apply>
      <apply>
        <times/>
        <cn>2</cn>
        <ci>a</ci>
      </apply>
    </apply>
  </apply>
</math>

Content MathML represents mathematical objects as expression trees (i.e. applying operator to sub objects). Hence, the terminal nodes represents basic math objects such as numbers, variables etc. and the internal nodes represent mathematical constructions or function applications. 

Token elements – ci (represent variables) ,cn(numbers), Predefined functions elements – divide, minus, plus are used here. And as we can see above that the Apply element groups the function with its arguments syntactically.

About thirty-eight of the MathML tags describe abstract notational structures, while another about one hundred and seventy provide a way of unambiguously specifying the intended meaning of an expression.