2

Is there any way to show a graphic Latex expression in a (textual) terminal? Particularly, can an LXTerminal show the rendering of a Latex equation? Alternatively, is there any terminal emulator that allows it?

Note: This question is posted here because the problem focuses on the terminal itself, not on the rendering process.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
nightcod3r
  • 952
  • 2
  • 16
  • 32

1 Answers1

5

Terminology is the way to go to display images in terminal emulators. In ttys, the framebuffer is available too.

tex2im provides a nice solution to convert formulas as images but has drawbacks which may be problematic depending on your usecase. It puts an out.png file in your current directory, accept only math, etc.

Here is a similar but somewhat more customizable approach:

#!/bin/sh

dir=$(mktemp -d) || exit 1

cd $dir
cat <<EOF > file.tex
\\documentclass[varwidth=true,border=5pt]{standalone}
\\begin{document}
$1
\\end{document}
EOF

texfot --quiet --interactive  pdflatex -shell-escape file.tex && \
convert -density 600 file.pdf -quality 90 -background white -alpha off -resize 50% file.png && \
tycat $dir/file.png && \
sleep 0.5
rm -r $dir

It uses the package standalone to produce a PDF the right size and then convert it with ImageMagick. Actually, standalone can handle the transformation but do not allow all the options ImageMagick accepts.

All the file are created in a temporary directory. It's necessary to wait a little before removing it in order not to race with tycat which displays the picture in the terminal.

Example of use: Example of use of the script

lgeorget
  • 13,656
  • 2
  • 41
  • 63
  • It is worth noting that this solution demands installation of `imagemagick`, `texlive-latex-extra`, `texlive-extra-utils`. `tex2im`, in principle, did not demand additional stuff for a fresh Lubuntu installation. – nightcod3r Mar 25 '17 at 14:48