Table of Content

These are Haskell related articles.

Preface

Goal: Write a Math Formula with LaTex.

I wish someone introduce me to LaTex, while I was studying Engineering Degree. Despite of my regret, I would like to introduce it to you. So that you can use it in daily lives, from just making school paper, or just to communicate your idea in social media.

$$ \lim\limits_{x \to \infty} \exp(-x) = x $$


Standalone

Now that I meet Data Science, and Functional Programming, I also have a need to write down formula, in a blog using MathJax. And sent Formula via Telegram or Whatsapp using PNG image.

Now here is the issue? I use LaTeX to create PDF, with output as pages. The output of the article always give a big page. I never use it to create standalone small images. And the output does not fit well with formula. It is always show one page, even for a small formula.

Luckily the word standalone helped me find the answer while googling. Now the output is only that little formula.

\documentclass{standalone}
\begin{document}
  {\Large
    $\displaystyle
      \lim\limits_{x \to \infty} \exp(-x) = x
    $
  }
\end{document}

Then run the folowing command

 latex equation.tex
 dvipng equation.dvi
 feh equation1.png

This will show you this below:

LaTeX: Result

Not good? How about some decoration?

 dvipng equation.dvi -D 200
 convert -border 20x20 -bordercolor white math-051.png math-052.png
 feh equation2.png

This will show you this below:

LaTeX: Result

If you need a cool image, I can show you LaTeX in ViM.

LaTeX: Source and PNG Result

If you wish you can also enable transparent background with dvipng.

 dvipng equation.dvi -D 200 -bg transparent

Install

You might also need to install extra package, and it depends on your system.

Gentoo

 sudo emerge -av texlive-latex
 sudo emerge -av dvisvgm
 sudo emerge -av texlive-latexextra

openSUSE

This will install 2148 packages on openSUSE 15.1

 sudo zypper install texlive-latex-bin-bin
 sudo zypper install texlive-standalone

Or if you need cases:

 sudo zypper install texlive-cases

Aligning Multiline Equation

After a few trial and error, I found a way to write down multiple equation with alignment, in standalone document.

Indentation Issue

\documentclass[
  preview
]{standalone}

\usepackage{amsmath}

\begin{document}
\begin{equation*}
\begin{split}
\nonumber 
f(x) &= \frac{5x + 6}{4}\\
     &= \frac{5x + 6}{4}\\
\end{split}
\end{equation*}
\end{document}

As you can see, the figure has undesirable left margin.

LaTeX: Multiline Issue

How to Solve ?

Just set indentation to zero.

\usepackage[fleqn]{amsmath}
\setlength{\mathindent}{0cm}

Example

\documentclass[
  preview
]{standalone}

\usepackage[fleqn]{amsmath}
\setlength{\mathindent}{0cm}

\usepackage{amssymb}

\begin{document}
\begin{equation*}
\begin{split}
\nonumber 
      && f(x) = \frac{2x}{4x - 7},
          x \ne \frac{7}{4}\\
\Rightarrow &&         y &= \frac{2x}{4x - 7}\\
\Rightarrow &&  4xy - 7y &= 2x\\
\Rightarrow &&  4xy - 2x &= 7y\\
\Rightarrow && x(4y - 2) &= 7y\\
\Rightarrow &&         x &= \frac{7y}{4y - 2}\\
\therefore
 && f(x)^{-1} = \frac{7x}{4x - 2},
          x \ne \frac{1}{2}\\
\end{split}
\end{equation*}
\end{document}

LaTeX: Multiline Result


I am Normie

But hey, I'm not a coder ? How do I start ?

Tea Inside

For non-savvy person, the easiest way to accomplish this is to use TeaLaTeX compiler, created by a talented young man named Ammar Faizi.

Just try a few LaTex, and this site will compile the result for you.

Source Code

How about source code? I do not have linux ricing to show eye candy code.

Well, you can utilize carbon.now.sh. Paste your code and voila.

LaTeX Source: carbon.now.sh result


Conclusion

I know that his article is short. It is intended to be a very basic start to LaTeX.

That is all. This is my first article in January 2020. A short article that might has big impact. Because I am going to need a lot of LaTeX, later on.


LaTeX is easy. Let's have some fun with it.

What do you think ?