|
| 1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 2 | +<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" --> |
| 3 | +<head> |
| 4 | +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 5 | +<!-- InstanceBeginEditable name="doctitle" --> |
| 6 | +<title>VPython Help</title> |
| 7 | +<!-- InstanceEndEditable --> |
| 8 | +<!-- InstanceBeginEditable name="head" --> |
| 9 | +<link href="VisualRef.css" rel="stylesheet" type="text/css" /> |
| 10 | +<!-- InstanceEndEditable --> |
| 11 | +<script type="text/javascript"> |
| 12 | +<!-- |
| 13 | +function MM_jumpMenu(targ,selObj,restore){ //v3.0 |
| 14 | + eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); |
| 15 | + if (restore) selObj.selectedIndex=0; |
| 16 | +} |
| 17 | +//--> |
| 18 | +</script> |
| 19 | +<link href="VPythonDocs/VisualRef.css" rel="stylesheet" type="text/css" /> |
| 20 | +</head> |
| 21 | + |
| 22 | +<body> |
| 23 | +<table width="800" border="0" cellpadding="1" cellspacing="0"> |
| 24 | + <!--DWLayoutDefaultTable--> |
| 25 | + <tr> |
| 26 | + <td width="10" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell--> </td> |
| 27 | + <td width="10" height="272" valign="top" bgcolor="#DDDDDD"><p> </p> </td> |
| 28 | + <td width="173" valign="top" bgcolor="#DDDDDD"><p class="Normal"><a href="index.html">Home</a></p> |
| 29 | + <p class="Normal">If you're new to Python <br /> |
| 30 | + and VPython: <a href="VisualIntro.html">Introduction</a></p> |
| 31 | + <p class="Normal">A VPython <a href="VPython_Intro.pdf" target="_blank">tutorial</a></p> |
| 32 | + <p class="Normal"><a href="primitives.html">Pictures</a> of 3D objects</p> |
| 33 | +<p><select id="menu1" onchange="jumpMenu(this)"></select></p> |
| 34 | +<p><select id="menu2" onchange="jumpMenu(this)"></select></p> |
| 35 | +<p><select id="menu3" onchange="jumpMenu(this)"></select></p> |
| 36 | + |
| 37 | + <p class="Normal"><a href="new_features.html">What's new</a></p> |
| 38 | + <p class="Normal"><a href="http://vpython.org" target="_blank">Classic VPython web site</a><br /> |
| 39 | + <a href="license.txt" target="_blank">VPython license</a><br /> |
| 40 | + <a href="http://www.python.org" target="_blank">Python web site</a> <br /></p></td> |
| 41 | + <td width="21" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell--> </td> |
| 42 | + <td width="586" rowspan="2" valign="top"><!-- InstanceBeginEditable name="content" --> |
| 43 | + <div> |
| 44 | + <h1 class="Heading-1"><font color="#0000A0">Math displays using LaTeX</font></h1> |
| 45 | + </div> |
| 46 | + <div> |
| 47 | + <p class="Normal">You can display complex mathematical expressions expressed in the widely used math editing format, <a href="http://www.latex-project.org/" target="_blank">LaTeX</a>. Here is <strong><a href="http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/LaTexMathDisplay" target="_blank">an example</a></strong>. The LaTeX capability is provided by <a href="http://www.mathjax.org/" target="_blank">MathJax</a>, which is imported by GlowScript. For example, consider this mathematical display:</p> |
| 48 | + <p class="Normal"> <img src="images/MathJax.jpg" width="350" height="48" alt="equation" /></p> |
| 49 | + <p class="Normal">You can display this in the caption of an existing GlowScript canvas with the following statements:</p> |
| 50 | + <p class="program"> box()<br /> |
| 51 | + scene.caption = "Final kinetic energy = \\( \\dfrac {1} {2}mv_i^{2}+\\int _{i}^{f}\\vec{F}\\circ d \\vec{r} \\)"<br /> |
| 52 | + <br /> |
| 53 | + MathJax.Hub.Queue(["Typeset",MathJax.Hub]) </p> |
| 54 | + <p class="Normal">In the first statement, note that all LaTeX backslashes must be replaced by double backslashes: \ -> \\. For a backslash to appear on the web page (where it will be processed by MathJax) a JavaScript string must use two backslashes, since in a string a single backslash can have special meaning (for example \n represents a carriage return). When you write or paste in a LaTeX description, make sure you double all the backslashes. Unfortunately, there doesn't seem to be any way to write a JavaScript function to double the backslashes for you.</p> |
| 55 | + <p class="Normal">A common way to place a LaTeX math expression within a sentence is to place the expression between dollar signs: $ ..... $. However, with MathJax you must use the format \\( ..... \\) instead. If you want the expression to be centered in the window, use the standard LaTeX format $$ ..... $$.</p> |
| 56 | + <p class="Normal">The second program statement shown above tells MathJax to typeset the LaTeX description and display the mathematics correctly. In fact, this statement will typeset all of the LaTeX expressions currently placed on the web page.</p> |
| 57 | + <p class="Normal">You can also typeset a specific element. For example, suppose you've placed an expression in the title:</p> |
| 58 | + <p class="program">scene.title = "\\(\\dfrac {5} {7} \\)"</p> |
| 59 | + <p class="Normal">You can typeset this element, and all other existing LaTeX elements in the usual way -- <span class="program">MathJax.Hub.Queue(["Typeset",MathJax.Hub])</span>. However, suppose that later you change the expression from representing 5/7 to representing 3y/4x. You can change the title like this::</p> |
| 60 | + <p class="program">scene.title = "\\(\\dfrac {3y} {4x} \\)"</p> |
| 61 | + <p class="Normal">Then you can typeset just this one element, without re-typesetting other formulas on the web page, with this statement:</p> |
| 62 | + <p class="program">MathJax.Hub.Queue(["Typeset",MathJax.Hub,scene.title])</p> |
| 63 | + <p class="Normal"><strong><font color="#0000A0">Easy creation of LaTeX expressions</font></strong></p> |
| 64 | + <p class="Normal">There is a a <a href="http://webdemo.myscript.com/" target="_blank"><strong>remarkable tool</strong></a> for creating LaTeX expressions from handwriting (choose "Web Equation". Using the mouse, you simply write the mathematics as you would normally do by hand, and the tool produces the corresponding LaTeX, which you can paste into your program. Remember that you must double all of the backslashes.</p> |
| 65 | + <p class="Normal"><strong><font color="#0000A0">Summary</font></strong></p> |
| 66 | + <p class="Normal">You can use LaTeX to display complex mathematics on the web page. Make all backslashes double: \ -> \\. Within a sentence, use \\( ..... \\). For a centered formula, use $$ ..... $$.</p> |
| 67 | + <p class="Normal">After the LaTeX has been sent to the web page, typeset all of the math with <span class="program">MathJax.Hub.Queue(["Typeset",MathJax.Hub])</span>. You can typeset a specific web page element with <span class="program">MathJax.Hub.Queue(["Typeset",MathJax.Hub, anchor_point])</span>, where anchor_point can for example be scene.title or scene.caption, or a jquery id.</p> |
| 68 | + <p class="Normal">Additional capabilities of MathJax are documented at <a href="http://www.mathjax.org/" target="_blank">MathJax</a>.</p> |
| 69 | + <p class="Normal">.</p> |
| 70 | + </div> |
| 71 | + <br /> |
| 72 | +<!-- InstanceEndEditable --></td> |
| 73 | + </tr> |
| 74 | + <tr> |
| 75 | + <td height="16" colspan="4"></td> |
| 76 | + </tr> |
| 77 | +</table> |
| 78 | +</body> |
| 79 | +<script type="text/javascript" language="javascript" src="navigation.js"></script> |
| 80 | +<!-- InstanceEnd --></html> |
0 commit comments