Coder Social home page Coder Social logo

latexify.jl's Introduction

Build Status Build status codecov Coverage Status

Latexify.jl

This is a package for generating LaTeX maths from julia objects.

This package utilises Julias homoiconicity to convert expressions to LaTeX-formatted strings. Latexify.jl supplies functionalities for converting a range of different Julia objects, including:

  • Expressions,
  • Strings,
  • Numbers (including rationals and complex),
  • Symbolic expressions from SymEngine.jl,
  • ParameterizedFunctions and ReactionNetworks from DifferentialEquations.jl

as well as arrays or dicts of supported types.

Examples

latexifying expressions

using Latexify
ex = :(x/(y+x)^2)
latexify(ex)

This generates a LaTeXString (from LaTeXStrings.jl) which, when printed looks like:

$\frac{x}{\left( y + x \right)^{2}}$

And when this LaTeXString is displayed in an environment which supports the tex/latex MIME type (Jupyter notebooks, Jupyterlab and Hydrogen for Atom) it will automatically render as:

fraction

latexifying other things

Latexify.jl is equipped to convert a whole range of types to latex formatted maths. This includes primitive types such as Symbols and Complex, but also of containers such as Arrays and Dicts.

using Latexify
print(latexify("x+y/(b-2)^2"))

outputs:

$x + \frac{y}{\left( b - 2 \right)^{2}}$
arr = ["x/y" 3//7 2+3im; 1 :P_x :(gamma(3))]
latexify(arr)

matrix

The GitHub website does not really support rendering of equations in the README file, so I therefore refer you to the documentation for more info/examples.

Use with DifferentialEquations.jl

The DifferentialEquations.jl suite has some nifty tools for generating differential equations. One of them is ParameterizedFunctions which allows you to type in an ODE in something which looks very much like just plain mathematics. The ability to latexify such ODEs is pretty much what lured me to create this package.

using DifferentialEquations
using Latexify

f = @ode_def positiveFeedback begin
    dx = v*y^n/(k^n+y^n) - x
    dy = x/(k_2+x) - y
end v n k k_2

latexify(f)

outputs:

positiveFeedback

DiffEqBiological.jl provides another cool domain-specific language which allows you to generate equations using a chemical arrow notation.

using DifferentialEquations
using Latexify

rn = @reaction_network demoNetwork begin
  (r_bind, r_unbind), A + B โ†” C
  Hill(C, v, k, n), 0 --> X
  d_x, X --> 0
end r_bind r_unbind v k n d_x

latexify(rn)

positiveFeedback

Or you can output the arrow notation directly to latex:

latexify(rn; env=:arrow)

positiveFeedback

There are more stuff that you can do, but for that I will refer you to the docs.

Convenience functions

  • copy_to_clipboard(::Bool), toggle automatic copying of the resulting LaTeX code to the clipboard (default is false).
  • auto_display(::Bool) toggles automatic display of your output, even if it is not the last command to have run.

Installation

This package is registered with METADATA.jl, so to install it you can just run

Pkg.add("Latexify")

Further information

For further information see the docs.

Contributing

I would be happy to receive feedback, suggestions, and help with improving this package. Please feel free to open an issue or a PR.

latexify.jl's People

Contributors

korsbo avatar chrisrackauckas avatar goropikari avatar

Watchers

Torkel Loman avatar

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.