
Show HN: SugarTeX – readable LaTeX language extension and transcompiler to LaTeX - kiwi0fruit
https://github.com/kiwi0fruit/sugartex
======
mkl
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.

~~~
hyperpallium
100% agree. But at least there is an example at the very end of the docs:
[https://github.com/kiwi0fruit/sugartex/blob/master/sugartex....](https://github.com/kiwi0fruit/sugartex/blob/master/sugartex.md#sugartex-
replacements-and-operators) 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
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](https://atom.io/packages/sugartex-completions)

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

~~~
kiwi0fruit
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 `&`.

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

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

------
kiwi0fruit
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](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....](https://github.com/kiwi0fruit/sugartex/blob/master/sugartex.pdf?raw=true)).

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

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

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

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

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

~~~
svat
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](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".

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

~~~
blackbear_
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

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

~~~
Ar-Curunir
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

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

~~~
kiwi0fruit
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``.

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

~~~
kiwi0fruit
Looks 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)

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

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

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

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

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

~~~
kiwi0fruit
Examples of input to output conversion see in this PDF:
[https://github.com/kiwi0fruit/sugartex/blob/master/examples/...](https://github.com/kiwi0fruit/sugartex/blob/master/examples/examples.pdf?raw=true)

------
skywal_l
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](http://mathdown.novidee.com/96699b9ccd482d662cd3332c2a53db25)
I am using marked, katex and Latex2JS.

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

well, I thought it was funny.

