# Usage (from version 4.0.0)

## Two types of LaTeX content

This app supports two types of LaTeX content. Simple content such as `e = mc^2` will be rendered by MathJax engine, and more complex content that uses packages such as `tikz` or `chemfig` will be rendered by TeX Live engine.

## Insert macros

In the article editor, click the **Insert** button, and select **Other macros** from the list.

<figure><img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2FvHkPOm14sWK4QMPRoY0J%2Fimage.png?alt=media&#x26;token=0276a014-ea6a-46cd-a11d-3a965124eea2" alt=""><figcaption><p>LaTeX for Confluence</p></figcaption></figure>

In the **Select macro** dialog, search for "**latex"**.

<figure><img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2FdsYVmxxA8djbteGivVkj%2Fimage.png?alt=media&#x26;token=b3dbd221-ae5e-4908-af52-3f64e4ecaf0c" alt=""><figcaption><p>LaTeX for Confluence</p></figcaption></figure>

Alternatively, type **{** and select the LaTeX macros.

<figure><img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2FAlaghPgRi8OmgnnH0ruS%2Fimage.png?alt=media&#x26;token=8186b8fd-d5bc-4ffc-8a14-7f5322b6ef75" alt=""><figcaption><p>LaTeX for Confluence</p></figcaption></figure>

## Insert simple LaTeX content (MathJax engine)

To insert simple LaTeX content please use the following macros:

* **LaTeX inline (MathJax engine)**
* **LaTeX block (MathJax engine)**

These macros use the MathJax engine to render content. The content is as simple as `e=mc2` and does not require LaTeX preambles.

<figure><img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2FUHJBD3FOvkkGG7FfVsuX%2Fimage.png?alt=media&#x26;token=c0f1b215-2768-4b24-9a77-081ad1f69c2c" alt=""><figcaption><p>LaTeX for Confluence</p></figcaption></figure>

While editing a formula, you can click on the **Math Editor** button to open the **LaTeX Math Editor**. This editor will help you write LaTeX content easily with many visual hints. You can open the **Math Keyboard** by clicking on the keyboard icon in the right-hand corner of the Math Editor preview area. The content you write here will be filled to the Macro editor. To close the editor, click **Save** or **Cancel** button.

<figure><img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2F4ZIo2iMhPNfRjNQTdhrp%2Fimage.png?alt=media&#x26;token=e9250431-e239-4216-a657-5532c2dbbf1a" alt=""><figcaption><p>LaTeX for Confluence</p></figcaption></figure>

Click **Publish** to save the article. The article with LaTeX content will then be rendered.

<figure><img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2F2rnIPkPqgELh0YxQVClj%2Fimage.png?alt=media&#x26;token=9f6b952f-b717-461b-97ca-423232cc8bad" alt=""><figcaption><p>LaTeX for Confluence</p></figcaption></figure>

## Insert complex LaTeX content (TeX Live engine)

{% hint style="info" %}
This feature was introduced in version 5.0.0.
{% endhint %}

Sometimes you need to render complex LaTeX content such as the following one

```latex
\documentclass{article}
\pagestyle{empty}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot3[
    surf,
]
{exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}
\end{document}
```

which will be rendered as

<figure><img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2FIQUcAcoZ0yPQ1SguAfWd%2Fimage.png?alt=media&#x26;token=8a16f04a-efe8-4f10-9911-e25f07aed9e9" alt=""><figcaption><p>LaTeX for Confluence</p></figcaption></figure>

In this case, please make use of the following macros:

* **(Advanced) LaTeX block (e.g. plot, chemistry formulae) using pdflatex engine**
* **(Advanced) Inline LaTeX content (e.g. plot, chemistry formulae) using pdflatex engine**

### System requirements

The `pdflatex` and Poppler (<https://poppler.freedesktop.org>) must be installed and added to the PATH environment variable. The Operating System user that the Confluence server is running in must be able to use the `pdflatex` without specifying its location.

We recommend installing `pdflatex` using TeX Live <https://www.tug.org/texlive/> (preferably) or MikTeX <https://miktex.org/>. All LaTeX packages should be installed to maximize the renderability.

To ensure the security of the Confluence server, this app does not allow the execution of bash commands in LaTeX content.

For a general instructions to install TeX Live and Poppler please see <https://fulstech.gitbook.io/docs/latex-beautiful-math-for-confluence/confluence-data-center-and-confluence-server/how-to-install-tex-live>.

### Verify if pdflatex has been installed correctly

To verify if `pdflatex` has been installed correctly, please following these steps:

Switch to the same OS user that is running Confluence.

Create a file `test.tex` with the following content.

```latex
\documentclass{article}
\begin{document}
Hello, world!
\end{document}
```

Execute this command: `pdflatex test.tex`. An PDF file with name `test.pdf` should be created.

<img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2FNX1gNRtbK0hro1Y2b97t%2Fimage.png?alt=media&#x26;token=01b56d67-8a06-44b0-8b66-b49b3f294aef" alt="" data-size="original">

### Syntax

Please make sure that the following preample is used since it will exclude page headers, footers, and numbers from the output:

```latex
\documentclass{article}
\pagestyle{empty}
```

The following sections will show you some examples.

<figure><img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2FLZ8G9k19aDp19sad2XmH%2Fimage.png?alt=media&#x26;token=f8470e46-f5f3-4e61-ad2a-4651ecbb313c" alt=""><figcaption><p>LaTeX for Confluence</p></figcaption></figure>

### 3d plots

```latex
\documentclass{article}
\pagestyle{empty}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot3[
    surf,
]
{exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}
\end{document}
```

### Chemistry formulae

```latex
\documentclass{article}
\pagestyle{empty}
\usepackage{chemfig}
\begin{document}
\chemfig{A*5(-B=C-D-E=)}
\end{document}
```

### Figures

```latex
\documentclass{article}
\pagestyle{empty}
\usepackage[pdftex]{pict2e}
\usepackage[dvipsnames]{xcolor}
\begin{document}
\setlength{\unitlength}{1cm}
\setlength{\fboxsep}{0pt}
\fbox{%
\begin{picture}(3,3)
\put(0,0){{\color{blue}\circle*{0.25}}\hbox{\kern3pt \texttt{(0,0)}}}
\put(3,3){{\color{red}\circle*{0.25}}\hbox{\kern3pt \texttt{(3,3)}}}
\end{picture}}
\end{document}
```

```latex
\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (-2,0) -- (2,0);
\filldraw [gray] (0,0) circle (2pt);
\draw (-2,-2) .. controls (0,0) .. (2,-2);
\draw (-2,2) .. controls (-1,0) and (1,0) .. (2,2);
\end{tikzpicture}
\end{document}
```

## Refer to a LaTeX content

You can refer to existing LaTeX content. Below are the instructions.

Click on the **Edit** button, and provide a reference name for the LaTeX content.

<figure><img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2FpUdN24Y2hnzRwYg5LBq5%2Fimage.png?alt=media&#x26;token=1025fb36-2f67-441b-bc69-1e29a778c86c" alt=""><figcaption><p>LaTeX for Confluence</p></figcaption></figure>

<figure><img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2FCGC2fKXBQL2XflABwVUc%2Fimage.png?alt=media&#x26;token=2de2c7ef-e100-4817-a485-87ff20a74a41" alt=""><figcaption><p>LaTeX for Confluence</p></figcaption></figure>

Insert the **Render LaTeX Reference** macro.

<figure><img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2Fg6GmbeE0MlEuY3QYsv9r%2Fimage.png?alt=media&#x26;token=3dd23107-75a7-4307-b2b1-69f081bc60b5" alt=""><figcaption><p>LaTeX for Confluence</p></figcaption></figure>

<figure><img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2FtmNy1j0SMcBhq2lHMK4p%2Fimage.png?alt=media&#x26;token=27d5f81b-f0fe-454c-a9eb-a57786d6d741" alt=""><figcaption><p>LaTeX for Confluence</p></figcaption></figure>

<figure><img src="https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ma7ua4NoSptEMaVrDMS%2Fuploads%2FQv1kfq3FhU5EyfLMYNIo%2Fimage.png?alt=media&#x26;token=21349014-bd5d-4d12-8f02-891335e89dc0" alt=""><figcaption><p>LaTeX for Confluence</p></figcaption></figure>

## Write Math in Page Title

For Page Title, inline LaTex must be wrapped inside `//(...//)`  and LaTex block must be wrapped inside `//[...//]`.

![Input](https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ma7ua4NoSptEMaVrDMS%2F-MfHtHk05IbHkqLdCvIK%2F-MfI6v1Or_m0Y5e4FX-k%2Fimage.png?alt=media\&token=6cb95c9f-ad16-4df2-88fa-e5137d855be6)

![Render](https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ma7ua4NoSptEMaVrDMS%2F-MfHtHk05IbHkqLdCvIK%2F-MfI74mjNutYtXF9C-iS%2Fimage.png?alt=media\&token=730e7c6c-09f9-45d9-b560-bc22fd147e01)

## Mobile support

![LaTeX for Confluence](https://3588362646-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ma7ua4NoSptEMaVrDMS%2F-MfN51AZc0yZzOlQALJa%2F-MfN5AkcMV_SKRfgCXjD%2Fconfluence-server-latex-mobile.jpg?alt=media\&token=306d2ebb-3356-489e-a1d4-b51c34869163)
