# Can we support TikZ picture rendering?

I found an older thread from 2013 with basically the same question: Using TikZ on math.stackexchange

I'd like to revive the discussion, since I believe it's certainly possible, even if it may not have been back then. That is, can we have TikZ picture rendering? Similar to math formula rendering?

A picture is worth a 1000 words. It would be very nice if we can easily post a picture (through TikZ) without relying on an external drawing program and uploading it in some bitmap format.

As a reference, we can see here how it might work. It's an interactive page that shows some templates.

And here is a vBulletin forum where members can include TikZ pictures in their posts that get rendered server side. Unfortunately you need to be a member to see the images.

• "[...] I believe it's certainly possible, even if it may not have been back then." What is the basis for this believe? – quid Jul 21 '17 at 19:29
• @quid, there is a vBulletin forum that actually has it. I'm currently discussing with its staff it it's okay to share it. When they give me permission, I can provide a link to show how it works on their site. – Klaas van Aarsen Jul 21 '17 at 19:31
• Thanks for the reply. Idly I wonder why you did not do that before posting the request here. – quid Jul 21 '17 at 19:36
• My request does not depend on the particular vBulletin forum. As it is I'm exploring since I don't expect this partocular meta forum to be in a position to make it happen – Klaas van Aarsen Jul 21 '17 at 20:06
• "In any math thread a picture is worth a 1000 words." Highly subjective and debatable. – Asaf Karagila Jul 21 '17 at 20:19
• Maybe we are talking at crossed purposes. I just want to know what "it" exactly means. For all I know MathJax does still not support TikZ. What does that board do? Do the uses another way to render math? Or do they take the code, create an image server side, and then serve the picture? Or is this a secret? – quid Jul 21 '17 at 23:34
• I'm sorry @AsafKaragila, but - really? That is, I really do believe that there is no debate that pictures are worthwhile in math threads. Ah well, let people shoot me down if they believe that I'm mistaken. – Klaas van Aarsen Jul 21 '17 at 23:35
• @quid, SE recognizes that there are LaTeX markers for math mode and invokes MathJAX to render it. That board recognizes LaTeX markers for TikZ pictures in the same fashion and replaces it by the corresponding picture. – Klaas van Aarsen Jul 21 '17 at 23:39
• A picture is worth a 1000 words is a common phrase. See en.wikipedia.org/wiki/A_picture_is_worth_a_thousand_words. Quantifier or not. Forgive me for not applying proper quantifiers. – Klaas van Aarsen Jul 22 '17 at 0:31
• I'm looking for some support here for what I believe is a valuable and innovative idea. I should even be able to 'pull' part of the effort (I did on the vBulletin board where I am on staff) - but that will only work if there is at least some support from the community. – Klaas van Aarsen Jul 22 '17 at 1:41
• I've added a couple of references where we can see how it can work in practice. Oh, and I've removed the quantifier. – Klaas van Aarsen Jul 23 '17 at 12:00
• The corresponding feature request on meta.SE: Can we have automatic TikZ rendering? – Martin Sleziak Jul 24 '17 at 14:34
• I am not sure that you realize how hard that would be. Consider that the PGF/TikZ manual is 1161 pages long (yes, more than a thousand; this is not a typo). – Najib Idrissi Jul 25 '17 at 14:27
• @NajibIdrissi I am not sure why it should be that hard to do what I think OP envisions, though this might well be distinct from what others understand the proposal to be. It is I think: suitably marked-up code would be compiled server-side, and the resulting image would be inserted. (The source would be preserved as a commentary or something like that.) Of course this would have some downsides, but this is what is I think proposed. It is also possible I am being naive about the difficulty of that, but it seems plausible to me as one could use existing compilers for the hard part. – quid Jul 25 '17 at 17:07
• @MarkMcClure how does this make the question off-topic? One would not even have to use MathJax for this. (To be clear, I find the feature request dubious but it's not off-topic; maybe it's a duplicate of the old one, and OP should not have posted it all over the network. But off-topic it is not.) Furthermore, impossible feature requests get declined not closed. – quid Jul 25 '17 at 17:34

Our standard procedure when we get any request for a special site plugin like this is to ask for two things:

• community support on meta
• evidence that it would make a significant improvement to post and/or community quality

In other words, we'd like for you to edit this meta question to show us examples of several posts on the site that would benefit substantially from the use of TikZ, and provide explanations of the benefit. (Please account for the fact that Math SE is a fairly high volume site.)

If other people agree with you, they'll upvote, and maybe even start contributing examples of their own. Collect enough upvotes and we can send this to our dev team and say "look, this really is worth your time and the performance cost." (Our devs care a lot about performance.)

For examples, see what our hams did to get CircuitLab enabled (or, for that matter, their request for MathJax).

• In the interim it might be worth to check if this is even compatible with MathJax (because clearly this requires an entirely different script to be implemented). The answer might be simple, and it might be a simple "no". – Asaf Karagila Jul 25 '17 at 8:53

I think TikZ rendering would be a great asset to the site. Well-made pictures can be an enormous aid in learning, from diagrams for path integrals in complex analysis to this image illustrating the proof of the Cantor–Schröder–Bernstein Theorem in set theory. Commutative diagrams in particular are essential in areas such as algebra, algebraic geometry, algebraic number theory, and algebraic topology. To my knowledge, the only package for commutative diagrams currently supported by MathJax is amscd, which is very basic and leaves a lot to be desired. (There are already quite a few threads dedicated to finding work-arounds for this limitation: 1, 2, 3.)

To show that there is demand for TikZ rendering, here are some answers that use images generated by TikZ or the commutative diagram package tikz-cd. (Please feel free to add more.)

Commutative diagrams:

Other pictures:

Here are some to which I might add diagrams if TikZ were supported on the site (and if I were not so lazy).

It's true that I can create an image using TikZ and then upload it, but this is a bit inconvenient (and again, I'm lazy). To do so, I have to:

1) Start my LaTeX editor; 2) Create a new file; 3) Create the image itself; 4) Crop the PDF and save it as a PNG; 5) Upload it to Stack Exchange; 6) Futz around with the size and make sure it looks okay.

Having TikZ support on the site would eliminate all but step 3 (and maybe 6), which would make me much more apt to include pictures in my answers.

In response to quid's comment:

You’re right that in theory steps 1, 2, and 5 take little time. But I’ve been a bit charitable to myself and only included the steps I have to take. Here are all the steps I usually take:

1) Find the TeX file for the most recent image I uploaded to Stack Exchange; 2) Open it and begin modifying it to make a new picture; 3) Realize I forgot to duplicate the file and have instead overwritten it; 4) Duplicate the file and begin modifying it again, while reverting the changes in the old file and recompiling it; 5) Create the new image; 6) Open the PDF in Preview since Adobe Acrobat Reader does not support cropping (the free version available for Mac, anyway); 7) Crop the picture; 8) Try to upload it to Stack Exchange; 9) Realize that although I cropped the image, I forgot to export it as a PNG; 10) Open the image in Preview again and export it as a PNG; 11) Upload the file to Stack Exchange; 12) Futz around with the size and make sure it looks okay.

You might think I’m exaggerating, and it’s true that I don’t make all these mistakes every time I make a picture. But I almost always make at least one (either 3-4 or 8-9).

The resizing part of step 6 of the original list can also be pretty time-consuming. Now that I’ve made a few images, I can finally remember the trick of putting an “m” after the file name to make the picture medium-sized without having to search for one of the meta posts on how to resize images. But sometimes even that doesn’t work well (it didn’t in this one since the figure became too small), and I have to go searching for how to set the picture dimensions exactly using HTML.

• Just a minor remark about the Cantor--Bernstein theorem proor you suggest is clearer with the drawing, it's actually clearer when you first work under the assumption that $B\subseteq A$, and then deduce the general case. Sure, it doesn't lend itself to this "cross-beam drawing", but it is clearer. One can also use the Knaster--Tarski fixed point theorem to simplify this a bit more as well. – Asaf Karagila Jul 25 '17 at 5:11
• How does the time needed for the steps compare? I usually do not write complicated posts, but if I would I think I'd do 1, 2, 5 for a post without images too. (Where by 5 I mean copy-paste the source.) – quid Jul 25 '17 at 11:11
• @quid I've edited to address your question. Regarding your last sentence, I almost never open my LaTeX editor for Stack Exchange posts unless I’m making an image. If I’m very concerned about losing a long post, I submit the partial answer and then immediately delete it, so I can continue to edit and save it without cluttering the front page. Once I’m done editing, I undelete. – André 3000 Jul 25 '17 at 16:19
• This submit, deleted, continue to edit is poor practice. While it is not explicit in your comment it was in your post that you do so not to clutter the frontpage. But guess what, you do clutter it! If you do not believe it, see why the reopen thread is on the frontpage now. And the more complex functionality we have the more it might happen that lots of tinkering with the post happens as preview does not cut it anymore . This is actually a concern of mine re this feature. Further, I do not see where you actually answer my question re the relative use of time. – quid Jul 25 '17 at 17:22
• Can you exaggerate even more with the editing process? How about steps 13--600 where you have to battle the ghosts of all the fallen generals from WW2, as well as Stalin, Bismarck, and Nero? What about step 601 which is essentially Ragnarok, where you have to be eaten by Fenris in order to save the Allfather and keep the realms together? – Asaf Karagila Jul 25 '17 at 18:18
• @quid I’m sorry to hear that this still clutters the front page. I can see that you modified the reopen thread, but not how: I assume you edited a deleted answer. Anyway, I’ll try to avoid it in the future. Usually I just copy all the text of my post before hitting submit so I can paste it back in if my browser crashes. – André 3000 Jul 26 '17 at 0:29
• @quid Regarding time, the first sentence of my edit was: “You’re right that in theory steps 1, 2, and 5 take little time.” I don’t know the number of seconds or minutes I spend on each part, but I invite you to try it yourself if you are so-inclined. I certainly think the bulk of the time is spent creating the image, but the cropping and resizing is not trivial, either. – André 3000 Jul 26 '17 at 0:29
• @AsafKaragila The entire point of this longer list is that while in theory the process may be simple, in practice there are many little hiccups and time-sinks that can occur, many of which would not be apparent to someone who has not tried to do it themselves. So Asaf, when was the last time you made an image in TikZ and included it on a post in Stack Exchange? These are problems I have run into myself while creating some of these graphics. – André 3000 Jul 26 '17 at 0:30
• Oh, I'm still fighting the WW2 generals ghosts for posting my first one. – Asaf Karagila Jul 26 '17 at 5:32
• Well, as long as I do not know at all how long it takes you roughly to create such an image to check how long it takes to open a file will not tell much about the relative time needed. I will admit though that actually that sentence did not fully register; otherwise I would phrased my comment differently. Sorry about that. Yet I truly have little idea how long it takes to create (you) the image, as I do not do this myself with any regularity. All that said, I still feel that you have some illusions how smoothly it would work if the thing would be integrated on the site. – quid Jul 26 '17 at 8:15
• For one thing, at times you would I assume still want to start on an existing image. So rather than to search the file locally you would (a) search it among your posts here, which may or may not be simpler. Then you would need to transfer it. So you would need to (b) click edit on the old post, to (c) copy the source I assume. Then you need to (d) go back to the new post and (e) insert it. There you might forget (d) and rather (d') actually start to edit the old post (d'') realize your mistake in the worst case (d''') roll back the old post (d'''') apologize for having created a mess. – quid Jul 26 '17 at 8:22
• Then (f) actually create the image, (g) check it looks good in the preview (h) change it as it does not lock good in the preview, then sometimes maybe (i) realize the preview stopped working (j) copy out or save the source (k) refresh the page or restart the browser (l) continue with the editing etc. More seriously, I can imagine some advantages to it being integrated here, but that it would work that smoothly in comparison to doing it locally seems like wishful thinking to me. – quid Jul 26 '17 at 8:28
• @quid: You forgot to mention the neuron firing to pass information to the muscles to move the hand, the fingers, and so on, between each of the steps. These take time too, ya'know! – Asaf Karagila Jul 26 '17 at 10:11
• @quid I think we’ve misunderstood each other. The reason I start with an existing file is so that I get the preamble with all the packages I usually need. I typically delete all the markup for the image and start from scratch. I always do with this when I make a new LaTeX file, regardless of whether or not I use TikZ. But I have no need to look through my old posts when I write a new post, and I wouldn’t have to for making new images either, since presumably most of these packages would automatically be included, just like they are for regular LaTeX. – André 3000 Jul 26 '17 at 21:08
• Indeed, I have misunderstood this. In this case maybe just put one sample file on the desktop? Also, why is 3 a problem if you never reuse the files anyway? Alright I am not quite serious in continuing this, and got a bit carried away. :-) I think I'll just stand by: "I can imagine some advantages to it being integrated here, but that it would work that smoothly in comparison to doing it locally seems like wishful thinking to me" Thank you, for compiling the list of posts; it makes a good basis for the discussion. – quid Jul 26 '17 at 23:44

One concern I have over implementing this feature is exactly how it would be set up on the site vis-à-vis comments. By intention comments on Stack Exchange sites allow only a very limited subset of Markdown markup (italics, bold, italic bold, inline code, and links). However a side effect of the way MathJax is set up on MathJax-enabled Stack Exchange sites is that comments on these sites also "allow" MathJax. This may often be useful, but at times we get very MathJax-laden comments with numerous displayed equations which end up looking more like (mini-)posts than how comments were intended. For example (some details changed to protect the innocent):

As it is, I am mainly "meh" about this feature request: it might be something nice to have, but I feel it will be of only very limited utility on the site compared to the overhead required. But TikZ-laden comments make me nervous, and this is something I decidedly do not wish to see on the site. Unless this could be implemented in a way so that TikZ does not render in comments, I would be against implementing such a feature.

• I guess that one way to ensure that is to make the TiKZ code wrapper about 500 characters long, and this way you only have 100 characters for the actual content, which won't be too much, I hope. :P – Asaf Karagila Jul 25 '17 at 6:55