statax
is a syntax highlighter for Stata. The packages includes two separate engines (JavaScript and LaTeX) to highlight Stata commands in HTML- and LaTeX-based documents. A plenty of Stata package produce documents or presentation slides in HTML and LaTeX and the engines can simply be wired to these packages to highlight the syntax of Stata commands. For example,
weaver
and MarkDoc packages require statax
for syntax highlighting.
Long story short, syntax highlighters might improve code comprehension and encourage learners to pay more attention to the
code.
You can directly download Statax from GitHub. Check the release page for the curent version and new features.
net install statax, from("https://raw.githubusercontent.com/haghish/statax/master/")
The complete guide for installing them is provided in the MarkDoc help file and also, Statax Homepage
statax
can acurately distinguish several different elements in Stata syntax such as:
- commands
- functions
- local and global macros
- strings
- numbers
- operators
- comments
- curly brackets
The JavaScript engine is hosted on my website and can be easily added to any webpage. See Statax Homepage for details. in brief, all you have to do to load the javaScript in your HTML document is adding the following code:
<script type="text/javascript" src='http://haghish.com/statax/Statax.js'></script>
And writing your Stata code in:
<pre class="sh_stata">
. Stata code
. Stata code
...
</pre>
The LaTeX syntax highlighter is even easier to implement. All you need to do is loading the Statax.tex in the header of your latex document, before you \begin{document}
as shown below:
\input{Statax}
Once the Statax file is loaded in the header, You can call the statax environment to highlight the Stata syntax. For example:
\begin{statax}
// JavaScript Syntax Highlighter for Stata
quietly erase "`This' $Example"
noisily do `Something'
forvalues num = 5/13 {
count if vari`num' > 10 //this is a comment
scalar 5 = 2 * 10
generate x = runiform()
}
/*
E. F. Haghish
Center for Medical Biometry and Medical Informatics
Unersity of Freiburg, Germany
*/
\end{statax}
E. F. Haghish
Center for Medical Biometry and Medical Informatics
University of Freiburg, Germany
haghish@imbi.uni-freiburg.de
http://www.haghish.com/weaver
@Haghish