In two recent questions

dnaviaux raised concerns about saving informations he could include in a typeset report.

In the first question these informations were mainly **printf **terminal outputs, while the second question was oriented to informations of type **Table** (in the sense of **DocumentTools:-Layout:-Table**).

Acer has given a direct answer to this last question.

On my side I proposed a less direct one based on a **LaTeX**approach.

Since several years I use to generate a **LaTeX** source code for typeset reports directly from **Maple **(this is not very difficult once you know **LaTeX**).

These reports often contain data tables **M**but **latex(M)**is not the good way to code these data tables into **LaTeX**.

That is why I turned towards the **LaTeX/tabular**structure

\begin{tabular}{...}
...
\end{tabular]

Data tables are very simple structures and converting them programmatically from **Maple Matrix** into **LaTeX tabular** is rather simple: the most important thing you must remember is that some characters have a special role in LaTeX (for instance "\" , "_" and "$") while having a special meaning in **Maple **too: so beware of conflicts.

The procedure **Tabular** in the attached file takes as argument a **Matrix** and returns the **LaTeX** code of its **tabular** counterpart.

Note that it could be easily extendend to accept a **DataFrame**as input.

This is a very simple simple version and fonts (\rm, \bf, \it... or others), styles (\scriptsize, \large, ...) and much more customization features could be accounted for without any difficulty.

For this particular example inspired by dnaviaux first question, it would be probably better to replace the LaTeX code by one of thes two:

\begin{tabular}{|c @{ $\pm$ } c|}
....
Asdfsdg & +5.190e+01 & 2.5950e+00 \\

or :

\begin{tabular}{|c|c|}
....
Asdfsdg & \multicolumn{2}{c|}{$+8.680e-01 \pm 0.9190$} \\

dnaviaux second question concerned a **DocumentTools:-Layout:-Table **object.

For what I understood this table has a simple structure (no **rowspan** neither **columnspan** used).

But, knowing that **tabular **can manage merged columns (**\multicolumn**) and merged rows (**\multirow**, provided the ad hoc pasckage is used), I wondered if it would be possible to generate the **LaTeX/tabular** code corresponding to a **Table** using **rowspan** and **columnspan**?

This is done by the procedure **Tabular_Table** in the attached file.

Here again this is a very simple procedure which doesn't exploit all the informations a **Table** structure contains (**backgroundstyle**, **fillcolor**, **align**, **alignment**, **separator** [**Tabular_Table** separates all columns and rows] ...).

The "raw" rendering is not bad but could be improved:

- adjust the way
**\multirow**centers the content of a cell (**X**is badly placed in example 3)
- adjust the spaces between
**line/cline**and the text
- by using the package
**cellspace**
- or my modufying
**\arraystretch **with **\renewcommand**.

- one could also add a legend with
** \caption**
- parameterize
**Tabular_Table** to accept other column separators
- manage the colors (for instance a blue for a math expression and a black for a text)
- ...

Finally **Tabular**and **Tabular_Table**could have an optional argument **file**:

{file::{symbol, string}:= terminal}

set by default to **terminal**or wich could be the name of a **.tex**file

**This work is still under developpement and I would be happy to exchange with you on this topic.**

Happy New Year to all of you

Tabular_from_Maple.mw

Here is the content of the .tex file (I used Welcome-to-CoCalc.texto create/compile it)

\documentclass{article}
% set font encoding for PDFLaTeX, XeLaTeX, or LuaTeX
\usepackage{ifxetex,ifluatex}
\if\ifxetex T\else\ifluatex T\else F\fi\fi T%
\usepackage{fontspec}
\else
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\fi
\usepackage{hyperref}
% DO NOT FORGET THIS PACKAGE !!!
\usepackage{multirow}
\title{Tabulars from Maple}
\author{mmcdara}
\begin{document}
\maketitle
\begin{itemize}
\item[\bf{Example 1}]
\begin{tabular}{|c|c|c|}
\hline
\hline
Quantity & Nominal value & Uncertainty \\
\hline
Asdfsdg & +9.060e+01 & 4.5298e+00 \\
\hline
Bdfg & +1.437e+01 & 7.1870e-01 \\
\hline
C123 & +8.025e+01 & 4.0125e+00 \\
\hline
Ddf sdfg dsfg & +9.614e+00 & 4.8072e-01 \\
\hline
\hline
\end{tabular}
\item[]\vspace*{10mm}
\item[\bf{Example 3}]
\begin{tabular}{| c | c | c | c | c |}
\hline
\multicolumn{1}{|c|}{\multirow{4}{*}{X}} & \multicolumn{2}{c|}{\multirow{1}{*}{A1}} & \multicolumn{1}{c|}{\multirow{2}{*}{A2}} & \multicolumn{1}{c|}{\multirow{1}{*}{A3}} \\
\cline{2-2}
\cline{3-3}
\cline{5-5}
& \multicolumn{1}{c|}{\multirow{2}{*}{B1}} &\multicolumn{1}{c|}{\multirow{1}{*}{B2}} & & \multicolumn{1}{c|}{\multirow{3}{*}{B3}} \\
\cline{3-3}
\cline{4-4}
& & \multicolumn{2}{c|}{${\cos \left( \omega\,t+\phi \right) }^{\mathstrut}_{\atop{}{\mathstrut}}$} & \\
\cline{2-2}
\cline{3-3}
\cline{4-4}
& \multicolumn{3}{c|}{${{\frac {1}{\Gamma \left( x \right) }\sqrt {{{\rm e}^{-{\frac {{t}^{2}}{\pi }}}}}}}^{\mathstrut}_{\atop{}{\mathstrut}}$} & \\
\hline
\end{tabular}
\end{itemize}
\end{document}

Image of the resulting **PDF**:

For comparison here is the **Table**of **Example 3 **that **Maple**displays in the worksheet