I'm guessing this has been done in a thread before, but I've just spent two hours reading various threads and cannot get my head around a very basic question.
Long story short: I'm trying to create dynamic equations/diagrams in a web browser for a homework generator. So far I've been using MathJax and loving it for the equation side of things. It's very simple as I just need to include a single line of Javascript code and then I'm good to start coding:
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['|','|'], ['\\
(','\\)']]}});
</script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX- AMS-MML_HTMLorMML">
</script>
<?
$x = rand(2,5);
echo "x|^2| = ".pow($x,2).", so x = |\pm|$x";
?>
And it correctly turns that into the equation form on the browser.
Now, my goal is to do the same sort of thing with TikZ
so I can create triangles and so forth on the fly using code like:
<?
$vertex1 = rand(2,5);
$vertex2 = rand(2,5);
?>
\documentclass[12pt, border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) node[anchor=north]{$A$}
-- (<? echo $vertex1; ?>,0) node[anchor=north]{$C$}
-- (<? echo $vertex1; ?>,<? echo $vertex2; ?>) node[anchor=south]{$B$}
-- cycle;
\end{tikzpicture}
\end{document}
So my first question, which I think is answered "no" but is worth checking anyhow - is there a simple way to call TikZ
in Javascript as with MathJax? Because that would be amazing.
If not, how can I get to a place where I can actually use TikZ
from HTML/Javascript
? I believe that some websites show TikZ
code, but I cannot find any documentation on this (everything just assumes I'm using a LaTeX program that can summon TikZ
with a simple \usepackage{tikz}
call, which I don't think MathJax can do).
For now, I'm running my scripts on a localhost my Macbook via MAMP, but eventually I would like to move it to an actual web server - but if it comes down to needing to install it at a root level, I can look into that. Just need some clear explanations since I'm really new to the technical side of LaTeX.