
Show HN: Lax – Write Python to output LaTeX - iogf
https://github.com/iogf/lax
======
lucb1e
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.

~~~
cyphar
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).

~~~
thearn4
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.

~~~
joshuamorton
I believe its possible to export ipynbs as markdown/tex.

------
adsche
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...](http://latex.codecogs.com/gif.latex?%5Cfrac%7B%5Csqrt%5B%5Cleft%28%5Cfrac%7Bx-1%7D%7Bx&plus;2%7D%5Cright%29%5D%7B%5Cleft%28x-1%5Cright%29%7D%7D%7By-z&plus;k-e&plus;w%7D)

~~~
iogf
I'm not sure i have fully understood your question, could you rephrase?

~~~
S4M
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}

~~~
iogf
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.

~~~
maxerickson
If you change the meanings of symbols then the description becomes "write lax,
output latex".

------
baldfat
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/](https://docs.racket-
lang.org/scribble/)

~~~
cedex12
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…

~~~
baldfat
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.

------
iogf
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](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.

------
therealmarv
This "pythonic" way looks for me like AsciiMath

[http://asciimath.org/](http://asciimath.org/)

Shameless plug... if you want to convert from AsciiMath to LaTeX here is
something I've written (it's not beautiful and works only online, but it was a
showcase only):

[https://github.com/oerpub/mathconverter](https://github.com/oerpub/mathconverter)

------
stared
Title should be more like "convert fractions to LaTeX using Python". Otherwise
it's misleading/overadvertising.

------
edwinksl
Related:
[https://github.com/JelteF/PyLaTeX](https://github.com/JelteF/PyLaTeX), which
is a "Python library for creating LaTeX files".

------
n4r9
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](http://doc.sagemath.org/html/en/tutorial/sagetex.html)

------
jmmcd
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](http://docs.sympy.org/latest/tutorial/printing.html#latex)

~~~
iogf
Interesting, i wasn't aware of that.However one of the goals of Lax is being
extensible through python easily and being simplistic, one could define their
own common latex structures in python then reuse it.

~~~
jakeogh
inversely:
[https://github.com/augustt198/latex2sympy](https://github.com/augustt198/latex2sympy)
[https://github.com/sympy/sympy/issues/5418](https://github.com/sympy/sympy/issues/5418)

------
denfromufa
PyLatex looks much more advanced:
[https://jeltef.github.io/PyLaTeX/current/examples/numpy_ex.h...](https://jeltef.github.io/PyLaTeX/current/examples/numpy_ex.html)

~~~
iogf
I don't think pylatex does what lax does i'm not sure though. Try getting
latex output from pylatex for formulaes like x * 3 * y * (x/(x-y)). Lax goal
is being handy for quickly writing down common math formulaes.

------
amelius
I wonder how it deals with code that depends on variables that are known only
at run time.

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

~~~
therealmarv
you should check out AsciiMath ...
[http://asciimath.org](http://asciimath.org) It's one of the easiest ways of
writing math and already pretty complete.

------
isatty
why tho

~~~
techdragon
Not everyone wants to learn another formatting language.

~~~
shawnz
So the solution is to create a new one?

~~~
posterboy
Using common ascii notation of basic maths it's hardly new in any surprising
way.

