On The Importance Of Syntax Highlighting For Teaching Statistics

E. F. Haghish Center for Medical Biometry and Medical Informatics (IMBI) University of Freiburg, Germany and Department of Mathematics and Computer Science University of Southern Denmark

[email protected] 1 Introduction Syntax coloring, also called syntax highlighting, provides a visual aid for pro- grammers by altering the appearance of lexical elements (e.g. changing color, font, font style, etc.) in the program. Syntax highlighting is merely secondary notation or cognitive dimension (Green 1989; Green and Petre 1996), which pro- vides perceptual cues for humans regarding the syntax and in turn, improves the readability of the code (Hendrix et al. 1998; Cross et al. 1999; Baecker and Marcus 1989). Consequently, it helps writing syntactically correct programs (Myers et al. 2004) and improves program comprehension (Gilmore and Green 1988; Kankuzi and Ayalew 2008). However, the effect is smaller for experienced (Sarkar 2015; Dimitri 2015), which underscores the importance of syntax highlighting for teaching newbies and developing educational materials. Nevertheless, the only third-party syntax highlighters available for Stata are limited to text editors, which cannot be used for coloring syntax of the code in documents. The statax package fills this gap by providing JavaScript and LATEX engines for highlighting the syntax of Stata code in HTML and LATEX documents respectively. The package is hosted on https://github.com/haghish/Statax and can be installed as shown below. The installation will copy the engines to the PLUS directory, however, the engines can also be downloaded from GitHub without installing the Stata package.

. net install statax, /// from("https://raw.githubusercontent.com/haghish/statax/master/")

2 statax engines 2.1 LATEX engine The LATEX engine is a single file named Statax.tex. It can be included in the header of the LATEX document or Beamer slides using \input{/path/to/Statax.tex}. Any Stata code that is placed within the statax environment will be highlighted after typesetting the document:

\begin{statax}

1 ... \end{statax}

2.1.1 JavaScript engine In order to install the JavaScript engine, the Statax.js should be added to the document. Websites and blogs that publish tutorials about Stata, can simply install the engine by including the following code in the HTML header:

or if the engine in located on the disk, the source path can be specified instead e.g. src="/path/to/Statax.js". Stata code that is placed within

 tag is highlighted:

 ... 

3 Customization For altering the default coloring theme of statax three CSS and tex themes were developed, which are sunset, daring, and wrangler. The themes only define the colors used for coloring the code background, keywords (commands), functions, local and global macros, string characters, numbers, and operator signs. Therefore, they can serve as a simple example for the users to edit the files and implement their own colors. In LATEX documents, the theme should be added after the Statax.tex engine e.g. \input{Sunset.tex} which redefines the default colors. Similarly, the CSS file should be linked to the HTML document after calling the JavaScript engine to redefine the theme colors:

If the CSS files are stored locally, the local address of the CSS file should be specified e.g. href="/path/to/Sunset.css".

4 Discussion There are several Stata packages that produce HTML or LaTeX files and can get benefit from statax syntax highlighter for developing appealing educational materials. For example, both JavaScript and LATEX engines are already imple- mented in weaver (Haghish 2014b) and markdoc (Haghish 2014a) packages for developing dynamic analysis documents. Programmers who wish to include the engines in their packages can get the path to the engines using findfile command and include them in the header of the HTML or LATEX document. Due to its simple installation and customization, statax can be easily added to blogs, websites, forums, or LATEX documents to facilitate newbies’ code com- prehension and makes the educational materials more appealing for learners.

2 Examples of statax implementations and template files can be downloaded at http://www.haghish.com/statax/statax.php.

5 References Baecker, R. M., and A. Marcus. 1989. Human Factors and Typography for More Readable Programs. New York, NY, USA: ACM. Cross, J. H., T. . Hendrix, K. S. Mathias, and L. A. Barowski. 1999. Soft- ware visualization and measurement in software engineering education: An experience report. In Frontiers in Education Conference, 1999. FIE’99. 29th Annual, vol. 2, 12B1–5. IEEE. Dimitri, G. M. 2015. PPIG 2015: The impact of syntax highlighting in Sonic Pi. In Proceedings of the 26th Annual Conference of the Psychology of Pro- gramming Interest Group (PPIG 2015), 59–68.

Gilmore, D. J., and T. R. G. Green. 1988. Programming plans and programming expertise. The Quarterly Journal of Experimental Psychology Section A 40(3): 423–442. URL http://dx.doi.org/10.1080/02724988843000005. Green, T. R. 1989. Cognitive dimensions of notations. People and computers V 443–460.

Green, T. R. G., and M. Petre. 1996. Usability analysis of visual program- ming environments: a cognitive dimensions framework. Journal of Visual Languages & Computing 7(2): 131–174.

Haghish, E. F. 2014a. MarkDoc: Literate Programming in Stata . URL http: //www.haghish.com/statistics/stata-blog/reproducible-research/ markdoc.. . 2014b. Rethinking Literate Programming in Statistics. URL http: //www.haghish.com/statistics/stata-blog/reproducible-research/ weaver.php. Hendrix, T. D., J. H. Cross, II, L. A. Barowski, and K. S. Mathias. 1998. Provid- ing Enhanced Visual Support for Software Development and Maintenance. In Proceedings of the 36th Annual Southeast Regional Conference, 23–28. ACM- SE 36. New York, NY, USA: ACM. URL http://doi.acm.org/10.1145/ 275295.275299. Kankuzi, B., and Y. Ayalew. 2008. An MCL algorithm based technique for comprehending spreadsheets. In 20th Annual Conference of the Psychology of Programming Interest Group, Lancaster, UK, 4–14. Myers, B. A., J. F. Pane, and A. Ko. 2004. Natural programming languages and environments. Communications of the ACM 47(9): 47–52.

3 Sarkar, A. 2015. The impact of syntax colouring on program comprehension. In Proceedings of the 26th Annual Conference of the Psychology of Programming Interest Group (PPIG 2015), 49–58.

4