4
$\begingroup$

I wanted to include a diagram in an answer, but Mathjax doesn't support TikZ. I therefore wrote the TikZ code in a local .tex file in my PC, compiled it, and included the diagram as a .png file. The problem with this procedure is that it prevents me from sharing the code (in case someone wants to use it themselves somewhere else), and it forces me to keep the .tex file in my PC (so that I can modify it in the future if I need to).

It would be great if I could include the TikZ code in the post itself but, preferably, to make it invisible. Is it possible somehow? An HTML trick perhaps?

$\endgroup$
2
  • $\begingroup$ FWIW: <!-- test --> doesn't work if test includes non-trivial characters (e.g., "\"). $\endgroup$ – AccidentalFourierTransform Mar 25 '18 at 14:43
  • $\begingroup$ FWIW, Phys.meta has a sandbox for further experiments... $\endgroup$ – Qmechanic Mar 25 '18 at 15:15
7
$\begingroup$

You can include TeX comments. For example, the Einstein equation is

$$
E = 
%\gamma
mc^2
$$

$$ E = %\gamma mc^2 $$

where most people don't include the $\gamma$ that describes the dynamics.

$\endgroup$
2
  • $\begingroup$ Thanks, I think I'm going to try this option first. I'll report back. Cheers! $\endgroup$ – AccidentalFourierTransform Mar 26 '18 at 13:15
  • 1
    $\begingroup$ This works just fine. I used it here, and it looks all right. $\endgroup$ – AccidentalFourierTransform Mar 26 '18 at 13:42
4
$\begingroup$

You can just define an empty tex macro and wrap your code in that. Like this:

$$\def\ignore #1{} \ignore{\begin{tikzpicture}
\draw (0,0) -- (1,1) ;
\end{tikzpicture}}$$

Which looks like this:

$$ \def\ignore #1{} \ignore{\begin{tikzpicture} \draw (0,0) -- (1,1) ; \end{tikzpicture}} $$

$\endgroup$
3
  • $\begingroup$ The disadvantage of this approach is that MathJax will parse the TeX command on loading the page, potentially slowing it considerably or giving syntax errors if it doesn't know the command you are using $\endgroup$ – ACuriousMind Mar 26 '18 at 6:43
  • $\begingroup$ @ACuriousMind Are you sure? I don't think the macros inside get expanded until after \ignore gets expanded, and by that point they don't exist anymore. MathJax doesn't complain about \ignore{\def\x{\x}\x}, for instance, and it definitely complains about \def\x{\x}\x. Even if that's wrong, if it becomes a problem you can \def those macros to do nothing as well. $\endgroup$ – Chris Mar 26 '18 at 7:43
  • $\begingroup$ @Chris Thanks. I'm going to go with Rob's suggestion first, and if it doesn't work, I'll try yours. Cheers! $\endgroup$ – AccidentalFourierTransform Mar 26 '18 at 13:16
3
$\begingroup$

An alternative to pasting invisible code is to simply post the code to a Latex sharing site, such as ShareLatex or Overleaf, and then link to it below the image. Then interested users could go see it without having to clicking the edit button (though it is forcing someone off-site).

Even repositories such as GitHub or PasteBin would work, though you wouldn't have the ability to compile and see the results on in these cases as you would with the previous option.

$\endgroup$
1
  • $\begingroup$ That's definitely a valid option, thanks! I guess I thought it would be easier to keep things local. But if the suggestions by Rob and Chris don't work, I'll follow yours. Cheers! $\endgroup$ – AccidentalFourierTransform Mar 26 '18 at 13:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .