# Is it possible to include invisible code in a post?

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?

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

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.

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

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}}$$

• 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 – ACuriousMind Mar 26 '18 at 6:43
• @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. – Chris Mar 26 '18 at 7:43
• @Chris Thanks. I'm going to go with Rob's suggestion first, and if it doesn't work, I'll try yours. Cheers! – AccidentalFourierTransform Mar 26 '18 at 13:16

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.

• 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! – AccidentalFourierTransform Mar 26 '18 at 13:31