A cpp library to generate tikz code. Featrures are added as needed; the whole library may be considered at an alpha state, so use at your own risk.
All of the files below are in lib/.
- General utility
fragmentco.h: data structure for a closed-open interval of integers (fragmentco)breakpoint.h: alignments between strings (breakpoint,breakpoint_repnbreakpoint representation)- Compute an optimal (breakpoint representation of) an alignment between two strings (
breakpoint_repn compute_breakpoints( const std::string& p_P, const std::string& p_T )) - Compute a slice of an alignment (
breakpoint_repn breakpoint_slice( const breakpoint_repn& p_brpts, fragmentco p_frag )) and the image of a fragment under an alignment (fragmentco align_fragment( const breakpoint_repn& p_brpts, fragmentco p_frag) - Normalize a breakpoint representation to start with (0,0) (
breakpoint_repn breakpoint_normalize( const breakpoint_repn& p_brpts ))
- Compute an optimal (breakpoint representation of) an alignment between two strings (
ag_slice.h: slices of the alignment graph of two strings (graph_slice), see [CKW25, Definition 4.3]; for each slice store its status as pure, top, bottom, primitive.- generate a list of slices from an alignment (
static std::deque<graph_slice> graph_slice::from_alignment( const breakpoint_repn& p_brpnt, u32 p_d )) - merge a list of slices into a new slice (
static graph_slice graph_slice::merged_slice( const std::deque<graph_slice>& p_primitiveSlices, fragmentco p_fragment )) - group/merge a list of primitive slices into a sequence of one top, several pure/non-pure, and onte bottom slice (
static std::deque<graph_slice> graph_slice::top_pure_bot_decomp( const std::deque<graph_slice>& p_primitiveSlices ))
- generate a list of slices from an alignment (
- General tikz Utility
tikz_util.h: useful defines and type aliases/tikz_document.h,tikz_picture.h,tikz_command.h: classes and structures to build a representation of a (set of) tikz pictures.tikz_option.h:tikz_option,kv_store: general utility for representing key-value tikz options (and their dependencies on libraries/packages)tikz_color.h:color, default color aliases.tikz_point.h:tikz_point,tikz_position, general utility to work with positions.
- Application-specific tikz Code Generation
tikz_stylized_string.h:stylized_stringdata structure to represent a string to be displayed either just by its name or by its individual characterstikz_string.h: generate pictures involving string or sequence data.void print_[vertical_]string( FILE* p_out, const stylized_string& p_S, tikz_point p_StopLeft ): writes tikz code to print the given string (vertically).void print_matched_string_pair( FILE* p_out, const stylized_string& p_P, tikz_point p_PtopLeft, const stylized_string& p_T, tikz_point p_TtopLeft, color p_bgColor ): prints two strings inside of a "glow bubble" and addes thin lines between matching pairs of characters. (See [CKW25, Figure 4, colored boxes] for an example.)void print_separator( FILE* p_out, tikz_point p_PtopLeft, tikz_point p_TtopLeft, color p_color ): prints separator of a breakpoint representation (withoult a label; See [CKW25, Figure 4] for an example)std::pair<tikz_point, tikz_point> print_alignment( FILE* p_out, const stylized_string& p_P, tikz_point p_PtopLeft, const stylized_string& p_T, tikz_point p_TtopLeft, const breakpoint_repn& p_brpnt ): prints an alignment between two strings. (See [CKW25, Figure 4] for an example.)vertex_grid print_alignment_graph( FILE* p_out, const std::string& p_P, fragmentco p_fragP, const std::string& p_T, fragmentco p_fragT ), prints the alignment graph of two strings (without the string labels). (See [CKW25, Figure 3] for an example.)void print_alignment_on_coordinates( FILE* p_out, const vertex_grid& p_vg, const breakpoint_repn& p_brpnt ): prints an alignment into a given alignment graph as a path of colored arrows. (See [CKW25, Figure 3] for an example.)
tikz_graph.h: generate pictures involving graphs- basic utility:
vertexfor all kinds of different ways to style a vertex of a graph;print_vertex(...),print_arrow(...).print_selected_arrow(...) vertex_gridfor producing (and printing) a set of 2D tikz-coordinates on which vertices or other objects may be placed
- basic utility:
- A
makeinstruction- builds the library
libtikzcpp.a. - for each file
src/<>.cppinsrc/, produces an executable<>(linking inlibtikzcpp.a) and runs<>(which is supposed to write*.texfiles into thefigs/folder. - compiles each file
figs/{}.texintoout/{}.pdfusinglatexmkandLuaLatex.
- builds the library
make out/lib/libtikzcpp.agenerates just the librarymake cleanremoves all intermediate files, but not the outputs inout/
Below is a list of publications that uses this library for its figures, as well as example figures from said publications (reproduced with permission; note the original copyright).
- [CKW25]; file
src/2025-10.cppgenerates Figures 3 to 7.
![[CKW25, Figure 4]](https://private-user-images.githubusercontent.com/5598893/513755445-1b379ef3-4cc4-4fa2-b3a7-264a9e04197f.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjYwODMwMjEsIm5iZiI6MTc2NjA4MjcyMSwicGF0aCI6Ii81NTk4ODkzLzUxMzc1NTQ0NS0xYjM3OWVmMy00Y2M0LTRmYTItYjNhNy0yNjRhOWUwNDE5N2YucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MTIxOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTEyMThUMTgzMjAxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9N2ZiYzg0YjBmYjRhZTRiMjhhYzg4Mjk2YWU4YmE4ZjBkNjQyZDhjZTk2NmEzNGY1ZTNiNTBiMmE3ZmZkM2NmYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.wq4bZn8-o-xOoylWag5hF56FzBAhwpjTJcoF9I3ObUs)