36 comments

[ 3.0 ms ] story [ 83.9 ms ] thread
why tho
Not everyone wants to learn another formatting language.
Law of leaky abstractions, though.
So the solution is to create a new one?
Using common ascii notation of basic maths it's hardly new in any surprising way.
Which is why it would be great if more things generating formatted mathematical output accepted UnicodeMath [0], which is about as minimal a formatting language as possible (and, as a result, maximally readable as plain text.)

Unfortunately, I don't know anything that uses it besides Microsoft's formula editors (in various Office apps.)

[0] http://unicode.org/notes/tn28/

I wonder how it deals with code that depends on variables that are known only at run time.
Interesting. Quick question though:

    tau@eletron:~$ lax -c '((x-1) ** ((x-1)/(x+2)))/(y-z+k-e+w)'
    \frac{\sqrt[\left(\frac{x-1}{x+2}\right)]{\left(x-1\right)}}{y-z+k-e+w}
That does not make sense to me. Why do you use a root here? A root with that long of a degree just looks weird to me [1].

And even if, does the degree of the root not have to be inverted? I.e.:

    x**(y/z) == \sqrt[z/y]{x}

[1] http://latex.codecogs.com/gif.latex?%5Cfrac%7B%5Csqrt%5B%5Cl...
I'm not sure i have fully understood your question, could you rephrase?
A simpler example:

    $ lax -c 'x ** 2'
    \sqrt[2]{x}
While the output should be:

    x^2.
If you wanted to use sqrt, it would have to be:

    \sqrt[\frac{1}{2}]{x}
The output for x 2 was chosen to print out \sqrt because it is possible to have x ^2 in python whose output would be x ^ 2 as expected. The idea is using to print long sqrt so advantaging this behavior. Although i haven't implemented x^2 planning to do it next week with the new improvements.
If you change the meanings of symbols then the description becomes "write lax, output latex".
The main idea consists of implementing sort of a "latex-like" templating system using python. Lax goal is similar to what markdown is for html.
I think Sympy's latex solution is probably more complete, but of course it requires a bigger install (but Sympy is already in Anaconda).

Their example:

    >>> print(latex(Integral(sqrt(1/x), x)))
    \int \sqrt{\frac{1}{x}}\, dx
http://docs.sympy.org/latest/tutorial/printing.html#latex
Likewise, in SageMath you can turn any expression obj (matrices, fractions, elliptic curves, etc.) into latex by typing `latex(obj)`. (Disclaimer: I started SageMath and wrote a lot of this conversion to latex functionality early on, since it's useful for notebook interfaces.) Most objects in Sage have an _latex_ method, and the latex function works by recursively calling those methods to build a big latex expression. SageTex -- which lets you embed Python code in LaTeX documents -- also uses this latex(obj) functionality.
My next plan is extending Lax with a basic set of latex structures and integrating with vy. (This was one of the goals behind Lax)

https://github.com/iogf/vy

I believe some other editors like emacs/vim could integrate with it so people could easily ease the effort for writing some latex structures.

The title suggests you can write Python and get LaTeX, but it's "converting ordinary expressions into mathTeX". I was expecting something like this:

    def section(name='Abstract'):
      print('We present a novel new way...')
      fig(path='my.png', width='90%')
Anyway, still a cool project! I might make use of this in the future. Just remarking that the title hints at something else -- at least to me.
I feel that (as much as I personally don't like them) IPython notebooks would solve this niche pretty well (though currently you still need a separate LaTeX document).
I do feel like there is a middle ground somewhere there between the "format all content to fit A4 paper" idiom of Word/TeX, and the more interactive markdown + simulation environment of Jupyter. The latter is really growing on me, but conferences really still want their paper articles and pdf/pptx slide decks.
I believe its possible to export ipynbs as markdown/tex.
I am really hopeful for Scribble from Racket as a Latex replacement.

> Scribble is a collection of tools for creating prose documents—papers, books, library documentation, etc.—in HTML or PDF (via Latex) form. More generally, Scribble helps you write programs that are rich in textual content, whether the content is prose to be typeset or any other form of text to be generated programmatically.

https://docs.racket-lang.org/scribble/

Very interesting. I'd be interested in seeing what an alternative to latex based on S-expressions would look like. I'm tempted to try and write it first as a scheme library; the end goal would be to have something more structured and closer to a programming language than latex, with a better content/styling separation…
Well Racket doesn't get more scheme like besides well Scheme :) Personally I find Racket to be my favorite Programming Language due to the Lisp and Schemeness.
Do you know how it relates to Skribilo (http://www.nongnu.org/skribilo)? I think that they are both derived from Skribe, but I got the impression that Scribble is more oriented towards documentation, whereas Skribilo is intended more as a general-purpose markup language. Maybe that distinction is specious. (I've been dying to try Skribilo as a properly programmable LaTeX alternative, but I can't manage to install it.)
If this interests you, there's also Sagetex [0]. Sagemath is a fully fledged computer algebra system based on Python; Sagetex is a Latex package that allows you to perform Sagemath computations and auto-generate Latex code while compiling the Latex document.

0. http://doc.sagemath.org/html/en/tutorial/sagetex.html

Title should be more like "convert fractions to LaTeX using Python". Otherwise it's misleading/overadvertising.
(comment deleted)
(comment deleted)