drawing binary trees in markdown

BG-flavoured markdown

Mardown BG (.mdbg) is an improvement of the existing Mardown language.

It provides nice features which make it possible to generate a fresh, correct and nice .tex document.

About

Usage

You can install mdbg easily with pip :

This will make the mdbg command available :

              >              mdbg usage: mdbg [-h] [--output OUTPUT] [-m              |              -b] [-T              |              -M              |              -H]                  [--title TITLE] [--date DATE] [--author AUTHOR]                  [--packages PACKAGES] [--documentclass DOCUMENTCLASS]                  [--roboto] [--disabletoc] [--minted MINTED]                  INPUT

To make things easier, you can create a bash function in your ~/.bash_profile (for example) :

              function              cpbg              { 	mdbg              $1.mdbg --title=                "                $2                "                            lualatex --shell-escape              $1.tex 	lualatex --shell-escape              $1.tex 	rm              $1.aux              $1.log              $1.out              $1.toc rm              $1.tex 	open              $1.pdf 	}

Alternately, you can use a Makefile like this one to compile from IDEs like SublimeText or Atom.io :

              .PHONY:              .SUFFIXES:              COMP              = mdbg              OUT              = a_file              TITLE              = "An inspiring title."              PACKAGE              = "{{MyPack2}}"              AUTHOR              = "Me"              DOCUMENTCLASS              = "report"              all:              $(COMP)              $(OUT).mdbg --title              $(TITLE)              --packages              $(PACKAGE)              --date              \\today --documentclass              $(DOCUMENTCLASS)              --author              $(AUTHOR)              lualatex --shell-escape              $(OUT).tex 	lualatex --shell-escape              $(OUT).tex 	rm              $(OUT).aux              $(OUT).log              $(OUT).out              $(OUT).toc 	rm              $(OUT).tex

Atom packages

mdbg comes with Atom support with these two packages :

  1. language-mdbg provides syntax highlighting
  2. mdbg-snippets provides autocompletion

Syntax

Markdown-flavoured

Headers

Like in markdown.

              # H1 ## H2 ### H3 #### H4 ##### H5 ###### H6                          
Non numbered sections

For non enumerated sections :

              #* H1 ##* H2 ###* H3 ####* H4 #####* H5 ######* H6                          

Emphasis

Translations :

Bold

In markdown :

In mdbg :

Underline
Italic

In markdown :

In mdbg :

Strikethrough

In markdown :

In mdbg :

Lists

Small changes have been made.

This is a list in mdbg :

              Neutral text :     - first item     - second item         - first second item         - second second item     - third item                          

and an enumerated list :

                              1. first item     2. second item         1. first second item         2. second second item     3. third item                          

The indentations can be four spaces or a tabulation but each item has to be idented.

Links

              [text for link](https://www.google.com)  [text for link](https://www.google.com "title for link")                          

Code

Like in Markdown.

Tables

Like Markdown, without the 2nd line.

In mdbg :

              | C11 | C21 | C31 | | C21 | C22 | C32 | | C31 | C32 | C33 |                          

Whereas in Markdown :

| C11 | C21 | C31 | | --- | --- | --- | | C21 | C22 | C32 | | C31 | C32 | C33 |

You can't chose text alignment for every cell but you can chose it for every row by adding the command !!tab followed by the alignments.

For example one possible table would be :

              !!tab r c l | C11 | C21 | C31 | | C21 | C22 | C32 | | C31 | C32 | C33 |                          

New !

Trees

Basic binary tree

Description :

  • Command : ![TREE]!
  • Root : R "text"
  • Node : N "text"
  • Leaf : L "text"
              ![TREE R "root" N "a node" L "a leaf" L "an other leaf" N "an other node" L "a leaf again !" N "a node again !" L  "OneWord" L "the last leaf"]!                          

If you want to draw an non strictly binary tree, you can write L () for an empty leaf

Non binary trees

Command : ![nTREE]!

              ![nTREE "A" -- {"B" -- {"H" -- {"N", "O"}, "I", "J"}, "C", "D", "E" -- {"K" -- "P", "L" -- "Q"}, "F", "G" -- "M"}]!                          

Graphs

You can draw graphs with a very simple syntax (the same as nTREE syntax).

This is made possible thanks to TikZ fantastic graphs and graphdrawing packages, with some of their libraries.

Command : ![GRAPH .............!]

With a possible !!option before ![GRAPH... line.

This option will be translated to \graph[<option>]... in LaTeX.

See pgfmanual for more information about the syntax.

You can also base your graph on the example given in the section Examples

New text features

Superscript

You can use text in superscript :

              We live in Paris, in the 5^{th}                          
Subscript

You can use text in subscript :

              This is a normal text_{this one is subscripted}                          
Footnotes

This is how to use footnotes :

Colored texts

How to use colored texts :

              I love {red}[red] and {green}[blue witten in green] !                          

A list of all possible colors is given at the end of this readme.

Center environnement

You can center some text or some figure with this :

Miscellaneous

Add a ! at the begining of a line to have a \noindent before this line in the LaTeX generated file.

Add a / at the end of a line to have a line break.

Examples

Trees

The command ![TREE R 1 N 2 F 3 F 4 F 5]! produces the following result in LaTeX :

Binary tree

the command ![nTREE A -- {B -- {H -- {N, O}, I, J}, C, D, E -- {K -- P, L -- Q}, F, G -- M}]! produces the following result in LaTeX :

Multiple tree

Code

Those lines :

```ocaml              let              fg i =              2              * i +              1                              ;;              let              fd i =              2              * i +              2                              ;;              let              rec heapify a n i = match fg i, fd i with 	| g, d              when              g > n -> () 	| g, d              when              d > n ->              if              a.(i) < a.(g) then swap a i g 	| g, d ->              if              a.(i) < a.(g) || a.(i) < a.(d) then begin              let              k =              if              a.(g) > a.(d) then g              else              d in swap a i k                ;                heapify a n k end;;              let              heap_sort a =              let              n = ref (vect_length a -              1) in 	for k = !n downto              0              do              heapify a !n k 	done                ;                            while !n <>              0              do              swap a              0              !n                ;                            decr n                ;                            heapify a !n              0              done                ;;              ```

Will produce this :

Some code in ocaml

Graphs

              !!layered layout ![GRAPH "5th Edition" -> { "6th Edition", "PWB 1.0" }; "6th Edition" -> { "LSX", "1 BSD", "Mini Unix", "Wollongong", "Interdata" }; "Interdata" -> { "Unix/TS 3.0", "PWB 2.0", "7th Edition" }; "7th Edition" -> { "8th Edition", "32V", "V7M", "Ultrix-11", "Xenix", "UniPlus+" }; "V7M" -> "Ultrix-11"; "8th Edition" -> "9th Edition"; "1 BSD" -> "2 BSD" -> "2.8 BSD" -> { "Ultrix-11", "2.9 BSD" }; "32V" -> "3 BSD" -> "4 BSD" -> "4.1 BSD" -> { "4.2 BSD", "2.8 BSD", "8th Edition" }; "4.2 BSD" -> { "4.3 BSD", "Ultrix-32" }; "PWB 1.0" -> { "PWB 1.2" -> "PWB 2.0", "USG 1.0" -> { "CB Unix 1", "USG 2.0" }}; "CB Unix 1" -> "CB Unix 2" -> "CB Unix 3" -> { "Unix/TS++", "PDP-11 Sys V" }; { "USG 2.0" -> "USG 3.0", "PWB 2.0", "Unix/TS 1.0" } -> "Unix/TS 3.0"; { "Unix/TS++", "CB Unix 3", "Unix/TS 3.0" } -> "TS 4.0" -> "System V.0" -> "System V.2" -> "System V.3"; ]!                          

Will produce this :

Graph example

Comprehensive list of colors

Colors

pgfmanual

Here is a link of a recent and accurate version of pgf-tikz manual.

It is used for trees and graphs in Markdown BG.

boucheroverearrever.blogspot.com

Source: https://github.com/yopox/mdbg

0 Response to "drawing binary trees in markdown"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel