GithubHelp home page GithubHelp logo

korsbo / latexstrings.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from juliastrings/latexstrings.jl

0.0 2.0 0.0 46 KB

convenient input and display of LaTeX equation strings for the Julia language

License: MIT License

Julia 100.00%

latexstrings.jl's Introduction

Build Status

LaTeXStrings

This is a small package to make it easier to type LaTeX equations in string literals in the Julia language, written by Steven G. Johnson.

With ordinary strings in Julia, to enter a string literal with embedded LaTeX equations you need to manually escape all backslashes and dollar signs: for example, $\alpha^2$ is written \$\\alpha^2\$. Also, even though IJulia is capable of displaying formatted LaTeX equations (via MathJax), an ordinary string will not exploit this. Therefore, the LaTeXStrings package defines:

  • A LaTeXString class (a subtype of String), which works like a string (for indexing, conversion, etcetera), but automatically displays as text/latex in IJulia.

  • L"..." and L"""...""" string macros which allow you to enter LaTeX equations without escaping backslashes and dollar signs (and which add the dollar signs for you if you omit them).

Usage

After installing LaTeXStrings with Pkg.add("LaTeXStrings") in Julia, run

using LaTeXStrings

to load the package. At this point, you can construct LaTeXString literals with the constructor L"..." (and L"""...""" for multi-line strings); for example L"1 + \alpha^2" or L"an equation: $1 + \alpha^2$". (Note that $ is added automatically around your string, i.e. the string is interpreted as an equation, if you do not include $ yourself.)

If you want to perform string interpolation (inserting the values of other variables into your string), use %$ instead of the plain $ that you would use for interpolation in ordinary Julia strings. For example, if x=3 is a Julia variable, then L"y = %$x" will produce L"y = 3".

You can also use the lower-level constructor latexstring(args...), which works much like string(args...) except that it produces a LaTeXString result and automatically puts $ at the beginning and end of the string if an unescaped $ is not already present. Note that with latexstring(...) you do have to escape $ and \: for example, latexstring("an equation: \$1 + \\alpha^2\$").
Note that you can supply multiple arguments (of any types) to latexstring, which are converted to strings and concatenated as in the string(...) function.

Finally, you can use the lowest-level constructor LaTeXString(s). The only advantage of this is that it does not automatically put $ at the beginning and end of the string. So, if for some reason you want to use text/latex display of ordinary text (with no equations or formatting), you can use this constructor. (Note that IJulia only formats LaTeX equations; other LaTeX text-formatting commands like \emph are ignored.)

Author

This package was written by Steven G. Johnson, and is distributed under the MIT/expat license (see the LICENSE.md file).

latexstrings.jl's People

Contributors

carstenbauer avatar chrisrackauckas avatar fredrikekre avatar gustaphe avatar juliatagbot avatar malmaud avatar quinnj avatar sacha0 avatar sglyon avatar simeonschaub avatar stevengj avatar stillyslalom avatar tkelman avatar yuyichao avatar

Watchers

 avatar  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.