reddit / emacs

Best packages for structural editing?

cuntymccuntlicker · 2022-11-25 02:43
I typeset math a lot in latex and im getting tired of distributing/leibniz'ing terms around. I wrote a pretty crappy package for sending some stuff to mathematica and inserting them into the document but this is not enough. Ideally, i would use mathematica as the last processing step, and use something more interactive to expand/distribute/factor terms. ​ My idea is to use Wisent to write a simple latex parser that can output the AST in lisp form, then modify it with structural editing in place, and finally have the lisp execute to print out automatically formatted latex code + any processing I may want to do with mathematica/sympy. Ofc, a big part of this plan depends on being able to modify the lisp code easily. Probably one of the most common cases would be transforming (product a (sum b1 b2 ... bn)) -> (sum (product a b1) ... (product a bn)) so I need a really featureful structural editing package that allows me to jump between and into terms, combine, swap, what have you. Do any hardcore lispers have a really powerful setup they would like to share?
_viz_ · 2022-11-25 02:49
In theory this sounds like the perfect job for embedded calc (C-x * e).
cuntymccuntlicker · 2022-11-25 02:56
I thought of using calc but im not sure its syntax tables are flexible enough to handle the latex input I want to give. There are several versions of integrals that i need to work with and i think a full parser would be better suited for this job.
ekd123 · 2022-11-25 04:35
> write a simple latex parser that can output the AST in lisp form tree-sitter > modify it with structural editing in place [tree-edit](https://github.com/ethan-leba/tree-edit) I think your use case is a perfect fit for tree-sitter, but the tree-sitter ecosystem on the emacs side is still weak, though quickly evolving: tree-sitter will be a core feature in emacs29.
field_thought_slight · 2022-11-25 06:22
A Lisp DSL for outputting LaTeX is something I've wanted for a while, but I've been scared to start such an ambitious-sounding project. **EDIT:** I'm so glad to have inadvertently invoked Cunningham's Law.
puntinoh · 2022-11-25 07:05
Here you go, not so front-facing-lispy but in its very heart: - [Pollen](https://docs.racket-lang.org/pollen/) - [Scribble](https://docs.racket-lang.org/scribble/) Both powered by Racket.
akater · 2022-11-25 08:10
I don't have a really powerful setup. But often enough, I just write mathematical expressions as sexps. Editing both individual expressions and whole chains of reasoning becomes easier. The experience gives me an impression of a possible sexp math syntax that is convenient enough to be usable. I abandoned LaTeX in notes, except for multi-char sub- and superscripts. It was designed for typesetting markup, not for mathematical writing.
NoisyFrequency · 2022-11-25 08:38
Could using [Maxima](https://github.com/emacsmirror/maxima) be an alternative solution?
deaddyfreddy · 2022-11-25 10:20
https://github.com/Cnly/clj-latex
heartb1t · 2022-11-25 18:04
there are at least two known solutions in Elisp: https://alejandrogallo.github.io/listex/ and https://oremacs.com/2015/01/23/eltex/
cuntymccuntlicker · 2022-11-27 01:38
It might be, but I feel it will just be a repeat of using mathematica.