5 ms·
Show HN: Lax – Write Python to output LaTeX
- isatty 9y agowhy tho
- techdragon 9y agoNot everyone wants to learn another formatting language.
- majewsky 9y agoLaw of leaky abstractions, though.
- shawnz 9y agoSo the solution is to create a new one?
- posterboy 9y agoUsing common ascii notation of basic maths it's hardly new in any surprising way.
- dragonwriter 9y agoWhich 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/ http://unicode.org/notes/tn28/
- amelius 9y agoI wonder how it deals with code that depends on variables that are known only at run time.
- adsche 9y agoInteresting. 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%5Cleft%28%5Cfrac%7Bx-1%7D%7Bx+2%7D%5Cright%29%5D%7B%5Cleft%28x-1%5Cright%29%7D%7D%7By-z+k-e+w%7D http://latex.codecogs.com/gif.latex?%5Cfrac%7B%5Csqrt%5B%5Cl...
- iogf 9y agoI'm not sure i have fully understood your question, could you rephrase?
- S4M 9y agoA 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 9y agoThe 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 9y agoIf you change the meanings of symbols then the description becomes "write lax, output latex".
- edwinksl 9y agoRelated: https://github.com/JelteF/PyLaTeX https://github.com/JelteF/PyLaTeX, which is a "Python library for creating LaTeX files".
- iogf 9y agoThe 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 9y agoyou should check out AsciiMath ... http://asciimath.org http://asciimath.org It's one of the easiest ways of writing math and already pretty complete.
- jmmcd 9y agoI 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 9y agoInteresting, 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 9y agoinversely: https://github.com/augustt198/latex2sympy https://github.com/augustt198/latex2sympy https://github.com/sympy/sympy/issues/5418 https://github.com/sympy/sympy/issues/5418
- williamstein 9y agoLikewise, 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.
- therealmarv 9y agoThis "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
- iogf 9y agoMy 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.
- lucb1e 9y agoThe 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 9y agoI 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 9y agoI 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 9y agoI believe its possible to export ipynbs as markdown/tex.
- Rick_Sullivan 9y agoPyLaTeX does that: with doc.create(Section('A section')): doc.append('Some regular text and some ') doc.append(italic('italic text. ')) https://github.com/JelteF/PyLaTeX https://github.com/JelteF/PyLaTeX
- baldfat 9y agoI 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 9y agoVery 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 9y agoWell 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.
- JadeNB 9y agoDo you know how it relates to Skribilo (http://www.nongnu.org/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.)
- n4r9 9y agoIf 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
- stared 9y agoTitle should be more like "convert fractions to LaTeX using Python". Otherwise it's misleading/overadvertising.
- denfromufa 9y agoPyLatex looks much more advanced: https://jeltef.github.io/PyLaTeX/current/examples/numpy_ex.html https://jeltef.github.io/PyLaTeX/current/examples/numpy_ex.h...
- iogf 9y agoI 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.
- deleted 9y ago[deleted]
- deleted 9y ago[deleted]