Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extension for \begin{...}, \end{...} latex math blocks #13

Closed
kasperpeulen opened this issue Dec 30, 2015 · 10 comments
Closed

extension for \begin{...}, \end{...} latex math blocks #13

kasperpeulen opened this issue Dec 30, 2015 · 10 comments

Comments

@kasperpeulen
Copy link

@dikmax I'm using your math extension now on my website, works great 👍

I have one other feature request. Many mathematicians also use \begin{...} \end{...} kind of code blocks. For example \begin{matrix}, \begin{align} etc. Those are supported by some markdown flavours, for example the one used at math.stackexchange.com.

Would be great if md_proc could also escape markdown for those blocks (and mark as <span class="math display">).

A workaround that is now possible, is to use $$...$$ around the equation, see:
http://kasperpeulen.github.io/mathedit/#/gist/097f6d551598a3a8487f

But I think people are so used to not having to do that from standard latex, math.stackexchange etc., so an extension would be great.

@Scorpiion
Copy link

I don't know anything about the details here, I don't know what css class names are used at the moment.

However just reading this I got a initial thought on the class names. Isn't both "math" and "display" very wide names (or so to speak) that might create issues? That is collisions with css names created by the end user.

I'm thinking that some kind of prefix of the css class name might be beneficial, especially if those class names are always machine generated (since the length of the machine generated names does not effect the end user, while using name they might also use can create hard to find bugs). As far as I know in normal css the namespace is always global, that's why these collisions might happen. Mdl for example prefixes all their css classes with mdl-. Maybe just md- could be used if there is not already some prefix used in md_proc overall.

@kasperpeulen
Copy link
Author

@Scorpiion I think that is a good point, the current behaviour of md_proc is that it adds the classes math inline or math display. But I think this may not be optimal indeed.

For my personal project, I don't need any class names, it just has to be escaped from the regular markdown parser. Mathjax will search for the latex the math delimeters, not for a class name.

@Scorpiion
Copy link

Okay, yeah I think a css prefix might be good then. It might not be an issue for smaller projects, especially in the beginning, however the bigger the project gets the bigger the risk is that someone will run into this. It could also be that you are using the css of another third party, that you don't control, and that one uses one of more names that collide.

I might have "hijacked" this issue a little bit, so I created a separate issue (#14) for the potential of adding a css class name prefix to md_proc.

I suggest any further thoughts or discussion on css prefixes could be done there instead. Would like to hear what you think about css classes @dikmax when you have some time to spare.

@dikmax
Copy link
Owner

dikmax commented Dec 31, 2015

@kasperpeulen I don't quite understand why you may want to use \begin{}..\end{} instead of $$..$$. If you need complete LaTeX syntax why not to use just it. What the point of mixing those syntaxes.

What is supposed HTML-output for such blocks? If it just escaping then I think code block already support it.

@dikmax
Copy link
Owner

dikmax commented Dec 31, 2015

BTW, Pandoc also have raw_tex extension. But it strips all TeX-blocks from HTML-output.

@kasperpeulen
Copy link
Author

@dikmax This is not really about having complete LaTeX syntax. It is only for the math LaTeX blocks. For example this how it works in math.stackexchange.com:


image


But in my editor it works now like this:


image


The markdown is not escaped. So basically for math.stackexchange.com they use a markdown flavour that escapes everything between those \begin{} ... \end{} blocks. In theory I only need the following:

align      
align* 
alignat      
alignat*        
aligned       
alignedat      
array

Bmatrix
bmatrix

cases
CD                    

eqnarray
eqnarray*
equation
equation*

gather             
gather* 
gathered   

matrix
multline   
multline*   

pmatrix

smallmatrix 
split              
subarray  

Vmatrix
vmatrix

Those are the environment blocks that mathjax accepts. But I guess it would be easier to just escape any environment block.

What is supposed HTML-output for such blocks? If it just escaping then I think code block already support it.

So I think that this:

This is the identity matrix:

\begin{pmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 &1 \\
\end{pmatrix}

Should be converted to:

<p>This is the identity matrix:</p>
<p>
  <span class="math display">\begin{pmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 &1 \\
\end{pmatrix}</span>
</p>

The span around is not strictly necessary for my case, but I think it could be useful for some cases (maybe for me in the future as well). I'm not sure sure about the class names. Maybe a prefix would be better.

@kasperpeulen
Copy link
Author

Btw about class names, it could make sense, to give all math blocks tex2jax_process. This is the default for classes that mathjax processes:

http://docs.mathjax.org/en/latest/options/tex2jax.html?highlight=tex2jax_process

I think then the extension may be called MathJax because this is very specific for mathjax. It doesn't work like that for KaTeX for example.

@dikmax
Copy link
Owner

dikmax commented Jan 1, 2016

@kasperpeulen I've checked how Pandoc handles raw TeX.
Your is rendered as:

<p>This is the identity matrix:</p>

\begin{pmatrix}
1 &amp; 0 &amp; 0 \\
0 &amp; 1 &amp; 0 \\
0 &amp; 0 &amp;1 \\
\end{pmatrix}

I think, I'll do same.

@kasperpeulen
Copy link
Author

@dikmax sorry for the late reply, but that would work fine for my use case :)

@dikmax
Copy link
Owner

dikmax commented Jan 10, 2016

Fixed in 0.8.1. Please tell me it some of blocks aren't parsed correctly.

@dikmax dikmax closed this as completed Jan 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants