Skip to content

Collection of various implementation of SAS and Stata highlighting

Notifications You must be signed in to change notification settings

macropeople/highlight-sas-stata

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Highlight SAS and Stata

SAS and Stata, while relatively simple to highlight, are not popular enough to be part of most highlighting packages. I use them quite extensively, however, and recently my RA work has required me to document work that uses SAS and Stata. Since I like pretty documentation, I have had to implement SAS and Stata highlghting in a variety of places.

Implementations

This repo contains SAS and Stata highlighting implementations for

  • Pygments, a syntax highlighter written in python. I wrote this to use with minted, a LaTeX code highlighter uses pygments.
  • Listings, a LaTeX implementation of syntax highlighting.
  • Highlight.js, a syntax highlighter written in JavaScript. (SAS only; Stata was already available).

This project started with me using listings and minted from LaTeX. Since I code in vim, I also wrote a short script to highlight code in LaTeX using the appropriate syntax/<lang>.vim. See here.

Minted is a LaTeX package that uses pygments to highlight code. Pygments is quite complex and has a lot of options, but this means highlighting here should be free of any issues. I added sas.py and stata.py styles to match the SAS and Stata editors (styles are just a list of types and colors, so defining them is quite easy).

The pull request was accepted into the main branch for pygments 2.2; you can try highlighting code on the pygments project website.

I used to use this before I discovered minted and pygments. Defining a package is extremely hard because the implementation is in TeX and it has all those limitations. I include it here because not everyone can or wants to go through installing pygments, but the drawback is that there will be highlighting quirks and errors I am unsure how to deal with.

To install, from a bash prompt

localtexmf=`kpsewhich -var-value=TEXMFHOME`/tex/latex/local
mkdir -p $localtexmf
cp -s $PWD/listings/lstsas.tex   $localtexmf/lstsas.tex
cp -s $PWD/listings/lststata.tex $localtexmf/lststata.tex

Now add this to your preamble

\input{lstsas}
\input{lststata}

This already had Stata support. I added SAS support only, mainly to use with Redmine. Defining the languages was pretty simple, and it should be mostly fine, but I don't think I have as fine-grained control as with Pygments. I did add sas.css and stata.css styles to match the SAS and Stata editors (styles are pretty straightforward CSS files).

I opened a pull request but it hasn't been accepted. To install, first install highlight.js. Then from a bash prompt

hljs=/path/to/highlight.js
cp -s $PWD/highlight.js/test/detect/sas/default.txt $hljs/test/detect/sas/default.txt
cp -s $PWD/highlight.js/src/languages/sas.js $hljs/src/languages/sas.js
cp -s $PWD/highlight.js/src/styles/sas.css   $hljs/src/styles/sas.css
cp -s $PWD/highlight.js/src/styles/stata.css $hljs/src/styles/stata.css
cd $hljs
node tools/build.js -n <list-of-languages>

About

Collection of various implementation of SAS and Stata highlighting

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 46.8%
  • TeX 42.2%
  • JavaScript 6.5%
  • CSS 1.9%
  • SAS 1.6%
  • Stata 1.0%