'Verbatim environment' render in MathJax

302 views
Skip to first unread message

ericnath...@gmail.com

unread,
Oct 20, 2015, 12:03:02 AM10/20/15
to MathJax Users
Hi.

I am going to post a bunch of computer code and need to use the LaTeX verbatim environment.  It works in MathJax but also prints the '\begin{verbatim}' and '\end{verbatim}' tags.  If I don't use the verbatim environment something else interprets the R code and it won't render at all.

A minor bug considering how great MathJax is!  It is truly wonderful to be able to print LaTeX quality mathematics on a webpage!

Thank you!

Eric

Try rendering this code:

$$  
\begin{verbatim}
> A2 <- matrix(c(0,1,0,0,1,1,0,1,1,1,0,1,0,0,0,0,1,0,0,0,1,1,0,0,0),5,5 )
> eigen(A2, symmetric=TRUE)
$values
[1]  2.3429231  0.4706834  0.0000000 -1.0000000 -1.8136065

$vectors
           [,1]       [,2]          [,3]          [,4]       [,5]
[1,] -0.4734862  0.4559848  0.000000e+00  7.071068e-01 -0.2605546
[2,] -0.6358555 -0.2413603  2.220446e-16 -7.771561e-16  0.7330982
[3,] -0.2713941 -0.5127870  7.071068e-01 -1.110223e-16 -0.4042212
[4,] -0.2713941 -0.5127870 -7.071068e-01 -2.029962e-16 -0.4042212
[5,] -0.4734862  0.4559848 -2.220446e-16 -7.071068e-01 -0.2605546  
\end{verbatim}    
$$ 

Peter Krautzberger

unread,
Oct 20, 2015, 2:21:35 PM10/20/15
to mathja...@googlegroups.com
Hi Eric,

MathJax's TeX input is focused on providing math mode macros. Verbatim is a text mode environment (i.e., wrapping $$ .... $$ around it is actually invalid in real LaTeX) and it is therefore not something we're currently planning to implement.

You could write a MathJax extension that does a similar job (e.g., map it to \verb from the verb extension) which would fit well on our third party extension repository at https://github.com/mathjax/MathJax-third-party-extensions which we mirror on the MathJax CDN.

Best regards,
Peter.

--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Johnson

unread,
Oct 20, 2015, 2:39:24 PM10/20/15
to mathja...@googlegroups.com
Thanks for the reply, Peter.  

Yeah - okay that makes sense.  I'm used to working in a pure TeX environment where I *have to* use verbatim or something like it to write out code that should not be interpreted by the TeX program...  I hadn't even thought of that fact.

Yeah - so I should perhaps use whatever regular HTML I can that will simply print out the text.

Thank you!  Your explanation saved me a lot of grief!

Eric



--
You received this message because you are subscribed to a topic in the Google Groups "MathJax Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mathjax-users/ya6rRKYqk6E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mathjax-user...@googlegroups.com.

Peter Krautzberger

unread,
Oct 20, 2015, 3:00:11 PM10/20/15
to mathja...@googlegroups.com
Perhaps I was overthinking it -- it's really easy to hack something using \newenvironment for a custom macro.

How about

$\newenvironment{verbatim}[1]{\verb|#1|}{}$

Or if you want to enforce display style

$\newenvironment{verbatim}[1]{\begin{gather}\verb|#1|\end{gather}}{}$

Peter.

William F Hammond

unread,
Oct 20, 2015, 4:12:51 PM10/20/15
to mathja...@googlegroups.com

On Tue, Oct 20, 2015 at 12:00 PM, Peter Krautzberger <peter.kra...@mathjax.org> wrote:

$\newenvironment{verbatim}[1]{\begin{gather}\verb|#1|\end{gather}}{}$

I'm too lazy to try it, but I'm skeptical about this. At the very least, the environment's content must not contain the \verb argument delimiter.  My guess is that newlines in the content will not work.  And a one item customized list would be better than 'gather'.  After all, the content is not going to be math.

Really, this is outside of the purview of MathJax.

For actual LaTeX source there are better verbatim environments than the default.
See the LaTeX Companion.

Eric Johnson

unread,
Oct 20, 2015, 8:15:46 PM10/20/15
to mathja...@googlegroups.com
Hey.  Thank you for all the input about this!

Putting <pre> and <code> tags works.  I had to look it up!

For example:

<pre><code>> A2 <- matrix(c(0,1,0,0,1,1,0,1,1,1,0,1,0,0,0,0,1,0,0,0,1,1,0,0,0),5,5 )
> eigen(A2, symmetric=TRUE)
$values
[1]  2.3429231  0.4706834  0.0000000 -1.0000000 -1.8136065

$vectors
           [,1]       [,2]          [,3]          [,4]       [,5]
[1,] -0.4734862  0.4559848  0.000000e+00  7.071068e-01 -0.2605546
[2,] -0.6358555 -0.2413603  2.220446e-16 -7.771561e-16  0.7330982
[3,] -0.2713941 -0.5127870  7.071068e-01 -1.110223e-16 -0.4042212
[4,] -0.2713941 -0.5127870 -7.071068e-01 -2.029962e-16 -0.4042212
[5,] -0.4734862  0.4559848 -2.220446e-16 -7.071068e-01 -0.2605546  
</pre></code> 

Eric

William F Hammond

unread,
Oct 20, 2015, 8:41:08 PM10/20/15
to mathja...@googlegroups.com

Earlier I wrote:

My guess is that newlines in the content will not work.

Correct.   If this newenvironment was for actual LaTeX, here is the issue:

Source:

\verb|a
b|

Error message:

! LaTeX Error: \verb ended by end of line.

Of course source newlines are entirely expected in LaTeX's verbatim environment.

                 -- Bill


Christophe Bal

unread,
Oct 21, 2015, 5:19:56 AM10/21/15
to mathja...@googlegroups.com
Hello.

In such a situation, I would use MathJax only for math and something like CodeMirror for listings.


Christophe BAL
Enseignant de mathématiques en Lycée et développeur Python amateur
---
French math teacher in a "Lycée" and Python amateur developer

Eric Johnson

unread,
Oct 22, 2015, 11:10:50 PM10/22/15
to MathJax Users
CodeMirror...

Thanks for the suggestion - I'll check it out!



Eric Johnson

unread,
Oct 22, 2015, 11:13:04 PM10/22/15
to MathJax Users
Hey.  Thank you for all the input about this!

Putting <pre> and <code> tags works.  I had to look it up!

For example:

<pre><code>> A2 <- matrix(c(0,1,0,0,1,1,0,1,1,1,0,1,0,0,0,0,1,0,0,0,1,1,0,0,0),5,5 )
> eigen(A2, symmetric=TRUE)
$values
[1]  2.3429231  0.4706834  0.0000000 -1.0000000 -1.8136065

$vectors
           [,1]       [,2]          [,3]          [,4]       [,5]
[1,] -0.4734862  0.4559848  0.000000e+00  7.071068e-01 -0.2605546
[2,] -0.6358555 -0.2413603  2.220446e-16 -7.771561e-16  0.7330982
[3,] -0.2713941 -0.5127870  7.071068e-01 -1.110223e-16 -0.4042212
[4,] -0.2713941 -0.5127870 -7.071068e-01 -2.029962e-16 -0.4042212
[5,] -0.4734862  0.4559848 -2.220446e-16 -7.071068e-01 -0.2605546  
</pre></code> 
Reply all
Reply to author
Forward
0 new messages