preview-inline icon indicating copy to clipboard operation
preview-inline copied to clipboard

enable for math-environments in LaTeX

Open runar-rkmedia opened this issue 8 years ago • 11 comments

It would be really great if it was possible to make this work for some math-environments in LaTeX. For instance \begin{equation} 1+1 \end{equation}, and other environments, like align would really make this a protool.

runar-rkmedia avatar Aug 14 '16 15:08 runar-rkmedia

Thanks, I've been meaning to add this but since I use markdown I haven't got round to it. Will try to get round to it though, PRs also welcome.

On 14 Aug 2016 11:29 a.m., "runartrollet" [email protected] wrote:

It would be really great if it was possible to make this work for some math-environments in LaTeX. For instance \begin{equation} 1+1 \end{equation}, and other environments, like align would really make this a protool.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mangecoeur/preview-inline/issues/15, or mute the thread https://github.com/notifications/unsubscribe-auth/AAtYVGVg2fiz2LtPW2XA7v4kn2NP2InGks5qfzREgaJpZM4Jj65z .

mangecoeur avatar Aug 14 '16 15:08 mangecoeur

It should now work for common math environments - please test with latest version 1.1

mangecoeur avatar Aug 22 '16 16:08 mangecoeur

This is super useful and seems to be working well in latex documents.

Is it possible to support macros in equation environments? For example, those created with \newcommand?

I have a number of user defined macros for common variables and it would be very useful if they were also rendered in the preview.

jasonmcewen avatar Aug 27 '16 23:08 jasonmcewen

Hi @jasonmcewen - it's not possible to use macros at the moment since preview-inline only processes the chunk of LaTeX that's part of the current math block. There does seem to be scope within MathJax to support macros, though I'm not sure how best to make this work in preview: http://docs.mathjax.org/en/latest/tex.html#defining-tex-macros

I would welcome suggestions for a design however - I could imagine for example being able to manually select a region of text containing macros and getting MathJax to process that and remember it when it generates equation previews. However since I don't use LaTeX (I'm writing pandoc-flavour markdown which I fine more elegant) I'm not sure to what extent this makes sense.

mangecoeur avatar Sep 13 '16 10:09 mangecoeur

The Latex delimiters "\begin{equation}...\end{equation}" work well. Would it be possible to add support for "\[...\]"? Thanks @mangecoeur.

ghost avatar Nov 22 '16 20:11 ghost

@mangecoeur I also just noticed that environments such as "\begin{align}...\end{align}" are not included.

ghost avatar Nov 22 '16 20:11 ghost

@44Space I'm not actually super familiar with LaTeX syntax - I would have expected an align environment to be inside an equation environment. They are not included as environments of their own because MathJax expects them to be inside the equation rather than part of the 'surroundings'. If you have more insight into the expected behaviour in LaTeX I would welcome a PR. Will try to explore a bit if I get the time myself.

mangecoeur avatar Nov 27 '16 23:11 mangecoeur

\begin{align} ... \end{align} is an alternative to \begin{equation} .... \end{equation} . It's more powerful and is included with the amsmath package which easily allows for multiline equations. Can you please enable support for this as well? Thanks.

onoderat avatar Jan 19 '17 23:01 onoderat

There is an issue with this that \align environments can also exist inside \equation environments, and it's not simple to support both. As a workaround it should be possible to simply wrap your align with equation.

On 19 Jan 2017 11:31 p.m., "Tatsuhiro Onodera" [email protected] wrote:

\begin{align} ... \end{align} is an alternative to \begin{equation} .... \end{equation} . It's more powerful and is included with the amsmath package which easily allows for multiline equations. Can you please enable support for this as well? Thanks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mangecoeur/preview-inline/issues/15#issuecomment-273932175, or mute the thread https://github.com/notifications/unsubscribe-auth/AAtYVD2YJoLh8TJdOGWI_ElpHOHP0etkks5rT_JOgaJpZM4Jj65z .

mangecoeur avatar Jan 19 '17 23:01 mangecoeur

I see thank you for the smart workaround!

onoderat avatar Jan 19 '17 23:01 onoderat

Hello, I look into this further and found that \begin{equation} \begin{align} f(x) & = x + x \ & = 2x \end{align} \end{equation} gives an error "Package amsmath: Erroneous nesting of equation structures". The inline preview does work with this wrapping trick. Finally, I found that if you highlight all of the equation text, the inline preview does work but does not update constantly (not a live preview).

On the other I checked that \begin{equation} \begin{align} f(x) & = x + x \ & = 2x \end{align} \end{equation} does work in mathjax. This suggests that align command is supported in mathjax.

Interesting, I verified that \begin{align} x + y \end{align} without the line breaks does work in inline preview. Its the command "&" does work.

onoderat avatar Jan 20 '17 06:01 onoderat