asciidoctor / asciimath

Asciimath parser
MIT License
24 stars 16 forks source link

Fix the spacing of some standard AsciiMath operators #37

Closed GarkGarcia closed 4 years ago

GarkGarcia commented 4 years ago

Some standard AsciiMath operators - such as Sin - don't really have a direct LaTeX equivalent. As of now, the solution I came up with was to output \text{Sin}, which mean the ouput for Sin x and "Sin" x is the same.

The rendered output look like the following:

CodeCogsEqn

One could then expect that Sin x (which is outputted as \text{Sin} x) would be rendered as:

CodeCogsEqn(1)

However, this is not the case. This is how \text{Sin} x is rendered in LaTeX:

CodeCogsEqn(2)

This could be fixed by outputting a \; between \text{Sin} and x (as of \text{Sin} \; x), but this is a bodge, a hack. This isn't a robust strategy. For example, if we were to adopt this strategy, the expression Sin (x)would be rendered as:

CodeCogsEqn(3)

This is incorrect. The correct output would be:

CodeCogsEqn(4)

It gets worse when dealing with infix operators - such as and, or and if. I'm not quite sure on how to deal with this. @davidfarmer @pepijnve I'd like your input.

Keep in mind I'm doing my best to make the LaTeX output as human-readable as possible. This could be easily fixed by using low-level TeX hacks, but as of now, my intention is to avoid them.

davidfarmer commented 4 years ago

I am not sure what you mean by "Sin". Is that different than "sin", which is what appears in the table on the asciimath home page?

If you wanted a function like the TeX \sin but with a capital S, then you write it as \operatorname{Sin}(x).

This Stackexchange question explains the point of operatorname as distinct from text or mathrm:

https://tex.stackexchange.com/questions/48459/whats-the-difference-between-mathrm-and-operatorname

This one is also relevant:

https://tex.stackexchange.com/questions/19502/is-there-a-preference-of-when-to-use-text-and-mathrm

The main thing to understand is that mathrm ignores all white space, just like everything in math mode. But \text respects spaces in its argument, like regular text in TeX.

On Thu, 7 May 2020, Gark Garcia wrote:

Some standard AsciiMath operators - such as Sin - don't really have a direct LaTeX equivalent. As of now, the solution I came up with was to output \text{Sin}, which mean the ouput for Sin x and "Sin" x is the same.

The rendered output look like the following:

CodeCogsEqn

One could then expect that Sin x (which is outputted as \text{Sin} x) would be rendered as:

CodeCogsEqn(1)

However, this is not the case. This is how \text{Sin} x is rendered in LaTeX:

CodeCogsEqn(2)

This could be fixed by outputting a \; between \text{Sin} and x (as of \text{Sin} \; x), but this is a bodge, a hack. This isn't a robust strategy. For example, if we were to adopt this strategy, the expression Sin (x)would be rendered as:

CodeCogsEqn(3)

This is incorrect. The correct output would be:

CodeCogsEqn(4)

It gets worse when dealing with infix operators - such as and, or and if. I'm not quite sure on how to deal with this. @davidfarmer @pepijnve I'd like your input.

Keep in mind I'm doing my best to make the LaTeX output as human-readable as possible. This could be easily fixed by using low-level TeX hacks, but, as of now, my intention is to avoid them.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.[AABTULFKWK5W5O5E2J5SVS3RQMZTBA5CNFSM4M3WZO32YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4JE6ZKZA.gif]

GarkGarcia commented 4 years ago

If you wanted a function like the TeX \sin but with a capital S, then you write it as \operatorname{Sin}(x).

Yep, that's what I wanted.

If you wanted a function like the TeX \sin but with a capital S, then you write it as \operatorname{Sin}(x).

Thanks! That's just what I was looking for!

GarkGarcia commented 4 years ago

Fixed on https://github.com/asciidoctor/asciimath/commit/74e5ba3355837774c202b4c61b085f9e0b62f612!