Writing with Markdown in Stata
| Quick Tips |
| Introduction |
| Syntax |
| Example |
| Download Template |
Quick Tips
Several packages such as MarkDoc, Weaver, and ketchup have been written for Stata to make Markdown codes available for Stata. Markdown provides a simple solution for writing and styling text as well as adding graphs and links to a document. In this document I will introduce you to Markdown and provide several example about how to style text and add graphs using markdown
Introduction
Markdown is a plain text syntax used for formating text. It was developed in 2004 by John Gruber to simplify HTML writing. In other words, Markdown is a text-to-HTML convertor that converts specific text symbols to XHTML codes. Markdown uses symbols to simplify these tags and as a results, has gained a lot of popularity for writing in blogs, websites, and online forums. In addition, many software have attempt to make use of Markdown codes for writing and styling text.
Writing in HTML format requires using a lot of tags, for example, to write a heading you should place text between <h1> and </h1> below I write a few more examples to give you an idea about writing with HTML codes. In the examples below, the HTML tags are highlighted in blue color and the black color text is the actual text that appear in the document.
Thus, âMarkdownâ is two things: (1) a plain text formatting syntax; and (2) a software tool, … that converts the plain text formatting to HTML. The overriding design goal for Markdownâs formatting syntax is to make it as readable as possible. The idea is that a Markdown-formatted document should be publishable as-is, as plain text, without looking like itâs been marked up with tags or formatting instructions. – J. Gruber
But how does Markdown simplify styling text in a plain-text formatted document? Here is an example about writing in HTML format. To give you a taste of writing in HTML format, I will introduce you to introduced the
â It is clear that Markdown significantly improve the readability of the document and simplify styling it. If you are interested to learn more about Markdown visit http://daringfireball.net/.
You can also practice Markdown syntax in the online Markdown simulator.
Syntax
One reason for popularity of Markdown code is that the syntax codes are only a few which I explain them below. These codes are applicable in Weaver, MarkDoc, and Ketchup packages in Stata.
In the example above, the “MyLink” is the hyperlinked text, i.e. the text that appears in the document. The “optional title” is the title that pops up if you keep your mouse cursor on it for a couple of seconds. Try it by holding your cursor on MyLink for a few seconds.
â Note that there should be no space between the
Inserting a graph in the document is very similar to creating a link. The difference is that the image begin with
Also pay attention to the file suffix (in this example, .jpg) that should be specified otherwise, markdown does not recognize the file that you are trying to import. Just to give you an example, I import an image named “smallheart.jpg” to this page using  because my Stata-Blog website is actually reading Markdown codes. In this example, I have used the absolute path of the file which shows where on the server my graph is. If my graph was in the same folder as my HTML file, then writing  would have been enough. Obviously the relative paths are shorter and easier to write. More importantly, the relative paths are dynamic i.e. if you move the HTML and the image to a different folder (but keep them in the same folder) the graph still appears in your document. If you wish to create this graph yourself, right click and download the graph code here.
The Markdown syntax for adding headings is very simple. Adding the
Writing a text paragraph is the simplest thing using Markdown because it does not have any syntax. More excitingly, you can always press the enter key and move on to the next line without breaking the paragraph. The enter key does not break the line. To break the line, you should end the line with 2 or more spaces.
Adding three or more dashes or asterisks will be converted to a horizontal rule which is defined as <hr /> in HTML.
Adding an indent to a normal Markdown file would be interpreted as a “code block” in HTML. In Stata, this interpretation has been ignored. Stata packages that can interpret Markdown codes, Ketchup and MarkDoc both ignore this interpretation and remove indents, unless indents are used to style braces, where indents improve readability of the code.
Example
For Stata packages that read Markdown text, the text has to be inserted within comment signs to tell Stata that the text is not meant to be executed. If you want to write only one line of text, the
However, if you wish to write more thext, the text should be inserted between
Example Template
The example template uses the codes of the graph, “I Love Stata” and uses both MarkDoc and Ketchup packages to read the codes and export them to docx (for microsoft word) and HTML.