Skip to content
Snippets Groups Projects
Commit b5c6051b authored by dgelessus's avatar dgelessus
Browse files

Render table contents as LaTeX

This also fixes problems with vertical bars (for example in |->) not
being escaped in tables.
parent f536ce93
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` prob
:help :table
```
%% Output
```
:table EXPRESSION
```
Display an expression as a table.
Although any expression is accepted, this command is most useful for sets of tuples.
```
:table EXPRESSION
```
Display an expression as a table.
Although any expression is accepted, this command is most useful for sets of tuples.
%% Cell type:code id: tags:
``` prob
:init
```
%% Output
Machine initialised using operation 0: $initialise_machine()
%% Cell type:code id: tags:
``` prob
:table {1, 2, 3, 4}
```
%% Output
|Nr|Elements|
|Elements|
|---|
|$1$|
|$2$|
|$3$|
|$4$|
Elements
1
2
3
4
%% Cell type:code id: tags:
``` prob
:table [1, 2, 3, 4]
```
%% Output
|prj1|prj2|
|---|---|
|1|1|
|2|2|
|3|3|
|4|4|
Nr Elements
|$1$|$1$|
|$2$|$2$|
|$3$|$3$|
|$4$|$4$|
prj1 prj2
1 1
2 2
3 3
4 4
%% Cell type:code id: tags:
``` prob
:table [1, 2, 3, 4]
:table {(1, 2, 3), (4, 5, 6), (7, 8, 9)}
```
%% Output
|Nr|prj1|prj2|
|prj11|prj12|prj2|
|---|---|---|
|1|1|1|
|2|2|2|
|3|3|3|
|4|4|4|
Nr prj1 prj2
1 1 1
2 2 2
3 3 3
4 4 4
|$1$|$2$|$3$|
|$4$|$5$|$6$|
|$7$|$8$|$9$|
prj11 prj12 prj2
1 2 3
4 5 6
7 8 9
%% Cell type:code id: tags:
``` prob
:table {(1, 2, 3), (4, 5, 6), (7, 8, 9)}
:table {({}, {})}
```
%% Output
|Nr|prj11|prj12|prj2|
|---|---|---|---|
|1|1|2|3|
|2|4|5|6|
|3|7|8|9|
Nr prj11 prj12 prj2
1 1 2 3
2 4 5 6
3 7 8 9
|prj1|prj2|
|---|---|
|$\renewcommand{\emptyset}{\mathord\varnothing}\renewcommand{\emptyset}{\mathord\varnothing}\emptyset$|$\emptyset$|
prj1 prj2
{} {}
%% Cell type:code id: tags:
``` prob
:table {({}, {})}
:table {({1|->2, 3|->4}, {5|->6, 7|->8}), ({2|->1, 4|->3}, {6|->5, 8|->7})}
```
%% Output
|Nr|prj1|prj2|
|---|---|---|
|1|{}|{}|
Nr prj1 prj2
1 {} {}
|prj1|prj2|
|---|---|
|$\{(1\mapsto 2),(3\mapsto 4)\}$|$\{(5\mapsto 6),(7\mapsto 8)\}$|
|$\{(2\mapsto 1),(4\mapsto 3)\}$|$\{(6\mapsto 5),(8\mapsto 7)\}$|
prj1 prj2
{(1|->2),(3|->4)} {(5|->6),(7|->8)}
{(2|->1),(4|->3)} {(6|->5),(8|->7)}
......
......@@ -2,6 +2,7 @@ package de.prob2.jupyter.commands;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import com.google.inject.Inject;
......@@ -13,6 +14,7 @@ import de.prob.animator.domainobjects.IEvalElement;
import de.prob.animator.domainobjects.TableData;
import de.prob.statespace.AnimationSelector;
import de.prob.statespace.Trace;
import de.prob.unicode.UnicodeTranslator;
import io.github.spencerpark.jupyter.kernel.ReplacementOptions;
import io.github.spencerpark.jupyter.kernel.display.DisplayData;
......@@ -76,7 +78,7 @@ public final class TableCommand implements Command {
sbPlain.append(String.join("\t", row));
sbPlain.append('\n');
sbMarkdown.append('|');
sbMarkdown.append(String.join("|", row));
sbMarkdown.append(row.stream().map(s -> '$' + UnicodeTranslator.toLatex(s) + '$').collect(Collectors.joining("|")));
sbMarkdown.append("|\n");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment