50

Although this question might have an opinion-based factor, it is still important for newcomers since it also treats the workflow with LaTeX. Currently, I use LaTeX to write my papers and make my block diagrams or other figures on draw.io since it makes this process pretty fast and simple.

However, I could notice that many researchers have a full-based LaTeX workflow since they use TikZ to produce vector graphics. I tried it out and I find it as terribly complicated as LaTeX in general. Apparently, I am not the unique who sees LaTeX as an unnecessarily complicated and confusing typesetting system. However, On the one hand, I do see an advantage in using LaTex regarding citation, references, and mathematical equations. On the other hand, I do not see any advantage in using Tikz as I wasted a huge amount of time making a simple diagram, which could be done much faster on draw.io (or another platform) without any loss.

Probably, there is a good reason for many researchers to adopt Tikz and I would really like to know what it is.

15
  • 21
    TikZ allows the use of document macros (and its mathmode), uses the document's fonts and produces vector graphics. Not all external tools do all three. (There are some that produce PG/TikZ code, though.) Commented Oct 9, 2022 at 16:07
  • 13
    It is the same as with everything else: once you spent enough time with a certain tool, you will be quick in using it as is becomes more and more continent to you. To me, one benefit of using TikZ/PGF is, that I can draw pretty exact stuff, just as with professional graphics tools but for free, while using ”tools“ such as MS PowerPoint is more or less not possible to get exact results. Commented Oct 9, 2022 at 16:16
  • 6
    @JohnKormylo shh, don't let David hear that! 😉
    – Rmano
    Commented Oct 9, 2022 at 21:11
  • 8
    @Rmano too late Commented Oct 9, 2022 at 22:31
  • 6
    @DanielDiniz I think this question is much more focused than the one that was closed, which is much more of a rant about LaTeX more generally. Here Rubem (the OP) is already a LaTeX user but is asking about workflow, which I think is not necessarily opinion based, since (as the answers I think attest) people can justify their particular workflows on somewhat objective terms. It's definitely more opinion based than many answers on the site, but I think we have a good set of answers that might prove helpful to others (which was the OP's intention).
    – Alan Munn
    Commented Oct 10, 2022 at 14:08

10 Answers 10

64

For me, the reason I prefer TikZ is the same reason I prefer LaTeX: Preserving the original source code of the document is as important — if not more important — than preserving the compiled document.

I assume that every document I write will need to be edited, and this hasn't been too far off in my experience. I use LaTeX because it lets me express my document in a high-level, semantic, easily-editable manner. I can tweak the formatting, layout, and even structure of my documents by tweaking macro definitions. It's programming for documents.

I take the same approach for diagrams. Having the diagram is great, but I don't just want the diagram — I want to preserve how I created the diagram in a high-level, semantic, easily-editable manner. The diagram will need to be tweaked, and if all I have is an image artifact — even an SVG artifact — I can't make fundamental changes to the formatting, layout, and structure of the diagram without essentially starting over.

Tools like Inkscape are better than simple drawing tools like Paint, because at least they let you save and tweak the definition of the diagram. (This may include the draw.io tool you mentioned. I've never tried it, so I don't know.) But they have the same problem that word processors like Word have — they tie formatting and structure to the content. Inkscape and Word just don't have nearly as powerful tools of abstraction as TikZ or LaTeX, respectively. TikZ, like LaTeX, is a programming language.

With TikZ, I can describe the nodes of a graph, including their relative positions, and I can tag them with arbitrary keys and values. I can separately tie formatting (including LaTeX formatting) to those keys and values. I can define lists, ranges, values, etc., and build the TikZ diagram dynamically from those lists, ranges, and values. And what pushes TikZ above other programmatic diagram programming languages (e.g., Diagrams in Python or Mermaid in JavaScript) is that the TikZ source code lives inside my LaTeX document and treats all my LaTeX macros and definitions as first-class citizens. So all my font and style choices are automatically used.

It's been pointed out elsewhere that, since modern LaTeX implementations like LuaLaTeX and XeLaTeX support system fonts, it's easy to have a tool like Inkscape use the same font choices, but there are additional benefits beyond simply using the same font. For one, TikZ will automatically use the same font, so I only have to change it in one place and it can't get out-of-sync. Also, the font is just one variable of style — there's spacing, widths, enabled ligatures, and that TikZ can use LaTeX's math mode.

All that said, TikZ is complex, and I often do have to read a lot of documentation to figure out how to express what I want in TikZ — much like I do in LaTeX! They both suffer from the same complications and difficulties of macro programming, and TikZ has its own peculiarities with its key-value configuration system. It's a trade-off, and sometimes it's very tempting to use a WYSIWYG tool to create diagrams. But I generally stick with TikZ because I know that, once I've put in the work to create the diagrams, it will be worth it for all the reasons I've described above.

11
  • 1
    There's also the option of using a WYSIWYG editor that produces TikZ code. Commented Oct 11, 2022 at 5:17
  • 8
    @MartinArgerami but that normally generates a code with is unmaintainable --- lots of numerical coordinates, no logical names, no "structure" to that. Not very different from having it in svg or even pdf...
    – Rmano
    Commented Oct 11, 2022 at 8:36
  • 1
    @user3067860 SVG it's definitely human editable, but unless someone wrote document by hand, it's usually computer-generated gibberish. (At least in my experience.) Commented Oct 11, 2022 at 19:05
  • 3
    @user3067860 SVG could be human readable, with comments and convenient IDs, a sensible coordinate grid, and with all the formatting abstracted into a nice <style> tag at the top. But if you created it with Inkscape, it isn't. Sure, you can open it as a text file, but the fact that it's stored as text and not as binary doesn't make it any more readable in itself. Commented Oct 11, 2022 at 20:15
  • 1
    @Polygnome I don't consider being able to edit the diagram in another application the same as having the source code inline. If I want to share the document now I need to make sure they have access to the same application, plus now we need to synchronize the PNGs or whatever we're now both creating. Inline source code is automatically shared with the LaTeX source code, and can be versioned with useful commit messages and diffs. And if a web application like draw.io goes down or shuts down you're SOL. Commented Oct 12, 2022 at 22:48
62

Well, complexity depends on the point of view and the familiarity with the tool. Let's see an example: this took exactly 3 minutes (ok, I have snippets in my editor, which saved me maybe 2 minutes... and being proficient with an editor is always a good thing whatever tool you use):

\documentclass{article}
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\begin{document}
\newcommand{\mya}{2}

I have a nice parabola:
\[ y = \mya x^2 + 3 x + 1 \]
which is drawn like:

\begin{tikzpicture}
    \begin{axis}[width=6cm,
        xmin=-3, xmax=3,
        ymin=-10, ymax=10,
        domain=-10:10,
        samples=100,
        axis x line = center,
        axis y line = center,
        xlabel = {$x$},
        ylabel = {$y$},
        ]
        \addplot[blue, thick] {\mya *x*x + 3*x +1 };
    \end{axis}
\end{tikzpicture}
\end{document}

parabola

...and now I can change the document consistently by just changing the value of the \mya macro.

This is why TikZ (and derivatives, like pgfplots and circuitikz and many others) are helpful. I never found an external tool so well integrated that let me have, say, 16 different documents in almost no time.

This is the main value of the tools you are asking about, in my opinion. They are fully integrated, you can use variables (macros, etc.) from your main document, and you can generate a document where you can tweak a couple of parameters, and you do not need to redraw anything. I use them a lot to prepare exams and exercises for my students!

And even if you do not use variable parameters, you have diagrams and graphs that inherit the characteristics of the document --- fonts, etc. In the example above, if you change the preamble to use, say, Palatino fonts, the graph labels will follow with no intervention needed.

Yes, the learning curve is a bit steep sometimes (but not so much, really). Tit for tat...

PS — writing this post was quite more time-consuming than making the example.

7
  • 6
    Also, besides font size, the widths of plotted lines and axes remain consistent throughout the document if plots are scaled.
    – AlexG
    Commented Oct 9, 2022 at 19:13
  • 17
    +1 for all the main good points about TikZ’s strengths — but the throwaway line “ok, I have snippets in my editor, but who doesn't?” is unhelpful. This kind of “Well, doesn’t everyone know how to do all the things that make it easy?” can be quite discouraging for beginners looking at a steep learning curve from the bottom. Commented Oct 9, 2022 at 20:55
  • 7
    @PeterLeFanuLumsdaine, could be, but LaTeX is a macro language, and it's written using a text editor, so being proficient with it is a quite important step. I think that all people I know that use MS Word daily use ctrl-b to bold text, and not the mouse interface.... Anyway, I edited it to be less "throwaway", I hope.
    – Rmano
    Commented Oct 9, 2022 at 21:07
  • 11
    @Rmano As an anti-MS-Word rant: at my German workplace, I couldn't use ctrl+B to bold text, because in the German localised version, it's ctrl+F instead (German fett instead of English bold). In LaTeX I never have such silly problems.
    – gerrit
    Commented Oct 10, 2022 at 8:23
  • 1
    @gerrit, you probably can do it by calling SymPi on the "program" formula, but then in general you'll have sub-par formatting... formatting and calculating an expression are different task. About the MS-thingy: yeah, here too, it's ctrl-G in Spanish. That, and the translation of formulas in Excel are the reason why I install my OS with Irish locale...
    – Rmano
    Commented Oct 10, 2022 at 11:16
21

I loved using TikZ and my arguments are:

  1. Trivial usage in version control system (Git or Subversion). You have human-readable diffs, the code is small (compared to XML or binary formats)
  2. Changes are easy, don't need to store original image files (Gimp, draw.io etc.) or conversion of file format. Just edit the code, commit it, compile it.
  3. Workflow can be automated. I have my measurements as CSV and imported them with TikZ. If I had to change my experiment, I replaced the CSV with a new one. If a paper reviewer would have asked me to to adjust my graph, it would be no effort to re-create the graph and modify them. (bonus points for reproducability of data analysis)
3
  • 6
    Human-readable diffs are a big advantage for me too! In hand-made drawings, a revision like "Revert the color scheme changes from this morning, but keep the shape and spacing adjustments from this afternoon" can be very annoying.
    – Vectornaut
    Commented Oct 10, 2022 at 16:21
  • Point number 2: Is "do need" a typo for "don't need"?
    – Oskar Skog
    Commented Oct 11, 2022 at 9:43
  • @OskarSkog You are right, thanks!
    – usr1234567
    Commented Oct 11, 2022 at 10:00
19

Besides those existing good answers, I have some opinions to add.

I was an industrial designer. I always ensure I have complete control of the point, line, and plane (Kandinsky, W., & Rebay, H. (1979). Point and line to plane.) precisely so that all elements work well.

Now I am pursuing my Ph.D. (OR) and writing my papers daily with LaTex. Most of my figures and graphs are made with Tikz. The biggest disadvantage is that everything in Tikz is time-consuming compared with simple drawing tools.

But some subjective advantages are as follows:

  • I have full access to each element of everything in the graph;
  • I have more flexible options from LaTex Color;
  • I can synchronize the color, font type, font size, etc., in multiple graphs;
  • I can compose the text, format, figure, and graph in the same style (or as similar as I can);
  • I do not need to consider the picture format (.jpg, .png...) or size limit problems when uploading;
  • I do not need to worry about exporting graphs from other drawing tools.

As for the "Simple-Difficult" measurement of the drawing tools, I used to make complex graphs in Adobe Suite to ensure quality. Tikz actually saves my eyes and time...

I personally view the paper as a piece of design work. I enjoy using Tikz since it can help me achieve my goal.

13

There are pros and cons to using TikZ for everything, and I suspect that for most of us the range of tools is much broader than that. While everyone's needs are different I think we can learn from a variety of users' practice. But I think the basic issue is most people prefer simpler workflows to more complex workflows, and using multiple tools (even if the tools themselves are simple) makes the overall workflow more, not less complicated.

I use TikZ for some things, and not for others. I do experimental work whose data is analyzed using R, so I never use something like pgfplots for plotting, but instead generate my graphs using R and then use \includegraphics to include them. With tools like knitr you can also include the R code within your LaTeX document, and keep everything self-contained if you like, although personally I find this more trouble than it's worth.

On the other hand, much of my work also depends on drawing syntactic trees, and for this I use TikZ exclusively. Tree packages like forest and tikz-qtree allow for extremely simple input (a labelled bracketing) and then draw the tree for you. This is orders of magnitude simpler than any GUI tree drawing tool, for example.

For other sorts of diagrams, even quite simple ones, doing things in TikZ simply makes the workflow simpler: no need to keep multiple documents created with multiple tools around. Furthermore, many kinds of small diagrams lend themselves to becoming macros. They are often repeated in but with different parameters, and this sort of programmability is something that TeX is well suited for.

It's often stated that doing everything in TikZ allows better font matching compared to other external tools. While this is true for pdflatex, if you are using more modern engine like lualatex or xelatex then font matching is much less of a problem, since those engines can use any system installed font, and therefore you can always match fonts with graphics made using other tools. Certainly other kinds of things like line spacing etc. might be harder to match, but for things like axis and legend labels in a graph, this is usually not a problem.

8
  • 9
    To me, font matching doesn't just mean using the same typeface in text and images. It also means keeping font sizes consistent and typesetting mathematical symbols in the same way. Many external tools make the latter things very time-consuming, or even impossible.
    – Vectornaut
    Commented Oct 10, 2022 at 4:04
  • 2
    @Vectornaut Yes, I understand, and agree. A lot depends on the kinds of images you're creating and the kinds of documents as well. I don't think there's a one size fits all approach.
    – Alan Munn
    Commented Oct 10, 2022 at 4:48
  • I disagree with "more trouble than it's worth" with respect knitr. IMHO knitr allow a munch easier work flow that first work with R and then in LaTeX, specially if the document should be updated (e.g., periodical reports of some increasing data) and invaluable to track always where the results come from. Moreover, although that is secondary (at least for me) it can use a tikz device taking the fonts of the document but the typical LaTeX look an feel, without font inconsistencies.
    – Fran
    Commented Oct 11, 2022 at 1:26
  • 3
    @Fran Oh I can certainly see the value in it for some applications, but not everyone in our lab uses LaTeX, so it's easier to keep R stuff separately.
    – Alan Munn
    Commented Oct 11, 2022 at 1:58
  • 1
    I'm curious about the complexity of figures that users are generating with TikZ. I'm a geologist and often need to create very complex figures that use several plot types at the same time (images, line graphs, scatter plots, etc.) so Inkscape is my go-to and then I use \includegraphics to bring in the various PNGs I create. I certainly see the benefit to simplifying the workflow so was curious if people are actually generating complex SVG-type diagrams using only TikZ
    – JJGabe
    Commented Oct 11, 2022 at 17:08
7

Just adding my arguments to all the others:

  • My figures become parametrizeable from the document: I can use macros to set e.g. line colors -- and can quickly modify them after I discover that the contrast in print is completely broken (instead of opening n image/SVG files to manually change all the line colors).
  • I can even parametrize the data of a figure: Same TikZ code, but different CSV data can become two figures.
  • Scaling becomes a non-issue: Lines have still the same width after modifying the size of a TikZ canvas. If I were to do the same with SVG, I'd have to make all SVG figures the same width (or a fraction thereof, if that figure shall span only one column), else all line widths will be scaled with the SVG.
  • Text in the figures
    • is still copy-pastable from a resulting PDF,
    • uses the same font as the document by default,
    • is not subject to scaling when scaling the figure.
  • Figures can be inlined in the document.

In conclusion: The overall style of the figures match the style of the document better when I use TikZ. And I don't want to miss parametrizeable figures.

7

I'll add to the already comprehensive list of answers.

Doing something in a well established workflow is often a time and resource saver, even if the tool you choose to use is not optimal. Learning something new can take a while

Also, I think the advantages of code-based graphics have been touched on, but for truly complicated graphics, it can be a blessing. One overlooked advantage is that you can actually write code to generate the tikz code!! I haven't done this in tikz, but I have used the technique to great effect in electronic layout programs to make very complicated electronic PCB footprints with more than 100 pads. You're assured all the elements end up exactly where you put them, and when you make a mistake, you fix it and rerun the code to generate new tikz. In my use with electronics, this has saved me days of time, and I'm sure it would be a time saver for complicated tikz as well.

1
  • 1
    That was the best advantage I've read so far. It is incredible how many people overlooked it. The possibility of writing code to generate tikz code is stunning. Commented Oct 12, 2022 at 21:00
5

For me there are three main reasons:

  1. When done well it looks really good. In particular the fonts in the diagrams perfectly match the fonts in the document, in both size and in style. This is difficult to achieve using any other tool.

  2. I can keep everything in one place. If I use a non-tikz tool I have to edit the diagram separately, give it a file name and include it in the document. Then if I want to edit it, I have to first figure out which file I need to edit, and then open it in my external editor. If there are a lot of diagrams and I need to edit them all this can get very laborious. But if the diagrams are in tikz they are right there in the document and I can just edit them straight away.

  3. Drawing can be automated. If I have a lot of similar diagrams I can write macros to draw the common elements, so that the source code for each diagram only contains the parts that are unique to that particular diagram. Then if I want to change the style of the diagrams slightly, I only have to change it in one place.

5

My top 2 use cases for TikZ:

  1. When creating multilingual documents, I do the layout and drawings once and compile the same document for every language. A macro selects the text contents as a function of the language setting.

  2. The TikZ code is generated automatically by a Perl script according to data read from a data base. Especially in a context of PDFLaTeX and a web server, database reports containing graphics can be generated via a HTTP request, returning a PDF document to the user's browser.

4

I won't repeat the huge advantages in many scenarios of being able to "program" the appareance of a text, since it's already been mentioned.

The most useful characteristics for me are that it's a very stable system and whatever you write in LaTeX/TeX ends up being very much what you need on "paper" (or on PDF) in the utmost detail. Moreover it is free and open source.

However I feel somewhat your pain, since I am a programmer at heart (and I was one professionally in another life) and I teach programming in high school.

I'm not a good LaTeX programmer and I know TeX even less. This notwithstanding I find the system very good to create my own documents that need to be generated from "code".

The approach I take is a peculiar one: I build my documents as a mix of LaTeX and Lua code, so most of the "code" part is written in Lua, which is a more current programming languages, with cleaner semantics and syntax. This allows me to generate fragments of LaTeX code which, written by hand, could require much more effort (and knowledge of the intricacies of the LaTeX/TeX duo).

In this approach TikZ is a fantastic tool, since it allows so much control of the rendered graphics. Yes, it is mind-blowingly complex, so I never got to learn everything (I've read the first part of the manual, about the high-level interface of the package, but I remember a tenth of it). However any complex drawing task I could hope for is there.

I've never found an alternative that meets all my requirements:

  • The text to be rendered is written in textual format (text file), not in some proprietary format, that can be easily generated/modified by a computer program

  • The text can include code to express graphical operations.

  • It is free and open source, so my sources won't be locked-in in the future.

If you think this latter can't happen, I have direct proof of it: when I was at the Uni I helped one of my professors to rewrite the course notes, to which I gave also some original contribution. All files where in Word 2.0 format. After 5 years I couldn't find a program that could open them without messing them up. Even Word 6.0 couldn't open them without messing up completely most of the figures!!! The same happened with my thesis, written in Word 6.0 doc format. I can't open it in a modern libre-office without having problems with that.

You must log in to answer this question.

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