Re: [mathjax-users] Updating the typesetting

19 views
Skip to first unread message

Davide Cervone

unread,
Oct 5, 2016, 6:26:42 PM10/5/16
to mathja...@googlegroups.com
Note that in Javascript string literals, the backslash is an escape character, so if you want to include a backslash in the string itself, you must double it.  So you need to use 

var conjectures = ['\\(n^3 + n\\) is always even' . . . etc];

otherwise you will get just '(n^2 + n)' in your document rather than '\(n^3 + n\)'.  Since normal parentheses are not math delimiters, MathJax won't be able to locate your intended math.

Try that out and see if that doesn't fix it for you.

Davide



On Oct 5, 2016, at 4:27 PM, richa...@gmail.com wrote:

Hi.

I've created a js file that picks some random MathJax from an array. For instance: 

var conjectures = ['\(n^3 + n\) is always even' . . . etc];    

I've then randomised printed it to html using jQuery 

$('.triangle-isosceles').html(randConjecture);

Now this won't display in the correct format because MathJax has already done it's typesetting. I looked at the documentation and added another line below the function like 
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
but this isn't working. I assume I've typed in rubbish here, or the problem might be that I've called MathJax in my HTML file but my javascript file doesn't know how to deal with it?

Can someone help me? I just want MathJax to look at the page again and re-render any code. 

I've added the code of my main file : 
Enter code here..<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="celeb.css" />
    <!--[if IE]>
<link href="http://fonts.googleapis.com/css?family=Bungee" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Slabo+27px" rel="stylesheet" type="text/css">

<![endif]-->
    <script type="text/javascript" async
</script>
</head>
<body>



<script src='celeb.js'></script>

<div id="container"><a href="https://twitter.com/share" class="twitter-share-button" data-show-count="false">Tweet</a><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
    <p id='backto'><a href=http://www.ticktockmaths.co.uk>[Go Home]</a></p>
    <p id="intro">
    These celebs have some thoughts. Do you agree? Can you prove or disprove them? 
    </p>
    <div class="triangle-isosceles">Click the celebrity to generate a conjecture.</div>
        <div id="randomelement"><img src="Celebs/jedward.png" />
    </div>
    <div>
    </div>
</div>


</body>
</html>.
and celeb.js

function main() {
                $('#randomelement').on('click', function () {
var celeb = ['joey.jpg', 'justin.jpg', 'jedward.png', 'david.jpg', 'adam.jpg'];    
var randCeleb = celeb[Math.floor(Math.random() * celeb.length)];
$('#randomelement').html('<img src="Celebs/' + randCeleb + '" />');
var conjectures = ['\(n^3 + n\) is always even', 'All even numbers, apart from 2 can be expressed as the sum of two primes.', 'The square numbers follow the patter odd, even odd', '\(n^2 + n\) is always odd', '\(2^n - 1\) is always prime'];    
var randConjecture = conjectures[Math.floor(Math.random() * conjectures.length)];
$('.triangle-isosceles').html(randConjecture);
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
} );
}
$(document).ready(main);


Yes. This stupid little program pairs up stupid celebrities with maths conjectures for pupils to try and disprove/prove. 

Geek maths teacher.


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

Reply all
Reply to author
Forward
0 new messages