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.

  • Do you want the formula to appear as an image or as text? – lgeorget Mar 22 '17 at 10:40
  • Graphically, the rendering of the equation itself. Without opening extra windows, in the terminal. – nightcod3r Mar 22 '17 at 10:44
3

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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.