|
| 1 | +--- |
| 2 | +title: Documentation Tools |
| 3 | +description: Tools supporting the documentation of Lingua Franca code. |
| 4 | +--- |
| 5 | + |
| 6 | +## Code Highlighting with Pygments |
| 7 | + |
| 8 | +[Pygments](https://pygments.org/) is a Python library for highlight code snippets in various languages. There is a [plugin](https://github.com/lf-lang/lf-pygments-lexer) for LF code highlighting available. This provides a tool for automatically generating beutiful LF code listings in a range of [styles](https://pygments.org/styles/) and in various output formats such as PNG, SVG, and HTML. It also integrates with LaTeX. |
| 9 | + |
| 10 | +### Installation |
| 11 | + |
| 12 | +We recommend to use a virtual environment to install the plugin and all its dependencies. |
| 13 | +There are several tool for managing virtual environments available. For instance: |
| 14 | +``` |
| 15 | +virtualenv ~/virtualenvs/lf-lexer -p python3 |
| 16 | +source ~/virtualenvs/lf-lexer/bin/activate |
| 17 | +``` |
| 18 | +You can also skip this step if you prefer installing the package in your user environment. |
| 19 | + |
| 20 | +To install the plugin, the following commands: |
| 21 | +``` |
| 22 | +git clone https://github.com/lf-lang/lf-pygments-lexer.git |
| 23 | +cd lf-pygments-lexer |
| 24 | +pip install. |
| 25 | +``` |
| 26 | + |
| 27 | +### Usage |
| 28 | + |
| 29 | +#### Command Line |
| 30 | + |
| 31 | +Pygements provides a CLI tool called `pygmentize`. For example, you can use it to produce an image containing highlighted LF code like so: |
| 32 | +``` |
| 33 | +pygmentize path/to/Example.lf -o out.png |
| 34 | +``` |
| 35 | +Note that pygments automatically selects the right language. For this it processes both the file extension and the target declaration in it. |
| 36 | +Therefore, auto detection works as long as your file uses the `.lf` suffix and contains a valid target declaration. If auto detection does not work as expected, you can to specify the language using the `-l` flag. For instance to use the Python target of LF, use `-l lf-py`. |
| 37 | + |
| 38 | +See the [pygments documentation](https://pygments.org/docs/cmdline/) for more detailed usage instructions. |
| 39 | + |
| 40 | +#### LaTeX |
| 41 | + |
| 42 | +Most prominently, pygments is used by the [minted](https://ctan.org/pkg/minted?lang=en) LaTeX package to create beautiful code listings with proper code highlighting. |
| 43 | +Using this is as simple as adding `\usepackage{minted}` and then adding `minted` blocks containing the code to be highlighted. |
| 44 | +There is an example document available [here](https://github.com/lf-lang/lf-pygments-lexer/blob/main/example/example.tex). |
0 commit comments