Sunday, March 13, 2016

What should be included in "good practices" for Tikz 101

Beamer - What should be included in "good practices" for Tikz 101:  Stefan Kottwitz

"Use styles. Whenever you have color, shape, fonts, alignment, define a TikZ style for it and use it. Don't apply such formatting details to nodes or edges, apply the style. A single point for consistent customizing.

Inherit styles. Start with a base node style (font family, base color), define styles which use base styles and add size or color or alignment - no repetitions, single points for global changes.

Use macros. Have consistent TikZ commands or command sequences, which can be reused and changed.

Use constants. For every value needed, such as distances, declare a constant via \def or a TikZ length command, so you can use it repeatedly and adjust it at a single source code position to customize a whole drawing or a lot of drawings.

Use relative positions. So you can change a reference coordinate, and all other positions will be automatically adjusted.

Let TikZ calculate for you. Once certain points such as corners are defined, use TikZ syntax to define a relative positions such as middle points and intersection points. Let TikZ do the geometry for you. If you change the reference points or image size, all will automatically adjust.

Name everything. Especially in non-trivial drawings, edges between named coordinates are much clearer to read than using coordinate numbers everywhere.

Use scopes. Don't repeat things - if you cannot apply a bunch of properties via styles, use a scope to apply settings to a whole area of a drawing. Also here, it's easy to change that part at a single position.




Use loops. If you need to repeat things, benefit from the power of TikZ \foreach loops to reduce the amount of repeated code.



Don't nest TikZ pictures. There is always another way to do it."



'via Blog this'

No comments: