Skip to content

flintstone1409/LaTeX-to-png

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LaTeX-to-png

Export LaTeX equations to PNGs.

This runs on macOS and probably on Linux (haven't tested).

What is this?

For what?

For some subjects at university I find it the easiest to learn using learning cards, which I want to have in a digital form (to always have them with me and be able to learn whenever I have some minutes spare). As most of these apps don't support Latex by themselves (thank you Studydrive for not implementing this after telling me a year ago you're working on this), I export formulas or whatever I need to write as an image and crop it. This script does this automatically for you, so you just need a .tex file that compiles to the text you want.

(As I don't want to publish my latex template, you might want to take a look at this for a document containing only your text)

What does this script do?

The script compiles your LaTeX-Code to pdf, crops the pdf and renders it into an image. The image and LaTeX sourcecode will be exported into your output folder, see Configure.

(Yes, your sourcecode will be copied so if you need to change something later you don't need to write everything from scratch).

How to use

bash

Make the script executable

chmod +x build.sh

Use the script

./build.sh <output_name>

VS Code

Using Run tasks (default keyboard shortcut: shift + cmd + R) you can run this script from inside VS Code. You will then be prompted to enter a destination file name.

Installation

You need the following tools to be installed:

  • TexLive for pdflatex and pdfcrop
  • poppler-utils for pdftoppm

TexLive

macOS using homebrew:

brew cask install mactex

or without bundled apps

brew cask install mactex-no-gui

Linux:

sudo apt install texlive-full

Of course you can use smaller installations but these installations should contain everything you will ever use, so it causes the least problems while compiling. In the end it's up to you how much you want to install.

poppler-utils

macOS:

brew install poppler

Linux (at least Ubuntu):

sudo apt update
sudo apt upgrade -y
sudo apt install poppler-utils -y

Configure

Configuration is done inside the script.

You have the following options:

  • Set the output folder (make sure it exists)
  • change the dpi (default is 3000 to get high-res images even with small fomulas)
  • Set a output file for pdflatex console output (default is /dev/null)

Contribute

I'd be happy to see the following improvements:

  • Confirmation this works fine on Linux
  • Instructions to use this on Windows
  • Instructions to execute this script as run option in VS Code

If you have anything else, just contact me (e.g. by opening an issue), although for now this works for me as I need it.

Releases

No releases published

Packages

No packages published

Languages