Hacker News new | past | comments | ask | show | jobs | submit login
Tikz.net – Graphics with TikZ in LaTeX (tikz.net)
199 points by JohnHammersley on Aug 21, 2021 | hide | past | favorite | 43 comments



I use this for many of my conference presentations, and I've used it for published papers as well as my dissertation.

I love that I can build up a diagram from specific constructs using macros. For instance, if I'm expressing a lot of linked lists, I can define a single macro for how I want to express "route the next pointer from the previous element around this element to the following element by arcing over this element", and do that consistently throughout the document.

I love that I can easily express "draw a line from 30° above the axis on this object to 150° around the axis on this object", and TikZ will connect those in a smooth way no matter where the objects are placed.

I love that I can express "create a point at the intersection of this line and this curve, and let me reference that point by name later".

It's a programming language, and a powerful one. I recommend it for any non-trivial diagramming or schematic task.

All that said, for cases where you need to express semantics and not worry as much about how the result looks, and you want the simplest possible way to express "connect a to b to c, and b to d, and d to c and back", and not worry about where the nodes are placed, I recommend graphviz. Graphviz is great for "let me dump the structure of this program's data structures out as text and turn it into a diagram". The biggest distinguishing factor between graphviz and TikZ, for me, is node placement and style: if you care how it looks and where nodes are placed, use TikZ; if you don't, use graphviz.


You can also use a syntax similar to Graphviz' dot language within TikZ, and either position the nodes manually or, as with Graphviz, let TikZ position them automatically with a choice of layout algorithms. You use LuaTeX, and the layout is calculated by a Lua program:

https://lwn.net/Articles/640302/

So you can get the best of both worlds, doing everything within TikZ/LuaLaTeX.


Interesting! I've seen things like that before with TikZ, but they required enabling \write18, which I didn't want to do. Using LuaTex support sounds much more appealing. I'll have to give that a try next time I build a diagram.


I've used tikz a bit, and the results do look very good, but it sure takes a lot longer than just whipping up a graphic in any other graphics software


Yeah, I tried to get into tikz in grad school, and found myself baaasically relearning it from scratch every time I wanted to do something. A 'bicycle of the mind' it is not.


> you want the simplest possible way to express "connect a to b to c, and b to d, and d to c and back",

TikZ has an easy to use DSL for expressing graphs :) you can write

    \graph a -> {b, c} -> d;
and it will produce something like

    a –– b -- d
      \     /
       \ c /


I am a heavy user of tikz and had a love-hate relationship with it. Have been using it since 2009. It takes time to learn and easy to forget.

Documentation is so great that you are sure you will find an answer. TeX.SE is also very helpful. The quality of graphics produced is stunning that I never manage to like alternatives. The control it gives you over your drawings is enormous. Heck, I can have Sam font in my text and diagram!

I remember spending 5 hours on the first drawing I made in Tikz for a research paper. My coauthor was amused. He thought it would have taken max 30 mins if I used a 'normal tool'. But he was impressed by neatly rotated text, scaling and alignment. Pity that I coundnt play with colors since IEEE accepted b/w images back then.

Love it or hate it, nothing come remoty close to it when you have mastered it. Something akin to vim editor. Huge respect for Till Tantau.


Tikz is fantastic if you know exactly what you want to draw. However in the case of many academic papers and presentations, the author doesn’t know exactly what they want to draw until after most of the graphics are made - only then can you observe some changes that can be made to make everything more consistent (not consistent with respect to line widths, colours, and whatever, I mean more consistent as in “tells a consistent story”). Tikz is awful for this - the amount of time one has to spend trying to edit a single graphic is so so much higher than with any other visual vector graphics program (Inkscape, Ipe, Illustrator, etc). It means that for many people, even if something looks out-of-place in the larger context of a paper or presentation, they won’t change it because it’s too hard. If you spent 20 minutes making a graphic with any other tool, then down the road if you feel it would be done better a completely different way, it’s fine to chuck it out and go again. With Tikz, making graphics can take much longer (this is doubly true if your edits are taking place outside of that one week you had Tikz loaded into your brain), and authors are much more reluctant to throw away work to improve a final result.

It’s because of this that I think working with Tikz (or other very-high-friction-for-most-people tools) is to the detriment of the end product. Being able to be agile, especially when displaying technical and complicated graphics, is paramount to those graphics ending up good.


There is a sister package PGFPlots that you can use to plot figures. It produces high quality figures, in my view much better than matplotlib, in part because it’s integrated with latex.

It’s worth mentioning that drawing complex diagrams with Tikz can take time. You need to code such that the plot is flexible if later you make a change, as much as possible.


There's a gallery that gives a nice overview with examples and compilable code: https://pgfplots.net


For plotting I prefer the latex output of Gnuplot, the graphs are still integrated but you have all the power of Gnuplot.


The advantage of GnuPlot is speed, and for quick 2D plots from terminal. It’s the fastest plotter that I have seen.

The output is also good, more so with latex terminal. However, Tikz/PGFplots is much more adjustable, has broader scope, and overall a much better tool for plotting.

GnuPlot syntax is also archaic, and documentation is scant.

As mentioned above, you can use GnuPlot backend to compute the function. At that point, pgfplots is well positioned to render an excellent plot!


pgfplots can use gnuplot as backend with pgf and TiKZ as frontend.


I've found it best to use GeoGebra to draw what you want, and then export as PGF/TikZ. You can then edit the code to make any modifications rather than writing TikZ from scratch.


Thank you for the tip, TIL.


Using TikZ in your (La)TeX document is great for a number of reasons:

* Fonts and line widths are always correct. It looks really unprofessional when your figures have completely different fonts and line widths to the rest of your document,

* Symbolic/declarative description of figures. No need to guess or manually calculate where an equidistant point is or how to draw an arrow between two points, you can just write it down. Your figure will be perfect, not "close enough",

* Ability to write macros and other stuff you would expect from programming your figures.


For those interested, there is a fairly basic WYSIWYG editor for this: http://www.tikzedt.org/

It's useful to throw together basic 2d diagrams, which can then be refined later


I think there's some xfig to tikz converters laying about (xfig being a pretty limited vector format) pretty sure I've used one before with good results (though i might be thinking of fig2pdf)


Used this all the time for graph theory papers in college. Works astoundingly well for that use case, highly recommend.

Beware though, if you include too many graphs in a paper it will take longer than Overleaf's free compilation time limit, so consider compiling locally.


This doesn't work on Overleaf, but locally this setup has saved me quite some time:

    % Tikz caching (use make -f main.makefile to rebuild figures).
    \usetikzlibrary{external}
    \tikzexternalize[mode=list and make,prefix=tikzcache/] % Comment out this line to disable caching.
    \newcommand{\includetikz}[1]{%
        \tikzsetnextfilename{#1}%
        \tikzpicturedependsonfile{#1.tikz}%
        \input{#1.tikz}%
    }
I would have all Tikz sources in a tikz/ directory, and include them where needed using e.g. \includetikz{tikz/foo}. Then the above would add an extra step to the compilation (make -f main.makefile), but in return all images would only be recompiled as necessary and otherwise included as a cached .pdf.


Nice; do you by chance combine this with latexmk? If so, how do you add the extra compilation step in latexmk?


I don't use latexmk, so I wouldn't know sorry. If you can incorporate it into latexmk you might even be able to use it on Overleaf.


I usually generate large tikz graphics independently using standalone tex files. Then include them in the paper as image files as usual.

Reduces the clutter inside the paper tex file.


I once tried to create a custom deck of cards in LaTeX, but it was harder than expected. Then I found this German dude on the Internet who already made some beautiful templates with Tikz, with mana and everything... The result was so good that I couldn't believe it, LaTeX is such an old technology but still is delivering so much value.


Do you have the link to that project?



Every time I try and use this I have to look up the syntax. It does deliver stunning graphics when used right though.


You get used to the syntax, and it's very consistent for most things (some addon TikZ libraries seem to do their own thing though).


Hot damn! What good examples.

Two weeks ago I had only seen TikZ mentioned in passing, as something key which a publisher wasn't supporting in their pipeline.


I wish the computer science community would contribute to this project as much as the physics community does



Looking at it a bit closer, it appears to actually be a one-man effort.


I am always amazed by how much effort has gone into Tikz. However, I always end up reaching for a manual diagramming tool (Omnigraffle on the Mac), along with cutting and pasting snippets of typeset text using LaTeXit.

I saw this tool on HN some time back and it seems to have evolved into a very promising product: LaTeX typesetting, manual drawing, programmable with Lua. The price seems excellent too ($25).

https://vexlio.com


I've used LaTeX extensively to write notes for my degree (math classes) and I can't stop recommending Tikz, it's one of the best parts of LaTeX. The Tikz/PGF manual [1] is absolutely great, as I could find solutions there for most things I wanted to do. There's support for 3D plots too, cached compilation (tikz-external IIRC), and quite a lot of useful libraries. I managed to do pretty complex drawings, and all of that integrated into the rest of the text.

If you write LaTeX, invest some time in learning Tikz if you need to do a drawing, it's worth it.

1: https://www.bu.edu/math/files/2013/08/tikzpgfmanual.pdf


I want nothing more than the MathJax version of this. edit: well evidently there's this: https://tikzjax.com/ although it turns out to be Pascal compiled to Webassembly.


It is Pascal, which is then used to compile the original TeX code. See example of running TeX/LaTeX at [1].

PGF/TikZ is a very well written program. What impresses me is that it does have the right amount of abstraction. It comes in different layers, starting from the Front End (TikZ), Basic Layer (which TikZ) uses This layer is built on top of the system layer. Whereas the system layer just provides the absolute minimum for drawing graphics, the basic layer provides numerous commands that make it possible to create sophisticated graphics easily and also quickly.

The basic layer does not provide a convenient syntax for describing graphics, which is left to frontends like TikZ. For this reason, the basic layer is typically used only by “other programs”. For example, the beamer package (can be used for presentations) uses the basic layer extensively, but does not need a convenient input syntax. Rather,speed and flexibility are needed when beamer creates graphics

The system layer, and drivers then create the the graphics in various formats, such as postscript, pdf etc.

[1] https://tex.rossprogram.org/


It's quite amazing the things you can do with TikZ. Often times I start with an idea for an illustration but it seems too daunting. Then I start writing the code, it begins to take shape, and in the end it's usually easier than I expected. Some times I have to use linear algebra to calculate coordinates though, so it's definitely not for everyone.


Did you look at MetaPost? It's especially suitable for task like that since it has a build in linear algebra solver.


I used CircuiTikZ when I taught a circuits course. The figures turned out so well, it was nice to be able to have such a uniform and portable representation.

I suspect starting from TikZ proper would make some of the wiring easier; there's a lot of naming nodes and connecting between them that seemed unintuitive, and like I always missed an easier way to draw a circuit.


TikZ is great, but this website ... On the frontpage the animation swapping out the diagrams all the time makes it really hard to read anything for me ... it's great they want to show many different things, but maybe some carousel one can manually scroll through or something would be nicer.



The about page https://tikz.net/about/ is not like about page. I still don't know what TikZ is after reading this page.


It is about the site itself. But I agree with you and added a short information about TikZ with a link to TikZ on GitHub.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: