7 ms·
Show HN: SugarTeX – readable LaTeX language extension and transcompiler to LaTeX
- kiwi0fruit 8y agoSugarTeX is a more readable LaTeX language extension and transcompiler to LaTeX. Designed to be used instead of $formula$ insertions to Markdown. I use Markdown with Python code blocks for document programming via [Pandoctools](https://github.com/kiwi0fruit/pandoctools https://github.com/kiwi0fruit/pandoctools) (like R-Markdown). Both Python and Markdown are very readable languages. Unfortunately LaTeX is not like this. So I wrote SugaTeX extension+transpiler that is highly readable. In order to achieve this it heavily uses Unicode so that SugarTeX install instructions even have recommended monospace font fallback chains. [SugarTeX repo](https://github.com/kiwi0fruit/sugartex https://github.com/kiwi0fruit/sugartex) with description. Example of input to output conversion is at the end of [this PDF](https://github.com/kiwi0fruit/sugartex/blob/master/sugartex.pdf?raw=true https://github.com/kiwi0fruit/sugartex/blob/master/sugartex....).
- kccqzy 8y ago> Designed to be used instead of $formula$ insertions to Markdown. What's the downside of having $formula$ blocks in Markdown?
- orangea 8y agoˎa/bˎ is easier to read than $\frac{a}{b}$.
- taeric 8y agoOddly, Knuth prefers ${a \over b}$. I think I agree, if only because it actually reads well. An odd thing I found, was the once I learned how to verbalize many of the maths that I encountered, reading them became much easier. LaTeX actually helped a lot here, because most of the constructs have good readable macros to typeset them.
- svat 8y agoMore on Knuth preferring `\over`: https://tex.stackexchange.com/a/390977/48 https://tex.stackexchange.com/a/390977/48 (I may have gone a little overboard…) The LaTeX (not TeX) community seems to strongly prefer `\frac` and strongly discourages `\over`, e.g. https://tex.stackexchange.com/questions/73822/what-is-the-difference-between-over-and-frac https://tex.stackexchange.com/questions/73822/what-is-the-di...
- jgtrosh 8y agoAlso, if you're interested in readable languages, there's the family of roff languages that might seem terse at first when coming from LaTeX but actually have a very enjoyable grammar. The LaTeX ecosystem is so great that I don't really miss roff but I do have nice memories of writing reports in roff a couple of years ago. More to the point I found it wonderful to write graphics in the roff pic sublanguage. Edit: actually even more to the point is the eqn sublanguage which really competes with Knuth notation.
- svat 8y agoIt's not a coincidence: in fact, eqn (the ACM paper by Kernighan and Cherry was published in 1975) predates the initial design of TeX (1977), and Knuth explicitly based the math notation in TeX on that of eqn. Initially, like eqn he had no backslashes, but quickly (before any code was written) changed it to one with backslashes. He discuses these matters of syntax in his Gibbs lecture of of January 1978 (https://projecteuclid.org/euclid.bams/1183544082 https://projecteuclid.org/euclid.bams/1183544082): see Figure 3 on the top of page 344, where the notation of eqn is marked "Type B" (“developed at Bell Telephone Laboratories”) and the third column is "Type T".
- kccqzy 8y ago> I found it wonderful to write graphics in the roff pic sublanguage. I happen to have fond memories of using lots of TikZ to do lots of graphics, making full-color posters with it. It was only because I was too poor to buy InDesign.
- diffeomorphism 8y agoIf it is only about reading then why not something like auctex preview (shows rendered graphics in place of commands)? https://www.gnu.org/software/auctex/img/preview-screenshot.png https://www.gnu.org/software/auctex/img/preview-screenshot.p... or fold-mode (shows unicode and abbreviations in place of commands)? https://www.flannaghan.com/2013/01/11/tex-fold-mode https://www.flannaghan.com/2013/01/11/tex-fold-mode Changing the representation seems more sensible to me than changing the underlying file. Also, while the a/b syntax is easier for easy cases, I shudder to think how a continued fraction might be type set: https://en.wikipedia.org/wiki/Continued_fraction https://en.wikipedia.org/wiki/Continued_fraction This seems to make easy things easier and harder things really hard. Kinda like https://www.lyx.org/Screenshots https://www.lyx.org/Screenshots or using org-mode for latex. Convenient for simple matters and something you have to fiddle with or work around when you want to do anything more advanced.
- kiwi0fruit 8y agoNEW EXAMPLES ADDED ================== Examples of input to output conversion see in this PDF: https://github.com/kiwi0fruit/sugartex/blob/master/examples/examples.pdf?raw=true https://github.com/kiwi0fruit/sugartex/blob/master/examples/...
- mkl 8y agoHi, this desperately needs examples of formulas (code and rendered) front and center. It's pretty hard to understand how this could be useful without that. A comparison to UnicodeMath (which seems very similar and is an existing standard which already works in Latex) would also be useful.
- hyperpallium 8y ago100% agree. But at least there is an example at the very end of the docs: https://github.com/kiwi0fruit/sugartex/blob/master/sugartex.md#sugartex-replacements-and-operators https://github.com/kiwi0fruit/sugartex/blob/master/sugartex.... I don't find it readable, but it is an extreme example - it would sell the concept better to start with simple, effortlessly superior cases. I'm not sure about this whole concept of unicode. It is more readable for sure, but harder to write (to remember which unicode to use, and how to get it). Perhaps surprisingly, java allows unicode identifiers etc, so I experimented with variables like δx and δt, and even ½i for PIC grids in CFG. It's cute, but I'm not really sure it's a good idea.
- kiwi0fruit 8y agoMy bad: I forget to tell about SugarTeX completions package for Atom. With it writing Unicode is lot faster and simple enough. https://atom.io/packages/sugartex-completions https://atom.io/packages/sugartex-completions
- hyperpallium 8y agoOK, so the whole system is: type in latex, becomes unicode text, finally rendered as symbols (e.g. in a pdf). Except that with that atom package, you needn't type the whole latex, because it autocompletes. BTW what is that kind of completion called (i.e. where it doesn't just complete, but also replaces it with something else); and is something like that available for vim - or for rlwrap? (I searched, but "completion" brings up all the standard vim completion modes). EDIT vim has "abbreviations", but the no built-in automcomplete mode for them (though you could also put them in a file, and have completion scan that file - or write your own). A "desugarTeX" could transform an existing latex doc into a unicode version, which could still be used as a source document, via sugarTeX. Arguably, this desugarTeX is kinda sorta like an output format of latex (like pdf or dvi), except that it's also machine readable as latex input.
- ajkjk 8y agoAs far as I can deduce, you're trying to incorporate LateX into .md using the Markdown Philosophy of "you should write something that's readable as plain text, without compilation, also". Is that basically right? If so it should probably be right at the top, because it's hard to tell right now. The idea makes sense, though I'm not sure if it's... better. Do you expect people to input " ⃗E" and "⨌" as text? Or ... what? Do you type the TeX and then have Atom autocomplete it into the Unicode symbols?
- kiwi0fruit 8y agoYou are completely right. But I thought ``Both Python and Markdown are very readable languages. Unfortunately LaTeX is not like this. So I wrote SugaTeX extension+transpiler that is highly readable.`` means the same... As about input. My bad: I forget to tell about SugarTeX completions package for Atom. There to write `` ⃗E`` you type ``\^->``(+E) this autocompletes to `` ⃗E``.
- kiwi0fruit 8y agoSugarTeX completions: https://atom.io/packages/sugartex-completions https://atom.io/packages/sugartex-completions
- robotresearcher 8y agoThe juice is at the very end of the README, where you can see the unicode markup (ignore HN-mangled newlines): ˎˎ ˱∇ × [ ⃗B] - 1∕c ∂[ ⃗E]∕∂t ˳= 4π∕c [ ⃗j] ¦# ∇ ⋅ [ ⃗E]\ ˳= 4πρ ¦ ∇ × [ ⃗E] + 1∕c ∂[ ⃗B]∕∂t ˳= [ ⃗0] ¦ ∇ ⋅ [ ⃗B]\ ˳= 0 ˲ ,ˎˎ{#eq:max} where ˎ[ ⃗B], [ ⃗E], [ ⃗j]: ℝ⁴ → ℝ³ˎ – vector functions of the form ˎ(t,x,y,z) ↦ [ ⃗f](t,x,y,z), [ ⃗f] = (f_˹x˺, f_˹y˺, f_˹z˺)ˎ. renders to: $$ \begin{aligned}∇ × {\mathbf{B}} - \frac{1}{c} \frac{∂{\mathbf{E}}}{∂t} &= \frac{4π}{c} {\mathbf{j}}\ ∇ ⋅ {\mathbf{E}}\ &= 4πρ \ ∇ × {\mathbf{E}} + \frac{1}{c} \frac{∂{\mathbf{B}}}{∂t} &= {\mathbf{0}} \ ∇ ⋅ {\mathbf{B}}\ &= 0 \end{aligned} ,$${#eq:max} where ${\mathbf{B}},,{\mathbf{E}},,{\mathbf{j}}:,ℝ^{4} → ℝ^{3}$ -- vector functions of the form $(t,x,y,z) ↦ {\mathbf{f}}(t,x,y,z),,{\mathbf{f}} = (f_{\mathrm{x}}, f_{\mathrm{y}}, f_{\mathrm{z}})$.
- srean 8y agoTranscompiler ! As if 'transpiler' was not nails-on-the-board grating enough. 'Compiler' is a fine word and the right word. Anyone knows who started this 'transpiler' nonsense. Seems very common in the javascript community but not sure if it was their 'innovation'.
- deleted 8y ago[deleted]
- enriquto 8y agoI do not understand what this is exactly, but I'm very interested! What is a LaTeX "extension" ? Is it a LaTeX package that will allow me to write my math directly in unicode ? That would be so cool! Could you please clarify the documentation (add some context) so that it is understandable to LaTeX users? Especially to LaTeX users that will want to keep using their own editor, and do not want to touch Atom with a long stick...
- kiwi0fruit 8y agoI meant extension in sence that it's a LaTeX language extension to it's superset. There's no LaTeX package and I myself will not port it. SugarTeX is Pandoc/Markdown oriented project in the first place. You can use it as a command line prepocess text filter though. It should work as long as you use ˎ or ˎˎ to define SugarTeX.
- svat 8y agoYou can already write your mathematics directly in Unicode, without needing any additional LaTeX package. See e.g. https://tex.stackexchange.com/q/87257/48 https://tex.stackexchange.com/q/87257/48 and the questions in the "Linked" sidebar on the right. (You may have to declare a few things one time; there are examples in the linked questions.) This thing here is only relevant if you're using Markdown and Pandoc, AFAICT.
- bryanrasmussen 8y agoBut isn't that what XSL-FO is for? well, I thought it was funny.
- kingkongjaffa 8y agoStandard LaTeX has worked just fine for like 35 years for the use cases it was intended: academic papers to write better looking mathematics and figures/citations, and heavyweight typesetting of things like books. Not really sure why people are insistent on building on top of stuff - it's taking abstraction to a new level that imho is not needed - LaTex isn't particularly unreadable.
- yodsanklai 8y agoLatex works fine but is far from perfect. People use it for lack of better options, but it's not exactly a joy to use (not for me at least). After 35 years, surely we can expect something better. So thanks to those working on that!
- blackbear_ 8y agoI'd say the problem isn't so much about readability but about ease of doing certain things. Case in point: non trivial tables, with multirows/multicols, newlines inside cells, and so on
- jimhefferon 8y agoBut aren't hard things going to be hard to do? There are things that, if you did them in a GUI, would be multiple steps down the tree of menus. It seems natural to me that they require multiple commands. (Not that LaTeX is perfect, for sure. Admit I only glanced at this. But after trying a bunch of things that the author asserts are simplifiers, I've not found one that is as capable. All too often they make super simple things that are already simple, and then fall back to LaTeX for the rest.)
- Ar-Curunir 8y agoDebugging those tables is still a pain in the ass. I am certain that we there's a better way than today, where if you accidentally add or remove a newline your table breaks
- wodenokoto 8y ago
- drwells 8y agoI would be interested to hear if this is a workflow that suits people that write mathematics papers or other complicated TeX documents. My TeX code is very macro heavy (I know some mathematicians who define almost everything through macros so that they can rewrite the paper quickly) and, as a result, I've never really seen the benefit of unicode mathematics. To go one step further: I think writing Greek letters (or, for that matter, any Latin letter that does not have a standard mathematical meaning) is an anti-pattern in mathematical prose: I think it is much, much better to write \coercivenessSymbol than \gamma or the unicode variant for the same reasons I would not name a floating point number gamma.
- kiwi0fruit 8y agoSugarTeX is tweakable. You can write your own Panflute Pandoc filter that additionally defines new non-standard replacements alike yet defined in SugarTeX. But I dont know if you need it: LaTeX macroses are valid SugarTeX too after all and they are quite powerfull.
- deleted 8y ago[deleted]
- kiwi0fruit 8y agoLooks like it already have been implemented: https://tex.stackexchange.com/a/28033/133525 https://tex.stackexchange.com/a/28033/133525 I mean having any macros name you want, even Unicode. So you can even have \γ macros. But if you want to write \coercivenessSymbol (even on the blackboard) we cannot stop you - after all it gives you pleasure. My conclusion about this feature: https://github.com/kiwi0fruit/sugartex/issues/1 https://github.com/kiwi0fruit/sugartex/issues/1
- skywal_l 8y agoAlthough not the easier to read, I think LaTeX language is still OK. The downside of this approach is the difficulty to learn the new Unicode character and how to type them! Just a couple of days ago I built a little editor to manipulate markdown, latex and even simple pictures thanks to the pspicture latex environment: http://mathdown.novidee.com/96699b9ccd482d662cd3332c2a53db25 http://mathdown.novidee.com/96699b9ccd482d662cd3332c2a53db25 I am using marked, katex and Latex2JS.
- Evidlo 8y agoYou should take one or two examples from sugartex.pdf and put it in the README (i.e. the SugarTex source and a screenshot of the rendered output).
- kiwi0fruit 8y agoExamples of input to output conversion see in this PDF: https://github.com/kiwi0fruit/sugartex/blob/master/examples/examples.pdf?raw=true https://github.com/kiwi0fruit/sugartex/blob/master/examples/...