# Major Section Heading

## Math

I’ll begin with a demonstration of typesetting mathematics with Markdown, and demonstrate basic text formatting at the same time. In the expressions below, the number of filters is N f N f
, the flux associated with the i i
th filter is F i F i
, and the weight, w i w i
, is defined as

w i≡σ−2 F,i,w i≡σ F,i−2,

where σ F,i σ F,i
is the uncertainty in the flux associated with the i i
th filter. Assume that all sums range from i=1 i=1
to i=N f i=N f
and use the summation convention on repeated indices. Note that we strike things out like this, italicize things like this or like this, and we can make things bold like this or like this.

Unfortunately, –> and => do not turn into arrows automatically, but you can make arrows like this →→
and ⇒⇒
. You can also implement a Pandoc filter to add features that are not built-in. So, it would be possible to make –> turn into →→
and introduce new features, such as Graphviz graph rendering. For examples of such filters, check out this list (or keep reading this document).

Here’s a horizontal line / separator:

## Table Creation

There are many ways of creating tables. This is an example of the pipe table creation syntax…

Label | Description
--- | ---
`meanflx` | ⟨F⟩=1 N f∑i F i⟨F⟩=1 N f∑i F i
`wmeanflx` | ⟨F⟩w=F i w i∑i w i⟨F⟩w=F i w i∑i w i
`rmsflx` | √⟨F 2⟩w=√F 2 i w i∑i⟨F 2⟩w=F i 2 w i∑i

Here’s one more example, with a table caption:

Demonstration of simple table syntax.
Right | Left | Center
--- | --- | ---
12 | 12 | 12
123 | 123 | 123
1 | 1 | 1

Refer to the documentation to learn more about the other types of tables.

## Line Blocks

Normally, adjacent lines are combined together, so a set of short formatted lines, such as an address or verse, becomes jumbled. To overcome this, place `|` at the beginning of each line, followed by a space. This preserves the formatting:

I am the very model of a modern Major-General, I’ve information vegetable, animal, and mineral, I know the kings of England, and I quote the fights historical From Marathon to Waterloo, in order categorical I’m very well acquainted, too, with matters mathematical, I understand equations, both the simple and quadratical, About binomial theorem I’m teeming with a lot o’ news, With many cheerful facts about the square of the hypotenuse. I’m very good at integral and differential calculus; I know the scientific names of beings animalculous: In short, in matters vegetable, animal, and mineral, I am the very model of a modern Major-General.

Note the indentation on the final two lines above.

## Inserting an Image

Images are inserted using the following syntax. Captions are optional.

This is a caption. Captions are optional. Just leave the square braces empty to omit the caption

## Block Quotes

The syntax for block quotes is extremely simple:

> You can write a block quote by putting a single ‘`>`’ at the beginning of a block of text or by placing the ‘`>`’ at the beginning of each line of the quoted block, similar to the way e-mail readers handle quoted messages.

## Enumerated lists

1. You can use integers or the `#` symbol in enumerated lists.
2. This is quite convenient. For example,
   1. You don’t have to count
   2. If you want to change the order, no numbering needs to be changed
3. You can also use roman numerals, obviously.

## Example Lists

1. This is Example (1).

2. This is Example (2).

Now we discuss something for a while and introduce the third example…

3. This is Example (3).

You can refer to an example by its label. For instance Example (2).

## Syntax Highlighting

### A Python syntax highlighting example:

You can include blocks of pre-formatted text, like this. If the text is source code, you can tell Pandoc to perform syntax highlighting. This is graphviz.py:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    #!/usr/bin/env python

    """
    Pandoc filter to process code blocks with class "graph" into
    graphviz-generated images.
    Requires pygraphviz, pandocfilters
    """

    import os
    import sys

    import pygraphviz

    from pandocfilters import toJSONFilter, Para, Image, get_filename4code
    from pandocfilters import get_caption, get_extension, get_value

    def document_name():
        if "PANDOC_INPUT_FILE" in os.environ:
            return os.environ["PANDOC_INPUT_FILE"]
        else:
            return "graph"

    def graphviz(key, value, format, _):
        if key == 'CodeBlock':
            [[ident, classes, keyvals], code] = value
            if "graph" in classes:
                caption, typef, keyvals = get_caption(keyvals)
                prog, keyvals = get_value(keyvals, u"prog", u"dot")
                filetype = get_extension(format, "svg", html="svg", latex="pdf")
                dest = get_filename4code(document_name(), code, filetype)

                if not os.path.isfile(dest):
                    g = pygraphviz.AGraph(string=code)
                    g.layout()
                    g.draw(dest, prog=prog)
                    sys.stderr.write('Created image ' + dest + '\n')

                image = Image([ident, classes, keyvals],
                              caption,
                              [dest, typef])

                return Para([image])

    if __name__ == "__main__":

        toJSONFilter(graphviz)

### A C++ syntax highlighting example:

Here’s another example using a different programming language (and a different method of specifying the pre-formatted text block).

    14
    15
    16
    17
    18
    19
    20
    21
    #include <iostream>

    int main()
    {
        // comment
        std::cout << "Hello, World!\n";
        return 0;
    }

## An example of the power of filters (graphviz.py)

This is an example of a feature that was added using a Pandoc filter (refer to the Python code above). Plain Pandoc does not automatically render Graphviz syntax to inline images, but the short Python program above adds this feature.

This was generated using the graphviz.py filter.

A diagram showing how this document is compiled, using a filter:

This demonstrates how filters work. They perform actions on Pandoc's abstract syntax tree (AST).

A singly-linked list.

A doubly-linked list.

A binary tree.

Note how this is rendered with `prog=neato`, instead of `prog=dot`, which is the default. Other options are `twopi`, `circo`, `fdp`, and `nop`:

Star network topology.

Ring network topology.

Fully-connected mesh network topology.

And one more, just because these are so fun…

A tiny neural network.

## Compiling this with Pandoc

To convert1 this Markdown document to HTML, I used the following command:

    # BTW, this is a Bash syntax highlighting example.

    $ pandoc example.md -s --smart --mathjax \
             --css nrstyle.css \
             --highlight-style pygments \
             --columns=200 \
             --filter graphviz.py \
             -o example.html

### An explanation of each parameter (as a bulleted list)

- `example.md`: the input file
- `-s`: create a stand-alone document (rather than a document fragment that lacks a header).
- `--smart`: automatically replace `--`, `---`, and `...` with –, —, and … and handle quotation marks properly.
- `--mathjax`: use the MathJax library for typesetting math in HTML documents.
- `--css nrstyle.css`: Use the nrstyle.css stylesheet in the HTML output document.
- `--highlight-style pygments`: Turn on syntax highlighting and use the pygments color scheme.
- `--columns=200`: set the line length to 200. This makes the tables display properly.
- `--filter graphviz.py`: Pass Pandoc’s abstract syntax tree through the filter program `graphviz.py` before rendering the output document.
- `-o example.html`: Specify the name and type of the output file. The format is inferred from the suffix (file extension).

### The same explanation, formatted as a definition list

`example.md`

  The input file

`-s`

  Create a stand-alone document (rather than a document fragment that lacks a header).

`--smart`

  Automatically replace `--`, `---`, and `...` with –, —, and … and handle quotation marks properly.

`--mathjax`

  Use the MathJax library for typesetting math in HTML documents.

`--css nrstyle.css`

  Use the nrstyle.css stylesheet in the HTML output document.

`--highlight-style pygments`

  Turn on syntax highlighting and use the pygments color scheme.

`--columns=200`

  set the line length to 200. This makes the tables display properly.

`--filter graphviz.py`

  Pass Pandoc’s abstract syntax tree through the filter program `graphviz.py` before rendering the output document.

`-o example.html`

  Specify the name and type of the output file. The format is inferred from the suffix (file extension).

1. This is a footnote.↩