### `tagsnip` is a LaTeX package for including tagged code snippets from local files or remote URLs. It extracts marked sections of code and typesets them in a consistent style, supporting reproducible and maintainable documentation.
**Documentation:** tagsnip-docs.pdf **Czech documentation:** tagsnip-docs-czech.pdf > The documentation files also double as example documents for `tagsnip`. ## Installation `tagsnip` consists of two parts: 1. LaTeX package `tagsnip.sty`, 2. Python backend package `tagsnip`. Both parts are required. ### Installing the LaTeX package from CTAN Download the `tagsnip` package archive from CTAN and extract it. For a local project installation, copy `tagsnip.sty` next to your main `.tex` file: ```sh project/ ├── main.tex └── tagsnip.sty ``` This is the simplest installation method and is sufficient for compiling a single project. For a user-wide installation, place `tagsnip.sty` into your local TeX tree. Also see: https://ctan.org/pkg/tagsnip ### Installing the Python backend `tagsnip` uses a Python backend with the same name to parse source files. The backend is published on PyPI. Before using the LaTeX package, install the backend: ```sh pip install tagsnip ``` Also see: https://pypi.org/project/tagsnip/ After installation, the backend must be available in the system `PATH` under the command name `tagsnip`. You can check this with: ~~~sh tagsnip --help ~~~ ## Compilation ```sh lualatex --shell-escape docs/tagsnip-docs.tex ``` ## Usage **Example document:** docs.pdf `tagsnip` defines the command `\IncludeCode`, which is used as follows: ```tex \IncludeCode[options]{source}{tag}{language}{caption} ``` The optional argument `options` allows the user to override code formatting settings. These options are passed directly to `minted`, so they must be valid `minted` options and must be separated by commas. For example: ```tex \IncludeCode[ firstnumber=1, fontsize=\scriptsize, style=monokai ]{docs/example.py}{tag1}{Python}{Example snippet.} ``` The option `firstnumber=1` starts line numbering at line 1, `fontsize=\scriptsize` changes the font size, and `style=monokai` changes the syntax highlighting style. Without changing `firstnumber`, `tagsnip` preserves the original line numbers from the source file. The mandatory argument `source` defines where the code should be loaded from. It can be either a local file path or a URL pointing to a remote text file. `tagsnip` distinguishes these cases automatically. The mandatory argument `tag` specifies the unique keyword identifying the requested snippet. A snippet is delimited in the source file by `tagsnip-start` and `tagsnip-end` markers: ```python # tagsnip-start tag1 def main(): x = 1 y = 2 print(x + y) return 0 # tagsnip-end tag1 ``` The tag must follow the marker after exactly one space. The mandatory argument `language` selects the programming language used for syntax highlighting. The final argument `caption` defines the snippet caption. It may be empty, but the braces must still be written. ## Local snippet Suppose the local file `docs/example.py` contains a function `main()` marked with the tag `tag1`, as seen above. The function can be included in the document with: ```tex \IncludeCode{example.py}{tag1}{Python}{Úryvek 2: ...} ```