Giter Club home page Giter Club logo

latex2png's Introduction

latex2png

Build Status Checked with mypy

A tiny command-line utility for generating PNG files from LaTeX snippets. The entrypoint is ./latex2png.

$ echo 'Hello! Would you like a slice of $ \pi $?' | l2p

Usage

Let's assume we have the following file:

$ cat res/example.tex-snippet
The best equation is $ e^{i\pi} = -1 $! It uses $ e^{x+iy} = e^x\left(\cos{y} + i\sin{y}\right) $.

This program uses stdin/stdout by default. For example, to write a LaTeX snippet to res/example.png, you could do

$ cat res/example.tex-snippet | ./latex2png > res/example.png

In order to generate this snippet: example.png

It's also useful to pipe this directly to your clipboard. You can do that with

$ cat res/example.tex-snippet | ./latex2png | xclip -selection c -t image/png -i  # Ubuntu
$ cat res/example.tex-snippet | ./latex2png | pbcopy                              # MacOS

To get the most out of this, we could add the following to our .bashrc (on Linux)

l2p() {
    /path/to/latex2png/latex2png "$@" | xclip -selection c -t image/png -i
}

Then we'll be able to get a snippet into our system clipboard with just

$ cat res/example.tex-snippet | l2p

To use filepaths, you can pass -i $input_file and -o $output_file, as in

$ ./latex2png -i res/example.tex-snippet -o res/example.png

For the full API, check

$ ./latex2png --help

Installation

To install on MacOS or Debian-based systems, run

./scripts/install

If you'd like to add support for another operating system, just open an issue or submit a pull request :^).

Troubleshooting

If you have any problems, feel free to file an issue!

latex2png's People

Contributors

keggsmurph21 avatar mhwombat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mhwombat

latex2png's Issues

Publish to pypi

Need to figure out how the ./scripts/install bit would work with pip

Unable to run `convert`

On (at least Ubuntu) machines with a fresh ImageMagick install, it's impossible to convert from PDFs. This is a deliberate security decision, since they can contain arbitrary code. However, it prevents latex2png from working correctly.

To fix this, you can just run this script:

$ ./scripts/enable-imagemagick-permissions

text2latex: More flexible inputs

Instead of specifying --tex-header and --tex-footer, we should just have a TEX_TEMPLATE that we embed the user string into, conditional on a --use-tex-template flag.

Entrypoint: Write some basic documentation for `--help`

Right now, ./latex2png --help outputs

usage: __main__.py [-h] [-i INPUT_FP] [-o OUTPUT_FP] [-v]
                   [--tex-header TEX_HEADER_FP] [--tex-footer TEX_FOOTER_FP]
                   [--png-density PNG_DENSITY] [--png-quality PNG_QUALITY]
                   [--png-background PNG_BACKGROUND]

optional arguments:
  -h, --help            show this help message and exit
  -i INPUT_FP
  -o OUTPUT_FP
  -v, --verbose
  --tex-header TEX_HEADER_FP
  --tex-footer TEX_FOOTER_FP
  --png-density PNG_DENSITY
  --png-quality PNG_QUALITY
  --png-background PNG_BACKGROUND

which isn't very useful...

Better error output

When any of the subprocess.check_output invocations fail, they give really opaque error messages. We should be able to grab the stderr directly from the failed process and show that instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.