Skip to content

phpre/tikz-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tikz-cpp

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.

Components

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_repn breakpoint 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 ))
    • 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 ))
  • 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_string data structure to represent a string to be displayed either just by its name or by its individual characters
    • tikz_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: vertex for all kinds of different ways to style a vertex of a graph; print_vertex(...), print_arrow(...). print_selected_arrow(...)
      • vertex_grid for producing (and printing) a set of 2D tikz-coordinates on which vertices or other objects may be placed

Build Instructions

  • A make instruction
    • builds the library libtikzcpp.a.
    • for each file src/<>.cpp in src/, produces an executable <> (linking in libtikzcpp.a) and runs <> (which is supposed to write *.tex files into the figs/ folder.
    • compiles each file figs/{}.tex into out/{}.pdf using latexmk and LuaLatex.
  • make out/lib/libtikzcpp.a generates just the library
  • make clean removes all intermediate files, but not the outputs in out/

Usage

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.cpp generates Figures 3 to 7.

    [CKW25, Figure 3] [CKW25, Figure 4]

About

cpp code to generate tikz pictures

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages