|
| 1 | +# LaTeX tool |
| 2 | + |
| 3 | +Using the LaTeX tool you can insert LaTeX formulas into a Xournal++ document. In order to use this tool you must have LaTeX installed on your system. |
| 4 | +The feature needs to be able to call pdflatex. In addition, the LaTeX `standalone` package needs to be installed, which typically requires installation of `texlive-latex-extra` or `texlive-standalone`. On Ubuntu or similar Linux systems this means |
| 5 | + |
| 6 | +`sudo apt-get install texlive-latex-extra` |
| 7 | + |
| 8 | +For other operating systems you will need to consult your LaTeX installation manual on how to add the standalone LaTeX package. |
| 9 | + |
| 10 | +## Basic LaTeX formulas |
| 11 | + |
| 12 | +Clicking on the LaTeX button in the toolbar will bring up a dialog which will allow you to type in a formula. A preview will be displayed in the center of the dialog, which will keep updating as you type and indicate whether your formula is valid. Once you are done, you can click the OK button to insert the LaTeX into the document; the rendered formula will appear at the center of the current page. The formula can be selected, moved scaled and edited as desired. |
| 13 | + |
| 14 | +Note that the LaTeX formula will always be set in *inline math mode*. If you want to exit math mode, you should write a $-sign to leave math mode and add another $-sign at the end to reenter math-mode. For instance the LaTeX formula |
| 15 | + |
| 16 | +```tex |
| 17 | +$\huge$ x^2 |
| 18 | +``` |
| 19 | + |
| 20 | +will use the command `\huge` to increase the font size, which cannot be done in math mode. |
| 21 | + |
| 22 | +## Enhanced LaTeX tool in Xournal++ 1.1.0+dev |
| 23 | + |
| 24 | +The LaTeX tool has recently been extended making it much more configurable. Most importantly a customizable template has been implemented, where you can load packages and define macros. Moreover a LaTeX settings panel has been added, where you choose the template, specify the LaTeX generation command and test your LaTeX configuration. The extension is only available in version 1.1.0+dev. |
| 25 | + |
| 26 | +## Customization of the template |
| 27 | + |
| 28 | +A default LaTeX template is provided under the name `default_template.tex`. By default it is pre-selected in the LaTeX settings panel. Clicking on it, you will find its location in your file system. On Linux systems it will typically be stored in |
| 29 | +`/usr/share/xournalpp/resources`. |
| 30 | + |
| 31 | +To generate a custom LaTeX template, make a copy of the default template, save it under a different name and start customizing it by adding packages and macros. Some suggestions are listed here: |
| 32 | + |
| 33 | +- Include the [**graphicx** package](https://ctan.org/pkg/graphicx) by adding `\usepackage{graphicx}` to your template file. As an example this will give you the possibility to add rotated text via a LaTeX formula like |
| 34 | + |
| 35 | +```tex |
| 36 | +\text{\rotatebox[origin=c]{90}{My Rotated Text}} |
| 37 | +``` |
| 38 | + |
| 39 | +- Include the [**TikZ** package](https://www.ctan.org/pkg/pgf) via `\usepackage{tikz}` for creating drawings with the powerful TikZ tool. A simple example would be to draw a table (or grid) with n rows and m columns via `\tikz{\draw (0,0) grid(m,n)}`. See [this issue](https://github.com/xournalpp/xournalpp/issues/2179) for more information. |
| 40 | + |
| 41 | +- Include the [**PGFPlots** package](https://www.ctan.org/pkg/pgfplots) via `\usepackage{pgfplots}` for plotting function graphs. Using a macro you will be able to plot function graphs nicely and very quickly. For example, add the following lines to your template: |
| 42 | + |
| 43 | +```teX |
| 44 | +%for defining commands |
| 45 | +\usepackage{xargs} |
| 46 | +
|
| 47 | +% for drawing and plotting |
| 48 | +\usepackage{pgfplots} |
| 49 | +\pgfplotsset{compat=newest} % Allows to place the legend below plot |
| 50 | +\newcommandx{\graph}[3][1=,2=]{ |
| 51 | + \begin{tikzpicture} |
| 52 | + \begin{axis}[xlabel=$x$,ylabel=$y$, axis lines=center,samples=100, #2] |
| 53 | + \addplot[#1]{#3}; |
| 54 | + \end{axis} |
| 55 | + \end{tikzpicture} |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +Then a LaTeX-formula like `\graph{x^2}` will plot the normal parabola and `\graph[domain=-2:2, blue][x=1cm,y=1cm]{x^2}` will further restrict the domain, set the color and define units. |
| 60 | + |
| 61 | +- Include the [**Listings** package](https://www.ctan.org/pkg/listings) via `\usepackage{listings}` for proper alignment and syntax coloring of code snippets. You need to define the style with `lstset` as in the following example, which you can add to your template: |
| 62 | + |
| 63 | +```tex |
| 64 | +\usepackage{listings} |
| 65 | +\lstset{language=C++, |
| 66 | + basicstyle=\ttfamily, |
| 67 | + keywordstyle=\color{blue}\ttfamily, |
| 68 | + stringstyle=\color{red}\ttfamily, |
| 69 | + commentstyle=\color{green}\ttfamily, |
| 70 | + morecomment=[l][\color{magenta}]{\#} |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +In the LaTeX formula you can then use the `lstlistings` enivronment as in the following example |
| 75 | + |
| 76 | +```tex |
| 77 | +\begin{lstlisting} |
| 78 | +#include<stdio.h> |
| 79 | +#include<iostream> |
| 80 | +// A comment |
| 81 | +int main(void) |
| 82 | +{ |
| 83 | + printf("Hello World\n"); |
| 84 | + return 0; |
| 85 | +} |
| 86 | +\end{lstlisting} |
| 87 | +``` |
| 88 | + |
0 commit comments