LabPlot/LaTeXTypesetting

From KDE UserBase Wiki
Revision as of 13:23, 23 January 2024 by Hmohona (talk | contribs) (create LaTeX typesetting page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

LaTeX Typesetting

Besides rich text formatting, LabPlot supports LaTeX typesetting in different areas of the application like in text labels, plot title, axis title, etc. In case the LaTeX environment is available on the system (more about the prerequisites below), the user can switch between the LaTeX and rich-text typesettings in the text fields for objects that support this.

In LaTeX mode when entering text in the text field, LabPlot automatically adds a mathematical environment, if not available yet. The user can simply start typing the mathematical expression which will be rendered correctly or, e.g. when combining with text, explicitly specify at which position the mathematical environment has to be used. LabPlot will add the proper header and footer. Following examples are valid inputs:

  • \sum
  • $\sum$
  • \begin{displaymath}
\sum 
\end{displaymath}
  • summation symbol $\sum$

Furthermore, it is possible to provide a complete LaTeX document:

\documentclass{...}
\begin{document}
...
\end{document}

With this, it is possible to use user-specific header and footer and to include additional packages that are not included by LabPlot on default. This allows to use texts and graphics of arbitrary complexity supported by LaTeX.

Default rendering engine is, if available, pdflatex. In application settings dialog (Settings > Configure LabPlot) it is possible to choose between other available rendering engines like latex, pdflatex, xelatex, or lualatex.

To modify the appearance of the rendered text, the user can specify the font size and color. For engines that support OpenType and TrueType fonts (xelatex and lualatex) it is also possible to provide the main font.

Prerequisites:

To render the text set using LaTeX syntax, LabPlot relies on the existence of a LaTeX environment. The rendered document is converted to a PNG image that is imported into and shown in LabPlot. The conversion process depends on the rendering engine used:

  • When using latex, the produced DVI file is converted first to a PostScript file with the help of dvips. The intermediate PostScript file is converted after that to a PNG file using convert from the ImageMagick package.
  • For rendering engines producing a PDF file (pdflatex, xelatex, and lualatex), the result PDF file is directly converted to a PNG file with convert.

In case no LaTeX installation is found on the system or one of the required tools for the conversion to PNG is missing, LaTeX typesetting is disabled. On Unix/Linux, the required packages are installed via the package manager. The Windows installer for LabPlot and the Mac OS X dmg-bundle include already convert - everything else has to be installed by the user on the system prior to using this typesetting mode in LabPlot.

When opening a LabPlot project file already containing LaTeX rendered text on systems with no LaTeX typesetting enabled (because of missing prerequisites), the rendered image is correctly shown but no editing is possible - the user still can switch to the rich-text format mode instead and modify the text.

Note about the technical implementation:

The text provided by the user is enriched with an appropriate header and footer to obtain a valid and complete LaTeX document that is processed, as described above, by the rendering engine.

The overall structure of the document generated by LabPlot is:

\documentclass{minimal}
\usepackage{color}
\usepackage[active,displaymath,textmath,tightpage]{preview}
\usepackage{mathtools}
\definecolor{fontcolor}{rgb}{red, green, blue}

%% for xelatex and lualatex engines only
\usepackage{xltxtra}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont[Mapping=tex-text]{font family}
%%

\begin{document}
\begin{preview}
\fontsize{font size}{font size}
\selectfont
\color{fontcolor}

...

\end{preview}
\end{document}

Here, "red", "green", and "blue" are the font colors provided by the user, "font family" is the OpenType or TrueType font family for the main document font (relevant for xelatex and lualatex only), and "font size" is the size of the font to be used. The text entered by the user, shown as "..." in the listing above, is wrapped into a preview-environment to render the document in a minimal possible size.

In case a complete LaTeX document is provided, LabPlot merges the definitions of the user's header and footer with the definitions shown in the above listing.