decksh is a domain-specific language (DSL) for generating deck markup.
decksh elements
- decksh overview
- decksh object reference
- Installing and Running decksh/pdfdeck
- Repository of decksh projects and visualizations
The Process function reads decksh commands from an io.Reader and writes deck markup to an io.Writer, returning an error.
For example:
Produces:
This repository also contains cmd/decksh, a client decksh command:
decksh reads from the specified input, and writes deck markup to the specified output destination:
Typically, decksh acts as the head of a rendering pipeline, where another deck client renders the markup. This example uses pdfdeck
decksh hello, world:
produces:
This deck script:
Produces:
Text, font, color, caption and link arguments follow Go conventions (surrounded by double quotes).
decksh (like the deck markup it produces) uses a traditional Cartesian coordinate system: The origin (0,0) is at the lower left, x increases to the right, and y increases upwards. The coordinate system is expliticly based on the percentages, with x and y ranging from 0-100. For example (50, 50) is the middle of the canvas, (100,100) is the upper right, (100,0) is the lower right, and (0,100) is the upper left.
Colors formats are:
- RGB: "rgb(n,n,n)", where n ranges from 0-255, for example ""rgb(128,0,128)" .
- hex: "#rrggbb", for example "#aa00aa",
- HSV: hsv(hue,saturation,value), hue ranges from 0-360, saturation and value range from 0-100, for example "hsv(360,30,30)" (pdfdeck and pngdeck support this syntax)
- SVG color names.
Color gradients (used for slide backgrounds and rectangle and square fills) are specified as color1/color2/percent, for example, "blue/white/90"
Coordinates, dimensions, scales and opacities are floating point numbers ranging from from 0-100 (representing percentages of the canvas width and percent opacity). Some arguments are optional, and if omitted defaults are applied (black for text, gray for graphics, 100% opacity).
Canvas size and image dimensions are in pixels.
Fonts may be:
- "sans"
- "serif"
- "mono"
- symbol"
Note that doc/edoc and page/epage are may also be used as synomyms for deck/edeck and slide/eslide.
id=<number> defines a constant, which may be then subtitited. For example:
The special identifier, deckshVersion contains the string denoting the version of decksh.
id+=<number> increment the value of id by <number>
id-=<number> decrement the value of id by <number>
id*=<number> multiply the value of id by <number>
id*=<number> divide the value of id by <number>
Addition id=<id> + number or <id>
Subtraction id=<id> - number or <id>
Muliplication id=<id> * number or <id>
Division id=<id> / number or <id>
Modulo id=<id> % number or <id>
a=x%10
Assign (x,y) coordinates to the specified identifier. The x coordinate is id_x and the y coordinate is id_y. The expression with the parentheses may be a constant, variable or binary expression.
This code:
makes this:
Return the polar coordinate given the center at (cx, cy), radius r, and angle theta (in degrees)
Return the polar coordinates (p_x) and (p_y) given the center at (cx, cy), radius r, and angle theta (in degrees)
The keyword dump causes a sorted list of variables and their values to be printed on standard error.
For example, given:
Produces:
You can also specify that specific variables are shown, dump x y shows:
return the circular area, a for the diameter d.
Assign a string variable with formatted text (using package fmt floating point format strings). Up to five variables may be used.
Large numbers may also be formatted with commas using the %, format string. For example:
assign a random number in the specified range
decksh supports these math functions:
- cosine
- sine
- square root
- tangent
return the coine of the number of expression (id or binary operation)
return the sine of the number of expression (id or binary operation)
return the square root of the number of expression (id or binary operation)
return the square root of the number of expression (id or binary operation)
For value v, map the range vmin-vmax to min-max.
assigns a substring given beginning and ending indicies.
- may be used as a shorthand for the beginning and end.
Loop over statements, with x starting at begin, ending at end with an optional increment (if omitted the increment is 1). Substitution of x will occur in statements.
Loop over statements, with x ranging over the contents of items within []. Substitution of x will occur in statements.
Loop over statements, with x ranging over the contents "file". Substitution of x will occur in statements.
Specify the conditional execution of decksh statements with if condition, else and eif. The else block is optional. The values for v1 and v2 may be either numbers of strings. (For strings only == and != apply). The conditions are:
For example:
The else block may be omitted:
For strings:
places the contents of "file" inline.
Functions have a defined name and arguments, and are specifed with statements between the def and edef keywords
Functions may be imported once, and then called by name.
For example, given a file redcircle.dsh:
which is referenced:
makes:
Functions may also be called with the func keyword:
For example, given a file "ftest.dsh"
calling the function:
produces:
makes a file named foo.d with the lines between data and edata.
The first file argument ("file.dsh" above) specifies a file with decksh commands; each item in the file must include the arguments "x" and "y". Normal variable substitution occurs for other arguments. For example if the contents of file.dsh has six items:
The line:
creates two rows: three circles and then three squares
x, y specify the beginning location of the items, xskip is the horizontal spacing between items. yinternal is the vertical spacing between items and limit the the horizontal limit. When the limit is reached, a new row is created.
Left, centered, end, or block-aligned text or file contents (x and y are the text's reference point), with optional font ("sans", "serif", "mono", or "symbol"), color and opacity.
Text rotated along the specified angle (in degrees)
Text on an arc centered at (x,y), with specified radius, between begin and ending angles (in degrees). if the beginning angle is less than the ending angle the text is rendered counter-clockwise. if the beginning angle is greater than the ending angle, the text is rendered clockwise.
Place the contents of "filename" at (x,y). Place the contents of "filename" in gray box, using a monospaced font.
Plain and captioned, with optional scales, links and caption size. (x, y) is the center of the image, and width and height are the image dimensions in pixels.
(plain, bulleted, numbered, centered). Optional arguments specify the color, opacity, line spacing, link and rotation (degrees)
Rectangles, ellipses, squares, circles: specify the center location (x, y) and dimensions (w,h) with optional color and opacity. The default color and opacity is gray, 100%. In the case of the acircle keyword, the a argument is the area, not the diameter.
Rounded rectangles are similar, with the added radius for the corners: (solid colors only)
For polygons, specify the x and y coordinates as a series of numbers, with optional color and opacity.
Note that the coordinates may be either discrete:
or use substitution:
A combination of constants and substitution is also allowed.
Polyline is similar to polygon, except line segments are used instead of a filled polygon, and you may specify a line width.
For lines, specify the coordinates for the beginning (x1,y1) and end points (x2, y2). For horizontal and vertical lines specify the initial point and the length. Line thickness, color and opacity are optional, with defaults (0.2, gray, 100%).
A "pill" shape has is a horizontal line with rounded ends.
Curve is a quadratic Bezier curve: specify the beginning location (bx, by), the control point (cx, cy), and ending location (ex, ey).
For arcs, specify the location of the center point (x,y), the width and height, and the beginning and ending angles (in degrees). Line thickness, color and opacity are optional, with defaults (0.2, gray, 100%).
To make n-sided stars, use the "star" keyword: (x,y) is the center of the star, np is the number of points, and inner and outer are the sizes of the inner and outer points, respectively.
Arrows with optional linewidth, width, height, color, and opacity. Default linewidth is 0.2, default arrow width and height is 3, default color and opacity is gray, 100%. The curve variants use the same syntax for specifying curves.
Left, right, up and down-facing braces. (x, y) is the location of the point of the brace, (aw, ah) are width and height of the braces's end curves; linewidth, color and opacity are optional (defaults are 0.2, gray, 100%)
Left, right, up and down-facing brackets.
(x, y) is the location of the center of the bracket. For left and right-facing brackets, width is the size of the top and bottom portions, and height is the span of the bracket. For upward and downward-facing brackets, width is the span of of bracket, and height is the size of the left and right portions. linewidth, color and opacity are optional (defaults are 0.2, gray, 100%)
Run the dchart command with the specified arguments.
Show a colored legend