Skip to main content

Print LaTeX code

Why LaTeX?

Consider the following Sullivan model of a free loop space.

PrintTex.kt
val indeterminateList = listOf(
Indeterminate("a", 2),
Indeterminate("b", 2),
Indeterminate("x", 3),
Indeterminate("y", 3),
Indeterminate("z", 3),
)
val matrixSpace = SparseMatrixSpaceOverRational
val freeDGAlgebra = FreeDGAlgebra.fromMap(matrixSpace, indeterminateList) { (a, b, x, y, z) ->
mapOf(
x to a.pow(2),
y to a * b,
z to b.pow(2),
)
}
val freeLoopSpace = FreeLoopSpace(freeDGAlgebra)

Now you can compute and print the basis of the cohomology by

PrintTex.kt
for (degree in 0..4) {
val basis = freeLoopSpace.cohomology.getBasis(degree)
println("H^$degree(LX) = Q$basis")
}

and this prints

H^0(LX) = Q[[1]]
H^1(LX) = Q[[sa], [sb]]
H^2(LX) = Q[[a], [b], [sasb]]
H^3(LX) = Q[[asb], [sasx], [2 sasy + sbsx], [1/2 sasz + sbsy], [sbsz]]
H^4(LX) = Q[[1/2 asx + xsa], [asy - 1/2 bsx + xsb], [1/2 bsx + ysa], [1/2 asz + ysb], [-1/2 asz + bsy + zsa], [1/2 bsz + zsb], [sasbsx], [sasbsy], [sasbsz]]

But this output is not very readable since

  • sasb can be confused with the product of indeterminates s, a, s and b.
  • Fractions such as 1/2 are hard to read.

By using Printer, you can print a LaTeX code:

PrintTex.kt
val p = Printer(printType = PrintType.TEX, showShift = ShowShift.BAR)
for (degree in 0..4) {
val basis = freeLoopSpace.cohomology.getBasis(degree)
println("H^{$degree}(LX) &= \\Q${basis.map { v -> p(v) }} \\\\")
}
H^{0}(LX) &= \Q[[1]] \\
H^{1}(LX) &= \Q[[\bar{a}], [\bar{b}]] \\
H^{2}(LX) &= \Q[[{a}], [{b}], [\bar{a}\bar{b}]] \\
H^{3}(LX) &= \Q[[{a}\bar{b}], [\bar{a}\bar{x}], [2 \bar{a}\bar{y} + \bar{b}\bar{x}], [\frac{1}{2} \bar{a}\bar{z} + \bar{b}\bar{y}], [\bar{b}\bar{z}]] \\
H^{4}(LX) &= \Q[[\frac{1}{2} {a}\bar{x} + {x}\bar{a}], [{a}\bar{y} - \frac{1}{2} {b}\bar{x} + {x}\bar{b}], [\frac{1}{2} {b}\bar{x} + {y}\bar{a}], [\frac{1}{2} {a}\bar{z} + {y}\bar{b}], [-\frac{1}{2} {a}\bar{z} + {b}\bar{y} + {z}\bar{a}], [\frac{1}{2} {b}\bar{z} + {z}\bar{b}], [\bar{a}\bar{b}\bar{x}], [\bar{a}\bar{b}\bar{y}], [\bar{a}\bar{b}\bar{z}]] \\
Full LaTeX source code
\documentclass{jsarticle}
\newcommand{\Q}{\mathbb Q}
\usepackage{amsmath}
\usepackage{amssymb}
\begin{document}
\begin{align*}
H^{0}(LX) &= \Q[[1]] \\
H^{1}(LX) &= \Q[[\bar{a}], [\bar{b}]] \\
H^{2}(LX) &= \Q[[{a}], [{b}], [\bar{a}\bar{b}]] \\
H^{3}(LX) &= \Q[[{a}\bar{b}], [\bar{a}\bar{x}], [2 \bar{a}\bar{y} + \bar{b}\bar{x}], [\frac{1}{2} \bar{a}\bar{z} + \bar{b}\bar{y}], [\bar{b}\bar{z}]] \\
H^{4}(LX) &= \Q[[\frac{1}{2} {a}\bar{x} + {x}\bar{a}], [{a}\bar{y} - \frac{1}{2} {b}\bar{x} + {x}\bar{b}], [\frac{1}{2} {b}\bar{x} + {y}\bar{a}], [\frac{1}{2} {a}\bar{z} + {y}\bar{b}], [-\frac{1}{2} {a}\bar{z} + {b}\bar{y} + {z}\bar{a}], [\frac{1}{2} {b}\bar{z} + {z}\bar{b}], [\bar{a}\bar{b}\bar{x}], [\bar{a}\bar{b}\bar{y}], [\bar{a}\bar{b}\bar{z}]] \\
\end{align*}
\end{document}

print-latex

Together with the LaTeX package autobreak, line breaks can be added automatically. In the environment autobreak, line breaks in the LaTeX source code are considered as possible candidates for line breaks in the output PDF file. So beforeSign = "\n" and joinToString(",\n") in the following code give such candidates.

PrintTex.kt
val p2 = Printer(printType = PrintType.TEX, beforeSign = "\n", showShift = ShowShift.BAR)
for (degree in 0..6) {
val basis = freeLoopSpace.cohomology.getBasis(degree)
val basisString = basis.joinToString(",\n") { v -> p2(v) }
println("\\begin{autobreak}\nH^{$degree}(LX) = \\Q[\n${basisString}]\n\\end{autobreak}\\\\")
}
Full LaTeX source code
\documentclass{jsarticle}
\newcommand{\Q}{\mathbb Q}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{autobreak}
\begin{document}
\begin{align*}
\begin{autobreak}
H^{0}(LX) = \Q[
[1]]
\end{autobreak}\\
\begin{autobreak}
H^{1}(LX) = \Q[
[\bar{a}],
[\bar{b}]]
\end{autobreak}\\
\begin{autobreak}
H^{2}(LX) = \Q[
[{a}],
[{b}],
[\bar{a}\bar{b}]]
\end{autobreak}\\
% ...
\end{align*}
\end{document}

print-latex