Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: SugarTeX – readable LaTeX language extension and transcompiler to LaTeX (github.com/kiwi0fruit)
53 points by kiwi0fruit on May 28, 2018 | hide | past | favorite | 49 comments



Hi, 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.


100% agree. But at least there is an example at the very end of the docs: 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.


My 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


OK, 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.


Not really. With that package you can type in LaTeX. But it's inherited behavior.

I myself prefer type `\^:` to get vector superscript symbol, type `\^->` to get another vector superscript symbol. Type:.\rot`to get matrix superscript symbol. Type `\-->` to get long arrow.

But yes, type `\\` to get broken vertical bar that's a new newline symbol, type `\&` to get small sing below that later again converts to `&`.


I think you started with something simple, but quickly found you needed to add features for it to work properly for you - and I'd guess it is more-or-less complete for your use-case now. The documentation is a reference for all the features. But it's difficult for a newcomer, to see the full complexity of the end-product, first.

Echoing the root of this thread, I think a tutorial would help, covering the simplest and most common features first (and the ones that work most neatly and elegantly). I'd suggest, for every example, have three parts, in the order a user would experience them:

  1. user-entered shortcut  e=mc\^2
  2. unicode appearing      e=mc²
  3. an image of pdf
I'd omit the actual latex from this tute, because the user never actually sees it...


Yep, this initially started as Pandoc filter that iterates over math elements and applies regex replacing. Then I switched to Panflute to iterate over math easier. And eventually added {, } counter with left, right and center regex patterns for binary math operators.


Snippets perhaps? Something like https://github.com/SirVer/ultisnips may be useful here. It's got completion and replaces with templates (with some other powerful things too)


I'd better call it 'TeX-Sugarer', though. And yes it's possible to create it to import LaTeX to SugarTeX.

SugarTeX completions is forked from latex-completions Atom package. I haven't seen something like this before.


It's very cool, especially combined with your sugarTeX idea. I believe your abbreviations are faster for an expert; but using widely-known latex makes it more accessible to new adopters. They can shift to your expert shortcuts later!


Yep, such examples are needed...

BTW: `mc\^2` gives mc²


It needs indeed...

I guess Unicode Math is a part of SugarTeX as every valid LaTeX is a valid SugarTeX (unless it has new SugarTeX meaning, otherwise it's a bug). Or maybe there's something I do not know about Unicode Math? I thought it simply replaces/treats some Unicode characters with LaTeX commands. So I used this feature and didn't bother replacing some Unicode.


The pdf version is better than the markdown.

https://github.com/kiwi0fruit/sugartex/blob/master/sugartex....


SugarTeX 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) (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) with description.

Example of input to output conversion is at the end of [this PDF](https://github.com/kiwi0fruit/sugartex/blob/master/sugartex....).


NEW EXAMPLES ADDED ==================

Examples of input to output conversion see in this PDF:

https://github.com/kiwi0fruit/sugartex/blob/master/examples/...


> Designed to be used instead of $formula$ insertions to Markdown.

What's the downside of having $formula$ blocks in Markdown?


ˎa/bˎ is easier to read than $\frac{a}{b}$.


If 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.p...

or fold-mode (shows unicode and abbreviations in place of commands)?

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

This seems to make easy things easier and harder things really hard.

Kinda like 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.


Oddly, 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.


More on Knuth preferring `\over`: 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-di...


Also, 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.


It'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): 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".


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


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


Latex 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!


I'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


But 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.)


Debugging 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


(Disclosure: Not an expert.) Standard LaTeX, meaning what exactly? Since 1983 there's been LaTeX2, LaTeX2e, and amsmath and the hundreds of packages that are now standard. The LaTeX used nowadays is a lot of stuff built on top of the improved later versions of LateX, which itself was built on top of Plain Tex (itself built on Tex).

I love how LaTeX/TeX is completely programmable, and anything particularly unreadable/messy can be made readable with user-defined commands, environments etc.


Have you tried debugging LateX? Miss a comma somewhere or screw up a package's options, and you'll be left wondering why your paper is broken, and then you're at the mercy of Google to help you find another person with the same issue.

LaTeX produces beautiful papers, but it's old and showing signs of its age.


Is it that bad? Have you tried to debug Markdown + LaTeX MathJax? Is it the same of differs? As for me it seems enough easy to debug each single math object. But I only used Markdown + LaTeX insertions so I cannot compare.


I've written papers with some complex tables, probably over 150 pages worth of dense latex, and I still have trouble debugging :/


I wrote my thesis using latex, and can with confidence say, no, it is not "working fine".

Maybe in the sense that COBOL is "working fine", so we should all just stick to that too.


But LaTeX itself was (and still is) just a wrapper on top of pure Knuth TeX to make it seem more like a once popular markup language called Scribe.


As 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?


You 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``.



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


Looks like it already have been implemented: 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


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


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


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


You can already write your mathematics directly in Unicode, without needing any additional LaTeX package. See e.g. 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.


The 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}})$.


Transcompiler !

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


You 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).


Examples of input to output conversion see in this PDF: https://github.com/kiwi0fruit/sugartex/blob/master/examples/...


Although 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 I am using marked, katex and Latex2JS.


But isn't that what XSL-FO is for?

well, I thought it was funny.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: